@effect-agent/storage-cloudflare 0.1.0-beta.8 → 0.1.0-beta.81

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 (73) hide show
  1. package/dist/DoMemoryStore.d.mts +29 -0
  2. package/dist/DoMemoryStore.mjs +55 -0
  3. package/dist/DoMemoryStore.mjs.map +1 -0
  4. package/dist/DoMessageDeliveryStore.d.mts +17 -0
  5. package/dist/DoMessageDeliveryStore.mjs +32 -0
  6. package/dist/DoMessageDeliveryStore.mjs.map +1 -0
  7. package/dist/DoScheduleStore.d.mts +36 -0
  8. package/dist/DoScheduleStore.mjs +388 -0
  9. package/dist/DoScheduleStore.mjs.map +1 -0
  10. package/dist/DoStorageConfig.d.mts +45 -0
  11. package/dist/DoStorageConfig.mjs +52 -0
  12. package/dist/DoStorageConfig.mjs.map +1 -0
  13. package/dist/DoStorageError-Cmhvl4TQ.d.mts +98 -0
  14. package/dist/DoStorageError.d.mts +2 -0
  15. package/dist/DoStorageError.mjs +164 -0
  16. package/dist/DoStorageError.mjs.map +1 -0
  17. package/dist/DoStorageFailpoint.d.mts +17 -0
  18. package/dist/DoStorageFailpoint.mjs +14 -0
  19. package/dist/DoStorageFailpoint.mjs.map +1 -0
  20. package/dist/DoStorageFailpointTesting.d.mts +34 -0
  21. package/dist/DoStorageFailpointTesting.mjs +35 -0
  22. package/dist/DoStorageFailpointTesting.mjs.map +1 -0
  23. package/dist/DoStorageVersion-x5OOurvZ.d.mts +12 -0
  24. package/dist/DoStorageVersion.d.mts +2 -0
  25. package/dist/DoStorageVersion.mjs +8 -0
  26. package/dist/DoStorageVersion.mjs.map +1 -0
  27. package/dist/DoSubmissionLedger.d.mts +23 -0
  28. package/dist/DoSubmissionLedger.mjs +1849 -0
  29. package/dist/DoSubmissionLedger.mjs.map +1 -0
  30. package/dist/DoSubscriptionStore.d.mts +25 -0
  31. package/dist/DoSubscriptionStore.mjs +183 -0
  32. package/dist/DoSubscriptionStore.mjs.map +1 -0
  33. package/dist/DoThreadStore.d.mts +59 -0
  34. package/dist/DoThreadStore.mjs +465 -0
  35. package/dist/DoThreadStore.mjs.map +1 -0
  36. package/dist/MemoryProtocol.d.mts +38160 -0
  37. package/dist/MemoryProtocol.mjs +219 -0
  38. package/dist/MemoryProtocol.mjs.map +1 -0
  39. package/dist/PortProtocol.d.mts +3207 -0
  40. package/dist/PortProtocol.mjs +176 -0
  41. package/dist/PortProtocol.mjs.map +1 -0
  42. package/dist/PortRouting.d.mts +83 -0
  43. package/dist/PortRouting.mjs +410 -0
  44. package/dist/PortRouting.mjs.map +1 -0
  45. package/dist/do-journal-DHqCQeBU.mjs +991 -0
  46. package/dist/do-journal-DHqCQeBU.mjs.map +1 -0
  47. package/dist/index.d.mts +14 -1521
  48. package/dist/index.mjs +14 -3695
  49. package/dist/migrations-Ba_kOrSx.mjs +287 -0
  50. package/dist/migrations-Ba_kOrSx.mjs.map +1 -0
  51. package/dist/rolldown-runtime-D7D4PA-g.mjs +13 -0
  52. package/package.json +1 -45
  53. package/src/DoMemoryStore.ts +59 -0
  54. package/src/DoMessageDeliveryStore.ts +53 -0
  55. package/src/DoScheduleStore.ts +622 -0
  56. package/src/{errors.ts → DoStorageError.ts} +10 -3
  57. package/src/DoStorageFailpoint.ts +20 -0
  58. package/src/{do-storage-failpoint.ts → DoStorageFailpointTesting.ts} +5 -18
  59. package/src/DoStorageVersion.ts +2 -0
  60. package/src/{do-ledger.ts → DoSubmissionLedger.ts} +862 -163
  61. package/src/DoSubscriptionStore.ts +329 -0
  62. package/src/DoThreadStore.ts +1014 -0
  63. package/src/MemoryProtocol.ts +355 -0
  64. package/src/{port-protocol.ts → PortProtocol.ts} +44 -37
  65. package/src/{routing.ts → PortRouting.ts} +292 -264
  66. package/src/index.ts +13 -32
  67. package/src/{do-journal.ts → internal/do-journal.ts} +716 -232
  68. package/src/internal/message-delivery-schema.ts +24 -0
  69. package/src/{migrations.ts → internal/migrations.ts} +51 -35
  70. package/src/internal/recovery-checkpoint-schema.ts +17 -0
  71. package/dist/index.mjs.map +0 -1
  72. package/src/do-conversation-store.ts +0 -850
  73. /package/src/{do-storage-config.ts → DoStorageConfig.ts} +0 -0
@@ -0,0 +1,287 @@
1
+ import { Effect } from "effect";
2
+ import * as SqlClient from "effect/unstable/sql/SqlClient";
3
+ import { SqliteMigrator } from "@effect/sql-sqlite-do";
4
+ //#region src/internal/message-delivery-schema.ts
5
+ /** Additive storage owned by this adapter; creation participates in its version transaction. */
6
+ const createMessageDeliveryTables = Effect.gen(function* () {
7
+ const sql = yield* SqlClient.SqlClient;
8
+ yield* sql`
9
+ CREATE TABLE effect_agent_message_deliveries (
10
+ owner_thread_id TEXT NOT NULL,
11
+ message_id TEXT NOT NULL,
12
+ version INTEGER NOT NULL,
13
+ state TEXT NOT NULL,
14
+ deadline_at_millis INTEGER,
15
+ record_json TEXT NOT NULL,
16
+ PRIMARY KEY (owner_thread_id, message_id)
17
+ )
18
+ `.withoutTransform;
19
+ yield* sql`
20
+ CREATE INDEX effect_agent_message_deliveries_due
21
+ ON effect_agent_message_deliveries (deadline_at_millis, owner_thread_id, message_id)
22
+ WHERE deadline_at_millis IS NOT NULL
23
+ `.withoutTransform;
24
+ });
25
+ //#endregion
26
+ //#region src/internal/recovery-checkpoint-schema.ts
27
+ /** One disposable recovery snapshot per Thread, independent of generic projections. */
28
+ const createRecoveryCheckpointTable = Effect.gen(function* () {
29
+ yield* (yield* SqlClient.SqlClient)`
30
+ CREATE TABLE effect_agent_recovery_checkpoints (
31
+ thread_id TEXT PRIMARY KEY NOT NULL,
32
+ through_sequence INTEGER NOT NULL,
33
+ tail_digest TEXT NOT NULL,
34
+ checkpoint_json TEXT NOT NULL,
35
+ FOREIGN KEY (thread_id) REFERENCES effect_agent_threads(thread_id) ON DELETE RESTRICT
36
+ )
37
+ `.withoutTransform;
38
+ });
39
+ //#endregion
40
+ //#region src/internal/migrations.ts
41
+ /** The current storage version recorded in `effect_agent_meta`. */
42
+ const CurrentDoStorageVersion = 6;
43
+ /** Index only outstanding obligations, ordered by the recovery scan's stable cursor. */
44
+ const createNonterminalIndex = Effect.gen(function* () {
45
+ yield* (yield* SqlClient.SqlClient)`CREATE INDEX effect_agent_submissions_nonterminal ON effect_agent_submissions (thread_id, queue_sequence) WHERE state <> 'settled'`.withoutTransform;
46
+ });
47
+ /**
48
+ * The Thread Durable Object schema shares its thread and ledger tables with Node/SQLite.
49
+ * Schedules and subscriptions use separate Durable Objects. Two DC-specific additions:
50
+ *
51
+ * 1. `effect_agent_meta` replaces `PRAGMA user_version` as the exact-or-fresh version gate —
52
+ * a meta table is portable regardless of which PRAGMAs Durable Object SQL storage allows.
53
+ * 2. `effect_agent_child_settlements` is the durable cross-store notification marker the
54
+ * SubmissionLedger port contract mandates for cross-store adapters (`suspend`'s covering
55
+ * check and `recordChildSettled`'s wake both consult it): parent and child Threads
56
+ * live in different Durable Objects, so a child settlement reported before the parent's
57
+ * suspend commits must be observable from the PARENT's own storage.
58
+ */
59
+ const doMigrations = SqliteMigrator.fromRecord({ "1_current_cloudflare_thread_object": Effect.gen(function* () {
60
+ const sql = yield* SqlClient.SqlClient;
61
+ yield* sql`
62
+ CREATE TABLE effect_agent_threads (
63
+ thread_id TEXT PRIMARY KEY NOT NULL,
64
+ created_at TEXT NOT NULL,
65
+ tail_sequence INTEGER NOT NULL,
66
+ tail_digest TEXT NOT NULL,
67
+ producer_epoch INTEGER NOT NULL
68
+ )
69
+ `.withoutTransform;
70
+ yield* sql`
71
+ CREATE TABLE effect_agent_canonical_batches (
72
+ thread_id TEXT NOT NULL,
73
+ batch_id TEXT NOT NULL,
74
+ first_sequence INTEGER NOT NULL,
75
+ last_sequence INTEGER NOT NULL,
76
+ batch_digest TEXT NOT NULL,
77
+ tail_digest TEXT NOT NULL,
78
+ batch_json TEXT NOT NULL,
79
+ PRIMARY KEY (thread_id, batch_id),
80
+ FOREIGN KEY (thread_id)
81
+ REFERENCES effect_agent_threads(thread_id)
82
+ ON DELETE RESTRICT
83
+ )
84
+ `.withoutTransform;
85
+ yield* sql`
86
+ CREATE TABLE effect_agent_canonical_records (
87
+ thread_id TEXT NOT NULL,
88
+ sequence INTEGER NOT NULL,
89
+ record_id TEXT NOT NULL,
90
+ batch_id TEXT NOT NULL,
91
+ record_json TEXT NOT NULL,
92
+ PRIMARY KEY (thread_id, sequence),
93
+ UNIQUE (thread_id, record_id),
94
+ FOREIGN KEY (thread_id, batch_id)
95
+ REFERENCES effect_agent_canonical_batches(thread_id, batch_id)
96
+ ON DELETE RESTRICT
97
+ )
98
+ `.withoutTransform;
99
+ yield* sql`
100
+ CREATE INDEX effect_agent_canonical_records_batch
101
+ ON effect_agent_canonical_records (thread_id, batch_id, sequence)
102
+ `.withoutTransform;
103
+ yield* sql`
104
+ CREATE TABLE effect_agent_checkpoints (
105
+ thread_id TEXT NOT NULL,
106
+ through_sequence INTEGER NOT NULL,
107
+ tail_digest TEXT NOT NULL,
108
+ checkpoint_json TEXT NOT NULL,
109
+ PRIMARY KEY (thread_id, through_sequence),
110
+ FOREIGN KEY (thread_id)
111
+ REFERENCES effect_agent_threads(thread_id)
112
+ ON DELETE RESTRICT
113
+ )
114
+ `.withoutTransform;
115
+ yield* sql`
116
+ CREATE TABLE effect_agent_submissions (
117
+ submission_id TEXT PRIMARY KEY NOT NULL,
118
+ thread_id TEXT NOT NULL,
119
+ queue_sequence INTEGER NOT NULL,
120
+ principal TEXT NOT NULL,
121
+ idempotency_key TEXT NOT NULL,
122
+ agent_id TEXT NOT NULL,
123
+ agent_digests_json TEXT NOT NULL,
124
+ deployment_id TEXT NOT NULL,
125
+ input_json TEXT NOT NULL,
126
+ input_digest TEXT NOT NULL,
127
+ receipt_id TEXT NOT NULL,
128
+ state TEXT NOT NULL,
129
+ settled_outcome TEXT,
130
+ created_at TEXT NOT NULL,
131
+ ready_at TEXT,
132
+ input_applied_record_id TEXT,
133
+ input_applied_sequence INTEGER,
134
+ joined_host_submission_id TEXT,
135
+ suspended_reason_json TEXT,
136
+ suspended_at TEXT,
137
+ unknown_reason TEXT,
138
+ unknown_tool_call_ids_json TEXT,
139
+ parent_submission_id TEXT,
140
+ parent_tool_call_id TEXT,
141
+ admission_group TEXT,
142
+ admission_fence_json TEXT,
143
+ worker_admission_json TEXT,
144
+ message_admission_json TEXT,
145
+ UNIQUE (thread_id, principal, idempotency_key),
146
+ UNIQUE (thread_id, queue_sequence)
147
+ )
148
+ `.withoutTransform;
149
+ yield* sql`
150
+ CREATE INDEX effect_agent_submissions_joined_host
151
+ ON effect_agent_submissions (joined_host_submission_id)
152
+ `.withoutTransform;
153
+ yield* sql`
154
+ CREATE INDEX effect_agent_submissions_parent
155
+ ON effect_agent_submissions (parent_submission_id)
156
+ `.withoutTransform;
157
+ yield* sql`
158
+ CREATE INDEX effect_agent_submissions_group
159
+ ON effect_agent_submissions (thread_id, admission_group, state)
160
+ `.withoutTransform;
161
+ yield* sql`
162
+ CREATE TABLE effect_agent_submission_ownership (
163
+ submission_id TEXT PRIMARY KEY NOT NULL,
164
+ attempt_id TEXT NOT NULL,
165
+ ownership_token TEXT NOT NULL,
166
+ producer_epoch INTEGER NOT NULL,
167
+ owner_producer_id TEXT NOT NULL,
168
+ lease_expires_at TEXT NOT NULL,
169
+ FOREIGN KEY (submission_id)
170
+ REFERENCES effect_agent_submissions(submission_id)
171
+ ON DELETE RESTRICT
172
+ )
173
+ `.withoutTransform;
174
+ yield* sql`
175
+ CREATE TABLE effect_agent_attempts (
176
+ attempt_id TEXT PRIMARY KEY NOT NULL,
177
+ submission_id TEXT NOT NULL,
178
+ thread_id TEXT NOT NULL,
179
+ owner_producer_id TEXT NOT NULL,
180
+ producer_epoch INTEGER NOT NULL,
181
+ claimed_at TEXT NOT NULL,
182
+ FOREIGN KEY (submission_id)
183
+ REFERENCES effect_agent_submissions(submission_id)
184
+ ON DELETE RESTRICT
185
+ )
186
+ `.withoutTransform;
187
+ yield* sql`
188
+ CREATE TABLE effect_agent_settlement_reservations (
189
+ submission_id TEXT PRIMARY KEY NOT NULL,
190
+ settlement_id TEXT NOT NULL,
191
+ outcome TEXT NOT NULL,
192
+ record_id TEXT NOT NULL,
193
+ record_json TEXT NOT NULL,
194
+ record_digest TEXT NOT NULL,
195
+ reserved_at TEXT NOT NULL,
196
+ finalized_at TEXT,
197
+ FOREIGN KEY (submission_id)
198
+ REFERENCES effect_agent_submissions(submission_id)
199
+ ON DELETE RESTRICT
200
+ )
201
+ `.withoutTransform;
202
+ yield* sql`
203
+ CREATE TABLE effect_agent_abort_intents (
204
+ submission_id TEXT PRIMARY KEY NOT NULL,
205
+ author TEXT NOT NULL,
206
+ reason TEXT NOT NULL,
207
+ requested_at TEXT NOT NULL,
208
+ canonical_record_id TEXT,
209
+ FOREIGN KEY (submission_id)
210
+ REFERENCES effect_agent_submissions(submission_id)
211
+ ON DELETE RESTRICT
212
+ )
213
+ `.withoutTransform;
214
+ yield* sql`
215
+ CREATE TABLE effect_agent_approval_decisions (
216
+ submission_id TEXT NOT NULL,
217
+ tool_call_id TEXT NOT NULL,
218
+ decision TEXT NOT NULL,
219
+ resolver TEXT NOT NULL,
220
+ reason TEXT NOT NULL,
221
+ decided_at TEXT NOT NULL,
222
+ PRIMARY KEY (submission_id, tool_call_id),
223
+ FOREIGN KEY (submission_id)
224
+ REFERENCES effect_agent_submissions(submission_id)
225
+ ON DELETE RESTRICT
226
+ )
227
+ `.withoutTransform;
228
+ yield* sql`
229
+ CREATE TABLE effect_agent_unknown_resolutions (
230
+ submission_id TEXT NOT NULL,
231
+ tool_call_id TEXT NOT NULL,
232
+ author TEXT NOT NULL,
233
+ reason TEXT NOT NULL,
234
+ resolution_json TEXT NOT NULL,
235
+ resolved_at TEXT NOT NULL,
236
+ PRIMARY KEY (submission_id, tool_call_id),
237
+ FOREIGN KEY (submission_id)
238
+ REFERENCES effect_agent_submissions(submission_id)
239
+ ON DELETE RESTRICT
240
+ )
241
+ `.withoutTransform;
242
+ yield* sql`
243
+ CREATE TABLE effect_agent_child_reservations (
244
+ reservation_id TEXT PRIMARY KEY NOT NULL,
245
+ parent_submission_id TEXT NOT NULL,
246
+ parent_tool_call_id TEXT NOT NULL,
247
+ child_submission_id TEXT,
248
+ status TEXT NOT NULL,
249
+ allocation_json TEXT NOT NULL,
250
+ allocation_digest TEXT NOT NULL,
251
+ accounting_json TEXT,
252
+ reserved_at TEXT NOT NULL,
253
+ release_began_at TEXT,
254
+ released_at TEXT,
255
+ UNIQUE (parent_submission_id, parent_tool_call_id),
256
+ FOREIGN KEY (parent_submission_id)
257
+ REFERENCES effect_agent_submissions(submission_id)
258
+ ON DELETE RESTRICT
259
+ )
260
+ `.withoutTransform;
261
+ yield* sql`
262
+ CREATE TABLE effect_agent_child_settlements (
263
+ parent_submission_id TEXT NOT NULL,
264
+ child_submission_id TEXT NOT NULL,
265
+ child_outcome TEXT,
266
+ recorded_at TEXT NOT NULL,
267
+ PRIMARY KEY (parent_submission_id, child_submission_id)
268
+ )
269
+ `.withoutTransform;
270
+ yield* createNonterminalIndex;
271
+ yield* createMessageDeliveryTables;
272
+ yield* createRecoveryCheckpointTable;
273
+ yield* sql`
274
+ CREATE TABLE effect_agent_meta (
275
+ key TEXT PRIMARY KEY NOT NULL,
276
+ value TEXT NOT NULL
277
+ )
278
+ `.withoutTransform;
279
+ yield* sql`
280
+ INSERT INTO effect_agent_meta (key, value)
281
+ VALUES ('storage_version', ${String(6)})
282
+ `.withoutTransform;
283
+ }) });
284
+ //#endregion
285
+ export { createMessageDeliveryTables as a, createRecoveryCheckpointTable as i, createNonterminalIndex as n, doMigrations as r, CurrentDoStorageVersion as t };
286
+
287
+ //# sourceMappingURL=migrations-Ba_kOrSx.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"migrations-Ba_kOrSx.mjs","names":[],"sources":["../src/internal/message-delivery-schema.ts","../src/internal/recovery-checkpoint-schema.ts","../src/internal/migrations.ts"],"sourcesContent":["import { Effect } from \"effect\";\nimport * as SqlClient from \"effect/unstable/sql/SqlClient\";\n\n/** Additive storage owned by this adapter; creation participates in its version transaction. */\nexport const createMessageDeliveryTables = Effect.gen(function* () {\n const sql = yield* SqlClient.SqlClient;\n\n yield* sql`\n CREATE TABLE effect_agent_message_deliveries (\n owner_thread_id TEXT NOT NULL,\n message_id TEXT NOT NULL,\n version INTEGER NOT NULL,\n state TEXT NOT NULL,\n deadline_at_millis INTEGER,\n record_json TEXT NOT NULL,\n PRIMARY KEY (owner_thread_id, message_id)\n )\n `.withoutTransform;\n yield* sql`\n CREATE INDEX effect_agent_message_deliveries_due\n ON effect_agent_message_deliveries (deadline_at_millis, owner_thread_id, message_id)\n WHERE deadline_at_millis IS NOT NULL\n `.withoutTransform;\n});\n","import { Effect } from \"effect\";\nimport * as SqlClient from \"effect/unstable/sql/SqlClient\";\n\n/** One disposable recovery snapshot per Thread, independent of generic projections. */\nexport const createRecoveryCheckpointTable = Effect.gen(function* () {\n const sql = yield* SqlClient.SqlClient;\n\n yield* sql`\n CREATE TABLE effect_agent_recovery_checkpoints (\n thread_id TEXT PRIMARY KEY NOT NULL,\n through_sequence INTEGER NOT NULL,\n tail_digest TEXT NOT NULL,\n checkpoint_json TEXT NOT NULL,\n FOREIGN KEY (thread_id) REFERENCES effect_agent_threads(thread_id) ON DELETE RESTRICT\n )\n `.withoutTransform;\n});\n","import { SqliteMigrator } from \"@effect/sql-sqlite-do\";\nimport { Effect } from \"effect\";\nimport * as SqlClient from \"effect/unstable/sql/SqlClient\";\n\nimport { createMessageDeliveryTables } from \"./message-delivery-schema.ts\";\nimport { createRecoveryCheckpointTable } from \"./recovery-checkpoint-schema.ts\";\n\n/** The current storage version recorded in `effect_agent_meta`. */\nexport const CurrentDoStorageVersion = 6;\n\n/** Index only outstanding obligations, ordered by the recovery scan's stable cursor. */\nexport const createNonterminalIndex = Effect.gen(function* () {\n const sql = yield* SqlClient.SqlClient;\n\n yield* sql`CREATE INDEX effect_agent_submissions_nonterminal ON effect_agent_submissions (thread_id, queue_sequence) WHERE state <> 'settled'`\n .withoutTransform;\n});\n\n/**\n * The Thread Durable Object schema shares its thread and ledger tables with Node/SQLite.\n * Schedules and subscriptions use separate Durable Objects. Two DC-specific additions:\n *\n * 1. `effect_agent_meta` replaces `PRAGMA user_version` as the exact-or-fresh version gate —\n * a meta table is portable regardless of which PRAGMAs Durable Object SQL storage allows.\n * 2. `effect_agent_child_settlements` is the durable cross-store notification marker the\n * SubmissionLedger port contract mandates for cross-store adapters (`suspend`'s covering\n * check and `recordChildSettled`'s wake both consult it): parent and child Threads\n * live in different Durable Objects, so a child settlement reported before the parent's\n * suspend commits must be observable from the PARENT's own storage.\n */\nexport const doMigrations = SqliteMigrator.fromRecord({\n \"1_current_cloudflare_thread_object\": Effect.gen(function* () {\n const sql = yield* SqlClient.SqlClient;\n\n yield* sql`\n CREATE TABLE effect_agent_threads (\n thread_id TEXT PRIMARY KEY NOT NULL,\n created_at TEXT NOT NULL,\n tail_sequence INTEGER NOT NULL,\n tail_digest TEXT NOT NULL,\n producer_epoch INTEGER NOT NULL\n )\n `.withoutTransform;\n\n yield* sql`\n CREATE TABLE effect_agent_canonical_batches (\n thread_id TEXT NOT NULL,\n batch_id TEXT NOT NULL,\n first_sequence INTEGER NOT NULL,\n last_sequence INTEGER NOT NULL,\n batch_digest TEXT NOT NULL,\n tail_digest TEXT NOT NULL,\n batch_json TEXT NOT NULL,\n PRIMARY KEY (thread_id, batch_id),\n FOREIGN KEY (thread_id)\n REFERENCES effect_agent_threads(thread_id)\n ON DELETE RESTRICT\n )\n `.withoutTransform;\n\n yield* sql`\n CREATE TABLE effect_agent_canonical_records (\n thread_id TEXT NOT NULL,\n sequence INTEGER NOT NULL,\n record_id TEXT NOT NULL,\n batch_id TEXT NOT NULL,\n record_json TEXT NOT NULL,\n PRIMARY KEY (thread_id, sequence),\n UNIQUE (thread_id, record_id),\n FOREIGN KEY (thread_id, batch_id)\n REFERENCES effect_agent_canonical_batches(thread_id, batch_id)\n ON DELETE RESTRICT\n )\n `.withoutTransform;\n\n yield* sql`\n CREATE INDEX effect_agent_canonical_records_batch\n ON effect_agent_canonical_records (thread_id, batch_id, sequence)\n `.withoutTransform;\n\n yield* sql`\n CREATE TABLE effect_agent_checkpoints (\n thread_id TEXT NOT NULL,\n through_sequence INTEGER NOT NULL,\n tail_digest TEXT NOT NULL,\n checkpoint_json TEXT NOT NULL,\n PRIMARY KEY (thread_id, through_sequence),\n FOREIGN KEY (thread_id)\n REFERENCES effect_agent_threads(thread_id)\n ON DELETE RESTRICT\n )\n `.withoutTransform;\n\n // Admission rows exist before Thread materialization (durability §4), so\n // thread_id intentionally carries no foreign key into effect_agent_threads.\n yield* sql`\n CREATE TABLE effect_agent_submissions (\n submission_id TEXT PRIMARY KEY NOT NULL,\n thread_id TEXT NOT NULL,\n queue_sequence INTEGER NOT NULL,\n principal TEXT NOT NULL,\n idempotency_key TEXT NOT NULL,\n agent_id TEXT NOT NULL,\n agent_digests_json TEXT NOT NULL,\n deployment_id TEXT NOT NULL,\n input_json TEXT NOT NULL,\n input_digest TEXT NOT NULL,\n receipt_id TEXT NOT NULL,\n state TEXT NOT NULL,\n settled_outcome TEXT,\n created_at TEXT NOT NULL,\n ready_at TEXT,\n input_applied_record_id TEXT,\n input_applied_sequence INTEGER,\n joined_host_submission_id TEXT,\n suspended_reason_json TEXT,\n suspended_at TEXT,\n unknown_reason TEXT,\n unknown_tool_call_ids_json TEXT,\n parent_submission_id TEXT,\n parent_tool_call_id TEXT,\n admission_group TEXT,\n admission_fence_json TEXT,\n worker_admission_json TEXT,\n message_admission_json TEXT,\n UNIQUE (thread_id, principal, idempotency_key),\n UNIQUE (thread_id, queue_sequence)\n )\n `.withoutTransform;\n\n yield* sql`\n CREATE INDEX effect_agent_submissions_joined_host\n ON effect_agent_submissions (joined_host_submission_id)\n `.withoutTransform;\n\n yield* sql`\n CREATE INDEX effect_agent_submissions_parent\n ON effect_agent_submissions (parent_submission_id)\n `.withoutTransform;\n\n yield* sql`\n CREATE INDEX effect_agent_submissions_group\n ON effect_agent_submissions (thread_id, admission_group, state)\n `.withoutTransform;\n\n yield* sql`\n CREATE TABLE effect_agent_submission_ownership (\n submission_id TEXT PRIMARY KEY NOT NULL,\n attempt_id TEXT NOT NULL,\n ownership_token TEXT NOT NULL,\n producer_epoch INTEGER NOT NULL,\n owner_producer_id TEXT NOT NULL,\n lease_expires_at TEXT NOT NULL,\n FOREIGN KEY (submission_id)\n REFERENCES effect_agent_submissions(submission_id)\n ON DELETE RESTRICT\n )\n `.withoutTransform;\n\n yield* sql`\n CREATE TABLE effect_agent_attempts (\n attempt_id TEXT PRIMARY KEY NOT NULL,\n submission_id TEXT NOT NULL,\n thread_id TEXT NOT NULL,\n owner_producer_id TEXT NOT NULL,\n producer_epoch INTEGER NOT NULL,\n claimed_at TEXT NOT NULL,\n FOREIGN KEY (submission_id)\n REFERENCES effect_agent_submissions(submission_id)\n ON DELETE RESTRICT\n )\n `.withoutTransform;\n\n yield* sql`\n CREATE TABLE effect_agent_settlement_reservations (\n submission_id TEXT PRIMARY KEY NOT NULL,\n settlement_id TEXT NOT NULL,\n outcome TEXT NOT NULL,\n record_id TEXT NOT NULL,\n record_json TEXT NOT NULL,\n record_digest TEXT NOT NULL,\n reserved_at TEXT NOT NULL,\n finalized_at TEXT,\n FOREIGN KEY (submission_id)\n REFERENCES effect_agent_submissions(submission_id)\n ON DELETE RESTRICT\n )\n `.withoutTransform;\n\n yield* sql`\n CREATE TABLE effect_agent_abort_intents (\n submission_id TEXT PRIMARY KEY NOT NULL,\n author TEXT NOT NULL,\n reason TEXT NOT NULL,\n requested_at TEXT NOT NULL,\n canonical_record_id TEXT,\n FOREIGN KEY (submission_id)\n REFERENCES effect_agent_submissions(submission_id)\n ON DELETE RESTRICT\n )\n `.withoutTransform;\n\n yield* sql`\n CREATE TABLE effect_agent_approval_decisions (\n submission_id TEXT NOT NULL,\n tool_call_id TEXT NOT NULL,\n decision TEXT NOT NULL,\n resolver TEXT NOT NULL,\n reason TEXT NOT NULL,\n decided_at TEXT NOT NULL,\n PRIMARY KEY (submission_id, tool_call_id),\n FOREIGN KEY (submission_id)\n REFERENCES effect_agent_submissions(submission_id)\n ON DELETE RESTRICT\n )\n `.withoutTransform;\n\n yield* sql`\n CREATE TABLE effect_agent_unknown_resolutions (\n submission_id TEXT NOT NULL,\n tool_call_id TEXT NOT NULL,\n author TEXT NOT NULL,\n reason TEXT NOT NULL,\n resolution_json TEXT NOT NULL,\n resolved_at TEXT NOT NULL,\n PRIMARY KEY (submission_id, tool_call_id),\n FOREIGN KEY (submission_id)\n REFERENCES effect_agent_submissions(submission_id)\n ON DELETE RESTRICT\n )\n `.withoutTransform;\n\n yield* sql`\n CREATE TABLE effect_agent_child_reservations (\n reservation_id TEXT PRIMARY KEY NOT NULL,\n parent_submission_id TEXT NOT NULL,\n parent_tool_call_id TEXT NOT NULL,\n child_submission_id TEXT,\n status TEXT NOT NULL,\n allocation_json TEXT NOT NULL,\n allocation_digest TEXT NOT NULL,\n accounting_json TEXT,\n reserved_at TEXT NOT NULL,\n release_began_at TEXT,\n released_at TEXT,\n UNIQUE (parent_submission_id, parent_tool_call_id),\n FOREIGN KEY (parent_submission_id)\n REFERENCES effect_agent_submissions(submission_id)\n ON DELETE RESTRICT\n )\n `.withoutTransform;\n\n // Durable cross-store child-settlement notification marker (parent-side; the child's row\n // lives in ANOTHER Durable Object). child_outcome is nullable: the notification command\n // carries identities only, and the child's canonical Settlement stays the outcome\n // authority (DUR-015). No foreign keys: the parent row is checked by the operation, and\n // the child row is intentionally foreign.\n yield* sql`\n CREATE TABLE effect_agent_child_settlements (\n parent_submission_id TEXT NOT NULL,\n child_submission_id TEXT NOT NULL,\n child_outcome TEXT,\n recorded_at TEXT NOT NULL,\n PRIMARY KEY (parent_submission_id, child_submission_id)\n )\n `.withoutTransform;\n\n yield* createNonterminalIndex;\n yield* createMessageDeliveryTables;\n yield* createRecoveryCheckpointTable;\n yield* sql`\n CREATE TABLE effect_agent_meta (\n key TEXT PRIMARY KEY NOT NULL,\n value TEXT NOT NULL\n )\n `.withoutTransform;\n\n yield* sql`\n INSERT INTO effect_agent_meta (key, value)\n VALUES ('storage_version', ${String(CurrentDoStorageVersion)})\n `.withoutTransform;\n }),\n});\n"],"mappings":";;;;;AAIA,MAAa,8BAA8B,OAAO,IAAI,aAAa;CACjE,MAAM,MAAM,OAAO,UAAU;CAE7B,OAAO,GAAG;;;;;;;;;;IAUR;CACF,OAAO,GAAG;;;;IAIR;AACJ,CAAC;;;;ACnBD,MAAa,gCAAgC,OAAO,IAAI,aAAa;CAGnE,OAAO,CAAA,OAFY,UAAU,UAAA,AAEnB;;;;;;;;IAQR;AACJ,CAAC;;;;ACRD,MAAa,0BAA0B;;AAGvC,MAAa,yBAAyB,OAAO,IAAI,aAAa;CAG5D,OAAO,CAAA,OAFY,UAAU,UAAA,AAEnB,qIACP;AACL,CAAC;;;;;;;;;;;;;AAcD,MAAa,eAAe,eAAe,WAAW,EACpD,sCAAsC,OAAO,IAAI,aAAa;CAC5D,MAAM,MAAM,OAAO,UAAU;CAE7B,OAAO,GAAG;;;;;;;;MAQR;CAEF,OAAO,GAAG;;;;;;;;;;;;;;MAcR;CAEF,OAAO,GAAG;;;;;;;;;;;;;MAaR;CAEF,OAAO,GAAG;;;MAGR;CAEF,OAAO,GAAG;;;;;;;;;;;MAWR;CAIF,OAAO,GAAG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;MAiCR;CAEF,OAAO,GAAG;;;MAGR;CAEF,OAAO,GAAG;;;MAGR;CAEF,OAAO,GAAG;;;MAGR;CAEF,OAAO,GAAG;;;;;;;;;;;;MAYR;CAEF,OAAO,GAAG;;;;;;;;;;;;MAYR;CAEF,OAAO,GAAG;;;;;;;;;;;;;;MAcR;CAEF,OAAO,GAAG;;;;;;;;;;;MAWR;CAEF,OAAO,GAAG;;;;;;;;;;;;;MAaR;CAEF,OAAO,GAAG;;;;;;;;;;;;;MAaR;CAEF,OAAO,GAAG;;;;;;;;;;;;;;;;;;MAkBR;CAOF,OAAO,GAAG;;;;;;;;MAQR;CAEF,OAAO;CACP,OAAO;CACP,OAAO;CACP,OAAO,GAAG;;;;;MAKR;CAEF,OAAO,GAAG;;mCAEqB,OAAA,CAA8B,EAAE;MAC7D;AACJ,CAAC,EACH,CAAC"}
@@ -0,0 +1,13 @@
1
+ //#region \0rolldown/runtime.js
2
+ var __defProp = Object.defineProperty;
3
+ var __exportAll = (all, no_symbols) => {
4
+ let target = {};
5
+ for (var name in all) __defProp(target, name, {
6
+ get: all[name],
7
+ enumerable: true
8
+ });
9
+ if (!no_symbols) __defProp(target, Symbol.toStringTag, { value: "Module" });
10
+ return target;
11
+ };
12
+ //#endregion
13
+ export { __exportAll as t };
package/package.json CHANGED
@@ -1,45 +1 @@
1
- {
2
- "name": "@effect-agent/storage-cloudflare",
3
- "version": "0.1.0-beta.8",
4
- "exports": {
5
- ".": {
6
- "types": "./dist/index.d.mts",
7
- "default": "./dist/index.mjs"
8
- }
9
- },
10
- "dependencies": {
11
- "@effect-agent/session": "0.1.0-beta.8",
12
- "@effect/platform-browser": "4.0.0-beta.107",
13
- "@effect/sql-sqlite-do": "4.0.0-beta.107",
14
- "effect": "4.0.0-beta.107"
15
- },
16
- "description": "Durable Object SQLite storage adapters and the routed port protocol for Effect Agent on Cloudflare.",
17
- "license": "MIT",
18
- "repository": {
19
- "type": "git",
20
- "url": "git+https://github.com/danieljvdm/effect-agent.git",
21
- "directory": "packages/storage-cloudflare"
22
- },
23
- "files": [
24
- "dist",
25
- "src"
26
- ],
27
- "type": "module",
28
- "publishConfig": {
29
- "access": "public"
30
- },
31
- "scripts": {
32
- "build": "vp pack",
33
- "check": "tsc --noEmit -p tsconfig.json",
34
- "test": "vitest run"
35
- },
36
- "devDependencies": {
37
- "@cloudflare/vitest-pool-workers": "0.21.3",
38
- "@cloudflare/workers-types": "5.20260813.1",
39
- "@effect-agent/testing": "0.1.0-beta.6",
40
- "@effect/vitest": "4.0.0-beta.107",
41
- "typescript": "7.0.2",
42
- "vite-plus": "0.2.6",
43
- "vitest": "4.1.10"
44
- }
45
- }
1
+ {"name":"@effect-agent/storage-cloudflare","version":"0.1.0-beta.81","dependencies":{"@effect-agent/core":"0.1.0-beta.81","@effect-agent/thread":"0.1.0-beta.81","@effect/platform-browser":"4.0.0-rc.112","@effect/sql-sqlite-do":"4.0.0-rc.112"},"devDependencies":{"@cloudflare/vitest-pool-workers":"0.21.3","@cloudflare/workers-types":"5.20260825.1","@effect-agent/testing":"0.1.0-beta.81","@effect/vitest":"4.0.0-rc.112","effect":"4.0.0-rc.112","typescript":"7.0.2","vite-plus":"0.3.0","vitest":"4.1.11"},"peerDependencies":{"effect":"^4.0.0-rc.112"},"exports":{".":{"types":"./dist/index.d.mts","default":"./dist/index.mjs"},"./DoMemoryStore":{"types":"./dist/DoMemoryStore.d.mts","default":"./dist/DoMemoryStore.mjs"},"./DoScheduleStore":{"types":"./dist/DoScheduleStore.d.mts","default":"./dist/DoScheduleStore.mjs"},"./DoStorageConfig":{"types":"./dist/DoStorageConfig.d.mts","default":"./dist/DoStorageConfig.mjs"},"./DoStorageError":{"types":"./dist/DoStorageError.d.mts","default":"./dist/DoStorageError.mjs"},"./DoStorageFailpoint":{"types":"./dist/DoStorageFailpoint.d.mts","default":"./dist/DoStorageFailpoint.mjs"},"./DoStorageVersion":{"types":"./dist/DoStorageVersion.d.mts","default":"./dist/DoStorageVersion.mjs"},"./DoSubmissionLedger":{"types":"./dist/DoSubmissionLedger.d.mts","default":"./dist/DoSubmissionLedger.mjs"},"./DoSubscriptionStore":{"types":"./dist/DoSubscriptionStore.d.mts","default":"./dist/DoSubscriptionStore.mjs"},"./DoThreadStore":{"types":"./dist/DoThreadStore.d.mts","default":"./dist/DoThreadStore.mjs"},"./MemoryProtocol":{"types":"./dist/MemoryProtocol.d.mts","default":"./dist/MemoryProtocol.mjs"},"./PortProtocol":{"types":"./dist/PortProtocol.d.mts","default":"./dist/PortProtocol.mjs"},"./PortRouting":{"types":"./dist/PortRouting.d.mts","default":"./dist/PortRouting.mjs"},"./testing/DoStorageFailpointTesting":{"types":"./dist/DoStorageFailpointTesting.d.mts","default":"./dist/DoStorageFailpointTesting.mjs"},"./DoMessageDeliveryStore":{"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/danieljvdm/effect-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"}}
@@ -0,0 +1,59 @@
1
+ import { MemoryStorageError, MemoryMutationFailpoint } from "@effect-agent/core/MemoryStore";
2
+ import {
3
+ memoryStoreLayerWithFailpoints,
4
+ SqlMemoryLimits,
5
+ } from "@effect-agent/thread/SqlMemoryStore";
6
+ import { SqliteClient } from "@effect/sql-sqlite-do";
7
+ import { Effect, Layer, Schema } from "effect";
8
+
9
+ export class DoMemoryStorageLimits extends Schema.Class<DoMemoryStorageLimits>(
10
+ "@effect-agent/storage-cloudflare/DoMemoryStorageLimits",
11
+ )({
12
+ maxRowBytes: Schema.Int.check(Schema.isBetween({ minimum: 1, maximum: 1_900_000 })),
13
+ maxStorageBytes: Schema.Int.check(Schema.isBetween({ minimum: 1, maximum: 536_870_912 })),
14
+ maxDocuments: Schema.Int.check(Schema.isBetween({ minimum: 1, maximum: 100_000 })),
15
+ maxReceipts: Schema.Int.check(Schema.isBetween({ minimum: 1, maximum: 1_000_000 })),
16
+ reservedWithdrawalBytes: Schema.optional(Schema.Natural),
17
+ reservedWithdrawalReceipts: Schema.optional(Schema.Natural),
18
+ }) {}
19
+
20
+ export const defaultDoMemoryStorageLimits = DoMemoryStorageLimits.make({
21
+ maxRowBytes: 1_900_000,
22
+ maxStorageBytes: 536_870_912,
23
+ maxDocuments: 10_000,
24
+ maxReceipts: 100_000,
25
+ });
26
+
27
+ /**
28
+ * Local memory only, without Thread tables. Keep one SQL client per owner and pass the
29
+ * full storage handle: sql-only handles cannot provide atomic receipts and revisions.
30
+ * Byte limits conservatively count encoded rows, not SQLite page/index overhead.
31
+ * Optional withdrawal reserves default to zero and stay within hard byte/receipt limits.
32
+ * Ordinary Put cannot consume them. Deploy exclusively upgraded writers before relying
33
+ * on reserves; the SQL accounting migration preserves older writers and their receipts.
34
+ */
35
+ export const doMemoryStoreLayerWithFailpoints = (
36
+ storage: NonNullable<SqliteClient.SqliteClientConfig["storage"]>,
37
+ limits: DoMemoryStorageLimits = defaultDoMemoryStorageLimits,
38
+ ) =>
39
+ Layer.unwrap(
40
+ Schema.decodeUnknownEffect(DoMemoryStorageLimits)(limits).pipe(
41
+ Effect.mapError(() =>
42
+ MemoryStorageError.make({ operation: "memory storage limits", reason: "invalid-input" }),
43
+ ),
44
+ Effect.map((validated) =>
45
+ memoryStoreLayerWithFailpoints.pipe(
46
+ Layer.provide(Layer.succeed(SqlMemoryLimits, validated)),
47
+ Layer.provide(SqliteClient.layer({ storage })),
48
+ ),
49
+ ),
50
+ ),
51
+ );
52
+
53
+ export const doMemoryStoreLayer = (
54
+ storage: NonNullable<SqliteClient.SqliteClientConfig["storage"]>,
55
+ limits: DoMemoryStorageLimits = defaultDoMemoryStorageLimits,
56
+ ) =>
57
+ doMemoryStoreLayerWithFailpoints(storage, limits).pipe(
58
+ Layer.provide(MemoryMutationFailpoint.layer),
59
+ );
@@ -0,0 +1,53 @@
1
+ import {
2
+ MessageDeliveryError,
3
+ MessageDeliveryStore,
4
+ type MessageDeliveryStoreLimits,
5
+ } from "@effect-agent/thread/MessageDelivery";
6
+ import {
7
+ makeSqlMessageDeliveryStore,
8
+ SqlMessageDeliveryTransaction,
9
+ } from "@effect-agent/thread/SqlMessageDeliveryStore";
10
+ import { Effect, Layer } from "effect";
11
+ import * as SqlClient from "effect/unstable/sql/SqlClient";
12
+
13
+ import { DoStorageConfig } from "./DoStorageConfig.ts";
14
+ import { DoStorageFailpoint } from "./DoStorageFailpoint.ts";
15
+ import { initializeDoJournal } from "./internal/do-journal.ts";
16
+
17
+ const transactions = Layer.effect(
18
+ SqlMessageDeliveryTransaction,
19
+ Effect.gen(function* () {
20
+ const sql = yield* SqlClient.SqlClient;
21
+
22
+ return SqlMessageDeliveryTransaction.of({
23
+ run: (body) =>
24
+ sql
25
+ .withTransaction(body)
26
+ .pipe(
27
+ Effect.catchTag("SqlError", () =>
28
+ MessageDeliveryError.make({ reason: "storage", operation: "transaction" }),
29
+ ),
30
+ ),
31
+ });
32
+ }),
33
+ );
34
+
35
+ /**
36
+ * Message obligations in a Thread Object's own SQL storage. The platform must prearm
37
+ * maintenance before insertion and retain its alarm while nextDeadline is present.
38
+ */
39
+ export const doMessageDeliveryStoreLayer = (limits?: MessageDeliveryStoreLimits) =>
40
+ Layer.effect(
41
+ MessageDeliveryStore,
42
+ Effect.gen(function* () {
43
+ const sql = yield* SqlClient.SqlClient;
44
+ const config = yield* DoStorageConfig;
45
+ const failpoint = yield* DoStorageFailpoint;
46
+
47
+ yield* initializeDoJournal(sql, failpoint.hit, config.maxStoredValueBytes);
48
+
49
+ return yield* makeSqlMessageDeliveryStore(limits, {
50
+ maxStoredValueBytes: config.maxStoredValueBytes,
51
+ });
52
+ }),
53
+ ).pipe(Layer.provide(transactions));