@rudderjs/ai 1.17.2 → 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-execution.js
DELETED
|
@@ -1,498 +0,0 @@
|
|
|
1
|
-
import { isHandoffTool } from './handoff.js';
|
|
2
|
-
import { runOnAbort, runOnAfterToolCall, runOnBeforeToolCall, runOnChunk, runOnError, runSequential, } from './middleware.js';
|
|
3
|
-
import { isPauseForApprovalChunk, isPauseForClientToolsChunk } from './tool.js';
|
|
4
|
-
import { applyToModelOutput, evaluateApproval, executeMaybeStreaming, validateToolArgs, } from './tool-helpers.js';
|
|
5
|
-
/**
|
|
6
|
-
* Execute the tool phase for a single agent step. Yields the same
|
|
7
|
-
* `StreamChunk` sequence (`tool-call` → `tool-update*` → `tool-result`) that
|
|
8
|
-
* the streaming caller surfaces to consumers. Non-streaming callers iterate
|
|
9
|
-
* via `.next()` and discard yields — the side effects (message pushes,
|
|
10
|
-
* pending-state mutations on `loopCtx`) are identical regardless of whether
|
|
11
|
-
* the chunks reach a consumer.
|
|
12
|
-
*
|
|
13
|
-
* Returns the step's `ToolResult[]`. The caller passes the assistant message
|
|
14
|
-
* to push before iteration so the AgentStep shape (response.message) and the
|
|
15
|
-
* final `messages` array stay in sync with the loop variant.
|
|
16
|
-
*/
|
|
17
|
-
export async function* executeToolPhase(loopCtx, toolCalls, assistantMessage) {
|
|
18
|
-
const { messages, middlewares, options, ctx } = loopCtx;
|
|
19
|
-
const toolResults = [];
|
|
20
|
-
messages.push(assistantMessage);
|
|
21
|
-
// Resolve parallelism setting. Per-call option wins; falls back to the
|
|
22
|
-
// agent-level override which defaults to `true`. Single-tool batches
|
|
23
|
-
// route through the serial path either way (no parallelism to gain, and
|
|
24
|
-
// serial preserves live `tool-update` streaming for that one tool).
|
|
25
|
-
//
|
|
26
|
-
// Handoffs always force serial dispatch — the parent loop has to halt
|
|
27
|
-
// immediately on the first handoff and synthesize "skipped" results for
|
|
28
|
-
// any sibling calls. Handling that across the parallel classify/replay
|
|
29
|
-
// phases is doable but adds complexity for negligible benefit (the model
|
|
30
|
-
// rarely emits parallel siblings alongside a handoff, and even then,
|
|
31
|
-
// running them while the agent is being torn down is wasted work).
|
|
32
|
-
const hasHandoff = toolCalls.some(tc => isHandoffTool(loopCtx.toolMap.get(tc.name)));
|
|
33
|
-
const parallel = (options?.parallelTools ?? loopCtx.agent.parallelTools()) && toolCalls.length > 1 && !hasHandoff;
|
|
34
|
-
if (parallel) {
|
|
35
|
-
yield* runToolPhaseParallel(loopCtx, toolCalls, toolResults);
|
|
36
|
-
}
|
|
37
|
-
else {
|
|
38
|
-
yield* runToolPhaseSerial(loopCtx, toolCalls, toolResults);
|
|
39
|
-
}
|
|
40
|
-
// onToolPhaseComplete
|
|
41
|
-
if (middlewares.length > 0)
|
|
42
|
-
await runSequential(middlewares, 'onToolPhaseComplete', ctx);
|
|
43
|
-
return toolResults;
|
|
44
|
-
}
|
|
45
|
-
/**
|
|
46
|
-
* Serial tool execution — the original behavior. Runs each tool call's
|
|
47
|
-
* prelude (approval, before-middleware, validation) and `execute()`
|
|
48
|
-
* one-after-another, streaming `tool-update` chunks live as the tool
|
|
49
|
-
* emits them.
|
|
50
|
-
*/
|
|
51
|
-
async function* runToolPhaseSerial(loopCtx, toolCalls, toolResults) {
|
|
52
|
-
const { messages, middlewares, toolMap, options, ctx } = loopCtx;
|
|
53
|
-
for (const tc of toolCalls) {
|
|
54
|
-
const tool = toolMap.get(tc.name);
|
|
55
|
-
if (!tool) {
|
|
56
|
-
const unknownResult = `Error: Unknown tool "${tc.name}"`;
|
|
57
|
-
toolResults.push({ toolCallId: tc.id, result: unknownResult });
|
|
58
|
-
messages.push({ role: 'tool', content: unknownResult, toolCallId: tc.id });
|
|
59
|
-
yield { type: 'tool-result', toolCall: tc, result: unknownResult };
|
|
60
|
-
continue;
|
|
61
|
-
}
|
|
62
|
-
// Handoff — detected before the no-execute (client tool) branch because
|
|
63
|
-
// a handoff tool also has no `execute`, but it has wholly different
|
|
64
|
-
// semantics: pivot control to a new agent instead of pausing for the
|
|
65
|
-
// browser. The first handoff in a step wins; any subsequent tool calls
|
|
66
|
-
// in the same step are skipped with a synthetic "skipped: handed off"
|
|
67
|
-
// tool result so the message log stays well-formed for replay.
|
|
68
|
-
if (loopCtx.stopForHandoff) {
|
|
69
|
-
const skippedResult = 'Skipped: parent agent handed off to another agent.';
|
|
70
|
-
toolResults.push({ toolCallId: tc.id, result: skippedResult });
|
|
71
|
-
messages.push({ role: 'tool', content: skippedResult, toolCallId: tc.id });
|
|
72
|
-
yield { type: 'tool-call', toolCall: tc };
|
|
73
|
-
yield { type: 'tool-result', toolCall: tc, result: skippedResult };
|
|
74
|
-
continue;
|
|
75
|
-
}
|
|
76
|
-
if (isHandoffTool(tool)) {
|
|
77
|
-
const spec = tool.__handoffSpec;
|
|
78
|
-
const validation = validateToolArgs(tool, tc.arguments);
|
|
79
|
-
// Handoff payload defaults to `{ message: string }`; custom schemas
|
|
80
|
-
// are accepted but the loop only uses `args.message` (string) as the
|
|
81
|
-
// transition prompt. Anything else surfaces in the conversation as
|
|
82
|
-
// the args of the synthetic tool-call.
|
|
83
|
-
const args = validation.ok ? validation.value : tc.arguments;
|
|
84
|
-
const transitionMessage = typeof args['message'] === 'string' ? args['message'] : '';
|
|
85
|
-
const handoffResult = `Handed off to ${spec.AgentClass.name}.`;
|
|
86
|
-
toolResults.push({ toolCallId: tc.id, result: handoffResult });
|
|
87
|
-
messages.push({ role: 'tool', content: handoffResult, toolCallId: tc.id });
|
|
88
|
-
yield { type: 'tool-call', toolCall: tc };
|
|
89
|
-
yield { type: 'tool-result', toolCall: tc, result: handoffResult };
|
|
90
|
-
yield {
|
|
91
|
-
type: 'handoff',
|
|
92
|
-
handoff: {
|
|
93
|
-
from: loopCtx.agent.constructor.name,
|
|
94
|
-
to: spec.AgentClass.name,
|
|
95
|
-
...(transitionMessage ? { message: transitionMessage } : {}),
|
|
96
|
-
},
|
|
97
|
-
};
|
|
98
|
-
loopCtx.pendingHandoff = { spec, transitionMessage, parentToolCallId: tc.id };
|
|
99
|
-
loopCtx.stopForHandoff = true;
|
|
100
|
-
// Do NOT break — keep iterating so any sibling tool calls in this
|
|
101
|
-
// step get their synthetic "skipped" tool results before the loop
|
|
102
|
-
// exits. This preserves message-log invariants for downstream
|
|
103
|
-
// persistence.
|
|
104
|
-
continue;
|
|
105
|
-
}
|
|
106
|
-
if (!tool.execute) {
|
|
107
|
-
// Client tool — no server-side handler.
|
|
108
|
-
if (options?.toolCallStreamingMode === 'stop-on-client-tool') {
|
|
109
|
-
loopCtx.pendingClientToolCalls.push(tc);
|
|
110
|
-
loopCtx.loopFinishReason = 'client_tool_calls';
|
|
111
|
-
loopCtx.stopForClientTools = true;
|
|
112
|
-
yield { type: 'tool-call', toolCall: tc };
|
|
113
|
-
continue;
|
|
114
|
-
}
|
|
115
|
-
const placeholder = '[client tool — execute on client]';
|
|
116
|
-
toolResults.push({ toolCallId: tc.id, result: placeholder });
|
|
117
|
-
messages.push({ role: 'tool', content: placeholder, toolCallId: tc.id });
|
|
118
|
-
yield { type: 'tool-call', toolCall: tc };
|
|
119
|
-
yield { type: 'tool-result', toolCall: tc, result: placeholder };
|
|
120
|
-
continue;
|
|
121
|
-
}
|
|
122
|
-
// needsApproval enforcement
|
|
123
|
-
const approvalDecision = await evaluateApproval(tool, tc, options);
|
|
124
|
-
if (approvalDecision === 'rejected') {
|
|
125
|
-
const rejectionResult = { rejected: true, reason: 'User rejected this tool call' };
|
|
126
|
-
toolResults.push({ toolCallId: tc.id, result: rejectionResult });
|
|
127
|
-
messages.push({ role: 'tool', content: JSON.stringify(rejectionResult), toolCallId: tc.id });
|
|
128
|
-
yield { type: 'tool-result', toolCall: tc, result: rejectionResult };
|
|
129
|
-
continue;
|
|
130
|
-
}
|
|
131
|
-
if (approvalDecision === 'pending') {
|
|
132
|
-
loopCtx.pendingApprovalToolCall = { toolCall: tc, isClientTool: false };
|
|
133
|
-
loopCtx.loopFinishReason = 'tool_approval_required';
|
|
134
|
-
loopCtx.stopForApproval = true;
|
|
135
|
-
yield { type: 'tool-call', toolCall: tc };
|
|
136
|
-
break;
|
|
137
|
-
}
|
|
138
|
-
// onBeforeToolCall
|
|
139
|
-
let toolArgs = tc.arguments;
|
|
140
|
-
if (middlewares.length > 0) {
|
|
141
|
-
const beforeResult = await runOnBeforeToolCall(middlewares, ctx, tc.name, toolArgs);
|
|
142
|
-
if (beforeResult) {
|
|
143
|
-
if (beforeResult.type === 'skip') {
|
|
144
|
-
const resultStr = typeof beforeResult.result === 'string' ? beforeResult.result : JSON.stringify(beforeResult.result);
|
|
145
|
-
toolResults.push({ toolCallId: tc.id, result: beforeResult.result });
|
|
146
|
-
messages.push({ role: 'tool', content: resultStr, toolCallId: tc.id });
|
|
147
|
-
yield { type: 'tool-result', toolCall: tc, result: beforeResult.result };
|
|
148
|
-
await runOnAfterToolCall(middlewares, ctx, tc.name, toolArgs, beforeResult.result);
|
|
149
|
-
continue;
|
|
150
|
-
}
|
|
151
|
-
if (beforeResult.type === 'abort') {
|
|
152
|
-
await runOnAbort(middlewares, ctx, beforeResult.reason);
|
|
153
|
-
break;
|
|
154
|
-
}
|
|
155
|
-
if (beforeResult.type === 'transformArgs') {
|
|
156
|
-
toolArgs = beforeResult.args;
|
|
157
|
-
}
|
|
158
|
-
}
|
|
159
|
-
}
|
|
160
|
-
// Validate args against the tool's inputSchema. Runs after middleware
|
|
161
|
-
// transforms so transforms can reshape malformed model output before
|
|
162
|
-
// it is judged. The tool-call chunk is emitted even on validation
|
|
163
|
-
// failure so streaming UIs see a paired tool-call → tool-result(error)
|
|
164
|
-
// sequence; non-streaming callers discard the chunk.
|
|
165
|
-
const validation = validateToolArgs(tool, toolArgs);
|
|
166
|
-
if (!validation.ok) {
|
|
167
|
-
yield { type: 'tool-call', toolCall: tc };
|
|
168
|
-
toolResults.push({ toolCallId: tc.id, result: validation.error });
|
|
169
|
-
messages.push({ role: 'tool', content: JSON.stringify(validation.error), toolCallId: tc.id });
|
|
170
|
-
yield { type: 'tool-result', toolCall: tc, result: validation.error };
|
|
171
|
-
if (middlewares.length > 0)
|
|
172
|
-
await runOnAfterToolCall(middlewares, ctx, tc.name, toolArgs, validation.error);
|
|
173
|
-
continue;
|
|
174
|
-
}
|
|
175
|
-
const validatedArgs = validation.value;
|
|
176
|
-
const toolStart = performance.now();
|
|
177
|
-
try {
|
|
178
|
-
// Emit the tool-call marker before execution so streaming UIs see
|
|
179
|
-
// tool-call → tool-update* → tool-result in order. Async-generator
|
|
180
|
-
// executes stream their yields as tool-update chunks live; plain
|
|
181
|
-
// executes yield nothing here.
|
|
182
|
-
//
|
|
183
|
-
// Pause detection: a yielded `pause_for_client_tools` control chunk
|
|
184
|
-
// halts iteration, propagates the nested calls to the parent's
|
|
185
|
-
// pending list, and SKIPS the tool_result emission — the yielding
|
|
186
|
-
// tool's own call stays orphaned in the parent message history
|
|
187
|
-
// until the caller resolves it on resume.
|
|
188
|
-
yield { type: 'tool-call', toolCall: tc };
|
|
189
|
-
const execGen = executeMaybeStreaming(tool, validatedArgs, { toolCallId: tc.id });
|
|
190
|
-
let result;
|
|
191
|
-
let paused = false;
|
|
192
|
-
while (true) {
|
|
193
|
-
const step = await execGen.next();
|
|
194
|
-
if (step.done) {
|
|
195
|
-
result = step.value;
|
|
196
|
-
break;
|
|
197
|
-
}
|
|
198
|
-
if (isPauseForClientToolsChunk(step.value)) {
|
|
199
|
-
for (const pending of step.value.toolCalls) {
|
|
200
|
-
loopCtx.pendingClientToolCalls.push(pending);
|
|
201
|
-
}
|
|
202
|
-
loopCtx.loopFinishReason = 'client_tool_calls';
|
|
203
|
-
loopCtx.stopForClientTools = true;
|
|
204
|
-
paused = true;
|
|
205
|
-
break;
|
|
206
|
-
}
|
|
207
|
-
if (isPauseForApprovalChunk(step.value)) {
|
|
208
|
-
loopCtx.pendingApprovalToolCall = {
|
|
209
|
-
toolCall: step.value.toolCall,
|
|
210
|
-
isClientTool: step.value.isClientTool,
|
|
211
|
-
};
|
|
212
|
-
loopCtx.loopFinishReason = 'tool_approval_required';
|
|
213
|
-
loopCtx.stopForApproval = true;
|
|
214
|
-
paused = true;
|
|
215
|
-
break;
|
|
216
|
-
}
|
|
217
|
-
const updateChunk = { type: 'tool-update', toolCall: tc, update: step.value };
|
|
218
|
-
if (middlewares.length > 0) {
|
|
219
|
-
const transformed = runOnChunk(middlewares, ctx, updateChunk);
|
|
220
|
-
if (transformed)
|
|
221
|
-
yield transformed;
|
|
222
|
-
}
|
|
223
|
-
else {
|
|
224
|
-
yield updateChunk;
|
|
225
|
-
}
|
|
226
|
-
}
|
|
227
|
-
if (paused)
|
|
228
|
-
continue; // skip tool_result emission + message push for this tc
|
|
229
|
-
const duration = performance.now() - toolStart;
|
|
230
|
-
// toolResults preserves the ORIGINAL value; only the message content
|
|
231
|
-
// pushed onto `messages` (next-step model input) is narrowed by
|
|
232
|
-
// toModelOutput. The streamed `tool-result` chunk also carries the
|
|
233
|
-
// ORIGINAL value.
|
|
234
|
-
toolResults.push({ toolCallId: tc.id, result, duration });
|
|
235
|
-
const resultStr = await applyToModelOutput(tool, result, middlewares.length > 0 ? (e) => runOnError(middlewares, ctx, e) : undefined);
|
|
236
|
-
messages.push({ role: 'tool', content: resultStr, toolCallId: tc.id });
|
|
237
|
-
yield { type: 'tool-result', toolCall: tc, result };
|
|
238
|
-
// onAfterToolCall
|
|
239
|
-
if (middlewares.length > 0)
|
|
240
|
-
await runOnAfterToolCall(middlewares, ctx, tc.name, toolArgs, result);
|
|
241
|
-
}
|
|
242
|
-
catch (err) {
|
|
243
|
-
const duration = performance.now() - toolStart;
|
|
244
|
-
const msg = err instanceof Error ? err.message : String(err);
|
|
245
|
-
const errResult = `Error: ${msg}`;
|
|
246
|
-
toolResults.push({ toolCallId: tc.id, result: errResult, duration });
|
|
247
|
-
messages.push({ role: 'tool', content: errResult, toolCallId: tc.id });
|
|
248
|
-
yield { type: 'tool-result', toolCall: tc, result: errResult };
|
|
249
|
-
// onAfterToolCall (error case)
|
|
250
|
-
if (middlewares.length > 0)
|
|
251
|
-
await runOnAfterToolCall(middlewares, ctx, tc.name, toolArgs, errResult);
|
|
252
|
-
}
|
|
253
|
-
}
|
|
254
|
-
}
|
|
255
|
-
/**
|
|
256
|
-
* Parallel tool execution — three phases:
|
|
257
|
-
*
|
|
258
|
-
* 1. **Prelude (serial, in tool-call order):** classify each call. Approval
|
|
259
|
-
* decisions, `onBeforeToolCall` middleware, and arg validation all
|
|
260
|
-
* resolve here; the next phase only sees calls that cleared every
|
|
261
|
-
* gate. `pending-approval` and `mw-abort` short-circuit the prelude
|
|
262
|
-
* exactly as they do in serial mode — later calls are never dispatched.
|
|
263
|
-
*
|
|
264
|
-
* 2. **Execution (parallel):** for every `ready` outcome, drive
|
|
265
|
-
* `executeMaybeStreaming` to completion concurrently. `tool-update`
|
|
266
|
-
* chunks (and any pause-for-client-tools mutations to `loopCtx`) are
|
|
267
|
-
* captured per-call into a buffer.
|
|
268
|
-
*
|
|
269
|
-
* 3. **Replay (serial, in tool-call order):** for each outcome, emit its
|
|
270
|
-
* chunks (including buffered `tool-update`s for ready calls), push
|
|
271
|
-
* tool messages, and run `onAfterToolCall`. This is the only phase
|
|
272
|
-
* that yields chunks to consumers, so streamed output stays
|
|
273
|
-
* deterministic regardless of which `execute()` finished first.
|
|
274
|
-
*/
|
|
275
|
-
async function* runToolPhaseParallel(loopCtx, toolCalls, toolResults) {
|
|
276
|
-
const { messages, middlewares, ctx } = loopCtx;
|
|
277
|
-
// ─── Phase 1: prelude ──────────────────────────────────
|
|
278
|
-
const outcomes = await classifyToolCalls(loopCtx, toolCalls);
|
|
279
|
-
// ─── Phase 2: dispatch ready executions concurrently ──
|
|
280
|
-
const ready = outcomes.filter((o) => o.kind === 'ready');
|
|
281
|
-
const executions = await Promise.all(ready.map(o => runToolExecution(loopCtx, o)));
|
|
282
|
-
const executionByCallId = new Map();
|
|
283
|
-
for (let i = 0; i < ready.length; i++) {
|
|
284
|
-
executionByCallId.set(ready[i].tc.id, executions[i]);
|
|
285
|
-
}
|
|
286
|
-
// ─── Phase 3: replay chunks + side-effects in order ───
|
|
287
|
-
for (const outcome of outcomes) {
|
|
288
|
-
if (outcome.kind === 'unknown-tool') {
|
|
289
|
-
toolResults.push({ toolCallId: outcome.tc.id, result: outcome.result });
|
|
290
|
-
messages.push({ role: 'tool', content: outcome.result, toolCallId: outcome.tc.id });
|
|
291
|
-
yield { type: 'tool-result', toolCall: outcome.tc, result: outcome.result };
|
|
292
|
-
continue;
|
|
293
|
-
}
|
|
294
|
-
if (outcome.kind === 'client-tool-stop') {
|
|
295
|
-
// loopCtx mutations already applied during the prelude.
|
|
296
|
-
yield { type: 'tool-call', toolCall: outcome.tc };
|
|
297
|
-
continue;
|
|
298
|
-
}
|
|
299
|
-
if (outcome.kind === 'client-tool-placeholder') {
|
|
300
|
-
toolResults.push({ toolCallId: outcome.tc.id, result: outcome.result });
|
|
301
|
-
messages.push({ role: 'tool', content: outcome.result, toolCallId: outcome.tc.id });
|
|
302
|
-
yield { type: 'tool-call', toolCall: outcome.tc };
|
|
303
|
-
yield { type: 'tool-result', toolCall: outcome.tc, result: outcome.result };
|
|
304
|
-
continue;
|
|
305
|
-
}
|
|
306
|
-
if (outcome.kind === 'rejected') {
|
|
307
|
-
toolResults.push({ toolCallId: outcome.tc.id, result: outcome.result });
|
|
308
|
-
messages.push({ role: 'tool', content: JSON.stringify(outcome.result), toolCallId: outcome.tc.id });
|
|
309
|
-
yield { type: 'tool-result', toolCall: outcome.tc, result: outcome.result };
|
|
310
|
-
continue;
|
|
311
|
-
}
|
|
312
|
-
if (outcome.kind === 'pending-approval') {
|
|
313
|
-
// loopCtx mutations already applied during the prelude.
|
|
314
|
-
yield { type: 'tool-call', toolCall: outcome.tc };
|
|
315
|
-
// Phase 1 stops classifying after pending-approval, so this is the
|
|
316
|
-
// last outcome — but `break` keeps the intent explicit.
|
|
317
|
-
break;
|
|
318
|
-
}
|
|
319
|
-
if (outcome.kind === 'mw-skip') {
|
|
320
|
-
const resultStr = typeof outcome.result === 'string' ? outcome.result : JSON.stringify(outcome.result);
|
|
321
|
-
toolResults.push({ toolCallId: outcome.tc.id, result: outcome.result });
|
|
322
|
-
messages.push({ role: 'tool', content: resultStr, toolCallId: outcome.tc.id });
|
|
323
|
-
yield { type: 'tool-result', toolCall: outcome.tc, result: outcome.result };
|
|
324
|
-
if (middlewares.length > 0)
|
|
325
|
-
await runOnAfterToolCall(middlewares, ctx, outcome.tc.name, outcome.toolArgs, outcome.result);
|
|
326
|
-
continue;
|
|
327
|
-
}
|
|
328
|
-
if (outcome.kind === 'validation-error') {
|
|
329
|
-
yield { type: 'tool-call', toolCall: outcome.tc };
|
|
330
|
-
toolResults.push({ toolCallId: outcome.tc.id, result: outcome.error });
|
|
331
|
-
messages.push({ role: 'tool', content: JSON.stringify(outcome.error), toolCallId: outcome.tc.id });
|
|
332
|
-
yield { type: 'tool-result', toolCall: outcome.tc, result: outcome.error };
|
|
333
|
-
if (middlewares.length > 0)
|
|
334
|
-
await runOnAfterToolCall(middlewares, ctx, outcome.tc.name, outcome.toolArgs, outcome.error);
|
|
335
|
-
continue;
|
|
336
|
-
}
|
|
337
|
-
// outcome.kind === 'ready'
|
|
338
|
-
const exec = executionByCallId.get(outcome.tc.id);
|
|
339
|
-
yield { type: 'tool-call', toolCall: outcome.tc };
|
|
340
|
-
for (const chunk of exec.updates)
|
|
341
|
-
yield chunk;
|
|
342
|
-
if (exec.kind === 'paused') {
|
|
343
|
-
// Pause-for-client-tools propagated its calls onto `loopCtx` during
|
|
344
|
-
// execution. Skip tool_result emission + message push — the call
|
|
345
|
-
// stays orphaned until resume.
|
|
346
|
-
continue;
|
|
347
|
-
}
|
|
348
|
-
if (exec.kind === 'error') {
|
|
349
|
-
const errResult = `Error: ${exec.error.message}`;
|
|
350
|
-
toolResults.push({ toolCallId: outcome.tc.id, result: errResult, duration: exec.duration });
|
|
351
|
-
messages.push({ role: 'tool', content: errResult, toolCallId: outcome.tc.id });
|
|
352
|
-
yield { type: 'tool-result', toolCall: outcome.tc, result: errResult };
|
|
353
|
-
if (middlewares.length > 0)
|
|
354
|
-
await runOnAfterToolCall(middlewares, ctx, outcome.tc.name, outcome.toolArgs, errResult);
|
|
355
|
-
continue;
|
|
356
|
-
}
|
|
357
|
-
// exec.kind === 'ok'
|
|
358
|
-
toolResults.push({ toolCallId: outcome.tc.id, result: exec.result, duration: exec.duration });
|
|
359
|
-
const resultStr = await applyToModelOutput(outcome.tool, exec.result, middlewares.length > 0 ? (e) => runOnError(middlewares, ctx, e) : undefined);
|
|
360
|
-
messages.push({ role: 'tool', content: resultStr, toolCallId: outcome.tc.id });
|
|
361
|
-
yield { type: 'tool-result', toolCall: outcome.tc, result: exec.result };
|
|
362
|
-
if (middlewares.length > 0)
|
|
363
|
-
await runOnAfterToolCall(middlewares, ctx, outcome.tc.name, outcome.toolArgs, exec.result);
|
|
364
|
-
}
|
|
365
|
-
}
|
|
366
|
-
/**
|
|
367
|
-
* Walk `toolCalls` in order and decide each call's fate. Mutations to
|
|
368
|
-
* `loopCtx` for client-tool-stop, pending-approval, and middleware-abort
|
|
369
|
-
* happen here so the rest of the parallel flow sees the same state the
|
|
370
|
-
* serial path would. `pending-approval` and `mw-abort` stop the walk —
|
|
371
|
-
* later calls are not classified and are silently dropped.
|
|
372
|
-
*/
|
|
373
|
-
async function classifyToolCalls(loopCtx, toolCalls) {
|
|
374
|
-
const { middlewares, toolMap, options, ctx } = loopCtx;
|
|
375
|
-
const outcomes = [];
|
|
376
|
-
for (const tc of toolCalls) {
|
|
377
|
-
const tool = toolMap.get(tc.name);
|
|
378
|
-
if (!tool) {
|
|
379
|
-
outcomes.push({ kind: 'unknown-tool', tc, result: `Error: Unknown tool "${tc.name}"` });
|
|
380
|
-
continue;
|
|
381
|
-
}
|
|
382
|
-
if (!tool.execute) {
|
|
383
|
-
if (options?.toolCallStreamingMode === 'stop-on-client-tool') {
|
|
384
|
-
loopCtx.pendingClientToolCalls.push(tc);
|
|
385
|
-
loopCtx.loopFinishReason = 'client_tool_calls';
|
|
386
|
-
loopCtx.stopForClientTools = true;
|
|
387
|
-
outcomes.push({ kind: 'client-tool-stop', tc });
|
|
388
|
-
continue;
|
|
389
|
-
}
|
|
390
|
-
outcomes.push({ kind: 'client-tool-placeholder', tc, result: '[client tool — execute on client]' });
|
|
391
|
-
continue;
|
|
392
|
-
}
|
|
393
|
-
const approvalDecision = await evaluateApproval(tool, tc, options);
|
|
394
|
-
if (approvalDecision === 'rejected') {
|
|
395
|
-
outcomes.push({ kind: 'rejected', tc, result: { rejected: true, reason: 'User rejected this tool call' } });
|
|
396
|
-
continue;
|
|
397
|
-
}
|
|
398
|
-
if (approvalDecision === 'pending') {
|
|
399
|
-
loopCtx.pendingApprovalToolCall = { toolCall: tc, isClientTool: false };
|
|
400
|
-
loopCtx.loopFinishReason = 'tool_approval_required';
|
|
401
|
-
loopCtx.stopForApproval = true;
|
|
402
|
-
outcomes.push({ kind: 'pending-approval', tc });
|
|
403
|
-
break;
|
|
404
|
-
}
|
|
405
|
-
let toolArgs = tc.arguments;
|
|
406
|
-
if (middlewares.length > 0) {
|
|
407
|
-
const beforeResult = await runOnBeforeToolCall(middlewares, ctx, tc.name, toolArgs);
|
|
408
|
-
if (beforeResult) {
|
|
409
|
-
if (beforeResult.type === 'skip') {
|
|
410
|
-
outcomes.push({ kind: 'mw-skip', tc, toolArgs, result: beforeResult.result });
|
|
411
|
-
continue;
|
|
412
|
-
}
|
|
413
|
-
if (beforeResult.type === 'abort') {
|
|
414
|
-
await runOnAbort(middlewares, ctx, beforeResult.reason);
|
|
415
|
-
// Drop any prior outcomes too? No — serial mode emits prior
|
|
416
|
-
// outcomes' chunks before hitting abort, so we keep them in the
|
|
417
|
-
// outcomes list and Phase 3 emits them up to (but not including)
|
|
418
|
-
// this call. Stop classifying further.
|
|
419
|
-
break;
|
|
420
|
-
}
|
|
421
|
-
if (beforeResult.type === 'transformArgs') {
|
|
422
|
-
toolArgs = beforeResult.args;
|
|
423
|
-
}
|
|
424
|
-
}
|
|
425
|
-
}
|
|
426
|
-
const validation = validateToolArgs(tool, toolArgs);
|
|
427
|
-
if (!validation.ok) {
|
|
428
|
-
outcomes.push({ kind: 'validation-error', tc, toolArgs, error: validation.error });
|
|
429
|
-
continue;
|
|
430
|
-
}
|
|
431
|
-
outcomes.push({ kind: 'ready', tc, tool, toolArgs, validatedArgs: validation.value });
|
|
432
|
-
}
|
|
433
|
-
return outcomes;
|
|
434
|
-
}
|
|
435
|
-
/**
|
|
436
|
-
* Drive a single tool's `executeMaybeStreaming` to completion. Buffers
|
|
437
|
-
* `tool-update` chunks for replay in tool-call order; pause-for-client-tools
|
|
438
|
-
* mutations to `loopCtx` apply immediately and the call returns `paused`.
|
|
439
|
-
*
|
|
440
|
-
* `ctx` is shared across concurrent invocations. Middleware that writes
|
|
441
|
-
* through `ctx` during `runOnChunk` (uncommon — most use it read-only for
|
|
442
|
-
* telemetry) may observe interleaved updates from sibling tool calls;
|
|
443
|
-
* apps with such middleware should opt out via `parallelTools: false`.
|
|
444
|
-
*/
|
|
445
|
-
async function runToolExecution(loopCtx, outcome) {
|
|
446
|
-
const { middlewares, ctx } = loopCtx;
|
|
447
|
-
const updates = [];
|
|
448
|
-
const toolStart = performance.now();
|
|
449
|
-
try {
|
|
450
|
-
const execGen = executeMaybeStreaming(outcome.tool, outcome.validatedArgs, { toolCallId: outcome.tc.id });
|
|
451
|
-
let result;
|
|
452
|
-
let paused = false;
|
|
453
|
-
while (true) {
|
|
454
|
-
const step = await execGen.next();
|
|
455
|
-
if (step.done) {
|
|
456
|
-
result = step.value;
|
|
457
|
-
break;
|
|
458
|
-
}
|
|
459
|
-
if (isPauseForClientToolsChunk(step.value)) {
|
|
460
|
-
for (const pending of step.value.toolCalls) {
|
|
461
|
-
loopCtx.pendingClientToolCalls.push(pending);
|
|
462
|
-
}
|
|
463
|
-
loopCtx.loopFinishReason = 'client_tool_calls';
|
|
464
|
-
loopCtx.stopForClientTools = true;
|
|
465
|
-
paused = true;
|
|
466
|
-
break;
|
|
467
|
-
}
|
|
468
|
-
if (isPauseForApprovalChunk(step.value)) {
|
|
469
|
-
loopCtx.pendingApprovalToolCall = {
|
|
470
|
-
toolCall: step.value.toolCall,
|
|
471
|
-
isClientTool: step.value.isClientTool,
|
|
472
|
-
};
|
|
473
|
-
loopCtx.loopFinishReason = 'tool_approval_required';
|
|
474
|
-
loopCtx.stopForApproval = true;
|
|
475
|
-
paused = true;
|
|
476
|
-
break;
|
|
477
|
-
}
|
|
478
|
-
const updateChunk = { type: 'tool-update', toolCall: outcome.tc, update: step.value };
|
|
479
|
-
if (middlewares.length > 0) {
|
|
480
|
-
const transformed = runOnChunk(middlewares, ctx, updateChunk);
|
|
481
|
-
if (transformed)
|
|
482
|
-
updates.push(transformed);
|
|
483
|
-
}
|
|
484
|
-
else {
|
|
485
|
-
updates.push(updateChunk);
|
|
486
|
-
}
|
|
487
|
-
}
|
|
488
|
-
const duration = performance.now() - toolStart;
|
|
489
|
-
if (paused)
|
|
490
|
-
return { kind: 'paused', updates, duration };
|
|
491
|
-
return { kind: 'ok', result, updates, duration };
|
|
492
|
-
}
|
|
493
|
-
catch (err) {
|
|
494
|
-
const duration = performance.now() - toolStart;
|
|
495
|
-
return { kind: 'error', error: err instanceof Error ? err : new Error(String(err)), updates, duration };
|
|
496
|
-
}
|
|
497
|
-
}
|
|
498
|
-
//# sourceMappingURL=tool-execution.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"tool-execution.js","sourceRoot":"","sources":["../src/tool-execution.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,aAAa,EAAE,MAAM,cAAc,CAAA;AAC5C,OAAO,EACL,UAAU,EACV,kBAAkB,EAClB,mBAAmB,EACnB,UAAU,EACV,UAAU,EACV,aAAa,GACd,MAAM,iBAAiB,CAAA;AACxB,OAAO,EAAE,uBAAuB,E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EAAE,CAAC;QACb,MAAM,QAAQ,GAAG,WAAW,CAAC,GAAG,EAAE,GAAG,SAAS,CAAA;QAC9C,OAAO,EAAE,IAAI,EAAE,OAAO,EAAE,KAAK,EAAE,GAAG,YAAY,KAAK,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,IAAI,KAAK,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,EAAE,OAAO,EAAE,QAAQ,EAAE,CAAA;IACzG,CAAC;AACH,CAAC"}
|
package/dist/tool-helpers.d.ts
DELETED
|
@@ -1,77 +0,0 @@
|
|
|
1
|
-
import type { AgentPromptOptions, Tool, ToolCall, ToolCallContext } from './types.js';
|
|
2
|
-
/**
|
|
3
|
-
* Detect an async generator (the value returned by `async function*` or any
|
|
4
|
-
* object implementing the AsyncGenerator protocol). We use a structural check
|
|
5
|
-
* because the executor may not be authored as a literal `async function*`
|
|
6
|
-
* (e.g. wrapped or returned from a factory).
|
|
7
|
-
*/
|
|
8
|
-
export declare function isAsyncGenerator(value: unknown): value is AsyncGenerator<unknown, unknown, void>;
|
|
9
|
-
/**
|
|
10
|
-
* Uniformly iterate a tool's `execute`, whether it returns a value, a
|
|
11
|
-
* promise, or an async generator.
|
|
12
|
-
*
|
|
13
|
-
* The helper is itself an async generator: each `yield` is a preliminary
|
|
14
|
-
* tool-update payload (only generator-style executes produce these), and the
|
|
15
|
-
* generator's `return` value is the final tool result.
|
|
16
|
-
*
|
|
17
|
-
* Streaming callers iterate and emit `tool-update` chunks live as updates
|
|
18
|
-
* arrive. Non-streaming callers iterate and discard yields, capturing only
|
|
19
|
-
* the final return value — same tool definition works in both modes.
|
|
20
|
-
*/
|
|
21
|
-
export declare function executeMaybeStreaming(tool: Tool, args: Record<string, unknown>, ctx: ToolCallContext): AsyncGenerator<unknown, unknown, void>;
|
|
22
|
-
/**
|
|
23
|
-
* Structured error returned to the model when a tool call's arguments fail
|
|
24
|
-
* the tool's `inputSchema`. Surfaced both as the `result` on `AgentStep`
|
|
25
|
-
* and as the JSON-encoded `tool` message the next provider step receives,
|
|
26
|
-
* so the model can correct itself on the next turn.
|
|
27
|
-
*/
|
|
28
|
-
export interface InvalidToolArgumentsError {
|
|
29
|
-
error: 'invalid_arguments';
|
|
30
|
-
message: string;
|
|
31
|
-
issues: Array<{
|
|
32
|
-
path: string;
|
|
33
|
-
message: string;
|
|
34
|
-
}>;
|
|
35
|
-
}
|
|
36
|
-
/**
|
|
37
|
-
* Validate a tool call's arguments against the tool's `inputSchema`. On
|
|
38
|
-
* success, the parsed value is returned — zod transforms (`.transform`,
|
|
39
|
-
* `.default`, type coercion) are applied, so `execute` receives the
|
|
40
|
-
* canonical shape the schema describes. On failure, a structured error
|
|
41
|
-
* suitable for feeding back to the model is returned.
|
|
42
|
-
*/
|
|
43
|
-
export declare function validateToolArgs(tool: Tool, args: Record<string, unknown>): {
|
|
44
|
-
ok: true;
|
|
45
|
-
value: Record<string, unknown>;
|
|
46
|
-
} | {
|
|
47
|
-
ok: false;
|
|
48
|
-
error: InvalidToolArgumentsError;
|
|
49
|
-
};
|
|
50
|
-
/**
|
|
51
|
-
* Default stringification used for the `tool` role message content when a
|
|
52
|
-
* tool has no `toModelOutput` transform: pass through strings, JSON-encode
|
|
53
|
-
* everything else.
|
|
54
|
-
*/
|
|
55
|
-
export declare function defaultStringify(value: unknown): string;
|
|
56
|
-
/**
|
|
57
|
-
* Convert a tool's structured `result` into the string the **model** will
|
|
58
|
-
* see on its next step. Honors `tool.toModelOutput` when present, falling
|
|
59
|
-
* back to {@link defaultStringify}.
|
|
60
|
-
*
|
|
61
|
-
* Per R6 in the ai-loop-parity plan: a throwing `toModelOutput` MUST NOT
|
|
62
|
-
* crash the loop. We swallow the error, route it through `onError`
|
|
63
|
-
* middleware so it stays observable, and use the default stringification
|
|
64
|
-
* as a safety net.
|
|
65
|
-
*/
|
|
66
|
-
export declare function applyToModelOutput(tool: Tool, result: unknown, onError?: (err: unknown) => void | Promise<void>): Promise<string>;
|
|
67
|
-
/**
|
|
68
|
-
* Resolve `needsApproval` for a tool call, taking into account the
|
|
69
|
-
* client-supplied `approvedToolCallIds` / `rejectedToolCallIds` lists.
|
|
70
|
-
*
|
|
71
|
-
* Returns:
|
|
72
|
-
* - `'allow'` — execute the tool normally (default; also when approved)
|
|
73
|
-
* - `'pending'` — needsApproval is truthy and the call has not been approved
|
|
74
|
-
* - `'rejected'` — the call appears in `rejectedToolCallIds`
|
|
75
|
-
*/
|
|
76
|
-
export declare function evaluateApproval(tool: Tool, tc: ToolCall, options: AgentPromptOptions | undefined): Promise<'allow' | 'pending' | 'rejected'>;
|
|
77
|
-
//# sourceMappingURL=tool-helpers.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"tool-helpers.d.ts","sourceRoot":"","sources":["../src/tool-helpers.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,kBAAkB,EAAE,IAAI,EAAE,QAAQ,EAAE,eAAe,EAAE,MAAM,YAAY,CAAA;AAErF;;;;;GAKG;AACH,wBAAgB,gBAAgB,CAAC,KAAK,EAAE,OAAO,GAAG,KAAK,IAAI,cAAc,CAAC,OAAO,EAAE,OAAO,EAAE,IAAI,CAAC,CAMhG;AAED;;;;;;;;;;;GAWG;AACH,wBAAuB,qBAAqB,CAC1C,IAAI,EAAE,IAAI,EACV,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAC7B,GAAG,EAAE,eAAe,GACnB,cAAc,CAAC,OAAO,EAAE,OAAO,EAAE,IAAI,CAAC,CAgBxC;AAED;;;;;GAKG;AACH,MAAM,WAAW,yBAAyB;IACxC,KAAK,EAAE,mBAAmB,CAAA;IAC1B,OAAO,EAAE,MAAM,CAAA;IACf,MAAM,EAAE,KAAK,CAAC;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,OAAO,EAAE,MAAM,CAAA;KAAE,CAAC,CAAA;CACjD;AAED;;;;;;GAMG;AACH,wBAAgB,gBAAgB,CAC9B,IAAI,EA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