@@ -40,7 +40,7 @@ const SessionsSendToolSchema = Type.Union([
4040 ) ,
4141 Type . Object (
4242 {
43- label : Type . String ( ) ,
43+ label : Type . String ( { minLength : 1 , maxLength : 64 } ) ,
4444 message : Type . String ( ) ,
4545 timeoutSeconds : Type . Optional ( Type . Integer ( { minimum : 0 } ) ) ,
4646 } ,
@@ -81,7 +81,7 @@ export function createSessionsSendTool(opts?: {
8181 ! isSubagentSessionKey ( requesterInternalKey ) ;
8282
8383 const sessionKeyParam = readStringParam ( params , "sessionKey" ) ;
84- const labelParam = readStringParam ( params , "label" ) ;
84+ const labelParam = readStringParam ( params , "label" ) ?. trim ( ) || undefined ;
8585 if ( sessionKeyParam && labelParam ) {
8686 return jsonResult ( {
8787 runId : crypto . randomUUID ( ) ,
@@ -99,32 +99,21 @@ export function createSessionsSendTool(opts?: {
9999 return Array . isArray ( result ?. sessions ) ? result . sessions : [ ] ;
100100 } ;
101101
102- const activeMinutes = 24 * 60 ;
103- const visibleSessions = restrictToSpawned
104- ? await listSessions ( {
105- activeMinutes,
106- includeGlobal : false ,
107- includeUnknown : false ,
108- limit : 500 ,
109- spawnedBy : requesterInternalKey ,
110- } )
111- : undefined ;
112-
113102 let sessionKey = sessionKeyParam ;
114103 if ( ! sessionKey && labelParam ) {
115- const sessions =
116- visibleSessions ??
117- ( await listSessions ( {
118- activeMinutes ,
119- includeGlobal : false ,
120- includeUnknown : false ,
121- limit : 500 ,
122- } ) ) ;
123- const matches = sessions . filter ( ( entry ) => {
124- const label =
125- typeof entry ?. label === "string" ? entry . label : undefined ;
126- return label === labelParam ;
127- } ) ;
104+ const agentIdForLookup = requesterInternalKey
105+ ? normalizeAgentId (
106+ parseAgentSessionKey ( requesterInternalKey ) ?. agentId ,
107+ )
108+ : undefined ;
109+ const listParams : Record < string , unknown > = {
110+ includeGlobal : false ,
111+ includeUnknown : false ,
112+ label : labelParam ,
113+ } ;
114+ if ( restrictToSpawned ) listParams . spawnedBy = requesterInternalKey ;
115+ if ( agentIdForLookup ) listParams . agentId = agentIdForLookup ;
116+ const matches = await listSessions ( listParams ) ;
128117 if ( matches . length === 0 ) {
129118 if ( restrictToSpawned ) {
130119 return jsonResult ( {
@@ -176,7 +165,18 @@ export function createSessionsSendTool(opts?: {
176165 } ) ;
177166
178167 if ( restrictToSpawned ) {
179- const sessions = visibleSessions ?? [ ] ;
168+ const agentIdForLookup = requesterInternalKey
169+ ? normalizeAgentId (
170+ parseAgentSessionKey ( requesterInternalKey ) ?. agentId ,
171+ )
172+ : undefined ;
173+ const sessions = await listSessions ( {
174+ includeGlobal : false ,
175+ includeUnknown : false ,
176+ limit : 500 ,
177+ spawnedBy : requesterInternalKey ,
178+ ...( agentIdForLookup ? { agentId : agentIdForLookup } : { } ) ,
179+ } ) ;
180180 const ok = sessions . some ( ( entry ) => entry ?. key === resolvedKey ) ;
181181 if ( ! ok ) {
182182 return jsonResult ( {
0 commit comments