The best way to control Claude Code, Codex and more from any computer or phone
| 1 | import { McpAttachmentInput } from "./input.ts"; |
| 2 | import { |
| 3 | AttachmentCreateUploadUrlInput, |
| 4 | AttachmentCreateUploadUrlResult, |
| 5 | AttachmentDeleteInput, |
| 6 | MessageId, |
| 7 | RunId, |
| 8 | ThreadId, |
| 9 | OrchestrationV2RunStatus, |
| 10 | OrchestratorMcpFailure, |
| 11 | } from "@t3tools/contracts"; |
| 12 | import * as SecureRandom from "effect/crypto/SecureRandom"; |
| 13 | import * as FileSystem from "effect/FileSystem"; |
| 14 | import * as Schema from "effect/Schema"; |
| 15 | import { Tool, Toolkit } from "effect/ai"; |
| 16 | import * as ServerSecretStore from "../../../auth/ServerSecretStore.ts"; |
| 17 | import * as ServerConfig from "../../../config.ts"; |
| 18 | import * as DocumentText from "../../../provider/DocumentText.ts"; |
| 19 | import * as ThreadManagementService from "../../../orchestration-v2/ThreadManagementService.ts"; |
| 20 | import * as McpInvocationContext from "../../McpInvocationContext.ts"; |
| 21 | |
| 22 | const shared = { |
| 23 | failure: OrchestratorMcpFailure, |
| 24 | failureMode: "return" as const, |
| 25 | dependencies: [ |
| 26 | McpInvocationContext.McpInvocationContext, |
| 27 | ThreadManagementService.ThreadManagementService, |
| 28 | ServerConfig.ServerConfig, |
| 29 | ServerSecretStore.ServerSecretStore, |
| 30 | FileSystem.FileSystem, |
| 31 | SecureRandom.SecureRandom, |
| 32 | ], |
| 33 | }; |
| 34 | const AttachmentUploadTool = Tool.make("t3_attachment_prepare_upload", { |
| 35 | ...shared, |
| 36 | description: |
| 37 | "Get an upload URL. POST the file's exact bytes to `uploadUrl` (else this server's `relativeUrl`), then send via `t3_thread_send_attachments` with the returned `attachmentId`.", |
| 38 | parameters: Schema.Struct({ upload: AttachmentCreateUploadUrlInput }), |
| 39 | success: Schema.Struct({ |
| 40 | ...AttachmentCreateUploadUrlResult.fields, |
| 41 | uploadUrl: Schema.optionalKey(Schema.String), |
| 42 | }), |
| 43 | }).annotate(Tool.Destructive, true); |
| 44 | const AttachmentDiscardTool = Tool.make("t3_attachment_discard", { |
| 45 | ...shared, |
| 46 | description: "Discard a pending upload (not a sent attachment).", |
| 47 | parameters: AttachmentDeleteInput, |
| 48 | success: Schema.Struct({}), |
| 49 | }).annotate(Tool.Destructive, true); |
| 50 | const AttachmentSendTool = Tool.make("t3_thread_send_attachments", { |
| 51 | ...shared, |
| 52 | dependencies: [...shared.dependencies, DocumentText.DocumentText], |
| 53 | description: |
| 54 | "Send uploaded attachments as a new message to a thread. No retry key. Target modes cannot exceed yours. Success does not mean the provider read them or finished.", |
| 55 | parameters: Schema.Struct({ |
| 56 | threadId: Schema.optional(ThreadId), |
| 57 | message: Schema.optional(Schema.String.check(Schema.isMaxLength(120000))), |
| 58 | attachments: Schema.Array(McpAttachmentInput).check( |
| 59 | Schema.isMinLength(1), |
| 60 | Schema.isMaxLength(8), |
| 61 | ), |
| 62 | }), |
| 63 | success: Schema.Struct({ |
| 64 | threadId: ThreadId, |
| 65 | messageId: MessageId, |
| 66 | runId: RunId, |
| 67 | status: OrchestrationV2RunStatus, |
| 68 | }), |
| 69 | }) |
| 70 | .annotate(Tool.Destructive, true) |
| 71 | .annotate(Tool.OpenWorld, true); |
| 72 | export const AttachmentToolkit = Toolkit.make( |
| 73 | AttachmentUploadTool, |
| 74 | AttachmentDiscardTool, |
| 75 | AttachmentSendTool, |
| 76 | ); |