@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,557 @@
1
+ {
2
+ "id": "32d63be5-7ab7-4d19-8527-212fbeb69055",
3
+ "prevId": "cc22eeb6-1c15-4fa7-ab84-51f8ddcd9e75",
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
+ "created_at": {
42
+ "name": "created_at",
43
+ "type": "timestamp",
44
+ "primaryKey": false,
45
+ "notNull": true,
46
+ "default": "now()"
47
+ },
48
+ "updated_at": {
49
+ "name": "updated_at",
50
+ "type": "timestamp",
51
+ "primaryKey": false,
52
+ "notNull": true,
53
+ "default": "now()"
54
+ },
55
+ "archived_at": {
56
+ "name": "archived_at",
57
+ "type": "timestamp",
58
+ "primaryKey": false,
59
+ "notNull": false
60
+ }
61
+ },
62
+ "indexes": {
63
+ "ai_conversations_user_idx": {
64
+ "name": "ai_conversations_user_idx",
65
+ "columns": [
66
+ {
67
+ "expression": "user_id",
68
+ "isExpression": false,
69
+ "asc": true,
70
+ "nulls": "last"
71
+ },
72
+ {
73
+ "expression": "updated_at",
74
+ "isExpression": false,
75
+ "asc": true,
76
+ "nulls": "last"
77
+ }
78
+ ],
79
+ "isUnique": false,
80
+ "concurrently": false,
81
+ "method": "btree",
82
+ "with": {}
83
+ }
84
+ },
85
+ "foreignKeys": {},
86
+ "compositePrimaryKeys": {},
87
+ "uniqueConstraints": {},
88
+ "policies": {},
89
+ "checkConstraints": {},
90
+ "isRLSEnabled": false
91
+ },
92
+ "public.ai_messages": {
93
+ "name": "ai_messages",
94
+ "schema": "",
95
+ "columns": {
96
+ "id": {
97
+ "name": "id",
98
+ "type": "text",
99
+ "primaryKey": true,
100
+ "notNull": true
101
+ },
102
+ "conversation_id": {
103
+ "name": "conversation_id",
104
+ "type": "text",
105
+ "primaryKey": false,
106
+ "notNull": true
107
+ },
108
+ "role": {
109
+ "name": "role",
110
+ "type": "ai_message_role",
111
+ "typeSchema": "public",
112
+ "primaryKey": false,
113
+ "notNull": true
114
+ },
115
+ "content": {
116
+ "name": "content",
117
+ "type": "jsonb",
118
+ "primaryKey": false,
119
+ "notNull": true
120
+ },
121
+ "tool_calls": {
122
+ "name": "tool_calls",
123
+ "type": "jsonb",
124
+ "primaryKey": false,
125
+ "notNull": false
126
+ },
127
+ "model_messages": {
128
+ "name": "model_messages",
129
+ "type": "jsonb",
130
+ "primaryKey": false,
131
+ "notNull": false
132
+ },
133
+ "created_at": {
134
+ "name": "created_at",
135
+ "type": "timestamp",
136
+ "primaryKey": false,
137
+ "notNull": true,
138
+ "default": "now()"
139
+ }
140
+ },
141
+ "indexes": {
142
+ "ai_messages_conversation_idx": {
143
+ "name": "ai_messages_conversation_idx",
144
+ "columns": [
145
+ {
146
+ "expression": "conversation_id",
147
+ "isExpression": false,
148
+ "asc": true,
149
+ "nulls": "last"
150
+ },
151
+ {
152
+ "expression": "created_at",
153
+ "isExpression": false,
154
+ "asc": true,
155
+ "nulls": "last"
156
+ }
157
+ ],
158
+ "isUnique": false,
159
+ "concurrently": false,
160
+ "method": "btree",
161
+ "with": {}
162
+ }
163
+ },
164
+ "foreignKeys": {
165
+ "ai_messages_conversation_id_ai_conversations_id_fk": {
166
+ "name": "ai_messages_conversation_id_ai_conversations_id_fk",
167
+ "tableFrom": "ai_messages",
168
+ "tableTo": "ai_conversations",
169
+ "columnsFrom": [
170
+ "conversation_id"
171
+ ],
172
+ "columnsTo": [
173
+ "id"
174
+ ],
175
+ "onDelete": "cascade",
176
+ "onUpdate": "no action"
177
+ }
178
+ },
179
+ "compositePrimaryKeys": {},
180
+ "uniqueConstraints": {},
181
+ "policies": {},
182
+ "checkConstraints": {},
183
+ "isRLSEnabled": false
184
+ },
185
+ "public.ai_spend": {
186
+ "name": "ai_spend",
187
+ "schema": "",
188
+ "columns": {
189
+ "id": {
190
+ "name": "id",
191
+ "type": "text",
192
+ "primaryKey": true,
193
+ "notNull": true
194
+ },
195
+ "integration_id": {
196
+ "name": "integration_id",
197
+ "type": "text",
198
+ "primaryKey": false,
199
+ "notNull": true
200
+ },
201
+ "principal_kind": {
202
+ "name": "principal_kind",
203
+ "type": "text",
204
+ "primaryKey": false,
205
+ "notNull": true
206
+ },
207
+ "principal_id": {
208
+ "name": "principal_id",
209
+ "type": "text",
210
+ "primaryKey": false,
211
+ "notNull": true
212
+ },
213
+ "conversation_id": {
214
+ "name": "conversation_id",
215
+ "type": "text",
216
+ "primaryKey": false,
217
+ "notNull": false
218
+ },
219
+ "model": {
220
+ "name": "model",
221
+ "type": "text",
222
+ "primaryKey": false,
223
+ "notNull": false
224
+ },
225
+ "input_tokens": {
226
+ "name": "input_tokens",
227
+ "type": "integer",
228
+ "primaryKey": false,
229
+ "notNull": true,
230
+ "default": 0
231
+ },
232
+ "output_tokens": {
233
+ "name": "output_tokens",
234
+ "type": "integer",
235
+ "primaryKey": false,
236
+ "notNull": true,
237
+ "default": 0
238
+ },
239
+ "total_tokens": {
240
+ "name": "total_tokens",
241
+ "type": "integer",
242
+ "primaryKey": false,
243
+ "notNull": true,
244
+ "default": 0
245
+ },
246
+ "created_at": {
247
+ "name": "created_at",
248
+ "type": "timestamp",
249
+ "primaryKey": false,
250
+ "notNull": true,
251
+ "default": "now()"
252
+ }
253
+ },
254
+ "indexes": {
255
+ "ai_spend_integration_principal_created_idx": {
256
+ "name": "ai_spend_integration_principal_created_idx",
257
+ "columns": [
258
+ {
259
+ "expression": "integration_id",
260
+ "isExpression": false,
261
+ "asc": true,
262
+ "nulls": "last"
263
+ },
264
+ {
265
+ "expression": "principal_kind",
266
+ "isExpression": false,
267
+ "asc": true,
268
+ "nulls": "last"
269
+ },
270
+ {
271
+ "expression": "principal_id",
272
+ "isExpression": false,
273
+ "asc": true,
274
+ "nulls": "last"
275
+ },
276
+ {
277
+ "expression": "created_at",
278
+ "isExpression": false,
279
+ "asc": true,
280
+ "nulls": "last"
281
+ }
282
+ ],
283
+ "isUnique": false,
284
+ "concurrently": false,
285
+ "method": "btree",
286
+ "with": {}
287
+ }
288
+ },
289
+ "foreignKeys": {},
290
+ "compositePrimaryKeys": {},
291
+ "uniqueConstraints": {},
292
+ "policies": {},
293
+ "checkConstraints": {},
294
+ "isRLSEnabled": false
295
+ },
296
+ "public.ai_tool_calls": {
297
+ "name": "ai_tool_calls",
298
+ "schema": "",
299
+ "columns": {
300
+ "id": {
301
+ "name": "id",
302
+ "type": "text",
303
+ "primaryKey": true,
304
+ "notNull": true
305
+ },
306
+ "principal_kind": {
307
+ "name": "principal_kind",
308
+ "type": "text",
309
+ "primaryKey": false,
310
+ "notNull": true
311
+ },
312
+ "principal_id": {
313
+ "name": "principal_id",
314
+ "type": "text",
315
+ "primaryKey": false,
316
+ "notNull": true
317
+ },
318
+ "transport": {
319
+ "name": "transport",
320
+ "type": "ai_transport",
321
+ "typeSchema": "public",
322
+ "primaryKey": false,
323
+ "notNull": true
324
+ },
325
+ "conversation_id": {
326
+ "name": "conversation_id",
327
+ "type": "text",
328
+ "primaryKey": false,
329
+ "notNull": false
330
+ },
331
+ "tool_name": {
332
+ "name": "tool_name",
333
+ "type": "text",
334
+ "primaryKey": false,
335
+ "notNull": true
336
+ },
337
+ "effect": {
338
+ "name": "effect",
339
+ "type": "ai_tool_effect",
340
+ "typeSchema": "public",
341
+ "primaryKey": false,
342
+ "notNull": true
343
+ },
344
+ "args_hash": {
345
+ "name": "args_hash",
346
+ "type": "text",
347
+ "primaryKey": false,
348
+ "notNull": true
349
+ },
350
+ "status": {
351
+ "name": "status",
352
+ "type": "ai_tool_call_status",
353
+ "typeSchema": "public",
354
+ "primaryKey": false,
355
+ "notNull": true
356
+ },
357
+ "proposal_nonce": {
358
+ "name": "proposal_nonce",
359
+ "type": "text",
360
+ "primaryKey": false,
361
+ "notNull": false
362
+ },
363
+ "proposal_expires_at": {
364
+ "name": "proposal_expires_at",
365
+ "type": "timestamp",
366
+ "primaryKey": false,
367
+ "notNull": false
368
+ },
369
+ "applied_by_kind": {
370
+ "name": "applied_by_kind",
371
+ "type": "text",
372
+ "primaryKey": false,
373
+ "notNull": false
374
+ },
375
+ "applied_by_id": {
376
+ "name": "applied_by_id",
377
+ "type": "text",
378
+ "primaryKey": false,
379
+ "notNull": false
380
+ },
381
+ "result_snapshot": {
382
+ "name": "result_snapshot",
383
+ "type": "jsonb",
384
+ "primaryKey": false,
385
+ "notNull": false
386
+ },
387
+ "proposed_payload": {
388
+ "name": "proposed_payload",
389
+ "type": "jsonb",
390
+ "primaryKey": false,
391
+ "notNull": false
392
+ },
393
+ "error": {
394
+ "name": "error",
395
+ "type": "text",
396
+ "primaryKey": false,
397
+ "notNull": false
398
+ },
399
+ "proposed_at": {
400
+ "name": "proposed_at",
401
+ "type": "timestamp",
402
+ "primaryKey": false,
403
+ "notNull": false
404
+ },
405
+ "applied_at": {
406
+ "name": "applied_at",
407
+ "type": "timestamp",
408
+ "primaryKey": false,
409
+ "notNull": false
410
+ },
411
+ "created_at": {
412
+ "name": "created_at",
413
+ "type": "timestamp",
414
+ "primaryKey": false,
415
+ "notNull": true,
416
+ "default": "now()"
417
+ }
418
+ },
419
+ "indexes": {
420
+ "ai_tool_calls_principal_created_idx": {
421
+ "name": "ai_tool_calls_principal_created_idx",
422
+ "columns": [
423
+ {
424
+ "expression": "principal_kind",
425
+ "isExpression": false,
426
+ "asc": true,
427
+ "nulls": "last"
428
+ },
429
+ {
430
+ "expression": "principal_id",
431
+ "isExpression": false,
432
+ "asc": true,
433
+ "nulls": "last"
434
+ },
435
+ {
436
+ "expression": "created_at",
437
+ "isExpression": false,
438
+ "asc": true,
439
+ "nulls": "last"
440
+ }
441
+ ],
442
+ "isUnique": false,
443
+ "concurrently": false,
444
+ "method": "btree",
445
+ "with": {}
446
+ },
447
+ "ai_tool_calls_status_expires_idx": {
448
+ "name": "ai_tool_calls_status_expires_idx",
449
+ "columns": [
450
+ {
451
+ "expression": "status",
452
+ "isExpression": false,
453
+ "asc": true,
454
+ "nulls": "last"
455
+ },
456
+ {
457
+ "expression": "proposal_expires_at",
458
+ "isExpression": false,
459
+ "asc": true,
460
+ "nulls": "last"
461
+ }
462
+ ],
463
+ "isUnique": false,
464
+ "concurrently": false,
465
+ "method": "btree",
466
+ "with": {}
467
+ },
468
+ "ai_tool_calls_conversation_idx": {
469
+ "name": "ai_tool_calls_conversation_idx",
470
+ "columns": [
471
+ {
472
+ "expression": "conversation_id",
473
+ "isExpression": false,
474
+ "asc": true,
475
+ "nulls": "last"
476
+ }
477
+ ],
478
+ "isUnique": false,
479
+ "concurrently": false,
480
+ "method": "btree",
481
+ "with": {}
482
+ }
483
+ },
484
+ "foreignKeys": {
485
+ "ai_tool_calls_conversation_id_ai_conversations_id_fk": {
486
+ "name": "ai_tool_calls_conversation_id_ai_conversations_id_fk",
487
+ "tableFrom": "ai_tool_calls",
488
+ "tableTo": "ai_conversations",
489
+ "columnsFrom": [
490
+ "conversation_id"
491
+ ],
492
+ "columnsTo": [
493
+ "id"
494
+ ],
495
+ "onDelete": "set null",
496
+ "onUpdate": "no action"
497
+ }
498
+ },
499
+ "compositePrimaryKeys": {},
500
+ "uniqueConstraints": {},
501
+ "policies": {},
502
+ "checkConstraints": {},
503
+ "isRLSEnabled": false
504
+ }
505
+ },
506
+ "enums": {
507
+ "public.ai_message_role": {
508
+ "name": "ai_message_role",
509
+ "schema": "public",
510
+ "values": [
511
+ "system",
512
+ "user",
513
+ "assistant",
514
+ "tool"
515
+ ]
516
+ },
517
+ "public.ai_tool_call_status": {
518
+ "name": "ai_tool_call_status",
519
+ "schema": "public",
520
+ "values": [
521
+ "proposed",
522
+ "applied",
523
+ "executed",
524
+ "failed",
525
+ "expired",
526
+ "rejected"
527
+ ]
528
+ },
529
+ "public.ai_tool_effect": {
530
+ "name": "ai_tool_effect",
531
+ "schema": "public",
532
+ "values": [
533
+ "read",
534
+ "mutate",
535
+ "destructive"
536
+ ]
537
+ },
538
+ "public.ai_transport": {
539
+ "name": "ai_transport",
540
+ "schema": "public",
541
+ "values": [
542
+ "chat",
543
+ "mcp"
544
+ ]
545
+ }
546
+ },
547
+ "schemas": {},
548
+ "sequences": {},
549
+ "roles": {},
550
+ "policies": {},
551
+ "views": {},
552
+ "_meta": {
553
+ "columns": {},
554
+ "schemas": {},
555
+ "tables": {}
556
+ }
557
+ }