@effect-agent/storage-sqlite 0.1.0-beta.6 → 0.1.0-beta.60

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.
Files changed (59) hide show
  1. package/dist/SqliteActivityStore.d.mts +14 -0
  2. package/dist/SqliteActivityStore.mjs +310 -0
  3. package/dist/SqliteActivityStore.mjs.map +1 -0
  4. package/dist/SqliteMessageDeliveryStore.d.mts +14 -0
  5. package/dist/SqliteMessageDeliveryStore.mjs +24 -0
  6. package/dist/SqliteMessageDeliveryStore.mjs.map +1 -0
  7. package/dist/SqliteScheduleStore.d.mts +14 -0
  8. package/dist/SqliteScheduleStore.mjs +255 -0
  9. package/dist/SqliteScheduleStore.mjs.map +1 -0
  10. package/dist/SqliteStorageConfig.d.mts +34 -0
  11. package/dist/SqliteStorageConfig.mjs +39 -0
  12. package/dist/SqliteStorageConfig.mjs.map +1 -0
  13. package/dist/SqliteStorageError-CzKmwCLl.d.mts +86 -0
  14. package/dist/SqliteStorageError.d.mts +2 -0
  15. package/dist/SqliteStorageError.mjs +148 -0
  16. package/dist/SqliteStorageError.mjs.map +1 -0
  17. package/dist/SqliteStorageFailpoint.d.mts +17 -0
  18. package/dist/SqliteStorageFailpoint.mjs +14 -0
  19. package/dist/SqliteStorageFailpoint.mjs.map +1 -0
  20. package/dist/SqliteStorageFailpointTesting.d.mts +15 -0
  21. package/dist/SqliteStorageFailpointTesting.mjs +19 -0
  22. package/dist/SqliteStorageFailpointTesting.mjs.map +1 -0
  23. package/dist/SqliteStorageVersion-gA7_96xM.d.mts +9 -0
  24. package/dist/SqliteStorageVersion.d.mts +2 -0
  25. package/dist/SqliteStorageVersion.mjs +8 -0
  26. package/dist/SqliteStorageVersion.mjs.map +1 -0
  27. package/dist/SqliteSubmissionLedger.d.mts +23 -0
  28. package/dist/SqliteSubmissionLedger.mjs +1765 -0
  29. package/dist/SqliteSubmissionLedger.mjs.map +1 -0
  30. package/dist/SqliteSubscriptionStore.d.mts +13 -0
  31. package/dist/SqliteSubscriptionStore.mjs +28 -0
  32. package/dist/SqliteSubscriptionStore.mjs.map +1 -0
  33. package/dist/SqliteThreadStore.d.mts +49 -0
  34. package/dist/SqliteThreadStore.mjs +427 -0
  35. package/dist/SqliteThreadStore.mjs.map +1 -0
  36. package/dist/index.d.mts +11 -193
  37. package/dist/index.mjs +11 -3082
  38. package/dist/migrations-dnTR0RKq.mjs +326 -0
  39. package/dist/migrations-dnTR0RKq.mjs.map +1 -0
  40. package/dist/rolldown-runtime-D7D4PA-g.mjs +13 -0
  41. package/dist/sqlite-journal-lDduEakl.mjs +887 -0
  42. package/dist/sqlite-journal-lDduEakl.mjs.map +1 -0
  43. package/package.json +1 -41
  44. package/src/SqliteActivityStore.ts +556 -0
  45. package/src/SqliteMessageDeliveryStore.ts +42 -0
  46. package/src/SqliteScheduleStore.ts +404 -0
  47. package/src/{sqlite-storage-config.ts → SqliteStorageConfig.ts} +1 -1
  48. package/src/{errors.ts → SqliteStorageError.ts} +8 -3
  49. package/src/SqliteStorageFailpoint.ts +23 -0
  50. package/src/{sqlite-storage-failpoint.ts → SqliteStorageFailpointTesting.ts} +7 -18
  51. package/src/SqliteStorageVersion.ts +2 -0
  52. package/src/{sqlite-ledger.ts → SqliteSubmissionLedger.ts} +753 -118
  53. package/src/SqliteSubscriptionStore.ts +59 -0
  54. package/src/{sqlite-conversation-store.ts → SqliteThreadStore.ts} +372 -302
  55. package/src/index.ts +10 -6
  56. package/src/internal/message-delivery-schema.ts +24 -0
  57. package/src/{migrations.ts → internal/migrations.ts} +145 -79
  58. package/src/{sqlite-journal.ts → internal/sqlite-journal.ts} +534 -222
  59. package/dist/index.mjs.map +0 -1
@@ -0,0 +1,887 @@
1
+ import { SqliteStorageConfig } from "./SqliteStorageConfig.mjs";
2
+ import { SqliteAppendConflict, SqliteCheckpointConflict, SqliteFenceRejected, SqliteStorageCompatibilityError, SqliteStorageCorruptionError, SqliteStorageError, SqliteStorageFailpointLocation, SqliteWriteContention } from "./SqliteStorageError.mjs";
3
+ import { SqliteStorageFailpoint } from "./SqliteStorageFailpoint.mjs";
4
+ import { n as sqliteMigrations, r as createMessageDeliveryTables } from "./migrations-dnTR0RKq.mjs";
5
+ import { Effect, Exit, Schema } from "effect";
6
+ import * as SqlClient from "effect/unstable/sql/SqlClient";
7
+ import { CanonicalSequence, ProducerEpoch } from "@effect-agent/thread/Records";
8
+ import { ScheduleFailpoint, ScheduleFailpointError } from "@effect-agent/thread/Schedule";
9
+ import { checkV2ThreadLayout, upgradeV2Schedules, upgradeV2Subscriptions } from "@effect-agent/thread/SqlStorageV2Upgrade";
10
+ import { SubscriptionFailpoint, SubscriptionFailpointError } from "@effect-agent/thread/Subscription";
11
+ import { NodeCrypto } from "@effect/platform-node";
12
+ import { SqliteMigrator } from "@effect/sql-sqlite-node";
13
+ //#region src/internal/sqlite-journal.ts
14
+ const BoundedStoredText = Schema.String.check(Schema.isMaxLength(16777216));
15
+ const BoundedIdentifier = Schema.NonEmptyString.check(Schema.isMaxLength(1024));
16
+ const NonNegativeInt = Schema.Int.check(Schema.isGreaterThanOrEqualTo(0));
17
+ const MAX_RECORDS_PER_THREAD = 65536;
18
+ const MAX_STORED_TEXT_BYTES = 16777216;
19
+ const MAX_IDENTIFIER_LENGTH = 1024;
20
+ const storedTextBytes = (value) => new TextEncoder().encode(value).byteLength;
21
+ var SqliteVersionRow = class extends Schema.Class("SqliteVersionRow")({ user_version: NonNegativeInt }) {};
22
+ var SqliteJournalModeRow = class extends Schema.Class("SqliteJournalModeRow")({ journal_mode: Schema.NonEmptyString.check(Schema.isMaxLength(32)) }) {};
23
+ var SqliteNameRow = class extends Schema.Class("SqliteNameRow")({ name: BoundedIdentifier }) {};
24
+ var ThreadRow = class extends Schema.Class("ThreadRow")({
25
+ thread_id: BoundedIdentifier,
26
+ created_at: Schema.NonEmptyString.check(Schema.isMaxLength(128)),
27
+ producer_epoch: ProducerEpoch,
28
+ tail_digest: BoundedStoredText,
29
+ tail_sequence: CanonicalSequence
30
+ }) {};
31
+ var BatchRow = class extends Schema.Class("BatchRow")({
32
+ batch_digest: BoundedStoredText,
33
+ batch_id: BoundedIdentifier,
34
+ batch_json: BoundedStoredText,
35
+ thread_id: BoundedIdentifier,
36
+ first_sequence: CanonicalSequence,
37
+ last_sequence: CanonicalSequence,
38
+ tail_digest: BoundedStoredText
39
+ }) {};
40
+ var RecordRow = class extends Schema.Class("RecordRow")({
41
+ batch_id: BoundedIdentifier,
42
+ thread_id: BoundedIdentifier,
43
+ record_id: BoundedIdentifier,
44
+ record_json: BoundedStoredText,
45
+ sequence: CanonicalSequence
46
+ }) {};
47
+ var CheckpointRow = class extends Schema.Class("CheckpointRow")({
48
+ checkpoint_json: BoundedStoredText,
49
+ thread_id: BoundedIdentifier,
50
+ tail_digest: BoundedStoredText,
51
+ through_sequence: CanonicalSequence
52
+ }) {};
53
+ var RawRecord = class extends Schema.Class("@effect-agent/storage-sqlite/RawRecord")({
54
+ recordId: BoundedIdentifier,
55
+ recordJson: BoundedStoredText
56
+ }) {};
57
+ var RawAppendRequest = class extends Schema.Class("@effect-agent/storage-sqlite/RawAppendRequest")({
58
+ batchDigest: BoundedStoredText,
59
+ batchId: BoundedIdentifier,
60
+ batchJson: BoundedStoredText,
61
+ threadId: BoundedIdentifier,
62
+ expectedTailDigest: BoundedStoredText,
63
+ expectedTailSequence: CanonicalSequence,
64
+ producerEpoch: ProducerEpoch,
65
+ records: Schema.NonEmptyArray(RawRecord).check(Schema.isMaxLength(256)),
66
+ tailDigest: BoundedStoredText
67
+ }) {};
68
+ var RawAppendResult = class extends Schema.Class("@effect-agent/storage-sqlite/RawAppendResult")({
69
+ firstSequence: CanonicalSequence,
70
+ lastSequence: CanonicalSequence,
71
+ replayed: Schema.Boolean,
72
+ tailDigest: BoundedStoredText
73
+ }) {};
74
+ var RawReadRequest = class extends Schema.Class("@effect-agent/storage-sqlite/RawReadRequest")({
75
+ threadId: BoundedIdentifier,
76
+ fromSequenceExclusive: CanonicalSequence,
77
+ limit: Schema.Int.check(Schema.isGreaterThan(0), Schema.isLessThanOrEqualTo(1024))
78
+ }) {};
79
+ var RawCheckpoint = class extends Schema.Class("@effect-agent/storage-sqlite/RawCheckpoint")({
80
+ checkpointJson: BoundedStoredText,
81
+ threadId: BoundedIdentifier,
82
+ tailDigest: BoundedStoredText,
83
+ throughSequence: CanonicalSequence
84
+ }) {};
85
+ var RawThreadExport = class extends Schema.Class("@effect-agent/storage-sqlite/RawThreadExport")({
86
+ thread: ThreadRow,
87
+ records: Schema.Array(RecordRow)
88
+ }) {};
89
+ const storageError = (operation) => (error) => SqliteStorageError.make({
90
+ cause: error,
91
+ operation,
92
+ message: error.message
93
+ });
94
+ /** Decode raw SQLite rows against a Schema, reporting failures as typed corruption. */
95
+ const decodeRows = Effect.fn("SqliteJournal.decodeRows")((schema, table, rowKey, rows) => Schema.decodeUnknownEffect(schema)(rows).pipe(Effect.mapError((error) => SqliteStorageCorruptionError.make({
96
+ table,
97
+ rowKey,
98
+ message: String(error)
99
+ }))));
100
+ /** Decode exactly one raw SQLite row against a Schema, reporting failures as typed corruption. */
101
+ const decodeSingleRow = Effect.fn("SqliteJournal.decodeSingleRow")((schema, table, rowKey, rows) => decodeRows(schema, table, rowKey, rows).pipe(Effect.flatMap((decoded) => decoded.length === 1 ? Effect.succeed(decoded[0]) : Effect.fail(SqliteStorageCorruptionError.make({
102
+ table,
103
+ rowKey,
104
+ message: `Expected exactly one row but found ${decoded.length}.`
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
+ });
296
+ const initializeSqliteJournal = Effect.fn("SqliteJournal.initialize")(function* () {
297
+ const sql = yield* SqlClient.SqlClient;
298
+ const { hit: failpoint } = yield* SqliteStorageFailpoint;
299
+ const { busyTimeout } = yield* SqliteStorageConfig;
300
+ yield* sql`PRAGMA foreign_keys = ON`.pipe(Effect.mapError(storageError("enable foreign keys")));
301
+ yield* sql.unsafe(`PRAGMA busy_timeout = ${busyTimeout}`).pipe(Effect.mapError(storageError("configure busy timeout")));
302
+ const journalModeRows = yield* sql`PRAGMA journal_mode`.pipe(Effect.mapError(storageError("read journal mode")));
303
+ const journalMode = yield* decodeSingleRow(Schema.Array(SqliteJournalModeRow), "pragma_journal_mode", "singleton", journalModeRows);
304
+ if (journalMode.journal_mode.toLowerCase() !== "wal") return yield* SqliteStorageCompatibilityError.make({
305
+ actualVersion: 0,
306
+ supportedVersion: 9,
307
+ message: `SQLite WAL mode is required; the database reported ${journalMode.journal_mode}.`
308
+ });
309
+ const versionRows = yield* sql`PRAGMA user_version`.pipe(Effect.mapError(storageError("read storage version")));
310
+ const version = yield* decodeSingleRow(Schema.Array(SqliteVersionRow), "pragma_user_version", "singleton", versionRows);
311
+ if (version.user_version !== 0 && version.user_version !== 7 && version.user_version !== 8 && version.user_version !== 9) return yield* SqliteStorageCompatibilityError.make({
312
+ actualVersion: version.user_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.`
315
+ });
316
+ if (version.user_version === 7 || version.user_version === 8) yield* sql.withTransaction(Effect.gen(function* () {
317
+ const current = yield* sql`PRAGMA user_version`;
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({
320
+ actualVersion: -1,
321
+ supportedVersion: 9,
322
+ message: "Storage version changed while acquiring the upgrade transaction."
323
+ });
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 }))) }));
347
+ }
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");
358
+ yield* failpoint("upgrade:before-version");
359
+ yield* sql`PRAGMA user_version = 9`;
360
+ yield* failpoint("upgrade:after-version");
361
+ })).pipe(Effect.provide(NodeCrypto.layer), Effect.catchTag("SqliteStorageFailpointError", (error) => SqliteStorageError.make({
362
+ cause: error,
363
+ operation: "upgrade storage",
364
+ message: error.message
365
+ })), Effect.catchTag(["ScheduleFailpointError", "SubscriptionFailpointError"], (error) => SqliteStorageError.make({
366
+ cause: error,
367
+ operation: "upgrade storage",
368
+ message: "Injected storage upgrade failure"
369
+ })), Effect.catchTag("StorageUpgradeError", (error) => SqliteStorageCorruptionError.make({
370
+ table: error.table,
371
+ rowKey: error.rowKey,
372
+ message: error.message
373
+ })), Effect.catchTag("SqlError", storageError("upgrade supported storage")), Effect.catchTag("SchemaError", (error) => SqliteStorageCorruptionError.make({
374
+ table: "upgrade",
375
+ rowKey: "v7",
376
+ message: error.message
377
+ })));
378
+ if (version.user_version === 0) {
379
+ const existingRows = yield* sql`
380
+ SELECT name
381
+ FROM sqlite_master
382
+ WHERE type = 'table'
383
+ AND name LIKE 'effect_agent_%'
384
+ ORDER BY name
385
+ `.pipe(Effect.mapError(storageError("inspect unversioned storage")));
386
+ if ((yield* decodeRows(Schema.Array(SqliteNameRow), "sqlite_master", "effect_agent_%", existingRows)).length > 0) return yield* SqliteStorageCompatibilityError.make({
387
+ actualVersion: 0,
388
+ supportedVersion: 9,
389
+ message: "The SQLite file contains unversioned Effect Agent tables. Refusing to mutate ambiguous stored data; retain it for inspection with its original writer."
390
+ });
391
+ yield* SqliteMigrator.run({ loader: sqliteMigrations }).pipe(Effect.mapError((error) => SqliteStorageError.make({
392
+ cause: error,
393
+ operation: "initialize current storage",
394
+ message: error.message
395
+ })));
396
+ }
397
+ const requiredRows = yield* sql`
398
+ SELECT name
399
+ FROM sqlite_master
400
+ WHERE type = 'table'
401
+ AND name IN (
402
+ 'effect_agent_threads',
403
+ 'effect_agent_canonical_batches',
404
+ 'effect_agent_canonical_records',
405
+ 'effect_agent_checkpoints',
406
+ 'effect_agent_submissions',
407
+ 'effect_agent_submission_ownership',
408
+ 'effect_agent_attempts',
409
+ 'effect_agent_settlement_reservations',
410
+ 'effect_agent_abort_intents',
411
+ 'effect_agent_approval_decisions',
412
+ 'effect_agent_unknown_resolutions',
413
+ 'effect_agent_schedules',
414
+ 'effect_agent_message_deliveries'
415
+ )
416
+ ORDER BY name
417
+ `.pipe(Effect.mapError(storageError("verify storage tables")));
418
+ if ((yield* decodeRows(Schema.Array(SqliteNameRow), "sqlite_master", "required_tables", requiredRows)).length !== 13) return yield* SqliteStorageCompatibilityError.make({
419
+ actualVersion: 9,
420
+ supportedVersion: 9,
421
+ message: "The SQLite file claims the current format but is missing required tables. Retain the original store for inspection."
422
+ });
423
+ const classifyWriteFailure = (operation) => (error) => error.reason._tag === "LockTimeoutError" ? SqliteWriteContention.make({
424
+ cause: error,
425
+ operation,
426
+ message: `Another producer holds the SQLite write lock; ${operation} is safe to retry.`
427
+ }) : storageError(operation)(error);
428
+ /**
429
+ * Runs one journal write transaction under `BEGIN IMMEDIATE`. SQLite's deferred `BEGIN`
430
+ * would let a read-then-write transaction start as a reader and fail with
431
+ * SQLITE_BUSY_SNAPSHOT on upgrade, which `busy_timeout` never retries. Taking the write
432
+ * lock up front keeps cross-owner contention inside the bounded busy retry; a lock
433
+ * timeout is classified as the retryable SqliteWriteContention. A failed `BEGIN` leaves
434
+ * no transaction, so no rollback is attempted for it.
435
+ *
436
+ * Journal write transactions are always top level. Nesting one inside another would
437
+ * deadlock the single-connection client, so new journal operations must not wrap this
438
+ * helper inside another transaction.
439
+ */
440
+ const withWriteTransaction = (operation) => (effect) => Effect.uninterruptibleMask((restore) => Effect.scoped(Effect.gen(function* () {
441
+ const connection = yield* sql.reserve.pipe(Effect.mapError(classifyWriteFailure(operation)));
442
+ yield* connection.executeUnprepared("BEGIN IMMEDIATE", [], void 0).pipe(Effect.mapError(classifyWriteFailure(operation)));
443
+ const exit = yield* restore(Effect.provideService(effect, sql.transactionService, [connection, 0])).pipe(Effect.exit);
444
+ if (Exit.isSuccess(exit)) {
445
+ yield* connection.executeUnprepared("COMMIT", [], void 0).pipe(Effect.mapError(classifyWriteFailure(operation)));
446
+ return exit.value;
447
+ }
448
+ yield* Effect.orDie(connection.executeUnprepared("ROLLBACK", [], void 0));
449
+ return yield* exit;
450
+ })).pipe(Effect.withSpan("SqliteJournal.withWriteTransaction", { attributes: { operation } })));
451
+ /**
452
+ * Runs a read-only snapshot under a deferred transaction. Effect's SQLite client now
453
+ * starts every writable-client `withTransaction` with `BEGIN IMMEDIATE`, which is the
454
+ * right default for mutations but would make exports take the write lock and block a
455
+ * concurrent append. Reserving the connection and beginning explicitly preserves the
456
+ * adapter's snapshot-with-concurrent-writer contract. As with the write helper, a failed
457
+ * `BEGIN` is reported directly because there is no transaction to roll back.
458
+ */
459
+ const withReadTransaction = (operation) => (effect) => Effect.uninterruptibleMask((restore) => Effect.scoped(Effect.gen(function* () {
460
+ const connection = yield* sql.reserve.pipe(Effect.mapError(storageError(operation)));
461
+ yield* connection.executeUnprepared("BEGIN", [], void 0).pipe(Effect.mapError(storageError(operation)));
462
+ const exit = yield* restore(Effect.provideService(effect, sql.transactionService, [connection, 0])).pipe(Effect.exit);
463
+ if (Exit.isSuccess(exit)) {
464
+ yield* connection.executeUnprepared("COMMIT", [], void 0).pipe(Effect.mapError(storageError(operation)));
465
+ return exit.value;
466
+ }
467
+ yield* Effect.orDie(connection.executeUnprepared("ROLLBACK", [], void 0));
468
+ return yield* exit;
469
+ })).pipe(Effect.withSpan("SqliteJournal.withReadTransaction", { attributes: { operation } })));
470
+ const materialize = Effect.fn("SqliteJournal.materialize")(function* (threadId, createdAt, emptyTailDigest, producerEpoch) {
471
+ if (threadId.length > MAX_IDENTIFIER_LENGTH || storedTextBytes(emptyTailDigest) > MAX_STORED_TEXT_BYTES) return yield* SqliteStorageError.make({
472
+ operation: "materialize thread",
473
+ message: "Thread identity or initial digest exceeds the SQLite storage bounds."
474
+ });
475
+ yield* withWriteTransaction("materialize transaction")(Effect.gen(function* () {
476
+ const existingRows = yield* sql`
477
+ SELECT
478
+ thread_id,
479
+ created_at,
480
+ tail_sequence,
481
+ tail_digest,
482
+ producer_epoch
483
+ FROM effect_agent_threads
484
+ WHERE thread_id = ${threadId}
485
+ `.pipe(Effect.mapError(storageError("read materialized thread")));
486
+ const existing = yield* decodeRows(Schema.Array(ThreadRow), "effect_agent_threads", threadId, existingRows);
487
+ if (existing.length > 1) return yield* SqliteStorageCorruptionError.make({
488
+ table: "effect_agent_threads",
489
+ rowKey: threadId,
490
+ message: "A thread primary key returned more than one row."
491
+ });
492
+ if (existing.length === 0) {
493
+ yield* sql`
494
+ INSERT INTO effect_agent_threads (
495
+ thread_id,
496
+ created_at,
497
+ tail_sequence,
498
+ tail_digest,
499
+ producer_epoch
500
+ ) VALUES (
501
+ ${threadId},
502
+ ${createdAt},
503
+ 0,
504
+ ${emptyTailDigest},
505
+ ${producerEpoch}
506
+ )
507
+ `.pipe(Effect.mapError(storageError("materialize thread")));
508
+ return;
509
+ }
510
+ if (producerEpoch < existing[0].producer_epoch) return yield* SqliteFenceRejected.make({
511
+ producerEpoch,
512
+ actualEpoch: existing[0].producer_epoch,
513
+ message: `Producer epoch ${producerEpoch} is stale; current epoch is ${existing[0].producer_epoch}.`
514
+ });
515
+ if (producerEpoch > existing[0].producer_epoch) yield* sql`
516
+ UPDATE effect_agent_threads
517
+ SET producer_epoch = ${producerEpoch}
518
+ WHERE thread_id = ${threadId}
519
+ `.pipe(Effect.mapError(storageError("advance materialization epoch")));
520
+ }));
521
+ });
522
+ const getThread = Effect.fn("SqliteJournal.getThread")(function* (threadId) {
523
+ const rows = yield* sql`
524
+ SELECT
525
+ thread_id,
526
+ created_at,
527
+ tail_sequence,
528
+ tail_digest,
529
+ producer_epoch
530
+ FROM effect_agent_threads
531
+ WHERE thread_id = ${threadId}
532
+ `.pipe(Effect.mapError(storageError("read thread")));
533
+ return yield* decodeRows(Schema.Array(ThreadRow), "effect_agent_threads", threadId, rows);
534
+ });
535
+ const append = Effect.fn("SqliteJournal.append")(function* (request) {
536
+ if (request.threadId.length > MAX_IDENTIFIER_LENGTH || request.batchId.length > MAX_IDENTIFIER_LENGTH || storedTextBytes(request.batchJson) > MAX_STORED_TEXT_BYTES || storedTextBytes(request.batchDigest) > MAX_STORED_TEXT_BYTES || storedTextBytes(request.tailDigest) > MAX_STORED_TEXT_BYTES || request.records.some((record) => record.recordId.length > MAX_IDENTIFIER_LENGTH || storedTextBytes(record.recordJson) > MAX_STORED_TEXT_BYTES)) return yield* SqliteStorageError.make({
537
+ operation: "append canonical batch",
538
+ message: "Canonical identifiers or encoded JSON exceed the SQLite storage bounds."
539
+ });
540
+ return yield* withWriteTransaction("append transaction")(Effect.gen(function* () {
541
+ const recordIds = request.records.map((record) => record.recordId);
542
+ if (new Set(recordIds).size !== recordIds.length) return yield* SqliteAppendConflict.make({
543
+ message: `Batch ${request.batchId} contains duplicate canonical record IDs.`,
544
+ reason: "record-identity"
545
+ });
546
+ const threadRows = yield* sql`
547
+ SELECT
548
+ thread_id,
549
+ created_at,
550
+ tail_sequence,
551
+ tail_digest,
552
+ producer_epoch
553
+ FROM effect_agent_threads
554
+ WHERE thread_id = ${request.threadId}
555
+ `.pipe(Effect.mapError(storageError("read append tail")));
556
+ const thread = yield* decodeSingleRow(Schema.Array(ThreadRow), "effect_agent_threads", request.threadId, threadRows);
557
+ if (request.producerEpoch !== thread.producer_epoch) return yield* SqliteFenceRejected.make({
558
+ producerEpoch: request.producerEpoch,
559
+ actualEpoch: thread.producer_epoch,
560
+ message: `Producer epoch ${request.producerEpoch} is not the current epoch ${thread.producer_epoch}.`
561
+ });
562
+ const batchRows = yield* sql`
563
+ SELECT
564
+ thread_id,
565
+ batch_id,
566
+ first_sequence,
567
+ last_sequence,
568
+ batch_digest,
569
+ tail_digest,
570
+ batch_json
571
+ FROM effect_agent_canonical_batches
572
+ WHERE thread_id = ${request.threadId}
573
+ AND batch_id = ${request.batchId}
574
+ `.pipe(Effect.mapError(storageError("read idempotent batch")));
575
+ const batches = yield* decodeRows(Schema.Array(BatchRow), "effect_agent_canonical_batches", `${request.threadId}/${request.batchId}`, batchRows);
576
+ if (batches.length > 1) return yield* SqliteStorageCorruptionError.make({
577
+ table: "effect_agent_canonical_batches",
578
+ rowKey: `${request.threadId}/${request.batchId}`,
579
+ message: "A canonical batch primary key returned more than one row."
580
+ });
581
+ if (batches.length === 1) {
582
+ const existing = batches[0];
583
+ if (existing.batch_digest !== request.batchDigest) return yield* SqliteAppendConflict.make({
584
+ message: `Batch ${request.batchId} already exists with different canonical content.`,
585
+ reason: "batch-digest"
586
+ });
587
+ return RawAppendResult.make({
588
+ firstSequence: existing.first_sequence,
589
+ lastSequence: existing.last_sequence,
590
+ replayed: true,
591
+ tailDigest: existing.tail_digest
592
+ });
593
+ }
594
+ if (request.expectedTailSequence !== thread.tail_sequence || request.expectedTailDigest !== thread.tail_digest) return yield* SqliteAppendConflict.make({
595
+ message: `Expected tail ${request.expectedTailSequence}/${request.expectedTailDigest} but found ${thread.tail_sequence}/${thread.tail_digest}.`,
596
+ reason: "tail",
597
+ actualTailSequence: thread.tail_sequence,
598
+ actualTailDigest: thread.tail_digest
599
+ });
600
+ if (thread.tail_sequence + request.records.length > MAX_RECORDS_PER_THREAD) return yield* SqliteStorageError.make({
601
+ operation: "append canonical batch",
602
+ message: `Thread record limit ${MAX_RECORDS_PER_THREAD} would be exceeded.`
603
+ });
604
+ const existingRecordRows = yield* sql`
605
+ SELECT
606
+ thread_id,
607
+ sequence,
608
+ record_id,
609
+ batch_id,
610
+ record_json
611
+ FROM effect_agent_canonical_records
612
+ WHERE thread_id = ${request.threadId}
613
+ AND record_id IN ${sql.in(recordIds)}
614
+ ORDER BY sequence
615
+ `.pipe(Effect.mapError(storageError("check canonical record identities")));
616
+ const existingRecords = yield* decodeRows(Schema.Array(RecordRow), "effect_agent_canonical_records", `${request.threadId}/record_ids`, existingRecordRows);
617
+ if (existingRecords.length > 0) return yield* SqliteAppendConflict.make({
618
+ message: `Canonical record ID ${existingRecords[0].record_id} already exists.`,
619
+ reason: "record-identity"
620
+ });
621
+ const firstSequence = yield* Schema.decodeUnknownEffect(CanonicalSequence)(thread.tail_sequence + 1).pipe(Effect.mapError((error) => SqliteStorageError.make({
622
+ cause: error,
623
+ operation: "append canonical batch",
624
+ message: error.message
625
+ })));
626
+ const lastSequence = yield* Schema.decodeUnknownEffect(CanonicalSequence)(firstSequence + request.records.length - 1).pipe(Effect.mapError((error) => SqliteStorageError.make({
627
+ cause: error,
628
+ operation: "append canonical batch",
629
+ message: error.message
630
+ })));
631
+ yield* sql`
632
+ INSERT INTO effect_agent_canonical_batches (
633
+ thread_id,
634
+ batch_id,
635
+ first_sequence,
636
+ last_sequence,
637
+ batch_digest,
638
+ tail_digest,
639
+ batch_json
640
+ ) VALUES (
641
+ ${request.threadId},
642
+ ${request.batchId},
643
+ ${firstSequence},
644
+ ${lastSequence},
645
+ ${request.batchDigest},
646
+ ${request.tailDigest},
647
+ ${request.batchJson}
648
+ )
649
+ `.pipe(Effect.mapError(storageError("insert canonical batch")));
650
+ yield* failpoint("append:after-batch-insert");
651
+ yield* Effect.forEach(request.records, (record, index) => Effect.gen(function* () {
652
+ yield* sql`
653
+ INSERT INTO effect_agent_canonical_records (
654
+ thread_id,
655
+ sequence,
656
+ record_id,
657
+ batch_id,
658
+ record_json
659
+ ) VALUES (
660
+ ${request.threadId},
661
+ ${firstSequence + index},
662
+ ${record.recordId},
663
+ ${request.batchId},
664
+ ${record.recordJson}
665
+ )
666
+ `.pipe(Effect.mapError(storageError("insert canonical record")));
667
+ yield* failpoint("append:after-record-insert");
668
+ }), { discard: true });
669
+ yield* sql`
670
+ UPDATE effect_agent_threads
671
+ SET
672
+ tail_sequence = ${lastSequence},
673
+ tail_digest = ${request.tailDigest},
674
+ producer_epoch = ${request.producerEpoch}
675
+ WHERE thread_id = ${request.threadId}
676
+ `.pipe(Effect.mapError(storageError("advance thread tail")));
677
+ yield* failpoint("append:after-tail-update");
678
+ return RawAppendResult.make({
679
+ firstSequence,
680
+ lastSequence,
681
+ replayed: false,
682
+ tailDigest: request.tailDigest
683
+ });
684
+ }));
685
+ });
686
+ const read = Effect.fn("SqliteJournal.read")(function* (request) {
687
+ const rows = yield* sql`
688
+ SELECT
689
+ thread_id,
690
+ sequence,
691
+ record_id,
692
+ batch_id,
693
+ record_json
694
+ FROM effect_agent_canonical_records
695
+ WHERE thread_id = ${request.threadId}
696
+ AND sequence > ${request.fromSequenceExclusive}
697
+ ORDER BY sequence
698
+ LIMIT ${request.limit}
699
+ `.pipe(Effect.mapError(storageError("read canonical records")));
700
+ return yield* decodeRows(Schema.Array(RecordRow), "effect_agent_canonical_records", `${request.threadId}>${request.fromSequenceExclusive}`, rows);
701
+ });
702
+ const exportThread = Effect.fn("SqliteJournal.exportThread")(function* (threadId) {
703
+ return yield* withReadTransaction("export transaction")(Effect.gen(function* () {
704
+ const threadRows = yield* sql`
705
+ SELECT
706
+ thread_id,
707
+ created_at,
708
+ tail_sequence,
709
+ tail_digest,
710
+ producer_epoch
711
+ FROM effect_agent_threads
712
+ WHERE thread_id = ${threadId}
713
+ `.pipe(Effect.mapError(storageError("export thread")));
714
+ const thread = yield* decodeSingleRow(Schema.Array(ThreadRow), "effect_agent_threads", threadId, threadRows);
715
+ yield* failpoint("export:after-thread-read");
716
+ const recordRows = yield* sql`
717
+ SELECT
718
+ thread_id,
719
+ sequence,
720
+ record_id,
721
+ batch_id,
722
+ record_json
723
+ FROM effect_agent_canonical_records
724
+ WHERE thread_id = ${threadId}
725
+ ORDER BY sequence
726
+ `.pipe(Effect.mapError(storageError("export canonical records")));
727
+ return RawThreadExport.make({
728
+ thread,
729
+ records: yield* decodeRows(Schema.Array(RecordRow), "effect_agent_canonical_records", threadId, recordRows)
730
+ });
731
+ }));
732
+ });
733
+ const saveCheckpoint = Effect.fn("SqliteJournal.saveCheckpoint")(function* (checkpoint) {
734
+ if (checkpoint.threadId.length > MAX_IDENTIFIER_LENGTH || storedTextBytes(checkpoint.checkpointJson) > MAX_STORED_TEXT_BYTES) return yield* SqliteStorageError.make({
735
+ operation: "save checkpoint",
736
+ message: "Checkpoint identity or encoded JSON exceeds the SQLite storage bounds."
737
+ });
738
+ yield* withWriteTransaction("checkpoint transaction")(Effect.gen(function* () {
739
+ const threadRows = yield* sql`
740
+ SELECT
741
+ thread_id,
742
+ created_at,
743
+ tail_sequence,
744
+ tail_digest,
745
+ producer_epoch
746
+ FROM effect_agent_threads
747
+ WHERE thread_id = ${checkpoint.threadId}
748
+ `.pipe(Effect.mapError(storageError("read checkpoint tail")));
749
+ const thread = yield* decodeSingleRow(Schema.Array(ThreadRow), "effect_agent_threads", checkpoint.threadId, threadRows);
750
+ if (checkpoint.throughSequence > thread.tail_sequence) return yield* SqliteCheckpointConflict.make({ message: `Checkpoint sequence ${checkpoint.throughSequence} is after canonical tail ${thread.tail_sequence}.` });
751
+ const checkpointRows = yield* sql`
752
+ SELECT
753
+ thread_id,
754
+ through_sequence,
755
+ tail_digest,
756
+ checkpoint_json
757
+ FROM effect_agent_checkpoints
758
+ WHERE thread_id = ${checkpoint.threadId}
759
+ AND through_sequence = ${checkpoint.throughSequence}
760
+ `.pipe(Effect.mapError(storageError("read idempotent checkpoint")));
761
+ const existing = yield* decodeRows(Schema.Array(CheckpointRow), "effect_agent_checkpoints", `${checkpoint.threadId}/${checkpoint.throughSequence}`, checkpointRows);
762
+ if (existing.length > 1) return yield* SqliteStorageCorruptionError.make({
763
+ table: "effect_agent_checkpoints",
764
+ rowKey: `${checkpoint.threadId}/${checkpoint.throughSequence}`,
765
+ message: "A checkpoint primary key returned more than one row."
766
+ });
767
+ if (existing.length === 1) {
768
+ if (existing[0].tail_digest !== checkpoint.tailDigest || existing[0].checkpoint_json !== checkpoint.checkpointJson) return yield* SqliteCheckpointConflict.make({ message: "A different checkpoint already exists at this canonical sequence." });
769
+ return;
770
+ }
771
+ yield* sql`
772
+ INSERT INTO effect_agent_checkpoints (
773
+ thread_id,
774
+ through_sequence,
775
+ tail_digest,
776
+ checkpoint_json
777
+ ) VALUES (
778
+ ${checkpoint.threadId},
779
+ ${checkpoint.throughSequence},
780
+ ${checkpoint.tailDigest},
781
+ ${checkpoint.checkpointJson}
782
+ )
783
+ `.pipe(Effect.mapError(storageError("insert checkpoint")));
784
+ }));
785
+ });
786
+ const loadCheckpoint = Effect.fn("SqliteJournal.loadCheckpoint")(function* (threadId, atOrBeforeSequence) {
787
+ const rows = yield* sql`
788
+ SELECT
789
+ thread_id,
790
+ through_sequence,
791
+ tail_digest,
792
+ checkpoint_json
793
+ FROM effect_agent_checkpoints
794
+ WHERE thread_id = ${threadId}
795
+ AND through_sequence <= ${atOrBeforeSequence}
796
+ ORDER BY through_sequence DESC
797
+ LIMIT 1
798
+ `.pipe(Effect.mapError(storageError("load checkpoint")));
799
+ return yield* decodeRows(Schema.Array(CheckpointRow), "effect_agent_checkpoints", `${threadId}<=${atOrBeforeSequence}`, rows);
800
+ });
801
+ return {
802
+ append,
803
+ exportThread,
804
+ getThread,
805
+ getTailDigestAt: Effect.fn("SqliteJournal.getTailDigestAt")(function* (threadId, sequence) {
806
+ if (sequence === 0) {
807
+ const threads = yield* getThread(threadId);
808
+ return threads.length === 0 ? [] : [threads[0].tail_sequence === 0 ? threads[0].tail_digest : void 0].filter((value) => value !== void 0);
809
+ }
810
+ const rows = yield* sql`
811
+ SELECT
812
+ thread_id,
813
+ batch_id,
814
+ first_sequence,
815
+ last_sequence,
816
+ batch_digest,
817
+ tail_digest,
818
+ batch_json
819
+ FROM effect_agent_canonical_batches
820
+ WHERE thread_id = ${threadId}
821
+ AND last_sequence = ${sequence}
822
+ `.pipe(Effect.mapError(storageError("read canonical digest at sequence")));
823
+ return (yield* decodeRows(Schema.Array(BatchRow), "effect_agent_canonical_batches", `${threadId}/${sequence}`, rows)).map((batch) => batch.tail_digest);
824
+ }),
825
+ loadCheckpoint,
826
+ materialize,
827
+ read,
828
+ saveCheckpoint,
829
+ scanStoredPayloads: Effect.fn("SqliteJournal.scanStoredPayloads")(function* () {
830
+ return yield* withReadTransaction("startup scan transaction")(Effect.gen(function* () {
831
+ const threads = yield* sql`
832
+ SELECT
833
+ thread_id,
834
+ created_at,
835
+ tail_sequence,
836
+ tail_digest,
837
+ producer_epoch
838
+ FROM effect_agent_threads
839
+ ORDER BY thread_id
840
+ `.pipe(Effect.mapError(storageError("scan threads")));
841
+ const batches = yield* sql`
842
+ SELECT
843
+ thread_id,
844
+ batch_id,
845
+ first_sequence,
846
+ last_sequence,
847
+ batch_digest,
848
+ tail_digest,
849
+ batch_json
850
+ FROM effect_agent_canonical_batches
851
+ ORDER BY thread_id, first_sequence
852
+ `.pipe(Effect.mapError(storageError("scan canonical batches")));
853
+ const records = yield* sql`
854
+ SELECT
855
+ thread_id,
856
+ sequence,
857
+ record_id,
858
+ batch_id,
859
+ record_json
860
+ FROM effect_agent_canonical_records
861
+ ORDER BY thread_id, sequence
862
+ `.pipe(Effect.mapError(storageError("scan canonical records")));
863
+ const checkpoints = yield* sql`
864
+ SELECT
865
+ thread_id,
866
+ through_sequence,
867
+ tail_digest,
868
+ checkpoint_json
869
+ FROM effect_agent_checkpoints
870
+ ORDER BY thread_id, through_sequence
871
+ `.pipe(Effect.mapError(storageError("scan checkpoints")));
872
+ return {
873
+ threads: yield* decodeRows(Schema.Array(ThreadRow), "effect_agent_threads", "startup_scan", threads),
874
+ batches: yield* decodeRows(Schema.Array(BatchRow), "effect_agent_canonical_batches", "startup_scan", batches),
875
+ records: yield* decodeRows(Schema.Array(RecordRow), "effect_agent_canonical_records", "startup_scan", records),
876
+ checkpoints: yield* decodeRows(Schema.Array(CheckpointRow), "effect_agent_checkpoints", "startup_scan", checkpoints)
877
+ };
878
+ }));
879
+ }),
880
+ withWriteTransaction,
881
+ withReadTransaction
882
+ };
883
+ });
884
+ //#endregion
885
+ export { initializeSqliteJournal as a, decodeRows as i, RawCheckpoint as n, RawReadRequest as r, RawAppendRequest as t };
886
+
887
+ //# sourceMappingURL=sqlite-journal-lDduEakl.mjs.map