ai 7.0.180 → 7.0.181
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 +11 -0
- package/dist/{default-stop-condition-vtYEJcnz.js → default-stop-condition-D8PwkeWe.js} +52 -27
- package/dist/default-stop-condition-D8PwkeWe.js.map +1 -0
- package/dist/{index-CM_8u8gB.d.ts → index-CKEJqCzY.d.ts} +69 -4
- package/dist/index-CKEJqCzY.d.ts.map +1 -0
- package/dist/index.d.ts +2 -2
- package/dist/index.js +192 -119
- package/dist/index.js.map +1 -1
- package/dist/internal/index.d.ts +8 -4
- package/dist/internal/index.d.ts.map +1 -1
- package/dist/internal/index.js +1 -1
- package/docs/03-agents/04-loop-control.mdx +35 -1
- package/docs/03-agents/08-terminal-ui.mdx +10 -0
- package/docs/03-ai-sdk-core/65-lifecycle-callbacks.mdx +6 -0
- package/docs/04-ai-sdk-ui/21-error-handling.mdx +21 -0
- package/docs/07-reference/01-ai-sdk-core/01-generate-text.mdx +19 -0
- package/docs/07-reference/01-ai-sdk-core/02-stream-text.mdx +25 -0
- package/docs/07-reference/01-ai-sdk-core/16-tool-loop-agent.mdx +7 -0
- package/docs/07-reference/06-ai-sdk-tui/01-run-agent-tui.mdx +3 -0
- package/package.json +4 -4
- package/src/agent/default-stop-condition.ts +12 -3
- package/src/agent/tool-loop-agent-settings.ts +11 -0
- package/src/agent/tool-loop-agent.ts +3 -1
- package/src/extract/restricted-telemetry-dispatcher.ts +9 -5
- package/src/generate-text/default-generate-text-result.ts +4 -0
- package/src/generate-text/generate-text-events.ts +7 -0
- package/src/generate-text/generate-text-result.ts +9 -0
- package/src/generate-text/generate-text.ts +37 -5
- package/src/generate-text/index.ts +1 -0
- package/src/generate-text/steering.ts +19 -5
- package/src/generate-text/stopped-by.ts +43 -0
- package/src/generate-text/stream-language-model-call.ts +21 -2
- package/src/generate-text/stream-text-result.ts +18 -0
- package/src/generate-text/stream-text.ts +59 -6
- package/src/logger/create-log-warnings.ts +17 -0
- package/src/model/as-language-model-v3.ts +3 -0
- package/src/model/as-language-model-v4.ts +5 -1
- package/src/model/resolve-model.ts +8 -3
- package/src/prompt/convert-to-language-model-prompt.ts +15 -6
- package/src/util/log-v2-compatibility-warning.ts +5 -2
- package/dist/default-stop-condition-vtYEJcnz.js.map +0 -1
- package/dist/index-CM_8u8gB.d.ts.map +0 -1
package/dist/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { t as __exportAll } from "./rolldown-runtime-D7D4PA-g.js";
|
|
2
|
-
import { $ as convertToLanguageModelPrompt, A as toolSearch, At as
|
|
2
|
+
import { $ as convertToLanguageModelPrompt, A as toolSearch, At as InvalidMessageRoleError, B as setAbortTimeout, Bt as InvalidToolApprovalError, C as resolveToolApproval, Ct as asLanguageModelV4, D as convertToReasoningOutputs, Dt as logWarnings, E as DefaultGenerateTextResult, Et as createLogWarnings, F as resolveGeneratedFileData, Ft as NoOutputGeneratedError, G as addLanguageModelUsage, H as mergeAbortSignals, I as DefaultGeneratedFile, It as MissingToolResultsError, J as standardizePrompt, K as asLanguageModelUsage, L as DefaultGeneratedFileWithType, Lt as ToolCallNotFoundForApprovalError, M as prepareToolsForToolCallers, Mt as UnsupportedModelVersionError, N as resolveToolCallerConfiguration, Nt as ToolCallRepairError, O as validateToolContext, Ot as notify, P as convertLanguageModelContent, Pt as NoSuchToolError, Q as createToolModelOutput, R as collectToolApprovals, Rt as InvalidToolInputError, S as filterIncludedContext, St as asVideoModelV4, T as getToolCallInputSchemaInput, Tt as asEmbeddingModelV4, U as getOwn, V as prepareRetries, Vt as InvalidArgumentError, W as addImageModelUsage, X as prepareToolChoice, Y as prepareTools, Z as prepareLanguageModelCallOptions, _ as createTelemetryDispatcher, _t as resolveSpeechModel, a as createAsyncIterableStream, at as convertDataContentToUint8Array, b as AI_SDK_TELEMETRY_TRACING_CHANNEL, bt as resolveVideoModel, c as validateApprovedToolApprovals, ct as download, dt as resolveDecisionModel, f as hashCanonical, ft as resolveEmbeddingModel, g as DefaultStepResult, gt as resolveRerankingModel, h as createRestrictedTelemetryDispatcher$4, ht as resolveLanguageModel, i as asAsyncIterableStream, it as convertDataContentToBase64String, j as appendToolCallerMessages, jt as InvalidDataContentError, k as createToolSearchState, kt as RetryError, l as maybeSignApproval, lt as VERSION, m as isDeepEqualData, mt as resolveImageModel, nt as convertToLanguageModelV4FilePart, o as mapWithConcurrency, ot as mergeObjects, p as toResponseMessages, pt as resolveExtractionModel, q as createNullLanguageModelUsage, r as isOutputChunk$1, rt as splitDataUrl, s as prepareToolCallConcurrency, t as createDefaultStopCondition, ut as asEvaluationModel, v as getGlobalTelemetryIntegrations, vt as resolveSpeechTranslationModel, w as parseToolCall, wt as asImageModelV4, x as mergeCallbacks, xt as asProviderV4, y as registerTelemetry, yt as resolveTranscriptionModel, z as calculateTokensPerSecond, zt as InvalidToolApprovalSignatureError } from "./default-stop-condition-D8PwkeWe.js";
|
|
3
3
|
import { t as simulateReadableStream } from "./simulate-readable-stream-Bi5kQKbv.js";
|
|
4
4
|
import { GatewayAuthenticationError, createGateway, gateway, gateway as gateway$1 } from "@ai-sdk/gateway";
|
|
5
5
|
import { DelayedPromise, DownloadError, DownloadError as DownloadError$1, EXPERIMENTAL_EMBEDDING_MODEL_MAX_INPUT_BYTES_PER_CALL, EXPERIMENTAL_EMBEDDING_MODEL_PROVIDER_OPTIONS_TRANSFORMER, asArray, asSchema, asSchema as asSchema$1, convertAsyncIteratorToReadableStream, convertBase64ToUint8Array, convertUint8ArrayToBase64, createIdGenerator, createIdGenerator as createIdGenerator$1, delay, detectMediaType, dynamicTool, executeTool, experimental_toolCaller, filterNullable, generateId, generateId as generateId$1, getErrorMessage, getRuntimeEnvironmentUserAgent, getTopLevelMediaType, getWebSocketConstructor, isAbortError, isArrayBuffer, isBuffer, isExecutableTool, isFullMediaType, isNonNullable, isProviderReference, isProviderStreamError, isUint8Array, jsonSchema, lazySchema, normalizeHeaders, parseJsonEventStream, parseJsonEventStream as parseJsonEventStream$1, readWebSocketMessageText, resolve, safeParseJSON, safeValidateTypes, toWebSocketUrl, tool, validateTypes, waitForWebSocketBufferDrain, withUserAgentSuffix, zodSchema, zodSchema as zodSchema$1 } from "@ai-sdk/provider-utils";
|
|
@@ -437,19 +437,6 @@ function now() {
|
|
|
437
437
|
return globalThis?.performance?.now() ?? Date.now();
|
|
438
438
|
}
|
|
439
439
|
//#endregion
|
|
440
|
-
//#region src/util/notify.ts
|
|
441
|
-
/**
|
|
442
|
-
* Notifies all provided callbacks with the given event in parallel.
|
|
443
|
-
* Errors in callbacks do not break the generation flow.
|
|
444
|
-
*/
|
|
445
|
-
async function notify(options) {
|
|
446
|
-
await Promise.all(asArray(options.callbacks).map(async (callback) => {
|
|
447
|
-
try {
|
|
448
|
-
await callback?.(options.event);
|
|
449
|
-
} catch {}
|
|
450
|
-
}));
|
|
451
|
-
}
|
|
452
|
-
//#endregion
|
|
453
440
|
//#region src/generate-text/execute-tool-call.ts
|
|
454
441
|
/**
|
|
455
442
|
* Executes a single tool call and manages its lifecycle callbacks.
|
|
@@ -1307,6 +1294,7 @@ const steeringRunStarter = Symbol.for("vercel.ai.steering.start");
|
|
|
1307
1294
|
var DefaultSteering = class {
|
|
1308
1295
|
constructor() {
|
|
1309
1296
|
this.state = "idle";
|
|
1297
|
+
this.endReason = "finished";
|
|
1310
1298
|
this.pending = [];
|
|
1311
1299
|
this.queued = [];
|
|
1312
1300
|
this.taken = [];
|
|
@@ -1350,7 +1338,7 @@ var DefaultSteering = class {
|
|
|
1350
1338
|
type: "not-delivered",
|
|
1351
1339
|
id,
|
|
1352
1340
|
message: userMessage,
|
|
1353
|
-
reason:
|
|
1341
|
+
reason: this.endReason
|
|
1354
1342
|
}) : new Promise((resolve) => {
|
|
1355
1343
|
target.push({
|
|
1356
1344
|
id,
|
|
@@ -1432,6 +1420,7 @@ var DefaultSteering = class {
|
|
|
1432
1420
|
this.pending = [];
|
|
1433
1421
|
this.queued = [];
|
|
1434
1422
|
this.state = "ended";
|
|
1423
|
+
this.endReason = reason;
|
|
1435
1424
|
this.interruptRequested = false;
|
|
1436
1425
|
this.onInterrupt = void 0;
|
|
1437
1426
|
for (const { id, message, resolve } of notDelivered) resolve({
|
|
@@ -1445,8 +1434,14 @@ var DefaultSteering = class {
|
|
|
1445
1434
|
}
|
|
1446
1435
|
};
|
|
1447
1436
|
function isSent({ message, sentMessages }) {
|
|
1448
|
-
const content =
|
|
1449
|
-
return sentMessages.some((sentMessage) => sentMessage === message || sentMessage.role === "user" &&
|
|
1437
|
+
const content = normalizeContent(message.content);
|
|
1438
|
+
return sentMessages.some((sentMessage) => sentMessage === message || sentMessage.role === "user" && normalizeContent(sentMessage.content) === content);
|
|
1439
|
+
}
|
|
1440
|
+
function normalizeContent(content) {
|
|
1441
|
+
return JSON.stringify((typeof content === "string" ? [{
|
|
1442
|
+
type: "text",
|
|
1443
|
+
text: content
|
|
1444
|
+
}] : content).map(({ providerOptions: _providerOptions, ...part }) => part));
|
|
1450
1445
|
}
|
|
1451
1446
|
/**
|
|
1452
1447
|
* Creates a steering object that sends user messages to a running generation.
|
|
@@ -1482,6 +1477,18 @@ function startSteeringRun(steering) {
|
|
|
1482
1477
|
return start.call(steering);
|
|
1483
1478
|
}
|
|
1484
1479
|
//#endregion
|
|
1480
|
+
//#region src/generate-text/stopped-by.ts
|
|
1481
|
+
function getPendingToolCallStoppedBy(step) {
|
|
1482
|
+
if (!isToolExecutionAllowedFinishReason(step.finishReason)) return "model";
|
|
1483
|
+
return hasPendingApproval(step) ? "approval" : "tool-without-execute";
|
|
1484
|
+
}
|
|
1485
|
+
function getModelStoppedBy(step) {
|
|
1486
|
+
return hasPendingApproval(step) ? "approval" : "model";
|
|
1487
|
+
}
|
|
1488
|
+
function hasPendingApproval({ content }) {
|
|
1489
|
+
return content.some((part) => part.type === "tool-approval-request" && part.isAutomatic !== true);
|
|
1490
|
+
}
|
|
1491
|
+
//#endregion
|
|
1485
1492
|
//#region src/generate-text/stop-condition.ts
|
|
1486
1493
|
/**
|
|
1487
1494
|
* Creates a stop condition that returns `true` when the number of completed
|
|
@@ -1604,6 +1611,7 @@ const originalGenerateCallId$10 = createIdGenerator$1({
|
|
|
1604
1611
|
* @param experimental_onToolCallFinish - Deprecated alias for `onToolExecutionEnd`.
|
|
1605
1612
|
* @param onStepFinish - Callback that is called when each step (LLM call) is finished, including intermediate steps.
|
|
1606
1613
|
* @param onStepError - Callback that is called when a step that started fails before it produces a step result, i.e. when the provider call throws or rejects, or when the call is aborted or times out.
|
|
1614
|
+
* @param onWarning - Callback that receives the warnings of the call instead of the global warning logger.
|
|
1607
1615
|
* @param onEnd - Callback that is called when all steps are finished and the response is complete.
|
|
1608
1616
|
* @param onFinish - Deprecated alias for `onEnd`.
|
|
1609
1617
|
*
|
|
@@ -1619,14 +1627,14 @@ async function generateText(options) {
|
|
|
1619
1627
|
throw error;
|
|
1620
1628
|
}
|
|
1621
1629
|
}
|
|
1622
|
-
async function generateTextInternal({ 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$10, now: now$4 = now } = {}, onStart, experimental_onStart, onStepStart, experimental_onStepStart, onLanguageModelCallStart, experimental_onLanguageModelCallStart, onLanguageModelCallEnd, experimental_onLanguageModelCallEnd, onToolExecutionStart, onToolExecutionEnd, experimental_onToolCallStart, experimental_onToolCallFinish, onStepEnd, onStepError, onStepFinish, onFinish, onEnd = onFinish, ...settings }, steeringRun) {
|
|
1630
|
+
async function generateTextInternal({ 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$10, now: now$4 = now } = {}, onStart, experimental_onStart, onStepStart, experimental_onStepStart, onLanguageModelCallStart, experimental_onLanguageModelCallStart, onLanguageModelCallEnd, experimental_onLanguageModelCallEnd, onToolExecutionStart, onToolExecutionEnd, experimental_onToolCallStart, experimental_onToolCallFinish, onStepEnd, onStepError, onStepFinish, onWarning, onFinish, onEnd = onFinish, ...settings }, steeringRun) {
|
|
1623
1631
|
include = {
|
|
1624
1632
|
requestBody: include?.requestBody ?? false,
|
|
1625
1633
|
requestMessages: include?.requestMessages ?? false,
|
|
1626
1634
|
responseBody: include?.responseBody ?? false
|
|
1627
1635
|
};
|
|
1628
1636
|
const resolvedToolCallConcurrency = prepareToolCallConcurrency(toolCallConcurrency);
|
|
1629
|
-
const model = resolveLanguageModel(modelArg);
|
|
1637
|
+
const model = resolveLanguageModel(modelArg, onWarning);
|
|
1630
1638
|
const resolvedToolCallers = resolveToolCallerConfiguration({
|
|
1631
1639
|
tools,
|
|
1632
1640
|
toolCallers: experimental_toolCallers
|
|
@@ -1643,6 +1651,7 @@ async function generateTextInternal({ model: modelArg, tools, toolChoice, instru
|
|
|
1643
1651
|
const resolvedOnToolExecutionStart = onToolExecutionStart ?? experimental_onToolCallStart;
|
|
1644
1652
|
const resolvedOnToolExecutionEnd = onToolExecutionEnd ?? experimental_onToolCallFinish;
|
|
1645
1653
|
const resolvedOnStepEnd = onStepEnd ?? onStepFinish;
|
|
1654
|
+
const logCallWarnings = createLogWarnings(onWarning);
|
|
1646
1655
|
const unsupportedTimeoutWarnings = [];
|
|
1647
1656
|
if (getFirstChunkTimeoutMs(timeout) != null) unsupportedTimeoutWarnings.push({
|
|
1648
1657
|
type: "unsupported",
|
|
@@ -1654,7 +1663,7 @@ async function generateTextInternal({ model: modelArg, tools, toolChoice, instru
|
|
|
1654
1663
|
feature: "timeout.chunkMs",
|
|
1655
1664
|
details: "The chunkMs timeout is only supported by streaming functions."
|
|
1656
1665
|
});
|
|
1657
|
-
if (unsupportedTimeoutWarnings.length > 0)
|
|
1666
|
+
if (unsupportedTimeoutWarnings.length > 0) logCallWarnings({
|
|
1658
1667
|
warnings: unsupportedTimeoutWarnings,
|
|
1659
1668
|
provider: model.provider,
|
|
1660
1669
|
model: model.modelId
|
|
@@ -1809,15 +1818,20 @@ async function generateTextInternal({ model: modelArg, tools, toolChoice, instru
|
|
|
1809
1818
|
let messagesForNextStep = [...initialMessages, ...initialResponseMessages];
|
|
1810
1819
|
const pendingDeferredToolCalls = /* @__PURE__ */ new Map();
|
|
1811
1820
|
let steeringEndReason = "finished";
|
|
1821
|
+
let stoppedBy = "model";
|
|
1812
1822
|
const shouldStartNextStep = async () => {
|
|
1813
1823
|
if (steps[steps.length - 1].finishReason === "interrupted") return false;
|
|
1814
1824
|
if (clientToolOutputs.length + deniedToolApprovalResponses.length !== clientToolCalls.length) {
|
|
1815
1825
|
steeringEndReason = "waiting-for-tool-results";
|
|
1826
|
+
stoppedBy = getPendingToolCallStoppedBy(steps[steps.length - 1]);
|
|
1816
1827
|
return false;
|
|
1817
1828
|
}
|
|
1818
1829
|
if (clientToolCalls.length === 0 && pendingDeferredToolCalls.size === 0) {
|
|
1819
1830
|
const isTruncated = steps[steps.length - 1].finishReason === "length" || steps[steps.length - 1].finishReason === "content-filter";
|
|
1820
|
-
if (!steeringRun?.hasPendingMessages() && (isTruncated || !steeringRun?.promoteQueuedMessage()))
|
|
1831
|
+
if (!steeringRun?.hasPendingMessages() && (isTruncated || !steeringRun?.promoteQueuedMessage())) {
|
|
1832
|
+
stoppedBy = getModelStoppedBy(steps[steps.length - 1]);
|
|
1833
|
+
return false;
|
|
1834
|
+
}
|
|
1821
1835
|
if (steps[steps.length - 1].finishReason === "error") {
|
|
1822
1836
|
steeringEndReason = "error";
|
|
1823
1837
|
return false;
|
|
@@ -1828,6 +1842,7 @@ async function generateTextInternal({ model: modelArg, tools, toolChoice, instru
|
|
|
1828
1842
|
steps
|
|
1829
1843
|
})) {
|
|
1830
1844
|
steeringEndReason = "stop-condition";
|
|
1845
|
+
stoppedBy = "stop-condition";
|
|
1831
1846
|
return false;
|
|
1832
1847
|
}
|
|
1833
1848
|
return true;
|
|
@@ -1879,7 +1894,7 @@ async function generateTextInternal({ model: modelArg, tools, toolChoice, instru
|
|
|
1879
1894
|
experimental_sandbox: sandbox
|
|
1880
1895
|
});
|
|
1881
1896
|
const stepSandbox = prepareStepResult?.experimental_sandbox ?? sandbox;
|
|
1882
|
-
const stepModel = resolveLanguageModel(prepareStepResult?.model ?? model);
|
|
1897
|
+
const stepModel = resolveLanguageModel(prepareStepResult?.model ?? model, onWarning);
|
|
1883
1898
|
const stepInstructions = prepareStepResult?.instructions ?? prepareStepResult?.system ?? instructionsForNextStep;
|
|
1884
1899
|
runtimeContext = prepareStepResult?.runtimeContext ?? runtimeContext;
|
|
1885
1900
|
toolsContext = prepareStepResult?.toolsContext ?? toolsContext;
|
|
@@ -1911,6 +1926,7 @@ async function generateTextInternal({ model: modelArg, tools, toolChoice, instru
|
|
|
1911
1926
|
stepNumber,
|
|
1912
1927
|
sentMessages: stepMessages
|
|
1913
1928
|
}) ?? []).map(({ message }) => message)];
|
|
1929
|
+
const promptWarnings = [];
|
|
1914
1930
|
const promptMessages = await convertToLanguageModelPrompt({
|
|
1915
1931
|
prompt: {
|
|
1916
1932
|
instructions: stepInstructions,
|
|
@@ -1919,8 +1935,10 @@ async function generateTextInternal({ model: modelArg, tools, toolChoice, instru
|
|
|
1919
1935
|
supportedUrls: await stepModel.supportedUrls,
|
|
1920
1936
|
download,
|
|
1921
1937
|
abortSignal: mergedAbortSignal,
|
|
1922
|
-
provider: stepModel.provider.split(".")[0]
|
|
1938
|
+
provider: stepModel.provider.split(".")[0],
|
|
1939
|
+
warnings: promptWarnings
|
|
1923
1940
|
});
|
|
1941
|
+
if (promptWarnings.length > 0) logCallWarnings({ warnings: promptWarnings });
|
|
1924
1942
|
const stepProviderOptions = mergeObjects(providerOptions, prepareStepResult?.providerOptions);
|
|
1925
1943
|
const stepCallSettings = prepareStepCallSettings({
|
|
1926
1944
|
callSettings,
|
|
@@ -2267,14 +2285,14 @@ async function generateTextInternal({ model: modelArg, tools, toolChoice, instru
|
|
|
2267
2285
|
rawFinishReason: currentModelResponse.finishReason.raw,
|
|
2268
2286
|
usage: stepUsage,
|
|
2269
2287
|
performance: stepPerformance,
|
|
2270
|
-
warnings: currentModelResponse.warnings,
|
|
2288
|
+
warnings: [...promptWarnings, ...currentModelResponse.warnings ?? []],
|
|
2271
2289
|
providerMetadata: currentModelResponse.providerMetadata,
|
|
2272
2290
|
request: stepRequest,
|
|
2273
2291
|
response: stepResponse,
|
|
2274
2292
|
toolsContext,
|
|
2275
2293
|
steeringMessages: stepSteeringMessages
|
|
2276
2294
|
});
|
|
2277
|
-
|
|
2295
|
+
logCallWarnings({
|
|
2278
2296
|
warnings: currentModelResponse.warnings ?? [],
|
|
2279
2297
|
provider: stepModel.provider,
|
|
2280
2298
|
model: stepModel.modelId
|
|
@@ -2322,37 +2340,39 @@ async function generateTextInternal({ model: modelArg, tools, toolChoice, instru
|
|
|
2322
2340
|
const staticToolResults = steps.flatMap((step) => step.staticToolResults);
|
|
2323
2341
|
const dynamicToolResults = steps.flatMap((step) => step.dynamicToolResults);
|
|
2324
2342
|
const warnings = steps.flatMap((step) => step.warnings ?? []);
|
|
2343
|
+
const onEndEvent = {
|
|
2344
|
+
callId,
|
|
2345
|
+
stepNumber: lastStep.stepNumber,
|
|
2346
|
+
model: lastStep.model,
|
|
2347
|
+
runtimeContext: lastStep.runtimeContext,
|
|
2348
|
+
finishReason: lastStep.finishReason,
|
|
2349
|
+
rawFinishReason: lastStep.rawFinishReason,
|
|
2350
|
+
stoppedBy,
|
|
2351
|
+
usage: totalUsage,
|
|
2352
|
+
totalUsage,
|
|
2353
|
+
content: steps.flatMap((step) => step.content),
|
|
2354
|
+
text: lastStep.text,
|
|
2355
|
+
reasoning: lastStep.reasoning,
|
|
2356
|
+
reasoningText: lastStep.reasoningText,
|
|
2357
|
+
files,
|
|
2358
|
+
sources,
|
|
2359
|
+
toolCalls,
|
|
2360
|
+
staticToolCalls,
|
|
2361
|
+
dynamicToolCalls,
|
|
2362
|
+
toolResults,
|
|
2363
|
+
staticToolResults,
|
|
2364
|
+
dynamicToolResults,
|
|
2365
|
+
responseMessages: [...initialResponseMessages, ...steps.flatMap((step) => step.response.messages)],
|
|
2366
|
+
warnings,
|
|
2367
|
+
request: lastStep.request,
|
|
2368
|
+
response: lastStep.response,
|
|
2369
|
+
providerMetadata: lastStep.providerMetadata,
|
|
2370
|
+
steps,
|
|
2371
|
+
finalStep: lastStep,
|
|
2372
|
+
toolsContext
|
|
2373
|
+
};
|
|
2325
2374
|
await notify({
|
|
2326
|
-
event:
|
|
2327
|
-
callId,
|
|
2328
|
-
stepNumber: lastStep.stepNumber,
|
|
2329
|
-
model: lastStep.model,
|
|
2330
|
-
runtimeContext: lastStep.runtimeContext,
|
|
2331
|
-
finishReason: lastStep.finishReason,
|
|
2332
|
-
rawFinishReason: lastStep.rawFinishReason,
|
|
2333
|
-
usage: totalUsage,
|
|
2334
|
-
totalUsage,
|
|
2335
|
-
content: steps.flatMap((step) => step.content),
|
|
2336
|
-
text: lastStep.text,
|
|
2337
|
-
reasoning: lastStep.reasoning,
|
|
2338
|
-
reasoningText: lastStep.reasoningText,
|
|
2339
|
-
files,
|
|
2340
|
-
sources,
|
|
2341
|
-
toolCalls,
|
|
2342
|
-
staticToolCalls,
|
|
2343
|
-
dynamicToolCalls,
|
|
2344
|
-
toolResults,
|
|
2345
|
-
staticToolResults,
|
|
2346
|
-
dynamicToolResults,
|
|
2347
|
-
responseMessages: [...initialResponseMessages, ...steps.flatMap((step) => step.response.messages)],
|
|
2348
|
-
warnings,
|
|
2349
|
-
request: lastStep.request,
|
|
2350
|
-
response: lastStep.response,
|
|
2351
|
-
providerMetadata: lastStep.providerMetadata,
|
|
2352
|
-
steps,
|
|
2353
|
-
finalStep: lastStep,
|
|
2354
|
-
toolsContext
|
|
2355
|
-
},
|
|
2375
|
+
event: onEndEvent,
|
|
2356
2376
|
callbacks: [onEnd, telemetryDispatcher.onEnd]
|
|
2357
2377
|
});
|
|
2358
2378
|
let resolvedOutput;
|
|
@@ -2369,7 +2389,8 @@ async function generateTextInternal({ model: modelArg, tools, toolChoice, instru
|
|
|
2369
2389
|
initialResponseMessages,
|
|
2370
2390
|
steps,
|
|
2371
2391
|
totalUsage,
|
|
2372
|
-
output: resolvedOutput
|
|
2392
|
+
output: resolvedOutput,
|
|
2393
|
+
stoppedBy
|
|
2373
2394
|
});
|
|
2374
2395
|
} catch (error) {
|
|
2375
2396
|
const wrappedError = wrapGatewayError(error);
|
|
@@ -4721,6 +4742,7 @@ async function streamLanguageModelCall({ model, tools, toolOrder, output, toolCh
|
|
|
4721
4742
|
messages,
|
|
4722
4743
|
allowSystemInMessages
|
|
4723
4744
|
});
|
|
4745
|
+
const promptWarnings = [];
|
|
4724
4746
|
const promptMessages = await convertToLanguageModelPrompt({
|
|
4725
4747
|
prompt: {
|
|
4726
4748
|
instructions: standardizedPrompt.instructions,
|
|
@@ -4729,7 +4751,8 @@ async function streamLanguageModelCall({ model, tools, toolOrder, output, toolCh
|
|
|
4729
4751
|
supportedUrls: await resolvedModel.supportedUrls,
|
|
4730
4752
|
download,
|
|
4731
4753
|
abortSignal,
|
|
4732
|
-
provider: resolvedModel.provider.split(".")[0]
|
|
4754
|
+
provider: resolvedModel.provider.split(".")[0],
|
|
4755
|
+
warnings: promptWarnings
|
|
4733
4756
|
});
|
|
4734
4757
|
const stepTools = await prepareTools({
|
|
4735
4758
|
tools,
|
|
@@ -4739,7 +4762,10 @@ async function streamLanguageModelCall({ model, tools, toolOrder, output, toolCh
|
|
|
4739
4762
|
});
|
|
4740
4763
|
const stepToolChoice = prepareToolChoice({ toolChoice });
|
|
4741
4764
|
await notify({
|
|
4742
|
-
event: {
|
|
4765
|
+
event: {
|
|
4766
|
+
promptMessages,
|
|
4767
|
+
promptWarnings
|
|
4768
|
+
},
|
|
4743
4769
|
callbacks: onStart
|
|
4744
4770
|
});
|
|
4745
4771
|
const languageModelCallStartEvent = {
|
|
@@ -4793,7 +4819,8 @@ async function streamLanguageModelCall({ model, tools, toolOrder, output, toolCh
|
|
|
4793
4819
|
callStartTimestampMs,
|
|
4794
4820
|
request,
|
|
4795
4821
|
onLanguageModelCallEnd,
|
|
4796
|
-
collectContent
|
|
4822
|
+
collectContent,
|
|
4823
|
+
promptWarnings
|
|
4797
4824
|
}));
|
|
4798
4825
|
return {
|
|
4799
4826
|
stream: createAsyncIterableStream(standardizedStream),
|
|
@@ -4801,7 +4828,7 @@ async function streamLanguageModelCall({ model, tools, toolOrder, output, toolCh
|
|
|
4801
4828
|
request
|
|
4802
4829
|
};
|
|
4803
4830
|
}
|
|
4804
|
-
function createLanguageModelV4StreamPartToLanguageModelStreamPartTransform({ tools, instructions, messages, repairToolCall, refineToolInput, download, abortSignal, callId, provider, modelId, toolChoice, generateId, now, callStartTimestampMs, request, onLanguageModelCallEnd, collectContent }) {
|
|
4831
|
+
function createLanguageModelV4StreamPartToLanguageModelStreamPartTransform({ tools, instructions, messages, repairToolCall, refineToolInput, download, abortSignal, callId, provider, modelId, toolChoice, generateId, now, callStartTimestampMs, request, onLanguageModelCallEnd, collectContent, promptWarnings }) {
|
|
4805
4832
|
const toolCallsByToolCallId = /* @__PURE__ */ new Map();
|
|
4806
4833
|
const modelCallContent = [];
|
|
4807
4834
|
const rawModelCallContent = [];
|
|
@@ -4815,7 +4842,15 @@ function createLanguageModelV4StreamPartToLanguageModelStreamPartTransform({ too
|
|
|
4815
4842
|
let previousOutputChunkTimestampMs;
|
|
4816
4843
|
const timeBetweenOutputChunksMs = [];
|
|
4817
4844
|
const withholdToolParts = toolChoice.type === "none";
|
|
4845
|
+
let hasStarted = false;
|
|
4818
4846
|
return new TransformStream({ async transform(chunk, controller) {
|
|
4847
|
+
if (!hasStarted && chunk.type !== "stream-start") {
|
|
4848
|
+
hasStarted = true;
|
|
4849
|
+
if (promptWarnings.length > 0) controller.enqueue({
|
|
4850
|
+
type: "model-call-start",
|
|
4851
|
+
warnings: promptWarnings
|
|
4852
|
+
});
|
|
4853
|
+
}
|
|
4819
4854
|
if (isOutputChunk(chunk)) {
|
|
4820
4855
|
const outputChunkTimestampMs = now();
|
|
4821
4856
|
if (timeToFirstOutputMs == null) timeToFirstOutputMs = outputChunkTimestampMs - callStartTimestampMs;
|
|
@@ -5113,8 +5148,9 @@ function createLanguageModelV4StreamPartToLanguageModelStreamPartTransform({ too
|
|
|
5113
5148
|
case "stream-start":
|
|
5114
5149
|
controller.enqueue({
|
|
5115
5150
|
type: "model-call-start",
|
|
5116
|
-
warnings: chunk.warnings
|
|
5151
|
+
warnings: [...promptWarnings, ...chunk.warnings]
|
|
5117
5152
|
});
|
|
5153
|
+
hasStarted = true;
|
|
5118
5154
|
break;
|
|
5119
5155
|
case "response-metadata":
|
|
5120
5156
|
responseId = chunk.id ?? responseId;
|
|
@@ -5266,6 +5302,7 @@ const originalGenerateCallId$8 = createIdGenerator$1({
|
|
|
5266
5302
|
* @param onStepEnd - Callback that is called when each step (LLM call) ends, including intermediate steps.
|
|
5267
5303
|
* @param onStepError - Callback that is called when a step that started fails before it produces a step result, i.e. when the provider call throws or rejects, or when the model stream ends without output. A provider `error` chunk still ends the step with `onStepEnd`, and an abort or timeout ends it with `onAbort`.
|
|
5268
5304
|
* @param onStepFinish - Deprecated alias for `onStepEnd`.
|
|
5305
|
+
* @param onWarning - Callback that receives the warnings of the call instead of the global warning logger.
|
|
5269
5306
|
* @param onEnd - Callback that is called when all steps are finished and the response is complete.
|
|
5270
5307
|
* @param onFinish - Deprecated alias for `onEnd`.
|
|
5271
5308
|
*
|
|
@@ -5303,7 +5340,7 @@ function startStreamText(options) {
|
|
|
5303
5340
|
throw error;
|
|
5304
5341
|
}
|
|
5305
5342
|
}
|
|
5306
|
-
function streamTextInternal({ 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, onStepError, 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$8, retention = {
|
|
5343
|
+
function streamTextInternal({ 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, onStepError, onStepFinish, onWarning, 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$8, retention = {
|
|
5307
5344
|
replay: true,
|
|
5308
5345
|
collectContent: true
|
|
5309
5346
|
} } = {}, ...settings }, steeringRun) {
|
|
@@ -5327,7 +5364,7 @@ function streamTextInternal({ model, tools, toolChoice, instructions, system, pr
|
|
|
5327
5364
|
const resolvedOnStepEnd = onStepEnd ?? onStepFinish;
|
|
5328
5365
|
return new DefaultStreamTextResult({
|
|
5329
5366
|
retention,
|
|
5330
|
-
model: resolveLanguageModel(model),
|
|
5367
|
+
model: resolveLanguageModel(model, onWarning),
|
|
5331
5368
|
telemetry,
|
|
5332
5369
|
headers,
|
|
5333
5370
|
settings,
|
|
@@ -5372,6 +5409,7 @@ function streamTextInternal({ model, tools, toolChoice, instructions, system, pr
|
|
|
5372
5409
|
onAbort,
|
|
5373
5410
|
onStepFinish: resolvedOnStepEnd,
|
|
5374
5411
|
onStepError,
|
|
5412
|
+
onWarning,
|
|
5375
5413
|
onStart: resolvedOnStart,
|
|
5376
5414
|
onStepStart: resolvedOnStepStart,
|
|
5377
5415
|
onLanguageModelCallStart: resolvedOnLanguageModelCallStart,
|
|
@@ -5591,10 +5629,11 @@ function applyStreamTextTransforms({ stream, transforms, tools, stopStream }) {
|
|
|
5591
5629
|
});
|
|
5592
5630
|
}
|
|
5593
5631
|
var DefaultStreamTextResult = class {
|
|
5594
|
-
constructor({ retention, model, telemetry, headers, settings, maxRetries: maxRetriesArg, streamRetries: streamRetriesArg, abortSignal, stepTimeoutMs, stepAbortController, firstChunkTimeoutMs, firstChunkAbortController, chunkTimeoutMs, chunkAbortController, instructions, system, prompt, messages, allowSystemInMessages, experimental_sandbox: sandbox, steeringRun, 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, onStepError, onStart, onStepStart, onLanguageModelCallStart, onLanguageModelCallEnd, onToolExecutionStart, onToolExecutionEnd, runtimeContext, toolsContext, download, include }) {
|
|
5632
|
+
constructor({ retention, model, telemetry, headers, settings, maxRetries: maxRetriesArg, streamRetries: streamRetriesArg, abortSignal, stepTimeoutMs, stepAbortController, firstChunkTimeoutMs, firstChunkAbortController, chunkTimeoutMs, chunkAbortController, instructions, system, prompt, messages, allowSystemInMessages, experimental_sandbox: sandbox, steeringRun, 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, onStepError, onWarning, onStart, onStepStart, onLanguageModelCallStart, onLanguageModelCallEnd, onToolExecutionStart, onToolExecutionEnd, runtimeContext, toolsContext, download, include }) {
|
|
5595
5633
|
this._totalUsage = new DelayedPromise();
|
|
5596
5634
|
this._finishReason = new DelayedPromise();
|
|
5597
5635
|
this._rawFinishReason = new DelayedPromise();
|
|
5636
|
+
this._stoppedBy = new DelayedPromise();
|
|
5598
5637
|
this._steps = new DelayedPromise();
|
|
5599
5638
|
this._initialResponseMessages = new DelayedPromise();
|
|
5600
5639
|
this.streamClaimed = false;
|
|
@@ -5615,13 +5654,16 @@ var DefaultStreamTextResult = class {
|
|
|
5615
5654
|
includeToolsContext: telemetry?.includeToolsContext
|
|
5616
5655
|
});
|
|
5617
5656
|
let stepFinish;
|
|
5657
|
+
const logCallWarnings = createLogWarnings(onWarning);
|
|
5618
5658
|
let recordedContent = [];
|
|
5619
5659
|
let recordedFinishReason = void 0;
|
|
5620
5660
|
let recordedRawFinishReason = void 0;
|
|
5661
|
+
let recordedStoppedBy = void 0;
|
|
5621
5662
|
let recordedTotalUsage = void 0;
|
|
5622
5663
|
let recordedRequest = {};
|
|
5623
5664
|
let recordedRequestMessages = [];
|
|
5624
5665
|
let recordedWarnings = [];
|
|
5666
|
+
let recordedPromptWarnings = [];
|
|
5625
5667
|
let recordedSteps = [];
|
|
5626
5668
|
const initialResponseMessages = [];
|
|
5627
5669
|
let stepMessagesForNextStep;
|
|
@@ -5828,8 +5870,8 @@ var DefaultStreamTextResult = class {
|
|
|
5828
5870
|
event: currentStepResult,
|
|
5829
5871
|
callbacks: [onStepFinish, telemetryDispatcher.onStepEnd]
|
|
5830
5872
|
});
|
|
5831
|
-
|
|
5832
|
-
warnings: recordedWarnings,
|
|
5873
|
+
logCallWarnings({
|
|
5874
|
+
warnings: recordedWarnings.filter((warning) => !recordedPromptWarnings.includes(warning)),
|
|
5833
5875
|
provider: currentStepModel.provider,
|
|
5834
5876
|
model: currentStepModel.modelId
|
|
5835
5877
|
});
|
|
@@ -5841,6 +5883,7 @@ var DefaultStreamTextResult = class {
|
|
|
5841
5883
|
recordedTotalUsage = part.totalUsage;
|
|
5842
5884
|
recordedFinishReason = part.finishReason;
|
|
5843
5885
|
recordedRawFinishReason = part.rawFinishReason;
|
|
5886
|
+
recordedStoppedBy = part.stoppedBy;
|
|
5844
5887
|
}
|
|
5845
5888
|
},
|
|
5846
5889
|
async flush(controller) {
|
|
@@ -5861,6 +5904,7 @@ var DefaultStreamTextResult = class {
|
|
|
5861
5904
|
const totalUsage = recordedTotalUsage ?? createNullLanguageModelUsage();
|
|
5862
5905
|
self._finishReason.resolve(finishReason);
|
|
5863
5906
|
self._rawFinishReason.resolve(recordedRawFinishReason);
|
|
5907
|
+
self._stoppedBy.resolve(recordedStoppedBy);
|
|
5864
5908
|
self._totalUsage.resolve(totalUsage);
|
|
5865
5909
|
self._steps.resolve(retention.replay ? recordedSteps : []);
|
|
5866
5910
|
if (isAborted) return;
|
|
@@ -5890,6 +5934,7 @@ var DefaultStreamTextResult = class {
|
|
|
5890
5934
|
runtimeContext: finalStep.runtimeContext,
|
|
5891
5935
|
finishReason: finalStep.finishReason,
|
|
5892
5936
|
rawFinishReason: finalStep.rawFinishReason,
|
|
5937
|
+
stoppedBy: recordedStoppedBy,
|
|
5893
5938
|
usage: totalUsage,
|
|
5894
5939
|
totalUsage,
|
|
5895
5940
|
content,
|
|
@@ -6279,7 +6324,7 @@ var DefaultStreamTextResult = class {
|
|
|
6279
6324
|
const stepSandbox = prepareStepResult?.experimental_sandbox ?? sandbox;
|
|
6280
6325
|
runtimeContext = prepareStepResult?.runtimeContext ?? runtimeContext;
|
|
6281
6326
|
toolsContext = prepareStepResult?.toolsContext ?? toolsContext;
|
|
6282
|
-
const stepModel = resolveLanguageModel(prepareStepResult?.model ?? model);
|
|
6327
|
+
const stepModel = resolveLanguageModel(prepareStepResult?.model ?? model, onWarning);
|
|
6283
6328
|
currentStepModel = stepModel;
|
|
6284
6329
|
const stepActiveTools = filterActiveTools({
|
|
6285
6330
|
tools,
|
|
@@ -6362,7 +6407,7 @@ var DefaultStreamTextResult = class {
|
|
|
6362
6407
|
let interruptWindowClosed = false;
|
|
6363
6408
|
let attemptInterrupted = false;
|
|
6364
6409
|
const callLanguageModel = () => runInStepTracingChannelContext(() => retry(async () => streamLanguageModelCall({
|
|
6365
|
-
model:
|
|
6410
|
+
model: stepModel,
|
|
6366
6411
|
tools: stepModelTools,
|
|
6367
6412
|
toolOrder: stepToolOrder,
|
|
6368
6413
|
toolChoice: prepareStepResult?.toolChoice ?? toolChoice,
|
|
@@ -6383,7 +6428,9 @@ var DefaultStreamTextResult = class {
|
|
|
6383
6428
|
experimental_sandbox: stepSandbox,
|
|
6384
6429
|
onLanguageModelCallStart: filterNullable(onLanguageModelCallStart, telemetryDispatcher.onLanguageModelCallStart),
|
|
6385
6430
|
onLanguageModelCallEnd: filterNullable(onLanguageModelCallEnd, telemetryDispatcher.onLanguageModelCallEnd),
|
|
6386
|
-
onStart: async ({ promptMessages }) => {
|
|
6431
|
+
onStart: async ({ promptMessages, promptWarnings }) => {
|
|
6432
|
+
recordedPromptWarnings = promptWarnings;
|
|
6433
|
+
if (!stepStart.notified && promptWarnings.length > 0) logCallWarnings({ warnings: promptWarnings });
|
|
6387
6434
|
if (stepStart.notified) return;
|
|
6388
6435
|
stepStart.notified = true;
|
|
6389
6436
|
const stepStartEvent = {
|
|
@@ -6852,15 +6899,20 @@ var DefaultStreamTextResult = class {
|
|
|
6852
6899
|
for (const output of stepToolOutputs) if (output.type === "tool-result" || output.type === "tool-error") pendingDeferredToolCalls.delete(output.toolCallId);
|
|
6853
6900
|
cleanupStepTimeouts();
|
|
6854
6901
|
let steeringEndReason = "finished";
|
|
6902
|
+
let stoppedBy = "model";
|
|
6855
6903
|
const shouldStartNextStep = async () => {
|
|
6856
6904
|
if (stepFinishReason === "interrupted") return false;
|
|
6857
6905
|
if (clientToolCalls.length !== clientToolOutputs.length + deniedToolApprovalResponses.length) {
|
|
6858
6906
|
steeringEndReason = "waiting-for-tool-results";
|
|
6907
|
+
stoppedBy = getPendingToolCallStoppedBy(recordedSteps[recordedSteps.length - 1]);
|
|
6859
6908
|
return false;
|
|
6860
6909
|
}
|
|
6861
6910
|
if (clientToolCalls.length === 0 && pendingDeferredToolCalls.size === 0) {
|
|
6862
6911
|
const isTruncated = stepFinishReason === "length" || stepFinishReason === "content-filter";
|
|
6863
|
-
if (!steeringRun?.hasPendingMessages() && (isTruncated || !steeringRun?.promoteQueuedMessage()))
|
|
6912
|
+
if (!steeringRun?.hasPendingMessages() && (isTruncated || !steeringRun?.promoteQueuedMessage())) {
|
|
6913
|
+
stoppedBy = getModelStoppedBy(recordedSteps[recordedSteps.length - 1]);
|
|
6914
|
+
return false;
|
|
6915
|
+
}
|
|
6864
6916
|
if (stepFinishReason === "error") {
|
|
6865
6917
|
steeringEndReason = "error";
|
|
6866
6918
|
return false;
|
|
@@ -6871,6 +6923,7 @@ var DefaultStreamTextResult = class {
|
|
|
6871
6923
|
steps: recordedSteps
|
|
6872
6924
|
})) {
|
|
6873
6925
|
steeringEndReason = "stop-condition";
|
|
6926
|
+
stoppedBy = "stop-condition";
|
|
6874
6927
|
return false;
|
|
6875
6928
|
}
|
|
6876
6929
|
return true;
|
|
@@ -6885,6 +6938,7 @@ var DefaultStreamTextResult = class {
|
|
|
6885
6938
|
type: "finish",
|
|
6886
6939
|
finishReason: stepFinishReason,
|
|
6887
6940
|
rawFinishReason: stepRawFinishReason,
|
|
6941
|
+
stoppedBy,
|
|
6888
6942
|
totalUsage: combinedUsage
|
|
6889
6943
|
});
|
|
6890
6944
|
self.closeStream();
|
|
@@ -6995,6 +7049,10 @@ var DefaultStreamTextResult = class {
|
|
|
6995
7049
|
if (this.retention.replay) this.consumeStream();
|
|
6996
7050
|
return this._rawFinishReason.promise;
|
|
6997
7051
|
}
|
|
7052
|
+
get stoppedBy() {
|
|
7053
|
+
if (this.retention.replay) this.consumeStream();
|
|
7054
|
+
return this._stoppedBy.promise;
|
|
7055
|
+
}
|
|
6998
7056
|
/**
|
|
6999
7057
|
* Split out a new stream from the original stream.
|
|
7000
7058
|
* The original stream is replaced to allow for further splitting,
|
|
@@ -7063,6 +7121,10 @@ var DefaultStreamTextResult = class {
|
|
|
7063
7121
|
delayedPromise: this._rawFinishReason,
|
|
7064
7122
|
error
|
|
7065
7123
|
});
|
|
7124
|
+
this.rejectResultPromise({
|
|
7125
|
+
delayedPromise: this._stoppedBy,
|
|
7126
|
+
error
|
|
7127
|
+
});
|
|
7066
7128
|
this.rejectResultPromise({
|
|
7067
7129
|
delayedPromise: this._totalUsage,
|
|
7068
7130
|
error
|
|
@@ -7257,7 +7319,7 @@ var ToolLoopAgent = class {
|
|
|
7257
7319
|
const { onStart: _settingsStableOnStart, experimental_onStart: _settingsExperimentalOnStart, onStepStart: _settingsStableOnStepStart, experimental_onStepStart: _settingsExperimentalOnStepStart, onToolExecutionStart: _settingsOnToolExecutionStart, onToolExecutionEnd: _settingsOnToolExecutionEnd, onStepEnd: _settingsOnStepEnd, onStepFinish: _settingsOnStepFinish, onError: _settingsOnError, onAbort: _settingsOnAbort, onFinish: _settingsOnFinish, onEnd: _settingsOnEnd, ...settingsWithoutCallbacks } = this.settings;
|
|
7258
7320
|
const baseCallArgs = {
|
|
7259
7321
|
...settingsWithoutCallbacks,
|
|
7260
|
-
stopWhen: this.settings.stopWhen ?? createDefaultStopCondition(20),
|
|
7322
|
+
stopWhen: this.settings.stopWhen ?? createDefaultStopCondition(20, this.settings.onWarning),
|
|
7261
7323
|
...options
|
|
7262
7324
|
};
|
|
7263
7325
|
const { instructions, allowSystemInMessages, messages, prompt, runtimeContext, ...callArgs } = await this.settings.prepareCall?.(baseCallArgs) ?? baseCallArgs;
|
|
@@ -10182,10 +10244,13 @@ function toTelemetryEvent(event) {
|
|
|
10182
10244
|
}
|
|
10183
10245
|
function redactFileLocations(state) {
|
|
10184
10246
|
if (!Array.isArray(state)) return state;
|
|
10185
|
-
return state.map((part) =>
|
|
10186
|
-
|
|
10187
|
-
|
|
10188
|
-
|
|
10247
|
+
return state.map((part) => {
|
|
10248
|
+
if (part?.type !== "text" && part?.type !== "file") return part;
|
|
10249
|
+
const copy = { ...part };
|
|
10250
|
+
delete copy.providerOptions;
|
|
10251
|
+
if (copy.type === "file" && isFileLocation(copy.data)) copy.data = "[redacted]";
|
|
10252
|
+
return copy;
|
|
10253
|
+
});
|
|
10189
10254
|
}
|
|
10190
10255
|
function isFileLocation(data) {
|
|
10191
10256
|
if (data instanceof URL) return true;
|
|
@@ -11036,22 +11101,23 @@ async function generateObject(options) {
|
|
|
11036
11101
|
provider: model.provider,
|
|
11037
11102
|
model: model.modelId
|
|
11038
11103
|
});
|
|
11104
|
+
const stepFinishEvent = {
|
|
11105
|
+
callId,
|
|
11106
|
+
stepNumber: 0,
|
|
11107
|
+
provider: model.provider,
|
|
11108
|
+
modelId: model.modelId,
|
|
11109
|
+
finishReason,
|
|
11110
|
+
usage,
|
|
11111
|
+
objectText: text,
|
|
11112
|
+
msToFirstChunk: void 0,
|
|
11113
|
+
reasoning,
|
|
11114
|
+
warnings,
|
|
11115
|
+
request,
|
|
11116
|
+
response,
|
|
11117
|
+
providerMetadata: resultProviderMetadata
|
|
11118
|
+
};
|
|
11039
11119
|
await notify({
|
|
11040
|
-
event:
|
|
11041
|
-
callId,
|
|
11042
|
-
stepNumber: 0,
|
|
11043
|
-
provider: model.provider,
|
|
11044
|
-
modelId: model.modelId,
|
|
11045
|
-
finishReason,
|
|
11046
|
-
usage,
|
|
11047
|
-
objectText: text,
|
|
11048
|
-
msToFirstChunk: void 0,
|
|
11049
|
-
reasoning,
|
|
11050
|
-
warnings,
|
|
11051
|
-
request,
|
|
11052
|
-
response,
|
|
11053
|
-
providerMetadata: resultProviderMetadata
|
|
11054
|
-
},
|
|
11120
|
+
event: stepFinishEvent,
|
|
11055
11121
|
callbacks: [resolvedOnStepEnd, telemetryDispatcher.onObjectStepEnd]
|
|
11056
11122
|
});
|
|
11057
11123
|
const object = await parseAndValidateObjectResultWithRepair(generateResult.structuredOutputText ?? text, outputStrategy, repairText, {
|
|
@@ -11905,8 +11971,8 @@ async function generateSpeech({ model, text, voice, outputFormat, instructions,
|
|
|
11905
11971
|
data: result.audio,
|
|
11906
11972
|
mediaType: detectedMediaType ?? getResponseAudioMediaType(result.response.headers) ?? getOutputFormatMediaType(outputFormat) ?? "audio/mp3"
|
|
11907
11973
|
});
|
|
11908
|
-
if (telemetryDispatcher.onEnd != null)
|
|
11909
|
-
|
|
11974
|
+
if (telemetryDispatcher.onEnd != null) {
|
|
11975
|
+
const endEvent = {
|
|
11910
11976
|
callId,
|
|
11911
11977
|
operationId: "ai.generateSpeech",
|
|
11912
11978
|
provider: resolvedModel.provider,
|
|
@@ -11921,9 +11987,12 @@ async function generateSpeech({ model, text, voice, outputFormat, instructions,
|
|
|
11921
11987
|
warnings: result.warnings,
|
|
11922
11988
|
providerMetadata: result.providerMetadata,
|
|
11923
11989
|
response: getTelemetryResponseMetadata(result.response)
|
|
11924
|
-
}
|
|
11925
|
-
|
|
11926
|
-
|
|
11990
|
+
};
|
|
11991
|
+
await notify({
|
|
11992
|
+
event: endEvent,
|
|
11993
|
+
callbacks: [telemetryDispatcher.onEnd]
|
|
11994
|
+
});
|
|
11995
|
+
}
|
|
11927
11996
|
return new DefaultSpeechResult({
|
|
11928
11997
|
audio,
|
|
11929
11998
|
warnings: result.warnings,
|
|
@@ -17141,26 +17210,27 @@ async function transcribe({ model, audio, providerOptions = {}, timestampGranula
|
|
|
17141
17210
|
model: resolvedModel.modelId
|
|
17142
17211
|
});
|
|
17143
17212
|
if (result.text == null) throw new NoTranscriptGeneratedError({ responses: [result.response] });
|
|
17144
|
-
|
|
17145
|
-
|
|
17146
|
-
|
|
17147
|
-
|
|
17148
|
-
|
|
17149
|
-
|
|
17150
|
-
|
|
17151
|
-
|
|
17152
|
-
mediaType
|
|
17153
|
-
},
|
|
17154
|
-
text: result.text,
|
|
17155
|
-
segments: result.segments,
|
|
17156
|
-
words: result.words,
|
|
17157
|
-
language: result.language,
|
|
17158
|
-
durationInSeconds: result.durationInSeconds,
|
|
17159
|
-
usage: result.usage,
|
|
17160
|
-
warnings: result.warnings,
|
|
17161
|
-
providerMetadata: result.providerMetadata,
|
|
17162
|
-
response: result.response
|
|
17213
|
+
const endEvent = {
|
|
17214
|
+
callId,
|
|
17215
|
+
operationId: "ai.transcribe",
|
|
17216
|
+
provider: resolvedModel.provider,
|
|
17217
|
+
modelId: resolvedModel.modelId,
|
|
17218
|
+
audio: {
|
|
17219
|
+
byteLength,
|
|
17220
|
+
mediaType
|
|
17163
17221
|
},
|
|
17222
|
+
text: result.text,
|
|
17223
|
+
segments: result.segments,
|
|
17224
|
+
words: result.words,
|
|
17225
|
+
language: result.language,
|
|
17226
|
+
durationInSeconds: result.durationInSeconds,
|
|
17227
|
+
usage: result.usage,
|
|
17228
|
+
warnings: result.warnings,
|
|
17229
|
+
providerMetadata: result.providerMetadata,
|
|
17230
|
+
response: result.response
|
|
17231
|
+
};
|
|
17232
|
+
await notify({
|
|
17233
|
+
event: endEvent,
|
|
17164
17234
|
callbacks: [telemetryDispatcher.onEnd]
|
|
17165
17235
|
});
|
|
17166
17236
|
return new DefaultTranscriptionResult({
|
|
@@ -17321,8 +17391,8 @@ function streamTranscribe({ model, audio, inputAudioFormat, providerOptions = {}
|
|
|
17321
17391
|
responsesPromise.resolve([currentResponseMetadata()]);
|
|
17322
17392
|
providerMetadataPromise.resolve(value.providerMetadata ?? {});
|
|
17323
17393
|
telemetrySettled = true;
|
|
17324
|
-
if (telemetryDispatcher.experimental_onStreamTranscriptionEnd != null)
|
|
17325
|
-
|
|
17394
|
+
if (telemetryDispatcher.experimental_onStreamTranscriptionEnd != null) {
|
|
17395
|
+
const endEvent = {
|
|
17326
17396
|
callId,
|
|
17327
17397
|
operationId: "ai.streamTranscribe",
|
|
17328
17398
|
provider: resolvedModel.provider,
|
|
@@ -17339,9 +17409,12 @@ function streamTranscribe({ model, audio, inputAudioFormat, providerOptions = {}
|
|
|
17339
17409
|
warnings,
|
|
17340
17410
|
providerMetadata: value.providerMetadata,
|
|
17341
17411
|
response: currentResponseMetadata()
|
|
17342
|
-
}
|
|
17343
|
-
|
|
17344
|
-
|
|
17412
|
+
};
|
|
17413
|
+
await notify({
|
|
17414
|
+
event: endEvent,
|
|
17415
|
+
callbacks: [telemetryDispatcher.experimental_onStreamTranscriptionEnd]
|
|
17416
|
+
});
|
|
17417
|
+
}
|
|
17345
17418
|
}
|
|
17346
17419
|
},
|
|
17347
17420
|
flush() {
|