@effect-agent/storage-sqlite 0.1.0-beta.55 → 0.1.0-beta.57

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.
@@ -1,5 +1,5 @@
1
1
  import { t as __exportAll } from "./rolldown-runtime-D7D4PA-g.mjs";
2
- import { a as initializeSqliteJournal } from "./sqlite-journal-Ce8lwVYx.mjs";
2
+ import { a as initializeSqliteJournal } from "./sqlite-journal-lDduEakl.mjs";
3
3
  import { Effect, Layer, Schema } from "effect";
4
4
  import * as SqlClientService from "effect/unstable/sql/SqlClient";
5
5
  import { SourcePartition, SubscriptionError, SubscriptionStore } from "@effect-agent/thread/Subscription";
@@ -1,5 +1,5 @@
1
- import { SqliteStorageConfig } from "./SqliteStorageConfig.mjs";
2
1
  import { a as SqliteStorageCompatibilityError, o as SqliteStorageCorruptionError, s as SqliteStorageError } from "./SqliteStorageError-CzKmwCLl.mjs";
2
+ import { SqliteStorageConfig } from "./SqliteStorageConfig.mjs";
3
3
  import { SqliteStorageFailpoint, SqliteStorageFailpointHandler } from "./SqliteStorageFailpoint.mjs";
4
4
  import { Crypto, Layer } from "effect";
5
5
  import * as SqlClientService from "effect/unstable/sql/SqlClient";
@@ -2,9 +2,9 @@ import { t as __exportAll } from "./rolldown-runtime-D7D4PA-g.mjs";
2
2
  import { SqliteStorageConfig, SqliteStorageConfigValue } from "./SqliteStorageConfig.mjs";
3
3
  import { SqliteAppendConflict, SqliteCheckpointConflict, SqliteFenceRejected, SqliteStorageCorruptionError, SqliteStorageError } from "./SqliteStorageError.mjs";
4
4
  import { SqliteStorageFailpoint } from "./SqliteStorageFailpoint.mjs";
5
- import { a as initializeSqliteJournal, n as RawCheckpoint, r as RawReadRequest, t as RawAppendRequest } from "./sqlite-journal-Ce8lwVYx.mjs";
6
- import { CanonicalBatch, CanonicalRecord, CanonicalRecordEnvelope, CanonicalSequence, Digest, ObservationOffset } from "@effect-agent/thread/Records";
5
+ import { a as initializeSqliteJournal, n as RawCheckpoint, r as RawReadRequest, t as RawAppendRequest } from "./sqlite-journal-lDduEakl.mjs";
7
6
  import { Clock, Context, Crypto, Duration, Effect, Layer, Option, Ref, Schema, Stream } from "effect";
7
+ import { CanonicalBatch, CanonicalRecord, CanonicalRecordEnvelope, CanonicalSequence, Digest, ObservationOffset } from "@effect-agent/thread/Records";
8
8
  import { NodeCrypto } from "@effect/platform-node";
9
9
  import { SqliteClient } from "@effect/sql-sqlite-node";
10
10
  import { EMPTY_TAIL_DIGEST, digestCanonicalBatch } from "@effect-agent/thread/Digest";
package/dist/index.d.mts CHANGED
@@ -1,10 +1,11 @@
1
1
  import { t as SqliteActivityStore_d_exports } from "./SqliteActivityStore.mjs";
2
- import { t as SqliteStorageConfig_d_exports } from "./SqliteStorageConfig.mjs";
3
2
  import { c as SqliteStorageError_d_exports } from "./SqliteStorageError-CzKmwCLl.mjs";
3
+ import { t as SqliteStorageConfig_d_exports } from "./SqliteStorageConfig.mjs";
4
4
  import { t as SqliteStorageFailpoint_d_exports } from "./SqliteStorageFailpoint.mjs";
5
+ import { t as SqliteMessageDeliveryStore_d_exports } from "./SqliteMessageDeliveryStore.mjs";
5
6
  import { t as SqliteThreadStore_d_exports } from "./SqliteThreadStore.mjs";
6
7
  import { t as SqliteScheduleStore_d_exports } from "./SqliteScheduleStore.mjs";
7
- import { t as SqliteStorageVersion_d_exports } from "./SqliteStorageVersion-DiIVkDFv.mjs";
8
+ import { t as SqliteStorageVersion_d_exports } from "./SqliteStorageVersion-gA7_96xM.mjs";
8
9
  import { t as SqliteSubmissionLedger_d_exports } from "./SqliteSubmissionLedger.mjs";
9
10
  import { t as SqliteSubscriptionStore_d_exports } from "./SqliteSubscriptionStore.mjs";
10
- export { SqliteActivityStore_d_exports as SqliteActivityStore, SqliteScheduleStore_d_exports as SqliteScheduleStore, SqliteStorageConfig_d_exports as SqliteStorageConfig, SqliteStorageError_d_exports as SqliteStorageError, SqliteStorageFailpoint_d_exports as SqliteStorageFailpoint, SqliteStorageVersion_d_exports as SqliteStorageVersion, SqliteSubmissionLedger_d_exports as SqliteSubmissionLedger, SqliteSubscriptionStore_d_exports as SqliteSubscriptionStore, SqliteThreadStore_d_exports as SqliteThreadStore };
11
+ export { SqliteActivityStore_d_exports as SqliteActivityStore, SqliteMessageDeliveryStore_d_exports as SqliteMessageDeliveryStore, SqliteScheduleStore_d_exports as SqliteScheduleStore, SqliteStorageConfig_d_exports as SqliteStorageConfig, SqliteStorageError_d_exports as SqliteStorageError, SqliteStorageFailpoint_d_exports as SqliteStorageFailpoint, SqliteStorageVersion_d_exports as SqliteStorageVersion, SqliteSubmissionLedger_d_exports as SqliteSubmissionLedger, SqliteSubscriptionStore_d_exports as SqliteSubscriptionStore, SqliteThreadStore_d_exports as SqliteThreadStore };
package/dist/index.mjs CHANGED
@@ -1,10 +1,11 @@
1
- import { t as SqliteActivityStore_exports } from "./SqliteActivityStore.mjs";
2
1
  import { t as SqliteStorageConfig_exports } from "./SqliteStorageConfig.mjs";
3
2
  import { t as SqliteStorageError_exports } from "./SqliteStorageError.mjs";
4
3
  import { t as SqliteStorageFailpoint_exports } from "./SqliteStorageFailpoint.mjs";
4
+ import { t as SqliteMessageDeliveryStore_exports } from "./SqliteMessageDeliveryStore.mjs";
5
+ import { t as SqliteActivityStore_exports } from "./SqliteActivityStore.mjs";
5
6
  import { t as SqliteScheduleStore_exports } from "./SqliteScheduleStore.mjs";
6
7
  import { t as SqliteStorageVersion_exports } from "./SqliteStorageVersion.mjs";
7
8
  import { t as SqliteThreadStore_exports } from "./SqliteThreadStore.mjs";
8
9
  import { t as SqliteSubmissionLedger_exports } from "./SqliteSubmissionLedger.mjs";
9
10
  import { t as SqliteSubscriptionStore_exports } from "./SqliteSubscriptionStore.mjs";
10
- export { SqliteActivityStore_exports as SqliteActivityStore, SqliteScheduleStore_exports as SqliteScheduleStore, SqliteStorageConfig_exports as SqliteStorageConfig, SqliteStorageError_exports as SqliteStorageError, SqliteStorageFailpoint_exports as SqliteStorageFailpoint, SqliteStorageVersion_exports as SqliteStorageVersion, SqliteSubmissionLedger_exports as SqliteSubmissionLedger, SqliteSubscriptionStore_exports as SqliteSubscriptionStore, SqliteThreadStore_exports as SqliteThreadStore };
11
+ export { SqliteActivityStore_exports as SqliteActivityStore, SqliteMessageDeliveryStore_exports as SqliteMessageDeliveryStore, SqliteScheduleStore_exports as SqliteScheduleStore, SqliteStorageConfig_exports as SqliteStorageConfig, SqliteStorageError_exports as SqliteStorageError, SqliteStorageFailpoint_exports as SqliteStorageFailpoint, SqliteStorageVersion_exports as SqliteStorageVersion, SqliteSubmissionLedger_exports as SqliteSubmissionLedger, SqliteSubscriptionStore_exports as SqliteSubscriptionStore, SqliteThreadStore_exports as SqliteThreadStore };
@@ -1,8 +1,30 @@
1
1
  import { Effect } from "effect";
2
2
  import * as SqlClient from "effect/unstable/sql/SqlClient";
3
3
  import { SqliteMigrator } from "@effect/sql-sqlite-node";
4
+ //#region src/internal/message-delivery-schema.ts
5
+ /** Additive storage owned by this adapter; creation participates in its version transaction. */
6
+ const createMessageDeliveryTables = Effect.gen(function* () {
7
+ const sql = yield* SqlClient.SqlClient;
8
+ yield* sql`
9
+ CREATE TABLE effect_agent_message_deliveries (
10
+ owner_thread_id TEXT NOT NULL,
11
+ message_id TEXT NOT NULL,
12
+ version INTEGER NOT NULL,
13
+ state TEXT NOT NULL,
14
+ deadline_at_millis INTEGER,
15
+ record_json TEXT NOT NULL,
16
+ PRIMARY KEY (owner_thread_id, message_id)
17
+ )
18
+ `.withoutTransform;
19
+ yield* sql`
20
+ CREATE INDEX effect_agent_message_deliveries_due
21
+ ON effect_agent_message_deliveries (deadline_at_millis, owner_thread_id, message_id)
22
+ WHERE deadline_at_millis IS NOT NULL
23
+ `.withoutTransform;
24
+ });
25
+ //#endregion
4
26
  //#region src/internal/migrations.ts
5
- const CurrentSqliteStorageVersion = 8;
27
+ const CurrentSqliteStorageVersion = 9;
6
28
  /** Initialize empty storage with the complete current schema. */
7
29
  const sqliteMigrations = SqliteMigrator.fromRecord({ "1_current_thread_storage": Effect.gen(function* () {
8
30
  const sql = yield* SqlClient.SqlClient;
@@ -88,6 +110,8 @@ const sqliteMigrations = SqliteMigrator.fromRecord({ "1_current_thread_storage":
88
110
  parent_tool_call_id TEXT,
89
111
  admission_group TEXT,
90
112
  admission_fence_json TEXT,
113
+ worker_admission_json TEXT,
114
+ message_admission_json TEXT,
91
115
  UNIQUE (thread_id, principal, idempotency_key),
92
116
  UNIQUE (thread_id, queue_sequence)
93
117
  )
@@ -293,9 +317,10 @@ const sqliteMigrations = SqliteMigrator.fromRecord({ "1_current_thread_storage":
293
317
  `.withoutTransform;
294
318
  yield* sql`CREATE INDEX effect_agent_subscription_deliveries_pending ON effect_agent_subscription_deliveries (tenant_id, source_address, state, next_attempt_at_millis, delivery_key)`.withoutTransform;
295
319
  yield* sql`CREATE INDEX effect_agent_subscription_deliveries_registration ON effect_agent_subscription_deliveries (tenant_id, source_address, owner_id, subscription_id, delivery_key)`.withoutTransform;
296
- yield* sql`PRAGMA user_version = 8`.withoutTransform;
320
+ yield* createMessageDeliveryTables;
321
+ yield* sql`PRAGMA user_version = 9`.withoutTransform;
297
322
  }) });
298
323
  //#endregion
299
- export { sqliteMigrations as n, CurrentSqliteStorageVersion as t };
324
+ export { sqliteMigrations as n, createMessageDeliveryTables as r, CurrentSqliteStorageVersion as t };
300
325
 
301
- //# sourceMappingURL=migrations-BKcJueHB.mjs.map
326
+ //# sourceMappingURL=migrations-dnTR0RKq.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"migrations-dnTR0RKq.mjs","names":[],"sources":["../src/internal/message-delivery-schema.ts","../src/internal/migrations.ts"],"sourcesContent":["import { Effect } from \"effect\";\nimport * as SqlClient from \"effect/unstable/sql/SqlClient\";\n\n/** Additive storage owned by this adapter; creation participates in its version transaction. */\nexport const createMessageDeliveryTables = Effect.gen(function* () {\n const sql = yield* SqlClient.SqlClient;\n\n yield* sql`\n CREATE TABLE effect_agent_message_deliveries (\n owner_thread_id TEXT NOT NULL,\n message_id TEXT NOT NULL,\n version INTEGER NOT NULL,\n state TEXT NOT NULL,\n deadline_at_millis INTEGER,\n record_json TEXT NOT NULL,\n PRIMARY KEY (owner_thread_id, message_id)\n )\n `.withoutTransform;\n yield* sql`\n CREATE INDEX effect_agent_message_deliveries_due\n ON effect_agent_message_deliveries (deadline_at_millis, owner_thread_id, message_id)\n WHERE deadline_at_millis IS NOT NULL\n `.withoutTransform;\n});\n","import { SqliteMigrator } from \"@effect/sql-sqlite-node\";\nimport { Effect } from \"effect\";\nimport * as SqlClient from \"effect/unstable/sql/SqlClient\";\n\nimport { createMessageDeliveryTables } from \"./message-delivery-schema.ts\";\n\nexport const CurrentSqliteStorageVersion = 9;\n\n/** Initialize empty storage with the complete current schema. */\nexport const sqliteMigrations = SqliteMigrator.fromRecord({\n \"1_current_thread_storage\": Effect.gen(function* () {\n const sql = yield* SqlClient.SqlClient;\n\n yield* sql`\n CREATE TABLE effect_agent_threads (\n thread_id TEXT PRIMARY KEY NOT NULL,\n created_at TEXT NOT NULL,\n tail_sequence INTEGER NOT NULL,\n tail_digest TEXT NOT NULL,\n producer_epoch INTEGER NOT NULL\n )\n `.withoutTransform;\n\n yield* sql`\n CREATE TABLE effect_agent_canonical_batches (\n thread_id TEXT NOT NULL,\n batch_id TEXT NOT NULL,\n first_sequence INTEGER NOT NULL,\n last_sequence INTEGER NOT NULL,\n batch_digest TEXT NOT NULL,\n tail_digest TEXT NOT NULL,\n batch_json TEXT NOT NULL,\n PRIMARY KEY (thread_id, batch_id),\n FOREIGN KEY (thread_id)\n REFERENCES effect_agent_threads(thread_id)\n ON DELETE RESTRICT\n )\n `.withoutTransform;\n\n yield* sql`\n CREATE TABLE effect_agent_canonical_records (\n thread_id TEXT NOT NULL,\n sequence INTEGER NOT NULL,\n record_id TEXT NOT NULL,\n batch_id TEXT NOT NULL,\n record_json TEXT NOT NULL,\n PRIMARY KEY (thread_id, sequence),\n UNIQUE (thread_id, record_id),\n FOREIGN KEY (thread_id, batch_id)\n REFERENCES effect_agent_canonical_batches(thread_id, batch_id)\n ON DELETE RESTRICT\n )\n `.withoutTransform;\n\n yield* sql`\n CREATE INDEX effect_agent_canonical_records_batch\n ON effect_agent_canonical_records (thread_id, batch_id, sequence)\n `.withoutTransform;\n\n yield* sql`\n CREATE TABLE effect_agent_checkpoints (\n thread_id TEXT NOT NULL,\n through_sequence INTEGER NOT NULL,\n tail_digest TEXT NOT NULL,\n checkpoint_json TEXT NOT NULL,\n PRIMARY KEY (thread_id, through_sequence),\n FOREIGN KEY (thread_id)\n REFERENCES effect_agent_threads(thread_id)\n ON DELETE RESTRICT\n )\n `.withoutTransform;\n\n // Admission rows exist before Thread materialization (durability §4), so\n // thread_id intentionally carries no foreign key into effect_agent_threads.\n yield* sql`\n CREATE TABLE effect_agent_submissions (\n submission_id TEXT PRIMARY KEY NOT NULL,\n thread_id TEXT NOT NULL,\n queue_sequence INTEGER NOT NULL,\n principal TEXT NOT NULL,\n idempotency_key TEXT NOT NULL,\n agent_id TEXT NOT NULL,\n agent_digests_json TEXT NOT NULL,\n deployment_id TEXT NOT NULL,\n input_json TEXT NOT NULL,\n input_digest TEXT NOT NULL,\n receipt_id TEXT NOT NULL,\n state TEXT NOT NULL,\n settled_outcome TEXT,\n created_at TEXT NOT NULL,\n ready_at TEXT,\n input_applied_record_id TEXT,\n input_applied_sequence INTEGER,\n joined_host_submission_id TEXT,\n suspended_reason_json TEXT,\n suspended_at TEXT,\n unknown_reason TEXT,\n unknown_tool_call_ids_json TEXT,\n parent_submission_id TEXT,\n parent_tool_call_id TEXT,\n admission_group TEXT,\n admission_fence_json TEXT,\n worker_admission_json TEXT,\n message_admission_json TEXT,\n UNIQUE (thread_id, principal, idempotency_key),\n UNIQUE (thread_id, queue_sequence)\n )\n `.withoutTransform;\n\n yield* sql`\n CREATE INDEX effect_agent_submissions_group\n ON effect_agent_submissions (thread_id, admission_group, state)\n `.withoutTransform;\n\n yield* sql`\n CREATE TABLE effect_agent_submission_ownership (\n submission_id TEXT PRIMARY KEY NOT NULL,\n attempt_id TEXT NOT NULL,\n ownership_token TEXT NOT NULL,\n producer_epoch INTEGER NOT NULL,\n owner_producer_id TEXT NOT NULL,\n lease_expires_at TEXT NOT NULL,\n FOREIGN KEY (submission_id)\n REFERENCES effect_agent_submissions(submission_id)\n ON DELETE RESTRICT\n )\n `.withoutTransform;\n\n yield* sql`\n CREATE TABLE effect_agent_attempts (\n attempt_id TEXT PRIMARY KEY NOT NULL,\n submission_id TEXT NOT NULL,\n thread_id TEXT NOT NULL,\n owner_producer_id TEXT NOT NULL,\n producer_epoch INTEGER NOT NULL,\n claimed_at TEXT NOT NULL,\n FOREIGN KEY (submission_id)\n REFERENCES effect_agent_submissions(submission_id)\n ON DELETE RESTRICT\n )\n `.withoutTransform;\n\n yield* sql`\n CREATE TABLE effect_agent_settlement_reservations (\n submission_id TEXT PRIMARY KEY NOT NULL,\n settlement_id TEXT NOT NULL,\n outcome TEXT NOT NULL,\n record_id TEXT NOT NULL,\n record_json TEXT NOT NULL,\n record_digest TEXT NOT NULL,\n reserved_at TEXT NOT NULL,\n finalized_at TEXT,\n FOREIGN KEY (submission_id)\n REFERENCES effect_agent_submissions(submission_id)\n ON DELETE RESTRICT\n )\n `.withoutTransform;\n\n yield* sql`\n CREATE TABLE effect_agent_abort_intents (\n submission_id TEXT PRIMARY KEY NOT NULL,\n author TEXT NOT NULL,\n reason TEXT NOT NULL,\n requested_at TEXT NOT NULL,\n canonical_record_id TEXT,\n FOREIGN KEY (submission_id)\n REFERENCES effect_agent_submissions(submission_id)\n ON DELETE RESTRICT\n )\n `.withoutTransform;\n\n yield* sql`\n CREATE INDEX effect_agent_submissions_joined_host\n ON effect_agent_submissions (joined_host_submission_id)\n `.withoutTransform;\n\n yield* sql`\n CREATE TABLE effect_agent_approval_decisions (\n submission_id TEXT NOT NULL,\n tool_call_id TEXT NOT NULL,\n decision TEXT NOT NULL,\n resolver TEXT NOT NULL,\n reason TEXT NOT NULL,\n decided_at TEXT NOT NULL,\n PRIMARY KEY (submission_id, tool_call_id),\n FOREIGN KEY (submission_id)\n REFERENCES effect_agent_submissions(submission_id)\n ON DELETE RESTRICT\n )\n `.withoutTransform;\n\n yield* sql`\n CREATE TABLE effect_agent_unknown_resolutions (\n submission_id TEXT NOT NULL,\n tool_call_id TEXT NOT NULL,\n author TEXT NOT NULL,\n reason TEXT NOT NULL,\n resolution_json TEXT NOT NULL,\n resolved_at TEXT NOT NULL,\n PRIMARY KEY (submission_id, tool_call_id),\n FOREIGN KEY (submission_id)\n REFERENCES effect_agent_submissions(submission_id)\n ON DELETE RESTRICT\n )\n `.withoutTransform;\n\n // Durable attached children (spec §12, SUB-004): a child Submission records its immutable\n // parent linkage at admission; the parent-side index serves the recovery attachment view.\n yield* sql`\n CREATE INDEX effect_agent_submissions_parent\n ON effect_agent_submissions (parent_submission_id)\n `.withoutTransform;\n\n // Parent-owned child budget reservations (spec §12 steps 2 and 6, SUB-010): generic\n // opaque-payload state-machine rows (D8) — allocation and accounting are Schema-encoded\n // JSON documents the adapter never interprets; status moves\n // reserved → releasePending → released, applied exactly once.\n yield* sql`\n CREATE TABLE effect_agent_child_reservations (\n reservation_id TEXT PRIMARY KEY NOT NULL,\n parent_submission_id TEXT NOT NULL,\n parent_tool_call_id TEXT NOT NULL,\n child_submission_id TEXT,\n status TEXT NOT NULL,\n allocation_json TEXT NOT NULL,\n allocation_digest TEXT NOT NULL,\n accounting_json TEXT,\n reserved_at TEXT NOT NULL,\n release_began_at TEXT,\n released_at TEXT,\n UNIQUE (parent_submission_id, parent_tool_call_id),\n FOREIGN KEY (parent_submission_id)\n REFERENCES effect_agent_submissions(submission_id)\n ON DELETE RESTRICT\n )\n `.withoutTransform;\n\n // record_json is authoritative. The remaining columns support owner keyset paging and\n // deadline queries without decoding unrelated future schedules.\n yield* sql`\n CREATE TABLE effect_agent_schedules (\n tenant_id TEXT NOT NULL,\n owner_id TEXT NOT NULL,\n schedule_id TEXT NOT NULL,\n deadline_at_millis INTEGER,\n record_json TEXT NOT NULL,\n PRIMARY KEY (tenant_id, owner_id, schedule_id)\n )\n `.withoutTransform;\n\n yield* sql`\n CREATE INDEX effect_agent_schedules_deadline\n ON effect_agent_schedules (deadline_at_millis, tenant_id, owner_id, schedule_id)\n WHERE deadline_at_millis IS NOT NULL\n `.withoutTransform;\n\n yield* sql`\n CREATE INDEX effect_agent_schedules_owner_deadline\n ON effect_agent_schedules (tenant_id, owner_id, deadline_at_millis, schedule_id)\n WHERE deadline_at_millis IS NOT NULL\n `.withoutTransform;\n\n yield* sql`\n CREATE TABLE effect_agent_subscription_sequences (\n tenant_id TEXT NOT NULL,\n source_address TEXT NOT NULL,\n sequence INTEGER NOT NULL,\n event_scan_cursor TEXT NOT NULL,\n delivery_scan_cursor TEXT NOT NULL,\n recovery_scan_cursor INTEGER NOT NULL,\n PRIMARY KEY (tenant_id, source_address)\n )\n `.withoutTransform;\n yield* sql`\n CREATE TABLE effect_agent_subscriptions (\n tenant_id TEXT NOT NULL,\n source_address TEXT NOT NULL,\n owner_id TEXT NOT NULL,\n subscription_id TEXT NOT NULL,\n ordinal INTEGER NOT NULL,\n source_name TEXT NOT NULL,\n source_version TEXT NOT NULL,\n matching_key TEXT NOT NULL,\n state TEXT NOT NULL,\n expires_at_millis INTEGER,\n recovery_at_millis INTEGER,\n recovery_present INTEGER NOT NULL DEFAULT 0,\n record_json TEXT NOT NULL,\n PRIMARY KEY (tenant_id, source_address, owner_id, subscription_id),\n UNIQUE (tenant_id, source_address, ordinal)\n )\n `.withoutTransform;\n yield* sql`CREATE INDEX effect_agent_subscriptions_owner ON effect_agent_subscriptions (tenant_id, source_address, owner_id, ordinal)`\n .withoutTransform;\n yield* sql`CREATE INDEX effect_agent_subscriptions_candidates ON effect_agent_subscriptions (tenant_id, source_address, source_name, source_version, matching_key, ordinal)`\n .withoutTransform;\n yield* sql`CREATE INDEX effect_agent_subscriptions_recovery ON effect_agent_subscriptions (tenant_id, source_address, recovery_at_millis, ordinal) WHERE recovery_at_millis IS NOT NULL`\n .withoutTransform;\n yield* sql`\n CREATE TABLE effect_agent_subscription_events (\n tenant_id TEXT NOT NULL,\n source_address TEXT NOT NULL,\n event_id TEXT NOT NULL,\n source_name TEXT NOT NULL,\n source_version TEXT NOT NULL,\n matching_key TEXT NOT NULL,\n payload_digest TEXT NOT NULL,\n cutoff INTEGER NOT NULL,\n cursor INTEGER NOT NULL,\n routing_complete INTEGER NOT NULL,\n tombstone INTEGER NOT NULL DEFAULT 0,\n next_attempt_at_millis INTEGER NOT NULL,\n record_json TEXT NOT NULL,\n PRIMARY KEY (tenant_id, source_address, event_id)\n )\n `.withoutTransform;\n yield* sql`CREATE INDEX effect_agent_subscription_events_pending ON effect_agent_subscription_events (tenant_id, source_address, routing_complete, next_attempt_at_millis, event_id)`\n .withoutTransform;\n yield* sql`\n CREATE TABLE effect_agent_subscription_deliveries (\n tenant_id TEXT NOT NULL,\n source_address TEXT NOT NULL,\n owner_id TEXT NOT NULL,\n subscription_id TEXT NOT NULL,\n event_id TEXT NOT NULL,\n delivery_key TEXT NOT NULL,\n state TEXT NOT NULL,\n next_attempt_at_millis INTEGER NOT NULL,\n record_json TEXT NOT NULL,\n PRIMARY KEY (tenant_id, source_address, owner_id, subscription_id, event_id),\n UNIQUE (tenant_id, source_address, delivery_key)\n )\n `.withoutTransform;\n yield* sql`CREATE INDEX effect_agent_subscription_deliveries_pending ON effect_agent_subscription_deliveries (tenant_id, source_address, state, next_attempt_at_millis, delivery_key)`\n .withoutTransform;\n yield* sql`CREATE INDEX effect_agent_subscription_deliveries_registration ON effect_agent_subscription_deliveries (tenant_id, source_address, owner_id, subscription_id, delivery_key)`\n .withoutTransform;\n yield* createMessageDeliveryTables;\n yield* sql`PRAGMA user_version = 9`.withoutTransform;\n }),\n});\n"],"mappings":";;;;;AAIA,MAAa,8BAA8B,OAAO,IAAI,aAAa;CACjE,MAAM,MAAM,OAAO,UAAU;CAE7B,OAAO,GAAG;;;;;;;;;;IAUR;CACF,OAAO,GAAG;;;;IAIR;AACJ,CAAC;;;ACjBD,MAAa,8BAA8B;;AAG3C,MAAa,mBAAmB,eAAe,WAAW,EACxD,4BAA4B,OAAO,IAAI,aAAa;CAClD,MAAM,MAAM,OAAO,UAAU;CAE7B,OAAO,GAAG;;;;;;;;MAQR;CAEF,OAAO,GAAG;;;;;;;;;;;;;;MAcR;CAEF,OAAO,GAAG;;;;;;;;;;;;;MAaR;CAEF,OAAO,GAAG;;;MAGR;CAEF,OAAO,GAAG;;;;;;;;;;;MAWR;CAIF,OAAO,GAAG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;MAiCR;CAEF,OAAO,GAAG;;;MAGR;CAEF,OAAO,GAAG;;;;;;;;;;;;MAYR;CAEF,OAAO,GAAG;;;;;;;;;;;;MAYR;CAEF,OAAO,GAAG;;;;;;;;;;;;;;MAcR;CAEF,OAAO,GAAG;;;;;;;;;;;MAWR;CAEF,OAAO,GAAG;;;MAGR;CAEF,OAAO,GAAG;;;;;;;;;;;;;MAaR;CAEF,OAAO,GAAG;;;;;;;;;;;;;MAaR;CAIF,OAAO,GAAG;;;MAGR;CAMF,OAAO,GAAG;;;;;;;;;;;;;;;;;;MAkBR;CAIF,OAAO,GAAG;;;;;;;;;MASR;CAEF,OAAO,GAAG;;;;MAIR;CAEF,OAAO,GAAG;;;;MAIR;CAEF,OAAO,GAAG;;;;;;;;;;MAUR;CACF,OAAO,GAAG;;;;;;;;;;;;;;;;;;MAkBR;CACF,OAAO,GAAG,6HACP;CACH,OAAO,GAAG,mKACP;CACH,OAAO,GAAG,+KACP;CACH,OAAO,GAAG;;;;;;;;;;;;;;;;;MAiBR;CACF,OAAO,GAAG,4KACP;CACH,OAAO,GAAG;;;;;;;;;;;;;;MAcR;CACF,OAAO,GAAG,6KACP;CACH,OAAO,GAAG,8KACP;CACH,OAAO;CACP,OAAO,GAAG,0BAA0B;AACtC,CAAC,EACH,CAAC"}
@@ -1,10 +1,10 @@
1
1
  import { SqliteStorageConfig } from "./SqliteStorageConfig.mjs";
2
2
  import { SqliteAppendConflict, SqliteCheckpointConflict, SqliteFenceRejected, SqliteStorageCompatibilityError, SqliteStorageCorruptionError, SqliteStorageError, SqliteStorageFailpointLocation, SqliteWriteContention } from "./SqliteStorageError.mjs";
3
3
  import { SqliteStorageFailpoint } from "./SqliteStorageFailpoint.mjs";
4
- import { n as sqliteMigrations } from "./migrations-BKcJueHB.mjs";
5
- import { CanonicalSequence, ProducerEpoch } from "@effect-agent/thread/Records";
4
+ import { n as sqliteMigrations, r as createMessageDeliveryTables } from "./migrations-dnTR0RKq.mjs";
6
5
  import { Effect, Exit, Schema } from "effect";
7
6
  import * as SqlClient from "effect/unstable/sql/SqlClient";
7
+ import { CanonicalSequence, ProducerEpoch } from "@effect-agent/thread/Records";
8
8
  import { ScheduleFailpoint, ScheduleFailpointError } from "@effect-agent/thread/Schedule";
9
9
  import { checkV2ThreadLayout, upgradeV2Schedules, upgradeV2Subscriptions } from "@effect-agent/thread/SqlStorageV2Upgrade";
10
10
  import { SubscriptionFailpoint, SubscriptionFailpointError } from "@effect-agent/thread/Subscription";
@@ -103,6 +103,196 @@ const decodeSingleRow = Effect.fn("SqliteJournal.decodeSingleRow")((schema, tabl
103
103
  rowKey,
104
104
  message: `Expected exactly one row but found ${decoded.length}.`
105
105
  })))));
106
+ /** Column inventory of the supported v8 predecessor, independent of physical column order. */
107
+ const predecessorColumns = {
108
+ effect_agent_threads: [
109
+ "thread_id",
110
+ "created_at",
111
+ "tail_sequence",
112
+ "tail_digest",
113
+ "producer_epoch"
114
+ ],
115
+ effect_agent_canonical_batches: [
116
+ "thread_id",
117
+ "batch_id",
118
+ "first_sequence",
119
+ "last_sequence",
120
+ "batch_digest",
121
+ "tail_digest",
122
+ "batch_json"
123
+ ],
124
+ effect_agent_canonical_records: [
125
+ "thread_id",
126
+ "sequence",
127
+ "record_id",
128
+ "batch_id",
129
+ "record_json"
130
+ ],
131
+ effect_agent_checkpoints: [
132
+ "thread_id",
133
+ "through_sequence",
134
+ "tail_digest",
135
+ "checkpoint_json"
136
+ ],
137
+ effect_agent_submissions: [
138
+ "submission_id",
139
+ "thread_id",
140
+ "queue_sequence",
141
+ "principal",
142
+ "idempotency_key",
143
+ "agent_id",
144
+ "agent_digests_json",
145
+ "deployment_id",
146
+ "input_json",
147
+ "input_digest",
148
+ "receipt_id",
149
+ "state",
150
+ "settled_outcome",
151
+ "created_at",
152
+ "ready_at",
153
+ "input_applied_record_id",
154
+ "input_applied_sequence",
155
+ "joined_host_submission_id",
156
+ "suspended_reason_json",
157
+ "suspended_at",
158
+ "unknown_reason",
159
+ "unknown_tool_call_ids_json",
160
+ "parent_submission_id",
161
+ "parent_tool_call_id",
162
+ "admission_group",
163
+ "admission_fence_json"
164
+ ],
165
+ effect_agent_submission_ownership: [
166
+ "submission_id",
167
+ "attempt_id",
168
+ "ownership_token",
169
+ "producer_epoch",
170
+ "owner_producer_id",
171
+ "lease_expires_at"
172
+ ],
173
+ effect_agent_attempts: [
174
+ "attempt_id",
175
+ "submission_id",
176
+ "thread_id",
177
+ "owner_producer_id",
178
+ "producer_epoch",
179
+ "claimed_at"
180
+ ],
181
+ effect_agent_settlement_reservations: [
182
+ "submission_id",
183
+ "settlement_id",
184
+ "outcome",
185
+ "record_id",
186
+ "record_json",
187
+ "record_digest",
188
+ "reserved_at",
189
+ "finalized_at"
190
+ ],
191
+ effect_agent_abort_intents: [
192
+ "submission_id",
193
+ "author",
194
+ "reason",
195
+ "requested_at",
196
+ "canonical_record_id"
197
+ ],
198
+ effect_agent_approval_decisions: [
199
+ "submission_id",
200
+ "tool_call_id",
201
+ "decision",
202
+ "resolver",
203
+ "reason",
204
+ "decided_at"
205
+ ],
206
+ effect_agent_unknown_resolutions: [
207
+ "submission_id",
208
+ "tool_call_id",
209
+ "author",
210
+ "reason",
211
+ "resolution_json",
212
+ "resolved_at"
213
+ ],
214
+ effect_agent_child_reservations: [
215
+ "reservation_id",
216
+ "parent_submission_id",
217
+ "parent_tool_call_id",
218
+ "child_submission_id",
219
+ "status",
220
+ "allocation_json",
221
+ "allocation_digest",
222
+ "accounting_json",
223
+ "reserved_at",
224
+ "release_began_at",
225
+ "released_at"
226
+ ],
227
+ effect_agent_schedules: [
228
+ "tenant_id",
229
+ "owner_id",
230
+ "schedule_id",
231
+ "deadline_at_millis",
232
+ "record_json"
233
+ ],
234
+ effect_agent_subscription_sequences: [
235
+ "tenant_id",
236
+ "source_address",
237
+ "sequence",
238
+ "event_scan_cursor",
239
+ "delivery_scan_cursor",
240
+ "recovery_scan_cursor"
241
+ ],
242
+ effect_agent_subscriptions: [
243
+ "tenant_id",
244
+ "source_address",
245
+ "owner_id",
246
+ "subscription_id",
247
+ "ordinal",
248
+ "source_name",
249
+ "source_version",
250
+ "matching_key",
251
+ "state",
252
+ "expires_at_millis",
253
+ "recovery_at_millis",
254
+ "recovery_present",
255
+ "record_json"
256
+ ],
257
+ effect_agent_subscription_events: [
258
+ "tenant_id",
259
+ "source_address",
260
+ "event_id",
261
+ "source_name",
262
+ "source_version",
263
+ "matching_key",
264
+ "payload_digest",
265
+ "cutoff",
266
+ "cursor",
267
+ "routing_complete",
268
+ "next_attempt_at_millis",
269
+ "record_json",
270
+ "tombstone"
271
+ ],
272
+ effect_agent_subscription_deliveries: [
273
+ "tenant_id",
274
+ "source_address",
275
+ "owner_id",
276
+ "subscription_id",
277
+ "event_id",
278
+ "delivery_key",
279
+ "state",
280
+ "next_attempt_at_millis",
281
+ "record_json"
282
+ ]
283
+ };
284
+ const checkPredecessorLayout = Effect.fn("SqliteJournal.checkPredecessorLayout")(function* () {
285
+ const sql = yield* SqlClient.SqlClient;
286
+ for (const [table, expected] of Object.entries(predecessorColumns)) {
287
+ const columns = yield* decodeRows(Schema.Array(Schema.Struct({ name: BoundedIdentifier })), table, "schema", yield* sql.unsafe(`PRAGMA table_info(${table})`));
288
+ const names = new Set(expected);
289
+ if (columns.length !== names.size || columns.some((column) => !names.has(column.name))) return yield* SqliteStorageCompatibilityError.make({
290
+ actualVersion: 8,
291
+ supportedVersion: 9,
292
+ message: `The v8 ${table} columns do not match the supported predecessor; no upgrade was committed.`
293
+ });
294
+ }
295
+ });
106
296
  const initializeSqliteJournal = Effect.fn("SqliteJournal.initialize")(function* () {
107
297
  const sql = yield* SqlClient.SqlClient;
108
298
  const { hit: failpoint } = yield* SqliteStorageFailpoint;
@@ -113,38 +303,60 @@ const initializeSqliteJournal = Effect.fn("SqliteJournal.initialize")(function*
113
303
  const journalMode = yield* decodeSingleRow(Schema.Array(SqliteJournalModeRow), "pragma_journal_mode", "singleton", journalModeRows);
114
304
  if (journalMode.journal_mode.toLowerCase() !== "wal") return yield* SqliteStorageCompatibilityError.make({
115
305
  actualVersion: 0,
116
- supportedVersion: 8,
306
+ supportedVersion: 9,
117
307
  message: `SQLite WAL mode is required; the database reported ${journalMode.journal_mode}.`
118
308
  });
119
309
  const versionRows = yield* sql`PRAGMA user_version`.pipe(Effect.mapError(storageError("read storage version")));
120
310
  const version = yield* decodeSingleRow(Schema.Array(SqliteVersionRow), "pragma_user_version", "singleton", versionRows);
121
- if (version.user_version !== 0 && version.user_version !== 7 && version.user_version !== 8) return yield* SqliteStorageCompatibilityError.make({
311
+ if (version.user_version !== 0 && version.user_version !== 7 && version.user_version !== 8 && version.user_version !== 9) return yield* SqliteStorageCompatibilityError.make({
122
312
  actualVersion: version.user_version,
123
- supportedVersion: 8,
124
- message: `The SQLite file uses unsupported storage version ${version.user_version}; this build supports exactly version 8. Only unpatched v7 can be upgraded automatically. Keep the original file and use a compatible library version.`
313
+ supportedVersion: 9,
314
+ message: `The SQLite file uses unsupported storage version ${version.user_version}; this build supports exactly version 9. Only supported v7 and v8 can be upgraded automatically. Keep the original file and use a compatible library version.`
125
315
  });
126
- if (version.user_version === 7) yield* sql.withTransaction(Effect.gen(function* () {
316
+ if (version.user_version === 7 || version.user_version === 8) yield* sql.withTransaction(Effect.gen(function* () {
127
317
  const current = yield* sql`PRAGMA user_version`;
128
- if (current.length === 1 && current[0].user_version === 8) return;
129
- if (current.length !== 1 || current[0].user_version !== 7) return yield* SqliteStorageCompatibilityError.make({
318
+ if (current.length === 1 && current[0].user_version === 9) return;
319
+ if (current.length !== 1 || current[0].user_version !== 7 && current[0].user_version !== 8) return yield* SqliteStorageCompatibilityError.make({
130
320
  actualVersion: -1,
131
- supportedVersion: 8,
321
+ supportedVersion: 9,
132
322
  message: "Storage version changed while acquiring the upgrade transaction."
133
323
  });
134
- yield* checkV2ThreadLayout();
135
- for (const statement of [
136
- sql`ALTER TABLE effect_agent_submissions ADD COLUMN admission_group TEXT`,
137
- sql`ALTER TABLE effect_agent_submissions ADD COLUMN admission_fence_json TEXT`,
138
- sql`CREATE INDEX effect_agent_submissions_group ON effect_agent_submissions (thread_id, admission_group, state)`
139
- ]) {
140
- yield* failpoint("upgrade:before-mutation");
141
- yield* statement;
142
- yield* failpoint("upgrade:after-mutation");
324
+ if ((yield* sql`SELECT name FROM sqlite_master WHERE type='table' AND name IN (
325
+ 'effect_agent_threads', 'effect_agent_canonical_batches', 'effect_agent_canonical_records',
326
+ 'effect_agent_checkpoints', 'effect_agent_submissions', 'effect_agent_submission_ownership',
327
+ 'effect_agent_attempts', 'effect_agent_settlement_reservations', 'effect_agent_abort_intents',
328
+ 'effect_agent_approval_decisions', 'effect_agent_unknown_resolutions', 'effect_agent_schedules'
329
+ )`).length !== 12) return yield* SqliteStorageCompatibilityError.make({
330
+ actualVersion: current[0].user_version,
331
+ supportedVersion: 9,
332
+ message: "The predecessor store is missing required tables; no upgrade was committed."
333
+ });
334
+ if (current[0].user_version === 7) {
335
+ yield* checkV2ThreadLayout();
336
+ for (const statement of [
337
+ sql`ALTER TABLE effect_agent_submissions ADD COLUMN admission_group TEXT`,
338
+ sql`ALTER TABLE effect_agent_submissions ADD COLUMN admission_fence_json TEXT`,
339
+ sql`CREATE INDEX effect_agent_submissions_group ON effect_agent_submissions (thread_id, admission_group, state)`
340
+ ]) {
341
+ yield* failpoint("upgrade:before-mutation");
342
+ yield* statement;
343
+ yield* failpoint("upgrade:after-mutation");
344
+ }
345
+ yield* upgradeV2Schedules(16777216).pipe(Effect.provideService(ScheduleFailpoint, { hit: (point) => Schema.decodeUnknownEffect(SqliteStorageFailpointLocation)(point).pipe(Effect.flatMap(failpoint), Effect.mapError(() => ScheduleFailpointError.make({ point }))) }));
346
+ yield* upgradeV2Subscriptions(16777216).pipe(Effect.provideService(SubscriptionFailpoint, { hit: (point) => Schema.decodeUnknownEffect(SqliteStorageFailpointLocation)(point).pipe(Effect.flatMap(failpoint), Effect.mapError(() => SubscriptionFailpointError.make({ point }))) }));
143
347
  }
144
- yield* upgradeV2Schedules(16777216).pipe(Effect.provideService(ScheduleFailpoint, { hit: (point) => Schema.decodeUnknownEffect(SqliteStorageFailpointLocation)(point).pipe(Effect.flatMap(failpoint), Effect.mapError(() => ScheduleFailpointError.make({ point }))) }));
145
- yield* upgradeV2Subscriptions(16777216).pipe(Effect.provideService(SubscriptionFailpoint, { hit: (point) => Schema.decodeUnknownEffect(SqliteStorageFailpointLocation)(point).pipe(Effect.flatMap(failpoint), Effect.mapError(() => SubscriptionFailpointError.make({ point }))) }));
348
+ if (current[0].user_version === 8) yield* checkPredecessorLayout();
349
+ yield* failpoint("upgrade:before-mutation");
350
+ yield* sql`ALTER TABLE effect_agent_submissions ADD COLUMN worker_admission_json TEXT`;
351
+ yield* failpoint("upgrade:after-mutation");
352
+ yield* failpoint("upgrade:before-mutation");
353
+ yield* sql`ALTER TABLE effect_agent_submissions ADD COLUMN message_admission_json TEXT`;
354
+ yield* failpoint("upgrade:after-mutation");
355
+ yield* failpoint("upgrade:before-mutation");
356
+ yield* createMessageDeliveryTables;
357
+ yield* failpoint("upgrade:after-mutation");
146
358
  yield* failpoint("upgrade:before-version");
147
- yield* sql`PRAGMA user_version = 8`;
359
+ yield* sql`PRAGMA user_version = 9`;
148
360
  yield* failpoint("upgrade:after-version");
149
361
  })).pipe(Effect.provide(NodeCrypto.layer), Effect.catchTag("SqliteStorageFailpointError", (error) => SqliteStorageError.make({
150
362
  cause: error,
@@ -158,7 +370,7 @@ const initializeSqliteJournal = Effect.fn("SqliteJournal.initialize")(function*
158
370
  table: error.table,
159
371
  rowKey: error.rowKey,
160
372
  message: error.message
161
- })), Effect.catchTag("SqlError", storageError("upgrade v7 storage")), Effect.catchTag("SchemaError", (error) => SqliteStorageCorruptionError.make({
373
+ })), Effect.catchTag("SqlError", storageError("upgrade supported storage")), Effect.catchTag("SchemaError", (error) => SqliteStorageCorruptionError.make({
162
374
  table: "upgrade",
163
375
  rowKey: "v7",
164
376
  message: error.message
@@ -173,7 +385,7 @@ const initializeSqliteJournal = Effect.fn("SqliteJournal.initialize")(function*
173
385
  `.pipe(Effect.mapError(storageError("inspect unversioned storage")));
174
386
  if ((yield* decodeRows(Schema.Array(SqliteNameRow), "sqlite_master", "effect_agent_%", existingRows)).length > 0) return yield* SqliteStorageCompatibilityError.make({
175
387
  actualVersion: 0,
176
- supportedVersion: 8,
388
+ supportedVersion: 9,
177
389
  message: "The SQLite file contains unversioned Effect Agent tables. Refusing to mutate ambiguous stored data; retain it for inspection with its original writer."
178
390
  });
179
391
  yield* SqliteMigrator.run({ loader: sqliteMigrations }).pipe(Effect.mapError((error) => SqliteStorageError.make({
@@ -198,13 +410,14 @@ const initializeSqliteJournal = Effect.fn("SqliteJournal.initialize")(function*
198
410
  'effect_agent_abort_intents',
199
411
  'effect_agent_approval_decisions',
200
412
  'effect_agent_unknown_resolutions',
201
- 'effect_agent_schedules'
413
+ 'effect_agent_schedules',
414
+ 'effect_agent_message_deliveries'
202
415
  )
203
416
  ORDER BY name
204
417
  `.pipe(Effect.mapError(storageError("verify storage tables")));
205
- if ((yield* decodeRows(Schema.Array(SqliteNameRow), "sqlite_master", "required_tables", requiredRows)).length !== 12) return yield* SqliteStorageCompatibilityError.make({
206
- actualVersion: 8,
207
- supportedVersion: 8,
418
+ if ((yield* decodeRows(Schema.Array(SqliteNameRow), "sqlite_master", "required_tables", requiredRows)).length !== 13) return yield* SqliteStorageCompatibilityError.make({
419
+ actualVersion: 9,
420
+ supportedVersion: 9,
208
421
  message: "The SQLite file claims the current format but is missing required tables. Retain the original store for inspection."
209
422
  });
210
423
  const classifyWriteFailure = (operation) => (error) => error.reason._tag === "LockTimeoutError" ? SqliteWriteContention.make({
@@ -671,4 +884,4 @@ const initializeSqliteJournal = Effect.fn("SqliteJournal.initialize")(function*
671
884
  //#endregion
672
885
  export { initializeSqliteJournal as a, decodeRows as i, RawCheckpoint as n, RawReadRequest as r, RawAppendRequest as t };
673
886
 
674
- //# sourceMappingURL=sqlite-journal-Ce8lwVYx.mjs.map
887
+ //# sourceMappingURL=sqlite-journal-lDduEakl.mjs.map