(input: StartRunInput)
| 92 | } |
| 93 | |
| 94 | export async function insertRun(input: StartRunInput): Promise<AgentRun> { |
| 95 | await ensureTable(); |
| 96 | const client = getDbExec(); |
| 97 | const id = input.id ?? randomUUID(); |
| 98 | const now = Date.now(); |
| 99 | try { |
| 100 | await client.execute({ |
| 101 | sql: `INSERT INTO progress_runs |
| 102 | (id, owner, title, step, percent, status, metadata, started_at, updated_at, completed_at) |
| 103 | VALUES (?, ?, ?, ?, NULL, 'running', ?, ?, ?, NULL)`, |
| 104 | args: [ |
| 105 | id, |
| 106 | input.owner, |
| 107 | input.title, |
| 108 | input.step ?? null, |
| 109 | input.metadata ? JSON.stringify(input.metadata) : null, |
| 110 | now, |
| 111 | now, |
| 112 | ], |
| 113 | }); |
| 114 | } catch (err) { |
| 115 | if (input.id && isUniqueViolation(err)) { |
| 116 | throw new Error( |
| 117 | `insertRun: run id "${input.id}" already exists for this owner`, |
| 118 | ); |
| 119 | } |
| 120 | throw err; |
| 121 | } |
| 122 | bumpPoll(input.owner); |
| 123 | return { |
| 124 | id, |
| 125 | owner: input.owner, |
| 126 | title: input.title, |
| 127 | step: input.step, |
| 128 | percent: null, |
| 129 | status: "running", |
| 130 | metadata: input.metadata, |
| 131 | startedAt: new Date(now).toISOString(), |
| 132 | updatedAt: new Date(now).toISOString(), |
| 133 | completedAt: null, |
| 134 | }; |
| 135 | } |
| 136 | |
| 137 | export async function getRun( |
| 138 | id: string, |
no test coverage detected