mirror of
https://github.com/openclaw/openclaw.git
synced 2026-04-19 04:07:28 +00:00
Plugins: add sessionKey to session lifecycle hooks
This commit is contained in:
committed by
Peter Steinberger
parent
16fd604219
commit
20c15ccc63
@@ -647,10 +647,12 @@ export async function initSessionState(params: {
|
||||
.runSessionEnd(
|
||||
{
|
||||
sessionId: previousSessionEntry.sessionId,
|
||||
sessionKey,
|
||||
messageCount: 0,
|
||||
},
|
||||
{
|
||||
sessionId: previousSessionEntry.sessionId,
|
||||
sessionKey,
|
||||
agentId: resolveSessionAgentId({ sessionKey, config: cfg }),
|
||||
},
|
||||
)
|
||||
@@ -664,10 +666,12 @@ export async function initSessionState(params: {
|
||||
.runSessionStart(
|
||||
{
|
||||
sessionId: effectiveSessionId,
|
||||
sessionKey,
|
||||
resumedFrom: previousSessionEntry?.sessionId,
|
||||
},
|
||||
{
|
||||
sessionId: effectiveSessionId,
|
||||
sessionKey,
|
||||
agentId: resolveSessionAgentId({ sessionKey, config: cfg }),
|
||||
},
|
||||
)
|
||||
|
||||
@@ -566,17 +566,20 @@ export type PluginHookBeforeMessageWriteResult = {
|
||||
export type PluginHookSessionContext = {
|
||||
agentId?: string;
|
||||
sessionId: string;
|
||||
sessionKey?: string;
|
||||
};
|
||||
|
||||
// session_start hook
|
||||
export type PluginHookSessionStartEvent = {
|
||||
sessionId: string;
|
||||
sessionKey?: string;
|
||||
resumedFrom?: string;
|
||||
};
|
||||
|
||||
// session_end hook
|
||||
export type PluginHookSessionEndEvent = {
|
||||
sessionId: string;
|
||||
sessionKey?: string;
|
||||
messageCount: number;
|
||||
durationMs?: number;
|
||||
};
|
||||
|
||||
@@ -14,13 +14,13 @@ describe("session hook runner methods", () => {
|
||||
const runner = createHookRunner(registry);
|
||||
|
||||
await runner.runSessionStart(
|
||||
{ sessionId: "abc-123", resumedFrom: "old-session" },
|
||||
{ sessionId: "abc-123", agentId: "main" },
|
||||
{ sessionId: "abc-123", sessionKey: "agent:main:abc", resumedFrom: "old-session" },
|
||||
{ sessionId: "abc-123", sessionKey: "agent:main:abc", agentId: "main" },
|
||||
);
|
||||
|
||||
expect(handler).toHaveBeenCalledWith(
|
||||
{ sessionId: "abc-123", resumedFrom: "old-session" },
|
||||
{ sessionId: "abc-123", agentId: "main" },
|
||||
{ sessionId: "abc-123", sessionKey: "agent:main:abc", resumedFrom: "old-session" },
|
||||
{ sessionId: "abc-123", sessionKey: "agent:main:abc", agentId: "main" },
|
||||
);
|
||||
});
|
||||
|
||||
@@ -30,13 +30,13 @@ describe("session hook runner methods", () => {
|
||||
const runner = createHookRunner(registry);
|
||||
|
||||
await runner.runSessionEnd(
|
||||
{ sessionId: "abc-123", messageCount: 42 },
|
||||
{ sessionId: "abc-123", agentId: "main" },
|
||||
{ sessionId: "abc-123", sessionKey: "agent:main:abc", messageCount: 42 },
|
||||
{ sessionId: "abc-123", sessionKey: "agent:main:abc", agentId: "main" },
|
||||
);
|
||||
|
||||
expect(handler).toHaveBeenCalledWith(
|
||||
{ sessionId: "abc-123", messageCount: 42 },
|
||||
{ sessionId: "abc-123", agentId: "main" },
|
||||
{ sessionId: "abc-123", sessionKey: "agent:main:abc", messageCount: 42 },
|
||||
{ sessionId: "abc-123", sessionKey: "agent:main:abc", agentId: "main" },
|
||||
);
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user