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