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

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,24 @@
1
+ import { Effect } from "effect";
2
+ import * as SqlClient from "effect/unstable/sql/SqlClient";
3
+
4
+ /** Additive storage owned by this adapter; creation participates in its version transaction. */
5
+ export const createMessageDeliveryTables = Effect.gen(function* () {
6
+ const sql = yield* SqlClient.SqlClient;
7
+
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
+ });
@@ -2,35 +2,39 @@ import { SqliteMigrator } from "@effect/sql-sqlite-do";
2
2
  import { Effect } from "effect";
3
3
  import * as SqlClient from "effect/unstable/sql/SqlClient";
4
4
 
5
- /**
6
- * The exact-or-fresh storage version recorded in `effect_agent_meta`. Cloudflare is a fresh
7
- * platform, so there is exactly ONE migration carrying the complete current schema — no
8
- * v1→v4 history to replay (deployment spec §9: no rolling data-version promise during
9
- * private development).
10
- */
11
- export const CurrentDoStorageVersion = 1;
5
+ import { createMessageDeliveryTables } from "./message-delivery-schema.ts";
6
+ import { createRecoveryCheckpointTable } from "./recovery-checkpoint-schema.ts";
7
+
8
+ /** The current storage version recorded in `effect_agent_meta`. */
9
+ export const CurrentDoStorageVersion = 6;
10
+
11
+ /** Index only outstanding obligations, ordered by the recovery scan's stable cursor. */
12
+ export const createNonterminalIndex = Effect.gen(function* () {
13
+ const sql = yield* SqlClient.SqlClient;
14
+
15
+ yield* sql`CREATE INDEX effect_agent_submissions_nonterminal ON effect_agent_submissions (thread_id, queue_sequence) WHERE state <> 'settled'`
16
+ .withoutTransform;
17
+ });
12
18
 
13
19
  /**
14
- * The Conversation Durable Object schema. Table names and columns mirror the Node/SQLite v4
15
- * schema byte-for-byte (`packages/storage-sqlite/src/migrations.ts`, migrations 1–4 collapsed
16
- * into their final shape) so the shared conformance suites and crash-matrix rows address
17
- * identical durable state. Two DC-specific additions:
20
+ * The Thread Durable Object schema shares its thread and ledger tables with Node/SQLite.
21
+ * Schedules and subscriptions use separate Durable Objects. Two DC-specific additions:
18
22
  *
19
23
  * 1. `effect_agent_meta` replaces `PRAGMA user_version` as the exact-or-fresh version gate —
20
24
  * a meta table is portable regardless of which PRAGMAs Durable Object SQL storage allows.
21
25
  * 2. `effect_agent_child_settlements` is the durable cross-store notification marker the
22
26
  * SubmissionLedger port contract mandates for cross-store adapters (`suspend`'s covering
23
- * check and `recordChildSettled`'s wake both consult it): parent and child Conversations
27
+ * check and `recordChildSettled`'s wake both consult it): parent and child Threads
24
28
  * live in different Durable Objects, so a child settlement reported before the parent's
25
29
  * suspend commits must be observable from the PARENT's own storage.
26
30
  */
27
31
  export const doMigrations = SqliteMigrator.fromRecord({
28
- "1_current_cloudflare_conversation_object": Effect.gen(function* () {
32
+ "1_current_cloudflare_thread_object": Effect.gen(function* () {
29
33
  const sql = yield* SqlClient.SqlClient;
30
34
 
31
35
  yield* sql`
32
- CREATE TABLE effect_agent_conversations (
33
- conversation_id TEXT PRIMARY KEY NOT NULL,
36
+ CREATE TABLE effect_agent_threads (
37
+ thread_id TEXT PRIMARY KEY NOT NULL,
34
38
  created_at TEXT NOT NULL,
35
39
  tail_sequence INTEGER NOT NULL,
36
40
  tail_digest TEXT NOT NULL,
@@ -40,59 +44,59 @@ export const doMigrations = SqliteMigrator.fromRecord({
40
44
 
41
45
  yield* sql`
42
46
  CREATE TABLE effect_agent_canonical_batches (
43
- conversation_id TEXT NOT NULL,
47
+ thread_id TEXT NOT NULL,
44
48
  batch_id TEXT NOT NULL,
45
49
  first_sequence INTEGER NOT NULL,
46
50
  last_sequence INTEGER NOT NULL,
47
51
  batch_digest TEXT NOT NULL,
48
52
  tail_digest TEXT NOT NULL,
49
53
  batch_json TEXT NOT NULL,
50
- PRIMARY KEY (conversation_id, batch_id),
51
- FOREIGN KEY (conversation_id)
52
- REFERENCES effect_agent_conversations(conversation_id)
54
+ PRIMARY KEY (thread_id, batch_id),
55
+ FOREIGN KEY (thread_id)
56
+ REFERENCES effect_agent_threads(thread_id)
53
57
  ON DELETE RESTRICT
54
58
  )
55
59
  `.withoutTransform;
56
60
 
57
61
  yield* sql`
58
62
  CREATE TABLE effect_agent_canonical_records (
59
- conversation_id TEXT NOT NULL,
63
+ thread_id TEXT NOT NULL,
60
64
  sequence INTEGER NOT NULL,
61
65
  record_id TEXT NOT NULL,
62
66
  batch_id TEXT NOT NULL,
63
67
  record_json TEXT NOT NULL,
64
- PRIMARY KEY (conversation_id, sequence),
65
- UNIQUE (conversation_id, record_id),
66
- FOREIGN KEY (conversation_id, batch_id)
67
- REFERENCES effect_agent_canonical_batches(conversation_id, batch_id)
68
+ PRIMARY KEY (thread_id, sequence),
69
+ UNIQUE (thread_id, record_id),
70
+ FOREIGN KEY (thread_id, batch_id)
71
+ REFERENCES effect_agent_canonical_batches(thread_id, batch_id)
68
72
  ON DELETE RESTRICT
69
73
  )
70
74
  `.withoutTransform;
71
75
 
72
76
  yield* sql`
73
77
  CREATE INDEX effect_agent_canonical_records_batch
74
- ON effect_agent_canonical_records (conversation_id, batch_id, sequence)
78
+ ON effect_agent_canonical_records (thread_id, batch_id, sequence)
75
79
  `.withoutTransform;
76
80
 
77
81
  yield* sql`
78
82
  CREATE TABLE effect_agent_checkpoints (
79
- conversation_id TEXT NOT NULL,
83
+ thread_id TEXT NOT NULL,
80
84
  through_sequence INTEGER NOT NULL,
81
85
  tail_digest TEXT NOT NULL,
82
86
  checkpoint_json TEXT NOT NULL,
83
- PRIMARY KEY (conversation_id, through_sequence),
84
- FOREIGN KEY (conversation_id)
85
- REFERENCES effect_agent_conversations(conversation_id)
87
+ PRIMARY KEY (thread_id, through_sequence),
88
+ FOREIGN KEY (thread_id)
89
+ REFERENCES effect_agent_threads(thread_id)
86
90
  ON DELETE RESTRICT
87
91
  )
88
92
  `.withoutTransform;
89
93
 
90
- // Admission rows exist before Conversation materialization (durability §4), so
91
- // conversation_id intentionally carries no foreign key into effect_agent_conversations.
94
+ // Admission rows exist before Thread materialization (durability §4), so
95
+ // thread_id intentionally carries no foreign key into effect_agent_threads.
92
96
  yield* sql`
93
97
  CREATE TABLE effect_agent_submissions (
94
98
  submission_id TEXT PRIMARY KEY NOT NULL,
95
- conversation_id TEXT NOT NULL,
99
+ thread_id TEXT NOT NULL,
96
100
  queue_sequence INTEGER NOT NULL,
97
101
  principal TEXT NOT NULL,
98
102
  idempotency_key TEXT NOT NULL,
@@ -115,8 +119,12 @@ export const doMigrations = SqliteMigrator.fromRecord({
115
119
  unknown_tool_call_ids_json TEXT,
116
120
  parent_submission_id TEXT,
117
121
  parent_tool_call_id TEXT,
118
- UNIQUE (conversation_id, principal, idempotency_key),
119
- UNIQUE (conversation_id, queue_sequence)
122
+ admission_group TEXT,
123
+ admission_fence_json TEXT,
124
+ worker_admission_json TEXT,
125
+ message_admission_json TEXT,
126
+ UNIQUE (thread_id, principal, idempotency_key),
127
+ UNIQUE (thread_id, queue_sequence)
120
128
  )
121
129
  `.withoutTransform;
122
130
 
@@ -130,6 +138,11 @@ export const doMigrations = SqliteMigrator.fromRecord({
130
138
  ON effect_agent_submissions (parent_submission_id)
131
139
  `.withoutTransform;
132
140
 
141
+ yield* sql`
142
+ CREATE INDEX effect_agent_submissions_group
143
+ ON effect_agent_submissions (thread_id, admission_group, state)
144
+ `.withoutTransform;
145
+
133
146
  yield* sql`
134
147
  CREATE TABLE effect_agent_submission_ownership (
135
148
  submission_id TEXT PRIMARY KEY NOT NULL,
@@ -148,7 +161,7 @@ export const doMigrations = SqliteMigrator.fromRecord({
148
161
  CREATE TABLE effect_agent_attempts (
149
162
  attempt_id TEXT PRIMARY KEY NOT NULL,
150
163
  submission_id TEXT NOT NULL,
151
- conversation_id TEXT NOT NULL,
164
+ thread_id TEXT NOT NULL,
152
165
  owner_producer_id TEXT NOT NULL,
153
166
  producer_epoch INTEGER NOT NULL,
154
167
  claimed_at TEXT NOT NULL,
@@ -252,6 +265,9 @@ export const doMigrations = SqliteMigrator.fromRecord({
252
265
  )
253
266
  `.withoutTransform;
254
267
 
268
+ yield* createNonterminalIndex;
269
+ yield* createMessageDeliveryTables;
270
+ yield* createRecoveryCheckpointTable;
255
271
  yield* sql`
256
272
  CREATE TABLE effect_agent_meta (
257
273
  key TEXT PRIMARY KEY NOT NULL,
@@ -0,0 +1,17 @@
1
+ import { Effect } from "effect";
2
+ import * as SqlClient from "effect/unstable/sql/SqlClient";
3
+
4
+ /** One disposable recovery snapshot per Thread, independent of generic projections. */
5
+ export const createRecoveryCheckpointTable = Effect.gen(function* () {
6
+ const sql = yield* SqlClient.SqlClient;
7
+
8
+ yield* sql`
9
+ CREATE TABLE effect_agent_recovery_checkpoints (
10
+ thread_id TEXT PRIMARY KEY NOT NULL,
11
+ through_sequence INTEGER NOT NULL,
12
+ tail_digest TEXT NOT NULL,
13
+ checkpoint_json TEXT NOT NULL,
14
+ FOREIGN KEY (thread_id) REFERENCES effect_agent_threads(thread_id) ON DELETE RESTRICT
15
+ )
16
+ `.withoutTransform;
17
+ });