@yielded/agent-storage-cloudflare 0.1.0-beta.174 → 0.1.0-beta.176

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 (41) hide show
  1. package/dist/DoMemoryStore.mjs +1 -1
  2. package/dist/DoMessageDeliveryStore.mjs +1 -1
  3. package/dist/DoStorageFailpoint.d.mts +3 -1
  4. package/dist/DoStorageFailpoint.mjs +7 -2
  5. package/dist/DoStorageFailpoint.mjs.map +1 -1
  6. package/dist/{DoStorageVersion-NKnQU3eR.d.mts → DoStorageVersion-Mc7CXMdN.d.mts} +2 -2
  7. package/dist/DoStorageVersion.d.mts +1 -1
  8. package/dist/DoStorageVersion.mjs +2 -2
  9. package/dist/DoSubmissionLedger.d.mts +1 -1
  10. package/dist/DoSubmissionLedger.mjs +194 -98
  11. package/dist/DoSubmissionLedger.mjs.map +1 -1
  12. package/dist/{DoThreadStore-Bd4fTns3.d.mts → DoThreadStore-BzYJjm4O.d.mts} +18 -8
  13. package/dist/{DoThreadStore-DyzOZDXK.mjs → DoThreadStore-DG0h5J6u.mjs} +25 -19
  14. package/dist/DoThreadStore-DG0h5J6u.mjs.map +1 -0
  15. package/dist/DoThreadStore.d.mts +2 -2
  16. package/dist/DoThreadStore.mjs +3 -2
  17. package/dist/PortProtocol.d.mts +7201 -7201
  18. package/dist/PortRouting.mjs +21 -11
  19. package/dist/PortRouting.mjs.map +1 -1
  20. package/dist/{do-journal-ZMAzzENZ.mjs → do-journal-ySC3eXNv.mjs} +144 -45
  21. package/dist/do-journal-ySC3eXNv.mjs.map +1 -0
  22. package/dist/index.d.mts +2 -2
  23. package/dist/index.mjs +1 -1
  24. package/dist/{migrations-C3N9GN6A.mjs → migrations-CAO_akhD.mjs} +45 -22
  25. package/dist/migrations-CAO_akhD.mjs.map +1 -0
  26. package/dist/{owned-state-DcFh0YNo.mjs → owned-state-BgGOA2Ak.mjs} +4 -3
  27. package/dist/owned-state-BgGOA2Ak.mjs.map +1 -0
  28. package/package.json +1 -1
  29. package/src/DoStorageFailpoint.ts +4 -0
  30. package/src/DoSubmissionLedger.ts +430 -228
  31. package/src/DoThreadStore.ts +25 -44
  32. package/src/PortRouting.ts +57 -31
  33. package/src/internal/do-journal.ts +318 -70
  34. package/src/internal/migrations.ts +52 -10
  35. package/src/internal/owned-state.ts +12 -5
  36. package/src/internal/prompt-checkpoint.ts +6 -3
  37. package/src/internal/storage-span.ts +14 -10
  38. package/dist/DoThreadStore-DyzOZDXK.mjs.map +0 -1
  39. package/dist/do-journal-ZMAzzENZ.mjs.map +0 -1
  40. package/dist/migrations-C3N9GN6A.mjs.map +0 -1
  41. package/dist/owned-state-DcFh0YNo.mjs.map +0 -1
@@ -1,13 +1,14 @@
1
1
  import { DoStorageCompatibilityError, DoStorageCorruptionError, DoStorageError } from "./DoStorageError.mjs";
2
2
  import { backfillPeerMessageRetention } from "@yielded/agent-storage-sql/sql-message-delivery-store";
3
- import { Effect, Schema } from "effect";
3
+ import { SqlStorageOwner } from "@yielded/agent/sql-memory-store";
4
+ import { Effect, Option, Schema } from "effect";
4
5
  import * as SqlClient$1 from "effect/sql/SqlClient";
5
6
  import { createSqlThreadWorkTables } from "@yielded/agent-storage-sql/sql-thread-work";
6
7
  import { CURRENT_RECORD_FORMAT } from "@yielded/agent/records";
7
8
  import { SQL_PROMPT_PREDICATE, upgradeExecutionCheckpoints } from "@yielded/agent-storage-sql/sql-thread-native-reads";
8
9
  import { makeSqliteLayoutInspection } from "@yielded/agent-storage-sql/sqlite-layout-inspection";
9
10
  //#region src/internal/migrations.ts
10
- const CurrentDoStorageVersion = 27;
11
+ const CurrentDoStorageVersion = 28;
11
12
  /** Fresh layout only. Unsupported stores are rejected before these statements execute. */
12
13
  const layoutStatements = [
13
14
  "CREATE TABLE effect_agent_threads ( thread_id TEXT PRIMARY KEY NOT NULL, created_at TEXT, tail_sequence INTEGER NOT NULL, work_version INTEGER NOT NULL DEFAULT 3, work_state TEXT NOT NULL DEFAULT 'ready', work_through_sequence INTEGER NOT NULL DEFAULT 0, work_reporting INTEGER NOT NULL DEFAULT 0, work_entry_count INTEGER NOT NULL DEFAULT 0, worker_input_sequence INTEGER, worker_settlement_sequence INTEGER )",
@@ -60,7 +61,6 @@ const layoutStatements = [
60
61
  "CREATE TABLE effect_agent_archive_batches (thread_id TEXT NOT NULL, batch_id TEXT NOT NULL, range_first_sequence INTEGER NOT NULL, batch_json TEXT NOT NULL, PRIMARY KEY (thread_id, batch_id), FOREIGN KEY (thread_id, batch_id) REFERENCES effect_agent_canonical_batches(thread_id, batch_id) ON DELETE RESTRICT, CONSTRAINT effect_agent_archive_batches_range_fkey FOREIGN KEY (thread_id, range_first_sequence) REFERENCES effect_agent_journal_ranges(thread_id, first_sequence) ON DELETE RESTRICT)",
61
62
  "CREATE TABLE effect_agent_archive_records (thread_id TEXT NOT NULL, sequence INTEGER NOT NULL, range_first_sequence INTEGER NOT NULL, record_json TEXT NOT NULL, PRIMARY KEY (thread_id, sequence), FOREIGN KEY (thread_id, sequence) REFERENCES effect_agent_canonical_records(thread_id, sequence) ON DELETE RESTRICT, CONSTRAINT effect_agent_archive_records_range_fkey FOREIGN KEY (thread_id, range_first_sequence) REFERENCES effect_agent_journal_ranges(thread_id, first_sequence) ON DELETE RESTRICT)",
62
63
  "CREATE UNIQUE INDEX effect_agent_canonical_batches_sequence ON effect_agent_canonical_batches(thread_id, first_sequence)",
63
- "CREATE INDEX effect_agent_canonical_batches_last ON effect_agent_canonical_batches(thread_id, last_sequence)",
64
64
  "CREATE TABLE effect_agent_live_child_reservations (reservation_id TEXT PRIMARY KEY NOT NULL, thread_id TEXT NOT NULL)",
65
65
  "CREATE INDEX effect_agent_live_child_reservations_thread ON effect_agent_live_child_reservations(thread_id, reservation_id)",
66
66
  "CREATE TABLE effect_agent_import_delivery_visits (thread_id TEXT NOT NULL, message_id TEXT NOT NULL, path_id TEXT NOT NULL, completed INTEGER NOT NULL, PRIMARY KEY (thread_id, message_id))",
@@ -86,7 +86,7 @@ const Legacy = Schema.Tuple([Schema.Struct({
86
86
  })]);
87
87
  const incompatible = (actualVersion, message) => DoStorageCompatibilityError.make({
88
88
  actualVersion,
89
- supportedVersion: 27,
89
+ supportedVersion: 28,
90
90
  message: `${message} Keep the original store; the store was not changed.`
91
91
  });
92
92
  const storageError = (cause) => DoStorageError.make({
@@ -108,10 +108,12 @@ const inspection = (version, statements) => makeSqliteLayoutInspection({
108
108
  })
109
109
  });
110
110
  const addedIndexes = /* @__PURE__ */ new Set(["effect_agent_message_deliveries_peer_retained"]);
111
- const layout25Statements = layoutObjects(layoutStatements).filter(([, name]) => !addedIndexes.has(name)).map(([, , index]) => layoutStatements[index].replace(", peer_retained_until_millis INTEGER", "").replace("'$.envelope.messageAdmission.peerName') IS NOT NULL", "'$.envelope.messageAdmission.schemaVersion') = 1"));
112
- const { decode, readObjects, readHeader } = inspection(27, layoutStatements);
111
+ const layout27Statements = [...layoutStatements, "CREATE INDEX effect_agent_canonical_batches_last ON effect_agent_canonical_batches(thread_id, last_sequence)"];
112
+ const layout25Statements = layoutObjects(layout27Statements).filter(([, name]) => !addedIndexes.has(name)).map(([, , index]) => layout27Statements[index].replace(", peer_retained_until_millis INTEGER", "").replace("'$.envelope.messageAdmission.peerName') IS NOT NULL", "'$.envelope.messageAdmission.schemaVersion') = 1"));
113
+ const { decode, readObjects, readHeader } = inspection(28, layoutStatements);
113
114
  const layout25 = inspection(25, layout25Statements);
114
- const layout26 = inspection(26, layoutStatements);
115
+ const layout26 = inspection(26, layout27Statements);
116
+ const layout27 = inspection(27, layout27Statements);
115
117
  const inspectStorage = Effect.fnUntraced(function* (allowUpgrade = false) {
116
118
  const sql = (yield* SqlClient$1.SqlClient).withoutTransforms();
117
119
  const objects = yield* readObjects();
@@ -123,9 +125,9 @@ const inspectStorage = Effect.fnUntraced(function* (allowUpgrade = false) {
123
125
  SELECT * FROM effect_agent_meta WHERE key = 'storage_version'
124
126
  `.pipe(Effect.mapError(storageError)), "effect_agent_meta");
125
127
  const version = legacy.value;
126
- if (allowUpgrade && (version === 25 || version === 26)) {
128
+ if (allowUpgrade && (version === 25 || version === 26 || version === 27)) {
127
129
  if (version === 25 && objects.some(({ name }) => addedIndexes.has(name))) return yield* incompatible(version, "Mixed layout 25 and 26 objects.");
128
- const predecessor = version === 25 ? layout25 : layout26;
130
+ const predecessor = version === 25 ? layout25 : version === 26 ? layout26 : layout27;
129
131
  const header = yield* predecessor.readHeader(objects, version);
130
132
  yield* predecessor.readManagedTriggers(true);
131
133
  return header;
@@ -138,8 +140,8 @@ const readDoStorageHeader = Effect.fnUntraced(function* () {
138
140
  if (header === void 0) return yield* incompatible(0, "No initialized Thread storage to export.");
139
141
  return header;
140
142
  });
141
- /** Initialize fresh storage or atomically upgrade the exact released layouts 25 and 26. */
142
- const ensureDoStorageLayout = Effect.fn("DoStorage.initializeLayout")(function* () {
143
+ /** Initialize fresh storage or atomically upgrade the exact released layouts 25–27. */
144
+ const initializeDoStorageLayout = Effect.fn("DoStorage.initializeLayout")(function* () {
143
145
  const sql = (yield* SqlClient$1.SqlClient).withoutTransforms();
144
146
  return yield* sql.withTransaction(Effect.gen(function* () {
145
147
  const header = yield* inspectStorage(true);
@@ -153,14 +155,15 @@ const ensureDoStorageLayout = Effect.fn("DoStorage.initializeLayout")(function*
153
155
  yield* sql`DROP INDEX effect_agent_message_deliveries_peer`;
154
156
  for (const [, name, index] of layoutObjects(layoutStatements)) if (addedIndexes.has(name) || name === "effect_agent_message_deliveries_peer") yield* sql.unsafe(layoutStatements[index]).withoutTransform;
155
157
  }
156
- if (header?.layoutVersion === 25 || header?.layoutVersion === 26) {
157
- yield* upgradeExecutionCheckpoints(void 0).pipe(Effect.catchTag("ThreadStoreError", (cause) => DoStorageCorruptionError.make({
158
- table: "effect_agent_executions",
159
- rowKey: "upgrade",
160
- message: `Invalid retained execution; upgrade rolled back: ${cause.message}`
161
- })));
162
- yield* sql`UPDATE effect_agent_schema SET layout_version=${27} WHERE singleton=1`;
163
- yield* sql`UPDATE effect_agent_meta SET value=${String(27)} WHERE key='storage_version'`;
158
+ if (header?.layoutVersion === 25 || header?.layoutVersion === 26) yield* upgradeExecutionCheckpoints(void 0).pipe(Effect.catchTag("ThreadStoreError", (cause) => DoStorageCorruptionError.make({
159
+ table: "effect_agent_executions",
160
+ rowKey: "upgrade",
161
+ message: `Invalid retained execution; upgrade rolled back: ${cause.message}`
162
+ })));
163
+ if (header !== void 0 && header.layoutVersion < 28) {
164
+ yield* sql`DROP INDEX effect_agent_canonical_batches_last`;
165
+ yield* sql`UPDATE effect_agent_schema SET layout_version=${28} WHERE singleton=1`;
166
+ yield* sql`UPDATE effect_agent_meta SET value=${String(28)} WHERE key='storage_version'`;
164
167
  return yield* readDoStorageHeader();
165
168
  }
166
169
  if (header !== void 0) return header;
@@ -171,12 +174,32 @@ const ensureDoStorageLayout = Effect.fn("DoStorage.initializeLayout")(function*
171
174
  cause
172
175
  })));
173
176
  yield* sql.unsafe(headerStatement).withoutTransform;
174
- yield* sql`INSERT INTO effect_agent_schema (singleton, layout_version, record_format) VALUES (1, ${27}, ${CURRENT_RECORD_FORMAT})`;
175
- yield* sql`INSERT INTO effect_agent_meta (key, value) VALUES ('storage_version', ${String(27)})`;
177
+ yield* sql`INSERT INTO effect_agent_schema (singleton, layout_version, record_format) VALUES (1, ${28}, ${CURRENT_RECORD_FORMAT})`;
178
+ yield* sql`INSERT INTO effect_agent_meta (key, value) VALUES ('storage_version', ${String(28)})`;
176
179
  return yield* readDoStorageHeader();
177
180
  })).pipe(Effect.catchTag("SqlError", storageError));
178
181
  });
182
+ const initializedLayouts = /* @__PURE__ */ new WeakMap();
183
+ /** Share committed inspection within one live Object owner; maintenance invalidates it. */
184
+ const ensureDoStorageLayout = Effect.fnUntraced(function* () {
185
+ const sql = yield* SqlClient$1.SqlClient;
186
+ const owner = yield* SqlStorageOwner;
187
+ if (owner === void 0 || Option.isSome(yield* Effect.serviceOption(sql.transactionService))) return yield* initializeDoStorageLayout();
188
+ const identity = owner.identity ?? owner;
189
+ return yield* owner.read(Effect.gen(function* () {
190
+ const previous = initializedLayouts.get(identity);
191
+ if (previous !== void 0) return previous;
192
+ const header = yield* initializeDoStorageLayout();
193
+ const invalidate = () => {
194
+ initializedLayouts.delete(identity);
195
+ owner.invalidators.delete(invalidate);
196
+ };
197
+ initializedLayouts.set(identity, header);
198
+ owner.invalidators.add(invalidate);
199
+ return header;
200
+ }));
201
+ });
179
202
  //#endregion
180
203
  export { ensureDoStorageLayout as n, readDoStorageHeader as r, CurrentDoStorageVersion as t };
181
204
 
182
- //# sourceMappingURL=migrations-C3N9GN6A.mjs.map
205
+ //# sourceMappingURL=migrations-CAO_akhD.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"migrations-CAO_akhD.mjs","names":["SqlClient"],"sources":["../src/internal/migrations.ts"],"sourcesContent":["import { backfillPeerMessageRetention } from \"@yielded/agent-storage-sql/sql-message-delivery-store\";\nimport {\n SQL_PROMPT_PREDICATE,\n upgradeExecutionCheckpoints,\n} from \"@yielded/agent-storage-sql/sql-thread-native-reads\";\nimport { createSqlThreadWorkTables } from \"@yielded/agent-storage-sql/sql-thread-work\";\nimport { makeSqliteLayoutInspection } from \"@yielded/agent-storage-sql/sqlite-layout-inspection\";\nimport { CURRENT_RECORD_FORMAT } from \"@yielded/agent/records\";\nimport { SqlStorageOwner } from \"@yielded/agent/sql-memory-store\";\nimport { Effect, Option, Schema } from \"effect\";\nimport * as SqlClient from \"effect/sql/SqlClient\";\nimport type { SqlError } from \"effect/sql/SqlError\";\n\nimport {\n DoStorageCompatibilityError,\n DoStorageCorruptionError,\n DoStorageError,\n} from \"../DoStorageError.ts\";\n\nexport const CurrentDoStorageVersion = 28;\n\n/** Fresh layout only. Unsupported stores are rejected before these statements execute. */\nconst layoutStatements = [\n \"CREATE TABLE effect_agent_threads ( thread_id TEXT PRIMARY KEY NOT NULL, created_at TEXT, tail_sequence INTEGER NOT NULL, work_version INTEGER NOT NULL DEFAULT 3, work_state TEXT NOT NULL DEFAULT 'ready', work_through_sequence INTEGER NOT NULL DEFAULT 0, work_reporting INTEGER NOT NULL DEFAULT 0, work_entry_count INTEGER NOT NULL DEFAULT 0, worker_input_sequence INTEGER, worker_settlement_sequence INTEGER )\",\n \"CREATE TABLE effect_agent_envelopes (envelope_key INTEGER PRIMARY KEY NOT NULL, content_digest TEXT UNIQUE NOT NULL, prefix TEXT NOT NULL, before_payload TEXT NOT NULL, before_record_id TEXT NOT NULL, suffix TEXT NOT NULL)\",\n \"CREATE TABLE effect_agent_run_keys (run_key INTEGER PRIMARY KEY NOT NULL, thread_id TEXT NOT NULL, run_id TEXT NOT NULL, UNIQUE (thread_id, run_id), FOREIGN KEY (thread_id) REFERENCES effect_agent_threads(thread_id) ON DELETE RESTRICT)\",\n \"CREATE TABLE effect_agent_definitions (definition_key INTEGER PRIMARY KEY NOT NULL, content_digest TEXT UNIQUE NOT NULL, value_json TEXT NOT NULL)\",\n \"CREATE TABLE effect_agent_executions (thread_id TEXT NOT NULL, run_id TEXT NOT NULL, input_sequence INTEGER NOT NULL, revision INTEGER NOT NULL, checkpoint_json TEXT NOT NULL, last_commit_id TEXT, last_commit_digest TEXT, PRIMARY KEY (thread_id, run_id), FOREIGN KEY (thread_id) REFERENCES effect_agent_threads(thread_id) ON DELETE RESTRICT)\",\n \"CREATE TABLE effect_agent_canonical_batches ( thread_id TEXT NOT NULL, batch_id TEXT NOT NULL, first_sequence INTEGER NOT NULL, last_sequence INTEGER NOT NULL, producer_id_json TEXT NOT NULL, CONSTRAINT effect_agent_canonical_batches_span CHECK (first_sequence >= 1 AND last_sequence >= first_sequence AND last_sequence - first_sequence < 256), PRIMARY KEY (thread_id, batch_id), FOREIGN KEY (thread_id) REFERENCES effect_agent_threads(thread_id) ON DELETE RESTRICT )\",\n \"CREATE TABLE effect_agent_canonical_records ( thread_id TEXT NOT NULL, sequence INTEGER NOT NULL, record_id TEXT NOT NULL, created_at_json TEXT NOT NULL, envelope_key INTEGER NOT NULL, payload_json TEXT, record_tag INTEGER NOT NULL, run_id INTEGER, tool_call_id TEXT, input_kind TEXT, source_submission_id TEXT, message_id TEXT, submission_id TEXT, application_input INTEGER NOT NULL, context_through INTEGER, context_kind TEXT, worker_thread_id TEXT, handoff INTEGER NOT NULL, PRIMARY KEY (thread_id, sequence), UNIQUE (thread_id, record_id), FOREIGN KEY (thread_id) REFERENCES effect_agent_threads(thread_id) ON DELETE RESTRICT )\",\n 'CREATE TABLE \"effect_agent_record_runs\" ( thread_id TEXT NOT NULL, run_id INTEGER NOT NULL, sequence INTEGER NOT NULL, PRIMARY KEY (thread_id, run_id, sequence), FOREIGN KEY (thread_id, sequence) REFERENCES \"effect_agent_canonical_records\"(thread_id, sequence) ON DELETE RESTRICT ) WITHOUT ROWID',\n \"CREATE TABLE effect_agent_rollover_buckets (thread_id TEXT NOT NULL, height INTEGER NOT NULL, bucket INTEGER NOT NULL, sequence INTEGER NOT NULL, PRIMARY KEY (thread_id, height, bucket, sequence), FOREIGN KEY (thread_id, sequence) REFERENCES effect_agent_canonical_records(thread_id, sequence) ON DELETE RESTRICT) WITHOUT ROWID\",\n \"CREATE TABLE effect_agent_tool_declarations (thread_id TEXT NOT NULL, settlement_record_id TEXT NOT NULL, sequence INTEGER NOT NULL, PRIMARY KEY (thread_id, settlement_record_id, sequence), FOREIGN KEY (thread_id, sequence) REFERENCES effect_agent_canonical_records(thread_id, sequence) ON DELETE RESTRICT)\",\n \"CREATE INDEX effect_agent_tool_declarations_sequence ON effect_agent_tool_declarations(thread_id, sequence)\",\n \"CREATE TABLE effect_agent_record_refusals (thread_id TEXT NOT NULL, reservation_record_id TEXT NOT NULL, sequence INTEGER NOT NULL, PRIMARY KEY (thread_id, reservation_record_id, sequence), FOREIGN KEY (thread_id, sequence) REFERENCES effect_agent_canonical_records(thread_id, sequence) ON DELETE RESTRICT)\",\n \"CREATE INDEX effect_agent_record_refusals_sequence ON effect_agent_record_refusals(thread_id, sequence)\",\n \"CREATE TABLE effect_agent_checkpoints ( thread_id TEXT NOT NULL, through_sequence INTEGER NOT NULL, checkpoint_json TEXT NOT NULL, PRIMARY KEY (thread_id, through_sequence), FOREIGN KEY (thread_id) REFERENCES effect_agent_threads(thread_id) ON DELETE RESTRICT )\",\n \"CREATE TABLE effect_agent_submissions ( submission_id TEXT PRIMARY KEY NOT NULL, thread_id TEXT NOT NULL, queue_sequence INTEGER NOT NULL, principal TEXT NOT NULL, idempotency_key TEXT NOT NULL, agent_id TEXT NOT NULL, definition_key INTEGER NOT NULL, deployment_id TEXT NOT NULL, input_json TEXT NOT NULL, input_digest TEXT NOT NULL, receipt_id TEXT NOT NULL, state TEXT NOT NULL, settled_outcome TEXT, settled_record_id TEXT, finalized_at TEXT, created_at TEXT NOT NULL, ready_at TEXT, input_applied_record_id TEXT, input_applied_sequence INTEGER, joined_host_submission_id TEXT, suspended_reason_json TEXT, suspended_at TEXT, unknown_reason TEXT, unknown_tool_call_ids_json TEXT, parent_submission_id TEXT, parent_tool_call_id TEXT, admission_group TEXT, admission_fence_json TEXT, worker_admission_json TEXT, message_admission_json TEXT, UNIQUE (thread_id, principal, idempotency_key), UNIQUE (thread_id, queue_sequence) )\",\n \"CREATE INDEX effect_agent_submissions_joined_host ON effect_agent_submissions (joined_host_submission_id) WHERE joined_host_submission_id IS NOT NULL\",\n \"CREATE INDEX effect_agent_submissions_parent ON effect_agent_submissions (parent_submission_id) WHERE parent_submission_id IS NOT NULL\",\n \"CREATE INDEX effect_agent_submissions_group ON effect_agent_submissions (thread_id, admission_group) WHERE admission_group IS NOT NULL AND state <> 'settled'\",\n \"CREATE TABLE effect_agent_abort_intents ( submission_id TEXT PRIMARY KEY NOT NULL, author TEXT NOT NULL, reason TEXT NOT NULL, requested_at TEXT NOT NULL, canonical_record_id TEXT, FOREIGN KEY (submission_id) REFERENCES effect_agent_submissions(submission_id) ON DELETE RESTRICT )\",\n \"CREATE TABLE effect_agent_approval_decisions ( submission_id TEXT NOT NULL, tool_call_id TEXT NOT NULL, decision TEXT NOT NULL, resolver TEXT NOT NULL, reason TEXT NOT NULL, decided_at TEXT NOT NULL, PRIMARY KEY (submission_id, tool_call_id), FOREIGN KEY (submission_id) REFERENCES effect_agent_submissions(submission_id) ON DELETE RESTRICT )\",\n \"CREATE TABLE effect_agent_unknown_resolutions ( submission_id TEXT NOT NULL, tool_call_id TEXT NOT NULL, resolution_kind TEXT NOT NULL, author TEXT NOT NULL, reason TEXT NOT NULL, resolution_json TEXT NOT NULL, resolved_at TEXT NOT NULL, PRIMARY KEY (submission_id, tool_call_id, resolution_kind), FOREIGN KEY (submission_id) REFERENCES effect_agent_submissions(submission_id) ON DELETE RESTRICT )\",\n \"CREATE TABLE effect_agent_child_reservations ( reservation_id TEXT PRIMARY KEY NOT NULL, parent_submission_id TEXT NOT NULL, parent_tool_call_id TEXT NOT NULL, child_submission_id TEXT, status TEXT NOT NULL, allocation_json TEXT NOT NULL, allocation_digest TEXT NOT NULL, accounting_json TEXT, reserved_at TEXT NOT NULL, release_began_at TEXT, released_at TEXT, UNIQUE (parent_submission_id, parent_tool_call_id), FOREIGN KEY (parent_submission_id) REFERENCES effect_agent_submissions(submission_id) ON DELETE RESTRICT )\",\n \"CREATE TABLE effect_agent_child_settlements ( parent_submission_id TEXT NOT NULL, child_submission_id TEXT NOT NULL, child_outcome TEXT, recorded_at TEXT NOT NULL, PRIMARY KEY (parent_submission_id, child_submission_id) )\",\n 'CREATE INDEX effect_agent_records_call ON \"effect_agent_canonical_records\"(thread_id, record_tag, run_id, tool_call_id) WHERE tool_call_id IS NOT NULL',\n \"CREATE INDEX effect_agent_records_run_input ON \\\"effect_agent_canonical_records\\\"(thread_id, run_id) WHERE record_tag = 30 AND input_kind = 'user'\",\n 'CREATE INDEX effect_agent_records_subtree ON \"effect_agent_canonical_records\"(thread_id, source_submission_id, sequence) WHERE record_tag = 22',\n 'CREATE INDEX effect_agent_records_worker_input ON \"effect_agent_canonical_records\"(thread_id, message_id) WHERE record_tag = 34',\n \"CREATE INDEX effect_agent_submissions_nonterminal ON effect_agent_submissions (thread_id, queue_sequence) WHERE state <> 'settled'\",\n \"CREATE TABLE effect_agent_message_deliveries ( owner_thread_id TEXT NOT NULL, message_id TEXT NOT NULL, version INTEGER NOT NULL, state TEXT NOT NULL, deadline_at_millis INTEGER, record_json TEXT NOT NULL, peer_retained_until_millis INTEGER, PRIMARY KEY (owner_thread_id, message_id) )\",\n \"CREATE INDEX effect_agent_message_deliveries_due ON effect_agent_message_deliveries (deadline_at_millis, owner_thread_id, message_id) WHERE deadline_at_millis IS NOT NULL\",\n \"CREATE INDEX effect_agent_message_deliveries_pending ON \\\"effect_agent_message_deliveries\\\"(owner_thread_id, message_id) WHERE state NOT IN ('processed', 'refused')\",\n \"CREATE TABLE effect_agent_worker_stops (thread_id TEXT PRIMARY KEY NOT NULL, terminal TEXT)\",\n \"CREATE INDEX effect_agent_worker_starts ON effect_agent_message_deliveries(owner_thread_id, json_extract(record_json, '$.envelope.workerAdmission.origin.worker.delegationId'), json_extract(record_json, '$.envelope.workerAdmission.origin.worker.targetAgentId'), message_id) WHERE message_id = json_extract(record_json, '$.envelope.workerAdmission.origin.firstMessageId')\",\n \"CREATE INDEX effect_agent_worker_pending ON effect_agent_message_deliveries(owner_thread_id, json_extract(record_json, '$.envelope.workerAdmission.origin.worker.threadId'), message_id) WHERE state IN ('pending', 'parked') AND json_extract(record_json, '$.receipt') IS NULL\",\n \"CREATE TABLE effect_agent_meta ( key TEXT PRIMARY KEY NOT NULL, value TEXT NOT NULL )\",\n 'CREATE INDEX effect_agent_records_tag ON \"effect_agent_canonical_records\"(thread_id, record_tag, sequence)',\n 'CREATE INDEX effect_agent_records_handoff ON \"effect_agent_canonical_records\"(thread_id, sequence) WHERE handoff = 1',\n \"CREATE INDEX effect_agent_records_application_input ON effect_agent_canonical_records(thread_id, sequence) WHERE application_input = 1\",\n `CREATE INDEX effect_agent_records_prompt ON effect_agent_canonical_records(thread_id, sequence) WHERE ${SQL_PROMPT_PREDICATE}`,\n \"CREATE INDEX effect_agent_records_admitted_input ON effect_agent_canonical_records(thread_id, sequence) WHERE record_tag = 30 AND submission_id IS NOT NULL\",\n \"CREATE INDEX effect_agent_records_worker_funding ON effect_agent_canonical_records(thread_id, source_submission_id, sequence, message_id) WHERE record_tag = 34\",\n \"CREATE INDEX effect_agent_records_worker_completed ON effect_agent_canonical_records(thread_id, message_id, sequence) WHERE record_tag = 32\",\n \"CREATE INDEX effect_agent_records_worker_stop ON effect_agent_canonical_records(thread_id, worker_thread_id, sequence) WHERE record_tag = 38\",\n \"CREATE INDEX effect_agent_message_deliveries_identity ON effect_agent_message_deliveries(owner_thread_id, json_quote(message_id))\",\n \"CREATE INDEX effect_agent_message_deliveries_peer_retained ON effect_agent_message_deliveries(owner_thread_id, peer_retained_until_millis, message_id) WHERE peer_retained_until_millis IS NOT NULL\",\n \"CREATE INDEX effect_agent_message_deliveries_peer ON effect_agent_message_deliveries(owner_thread_id, message_id) WHERE state NOT IN ('processed', 'refused') AND json_extract(record_json, '$.envelope.messageAdmission.peerName') IS NOT NULL\",\n \"CREATE TABLE effect_agent_journal_ranges (thread_id TEXT NOT NULL, first_sequence INTEGER NOT NULL, last_sequence INTEGER NOT NULL, record_count INTEGER NOT NULL, batch_count INTEGER NOT NULL, byte_count INTEGER NOT NULL, state TEXT NOT NULL, locator TEXT, PRIMARY KEY (thread_id, first_sequence), FOREIGN KEY (thread_id) REFERENCES effect_agent_threads(thread_id) ON DELETE RESTRICT)\",\n \"CREATE TABLE effect_agent_archive_batches (thread_id TEXT NOT NULL, batch_id TEXT NOT NULL, range_first_sequence INTEGER NOT NULL, batch_json TEXT NOT NULL, PRIMARY KEY (thread_id, batch_id), FOREIGN KEY (thread_id, batch_id) REFERENCES effect_agent_canonical_batches(thread_id, batch_id) ON DELETE RESTRICT, CONSTRAINT effect_agent_archive_batches_range_fkey FOREIGN KEY (thread_id, range_first_sequence) REFERENCES effect_agent_journal_ranges(thread_id, first_sequence) ON DELETE RESTRICT)\",\n \"CREATE TABLE effect_agent_archive_records (thread_id TEXT NOT NULL, sequence INTEGER NOT NULL, range_first_sequence INTEGER NOT NULL, record_json TEXT NOT NULL, PRIMARY KEY (thread_id, sequence), FOREIGN KEY (thread_id, sequence) REFERENCES effect_agent_canonical_records(thread_id, sequence) ON DELETE RESTRICT, CONSTRAINT effect_agent_archive_records_range_fkey FOREIGN KEY (thread_id, range_first_sequence) REFERENCES effect_agent_journal_ranges(thread_id, first_sequence) ON DELETE RESTRICT)\",\n \"CREATE UNIQUE INDEX effect_agent_canonical_batches_sequence ON effect_agent_canonical_batches(thread_id, first_sequence)\",\n \"CREATE TABLE effect_agent_live_child_reservations (reservation_id TEXT PRIMARY KEY NOT NULL, thread_id TEXT NOT NULL)\",\n \"CREATE INDEX effect_agent_live_child_reservations_thread ON effect_agent_live_child_reservations(thread_id, reservation_id)\",\n // Compact native positions keep accepted identities out of bounded export cursors.\n // Persistent scalar FIFO derivatives; rebuild from canonical input/settlement boundaries.\n // Writer-local import indexes; rows are removed before publication.\n \"CREATE TABLE effect_agent_import_delivery_visits (thread_id TEXT NOT NULL, message_id TEXT NOT NULL, path_id TEXT NOT NULL, completed INTEGER NOT NULL, PRIMARY KEY (thread_id, message_id))\",\n \"CREATE INDEX effect_agent_import_delivery_visits_path ON effect_agent_import_delivery_visits(thread_id, path_id)\",\n \"CREATE TRIGGER effect_agent_live_child_insert AFTER INSERT ON effect_agent_child_reservations FOR EACH ROW BEGIN INSERT INTO effect_agent_live_child_reservations (reservation_id, thread_id) SELECT NEW.reservation_id, thread_id FROM effect_agent_submissions WHERE submission_id=NEW.parent_submission_id AND NEW.status<>'released'; END\",\n \"CREATE TRIGGER effect_agent_live_child_update AFTER UPDATE ON effect_agent_child_reservations FOR EACH ROW WHEN OLD.reservation_id IS NOT NEW.reservation_id OR OLD.parent_submission_id IS NOT NEW.parent_submission_id OR OLD.parent_tool_call_id IS NOT NEW.parent_tool_call_id OR OLD.child_submission_id IS NOT NEW.child_submission_id OR OLD.status IS NOT NEW.status OR OLD.allocation_json IS NOT NEW.allocation_json OR OLD.allocation_digest IS NOT NEW.allocation_digest OR OLD.accounting_json IS NOT NEW.accounting_json OR OLD.reserved_at IS NOT NEW.reserved_at OR OLD.release_began_at IS NOT NEW.release_began_at OR OLD.released_at IS NOT NEW.released_at BEGIN DELETE FROM effect_agent_live_child_reservations WHERE reservation_id=OLD.reservation_id; INSERT INTO effect_agent_live_child_reservations (reservation_id, thread_id) SELECT NEW.reservation_id, thread_id FROM effect_agent_submissions WHERE submission_id=NEW.parent_submission_id AND NEW.status<>'released'; END\",\n \"CREATE TRIGGER effect_agent_live_child_delete AFTER DELETE ON effect_agent_child_reservations FOR EACH ROW BEGIN DELETE FROM effect_agent_live_child_reservations WHERE reservation_id=OLD.reservation_id; END\",\n \"CREATE INDEX effect_agent_message_deliveries_capacity ON effect_agent_message_deliveries(owner_thread_id, (COALESCE(json_extract(record_json, '$.envelope.messageAdmission._tag'), '') = 'WorkerUpdate'), message_id) WHERE state IN ('pending', 'accepted', 'parked')\",\n] as const;\n\nconst headerStatement =\n \"CREATE TABLE effect_agent_schema (singleton INTEGER PRIMARY KEY NOT NULL CHECK (singleton = 1), layout_version INTEGER NOT NULL CHECK (layout_version > 0), record_format TEXT NOT NULL CHECK (length(record_format) > 0))\";\n\nconst layoutObjects = (statements: ReadonlyArray<string>) =>\n statements.map((statement, index) => {\n const name = /^CREATE (TABLE|(?:UNIQUE )?INDEX|TRIGGER) \"?([a-z_][a-z_0-9]*)\"?/.exec(statement);\n\n // oxlint-disable-next-line effect/no-untyped-throw, effect/no-native-error -- The synchronous SQL layout parser rejects malformed developer-authored declarations before storage mutation.\n if (name === null) throw new Error(\"Invalid fresh layout statement\");\n\n return [name[1].replace(\"UNIQUE \", \"\").toLowerCase(), name[2], index] as const;\n });\n\nconst Legacy = Schema.Tuple([\n Schema.Struct({\n key: Schema.Literal(\"storage_version\"),\n value: Schema.String.check(Schema.isPattern(/^(0|[1-9][0-9]*)$/)).pipe(\n Schema.decodeTo(Schema.FiniteFromString),\n Schema.decodeTo(Schema.Int),\n ),\n }),\n]);\n\nexport interface DoStorageHeader {\n readonly layoutVersion: number;\n readonly recordFormat: string;\n}\n\nconst incompatible = (actualVersion: number, message: string) =>\n DoStorageCompatibilityError.make({\n actualVersion,\n supportedVersion: CurrentDoStorageVersion,\n message: `${message} Keep the original store; the store was not changed.`,\n });\n\nconst storageError = (cause: SqlError) =>\n DoStorageError.make({ operation: \"inspect storage layout\", cause, message: cause.message });\n\nconst inspection = (version: number, statements: ReadonlyArray<string>) =>\n makeSqliteLayoutInspection({\n version,\n statements,\n objects: layoutObjects(statements),\n headerStatement,\n incompatible,\n storageError,\n corruption: (table) =>\n DoStorageCorruptionError.make({\n table,\n rowKey: \"schema\",\n message: \"Malformed storage layout or version header.\",\n }),\n });\n\n// Released predecessors retain the same record format and canonical tables.\nconst addedIndexes = new Set([\"effect_agent_message_deliveries_peer_retained\"]);\n\nconst layout27Statements = [\n ...layoutStatements,\n \"CREATE INDEX effect_agent_canonical_batches_last ON effect_agent_canonical_batches(thread_id, last_sequence)\",\n];\n\nconst layout25Statements = layoutObjects(layout27Statements)\n .filter(([, name]) => !addedIndexes.has(name))\n .map(([, , index]) =>\n layout27Statements[index]\n .replace(\", peer_retained_until_millis INTEGER\", \"\")\n .replace(\n \"'$.envelope.messageAdmission.peerName') IS NOT NULL\",\n \"'$.envelope.messageAdmission.schemaVersion') = 1\",\n ),\n );\n\nconst { decode, readObjects, readHeader } = inspection(CurrentDoStorageVersion, layoutStatements);\nconst layout25 = inspection(25, layout25Statements);\nconst layout26 = inspection(26, layout27Statements);\nconst layout27 = inspection(27, layout27Statements);\n\nconst inspectStorage = Effect.fnUntraced(function* (\n allowUpgrade = false,\n): Effect.fn.Return<\n DoStorageHeader | undefined,\n DoStorageCompatibilityError | DoStorageCorruptionError | DoStorageError,\n SqlClient.SqlClient\n> {\n const sql = (yield* SqlClient.SqlClient).withoutTransforms();\n\n const objects = yield* readObjects();\n\n const meta = objects.find((row) => row.name === \"effect_agent_meta\");\n\n if (meta === undefined) {\n if (objects.length === 0) return undefined;\n\n return yield* incompatible(0, \"Unversioned or incomplete Effect Agent storage.\");\n }\n\n const [legacy] = yield* decode(\n Legacy,\n yield* sql<Record<string, unknown>>`\n SELECT * FROM effect_agent_meta WHERE key = 'storage_version'\n `.pipe(Effect.mapError(storageError)),\n \"effect_agent_meta\",\n );\n\n const version = legacy.value;\n\n if (allowUpgrade && (version === 25 || version === 26 || version === 27)) {\n if (version === 25 && objects.some(({ name }) => addedIndexes.has(name)))\n return yield* incompatible(version, \"Mixed layout 25 and 26 objects.\");\n const predecessor = version === 25 ? layout25 : version === 26 ? layout26 : layout27;\n const header = yield* predecessor.readHeader(objects, version);\n\n yield* predecessor.readManagedTriggers(true);\n\n return header;\n }\n\n return yield* readHeader(objects, version);\n});\n\n/** Read-only inspection. The caller owns a snapshot covering this check and its export reads. */\nexport const readDoStorageHeader = Effect.fnUntraced(function* () {\n const header = yield* inspectStorage();\n\n if (header === undefined)\n return yield* incompatible(0, \"No initialized Thread storage to export.\");\n\n return header;\n});\n\n/** Initialize fresh storage or atomically upgrade the exact released layouts 25–27. */\nconst initializeDoStorageLayout = Effect.fn(\"DoStorage.initializeLayout\")(function* () {\n const sql = (yield* SqlClient.SqlClient).withoutTransforms();\n\n return yield* sql\n .withTransaction(\n Effect.gen(function* () {\n const header = yield* inspectStorage(true);\n\n if (header?.layoutVersion === 25) {\n yield* sql`ALTER TABLE effect_agent_message_deliveries ADD COLUMN peer_retained_until_millis INTEGER`;\n yield* backfillPeerMessageRetention().pipe(\n Effect.catchTag(\"MessageDeliveryError\", () =>\n DoStorageCorruptionError.make({\n table: \"effect_agent_message_deliveries\",\n rowKey: \"upgrade\",\n message: \"Invalid layout-25 delivery evidence; upgrade rolled back.\",\n }),\n ),\n );\n yield* sql`DROP INDEX effect_agent_message_deliveries_peer`;\n for (const [, name, index] of layoutObjects(layoutStatements))\n if (addedIndexes.has(name) || name === \"effect_agent_message_deliveries_peer\")\n yield* sql.unsafe(layoutStatements[index]).withoutTransform;\n }\n if (header?.layoutVersion === 25 || header?.layoutVersion === 26) {\n yield* upgradeExecutionCheckpoints(undefined).pipe(\n Effect.catchTag(\"ThreadStoreError\", (cause) =>\n DoStorageCorruptionError.make({\n table: \"effect_agent_executions\",\n rowKey: \"upgrade\",\n message: `Invalid retained execution; upgrade rolled back: ${cause.message}`,\n }),\n ),\n );\n }\n if (header !== undefined && header.layoutVersion < CurrentDoStorageVersion) {\n yield* sql`DROP INDEX effect_agent_canonical_batches_last`;\n yield* sql`UPDATE effect_agent_schema SET layout_version=${CurrentDoStorageVersion} WHERE singleton=1`;\n yield* sql`UPDATE effect_agent_meta SET value=${String(CurrentDoStorageVersion)} WHERE key='storage_version'`;\n\n return yield* readDoStorageHeader();\n }\n if (header !== undefined) return header;\n for (const statement of layoutStatements) yield* sql.unsafe(statement).withoutTransform;\n yield* createSqlThreadWorkTables().pipe(\n Effect.mapError((cause) =>\n DoStorageError.make({\n operation: \"initialize work catalogue\",\n message: cause.message,\n cause,\n }),\n ),\n );\n yield* sql.unsafe(headerStatement).withoutTransform;\n yield* sql`INSERT INTO effect_agent_schema (singleton, layout_version, record_format) VALUES (1, ${CurrentDoStorageVersion}, ${CURRENT_RECORD_FORMAT})`;\n yield* sql`INSERT INTO effect_agent_meta (key, value) VALUES ('storage_version', ${String(CurrentDoStorageVersion)})`;\n\n return yield* readDoStorageHeader();\n }),\n )\n .pipe(Effect.catchTag(\"SqlError\", storageError));\n});\n\nconst initializedLayouts = new WeakMap<object, DoStorageHeader>();\n\n/** Share committed inspection within one live Object owner; maintenance invalidates it. */\nexport const ensureDoStorageLayout = Effect.fnUntraced(function* () {\n const sql = yield* SqlClient.SqlClient;\n const owner = yield* SqlStorageOwner;\n\n // A caller-owned transaction can still roll back after this initializer returns.\n if (owner === undefined || Option.isSome(yield* Effect.serviceOption(sql.transactionService)))\n return yield* initializeDoStorageLayout();\n\n const identity = owner.identity ?? owner;\n\n return yield* owner.read(\n Effect.gen(function* () {\n const previous = initializedLayouts.get(identity);\n\n if (previous !== undefined) return previous;\n const header = yield* initializeDoStorageLayout();\n\n const invalidate = () => {\n initializedLayouts.delete(identity);\n owner.invalidators.delete(invalidate);\n };\n\n initializedLayouts.set(identity, header);\n owner.invalidators.add(invalidate);\n\n return header;\n }),\n );\n});\n"],"mappings":";;;;;;;;;;AAmBA,MAAa,0BAA0B;;AAGvC,MAAM,mBAAmB;CACvB;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA,yGAAyG;CACzG;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CAIA;CACA;CACA;CACA;CACA;CACA;AACF;AAEA,MAAM,kBACJ;AAEF,MAAM,iBAAiB,eACrB,WAAW,KAAK,WAAW,UAAU;CACnC,MAAM,OAAO,mEAAmE,KAAK,SAAS;CAG9F,IAAI,SAAS,MAAM,MAAM,IAAI,MAAM,gCAAgC;CAEnE,OAAO;EAAC,KAAK,EAAE,CAAC,QAAQ,WAAW,EAAE,CAAC,CAAC,YAAY;EAAG,KAAK;EAAI;CAAK;AACtE,CAAC;AAEH,MAAM,SAAS,OAAO,MAAM,CAC1B,OAAO,OAAO;CACZ,KAAK,OAAO,QAAQ,iBAAiB;CACrC,OAAO,OAAO,OAAO,MAAM,OAAO,UAAU,mBAAmB,CAAC,CAAC,CAAC,KAChE,OAAO,SAAS,OAAO,gBAAgB,GACvC,OAAO,SAAS,OAAO,GAAG,CAC5B;AACF,CAAC,CACH,CAAC;AAOD,MAAM,gBAAgB,eAAuB,YAC3C,4BAA4B,KAAK;CAC/B;CACA,kBAAA;CACA,SAAS,GAAG,QAAQ;AACtB,CAAC;AAEH,MAA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}
@@ -78,7 +78,7 @@ const ownedRows = (schema, table, key, identityColumn, uniqueFields = [], projec
78
78
  state.invalidators.add(() => current.clear());
79
79
  }
80
80
  const current = cache;
81
- const decode = (rows) => decodeRows(rows).pipe(Effect.mapError(() => DoStorageCorruptionError.make({
81
+ const decode = (rows) => decodeRows(rows).pipe(Effect.mapErrorEager(() => DoStorageCorruptionError.make({
82
82
  table,
83
83
  rowKey: "owned-state",
84
84
  message: "Stored rows do not satisfy the storage schema"
@@ -106,7 +106,7 @@ const ownedRows = (schema, table, key, identityColumn, uniqueFields = [], projec
106
106
  const matching = (id, matches, query, maxRows = Infinity) => state.read(Effect.suspend(() => {
107
107
  const view = current.get(id);
108
108
  if (view !== void 0) return Effect.succeed(view.rows);
109
- return query.pipe(Effect.flatMap(decode), Effect.map((rows) => {
109
+ return Effect.flatMap(query, (rows) => Effect.mapEager(decode(rows), (rows) => {
110
110
  retain(id, matches, rows, maxRows);
111
111
  return rows;
112
112
  }));
@@ -140,6 +140,7 @@ const ownedRows = (schema, table, key, identityColumn, uniqueFields = [], projec
140
140
  byFields,
141
141
  matching,
142
142
  seed,
143
+ seedMatching: retain,
143
144
  write: apply(false),
144
145
  remove: apply(true)
145
146
  };
@@ -148,4 +149,4 @@ const ownedRows = (schema, table, key, identityColumn, uniqueFields = [], projec
148
149
  //#endregion
149
150
  export { ownedRows as n, ownedState as r, invalidateOwnedState as t };
150
151
 
151
- //# sourceMappingURL=owned-state-DcFh0YNo.mjs.map
152
+ //# sourceMappingURL=owned-state-BgGOA2Ak.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"owned-state-BgGOA2Ak.mjs","names":[],"sources":["../src/internal/owned-state.ts"],"sourcesContent":["import { SqliteClient } from \"@effect/sql-sqlite-do\";\nimport { makeStorageOwner, type StorageOwner } from \"@yielded/agent/run-storage\";\nimport { Deferred, Effect, Exit, Predicate, Schema, Scope, Semaphore } from \"effect\";\nimport { SqlClient } from \"effect/sql/SqlClient\";\nimport type { SqlError } from \"effect/sql/SqlError\";\n\nimport { DoStorageCorruptionError, DoStorageError } from \"../DoStorageError.ts\";\n\n/** One disposable view per physical Object database, including separately acquired adapters. */\nexport class OwnedState {\n constructor(readonly owner: StorageOwner[\"Service\"]) {}\n readonly invalidators = new Set<() => void>();\n\n readonly invalidate = Effect.sync(() => {\n for (const invalidate of this.invalidators) invalidate();\n });\n\n /** Cached readers must wait for the complete transaction, including rollback/commit. */\n readonly read = <A, E, R>(effect: Effect.Effect<A, E, R>): Effect.Effect<A, E, R> =>\n this.owner.withMutation(effect);\n\n readonly transaction = <A, E, R>(\n effect: Effect.Effect<A, E, R>,\n ): Effect.Effect<A, E | SqlError, R | SqlClient> =>\n this.read(\n Effect.flatMap(SqlClient, (sql) =>\n sql\n .withTransaction(effect)\n .pipe(Effect.onExit((exit) => (Exit.isFailure(exit) ? this.invalidate : Effect.void))),\n ),\n );\n}\n\ninterface RetainedState {\n readonly ready: Deferred.Deferred<OwnedState>;\n readonly disposed: Deferred.Deferred<void>;\n readonly scope: Scope.Closeable;\n references: number;\n closing: boolean;\n}\n\nconst states = new WeakMap<object, RetainedState>();\n\n/** Explicit invalidation for maintenance that writes private tables outside the adapters. */\nexport const invalidateOwnedState = (storage: DurableObjectStorage): Effect.Effect<void> =>\n Effect.suspend(() => {\n const state = states.get(storage);\n\n return state === undefined\n ? Effect.void\n : Deferred.await(state.ready).pipe(Effect.flatMap((state) => state.read(state.invalidate)));\n });\n\nconst DoClient = Schema.declare<SqliteClient.SqliteClient>(\n (value): value is SqliteClient.SqliteClient => Predicate.hasProperty(value, SqliteClient.TypeId),\n);\n\nexport const ownedState = (sql: SqlClient) =>\n Schema.decodeUnknownEffect(DoClient)(sql).pipe(\n Effect.mapError(() =>\n DoStorageError.make({\n operation: \"open owned state\",\n message: \"Owned state requires a Durable Object SQLite client.\",\n }),\n ),\n Effect.flatMap((client) =>\n Effect.uninterruptible(\n Effect.gen(function* () {\n // Instrumentation may return fresh wrappers; the physical Object identity owns the root.\n const key = client.config.storage ?? client.config.db ?? client;\n\n for (;;) {\n let retained = states.get(key);\n\n if (retained?.closing) {\n yield* Deferred.await(retained.disposed);\n continue;\n }\n if (retained === undefined) {\n retained = {\n ready: Deferred.makeUnsafe(),\n disposed: Deferred.makeUnsafe(),\n scope: Scope.makeUnsafe(),\n references: 1,\n closing: false,\n };\n states.set(key, retained);\n\n const owner = yield* makeStorageOwner(Semaphore.makeUnsafe(1).withPermits(1)).pipe(\n Scope.provide(retained.scope),\n );\n\n yield* Deferred.succeed(retained.ready, new OwnedState(owner));\n } else retained.references++;\n const current = retained;\n\n yield* Effect.addFinalizer(() =>\n Effect.uninterruptible(\n Effect.gen(function* () {\n current.references--;\n if (current.references !== 0) return;\n current.closing = true;\n yield* Scope.close(current.scope, Exit.void).pipe(\n Effect.ensuring(\n Effect.gen(function* () {\n if (states.get(key) === current) states.delete(key);\n yield* Deferred.succeed(current.disposed, undefined);\n }),\n ),\n );\n }),\n ),\n );\n\n return yield* Deferred.await(current.ready);\n }\n }),\n ),\n ),\n );\n\n/**\n * Demand-loaded row views. Writes apply SQLite's RETURNING rows to affected retained views in\n * the same transaction; rollback discards them. Bounded views avoid loading a host's entire\n * retained submission history just to fence one live submission.\n */\nexport const ownedRows = <A, I>(\n schema: Schema.Codec<A, I>,\n table: string,\n key: (row: A) => string,\n identityColumn?: keyof A & string,\n uniqueFields: ReadonlyArray<ReadonlyArray<keyof A & string>> = [],\n projection: (sql: SqlClient) => ReturnType<SqlClient[\"literal\"]> = (sql) => sql.literal(\"*\"),\n) => {\n type View = {\n readonly id: string;\n readonly matches: (row: A) => boolean;\n readonly maxRows: number;\n readonly rows: ReadonlyArray<A>;\n readonly bytes: number;\n };\n const caches = new WeakMap<OwnedState, Map<string, View>>();\n const decodeRows = Schema.decodeUnknownEffect(Schema.Array(schema));\n\n return (state: OwnedState, sql: SqlClient) => {\n let cache = caches.get(state);\n\n if (cache === undefined) {\n cache = new Map();\n caches.set(state, cache);\n const current = cache;\n\n state.invalidators.add(() => current.clear());\n }\n const current = cache;\n\n const decode = (rows: unknown) =>\n decodeRows(rows).pipe(\n Effect.mapErrorEager(() =>\n DoStorageCorruptionError.make({\n table,\n rowKey: \"owned-state\",\n message: \"Stored rows do not satisfy the storage schema\",\n }),\n ),\n );\n\n const retain = (\n id: string,\n matches: View[\"matches\"],\n rows: ReadonlyArray<A>,\n maxRows: number,\n ) => {\n const bytes = new TextEncoder().encode(JSON.stringify(rows)).byteLength;\n\n current.delete(id);\n if (rows.length > maxRows || bytes > 4 * 1024 * 1024) return;\n current.set(id, { id, matches, maxRows, rows, bytes });\n let total = 0;\n\n for (const view of current.values()) total += view.bytes;\n while (current.size > 128 || total > 4 * 1024 * 1024) {\n const oldest = current.entries().next().value;\n\n if (oldest === undefined) break;\n total -= oldest[1].bytes;\n current.delete(oldest[0]);\n }\n };\n\n const matching = (\n id: string,\n matches: View[\"matches\"],\n query: Effect.Effect<ReadonlyArray<unknown>, SqlError>,\n maxRows = Infinity,\n ) =>\n state.read(\n Effect.suspend(() => {\n const view = current.get(id);\n\n if (view !== undefined) return Effect.succeed(view.rows);\n\n return Effect.flatMap(query, (rows) =>\n Effect.mapEager(decode(rows), (rows) => {\n retain(id, matches, rows, maxRows);\n\n return rows;\n }),\n );\n }),\n );\n\n const by = (field: keyof A & string, value: string) =>\n matching(\n JSON.stringify([field, value]),\n (row) => row[field] === value,\n sql`SELECT ${projection(sql)} FROM ${sql(table)} WHERE ${sql(field)} = ${value}`,\n );\n\n // Only a source mutation proving the complete result may seed a view. This must run\n // under the owner transaction; rollback invalidates it with every other retained view.\n const seed = (field: keyof A & string, value: string, rows: ReadonlyArray<A>) =>\n retain(JSON.stringify([field, value]), (row) => row[field] === value, rows, Infinity);\n\n const byFields = (fields: ReadonlyArray<readonly [keyof A & string, string]>) =>\n matching(\n JSON.stringify(fields),\n (row) => fields.every(([field, value]) => row[field] === value),\n sql`SELECT ${projection(sql)} FROM ${sql(table)} WHERE ${sql.and(fields.map(([field, value]) => sql`${sql(field)} = ${value}`))}`,\n );\n\n const apply =\n (remove: boolean) =>\n <E, R>(effect: Effect.Effect<ReadonlyArray<unknown>, E, R>) =>\n Effect.gen(function* () {\n const rows = yield* decode(yield* effect);\n\n if (rows.length === 0) return rows;\n const changed = new Set(rows.map(key));\n\n for (const { id, matches, maxRows, rows: prior } of Array.from(current.values())) {\n const matchingRows = remove ? [] : rows.filter(matches);\n\n if (matchingRows.length === 0 && !prior.some((row) => changed.has(key(row)))) continue;\n const next = prior.filter((row) => !changed.has(key(row)));\n\n next.push(...matchingRows);\n retain(id, matches, next, maxRows);\n }\n // A RETURNING row completely defines its unique-key view, even on a new Thread.\n if (identityColumn !== undefined)\n for (const row of rows) {\n const value = row[identityColumn];\n\n if (typeof value === \"string\")\n retain(\n JSON.stringify([identityColumn, value]),\n (row) => row[identityColumn] === value,\n remove ? [] : [row],\n Infinity,\n );\n }\n\n for (const row of rows)\n for (const fields of uniqueFields) {\n const values = fields.map((field) => [field, row[field]] as const);\n\n retain(\n JSON.stringify(values),\n (candidate) => values.every(([field, value]) => candidate[field] === value),\n remove ? [] : [row],\n 1,\n );\n }\n\n return rows;\n });\n\n return {\n by,\n byFields,\n matching,\n seed,\n seedMatching: retain,\n write: apply(false),\n remove: apply(true),\n };\n };\n};\n"],"mappings":";;;;;;;AASA,IAAa,aAAb,MAAwB;CACD;CAArB,YAAY,OAAyC;EAAhC,KAAA,QAAA;CAAiC;CACtD,+BAAwB,IAAI,IAAgB;CAE5C,aAAsB,OAAO,WAAW;EACtC,KAAK,MAAM,cAAc,KAAK,cAAc,WAAW;CACzD,CAAC;;CAGD,QAA0B,WACxB,KAAK,MAAM,aAAa,MAAM;CAEhC,eACE,WAEA,KAAK,KACH,OAAO,QAAQ,YAAY,QACzB,IACG,gBAAgB,MAAM,CAAC,CACvB,KAAK,OAAO,QAAQ,SAAU,KAAK,UAAU,IAAI,IAAI,KAAK,aAAa,OAAO,IAAK,CAAC,CACzF,CACF;AACJ;AAUA,MAA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GAAG,OAAO;GAC9B,MAAM,UAAU,IAAI,IAAI,KAAK,IAAI,GAAG,CAAC;GAErC,KAAK,MAAM,EAAE,IAAI,SAAS,SAAS,MAAM,WAAW,MAAM,KAAK,QAAQ,OAAO,CAAC,GAAG;IAChF,MAAM,eAAe,SAAS,CAAC,IAAI,KAAK,OAAO,OAAO;IAEtD,IAAI,aAAa,WAAW,KAAK,CAAC,MAAM,MAAM,QAAQ,QAAQ,IAAI,IAAI,GAAG,CAAC,CAAC,GAAG;IAC9E,MAAM,OAAO,MAAM,QAAQ,QAAQ,CAAC,QAAQ,IAAI,IAAI,GAAG,CAAC,CAAC;IAEzD,KAAK,KAAK,GAAG,YAAY;IACzB,OAAO,IAAI,SAAS,MAAM,OAAO;GACnC;GAEA,IAAI,mBAAmB,KAAA,GACrB,KAAK,MAAM,OAAO,MAAM;IACtB,MAAM,QAAQ,IAAI;IAElB,IAAI,OAAO,UAAU,UACnB,OACE,KAAK,UAAU,CAAC,gBAAgB,KAAK,CAAC,IACrC,QAAQ,IAAI,oBAAoB,OACjC,SAAS,CAAC,IAAI,CAAC,GAAG,GAClB,QACF;GACJ;GAEF,KAAK,MAAM,OAAO,MAChB,KAAK,MAAM,UAAU,cAAc;IACjC,MAAM,SAAS,OAAO,KAAK,UAAU,CAAC,OAAO,IAAI,MAAM,CAAU;IAEjE,OACE,KAAK,UAAU,MAAM,IACpB,cAAc,OAAO,OAAO,CAAC,OAAO,WAAW,UAAU,WAAW,KAAK,GAC1E,SAAS,CAAC,IAAI,CAAC,GAAG,GAClB,CACF;GACF;GAEF,OAAO;EACT,CAAC;EAEL,OAAO;GACL;GACA;GACA;GACA;GACA,cAAc;GACd,OAAO,MAAM,KAAK;GAClB,QAAQ,MAAM,IAAI;EACpB;CACF;AACF"}
package/package.json CHANGED
@@ -1 +1 @@
1
- {"name":"@yielded/agent-storage-cloudflare","version":"0.1.0-beta.174","dependencies":{"@effect/platform-browser":"4.0.3","@effect/sql-sqlite-do":"4.0.3","@yielded/agent":"0.1.0-beta.174","@yielded/agent-storage-sql":"0.1.0-beta.174"},"devDependencies":{"@cloudflare/vitest-plugin":"1.4.0","@cloudflare/workers-types":"5.20260926.1","@effect/vitest":"4.0.3","@yielded/agent-testing":"0.1.0-beta.174","effect":"4.0.3","typescript":"7.0.2","vite":"npm:@voidzero-dev/vite-plus-core@1.1.0","vite-plus":"1.1.0","vitest":"5.0.3"},"peerDependencies":{"effect":"^4.0.3"},"exports":{".":{"types":"./dist/index.d.mts","default":"./dist/index.mjs"},"./do-memory-store":{"types":"./dist/DoMemoryStore.d.mts","default":"./dist/DoMemoryStore.mjs"},"./do-schedule-store":{"types":"./dist/DoScheduleStore.d.mts","default":"./dist/DoScheduleStore.mjs"},"./do-storage-config":{"types":"./dist/DoStorageConfig.d.mts","default":"./dist/DoStorageConfig.mjs"},"./do-storage-error":{"types":"./dist/DoStorageError.d.mts","default":"./dist/DoStorageError.mjs"},"./do-storage-failpoint":{"types":"./dist/DoStorageFailpoint.d.mts","default":"./dist/DoStorageFailpoint.mjs"},"./do-storage-version":{"types":"./dist/DoStorageVersion.d.mts","default":"./dist/DoStorageVersion.mjs"},"./do-submission-ledger":{"types":"./dist/DoSubmissionLedger.d.mts","default":"./dist/DoSubmissionLedger.mjs"},"./do-subscription-store":{"types":"./dist/DoSubscriptionStore.d.mts","default":"./dist/DoSubscriptionStore.mjs"},"./do-thread-store":{"types":"./dist/DoThreadStore.d.mts","default":"./dist/DoThreadStore.mjs"},"./memory-protocol":{"types":"./dist/MemoryProtocol.d.mts","default":"./dist/MemoryProtocol.mjs"},"./port-protocol":{"types":"./dist/PortProtocol.d.mts","default":"./dist/PortProtocol.mjs"},"./port-routing":{"types":"./dist/PortRouting.d.mts","default":"./dist/PortRouting.mjs"},"./testing/do-storage-failpoint-testing":{"types":"./dist/DoStorageFailpointTesting.d.mts","default":"./dist/DoStorageFailpointTesting.mjs"},"./do-message-delivery-store":{"types":"./dist/DoMessageDeliveryStore.d.mts","default":"./dist/DoMessageDeliveryStore.mjs"}},"description":"Durable Object SQLite storage adapters and the routed port protocol for Effect Agent on Cloudflare.","license":"MIT","repository":{"type":"git","url":"git+https://github.com/yielded-dev/agent.git","directory":"packages/storage-cloudflare"},"files":["dist","src"],"type":"module","sideEffects":[],"publishConfig":{"access":"public"},"scripts":{"build":"vp pack","check":"tsc --noEmit -p tsconfig.json"}}
1
+ {"name":"@yielded/agent-storage-cloudflare","version":"0.1.0-beta.176","dependencies":{"@effect/platform-browser":"4.0.4","@effect/sql-sqlite-do":"4.0.4","@yielded/agent":"0.1.0-beta.176","@yielded/agent-storage-sql":"0.1.0-beta.176"},"devDependencies":{"@cloudflare/vitest-plugin":"1.4.0","@cloudflare/workers-types":"5.20260926.1","@effect/vitest":"4.0.4","@yielded/agent-testing":"0.1.0-beta.176","effect":"4.0.4","typescript":"7.0.2","vite":"npm:@voidzero-dev/vite-plus-core@1.1.0","vite-plus":"1.1.0","vitest":"5.0.3"},"peerDependencies":{"effect":"^4.0.3"},"exports":{".":{"types":"./dist/index.d.mts","default":"./dist/index.mjs"},"./do-memory-store":{"types":"./dist/DoMemoryStore.d.mts","default":"./dist/DoMemoryStore.mjs"},"./do-schedule-store":{"types":"./dist/DoScheduleStore.d.mts","default":"./dist/DoScheduleStore.mjs"},"./do-storage-config":{"types":"./dist/DoStorageConfig.d.mts","default":"./dist/DoStorageConfig.mjs"},"./do-storage-error":{"types":"./dist/DoStorageError.d.mts","default":"./dist/DoStorageError.mjs"},"./do-storage-failpoint":{"types":"./dist/DoStorageFailpoint.d.mts","default":"./dist/DoStorageFailpoint.mjs"},"./do-storage-version":{"types":"./dist/DoStorageVersion.d.mts","default":"./dist/DoStorageVersion.mjs"},"./do-submission-ledger":{"types":"./dist/DoSubmissionLedger.d.mts","default":"./dist/DoSubmissionLedger.mjs"},"./do-subscription-store":{"types":"./dist/DoSubscriptionStore.d.mts","default":"./dist/DoSubscriptionStore.mjs"},"./do-thread-store":{"types":"./dist/DoThreadStore.d.mts","default":"./dist/DoThreadStore.mjs"},"./memory-protocol":{"types":"./dist/MemoryProtocol.d.mts","default":"./dist/MemoryProtocol.mjs"},"./port-protocol":{"types":"./dist/PortProtocol.d.mts","default":"./dist/PortProtocol.mjs"},"./port-routing":{"types":"./dist/PortRouting.d.mts","default":"./dist/PortRouting.mjs"},"./testing/do-storage-failpoint-testing":{"types":"./dist/DoStorageFailpointTesting.d.mts","default":"./dist/DoStorageFailpointTesting.mjs"},"./do-message-delivery-store":{"types":"./dist/DoMessageDeliveryStore.d.mts","default":"./dist/DoMessageDeliveryStore.mjs"}},"description":"Durable Object SQLite storage adapters and the routed port protocol for Effect Agent on Cloudflare.","license":"MIT","repository":{"type":"git","url":"git+https://github.com/yielded-dev/agent.git","directory":"packages/storage-cloudflare"},"files":["dist","src"],"type":"module","sideEffects":[],"publishConfig":{"access":"public"},"scripts":{"build":"vp pack","check":"tsc --noEmit -p tsconfig.json"}}
@@ -8,6 +8,10 @@ export type DoStorageFailpointHandler = (
8
8
 
9
9
  const noFailpoint: DoStorageFailpointHandler = () => Effect.void;
10
10
 
11
+ /** @internal Select a plain native body only for the library's no-op handler. */
12
+ export const isDefaultDoStorageFailpoint = (handler: DoStorageFailpointHandler): boolean =>
13
+ handler === noFailpoint;
14
+
11
15
  /** Explicit fault-injection authority used at Durable Object storage operation boundaries. */
12
16
  export class DoStorageFailpoint extends Context.Service<
13
17
  DoStorageFailpoint,