fix: expose parent session keys in sessions list

This commit is contained in:
Tak Hoffman
2026-03-26 12:18:19 -05:00
parent cb46b08efc
commit c041fcc04d
3 changed files with 21 additions and 1 deletions

View File

@@ -160,6 +160,13 @@ describe("sessions tools", () => {
estimatedCostUsd: 0.0042,
childSessions: ["agent:main:subagent:worker"],
},
{
key: "agent:main:dashboard:child",
kind: "direct",
sessionId: "s-dashboard-child",
updatedAt: 12,
parentSessionKey: "agent:main:main",
},
{
key: "cron:job-1",
kind: "direct",
@@ -201,10 +208,11 @@ describe("sessions tools", () => {
runtimeMs?: number;
estimatedCostUsd?: number;
childSessions?: string[];
parentSessionKey?: string;
messages?: Array<{ role?: string }>;
}>;
};
expect(details.sessions).toHaveLength(3);
expect(details.sessions).toHaveLength(4);
const main = details.sessions?.find((s) => s.key === "main");
expect(main?.channel).toBe("whatsapp");
expect(main?.messages?.length).toBe(1);
@@ -217,6 +225,9 @@ describe("sessions tools", () => {
expect(group?.estimatedCostUsd).toBe(0.0042);
expect(group?.childSessions).toEqual(["agent:main:subagent:worker"]);
const dashboardChild = details.sessions?.find((s) => s.key === "agent:main:dashboard:child");
expect(dashboardChild?.parentSessionKey).toBe("agent:main:main");
const cronOnly = await tool.execute("call2", { kinds: ["cron"] });
const cronDetails = cronOnly.details as {
sessions?: Array<Record<string, unknown>>;

View File

@@ -54,6 +54,7 @@ export type SessionListRow = {
channel: string;
label?: string;
displayName?: string;
parentSessionKey?: string;
deliveryContext?: SessionListDeliveryContext;
updatedAt?: number | null;
sessionId?: string;

View File

@@ -195,6 +195,14 @@ export function createSessionsListTool(opts?: {
channel: derivedChannel,
label: typeof entry.label === "string" ? entry.label : undefined,
displayName: typeof entry.displayName === "string" ? entry.displayName : undefined,
parentSessionKey:
typeof entry.parentSessionKey === "string"
? resolveDisplaySessionKey({
key: entry.parentSessionKey,
alias,
mainKey,
})
: undefined,
deliveryContext:
deliveryChannel || deliveryTo || deliveryAccountId
? {