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
+20
View File
@@ -0,0 +1,20 @@
import { isDeepStrictEqual } from "node:util";
import { queryMcpToolId } from "../runtime/product-mcp-tools.js";
const record = (value: unknown): value is Record<string, unknown> => !!value && typeof value === "object" && !Array.isArray(value);
// Use only host-read native history. Ambiguous simultaneous identical calls fail
// closed rather than assigning a second submission to the first call's job.
export function resolveMatchingNativeCall(messages: unknown, toolName: string, args: Record<string, unknown>): string | null {
if (!Array.isArray(messages)) return null;
const ids = new Set<string>();
for (const message of messages) {
if (!record(message) || !Array.isArray(message.parts)) continue;
for (const part of message.parts) {
if (!record(part) || part.type !== "tool" || part.tool !== queryMcpToolId(toolName) || !record(part.state)) continue;
if (!["running", "pending"].includes(String(part.state.status)) || !isDeepStrictEqual(part.state.input, args)) continue;
if (typeof part.callID === "string" && part.callID.length > 0 && part.callID.length <= 256) ids.add(part.callID);
}
}
return ids.size === 1 ? [...ids][0]! : null;
}