File tree Expand file tree Collapse file tree 3 files changed +24
-7
lines changed
app/workspace/[workspaceId]/home/hooks Expand file tree Collapse file tree 3 files changed +24
-7
lines changed Original file line number Diff line number Diff line change @@ -1155,7 +1155,7 @@ export function useChat(
11551155 } ) )
11561156 : undefined
11571157
1158- const requestChatId = selectedChatIdRef . current
1158+ const requestChatId = selectedChatIdRef . current ?? chatIdRef . current
11591159 if ( requestChatId ) {
11601160 const cachedUserMsg : TaskStoredMessage = {
11611161 id : userMessageId ,
Original file line number Diff line number Diff line change @@ -197,11 +197,6 @@ export function createSSEStream(params: StreamingOrchestrationParams): ReadableS
197197
198198 const eventId = ++ localSeq
199199
200- const response = ( event ?. data ?. response || { } ) as Record < string , unknown >
201- if ( event . type === 'done' && response . async_pause ) {
202- await updateRunStatus ( runId , 'paused_waiting_for_tool' ) . catch ( ( ) => { } )
203- }
204-
205200 // Enqueue to client stream FIRST for minimal latency.
206201 // Redis persistence happens after so the client never waits on I/O.
207202 try {
Original file line number Diff line number Diff line change 11import { createLogger } from '@sim/logger'
2+ import { updateRunStatus } from '@/lib/copilot/async-runs/repository'
23import { SIM_AGENT_API_URL , SIM_AGENT_VERSION } from '@/lib/copilot/constants'
34import { prepareExecutionContext } from '@/lib/copilot/orchestrator/tool-executor'
45import type {
56 ExecutionContext ,
67 OrchestratorOptions ,
78 OrchestratorResult ,
9+ SSEEvent ,
810} from '@/lib/copilot/orchestrator/types'
911import { env } from '@/lib/core/config/env'
1012import { getEffectiveDecryptedEnv } from '@/lib/environment/utils'
@@ -71,8 +73,28 @@ export async function orchestrateCopilotStream(
7173 let route = goRoute
7274 let payload = requestPayload
7375
76+ const callerOnEvent = options . onEvent
77+
7478 for ( ; ; ) {
7579 context . streamComplete = false
80+
81+ const loopOptions = {
82+ ...options ,
83+ onEvent : async ( event : SSEEvent ) => {
84+ if ( event . type === 'done' ) {
85+ const d = ( event . data ?? { } ) as Record < string , unknown >
86+ const response = ( d . response ?? { } ) as Record < string , unknown >
87+ if ( response . async_pause ) {
88+ if ( runId ) {
89+ await updateRunStatus ( runId , 'paused_waiting_for_tool' ) . catch ( ( ) => { } )
90+ }
91+ return
92+ }
93+ }
94+ await callerOnEvent ?.( event )
95+ } ,
96+ }
97+
7698 await runStreamLoop (
7799 `${ SIM_AGENT_API_URL } ${ route } ` ,
78100 {
@@ -86,7 +108,7 @@ export async function orchestrateCopilotStream(
86108 } ,
87109 context ,
88110 execContext ,
89- options
111+ loopOptions
90112 )
91113
92114 const continuation = context . awaitingAsyncContinuation
You can’t perform that action at this time.
0 commit comments