fix: keep session thread ids in sessions list

This commit is contained in:
Tak Hoffman
2026-03-26 22:41:08 -05:00
parent a2cc0630d2
commit e25965ed4a
3 changed files with 81 additions and 1 deletions

View File

@@ -44,6 +44,7 @@ export type SessionListDeliveryContext = {
channel?: string;
to?: string;
accountId?: string;
threadId?: string;
};
export type SessionRunStatus = "running" | "done" | "failed" | "killed" | "timeout";

View 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",
});
});
});

View File

@@ -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,