(
sessionDir: string,
params: {
runId: string;
workspaceId?: string;
completedAt?: string;
failed?: boolean;
parentWorkflow?: {
runId: string;
stepId: string;
inputHash: string;
depth: number;
};
reportMarkdown?: string;
}
)
| 38 | } |
| 39 | |
| 40 | async function writeWorkflowRun( |
| 41 | sessionDir: string, |
| 42 | params: { |
| 43 | runId: string; |
| 44 | workspaceId?: string; |
| 45 | completedAt?: string; |
| 46 | failed?: boolean; |
| 47 | parentWorkflow?: { |
| 48 | runId: string; |
| 49 | stepId: string; |
| 50 | inputHash: string; |
| 51 | depth: number; |
| 52 | }; |
| 53 | reportMarkdown?: string; |
| 54 | } |
| 55 | ): Promise<void> { |
| 56 | const store = new WorkflowRunStore({ sessionDir }); |
| 57 | await store.createRun({ |
| 58 | id: params.runId, |
| 59 | workspaceId: params.workspaceId ?? WORKSPACE_ID, |
| 60 | workflow: { |
| 61 | name: "deep-research", |
| 62 | description: "Research a topic", |
| 63 | scope: "built-in" as const, |
| 64 | executable: true, |
| 65 | }, |
| 66 | ...(params.parentWorkflow !== undefined ? { parentWorkflow: params.parentWorkflow } : {}), |
| 67 | source: "export default async function workflow() { return 'ok'; }\n", |
| 68 | args: {}, |
| 69 | now: "2026-06-01T00:00:00.000Z", |
| 70 | }); |
| 71 | await store.appendNextEvent(params.runId, { |
| 72 | type: "status", |
| 73 | at: "2026-06-01T00:00:01.000Z", |
| 74 | status: "running", |
| 75 | }); |
| 76 | if (params.completedAt === undefined) { |
| 77 | return; // leave the run active |
| 78 | } |
| 79 | if (params.failed) { |
| 80 | await store.appendNextEvent(params.runId, { |
| 81 | type: "error", |
| 82 | at: params.completedAt, |
| 83 | message: "boom", |
| 84 | }); |
| 85 | await store.appendNextEvent(params.runId, { |
| 86 | type: "status", |
| 87 | at: params.completedAt, |
| 88 | status: "failed", |
| 89 | }); |
| 90 | return; |
| 91 | } |
| 92 | await store.appendNextEvent(params.runId, { |
| 93 | type: "result", |
| 94 | at: params.completedAt, |
| 95 | result: { reportMarkdown: params.reportMarkdown ?? "# Workflow report" }, |
| 96 | }); |
| 97 | await store.appendNextEvent(params.runId, { |
no test coverage detected