mirror of
https://github.com/simstudioai/sim.git
synced 2026-04-28 03:00:29 -04:00
temp
This commit is contained in:
@@ -368,6 +368,15 @@ export function useChat(
|
||||
options?: { preserveExistingState?: boolean }
|
||||
) => Promise<{ sawStreamError: boolean; sawComplete: boolean }>
|
||||
>(async () => ({ sawStreamError: false, sawComplete: false }))
|
||||
const attachToExistingStreamRef = useRef<
|
||||
(opts: {
|
||||
streamId: string
|
||||
assistantId: string
|
||||
expectedGen: number
|
||||
initialBatch?: StreamBatchResponse | null
|
||||
afterCursor?: string
|
||||
}) => Promise<{ error: boolean; aborted: boolean }>
|
||||
>(async () => ({ error: false, aborted: true }))
|
||||
const retryReconnectRef = useRef<
|
||||
(opts: { streamId: string; assistantId: string; gen: number }) => Promise<boolean>
|
||||
>(async () => false)
|
||||
@@ -617,7 +626,7 @@ export function useChat(
|
||||
|
||||
const reconnectResult =
|
||||
snapshotEvents.length > 0
|
||||
? await attachToExistingStream({
|
||||
? await attachToExistingStreamRef.current({
|
||||
streamId: activeStreamId,
|
||||
assistantId,
|
||||
expectedGen: gen,
|
||||
@@ -1613,6 +1622,7 @@ export function useChat(
|
||||
},
|
||||
[fetchStreamBatch]
|
||||
)
|
||||
attachToExistingStreamRef.current = attachToExistingStream
|
||||
|
||||
const resumeOrFinalize = useCallback(
|
||||
async (opts: {
|
||||
|
||||
@@ -282,6 +282,12 @@ async function runCheckpointLoop(
|
||||
)
|
||||
}
|
||||
|
||||
if (isAborted(options, context)) {
|
||||
cancelPendingTools(context)
|
||||
context.awaitingAsyncContinuation = undefined
|
||||
break
|
||||
}
|
||||
|
||||
const results: Array<{
|
||||
callId: string
|
||||
name: string
|
||||
@@ -289,6 +295,11 @@ async function runCheckpointLoop(
|
||||
success: boolean
|
||||
}> = []
|
||||
for (const toolCallId of continuation.pendingToolCallIds) {
|
||||
if (isAborted(options, context)) {
|
||||
cancelPendingTools(context)
|
||||
context.awaitingAsyncContinuation = undefined
|
||||
break
|
||||
}
|
||||
const tool = context.toolCalls.get(toolCallId)
|
||||
if (!tool || (!tool.result && !tool.error)) {
|
||||
logger.error('Missing tool result for pending tool call', {
|
||||
@@ -309,6 +320,12 @@ async function runCheckpointLoop(
|
||||
})
|
||||
}
|
||||
|
||||
if (isAborted(options, context)) {
|
||||
cancelPendingTools(context)
|
||||
context.awaitingAsyncContinuation = undefined
|
||||
break
|
||||
}
|
||||
|
||||
logger.info('Resuming with tool results', {
|
||||
checkpointId: continuation.checkpointId,
|
||||
runId: continuation.runId,
|
||||
@@ -324,6 +341,13 @@ async function runCheckpointLoop(
|
||||
checkpointId: continuation.checkpointId,
|
||||
results,
|
||||
}
|
||||
|
||||
if (isAborted(options, context)) {
|
||||
cancelPendingTools(context)
|
||||
context.awaitingAsyncContinuation = undefined
|
||||
break
|
||||
}
|
||||
|
||||
logger.info('Prepared resume request payload', {
|
||||
route,
|
||||
streamId: context.messageId,
|
||||
|
||||
Reference in New Issue
Block a user