fix(session): finalize interrupted assistant messages (#27254)
This commit is contained in:
@@ -1755,12 +1755,25 @@ NOTE: At any point in time through this workflow you should feel free to ask the
|
||||
sessionID,
|
||||
}
|
||||
yield* sessions.updateMessage(msg)
|
||||
const handle = yield* processor.create({
|
||||
assistantMessage: msg,
|
||||
sessionID,
|
||||
model,
|
||||
|
||||
const finalizeInterruptedAssistant = Effect.gen(function* () {
|
||||
if (msg.time.completed) return
|
||||
msg.error ??= MessageV2.fromError(new DOMException("Aborted", "AbortError"), {
|
||||
providerID: msg.providerID,
|
||||
aborted: true,
|
||||
})
|
||||
msg.time.completed = Date.now()
|
||||
yield* sessions.updateMessage(msg)
|
||||
})
|
||||
|
||||
const handle = yield* processor
|
||||
.create({
|
||||
assistantMessage: msg,
|
||||
sessionID,
|
||||
model,
|
||||
})
|
||||
.pipe(Effect.onInterrupt(() => finalizeInterruptedAssistant))
|
||||
|
||||
const outcome: "break" | "continue" = yield* Effect.gen(function* () {
|
||||
const lastUserMsg = msgs.findLast((m) => m.info.role === "user")
|
||||
const bypassAgentCheck = lastUserMsg?.parts.some((p) => p.type === "agent") ?? false
|
||||
@@ -1859,7 +1872,10 @@ NOTE: At any point in time through this workflow you should feel free to ask the
|
||||
})
|
||||
}
|
||||
return "continue" as const
|
||||
}).pipe(Effect.ensuring(instruction.clear(handle.message.id)))
|
||||
}).pipe(
|
||||
Effect.ensuring(instruction.clear(handle.message.id)),
|
||||
Effect.onInterrupt(() => finalizeInterruptedAssistant),
|
||||
)
|
||||
if (outcome === "break") break
|
||||
continue
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user