ai 7.0.139 → 7.0.141
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/CHANGELOG.md +18 -0
- package/dist/index.d.ts +27 -4
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +148 -73
- package/dist/index.js.map +1 -1
- package/dist/internal/index.d.ts +28 -0
- package/dist/internal/index.d.ts.map +1 -1
- package/dist/internal/index.js +55 -3
- package/dist/internal/index.js.map +1 -1
- package/docs/03-agents/07-workflow-agent.mdx +20 -0
- package/docs/03-ai-sdk-core/15-tools-and-tool-calling.mdx +29 -0
- package/docs/03-ai-sdk-core/17-mcp-events.mdx +4 -1
- package/docs/03-ai-sdk-harnesses/05-harness-adapters.mdx +1 -1
- package/docs/07-reference/01-ai-sdk-core/01-generate-text.mdx +7 -0
- package/docs/07-reference/01-ai-sdk-core/02-stream-text.mdx +7 -0
- package/docs/07-reference/01-ai-sdk-core/16-tool-loop-agent.mdx +7 -0
- package/docs/07-reference/04-ai-sdk-workflow/01-workflow-agent.mdx +14 -0
- package/package.json +11 -11
- package/src/agent/tool-loop-agent-settings.ts +10 -0
- package/src/generate-text/collect-tool-approvals.ts +11 -0
- package/src/generate-text/execute-tools-from-stream.ts +10 -4
- package/src/generate-text/generate-text.ts +40 -19
- package/src/generate-text/stream-text.ts +27 -4
- package/src/generate-text/tool-call-concurrency.ts +80 -0
package/dist/index.js
CHANGED
|
@@ -1174,7 +1174,7 @@ function cloneValue(value) {
|
|
|
1174
1174
|
}
|
|
1175
1175
|
//#endregion
|
|
1176
1176
|
//#region src/version.ts
|
|
1177
|
-
const VERSION = "7.0.
|
|
1177
|
+
const VERSION = "7.0.141";
|
|
1178
1178
|
//#endregion
|
|
1179
1179
|
//#region src/util/download/download.ts
|
|
1180
1180
|
/**
|
|
@@ -2722,9 +2722,14 @@ function collectToolApprovals({ messages }) {
|
|
|
2722
2722
|
deniedToolApprovals: []
|
|
2723
2723
|
};
|
|
2724
2724
|
const toolCallsByToolCallId = Object.create(null);
|
|
2725
|
+
const toolCallOrder = Object.create(null);
|
|
2726
|
+
let nextToolCallIndex = 0;
|
|
2725
2727
|
for (const message of messages) if (message.role === "assistant" && typeof message.content !== "string") {
|
|
2726
2728
|
const content = message.content;
|
|
2727
|
-
for (const part of content) if (part.type === "tool-call")
|
|
2729
|
+
for (const part of content) if (part.type === "tool-call") {
|
|
2730
|
+
toolCallsByToolCallId[part.toolCallId] = part;
|
|
2731
|
+
toolCallOrder[part.toolCallId] = nextToolCallIndex++;
|
|
2732
|
+
}
|
|
2728
2733
|
}
|
|
2729
2734
|
const toolApprovalRequestsByApprovalId = Object.create(null);
|
|
2730
2735
|
for (const message of messages) if (message.role === "assistant" && typeof message.content !== "string") {
|
|
@@ -2755,6 +2760,7 @@ function collectToolApprovals({ messages }) {
|
|
|
2755
2760
|
if (approvalResponse.approved) approvedToolApprovals.push(approval);
|
|
2756
2761
|
else deniedToolApprovals.push(approval);
|
|
2757
2762
|
}
|
|
2763
|
+
approvedToolApprovals.sort((a, b) => toolCallOrder[a.toolCall.toolCallId] - toolCallOrder[b.toolCall.toolCallId]);
|
|
2758
2764
|
return {
|
|
2759
2765
|
approvedToolApprovals,
|
|
2760
2766
|
deniedToolApprovals
|
|
@@ -5212,6 +5218,52 @@ async function validateApprovedToolApprovals({ approvedToolApprovals, tools, too
|
|
|
5212
5218
|
};
|
|
5213
5219
|
}
|
|
5214
5220
|
//#endregion
|
|
5221
|
+
//#region src/generate-text/tool-call-concurrency.ts
|
|
5222
|
+
/**
|
|
5223
|
+
* Validates the maximum number of tool calls that may execute concurrently.
|
|
5224
|
+
*/
|
|
5225
|
+
function prepareToolCallConcurrency(toolCallConcurrency) {
|
|
5226
|
+
if (toolCallConcurrency == null) return;
|
|
5227
|
+
if (!Number.isInteger(toolCallConcurrency)) throw new InvalidArgumentError({
|
|
5228
|
+
parameter: "toolCallConcurrency",
|
|
5229
|
+
value: toolCallConcurrency,
|
|
5230
|
+
message: "toolCallConcurrency must be an integer"
|
|
5231
|
+
});
|
|
5232
|
+
if (toolCallConcurrency < 1) throw new InvalidArgumentError({
|
|
5233
|
+
parameter: "toolCallConcurrency",
|
|
5234
|
+
value: toolCallConcurrency,
|
|
5235
|
+
message: "toolCallConcurrency must be >= 1"
|
|
5236
|
+
});
|
|
5237
|
+
return toolCallConcurrency;
|
|
5238
|
+
}
|
|
5239
|
+
/**
|
|
5240
|
+
* Maps items with an optional concurrency limit while preserving result order.
|
|
5241
|
+
*
|
|
5242
|
+
* Workers claim items in input order. When the signal is aborted or an
|
|
5243
|
+
* execution rejects, no additional queued items are started.
|
|
5244
|
+
*/
|
|
5245
|
+
async function mapWithConcurrency({ items, concurrency, abortSignal, execute }) {
|
|
5246
|
+
if (concurrency == null || concurrency >= items.length) return Promise.all(items.map(execute));
|
|
5247
|
+
const results = new Array(items.length);
|
|
5248
|
+
let nextIndex = 0;
|
|
5249
|
+
let stopped = false;
|
|
5250
|
+
const worker = async () => {
|
|
5251
|
+
while (!stopped) {
|
|
5252
|
+
abortSignal?.throwIfAborted();
|
|
5253
|
+
const index = nextIndex++;
|
|
5254
|
+
if (index >= items.length) return;
|
|
5255
|
+
try {
|
|
5256
|
+
results[index] = await execute(items[index], index);
|
|
5257
|
+
} catch (error) {
|
|
5258
|
+
stopped = true;
|
|
5259
|
+
throw error;
|
|
5260
|
+
}
|
|
5261
|
+
}
|
|
5262
|
+
};
|
|
5263
|
+
await Promise.all(Array.from({ length: Math.min(concurrency, items.length) }, worker));
|
|
5264
|
+
return results;
|
|
5265
|
+
}
|
|
5266
|
+
//#endregion
|
|
5215
5267
|
//#region src/generate-text/generate-text.ts
|
|
5216
5268
|
const originalGenerateId$4 = createIdGenerator$1({
|
|
5217
5269
|
prefix: "aitxt",
|
|
@@ -5231,6 +5283,7 @@ const originalGenerateCallId$9 = createIdGenerator$1({
|
|
|
5231
5283
|
* @param tools - Tools that are accessible to and can be called by the model. The model needs to support calling tools.
|
|
5232
5284
|
* @param toolChoice - The tool choice strategy. Default: 'auto'.
|
|
5233
5285
|
* @param toolOrder - Controls the order in which tools are sent to the provider. Tools not listed are appended alphabetically.
|
|
5286
|
+
* @param toolCallConcurrency - Maximum number of tool calls that may execute concurrently within a step. Set to 1 for sequential execution. Default: unlimited.
|
|
5234
5287
|
*
|
|
5235
5288
|
* @param system - A system message that will be part of the prompt.
|
|
5236
5289
|
* @param prompt - A simple text prompt. You can either use `prompt` or `messages` but not both.
|
|
@@ -5288,12 +5341,13 @@ const originalGenerateCallId$9 = createIdGenerator$1({
|
|
|
5288
5341
|
* @returns
|
|
5289
5342
|
* A result object that contains the generated text, the results of the tool calls, and additional information.
|
|
5290
5343
|
*/
|
|
5291
|
-
async function generateText({ model: modelArg, tools, toolChoice, instructions, system, prompt, messages, allowSystemInMessages, maxRetries: maxRetriesArg, abortSignal, timeout, headers, stopWhen = isStepCount(1), experimental_sandbox: sandbox, output, toolApproval, experimental_toolCallers, experimental_toolApprovalSecret, experimental_telemetry, telemetry = experimental_telemetry, providerOptions, activeTools, toolOrder, prepareStep, experimental_repairToolCall, repairToolCall = experimental_repairToolCall, experimental_refineToolInput: refineToolInput, experimental_download: download, runtimeContext = {}, toolsContext = {}, experimental_include, include = experimental_include, _internal: { generateId = originalGenerateId$4, generateCallId = originalGenerateCallId$9, now: now$4 = now } = {}, onStart, experimental_onStart, onStepStart, experimental_onStepStart, onLanguageModelCallStart, experimental_onLanguageModelCallStart, onLanguageModelCallEnd, experimental_onLanguageModelCallEnd, onToolExecutionStart, onToolExecutionEnd, experimental_onToolCallStart, experimental_onToolCallFinish, onStepEnd, onStepFinish, onFinish, onEnd = onFinish, ...settings }) {
|
|
5344
|
+
async function generateText({ model: modelArg, tools, toolChoice, instructions, system, prompt, messages, allowSystemInMessages, maxRetries: maxRetriesArg, abortSignal, timeout, headers, stopWhen = isStepCount(1), experimental_sandbox: sandbox, output, toolApproval, experimental_toolCallers, experimental_toolApprovalSecret, experimental_telemetry, telemetry = experimental_telemetry, providerOptions, activeTools, toolOrder, toolCallConcurrency, prepareStep, experimental_repairToolCall, repairToolCall = experimental_repairToolCall, experimental_refineToolInput: refineToolInput, experimental_download: download, runtimeContext = {}, toolsContext = {}, experimental_include, include = experimental_include, _internal: { generateId = originalGenerateId$4, generateCallId = originalGenerateCallId$9, now: now$4 = now } = {}, onStart, experimental_onStart, onStepStart, experimental_onStepStart, onLanguageModelCallStart, experimental_onLanguageModelCallStart, onLanguageModelCallEnd, experimental_onLanguageModelCallEnd, onToolExecutionStart, onToolExecutionEnd, experimental_onToolCallStart, experimental_onToolCallFinish, onStepEnd, onStepFinish, onFinish, onEnd = onFinish, ...settings }) {
|
|
5292
5345
|
include = {
|
|
5293
5346
|
requestBody: include?.requestBody ?? false,
|
|
5294
5347
|
requestMessages: include?.requestMessages ?? false,
|
|
5295
5348
|
responseBody: include?.responseBody ?? false
|
|
5296
5349
|
};
|
|
5350
|
+
const resolvedToolCallConcurrency = prepareToolCallConcurrency(toolCallConcurrency);
|
|
5297
5351
|
const model = resolveLanguageModel(modelArg);
|
|
5298
5352
|
const resolvedToolCallers = resolveToolCallerConfiguration({
|
|
5299
5353
|
tools,
|
|
@@ -5418,7 +5472,8 @@ async function generateText({ model: modelArg, tools, toolChoice, instructions,
|
|
|
5418
5472
|
callbacks: [resolvedOnToolExecutionEnd, telemetryDispatcher.onToolExecutionEnd]
|
|
5419
5473
|
}),
|
|
5420
5474
|
executeToolInTelemetryContext: telemetryDispatcher.executeTool,
|
|
5421
|
-
runInTracingChannelSpan
|
|
5475
|
+
runInTracingChannelSpan,
|
|
5476
|
+
toolCallConcurrency: resolvedToolCallConcurrency
|
|
5422
5477
|
});
|
|
5423
5478
|
const toolContent = [];
|
|
5424
5479
|
for (const result of toolResults) {
|
|
@@ -5796,7 +5851,8 @@ async function generateText({ model: modelArg, tools, toolChoice, instructions,
|
|
|
5796
5851
|
callbacks: [resolvedOnToolExecutionEnd, telemetryDispatcher.onToolExecutionEnd]
|
|
5797
5852
|
}),
|
|
5798
5853
|
executeToolInTelemetryContext: telemetryDispatcher.executeTool,
|
|
5799
|
-
runInTracingChannelSpan
|
|
5854
|
+
runInTracingChannelSpan,
|
|
5855
|
+
toolCallConcurrency: resolvedToolCallConcurrency
|
|
5800
5856
|
});
|
|
5801
5857
|
for (const result of toolExecutionResults) {
|
|
5802
5858
|
toolExecutionMs[result.output.toolCallId] = result.toolExecutionMs;
|
|
@@ -5976,21 +6032,26 @@ async function generateText({ model: modelArg, tools, toolChoice, instructions,
|
|
|
5976
6032
|
execute: executeGenerateText
|
|
5977
6033
|
});
|
|
5978
6034
|
}
|
|
5979
|
-
async function executeTools({ toolCalls, tools, callId, messages, abortSignal, timeout, experimental_sandbox: sandbox, toolsContext, onToolExecutionStart, onToolExecutionEnd, executeToolInTelemetryContext, runInTracingChannelSpan }) {
|
|
5980
|
-
return (await
|
|
5981
|
-
|
|
5982
|
-
|
|
5983
|
-
callId,
|
|
5984
|
-
messages,
|
|
6035
|
+
async function executeTools({ toolCalls, tools, callId, messages, abortSignal, timeout, experimental_sandbox: sandbox, toolsContext, onToolExecutionStart, onToolExecutionEnd, executeToolInTelemetryContext, runInTracingChannelSpan, toolCallConcurrency }) {
|
|
6036
|
+
return (await mapWithConcurrency({
|
|
6037
|
+
items: toolCalls,
|
|
6038
|
+
concurrency: toolCallConcurrency,
|
|
5985
6039
|
abortSignal,
|
|
5986
|
-
|
|
5987
|
-
|
|
5988
|
-
|
|
5989
|
-
|
|
5990
|
-
|
|
5991
|
-
|
|
5992
|
-
|
|
5993
|
-
|
|
6040
|
+
execute: async (toolCall) => await executeToolCall({
|
|
6041
|
+
toolCall,
|
|
6042
|
+
tools,
|
|
6043
|
+
callId,
|
|
6044
|
+
messages,
|
|
6045
|
+
abortSignal,
|
|
6046
|
+
timeout,
|
|
6047
|
+
experimental_sandbox: sandbox,
|
|
6048
|
+
toolsContext,
|
|
6049
|
+
onToolExecutionStart,
|
|
6050
|
+
onToolExecutionEnd,
|
|
6051
|
+
executeToolInTelemetryContext,
|
|
6052
|
+
runInTracingChannelSpan
|
|
6053
|
+
})
|
|
6054
|
+
})).filter((result) => result != null);
|
|
5994
6055
|
}
|
|
5995
6056
|
//#endregion
|
|
5996
6057
|
//#region src/util/prepare-headers.ts
|
|
@@ -7808,7 +7869,7 @@ function isStreamRetryAttemptBoundaryPart(part) {
|
|
|
7808
7869
|
}
|
|
7809
7870
|
//#endregion
|
|
7810
7871
|
//#region src/generate-text/execute-tools-from-stream.ts
|
|
7811
|
-
function executeToolsFromStream({ stream, tools, callId, messages, abortSignal, timeout, experimental_sandbox: sandbox, toolsContext, toolApproval, runtimeContext, toolApprovalSecret, generateId, onToolExecutionStart, onToolExecutionEnd, executeToolInTelemetryContext, runInTracingChannelSpan }) {
|
|
7872
|
+
function executeToolsFromStream({ stream, tools, callId, messages, abortSignal, timeout, experimental_sandbox: sandbox, toolsContext, toolApproval, runtimeContext, toolApprovalSecret, generateId, onToolExecutionStart, onToolExecutionEnd, executeToolInTelemetryContext, runInTracingChannelSpan, toolCallConcurrency }) {
|
|
7812
7873
|
const toolCallsToExecute = [];
|
|
7813
7874
|
return stream.pipeThrough(new TransformStream({ async transform(chunk, controller) {
|
|
7814
7875
|
controller.enqueue(chunk);
|
|
@@ -7895,40 +7956,45 @@ function executeToolsFromStream({ stream, tools, callId, messages, abortSignal,
|
|
|
7895
7956
|
}
|
|
7896
7957
|
case "model-call-end":
|
|
7897
7958
|
if (!isToolExecutionAllowedFinishReason(chunk.finishReason)) return;
|
|
7898
|
-
await
|
|
7899
|
-
|
|
7900
|
-
|
|
7901
|
-
|
|
7902
|
-
|
|
7903
|
-
|
|
7904
|
-
|
|
7905
|
-
|
|
7906
|
-
|
|
7907
|
-
|
|
7908
|
-
|
|
7909
|
-
|
|
7910
|
-
|
|
7911
|
-
|
|
7912
|
-
|
|
7913
|
-
|
|
7914
|
-
|
|
7959
|
+
await mapWithConcurrency({
|
|
7960
|
+
items: toolCallsToExecute,
|
|
7961
|
+
concurrency: toolCallConcurrency,
|
|
7962
|
+
abortSignal,
|
|
7963
|
+
execute: async (toolCall) => {
|
|
7964
|
+
try {
|
|
7965
|
+
const result = await executeToolCall({
|
|
7966
|
+
toolCall,
|
|
7967
|
+
tools,
|
|
7968
|
+
callId,
|
|
7969
|
+
messages,
|
|
7970
|
+
abortSignal,
|
|
7971
|
+
timeout,
|
|
7972
|
+
experimental_sandbox: sandbox,
|
|
7973
|
+
toolsContext,
|
|
7974
|
+
onToolExecutionStart,
|
|
7975
|
+
onToolExecutionEnd,
|
|
7976
|
+
executeToolInTelemetryContext,
|
|
7977
|
+
runInTracingChannelSpan,
|
|
7978
|
+
onPreliminaryToolResult: (result) => {
|
|
7979
|
+
controller.enqueue(result);
|
|
7980
|
+
}
|
|
7981
|
+
});
|
|
7982
|
+
if (result != null) {
|
|
7983
|
+
controller.enqueue({
|
|
7984
|
+
type: "tool-execution-end",
|
|
7985
|
+
toolCallId: result.output.toolCallId,
|
|
7986
|
+
toolExecutionMs: result.toolExecutionMs
|
|
7987
|
+
});
|
|
7988
|
+
controller.enqueue(result.output);
|
|
7915
7989
|
}
|
|
7916
|
-
})
|
|
7917
|
-
if (result != null) {
|
|
7990
|
+
} catch (error) {
|
|
7918
7991
|
controller.enqueue({
|
|
7919
|
-
type: "
|
|
7920
|
-
|
|
7921
|
-
toolExecutionMs: result.toolExecutionMs
|
|
7992
|
+
type: "error",
|
|
7993
|
+
error
|
|
7922
7994
|
});
|
|
7923
|
-
controller.enqueue(result.output);
|
|
7924
7995
|
}
|
|
7925
|
-
} catch (error) {
|
|
7926
|
-
controller.enqueue({
|
|
7927
|
-
type: "error",
|
|
7928
|
-
error
|
|
7929
|
-
});
|
|
7930
7996
|
}
|
|
7931
|
-
})
|
|
7997
|
+
});
|
|
7932
7998
|
}
|
|
7933
7999
|
} }));
|
|
7934
8000
|
}
|
|
@@ -8654,6 +8720,7 @@ const originalGenerateCallId$7 = createIdGenerator$1({
|
|
|
8654
8720
|
* @param model - The language model to use.
|
|
8655
8721
|
* @param tools - Tools that are accessible to and can be called by the model. The model needs to support calling tools.
|
|
8656
8722
|
* @param toolOrder - Controls the order in which tools are sent to the provider. Tools not listed are appended alphabetically.
|
|
8723
|
+
* @param toolCallConcurrency - Maximum number of tool calls that may execute concurrently within a step. Set to 1 for sequential execution. Default: unlimited.
|
|
8657
8724
|
*
|
|
8658
8725
|
* @param system - A system message that will be part of the prompt.
|
|
8659
8726
|
* @param prompt - A simple text prompt. You can either use `prompt` or `messages` but not both.
|
|
@@ -8713,7 +8780,8 @@ const originalGenerateCallId$7 = createIdGenerator$1({
|
|
|
8713
8780
|
* @returns
|
|
8714
8781
|
* A result object for accessing different stream types and additional information.
|
|
8715
8782
|
*/
|
|
8716
|
-
function streamText({ model, tools, toolChoice, instructions, system, prompt, messages, allowSystemInMessages, maxRetries, streamRetries, abortSignal, timeout, headers, stopWhen = isStepCount(1), experimental_sandbox: sandbox, output, toolApproval, experimental_toolCallers, experimental_toolApprovalSecret, experimental_telemetry, telemetry = experimental_telemetry, prepareStep, providerOptions, activeTools, toolOrder, experimental_repairToolCall, repairToolCall = experimental_repairToolCall, experimental_refineToolInput: refineToolInput, experimental_transform: transform, experimental_download: download, includeRawChunks, onChunk, onError: onErrorArg, onFinish, onEnd = onFinish, onAbort, onStepEnd, onStepFinish, onStart, experimental_onStart, onStepStart, experimental_onStepStart, onLanguageModelCallStart, experimental_onLanguageModelCallStart, onLanguageModelCallEnd, experimental_onLanguageModelCallEnd, onToolExecutionStart, onToolExecutionEnd, experimental_onToolCallStart, experimental_onToolCallFinish, runtimeContext = {}, toolsContext = {}, experimental_include, include = experimental_include, _internal: { now: now$2 = now, generateId = originalGenerateId$2, generateCallId = originalGenerateCallId$7 } = {}, ...settings }) {
|
|
8783
|
+
function streamText({ model, tools, toolChoice, instructions, system, prompt, messages, allowSystemInMessages, maxRetries, streamRetries, abortSignal, timeout, headers, stopWhen = isStepCount(1), experimental_sandbox: sandbox, output, toolApproval, experimental_toolCallers, experimental_toolApprovalSecret, experimental_telemetry, telemetry = experimental_telemetry, prepareStep, providerOptions, activeTools, toolOrder, toolCallConcurrency, experimental_repairToolCall, repairToolCall = experimental_repairToolCall, experimental_refineToolInput: refineToolInput, experimental_transform: transform, experimental_download: download, includeRawChunks, onChunk, onError: onErrorArg, onFinish, onEnd = onFinish, onAbort, onStepEnd, onStepFinish, onStart, experimental_onStart, onStepStart, experimental_onStepStart, onLanguageModelCallStart, experimental_onLanguageModelCallStart, onLanguageModelCallEnd, experimental_onLanguageModelCallEnd, onToolExecutionStart, onToolExecutionEnd, experimental_onToolCallStart, experimental_onToolCallFinish, runtimeContext = {}, toolsContext = {}, experimental_include, include = experimental_include, _internal: { now: now$2 = now, generateId = originalGenerateId$2, generateCallId = originalGenerateCallId$7 } = {}, ...settings }) {
|
|
8784
|
+
const resolvedToolCallConcurrency = prepareToolCallConcurrency(toolCallConcurrency);
|
|
8717
8785
|
const totalTimeoutMs = getTotalTimeoutMs(timeout);
|
|
8718
8786
|
const stepTimeoutMs = getStepTimeoutMs(timeout);
|
|
8719
8787
|
const firstChunkTimeoutMs = getFirstChunkTimeoutMs(timeout);
|
|
@@ -8758,6 +8826,7 @@ function streamText({ model, tools, toolChoice, instructions, system, prompt, me
|
|
|
8758
8826
|
transforms: asArray(transform),
|
|
8759
8827
|
activeTools,
|
|
8760
8828
|
toolOrder,
|
|
8829
|
+
toolCallConcurrency: resolvedToolCallConcurrency,
|
|
8761
8830
|
repairToolCall,
|
|
8762
8831
|
refineToolInput,
|
|
8763
8832
|
stopConditions: asArray(stopWhen),
|
|
@@ -8964,7 +9033,7 @@ function applyStreamTextTransforms({ stream, transforms, tools, stopStream }) {
|
|
|
8964
9033
|
});
|
|
8965
9034
|
}
|
|
8966
9035
|
var DefaultStreamTextResult = class {
|
|
8967
|
-
constructor({ model, telemetry, headers, settings, maxRetries: maxRetriesArg, streamRetries: streamRetriesArg, abortSignal, stepTimeoutMs, stepAbortController, firstChunkTimeoutMs, firstChunkAbortController, chunkTimeoutMs, chunkAbortController, instructions, system, prompt, messages, allowSystemInMessages, experimental_sandbox: sandbox, tools, toolChoice, transforms, activeTools, toolOrder, repairToolCall, refineToolInput, stopConditions, output, toolApproval, experimental_toolCallers, experimental_toolApprovalSecret, providerOptions, prepareStep, now, generateId, generateCallId, timeout, onChunk, onError, canRetryStreamViaOnError, onEnd, onAbort, onStepFinish, onStart, onStepStart, onLanguageModelCallStart, onLanguageModelCallEnd, onToolExecutionStart, onToolExecutionEnd, runtimeContext, toolsContext, download, include }) {
|
|
9036
|
+
constructor({ model, telemetry, headers, settings, maxRetries: maxRetriesArg, streamRetries: streamRetriesArg, abortSignal, stepTimeoutMs, stepAbortController, firstChunkTimeoutMs, firstChunkAbortController, chunkTimeoutMs, chunkAbortController, instructions, system, prompt, messages, allowSystemInMessages, experimental_sandbox: sandbox, tools, toolChoice, transforms, activeTools, toolOrder, toolCallConcurrency, repairToolCall, refineToolInput, stopConditions, output, toolApproval, experimental_toolCallers, experimental_toolApprovalSecret, providerOptions, prepareStep, now, generateId, generateCallId, timeout, onChunk, onError, canRetryStreamViaOnError, onEnd, onAbort, onStepFinish, onStart, onStepStart, onLanguageModelCallStart, onLanguageModelCallEnd, onToolExecutionStart, onToolExecutionEnd, runtimeContext, toolsContext, download, include }) {
|
|
8968
9037
|
this._totalUsage = new DelayedPromise();
|
|
8969
9038
|
this._finishReason = new DelayedPromise();
|
|
8970
9039
|
this._rawFinishReason = new DelayedPromise();
|
|
@@ -9438,29 +9507,34 @@ var DefaultStreamTextResult = class {
|
|
|
9438
9507
|
...toolApproval.toolCall.toolMetadata != null ? { toolMetadata: toolApproval.toolCall.toolMetadata } : {}
|
|
9439
9508
|
});
|
|
9440
9509
|
const toolOutputs = [];
|
|
9441
|
-
await
|
|
9442
|
-
|
|
9443
|
-
|
|
9444
|
-
|
|
9445
|
-
|
|
9446
|
-
|
|
9447
|
-
|
|
9448
|
-
|
|
9449
|
-
|
|
9450
|
-
|
|
9451
|
-
|
|
9452
|
-
|
|
9453
|
-
|
|
9454
|
-
|
|
9455
|
-
|
|
9456
|
-
|
|
9510
|
+
await mapWithConcurrency({
|
|
9511
|
+
items: localApprovedToolApprovals,
|
|
9512
|
+
concurrency: toolCallConcurrency,
|
|
9513
|
+
abortSignal,
|
|
9514
|
+
execute: async (toolApproval) => {
|
|
9515
|
+
const result = await executeToolCall({
|
|
9516
|
+
toolCall: toolApproval.toolCall,
|
|
9517
|
+
tools,
|
|
9518
|
+
callId,
|
|
9519
|
+
messages: initialMessages,
|
|
9520
|
+
abortSignal,
|
|
9521
|
+
timeout,
|
|
9522
|
+
experimental_sandbox: sandbox,
|
|
9523
|
+
toolsContext,
|
|
9524
|
+
onToolExecutionStart: filterNullable(onToolExecutionStart, telemetryDispatcher.onToolExecutionStart),
|
|
9525
|
+
onToolExecutionEnd: filterNullable(onToolExecutionEnd, telemetryDispatcher.onToolExecutionEnd),
|
|
9526
|
+
executeToolInTelemetryContext: telemetryDispatcher.executeTool,
|
|
9527
|
+
runInTracingChannelSpan: runInTracingChannelSpanInStreamText,
|
|
9528
|
+
onPreliminaryToolResult: (result) => {
|
|
9529
|
+
toolExecutionStepStreamController?.enqueue(result);
|
|
9530
|
+
}
|
|
9531
|
+
});
|
|
9532
|
+
if (result != null) {
|
|
9533
|
+
toolExecutionStepStreamController?.enqueue(result.output);
|
|
9534
|
+
toolOutputs.push(result.output);
|
|
9457
9535
|
}
|
|
9458
|
-
});
|
|
9459
|
-
if (result != null) {
|
|
9460
|
-
toolExecutionStepStreamController?.enqueue(result.output);
|
|
9461
|
-
toolOutputs.push(result.output);
|
|
9462
9536
|
}
|
|
9463
|
-
})
|
|
9537
|
+
});
|
|
9464
9538
|
if (toolOutputs.length > 0 || localDeniedToolApprovalsWithoutResults.length > 0 || invalidToolApprovals.length > 0) {
|
|
9465
9539
|
const localToolContent = [];
|
|
9466
9540
|
for (const output of toolOutputs) localToolContent.push({
|
|
@@ -9834,7 +9908,8 @@ var DefaultStreamTextResult = class {
|
|
|
9834
9908
|
onToolExecutionStart: filterNullable(onToolExecutionStart, telemetryDispatcher.onToolExecutionStart),
|
|
9835
9909
|
onToolExecutionEnd: filterNullable(onToolExecutionEnd, telemetryDispatcher.onToolExecutionEnd),
|
|
9836
9910
|
executeToolInTelemetryContext: telemetryDispatcher.executeTool,
|
|
9837
|
-
runInTracingChannelSpan: runInTracingChannelSpanInStep
|
|
9911
|
+
runInTracingChannelSpan: runInTracingChannelSpanInStep,
|
|
9912
|
+
toolCallConcurrency
|
|
9838
9913
|
});
|
|
9839
9914
|
const getStepRequest = () => ({
|
|
9840
9915
|
...request,
|