@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.
- package/README.md +19 -1274
- package/dist/budget-orm/index.d.ts +1 -95
- package/dist/budget-orm/index.d.ts.map +1 -1
- package/dist/budget-orm/index.js +4 -176
- package/dist/budget-orm/index.js.map +1 -1
- package/dist/chat-mentions.d.ts +1 -58
- package/dist/chat-mentions.d.ts.map +1 -1
- package/dist/chat-mentions.js +4 -80
- package/dist/chat-mentions.js.map +1 -1
- package/dist/commands/ai-eval.d.ts +1 -92
- package/dist/commands/ai-eval.d.ts.map +1 -1
- package/dist/commands/ai-eval.js +4 -377
- package/dist/commands/ai-eval.js.map +1 -1
- package/dist/commands/make-agent.d.ts +1 -2
- package/dist/commands/make-agent.d.ts.map +1 -1
- package/dist/commands/make-agent.js +4 -22
- package/dist/commands/make-agent.js.map +1 -1
- package/dist/computer-use/index.d.ts +1 -52
- package/dist/computer-use/index.d.ts.map +1 -1
- package/dist/computer-use/index.js +4 -50
- package/dist/computer-use/index.js.map +1 -1
- package/dist/conversation-orm/index.d.ts +1 -108
- package/dist/conversation-orm/index.d.ts.map +1 -1
- package/dist/conversation-orm/index.js +4 -214
- package/dist/conversation-orm/index.js.map +1 -1
- package/dist/doctor.d.ts +1 -1
- package/dist/doctor.d.ts.map +1 -1
- package/dist/doctor.js +4 -65
- package/dist/doctor.js.map +1 -1
- package/dist/eval/index.d.ts +1 -270
- package/dist/eval/index.d.ts.map +1 -1
- package/dist/eval/index.js +4 -509
- package/dist/eval/index.js.map +1 -1
- package/dist/gateway/index.d.ts +1 -10
- package/dist/gateway/index.d.ts.map +1 -1
- package/dist/gateway/index.js +4 -10
- package/dist/gateway/index.js.map +1 -1
- package/dist/index.d.ts +1 -66
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +4 -78
- package/dist/index.js.map +1 -1
- package/dist/mcp/index.d.ts +1 -15
- package/dist/mcp/index.d.ts.map +1 -1
- package/dist/mcp/index.js +4 -14
- package/dist/mcp/index.js.map +1 -1
- package/dist/memory-embedding/index.d.ts +1 -120
- package/dist/memory-embedding/index.d.ts.map +1 -1
- package/dist/memory-embedding/index.js +4 -228
- package/dist/memory-embedding/index.js.map +1 -1
- package/dist/memory-orm/index.d.ts +1 -117
- package/dist/memory-orm/index.d.ts.map +1 -1
- package/dist/memory-orm/index.js +4 -186
- package/dist/memory-orm/index.js.map +1 -1
- package/dist/node/index.d.ts +1 -2
- package/dist/node/index.d.ts.map +1 -1
- package/dist/node/index.js +4 -2
- package/dist/node/index.js.map +1 -1
- package/dist/observers.d.ts +1 -129
- package/dist/observers.d.ts.map +1 -1
- package/dist/observers.js +4 -39
- package/dist/observers.js.map +1 -1
- package/dist/react/index.d.ts +1 -15
- package/dist/react/index.d.ts.map +1 -1
- package/dist/react/index.js +4 -15
- package/dist/react/index.js.map +1 -1
- package/dist/server/index.d.ts +1 -1
- package/dist/server/index.d.ts.map +1 -1
- package/dist/server/index.js +4 -1
- package/dist/server/index.js.map +1 -1
- package/package.json +9 -13
- package/boost/guidelines.md +0 -260
- package/boost/skills/ai-agents/SKILL.md +0 -240
- package/boost/skills/ai-tools/SKILL.md +0 -260
- package/dist/agent-run-store.d.ts +0 -161
- package/dist/agent-run-store.d.ts.map +0 -1
- package/dist/agent-run-store.js +0 -98
- package/dist/agent-run-store.js.map +0 -1
- package/dist/agent-sse.d.ts +0 -153
- package/dist/agent-sse.d.ts.map +0 -1
- package/dist/agent-sse.js +0 -282
- package/dist/agent-sse.js.map +0 -1
- package/dist/agent.d.ts +0 -508
- package/dist/agent.d.ts.map +0 -1
- package/dist/agent.js +0 -1538
- package/dist/agent.js.map +0 -1
- package/dist/attachment.d.ts +0 -31
- package/dist/attachment.d.ts.map +0 -1
- package/dist/attachment.js +0 -89
- package/dist/attachment.js.map +0 -1
- package/dist/audio.d.ts +0 -45
- package/dist/audio.d.ts.map +0 -1
- package/dist/audio.js +0 -93
- package/dist/audio.js.map +0 -1
- package/dist/base64.d.ts +0 -7
- package/dist/base64.d.ts.map +0 -1
- package/dist/base64.js +0 -39
- package/dist/base64.js.map +0 -1
- package/dist/budget/pricing.d.ts +0 -124
- package/dist/budget/pricing.d.ts.map +0 -1
- package/dist/budget/pricing.js +0 -175
- package/dist/budget/pricing.js.map +0 -1
- package/dist/budget/storage.d.ts +0 -104
- package/dist/budget/storage.d.ts.map +0 -1
- package/dist/budget/storage.js +0 -0
- package/dist/budget/storage.js.map +0 -1
- package/dist/budget/with-budget.d.ts +0 -119
- package/dist/budget/with-budget.d.ts.map +0 -1
- package/dist/budget/with-budget.js +0 -175
- package/dist/budget/with-budget.js.map +0 -1
- package/dist/cached-embedding.d.ts +0 -14
- package/dist/cached-embedding.d.ts.map +0 -1
- package/dist/cached-embedding.js +0 -44
- package/dist/cached-embedding.js.map +0 -1
- package/dist/computer-use/actions.d.ts +0 -214
- package/dist/computer-use/actions.d.ts.map +0 -1
- package/dist/computer-use/actions.js +0 -48
- package/dist/computer-use/actions.js.map +0 -1
- package/dist/computer-use/errors.d.ts +0 -57
- package/dist/computer-use/errors.d.ts.map +0 -1
- package/dist/computer-use/errors.js +0 -76
- package/dist/computer-use/errors.js.map +0 -1
- package/dist/computer-use/playwright.d.ts +0 -76
- package/dist/computer-use/playwright.d.ts.map +0 -1
- package/dist/computer-use/playwright.js +0 -270
- package/dist/computer-use/playwright.js.map +0 -1
- package/dist/computer-use/tool.d.ts +0 -154
- package/dist/computer-use/tool.d.ts.map +0 -1
- package/dist/computer-use/tool.js +0 -210
- package/dist/computer-use/tool.js.map +0 -1
- package/dist/continuation-validation.d.ts +0 -85
- package/dist/continuation-validation.d.ts.map +0 -1
- package/dist/continuation-validation.js +0 -166
- package/dist/continuation-validation.js.map +0 -1
- package/dist/conversation-persistence.d.ts +0 -46
- package/dist/conversation-persistence.d.ts.map +0 -1
- package/dist/conversation-persistence.js +0 -176
- package/dist/conversation-persistence.js.map +0 -1
- package/dist/conversation.d.ts +0 -11
- package/dist/conversation.d.ts.map +0 -1
- package/dist/conversation.js +0 -55
- package/dist/conversation.js.map +0 -1
- package/dist/eval/fixtures.d.ts +0 -65
- package/dist/eval/fixtures.d.ts.map +0 -1
- package/dist/eval/fixtures.js +0 -110
- package/dist/eval/fixtures.js.map +0 -1
- package/dist/eval/html-reporter.d.ts +0 -25
- package/dist/eval/html-reporter.d.ts.map +0 -1
- package/dist/eval/html-reporter.js +0 -209
- package/dist/eval/html-reporter.js.map +0 -1
- package/dist/eval/json-reporter.d.ts +0 -43
- package/dist/eval/json-reporter.d.ts.map +0 -1
- package/dist/eval/json-reporter.js +0 -40
- package/dist/eval/json-reporter.js.map +0 -1
- package/dist/facade.d.ts +0 -96
- package/dist/facade.d.ts.map +0 -1
- package/dist/facade.js +0 -146
- package/dist/facade.js.map +0 -1
- package/dist/fake.d.ts +0 -201
- package/dist/fake.d.ts.map +0 -1
- package/dist/fake.js +0 -428
- package/dist/fake.js.map +0 -1
- package/dist/file-search.d.ts +0 -168
- package/dist/file-search.d.ts.map +0 -1
- package/dist/file-search.js +0 -158
- package/dist/file-search.js.map +0 -1
- package/dist/files.d.ts +0 -27
- package/dist/files.d.ts.map +0 -1
- package/dist/files.js +0 -44
- package/dist/files.js.map +0 -1
- package/dist/gateway/http-gateway-adapter.d.ts +0 -94
- package/dist/gateway/http-gateway-adapter.d.ts.map +0 -1
- package/dist/gateway/http-gateway-adapter.js +0 -106
- package/dist/gateway/http-gateway-adapter.js.map +0 -1
- package/dist/gateway/sse.d.ts +0 -28
- package/dist/gateway/sse.d.ts.map +0 -1
- package/dist/gateway/sse.js +0 -78
- package/dist/gateway/sse.js.map +0 -1
- package/dist/handoff.d.ts +0 -95
- package/dist/handoff.d.ts.map +0 -1
- package/dist/handoff.js +0 -78
- package/dist/handoff.js.map +0 -1
- package/dist/handoffs-driver.d.ts +0 -58
- package/dist/handoffs-driver.d.ts.map +0 -1
- package/dist/handoffs-driver.js +0 -103
- package/dist/handoffs-driver.js.map +0 -1
- package/dist/image.d.ts +0 -40
- package/dist/image.d.ts.map +0 -1
- package/dist/image.js +0 -109
- package/dist/image.js.map +0 -1
- package/dist/mcp/client-tools.d.ts +0 -39
- package/dist/mcp/client-tools.d.ts.map +0 -1
- package/dist/mcp/client-tools.js +0 -147
- package/dist/mcp/client-tools.js.map +0 -1
- package/dist/mcp/server-from-agent.d.ts +0 -24
- package/dist/mcp/server-from-agent.d.ts.map +0 -1
- package/dist/mcp/server-from-agent.js +0 -113
- package/dist/mcp/server-from-agent.js.map +0 -1
- package/dist/mcp/types.d.ts +0 -64
- package/dist/mcp/types.d.ts.map +0 -1
- package/dist/mcp/types.js +0 -6
- package/dist/mcp/types.js.map +0 -1
- package/dist/memory-extract.d.ts +0 -60
- package/dist/memory-extract.d.ts.map +0 -1
- package/dist/memory-extract.js +0 -163
- package/dist/memory-extract.js.map +0 -1
- package/dist/memory-inject.d.ts +0 -39
- package/dist/memory-inject.d.ts.map +0 -1
- package/dist/memory-inject.js +0 -135
- package/dist/memory-inject.js.map +0 -1
- package/dist/memory.d.ts +0 -55
- package/dist/memory.d.ts.map +0 -1
- package/dist/memory.js +0 -132
- package/dist/memory.js.map +0 -1
- package/dist/middleware.d.ts +0 -18
- package/dist/middleware.d.ts.map +0 -1
- package/dist/middleware.js +0 -72
- package/dist/middleware.js.map +0 -1
- package/dist/node/attachment.d.ts +0 -6
- package/dist/node/attachment.d.ts.map +0 -1
- package/dist/node/attachment.js +0 -35
- package/dist/node/attachment.js.map +0 -1
- package/dist/node/transcription.d.ts +0 -4
- package/dist/node/transcription.d.ts.map +0 -1
- package/dist/node/transcription.js +0 -8
- package/dist/node/transcription.js.map +0 -1
- package/dist/output.d.ts +0 -22
- package/dist/output.d.ts.map +0 -1
- package/dist/output.js +0 -60
- package/dist/output.js.map +0 -1
- package/dist/provider-tools.d.ts +0 -87
- package/dist/provider-tools.d.ts.map +0 -1
- package/dist/provider-tools.js +0 -189
- package/dist/provider-tools.js.map +0 -1
- package/dist/providers/anthropic.d.ts +0 -24
- package/dist/providers/anthropic.d.ts.map +0 -1
- package/dist/providers/anthropic.js +0 -405
- package/dist/providers/anthropic.js.map +0 -1
- package/dist/providers/azure.d.ts +0 -13
- package/dist/providers/azure.d.ts.map +0 -1
- package/dist/providers/azure.js +0 -15
- package/dist/providers/azure.js.map +0 -1
- package/dist/providers/bedrock.d.ts +0 -75
- package/dist/providers/bedrock.d.ts.map +0 -1
- package/dist/providers/bedrock.js +0 -181
- package/dist/providers/bedrock.js.map +0 -1
- package/dist/providers/cohere.d.ts +0 -13
- package/dist/providers/cohere.d.ts.map +0 -1
- package/dist/providers/cohere.js +0 -87
- package/dist/providers/cohere.js.map +0 -1
- package/dist/providers/deepseek.d.ts +0 -12
- package/dist/providers/deepseek.d.ts.map +0 -1
- package/dist/providers/deepseek.js +0 -15
- package/dist/providers/deepseek.js.map +0 -1
- package/dist/providers/elevenlabs.d.ts +0 -98
- package/dist/providers/elevenlabs.d.ts.map +0 -1
- package/dist/providers/elevenlabs.js +0 -229
- package/dist/providers/elevenlabs.js.map +0 -1
- package/dist/providers/google-cache-registry.d.ts +0 -132
- package/dist/providers/google-cache-registry.d.ts.map +0 -1
- package/dist/providers/google-cache-registry.js +0 -209
- package/dist/providers/google-cache-registry.js.map +0 -1
- package/dist/providers/google.d.ts +0 -38
- package/dist/providers/google.d.ts.map +0 -1
- package/dist/providers/google.js +0 -903
- package/dist/providers/google.js.map +0 -1
- package/dist/providers/groq.d.ts +0 -12
- package/dist/providers/groq.d.ts.map +0 -1
- package/dist/providers/groq.js +0 -15
- package/dist/providers/groq.js.map +0 -1
- package/dist/providers/jina.d.ts +0 -13
- package/dist/providers/jina.d.ts.map +0 -1
- package/dist/providers/jina.js +0 -90
- package/dist/providers/jina.js.map +0 -1
- package/dist/providers/mistral.d.ts +0 -13
- package/dist/providers/mistral.d.ts.map +0 -1
- package/dist/providers/mistral.js +0 -46
- package/dist/providers/mistral.js.map +0 -1
- package/dist/providers/ollama.d.ts +0 -11
- package/dist/providers/ollama.d.ts.map +0 -1
- package/dist/providers/ollama.js +0 -15
- package/dist/providers/ollama.js.map +0 -1
- package/dist/providers/openai.d.ts +0 -79
- package/dist/providers/openai.d.ts.map +0 -1
- package/dist/providers/openai.js +0 -792
- package/dist/providers/openai.js.map +0 -1
- package/dist/providers/openrouter.d.ts +0 -43
- package/dist/providers/openrouter.d.ts.map +0 -1
- package/dist/providers/openrouter.js +0 -21
- package/dist/providers/openrouter.js.map +0 -1
- package/dist/providers/voyage.d.ts +0 -91
- package/dist/providers/voyage.d.ts.map +0 -1
- package/dist/providers/voyage.js +0 -166
- package/dist/providers/voyage.js.map +0 -1
- package/dist/providers/xai.d.ts +0 -12
- package/dist/providers/xai.d.ts.map +0 -1
- package/dist/providers/xai.js +0 -15
- package/dist/providers/xai.js.map +0 -1
- package/dist/queue-job.d.ts +0 -100
- package/dist/queue-job.d.ts.map +0 -1
- package/dist/queue-job.js +0 -185
- package/dist/queue-job.js.map +0 -1
- package/dist/react/agent-run.d.ts +0 -111
- package/dist/react/agent-run.d.ts.map +0 -1
- package/dist/react/agent-run.js +0 -107
- package/dist/react/agent-run.js.map +0 -1
- package/dist/react/useAgentRun.d.ts +0 -68
- package/dist/react/useAgentRun.d.ts.map +0 -1
- package/dist/react/useAgentRun.js +0 -125
- package/dist/react/useAgentRun.js.map +0 -1
- package/dist/registry.d.ts +0 -45
- package/dist/registry.d.ts.map +0 -1
- package/dist/registry.js +0 -131
- package/dist/registry.js.map +0 -1
- package/dist/rerank.d.ts +0 -20
- package/dist/rerank.d.ts.map +0 -1
- package/dist/rerank.js +0 -40
- package/dist/rerank.js.map +0 -1
- package/dist/resume-approval.d.ts +0 -30
- package/dist/resume-approval.d.ts.map +0 -1
- package/dist/resume-approval.js +0 -147
- package/dist/resume-approval.js.map +0 -1
- package/dist/sanitize-conversation.d.ts +0 -43
- package/dist/sanitize-conversation.d.ts.map +0 -1
- package/dist/sanitize-conversation.js +0 -85
- package/dist/sanitize-conversation.js.map +0 -1
- package/dist/scoped-tool.d.ts +0 -98
- package/dist/scoped-tool.d.ts.map +0 -1
- package/dist/scoped-tool.js +0 -174
- package/dist/scoped-tool.js.map +0 -1
- package/dist/server/provider.d.ts +0 -22
- package/dist/server/provider.d.ts.map +0 -1
- package/dist/server/provider.js +0 -194
- package/dist/server/provider.js.map +0 -1
- package/dist/similarity-search.d.ts +0 -163
- package/dist/similarity-search.d.ts.map +0 -1
- package/dist/similarity-search.js +0 -147
- package/dist/similarity-search.js.map +0 -1
- package/dist/sub-agent-run-store.d.ts +0 -157
- package/dist/sub-agent-run-store.d.ts.map +0 -1
- package/dist/sub-agent-run-store.js +0 -87
- package/dist/sub-agent-run-store.js.map +0 -1
- package/dist/tool-execution.d.ts +0 -16
- package/dist/tool-execution.d.ts.map +0 -1
- package/dist/tool-execution.js +0 -498
- package/dist/tool-execution.js.map +0 -1
- package/dist/tool-helpers.d.ts +0 -77
- package/dist/tool-helpers.d.ts.map +0 -1
- package/dist/tool-helpers.js +0 -117
- package/dist/tool-helpers.js.map +0 -1
- package/dist/tool.d.ts +0 -216
- package/dist/tool.d.ts.map +0 -1
- package/dist/tool.js +0 -175
- package/dist/tool.js.map +0 -1
- package/dist/transcription.d.ts +0 -42
- package/dist/transcription.d.ts.map +0 -1
- package/dist/transcription.js +0 -77
- package/dist/transcription.js.map +0 -1
- package/dist/types.d.ts +0 -1020
- package/dist/types.d.ts.map +0 -1
- package/dist/types.js +0 -2
- package/dist/types.js.map +0 -1
- package/dist/util/hash.d.ts +0 -11
- package/dist/util/hash.d.ts.map +0 -1
- package/dist/util/hash.js +0 -23
- package/dist/util/hash.js.map +0 -1
- package/dist/vector-stores/index.d.ts +0 -96
- package/dist/vector-stores/index.d.ts.map +0 -1
- package/dist/vector-stores/index.js +0 -153
- package/dist/vector-stores/index.js.map +0 -1
- package/dist/vercel-protocol.d.ts +0 -18
- package/dist/vercel-protocol.d.ts.map +0 -1
- package/dist/vercel-protocol.js +0 -75
- package/dist/vercel-protocol.js.map +0 -1
- package/dist/zod-to-json-schema.d.ts +0 -16
- package/dist/zod-to-json-schema.d.ts.map +0 -1
- package/dist/zod-to-json-schema.js +0 -17
- 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":"
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/budget-orm/index.ts"],"names":[],"mappings":"AAGA,cAAc,6BAA6B,CAAA"}
|
package/dist/budget-orm/index.js
CHANGED
|
@@ -1,177 +1,5 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
*
|
|
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
|
|
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"}
|
package/dist/chat-mentions.d.ts
CHANGED
|
@@ -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":"
|
|
1
|
+
{"version":3,"file":"chat-mentions.d.ts","sourceRoot":"","sources":["../src/chat-mentions.ts"],"names":[],"mappings":"AAGA,cAAc,gCAAgC,CAAA"}
|
package/dist/chat-mentions.js
CHANGED
|
@@ -1,81 +1,5 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
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
|
|
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":"
|
|
1
|
+
{"version":3,"file":"ai-eval.d.ts","sourceRoot":"","sources":["../../src/commands/ai-eval.ts"],"names":[],"mappings":"AAGA,cAAc,mCAAmC,CAAA"}
|