feat(mcp): resume queued calculation jobs

This commit is contained in:
2026-10-29 18:25:22 +08:00
parent 52681a8451
commit 799b99f310
20 changed files with 348 additions and 42 deletions
+6 -4
View File
@@ -77,7 +77,7 @@ type StreamPromptOptions = {
onInboxEvent?: (type: string, data: { inboxID?: string; delivery?: "steer" | "queue" }) => void;
waitForUserInput?: () => Promise<boolean>;
beforePrompt?: () => Promise<void>;
beforeIdle?: () => Promise<boolean>;
beforeIdle?: () => Promise<boolean | string>;
beforeRichAnswerClose?: () => Promise<boolean>;
runtime: OpencodeRuntimeAdapter;
sessionId: string;
@@ -904,7 +904,7 @@ export const streamPromptResponse = async ({
id: part.id,
phase: "tool",
status: normalizeToolStatus(part.state.status),
title: getToolProgressTitle(part.tool, part.state.status),
title: getToolProgressTitle(part.tool, part.state.status, part.state.status === "completed" ? part.state.output : undefined),
tool: { name: part.tool, call_id: part.callID, input: sanitizeToolProgressInput(toolParams) },
detail: buildToolProgressDetail(
part.tool,
@@ -912,6 +912,7 @@ export const streamPromptResponse = async ({
toolParams,
reason,
part.state.status === "error" ? part.state.error : undefined,
part.state.status === "completed" ? part.state.output : undefined,
),
});
if (
@@ -1022,12 +1023,13 @@ export const streamPromptResponse = async ({
});
continue;
}
if (beforeIdle && !await beforeIdle()) {
const idleDecision = beforeIdle ? await beforeIdle() : true;
if (idleDecision === false || typeof idleDecision === "string") {
// A durable message won the race with completion. Continue within
// the same managed session/lease, never create another task run.
finalAnswer = undefined;
sawResponseActivity = false;
await runtime.prompt(sessionId, "请处理收信箱中新到达的调查协作消息,按需回复,然后完成本轮工作。", toRuntimeModel(model));
await runtime.prompt(sessionId, typeof idleDecision === "string" ? idleDecision : "请处理收信箱中新到达的调查协作消息,按需回复,然后完成本轮工作。", toRuntimeModel(model));
continue;
}
if (waitForUserInput && await waitForUserInput()) {