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
+23
View File
@@ -45,6 +45,29 @@ describe("streamPromptResponse", () => {
expect(emitted.filter((event) => event === "done")).toHaveLength(1);
});
it("resumes the same investigation with host-provided calculation result guidance", async () => {
const prompts: string[] = [];
let idleChecks = 0;
const runtime = {
prompt: async (_sessionId: string, text: string) => { prompts.push(text); },
subscribeEvents: async () => createEventStream([1, 2].flatMap((round) => [
{ type: "message.part.updated", properties: { sessionID: "s", part: {
id: `calculation-text-${round}`, type: "text", text: `round ${round}`, sessionID: "s", messageID: `m-${round}`,
} } },
{ type: "session.idle", properties: { sessionID: "s" } },
])),
messages: async () => [],
} as unknown as OpencodeRuntimeAdapter;
const result = await streamPromptResponse({
runtime, sessionId: "s", clientSessionId: "client", message: "investigate", suppressAnswerUi: true,
beforeIdle: async () => ++idleChecks === 1 ? "Read get_calculation_result for job-1" : true,
write: () => {},
});
expect(result.failed).toBeFalse();
expect(prompts).toEqual(["investigate", "Read get_calculation_result for job-1"]);
expect(idleChecks).toBe(2);
});
it("keeps the first pending event when the V2 prompt acknowledgement arrives first", async () => {
const emitted: { event: string; data: Record<string, unknown> }[] = [];
const runtime = {