| 102 | } |
| 103 | |
| 104 | async createRun(input: CreateWorkflowRunInput): Promise<WorkflowRunRecord> { |
| 105 | assert(input.id.length > 0, "WorkflowRunStore.createRun: id is required"); |
| 106 | assert(input.workspaceId.length > 0, "WorkflowRunStore.createRun: workspaceId is required"); |
| 107 | assert(input.source.length > 0, "WorkflowRunStore.createRun: source is required"); |
| 108 | |
| 109 | const runDir = this.runDir(input.id); |
| 110 | await fs.mkdir(runDir, { recursive: true }); |
| 111 | await fs.writeFile(path.join(runDir, WORKFLOW_SOURCE_FILENAME), input.source, "utf-8"); |
| 112 | await fs.writeFile(path.join(runDir, "events.jsonl"), "", { flag: "a" }); |
| 113 | await fs.writeFile(path.join(runDir, "steps.jsonl"), "", { flag: "a" }); |
| 114 | |
| 115 | const run = WorkflowRunRecordSchema.parse({ |
| 116 | id: input.id, |
| 117 | workspaceId: input.workspaceId, |
| 118 | workflow: input.workflow, |
| 119 | source: input.source, |
| 120 | sourceHash: hashSource(input.source), |
| 121 | args: input.args, |
| 122 | agentOutputSchemaRequired: input.agentOutputSchemaRequired ?? true, |
| 123 | agentTypeAliasAllowed: input.agentTypeAliasAllowed ?? false, |
| 124 | ...(input.parentWorkflow != null ? { parentWorkflow: input.parentWorkflow } : {}), |
| 125 | ...(input.attentionPolicy != null ? { attentionPolicy: input.attentionPolicy } : {}), |
| 126 | status: "pending", |
| 127 | createdAt: input.now, |
| 128 | updatedAt: input.now, |
| 129 | events: [], |
| 130 | steps: [], |
| 131 | }); |
| 132 | |
| 133 | await this.writeRunFile(input.id, run); |
| 134 | return run; |
| 135 | } |
| 136 | |
| 137 | async createRunIfAbsent(input: CreateWorkflowRunInput): Promise<WorkflowRunRecord> { |
| 138 | assert(input.id.length > 0, "WorkflowRunStore.createRunIfAbsent: id is required"); |