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