@@ -14,13 +14,14 @@ import {
1414 unsealClientToolContext ,
1515} from '@/lib/mothership/request/tools/client-completion-seal.server'
1616import { inspectToolResultForCopilot } from '@/lib/mothership/request/tools/resolved-secret-result'
17+ import { presentWorkflowLogs } from '@/lib/mothership/tools/workflow-output'
1718import {
18- type AsyncWorkflowDeploymentError ,
1919 createStructuralWorkflowToolCompletionData ,
20- getAsyncWorkflowDeploymentError ,
2120 getWorkflowToolCompletionExecutionId ,
2221 getWorkflowToolCompletionMessage ,
2322 getWorkflowToolConfirmationStatus ,
23+ getWorkflowToolLaunchError ,
24+ type WorkflowToolLaunchError ,
2425} from '@/lib/mothership/tools/workflow-tools'
2526import { getTrustedWorkflowToolExecution } from '@/lib/workflows/executor/execution-state'
2627import type { ResolvedSecretTraceRegistry } from '@/executor/utils/resolved-secret-trace-registry'
@@ -211,6 +212,7 @@ export async function waitForClientToolCompletion({
211212}
212213
213214interface WaitForWorkflowToolCompletionOptions {
215+ select ?: string [ ]
214216 toolCallId : string
215217 workflowId ?: string
216218 timeoutMs : number
@@ -222,17 +224,12 @@ function structuralWorkflowCompletion(
222224 status : AsyncTerminalCompletionSnapshot [ 'status' ] ,
223225 workflowId ?: string ,
224226 executionId ?: string ,
225- deploymentError ?: AsyncWorkflowDeploymentError
227+ launchError ?: WorkflowToolLaunchError
226228) : AsyncTerminalCompletionSnapshot {
227229 return {
228230 status,
229- message : deploymentError ?. message ?? getWorkflowToolCompletionMessage ( status ) ,
230- data : createStructuralWorkflowToolCompletionData (
231- status ,
232- workflowId ,
233- executionId ,
234- deploymentError
235- ) ,
231+ message : launchError ?. message ?? getWorkflowToolCompletionMessage ( status ) ,
232+ data : createStructuralWorkflowToolCompletionData ( status , workflowId , executionId , launchError ) ,
236233 }
237234}
238235
@@ -241,6 +238,7 @@ function structuralWorkflowCompletion(
241238 * The browser confirmation is only a wakeup and structural identity carrier.
242239 */
243240export async function waitForWorkflowToolCompletion ( {
241+ select,
244242 toolCallId,
245243 workflowId,
246244 timeoutMs,
@@ -260,7 +258,7 @@ export async function waitForWorkflowToolCompletion({
260258 }
261259
262260 const executionId = getWorkflowToolCompletionExecutionId ( completion . data )
263- const deploymentError = getAsyncWorkflowDeploymentError ( completion . data )
261+ const launchError = getWorkflowToolLaunchError ( completion . data )
264262 if ( completion . status === ASYNC_TOOL_CONFIRMATION_STATUS . background ) {
265263 toolRegistry ?. markIncomplete ( 'client-tool-completion-deferred' )
266264 return structuralWorkflowCompletion ( completion . status , workflowId , executionId )
@@ -271,12 +269,7 @@ export async function waitForWorkflowToolCompletion({
271269 completion . status === MothershipStreamV1ToolOutcome . success
272270 ? MothershipStreamV1ToolOutcome . error
273271 : completion . status
274- return structuralWorkflowCompletion (
275- structuralStatus ,
276- workflowId ,
277- executionId ,
278- deploymentError
279- )
272+ return structuralWorkflowCompletion ( structuralStatus , workflowId , executionId , launchError )
280273 }
281274
282275 try {
@@ -381,8 +374,10 @@ export async function waitForWorkflowToolCompletion({
381374 )
382375 const projected = projection . result
383376 const projectedData = isPlainRecord ( projected . output ) ? projected . output : { }
377+ const { logs, ...projectedFields } = projectedData
384378 const data = {
385- ...projectedData ,
379+ ...projectedFields ,
380+ ...( Object . hasOwn ( projectedData , 'logs' ) ? presentWorkflowLogs ( logs , select ) : { } ) ,
386381 ...createStructuralWorkflowToolCompletionData ( status , workflowId , executionId ) ,
387382 }
388383 const message =
0 commit comments