From 8c9e32c4a32108e0931899e827e6d1acb135a790 Mon Sep 17 00:00:00 2001 From: Peter Steinberger Date: Sat, 17 Jan 2026 07:09:26 +0000 Subject: [PATCH] refactor: share sessions list row type Co-authored-by: Adam Holt --- src/agents/tools/sessions-helpers.ts | 30 ++++++++++++++++++++++++++ src/agents/tools/sessions-list-tool.ts | 26 +--------------------- 2 files changed, 31 insertions(+), 25 deletions(-) diff --git a/src/agents/tools/sessions-helpers.ts b/src/agents/tools/sessions-helpers.ts index cc63d545d..c0abdd6a1 100644 --- a/src/agents/tools/sessions-helpers.ts +++ b/src/agents/tools/sessions-helpers.ts @@ -3,6 +3,36 @@ import { normalizeMainKey } from "../../routing/session-key.js"; export type SessionKind = "main" | "group" | "cron" | "hook" | "node" | "other"; +export type SessionListDeliveryContext = { + channel?: string; + to?: string; + accountId?: string; +}; + +export type SessionListRow = { + key: string; + kind: SessionKind; + channel: string; + label?: string; + displayName?: string; + deliveryContext?: SessionListDeliveryContext; + updatedAt?: number | null; + sessionId?: string; + model?: string; + contextTokens?: number | null; + totalTokens?: number | null; + thinkingLevel?: string; + verboseLevel?: string; + systemSent?: boolean; + abortedLastRun?: boolean; + sendPolicy?: string; + lastChannel?: string; + lastTo?: string; + lastAccountId?: string; + transcriptPath?: string; + messages?: unknown[]; +}; + function normalizeKey(value?: string) { const trimmed = value?.trim(); return trimmed ? trimmed : undefined; diff --git a/src/agents/tools/sessions-list-tool.ts b/src/agents/tools/sessions-list-tool.ts index ae51a3441..b00c65fdf 100644 --- a/src/agents/tools/sessions-list-tool.ts +++ b/src/agents/tools/sessions-list-tool.ts @@ -17,34 +17,10 @@ import { resolveDisplaySessionKey, resolveInternalSessionKey, resolveMainSessionAlias, - type SessionKind, + type SessionListRow, stripToolMessages, } from "./sessions-helpers.js"; -type SessionListRow = { - key: string; - kind: SessionKind; - channel: string; - label?: string; - displayName?: string; - deliveryContext?: { channel?: string; to?: string; accountId?: string }; - updatedAt?: number | null; - sessionId?: string; - model?: string; - contextTokens?: number | null; - totalTokens?: number | null; - thinkingLevel?: string; - verboseLevel?: string; - systemSent?: boolean; - abortedLastRun?: boolean; - sendPolicy?: string; - lastChannel?: string; - lastTo?: string; - lastAccountId?: string; - transcriptPath?: string; - messages?: unknown[]; -}; - const SessionsListToolSchema = Type.Object({ kinds: Type.Optional(Type.Array(Type.String())), limit: Type.Optional(Type.Number({ minimum: 1 })),