@effect-agent/storage-cloudflare 0.1.0-beta.6 → 0.1.0-beta.61

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 (72) 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-UrxrvbnF.d.mts +98 -0
  14. package/dist/DoStorageError.d.mts +2 -0
  15. package/dist/DoStorageError.mjs +162 -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-Pt3jEHdW.d.mts +10 -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 +1826 -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 +432 -0
  35. package/dist/DoThreadStore.mjs.map +1 -0
  36. package/dist/MemoryProtocol.d.mts +19796 -0
  37. package/dist/MemoryProtocol.mjs +182 -0
  38. package/dist/MemoryProtocol.mjs.map +1 -0
  39. package/dist/PortProtocol.d.mts +3099 -0
  40. package/dist/PortProtocol.mjs +176 -0
  41. package/dist/PortProtocol.mjs.map +1 -0
  42. package/dist/PortRouting.d.mts +82 -0
  43. package/dist/PortRouting.mjs +405 -0
  44. package/dist/PortRouting.mjs.map +1 -0
  45. package/dist/do-journal-Brv7xSH5.mjs +869 -0
  46. package/dist/do-journal-Brv7xSH5.mjs.map +1 -0
  47. package/dist/index.d.mts +14 -1505
  48. package/dist/index.mjs +14 -3695
  49. package/dist/migrations-soC86CQA.mjs +267 -0
  50. package/dist/migrations-soC86CQA.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} +8 -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} +757 -123
  61. package/src/DoSubscriptionStore.ts +329 -0
  62. package/src/DoThreadStore.ts +924 -0
  63. package/src/MemoryProtocol.ts +291 -0
  64. package/src/{port-protocol.ts → PortProtocol.ts} +41 -34
  65. package/src/{routing.ts → PortRouting.ts} +266 -259
  66. package/src/index.ts +13 -32
  67. package/src/{do-journal.ts → internal/do-journal.ts} +495 -214
  68. package/src/internal/message-delivery-schema.ts +24 -0
  69. package/src/{migrations.ts → internal/migrations.ts} +40 -35
  70. package/dist/index.mjs.map +0 -1
  71. package/src/do-conversation-store.ts +0 -850
  72. /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,30 @@ 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
+
7
+ /** The current storage version recorded in `effect_agent_meta`. */
8
+ export const CurrentDoStorageVersion = 4;
12
9
 
13
10
  /**
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:
11
+ * The Thread Durable Object schema shares its thread and ledger tables with Node/SQLite.
12
+ * Schedules and subscriptions use separate Durable Objects. Two DC-specific additions:
18
13
  *
19
14
  * 1. `effect_agent_meta` replaces `PRAGMA user_version` as the exact-or-fresh version gate —
20
15
  * a meta table is portable regardless of which PRAGMAs Durable Object SQL storage allows.
21
16
  * 2. `effect_agent_child_settlements` is the durable cross-store notification marker the
22
17
  * SubmissionLedger port contract mandates for cross-store adapters (`suspend`'s covering
23
- * check and `recordChildSettled`'s wake both consult it): parent and child Conversations
18
+ * check and `recordChildSettled`'s wake both consult it): parent and child Threads
24
19
  * live in different Durable Objects, so a child settlement reported before the parent's
25
20
  * suspend commits must be observable from the PARENT's own storage.
26
21
  */
27
22
  export const doMigrations = SqliteMigrator.fromRecord({
28
- "1_current_cloudflare_conversation_object": Effect.gen(function* () {
23
+ "1_current_cloudflare_thread_object": Effect.gen(function* () {
29
24
  const sql = yield* SqlClient.SqlClient;
30
25
 
31
26
  yield* sql`
32
- CREATE TABLE effect_agent_conversations (
33
- conversation_id TEXT PRIMARY KEY NOT NULL,
27
+ CREATE TABLE effect_agent_threads (
28
+ thread_id TEXT PRIMARY KEY NOT NULL,
34
29
  created_at TEXT NOT NULL,
35
30
  tail_sequence INTEGER NOT NULL,
36
31
  tail_digest TEXT NOT NULL,
@@ -40,59 +35,59 @@ export const doMigrations = SqliteMigrator.fromRecord({
40
35
 
41
36
  yield* sql`
42
37
  CREATE TABLE effect_agent_canonical_batches (
43
- conversation_id TEXT NOT NULL,
38
+ thread_id TEXT NOT NULL,
44
39
  batch_id TEXT NOT NULL,
45
40
  first_sequence INTEGER NOT NULL,
46
41
  last_sequence INTEGER NOT NULL,
47
42
  batch_digest TEXT NOT NULL,
48
43
  tail_digest TEXT NOT NULL,
49
44
  batch_json TEXT NOT NULL,
50
- PRIMARY KEY (conversation_id, batch_id),
51
- FOREIGN KEY (conversation_id)
52
- REFERENCES effect_agent_conversations(conversation_id)
45
+ PRIMARY KEY (thread_id, batch_id),
46
+ FOREIGN KEY (thread_id)
47
+ REFERENCES effect_agent_threads(thread_id)
53
48
  ON DELETE RESTRICT
54
49
  )
55
50
  `.withoutTransform;
56
51
 
57
52
  yield* sql`
58
53
  CREATE TABLE effect_agent_canonical_records (
59
- conversation_id TEXT NOT NULL,
54
+ thread_id TEXT NOT NULL,
60
55
  sequence INTEGER NOT NULL,
61
56
  record_id TEXT NOT NULL,
62
57
  batch_id TEXT NOT NULL,
63
58
  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)
59
+ PRIMARY KEY (thread_id, sequence),
60
+ UNIQUE (thread_id, record_id),
61
+ FOREIGN KEY (thread_id, batch_id)
62
+ REFERENCES effect_agent_canonical_batches(thread_id, batch_id)
68
63
  ON DELETE RESTRICT
69
64
  )
70
65
  `.withoutTransform;
71
66
 
72
67
  yield* sql`
73
68
  CREATE INDEX effect_agent_canonical_records_batch
74
- ON effect_agent_canonical_records (conversation_id, batch_id, sequence)
69
+ ON effect_agent_canonical_records (thread_id, batch_id, sequence)
75
70
  `.withoutTransform;
76
71
 
77
72
  yield* sql`
78
73
  CREATE TABLE effect_agent_checkpoints (
79
- conversation_id TEXT NOT NULL,
74
+ thread_id TEXT NOT NULL,
80
75
  through_sequence INTEGER NOT NULL,
81
76
  tail_digest TEXT NOT NULL,
82
77
  checkpoint_json TEXT NOT NULL,
83
- PRIMARY KEY (conversation_id, through_sequence),
84
- FOREIGN KEY (conversation_id)
85
- REFERENCES effect_agent_conversations(conversation_id)
78
+ PRIMARY KEY (thread_id, through_sequence),
79
+ FOREIGN KEY (thread_id)
80
+ REFERENCES effect_agent_threads(thread_id)
86
81
  ON DELETE RESTRICT
87
82
  )
88
83
  `.withoutTransform;
89
84
 
90
- // Admission rows exist before Conversation materialization (durability §4), so
91
- // conversation_id intentionally carries no foreign key into effect_agent_conversations.
85
+ // Admission rows exist before Thread materialization (durability §4), so
86
+ // thread_id intentionally carries no foreign key into effect_agent_threads.
92
87
  yield* sql`
93
88
  CREATE TABLE effect_agent_submissions (
94
89
  submission_id TEXT PRIMARY KEY NOT NULL,
95
- conversation_id TEXT NOT NULL,
90
+ thread_id TEXT NOT NULL,
96
91
  queue_sequence INTEGER NOT NULL,
97
92
  principal TEXT NOT NULL,
98
93
  idempotency_key TEXT NOT NULL,
@@ -115,8 +110,12 @@ export const doMigrations = SqliteMigrator.fromRecord({
115
110
  unknown_tool_call_ids_json TEXT,
116
111
  parent_submission_id TEXT,
117
112
  parent_tool_call_id TEXT,
118
- UNIQUE (conversation_id, principal, idempotency_key),
119
- UNIQUE (conversation_id, queue_sequence)
113
+ admission_group TEXT,
114
+ admission_fence_json TEXT,
115
+ worker_admission_json TEXT,
116
+ message_admission_json TEXT,
117
+ UNIQUE (thread_id, principal, idempotency_key),
118
+ UNIQUE (thread_id, queue_sequence)
120
119
  )
121
120
  `.withoutTransform;
122
121
 
@@ -130,6 +129,11 @@ export const doMigrations = SqliteMigrator.fromRecord({
130
129
  ON effect_agent_submissions (parent_submission_id)
131
130
  `.withoutTransform;
132
131
 
132
+ yield* sql`
133
+ CREATE INDEX effect_agent_submissions_group
134
+ ON effect_agent_submissions (thread_id, admission_group, state)
135
+ `.withoutTransform;
136
+
133
137
  yield* sql`
134
138
  CREATE TABLE effect_agent_submission_ownership (
135
139
  submission_id TEXT PRIMARY KEY NOT NULL,
@@ -148,7 +152,7 @@ export const doMigrations = SqliteMigrator.fromRecord({
148
152
  CREATE TABLE effect_agent_attempts (
149
153
  attempt_id TEXT PRIMARY KEY NOT NULL,
150
154
  submission_id TEXT NOT NULL,
151
- conversation_id TEXT NOT NULL,
155
+ thread_id TEXT NOT NULL,
152
156
  owner_producer_id TEXT NOT NULL,
153
157
  producer_epoch INTEGER NOT NULL,
154
158
  claimed_at TEXT NOT NULL,
@@ -252,6 +256,7 @@ export const doMigrations = SqliteMigrator.fromRecord({
252
256
  )
253
257
  `.withoutTransform;
254
258
 
259
+ yield* createMessageDeliveryTables;
255
260
  yield* sql`
256
261
  CREATE TABLE effect_agent_meta (
257
262
  key TEXT PRIMARY KEY NOT NULL,