* Extract a structured result payload from the raw execution result * for the LLM to see the actual workflow output.
(result: unknown)
| 541 | * for the LLM to see the actual workflow output. |
| 542 | */ |
| 543 | function buildResultData(result: unknown): Record<string, unknown> | undefined { |
| 544 | if (!result || typeof result !== 'object') return undefined |
| 545 | |
| 546 | const r = result as Record<string, unknown> |
| 547 | |
| 548 | if ('success' in r) { |
| 549 | return { |
| 550 | success: r.success, |
| 551 | output: r.output, |
| 552 | logs: r.logs, |
| 553 | error: r.error, |
| 554 | } |
| 555 | } |
| 556 | |
| 557 | if ('execution' in r && r.execution && typeof r.execution === 'object') { |
| 558 | const exec = r.execution as Record<string, unknown> |
| 559 | return { |
| 560 | success: exec.success, |
| 561 | output: exec.output, |
| 562 | logs: exec.logs, |
| 563 | error: exec.error, |
| 564 | } |
| 565 | } |
| 566 | |
| 567 | return undefined |
| 568 | } |
| 569 | |
| 570 | /** |
| 571 | * Report tool completion to the server via the existing /api/copilot/confirm endpoint. |