mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-03 19:30:23 +00:00
fix: keep session thread ids in sessions list
This commit is contained in:
@@ -44,6 +44,7 @@ export type SessionListDeliveryContext = {
|
||||
channel?: string;
|
||||
to?: string;
|
||||
accountId?: string;
|
||||
threadId?: string;
|
||||
};
|
||||
|
||||
export type SessionRunStatus = "running" | "done" | "failed" | "killed" | "timeout";
|
||||
|
||||
76
src/agents/tools/sessions-list-tool.test.ts
Normal file
76
src/agents/tools/sessions-list-tool.test.ts
Normal file
@@ -0,0 +1,76 @@
|
||||
import { beforeEach, describe, expect, it, vi } from "vitest";
|
||||
|
||||
describe("sessions-list-tool", () => {
|
||||
beforeEach(() => {
|
||||
vi.resetModules();
|
||||
});
|
||||
|
||||
it("keeps deliveryContext.threadId in sessions_list results", async () => {
|
||||
const gatewayCallMock = vi.fn(async (opts: unknown) => {
|
||||
const request = opts as { method?: string };
|
||||
if (request.method === "sessions.list") {
|
||||
return {
|
||||
path: "/tmp/sessions.json",
|
||||
sessions: [
|
||||
{
|
||||
key: "agent:main:dashboard:child",
|
||||
kind: "direct",
|
||||
sessionId: "sess-dashboard-child",
|
||||
deliveryContext: {
|
||||
channel: "discord",
|
||||
to: "discord:child",
|
||||
accountId: "acct-1",
|
||||
threadId: "thread-1",
|
||||
},
|
||||
},
|
||||
],
|
||||
};
|
||||
}
|
||||
return {};
|
||||
});
|
||||
|
||||
vi.doMock("../../gateway/call.js", () => ({
|
||||
callGateway: gatewayCallMock,
|
||||
}));
|
||||
vi.doMock("./sessions-helpers.js", async () => {
|
||||
const actual =
|
||||
await vi.importActual<typeof import("./sessions-helpers.js")>("./sessions-helpers.js");
|
||||
return {
|
||||
...actual,
|
||||
createAgentToAgentPolicy: () => ({}),
|
||||
createSessionVisibilityGuard: async () => ({
|
||||
check: () => ({ allowed: true }),
|
||||
}),
|
||||
resolveEffectiveSessionToolsVisibility: () => "all",
|
||||
resolveSandboxedSessionToolContext: () => ({
|
||||
mainKey: "main",
|
||||
alias: "main",
|
||||
requesterInternalKey: undefined,
|
||||
restrictToSpawned: false,
|
||||
}),
|
||||
};
|
||||
});
|
||||
|
||||
const { createSessionsListTool } = await import("./sessions-list-tool.js");
|
||||
const tool = createSessionsListTool({ config: {} as never });
|
||||
|
||||
const result = await tool.execute("call-1", {});
|
||||
const details = result.details as {
|
||||
sessions?: Array<{
|
||||
deliveryContext?: {
|
||||
channel?: string;
|
||||
to?: string;
|
||||
accountId?: string;
|
||||
threadId?: string;
|
||||
};
|
||||
}>;
|
||||
};
|
||||
|
||||
expect(details.sessions?.[0]?.deliveryContext).toEqual({
|
||||
channel: "discord",
|
||||
to: "discord:child",
|
||||
accountId: "acct-1",
|
||||
threadId: "thread-1",
|
||||
});
|
||||
});
|
||||
});
|
||||
@@ -152,6 +152,8 @@ export function createSessionsListTool(opts?: {
|
||||
const deliveryTo = typeof deliveryContext?.to === "string" ? deliveryContext.to : undefined;
|
||||
const deliveryAccountId =
|
||||
typeof deliveryContext?.accountId === "string" ? deliveryContext.accountId : undefined;
|
||||
const deliveryThreadId =
|
||||
typeof deliveryContext?.threadId === "string" ? deliveryContext.threadId : undefined;
|
||||
const lastChannel =
|
||||
deliveryChannel ??
|
||||
(typeof entry.lastChannel === "string" ? entry.lastChannel : undefined);
|
||||
@@ -218,11 +220,12 @@ export function createSessionsListTool(opts?: {
|
||||
})
|
||||
: undefined,
|
||||
deliveryContext:
|
||||
deliveryChannel || deliveryTo || deliveryAccountId
|
||||
deliveryChannel || deliveryTo || deliveryAccountId || deliveryThreadId
|
||||
? {
|
||||
channel: deliveryChannel,
|
||||
to: deliveryTo,
|
||||
accountId: deliveryAccountId,
|
||||
threadId: deliveryThreadId,
|
||||
}
|
||||
: undefined,
|
||||
updatedAt: typeof entry.updatedAt === "number" ? entry.updatedAt : undefined,
|
||||
|
||||
Reference in New Issue
Block a user