@clearideas/agent-runtime-store-sqlite 0.6.3 → 0.7.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.ts CHANGED
@@ -15,6 +15,7 @@ export declare class SqliteRunStore implements RunStore {
15
15
  suspendRun(runId: string, suspendedAt: string, expectedAttempt: number): Promise<void>;
16
16
  completeRun(record: CompletedRunRecord): Promise<void>;
17
17
  failRun(runId: string, error: RunError, failedAt: string, expectedAttempt: number): Promise<void>;
18
+ interruptRun(runId: string, error: RunError, interruptedAt: string, expectedAttempt: number): Promise<void>;
18
19
  cancelRun(runId: string, cancelledAt: string, expectedAttempt: number): Promise<void>;
19
20
  close(): void;
20
21
  }
package/dist/index.js CHANGED
@@ -284,6 +284,40 @@ export class SqliteRunStore {
284
284
  throw caught;
285
285
  }
286
286
  }
287
+ async interruptRun(runId, error, interruptedAt, expectedAttempt) {
288
+ this.#database.exec("BEGIN IMMEDIATE");
289
+ try {
290
+ const row = this.#database
291
+ .prepare("SELECT record_json AS json FROM agent_runtime_runs WHERE run_id = ?")
292
+ .get(runId);
293
+ if (!row)
294
+ throw new Error(`Run ${runId} does not exist`);
295
+ const current = parse(row.json);
296
+ if (current.status !== "created" && current.status !== "running") {
297
+ throw new Error(`Cannot interrupt ${current.status} run ${runId}`);
298
+ }
299
+ if ((current.attempt ?? 1) !== expectedAttempt) {
300
+ throw new Error(`Run ${runId} is owned by another attempt`);
301
+ }
302
+ const interruptedRecord = {
303
+ ...current,
304
+ status: "interrupted",
305
+ updatedAt: interruptedAt,
306
+ };
307
+ this.#database
308
+ .prepare(`
309
+ UPDATE agent_runtime_runs
310
+ SET record_json = ?, failure_json = ?
311
+ WHERE run_id = ?
312
+ `)
313
+ .run(serialize(interruptedRecord), serialize({ error, interruptedAt }), runId);
314
+ this.#database.exec("COMMIT");
315
+ }
316
+ catch (caught) {
317
+ this.#database.exec("ROLLBACK");
318
+ throw caught;
319
+ }
320
+ }
287
321
  async cancelRun(runId, cancelledAt, expectedAttempt) {
288
322
  this.#database.exec("BEGIN IMMEDIATE");
289
323
  try {
@@ -299,7 +333,8 @@ export class SqliteRunStore {
299
333
  }
300
334
  if (current.status !== "created" &&
301
335
  current.status !== "running" &&
302
- current.status !== "suspended") {
336
+ current.status !== "suspended" &&
337
+ current.status !== "interrupted") {
303
338
  throw new Error(`Cannot cancel ${current.status} run ${runId}`);
304
339
  }
305
340
  if ((current.attempt ?? 1) !== expectedAttempt) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@clearideas/agent-runtime-store-sqlite",
3
- "version": "0.6.3",
3
+ "version": "0.7.1",
4
4
  "description": "Durable SQLite run and checkpoint storage for Clear Ideas Agent Runtime.",
5
5
  "license": "Apache-2.0",
6
6
  "author": "Clear Ideas Incorporated",
@@ -36,8 +36,8 @@
36
36
  "postpack": "node ../../scripts/cleanup-package-license.mjs"
37
37
  },
38
38
  "dependencies": {
39
- "@clearideas/agent-runtime-contracts": "0.6.3",
40
- "@clearideas/agent-runtime-core": "0.6.3"
39
+ "@clearideas/agent-runtime-contracts": "0.7.1",
40
+ "@clearideas/agent-runtime-core": "0.7.1"
41
41
  },
42
42
  "devDependencies": {
43
43
  "@types/node": "^26.6.6",