feat(mcp): resume queued calculation jobs
This commit is contained in:
@@ -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;
|
||||
}
|
||||
Reference in New Issue
Block a user