@rudderjs/ai 1.17.3 → 1.18.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 (377) hide show
  1. package/README.md +19 -1274
  2. package/dist/budget-orm/index.d.ts +1 -95
  3. package/dist/budget-orm/index.d.ts.map +1 -1
  4. package/dist/budget-orm/index.js +4 -176
  5. package/dist/budget-orm/index.js.map +1 -1
  6. package/dist/chat-mentions.d.ts +1 -58
  7. package/dist/chat-mentions.d.ts.map +1 -1
  8. package/dist/chat-mentions.js +4 -80
  9. package/dist/chat-mentions.js.map +1 -1
  10. package/dist/commands/ai-eval.d.ts +1 -92
  11. package/dist/commands/ai-eval.d.ts.map +1 -1
  12. package/dist/commands/ai-eval.js +4 -377
  13. package/dist/commands/ai-eval.js.map +1 -1
  14. package/dist/commands/make-agent.d.ts +1 -2
  15. package/dist/commands/make-agent.d.ts.map +1 -1
  16. package/dist/commands/make-agent.js +4 -22
  17. package/dist/commands/make-agent.js.map +1 -1
  18. package/dist/computer-use/index.d.ts +1 -52
  19. package/dist/computer-use/index.d.ts.map +1 -1
  20. package/dist/computer-use/index.js +4 -50
  21. package/dist/computer-use/index.js.map +1 -1
  22. package/dist/conversation-orm/index.d.ts +1 -108
  23. package/dist/conversation-orm/index.d.ts.map +1 -1
  24. package/dist/conversation-orm/index.js +4 -214
  25. package/dist/conversation-orm/index.js.map +1 -1
  26. package/dist/doctor.d.ts +1 -1
  27. package/dist/doctor.d.ts.map +1 -1
  28. package/dist/doctor.js +4 -65
  29. package/dist/doctor.js.map +1 -1
  30. package/dist/eval/index.d.ts +1 -270
  31. package/dist/eval/index.d.ts.map +1 -1
  32. package/dist/eval/index.js +4 -509
  33. package/dist/eval/index.js.map +1 -1
  34. package/dist/gateway/index.d.ts +1 -10
  35. package/dist/gateway/index.d.ts.map +1 -1
  36. package/dist/gateway/index.js +4 -10
  37. package/dist/gateway/index.js.map +1 -1
  38. package/dist/index.d.ts +1 -66
  39. package/dist/index.d.ts.map +1 -1
  40. package/dist/index.js +4 -78
  41. package/dist/index.js.map +1 -1
  42. package/dist/mcp/index.d.ts +1 -15
  43. package/dist/mcp/index.d.ts.map +1 -1
  44. package/dist/mcp/index.js +4 -14
  45. package/dist/mcp/index.js.map +1 -1
  46. package/dist/memory-embedding/index.d.ts +1 -120
  47. package/dist/memory-embedding/index.d.ts.map +1 -1
  48. package/dist/memory-embedding/index.js +4 -228
  49. package/dist/memory-embedding/index.js.map +1 -1
  50. package/dist/memory-orm/index.d.ts +1 -117
  51. package/dist/memory-orm/index.d.ts.map +1 -1
  52. package/dist/memory-orm/index.js +4 -186
  53. package/dist/memory-orm/index.js.map +1 -1
  54. package/dist/node/index.d.ts +1 -2
  55. package/dist/node/index.d.ts.map +1 -1
  56. package/dist/node/index.js +4 -2
  57. package/dist/node/index.js.map +1 -1
  58. package/dist/observers.d.ts +1 -129
  59. package/dist/observers.d.ts.map +1 -1
  60. package/dist/observers.js +4 -39
  61. package/dist/observers.js.map +1 -1
  62. package/dist/react/index.d.ts +1 -15
  63. package/dist/react/index.d.ts.map +1 -1
  64. package/dist/react/index.js +4 -15
  65. package/dist/react/index.js.map +1 -1
  66. package/dist/server/index.d.ts +1 -1
  67. package/dist/server/index.d.ts.map +1 -1
  68. package/dist/server/index.js +4 -1
  69. package/dist/server/index.js.map +1 -1
  70. package/package.json +9 -13
  71. package/boost/guidelines.md +0 -260
  72. package/boost/skills/ai-agents/SKILL.md +0 -240
  73. package/boost/skills/ai-tools/SKILL.md +0 -260
  74. package/dist/agent-run-store.d.ts +0 -161
  75. package/dist/agent-run-store.d.ts.map +0 -1
  76. package/dist/agent-run-store.js +0 -98
  77. package/dist/agent-run-store.js.map +0 -1
  78. package/dist/agent-sse.d.ts +0 -153
  79. package/dist/agent-sse.d.ts.map +0 -1
  80. package/dist/agent-sse.js +0 -282
  81. package/dist/agent-sse.js.map +0 -1
  82. package/dist/agent.d.ts +0 -508
  83. package/dist/agent.d.ts.map +0 -1
  84. package/dist/agent.js +0 -1538
  85. package/dist/agent.js.map +0 -1
  86. package/dist/attachment.d.ts +0 -31
  87. package/dist/attachment.d.ts.map +0 -1
  88. package/dist/attachment.js +0 -89
  89. package/dist/attachment.js.map +0 -1
  90. package/dist/audio.d.ts +0 -45
  91. package/dist/audio.d.ts.map +0 -1
  92. package/dist/audio.js +0 -93
  93. package/dist/audio.js.map +0 -1
  94. package/dist/base64.d.ts +0 -7
  95. package/dist/base64.d.ts.map +0 -1
  96. package/dist/base64.js +0 -39
  97. package/dist/base64.js.map +0 -1
  98. package/dist/budget/pricing.d.ts +0 -124
  99. package/dist/budget/pricing.d.ts.map +0 -1
  100. package/dist/budget/pricing.js +0 -175
  101. package/dist/budget/pricing.js.map +0 -1
  102. package/dist/budget/storage.d.ts +0 -104
  103. package/dist/budget/storage.d.ts.map +0 -1
  104. package/dist/budget/storage.js +0 -0
  105. package/dist/budget/storage.js.map +0 -1
  106. package/dist/budget/with-budget.d.ts +0 -119
  107. package/dist/budget/with-budget.d.ts.map +0 -1
  108. package/dist/budget/with-budget.js +0 -175
  109. package/dist/budget/with-budget.js.map +0 -1
  110. package/dist/cached-embedding.d.ts +0 -14
  111. package/dist/cached-embedding.d.ts.map +0 -1
  112. package/dist/cached-embedding.js +0 -44
  113. package/dist/cached-embedding.js.map +0 -1
  114. package/dist/computer-use/actions.d.ts +0 -214
  115. package/dist/computer-use/actions.d.ts.map +0 -1
  116. package/dist/computer-use/actions.js +0 -48
  117. package/dist/computer-use/actions.js.map +0 -1
  118. package/dist/computer-use/errors.d.ts +0 -57
  119. package/dist/computer-use/errors.d.ts.map +0 -1
  120. package/dist/computer-use/errors.js +0 -76
  121. package/dist/computer-use/errors.js.map +0 -1
  122. package/dist/computer-use/playwright.d.ts +0 -76
  123. package/dist/computer-use/playwright.d.ts.map +0 -1
  124. package/dist/computer-use/playwright.js +0 -270
  125. package/dist/computer-use/playwright.js.map +0 -1
  126. package/dist/computer-use/tool.d.ts +0 -154
  127. package/dist/computer-use/tool.d.ts.map +0 -1
  128. package/dist/computer-use/tool.js +0 -210
  129. package/dist/computer-use/tool.js.map +0 -1
  130. package/dist/continuation-validation.d.ts +0 -85
  131. package/dist/continuation-validation.d.ts.map +0 -1
  132. package/dist/continuation-validation.js +0 -166
  133. package/dist/continuation-validation.js.map +0 -1
  134. package/dist/conversation-persistence.d.ts +0 -46
  135. package/dist/conversation-persistence.d.ts.map +0 -1
  136. package/dist/conversation-persistence.js +0 -176
  137. package/dist/conversation-persistence.js.map +0 -1
  138. package/dist/conversation.d.ts +0 -11
  139. package/dist/conversation.d.ts.map +0 -1
  140. package/dist/conversation.js +0 -55
  141. package/dist/conversation.js.map +0 -1
  142. package/dist/eval/fixtures.d.ts +0 -65
  143. package/dist/eval/fixtures.d.ts.map +0 -1
  144. package/dist/eval/fixtures.js +0 -110
  145. package/dist/eval/fixtures.js.map +0 -1
  146. package/dist/eval/html-reporter.d.ts +0 -25
  147. package/dist/eval/html-reporter.d.ts.map +0 -1
  148. package/dist/eval/html-reporter.js +0 -209
  149. package/dist/eval/html-reporter.js.map +0 -1
  150. package/dist/eval/json-reporter.d.ts +0 -43
  151. package/dist/eval/json-reporter.d.ts.map +0 -1
  152. package/dist/eval/json-reporter.js +0 -40
  153. package/dist/eval/json-reporter.js.map +0 -1
  154. package/dist/facade.d.ts +0 -96
  155. package/dist/facade.d.ts.map +0 -1
  156. package/dist/facade.js +0 -146
  157. package/dist/facade.js.map +0 -1
  158. package/dist/fake.d.ts +0 -201
  159. package/dist/fake.d.ts.map +0 -1
  160. package/dist/fake.js +0 -428
  161. package/dist/fake.js.map +0 -1
  162. package/dist/file-search.d.ts +0 -168
  163. package/dist/file-search.d.ts.map +0 -1
  164. package/dist/file-search.js +0 -158
  165. package/dist/file-search.js.map +0 -1
  166. package/dist/files.d.ts +0 -27
  167. package/dist/files.d.ts.map +0 -1
  168. package/dist/files.js +0 -44
  169. package/dist/files.js.map +0 -1
  170. package/dist/gateway/http-gateway-adapter.d.ts +0 -94
  171. package/dist/gateway/http-gateway-adapter.d.ts.map +0 -1
  172. package/dist/gateway/http-gateway-adapter.js +0 -106
  173. package/dist/gateway/http-gateway-adapter.js.map +0 -1
  174. package/dist/gateway/sse.d.ts +0 -28
  175. package/dist/gateway/sse.d.ts.map +0 -1
  176. package/dist/gateway/sse.js +0 -78
  177. package/dist/gateway/sse.js.map +0 -1
  178. package/dist/handoff.d.ts +0 -95
  179. package/dist/handoff.d.ts.map +0 -1
  180. package/dist/handoff.js +0 -78
  181. package/dist/handoff.js.map +0 -1
  182. package/dist/handoffs-driver.d.ts +0 -58
  183. package/dist/handoffs-driver.d.ts.map +0 -1
  184. package/dist/handoffs-driver.js +0 -103
  185. package/dist/handoffs-driver.js.map +0 -1
  186. package/dist/image.d.ts +0 -40
  187. package/dist/image.d.ts.map +0 -1
  188. package/dist/image.js +0 -109
  189. package/dist/image.js.map +0 -1
  190. package/dist/mcp/client-tools.d.ts +0 -39
  191. package/dist/mcp/client-tools.d.ts.map +0 -1
  192. package/dist/mcp/client-tools.js +0 -147
  193. package/dist/mcp/client-tools.js.map +0 -1
  194. package/dist/mcp/server-from-agent.d.ts +0 -24
  195. package/dist/mcp/server-from-agent.d.ts.map +0 -1
  196. package/dist/mcp/server-from-agent.js +0 -113
  197. package/dist/mcp/server-from-agent.js.map +0 -1
  198. package/dist/mcp/types.d.ts +0 -64
  199. package/dist/mcp/types.d.ts.map +0 -1
  200. package/dist/mcp/types.js +0 -6
  201. package/dist/mcp/types.js.map +0 -1
  202. package/dist/memory-extract.d.ts +0 -60
  203. package/dist/memory-extract.d.ts.map +0 -1
  204. package/dist/memory-extract.js +0 -163
  205. package/dist/memory-extract.js.map +0 -1
  206. package/dist/memory-inject.d.ts +0 -39
  207. package/dist/memory-inject.d.ts.map +0 -1
  208. package/dist/memory-inject.js +0 -135
  209. package/dist/memory-inject.js.map +0 -1
  210. package/dist/memory.d.ts +0 -55
  211. package/dist/memory.d.ts.map +0 -1
  212. package/dist/memory.js +0 -132
  213. package/dist/memory.js.map +0 -1
  214. package/dist/middleware.d.ts +0 -18
  215. package/dist/middleware.d.ts.map +0 -1
  216. package/dist/middleware.js +0 -72
  217. package/dist/middleware.js.map +0 -1
  218. package/dist/node/attachment.d.ts +0 -6
  219. package/dist/node/attachment.d.ts.map +0 -1
  220. package/dist/node/attachment.js +0 -35
  221. package/dist/node/attachment.js.map +0 -1
  222. package/dist/node/transcription.d.ts +0 -4
  223. package/dist/node/transcription.d.ts.map +0 -1
  224. package/dist/node/transcription.js +0 -8
  225. package/dist/node/transcription.js.map +0 -1
  226. package/dist/output.d.ts +0 -22
  227. package/dist/output.d.ts.map +0 -1
  228. package/dist/output.js +0 -60
  229. package/dist/output.js.map +0 -1
  230. package/dist/provider-tools.d.ts +0 -87
  231. package/dist/provider-tools.d.ts.map +0 -1
  232. package/dist/provider-tools.js +0 -189
  233. package/dist/provider-tools.js.map +0 -1
  234. package/dist/providers/anthropic.d.ts +0 -24
  235. package/dist/providers/anthropic.d.ts.map +0 -1
  236. package/dist/providers/anthropic.js +0 -405
  237. package/dist/providers/anthropic.js.map +0 -1
  238. package/dist/providers/azure.d.ts +0 -13
  239. package/dist/providers/azure.d.ts.map +0 -1
  240. package/dist/providers/azure.js +0 -15
  241. package/dist/providers/azure.js.map +0 -1
  242. package/dist/providers/bedrock.d.ts +0 -75
  243. package/dist/providers/bedrock.d.ts.map +0 -1
  244. package/dist/providers/bedrock.js +0 -181
  245. package/dist/providers/bedrock.js.map +0 -1
  246. package/dist/providers/cohere.d.ts +0 -13
  247. package/dist/providers/cohere.d.ts.map +0 -1
  248. package/dist/providers/cohere.js +0 -87
  249. package/dist/providers/cohere.js.map +0 -1
  250. package/dist/providers/deepseek.d.ts +0 -12
  251. package/dist/providers/deepseek.d.ts.map +0 -1
  252. package/dist/providers/deepseek.js +0 -15
  253. package/dist/providers/deepseek.js.map +0 -1
  254. package/dist/providers/elevenlabs.d.ts +0 -98
  255. package/dist/providers/elevenlabs.d.ts.map +0 -1
  256. package/dist/providers/elevenlabs.js +0 -229
  257. package/dist/providers/elevenlabs.js.map +0 -1
  258. package/dist/providers/google-cache-registry.d.ts +0 -132
  259. package/dist/providers/google-cache-registry.d.ts.map +0 -1
  260. package/dist/providers/google-cache-registry.js +0 -209
  261. package/dist/providers/google-cache-registry.js.map +0 -1
  262. package/dist/providers/google.d.ts +0 -38
  263. package/dist/providers/google.d.ts.map +0 -1
  264. package/dist/providers/google.js +0 -903
  265. package/dist/providers/google.js.map +0 -1
  266. package/dist/providers/groq.d.ts +0 -12
  267. package/dist/providers/groq.d.ts.map +0 -1
  268. package/dist/providers/groq.js +0 -15
  269. package/dist/providers/groq.js.map +0 -1
  270. package/dist/providers/jina.d.ts +0 -13
  271. package/dist/providers/jina.d.ts.map +0 -1
  272. package/dist/providers/jina.js +0 -90
  273. package/dist/providers/jina.js.map +0 -1
  274. package/dist/providers/mistral.d.ts +0 -13
  275. package/dist/providers/mistral.d.ts.map +0 -1
  276. package/dist/providers/mistral.js +0 -46
  277. package/dist/providers/mistral.js.map +0 -1
  278. package/dist/providers/ollama.d.ts +0 -11
  279. package/dist/providers/ollama.d.ts.map +0 -1
  280. package/dist/providers/ollama.js +0 -15
  281. package/dist/providers/ollama.js.map +0 -1
  282. package/dist/providers/openai.d.ts +0 -79
  283. package/dist/providers/openai.d.ts.map +0 -1
  284. package/dist/providers/openai.js +0 -792
  285. package/dist/providers/openai.js.map +0 -1
  286. package/dist/providers/openrouter.d.ts +0 -43
  287. package/dist/providers/openrouter.d.ts.map +0 -1
  288. package/dist/providers/openrouter.js +0 -21
  289. package/dist/providers/openrouter.js.map +0 -1
  290. package/dist/providers/voyage.d.ts +0 -91
  291. package/dist/providers/voyage.d.ts.map +0 -1
  292. package/dist/providers/voyage.js +0 -166
  293. package/dist/providers/voyage.js.map +0 -1
  294. package/dist/providers/xai.d.ts +0 -12
  295. package/dist/providers/xai.d.ts.map +0 -1
  296. package/dist/providers/xai.js +0 -15
  297. package/dist/providers/xai.js.map +0 -1
  298. package/dist/queue-job.d.ts +0 -100
  299. package/dist/queue-job.d.ts.map +0 -1
  300. package/dist/queue-job.js +0 -185
  301. package/dist/queue-job.js.map +0 -1
  302. package/dist/react/agent-run.d.ts +0 -111
  303. package/dist/react/agent-run.d.ts.map +0 -1
  304. package/dist/react/agent-run.js +0 -107
  305. package/dist/react/agent-run.js.map +0 -1
  306. package/dist/react/useAgentRun.d.ts +0 -68
  307. package/dist/react/useAgentRun.d.ts.map +0 -1
  308. package/dist/react/useAgentRun.js +0 -125
  309. package/dist/react/useAgentRun.js.map +0 -1
  310. package/dist/registry.d.ts +0 -45
  311. package/dist/registry.d.ts.map +0 -1
  312. package/dist/registry.js +0 -131
  313. package/dist/registry.js.map +0 -1
  314. package/dist/rerank.d.ts +0 -20
  315. package/dist/rerank.d.ts.map +0 -1
  316. package/dist/rerank.js +0 -40
  317. package/dist/rerank.js.map +0 -1
  318. package/dist/resume-approval.d.ts +0 -30
  319. package/dist/resume-approval.d.ts.map +0 -1
  320. package/dist/resume-approval.js +0 -147
  321. package/dist/resume-approval.js.map +0 -1
  322. package/dist/sanitize-conversation.d.ts +0 -43
  323. package/dist/sanitize-conversation.d.ts.map +0 -1
  324. package/dist/sanitize-conversation.js +0 -85
  325. package/dist/sanitize-conversation.js.map +0 -1
  326. package/dist/scoped-tool.d.ts +0 -98
  327. package/dist/scoped-tool.d.ts.map +0 -1
  328. package/dist/scoped-tool.js +0 -174
  329. package/dist/scoped-tool.js.map +0 -1
  330. package/dist/server/provider.d.ts +0 -22
  331. package/dist/server/provider.d.ts.map +0 -1
  332. package/dist/server/provider.js +0 -194
  333. package/dist/server/provider.js.map +0 -1
  334. package/dist/similarity-search.d.ts +0 -163
  335. package/dist/similarity-search.d.ts.map +0 -1
  336. package/dist/similarity-search.js +0 -147
  337. package/dist/similarity-search.js.map +0 -1
  338. package/dist/sub-agent-run-store.d.ts +0 -157
  339. package/dist/sub-agent-run-store.d.ts.map +0 -1
  340. package/dist/sub-agent-run-store.js +0 -87
  341. package/dist/sub-agent-run-store.js.map +0 -1
  342. package/dist/tool-execution.d.ts +0 -16
  343. package/dist/tool-execution.d.ts.map +0 -1
  344. package/dist/tool-execution.js +0 -498
  345. package/dist/tool-execution.js.map +0 -1
  346. package/dist/tool-helpers.d.ts +0 -77
  347. package/dist/tool-helpers.d.ts.map +0 -1
  348. package/dist/tool-helpers.js +0 -117
  349. package/dist/tool-helpers.js.map +0 -1
  350. package/dist/tool.d.ts +0 -216
  351. package/dist/tool.d.ts.map +0 -1
  352. package/dist/tool.js +0 -175
  353. package/dist/tool.js.map +0 -1
  354. package/dist/transcription.d.ts +0 -42
  355. package/dist/transcription.d.ts.map +0 -1
  356. package/dist/transcription.js +0 -77
  357. package/dist/transcription.js.map +0 -1
  358. package/dist/types.d.ts +0 -1020
  359. package/dist/types.d.ts.map +0 -1
  360. package/dist/types.js +0 -2
  361. package/dist/types.js.map +0 -1
  362. package/dist/util/hash.d.ts +0 -11
  363. package/dist/util/hash.d.ts.map +0 -1
  364. package/dist/util/hash.js +0 -23
  365. package/dist/util/hash.js.map +0 -1
  366. package/dist/vector-stores/index.d.ts +0 -96
  367. package/dist/vector-stores/index.d.ts.map +0 -1
  368. package/dist/vector-stores/index.js +0 -153
  369. package/dist/vector-stores/index.js.map +0 -1
  370. package/dist/vercel-protocol.d.ts +0 -18
  371. package/dist/vercel-protocol.d.ts.map +0 -1
  372. package/dist/vercel-protocol.js +0 -75
  373. package/dist/vercel-protocol.js.map +0 -1
  374. package/dist/zod-to-json-schema.d.ts +0 -16
  375. package/dist/zod-to-json-schema.d.ts.map +0 -1
  376. package/dist/zod-to-json-schema.js +0 -17
  377. package/dist/zod-to-json-schema.js.map +0 -1
@@ -1,96 +1,2 @@
1
- /**
2
- * `@rudderjs/ai/budget-orm` — ORM-backed {@link BudgetStorage} for #A6 Phase 4.
3
- *
4
- * Production-grade replacement for `memoryBudgetStorage()` (which is
5
- * single-process only). Persists per-user spend counters in a
6
- * `BudgetUsage` table via the registered `@rudderjs/orm` adapter — works
7
- * across queue workers, web processes, and horizontally-scaled deployments.
8
- *
9
- * Wire it into your AI middleware:
10
- *
11
- * ```ts
12
- * import { withBudget } from '@rudderjs/ai'
13
- * import { ormBudgetStorage } from '@rudderjs/ai/budget-orm'
14
- *
15
- * const budgeted = withBudget({
16
- * user: (ctx) => ctx.context as string,
17
- * budget: () => ({ daily: 0.50, monthly: 10 }),
18
- * storage: ormBudgetStorage(),
19
- * })
20
- * ```
21
- *
22
- * The schema lives at {@link budgetUsagePrismaSchema} — copy it into your
23
- * Prisma schema (or a new `prisma/schema/<file>.prisma` if you use the
24
- * multi-file setup). The `@@unique([userId, period, periodKey])`
25
- * constraint is the one load-bearing index — without it, the
26
- * find-or-create path can race and produce duplicate rows.
27
- *
28
- * # Atomicity caveat
29
- *
30
- * `checkAndDebit` does a read-then-conditional-increment. The increment
31
- * itself is atomic (`UPDATE col = col + n`), but the cap check sits
32
- * between the read and the write. Under high concurrency for a single
33
- * user (more than ~1 in-flight budgeted request at a time), total spend
34
- * can briefly exceed `cap` by up to `costUsd × concurrency`. For typical
35
- * apps this is a non-issue.
36
- *
37
- * Strict guarantees require a database transaction with serializable
38
- * isolation or a Redis-backed counter — both planned as follow-ups. File
39
- * an issue if you hit this in production.
40
- */
41
- import { Model } from '@rudderjs/orm';
42
- import { type BudgetCheckOptions, type BudgetCheckResult, type BudgetPeriod, type BudgetStorage } from '../budget/storage.js';
43
- /**
44
- * Model row backing {@link OrmBudgetStorage}. Exposed so apps that
45
- * want admin views (e.g. "show me top spenders this month") can use
46
- * `BudgetUsageRecord.where(...).get()` instead of routing every read
47
- * through the {@link BudgetStorage} interface.
48
- *
49
- * The `@@unique([userId, period, periodKey])` constraint is required —
50
- * without it, two concurrent first-writes for the same user/period
51
- * create duplicate rows and the cap accounting silently drifts.
52
- */
53
- export declare class BudgetUsageRecord extends Model {
54
- static table: string;
55
- static fillable: string[];
56
- id: string;
57
- userId: string;
58
- /** `'daily'` or `'monthly'`. */
59
- period: string;
60
- /** TZ-aware bucket key — `YYYY-MM-DD` (daily) or `YYYY-MM` (monthly). */
61
- periodKey: string;
62
- /** Cumulative USD spend in this period. */
63
- spent: number;
64
- createdAt: Date;
65
- updatedAt: Date | null;
66
- }
67
- /**
68
- * Production `BudgetStorage` backed by the registered `@rudderjs/orm`
69
- * adapter. See the module JSDoc for setup + the atomicity caveat.
70
- */
71
- export declare class OrmBudgetStorage implements BudgetStorage {
72
- checkAndDebit(opts: BudgetCheckOptions): Promise<BudgetCheckResult>;
73
- /** Apply the read-then-conditional-increment path on an existing row. */
74
- private _applyIncrementPath;
75
- reset(userId: string, period: BudgetPeriod, now?: Date, timezone?: string): Promise<void>;
76
- }
77
- /**
78
- * Convenience factory — returns a fresh {@link OrmBudgetStorage}
79
- * instance. Prefer this over `new OrmBudgetStorage()` for symmetry with
80
- * `memoryBudgetStorage()`.
81
- */
82
- export declare function ormBudgetStorage(): BudgetStorage;
83
- /**
84
- * Reference Prisma schema for `OrmBudgetStorage`. Copy into your
85
- * `prisma/schema/<file>.prisma` (or paste alongside an existing model).
86
- *
87
- * The `@@unique([userId, period, periodKey])` constraint is required —
88
- * without it the find-or-create path can race and produce duplicate
89
- * rows, breaking cap accounting.
90
- *
91
- * SQLite stores `Float` as `REAL`; Postgres / MySQL as `DOUBLE
92
- * PRECISION` / `DOUBLE`. All three give 15+ significant digits — more
93
- * than enough for sub-cent budget tracking.
94
- */
95
- export declare const budgetUsagePrismaSchema = "model BudgetUsage {\n id String @id @default(cuid())\n userId String\n /// 'daily' | 'monthly'\n period String\n /// YYYY-MM-DD (daily) or YYYY-MM (monthly), in the configured timezone\n periodKey String\n /// Cumulative USD spend in this period\n spent Float @default(0)\n createdAt DateTime @default(now())\n updatedAt DateTime @updatedAt\n\n @@unique([userId, period, periodKey])\n @@index([userId])\n}\n";
1
+ export * from '@gemstack/ai-sdk/budget-orm';
96
2
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/budget-orm/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAuCG;AAEH,OAAO,EAAE,KAAK,EAAE,MAAM,eAAe,CAAA;AACrC,OAAO,EACL,KAAK,kBAAkB,EACvB,KAAK,iBAAiB,EACtB,KAAK,YAAY,EACjB,KAAK,aAAa,EAEnB,MAAM,sBAAsB,CAAA;AAI7B;;;;;;;;;GASG;AACH,qBAAa,iBAAkB,SAAQ,KAAK;IAC1C,OAAgB,KAAK,SAAmB;IACxC,OAAgB,QAAQ,WAA6C;IAE7D,EAAE,EAAS,MAAM,CAAA;IACjB,MAAM,EAAK,MAAM,CAAA;IACzB,gCAAgC;IACxB,MAAM,EAAK,MAAM,CAAA;IACzB,yEAAyE;IACjE,SAAS,EAAE,MAAM,CAAA;IACzB,2CAA2C;IACnC,KAAK,EAAM,MAAM,CAAA;IACjB,SAAS,EAAE,IAAI,CAAA;IACf,SAAS,EAAE,IAAI,GAAG,IAAI,CAAA;CAC/B;AAID;;;GAGG;AACH,qBAAa,gBAAiB,YAAW,aAAa;IAC9C,aAAa,CAAC,IAAI,EAAE,kBAAkB,GAAG,OAAO,CAAC,iBAAiB,CAAC;IAuDzE,yEAAyE;YAC3D,mBAAmB;IAsB3B,KAAK,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,YAAY,EAAE,GAAG,CAAC,EAAE,IAAI,EAAE,QAAQ,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;CAQhG;AAED;;;;GAIG;AACH,wBAAgB,gBAAgB,IAAI,aAAa,CAEhD;AAID;;;;;;;;;;;GAWG;AACH,eAAO,MAAM,uBAAuB,8bAenC,CAAA"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/budget-orm/index.ts"],"names":[],"mappings":"AAGA,cAAc,6BAA6B,CAAA"}
@@ -1,177 +1,5 @@
1
- /**
2
- * `@rudderjs/ai/budget-orm` — ORM-backed {@link BudgetStorage} for #A6 Phase 4.
3
- *
4
- * Production-grade replacement for `memoryBudgetStorage()` (which is
5
- * single-process only). Persists per-user spend counters in a
6
- * `BudgetUsage` table via the registered `@rudderjs/orm` adapter — works
7
- * across queue workers, web processes, and horizontally-scaled deployments.
8
- *
9
- * Wire it into your AI middleware:
10
- *
11
- * ```ts
12
- * import { withBudget } from '@rudderjs/ai'
13
- * import { ormBudgetStorage } from '@rudderjs/ai/budget-orm'
14
- *
15
- * const budgeted = withBudget({
16
- * user: (ctx) => ctx.context as string,
17
- * budget: () => ({ daily: 0.50, monthly: 10 }),
18
- * storage: ormBudgetStorage(),
19
- * })
20
- * ```
21
- *
22
- * The schema lives at {@link budgetUsagePrismaSchema} — copy it into your
23
- * Prisma schema (or a new `prisma/schema/<file>.prisma` if you use the
24
- * multi-file setup). The `@@unique([userId, period, periodKey])`
25
- * constraint is the one load-bearing index — without it, the
26
- * find-or-create path can race and produce duplicate rows.
27
- *
28
- * # Atomicity caveat
29
- *
30
- * `checkAndDebit` does a read-then-conditional-increment. The increment
31
- * itself is atomic (`UPDATE col = col + n`), but the cap check sits
32
- * between the read and the write. Under high concurrency for a single
33
- * user (more than ~1 in-flight budgeted request at a time), total spend
34
- * can briefly exceed `cap` by up to `costUsd × concurrency`. For typical
35
- * apps this is a non-issue.
36
- *
37
- * Strict guarantees require a database transaction with serializable
38
- * isolation or a Redis-backed counter — both planned as follow-ups. File
39
- * an issue if you hit this in production.
40
- */
41
- import { Model } from '@rudderjs/orm';
42
- import { periodKey as buildPeriodKey, } from '../budget/storage.js';
43
- // ─── ORM Model ────────────────────────────────────────────
44
- /**
45
- * Model row backing {@link OrmBudgetStorage}. Exposed so apps that
46
- * want admin views (e.g. "show me top spenders this month") can use
47
- * `BudgetUsageRecord.where(...).get()` instead of routing every read
48
- * through the {@link BudgetStorage} interface.
49
- *
50
- * The `@@unique([userId, period, periodKey])` constraint is required —
51
- * without it, two concurrent first-writes for the same user/period
52
- * create duplicate rows and the cap accounting silently drifts.
53
- */
54
- export class BudgetUsageRecord extends Model {
55
- static table = 'budgetUsage';
56
- static fillable = ['userId', 'period', 'periodKey', 'spent'];
57
- }
58
- // ─── BudgetStorage adapter ────────────────────────────────
59
- /**
60
- * Production `BudgetStorage` backed by the registered `@rudderjs/orm`
61
- * adapter. See the module JSDoc for setup + the atomicity caveat.
62
- */
63
- export class OrmBudgetStorage {
64
- async checkAndDebit(opts) {
65
- if (!Number.isFinite(opts.cap) || opts.cap < 0) {
66
- throw new Error(`[Rudder AI] BudgetStorage: cap must be a non-negative finite number, got ${opts.cap}`);
67
- }
68
- if (!Number.isFinite(opts.costUsd) || opts.costUsd < 0) {
69
- throw new Error(`[Rudder AI] BudgetStorage: costUsd must be a non-negative finite number, got ${opts.costUsd}`);
70
- }
71
- const now = opts.now ?? new Date();
72
- const key = buildPeriodKey(opts.period, now, opts.timezone);
73
- const existing = await BudgetUsageRecord
74
- .where('userId', opts.userId)
75
- .where('period', opts.period)
76
- .where('periodKey', key)
77
- .first();
78
- // ─── No row yet — first write for this period ─────────
79
- if (!existing) {
80
- // Pure-read on an empty bucket — still empty after.
81
- if (opts.costUsd === 0) {
82
- return { allowed: true, spent: 0, cap: opts.cap };
83
- }
84
- // Single debit larger than cap — refuse before creating the row,
85
- // so we don't pollute storage with denied requests.
86
- if (opts.costUsd > opts.cap) {
87
- return { allowed: false, spent: 0, cap: opts.cap };
88
- }
89
- try {
90
- await BudgetUsageRecord.create({
91
- userId: opts.userId,
92
- period: opts.period,
93
- periodKey: key,
94
- spent: opts.costUsd,
95
- });
96
- return { allowed: true, spent: opts.costUsd, cap: opts.cap };
97
- }
98
- catch (e) {
99
- // Race: another caller created the row between our `first()` and
100
- // `create()`. Re-read and fall through to the increment path.
101
- // We deliberately don't sniff the error type — any create failure
102
- // means the row may now exist; let the re-read decide.
103
- const refetched = await BudgetUsageRecord
104
- .where('userId', opts.userId)
105
- .where('period', opts.period)
106
- .where('periodKey', key)
107
- .first();
108
- if (!refetched)
109
- throw e; // not a unique-constraint race; surface the original error
110
- return this._applyIncrementPath(refetched, opts);
111
- }
112
- }
113
- return this._applyIncrementPath(existing, opts);
114
- }
115
- /** Apply the read-then-conditional-increment path on an existing row. */
116
- async _applyIncrementPath(row, opts) {
117
- const current = Number(row.spent ?? 0);
118
- // Pure read.
119
- if (opts.costUsd === 0) {
120
- return { allowed: true, spent: current, cap: opts.cap };
121
- }
122
- // Cap check — read-then-decide. Atomic under single-writer; under
123
- // concurrent writers, see the module-level atomicity caveat.
124
- if (current + opts.costUsd > opts.cap) {
125
- return { allowed: false, spent: current, cap: opts.cap };
126
- }
127
- const updated = await BudgetUsageRecord.increment(row.id, 'spent', opts.costUsd);
128
- const newSpent = Number(updated?.spent ?? current + opts.costUsd);
129
- return { allowed: true, spent: newSpent, cap: opts.cap };
130
- }
131
- async reset(userId, period, now, timezone) {
132
- const key = buildPeriodKey(period, now ?? new Date(), timezone);
133
- await BudgetUsageRecord
134
- .where('userId', userId)
135
- .where('period', period)
136
- .where('periodKey', key)
137
- .deleteAll();
138
- }
139
- }
140
- /**
141
- * Convenience factory — returns a fresh {@link OrmBudgetStorage}
142
- * instance. Prefer this over `new OrmBudgetStorage()` for symmetry with
143
- * `memoryBudgetStorage()`.
144
- */
145
- export function ormBudgetStorage() {
146
- return new OrmBudgetStorage();
147
- }
148
- // ─── Schema reference ─────────────────────────────────────
149
- /**
150
- * Reference Prisma schema for `OrmBudgetStorage`. Copy into your
151
- * `prisma/schema/<file>.prisma` (or paste alongside an existing model).
152
- *
153
- * The `@@unique([userId, period, periodKey])` constraint is required —
154
- * without it the find-or-create path can race and produce duplicate
155
- * rows, breaking cap accounting.
156
- *
157
- * SQLite stores `Float` as `REAL`; Postgres / MySQL as `DOUBLE
158
- * PRECISION` / `DOUBLE`. All three give 15+ significant digits — more
159
- * than enough for sub-cent budget tracking.
160
- */
161
- export const budgetUsagePrismaSchema = `model BudgetUsage {
162
- id String @id @default(cuid())
163
- userId String
164
- /// 'daily' | 'monthly'
165
- period String
166
- /// YYYY-MM-DD (daily) or YYYY-MM (monthly), in the configured timezone
167
- periodKey String
168
- /// Cumulative USD spend in this period
169
- spent Float @default(0)
170
- createdAt DateTime @default(now())
171
- updatedAt DateTime @updatedAt
172
-
173
- @@unique([userId, period, periodKey])
174
- @@index([userId])
175
- }
176
- `;
1
+ // @rudderjs/ai is deprecated. The AI engine now lives in @gemstack/ai-sdk.
2
+ // This module re-exports it for backwards compatibility; import from
3
+ // '@gemstack/ai-sdk/budget-orm' directly in new code.
4
+ export * from '@gemstack/ai-sdk/budget-orm';
177
5
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/budget-orm/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAuCG;AAEH,OAAO,EAAE,KAAK,EAAE,MAAM,eAAe,CAAA;AACrC,OAAO,EAKL,SAAS,IAAI,cAAc,GAC5B,MAAM,sBAAsB,CAAA;AAE7B,6DAA6D;AAE7D;;;;;;;;;GASG;AACH,MAAM,OAAO,iBAAkB,SAAQ,KAAK;IAC1C,MAAM,CAAU,KAAK,GAAM,aAAa,CAAA;IACxC,MAAM,CAAU,QAAQ,GAAG,CAAC,QAAQ,EAAE,QAAQ,EAAE,WAAW,EAAE,OAAO,CAAC,CAAA;;AAcvE,6DAA6D;AAE7D;;;GAGG;AACH,MAAM,OAAO,gBAAgB;IAC3B,KAAK,CAAC,aAAa,CAAC,IAAwB;QAC1C,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC,IAAI,CAAC,GAAG,CAAC,IAAI,IAAI,CAAC,GAAG,GAAG,CAAC,EAAE,CAAC;YAC/C,MAAM,IAAI,KAAK,CAAC,4EAA4E,IAAI,CAAC,GAAG,EAAE,CAAC,CAAA;QACzG,CAAC;QACD,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC,IAAI,CAAC,OA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,MAAM,OAAO,GAAG,MAAM,iBAAiB,CAAC,SAAS,CAAC,GAAG,CAAC,EAAE,EAAE,OAAO,EAAE,IAAI,CAAC,OAAO,CAAiC,CAAA;QAChH,MAAM,QAAQ,GAAG,MAAM,CAAC,OAAO,EAAE,KAAK,IAAI,OAAO,GAAG,IAAI,CAAC,OAAO,CAAC,CAAA;QACjE,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,KAAK,EAAE,QAAQ,EAAE,GAAG,EAAE,IAAI,CAAC,GAAG,EAAE,CAAA;IAC1D,CAAC;IAED,KAAK,CAAC,KAAK,CAAC,MAAc,EAAE,MAAoB,EAAE,GAAU,EAAE,QAAiB;QAC7E,MAAM,GAAG,GAAG,cAAc,CAAC,MAAM,EAAE,GAAG,IAAI,IAAI,IAAI,EAAE,EAAE,QAAQ,CAAC,CAAA;QAC/D,MAAM,iBAAiB;aACpB,KAAK,CAAC,QAAQ,EAAK,MAAM,CAAC;aAC1B,KAAK,CAAC,QAAQ,EAAK,MAAM,CAAC;aAC1B,KAAK,CAAC,WAAW,EAAE,GAAG,CAAC;aACvB,SAAS,EAAE,CAAA;IAChB,CAAC;CACF;AAED;;;;GAIG;AACH,MAAM,UAAU,gBAAgB;IAC9B,OAAO,IAAI,gBAAgB,EAAE,CAAA;AAC/B,CAAC;AAED,6DAA6D;AAE7D;;;;;;;;;;;GAWG;AACH,MAAM,CAAC,MAAM,uBAAuB,GAAG;;;;;;;;;;;;;;;CAetC,CAAA"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/budget-orm/index.ts"],"names":[],"mappings":"AAAA,2EAA2E;AAC3E,qEAAqE;AACrE,sDAAsD;AACtD,cAAc,6BAA6B,CAAA"}
@@ -1,59 +1,2 @@
1
- /**
2
- * `@rudderjs/ai/chat-mentions` - parse `@<slug>` agent mentions out of a chat
3
- * message and turn them into an orchestrator routing rule.
4
- *
5
- * A chat UX where the user types `@<slug>` to explicitly invoke an agent
6
- * (overriding the orchestrator's own routing judgment) is generic: chat
7
- * panels, Slack/Discord bots, CLIs. This ships the two reusable pieces every
8
- * such consumer would otherwise hand-roll:
9
- *
10
- * - {@link parseMentions} extracts and validates the tokens, returning the
11
- * matched slugs plus the message with the tokens stripped.
12
- * - {@link buildMentionRoutingRule} renders a system-prompt rule that forces
13
- * the orchestrator to dispatch the mentioned agents in order.
14
- *
15
- * Token shape: `@<slug>` where `<slug>` matches `[a-z0-9-]+`. A whitespace (or
16
- * start-of-string) is required before the `@` so `email@host` is not parsed as
17
- * a mention, and the right side is bounded by a non-word boundary so
18
- * `@seo-assistant.` does not eat the trailing punctuation.
19
- */
20
- /** Global regex matching an `@<slug>` mention with its leading boundary. */
21
- export declare const MENTION_REGEX: RegExp;
22
- export interface ParsedMentions {
23
- /** Slugs found in the message, lower-cased, in first-seen order, deduplicated. */
24
- slugs: string[];
25
- /** The message with every recognized `@<slug>` token removed and whitespace collapsed. */
26
- cleaned: string;
27
- }
28
- /**
29
- * Parse `@<slug>` mentions from a message and validate them against a set of
30
- * known agent slugs. Unknown mentions (e.g. `@nope`) are left in the message
31
- * verbatim - they are plain text, not a routing signal. Matched tokens are
32
- * stripped and surrounding whitespace is collapsed, so the model sees only the
33
- * cleaned intent.
34
- *
35
- * `knownSlugs` accepts any iterable (array or `Set`); matching is
36
- * case-insensitive and the returned slugs are lower-cased.
37
- */
38
- export declare function parseMentions(message: string, knownSlugs: Iterable<string>): ParsedMentions;
39
- export interface MentionRoutingRuleOptions {
40
- /**
41
- * Name of the tool the orchestrator calls to dispatch an agent.
42
- * Default `'run_agent'`.
43
- */
44
- toolName?: string;
45
- /**
46
- * The argument key on that tool carrying the agent slug.
47
- * Default `'agentSlug'`.
48
- */
49
- argKey?: string;
50
- }
51
- /**
52
- * Build the system-prompt rule injected when a message carries one or more
53
- * validated mentions. The orchestrator is instructed to call the dispatch
54
- * tool (default `run_agent({ agentSlug })`) for each mentioned agent in order,
55
- * overriding its own routing decision. Returns `null` when `slugs` is empty so
56
- * callers can `if (rule) systemPrompt += rule` without a length check.
57
- */
58
- export declare function buildMentionRoutingRule(slugs: readonly string[], opts?: MentionRoutingRuleOptions): string | null;
1
+ export * from '@gemstack/ai-sdk/chat-mentions';
59
2
  //# sourceMappingURL=chat-mentions.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"chat-mentions.d.ts","sourceRoot":"","sources":["../src/chat-mentions.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;GAkBG;AAEH,4EAA4E;AAC5E,eAAO,MAAM,aAAa,QAAsC,CAAA;AAEhE,MAAM,WAAW,cAAc;IAC7B,kFAAkF;IAClF,KAAK,EAAI,MAAM,EAAE,CAAA;IACjB,0FAA0F;IAC1F,OAAO,EAAE,MAAM,CAAA;CAChB;AAED;;;;;;;;;GASG;AACH,wBAAgB,aAAa,CAAC,OAAO,EAAE,MAAM,EAAE,UAAU,EAAE,QAAQ,CAAC,MAAM,CAAC,GAAG,cAAc,CAyB3F;AAED,MAAM,WAAW,yBAAyB;IACxC;;;OAGG;IACH,QAAQ,CAAC,EAAE,MAAM,CAAA;IACjB;;;OAGG;IACH,MAAM,CAAC,EAAI,MAAM,CAAA;CAClB;AAED;;;;;;GAMG;AACH,wBAAgB,uBAAuB,CACrC,KAAK,EAAE,SAAS,MAAM,EAAE,EACxB,IAAI,GAAG,yBAA8B,GACpC,MAAM,GAAG,IAAI,CAmBf"}
1
+ {"version":3,"file":"chat-mentions.d.ts","sourceRoot":"","sources":["../src/chat-mentions.ts"],"names":[],"mappings":"AAGA,cAAc,gCAAgC,CAAA"}
@@ -1,81 +1,5 @@
1
- /**
2
- * `@rudderjs/ai/chat-mentions` - parse `@<slug>` agent mentions out of a chat
3
- * message and turn them into an orchestrator routing rule.
4
- *
5
- * A chat UX where the user types `@<slug>` to explicitly invoke an agent
6
- * (overriding the orchestrator's own routing judgment) is generic: chat
7
- * panels, Slack/Discord bots, CLIs. This ships the two reusable pieces every
8
- * such consumer would otherwise hand-roll:
9
- *
10
- * - {@link parseMentions} extracts and validates the tokens, returning the
11
- * matched slugs plus the message with the tokens stripped.
12
- * - {@link buildMentionRoutingRule} renders a system-prompt rule that forces
13
- * the orchestrator to dispatch the mentioned agents in order.
14
- *
15
- * Token shape: `@<slug>` where `<slug>` matches `[a-z0-9-]+`. A whitespace (or
16
- * start-of-string) is required before the `@` so `email@host` is not parsed as
17
- * a mention, and the right side is bounded by a non-word boundary so
18
- * `@seo-assistant.` does not eat the trailing punctuation.
19
- */
20
- /** Global regex matching an `@<slug>` mention with its leading boundary. */
21
- export const MENTION_REGEX = /(^|\s)@([a-z0-9-]+)(?=$|[^\w-])/gi;
22
- /**
23
- * Parse `@<slug>` mentions from a message and validate them against a set of
24
- * known agent slugs. Unknown mentions (e.g. `@nope`) are left in the message
25
- * verbatim - they are plain text, not a routing signal. Matched tokens are
26
- * stripped and surrounding whitespace is collapsed, so the model sees only the
27
- * cleaned intent.
28
- *
29
- * `knownSlugs` accepts any iterable (array or `Set`); matching is
30
- * case-insensitive and the returned slugs are lower-cased.
31
- */
32
- export function parseMentions(message, knownSlugs) {
33
- const known = new Set();
34
- for (const s of knownSlugs)
35
- known.add(s.toLowerCase());
36
- const seen = new Set();
37
- const slugs = [];
38
- // Fresh regex instance so a shared `MENTION_REGEX.lastIndex` can never leak
39
- // across calls (the exported constant is global).
40
- const re = new RegExp(MENTION_REGEX.source, MENTION_REGEX.flags);
41
- const cleaned = message
42
- .replace(re, (full, lead, slug) => {
43
- const lower = slug.toLowerCase();
44
- if (!known.has(lower))
45
- return full; // unknown slug - leave intact
46
- if (!seen.has(lower)) {
47
- seen.add(lower);
48
- slugs.push(lower);
49
- }
50
- return lead === '' ? '' : ' ';
51
- })
52
- .replace(/\s{2,}/g, ' ')
53
- .trim();
54
- return { slugs, cleaned };
55
- }
56
- /**
57
- * Build the system-prompt rule injected when a message carries one or more
58
- * validated mentions. The orchestrator is instructed to call the dispatch
59
- * tool (default `run_agent({ agentSlug })`) for each mentioned agent in order,
60
- * overriding its own routing decision. Returns `null` when `slugs` is empty so
61
- * callers can `if (rule) systemPrompt += rule` without a length check.
62
- */
63
- export function buildMentionRoutingRule(slugs, opts = {}) {
64
- if (slugs.length === 0)
65
- return null;
66
- const toolName = opts.toolName ?? 'run_agent';
67
- const argKey = opts.argKey ?? 'agentSlug';
68
- if (slugs.length === 1) {
69
- const slug = slugs[0];
70
- return [
71
- '## @-mention routing (HARD RULE)',
72
- `The user explicitly invoked agent \`${slug}\` via @-mention. You MUST call \`${toolName}({ ${argKey}: "${slug}" })\` immediately with the user's request, regardless of how well the request matches that agent. Do not ask clarifying questions. Do not call other tools first. The mention has already been validated by the server.`,
73
- ].join('\n');
74
- }
75
- const list = slugs.map((s) => `\`${s}\``).join(', ');
76
- return [
77
- '## @-mention routing (HARD RULE)',
78
- `The user explicitly invoked these agents via @-mention, in order: ${list}. You MUST call \`${toolName}\` for each one in turn (passing its slug as \`${argKey}\`), passing the user's request as input. Do not ask clarifying questions between mentions. Do not call other tools first. The mentions have already been validated by the server.`,
79
- ].join('\n');
80
- }
1
+ // @rudderjs/ai is deprecated. The AI engine now lives in @gemstack/ai-sdk.
2
+ // This module re-exports it for backwards compatibility; import from
3
+ // '@gemstack/ai-sdk/chat-mentions' directly in new code.
4
+ export * from '@gemstack/ai-sdk/chat-mentions';
81
5
  //# sourceMappingURL=chat-mentions.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"chat-mentions.js","sourceRoot":"","sources":["../src/chat-mentions.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;GAkBG;AAEH,4EAA4E;AAC5E,MAAM,CAAC,MAAM,aAAa,GAAG,mCAAmC,CAAA;AAShE;;;;;;;;;GASG;AACH,MAAM,UAAU,aAAa,CAAC,OAAe,EAAE,UAA4B;IACzE,MAAM,KAAK,GAAG,IAAI,GAAG,EAAU,CAAA;IAC/B,KAAK,MAAM,CAAC,IAAI,UAAU;QAAE,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,WAAW,EAAE,CAAC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AAC,CAAC,CAAE,CAAA;QACtB,OAAO;YACL,kCAAkC;YAClC,uCAAuC,IAAI,qCAAqC,QAAQ,MAAM,MAAM,MAAM,IAAI,0NAA0N;SACzU,CAAC,IAAI,CAAC,IAAI,CAAC,CAAA;IACd,CAAC;IAED,MAAM,IAAI,GAAG,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAA;IACpD,OAAO;QACL,kCAAkC;QAClC,qEAAqE,IAAI,qBAAqB,QAAQ,kDAAkD,MAAM,oLAAoL;KACnV,CAAC,IAAI,CAAC,IAAI,CAAC,CAAA;AACd,CAAC"}
1
+ {"version":3,"file":"chat-mentions.js","sourceRoot":"","sources":["../src/chat-mentions.ts"],"names":[],"mappings":"AAAA,2EAA2E;AAC3E,qEAAqE;AACrE,yDAAyD;AACzD,cAAc,gCAAgC,CAAA"}
@@ -1,93 +1,2 @@
1
- /**
2
- * `pnpm rudder ai:eval` — discover `evals/**\/*.eval.ts` suites,
3
- * run each, and report. Console reporter by default; `--json` emits
4
- * a machine-readable envelope to stdout for CI.
5
- *
6
- * Registered from the CLI loader (`packages/cli/src/index.ts`)
7
- * — the AiProvider doesn't own this so it surfaces even when the
8
- * user app fails to boot, matching the `command:list --json`
9
- * graceful-degradation pattern from #349.
10
- */
11
- import type { EvalSuite } from '../eval/index.js';
12
- type Rudder = {
13
- command(name: string, handler: (args: string[]) => void | Promise<void>): {
14
- description(text: string): unknown;
15
- };
16
- };
17
- /** CLI flags + positional name filter. */
18
- export interface AiEvalOptions {
19
- /** Substring filter (case-insensitive) applied to suite names. */
20
- filter?: string;
21
- /** Stop on the first failing suite. */
22
- bail: boolean;
23
- /** Emit `{ suites: [...] }` JSON to stdout. */
24
- json: boolean;
25
- /**
26
- * Run against the real provider, capture each case's assistant
27
- * turns to `evals/__fixtures__/<suite>/<case>.json`. Existing
28
- * fixtures are overwritten — diff in your VCS to see what changed.
29
- * Default `false`.
30
- */
31
- record?: boolean;
32
- /**
33
- * Swap the runtime with `AiFake.fake()` and feed each case its
34
- * recorded fixture via `respondWithSequence`. Zero API calls,
35
- * deterministic regression tests. Cases without a fixture fall
36
- * through to a normal run with a stderr warning. Default `false`.
37
- */
38
- replay?: boolean;
39
- /**
40
- * Path for a self-contained HTML report (#A5 Phase 5). Pasteable
41
- * into PR comments / Slack threads. Coexists with `--json` (JSON
42
- * still goes to stdout, HTML goes to disk).
43
- */
44
- html?: string;
45
- }
46
- /**
47
- * Test seam — every external dependency gets an injectable
48
- * override. The CLI handler defaults each to its real impl.
49
- */
50
- export interface AiEvalDeps {
51
- cwd?: string;
52
- stdout?: {
53
- write(s: string): boolean | void;
54
- };
55
- stderr?: {
56
- write(s: string): boolean | void;
57
- };
58
- /** Override the file walk (test harness returns a virtual list). */
59
- discover?: (cwd: string, pattern: string) => Promise<string[]>;
60
- /** Override file → suite loader (test harness uses an in-memory map). */
61
- loadSuite?: (absPath: string) => Promise<EvalSuite | null>;
62
- /** Override config lookup (test harness skips `@rudderjs/core`). */
63
- configPattern?: () => string | null | Promise<string | null>;
64
- /**
65
- * Override fixtures directory (defaults to `<cwd>/evals/__fixtures__`).
66
- * Tests point to a tmpdir to keep round-trips off the source tree.
67
- */
68
- fixturesDir?: string;
69
- }
70
- /** Register the `ai:eval` command on the rudder runner. */
71
- export declare function registerAiEvalCommand(rudder: Rudder): void;
72
- /**
73
- * Parse the rest-of-line. Recognizes:
74
- * - boolean flags: `--bail`, `--json`, `--record`, `--replay`
75
- * - value flags : `--html <path>` or `--html=<path>`
76
- * - one positional name filter (anything not consumed above)
77
- */
78
- export declare function parseArgs(args: string[]): AiEvalOptions;
79
- /**
80
- * Execute the CLI flow. Returns the process exit code (0 = all pass,
81
- * 1 = at least one suite had a failure or no suites discovered).
82
- *
83
- * The handler is `process.exit`-free so tests can drive it directly.
84
- */
85
- export declare function runEvalCli(opts: AiEvalOptions, deps?: AiEvalDeps): Promise<number>;
86
- /**
87
- * Recursive walk constrained to a `<dir>/**\/*<suffix>` shape.
88
- * Returns absolute paths sorted lexicographically for stable test
89
- * output and predictable `--bail` ordering.
90
- */
91
- export declare function discoverSuiteFiles(cwd: string, pattern: string): Promise<string[]>;
92
- export {};
1
+ export * from '@gemstack/ai-sdk/commands/ai-eval';
93
2
  //# sourceMappingURL=ai-eval.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"ai-eval.d.ts","sourceRoot":"","sources":["../../src/commands/ai-eval.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAMH,OAAO,KAAK,EAAE,SAAS,EAAiC,MAAM,kBAAkB,CAAA;AAUhF,KAAK,MAAM,GAAG;IACZ,OAAO,CACL,IAAI,EAAE,MAAM,EACZ,OAAO,EAAE,CAAC,IAAI,EAAE,MAAM,EAAE,KAAK,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,GAChD;QAAE,WAAW,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAA;KAAE,CAAA;CAC1C,CAAA;AAED,0CAA0C;AAC1C,MAAM,WAAW,aAAa;IAC5B,kEAAkE;IAClE,MAAM,CAAC,EAAE,MAAM,CAAA;IACf,uCAAuC;IACvC,IAAI,EAAK,OAAO,CAAA;IAChB,+CAA+C;IAC/C,IAAI,EAAK,OAAO,CAAA;IAChB;;;;;OAKG;IACH,MAAM,CAAC,EAAE,OAAO,CAAA;IAChB;;;;;OAKG;IACH,MAAM,CAAC,EAAE,OAAO,CAAA;IAChB;;;;OAIG;IACH,IAAI,CAAC,EAAE,MAAM,CAAA;CACd;AAED;;;GAGG;AACH,MAAM,WAAW,UAAU;IACzB,GAAG,CAAC,EAAS,MAAM,CAAA;IACnB,MAAM,CAAC,EAAM;QAAE,KAAK,CAAC,CAAC,EAAE,MAAM,GAAG,OAAO,GAAG,IAAI,CAAA;KAAE,CAAA;IACjD,MAAM,CAAC,EAAM;QAAE,KAAK,CAAC,CAAC,EAAE,MAAM,GAAG,OA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