Skip to content

Commit 69d69ee

Browse files
committed
temp
1 parent a738a6d commit 69d69ee

File tree

2 files changed

+35
-1
lines changed
  • apps/sim

2 files changed

+35
-1
lines changed

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

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -368,6 +368,15 @@ export function useChat(
368368
options?: { preserveExistingState?: boolean }
369369
) => Promise<{ sawStreamError: boolean; sawComplete: boolean }>
370370
>(async () => ({ sawStreamError: false, sawComplete: false }))
371+
const attachToExistingStreamRef = useRef<
372+
(opts: {
373+
streamId: string
374+
assistantId: string
375+
expectedGen: number
376+
initialBatch?: StreamBatchResponse | null
377+
afterCursor?: string
378+
}) => Promise<{ error: boolean; aborted: boolean }>
379+
>(async () => ({ error: false, aborted: true }))
371380
const retryReconnectRef = useRef<
372381
(opts: { streamId: string; assistantId: string; gen: number }) => Promise<boolean>
373382
>(async () => false)
@@ -617,7 +626,7 @@ export function useChat(
617626

618627
const reconnectResult =
619628
snapshotEvents.length > 0
620-
? await attachToExistingStream({
629+
? await attachToExistingStreamRef.current({
621630
streamId: activeStreamId,
622631
assistantId,
623632
expectedGen: gen,
@@ -1613,6 +1622,7 @@ export function useChat(
16131622
},
16141623
[fetchStreamBatch]
16151624
)
1625+
attachToExistingStreamRef.current = attachToExistingStream
16161626

16171627
const resumeOrFinalize = useCallback(
16181628
async (opts: {

apps/sim/lib/copilot/request/lifecycle/run.ts

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -282,13 +282,24 @@ async function runCheckpointLoop(
282282
)
283283
}
284284

285+
if (isAborted(options, context)) {
286+
cancelPendingTools(context)
287+
context.awaitingAsyncContinuation = undefined
288+
break
289+
}
290+
285291
const results: Array<{
286292
callId: string
287293
name: string
288294
data: unknown
289295
success: boolean
290296
}> = []
291297
for (const toolCallId of continuation.pendingToolCallIds) {
298+
if (isAborted(options, context)) {
299+
cancelPendingTools(context)
300+
context.awaitingAsyncContinuation = undefined
301+
break
302+
}
292303
const tool = context.toolCalls.get(toolCallId)
293304
if (!tool || (!tool.result && !tool.error)) {
294305
logger.error('Missing tool result for pending tool call', {
@@ -309,6 +320,12 @@ async function runCheckpointLoop(
309320
})
310321
}
311322

323+
if (isAborted(options, context)) {
324+
cancelPendingTools(context)
325+
context.awaitingAsyncContinuation = undefined
326+
break
327+
}
328+
312329
logger.info('Resuming with tool results', {
313330
checkpointId: continuation.checkpointId,
314331
runId: continuation.runId,
@@ -324,6 +341,13 @@ async function runCheckpointLoop(
324341
checkpointId: continuation.checkpointId,
325342
results,
326343
}
344+
345+
if (isAborted(options, context)) {
346+
cancelPendingTools(context)
347+
context.awaitingAsyncContinuation = undefined
348+
break
349+
}
350+
327351
logger.info('Prepared resume request payload', {
328352
route,
329353
streamId: context.messageId,

0 commit comments

Comments
 (0)