@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
package/dist/tool-helpers.js
DELETED
|
@@ -1,117 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Detect an async generator (the value returned by `async function*` or any
|
|
3
|
-
* object implementing the AsyncGenerator protocol). We use a structural check
|
|
4
|
-
* because the executor may not be authored as a literal `async function*`
|
|
5
|
-
* (e.g. wrapped or returned from a factory).
|
|
6
|
-
*/
|
|
7
|
-
export function isAsyncGenerator(value) {
|
|
8
|
-
if (value === null || typeof value !== 'object')
|
|
9
|
-
return false;
|
|
10
|
-
const v = value;
|
|
11
|
-
return typeof v.next === 'function'
|
|
12
|
-
&& typeof v.return === 'function'
|
|
13
|
-
&& typeof v[Symbol.asyncIterator] === 'function';
|
|
14
|
-
}
|
|
15
|
-
/**
|
|
16
|
-
* Uniformly iterate a tool's `execute`, whether it returns a value, a
|
|
17
|
-
* promise, or an async generator.
|
|
18
|
-
*
|
|
19
|
-
* The helper is itself an async generator: each `yield` is a preliminary
|
|
20
|
-
* tool-update payload (only generator-style executes produce these), and the
|
|
21
|
-
* generator's `return` value is the final tool result.
|
|
22
|
-
*
|
|
23
|
-
* Streaming callers iterate and emit `tool-update` chunks live as updates
|
|
24
|
-
* arrive. Non-streaming callers iterate and discard yields, capturing only
|
|
25
|
-
* the final return value — same tool definition works in both modes.
|
|
26
|
-
*/
|
|
27
|
-
export async function* executeMaybeStreaming(tool, args, ctx) {
|
|
28
|
-
const execute = tool.execute;
|
|
29
|
-
if (!execute) {
|
|
30
|
-
throw new Error('Tool has no execute function');
|
|
31
|
-
}
|
|
32
|
-
const ret = execute(args, ctx);
|
|
33
|
-
if (isAsyncGenerator(ret)) {
|
|
34
|
-
while (true) {
|
|
35
|
-
const step = await ret.next();
|
|
36
|
-
if (step.done)
|
|
37
|
-
return step.value;
|
|
38
|
-
yield step.value;
|
|
39
|
-
}
|
|
40
|
-
}
|
|
41
|
-
return await ret;
|
|
42
|
-
}
|
|
43
|
-
/**
|
|
44
|
-
* Validate a tool call's arguments against the tool's `inputSchema`. On
|
|
45
|
-
* success, the parsed value is returned — zod transforms (`.transform`,
|
|
46
|
-
* `.default`, type coercion) are applied, so `execute` receives the
|
|
47
|
-
* canonical shape the schema describes. On failure, a structured error
|
|
48
|
-
* suitable for feeding back to the model is returned.
|
|
49
|
-
*/
|
|
50
|
-
export function validateToolArgs(tool, args) {
|
|
51
|
-
const parsed = tool.definition.inputSchema.safeParse(args);
|
|
52
|
-
if (parsed.success) {
|
|
53
|
-
return { ok: true, value: parsed.data };
|
|
54
|
-
}
|
|
55
|
-
return {
|
|
56
|
-
ok: false,
|
|
57
|
-
error: {
|
|
58
|
-
error: 'invalid_arguments',
|
|
59
|
-
message: `Tool "${tool.definition.name}" received arguments that did not match its inputSchema.`,
|
|
60
|
-
issues: parsed.error.issues.map(i => ({
|
|
61
|
-
path: i.path.map(seg => String(seg)).join('.'),
|
|
62
|
-
message: i.message,
|
|
63
|
-
})),
|
|
64
|
-
},
|
|
65
|
-
};
|
|
66
|
-
}
|
|
67
|
-
/**
|
|
68
|
-
* Default stringification used for the `tool` role message content when a
|
|
69
|
-
* tool has no `toModelOutput` transform: pass through strings, JSON-encode
|
|
70
|
-
* everything else.
|
|
71
|
-
*/
|
|
72
|
-
export function defaultStringify(value) {
|
|
73
|
-
return typeof value === 'string' ? value : JSON.stringify(value);
|
|
74
|
-
}
|
|
75
|
-
/**
|
|
76
|
-
* Convert a tool's structured `result` into the string the **model** will
|
|
77
|
-
* see on its next step. Honors `tool.toModelOutput` when present, falling
|
|
78
|
-
* back to {@link defaultStringify}.
|
|
79
|
-
*
|
|
80
|
-
* Per R6 in the ai-loop-parity plan: a throwing `toModelOutput` MUST NOT
|
|
81
|
-
* crash the loop. We swallow the error, route it through `onError`
|
|
82
|
-
* middleware so it stays observable, and use the default stringification
|
|
83
|
-
* as a safety net.
|
|
84
|
-
*/
|
|
85
|
-
export async function applyToModelOutput(tool, result, onError) {
|
|
86
|
-
if (tool.toModelOutput) {
|
|
87
|
-
try {
|
|
88
|
-
return await tool.toModelOutput(result);
|
|
89
|
-
}
|
|
90
|
-
catch (err) {
|
|
91
|
-
if (onError)
|
|
92
|
-
await onError(err);
|
|
93
|
-
}
|
|
94
|
-
}
|
|
95
|
-
return defaultStringify(result);
|
|
96
|
-
}
|
|
97
|
-
/**
|
|
98
|
-
* Resolve `needsApproval` for a tool call, taking into account the
|
|
99
|
-
* client-supplied `approvedToolCallIds` / `rejectedToolCallIds` lists.
|
|
100
|
-
*
|
|
101
|
-
* Returns:
|
|
102
|
-
* - `'allow'` — execute the tool normally (default; also when approved)
|
|
103
|
-
* - `'pending'` — needsApproval is truthy and the call has not been approved
|
|
104
|
-
* - `'rejected'` — the call appears in `rejectedToolCallIds`
|
|
105
|
-
*/
|
|
106
|
-
export async function evaluateApproval(tool, tc, options) {
|
|
107
|
-
const needs = tool.definition.needsApproval;
|
|
108
|
-
const requires = typeof needs === 'function' ? await needs(tc.arguments) : !!needs;
|
|
109
|
-
if (!requires)
|
|
110
|
-
return 'allow';
|
|
111
|
-
if (options?.rejectedToolCallIds?.includes(tc.id))
|
|
112
|
-
return 'rejected';
|
|
113
|
-
if (options?.approvedToolCallIds?.includes(tc.id))
|
|
114
|
-
return 'allow';
|
|
115
|
-
return 'pending';
|
|
116
|
-
}
|
|
117
|
-
//# sourceMappingURL=tool-helpers.js.map
|
package/dist/tool-helpers.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"tool-helpers.js","sourceRoot":"","sources":["../src/tool-helpers.ts"],"names":[],"mappings":"AAEA;;;;;GAKG;AACH,MAAM,UAAU,gBAAgB,CAAC,KAAc;IAC7C,IAAI,KAAK,KAAK,IAAI,IAAI,OAAO,KAAK,KAAK,QAAQ;QAAE,OAAO,KAAK,CAAA;IAC7D,MAAM,CA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AK,CAAA;IAClF,IAAI,CAAC,QAAQ;QAAE,OAAO,OAAO,CAAA;IAE7B,IAAI,OAAO,EAAE,mBAAmB,EAAE,QAAQ,CAAC,EAAE,CAAC,EAAE,CAAC;QAAE,OAAO,UAAU,CAAA;IACpE,IAAI,OAAO,EAAE,mBAAmB,EAAE,QAAQ,CAAC,EAAE,CAAC,EAAE,CAAC;QAAE,OAAO,OAAO,CAAA;IACjE,OAAO,SAAS,CAAA;AAClB,CAAC"}
|
package/dist/tool.d.ts
DELETED
|
@@ -1,216 +0,0 @@
|
|
|
1
|
-
import type { z } from 'zod';
|
|
2
|
-
import type { Tool, ToolCall, ToolCallContext, ToolDefinitionOptions, ToolDefinitionSchema, ToolExecuteFn } from './types.js';
|
|
3
|
-
/**
|
|
4
|
-
* Control chunk a server tool can `yield` from an `async function*`
|
|
5
|
-
* execute to pause the enclosing agent loop and surface a set of CLIENT
|
|
6
|
-
* tool calls to the caller — as if the model itself had emitted them.
|
|
7
|
-
*
|
|
8
|
-
* This is the sanctioned way for a server tool to inject client-tool
|
|
9
|
-
* calls into the parent loop's pending list. The agent loop iterating
|
|
10
|
-
* the execute generator recognizes the shape via the reserved `__rudderjs`
|
|
11
|
-
* discriminator, appends `toolCalls` to the parent's
|
|
12
|
-
* `pendingClientToolCalls`, sets the stop-for-client-tools flag, and —
|
|
13
|
-
* critically — does NOT push an error tool_result / tool message for the
|
|
14
|
-
* yielding tool call. The yielding tool's own call remains orphaned in
|
|
15
|
-
* the parent's message history until the caller resolves it on
|
|
16
|
-
* continuation (typically by computing a final result from whatever the
|
|
17
|
-
* client-side tool execution returned).
|
|
18
|
-
*
|
|
19
|
-
* Why a yield instead of a throw:
|
|
20
|
-
* - Symmetry with the existing `tool-update` yield protocol — no parallel
|
|
21
|
-
* catch-based control path.
|
|
22
|
-
* - Middleware can observe pauses through `runOnChunk`; a thrown error
|
|
23
|
-
* would route through `onError` and muddle telemetry.
|
|
24
|
-
* - Exceptions signal "something went wrong"; this is not an error.
|
|
25
|
-
* - Platform-level feature: any server tool can yield this, not just
|
|
26
|
-
* nested agent runners. E.g., a tool that wants the browser's
|
|
27
|
-
* geolocation, clipboard, or a user file upload.
|
|
28
|
-
*
|
|
29
|
-
* **Primary use case today:** nested agent runners (`run_agent` in
|
|
30
|
-
* panels). A runner that streams a sub-agent server-side can hit a pause
|
|
31
|
-
* point when the sub-agent's model calls a client tool. Those calls have
|
|
32
|
-
* to execute in the browser, not server-side, so the parent loop must
|
|
33
|
-
* surface them to its own caller.
|
|
34
|
-
*
|
|
35
|
-
* Tools that yield this chunk are responsible for persisting any state
|
|
36
|
-
* they need to resume the inner work on continuation (usually in a cache
|
|
37
|
-
* or runStore). `@rudderjs/ai` does not know or care about that state —
|
|
38
|
-
* it just propagates the pause. The optional `resumeHandle` is an opaque
|
|
39
|
-
* string the tool author owns; the agent loop never inspects it.
|
|
40
|
-
*
|
|
41
|
-
* Tool authors should construct this via {@link pauseForClientTools},
|
|
42
|
-
* not by hand, so future shape changes stay source-compatible.
|
|
43
|
-
*/
|
|
44
|
-
export interface PauseForClientToolsChunk {
|
|
45
|
-
/** Reserved discriminator. Namespaced to avoid colliding with user data. */
|
|
46
|
-
readonly __rudderjs: 'pause_for_client_tools';
|
|
47
|
-
readonly toolCalls: ToolCall[];
|
|
48
|
-
readonly resumeHandle?: string;
|
|
49
|
-
}
|
|
50
|
-
/**
|
|
51
|
-
* Construct a pause control chunk for `yield`ing from a server tool's
|
|
52
|
-
* async-generator execute.
|
|
53
|
-
*
|
|
54
|
-
* @example
|
|
55
|
-
* .server(async function* (input, ctx) {
|
|
56
|
-
* const subRunId = await persistSubRunState(...)
|
|
57
|
-
* yield pauseForClientTools(subAgentPending, subRunId)
|
|
58
|
-
* // Unreachable — the loop halts iteration after the pause chunk.
|
|
59
|
-
* return undefined as never
|
|
60
|
-
* })
|
|
61
|
-
*/
|
|
62
|
-
export declare function pauseForClientTools(toolCalls: ToolCall[], resumeHandle?: string): PauseForClientToolsChunk;
|
|
63
|
-
/**
|
|
64
|
-
* Structural typeguard for a pause chunk. Used by the agent loop to
|
|
65
|
-
* detect pauses mid-execute without requiring tool authors to import any
|
|
66
|
-
* `@rudderjs/ai` symbol at the yield site — they can yield via
|
|
67
|
-
* {@link pauseForClientTools} or construct the object literal directly.
|
|
68
|
-
*/
|
|
69
|
-
export declare function isPauseForClientToolsChunk(value: unknown): value is PauseForClientToolsChunk;
|
|
70
|
-
/**
|
|
71
|
-
* Control chunk a server tool can `yield` to pause the enclosing agent
|
|
72
|
-
* loop on an APPROVAL gate inside a sub-agent — the sibling of
|
|
73
|
-
* {@link PauseForClientToolsChunk} for the
|
|
74
|
-
* `finishReason === 'tool_approval_required'` case.
|
|
75
|
-
*
|
|
76
|
-
* The agent loop iterating the execute generator recognizes the shape
|
|
77
|
-
* via the reserved `__rudderjs` discriminator, sets
|
|
78
|
-
* `loopCtx.pendingApprovalToolCall` from `toolCall`/`isClientTool`,
|
|
79
|
-
* flips `loopCtx.loopFinishReason = 'tool_approval_required'` and
|
|
80
|
-
* `loopCtx.stopForApproval = true`, and SKIPS the tool_result emission
|
|
81
|
-
* for the yielding tool call — the sub-agent's call stays orphaned in
|
|
82
|
-
* the parent message history until the approve/reject decision arrives
|
|
83
|
-
* via {@link Agent.resumeAsTool}.
|
|
84
|
-
*
|
|
85
|
-
* The optional `resumeHandle` (typically the `subRunId` the wrapper just
|
|
86
|
-
* persisted) is opaque to the framework — tool authors own the lookup.
|
|
87
|
-
*
|
|
88
|
-
* **Primary use case:** a sub-agent surfaced through
|
|
89
|
-
* {@link Agent.asTool} whose model invokes a `.requireApproval(true)`
|
|
90
|
-
* tool. The sub-agent loop emits `pending-approval`, the wrapping
|
|
91
|
-
* `asTool` generator persists a snapshot with `pauseKind: 'approval'`
|
|
92
|
-
* and yields this chunk so the parent loop halts the same way it does
|
|
93
|
-
* for client-tool pauses.
|
|
94
|
-
*
|
|
95
|
-
* Tool authors should construct this via {@link pauseForApproval}, not
|
|
96
|
-
* by hand, so future shape changes stay source-compatible.
|
|
97
|
-
*/
|
|
98
|
-
export interface PauseForApprovalChunk {
|
|
99
|
-
/** Reserved discriminator. Namespaced to avoid colliding with user data. */
|
|
100
|
-
readonly __rudderjs: 'pause_for_approval';
|
|
101
|
-
readonly toolCall: ToolCall;
|
|
102
|
-
/**
|
|
103
|
-
* `true` when the gated call is a client tool (no `execute` on the
|
|
104
|
-
* server side); `false` for a server tool the sub-agent would have
|
|
105
|
-
* run if approval had been granted.
|
|
106
|
-
*/
|
|
107
|
-
readonly isClientTool: boolean;
|
|
108
|
-
readonly resumeHandle?: string;
|
|
109
|
-
}
|
|
110
|
-
/**
|
|
111
|
-
* Construct an approval-pause control chunk for `yield`ing from a server
|
|
112
|
-
* tool's async-generator execute.
|
|
113
|
-
*
|
|
114
|
-
* @example
|
|
115
|
-
* .server(async function* (input, ctx) {
|
|
116
|
-
* const subRunId = await persistSubRunState(...)
|
|
117
|
-
* yield pauseForApproval(innerToolCall, isClientTool, subRunId)
|
|
118
|
-
* return undefined as never
|
|
119
|
-
* })
|
|
120
|
-
*/
|
|
121
|
-
export declare function pauseForApproval(toolCall: ToolCall, isClientTool: boolean, resumeHandle?: string): PauseForApprovalChunk;
|
|
122
|
-
/**
|
|
123
|
-
* Structural typeguard for an approval-pause chunk. Mirrors
|
|
124
|
-
* {@link isPauseForClientToolsChunk} so the parent loop can recognize a
|
|
125
|
-
* pause without forcing tool authors to import any `@rudderjs/ai` symbol
|
|
126
|
-
* at the yield site.
|
|
127
|
-
*/
|
|
128
|
-
export declare function isPauseForApprovalChunk(value: unknown): value is PauseForApprovalChunk;
|
|
129
|
-
/**
|
|
130
|
-
* Builder returned by {@link toolDefinition}. The builder itself is a valid
|
|
131
|
-
* `Tool` — call `.server(execute)` to attach a server-side handler, or use
|
|
132
|
-
* the builder as-is to register a client tool (no `execute`).
|
|
133
|
-
*/
|
|
134
|
-
export declare class ToolBuilder<TInput extends z.ZodType = z.ZodType, TOutput extends z.ZodType = z.ZodType> implements Tool<z.infer<TInput>, never> {
|
|
135
|
-
readonly options: ToolDefinitionOptions<TInput, TOutput>;
|
|
136
|
-
readonly definition: ToolDefinitionOptions;
|
|
137
|
-
/** Builders are valid client tools — `execute` is intentionally absent. */
|
|
138
|
-
readonly execute?: undefined;
|
|
139
|
-
constructor(options: ToolDefinitionOptions<TInput, TOutput>);
|
|
140
|
-
/**
|
|
141
|
-
* Attach a server-side handler.
|
|
142
|
-
*
|
|
143
|
-
* The handler may be a regular async function (single return value) or an
|
|
144
|
-
* async generator (`async function*`). Generators can `yield` preliminary
|
|
145
|
-
* progress payloads — each yield surfaces as a `tool-update` stream chunk
|
|
146
|
-
* while the tool runs. The generator's `return` value becomes the final
|
|
147
|
-
* tool result. The same tool definition works in both `agent.prompt()`
|
|
148
|
-
* (yields are silently drained) and `agent.stream()`.
|
|
149
|
-
*/
|
|
150
|
-
server<TReturn = unknown, TUpdate = unknown>(execute: (input: z.infer<TInput>, ctx?: ToolCallContext) => AsyncGenerator<TUpdate, TReturn, void>): ServerToolBuilder<z.infer<TInput>, TReturn>;
|
|
151
|
-
server<TReturn = unknown>(execute: (input: z.infer<TInput>, ctx?: ToolCallContext) => TReturn | Promise<TReturn>): ServerToolBuilder<z.infer<TInput>, TReturn>;
|
|
152
|
-
/** Convert to provider-friendly JSON Schema format */
|
|
153
|
-
toSchema(): ToolDefinitionSchema;
|
|
154
|
-
}
|
|
155
|
-
/**
|
|
156
|
-
* Builder returned by {@link ToolBuilder.server}. Itself a valid `Tool`, so
|
|
157
|
-
* it can be passed directly into `tools()` arrays — `.toModelOutput(...)` is
|
|
158
|
-
* an optional chained refinement, not a required `.build()` step.
|
|
159
|
-
*
|
|
160
|
-
* Future per-tool refinements (`.onError(...)`, `.middleware(...)`) would slot
|
|
161
|
-
* in here in the same chained-builder style.
|
|
162
|
-
*/
|
|
163
|
-
export declare class ServerToolBuilder<TInput = unknown, TOutput = unknown> implements Tool<TInput, TOutput> {
|
|
164
|
-
readonly definition: ToolDefinitionOptions;
|
|
165
|
-
readonly execute: ToolExecuteFn<TInput, TOutput, unknown>;
|
|
166
|
-
readonly toModelOutput?: ((result: TOutput) => string | Promise<string>) | undefined;
|
|
167
|
-
constructor(definition: ToolDefinitionOptions, execute: ToolExecuteFn<TInput, TOutput, unknown>, toModelOutput?: (result: TOutput) => string | Promise<string>);
|
|
168
|
-
/**
|
|
169
|
-
* Declare a transform from this tool's structured result to the string the
|
|
170
|
-
* **model** sees on its next step. The UI continues to receive the original
|
|
171
|
-
* structured result.
|
|
172
|
-
*
|
|
173
|
-
* @example
|
|
174
|
-
* toolDefinition({...})
|
|
175
|
-
* .server(async (input) => bigStructuredResult)
|
|
176
|
-
* .modelOutput((result) => `${result.items.length} items found`)
|
|
177
|
-
*/
|
|
178
|
-
modelOutput(fn: (result: TOutput) => string | Promise<string>): ServerToolBuilder<TInput, TOutput>;
|
|
179
|
-
}
|
|
180
|
-
/**
|
|
181
|
-
* Define a tool with typed input/output schemas.
|
|
182
|
-
*
|
|
183
|
-
* @example Server tool
|
|
184
|
-
* const weatherTool = toolDefinition({
|
|
185
|
-
* name: 'get_weather',
|
|
186
|
-
* description: 'Get weather for a location',
|
|
187
|
-
* inputSchema: z.object({ location: z.string() }),
|
|
188
|
-
* }).server(async ({ location }) => ({ temp: 72, unit: 'F' }))
|
|
189
|
-
*
|
|
190
|
-
* @example Client tool (no `.server()`)
|
|
191
|
-
* const readFormStateTool = toolDefinition({
|
|
192
|
-
* name: 'read_form_state',
|
|
193
|
-
* description: 'Read the user\'s current local form values.',
|
|
194
|
-
* inputSchema: z.object({ fields: z.array(z.string()).optional() }),
|
|
195
|
-
* })
|
|
196
|
-
*/
|
|
197
|
-
export declare function toolDefinition<TInput extends z.ZodType, TOutput extends z.ZodType = z.ZodUndefined>(options: ToolDefinitionOptions<TInput, TOutput>): ToolBuilder<TInput, TOutput>;
|
|
198
|
-
/**
|
|
199
|
-
* Build a tool whose input/output types are not known at compile time.
|
|
200
|
-
*
|
|
201
|
-
* Use this when the tool's schema is constructed dynamically from user data
|
|
202
|
-
* (e.g. a resource agent that exposes one tool per agent definition).
|
|
203
|
-
*
|
|
204
|
-
* @example
|
|
205
|
-
* const t = dynamicTool({
|
|
206
|
-
* name: agentDef.slug,
|
|
207
|
-
* description: agentDef.description,
|
|
208
|
-
* inputSchema: z.object({}),
|
|
209
|
-
* }).server(async () => agentDef.run())
|
|
210
|
-
*/
|
|
211
|
-
export declare function dynamicTool(options: ToolDefinitionOptions): ToolBuilder;
|
|
212
|
-
/** Convert any Tool to a ToolDefinitionSchema for provider consumption */
|
|
213
|
-
export declare function toolToSchema(tool: {
|
|
214
|
-
definition: ToolDefinitionOptions;
|
|
215
|
-
}): ToolDefinitionSchema;
|
|
216
|
-
//# sourceMappingURL=tool.d.ts.map
|
package/dist/tool.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"tool.d.ts","sourceRoot":"","sources":["../src/tool.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,CAAC,EAAE,MAAM,KAAK,CAAA;AAE5B,OAAO,KAAK,EACV,IAAI,EACJ,QAAQ,EACR,eAAe,EACf,qBAAqB,EACrB,oBAAoB,EACpB,aAAa,EACd,MAAM,YAAY,CAAA;AAInB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAwCG;AACH,MAAM,WAAW,wBAAwB;IACvC,4EAA4E;IAC5E,QAAQ,CAAC,UAAU,EAAE,wBAAwB,CAAA;IAC7C,QAAQ,CAAC,SAAS,EAAG,QAAQ,EAAE,CAAA;IAC/B,QAAQ,CAAC,YAAY,CAAC,EAAE,MAAM,CAAA;CAC/B;AAED;;;;;;;;;;;GAWG;AACH,wBAAgB,mBAAmB,CACjC,SAAS,EAAE,QAAQ,EAAE,EACrB,YAAY,CAAC,EAAE,MAAM,GACpB,wBAAwB,CAK1B;AAED;;;;;GAKG;AACH,wBAAgB,0BAA0B,CAAC,KAAK,EAAE,OAAO,GAAG,KAAK,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AM,SAAS,CAAC,CAAC,OAAO,EACxB,OAAO,SAAS,CAAC,CAAC,OAAO,GAAG,CAAC,CAAC,YAAY,EAC1C,OAAO,EAAE,qBAAqB,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,WAAW,CAAC,MAAM,EAAE,OAAO,CAAC,CAE/E;AAED;;;;;;;;;;;;GAYG;AACH,wBAAgB,WAAW,CACzB,OAAO,EAAE,qBAAqB,GAC7B,WAAW,CAEb;AAED,0EAA0E;AAC1E,wBAAgB,YAAY,CAAC,IAAI,EAAE;IAAE,UAAU,EAAE,qBAAqB,CAAA;CAAE,GAAG,oBAAoB,CAW9F"}
|
package/dist/tool.js
DELETED
|
@@ -1,175 +0,0 @@
|
|
|
1
|
-
import { zodToJsonSchema } from './zod-to-json-schema.js';
|
|
2
|
-
/**
|
|
3
|
-
* Construct a pause control chunk for `yield`ing from a server tool's
|
|
4
|
-
* async-generator execute.
|
|
5
|
-
*
|
|
6
|
-
* @example
|
|
7
|
-
* .server(async function* (input, ctx) {
|
|
8
|
-
* const subRunId = await persistSubRunState(...)
|
|
9
|
-
* yield pauseForClientTools(subAgentPending, subRunId)
|
|
10
|
-
* // Unreachable — the loop halts iteration after the pause chunk.
|
|
11
|
-
* return undefined as never
|
|
12
|
-
* })
|
|
13
|
-
*/
|
|
14
|
-
export function pauseForClientTools(toolCalls, resumeHandle) {
|
|
15
|
-
const chunk = resumeHandle !== undefined
|
|
16
|
-
? { __rudderjs: 'pause_for_client_tools', toolCalls, resumeHandle }
|
|
17
|
-
: { __rudderjs: 'pause_for_client_tools', toolCalls };
|
|
18
|
-
return chunk;
|
|
19
|
-
}
|
|
20
|
-
/**
|
|
21
|
-
* Structural typeguard for a pause chunk. Used by the agent loop to
|
|
22
|
-
* detect pauses mid-execute without requiring tool authors to import any
|
|
23
|
-
* `@rudderjs/ai` symbol at the yield site — they can yield via
|
|
24
|
-
* {@link pauseForClientTools} or construct the object literal directly.
|
|
25
|
-
*/
|
|
26
|
-
export function isPauseForClientToolsChunk(value) {
|
|
27
|
-
if (value === null || typeof value !== 'object')
|
|
28
|
-
return false;
|
|
29
|
-
const v = value;
|
|
30
|
-
return v.__rudderjs === 'pause_for_client_tools' && Array.isArray(v.toolCalls);
|
|
31
|
-
}
|
|
32
|
-
/**
|
|
33
|
-
* Construct an approval-pause control chunk for `yield`ing from a server
|
|
34
|
-
* tool's async-generator execute.
|
|
35
|
-
*
|
|
36
|
-
* @example
|
|
37
|
-
* .server(async function* (input, ctx) {
|
|
38
|
-
* const subRunId = await persistSubRunState(...)
|
|
39
|
-
* yield pauseForApproval(innerToolCall, isClientTool, subRunId)
|
|
40
|
-
* return undefined as never
|
|
41
|
-
* })
|
|
42
|
-
*/
|
|
43
|
-
export function pauseForApproval(toolCall, isClientTool, resumeHandle) {
|
|
44
|
-
const chunk = resumeHandle !== undefined
|
|
45
|
-
? { __rudderjs: 'pause_for_approval', toolCall, isClientTool, resumeHandle }
|
|
46
|
-
: { __rudderjs: 'pause_for_approval', toolCall, isClientTool };
|
|
47
|
-
return chunk;
|
|
48
|
-
}
|
|
49
|
-
/**
|
|
50
|
-
* Structural typeguard for an approval-pause chunk. Mirrors
|
|
51
|
-
* {@link isPauseForClientToolsChunk} so the parent loop can recognize a
|
|
52
|
-
* pause without forcing tool authors to import any `@rudderjs/ai` symbol
|
|
53
|
-
* at the yield site.
|
|
54
|
-
*/
|
|
55
|
-
export function isPauseForApprovalChunk(value) {
|
|
56
|
-
if (value === null || typeof value !== 'object')
|
|
57
|
-
return false;
|
|
58
|
-
const v = value;
|
|
59
|
-
return (v.__rudderjs === 'pause_for_approval' &&
|
|
60
|
-
typeof v.toolCall === 'object' &&
|
|
61
|
-
v.toolCall !== null &&
|
|
62
|
-
typeof v.isClientTool === 'boolean');
|
|
63
|
-
}
|
|
64
|
-
/**
|
|
65
|
-
* Builder returned by {@link toolDefinition}. The builder itself is a valid
|
|
66
|
-
* `Tool` — call `.server(execute)` to attach a server-side handler, or use
|
|
67
|
-
* the builder as-is to register a client tool (no `execute`).
|
|
68
|
-
*/
|
|
69
|
-
export class ToolBuilder {
|
|
70
|
-
options;
|
|
71
|
-
definition;
|
|
72
|
-
/** Builders are valid client tools — `execute` is intentionally absent. */
|
|
73
|
-
execute;
|
|
74
|
-
constructor(options) {
|
|
75
|
-
this.options = options;
|
|
76
|
-
this.definition = options;
|
|
77
|
-
}
|
|
78
|
-
server(execute) {
|
|
79
|
-
return new ServerToolBuilder(this.options, execute);
|
|
80
|
-
}
|
|
81
|
-
/** Convert to provider-friendly JSON Schema format */
|
|
82
|
-
toSchema() {
|
|
83
|
-
const schema = {
|
|
84
|
-
name: this.options.name,
|
|
85
|
-
description: this.options.description,
|
|
86
|
-
parameters: this.options.jsonSchema ?? zodToJsonSchema(this.options.inputSchema, 'input'),
|
|
87
|
-
};
|
|
88
|
-
if (this.options.providerHint)
|
|
89
|
-
schema.providerHint = this.options.providerHint;
|
|
90
|
-
return schema;
|
|
91
|
-
}
|
|
92
|
-
}
|
|
93
|
-
/**
|
|
94
|
-
* Builder returned by {@link ToolBuilder.server}. Itself a valid `Tool`, so
|
|
95
|
-
* it can be passed directly into `tools()` arrays — `.toModelOutput(...)` is
|
|
96
|
-
* an optional chained refinement, not a required `.build()` step.
|
|
97
|
-
*
|
|
98
|
-
* Future per-tool refinements (`.onError(...)`, `.middleware(...)`) would slot
|
|
99
|
-
* in here in the same chained-builder style.
|
|
100
|
-
*/
|
|
101
|
-
export class ServerToolBuilder {
|
|
102
|
-
definition;
|
|
103
|
-
execute;
|
|
104
|
-
toModelOutput;
|
|
105
|
-
constructor(definition, execute, toModelOutput) {
|
|
106
|
-
this.definition = definition;
|
|
107
|
-
this.execute = execute;
|
|
108
|
-
if (toModelOutput)
|
|
109
|
-
this.toModelOutput = toModelOutput;
|
|
110
|
-
}
|
|
111
|
-
/**
|
|
112
|
-
* Declare a transform from this tool's structured result to the string the
|
|
113
|
-
* **model** sees on its next step. The UI continues to receive the original
|
|
114
|
-
* structured result.
|
|
115
|
-
*
|
|
116
|
-
* @example
|
|
117
|
-
* toolDefinition({...})
|
|
118
|
-
* .server(async (input) => bigStructuredResult)
|
|
119
|
-
* .modelOutput((result) => `${result.items.length} items found`)
|
|
120
|
-
*/
|
|
121
|
-
modelOutput(fn) {
|
|
122
|
-
return new ServerToolBuilder(this.definition, this.execute, fn);
|
|
123
|
-
}
|
|
124
|
-
}
|
|
125
|
-
/**
|
|
126
|
-
* Define a tool with typed input/output schemas.
|
|
127
|
-
*
|
|
128
|
-
* @example Server tool
|
|
129
|
-
* const weatherTool = toolDefinition({
|
|
130
|
-
* name: 'get_weather',
|
|
131
|
-
* description: 'Get weather for a location',
|
|
132
|
-
* inputSchema: z.object({ location: z.string() }),
|
|
133
|
-
* }).server(async ({ location }) => ({ temp: 72, unit: 'F' }))
|
|
134
|
-
*
|
|
135
|
-
* @example Client tool (no `.server()`)
|
|
136
|
-
* const readFormStateTool = toolDefinition({
|
|
137
|
-
* name: 'read_form_state',
|
|
138
|
-
* description: 'Read the user\'s current local form values.',
|
|
139
|
-
* inputSchema: z.object({ fields: z.array(z.string()).optional() }),
|
|
140
|
-
* })
|
|
141
|
-
*/
|
|
142
|
-
export function toolDefinition(options) {
|
|
143
|
-
return new ToolBuilder(options);
|
|
144
|
-
}
|
|
145
|
-
/**
|
|
146
|
-
* Build a tool whose input/output types are not known at compile time.
|
|
147
|
-
*
|
|
148
|
-
* Use this when the tool's schema is constructed dynamically from user data
|
|
149
|
-
* (e.g. a resource agent that exposes one tool per agent definition).
|
|
150
|
-
*
|
|
151
|
-
* @example
|
|
152
|
-
* const t = dynamicTool({
|
|
153
|
-
* name: agentDef.slug,
|
|
154
|
-
* description: agentDef.description,
|
|
155
|
-
* inputSchema: z.object({}),
|
|
156
|
-
* }).server(async () => agentDef.run())
|
|
157
|
-
*/
|
|
158
|
-
export function dynamicTool(options) {
|
|
159
|
-
return new ToolBuilder(options);
|
|
160
|
-
}
|
|
161
|
-
/** Convert any Tool to a ToolDefinitionSchema for provider consumption */
|
|
162
|
-
export function toolToSchema(tool) {
|
|
163
|
-
const schema = {
|
|
164
|
-
name: tool.definition.name,
|
|
165
|
-
description: tool.definition.description,
|
|
166
|
-
parameters: tool.definition.jsonSchema ?? zodToJsonSchema(tool.definition.inputSchema, 'input'),
|
|
167
|
-
};
|
|
168
|
-
// Propagate provider-specific hints so adapters that recognize the
|
|
169
|
-
// `providerHint.type` can substitute their native tool block (see
|
|
170
|
-
// `toAnthropicTools` for computer-use, `toOpenAITools` for file-search).
|
|
171
|
-
if (tool.definition.providerHint)
|
|
172
|
-
schema.providerHint = tool.definition.providerHint;
|
|
173
|
-
return schema;
|
|
174
|
-
}
|
|
175
|
-
//# sourceMappingURL=tool.js.map
|
package/dist/tool.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"tool.js","sourceRoot":"","sources":["../src/tool.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,eAAe,EAAE,MAAM,yBAAyB,CAAA;AA4DzD;;;;;;;;;;;GAWG;AACH,MAAM,UAAU,mBAAmB,CACjC,SAAqB,EACrB,YAAqB;IAErB,MAAM,KAAK,GAA6B,YAAY,KAAK,SAAS;QAChE,CAAC,CAAC,EAAE,UAAU,EAAE,wBAAwB,EAAE,SAAS,EAAE,YAAY,EAAE;QACnE,CAAC,CAAC,EAAE,UAAU,EAAE,wBAAwB,EAAE,SAAS,EAAE,CAAA;IACvD,OAAO,KAAK,CAAA;AACd,CAAC;AAED;;;;;GAKG;AACH,MAAM,UAAU,0BAA0B,CAAC,KAAc;IACvD,IAAI,KAAK,KAAK,IAAI,IAAI,OAAO,KAAK,KAAK,QAAQ;QAAE,OAAO,KAAK,CAAA;IAC7D,MAAM,CAAC,GAAG,KAAsD,CAAA;IAChE,OAAO,CAAC,CAAC,UAAU,KAAK,wBAAwB,IAAI,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,SAAS,CAAC,CAAA;AAChF,CAAC;AA2CD;;;;;;;;;;GAUG;AACH,MA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G,CAAA;IACD,mEAAmE;IACnE,kEAAkE;IAClE,yEAAyE;IACzE,IAAI,IAAI,CAAC,UAAU,CAAC,YAAY;QAAE,MAAM,CAAC,YAAY,GAAG,IAAI,CAAC,UAAU,CAAC,YAAY,CAAA;IACpF,OAAO,MAAM,CAAA;AACf,CAAC"}
|
package/dist/transcription.d.ts
DELETED
|
@@ -1,42 +0,0 @@
|
|
|
1
|
-
import type { SpeechToTextResult } from './types.js';
|
|
2
|
-
/**
|
|
3
|
-
* Fluent builder for speech-to-text transcription.
|
|
4
|
-
*
|
|
5
|
-
* @example
|
|
6
|
-
* const result = await Transcription.fromBytes(bytes).language('en').generate()
|
|
7
|
-
*
|
|
8
|
-
* For Node-only path-based loading, see `@rudderjs/ai/node`:
|
|
9
|
-
* const t = await transcribeFromPath('./audio.mp3')
|
|
10
|
-
*
|
|
11
|
-
* @example Failover across providers
|
|
12
|
-
* const result = await Transcription.fromBytes(bytes)
|
|
13
|
-
* .model('openai/whisper-1')
|
|
14
|
-
* .failover('google/gemini-2.0-flash-exp')
|
|
15
|
-
* .generate()
|
|
16
|
-
*/
|
|
17
|
-
export declare class Transcription {
|
|
18
|
-
private readonly _audio;
|
|
19
|
-
private _model?;
|
|
20
|
-
private _language?;
|
|
21
|
-
private _prompt?;
|
|
22
|
-
private _failover;
|
|
23
|
-
private constructor();
|
|
24
|
-
/** Create a Transcription from raw audio bytes */
|
|
25
|
-
static fromBytes(bytes: Uint8Array): Transcription;
|
|
26
|
-
/** @deprecated Use fromBytes(). Buffer extends Uint8Array, so this is a thin alias. */
|
|
27
|
-
static fromBuffer(buffer: Uint8Array): Transcription;
|
|
28
|
-
/** Set the STT model (e.g. 'openai/whisper-1') */
|
|
29
|
-
model(m: string): this;
|
|
30
|
-
/**
|
|
31
|
-
* Provider/model strings to try if the primary fails.
|
|
32
|
-
* Tried in order; the first to succeed wins.
|
|
33
|
-
*/
|
|
34
|
-
failover(...models: string[]): this;
|
|
35
|
-
/** Set the language hint (ISO-639-1, e.g. 'en', 'es', 'fr') */
|
|
36
|
-
language(l: string): this;
|
|
37
|
-
/** Set an optional prompt to guide transcription style */
|
|
38
|
-
prompt(p: string): this;
|
|
39
|
-
/** Run the transcription */
|
|
40
|
-
generate(): Promise<SpeechToTextResult>;
|
|
41
|
-
}
|
|
42
|
-
//# sourceMappingURL=transcription.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"transcription.d.ts","sourceRoot":"","sources":["../src/transcription.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,YAAY,CAAA;AAEpD;;;;;;;;;;;;;;GAcG;AACH,qBAAa,aAAa;IAMJ,OAAO,CAAC,QAAQ,CAAC,MAAM;IAL3C,OAAO,CAAC,MAAM,CAAC,CAAQ;IACvB,OAAO,CAAC,SAAS,CAAC,CAAQ;IAC1B,OAAO,CAAC,OAAO,CAAC,CAAQ;IACxB,OAAO,CAAC,SAAS,CAAe;IAEhC,OAAO;IAEP,kDAAkD;IAClD,MAAM,CAAC,SAAS,CAAC,KAAK,EAAE,UAAU,GAAG,aAAa;IAIlD,uFAAuF;IACvF,MAAM,CAAC,UAAU,CAAC,MAAM,EAAE,UAAU,GAAG,aAAa;IAIpD,kDAAkD;IAClD,KAAK,CAAC,CAAC,EAAE,MAAM,GAAG,IAAI;IAKtB;;;OAGG;IACH,QAAQ,CAAC,GAAG,MAAM,EAAE,MAAM,EAAE,GAAG,IAAI;IAKnC,+DAA+D;IAC/D,QAAQ,CAAC,CAAC,EAAE,MAAM,GAAG,IAAI;IAKzB,0DAA0D;IAC1D,MAAM,CAAC,CAAC,EAAE,MAAM,GAAG,IAAI;IAKvB,4BAA4B;IACtB,QAAQ,IAAI,OAAO,CAAC,kBAAkB,CAAC;CAsB9C"}
|
package/dist/transcription.js
DELETED
|
@@ -1,77 +0,0 @@
|
|
|
1
|
-
import { AiRegistry, tryWithFailover } from './registry.js';
|
|
2
|
-
/**
|
|
3
|
-
* Fluent builder for speech-to-text transcription.
|
|
4
|
-
*
|
|
5
|
-
* @example
|
|
6
|
-
* const result = await Transcription.fromBytes(bytes).language('en').generate()
|
|
7
|
-
*
|
|
8
|
-
* For Node-only path-based loading, see `@rudderjs/ai/node`:
|
|
9
|
-
* const t = await transcribeFromPath('./audio.mp3')
|
|
10
|
-
*
|
|
11
|
-
* @example Failover across providers
|
|
12
|
-
* const result = await Transcription.fromBytes(bytes)
|
|
13
|
-
* .model('openai/whisper-1')
|
|
14
|
-
* .failover('google/gemini-2.0-flash-exp')
|
|
15
|
-
* .generate()
|
|
16
|
-
*/
|
|
17
|
-
export class Transcription {
|
|
18
|
-
_audio;
|
|
19
|
-
_model;
|
|
20
|
-
_language;
|
|
21
|
-
_prompt;
|
|
22
|
-
_failover = [];
|
|
23
|
-
constructor(_audio) {
|
|
24
|
-
this._audio = _audio;
|
|
25
|
-
}
|
|
26
|
-
/** Create a Transcription from raw audio bytes */
|
|
27
|
-
static fromBytes(bytes) {
|
|
28
|
-
return new Transcription(bytes);
|
|
29
|
-
}
|
|
30
|
-
/** @deprecated Use fromBytes(). Buffer extends Uint8Array, so this is a thin alias. */
|
|
31
|
-
static fromBuffer(buffer) {
|
|
32
|
-
return new Transcription(buffer);
|
|
33
|
-
}
|
|
34
|
-
/** Set the STT model (e.g. 'openai/whisper-1') */
|
|
35
|
-
model(m) {
|
|
36
|
-
this._model = m;
|
|
37
|
-
return this;
|
|
38
|
-
}
|
|
39
|
-
/**
|
|
40
|
-
* Provider/model strings to try if the primary fails.
|
|
41
|
-
* Tried in order; the first to succeed wins.
|
|
42
|
-
*/
|
|
43
|
-
failover(...models) {
|
|
44
|
-
this._failover = models;
|
|
45
|
-
return this;
|
|
46
|
-
}
|
|
47
|
-
/** Set the language hint (ISO-639-1, e.g. 'en', 'es', 'fr') */
|
|
48
|
-
language(l) {
|
|
49
|
-
this._language = l;
|
|
50
|
-
return this;
|
|
51
|
-
}
|
|
52
|
-
/** Set an optional prompt to guide transcription style */
|
|
53
|
-
prompt(p) {
|
|
54
|
-
this._prompt = p;
|
|
55
|
-
return this;
|
|
56
|
-
}
|
|
57
|
-
/** Run the transcription */
|
|
58
|
-
async generate() {
|
|
59
|
-
const primary = this._model ?? AiRegistry.getDefault();
|
|
60
|
-
return tryWithFailover(primary, this._failover, async (modelString) => {
|
|
61
|
-
const [providerName, modelId] = AiRegistry.parseModelString(modelString);
|
|
62
|
-
const factory = AiRegistry.getFactory(providerName);
|
|
63
|
-
if (!factory.createStt) {
|
|
64
|
-
throw new Error(`[Rudder AI] Provider "${providerName}" does not support speech-to-text. ` +
|
|
65
|
-
`Use a provider that implements createStt() (e.g. openai).`);
|
|
66
|
-
}
|
|
67
|
-
const adapter = factory.createStt(modelId);
|
|
68
|
-
return adapter.transcribe({
|
|
69
|
-
audio: this._audio,
|
|
70
|
-
model: modelId,
|
|
71
|
-
language: this._language,
|
|
72
|
-
prompt: this._prompt,
|
|
73
|
-
});
|
|
74
|
-
});
|
|
75
|
-
}
|
|
76
|
-
}
|
|
77
|
-
//# sourceMappingURL=transcription.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"transcription.js","sourceRoot":"","sources":["../src/transcription.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,eAAe,EAAE,MAAM,eAAe,CAAA;AAG3D;;;;;;;;;;;;;;GAcG;AACH,MAAM,OAAO,aAAa;IAMa;IAL7B,MAAM,CAAS;IACf,SAAS,CAAS;IAClB,OAAO,CAAS;IAChB,SAAS,GAAa,EAAE,CAAA;IAEhC,YAAqC,MAAkB;QAAlB,WAAM,GAAN,MAAM,CAAY;IAAG,CAAC;IAE3D,kDAAkD;IAClD,MAAM,CAAC,SAAS,CAAC,KAAiB;QAChC,OAAO,IAAI,aAAa,CAAC,KAAK,CAAC,CAAA;IACjC,CAAC;IAED,uFAAuF;IACvF,MAAM,CAAC,UAAU,CAAC,MAAkB;QAClC,OAAO,IAAI,aAAa,CAAC,MAAM,C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