11import { MessageId , ThreadId , OrchestratorMcpFailure , ProjectId } from "@t3tools/contracts" ;
22import * as Effect from "effect/Effect" ;
33import * as Option from "effect/Option" ;
4- import * as Launch from "../../../orchestration-v2/ThreadLaunchService .ts" ;
4+ import * as ThreadMessageIntake from "../../../orchestration-v2/ThreadMessageIntake .ts" ;
55import * as Claims from "../../../orchestration-v2/AttachmentClaims.ts" ;
66import * as Project from "../../../project/ProjectService.ts" ;
77import * 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 {
0 commit comments