Skip to content

Commit 3492b15

Browse files
refactor(mcp): use shared attachment launch intake
1 parent f3bb499 commit 3492b15

2 files changed

Lines changed: 27 additions & 31 deletions

File tree

‎apps/server/src/mcp/toolkits/project/handlers.ts‎

Lines changed: 25 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { MessageId, ThreadId, OrchestratorMcpFailure, ProjectId } from "@t3tools/contracts";
22
import * as Effect from "effect/Effect";
33
import * as Option from "effect/Option";
4-
import * as Launch from "../../../orchestration-v2/ThreadLaunchService.ts";
4+
import * as ThreadMessageIntake from "../../../orchestration-v2/ThreadMessageIntake.ts";
55
import * as Claims from "../../../orchestration-v2/AttachmentClaims.ts";
66
import * as Project from "../../../project/ProjectService.ts";
77
import * as Repositories from "../../../sourceControl/SourceControlRepositoryService.ts";
@@ -45,7 +45,6 @@ export const ProjectHandlersLive = ProjectToolkit.toLayer({
4545
code: "capability_denied",
4646
message: "Project launches require a full-access/default calling thread.",
4747
});
48-
const launch = yield* Launch.ThreadLaunchService;
4948
const commandId = yield* newCommandId();
5049
const threadId = ThreadId.make(commandId);
5150
const messageId = MessageId.make(commandId);
@@ -55,38 +54,33 @@ export const ProjectHandlersLive = ProjectToolkit.toLayer({
5554
code: "invalid_request",
5655
message: "A new thread accepts only pending attachment uploads.",
5756
});
58-
const claimed = yield* Claims.claimPendingAttachments({ threadId, attachments }).pipe(
59-
Effect.mapError(
60-
(error) =>
61-
new OrchestratorMcpFailure({
62-
code: "orchestration_error",
63-
message: error.message,
57+
const result = yield* ThreadMessageIntake.launchThread({
58+
commandId,
59+
threadId,
60+
projectId: input.projectId ?? caller.projectId,
61+
title: input.title,
62+
modelSelection: input.modelSelection ?? caller.modelSelection,
63+
runtimeMode: input.runtimeMode ?? caller.runtimeMode,
64+
interactionMode: input.interactionMode ?? caller.interactionMode,
65+
workspaceStrategy: input.workspaceStrategy ?? { type: "root" },
66+
...(input.message === undefined && attachments.length === 0
67+
? {}
68+
: {
69+
initialMessage: {
70+
messageId,
71+
text: input.message ?? "",
72+
attachments,
73+
},
6474
}),
75+
createdBy: "agent",
76+
creationSource: "mcp",
77+
}).pipe(
78+
Effect.mapError((error) =>
79+
error._tag === "AttachmentClaimError"
80+
? new OrchestratorMcpFailure({ code: "orchestration_error", message: error.message })
81+
: unavailable(),
6582
),
6683
);
67-
const result = yield* launch
68-
.launch({
69-
commandId,
70-
threadId,
71-
projectId: input.projectId ?? caller.projectId,
72-
title: input.title,
73-
modelSelection: input.modelSelection ?? caller.modelSelection,
74-
runtimeMode: input.runtimeMode ?? caller.runtimeMode,
75-
interactionMode: input.interactionMode ?? caller.interactionMode,
76-
workspaceStrategy: input.workspaceStrategy ?? { type: "root" },
77-
...(input.message === undefined && attachments.length === 0
78-
? {}
79-
: {
80-
initialMessage: {
81-
messageId,
82-
text: input.message ?? "",
83-
attachments: claimed.attachments,
84-
},
85-
}),
86-
createdBy: "agent",
87-
creationSource: "mcp",
88-
})
89-
.pipe(Effect.mapError(unavailable));
9084
const thread = result.projection.thread;
9185
const run = result.projection.runs.find((run) => run.userMessageId === messageId);
9286
return {

‎apps/server/src/mcp/toolkits/project/tools.ts‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
import {
22
NonNegativeInt,
3+
ModelSelection,
4+
TrimmedNonEmptyString,
35
ThreadId,
46
RunId,
57
OrchestrationV2RunStatus,

0 commit comments

Comments
 (0)