@effect-agent/storage-sqlite 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.
- package/dist/SqliteActivityStore.d.mts +14 -0
- package/dist/SqliteActivityStore.mjs +310 -0
- package/dist/SqliteActivityStore.mjs.map +1 -0
- package/dist/SqliteMessageDeliveryStore.d.mts +14 -0
- package/dist/SqliteMessageDeliveryStore.mjs +24 -0
- package/dist/SqliteMessageDeliveryStore.mjs.map +1 -0
- package/dist/SqliteScheduleStore.d.mts +14 -0
- package/dist/SqliteScheduleStore.mjs +255 -0
- package/dist/SqliteScheduleStore.mjs.map +1 -0
- package/dist/SqliteStorageConfig.d.mts +34 -0
- package/dist/SqliteStorageConfig.mjs +39 -0
- package/dist/SqliteStorageConfig.mjs.map +1 -0
- package/dist/SqliteStorageError-DVWeaWLm.d.mts +86 -0
- package/dist/SqliteStorageError.d.mts +2 -0
- package/dist/SqliteStorageError.mjs +150 -0
- package/dist/SqliteStorageError.mjs.map +1 -0
- package/dist/SqliteStorageFailpoint.d.mts +17 -0
- package/dist/SqliteStorageFailpoint.mjs +14 -0
- package/dist/SqliteStorageFailpoint.mjs.map +1 -0
- package/dist/SqliteStorageFailpointTesting.d.mts +15 -0
- package/dist/SqliteStorageFailpointTesting.mjs +19 -0
- package/dist/SqliteStorageFailpointTesting.mjs.map +1 -0
- package/dist/SqliteStorageVersion-BqmqX0CI.d.mts +11 -0
- package/dist/SqliteStorageVersion.d.mts +2 -0
- package/dist/SqliteStorageVersion.mjs +8 -0
- package/dist/SqliteStorageVersion.mjs.map +1 -0
- package/dist/SqliteSubmissionLedger.d.mts +23 -0
- package/dist/SqliteSubmissionLedger.mjs +1788 -0
- package/dist/SqliteSubmissionLedger.mjs.map +1 -0
- package/dist/SqliteSubscriptionStore.d.mts +13 -0
- package/dist/SqliteSubscriptionStore.mjs +28 -0
- package/dist/SqliteSubscriptionStore.mjs.map +1 -0
- package/dist/SqliteThreadStore.d.mts +49 -0
- package/dist/SqliteThreadStore.mjs +460 -0
- package/dist/SqliteThreadStore.mjs.map +1 -0
- package/dist/index.d.mts +11 -193
- package/dist/index.mjs +11 -3082
- package/dist/migrations-Dy5v0HGe.mjs +346 -0
- package/dist/migrations-Dy5v0HGe.mjs.map +1 -0
- package/dist/rolldown-runtime-D7D4PA-g.mjs +13 -0
- package/dist/sqlite-journal-D9xFxCw-.mjs +998 -0
- package/dist/sqlite-journal-D9xFxCw-.mjs.map +1 -0
- package/package.json +1 -41
- package/src/SqliteActivityStore.ts +556 -0
- package/src/SqliteMessageDeliveryStore.ts +42 -0
- package/src/SqliteScheduleStore.ts +404 -0
- package/src/{sqlite-storage-config.ts → SqliteStorageConfig.ts} +1 -1
- package/src/{errors.ts → SqliteStorageError.ts} +10 -3
- package/src/SqliteStorageFailpoint.ts +23 -0
- package/src/{sqlite-storage-failpoint.ts → SqliteStorageFailpointTesting.ts} +7 -18
- package/src/SqliteStorageVersion.ts +2 -0
- package/src/{sqlite-ledger.ts → SqliteSubmissionLedger.ts} +857 -157
- package/src/SqliteSubscriptionStore.ts +59 -0
- package/src/{sqlite-conversation-store.ts → SqliteThreadStore.ts} +448 -288
- package/src/index.ts +10 -6
- package/src/internal/message-delivery-schema.ts +24 -0
- package/src/{migrations.ts → internal/migrations.ts} +156 -79
- package/src/internal/recovery-checkpoint-schema.ts +17 -0
- package/src/{sqlite-journal.ts → internal/sqlite-journal.ts} +752 -239
- package/dist/index.mjs.map +0 -1
|
@@ -0,0 +1,346 @@
|
|
|
1
|
+
import { Effect } from "effect";
|
|
2
|
+
import * as SqlClient from "effect/unstable/sql/SqlClient";
|
|
3
|
+
import { SqliteMigrator } from "@effect/sql-sqlite-node";
|
|
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
|
+
const CurrentSqliteStorageVersion = 11;
|
|
42
|
+
/** Index only outstanding obligations, ordered by the recovery scan's stable cursor. */
|
|
43
|
+
const createNonterminalIndex = Effect.gen(function* () {
|
|
44
|
+
yield* (yield* SqlClient.SqlClient)`CREATE INDEX effect_agent_submissions_nonterminal ON effect_agent_submissions (thread_id, queue_sequence) WHERE state <> 'settled'`.withoutTransform;
|
|
45
|
+
});
|
|
46
|
+
/** Initialize empty storage with the complete current schema. */
|
|
47
|
+
const sqliteMigrations = SqliteMigrator.fromRecord({ "1_current_thread_storage": Effect.gen(function* () {
|
|
48
|
+
const sql = yield* SqlClient.SqlClient;
|
|
49
|
+
yield* sql`
|
|
50
|
+
CREATE TABLE effect_agent_threads (
|
|
51
|
+
thread_id TEXT PRIMARY KEY NOT NULL,
|
|
52
|
+
created_at TEXT NOT NULL,
|
|
53
|
+
tail_sequence INTEGER NOT NULL,
|
|
54
|
+
tail_digest TEXT NOT NULL,
|
|
55
|
+
producer_epoch INTEGER NOT NULL
|
|
56
|
+
)
|
|
57
|
+
`.withoutTransform;
|
|
58
|
+
yield* sql`
|
|
59
|
+
CREATE TABLE effect_agent_canonical_batches (
|
|
60
|
+
thread_id TEXT NOT NULL,
|
|
61
|
+
batch_id TEXT NOT NULL,
|
|
62
|
+
first_sequence INTEGER NOT NULL,
|
|
63
|
+
last_sequence INTEGER NOT NULL,
|
|
64
|
+
batch_digest TEXT NOT NULL,
|
|
65
|
+
tail_digest TEXT NOT NULL,
|
|
66
|
+
batch_json TEXT NOT NULL,
|
|
67
|
+
PRIMARY KEY (thread_id, batch_id),
|
|
68
|
+
FOREIGN KEY (thread_id)
|
|
69
|
+
REFERENCES effect_agent_threads(thread_id)
|
|
70
|
+
ON DELETE RESTRICT
|
|
71
|
+
)
|
|
72
|
+
`.withoutTransform;
|
|
73
|
+
yield* sql`
|
|
74
|
+
CREATE TABLE effect_agent_canonical_records (
|
|
75
|
+
thread_id TEXT NOT NULL,
|
|
76
|
+
sequence INTEGER NOT NULL,
|
|
77
|
+
record_id TEXT NOT NULL,
|
|
78
|
+
batch_id TEXT NOT NULL,
|
|
79
|
+
record_json TEXT NOT NULL,
|
|
80
|
+
PRIMARY KEY (thread_id, sequence),
|
|
81
|
+
UNIQUE (thread_id, record_id),
|
|
82
|
+
FOREIGN KEY (thread_id, batch_id)
|
|
83
|
+
REFERENCES effect_agent_canonical_batches(thread_id, batch_id)
|
|
84
|
+
ON DELETE RESTRICT
|
|
85
|
+
)
|
|
86
|
+
`.withoutTransform;
|
|
87
|
+
yield* sql`
|
|
88
|
+
CREATE INDEX effect_agent_canonical_records_batch
|
|
89
|
+
ON effect_agent_canonical_records (thread_id, batch_id, sequence)
|
|
90
|
+
`.withoutTransform;
|
|
91
|
+
yield* sql`
|
|
92
|
+
CREATE TABLE effect_agent_checkpoints (
|
|
93
|
+
thread_id TEXT NOT NULL,
|
|
94
|
+
through_sequence INTEGER NOT NULL,
|
|
95
|
+
tail_digest TEXT NOT NULL,
|
|
96
|
+
checkpoint_json TEXT NOT NULL,
|
|
97
|
+
PRIMARY KEY (thread_id, through_sequence),
|
|
98
|
+
FOREIGN KEY (thread_id)
|
|
99
|
+
REFERENCES effect_agent_threads(thread_id)
|
|
100
|
+
ON DELETE RESTRICT
|
|
101
|
+
)
|
|
102
|
+
`.withoutTransform;
|
|
103
|
+
yield* sql`
|
|
104
|
+
CREATE TABLE effect_agent_submissions (
|
|
105
|
+
submission_id TEXT PRIMARY KEY NOT NULL,
|
|
106
|
+
thread_id TEXT NOT NULL,
|
|
107
|
+
queue_sequence INTEGER NOT NULL,
|
|
108
|
+
principal TEXT NOT NULL,
|
|
109
|
+
idempotency_key TEXT NOT NULL,
|
|
110
|
+
agent_id TEXT NOT NULL,
|
|
111
|
+
agent_digests_json TEXT NOT NULL,
|
|
112
|
+
deployment_id TEXT NOT NULL,
|
|
113
|
+
input_json TEXT NOT NULL,
|
|
114
|
+
input_digest TEXT NOT NULL,
|
|
115
|
+
receipt_id TEXT NOT NULL,
|
|
116
|
+
state TEXT NOT NULL,
|
|
117
|
+
settled_outcome TEXT,
|
|
118
|
+
created_at TEXT NOT NULL,
|
|
119
|
+
ready_at TEXT,
|
|
120
|
+
input_applied_record_id TEXT,
|
|
121
|
+
input_applied_sequence INTEGER,
|
|
122
|
+
joined_host_submission_id TEXT,
|
|
123
|
+
suspended_reason_json TEXT,
|
|
124
|
+
suspended_at TEXT,
|
|
125
|
+
unknown_reason TEXT,
|
|
126
|
+
unknown_tool_call_ids_json TEXT,
|
|
127
|
+
parent_submission_id TEXT,
|
|
128
|
+
parent_tool_call_id TEXT,
|
|
129
|
+
admission_group TEXT,
|
|
130
|
+
admission_fence_json TEXT,
|
|
131
|
+
worker_admission_json TEXT,
|
|
132
|
+
message_admission_json TEXT,
|
|
133
|
+
UNIQUE (thread_id, principal, idempotency_key),
|
|
134
|
+
UNIQUE (thread_id, queue_sequence)
|
|
135
|
+
)
|
|
136
|
+
`.withoutTransform;
|
|
137
|
+
yield* sql`
|
|
138
|
+
CREATE INDEX effect_agent_submissions_group
|
|
139
|
+
ON effect_agent_submissions (thread_id, admission_group, state)
|
|
140
|
+
`.withoutTransform;
|
|
141
|
+
yield* sql`
|
|
142
|
+
CREATE TABLE effect_agent_submission_ownership (
|
|
143
|
+
submission_id TEXT PRIMARY KEY NOT NULL,
|
|
144
|
+
attempt_id TEXT NOT NULL,
|
|
145
|
+
ownership_token TEXT NOT NULL,
|
|
146
|
+
producer_epoch INTEGER NOT NULL,
|
|
147
|
+
owner_producer_id TEXT NOT NULL,
|
|
148
|
+
lease_expires_at TEXT NOT NULL,
|
|
149
|
+
FOREIGN KEY (submission_id)
|
|
150
|
+
REFERENCES effect_agent_submissions(submission_id)
|
|
151
|
+
ON DELETE RESTRICT
|
|
152
|
+
)
|
|
153
|
+
`.withoutTransform;
|
|
154
|
+
yield* sql`
|
|
155
|
+
CREATE TABLE effect_agent_attempts (
|
|
156
|
+
attempt_id TEXT PRIMARY KEY NOT NULL,
|
|
157
|
+
submission_id TEXT NOT NULL,
|
|
158
|
+
thread_id TEXT NOT NULL,
|
|
159
|
+
owner_producer_id TEXT NOT NULL,
|
|
160
|
+
producer_epoch INTEGER NOT NULL,
|
|
161
|
+
claimed_at TEXT NOT NULL,
|
|
162
|
+
FOREIGN KEY (submission_id)
|
|
163
|
+
REFERENCES effect_agent_submissions(submission_id)
|
|
164
|
+
ON DELETE RESTRICT
|
|
165
|
+
)
|
|
166
|
+
`.withoutTransform;
|
|
167
|
+
yield* sql`
|
|
168
|
+
CREATE TABLE effect_agent_settlement_reservations (
|
|
169
|
+
submission_id TEXT PRIMARY KEY NOT NULL,
|
|
170
|
+
settlement_id TEXT NOT NULL,
|
|
171
|
+
outcome TEXT NOT NULL,
|
|
172
|
+
record_id TEXT NOT NULL,
|
|
173
|
+
record_json TEXT NOT NULL,
|
|
174
|
+
record_digest TEXT NOT NULL,
|
|
175
|
+
reserved_at TEXT NOT NULL,
|
|
176
|
+
finalized_at TEXT,
|
|
177
|
+
FOREIGN KEY (submission_id)
|
|
178
|
+
REFERENCES effect_agent_submissions(submission_id)
|
|
179
|
+
ON DELETE RESTRICT
|
|
180
|
+
)
|
|
181
|
+
`.withoutTransform;
|
|
182
|
+
yield* sql`
|
|
183
|
+
CREATE TABLE effect_agent_abort_intents (
|
|
184
|
+
submission_id TEXT PRIMARY KEY NOT NULL,
|
|
185
|
+
author TEXT NOT NULL,
|
|
186
|
+
reason TEXT NOT NULL,
|
|
187
|
+
requested_at TEXT NOT NULL,
|
|
188
|
+
canonical_record_id TEXT,
|
|
189
|
+
FOREIGN KEY (submission_id)
|
|
190
|
+
REFERENCES effect_agent_submissions(submission_id)
|
|
191
|
+
ON DELETE RESTRICT
|
|
192
|
+
)
|
|
193
|
+
`.withoutTransform;
|
|
194
|
+
yield* sql`
|
|
195
|
+
CREATE INDEX effect_agent_submissions_joined_host
|
|
196
|
+
ON effect_agent_submissions (joined_host_submission_id)
|
|
197
|
+
`.withoutTransform;
|
|
198
|
+
yield* sql`
|
|
199
|
+
CREATE TABLE effect_agent_approval_decisions (
|
|
200
|
+
submission_id TEXT NOT NULL,
|
|
201
|
+
tool_call_id TEXT NOT NULL,
|
|
202
|
+
decision TEXT NOT NULL,
|
|
203
|
+
resolver TEXT NOT NULL,
|
|
204
|
+
reason TEXT NOT NULL,
|
|
205
|
+
decided_at TEXT NOT NULL,
|
|
206
|
+
PRIMARY KEY (submission_id, tool_call_id),
|
|
207
|
+
FOREIGN KEY (submission_id)
|
|
208
|
+
REFERENCES effect_agent_submissions(submission_id)
|
|
209
|
+
ON DELETE RESTRICT
|
|
210
|
+
)
|
|
211
|
+
`.withoutTransform;
|
|
212
|
+
yield* sql`
|
|
213
|
+
CREATE TABLE effect_agent_unknown_resolutions (
|
|
214
|
+
submission_id TEXT NOT NULL,
|
|
215
|
+
tool_call_id TEXT NOT NULL,
|
|
216
|
+
author TEXT NOT NULL,
|
|
217
|
+
reason TEXT NOT NULL,
|
|
218
|
+
resolution_json TEXT NOT NULL,
|
|
219
|
+
resolved_at TEXT NOT NULL,
|
|
220
|
+
PRIMARY KEY (submission_id, tool_call_id),
|
|
221
|
+
FOREIGN KEY (submission_id)
|
|
222
|
+
REFERENCES effect_agent_submissions(submission_id)
|
|
223
|
+
ON DELETE RESTRICT
|
|
224
|
+
)
|
|
225
|
+
`.withoutTransform;
|
|
226
|
+
yield* sql`
|
|
227
|
+
CREATE INDEX effect_agent_submissions_parent
|
|
228
|
+
ON effect_agent_submissions (parent_submission_id)
|
|
229
|
+
`.withoutTransform;
|
|
230
|
+
yield* sql`
|
|
231
|
+
CREATE TABLE effect_agent_child_reservations (
|
|
232
|
+
reservation_id TEXT PRIMARY KEY NOT NULL,
|
|
233
|
+
parent_submission_id TEXT NOT NULL,
|
|
234
|
+
parent_tool_call_id TEXT NOT NULL,
|
|
235
|
+
child_submission_id TEXT,
|
|
236
|
+
status TEXT NOT NULL,
|
|
237
|
+
allocation_json TEXT NOT NULL,
|
|
238
|
+
allocation_digest TEXT NOT NULL,
|
|
239
|
+
accounting_json TEXT,
|
|
240
|
+
reserved_at TEXT NOT NULL,
|
|
241
|
+
release_began_at TEXT,
|
|
242
|
+
released_at TEXT,
|
|
243
|
+
UNIQUE (parent_submission_id, parent_tool_call_id),
|
|
244
|
+
FOREIGN KEY (parent_submission_id)
|
|
245
|
+
REFERENCES effect_agent_submissions(submission_id)
|
|
246
|
+
ON DELETE RESTRICT
|
|
247
|
+
)
|
|
248
|
+
`.withoutTransform;
|
|
249
|
+
yield* sql`
|
|
250
|
+
CREATE TABLE effect_agent_schedules (
|
|
251
|
+
tenant_id TEXT NOT NULL,
|
|
252
|
+
owner_id TEXT NOT NULL,
|
|
253
|
+
schedule_id TEXT NOT NULL,
|
|
254
|
+
deadline_at_millis INTEGER,
|
|
255
|
+
record_json TEXT NOT NULL,
|
|
256
|
+
PRIMARY KEY (tenant_id, owner_id, schedule_id)
|
|
257
|
+
)
|
|
258
|
+
`.withoutTransform;
|
|
259
|
+
yield* sql`
|
|
260
|
+
CREATE INDEX effect_agent_schedules_deadline
|
|
261
|
+
ON effect_agent_schedules (deadline_at_millis, tenant_id, owner_id, schedule_id)
|
|
262
|
+
WHERE deadline_at_millis IS NOT NULL
|
|
263
|
+
`.withoutTransform;
|
|
264
|
+
yield* sql`
|
|
265
|
+
CREATE INDEX effect_agent_schedules_owner_deadline
|
|
266
|
+
ON effect_agent_schedules (tenant_id, owner_id, deadline_at_millis, schedule_id)
|
|
267
|
+
WHERE deadline_at_millis IS NOT NULL
|
|
268
|
+
`.withoutTransform;
|
|
269
|
+
yield* sql`
|
|
270
|
+
CREATE TABLE effect_agent_subscription_sequences (
|
|
271
|
+
tenant_id TEXT NOT NULL,
|
|
272
|
+
source_address TEXT NOT NULL,
|
|
273
|
+
sequence INTEGER NOT NULL,
|
|
274
|
+
event_scan_cursor TEXT NOT NULL,
|
|
275
|
+
delivery_scan_cursor TEXT NOT NULL,
|
|
276
|
+
recovery_scan_cursor INTEGER NOT NULL,
|
|
277
|
+
PRIMARY KEY (tenant_id, source_address)
|
|
278
|
+
)
|
|
279
|
+
`.withoutTransform;
|
|
280
|
+
yield* sql`
|
|
281
|
+
CREATE TABLE effect_agent_subscriptions (
|
|
282
|
+
tenant_id TEXT NOT NULL,
|
|
283
|
+
source_address TEXT NOT NULL,
|
|
284
|
+
owner_id TEXT NOT NULL,
|
|
285
|
+
subscription_id TEXT NOT NULL,
|
|
286
|
+
ordinal INTEGER NOT NULL,
|
|
287
|
+
source_name TEXT NOT NULL,
|
|
288
|
+
source_version TEXT NOT NULL,
|
|
289
|
+
matching_key TEXT NOT NULL,
|
|
290
|
+
state TEXT NOT NULL,
|
|
291
|
+
expires_at_millis INTEGER,
|
|
292
|
+
recovery_at_millis INTEGER,
|
|
293
|
+
recovery_present INTEGER NOT NULL DEFAULT 0,
|
|
294
|
+
record_json TEXT NOT NULL,
|
|
295
|
+
PRIMARY KEY (tenant_id, source_address, owner_id, subscription_id),
|
|
296
|
+
UNIQUE (tenant_id, source_address, ordinal)
|
|
297
|
+
)
|
|
298
|
+
`.withoutTransform;
|
|
299
|
+
yield* sql`CREATE INDEX effect_agent_subscriptions_owner ON effect_agent_subscriptions (tenant_id, source_address, owner_id, ordinal)`.withoutTransform;
|
|
300
|
+
yield* sql`CREATE INDEX effect_agent_subscriptions_candidates ON effect_agent_subscriptions (tenant_id, source_address, source_name, source_version, matching_key, ordinal)`.withoutTransform;
|
|
301
|
+
yield* sql`CREATE INDEX effect_agent_subscriptions_recovery ON effect_agent_subscriptions (tenant_id, source_address, recovery_at_millis, ordinal) WHERE recovery_at_millis IS NOT NULL`.withoutTransform;
|
|
302
|
+
yield* sql`
|
|
303
|
+
CREATE TABLE effect_agent_subscription_events (
|
|
304
|
+
tenant_id TEXT NOT NULL,
|
|
305
|
+
source_address TEXT NOT NULL,
|
|
306
|
+
event_id TEXT NOT NULL,
|
|
307
|
+
source_name TEXT NOT NULL,
|
|
308
|
+
source_version TEXT NOT NULL,
|
|
309
|
+
matching_key TEXT NOT NULL,
|
|
310
|
+
payload_digest TEXT NOT NULL,
|
|
311
|
+
cutoff INTEGER NOT NULL,
|
|
312
|
+
cursor INTEGER NOT NULL,
|
|
313
|
+
routing_complete INTEGER NOT NULL,
|
|
314
|
+
tombstone INTEGER NOT NULL DEFAULT 0,
|
|
315
|
+
next_attempt_at_millis INTEGER NOT NULL,
|
|
316
|
+
record_json TEXT NOT NULL,
|
|
317
|
+
PRIMARY KEY (tenant_id, source_address, event_id)
|
|
318
|
+
)
|
|
319
|
+
`.withoutTransform;
|
|
320
|
+
yield* sql`CREATE INDEX effect_agent_subscription_events_pending ON effect_agent_subscription_events (tenant_id, source_address, routing_complete, next_attempt_at_millis, event_id)`.withoutTransform;
|
|
321
|
+
yield* sql`
|
|
322
|
+
CREATE TABLE effect_agent_subscription_deliveries (
|
|
323
|
+
tenant_id TEXT NOT NULL,
|
|
324
|
+
source_address TEXT NOT NULL,
|
|
325
|
+
owner_id TEXT NOT NULL,
|
|
326
|
+
subscription_id TEXT NOT NULL,
|
|
327
|
+
event_id TEXT NOT NULL,
|
|
328
|
+
delivery_key TEXT NOT NULL,
|
|
329
|
+
state TEXT NOT NULL,
|
|
330
|
+
next_attempt_at_millis INTEGER NOT NULL,
|
|
331
|
+
record_json TEXT NOT NULL,
|
|
332
|
+
PRIMARY KEY (tenant_id, source_address, owner_id, subscription_id, event_id),
|
|
333
|
+
UNIQUE (tenant_id, source_address, delivery_key)
|
|
334
|
+
)
|
|
335
|
+
`.withoutTransform;
|
|
336
|
+
yield* sql`CREATE INDEX effect_agent_subscription_deliveries_pending ON effect_agent_subscription_deliveries (tenant_id, source_address, state, next_attempt_at_millis, delivery_key)`.withoutTransform;
|
|
337
|
+
yield* sql`CREATE INDEX effect_agent_subscription_deliveries_registration ON effect_agent_subscription_deliveries (tenant_id, source_address, owner_id, subscription_id, delivery_key)`.withoutTransform;
|
|
338
|
+
yield* createNonterminalIndex;
|
|
339
|
+
yield* createMessageDeliveryTables;
|
|
340
|
+
yield* createRecoveryCheckpointTable;
|
|
341
|
+
yield* sql`PRAGMA user_version = 11`.withoutTransform;
|
|
342
|
+
}) });
|
|
343
|
+
//#endregion
|
|
344
|
+
export { createMessageDeliveryTables as a, createRecoveryCheckpointTable as i, createNonterminalIndex as n, sqliteMigrations as r, CurrentSqliteStorageVersion as t };
|
|
345
|
+
|
|
346
|
+
//# sourceMappingURL=migrations-Dy5v0HGe.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"migrations-Dy5v0HGe.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-node\";\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\nexport const CurrentSqliteStorageVersion = 11;\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/** Initialize empty storage with the complete current schema. */\nexport const sqliteMigrations = SqliteMigrator.fromRecord({\n \"1_current_thread_storage\": 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_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 INDEX effect_agent_submissions_joined_host\n ON effect_agent_submissions (joined_host_submission_id)\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 // Durable attached children (spec §12, SUB-004): a child Submission records its immutable\n // parent linkage at admission; the parent-side index serves the recovery attachment view.\n yield* sql`\n CREATE INDEX effect_agent_submissions_parent\n ON effect_agent_submissions (parent_submission_id)\n `.withoutTransform;\n\n // Parent-owned child budget reservations (spec §12 steps 2 and 6, SUB-010): generic\n // opaque-payload state-machine rows (D8) — allocation and accounting are Schema-encoded\n // JSON documents the adapter never interprets; status moves\n // reserved → releasePending → released, applied exactly once.\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 // record_json is authoritative. The remaining columns support owner keyset paging and\n // deadline queries without decoding unrelated future schedules.\n yield* sql`\n CREATE TABLE effect_agent_schedules (\n tenant_id TEXT NOT NULL,\n owner_id TEXT NOT NULL,\n schedule_id TEXT NOT NULL,\n deadline_at_millis INTEGER,\n record_json TEXT NOT NULL,\n PRIMARY KEY (tenant_id, owner_id, schedule_id)\n )\n `.withoutTransform;\n\n yield* sql`\n CREATE INDEX effect_agent_schedules_deadline\n ON effect_agent_schedules (deadline_at_millis, tenant_id, owner_id, schedule_id)\n WHERE deadline_at_millis IS NOT NULL\n `.withoutTransform;\n\n yield* sql`\n CREATE INDEX effect_agent_schedules_owner_deadline\n ON effect_agent_schedules (tenant_id, owner_id, deadline_at_millis, schedule_id)\n WHERE deadline_at_millis IS NOT NULL\n `.withoutTransform;\n\n yield* sql`\n CREATE TABLE effect_agent_subscription_sequences (\n tenant_id TEXT NOT NULL,\n source_address TEXT NOT NULL,\n sequence INTEGER NOT NULL,\n event_scan_cursor TEXT NOT NULL,\n delivery_scan_cursor TEXT NOT NULL,\n recovery_scan_cursor INTEGER NOT NULL,\n PRIMARY KEY (tenant_id, source_address)\n )\n `.withoutTransform;\n yield* sql`\n CREATE TABLE effect_agent_subscriptions (\n tenant_id TEXT NOT NULL,\n source_address TEXT NOT NULL,\n owner_id TEXT NOT NULL,\n subscription_id TEXT NOT NULL,\n ordinal INTEGER NOT NULL,\n source_name TEXT NOT NULL,\n source_version TEXT NOT NULL,\n matching_key TEXT NOT NULL,\n state TEXT NOT NULL,\n expires_at_millis INTEGER,\n recovery_at_millis INTEGER,\n recovery_present INTEGER NOT NULL DEFAULT 0,\n record_json TEXT NOT NULL,\n PRIMARY KEY (tenant_id, source_address, owner_id, subscription_id),\n UNIQUE (tenant_id, source_address, ordinal)\n )\n `.withoutTransform;\n yield* sql`CREATE INDEX effect_agent_subscriptions_owner ON effect_agent_subscriptions (tenant_id, source_address, owner_id, ordinal)`\n .withoutTransform;\n yield* sql`CREATE INDEX effect_agent_subscriptions_candidates ON effect_agent_subscriptions (tenant_id, source_address, source_name, source_version, matching_key, ordinal)`\n .withoutTransform;\n yield* sql`CREATE INDEX effect_agent_subscriptions_recovery ON effect_agent_subscriptions (tenant_id, source_address, recovery_at_millis, ordinal) WHERE recovery_at_millis IS NOT NULL`\n .withoutTransform;\n yield* sql`\n CREATE TABLE effect_agent_subscription_events (\n tenant_id TEXT NOT NULL,\n source_address TEXT NOT NULL,\n event_id TEXT NOT NULL,\n source_name TEXT NOT NULL,\n source_version TEXT NOT NULL,\n matching_key TEXT NOT NULL,\n payload_digest TEXT NOT NULL,\n cutoff INTEGER NOT NULL,\n cursor INTEGER NOT NULL,\n routing_complete INTEGER NOT NULL,\n tombstone INTEGER NOT NULL DEFAULT 0,\n next_attempt_at_millis INTEGER NOT NULL,\n record_json TEXT NOT NULL,\n PRIMARY KEY (tenant_id, source_address, event_id)\n )\n `.withoutTransform;\n yield* sql`CREATE INDEX effect_agent_subscription_events_pending ON effect_agent_subscription_events (tenant_id, source_address, routing_complete, next_attempt_at_millis, event_id)`\n .withoutTransform;\n yield* sql`\n CREATE TABLE effect_agent_subscription_deliveries (\n tenant_id TEXT NOT NULL,\n source_address TEXT NOT NULL,\n owner_id TEXT NOT NULL,\n subscription_id TEXT NOT NULL,\n event_id TEXT NOT NULL,\n delivery_key TEXT NOT NULL,\n state TEXT NOT NULL,\n next_attempt_at_millis INTEGER NOT NULL,\n record_json TEXT NOT NULL,\n PRIMARY KEY (tenant_id, source_address, owner_id, subscription_id, event_id),\n UNIQUE (tenant_id, source_address, delivery_key)\n )\n `.withoutTransform;\n yield* sql`CREATE INDEX effect_agent_subscription_deliveries_pending ON effect_agent_subscription_deliveries (tenant_id, source_address, state, next_attempt_at_millis, delivery_key)`\n .withoutTransform;\n yield* sql`CREATE INDEX effect_agent_subscription_deliveries_registration ON effect_agent_subscription_deliveries (tenant_id, source_address, owner_id, subscription_id, delivery_key)`\n .withoutTransform;\n yield* createNonterminalIndex;\n yield* createMessageDeliveryTables;\n yield* createRecoveryCheckpointTable;\n yield* sql`PRAGMA user_version = 11`.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;;;ACTD,MAAa,8BAA8B;;AAG3C,MAAa,yBAAyB,OAAO,IAAI,aAAa;CAG5D,OAAO,CAAA,OAFY,UAAU,UAAA,AAEnB,qIACP;AACL,CAAC;;AAGD,MAAa,mBAAmB,eAAe,WAAW,EACxD,4BAA4B,OAAO,IAAI,aAAa;CAClD,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;;;;;;;;;;;;MAYR;CAEF,OAAO,GAAG;;;;;;;;;;;;MAYR;CAEF,OAAO,GAAG;;;;;;;;;;;;;;MAcR;CAEF,OAAO,GAAG;;;;;;;;;;;MAWR;CAEF,OAAO,GAAG;;;MAGR;CAEF,OAAO,GAAG;;;;;;;;;;;;;MAaR;CAEF,OAAO,GAAG;;;;;;;;;;;;;MAaR;CAIF,OAAO,GAAG;;;MAGR;CAMF,OAAO,GAAG;;;;;;;;;;;;;;;;;;MAkBR;CAIF,OAAO,GAAG;;;;;;;;;MASR;CAEF,OAAO,GAAG;;;;MAIR;CAEF,OAAO,GAAG;;;;MAIR;CAEF,OAAO,GAAG;;;;;;;;;;MAUR;CACF,OAAO,GAAG;;;;;;;;;;;;;;;;;;MAkBR;CACF,OAAO,GAAG,6HACP;CACH,OAAO,GAAG,mKACP;CACH,OAAO,GAAG,+KACP;CACH,OAAO,GAAG;;;;;;;;;;;;;;;;;MAiBR;CACF,OAAO,GAAG,4KACP;CACH,OAAO,GAAG;;;;;;;;;;;;;;MAcR;CACF,OAAO,GAAG,6KACP;CACH,OAAO,GAAG,8KACP;CACH,OAAO;CACP,OAAO;CACP,OAAO;CACP,OAAO,GAAG,2BAA2B;AACvC,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 };
|