|
1 | 1 | import * as NodeURL from "node:url"; |
| 2 | +import { toolOutputImages } from "@t3tools/shared/toolOutput"; |
2 | 3 | import * as NodeCrypto from "@effect/platform-node/NodeCrypto"; |
3 | 4 | import * as NodeServices from "@effect/platform-node/NodeServices"; |
4 | 5 | import { assert, it } from "@effect/vitest"; |
@@ -2715,48 +2716,67 @@ it.layer(McpProviderSessions.layer)("OpenCode2 adapter", (it) => { |
2715 | 2716 | }).pipe(Effect.scoped), |
2716 | 2717 | ); |
2717 | 2718 |
|
2718 | | - it.effect("keeps thread-scoped T3 waits as dynamic tools through their lifecycle", () => |
2719 | | - Effect.gen(function* () { |
2720 | | - const tool = { sessionID: SESSION, assistantMessageID: "msg_assistant", id: "call-wait" }; |
2721 | | - const name = "t3-code-web_delegate_task"; |
2722 | | - const input = { task: "Review", mode: "wait" }; |
2723 | | - const { runtime, thread } = yield* resumed([ |
2724 | | - out("session.prompt", { sessionID: SESSION, text: "<any>" }), |
2725 | | - promptAccepted, |
2726 | | - event("session.tool.input.started", { ...tool, name }), |
2727 | | - event("session.tool.called", { ...tool, name, input, executed: true }), |
2728 | | - event("session.tool.success", { |
2729 | | - ...tool, |
2730 | | - content: [{ type: "text", text: "Reviewed" }], |
2731 | | - metadata: {}, |
2732 | | - executed: true, |
2733 | | - }), |
2734 | | - event("session.execution.succeeded", { sessionID: SESSION }), |
2735 | | - ]); |
2736 | | - const events = yield* runtime.events.pipe( |
2737 | | - Stream.takeUntil((event) => event.type === "turn.terminal"), |
2738 | | - Stream.runCollect, |
2739 | | - Effect.forkScoped, |
2740 | | - ); |
2741 | | - yield* runtime.startTurn(turnInput(thread)); |
2742 | | - const items = (yield* Fiber.join(events)).flatMap((event) => |
2743 | | - event.type === "turn_item.updated" && |
2744 | | - event.turnItem.nativeItemRef?.nativeId?.endsWith(tool.id) |
2745 | | - ? [event.turnItem] |
2746 | | - : [], |
2747 | | - ); |
2748 | | - assert.deepEqual( |
2749 | | - items.map((item) => item.type), |
2750 | | - ["dynamic_tool", "dynamic_tool", "dynamic_tool"], |
2751 | | - ); |
2752 | | - assert.deepEqual( |
2753 | | - items.map((item) => item.status), |
2754 | | - ["running", "running", "completed"], |
2755 | | - ); |
2756 | | - const last = items.at(-1); |
2757 | | - assert.equal(last?.type === "dynamic_tool" ? last.toolName : null, name); |
2758 | | - assert.deepEqual(last?.type === "dynamic_tool" ? last.input : null, input); |
2759 | | - }).pipe(Effect.scoped), |
| 2719 | + it.effect.each(["delegate_task", "html_preview", "mcp__acme__edit_document"])( |
| 2720 | + "keeps MCP %s as a dynamic tool through its lifecycle", |
| 2721 | + (toolName) => |
| 2722 | + Effect.gen(function* () { |
| 2723 | + const tool = { sessionID: SESSION, assistantMessageID: "msg_assistant", id: "call-wait" }; |
| 2724 | + const name = toolName.startsWith("mcp__") ? toolName : `t3-code-web_${toolName}`; |
| 2725 | + const input = |
| 2726 | + toolName !== "delegate_task" |
| 2727 | + ? { html: "<p>Preview</p>" } |
| 2728 | + : { task: "Review", mode: "wait" }; |
| 2729 | + const { runtime, thread } = yield* resumed([ |
| 2730 | + out("session.prompt", { sessionID: SESSION, text: "<any>" }), |
| 2731 | + promptAccepted, |
| 2732 | + event("session.tool.input.started", { ...tool, name }), |
| 2733 | + event("session.tool.called", { ...tool, name, input, executed: true }), |
| 2734 | + event( |
| 2735 | + "session.tool.success", |
| 2736 | + { |
| 2737 | + ...tool, |
| 2738 | + content: [ |
| 2739 | + { type: "text", text: "Reviewed" }, |
| 2740 | + ...(toolName !== "delegate_task" |
| 2741 | + ? [{ type: "file", uri: "data:image/png;base64,iVBORw0KGgo=", mime: "image/png" }] |
| 2742 | + : []), |
| 2743 | + ], |
| 2744 | + metadata: {}, |
| 2745 | + executed: true, |
| 2746 | + }, |
| 2747 | + undefined, |
| 2748 | + 2, |
| 2749 | + ), |
| 2750 | + event("session.execution.succeeded", { sessionID: SESSION }), |
| 2751 | + ]); |
| 2752 | + const events = yield* runtime.events.pipe( |
| 2753 | + Stream.takeUntil((event) => event.type === "turn.terminal"), |
| 2754 | + Stream.runCollect, |
| 2755 | + Effect.forkScoped, |
| 2756 | + ); |
| 2757 | + yield* runtime.startTurn(turnInput(thread)); |
| 2758 | + const items = (yield* Fiber.join(events)).flatMap((event) => |
| 2759 | + event.type === "turn_item.updated" && |
| 2760 | + event.turnItem.nativeItemRef?.nativeId?.endsWith(tool.id) |
| 2761 | + ? [event.turnItem] |
| 2762 | + : [], |
| 2763 | + ); |
| 2764 | + assert.deepEqual( |
| 2765 | + items.map((item) => item.type), |
| 2766 | + ["dynamic_tool", "dynamic_tool", "dynamic_tool"], |
| 2767 | + ); |
| 2768 | + assert.deepEqual( |
| 2769 | + items.map((item) => item.status), |
| 2770 | + ["running", "running", "completed"], |
| 2771 | + ); |
| 2772 | + const last = items.at(-1); |
| 2773 | + assert.equal(last?.type === "dynamic_tool" ? last.toolName : null, name); |
| 2774 | + assert.deepEqual(last?.type === "dynamic_tool" ? last.input : null, input); |
| 2775 | + assert.deepEqual( |
| 2776 | + toolOutputImages(last?.type === "dynamic_tool" ? last.output : null), |
| 2777 | + toolName !== "delegate_task" ? [{ mimeType: "image/png", data: "iVBORw0KGgo=" }] : [], |
| 2778 | + ); |
| 2779 | + }).pipe(Effect.scoped), |
2760 | 2780 | ); |
2761 | 2781 |
|
2762 | 2782 | it.effect("stores a shell command that exits non-zero as failed", () => |
|
0 commit comments