@@ -45,7 +45,6 @@ import {
4545} from "./attempt-async-tasks.js" ;
4646import { steerActiveSessionWithOptionalDeliveryWait } from "./attempt-queue-message.js" ;
4747import type { EmbeddedAttemptClientToolCallSlot } from "./attempt-result.js" ;
48- import { buildEmbeddedSubscriptionParams } from "./attempt-subscription-cleanup.js" ;
4948import {
5049 resolveFinalAssistantRawText ,
5150 resolveFinalAssistantVisibleText ,
@@ -243,83 +242,81 @@ export function prepareEmbeddedAttemptStream(input: {
243242 // Terminal callbacks run after queue construction; keep the queue in this
244243 // phase so active-run clearing and subscription teardown share one owner.
245244 const getQueueHandle = ( ) : AttemptStreamQueueHandle => queueHandle ;
246- const subscription = subscribeEmbeddedAgentSession (
247- buildEmbeddedSubscriptionParams ( {
248- session : input . activeSession ,
249- runId : attempt . runId ,
250- lifecycleGeneration : attempt . lifecycleGeneration ,
251- messageChannel : input . runtimeChannel ,
252- initialReplayState : attempt . initialReplayState ,
253- hookRunner : getGlobalHookRunner ( ) ?? undefined ,
254- verboseLevel : attempt . verboseLevel ,
255- reasoningMode : attempt . reasoningLevel ?? "off" ,
256- thinkingLevel : attempt . thinkLevel ,
257- toolResultFormat : attempt . toolResultFormat ,
258- shouldEmitToolResult : attempt . shouldEmitToolResult ,
259- shouldEmitToolOutput : attempt . shouldEmitToolOutput ,
260- sourceReplyDeliveryMode : attempt . sourceReplyDeliveryMode ,
261- hasDeliveredMessageToolOnlySourceReply : input . hasDeliveredSourceReply ,
262- onDeliveredMessageToolOnlySourceReply : input . markSourceReplyDelivered ,
263- onAgentToolResult : attempt . onAgentToolResult ,
264- observeToolTerminal : attempt . observeToolTerminal ,
265- onToolResult : attempt . onToolResult ,
266- onReasoningStream : attempt . onReasoningStream ,
267- streamReasoningInNonStreamModes : attempt . streamReasoningInNonStreamModes ,
268- onReasoningEnd : attempt . onReasoningEnd ,
269- onBlockReply : input . onBlockReply ,
270- onBlockReplyFlush : input . onBlockReplyFlush ,
271- onBeforeTerminalDelivery,
272- blockReplyBreak : attempt . blockReplyBreak ,
273- blockReplyChunking : attempt . blockReplyChunking ,
274- onPartialReply : attempt . onPartialReply ,
275- onAssistantMessageStart : attempt . onAssistantMessageStart ,
276- onExecutionPhase : attempt . onExecutionPhase ,
277- onAgentEvent : attempt . onAgentEvent ,
278- terminalLifecyclePhase : attempt . deferTerminalLifecycle ? "finishing" : "end" ,
279- onToolStreamBoundary : attempt . onToolStreamBoundary ,
280- isTerminalAborted : ( ) => input . getRunState ( ) . aborted ,
281- resolveTerminalStopReason : ( ) =>
282- isAgentRunRestartAbortReason ( input . runAbortController . signal . reason )
283- ? AGENT_RUN_RESTART_ABORT_STOP_REASON
284- : undefined ,
285- onBeforeLifecycleTerminal : ( ) => {
286- if (
287- requiresCompletionRequiredAsyncTaskWait ( {
288- sessionKey : attempt . sessionKey ,
289- toolMetas : toolMetasForTerminal ,
290- } )
291- ) {
292- return ;
293- }
294- // Clear embedded-run activity before emitting terminal lifecycle events so
295- // post-completion cleanup does not observe a logically finished run as active.
296- clearActiveEmbeddedRun (
297- attempt . sessionId ,
298- getQueueHandle ( ) ,
299- attempt . sessionKey ,
300- attempt . sessionFile ,
301- ) ;
302- } ,
303- enforceFinalTag : attempt . enforceFinalTag ,
304- silentExpected : attempt . silentExpected ,
305- suppressLiveStreamOutput : attempt . suppressLiveStreamOutput ,
306- config : attempt . config ,
307- // Live events belong to the transcript session. The sandbox key is only
308- // authority context and may intentionally point at a visible parent.
309- sessionKey : attempt . sessionKey ,
310- currentChannelId : attempt . currentChannelId ,
311- currentMessagingTarget : attempt . currentMessagingTarget ,
312- currentThreadId : attempt . currentThreadTs ,
313- currentMessageId : attempt . currentMessageId ,
314- replyToMode : attempt . replyToMode ,
315- hasRepliedRef : attempt . hasRepliedRef ,
316- sessionId : attempt . sessionId ,
317- agentId : input . hookAgentId ,
318- builtinToolNames : input . builtinToolNames ,
319- replaySafeToolNames : input . replaySafeToolNames ,
320- internalEvents : attempt . internalEvents ,
321- } ) ,
322- ) ;
245+ const subscription = subscribeEmbeddedAgentSession ( {
246+ session : input . activeSession ,
247+ runId : attempt . runId ,
248+ lifecycleGeneration : attempt . lifecycleGeneration ,
249+ messageChannel : input . runtimeChannel ,
250+ initialReplayState : attempt . initialReplayState ,
251+ hookRunner : getGlobalHookRunner ( ) ?? undefined ,
252+ verboseLevel : attempt . verboseLevel ,
253+ reasoningMode : attempt . reasoningLevel ?? "off" ,
254+ thinkingLevel : attempt . thinkLevel ,
255+ toolResultFormat : attempt . toolResultFormat ,
256+ shouldEmitToolResult : attempt . shouldEmitToolResult ,
257+ shouldEmitToolOutput : attempt . shouldEmitToolOutput ,
258+ sourceReplyDeliveryMode : attempt . sourceReplyDeliveryMode ,
259+ hasDeliveredMessageToolOnlySourceReply : input . hasDeliveredSourceReply ,
260+ onDeliveredMessageToolOnlySourceReply : input . markSourceReplyDelivered ,
261+ onAgentToolResult : attempt . onAgentToolResult ,
262+ observeToolTerminal : attempt . observeToolTerminal ,
263+ onToolResult : attempt . onToolResult ,
264+ onReasoningStream : attempt . onReasoningStream ,
265+ streamReasoningInNonStreamModes : attempt . streamReasoningInNonStreamModes ,
266+ onReasoningEnd : attempt . onReasoningEnd ,
267+ onBlockReply : input . onBlockReply ,
268+ onBlockReplyFlush : input . onBlockReplyFlush ,
269+ onBeforeTerminalDelivery,
270+ blockReplyBreak : attempt . blockReplyBreak ,
271+ blockReplyChunking : attempt . blockReplyChunking ,
272+ onPartialReply : attempt . onPartialReply ,
273+ onAssistantMessageStart : attempt . onAssistantMessageStart ,
274+ onExecutionPhase : attempt . onExecutionPhase ,
275+ onAgentEvent : attempt . onAgentEvent ,
276+ terminalLifecyclePhase : attempt . deferTerminalLifecycle ? "finishing" : "end" ,
277+ onToolStreamBoundary : attempt . onToolStreamBoundary ,
278+ isTerminalAborted : ( ) => input . getRunState ( ) . aborted ,
279+ resolveTerminalStopReason : ( ) =>
280+ isAgentRunRestartAbortReason ( input . runAbortController . signal . reason )
281+ ? AGENT_RUN_RESTART_ABORT_STOP_REASON
282+ : undefined ,
283+ onBeforeLifecycleTerminal : ( ) => {
284+ if (
285+ requiresCompletionRequiredAsyncTaskWait ( {
286+ sessionKey : attempt . sessionKey ,
287+ toolMetas : toolMetasForTerminal ,
288+ } )
289+ ) {
290+ return ;
291+ }
292+ // Clear embedded-run activity before emitting terminal lifecycle events so
293+ // post-completion cleanup does not observe a logically finished run as active.
294+ clearActiveEmbeddedRun (
295+ attempt . sessionId ,
296+ getQueueHandle ( ) ,
297+ attempt . sessionKey ,
298+ attempt . sessionFile ,
299+ ) ;
300+ } ,
301+ enforceFinalTag : attempt . enforceFinalTag ,
302+ silentExpected : attempt . silentExpected ,
303+ suppressLiveStreamOutput : attempt . suppressLiveStreamOutput ,
304+ config : attempt . config ,
305+ // Live events belong to the transcript session. The sandbox key is only
306+ // authority context and may intentionally point at a visible parent.
307+ sessionKey : attempt . sessionKey ,
308+ currentChannelId : attempt . currentChannelId ,
309+ currentMessagingTarget : attempt . currentMessagingTarget ,
310+ currentThreadId : attempt . currentThreadTs ,
311+ currentMessageId : attempt . currentMessageId ,
312+ replyToMode : attempt . replyToMode ,
313+ hasRepliedRef : attempt . hasRepliedRef ,
314+ sessionId : attempt . sessionId ,
315+ agentId : input . hookAgentId ,
316+ builtinToolNames : input . builtinToolNames ,
317+ replaySafeToolNames : input . replaySafeToolNames ,
318+ internalEvents : attempt . internalEvents ,
319+ } ) ;
323320 toolMetasForTerminal = subscription . toolMetas ;
324321
325322 const toolSearchCatalogExecutor : ToolSearchCatalogToolExecutor = async ( toolParams ) => {
0 commit comments