@m6d/cortex-server 2.3.0 → 2.4.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 +1 -1
  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,581 @@
1
+ {
2
+ "version": "2",
3
+ "dialect": "mssql",
4
+ "id": "74f59860-fdf9-42ca-967e-45231de292be",
5
+ "prevIds": ["d4d870f7-f371-4bdc-a5b3-cb66902a9a10"],
6
+ "ddl": [
7
+ {
8
+ "name": "ai",
9
+ "entityType": "schemas"
10
+ },
11
+ {
12
+ "name": "attachments",
13
+ "entityType": "tables",
14
+ "schema": "ai"
15
+ },
16
+ {
17
+ "name": "llm_requests",
18
+ "entityType": "tables",
19
+ "schema": "ai"
20
+ },
21
+ {
22
+ "name": "messages",
23
+ "entityType": "tables",
24
+ "schema": "ai"
25
+ },
26
+ {
27
+ "name": "sync_outbox",
28
+ "entityType": "tables",
29
+ "schema": "ai"
30
+ },
31
+ {
32
+ "name": "threads",
33
+ "entityType": "tables",
34
+ "schema": "ai"
35
+ },
36
+ {
37
+ "type": "UNIQUEIDENTIFIER",
38
+ "notNull": true,
39
+ "generated": null,
40
+ "identity": null,
41
+ "name": "id",
42
+ "schema": "ai",
43
+ "entityType": "columns",
44
+ "table": "attachments"
45
+ },
46
+ {
47
+ "type": "UNIQUEIDENTIFIER",
48
+ "notNull": true,
49
+ "generated": null,
50
+ "identity": null,
51
+ "name": "thread_id",
52
+ "schema": "ai",
53
+ "entityType": "columns",
54
+ "table": "attachments"
55
+ },
56
+ {
57
+ "type": "nvarchar(255)",
58
+ "notNull": true,
59
+ "generated": null,
60
+ "identity": null,
61
+ "name": "user_id",
62
+ "schema": "ai",
63
+ "entityType": "columns",
64
+ "table": "attachments"
65
+ },
66
+ {
67
+ "type": "nvarchar(128)",
68
+ "notNull": false,
69
+ "generated": null,
70
+ "identity": null,
71
+ "name": "message_id",
72
+ "schema": "ai",
73
+ "entityType": "columns",
74
+ "table": "attachments"
75
+ },
76
+ {
77
+ "type": "nvarchar(2048)",
78
+ "notNull": true,
79
+ "generated": null,
80
+ "identity": null,
81
+ "name": "filename",
82
+ "schema": "ai",
83
+ "entityType": "columns",
84
+ "table": "attachments"
85
+ },
86
+ {
87
+ "type": "nvarchar(256)",
88
+ "notNull": true,
89
+ "generated": null,
90
+ "identity": null,
91
+ "name": "content_type",
92
+ "schema": "ai",
93
+ "entityType": "columns",
94
+ "table": "attachments"
95
+ },
96
+ {
97
+ "type": "int",
98
+ "notNull": true,
99
+ "generated": null,
100
+ "identity": null,
101
+ "name": "size_bytes",
102
+ "schema": "ai",
103
+ "entityType": "columns",
104
+ "table": "attachments"
105
+ },
106
+ {
107
+ "type": "nvarchar(512)",
108
+ "notNull": true,
109
+ "generated": null,
110
+ "identity": null,
111
+ "name": "storage_key",
112
+ "schema": "ai",
113
+ "entityType": "columns",
114
+ "table": "attachments"
115
+ },
116
+ {
117
+ "type": "nvarchar(16)",
118
+ "notNull": true,
119
+ "generated": null,
120
+ "identity": null,
121
+ "name": "status",
122
+ "schema": "ai",
123
+ "entityType": "columns",
124
+ "table": "attachments"
125
+ },
126
+ {
127
+ "type": "nvarchar(max)",
128
+ "notNull": false,
129
+ "generated": null,
130
+ "identity": null,
131
+ "name": "description",
132
+ "schema": "ai",
133
+ "entityType": "columns",
134
+ "table": "attachments"
135
+ },
136
+ {
137
+ "type": "datetime2",
138
+ "notNull": true,
139
+ "generated": null,
140
+ "identity": null,
141
+ "name": "created_at",
142
+ "schema": "ai",
143
+ "entityType": "columns",
144
+ "table": "attachments"
145
+ },
146
+ {
147
+ "type": "datetime2",
148
+ "notNull": true,
149
+ "generated": null,
150
+ "identity": null,
151
+ "name": "updated_at",
152
+ "schema": "ai",
153
+ "entityType": "columns",
154
+ "table": "attachments"
155
+ },
156
+ {
157
+ "type": "UNIQUEIDENTIFIER",
158
+ "notNull": true,
159
+ "generated": null,
160
+ "identity": null,
161
+ "name": "id",
162
+ "schema": "ai",
163
+ "entityType": "columns",
164
+ "table": "llm_requests"
165
+ },
166
+ {
167
+ "type": "nvarchar(128)",
168
+ "notNull": true,
169
+ "generated": null,
170
+ "identity": null,
171
+ "name": "message_id",
172
+ "schema": "ai",
173
+ "entityType": "columns",
174
+ "table": "llm_requests"
175
+ },
176
+ {
177
+ "type": "int",
178
+ "notNull": true,
179
+ "generated": null,
180
+ "identity": null,
181
+ "name": "step_number",
182
+ "schema": "ai",
183
+ "entityType": "columns",
184
+ "table": "llm_requests"
185
+ },
186
+ {
187
+ "type": "nvarchar(max)",
188
+ "notNull": true,
189
+ "generated": null,
190
+ "identity": null,
191
+ "name": "prompt",
192
+ "schema": "ai",
193
+ "entityType": "columns",
194
+ "table": "llm_requests"
195
+ },
196
+ {
197
+ "type": "nvarchar(max)",
198
+ "notNull": false,
199
+ "generated": null,
200
+ "identity": null,
201
+ "name": "output",
202
+ "schema": "ai",
203
+ "entityType": "columns",
204
+ "table": "llm_requests"
205
+ },
206
+ {
207
+ "type": "nvarchar(max)",
208
+ "notNull": false,
209
+ "generated": null,
210
+ "identity": null,
211
+ "name": "token_usage",
212
+ "schema": "ai",
213
+ "entityType": "columns",
214
+ "table": "llm_requests"
215
+ },
216
+ {
217
+ "type": "nvarchar(128)",
218
+ "notNull": true,
219
+ "generated": null,
220
+ "identity": null,
221
+ "name": "id",
222
+ "schema": "ai",
223
+ "entityType": "columns",
224
+ "table": "messages"
225
+ },
226
+ {
227
+ "type": "UNIQUEIDENTIFIER",
228
+ "notNull": true,
229
+ "generated": null,
230
+ "identity": null,
231
+ "name": "thread_id",
232
+ "schema": "ai",
233
+ "entityType": "columns",
234
+ "table": "messages"
235
+ },
236
+ {
237
+ "type": "nvarchar(max)",
238
+ "notNull": false,
239
+ "generated": null,
240
+ "identity": null,
241
+ "name": "text",
242
+ "schema": "ai",
243
+ "entityType": "columns",
244
+ "table": "messages"
245
+ },
246
+ {
247
+ "type": "nvarchar(max)",
248
+ "notNull": true,
249
+ "generated": null,
250
+ "identity": null,
251
+ "name": "content",
252
+ "schema": "ai",
253
+ "entityType": "columns",
254
+ "table": "messages"
255
+ },
256
+ {
257
+ "type": "int",
258
+ "notNull": true,
259
+ "generated": null,
260
+ "identity": null,
261
+ "name": "ordinal",
262
+ "schema": "ai",
263
+ "entityType": "columns",
264
+ "table": "messages"
265
+ },
266
+ {
267
+ "type": "nvarchar(16)",
268
+ "notNull": true,
269
+ "generated": null,
270
+ "identity": null,
271
+ "name": "role",
272
+ "schema": "ai",
273
+ "entityType": "columns",
274
+ "table": "messages"
275
+ },
276
+ {
277
+ "type": "datetime2",
278
+ "notNull": true,
279
+ "generated": null,
280
+ "identity": null,
281
+ "name": "created_at",
282
+ "schema": "ai",
283
+ "entityType": "columns",
284
+ "table": "messages"
285
+ },
286
+ {
287
+ "type": "datetime2",
288
+ "notNull": true,
289
+ "generated": null,
290
+ "identity": null,
291
+ "name": "updated_at",
292
+ "schema": "ai",
293
+ "entityType": "columns",
294
+ "table": "messages"
295
+ },
296
+ {
297
+ "type": "bigint",
298
+ "notNull": true,
299
+ "generated": null,
300
+ "identity": {
301
+ "seed": 1,
302
+ "increment": 1
303
+ },
304
+ "name": "id",
305
+ "schema": "ai",
306
+ "entityType": "columns",
307
+ "table": "sync_outbox"
308
+ },
309
+ {
310
+ "type": "nvarchar(max)",
311
+ "notNull": true,
312
+ "generated": null,
313
+ "identity": null,
314
+ "name": "event",
315
+ "schema": "ai",
316
+ "entityType": "columns",
317
+ "table": "sync_outbox"
318
+ },
319
+ {
320
+ "type": "datetime2",
321
+ "notNull": true,
322
+ "generated": null,
323
+ "identity": null,
324
+ "name": "created_at",
325
+ "schema": "ai",
326
+ "entityType": "columns",
327
+ "table": "sync_outbox"
328
+ },
329
+ {
330
+ "type": "UNIQUEIDENTIFIER",
331
+ "notNull": true,
332
+ "generated": null,
333
+ "identity": null,
334
+ "name": "id",
335
+ "schema": "ai",
336
+ "entityType": "columns",
337
+ "table": "threads"
338
+ },
339
+ {
340
+ "type": "nvarchar(255)",
341
+ "notNull": true,
342
+ "generated": null,
343
+ "identity": null,
344
+ "name": "user_id",
345
+ "schema": "ai",
346
+ "entityType": "columns",
347
+ "table": "threads"
348
+ },
349
+ {
350
+ "type": "nvarchar(128)",
351
+ "notNull": true,
352
+ "generated": null,
353
+ "identity": null,
354
+ "name": "agent_id",
355
+ "schema": "ai",
356
+ "entityType": "columns",
357
+ "table": "threads"
358
+ },
359
+ {
360
+ "type": "nvarchar(256)",
361
+ "notNull": false,
362
+ "generated": null,
363
+ "identity": null,
364
+ "name": "title",
365
+ "schema": "ai",
366
+ "entityType": "columns",
367
+ "table": "threads"
368
+ },
369
+ {
370
+ "type": "bit",
371
+ "notNull": true,
372
+ "generated": null,
373
+ "identity": null,
374
+ "name": "is_test",
375
+ "schema": "ai",
376
+ "entityType": "columns",
377
+ "table": "threads"
378
+ },
379
+ {
380
+ "type": "nvarchar(max)",
381
+ "notNull": false,
382
+ "generated": null,
383
+ "identity": null,
384
+ "name": "session",
385
+ "schema": "ai",
386
+ "entityType": "columns",
387
+ "table": "threads"
388
+ },
389
+ {
390
+ "type": "nvarchar(max)",
391
+ "notNull": false,
392
+ "generated": null,
393
+ "identity": null,
394
+ "name": "context_meta",
395
+ "schema": "ai",
396
+ "entityType": "columns",
397
+ "table": "threads"
398
+ },
399
+ {
400
+ "type": "datetime2",
401
+ "notNull": true,
402
+ "generated": null,
403
+ "identity": null,
404
+ "name": "created_at",
405
+ "schema": "ai",
406
+ "entityType": "columns",
407
+ "table": "threads"
408
+ },
409
+ {
410
+ "type": "datetime2",
411
+ "notNull": true,
412
+ "generated": null,
413
+ "identity": null,
414
+ "name": "updated_at",
415
+ "schema": "ai",
416
+ "entityType": "columns",
417
+ "table": "threads"
418
+ },
419
+ {
420
+ "columns": [
421
+ {
422
+ "value": "thread_id",
423
+ "isExpression": false
424
+ }
425
+ ],
426
+ "isUnique": false,
427
+ "where": null,
428
+ "name": "attachments_thread_id_index",
429
+ "entityType": "indexes",
430
+ "table": "attachments",
431
+ "schema": "ai"
432
+ },
433
+ {
434
+ "columns": ["thread_id"],
435
+ "nameExplicit": false,
436
+ "schemaTo": "ai",
437
+ "tableTo": "threads",
438
+ "columnsTo": ["id"],
439
+ "onUpdate": "NO ACTION",
440
+ "onDelete": "CASCADE",
441
+ "name": "attachments_thread_id_threads_id_fk",
442
+ "entityType": "fks",
443
+ "table": "attachments",
444
+ "schema": "ai"
445
+ },
446
+ {
447
+ "columns": ["message_id"],
448
+ "nameExplicit": false,
449
+ "schemaTo": "ai",
450
+ "tableTo": "messages",
451
+ "columnsTo": ["id"],
452
+ "onUpdate": "NO ACTION",
453
+ "onDelete": "NO ACTION",
454
+ "name": "attachments_message_id_messages_id_fk",
455
+ "entityType": "fks",
456
+ "table": "attachments",
457
+ "schema": "ai"
458
+ },
459
+ {
460
+ "columns": ["message_id"],
461
+ "nameExplicit": false,
462
+ "schemaTo": "ai",
463
+ "tableTo": "messages",
464
+ "columnsTo": ["id"],
465
+ "onUpdate": "NO ACTION",
466
+ "onDelete": "CASCADE",
467
+ "name": "llm_requests_message_id_messages_id_fk",
468
+ "entityType": "fks",
469
+ "table": "llm_requests",
470
+ "schema": "ai"
471
+ },
472
+ {
473
+ "columns": ["thread_id"],
474
+ "nameExplicit": false,
475
+ "schemaTo": "ai",
476
+ "tableTo": "threads",
477
+ "columnsTo": ["id"],
478
+ "onUpdate": "NO ACTION",
479
+ "onDelete": "CASCADE",
480
+ "name": "messages_thread_id_threads_id_fk",
481
+ "entityType": "fks",
482
+ "table": "messages",
483
+ "schema": "ai"
484
+ },
485
+ {
486
+ "nameExplicit": false,
487
+ "columns": ["id"],
488
+ "name": "attachments_pkey",
489
+ "table": "attachments",
490
+ "schema": "ai",
491
+ "entityType": "pks"
492
+ },
493
+ {
494
+ "nameExplicit": false,
495
+ "columns": ["id"],
496
+ "name": "llm_requests_pkey",
497
+ "table": "llm_requests",
498
+ "schema": "ai",
499
+ "entityType": "pks"
500
+ },
501
+ {
502
+ "nameExplicit": false,
503
+ "columns": ["id"],
504
+ "name": "messages_pkey",
505
+ "table": "messages",
506
+ "schema": "ai",
507
+ "entityType": "pks"
508
+ },
509
+ {
510
+ "nameExplicit": false,
511
+ "columns": ["id"],
512
+ "name": "sync_outbox_pkey",
513
+ "table": "sync_outbox",
514
+ "schema": "ai",
515
+ "entityType": "pks"
516
+ },
517
+ {
518
+ "nameExplicit": false,
519
+ "columns": ["id"],
520
+ "name": "threads_pkey",
521
+ "table": "threads",
522
+ "schema": "ai",
523
+ "entityType": "pks"
524
+ },
525
+ {
526
+ "column": "id",
527
+ "nameExplicit": false,
528
+ "default": "(NEWID())",
529
+ "name": "attachments_id_default",
530
+ "entityType": "defaults",
531
+ "schema": "ai",
532
+ "table": "attachments"
533
+ },
534
+ {
535
+ "column": "id",
536
+ "nameExplicit": false,
537
+ "default": "(NEWID())",
538
+ "name": "llm_requests_id_default",
539
+ "entityType": "defaults",
540
+ "schema": "ai",
541
+ "table": "llm_requests"
542
+ },
543
+ {
544
+ "column": "ordinal",
545
+ "nameExplicit": false,
546
+ "default": "((0))",
547
+ "name": "messages_ordinal_default",
548
+ "entityType": "defaults",
549
+ "schema": "ai",
550
+ "table": "messages"
551
+ },
552
+ {
553
+ "column": "id",
554
+ "nameExplicit": false,
555
+ "default": "(NEWID())",
556
+ "name": "threads_id_default",
557
+ "entityType": "defaults",
558
+ "schema": "ai",
559
+ "table": "threads"
560
+ },
561
+ {
562
+ "column": "agent_id",
563
+ "nameExplicit": false,
564
+ "default": "('default')",
565
+ "name": "threads_agent_id_default",
566
+ "entityType": "defaults",
567
+ "schema": "ai",
568
+ "table": "threads"
569
+ },
570
+ {
571
+ "column": "is_test",
572
+ "nameExplicit": false,
573
+ "default": "((0))",
574
+ "name": "threads_is_test_default",
575
+ "entityType": "defaults",
576
+ "schema": "ai",
577
+ "table": "threads"
578
+ }
579
+ ],
580
+ "renames": []
581
+ }
@@ -0,0 +1,5 @@
1
+ CREATE TABLE [ai].[sync_meta] (
2
+ [id] int,
3
+ [epoch] nvarchar(36) NOT NULL,
4
+ CONSTRAINT [sync_meta_pkey] PRIMARY KEY([id])
5
+ );