@@ -6,7 +6,7 @@ import type { GatewayRequestContext, GatewayRequestHandlers } from "./types.js";
66import { resolveSessionAgentId } from "../../agents/agent-scope.js" ;
77import { resolveThinkingDefault } from "../../agents/model-selection.js" ;
88import { resolveAgentTimeoutMs } from "../../agents/timeout.js" ;
9- import { dispatchInboundMessage , withReplyDispatcher } from "../../auto-reply/dispatch.js" ;
9+ import { dispatchInboundMessage } from "../../auto-reply/dispatch.js" ;
1010import { createReplyDispatcher } from "../../auto-reply/reply/reply-dispatcher.js" ;
1111import { createReplyPrefixOptions } from "../../channels/reply-prefix.js" ;
1212import { resolveSessionFilePath } from "../../config/sessions.js" ;
@@ -524,40 +524,36 @@ export const chatHandlers: GatewayRequestHandlers = {
524524 } ) ;
525525
526526 let agentRunStarted = false ;
527- void withReplyDispatcher ( {
527+ void dispatchInboundMessage ( {
528+ ctx,
529+ cfg,
528530 dispatcher,
529- run : ( ) =>
530- dispatchInboundMessage ( {
531- ctx,
532- cfg,
533- dispatcher,
534- replyOptions : {
535- runId : clientRunId ,
536- abortSignal : abortController . signal ,
537- images : parsedImages . length > 0 ? parsedImages : undefined ,
538- disableBlockStreaming : true ,
539- onAgentRunStart : ( runId ) => {
540- agentRunStarted = true ;
541- const connId = typeof client ?. connId === "string" ? client . connId : undefined ;
542- const wantsToolEvents = hasGatewayClientCap (
543- client ?. connect ?. caps ,
544- GATEWAY_CLIENT_CAPS . TOOL_EVENTS ,
545- ) ;
546- if ( connId && wantsToolEvents ) {
547- context . registerToolEventRecipient ( runId , connId ) ;
548- // Register for any other active runs *in the same session* so
549- // late-joining clients (e.g. page refresh mid-response) receive
550- // in-progress tool events without leaking cross-session data.
551- for ( const [ activeRunId , active ] of context . chatAbortControllers ) {
552- if ( activeRunId !== runId && active . sessionKey === p . sessionKey ) {
553- context . registerToolEventRecipient ( activeRunId , connId ) ;
554- }
555- }
531+ replyOptions : {
532+ runId : clientRunId ,
533+ abortSignal : abortController . signal ,
534+ images : parsedImages . length > 0 ? parsedImages : undefined ,
535+ disableBlockStreaming : true ,
536+ onAgentRunStart : ( runId ) => {
537+ agentRunStarted = true ;
538+ const connId = typeof client ?. connId === "string" ? client . connId : undefined ;
539+ const wantsToolEvents = hasGatewayClientCap (
540+ client ?. connect ?. caps ,
541+ GATEWAY_CLIENT_CAPS . TOOL_EVENTS ,
542+ ) ;
543+ if ( connId && wantsToolEvents ) {
544+ context . registerToolEventRecipient ( runId , connId ) ;
545+ // Register for any other active runs *in the same session* so
546+ // late-joining clients (e.g. page refresh mid-response) receive
547+ // in-progress tool events without leaking cross-session data.
548+ for ( const [ activeRunId , active ] of context . chatAbortControllers ) {
549+ if ( activeRunId !== runId && active . sessionKey === p . sessionKey ) {
550+ context . registerToolEventRecipient ( activeRunId , connId ) ;
556551 }
557- } ,
558- onModelSelected,
559- } ,
560- } ) ,
552+ }
553+ }
554+ } ,
555+ onModelSelected,
556+ } ,
561557 } )
562558 . then ( ( ) => {
563559 if ( ! agentRunStarted ) {
0 commit comments