@deepagents/context 0.17.1 → 0.18.0

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.js CHANGED
@@ -10,7 +10,6 @@ import {
10
10
  streamText
11
11
  } from "ai";
12
12
  import chalk from "chalk";
13
- import "zod";
14
13
  import { createRepairToolCall } from "@deepagents/agent";
15
14
 
16
15
  // packages/context/src/lib/fragments.ts
@@ -5677,6 +5676,47 @@ var SqliteStreamStore = class extends StreamStore {
5677
5676
  async deleteStream(streamId) {
5678
5677
  this.#stmt("DELETE FROM streams WHERE id = ?").run(streamId);
5679
5678
  }
5679
+ async reopenStream(streamId) {
5680
+ return this.#transaction(() => {
5681
+ const row = this.#stmt("SELECT * FROM streams WHERE id = ?").get(
5682
+ streamId
5683
+ );
5684
+ if (!row) {
5685
+ throw new Error(`Stream "${streamId}" not found`);
5686
+ }
5687
+ if (row.status !== "completed" && row.status !== "failed" && row.status !== "cancelled") {
5688
+ throw new Error(
5689
+ `Cannot reopen stream "${streamId}" with status "${row.status}". Only terminal streams can be reopened.`
5690
+ );
5691
+ }
5692
+ this.#stmt("DELETE FROM streams WHERE id = ?").run(streamId);
5693
+ const now = Date.now();
5694
+ this.#stmt(
5695
+ `INSERT INTO streams (id, status, createdAt, startedAt, finishedAt, cancelRequestedAt, error)
5696
+ VALUES (?, ?, ?, ?, ?, ?, ?)`
5697
+ ).run(streamId, "queued", now, null, null, null, null);
5698
+ return {
5699
+ id: streamId,
5700
+ status: "queued",
5701
+ createdAt: now,
5702
+ startedAt: null,
5703
+ finishedAt: null,
5704
+ cancelRequestedAt: null,
5705
+ error: null
5706
+ };
5707
+ });
5708
+ }
5709
+ #transaction(callback) {
5710
+ try {
5711
+ this.#db.exec("BEGIN IMMEDIATE");
5712
+ const result = callback();
5713
+ this.#db.exec("COMMIT");
5714
+ return result;
5715
+ } catch (error) {
5716
+ this.#db.exec("ROLLBACK");
5717
+ throw error;
5718
+ }
5719
+ }
5680
5720
  };
5681
5721
 
5682
5722
  // packages/context/src/lib/stream/stream-manager.ts
@@ -5801,6 +5841,10 @@ var StreamManager = class {
5801
5841
  }
5802
5842
  });
5803
5843
  }
5844
+ async reopen(streamId) {
5845
+ const stream = await this.#store.reopenStream(streamId);
5846
+ return { stream, created: true };
5847
+ }
5804
5848
  async cleanup(streamId) {
5805
5849
  await this.#store.deleteStream(streamId);
5806
5850
  }