@checkstack/ai-backend 0.1.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 (106) hide show
  1. package/CHANGELOG.md +97 -0
  2. package/drizzle/0000_productive_jackpot.sql +26 -0
  3. package/drizzle/0001_puzzling_purple_man.sql +26 -0
  4. package/drizzle/0002_sparkling_paper_doll.sql +15 -0
  5. package/drizzle/0003_married_senator_kelly.sql +1 -0
  6. package/drizzle/0004_crazy_miek.sql +2 -0
  7. package/drizzle/0005_tearful_randall_flagg.sql +1 -0
  8. package/drizzle/meta/0000_snapshot.json +232 -0
  9. package/drizzle/meta/0001_snapshot.json +434 -0
  10. package/drizzle/meta/0002_snapshot.json +551 -0
  11. package/drizzle/meta/0003_snapshot.json +557 -0
  12. package/drizzle/meta/0004_snapshot.json +573 -0
  13. package/drizzle/meta/0005_snapshot.json +574 -0
  14. package/drizzle/meta/_journal.json +48 -0
  15. package/drizzle.config.ts +7 -0
  16. package/package.json +42 -0
  17. package/src/agent-runner.test.ts +262 -0
  18. package/src/agent-runner.ts +262 -0
  19. package/src/chat/agent-loop.test.ts +119 -0
  20. package/src/chat/agent-loop.ts +73 -0
  21. package/src/chat/auto-apply.test.ts +237 -0
  22. package/src/chat/chat-handler.ts +111 -0
  23. package/src/chat/chat-service.streamturn.test.ts +417 -0
  24. package/src/chat/chat-service.test.ts +250 -0
  25. package/src/chat/chat-service.ts +923 -0
  26. package/src/chat/classifier-service.ts +64 -0
  27. package/src/chat/classifier.logic.test.ts +92 -0
  28. package/src/chat/classifier.logic.ts +71 -0
  29. package/src/chat/conversation-store.it.test.ts +203 -0
  30. package/src/chat/conversation-store.test.ts +248 -0
  31. package/src/chat/conversation-store.ts +237 -0
  32. package/src/chat/decision.logic.test.ts +45 -0
  33. package/src/chat/decision.logic.ts +54 -0
  34. package/src/chat/llm-provider.test.ts +63 -0
  35. package/src/chat/llm-provider.ts +67 -0
  36. package/src/chat/model-error.logic.test.ts +60 -0
  37. package/src/chat/model-error.logic.ts +65 -0
  38. package/src/chat/normalize-messages.logic.test.ts +101 -0
  39. package/src/chat/normalize-messages.logic.ts +65 -0
  40. package/src/chat/permission-mode.logic.test.ts +70 -0
  41. package/src/chat/permission-mode.logic.ts +45 -0
  42. package/src/chat/read-invoker.ts +72 -0
  43. package/src/chat/replay.test.ts +174 -0
  44. package/src/chat/scrub-content.test.ts +183 -0
  45. package/src/chat/scrub-content.ts +154 -0
  46. package/src/chat/sdk-tools.test.ts +168 -0
  47. package/src/chat/sdk-tools.ts +181 -0
  48. package/src/chat/title-service.test.ts +146 -0
  49. package/src/chat/title-service.ts +111 -0
  50. package/src/chat/title.logic.test.ts +98 -0
  51. package/src/chat/title.logic.ts +102 -0
  52. package/src/extension-points.ts +41 -0
  53. package/src/generated/docs-index.ts +3020 -0
  54. package/src/hardening/handler-authz.test.ts +282 -0
  55. package/src/hardening/no-secret-leak.test.ts +303 -0
  56. package/src/hooks.ts +33 -0
  57. package/src/index.ts +542 -0
  58. package/src/mcp/connection-registry.test.ts +25 -0
  59. package/src/mcp/connection-registry.ts +54 -0
  60. package/src/mcp/mcp-conformance.it.test.ts +128 -0
  61. package/src/mcp/server.test.ts +285 -0
  62. package/src/mcp/server.ts +300 -0
  63. package/src/mcp/tool-invoker.ts +65 -0
  64. package/src/openai-provider.test.ts +64 -0
  65. package/src/openai-provider.ts +146 -0
  66. package/src/projection.test.ts +97 -0
  67. package/src/projection.ts +132 -0
  68. package/src/propose-apply/args-hash.test.ts +26 -0
  69. package/src/propose-apply/args-hash.ts +30 -0
  70. package/src/propose-apply/service.test.ts +423 -0
  71. package/src/propose-apply/service.ts +419 -0
  72. package/src/propose-apply/store.test.ts +136 -0
  73. package/src/propose-apply/store.ts +224 -0
  74. package/src/propose-apply/token.test.ts +52 -0
  75. package/src/propose-apply/token.ts +71 -0
  76. package/src/rate-limit/spend-ledger.it.test.ts +224 -0
  77. package/src/rate-limit/spend-ledger.test.ts +176 -0
  78. package/src/rate-limit/spend-ledger.ts +162 -0
  79. package/src/rate-limit/tool-budget.it.test.ts +173 -0
  80. package/src/rate-limit/tool-budget.test.ts +58 -0
  81. package/src/rate-limit/tool-budget.ts +107 -0
  82. package/src/registry-wiring.test.ts +131 -0
  83. package/src/registry-wiring.ts +68 -0
  84. package/src/resolver.test.ts +156 -0
  85. package/src/resolver.ts +78 -0
  86. package/src/router.test.ts +78 -0
  87. package/src/router.ts +345 -0
  88. package/src/schema.ts +284 -0
  89. package/src/serializer.test.ts +88 -0
  90. package/src/serializer.ts +42 -0
  91. package/src/tool-registry.ts +58 -0
  92. package/src/tools/composite-tools.ts +24 -0
  93. package/src/tools/docs-tools.test.ts +150 -0
  94. package/src/tools/docs-tools.ts +115 -0
  95. package/src/tools/probe-url.test.ts +51 -0
  96. package/src/tools/probe-url.ts +146 -0
  97. package/src/tools/rank-docs.test.ts +153 -0
  98. package/src/tools/rank-docs.ts +209 -0
  99. package/src/tools/script-context-extract.test.ts +93 -0
  100. package/src/tools/script-context-extract.ts +283 -0
  101. package/src/tools/ssrf-guard.test.ts +69 -0
  102. package/src/tools/ssrf-guard.ts +108 -0
  103. package/src/tools/tool-set.e2e.test.ts +64 -0
  104. package/src/user-rpc-client.test.ts +45 -0
  105. package/src/user-rpc-client.ts +60 -0
  106. package/tsconfig.json +26 -0
@@ -0,0 +1,573 @@
1
+ {
2
+ "id": "23dfed87-129e-48cc-b01a-43d2a3ab34b8",
3
+ "prevId": "32d63be5-7ab7-4d19-8527-212fbeb69055",
4
+ "version": "7",
5
+ "dialect": "postgresql",
6
+ "tables": {
7
+ "public.ai_conversations": {
8
+ "name": "ai_conversations",
9
+ "schema": "",
10
+ "columns": {
11
+ "id": {
12
+ "name": "id",
13
+ "type": "text",
14
+ "primaryKey": true,
15
+ "notNull": true
16
+ },
17
+ "user_id": {
18
+ "name": "user_id",
19
+ "type": "text",
20
+ "primaryKey": false,
21
+ "notNull": true
22
+ },
23
+ "title": {
24
+ "name": "title",
25
+ "type": "text",
26
+ "primaryKey": false,
27
+ "notNull": false
28
+ },
29
+ "integration_id": {
30
+ "name": "integration_id",
31
+ "type": "text",
32
+ "primaryKey": false,
33
+ "notNull": false
34
+ },
35
+ "model": {
36
+ "name": "model",
37
+ "type": "text",
38
+ "primaryKey": false,
39
+ "notNull": false
40
+ },
41
+ "permission_mode": {
42
+ "name": "permission_mode",
43
+ "type": "ai_permission_mode",
44
+ "typeSchema": "public",
45
+ "primaryKey": false,
46
+ "notNull": true,
47
+ "default": "'approve'"
48
+ },
49
+ "created_at": {
50
+ "name": "created_at",
51
+ "type": "timestamp",
52
+ "primaryKey": false,
53
+ "notNull": true,
54
+ "default": "now()"
55
+ },
56
+ "updated_at": {
57
+ "name": "updated_at",
58
+ "type": "timestamp",
59
+ "primaryKey": false,
60
+ "notNull": true,
61
+ "default": "now()"
62
+ },
63
+ "archived_at": {
64
+ "name": "archived_at",
65
+ "type": "timestamp",
66
+ "primaryKey": false,
67
+ "notNull": false
68
+ }
69
+ },
70
+ "indexes": {
71
+ "ai_conversations_user_idx": {
72
+ "name": "ai_conversations_user_idx",
73
+ "columns": [
74
+ {
75
+ "expression": "user_id",
76
+ "isExpression": false,
77
+ "asc": true,
78
+ "nulls": "last"
79
+ },
80
+ {
81
+ "expression": "updated_at",
82
+ "isExpression": false,
83
+ "asc": true,
84
+ "nulls": "last"
85
+ }
86
+ ],
87
+ "isUnique": false,
88
+ "concurrently": false,
89
+ "method": "btree",
90
+ "with": {}
91
+ }
92
+ },
93
+ "foreignKeys": {},
94
+ "compositePrimaryKeys": {},
95
+ "uniqueConstraints": {},
96
+ "policies": {},
97
+ "checkConstraints": {},
98
+ "isRLSEnabled": false
99
+ },
100
+ "public.ai_messages": {
101
+ "name": "ai_messages",
102
+ "schema": "",
103
+ "columns": {
104
+ "id": {
105
+ "name": "id",
106
+ "type": "text",
107
+ "primaryKey": true,
108
+ "notNull": true
109
+ },
110
+ "conversation_id": {
111
+ "name": "conversation_id",
112
+ "type": "text",
113
+ "primaryKey": false,
114
+ "notNull": true
115
+ },
116
+ "role": {
117
+ "name": "role",
118
+ "type": "ai_message_role",
119
+ "typeSchema": "public",
120
+ "primaryKey": false,
121
+ "notNull": true
122
+ },
123
+ "content": {
124
+ "name": "content",
125
+ "type": "jsonb",
126
+ "primaryKey": false,
127
+ "notNull": true
128
+ },
129
+ "tool_calls": {
130
+ "name": "tool_calls",
131
+ "type": "jsonb",
132
+ "primaryKey": false,
133
+ "notNull": false
134
+ },
135
+ "model_messages": {
136
+ "name": "model_messages",
137
+ "type": "jsonb",
138
+ "primaryKey": false,
139
+ "notNull": false
140
+ },
141
+ "created_at": {
142
+ "name": "created_at",
143
+ "type": "timestamp",
144
+ "primaryKey": false,
145
+ "notNull": true,
146
+ "default": "now()"
147
+ }
148
+ },
149
+ "indexes": {
150
+ "ai_messages_conversation_idx": {
151
+ "name": "ai_messages_conversation_idx",
152
+ "columns": [
153
+ {
154
+ "expression": "conversation_id",
155
+ "isExpression": false,
156
+ "asc": true,
157
+ "nulls": "last"
158
+ },
159
+ {
160
+ "expression": "created_at",
161
+ "isExpression": false,
162
+ "asc": true,
163
+ "nulls": "last"
164
+ }
165
+ ],
166
+ "isUnique": false,
167
+ "concurrently": false,
168
+ "method": "btree",
169
+ "with": {}
170
+ }
171
+ },
172
+ "foreignKeys": {
173
+ "ai_messages_conversation_id_ai_conversations_id_fk": {
174
+ "name": "ai_messages_conversation_id_ai_conversations_id_fk",
175
+ "tableFrom": "ai_messages",
176
+ "tableTo": "ai_conversations",
177
+ "columnsFrom": [
178
+ "conversation_id"
179
+ ],
180
+ "columnsTo": [
181
+ "id"
182
+ ],
183
+ "onDelete": "cascade",
184
+ "onUpdate": "no action"
185
+ }
186
+ },
187
+ "compositePrimaryKeys": {},
188
+ "uniqueConstraints": {},
189
+ "policies": {},
190
+ "checkConstraints": {},
191
+ "isRLSEnabled": false
192
+ },
193
+ "public.ai_spend": {
194
+ "name": "ai_spend",
195
+ "schema": "",
196
+ "columns": {
197
+ "id": {
198
+ "name": "id",
199
+ "type": "text",
200
+ "primaryKey": true,
201
+ "notNull": true
202
+ },
203
+ "integration_id": {
204
+ "name": "integration_id",
205
+ "type": "text",
206
+ "primaryKey": false,
207
+ "notNull": true
208
+ },
209
+ "principal_kind": {
210
+ "name": "principal_kind",
211
+ "type": "text",
212
+ "primaryKey": false,
213
+ "notNull": true
214
+ },
215
+ "principal_id": {
216
+ "name": "principal_id",
217
+ "type": "text",
218
+ "primaryKey": false,
219
+ "notNull": true
220
+ },
221
+ "conversation_id": {
222
+ "name": "conversation_id",
223
+ "type": "text",
224
+ "primaryKey": false,
225
+ "notNull": false
226
+ },
227
+ "model": {
228
+ "name": "model",
229
+ "type": "text",
230
+ "primaryKey": false,
231
+ "notNull": false
232
+ },
233
+ "input_tokens": {
234
+ "name": "input_tokens",
235
+ "type": "integer",
236
+ "primaryKey": false,
237
+ "notNull": true,
238
+ "default": 0
239
+ },
240
+ "output_tokens": {
241
+ "name": "output_tokens",
242
+ "type": "integer",
243
+ "primaryKey": false,
244
+ "notNull": true,
245
+ "default": 0
246
+ },
247
+ "total_tokens": {
248
+ "name": "total_tokens",
249
+ "type": "integer",
250
+ "primaryKey": false,
251
+ "notNull": true,
252
+ "default": 0
253
+ },
254
+ "created_at": {
255
+ "name": "created_at",
256
+ "type": "timestamp",
257
+ "primaryKey": false,
258
+ "notNull": true,
259
+ "default": "now()"
260
+ }
261
+ },
262
+ "indexes": {
263
+ "ai_spend_integration_principal_created_idx": {
264
+ "name": "ai_spend_integration_principal_created_idx",
265
+ "columns": [
266
+ {
267
+ "expression": "integration_id",
268
+ "isExpression": false,
269
+ "asc": true,
270
+ "nulls": "last"
271
+ },
272
+ {
273
+ "expression": "principal_kind",
274
+ "isExpression": false,
275
+ "asc": true,
276
+ "nulls": "last"
277
+ },
278
+ {
279
+ "expression": "principal_id",
280
+ "isExpression": false,
281
+ "asc": true,
282
+ "nulls": "last"
283
+ },
284
+ {
285
+ "expression": "created_at",
286
+ "isExpression": false,
287
+ "asc": true,
288
+ "nulls": "last"
289
+ }
290
+ ],
291
+ "isUnique": false,
292
+ "concurrently": false,
293
+ "method": "btree",
294
+ "with": {}
295
+ }
296
+ },
297
+ "foreignKeys": {},
298
+ "compositePrimaryKeys": {},
299
+ "uniqueConstraints": {},
300
+ "policies": {},
301
+ "checkConstraints": {},
302
+ "isRLSEnabled": false
303
+ },
304
+ "public.ai_tool_calls": {
305
+ "name": "ai_tool_calls",
306
+ "schema": "",
307
+ "columns": {
308
+ "id": {
309
+ "name": "id",
310
+ "type": "text",
311
+ "primaryKey": true,
312
+ "notNull": true
313
+ },
314
+ "principal_kind": {
315
+ "name": "principal_kind",
316
+ "type": "text",
317
+ "primaryKey": false,
318
+ "notNull": true
319
+ },
320
+ "principal_id": {
321
+ "name": "principal_id",
322
+ "type": "text",
323
+ "primaryKey": false,
324
+ "notNull": true
325
+ },
326
+ "transport": {
327
+ "name": "transport",
328
+ "type": "ai_transport",
329
+ "typeSchema": "public",
330
+ "primaryKey": false,
331
+ "notNull": true
332
+ },
333
+ "conversation_id": {
334
+ "name": "conversation_id",
335
+ "type": "text",
336
+ "primaryKey": false,
337
+ "notNull": false
338
+ },
339
+ "tool_name": {
340
+ "name": "tool_name",
341
+ "type": "text",
342
+ "primaryKey": false,
343
+ "notNull": true
344
+ },
345
+ "effect": {
346
+ "name": "effect",
347
+ "type": "ai_tool_effect",
348
+ "typeSchema": "public",
349
+ "primaryKey": false,
350
+ "notNull": true
351
+ },
352
+ "args_hash": {
353
+ "name": "args_hash",
354
+ "type": "text",
355
+ "primaryKey": false,
356
+ "notNull": true
357
+ },
358
+ "status": {
359
+ "name": "status",
360
+ "type": "ai_tool_call_status",
361
+ "typeSchema": "public",
362
+ "primaryKey": false,
363
+ "notNull": true
364
+ },
365
+ "proposal_nonce": {
366
+ "name": "proposal_nonce",
367
+ "type": "text",
368
+ "primaryKey": false,
369
+ "notNull": false
370
+ },
371
+ "proposal_expires_at": {
372
+ "name": "proposal_expires_at",
373
+ "type": "timestamp",
374
+ "primaryKey": false,
375
+ "notNull": false
376
+ },
377
+ "applied_by_kind": {
378
+ "name": "applied_by_kind",
379
+ "type": "text",
380
+ "primaryKey": false,
381
+ "notNull": false
382
+ },
383
+ "applied_by_id": {
384
+ "name": "applied_by_id",
385
+ "type": "text",
386
+ "primaryKey": false,
387
+ "notNull": false
388
+ },
389
+ "result_snapshot": {
390
+ "name": "result_snapshot",
391
+ "type": "jsonb",
392
+ "primaryKey": false,
393
+ "notNull": false
394
+ },
395
+ "proposed_payload": {
396
+ "name": "proposed_payload",
397
+ "type": "jsonb",
398
+ "primaryKey": false,
399
+ "notNull": false
400
+ },
401
+ "error": {
402
+ "name": "error",
403
+ "type": "text",
404
+ "primaryKey": false,
405
+ "notNull": false
406
+ },
407
+ "proposed_at": {
408
+ "name": "proposed_at",
409
+ "type": "timestamp",
410
+ "primaryKey": false,
411
+ "notNull": false
412
+ },
413
+ "applied_at": {
414
+ "name": "applied_at",
415
+ "type": "timestamp",
416
+ "primaryKey": false,
417
+ "notNull": false
418
+ },
419
+ "created_at": {
420
+ "name": "created_at",
421
+ "type": "timestamp",
422
+ "primaryKey": false,
423
+ "notNull": true,
424
+ "default": "now()"
425
+ }
426
+ },
427
+ "indexes": {
428
+ "ai_tool_calls_principal_created_idx": {
429
+ "name": "ai_tool_calls_principal_created_idx",
430
+ "columns": [
431
+ {
432
+ "expression": "principal_kind",
433
+ "isExpression": false,
434
+ "asc": true,
435
+ "nulls": "last"
436
+ },
437
+ {
438
+ "expression": "principal_id",
439
+ "isExpression": false,
440
+ "asc": true,
441
+ "nulls": "last"
442
+ },
443
+ {
444
+ "expression": "created_at",
445
+ "isExpression": false,
446
+ "asc": true,
447
+ "nulls": "last"
448
+ }
449
+ ],
450
+ "isUnique": false,
451
+ "concurrently": false,
452
+ "method": "btree",
453
+ "with": {}
454
+ },
455
+ "ai_tool_calls_status_expires_idx": {
456
+ "name": "ai_tool_calls_status_expires_idx",
457
+ "columns": [
458
+ {
459
+ "expression": "status",
460
+ "isExpression": false,
461
+ "asc": true,
462
+ "nulls": "last"
463
+ },
464
+ {
465
+ "expression": "proposal_expires_at",
466
+ "isExpression": false,
467
+ "asc": true,
468
+ "nulls": "last"
469
+ }
470
+ ],
471
+ "isUnique": false,
472
+ "concurrently": false,
473
+ "method": "btree",
474
+ "with": {}
475
+ },
476
+ "ai_tool_calls_conversation_idx": {
477
+ "name": "ai_tool_calls_conversation_idx",
478
+ "columns": [
479
+ {
480
+ "expression": "conversation_id",
481
+ "isExpression": false,
482
+ "asc": true,
483
+ "nulls": "last"
484
+ }
485
+ ],
486
+ "isUnique": false,
487
+ "concurrently": false,
488
+ "method": "btree",
489
+ "with": {}
490
+ }
491
+ },
492
+ "foreignKeys": {
493
+ "ai_tool_calls_conversation_id_ai_conversations_id_fk": {
494
+ "name": "ai_tool_calls_conversation_id_ai_conversations_id_fk",
495
+ "tableFrom": "ai_tool_calls",
496
+ "tableTo": "ai_conversations",
497
+ "columnsFrom": [
498
+ "conversation_id"
499
+ ],
500
+ "columnsTo": [
501
+ "id"
502
+ ],
503
+ "onDelete": "set null",
504
+ "onUpdate": "no action"
505
+ }
506
+ },
507
+ "compositePrimaryKeys": {},
508
+ "uniqueConstraints": {},
509
+ "policies": {},
510
+ "checkConstraints": {},
511
+ "isRLSEnabled": false
512
+ }
513
+ },
514
+ "enums": {
515
+ "public.ai_message_role": {
516
+ "name": "ai_message_role",
517
+ "schema": "public",
518
+ "values": [
519
+ "system",
520
+ "user",
521
+ "assistant",
522
+ "tool"
523
+ ]
524
+ },
525
+ "public.ai_permission_mode": {
526
+ "name": "ai_permission_mode",
527
+ "schema": "public",
528
+ "values": [
529
+ "approve",
530
+ "auto"
531
+ ]
532
+ },
533
+ "public.ai_tool_call_status": {
534
+ "name": "ai_tool_call_status",
535
+ "schema": "public",
536
+ "values": [
537
+ "proposed",
538
+ "applied",
539
+ "executed",
540
+ "failed",
541
+ "expired",
542
+ "rejected"
543
+ ]
544
+ },
545
+ "public.ai_tool_effect": {
546
+ "name": "ai_tool_effect",
547
+ "schema": "public",
548
+ "values": [
549
+ "read",
550
+ "mutate",
551
+ "destructive"
552
+ ]
553
+ },
554
+ "public.ai_transport": {
555
+ "name": "ai_transport",
556
+ "schema": "public",
557
+ "values": [
558
+ "chat",
559
+ "mcp"
560
+ ]
561
+ }
562
+ },
563
+ "schemas": {},
564
+ "sequences": {},
565
+ "roles": {},
566
+ "policies": {},
567
+ "views": {},
568
+ "_meta": {
569
+ "columns": {},
570
+ "schemas": {},
571
+ "tables": {}
572
+ }
573
+ }