| 31 | } |
| 32 | |
| 33 | async function startRun() { |
| 34 | const response = await fetch( |
| 35 | `${API_BASE_URL}/api/v1/workflows/${WORKFLOW_ID}/run`, |
| 36 | { |
| 37 | method: 'POST', |
| 38 | headers: { |
| 39 | ...COMMON_HEADERS, |
| 40 | 'Content-Type': 'application/json', |
| 41 | }, |
| 42 | body: JSON.stringify({}), |
| 43 | }, |
| 44 | ) |
| 45 | |
| 46 | if (!response.ok) { |
| 47 | const text = await response.text() |
| 48 | throw new Error( |
| 49 | `Failed to start workflow ${WORKFLOW_ID}: ${response.status} ${response.statusText} - ${text}`, |
| 50 | ) |
| 51 | } |
| 52 | |
| 53 | const payload = await response.json() |
| 54 | const runId = payload.runId ?? payload.executionId ?? payload.id |
| 55 | if (!runId) { |
| 56 | throw new Error( |
| 57 | `Start response missing runId: ${JSON.stringify(payload, null, 2)}`, |
| 58 | ) |
| 59 | } |
| 60 | |
| 61 | return { runId, payload } |
| 62 | } |
| 63 | |
| 64 | async function captureStream(runId: string, filePath: string) { |
| 65 | await ensureOutputDir(filePath) |