@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,434 @@
1
+ {
2
+ "id": "099095e0-5109-485c-8d2a-b50378e60078",
3
+ "prevId": "2b6f36f7-1660-4cb7-95ab-abb0221396d8",
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
+ "created_at": {
122
+ "name": "created_at",
123
+ "type": "timestamp",
124
+ "primaryKey": false,
125
+ "notNull": true,
126
+ "default": "now()"
127
+ }
128
+ },
129
+ "indexes": {
130
+ "ai_messages_conversation_idx": {
131
+ "name": "ai_messages_conversation_idx",
132
+ "columns": [
133
+ {
134
+ "expression": "conversation_id",
135
+ "isExpression": false,
136
+ "asc": true,
137
+ "nulls": "last"
138
+ },
139
+ {
140
+ "expression": "created_at",
141
+ "isExpression": false,
142
+ "asc": true,
143
+ "nulls": "last"
144
+ }
145
+ ],
146
+ "isUnique": false,
147
+ "concurrently": false,
148
+ "method": "btree",
149
+ "with": {}
150
+ }
151
+ },
152
+ "foreignKeys": {
153
+ "ai_messages_conversation_id_ai_conversations_id_fk": {
154
+ "name": "ai_messages_conversation_id_ai_conversations_id_fk",
155
+ "tableFrom": "ai_messages",
156
+ "tableTo": "ai_conversations",
157
+ "columnsFrom": [
158
+ "conversation_id"
159
+ ],
160
+ "columnsTo": [
161
+ "id"
162
+ ],
163
+ "onDelete": "cascade",
164
+ "onUpdate": "no action"
165
+ }
166
+ },
167
+ "compositePrimaryKeys": {},
168
+ "uniqueConstraints": {},
169
+ "policies": {},
170
+ "checkConstraints": {},
171
+ "isRLSEnabled": false
172
+ },
173
+ "public.ai_tool_calls": {
174
+ "name": "ai_tool_calls",
175
+ "schema": "",
176
+ "columns": {
177
+ "id": {
178
+ "name": "id",
179
+ "type": "text",
180
+ "primaryKey": true,
181
+ "notNull": true
182
+ },
183
+ "principal_kind": {
184
+ "name": "principal_kind",
185
+ "type": "text",
186
+ "primaryKey": false,
187
+ "notNull": true
188
+ },
189
+ "principal_id": {
190
+ "name": "principal_id",
191
+ "type": "text",
192
+ "primaryKey": false,
193
+ "notNull": true
194
+ },
195
+ "transport": {
196
+ "name": "transport",
197
+ "type": "ai_transport",
198
+ "typeSchema": "public",
199
+ "primaryKey": false,
200
+ "notNull": true
201
+ },
202
+ "conversation_id": {
203
+ "name": "conversation_id",
204
+ "type": "text",
205
+ "primaryKey": false,
206
+ "notNull": false
207
+ },
208
+ "tool_name": {
209
+ "name": "tool_name",
210
+ "type": "text",
211
+ "primaryKey": false,
212
+ "notNull": true
213
+ },
214
+ "effect": {
215
+ "name": "effect",
216
+ "type": "ai_tool_effect",
217
+ "typeSchema": "public",
218
+ "primaryKey": false,
219
+ "notNull": true
220
+ },
221
+ "args_hash": {
222
+ "name": "args_hash",
223
+ "type": "text",
224
+ "primaryKey": false,
225
+ "notNull": true
226
+ },
227
+ "status": {
228
+ "name": "status",
229
+ "type": "ai_tool_call_status",
230
+ "typeSchema": "public",
231
+ "primaryKey": false,
232
+ "notNull": true
233
+ },
234
+ "proposal_nonce": {
235
+ "name": "proposal_nonce",
236
+ "type": "text",
237
+ "primaryKey": false,
238
+ "notNull": false
239
+ },
240
+ "proposal_expires_at": {
241
+ "name": "proposal_expires_at",
242
+ "type": "timestamp",
243
+ "primaryKey": false,
244
+ "notNull": false
245
+ },
246
+ "applied_by_kind": {
247
+ "name": "applied_by_kind",
248
+ "type": "text",
249
+ "primaryKey": false,
250
+ "notNull": false
251
+ },
252
+ "applied_by_id": {
253
+ "name": "applied_by_id",
254
+ "type": "text",
255
+ "primaryKey": false,
256
+ "notNull": false
257
+ },
258
+ "result_snapshot": {
259
+ "name": "result_snapshot",
260
+ "type": "jsonb",
261
+ "primaryKey": false,
262
+ "notNull": false
263
+ },
264
+ "proposed_payload": {
265
+ "name": "proposed_payload",
266
+ "type": "jsonb",
267
+ "primaryKey": false,
268
+ "notNull": false
269
+ },
270
+ "error": {
271
+ "name": "error",
272
+ "type": "text",
273
+ "primaryKey": false,
274
+ "notNull": false
275
+ },
276
+ "proposed_at": {
277
+ "name": "proposed_at",
278
+ "type": "timestamp",
279
+ "primaryKey": false,
280
+ "notNull": false
281
+ },
282
+ "applied_at": {
283
+ "name": "applied_at",
284
+ "type": "timestamp",
285
+ "primaryKey": false,
286
+ "notNull": false
287
+ },
288
+ "created_at": {
289
+ "name": "created_at",
290
+ "type": "timestamp",
291
+ "primaryKey": false,
292
+ "notNull": true,
293
+ "default": "now()"
294
+ }
295
+ },
296
+ "indexes": {
297
+ "ai_tool_calls_principal_created_idx": {
298
+ "name": "ai_tool_calls_principal_created_idx",
299
+ "columns": [
300
+ {
301
+ "expression": "principal_kind",
302
+ "isExpression": false,
303
+ "asc": true,
304
+ "nulls": "last"
305
+ },
306
+ {
307
+ "expression": "principal_id",
308
+ "isExpression": false,
309
+ "asc": true,
310
+ "nulls": "last"
311
+ },
312
+ {
313
+ "expression": "created_at",
314
+ "isExpression": false,
315
+ "asc": true,
316
+ "nulls": "last"
317
+ }
318
+ ],
319
+ "isUnique": false,
320
+ "concurrently": false,
321
+ "method": "btree",
322
+ "with": {}
323
+ },
324
+ "ai_tool_calls_status_expires_idx": {
325
+ "name": "ai_tool_calls_status_expires_idx",
326
+ "columns": [
327
+ {
328
+ "expression": "status",
329
+ "isExpression": false,
330
+ "asc": true,
331
+ "nulls": "last"
332
+ },
333
+ {
334
+ "expression": "proposal_expires_at",
335
+ "isExpression": false,
336
+ "asc": true,
337
+ "nulls": "last"
338
+ }
339
+ ],
340
+ "isUnique": false,
341
+ "concurrently": false,
342
+ "method": "btree",
343
+ "with": {}
344
+ },
345
+ "ai_tool_calls_conversation_idx": {
346
+ "name": "ai_tool_calls_conversation_idx",
347
+ "columns": [
348
+ {
349
+ "expression": "conversation_id",
350
+ "isExpression": false,
351
+ "asc": true,
352
+ "nulls": "last"
353
+ }
354
+ ],
355
+ "isUnique": false,
356
+ "concurrently": false,
357
+ "method": "btree",
358
+ "with": {}
359
+ }
360
+ },
361
+ "foreignKeys": {
362
+ "ai_tool_calls_conversation_id_ai_conversations_id_fk": {
363
+ "name": "ai_tool_calls_conversation_id_ai_conversations_id_fk",
364
+ "tableFrom": "ai_tool_calls",
365
+ "tableTo": "ai_conversations",
366
+ "columnsFrom": [
367
+ "conversation_id"
368
+ ],
369
+ "columnsTo": [
370
+ "id"
371
+ ],
372
+ "onDelete": "set null",
373
+ "onUpdate": "no action"
374
+ }
375
+ },
376
+ "compositePrimaryKeys": {},
377
+ "uniqueConstraints": {},
378
+ "policies": {},
379
+ "checkConstraints": {},
380
+ "isRLSEnabled": false
381
+ }
382
+ },
383
+ "enums": {
384
+ "public.ai_message_role": {
385
+ "name": "ai_message_role",
386
+ "schema": "public",
387
+ "values": [
388
+ "system",
389
+ "user",
390
+ "assistant",
391
+ "tool"
392
+ ]
393
+ },
394
+ "public.ai_tool_call_status": {
395
+ "name": "ai_tool_call_status",
396
+ "schema": "public",
397
+ "values": [
398
+ "proposed",
399
+ "applied",
400
+ "executed",
401
+ "failed",
402
+ "expired",
403
+ "rejected"
404
+ ]
405
+ },
406
+ "public.ai_tool_effect": {
407
+ "name": "ai_tool_effect",
408
+ "schema": "public",
409
+ "values": [
410
+ "read",
411
+ "mutate",
412
+ "destructive"
413
+ ]
414
+ },
415
+ "public.ai_transport": {
416
+ "name": "ai_transport",
417
+ "schema": "public",
418
+ "values": [
419
+ "chat",
420
+ "mcp"
421
+ ]
422
+ }
423
+ },
424
+ "schemas": {},
425
+ "sequences": {},
426
+ "roles": {},
427
+ "policies": {},
428
+ "views": {},
429
+ "_meta": {
430
+ "columns": {},
431
+ "schemas": {},
432
+ "tables": {}
433
+ }
434
+ }