@@ -84,7 +84,7 @@ describe('MothershipBlockHandler', () => {
8484 metadata : { id : BlockType . MOTHERSHIP , name : 'Mothership' } ,
8585 position : { x : 0 , y : 0 } ,
8686 config : { tool : BlockType . MOTHERSHIP , params : { } } ,
87- inputs : { prompt : 'string' } ,
87+ inputs : { prompt : 'string' , conversationId : 'string' } ,
8888 outputs : { } ,
8989 enabled : true ,
9090 } as SerializedBlock
@@ -122,6 +122,7 @@ describe('MothershipBlockHandler', () => {
122122 JSON . stringify ( {
123123 content : 'done' ,
124124 model : 'mothership' ,
125+ conversationId : 'chat-uuid' ,
125126 tokens : { total : 5 } ,
126127 toolCalls : [ ] ,
127128 } ) ,
@@ -137,6 +138,7 @@ describe('MothershipBlockHandler', () => {
137138 expect ( result ) . toEqual ( {
138139 content : 'done' ,
139140 model : 'mothership' ,
141+ conversationId : 'chat-uuid' ,
140142 tokens : { total : 5 } ,
141143 toolCalls : { list : [ ] , count : 0 } ,
142144 cost : undefined ,
@@ -161,6 +163,55 @@ describe('MothershipBlockHandler', () => {
161163 } )
162164 } )
163165
166+ it ( 'uses a provided conversation ID as the mothership chat ID' , async ( ) => {
167+ mockGenerateId . mockReturnValueOnce ( 'message-uuid' )
168+ mockGenerateId . mockReturnValueOnce ( 'request-uuid' )
169+
170+ fetchMock . mockResolvedValue (
171+ new Response (
172+ JSON . stringify ( {
173+ content : 'continued' ,
174+ model : 'mothership' ,
175+ conversationId : 'existing-chat-id' ,
176+ tokens : { } ,
177+ toolCalls : [ ] ,
178+ } ) ,
179+ {
180+ status : 200 ,
181+ headers : { 'Content-Type' : 'application/json' } ,
182+ }
183+ )
184+ )
185+
186+ const result = await handler . execute ( context , block , {
187+ prompt : 'Continue this thread' ,
188+ conversationId : ' existing-chat-id ' ,
189+ } )
190+
191+ expect ( result ) . toEqual ( {
192+ content : 'continued' ,
193+ model : 'mothership' ,
194+ conversationId : 'existing-chat-id' ,
195+ tokens : { } ,
196+ toolCalls : { list : [ ] , count : 0 } ,
197+ cost : undefined ,
198+ } )
199+
200+ const [ , options ] = fetchMock . mock . calls [ 0 ] as [ string , RequestInit ]
201+ const body = JSON . parse ( String ( options . body ) )
202+ expect ( body ) . toEqual ( {
203+ messages : [ { role : 'user' , content : 'Continue this thread' } ] ,
204+ workspaceId : 'workspace-1' ,
205+ userId : 'user-1' ,
206+ chatId : 'existing-chat-id' ,
207+ messageId : 'message-uuid' ,
208+ requestId : 'request-uuid' ,
209+ workflowId : 'workflow-1' ,
210+ executionId : 'execution-1' ,
211+ } )
212+ expect ( mockGenerateId ) . toHaveBeenCalledTimes ( 2 )
213+ } )
214+
164215 it ( 'propagates local aborts to the mothership request' , async ( ) => {
165216 const abortController = new AbortController ( )
166217 context . abortSignal = abortController . signal
0 commit comments