import { repoDb } from "../scoped-db"; import { registerLocator } from "../scoped-db/locators"; import { scopedId } from "../scoped-db/ids"; import { jobDb } from "./scope"; export type ArtifactInput = { runId: string; jobId: string; name: string; size: number; r2Key: string }; /** Records an uploaded job artifact and makes it addressable by id (`/api/artifacts/:id`). */ export async function recordJobArtifact(repoId: string, artifact: ArtifactInput): Promise { const id = scopedId(repoId); await repoDb(repoId).run( "INSERT INTO job_artifacts (id, run_id, job_id, name, size, r2_key, created_at) VALUES (?, ?, ?, ?, ?, ?, ?)", id, artifact.runId, artifact.jobId, artifact.name, artifact.size, artifact.r2Key, Date.now(), ); await registerLocator("job_artifact", id, repoId); return id; } export async function saveJobOutputs(jobId: string, outputs: Record): Promise { await (await jobDb(jobId))?.run("UPDATE workflow_jobs SET outputs = ? WHERE id = ?", JSON.stringify(outputs), jobId); }