33 *
44 * Lists visible sessions and optionally hydrates titles, last messages, and transcript-derived metadata.
55 */
6- import {
7- normalizeOptionalLowercaseString ,
8- readStringValue ,
9- } from "@openclaw/normalization-core/string-coerce" ;
6+ import { readStringValue } from "@openclaw/normalization-core/string-coerce" ;
107import pMap from "p-map" ;
118import { Type } from "typebox" ;
129import type { SessionRunStatus } from "../../../packages/gateway-protocol/src/schema/sessions-row.js" ;
@@ -21,6 +18,7 @@ import { resolveSessionAgentIds } from "../agent-scope.js";
2118import {
2219 optionalNonNegativeIntegerSchema ,
2320 optionalPositiveIntegerSchema ,
21+ stringEnum ,
2422} from "../schema/typebox.js" ;
2523import {
2624 describeSessionLinkRule ,
@@ -51,12 +49,13 @@ import {
5149 resolveEffectiveSessionToolsVisibility ,
5250 resolveInternalSessionKey ,
5351 resolveSandboxedSessionToolContext ,
52+ SESSION_LIST_KINDS ,
5453 type GatewaySessionListRow ,
5554 type SessionListRow ,
5655} from "./sessions-helpers.js" ;
5756
5857const SessionsListToolSchema = Type . Object ( {
59- kinds : Type . Optional ( Type . Array ( Type . String ( ) ) ) ,
58+ kinds : Type . Optional ( Type . Array ( stringEnum ( SESSION_LIST_KINDS ) ) ) ,
6059 limit : optionalPositiveIntegerSchema ( ) ,
6160 activeMinutes : optionalPositiveIntegerSchema ( ) ,
6261 messageLimit : optionalNonNegativeIntegerSchema ( ) ,
@@ -73,14 +72,7 @@ const SessionListRowOutputSchema = Type.Object(
7372 key : Type . String ( ) ,
7473 sessionId : Type . Optional ( Type . String ( ) ) ,
7574 agentId : Type . String ( ) ,
76- kind : Type . Union ( [
77- Type . Literal ( "main" ) ,
78- Type . Literal ( "group" ) ,
79- Type . Literal ( "cron" ) ,
80- Type . Literal ( "hook" ) ,
81- Type . Literal ( "node" ) ,
82- Type . Literal ( "other" ) ,
83- ] ) ,
75+ kind : stringEnum ( SESSION_LIST_KINDS ) ,
8476 channel : Type . String ( ) ,
8577 archived : Type . Boolean ( ) ,
8678 pinned : Type . Boolean ( ) ,
@@ -185,13 +177,13 @@ export function createSessionsListTool(opts?: {
185177 sandboxed : opts ?. sandboxed === true ,
186178 } ) ;
187179
188- const kindsRaw = readStringArrayParam ( params , "kinds" )
189- ?. map ( ( value ) => normalizeOptionalLowercaseString ( value ) )
190- . filter ( ( value ) : value is string => Boolean ( value ) ) ;
191- const allowedKindsList = ( kindsRaw ?? [ ] ) . filter ( ( value ) =>
192- [ "main" , "group" , "cron" , "hook" , "node" , "other" ] . includes ( value ) ,
193- ) ;
194- const allowedKinds = allowedKindsList . length ? new Set ( allowedKindsList ) : undefined ;
180+ const kindsRaw = readStringArrayParam ( params , "kinds" ) ?. map ( ( value ) => value . toLowerCase ( ) ) ;
181+ const requestedKinds = params . kinds ;
182+ const allowedKinds =
183+ ( Array . isArray ( requestedKinds ) || typeof requestedKinds === "string" ) &&
184+ requestedKinds . length > 0
185+ ? new Set ( kindsRaw )
186+ : undefined ;
195187
196188 const limit = readPositiveIntegerParam ( params , "limit" ) ;
197189 const activeMinutes = readPositiveIntegerParam ( params , "activeMinutes" ) ;
0 commit comments