@@ -2,6 +2,7 @@ import { type ChatAttachment, MessageId, OrchestratorMcpFailure } from "@t3tools
22import * as Effect from "effect/Effect" ;
33import * as Upload from "../../../assets/AttachmentUpload.ts" ;
44import * as Claims from "../../../orchestration-v2/AttachmentClaims.ts" ;
5+ import * as ThreadMessageIntake from "../../../orchestration-v2/ThreadMessageIntake.ts" ;
56import {
67 newCommandId ,
78 readMutationCaller ,
@@ -46,7 +47,7 @@ export const AttachmentHandlersLive = AttachmentToolkit.toLayer({
4647 } ) ,
4748 t3_thread_send_attachments : ( input ) =>
4849 Effect . gen ( function * ( ) {
49- const { caller, threads , projection } = yield * readWritableThread ( input . threadId ) ;
50+ const { caller, projection } = yield * readWritableThread ( input . threadId ) ;
5051 if ( projection . thread . archivedAt !== null )
5152 return yield * new OrchestratorMcpFailure ( {
5253 code : "invalid_request" ,
@@ -58,32 +59,23 @@ export const AttachmentHandlersLive = AttachmentToolkit.toLayer({
5859 ) ;
5960 const commandId = yield * newCommandId ( ) ;
6061 const messageId = MessageId . make ( commandId ) ;
61- const claimed = yield * Claims . claimPendingAttachments ( {
62+ const result = yield * ThreadMessageIntake . sendToThread ( {
63+ projectId : caller . projectId ,
6264 threadId : projection . thread . id ,
65+ commandId,
66+ messageId,
67+ text : input . message ?? "" ,
6368 attachments,
69+ mode : "auto" ,
70+ createdBy : "agent" ,
71+ creationSource : "mcp" ,
6472 } ) . pipe (
65- Effect . mapError (
66- ( error ) =>
67- new OrchestratorMcpFailure ( {
68- code : "orchestration_error" ,
69- message : error . message ,
70- } ) ,
73+ Effect . mapError ( ( error ) =>
74+ error . _tag === "AttachmentClaimError"
75+ ? new OrchestratorMcpFailure ( { code : "orchestration_error" , message : error . message } )
76+ : unavailable ( ) ,
7177 ) ,
7278 ) ;
73- // Preserve claimed copies if dispatch may have committed before failing to return.
74- const result = yield * threads
75- . sendToThread ( {
76- projectId : caller . projectId ,
77- threadId : projection . thread . id ,
78- commandId,
79- messageId,
80- text : input . message ?? "" ,
81- attachments : claimed . attachments ,
82- mode : "auto" ,
83- createdBy : "agent" ,
84- creationSource : "mcp" ,
85- } )
86- . pipe ( Effect . mapError ( unavailable ) ) ;
8779 return {
8880 threadId : projection . thread . id ,
8981 messageId,
0 commit comments