The best way to control Claude Code, Codex and more from any computer or phone
Mirrored from https://github.com/Camo67/t3code.git
Synced Nov 21, 04:45 UTC
| 1 | import { |
| 2 | clampedPositiveInt, |
| 3 | NonNegativeInt, |
| 4 | OrchestratorMcpFailure, |
| 5 | PreviewAutomationError, |
| 6 | PreviewListResult, |
| 7 | PreviewTabId, |
| 8 | } from "@t3tools/contracts"; |
| 9 | import * as Schema from "effect/Schema"; |
| 10 | import { McpSchema, Tool, Toolkit } from "effect/ai"; |
| 11 | import * as ThreadManagementService from "../../../orchestration-v2/ThreadManagementService.ts"; |
| 12 | import * as PreviewManager from "../../../preview/Manager.ts"; |
| 13 | import * as PreviewAutomationBroker from "../../PreviewAutomationBroker.ts"; |
| 14 | import * as McpInvocationContext from "../../McpInvocationContext.ts"; |
| 15 | |
| 16 | const shared = { |
| 17 | failure: Schema.Union([PreviewAutomationError, OrchestratorMcpFailure]), |
| 18 | failureMode: "return" as const, |
| 19 | dependencies: [ |
| 20 | McpInvocationContext.McpInvocationContext, |
| 21 | ThreadManagementService.ThreadManagementService, |
| 22 | PreviewManager.PreviewManager, |
| 23 | PreviewAutomationBroker.PreviewAutomationBroker, |
| 24 | ], |
| 25 | }; |
| 26 | const PreviewListTool = Tool.make("t3_preview_list", { |
| 27 | ...shared, |
| 28 | description: |
| 29 | "List this thread's preview tabs. Only `runtime:'server'` entries can be automated here. Others are in the user's local desktop app. Never pass a non-server `tabId` to a `preview_*` tool. Tell the user that tab is on their local desktop and this environment cannot reach it.", |
| 30 | parameters: Schema.Struct({ |
| 31 | cursor: Schema.optional(NonNegativeInt), |
| 32 | limit: Schema.optional(clampedPositiveInt(50)), |
| 33 | }), |
| 34 | success: Schema.Struct({ |
| 35 | ...PreviewListResult.fields, |
| 36 | nextCursor: Schema.NullOr(NonNegativeInt), |
| 37 | }), |
| 38 | }) |
| 39 | .annotate(Tool.Readonly, true) |
| 40 | .annotate(Tool.Destructive, false) |
| 41 | .annotate(McpSchema.EnabledWhen, McpInvocationContext.hiddenFromOutsideClients); |
| 42 | const PreviewCloseTool = Tool.make("t3_preview_close", { |
| 43 | ...shared, |
| 44 | description: |
| 45 | "Close one preview tab this thread owns. Use it on a tab you opened for your own check when you finish.", |
| 46 | parameters: Schema.Struct({ tabId: PreviewTabId }), |
| 47 | success: Schema.Struct({}), |
| 48 | }) |
| 49 | .annotate(Tool.Destructive, true) |
| 50 | .annotate(McpSchema.EnabledWhen, McpInvocationContext.hiddenFromOutsideClients); |
| 51 | export const PreviewControlsToolkit = Toolkit.make(PreviewListTool, PreviewCloseTool); |