(input: {
rawCommand: string;
name: string;
runId: string;
status: string;
result: unknown;
run: WorkflowRunRecord | null;
})
| 90 | } |
| 91 | |
| 92 | export function buildWorkflowResultContextMessage(input: { |
| 93 | rawCommand: string; |
| 94 | name: string; |
| 95 | runId: string; |
| 96 | status: string; |
| 97 | result: unknown; |
| 98 | run: WorkflowRunRecord | null; |
| 99 | }): string { |
| 100 | assert( |
| 101 | input.rawCommand.trim().length > 0, |
| 102 | "buildWorkflowResultContextMessage: rawCommand required" |
| 103 | ); |
| 104 | assert(input.name.length > 0, "buildWorkflowResultContextMessage: workflow name required"); |
| 105 | assert(input.runId.length > 0, "buildWorkflowResultContextMessage: runId required"); |
| 106 | |
| 107 | const resultValue = getWorkflowResultValue(input.result, input.run); |
| 108 | const reportMarkdown = getWorkflowResultField(resultValue, "reportMarkdown"); |
| 109 | const structuredOutput = getWorkflowResultField(resultValue, "structuredOutput"); |
| 110 | const workflowError = getWorkflowError({ |
| 111 | run: input.run, |
| 112 | status: input.status, |
| 113 | resultValue, |
| 114 | }); |
| 115 | const payload = { |
| 116 | workflow: { |
| 117 | name: input.name, |
| 118 | runId: input.runId, |
| 119 | status: input.status, |
| 120 | }, |
| 121 | ...(typeof reportMarkdown === "string" ? { reportMarkdown } : {}), |
| 122 | ...(structuredOutput !== undefined ? { structuredOutput } : {}), |
| 123 | ...(resultValue != null ? { result: resultValue } : {}), |
| 124 | ...(workflowError ? { error: workflowError } : {}), |
| 125 | }; |
| 126 | |
| 127 | return [ |
| 128 | "The workflow below has finished. Continue the agent turn for the original request using this workflow result. Do not merely restate the raw payload; synthesize the next answer or action from it.", |
| 129 | `Original workflow command: ${input.rawCommand}`, |
| 130 | `<${WORKFLOW_RESULT_XML_TAG}>\n${stringifyWorkflowResultPayload(payload)}\n</${WORKFLOW_RESULT_XML_TAG}>`, |
| 131 | ].join("\n\n"); |
| 132 | } |
| 133 | |
| 134 | export interface WorkflowRunCardInput { |
| 135 | scriptPath?: string; |
no test coverage detected