MCPcopy
hub / github.com/BuilderIO/agent-native / insertRun

Function insertRun

packages/core/src/progress/store.ts:94–135  ·  view source on GitHub ↗
(input: StartRunInput)

Source from the content-addressed store, hash-verified

92}
93
94export 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
137export async function getRun(
138 id: string,

Callers 1

startRunFunction · 0.70

Calls 5

getDbExecFunction · 0.85
isUniqueViolationFunction · 0.85
ensureTableFunction · 0.70
bumpPollFunction · 0.70
executeMethod · 0.65

Tested by

no test coverage detected