@electric-ax/agents-server 0.3.0

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 (68) hide show
  1. package/LICENSE +177 -0
  2. package/dist/chunk-Cl8Af3a2.js +11 -0
  3. package/dist/entrypoint.js +7319 -0
  4. package/dist/index.cjs +7090 -0
  5. package/dist/index.d.cts +4262 -0
  6. package/dist/index.d.ts +4263 -0
  7. package/dist/index.js +7053 -0
  8. package/drizzle/0000_baseline.sql +97 -0
  9. package/drizzle/0001_entity_tags_and_bridges.sql +45 -0
  10. package/drizzle/0002_tag_outbox_hardening.sql +14 -0
  11. package/drizzle/0003_entity_manifest_sources.sql +11 -0
  12. package/drizzle/0004_tenant_scoping.sql +139 -0
  13. package/drizzle/0005_pull_wake_control_plane.sql +156 -0
  14. package/drizzle/meta/0000_snapshot.json +593 -0
  15. package/drizzle/meta/_journal.json +48 -0
  16. package/package.json +89 -0
  17. package/src/authenticated-user-format.ts +17 -0
  18. package/src/claim-write-token-store.ts +74 -0
  19. package/src/db/index.ts +53 -0
  20. package/src/db/schema.ts +490 -0
  21. package/src/dev-asserted-auth.ts +46 -0
  22. package/src/dispatch-policy-schema.ts +52 -0
  23. package/src/electric-agents/adapter-types.ts +70 -0
  24. package/src/electric-agents/default-entity-schemas.ts +1 -0
  25. package/src/electric-agents/schema-validator.ts +143 -0
  26. package/src/electric-agents-http.ts +46 -0
  27. package/src/electric-agents-types.ts +335 -0
  28. package/src/entity-bridge-manager.ts +694 -0
  29. package/src/entity-manager.ts +2601 -0
  30. package/src/entity-projector.ts +765 -0
  31. package/src/entity-registry.ts +1162 -0
  32. package/src/entrypoint-lib.ts +295 -0
  33. package/src/entrypoint.ts +11 -0
  34. package/src/host.ts +323 -0
  35. package/src/index.ts +49 -0
  36. package/src/manifest-side-effects.ts +183 -0
  37. package/src/routing/agent-ui-router.ts +81 -0
  38. package/src/routing/context.ts +35 -0
  39. package/src/routing/cron-router.ts +45 -0
  40. package/src/routing/dispatch-policy.ts +248 -0
  41. package/src/routing/durable-streams-router.ts +407 -0
  42. package/src/routing/durable-streams-routing-adapter.ts +96 -0
  43. package/src/routing/electric-proxy-router.ts +61 -0
  44. package/src/routing/entities-router.ts +484 -0
  45. package/src/routing/entity-types-router.ts +229 -0
  46. package/src/routing/global-router.ts +33 -0
  47. package/src/routing/hooks.ts +123 -0
  48. package/src/routing/internal-router.ts +741 -0
  49. package/src/routing/oss-server-router.ts +56 -0
  50. package/src/routing/runners-router.ts +416 -0
  51. package/src/routing/schema.ts +141 -0
  52. package/src/routing/stream-append.ts +196 -0
  53. package/src/routing/tenant-stream-paths.ts +26 -0
  54. package/src/runtime-registry.ts +49 -0
  55. package/src/runtime.ts +537 -0
  56. package/src/scheduler.ts +788 -0
  57. package/src/schema-validation.ts +15 -0
  58. package/src/server.ts +374 -0
  59. package/src/standalone-runtime.ts +188 -0
  60. package/src/stream-client.ts +842 -0
  61. package/src/tag-stream-outbox-drainer.ts +188 -0
  62. package/src/tenant.ts +25 -0
  63. package/src/tracing.ts +57 -0
  64. package/src/utils/electric-url.ts +15 -0
  65. package/src/utils/log.ts +95 -0
  66. package/src/utils/server-utils.ts +245 -0
  67. package/src/utils/webhook-url.ts +33 -0
  68. package/src/wake-registry.ts +946 -0
@@ -0,0 +1,593 @@
1
+ {
2
+ "id": "414a442d-cfa4-43e8-8234-65c169726728",
3
+ "prevId": "00000000-0000-0000-0000-000000000000",
4
+ "version": "7",
5
+ "dialect": "postgresql",
6
+ "tables": {
7
+ "public.consumer_callbacks": {
8
+ "name": "consumer_callbacks",
9
+ "schema": "",
10
+ "columns": {
11
+ "consumer_id": {
12
+ "name": "consumer_id",
13
+ "type": "text",
14
+ "primaryKey": true,
15
+ "notNull": true
16
+ },
17
+ "callback_url": {
18
+ "name": "callback_url",
19
+ "type": "text",
20
+ "primaryKey": false,
21
+ "notNull": true
22
+ },
23
+ "primary_stream": {
24
+ "name": "primary_stream",
25
+ "type": "text",
26
+ "primaryKey": false,
27
+ "notNull": false
28
+ },
29
+ "created_at": {
30
+ "name": "created_at",
31
+ "type": "timestamp with time zone",
32
+ "primaryKey": false,
33
+ "notNull": true,
34
+ "default": "now()"
35
+ }
36
+ },
37
+ "indexes": {},
38
+ "foreignKeys": {},
39
+ "compositePrimaryKeys": {},
40
+ "uniqueConstraints": {},
41
+ "policies": {},
42
+ "checkConstraints": {},
43
+ "isRLSEnabled": false
44
+ },
45
+ "public.entities": {
46
+ "name": "entities",
47
+ "schema": "",
48
+ "columns": {
49
+ "url": {
50
+ "name": "url",
51
+ "type": "text",
52
+ "primaryKey": true,
53
+ "notNull": true
54
+ },
55
+ "type": {
56
+ "name": "type",
57
+ "type": "text",
58
+ "primaryKey": false,
59
+ "notNull": true
60
+ },
61
+ "status": {
62
+ "name": "status",
63
+ "type": "text",
64
+ "primaryKey": false,
65
+ "notNull": true,
66
+ "default": "'idle'"
67
+ },
68
+ "subscription_id": {
69
+ "name": "subscription_id",
70
+ "type": "text",
71
+ "primaryKey": false,
72
+ "notNull": true
73
+ },
74
+ "write_token": {
75
+ "name": "write_token",
76
+ "type": "text",
77
+ "primaryKey": false,
78
+ "notNull": true
79
+ },
80
+ "metadata": {
81
+ "name": "metadata",
82
+ "type": "jsonb",
83
+ "primaryKey": false,
84
+ "notNull": false,
85
+ "default": "'{}'::jsonb"
86
+ },
87
+ "spawn_args": {
88
+ "name": "spawn_args",
89
+ "type": "jsonb",
90
+ "primaryKey": false,
91
+ "notNull": false,
92
+ "default": "'{}'::jsonb"
93
+ },
94
+ "parent": {
95
+ "name": "parent",
96
+ "type": "text",
97
+ "primaryKey": false,
98
+ "notNull": false
99
+ },
100
+ "type_revision": {
101
+ "name": "type_revision",
102
+ "type": "integer",
103
+ "primaryKey": false,
104
+ "notNull": false
105
+ },
106
+ "inbox_schemas": {
107
+ "name": "inbox_schemas",
108
+ "type": "jsonb",
109
+ "primaryKey": false,
110
+ "notNull": false
111
+ },
112
+ "state_schemas": {
113
+ "name": "state_schemas",
114
+ "type": "jsonb",
115
+ "primaryKey": false,
116
+ "notNull": false
117
+ },
118
+ "metadata_schema": {
119
+ "name": "metadata_schema",
120
+ "type": "jsonb",
121
+ "primaryKey": false,
122
+ "notNull": false
123
+ },
124
+ "created_at": {
125
+ "name": "created_at",
126
+ "type": "bigint",
127
+ "primaryKey": false,
128
+ "notNull": true
129
+ },
130
+ "updated_at": {
131
+ "name": "updated_at",
132
+ "type": "bigint",
133
+ "primaryKey": false,
134
+ "notNull": true
135
+ }
136
+ },
137
+ "indexes": {
138
+ "idx_entities_type": {
139
+ "name": "idx_entities_type",
140
+ "columns": [
141
+ {
142
+ "expression": "type",
143
+ "isExpression": false,
144
+ "asc": true,
145
+ "nulls": "last"
146
+ }
147
+ ],
148
+ "isUnique": false,
149
+ "concurrently": false,
150
+ "method": "btree",
151
+ "with": {}
152
+ },
153
+ "idx_entities_status": {
154
+ "name": "idx_entities_status",
155
+ "columns": [
156
+ {
157
+ "expression": "status",
158
+ "isExpression": false,
159
+ "asc": true,
160
+ "nulls": "last"
161
+ }
162
+ ],
163
+ "isUnique": false,
164
+ "concurrently": false,
165
+ "method": "btree",
166
+ "with": {}
167
+ },
168
+ "idx_entities_parent": {
169
+ "name": "idx_entities_parent",
170
+ "columns": [
171
+ {
172
+ "expression": "parent",
173
+ "isExpression": false,
174
+ "asc": true,
175
+ "nulls": "last"
176
+ }
177
+ ],
178
+ "isUnique": false,
179
+ "concurrently": false,
180
+ "method": "btree",
181
+ "with": {}
182
+ }
183
+ },
184
+ "foreignKeys": {},
185
+ "compositePrimaryKeys": {},
186
+ "uniqueConstraints": {},
187
+ "policies": {},
188
+ "checkConstraints": {
189
+ "chk_entities_status": {
190
+ "name": "chk_entities_status",
191
+ "value": "\"entities\".\"status\" IN ('spawning', 'running', 'idle', 'stopped')"
192
+ }
193
+ },
194
+ "isRLSEnabled": false
195
+ },
196
+ "public.entity_types": {
197
+ "name": "entity_types",
198
+ "schema": "",
199
+ "columns": {
200
+ "name": {
201
+ "name": "name",
202
+ "type": "text",
203
+ "primaryKey": true,
204
+ "notNull": true
205
+ },
206
+ "description": {
207
+ "name": "description",
208
+ "type": "text",
209
+ "primaryKey": false,
210
+ "notNull": true
211
+ },
212
+ "creation_schema": {
213
+ "name": "creation_schema",
214
+ "type": "jsonb",
215
+ "primaryKey": false,
216
+ "notNull": false
217
+ },
218
+ "inbox_schemas": {
219
+ "name": "inbox_schemas",
220
+ "type": "jsonb",
221
+ "primaryKey": false,
222
+ "notNull": false
223
+ },
224
+ "state_schemas": {
225
+ "name": "state_schemas",
226
+ "type": "jsonb",
227
+ "primaryKey": false,
228
+ "notNull": false
229
+ },
230
+ "metadata_schema": {
231
+ "name": "metadata_schema",
232
+ "type": "jsonb",
233
+ "primaryKey": false,
234
+ "notNull": false
235
+ },
236
+ "serve_endpoint": {
237
+ "name": "serve_endpoint",
238
+ "type": "text",
239
+ "primaryKey": false,
240
+ "notNull": false
241
+ },
242
+ "revision": {
243
+ "name": "revision",
244
+ "type": "integer",
245
+ "primaryKey": false,
246
+ "notNull": true,
247
+ "default": 1
248
+ },
249
+ "created_at": {
250
+ "name": "created_at",
251
+ "type": "text",
252
+ "primaryKey": false,
253
+ "notNull": true
254
+ },
255
+ "updated_at": {
256
+ "name": "updated_at",
257
+ "type": "text",
258
+ "primaryKey": false,
259
+ "notNull": true
260
+ }
261
+ },
262
+ "indexes": {},
263
+ "foreignKeys": {},
264
+ "compositePrimaryKeys": {},
265
+ "uniqueConstraints": {},
266
+ "policies": {},
267
+ "checkConstraints": {},
268
+ "isRLSEnabled": false
269
+ },
270
+ "public.scheduled_tasks": {
271
+ "name": "scheduled_tasks",
272
+ "schema": "",
273
+ "columns": {
274
+ "id": {
275
+ "name": "id",
276
+ "type": "bigserial",
277
+ "primaryKey": true,
278
+ "notNull": true
279
+ },
280
+ "kind": {
281
+ "name": "kind",
282
+ "type": "text",
283
+ "primaryKey": false,
284
+ "notNull": true
285
+ },
286
+ "payload": {
287
+ "name": "payload",
288
+ "type": "jsonb",
289
+ "primaryKey": false,
290
+ "notNull": true
291
+ },
292
+ "fire_at": {
293
+ "name": "fire_at",
294
+ "type": "timestamp with time zone",
295
+ "primaryKey": false,
296
+ "notNull": true
297
+ },
298
+ "cron_expression": {
299
+ "name": "cron_expression",
300
+ "type": "text",
301
+ "primaryKey": false,
302
+ "notNull": false
303
+ },
304
+ "cron_timezone": {
305
+ "name": "cron_timezone",
306
+ "type": "text",
307
+ "primaryKey": false,
308
+ "notNull": false
309
+ },
310
+ "cron_tick_number": {
311
+ "name": "cron_tick_number",
312
+ "type": "integer",
313
+ "primaryKey": false,
314
+ "notNull": false
315
+ },
316
+ "owner_entity_url": {
317
+ "name": "owner_entity_url",
318
+ "type": "text",
319
+ "primaryKey": false,
320
+ "notNull": false
321
+ },
322
+ "manifest_key": {
323
+ "name": "manifest_key",
324
+ "type": "text",
325
+ "primaryKey": false,
326
+ "notNull": false
327
+ },
328
+ "claimed_by": {
329
+ "name": "claimed_by",
330
+ "type": "text",
331
+ "primaryKey": false,
332
+ "notNull": false
333
+ },
334
+ "claimed_at": {
335
+ "name": "claimed_at",
336
+ "type": "timestamp with time zone",
337
+ "primaryKey": false,
338
+ "notNull": false
339
+ },
340
+ "completed_at": {
341
+ "name": "completed_at",
342
+ "type": "timestamp with time zone",
343
+ "primaryKey": false,
344
+ "notNull": false
345
+ },
346
+ "last_error": {
347
+ "name": "last_error",
348
+ "type": "text",
349
+ "primaryKey": false,
350
+ "notNull": false
351
+ },
352
+ "created_at": {
353
+ "name": "created_at",
354
+ "type": "timestamp with time zone",
355
+ "primaryKey": false,
356
+ "notNull": true,
357
+ "default": "now()"
358
+ }
359
+ },
360
+ "indexes": {
361
+ "idx_scheduled_tasks_fire_ready": {
362
+ "name": "idx_scheduled_tasks_fire_ready",
363
+ "columns": [
364
+ {
365
+ "expression": "fire_at",
366
+ "isExpression": false,
367
+ "asc": true,
368
+ "nulls": "last"
369
+ }
370
+ ],
371
+ "isUnique": false,
372
+ "where": "\"scheduled_tasks\".\"completed_at\" IS NULL AND \"scheduled_tasks\".\"claimed_at\" IS NULL",
373
+ "concurrently": false,
374
+ "method": "btree",
375
+ "with": {}
376
+ },
377
+ "idx_scheduled_tasks_manifest_pending": {
378
+ "name": "idx_scheduled_tasks_manifest_pending",
379
+ "columns": [
380
+ {
381
+ "expression": "owner_entity_url",
382
+ "isExpression": false,
383
+ "asc": true,
384
+ "nulls": "last"
385
+ },
386
+ {
387
+ "expression": "manifest_key",
388
+ "isExpression": false,
389
+ "asc": true,
390
+ "nulls": "last"
391
+ }
392
+ ],
393
+ "isUnique": false,
394
+ "where": "\"scheduled_tasks\".\"kind\" = 'delayed_send' AND \"scheduled_tasks\".\"completed_at\" IS NULL AND \"scheduled_tasks\".\"manifest_key\" IS NOT NULL",
395
+ "concurrently": false,
396
+ "method": "btree",
397
+ "with": {}
398
+ },
399
+ "idx_scheduled_tasks_stale_claims": {
400
+ "name": "idx_scheduled_tasks_stale_claims",
401
+ "columns": [
402
+ {
403
+ "expression": "claimed_at",
404
+ "isExpression": false,
405
+ "asc": true,
406
+ "nulls": "last"
407
+ }
408
+ ],
409
+ "isUnique": false,
410
+ "where": "\"scheduled_tasks\".\"completed_at\" IS NULL AND \"scheduled_tasks\".\"claimed_at\" IS NOT NULL",
411
+ "concurrently": false,
412
+ "method": "btree",
413
+ "with": {}
414
+ }
415
+ },
416
+ "foreignKeys": {},
417
+ "compositePrimaryKeys": {},
418
+ "uniqueConstraints": {
419
+ "uq_cron_tick": {
420
+ "name": "uq_cron_tick",
421
+ "nullsNotDistinct": false,
422
+ "columns": ["cron_expression", "cron_timezone", "cron_tick_number"]
423
+ }
424
+ },
425
+ "policies": {},
426
+ "checkConstraints": {
427
+ "chk_scheduled_tasks_kind": {
428
+ "name": "chk_scheduled_tasks_kind",
429
+ "value": "\"scheduled_tasks\".\"kind\" IN ('delayed_send', 'cron_tick')"
430
+ }
431
+ },
432
+ "isRLSEnabled": false
433
+ },
434
+ "public.subscription_webhooks": {
435
+ "name": "subscription_webhooks",
436
+ "schema": "",
437
+ "columns": {
438
+ "subscription_id": {
439
+ "name": "subscription_id",
440
+ "type": "text",
441
+ "primaryKey": true,
442
+ "notNull": true
443
+ },
444
+ "webhook_url": {
445
+ "name": "webhook_url",
446
+ "type": "text",
447
+ "primaryKey": false,
448
+ "notNull": true
449
+ },
450
+ "created_at": {
451
+ "name": "created_at",
452
+ "type": "timestamp with time zone",
453
+ "primaryKey": false,
454
+ "notNull": true,
455
+ "default": "now()"
456
+ }
457
+ },
458
+ "indexes": {},
459
+ "foreignKeys": {},
460
+ "compositePrimaryKeys": {},
461
+ "uniqueConstraints": {},
462
+ "policies": {},
463
+ "checkConstraints": {},
464
+ "isRLSEnabled": false
465
+ },
466
+ "public.wake_registrations": {
467
+ "name": "wake_registrations",
468
+ "schema": "",
469
+ "columns": {
470
+ "id": {
471
+ "name": "id",
472
+ "type": "serial",
473
+ "primaryKey": true,
474
+ "notNull": true
475
+ },
476
+ "subscriber_url": {
477
+ "name": "subscriber_url",
478
+ "type": "text",
479
+ "primaryKey": false,
480
+ "notNull": true
481
+ },
482
+ "source_url": {
483
+ "name": "source_url",
484
+ "type": "text",
485
+ "primaryKey": false,
486
+ "notNull": true
487
+ },
488
+ "condition": {
489
+ "name": "condition",
490
+ "type": "jsonb",
491
+ "primaryKey": false,
492
+ "notNull": true
493
+ },
494
+ "debounce_ms": {
495
+ "name": "debounce_ms",
496
+ "type": "integer",
497
+ "primaryKey": false,
498
+ "notNull": true,
499
+ "default": 0
500
+ },
501
+ "timeout_ms": {
502
+ "name": "timeout_ms",
503
+ "type": "integer",
504
+ "primaryKey": false,
505
+ "notNull": true,
506
+ "default": 0
507
+ },
508
+ "one_shot": {
509
+ "name": "one_shot",
510
+ "type": "boolean",
511
+ "primaryKey": false,
512
+ "notNull": true,
513
+ "default": false
514
+ },
515
+ "timeout_consumed": {
516
+ "name": "timeout_consumed",
517
+ "type": "boolean",
518
+ "primaryKey": false,
519
+ "notNull": true,
520
+ "default": false
521
+ },
522
+ "include_response": {
523
+ "name": "include_response",
524
+ "type": "boolean",
525
+ "primaryKey": false,
526
+ "notNull": true,
527
+ "default": true
528
+ },
529
+ "manifest_key": {
530
+ "name": "manifest_key",
531
+ "type": "text",
532
+ "primaryKey": false,
533
+ "notNull": false
534
+ },
535
+ "created_at": {
536
+ "name": "created_at",
537
+ "type": "timestamp with time zone",
538
+ "primaryKey": false,
539
+ "notNull": true,
540
+ "default": "now()"
541
+ }
542
+ },
543
+ "indexes": {
544
+ "idx_wake_source_url": {
545
+ "name": "idx_wake_source_url",
546
+ "columns": [
547
+ {
548
+ "expression": "source_url",
549
+ "isExpression": false,
550
+ "asc": true,
551
+ "nulls": "last"
552
+ }
553
+ ],
554
+ "isUnique": false,
555
+ "concurrently": false,
556
+ "method": "btree",
557
+ "with": {}
558
+ }
559
+ },
560
+ "foreignKeys": {},
561
+ "compositePrimaryKeys": {},
562
+ "uniqueConstraints": {
563
+ "uq_wake_registration": {
564
+ "name": "uq_wake_registration",
565
+ "nullsNotDistinct": false,
566
+ "columns": [
567
+ "subscriber_url",
568
+ "source_url",
569
+ "one_shot",
570
+ "debounce_ms",
571
+ "timeout_ms",
572
+ "condition",
573
+ "manifest_key"
574
+ ]
575
+ }
576
+ },
577
+ "policies": {},
578
+ "checkConstraints": {},
579
+ "isRLSEnabled": false
580
+ }
581
+ },
582
+ "enums": {},
583
+ "schemas": {},
584
+ "sequences": {},
585
+ "roles": {},
586
+ "policies": {},
587
+ "views": {},
588
+ "_meta": {
589
+ "columns": {},
590
+ "schemas": {},
591
+ "tables": {}
592
+ }
593
+ }
@@ -0,0 +1,48 @@
1
+ {
2
+ "version": "7",
3
+ "dialect": "postgresql",
4
+ "entries": [
5
+ {
6
+ "idx": 0,
7
+ "version": "7",
8
+ "when": 1776187036654,
9
+ "tag": "0000_baseline",
10
+ "breakpoints": true
11
+ },
12
+ {
13
+ "idx": 1,
14
+ "version": "7",
15
+ "when": 1776219000000,
16
+ "tag": "0001_entity_tags_and_bridges",
17
+ "breakpoints": true
18
+ },
19
+ {
20
+ "idx": 2,
21
+ "version": "7",
22
+ "when": 1776233400000,
23
+ "tag": "0002_tag_outbox_hardening",
24
+ "breakpoints": true
25
+ },
26
+ {
27
+ "idx": 3,
28
+ "version": "7",
29
+ "when": 1776240000000,
30
+ "tag": "0003_entity_manifest_sources",
31
+ "breakpoints": true
32
+ },
33
+ {
34
+ "idx": 4,
35
+ "version": "7",
36
+ "when": 1776261600000,
37
+ "tag": "0004_tenant_scoping",
38
+ "breakpoints": true
39
+ },
40
+ {
41
+ "idx": 5,
42
+ "version": "7",
43
+ "when": 1776265200000,
44
+ "tag": "0005_pull_wake_control_plane",
45
+ "breakpoints": true
46
+ }
47
+ ]
48
+ }