Skip to content

Commit 62531f2

Browse files
committed
Fixes
1 parent 7ee6ee4 commit 62531f2

File tree

3 files changed

+24
-7
lines changed

3 files changed

+24
-7
lines changed

apps/sim/app/workspace/[workspaceId]/home/hooks/use-chat.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff 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,

apps/sim/lib/copilot/chat-streaming.ts

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff 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 {

apps/sim/lib/copilot/orchestrator/index.ts

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
import { createLogger } from '@sim/logger'
2+
import { updateRunStatus } from '@/lib/copilot/async-runs/repository'
23
import { SIM_AGENT_API_URL, SIM_AGENT_VERSION } from '@/lib/copilot/constants'
34
import { prepareExecutionContext } from '@/lib/copilot/orchestrator/tool-executor'
45
import type {
56
ExecutionContext,
67
OrchestratorOptions,
78
OrchestratorResult,
9+
SSEEvent,
810
} from '@/lib/copilot/orchestrator/types'
911
import { env } from '@/lib/core/config/env'
1012
import { 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

0 commit comments

Comments
 (0)