Skip to content
Source
Sign inSign up
pingdotgg/t3code
Open History to see the last commit

tools.ts

122 lines5.4 KB

1import { McpAttachmentInput } from "../attachment/input.ts";
2import {
3 NonNegativeInt,
4 ModelSelection,
5 TrimmedNonEmptyString,
6 ThreadId,
7 RunId,
8 OrchestrationV2RunStatus,
9 OrchestrationV2ThreadLaunchWorkspaceStrategy,
10 RuntimeMode,
11 ProviderInteractionMode,
12 Project,
13 ProjectCreatePayload,
14 ProjectUpdatePayload,
15 ProjectId,
16 OrchestratorMcpFailure,
17 SourceControlCloneRepositoryInput,
18 SourceControlCloneRepositoryResult,
19} from "@t3tools/contracts";
20import * as FileSystem from "effect/FileSystem";
21import { ServerConfig } from "../../../config.ts";
22import { ThreadLaunchService } from "../../../orchestration-v2/ThreadLaunchService.ts";
23import * as Crypto from "effect/Crypto";
24import * as Schema from "effect/Schema";
25import { Tool, Toolkit } from "effect/unstable/ai";
26import { ProjectService } from "../../../project/ProjectService.ts";
27import { ThreadManagementService } from "../../../orchestration-v2/ThreadManagementService.ts";
28import { SourceControlRepositoryService } from "../../../sourceControl/SourceControlRepositoryService.ts";
29import { McpInvocationContext } from "../../McpInvocationContext.ts";
30​
31const shared = {
32 success: Project,
33 failure: OrchestratorMcpFailure,
34 failureMode: "return" as const,
35 dependencies: [McpInvocationContext, ThreadManagementService, ProjectService, Crypto.Crypto],
36};
37const ProjectListTool = Tool.make("t3_project_list", {
38 ...shared,
39 description:
40 "List registered projects in this environment. Pages use the current project snapshot and may shift between calls.",
41 parameters: Schema.Struct({
42 cursor: Schema.optional(NonNegativeInt),
43 limit: Schema.optional(Schema.Int.check(Schema.isBetween({ minimum: 1, maximum: 100 }))),
44 }),
45 success: Schema.Struct({
46 projects: Schema.Array(Project),
47 nextCursor: Schema.NullOr(NonNegativeInt),
48 }),
49})
50 .annotate(Tool.Readonly, true)
51 .annotate(Tool.Destructive, false);
52const ProjectReadTool = Tool.make("t3_project_read", {
53 ...shared,
54 description:
55 "Read a registered project in this environment, including its workspace and saved scripts.",
56 parameters: Schema.Struct({ projectId: ProjectId }),
57})
58 .annotate(Tool.Readonly, true)
59 .annotate(Tool.Destructive, false);
60const ProjectCreateTool = Tool.make("t3_project_create", {
61 ...shared,
62 description:
63 "Register a project directory through the existing project service. Set createWorkspaceRootIfMissing to create a directory. Each call creates a new request; an existing registered workspace is rejected. Clone separately with t3_project_clone when needed.",
64 parameters: ProjectCreatePayload,
65}).annotate(Tool.Destructive, true);
66const ProjectUpdateTool = Tool.make("t3_project_update", {
67 ...shared,
68 description:
69 "Update a registered project's settings. Omitted fields are preserved. Uses the same project service as the app.",
70 parameters: Schema.Struct({ projectId: ProjectId, ...ProjectUpdatePayload.fields }),
71}).annotate(Tool.Destructive, true);
72const ProjectDeleteTool = Tool.make("t3_project_delete", {
73 ...shared,
74 description:
75 "Delete a project using the existing project deletion lifecycle. Nonempty projects require force=true. This does not delete the repository directory or promise a deleted-thread count.",
76 parameters: Schema.Struct({ projectId: ProjectId, force: Schema.optionalKey(Schema.Boolean) }),
77}).annotate(Tool.Destructive, true);
78const ProjectCloneTool = Tool.make("t3_project_clone", {
79 ...shared,
80 description:
81 "Clone a repository using the app's source-control service. This only clones; register the returned cwd with t3_project_create. An existing destination is not adopted or removed on failure.",
82 parameters: SourceControlCloneRepositoryInput,
83 success: SourceControlCloneRepositoryResult,
84 dependencies: [...shared.dependencies, SourceControlRepositoryService],
85})
86 .annotate(Tool.Destructive, true)
87 .annotate(Tool.OpenWorld, true);
88const ThreadLaunchTool = Tool.make("t3_thread_launch", {
89 ...shared,
90 description:
91 "Launch a thread in a registered project using the same launch service as the app. Omit projectId/modelSelection/modes to inherit from the caller. Supports root, existing_worktree, or a new worktree. Each call is a new launch, with no retry key. Preparation can continue after acceptance; failures may leave a created thread. Attachments must be pending uploads. Requires a full-access/default caller.",
92 parameters: Schema.Struct({
93 projectId: Schema.optional(ProjectId),
94 title: TrimmedNonEmptyString,
95 modelSelection: Schema.optional(ModelSelection),
96 runtimeMode: Schema.optional(RuntimeMode),
97 interactionMode: Schema.optional(ProviderInteractionMode),
98 workspaceStrategy: Schema.optional(OrchestrationV2ThreadLaunchWorkspaceStrategy),
99 message: Schema.optional(Schema.String.check(Schema.isMaxLength(120000))),
100 attachments: Schema.optional(Schema.Array(McpAttachmentInput).check(Schema.isMaxLength(8))),
101 }),
102 success: Schema.Struct({
103 threadId: ThreadId,
104 projectId: ProjectId,
105 modelSelection: ModelSelection,
106 runId: Schema.NullOr(RunId),
107 status: Schema.NullOr(OrchestrationV2RunStatus),
108 }),
109 dependencies: [...shared.dependencies, ThreadLaunchService, FileSystem.FileSystem, ServerConfig],
110})
111 .annotate(Tool.Destructive, true)
112 .annotate(Tool.OpenWorld, true);
113​
114export const ProjectToolkit = Toolkit.make(
115 ThreadLaunchTool,
116 ProjectListTool,
117 ProjectReadTool,
118 ProjectCreateTool,
119 ProjectUpdateTool,
120 ProjectDeleteTool,
121 ProjectCloneTool,
122);