mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-10 01:13:29 +00:00
Gateway/Control UI: preserve partial output on abort (#15026)
* Gateway/Control UI: preserve partial output on abort * fix: finalize abort partial handling and tests (#15026) (thanks @advaitpaliwal) --------- Co-authored-by: Tyler Yust <TYTYYUST@YAHOO.COM>
This commit is contained in:
@@ -52,15 +52,23 @@ function broadcastChatAborted(
|
||||
runId: string;
|
||||
sessionKey: string;
|
||||
stopReason?: string;
|
||||
partialText?: string;
|
||||
},
|
||||
) {
|
||||
const { runId, sessionKey, stopReason } = params;
|
||||
const { runId, sessionKey, stopReason, partialText } = params;
|
||||
const payload = {
|
||||
runId,
|
||||
sessionKey,
|
||||
seq: (ops.agentRunSeq.get(runId) ?? 0) + 1,
|
||||
state: "aborted" as const,
|
||||
stopReason,
|
||||
message: partialText
|
||||
? {
|
||||
role: "assistant",
|
||||
content: [{ type: "text", text: partialText }],
|
||||
timestamp: Date.now(),
|
||||
}
|
||||
: undefined,
|
||||
};
|
||||
ops.broadcast("chat", payload);
|
||||
ops.nodeSendToSession(sessionKey, "chat", payload);
|
||||
@@ -83,13 +91,15 @@ export function abortChatRunById(
|
||||
return { aborted: false };
|
||||
}
|
||||
|
||||
const bufferedText = ops.chatRunBuffers.get(runId);
|
||||
const partialText = bufferedText && bufferedText.trim() ? bufferedText : undefined;
|
||||
ops.chatAbortedRuns.set(runId, Date.now());
|
||||
active.controller.abort();
|
||||
ops.chatAbortControllers.delete(runId);
|
||||
ops.chatRunBuffers.delete(runId);
|
||||
ops.chatDeltaSentAt.delete(runId);
|
||||
const removed = ops.removeChatRun(runId, runId, sessionKey);
|
||||
broadcastChatAborted(ops, { runId, sessionKey, stopReason });
|
||||
broadcastChatAborted(ops, { runId, sessionKey, stopReason, partialText });
|
||||
ops.agentRunSeq.delete(runId);
|
||||
if (removed?.clientRunId) {
|
||||
ops.agentRunSeq.delete(removed.clientRunId);
|
||||
|
||||
Reference in New Issue
Block a user