@m6d/cortex-server 2.3.0 → 2.5.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 (62) hide show
  1. package/contracts/src/runtime/index.ts +99 -3
  2. package/dist/contracts/src/graph/helpers.d.ts +5 -5
  3. package/dist/contracts/src/runtime/index.d.ts +175 -3
  4. package/dist/src/lib/adapters/database/index.d.ts +20 -2
  5. package/dist/src/lib/adapters/database/mssql/attachments.d.ts +9 -9
  6. package/dist/src/lib/adapters/database/mssql/index.d.ts +133 -28
  7. package/dist/src/lib/adapters/database/mssql/llm-requests.d.ts +3 -2
  8. package/dist/src/lib/adapters/database/mssql/messages.d.ts +6 -5
  9. package/dist/src/lib/adapters/database/mssql/outbox.d.ts +103 -0
  10. package/dist/src/lib/adapters/database/mssql/threads.d.ts +21 -14
  11. package/dist/src/lib/adapters/database/postgres/attachments.d.ts +9 -9
  12. package/dist/src/lib/adapters/database/postgres/index.d.ts +133 -28
  13. package/dist/src/lib/adapters/database/postgres/llm-requests.d.ts +3 -2
  14. package/dist/src/lib/adapters/database/postgres/messages.d.ts +6 -5
  15. package/dist/src/lib/adapters/database/postgres/outbox.d.ts +103 -0
  16. package/dist/src/lib/adapters/database/postgres/threads.d.ts +21 -14
  17. package/dist/src/lib/ai/attachments.d.ts +2 -2
  18. package/dist/src/lib/ai/client-tools.d.ts +1 -1
  19. package/dist/src/lib/auth/middleware.d.ts +2 -2
  20. package/dist/src/lib/auth/playground.d.ts +14 -0
  21. package/dist/src/lib/cc/client.d.ts +9 -1
  22. package/dist/src/lib/cc/flusher.d.ts +40 -0
  23. package/dist/src/lib/cc/sync-events.d.ts +45 -0
  24. package/dist/src/lib/cc/types.d.ts +1 -1
  25. package/dist/src/lib/config.d.ts +11 -0
  26. package/dist/src/lib/db/schema.mssql.d.ts +161 -0
  27. package/dist/src/lib/db/schema.pg.d.ts +199 -0
  28. package/dist/src/lib/factory.d.ts +3 -0
  29. package/dist/src/lib/routes/owned-thread.d.ts +5 -4
  30. package/package.json +2 -2
  31. package/src/lib/adapters/database/index.ts +15 -1
  32. package/src/lib/adapters/database/mssql/index.ts +13 -4
  33. package/src/lib/adapters/database/mssql/llm-requests.ts +35 -15
  34. package/src/lib/adapters/database/mssql/messages.ts +81 -30
  35. package/src/lib/adapters/database/mssql/outbox.ts +71 -0
  36. package/src/lib/adapters/database/mssql/threads.ts +42 -11
  37. package/src/lib/adapters/database/postgres/index.ts +13 -4
  38. package/src/lib/adapters/database/postgres/llm-requests.ts +35 -15
  39. package/src/lib/adapters/database/postgres/messages.ts +81 -30
  40. package/src/lib/adapters/database/postgres/outbox.ts +66 -0
  41. package/src/lib/adapters/database/postgres/threads.ts +39 -11
  42. package/src/lib/ai/finish-turn.ts +3 -1
  43. package/src/lib/ai/prompt.ts +3 -1
  44. package/src/lib/auth/middleware.ts +34 -8
  45. package/src/lib/auth/playground.ts +72 -0
  46. package/src/lib/cc/client.ts +21 -1
  47. package/src/lib/cc/flusher.ts +147 -0
  48. package/src/lib/cc/sync-events.ts +65 -0
  49. package/src/lib/cc/types.ts +3 -0
  50. package/src/lib/config.ts +11 -0
  51. package/src/lib/db/migrations/mssql/20260829050547_friendly_red_shift/migration.sql +8 -0
  52. package/src/lib/db/migrations/mssql/20260829050547_friendly_red_shift/snapshot.json +581 -0
  53. package/src/lib/db/migrations/mssql/20260830022424_easy_nicolaos/migration.sql +5 -0
  54. package/src/lib/db/migrations/mssql/20260830022424_easy_nicolaos/snapshot.json +614 -0
  55. package/src/lib/db/migrations/pg/20260829050547_perfect_wildside/migration.sql +7 -0
  56. package/src/lib/db/migrations/pg/20260829050547_perfect_wildside/snapshot.json +650 -0
  57. package/src/lib/db/migrations/pg/20260830022424_serious_deadpool/migration.sql +4 -0
  58. package/src/lib/db/migrations/pg/20260830022424_serious_deadpool/snapshot.json +690 -0
  59. package/src/lib/db/schema.mssql.ts +32 -1
  60. package/src/lib/db/schema.pg.ts +24 -0
  61. package/src/lib/factory.ts +22 -8
  62. package/src/lib/routes/threads.ts +5 -1
@@ -0,0 +1,650 @@
1
+ {
2
+ "version": "8",
3
+ "dialect": "postgres",
4
+ "id": "2117476b-c06c-4a15-9833-31ba6e927720",
5
+ "prevIds": ["a5037982-d7a6-419a-8d7a-aaacd8bf939b"],
6
+ "ddl": [
7
+ {
8
+ "name": "ai",
9
+ "entityType": "schemas"
10
+ },
11
+ {
12
+ "isRlsEnabled": false,
13
+ "name": "attachments",
14
+ "entityType": "tables",
15
+ "schema": "ai"
16
+ },
17
+ {
18
+ "isRlsEnabled": false,
19
+ "name": "llm_requests",
20
+ "entityType": "tables",
21
+ "schema": "ai"
22
+ },
23
+ {
24
+ "isRlsEnabled": false,
25
+ "name": "messages",
26
+ "entityType": "tables",
27
+ "schema": "ai"
28
+ },
29
+ {
30
+ "isRlsEnabled": false,
31
+ "name": "sync_outbox",
32
+ "entityType": "tables",
33
+ "schema": "ai"
34
+ },
35
+ {
36
+ "isRlsEnabled": false,
37
+ "name": "threads",
38
+ "entityType": "tables",
39
+ "schema": "ai"
40
+ },
41
+ {
42
+ "type": "uuid",
43
+ "typeSchema": null,
44
+ "notNull": true,
45
+ "dimensions": 0,
46
+ "default": "gen_random_uuid()",
47
+ "generated": null,
48
+ "identity": null,
49
+ "name": "id",
50
+ "entityType": "columns",
51
+ "schema": "ai",
52
+ "table": "attachments"
53
+ },
54
+ {
55
+ "type": "uuid",
56
+ "typeSchema": null,
57
+ "notNull": true,
58
+ "dimensions": 0,
59
+ "default": null,
60
+ "generated": null,
61
+ "identity": null,
62
+ "name": "thread_id",
63
+ "entityType": "columns",
64
+ "schema": "ai",
65
+ "table": "attachments"
66
+ },
67
+ {
68
+ "type": "varchar(255)",
69
+ "typeSchema": null,
70
+ "notNull": true,
71
+ "dimensions": 0,
72
+ "default": null,
73
+ "generated": null,
74
+ "identity": null,
75
+ "name": "user_id",
76
+ "entityType": "columns",
77
+ "schema": "ai",
78
+ "table": "attachments"
79
+ },
80
+ {
81
+ "type": "varchar(128)",
82
+ "typeSchema": null,
83
+ "notNull": false,
84
+ "dimensions": 0,
85
+ "default": null,
86
+ "generated": null,
87
+ "identity": null,
88
+ "name": "message_id",
89
+ "entityType": "columns",
90
+ "schema": "ai",
91
+ "table": "attachments"
92
+ },
93
+ {
94
+ "type": "varchar(2048)",
95
+ "typeSchema": null,
96
+ "notNull": true,
97
+ "dimensions": 0,
98
+ "default": null,
99
+ "generated": null,
100
+ "identity": null,
101
+ "name": "filename",
102
+ "entityType": "columns",
103
+ "schema": "ai",
104
+ "table": "attachments"
105
+ },
106
+ {
107
+ "type": "varchar(256)",
108
+ "typeSchema": null,
109
+ "notNull": true,
110
+ "dimensions": 0,
111
+ "default": null,
112
+ "generated": null,
113
+ "identity": null,
114
+ "name": "content_type",
115
+ "entityType": "columns",
116
+ "schema": "ai",
117
+ "table": "attachments"
118
+ },
119
+ {
120
+ "type": "integer",
121
+ "typeSchema": null,
122
+ "notNull": true,
123
+ "dimensions": 0,
124
+ "default": null,
125
+ "generated": null,
126
+ "identity": null,
127
+ "name": "size_bytes",
128
+ "entityType": "columns",
129
+ "schema": "ai",
130
+ "table": "attachments"
131
+ },
132
+ {
133
+ "type": "varchar(512)",
134
+ "typeSchema": null,
135
+ "notNull": true,
136
+ "dimensions": 0,
137
+ "default": null,
138
+ "generated": null,
139
+ "identity": null,
140
+ "name": "storage_key",
141
+ "entityType": "columns",
142
+ "schema": "ai",
143
+ "table": "attachments"
144
+ },
145
+ {
146
+ "type": "varchar(16)",
147
+ "typeSchema": null,
148
+ "notNull": true,
149
+ "dimensions": 0,
150
+ "default": null,
151
+ "generated": null,
152
+ "identity": null,
153
+ "name": "status",
154
+ "entityType": "columns",
155
+ "schema": "ai",
156
+ "table": "attachments"
157
+ },
158
+ {
159
+ "type": "text",
160
+ "typeSchema": null,
161
+ "notNull": false,
162
+ "dimensions": 0,
163
+ "default": null,
164
+ "generated": null,
165
+ "identity": null,
166
+ "name": "description",
167
+ "entityType": "columns",
168
+ "schema": "ai",
169
+ "table": "attachments"
170
+ },
171
+ {
172
+ "type": "timestamp with time zone",
173
+ "typeSchema": null,
174
+ "notNull": true,
175
+ "dimensions": 0,
176
+ "default": null,
177
+ "generated": null,
178
+ "identity": null,
179
+ "name": "created_at",
180
+ "entityType": "columns",
181
+ "schema": "ai",
182
+ "table": "attachments"
183
+ },
184
+ {
185
+ "type": "timestamp with time zone",
186
+ "typeSchema": null,
187
+ "notNull": true,
188
+ "dimensions": 0,
189
+ "default": null,
190
+ "generated": null,
191
+ "identity": null,
192
+ "name": "updated_at",
193
+ "entityType": "columns",
194
+ "schema": "ai",
195
+ "table": "attachments"
196
+ },
197
+ {
198
+ "type": "uuid",
199
+ "typeSchema": null,
200
+ "notNull": true,
201
+ "dimensions": 0,
202
+ "default": "gen_random_uuid()",
203
+ "generated": null,
204
+ "identity": null,
205
+ "name": "id",
206
+ "entityType": "columns",
207
+ "schema": "ai",
208
+ "table": "llm_requests"
209
+ },
210
+ {
211
+ "type": "varchar(128)",
212
+ "typeSchema": null,
213
+ "notNull": true,
214
+ "dimensions": 0,
215
+ "default": null,
216
+ "generated": null,
217
+ "identity": null,
218
+ "name": "message_id",
219
+ "entityType": "columns",
220
+ "schema": "ai",
221
+ "table": "llm_requests"
222
+ },
223
+ {
224
+ "type": "integer",
225
+ "typeSchema": null,
226
+ "notNull": true,
227
+ "dimensions": 0,
228
+ "default": null,
229
+ "generated": null,
230
+ "identity": null,
231
+ "name": "step_number",
232
+ "entityType": "columns",
233
+ "schema": "ai",
234
+ "table": "llm_requests"
235
+ },
236
+ {
237
+ "type": "text",
238
+ "typeSchema": null,
239
+ "notNull": true,
240
+ "dimensions": 0,
241
+ "default": null,
242
+ "generated": null,
243
+ "identity": null,
244
+ "name": "prompt",
245
+ "entityType": "columns",
246
+ "schema": "ai",
247
+ "table": "llm_requests"
248
+ },
249
+ {
250
+ "type": "text",
251
+ "typeSchema": null,
252
+ "notNull": false,
253
+ "dimensions": 0,
254
+ "default": null,
255
+ "generated": null,
256
+ "identity": null,
257
+ "name": "output",
258
+ "entityType": "columns",
259
+ "schema": "ai",
260
+ "table": "llm_requests"
261
+ },
262
+ {
263
+ "type": "jsonb",
264
+ "typeSchema": null,
265
+ "notNull": false,
266
+ "dimensions": 0,
267
+ "default": null,
268
+ "generated": null,
269
+ "identity": null,
270
+ "name": "token_usage",
271
+ "entityType": "columns",
272
+ "schema": "ai",
273
+ "table": "llm_requests"
274
+ },
275
+ {
276
+ "type": "varchar(128)",
277
+ "typeSchema": null,
278
+ "notNull": true,
279
+ "dimensions": 0,
280
+ "default": null,
281
+ "generated": null,
282
+ "identity": null,
283
+ "name": "id",
284
+ "entityType": "columns",
285
+ "schema": "ai",
286
+ "table": "messages"
287
+ },
288
+ {
289
+ "type": "uuid",
290
+ "typeSchema": null,
291
+ "notNull": true,
292
+ "dimensions": 0,
293
+ "default": null,
294
+ "generated": null,
295
+ "identity": null,
296
+ "name": "thread_id",
297
+ "entityType": "columns",
298
+ "schema": "ai",
299
+ "table": "messages"
300
+ },
301
+ {
302
+ "type": "text",
303
+ "typeSchema": null,
304
+ "notNull": false,
305
+ "dimensions": 0,
306
+ "default": null,
307
+ "generated": null,
308
+ "identity": null,
309
+ "name": "text",
310
+ "entityType": "columns",
311
+ "schema": "ai",
312
+ "table": "messages"
313
+ },
314
+ {
315
+ "type": "jsonb",
316
+ "typeSchema": null,
317
+ "notNull": true,
318
+ "dimensions": 0,
319
+ "default": null,
320
+ "generated": null,
321
+ "identity": null,
322
+ "name": "content",
323
+ "entityType": "columns",
324
+ "schema": "ai",
325
+ "table": "messages"
326
+ },
327
+ {
328
+ "type": "integer",
329
+ "typeSchema": null,
330
+ "notNull": true,
331
+ "dimensions": 0,
332
+ "default": "0",
333
+ "generated": null,
334
+ "identity": null,
335
+ "name": "ordinal",
336
+ "entityType": "columns",
337
+ "schema": "ai",
338
+ "table": "messages"
339
+ },
340
+ {
341
+ "type": "varchar(16)",
342
+ "typeSchema": null,
343
+ "notNull": true,
344
+ "dimensions": 0,
345
+ "default": null,
346
+ "generated": null,
347
+ "identity": null,
348
+ "name": "role",
349
+ "entityType": "columns",
350
+ "schema": "ai",
351
+ "table": "messages"
352
+ },
353
+ {
354
+ "type": "timestamp with time zone",
355
+ "typeSchema": null,
356
+ "notNull": true,
357
+ "dimensions": 0,
358
+ "default": null,
359
+ "generated": null,
360
+ "identity": null,
361
+ "name": "created_at",
362
+ "entityType": "columns",
363
+ "schema": "ai",
364
+ "table": "messages"
365
+ },
366
+ {
367
+ "type": "timestamp with time zone",
368
+ "typeSchema": null,
369
+ "notNull": true,
370
+ "dimensions": 0,
371
+ "default": null,
372
+ "generated": null,
373
+ "identity": null,
374
+ "name": "updated_at",
375
+ "entityType": "columns",
376
+ "schema": "ai",
377
+ "table": "messages"
378
+ },
379
+ {
380
+ "type": "bigserial",
381
+ "typeSchema": null,
382
+ "notNull": true,
383
+ "dimensions": 0,
384
+ "default": null,
385
+ "generated": null,
386
+ "identity": null,
387
+ "name": "id",
388
+ "entityType": "columns",
389
+ "schema": "ai",
390
+ "table": "sync_outbox"
391
+ },
392
+ {
393
+ "type": "jsonb",
394
+ "typeSchema": null,
395
+ "notNull": true,
396
+ "dimensions": 0,
397
+ "default": null,
398
+ "generated": null,
399
+ "identity": null,
400
+ "name": "event",
401
+ "entityType": "columns",
402
+ "schema": "ai",
403
+ "table": "sync_outbox"
404
+ },
405
+ {
406
+ "type": "timestamp with time zone",
407
+ "typeSchema": null,
408
+ "notNull": true,
409
+ "dimensions": 0,
410
+ "default": null,
411
+ "generated": null,
412
+ "identity": null,
413
+ "name": "created_at",
414
+ "entityType": "columns",
415
+ "schema": "ai",
416
+ "table": "sync_outbox"
417
+ },
418
+ {
419
+ "type": "uuid",
420
+ "typeSchema": null,
421
+ "notNull": true,
422
+ "dimensions": 0,
423
+ "default": "gen_random_uuid()",
424
+ "generated": null,
425
+ "identity": null,
426
+ "name": "id",
427
+ "entityType": "columns",
428
+ "schema": "ai",
429
+ "table": "threads"
430
+ },
431
+ {
432
+ "type": "varchar(255)",
433
+ "typeSchema": null,
434
+ "notNull": true,
435
+ "dimensions": 0,
436
+ "default": null,
437
+ "generated": null,
438
+ "identity": null,
439
+ "name": "user_id",
440
+ "entityType": "columns",
441
+ "schema": "ai",
442
+ "table": "threads"
443
+ },
444
+ {
445
+ "type": "varchar(128)",
446
+ "typeSchema": null,
447
+ "notNull": true,
448
+ "dimensions": 0,
449
+ "default": "'default'",
450
+ "generated": null,
451
+ "identity": null,
452
+ "name": "agent_id",
453
+ "entityType": "columns",
454
+ "schema": "ai",
455
+ "table": "threads"
456
+ },
457
+ {
458
+ "type": "varchar(256)",
459
+ "typeSchema": null,
460
+ "notNull": false,
461
+ "dimensions": 0,
462
+ "default": null,
463
+ "generated": null,
464
+ "identity": null,
465
+ "name": "title",
466
+ "entityType": "columns",
467
+ "schema": "ai",
468
+ "table": "threads"
469
+ },
470
+ {
471
+ "type": "boolean",
472
+ "typeSchema": null,
473
+ "notNull": true,
474
+ "dimensions": 0,
475
+ "default": "false",
476
+ "generated": null,
477
+ "identity": null,
478
+ "name": "is_test",
479
+ "entityType": "columns",
480
+ "schema": "ai",
481
+ "table": "threads"
482
+ },
483
+ {
484
+ "type": "jsonb",
485
+ "typeSchema": null,
486
+ "notNull": false,
487
+ "dimensions": 0,
488
+ "default": null,
489
+ "generated": null,
490
+ "identity": null,
491
+ "name": "session",
492
+ "entityType": "columns",
493
+ "schema": "ai",
494
+ "table": "threads"
495
+ },
496
+ {
497
+ "type": "jsonb",
498
+ "typeSchema": null,
499
+ "notNull": false,
500
+ "dimensions": 0,
501
+ "default": null,
502
+ "generated": null,
503
+ "identity": null,
504
+ "name": "context_meta",
505
+ "entityType": "columns",
506
+ "schema": "ai",
507
+ "table": "threads"
508
+ },
509
+ {
510
+ "type": "timestamp with time zone",
511
+ "typeSchema": null,
512
+ "notNull": true,
513
+ "dimensions": 0,
514
+ "default": null,
515
+ "generated": null,
516
+ "identity": null,
517
+ "name": "created_at",
518
+ "entityType": "columns",
519
+ "schema": "ai",
520
+ "table": "threads"
521
+ },
522
+ {
523
+ "type": "timestamp with time zone",
524
+ "typeSchema": null,
525
+ "notNull": true,
526
+ "dimensions": 0,
527
+ "default": null,
528
+ "generated": null,
529
+ "identity": null,
530
+ "name": "updated_at",
531
+ "entityType": "columns",
532
+ "schema": "ai",
533
+ "table": "threads"
534
+ },
535
+ {
536
+ "nameExplicit": true,
537
+ "columns": [
538
+ {
539
+ "value": "thread_id",
540
+ "isExpression": false,
541
+ "asc": true,
542
+ "nullsFirst": false,
543
+ "opclass": null
544
+ }
545
+ ],
546
+ "isUnique": false,
547
+ "where": null,
548
+ "with": "",
549
+ "method": "btree",
550
+ "concurrently": false,
551
+ "name": "attachments_thread_id_index",
552
+ "entityType": "indexes",
553
+ "schema": "ai",
554
+ "table": "attachments"
555
+ },
556
+ {
557
+ "nameExplicit": false,
558
+ "columns": ["thread_id"],
559
+ "schemaTo": "ai",
560
+ "tableTo": "threads",
561
+ "columnsTo": ["id"],
562
+ "onUpdate": "NO ACTION",
563
+ "onDelete": "CASCADE",
564
+ "name": "attachments_thread_id_threads_id_fkey",
565
+ "entityType": "fks",
566
+ "schema": "ai",
567
+ "table": "attachments"
568
+ },
569
+ {
570
+ "nameExplicit": false,
571
+ "columns": ["message_id"],
572
+ "schemaTo": "ai",
573
+ "tableTo": "messages",
574
+ "columnsTo": ["id"],
575
+ "onUpdate": "NO ACTION",
576
+ "onDelete": "NO ACTION",
577
+ "name": "attachments_message_id_messages_id_fkey",
578
+ "entityType": "fks",
579
+ "schema": "ai",
580
+ "table": "attachments"
581
+ },
582
+ {
583
+ "nameExplicit": false,
584
+ "columns": ["message_id"],
585
+ "schemaTo": "ai",
586
+ "tableTo": "messages",
587
+ "columnsTo": ["id"],
588
+ "onUpdate": "NO ACTION",
589
+ "onDelete": "CASCADE",
590
+ "name": "llm_requests_message_id_messages_id_fkey",
591
+ "entityType": "fks",
592
+ "schema": "ai",
593
+ "table": "llm_requests"
594
+ },
595
+ {
596
+ "nameExplicit": false,
597
+ "columns": ["thread_id"],
598
+ "schemaTo": "ai",
599
+ "tableTo": "threads",
600
+ "columnsTo": ["id"],
601
+ "onUpdate": "NO ACTION",
602
+ "onDelete": "CASCADE",
603
+ "name": "messages_thread_id_threads_id_fkey",
604
+ "entityType": "fks",
605
+ "schema": "ai",
606
+ "table": "messages"
607
+ },
608
+ {
609
+ "columns": ["id"],
610
+ "nameExplicit": false,
611
+ "name": "attachments_pkey",
612
+ "schema": "ai",
613
+ "table": "attachments",
614
+ "entityType": "pks"
615
+ },
616
+ {
617
+ "columns": ["id"],
618
+ "nameExplicit": false,
619
+ "name": "llm_requests_pkey",
620
+ "schema": "ai",
621
+ "table": "llm_requests",
622
+ "entityType": "pks"
623
+ },
624
+ {
625
+ "columns": ["id"],
626
+ "nameExplicit": false,
627
+ "name": "messages_pkey",
628
+ "schema": "ai",
629
+ "table": "messages",
630
+ "entityType": "pks"
631
+ },
632
+ {
633
+ "columns": ["id"],
634
+ "nameExplicit": false,
635
+ "name": "sync_outbox_pkey",
636
+ "schema": "ai",
637
+ "table": "sync_outbox",
638
+ "entityType": "pks"
639
+ },
640
+ {
641
+ "columns": ["id"],
642
+ "nameExplicit": false,
643
+ "name": "threads_pkey",
644
+ "schema": "ai",
645
+ "table": "threads",
646
+ "entityType": "pks"
647
+ }
648
+ ],
649
+ "renames": []
650
+ }
@@ -0,0 +1,4 @@
1
+ CREATE TABLE "ai"."sync_meta" (
2
+ "id" integer PRIMARY KEY,
3
+ "epoch" varchar(36) NOT NULL
4
+ );