The best way to control Claude Code, Codex and more from any computer or phone

main
ts 40 lines 1.91 KB
Raw
1 import { OrchestratorMcpFailure } from "@t3tools/contracts";
2 import { SEND_TO_USER_MAX_LENGTH, SEND_TO_USER_TOOL_NAME } from "@t3tools/shared/toolOutput";
3 import * as Schema from "effect/Schema";
4 import { McpSchema, Tool, Toolkit } from "effect/ai";
5
6 import * as ThreadManagementService from "../../../orchestration-v2/ThreadManagementService.ts";
7 import * as McpInvocationContext from "../../McpInvocationContext.ts";
8
9 // Claude 5.1+ returns text written before a tool call only as a short summary; tool input arrives intact.
10 // It affects only the caller's thread, so read-only sandboxes and plan mode may use it.
11 const SendToUserTool = Tool.make(SEND_TO_USER_TOOL_NAME, {
12 description:
13 "Show the user a Markdown message in this thread, exactly as written, before your turn ends. Use it for content the user must read in full mid-turn, such as a draft, a code block, or what a question you are about to ask refers to. Don't repeat it in your reply.",
14 parameters: Schema.Struct({
15 message: Schema.String.check(
16 Schema.isMinLength(1),
17 Schema.isMaxLength(SEND_TO_USER_MAX_LENGTH),
18 ).annotate({ description: "Markdown, shown verbatim." }),
19 }),
20 success: Schema.Struct({
21 sentMessage: Schema.String,
22 message: Schema.String,
23 }),
24 failure: OrchestratorMcpFailure,
25 failureMode: "return",
26 dependencies: [
27 McpInvocationContext.McpInvocationContext,
28 ThreadManagementService.ThreadManagementService,
29 ],
30 })
31 .annotate(Tool.Title, "Send a message to the user")
32 .annotate(Tool.Readonly, true)
33 .annotate(Tool.Destructive, false)
34 .annotate(Tool.Idempotent, false)
35 .annotate(Tool.OpenWorld, false)
36 .annotate(McpSchema.EnabledWhen, McpInvocationContext.hiddenFromOutsideClients)
37 // Claude Code defers MCP tools behind ToolSearch; Anthropic says to declare this from the first request.
38 .annotate(Tool.Meta, { "anthropic/alwaysLoad": true });
39
40 export const MessageToolkit = Toolkit.make(SendToUserTool);