ai 7.0.127 → 7.0.129
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 +53 -0
- package/dist/index.d.ts +230 -155
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +386 -209
- package/dist/index.js.map +1 -1
- package/dist/internal/index.d.ts +288 -70
- package/dist/internal/index.d.ts.map +1 -1
- package/dist/internal/index.js +407 -76
- package/dist/internal/index.js.map +1 -1
- package/dist/test/index.d.ts +25 -17
- package/dist/test/index.d.ts.map +1 -1
- package/dist/test/index.js +27 -21
- package/dist/test/index.js.map +1 -1
- package/docs/02-foundations/06-provider-options.mdx +11 -10
- package/docs/02-getting-started/03-nextjs-pages-router.mdx +1 -1
- package/docs/02-getting-started/07-expo.mdx +1 -1
- package/docs/03-agents/02-building-agents.mdx +16 -11
- package/docs/03-agents/07-workflow-agent.mdx +83 -15
- package/docs/03-ai-sdk-core/16-mcp-tools.mdx +44 -0
- package/docs/03-ai-sdk-core/17-runtime-and-tool-context.mdx +18 -14
- package/docs/03-ai-sdk-core/25-settings.mdx +3 -2
- package/docs/03-ai-sdk-core/26-reasoning.mdx +12 -5
- package/docs/03-ai-sdk-core/{32-evaluation.mdx → 32-decisions.mdx} +64 -67
- package/docs/03-ai-sdk-core/35-image-generation.mdx +3 -1
- package/docs/03-ai-sdk-core/45-provider-management.mdx +8 -8
- package/docs/03-ai-sdk-core/60-telemetry.mdx +40 -31
- package/docs/03-ai-sdk-core/65-lifecycle-callbacks.mdx +21 -22
- package/docs/03-ai-sdk-harnesses/08-terminal-ui.mdx +2 -2
- package/docs/04-ai-sdk-ui/21-error-handling.mdx +28 -3
- package/docs/06-advanced/09-multistep-interfaces.mdx +1 -1
- package/docs/07-reference/01-ai-sdk-core/01-generate-text.mdx +2 -2
- package/docs/07-reference/01-ai-sdk-core/02-stream-text.mdx +2 -2
- package/docs/07-reference/01-ai-sdk-core/14-decide.mdx +74 -0
- package/docs/07-reference/01-ai-sdk-core/23-create-mcp-client.mdx +58 -4
- package/docs/07-reference/01-ai-sdk-core/40-provider-registry.mdx +11 -11
- package/docs/07-reference/01-ai-sdk-core/42-custom-provider.mdx +9 -9
- package/docs/07-reference/01-ai-sdk-core/66-extract-reasoning-middleware.mdx +24 -8
- package/docs/07-reference/02-ai-sdk-ui/32-prune-messages.mdx +1 -1
- package/docs/07-reference/03-ai-sdk-rsc/01-stream-ui.mdx +1 -0
- package/docs/07-reference/04-ai-sdk-workflow/01-workflow-agent.mdx +39 -2
- package/docs/07-reference/05-ai-sdk-errors/ai-decision-unsupported-question-type-error.mdx +31 -0
- package/docs/07-reference/05-ai-sdk-errors/ai-no-such-model-error.mdx +3 -3
- package/docs/07-reference/05-ai-sdk-errors/ai-no-such-provider-error.mdx +3 -3
- package/docs/08-migration-guides/23-migration-guide-7-0.mdx +1 -1
- package/docs/08-migration-guides/29-migration-guide-4-0.mdx +1 -1
- package/docs/09-troubleshooting/05-tool-invocation-missing-result.mdx +2 -2
- package/package.json +15 -15
- package/src/decide/decide-events.ts +129 -0
- package/src/{evaluate/evaluate.ts → decide/decide.ts} +36 -38
- package/src/decide/decision-provider.ts +11 -0
- package/src/decide/decision-result.ts +39 -0
- package/src/decide/index.ts +64 -0
- package/src/{evaluate → decide}/restricted-telemetry-dispatcher.ts +7 -7
- package/src/{evaluate/validate-evaluation.ts → decide/validate-decision.ts} +9 -9
- package/src/error/index.ts +10 -1
- package/src/generate-object/generate-object.ts +10 -0
- package/src/generate-object/stream-object.ts +10 -0
- package/src/generate-speech/generated-audio-file.ts +5 -4
- package/src/generate-speech/index.ts +13 -1
- package/src/generate-text/default-generate-text-result.ts +127 -0
- package/src/generate-text/generate-text.ts +5 -123
- package/src/generate-text/tool-approval-signature.ts +7 -4
- package/src/global.ts +3 -2
- package/src/index.ts +1 -1
- package/src/logger/deprecations.ts +72 -0
- package/src/logger/log-warnings.ts +25 -3
- package/src/middleware/extract-reasoning-middleware.ts +25 -6
- package/src/model/as-language-model-v3.ts +4 -0
- package/src/model/resolve-model.ts +45 -14
- package/src/prompt/convert-to-language-model-prompt.ts +7 -1
- package/src/realtime/encode-realtime-frame.ts +7 -2
- package/src/registry/custom-provider.ts +38 -26
- package/src/registry/index.ts +13 -1
- package/src/registry/no-such-provider-error.ts +2 -0
- package/src/registry/provider-registry.ts +56 -29
- package/src/telemetry/create-telemetry-dispatcher.ts +17 -5
- package/src/telemetry/telemetry.ts +35 -19
- package/src/telemetry/tracing-channel.ts +1 -1
- package/src/test/decision-mock-model-v4.ts +35 -0
- package/src/transcribe/index.ts +13 -1
- package/src/transcribe/transcribe.ts +1 -1
- package/src/types/index.ts +1 -0
- package/src/types/language-model.ts +9 -1
- package/src/types/usage.ts +21 -0
- package/src/ui/chat.ts +25 -9
- package/src/ui/convert-to-model-messages.ts +40 -8
- package/src/ui/http-chat-transport.ts +5 -3
- package/src/ui/process-text-stream.ts +5 -1
- package/src/ui/process-ui-message-stream.ts +21 -0
- package/src/ui/text-stream-chat-transport.ts +3 -1
- package/src/ui/ui-messages.ts +8 -0
- package/src/ui/unavailable-tool.ts +17 -0
- package/src/ui/validate-ui-messages.ts +10 -2
- package/docs/07-reference/01-ai-sdk-core/14-evaluate.mdx +0 -74
- package/docs/07-reference/05-ai-sdk-errors/ai-evaluation-unsupported-question-type-error.mdx +0 -31
- package/src/evaluate/evaluate-events.ts +0 -131
- package/src/evaluate/evaluation-provider.ts +0 -6
- package/src/evaluate/evaluation-result.ts +0 -39
- package/src/evaluate/index.ts +0 -13
- package/src/test/evaluation-mock-model-v4.ts +0 -27
package/dist/index.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { t as __exportAll } from "./rolldown-runtime-D7D4PA-g.js";
|
|
2
2
|
import { GatewayAuthenticationError, GatewayError, createGateway, gateway, gateway as gateway$1 } from "@ai-sdk/gateway";
|
|
3
3
|
import { DEFAULT_MAX_DOWNLOAD_SIZE, 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, cancelResponseBody, convertBase64ToUint8Array, convertUint8ArrayToBase64, createIdGenerator, createIdGenerator as createIdGenerator$1, delay, detectMediaType, dynamicTool, executeTool, experimental_getToolCaller, experimental_toolCaller, fetchUntrustedUrl, filterNullable, generateId, generateId as generateId$1, getErrorMessage, getRuntimeEnvironmentUserAgent, isAbortError, isBuffer, isExecutableTool, isFullMediaType, isNonNullable, isProviderReference, isProviderStreamError, isUrlSupported, jsonSchema, jsonSchema as jsonSchema$1, lazySchema, normalizeHeaders, parseJsonEventStream, parseJsonEventStream as parseJsonEventStream$1, readResponseWithSizeLimit, resolve, retryWithExponentialBackoff, safeParseJSON, safeValidateTypes, tool, tool as tool$1, validateTypes, withUserAgentSuffix, zodSchema, zodSchema as zodSchema$1 } from "@ai-sdk/provider-utils";
|
|
4
|
-
import { AISDKError, AISDKError as AISDKError$1, APICallError, APICallError as APICallError$1, EmptyResponseBodyError, EmptyResponseBodyError as EmptyResponseBodyError$1,
|
|
4
|
+
import { AISDKError, AISDKError as AISDKError$1, APICallError, APICallError as APICallError$1, EmptyResponseBodyError, EmptyResponseBodyError as EmptyResponseBodyError$1, Experimental_DecisionUnsupportedQuestionTypeError, Experimental_DecisionUnsupportedQuestionTypeError as Experimental_DecisionUnsupportedQuestionTypeError$1, InvalidArgumentError as InvalidArgumentError$1, InvalidPromptError, InvalidPromptError as InvalidPromptError$1, InvalidResponseDataError, InvalidResponseDataError as InvalidResponseDataError$1, JSONParseError, JSONParseError as JSONParseError$1, LoadAPIKeyError, LoadSettingError, NoContentGeneratedError, NoSuchModelError, NoSuchModelError as NoSuchModelError$1, NoSuchProviderReferenceError, TooManyEmbeddingValuesForCallError, TypeValidationError, TypeValidationError as TypeValidationError$1, UnsupportedFunctionalityError, UnsupportedFunctionalityError as UnsupportedFunctionalityError$1, getErrorMessage as getErrorMessage$1, isJSONArray, isJSONObject } from "@ai-sdk/provider";
|
|
5
5
|
import { array, boolean, custom, discriminatedUnion, enum as enum$1, instanceof as instanceof$1, lazy, literal, looseObject, never, null as null$1, number, object, record, string, union, unknown } from "zod/v4";
|
|
6
6
|
//#region src/error/invalid-argument-error.ts
|
|
7
7
|
const name$23 = "AI_InvalidArgumentError";
|
|
@@ -528,6 +528,39 @@ var RetryError = class extends AISDKError$1 {
|
|
|
528
528
|
}
|
|
529
529
|
};
|
|
530
530
|
//#endregion
|
|
531
|
+
//#region src/error/index.ts
|
|
532
|
+
/** @deprecated Use `Experimental_DecisionUnsupportedQuestionTypeError` instead. */
|
|
533
|
+
const Experimental_EvaluationUnsupportedQuestionTypeError = Experimental_DecisionUnsupportedQuestionTypeError$1;
|
|
534
|
+
//#endregion
|
|
535
|
+
//#region src/logger/deprecations.ts
|
|
536
|
+
const deprecationCodes = /* @__PURE__ */ new Map([
|
|
537
|
+
["generateObject", "AISDK_DEP_GENERATE_OBJECT"],
|
|
538
|
+
["streamObject", "AISDK_DEP_STREAM_OBJECT"],
|
|
539
|
+
["experimental_generateSpeech", "AISDK_DEP_EXPERIMENTAL_GENERATE_SPEECH"],
|
|
540
|
+
["experimental_transcribe", "AISDK_DEP_EXPERIMENTAL_TRANSCRIBE"],
|
|
541
|
+
["\"image\" content part", "AISDK_DEP_IMAGE_CONTENT_PART"],
|
|
542
|
+
["\"tool-result\" content of type \"file-data\"", "AISDK_DEP_TOOL_RESULT_FILE_DATA"],
|
|
543
|
+
["\"tool-result\" content of type \"file-url\"", "AISDK_DEP_TOOL_RESULT_FILE_URL"],
|
|
544
|
+
["\"tool-result\" content of type \"file-id\"", "AISDK_DEP_TOOL_RESULT_FILE_ID"],
|
|
545
|
+
["\"tool-result\" content of type \"file-reference\"", "AISDK_DEP_TOOL_RESULT_FILE_REFERENCE"],
|
|
546
|
+
["\"tool-result\" content of type \"image-data\"", "AISDK_DEP_TOOL_RESULT_IMAGE_DATA"],
|
|
547
|
+
["\"tool-result\" content of type \"image-url\"", "AISDK_DEP_TOOL_RESULT_IMAGE_URL"],
|
|
548
|
+
["\"tool-result\" content of type \"image-file-id\"", "AISDK_DEP_TOOL_RESULT_IMAGE_FILE_ID"],
|
|
549
|
+
["\"tool-result\" content of type \"image-file-reference\"", "AISDK_DEP_TOOL_RESULT_IMAGE_FILE_REFERENCE"],
|
|
550
|
+
["rawInput in output-error UI message parts", "AISDK_DEP_UI_MESSAGE_RAW_INPUT"]
|
|
551
|
+
]);
|
|
552
|
+
/**
|
|
553
|
+
* Escape punctuation and UTF-16 code units without losing case or collapsing
|
|
554
|
+
* distinct settings. Underscores are escaped too, so `__` separates code parts.
|
|
555
|
+
*/
|
|
556
|
+
function encodeCodePart(value) {
|
|
557
|
+
return value.replace(/[^a-zA-Z0-9]/g, (character) => `_${character.charCodeAt(0).toString(16).toUpperCase().padStart(4, "0")}`);
|
|
558
|
+
}
|
|
559
|
+
function getDeprecationCode({ setting, provider }) {
|
|
560
|
+
if (provider == null) return deprecationCodes.get(setting) ?? `AISDK_DEP_SETTING_${encodeCodePart(setting)}`;
|
|
561
|
+
return `AISDK_DEP_PROVIDER_${encodeCodePart(provider)}__${encodeCodePart(setting)}`;
|
|
562
|
+
}
|
|
563
|
+
//#endregion
|
|
531
564
|
//#region src/logger/log-warnings.ts
|
|
532
565
|
/**
|
|
533
566
|
* Formats a warning object into a human-readable string with clear AI SDK branding.
|
|
@@ -558,9 +591,13 @@ function formatWarning({ warning, provider, model }) {
|
|
|
558
591
|
}
|
|
559
592
|
const FIRST_WARNING_INFO_MESSAGE = "AI SDK Warning System: To turn off warning logging, set the AI_SDK_LOG_WARNINGS global to false.";
|
|
560
593
|
let hasLoggedBefore = false;
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
594
|
+
const emittedDeprecationCodes = /* @__PURE__ */ new Set();
|
|
595
|
+
function emitWarning({ message, type, code }) {
|
|
596
|
+
if (typeof process !== "undefined" && typeof process.emitWarning === "function") process.emitWarning(message, code == null ? { type } : {
|
|
597
|
+
type,
|
|
598
|
+
code
|
|
599
|
+
});
|
|
600
|
+
else console.warn(code == null ? message : `[${code}] ${message}`);
|
|
564
601
|
}
|
|
565
602
|
/**
|
|
566
603
|
* Logs warnings to the console or uses a custom logger if configured.
|
|
@@ -568,7 +605,9 @@ function emitWarning({ message, type }) {
|
|
|
568
605
|
* The behavior can be customized via the `AI_SDK_LOG_WARNINGS` global variable:
|
|
569
606
|
* - If set to `false`, warnings are suppressed.
|
|
570
607
|
* - If set to a function, that function is called with the warnings.
|
|
571
|
-
* - Otherwise, warnings
|
|
608
|
+
* - Otherwise, warnings use `process.emitWarning` when available, falling back
|
|
609
|
+
* to `console.warn`. Deprecations have stable codes and are emitted once per
|
|
610
|
+
* code by the default logger. Custom loggers receive every warning.
|
|
572
611
|
*
|
|
573
612
|
* @param options - The options containing warnings and context.
|
|
574
613
|
* @param options.warnings - The warnings to log.
|
|
@@ -590,14 +629,25 @@ const logWarnings = (options) => {
|
|
|
590
629
|
type: "Warning"
|
|
591
630
|
});
|
|
592
631
|
}
|
|
593
|
-
for (const warning of options.warnings)
|
|
594
|
-
|
|
595
|
-
warning,
|
|
596
|
-
provider: options.provider
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
632
|
+
for (const warning of options.warnings) {
|
|
633
|
+
const code = warning.type === "deprecated" ? getDeprecationCode({
|
|
634
|
+
setting: warning.setting,
|
|
635
|
+
provider: options.provider
|
|
636
|
+
}) : void 0;
|
|
637
|
+
if (code != null) {
|
|
638
|
+
if (emittedDeprecationCodes.has(code)) continue;
|
|
639
|
+
emittedDeprecationCodes.add(code);
|
|
640
|
+
}
|
|
641
|
+
emitWarning({
|
|
642
|
+
message: formatWarning({
|
|
643
|
+
warning,
|
|
644
|
+
provider: options.provider,
|
|
645
|
+
model: options.model
|
|
646
|
+
}),
|
|
647
|
+
type: warning.type === "deprecated" ? "DeprecationWarning" : "Warning",
|
|
648
|
+
code
|
|
649
|
+
});
|
|
650
|
+
}
|
|
601
651
|
};
|
|
602
652
|
//#endregion
|
|
603
653
|
//#region src/util/log-v2-compatibility-warning.ts
|
|
@@ -720,7 +770,8 @@ function convertV2UsageToV3(usage) {
|
|
|
720
770
|
total: usage.outputTokens,
|
|
721
771
|
text: void 0,
|
|
722
772
|
reasoning: usage.reasoningTokens
|
|
723
|
-
}
|
|
773
|
+
},
|
|
774
|
+
raw: usage.totalTokens == null ? void 0 : { totalTokens: usage.totalTokens }
|
|
724
775
|
};
|
|
725
776
|
}
|
|
726
777
|
//#endregion
|
|
@@ -1057,18 +1108,19 @@ function resolveRerankingModel(model) {
|
|
|
1057
1108
|
}
|
|
1058
1109
|
return asRerankingModelV4(model);
|
|
1059
1110
|
}
|
|
1060
|
-
function
|
|
1111
|
+
function resolveDecisionModel(model) {
|
|
1061
1112
|
if (typeof model === "string") {
|
|
1062
1113
|
const provider = globalThis.AI_SDK_DEFAULT_PROVIDER ?? gateway$1;
|
|
1063
|
-
|
|
1114
|
+
const factory = provider.decisionModel ?? provider.evaluationModel;
|
|
1115
|
+
if (typeof factory !== "function") throw new NoSuchModelError$1({
|
|
1064
1116
|
modelId: model,
|
|
1065
|
-
modelType: "
|
|
1066
|
-
message: "The default provider does not support
|
|
1117
|
+
modelType: "decisionModel",
|
|
1118
|
+
message: "The default provider does not support decision models. Pass a decision model instance or configure AI_SDK_DEFAULT_PROVIDER with a decisionModel method."
|
|
1067
1119
|
});
|
|
1068
|
-
const resolvedModel =
|
|
1120
|
+
const resolvedModel = factory.call(provider, model);
|
|
1069
1121
|
if (resolvedModel == null) throw new NoSuchModelError$1({
|
|
1070
1122
|
modelId: model,
|
|
1071
|
-
modelType: "
|
|
1123
|
+
modelType: "decisionModel"
|
|
1072
1124
|
});
|
|
1073
1125
|
model = resolvedModel;
|
|
1074
1126
|
}
|
|
@@ -1077,11 +1129,31 @@ function resolveEvaluationModel(model) {
|
|
|
1077
1129
|
provider: model.provider,
|
|
1078
1130
|
modelId: model.modelId
|
|
1079
1131
|
});
|
|
1080
|
-
return model;
|
|
1132
|
+
if ("doDecide" in model) return model;
|
|
1133
|
+
const legacyModel = model;
|
|
1134
|
+
return {
|
|
1135
|
+
specificationVersion: legacyModel.specificationVersion,
|
|
1136
|
+
provider: legacyModel.provider,
|
|
1137
|
+
modelId: legacyModel.modelId,
|
|
1138
|
+
supportedQuestionTypes: legacyModel.supportedQuestionTypes,
|
|
1139
|
+
doDecide: (options) => legacyModel.doEvaluate(options)
|
|
1140
|
+
};
|
|
1081
1141
|
}
|
|
1082
1142
|
function getGlobalProvider() {
|
|
1083
1143
|
return asProviderV4(globalThis.AI_SDK_DEFAULT_PROVIDER ?? gateway$1);
|
|
1084
1144
|
}
|
|
1145
|
+
/** Internal adapter for deprecated provider factories. */
|
|
1146
|
+
function asEvaluationModel(model) {
|
|
1147
|
+
if ("doEvaluate" in model && typeof model.doEvaluate === "function") return model;
|
|
1148
|
+
return {
|
|
1149
|
+
specificationVersion: model.specificationVersion,
|
|
1150
|
+
provider: model.provider,
|
|
1151
|
+
modelId: model.modelId,
|
|
1152
|
+
supportedQuestionTypes: model.supportedQuestionTypes,
|
|
1153
|
+
doDecide: (options) => model.doDecide(options),
|
|
1154
|
+
doEvaluate: (options) => model.doDecide(options)
|
|
1155
|
+
};
|
|
1156
|
+
}
|
|
1085
1157
|
//#endregion
|
|
1086
1158
|
//#region src/prompt/clone-model-message.ts
|
|
1087
1159
|
/**
|
|
@@ -1102,7 +1174,7 @@ function cloneValue(value) {
|
|
|
1102
1174
|
}
|
|
1103
1175
|
//#endregion
|
|
1104
1176
|
//#region src/version.ts
|
|
1105
|
-
const VERSION = "7.0.
|
|
1177
|
+
const VERSION = "7.0.129";
|
|
1106
1178
|
//#endregion
|
|
1107
1179
|
//#region src/util/download/download.ts
|
|
1108
1180
|
/**
|
|
@@ -1358,7 +1430,7 @@ async function convertToLanguageModelPrompt({ prompt, supportedUrls, download, a
|
|
|
1358
1430
|
const lastContentPart = lastCombinedMessage.content.at(-1);
|
|
1359
1431
|
if (lastContentPart != null && lastCombinedMessage.providerOptions != null) lastContentPart.providerOptions = mergeObjects(lastCombinedMessage.providerOptions, lastContentPart.providerOptions);
|
|
1360
1432
|
lastCombinedMessage.content.push(...message.content);
|
|
1361
|
-
lastCombinedMessage.providerOptions = message.providerOptions;
|
|
1433
|
+
lastCombinedMessage.providerOptions = lastContentPart == null ? mergeObjects(lastCombinedMessage.providerOptions, message.providerOptions) : message.providerOptions;
|
|
1362
1434
|
} else combinedMessages.push(message);
|
|
1363
1435
|
}
|
|
1364
1436
|
const toolCallIds = /* @__PURE__ */ new Set();
|
|
@@ -2472,6 +2544,7 @@ function createNullLanguageModelUsage() {
|
|
|
2472
2544
|
};
|
|
2473
2545
|
}
|
|
2474
2546
|
function addLanguageModelUsage(usage1, usage2) {
|
|
2547
|
+
const raw = isNullLanguageModelUsage(usage1) ? usage2.raw : isNullLanguageModelUsage(usage2) ? usage1.raw : void 0;
|
|
2475
2548
|
return {
|
|
2476
2549
|
inputTokens: addTokenCounts(usage1.inputTokens, usage2.inputTokens),
|
|
2477
2550
|
inputTokenDetails: {
|
|
@@ -2484,9 +2557,13 @@ function addLanguageModelUsage(usage1, usage2) {
|
|
|
2484
2557
|
textTokens: addTokenCounts(usage1.outputTokenDetails?.textTokens, usage2.outputTokenDetails?.textTokens),
|
|
2485
2558
|
reasoningTokens: addTokenCounts(usage1.outputTokenDetails?.reasoningTokens, usage2.outputTokenDetails?.reasoningTokens)
|
|
2486
2559
|
},
|
|
2487
|
-
totalTokens: addTokenCounts(usage1.totalTokens, usage2.totalTokens)
|
|
2560
|
+
totalTokens: addTokenCounts(usage1.totalTokens, usage2.totalTokens),
|
|
2561
|
+
...raw == null ? {} : { raw }
|
|
2488
2562
|
};
|
|
2489
2563
|
}
|
|
2564
|
+
function isNullLanguageModelUsage(usage) {
|
|
2565
|
+
return usage.inputTokens == null && usage.inputTokenDetails?.noCacheTokens == null && usage.inputTokenDetails?.cacheReadTokens == null && usage.inputTokenDetails?.cacheWriteTokens == null && usage.outputTokens == null && usage.outputTokenDetails?.textTokens == null && usage.outputTokenDetails?.reasoningTokens == null && usage.totalTokens == null && usage.raw == null;
|
|
2566
|
+
}
|
|
2490
2567
|
function addTokenCounts(tokenCount1, tokenCount2) {
|
|
2491
2568
|
return tokenCount1 == null && tokenCount2 == null ? void 0 : (tokenCount1 ?? 0) + (tokenCount2 ?? 0);
|
|
2492
2569
|
}
|
|
@@ -3236,6 +3313,122 @@ function filterActiveTools({ tools, activeTools }) {
|
|
|
3236
3313
|
return Object.fromEntries(Object.entries(tools).filter(([name]) => activeTools.includes(name)));
|
|
3237
3314
|
}
|
|
3238
3315
|
//#endregion
|
|
3316
|
+
//#region src/generate-text/reasoning-output.ts
|
|
3317
|
+
function unwrapReasoningFileData(data) {
|
|
3318
|
+
if (typeof data === "object" && data !== null && "type" in data) return data.type === "data" ? data.data : data.url;
|
|
3319
|
+
return data;
|
|
3320
|
+
}
|
|
3321
|
+
function convertFromReasoningOutputs(parts) {
|
|
3322
|
+
return parts.map((part) => {
|
|
3323
|
+
if (part.type === "reasoning") return {
|
|
3324
|
+
type: "reasoning",
|
|
3325
|
+
text: part.text,
|
|
3326
|
+
...part.providerMetadata != null ? { providerOptions: part.providerMetadata } : {}
|
|
3327
|
+
};
|
|
3328
|
+
return {
|
|
3329
|
+
type: "reasoning-file",
|
|
3330
|
+
data: part.file.base64,
|
|
3331
|
+
mediaType: part.file.mediaType,
|
|
3332
|
+
...part.providerMetadata != null ? { providerOptions: part.providerMetadata } : {}
|
|
3333
|
+
};
|
|
3334
|
+
});
|
|
3335
|
+
}
|
|
3336
|
+
function convertToReasoningOutputs(parts) {
|
|
3337
|
+
return parts.map((part) => {
|
|
3338
|
+
if (part.type === "reasoning") return {
|
|
3339
|
+
type: "reasoning",
|
|
3340
|
+
text: part.text,
|
|
3341
|
+
...part.providerOptions != null ? { providerMetadata: part.providerOptions } : {}
|
|
3342
|
+
};
|
|
3343
|
+
const rawData = unwrapReasoningFileData(part.data);
|
|
3344
|
+
return {
|
|
3345
|
+
type: "reasoning-file",
|
|
3346
|
+
file: new DefaultGeneratedFile({
|
|
3347
|
+
data: rawData instanceof ArrayBuffer ? new Uint8Array(rawData) : rawData instanceof URL ? rawData.toString() : rawData,
|
|
3348
|
+
mediaType: part.mediaType
|
|
3349
|
+
}),
|
|
3350
|
+
...part.providerOptions != null ? { providerMetadata: part.providerOptions } : {}
|
|
3351
|
+
};
|
|
3352
|
+
});
|
|
3353
|
+
}
|
|
3354
|
+
//#endregion
|
|
3355
|
+
//#region src/generate-text/default-generate-text-result.ts
|
|
3356
|
+
var DefaultGenerateTextResult = class {
|
|
3357
|
+
constructor(options) {
|
|
3358
|
+
this.initialResponseMessages = options.initialResponseMessages;
|
|
3359
|
+
this.steps = options.steps;
|
|
3360
|
+
this._output = options.output;
|
|
3361
|
+
this.totalUsage = options.totalUsage;
|
|
3362
|
+
}
|
|
3363
|
+
get finalStep() {
|
|
3364
|
+
return this.steps.at(-1);
|
|
3365
|
+
}
|
|
3366
|
+
get content() {
|
|
3367
|
+
return this.steps.flatMap((step) => step.content);
|
|
3368
|
+
}
|
|
3369
|
+
get text() {
|
|
3370
|
+
return this.finalStep.text;
|
|
3371
|
+
}
|
|
3372
|
+
get files() {
|
|
3373
|
+
return this.steps.flatMap((step) => step.files);
|
|
3374
|
+
}
|
|
3375
|
+
get reasoningText() {
|
|
3376
|
+
return this.finalStep.reasoningText;
|
|
3377
|
+
}
|
|
3378
|
+
get reasoning() {
|
|
3379
|
+
return convertToReasoningOutputs(this.finalStep.reasoning);
|
|
3380
|
+
}
|
|
3381
|
+
get toolCalls() {
|
|
3382
|
+
return this.steps.flatMap((step) => step.toolCalls);
|
|
3383
|
+
}
|
|
3384
|
+
get staticToolCalls() {
|
|
3385
|
+
return this.steps.flatMap((step) => step.staticToolCalls);
|
|
3386
|
+
}
|
|
3387
|
+
get dynamicToolCalls() {
|
|
3388
|
+
return this.steps.flatMap((step) => step.dynamicToolCalls);
|
|
3389
|
+
}
|
|
3390
|
+
get toolResults() {
|
|
3391
|
+
return this.steps.flatMap((step) => step.toolResults);
|
|
3392
|
+
}
|
|
3393
|
+
get staticToolResults() {
|
|
3394
|
+
return this.steps.flatMap((step) => step.staticToolResults);
|
|
3395
|
+
}
|
|
3396
|
+
get dynamicToolResults() {
|
|
3397
|
+
return this.steps.flatMap((step) => step.dynamicToolResults);
|
|
3398
|
+
}
|
|
3399
|
+
get sources() {
|
|
3400
|
+
return this.steps.flatMap((step) => step.sources);
|
|
3401
|
+
}
|
|
3402
|
+
get finishReason() {
|
|
3403
|
+
return this.finalStep.finishReason;
|
|
3404
|
+
}
|
|
3405
|
+
get rawFinishReason() {
|
|
3406
|
+
return this.finalStep.rawFinishReason;
|
|
3407
|
+
}
|
|
3408
|
+
get warnings() {
|
|
3409
|
+
return this.steps.flatMap((step) => step.warnings ?? []);
|
|
3410
|
+
}
|
|
3411
|
+
get providerMetadata() {
|
|
3412
|
+
return this.finalStep.providerMetadata;
|
|
3413
|
+
}
|
|
3414
|
+
get response() {
|
|
3415
|
+
return this.finalStep.response;
|
|
3416
|
+
}
|
|
3417
|
+
get responseMessages() {
|
|
3418
|
+
return [...this.initialResponseMessages, ...this.steps.flatMap((step) => step.response.messages)];
|
|
3419
|
+
}
|
|
3420
|
+
get request() {
|
|
3421
|
+
return this.finalStep.request;
|
|
3422
|
+
}
|
|
3423
|
+
get usage() {
|
|
3424
|
+
return this.totalUsage;
|
|
3425
|
+
}
|
|
3426
|
+
get output() {
|
|
3427
|
+
if (this._output == null) throw new NoOutputGeneratedError();
|
|
3428
|
+
return this._output;
|
|
3429
|
+
}
|
|
3430
|
+
};
|
|
3431
|
+
//#endregion
|
|
3239
3432
|
//#region src/generate-text/is-tool-execution-allowed-finish-reason.ts
|
|
3240
3433
|
function isToolExecutionAllowedFinishReason(finishReason) {
|
|
3241
3434
|
return finishReason === "stop" || finishReason === "tool-calls";
|
|
@@ -4079,45 +4272,6 @@ function prepareStepCallSettings({ callSettings, stepSettings }) {
|
|
|
4079
4272
|
});
|
|
4080
4273
|
}
|
|
4081
4274
|
//#endregion
|
|
4082
|
-
//#region src/generate-text/reasoning-output.ts
|
|
4083
|
-
function unwrapReasoningFileData(data) {
|
|
4084
|
-
if (typeof data === "object" && data !== null && "type" in data) return data.type === "data" ? data.data : data.url;
|
|
4085
|
-
return data;
|
|
4086
|
-
}
|
|
4087
|
-
function convertFromReasoningOutputs(parts) {
|
|
4088
|
-
return parts.map((part) => {
|
|
4089
|
-
if (part.type === "reasoning") return {
|
|
4090
|
-
type: "reasoning",
|
|
4091
|
-
text: part.text,
|
|
4092
|
-
...part.providerMetadata != null ? { providerOptions: part.providerMetadata } : {}
|
|
4093
|
-
};
|
|
4094
|
-
return {
|
|
4095
|
-
type: "reasoning-file",
|
|
4096
|
-
data: part.file.base64,
|
|
4097
|
-
mediaType: part.file.mediaType,
|
|
4098
|
-
...part.providerMetadata != null ? { providerOptions: part.providerMetadata } : {}
|
|
4099
|
-
};
|
|
4100
|
-
});
|
|
4101
|
-
}
|
|
4102
|
-
function convertToReasoningOutputs(parts) {
|
|
4103
|
-
return parts.map((part) => {
|
|
4104
|
-
if (part.type === "reasoning") return {
|
|
4105
|
-
type: "reasoning",
|
|
4106
|
-
text: part.text,
|
|
4107
|
-
...part.providerOptions != null ? { providerMetadata: part.providerOptions } : {}
|
|
4108
|
-
};
|
|
4109
|
-
const rawData = unwrapReasoningFileData(part.data);
|
|
4110
|
-
return {
|
|
4111
|
-
type: "reasoning-file",
|
|
4112
|
-
file: new DefaultGeneratedFile({
|
|
4113
|
-
data: rawData instanceof ArrayBuffer ? new Uint8Array(rawData) : rawData instanceof URL ? rawData.toString() : rawData,
|
|
4114
|
-
mediaType: part.mediaType
|
|
4115
|
-
}),
|
|
4116
|
-
...part.providerOptions != null ? { providerMetadata: part.providerOptions } : {}
|
|
4117
|
-
};
|
|
4118
|
-
});
|
|
4119
|
-
}
|
|
4120
|
-
//#endregion
|
|
4121
4275
|
//#region src/generate-text/resolve-tool-approval.ts
|
|
4122
4276
|
/**
|
|
4123
4277
|
* Resolves the approval state for a tool call by checking user-supplied and tool-defined
|
|
@@ -4381,8 +4535,11 @@ function createTelemetryDispatcher({ telemetry }) {
|
|
|
4381
4535
|
includeRuntimeContext: telemetry?.includeRuntimeContext,
|
|
4382
4536
|
includeToolsContext: telemetry?.includeToolsContext
|
|
4383
4537
|
};
|
|
4384
|
-
const mergeTelemetryCallback = (key) => {
|
|
4385
|
-
const integrationCallbacks = integrations.map((integration) =>
|
|
4538
|
+
const mergeTelemetryCallback = (key, deprecatedKey) => {
|
|
4539
|
+
const integrationCallbacks = integrations.map((integration) => {
|
|
4540
|
+
const callback = integration[key] ?? (deprecatedKey == null ? void 0 : integration[deprecatedKey]);
|
|
4541
|
+
return typeof callback === "function" ? callback.bind(integration) : void 0;
|
|
4542
|
+
}).filter(Boolean).map((callback) => ((event) => callback(augmentEvent(event, telemetryMetadata))));
|
|
4386
4543
|
if (integrationCallbacks.length === 0) return;
|
|
4387
4544
|
const mergedIntegrationCallback = mergeCallbacks(...integrationCallbacks);
|
|
4388
4545
|
return async (event) => {
|
|
@@ -4418,10 +4575,10 @@ function createTelemetryDispatcher({ telemetry }) {
|
|
|
4418
4575
|
onEmbedEnd: mergeTelemetryCallback("onEmbedEnd"),
|
|
4419
4576
|
onRerankStart: mergeTelemetryCallback("onRerankStart"),
|
|
4420
4577
|
onRerankEnd: mergeTelemetryCallback("onRerankEnd"),
|
|
4421
|
-
|
|
4422
|
-
|
|
4423
|
-
|
|
4424
|
-
|
|
4578
|
+
experimental_onDecideStart: mergeTelemetryCallback("experimental_onDecideStart", "experimental_onEvaluateStart"),
|
|
4579
|
+
experimental_onDecisionModelCallStart: mergeTelemetryCallback("experimental_onDecisionModelCallStart", "experimental_onEvaluationModelCallStart"),
|
|
4580
|
+
experimental_onDecisionModelCallEnd: mergeTelemetryCallback("experimental_onDecisionModelCallEnd", "experimental_onEvaluationModelCallEnd"),
|
|
4581
|
+
experimental_onDecideEnd: mergeTelemetryCallback("experimental_onDecideEnd", "experimental_onEvaluateEnd"),
|
|
4425
4582
|
experimental_onStreamTranscriptionStart: mergeTelemetryCallback("experimental_onStreamTranscriptionStart"),
|
|
4426
4583
|
experimental_onStreamTranscriptionEnd: mergeTelemetryCallback("experimental_onStreamTranscriptionEnd"),
|
|
4427
4584
|
onEnd: mergeTelemetryCallback("onEnd"),
|
|
@@ -5849,81 +6006,6 @@ async function executeTools({ toolCalls, tools, callId, messages, abortSignal, t
|
|
|
5849
6006
|
runInTracingChannelSpan
|
|
5850
6007
|
})))).filter((result) => result != null);
|
|
5851
6008
|
}
|
|
5852
|
-
var DefaultGenerateTextResult = class {
|
|
5853
|
-
constructor(options) {
|
|
5854
|
-
this.initialResponseMessages = options.initialResponseMessages;
|
|
5855
|
-
this.steps = options.steps;
|
|
5856
|
-
this._output = options.output;
|
|
5857
|
-
this.totalUsage = options.totalUsage;
|
|
5858
|
-
}
|
|
5859
|
-
get finalStep() {
|
|
5860
|
-
return this.steps.at(-1);
|
|
5861
|
-
}
|
|
5862
|
-
get content() {
|
|
5863
|
-
return this.steps.flatMap((step) => step.content);
|
|
5864
|
-
}
|
|
5865
|
-
get text() {
|
|
5866
|
-
return this.finalStep.text;
|
|
5867
|
-
}
|
|
5868
|
-
get files() {
|
|
5869
|
-
return this.steps.flatMap((step) => step.files);
|
|
5870
|
-
}
|
|
5871
|
-
get reasoningText() {
|
|
5872
|
-
return this.finalStep.reasoningText;
|
|
5873
|
-
}
|
|
5874
|
-
get reasoning() {
|
|
5875
|
-
return convertToReasoningOutputs(this.finalStep.reasoning);
|
|
5876
|
-
}
|
|
5877
|
-
get toolCalls() {
|
|
5878
|
-
return this.steps.flatMap((step) => step.toolCalls);
|
|
5879
|
-
}
|
|
5880
|
-
get staticToolCalls() {
|
|
5881
|
-
return this.steps.flatMap((step) => step.staticToolCalls);
|
|
5882
|
-
}
|
|
5883
|
-
get dynamicToolCalls() {
|
|
5884
|
-
return this.steps.flatMap((step) => step.dynamicToolCalls);
|
|
5885
|
-
}
|
|
5886
|
-
get toolResults() {
|
|
5887
|
-
return this.steps.flatMap((step) => step.toolResults);
|
|
5888
|
-
}
|
|
5889
|
-
get staticToolResults() {
|
|
5890
|
-
return this.steps.flatMap((step) => step.staticToolResults);
|
|
5891
|
-
}
|
|
5892
|
-
get dynamicToolResults() {
|
|
5893
|
-
return this.steps.flatMap((step) => step.dynamicToolResults);
|
|
5894
|
-
}
|
|
5895
|
-
get sources() {
|
|
5896
|
-
return this.steps.flatMap((step) => step.sources);
|
|
5897
|
-
}
|
|
5898
|
-
get finishReason() {
|
|
5899
|
-
return this.finalStep.finishReason;
|
|
5900
|
-
}
|
|
5901
|
-
get rawFinishReason() {
|
|
5902
|
-
return this.finalStep.rawFinishReason;
|
|
5903
|
-
}
|
|
5904
|
-
get warnings() {
|
|
5905
|
-
return this.steps.flatMap((step) => step.warnings ?? []);
|
|
5906
|
-
}
|
|
5907
|
-
get providerMetadata() {
|
|
5908
|
-
return this.finalStep.providerMetadata;
|
|
5909
|
-
}
|
|
5910
|
-
get response() {
|
|
5911
|
-
return this.finalStep.response;
|
|
5912
|
-
}
|
|
5913
|
-
get responseMessages() {
|
|
5914
|
-
return [...this.initialResponseMessages, ...this.steps.flatMap((step) => step.response.messages)];
|
|
5915
|
-
}
|
|
5916
|
-
get request() {
|
|
5917
|
-
return this.finalStep.request;
|
|
5918
|
-
}
|
|
5919
|
-
get usage() {
|
|
5920
|
-
return this.totalUsage;
|
|
5921
|
-
}
|
|
5922
|
-
get output() {
|
|
5923
|
-
if (this._output == null) throw new NoOutputGeneratedError();
|
|
5924
|
-
return this._output;
|
|
5925
|
-
}
|
|
5926
|
-
};
|
|
5927
6009
|
//#endregion
|
|
5928
6010
|
//#region src/util/prepare-headers.ts
|
|
5929
6011
|
function prepareHeaders(headers, defaultHeaders) {
|
|
@@ -6521,7 +6603,7 @@ function createStreamingUIMessageState({ lastMessage, messageId }) {
|
|
|
6521
6603
|
partialToolCalls
|
|
6522
6604
|
};
|
|
6523
6605
|
}
|
|
6524
|
-
function processUIMessageStream({ stream, messageMetadataSchema, dataPartSchemas, runUpdateMessageJob, onError, onToolCall, onData }) {
|
|
6606
|
+
function processUIMessageStream({ stream, messageMetadataSchema, dataPartSchemas, runUpdateMessageJob, onError, onToolCall, onData, resetStateOnMessageIdChange = false }) {
|
|
6525
6607
|
return stream.pipeThrough(new TransformStream({ async transform(chunk, controller) {
|
|
6526
6608
|
await runUpdateMessageJob(async ({ state, write }) => {
|
|
6527
6609
|
function getCurrentStepParts() {
|
|
@@ -6987,6 +7069,10 @@ function processUIMessageStream({ stream, messageMetadataSchema, dataPartSchemas
|
|
|
6987
7069
|
break;
|
|
6988
7070
|
}
|
|
6989
7071
|
case "start":
|
|
7072
|
+
if (resetStateOnMessageIdChange && chunk.messageId != null && chunk.messageId !== state.message.id) Object.assign(state, createStreamingUIMessageState({
|
|
7073
|
+
lastMessage: void 0,
|
|
7074
|
+
messageId: chunk.messageId
|
|
7075
|
+
}), { finishReason: void 0 });
|
|
6990
7076
|
if (chunk.messageId != null) state.message.id = chunk.messageId;
|
|
6991
7077
|
await updateMessageMetadata(chunk.messageMetadata);
|
|
6992
7078
|
if (chunk.messageId != null || chunk.messageMetadata != null) write({ updateStatus: false });
|
|
@@ -10540,6 +10626,15 @@ function readUIMessageStream({ message, stream, onError, terminateOnError = fals
|
|
|
10540
10626
|
return createAsyncIterableStream(outputStream);
|
|
10541
10627
|
}
|
|
10542
10628
|
//#endregion
|
|
10629
|
+
//#region src/ui/unavailable-tool.ts
|
|
10630
|
+
function markToolPartAsUnavailable(part) {
|
|
10631
|
+
part.dynamic = false;
|
|
10632
|
+
return part;
|
|
10633
|
+
}
|
|
10634
|
+
function isToolPartFromUnavailableTool(part) {
|
|
10635
|
+
return part.type === "dynamic-tool" && part.dynamic === false;
|
|
10636
|
+
}
|
|
10637
|
+
//#endregion
|
|
10543
10638
|
//#region src/ui/warn-if-ui-message-has-deprecated-raw-input.ts
|
|
10544
10639
|
const rawInputDeprecationWarning = {
|
|
10545
10640
|
type: "deprecated",
|
|
@@ -10570,6 +10665,20 @@ async function convertToModelMessages(messages, options) {
|
|
|
10570
10665
|
...message,
|
|
10571
10666
|
parts: message.parts.filter((part) => !isToolUIPart(part) || (part.state !== "approval-requested" || messageIndex >= lastUserMessageIndex) && (!options?.ignoreIncompleteToolCalls || part.state === "approval-responded" || part.state === "output-available" && part.preliminary !== true || part.state === "output-error" || part.state === "output-denied"))
|
|
10572
10667
|
}));
|
|
10668
|
+
async function createModelOutput({ toolPart, toolName, output, errorMode }) {
|
|
10669
|
+
const tool = getOwn(options?.tools, toolName);
|
|
10670
|
+
if (errorMode === "none" && tool == null && isToolPartFromUnavailableTool(toolPart)) return {
|
|
10671
|
+
type: "text",
|
|
10672
|
+
value: "Tool output omitted because the tool is no longer available."
|
|
10673
|
+
};
|
|
10674
|
+
return createToolModelOutput({
|
|
10675
|
+
toolCallId: toolPart.toolCallId,
|
|
10676
|
+
input: toolPart.input,
|
|
10677
|
+
output,
|
|
10678
|
+
tool,
|
|
10679
|
+
errorMode
|
|
10680
|
+
});
|
|
10681
|
+
}
|
|
10573
10682
|
for (const message of messages) switch (message.role) {
|
|
10574
10683
|
case "system": {
|
|
10575
10684
|
const textParts = message.parts.filter((part) => part.type === "text");
|
|
@@ -10683,11 +10792,10 @@ async function convertToModelMessages(messages, options) {
|
|
|
10683
10792
|
type: "tool-result",
|
|
10684
10793
|
toolCallId: part.toolCallId,
|
|
10685
10794
|
toolName,
|
|
10686
|
-
output: await
|
|
10687
|
-
|
|
10688
|
-
|
|
10795
|
+
output: await createModelOutput({
|
|
10796
|
+
toolPart: part,
|
|
10797
|
+
toolName,
|
|
10689
10798
|
output: part.state === "output-error" ? part.errorText : part.output,
|
|
10690
|
-
tool: getOwn(options?.tools, toolName),
|
|
10691
10799
|
errorMode: part.state === "output-error" ? "json" : "none"
|
|
10692
10800
|
}),
|
|
10693
10801
|
...resultProviderMetadata != null ? { providerOptions: resultProviderMetadata } : {}
|
|
@@ -10744,11 +10852,10 @@ async function convertToModelMessages(messages, options) {
|
|
|
10744
10852
|
type: "tool-result",
|
|
10745
10853
|
toolCallId: toolPart.toolCallId,
|
|
10746
10854
|
toolName,
|
|
10747
|
-
output: await
|
|
10748
|
-
|
|
10749
|
-
|
|
10855
|
+
output: await createModelOutput({
|
|
10856
|
+
toolPart,
|
|
10857
|
+
toolName,
|
|
10750
10858
|
output: toolPart.state === "output-error" ? toolPart.errorText : toolPart.output,
|
|
10751
|
-
tool: getOwn(options?.tools, toolName),
|
|
10752
10859
|
errorMode: toolPart.state === "output-error" ? "text" : "none"
|
|
10753
10860
|
}),
|
|
10754
10861
|
...toolPart.callProviderMetadata != null ? { providerOptions: toolPart.callProviderMetadata } : {}
|
|
@@ -10789,11 +10896,11 @@ function isEmptyObject(value) {
|
|
|
10789
10896
|
}
|
|
10790
10897
|
function asDynamicToolPart(toolPart) {
|
|
10791
10898
|
const { type, ...part } = toolPart;
|
|
10792
|
-
return {
|
|
10899
|
+
return markToolPartAsUnavailable({
|
|
10793
10900
|
...part,
|
|
10794
10901
|
type: "dynamic-tool",
|
|
10795
10902
|
toolName: type.slice(5)
|
|
10796
|
-
};
|
|
10903
|
+
});
|
|
10797
10904
|
}
|
|
10798
10905
|
function getToolPartInputSchemaInput(toolPart) {
|
|
10799
10906
|
return toolPart.approval != null && Object.prototype.hasOwnProperty.call(toolPart.approval, "inputSchemaInput") ? { value: toolPart.approval.inputSchemaInput } : void 0;
|
|
@@ -10879,6 +10986,7 @@ const uiMessagesSchema = lazySchema(() => {
|
|
|
10879
10986
|
}),
|
|
10880
10987
|
z.object({
|
|
10881
10988
|
type: z.literal("dynamic-tool"),
|
|
10989
|
+
dynamic: z.literal(false).optional(),
|
|
10882
10990
|
toolName: z.string(),
|
|
10883
10991
|
toolCallId: z.string(),
|
|
10884
10992
|
title: z.string().optional(),
|
|
@@ -10894,6 +11002,7 @@ const uiMessagesSchema = lazySchema(() => {
|
|
|
10894
11002
|
}),
|
|
10895
11003
|
z.object({
|
|
10896
11004
|
type: z.literal("dynamic-tool"),
|
|
11005
|
+
dynamic: z.literal(false).optional(),
|
|
10897
11006
|
toolName: z.string(),
|
|
10898
11007
|
toolCallId: z.string(),
|
|
10899
11008
|
title: z.string().optional(),
|
|
@@ -10908,6 +11017,7 @@ const uiMessagesSchema = lazySchema(() => {
|
|
|
10908
11017
|
}),
|
|
10909
11018
|
z.object({
|
|
10910
11019
|
type: z.literal("dynamic-tool"),
|
|
11020
|
+
dynamic: z.literal(false).optional(),
|
|
10911
11021
|
toolName: z.string(),
|
|
10912
11022
|
toolCallId: z.string(),
|
|
10913
11023
|
title: z.string().optional(),
|
|
@@ -10922,6 +11032,7 @@ const uiMessagesSchema = lazySchema(() => {
|
|
|
10922
11032
|
}),
|
|
10923
11033
|
z.object({
|
|
10924
11034
|
type: z.literal("dynamic-tool"),
|
|
11035
|
+
dynamic: z.literal(false).optional(),
|
|
10925
11036
|
toolName: z.string(),
|
|
10926
11037
|
toolCallId: z.string(),
|
|
10927
11038
|
title: z.string().optional(),
|
|
@@ -10936,6 +11047,7 @@ const uiMessagesSchema = lazySchema(() => {
|
|
|
10936
11047
|
}),
|
|
10937
11048
|
z.object({
|
|
10938
11049
|
type: z.literal("dynamic-tool"),
|
|
11050
|
+
dynamic: z.literal(false).optional(),
|
|
10939
11051
|
toolName: z.string(),
|
|
10940
11052
|
toolCallId: z.string(),
|
|
10941
11053
|
title: z.string().optional(),
|
|
@@ -10952,6 +11064,7 @@ const uiMessagesSchema = lazySchema(() => {
|
|
|
10952
11064
|
}),
|
|
10953
11065
|
z.object({
|
|
10954
11066
|
type: z.literal("dynamic-tool"),
|
|
11067
|
+
dynamic: z.literal(false).optional(),
|
|
10955
11068
|
toolName: z.string(),
|
|
10956
11069
|
toolCallId: z.string(),
|
|
10957
11070
|
title: z.string().optional(),
|
|
@@ -10968,6 +11081,7 @@ const uiMessagesSchema = lazySchema(() => {
|
|
|
10968
11081
|
}),
|
|
10969
11082
|
z.object({
|
|
10970
11083
|
type: z.literal("dynamic-tool"),
|
|
11084
|
+
dynamic: z.literal(false).optional(),
|
|
10971
11085
|
toolName: z.string(),
|
|
10972
11086
|
toolCallId: z.string(),
|
|
10973
11087
|
title: z.string().optional(),
|
|
@@ -12544,19 +12658,19 @@ var DefaultEmbedManyResult = class {
|
|
|
12544
12658
|
}
|
|
12545
12659
|
};
|
|
12546
12660
|
//#endregion
|
|
12547
|
-
//#region src/
|
|
12661
|
+
//#region src/decide/restricted-telemetry-dispatcher.ts
|
|
12548
12662
|
function createRestrictedTelemetryDispatcher$1({ telemetry }) {
|
|
12549
12663
|
const dispatcher = createTelemetryDispatcher({ telemetry });
|
|
12550
12664
|
return {
|
|
12551
12665
|
...dispatcher,
|
|
12552
|
-
onStart: (event) => dispatcher.
|
|
12666
|
+
onStart: (event) => dispatcher.experimental_onDecideStart?.({
|
|
12553
12667
|
...event,
|
|
12554
12668
|
runtimeContext: filterIncludedContext({
|
|
12555
12669
|
context: event.runtimeContext,
|
|
12556
12670
|
includeContext: telemetry?.includeRuntimeContext
|
|
12557
12671
|
})
|
|
12558
12672
|
}),
|
|
12559
|
-
onEnd: (event) => dispatcher.
|
|
12673
|
+
onEnd: (event) => dispatcher.experimental_onDecideEnd?.({
|
|
12560
12674
|
...event,
|
|
12561
12675
|
runtimeContext: filterIncludedContext({
|
|
12562
12676
|
context: event.runtimeContext,
|
|
@@ -12566,7 +12680,7 @@ function createRestrictedTelemetryDispatcher$1({ telemetry }) {
|
|
|
12566
12680
|
};
|
|
12567
12681
|
}
|
|
12568
12682
|
//#endregion
|
|
12569
|
-
//#region src/
|
|
12683
|
+
//#region src/decide/validate-decision.ts
|
|
12570
12684
|
const tolerance = 1e-6;
|
|
12571
12685
|
function isRecord(value) {
|
|
12572
12686
|
if (value == null || typeof value !== "object" || Array.isArray(value)) return false;
|
|
@@ -12593,7 +12707,7 @@ function invalidInput(parameter, value, message) {
|
|
|
12593
12707
|
message
|
|
12594
12708
|
});
|
|
12595
12709
|
}
|
|
12596
|
-
function
|
|
12710
|
+
function validateDecisionInput({ state, questions }) {
|
|
12597
12711
|
if (!isInput(state)) invalidInput("state", state, "must be a JSON-compatible string, object, or array");
|
|
12598
12712
|
if (!isRecord(questions) || Object.keys(questions).length === 0) invalidInput("questions", questions, "must be a nonempty question map");
|
|
12599
12713
|
for (const [id, question] of Object.entries(questions)) {
|
|
@@ -12633,15 +12747,15 @@ function validateDistribution(value, keys, answers, id, roundingError) {
|
|
|
12633
12747
|
const sum = Object.values(value).reduce((total, probability) => total + probability, 0);
|
|
12634
12748
|
if (Math.abs(sum - 1) > tolerance + keys.length * roundingError) invalidAnswer(answers, `Question "${id}" probabilities must sum to 1 within the declared rounding precision.`);
|
|
12635
12749
|
}
|
|
12636
|
-
function
|
|
12750
|
+
function validateDecisionAnswers({ questions, answers, rounding }) {
|
|
12637
12751
|
function roundingError(decimals) {
|
|
12638
12752
|
if (decimals === void 0) return 0;
|
|
12639
|
-
if (!Number.isInteger(decimals) || decimals < 0 || decimals > 15) invalidAnswer(answers, "
|
|
12753
|
+
if (!Number.isInteger(decimals) || decimals < 0 || decimals > 15) invalidAnswer(answers, "Decision rounding decimals must be integers between 0 and 15.");
|
|
12640
12754
|
return .5 * 10 ** -decimals;
|
|
12641
12755
|
}
|
|
12642
12756
|
const probabilityError = roundingError(rounding?.probabilityDecimals);
|
|
12643
12757
|
const scoreError = roundingError(rounding?.scoreDecimals);
|
|
12644
|
-
if (!isRecord(answers) || !hasExactKeys(answers, Object.keys(questions))) invalidAnswer(answers, "
|
|
12758
|
+
if (!isRecord(answers) || !hasExactKeys(answers, Object.keys(questions))) invalidAnswer(answers, "Decision must return exactly one answer for every question.");
|
|
12645
12759
|
for (const [id, question] of Object.entries(questions)) {
|
|
12646
12760
|
const answer = answers[id];
|
|
12647
12761
|
if (!isRecord(answer) || answer.type !== question.type) invalidAnswer(answers, `Question "${id}" returned an answer with the wrong type.`);
|
|
@@ -12669,19 +12783,19 @@ function validateEvaluationAnswers({ questions, answers, rounding }) {
|
|
|
12669
12783
|
}
|
|
12670
12784
|
}
|
|
12671
12785
|
//#endregion
|
|
12672
|
-
//#region src/
|
|
12786
|
+
//#region src/decide/decide.ts
|
|
12673
12787
|
const originalGenerateCallId$4 = createIdGenerator$1({
|
|
12674
12788
|
prefix: "call",
|
|
12675
12789
|
size: 24
|
|
12676
12790
|
});
|
|
12677
|
-
/**
|
|
12678
|
-
async function
|
|
12679
|
-
const model =
|
|
12680
|
-
|
|
12791
|
+
/** Decide answers to typed questions against one shared state. Experimental. */
|
|
12792
|
+
async function decide({ model: modelArg, state, questions, maxRetries, abortSignal, headers, providerOptions = {}, telemetry, runtimeContext = {}, onStart, onEnd, _internal: { generateCallId = originalGenerateCallId$4 } = {} }) {
|
|
12793
|
+
const model = resolveDecisionModel(modelArg);
|
|
12794
|
+
validateDecisionInput({
|
|
12681
12795
|
state,
|
|
12682
12796
|
questions
|
|
12683
12797
|
});
|
|
12684
|
-
for (const [questionId, question] of Object.entries(questions)) if (!model.supportedQuestionTypes.includes(question.type)) throw new
|
|
12798
|
+
for (const [questionId, question] of Object.entries(questions)) if (!model.supportedQuestionTypes.includes(question.type)) throw new Experimental_DecisionUnsupportedQuestionTypeError$1({
|
|
12685
12799
|
questionId,
|
|
12686
12800
|
questionType: question.type,
|
|
12687
12801
|
provider: model.provider,
|
|
@@ -12696,7 +12810,7 @@ async function evaluate({ model: modelArg, state, questions, maxRetries, abortSi
|
|
|
12696
12810
|
const runInTracingChannelSpan = telemetryDispatcher.runInTracingChannelSpan ?? (async ({ execute }) => await execute());
|
|
12697
12811
|
const startEvent = {
|
|
12698
12812
|
callId,
|
|
12699
|
-
operationId: "ai.
|
|
12813
|
+
operationId: "ai.decide",
|
|
12700
12814
|
runtimeContext,
|
|
12701
12815
|
provider: model.provider,
|
|
12702
12816
|
modelId: model.modelId,
|
|
@@ -12707,7 +12821,7 @@ async function evaluate({ model: modelArg, state, questions, maxRetries, abortSi
|
|
|
12707
12821
|
providerOptions
|
|
12708
12822
|
};
|
|
12709
12823
|
return await runInTracingChannelSpan({
|
|
12710
|
-
type: "
|
|
12824
|
+
type: "experimental_decide",
|
|
12711
12825
|
event: startEvent,
|
|
12712
12826
|
execute: async () => {
|
|
12713
12827
|
await notify({
|
|
@@ -12717,7 +12831,7 @@ async function evaluate({ model: modelArg, state, questions, maxRetries, abortSi
|
|
|
12717
12831
|
try {
|
|
12718
12832
|
const modelCallEvent = {
|
|
12719
12833
|
callId,
|
|
12720
|
-
operationId: "ai.
|
|
12834
|
+
operationId: "ai.decide.doDecide",
|
|
12721
12835
|
provider: model.provider,
|
|
12722
12836
|
modelId: model.modelId,
|
|
12723
12837
|
state,
|
|
@@ -12725,11 +12839,11 @@ async function evaluate({ model: modelArg, state, questions, maxRetries, abortSi
|
|
|
12725
12839
|
};
|
|
12726
12840
|
await notify({
|
|
12727
12841
|
event: modelCallEvent,
|
|
12728
|
-
callbacks: [telemetryDispatcher.
|
|
12842
|
+
callbacks: [telemetryDispatcher.experimental_onDecisionModelCallStart]
|
|
12729
12843
|
});
|
|
12730
12844
|
const result = await retry(async () => {
|
|
12731
12845
|
abortSignal?.throwIfAborted();
|
|
12732
|
-
return await model.
|
|
12846
|
+
return await model.doDecide({
|
|
12733
12847
|
state,
|
|
12734
12848
|
questions,
|
|
12735
12849
|
abortSignal,
|
|
@@ -12738,7 +12852,7 @@ async function evaluate({ model: modelArg, state, questions, maxRetries, abortSi
|
|
|
12738
12852
|
});
|
|
12739
12853
|
});
|
|
12740
12854
|
abortSignal?.throwIfAborted();
|
|
12741
|
-
|
|
12855
|
+
validateDecisionAnswers({
|
|
12742
12856
|
questions,
|
|
12743
12857
|
answers: result.answers,
|
|
12744
12858
|
rounding: result.rounding
|
|
@@ -12748,7 +12862,7 @@ async function evaluate({ model: modelArg, state, questions, maxRetries, abortSi
|
|
|
12748
12862
|
...modelCallEvent,
|
|
12749
12863
|
...result
|
|
12750
12864
|
},
|
|
12751
|
-
callbacks: [telemetryDispatcher.
|
|
12865
|
+
callbacks: [telemetryDispatcher.experimental_onDecisionModelCallEnd]
|
|
12752
12866
|
});
|
|
12753
12867
|
logWarnings({
|
|
12754
12868
|
warnings: result.warnings,
|
|
@@ -12757,7 +12871,7 @@ async function evaluate({ model: modelArg, state, questions, maxRetries, abortSi
|
|
|
12757
12871
|
});
|
|
12758
12872
|
const inputTokens = result.usage?.inputTokens;
|
|
12759
12873
|
const outputTokens = result.usage?.outputTokens;
|
|
12760
|
-
const
|
|
12874
|
+
const decisionResult = {
|
|
12761
12875
|
answers: result.answers,
|
|
12762
12876
|
usage: {
|
|
12763
12877
|
inputTokens,
|
|
@@ -12776,11 +12890,11 @@ async function evaluate({ model: modelArg, state, questions, maxRetries, abortSi
|
|
|
12776
12890
|
await notify({
|
|
12777
12891
|
event: {
|
|
12778
12892
|
...startEvent,
|
|
12779
|
-
...
|
|
12893
|
+
...decisionResult
|
|
12780
12894
|
},
|
|
12781
12895
|
callbacks: [onEnd, telemetryDispatcher.onEnd]
|
|
12782
12896
|
});
|
|
12783
|
-
return
|
|
12897
|
+
return decisionResult;
|
|
12784
12898
|
} catch (error) {
|
|
12785
12899
|
await telemetryDispatcher.onError?.({
|
|
12786
12900
|
callId,
|
|
@@ -12792,6 +12906,10 @@ async function evaluate({ model: modelArg, state, questions, maxRetries, abortSi
|
|
|
12792
12906
|
});
|
|
12793
12907
|
}
|
|
12794
12908
|
//#endregion
|
|
12909
|
+
//#region src/decide/index.ts
|
|
12910
|
+
/** @deprecated Use `experimental_decide` instead. */
|
|
12911
|
+
const experimental_evaluate = decide;
|
|
12912
|
+
//#endregion
|
|
12795
12913
|
//#region src/generate-text/extract-reasoning-content.ts
|
|
12796
12914
|
function extractReasoningContent(content) {
|
|
12797
12915
|
const parts = content.filter((content) => content.type === "reasoning");
|
|
@@ -13250,6 +13368,11 @@ const originalGenerateId$1 = createIdGenerator$1({
|
|
|
13250
13368
|
* @deprecated Use `generateText` with an `output` setting instead.
|
|
13251
13369
|
*/
|
|
13252
13370
|
async function generateObject(options) {
|
|
13371
|
+
logWarnings({ warnings: [{
|
|
13372
|
+
type: "deprecated",
|
|
13373
|
+
setting: "generateObject",
|
|
13374
|
+
message: "Use generateText with an output setting instead."
|
|
13375
|
+
}] });
|
|
13253
13376
|
const { model: modelArg, output = "object", instructions, system, prompt, messages, allowSystemInMessages, maxRetries: maxRetriesArg, abortSignal, headers, experimental_repairText, repairText = experimental_repairText, experimental_telemetry, telemetry = experimental_telemetry, experimental_download: download, providerOptions, onStart, experimental_onStart, onStepStart, experimental_onStepStart, onStepEnd, onStepFinish, onFinish, _internal: { generateId = originalGenerateId$1, currentDate = () => /* @__PURE__ */ new Date() } = {}, ...settings } = options;
|
|
13254
13377
|
const model = resolveLanguageModel(modelArg);
|
|
13255
13378
|
const enumValues = "enum" in options ? options.enum : void 0;
|
|
@@ -13655,6 +13778,11 @@ async function markPromiseAsHandled(promise) {
|
|
|
13655
13778
|
* @deprecated Use `streamText` with an `output` setting instead.
|
|
13656
13779
|
*/
|
|
13657
13780
|
function streamObject(options) {
|
|
13781
|
+
logWarnings({ warnings: [{
|
|
13782
|
+
type: "deprecated",
|
|
13783
|
+
setting: "streamObject",
|
|
13784
|
+
message: "Use streamText with an output setting instead."
|
|
13785
|
+
}] });
|
|
13658
13786
|
const { model, output = "object", instructions, system, prompt, messages, allowSystemInMessages, maxRetries, abortSignal, headers, experimental_repairText, repairText = experimental_repairText, experimental_telemetry, telemetry = experimental_telemetry, experimental_download: download, providerOptions, onStart, experimental_onStart, onStepStart, experimental_onStepStart, onStepEnd, onStepFinish, onError = ({ error }) => {
|
|
13659
13787
|
console.error(error);
|
|
13660
13788
|
}, onFinish, _internal: { generateId = originalGenerateId, currentDate = () => /* @__PURE__ */ new Date(), now: now$1 = now } = {}, ...settings } = options;
|
|
@@ -14124,7 +14252,10 @@ var DefaultGeneratedAudioFile = class extends DefaultGeneratedFile {
|
|
|
14124
14252
|
if (mediaType !== "audio/mpeg") format = mediaTypeParts[1];
|
|
14125
14253
|
}
|
|
14126
14254
|
}
|
|
14127
|
-
if (!format) throw new
|
|
14255
|
+
if (!format) throw new InvalidResponseDataError$1({
|
|
14256
|
+
data: mediaType,
|
|
14257
|
+
message: `Could not determine audio format from media type: ${mediaType}`
|
|
14258
|
+
});
|
|
14128
14259
|
this.format = format;
|
|
14129
14260
|
}
|
|
14130
14261
|
};
|
|
@@ -14302,7 +14433,14 @@ var DefaultSpeechResult = class {
|
|
|
14302
14433
|
/**
|
|
14303
14434
|
* @deprecated Use `generateSpeech` instead.
|
|
14304
14435
|
*/
|
|
14305
|
-
const experimental_generateSpeech =
|
|
14436
|
+
const experimental_generateSpeech = (options) => {
|
|
14437
|
+
logWarnings({ warnings: [{
|
|
14438
|
+
type: "deprecated",
|
|
14439
|
+
setting: "experimental_generateSpeech",
|
|
14440
|
+
message: "Use generateSpeech instead."
|
|
14441
|
+
}] });
|
|
14442
|
+
return generateSpeech(options);
|
|
14443
|
+
};
|
|
14306
14444
|
//#endregion
|
|
14307
14445
|
//#region src/generate-text/prune-messages.ts
|
|
14308
14446
|
/**
|
|
@@ -15218,16 +15356,24 @@ function getPotentialStartIndex(text, searchedText) {
|
|
|
15218
15356
|
//#endregion
|
|
15219
15357
|
//#region src/middleware/extract-reasoning-middleware.ts
|
|
15220
15358
|
/**
|
|
15221
|
-
* Extracts
|
|
15359
|
+
* Extracts a delimited reasoning section from the generated text and exposes it
|
|
15222
15360
|
* as a `reasoning` property on the result.
|
|
15223
15361
|
*
|
|
15224
|
-
* @param tagName -
|
|
15362
|
+
* @param tagName - An XML tag name (without angle brackets), or literal opening
|
|
15363
|
+
* and closing delimiters for formats such as Gemma's thought channel.
|
|
15225
15364
|
* @param separator - The separator to use between reasoning and text sections.
|
|
15226
15365
|
* @param startWithReasoning - Whether to start with reasoning tokens.
|
|
15227
15366
|
*/
|
|
15228
15367
|
function extractReasoningMiddleware({ tagName, separator = "\n", startWithReasoning = false }) {
|
|
15229
|
-
const openingTag = `<${tagName}
|
|
15230
|
-
const closingTag = `</${tagName}
|
|
15368
|
+
const openingTag = typeof tagName === "string" ? `<${tagName}>` : tagName.opening;
|
|
15369
|
+
const closingTag = typeof tagName === "string" ? `</${tagName}>` : tagName.closing;
|
|
15370
|
+
if (openingTag.length === 0 || closingTag.length === 0) throw new InvalidArgumentError({
|
|
15371
|
+
parameter: "tagName",
|
|
15372
|
+
value: tagName,
|
|
15373
|
+
message: "Reasoning delimiters must not be empty."
|
|
15374
|
+
});
|
|
15375
|
+
const escapedOpeningTag = openingTag.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
15376
|
+
const escapedClosingTag = closingTag.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
15231
15377
|
return {
|
|
15232
15378
|
specificationVersion: "v4",
|
|
15233
15379
|
wrapGenerate: async ({ doGenerate }) => {
|
|
@@ -15239,7 +15385,7 @@ function extractReasoningMiddleware({ tagName, separator = "\n", startWithReason
|
|
|
15239
15385
|
continue;
|
|
15240
15386
|
}
|
|
15241
15387
|
const text = startWithReasoning ? openingTag + part.text : part.text;
|
|
15242
|
-
const regexp = new RegExp(`${
|
|
15388
|
+
const regexp = new RegExp(`${escapedOpeningTag}(.*?)${escapedClosingTag}`, "gs");
|
|
15243
15389
|
const matches = Array.from(text.matchAll(regexp));
|
|
15244
15390
|
if (!matches.length) {
|
|
15245
15391
|
transformedContent.push(part);
|
|
@@ -16087,7 +16233,11 @@ const REALTIME_MAX_FRAME_BYTES = 131072;
|
|
|
16087
16233
|
const REALTIME_MAX_BUFFERED_BYTES = 131072;
|
|
16088
16234
|
/** Serialize once, measuring the exact payload passed to the browser. */
|
|
16089
16235
|
function encodeRealtimeFrame(value) {
|
|
16090
|
-
if (value instanceof ArrayBuffer
|
|
16236
|
+
if (value instanceof ArrayBuffer) return {
|
|
16237
|
+
data: value,
|
|
16238
|
+
byteLength: value.byteLength
|
|
16239
|
+
};
|
|
16240
|
+
if (ArrayBuffer.isView(value)) return {
|
|
16091
16241
|
data: value,
|
|
16092
16242
|
byteLength: value.byteLength
|
|
16093
16243
|
};
|
|
@@ -18022,7 +18172,7 @@ var AbstractRealtimeSession = class {
|
|
|
18022
18172
|
* @param {Record<string, SpeechModel>} [options.speechModels] - A record of speech models, where keys are model IDs and values are speech model instances.
|
|
18023
18173
|
* @param {Record<string, RerankingModel>} [options.rerankingModels] - A record of reranking models, where keys are model IDs and values are reranking model instances.
|
|
18024
18174
|
* @param {Record<string, VideoModel>} [options.videoModels] - A record of video models, where keys are model IDs and values are video model instances.
|
|
18025
|
-
* @param {Record<string,
|
|
18175
|
+
* @param {Record<string, DecisionModel>} [options.decisionModels] - Experimental decision models or default-provider model IDs, keyed by alias.
|
|
18026
18176
|
* @param {FilesV4} [options.files] - A files interface for uploading files.
|
|
18027
18177
|
* @param {SkillsV4} [options.skills] - A skills interface for uploading skills.
|
|
18028
18178
|
* @param {ProviderV2 | ProviderV3 | ProviderV4} [options.fallbackProvider] - An optional fallback provider to use when a requested model is not found in the custom provider.
|
|
@@ -18030,7 +18180,8 @@ var AbstractRealtimeSession = class {
|
|
|
18030
18180
|
*
|
|
18031
18181
|
* @throws {NoSuchModelError} Throws when a requested model is not found and no fallback provider is available.
|
|
18032
18182
|
*/
|
|
18033
|
-
function customProvider({ languageModels, embeddingModels, imageModels, transcriptionModels, speechModels, rerankingModels, videoModels, evaluationModels, files, skills, fallbackProvider: fallbackProviderArg }) {
|
|
18183
|
+
function customProvider({ languageModels, embeddingModels, imageModels, transcriptionModels, speechModels, rerankingModels, videoModels, decisionModels: decisionModelsArg, evaluationModels, files, skills, fallbackProvider: fallbackProviderArg }) {
|
|
18184
|
+
const decisionModels = decisionModelsArg ?? evaluationModels;
|
|
18034
18185
|
const fallbackProvider = fallbackProviderArg == null ? void 0 : asProviderV4(fallbackProviderArg);
|
|
18035
18186
|
const baseProvider = {
|
|
18036
18187
|
specificationVersion: "v4",
|
|
@@ -18088,18 +18239,22 @@ function customProvider({ languageModels, embeddingModels, imageModels, transcri
|
|
|
18088
18239
|
modelType: "rerankingModel"
|
|
18089
18240
|
});
|
|
18090
18241
|
},
|
|
18091
|
-
|
|
18092
|
-
if (
|
|
18242
|
+
decisionModel(modelId) {
|
|
18243
|
+
if (decisionModels != null && Object.hasOwn(decisionModels, modelId)) return resolveDecisionModel(decisionModels[modelId]);
|
|
18093
18244
|
const provider = fallbackProviderArg;
|
|
18094
|
-
|
|
18095
|
-
|
|
18096
|
-
|
|
18245
|
+
const factory = provider?.decisionModel ?? provider?.evaluationModel;
|
|
18246
|
+
if (typeof factory === "function") {
|
|
18247
|
+
const model = factory.call(provider, modelId);
|
|
18248
|
+
if (model != null) return resolveDecisionModel(model);
|
|
18097
18249
|
}
|
|
18098
18250
|
throw new NoSuchModelError$1({
|
|
18099
18251
|
modelId,
|
|
18100
|
-
modelType: "
|
|
18252
|
+
modelType: "decisionModel"
|
|
18101
18253
|
});
|
|
18102
18254
|
},
|
|
18255
|
+
evaluationModel(modelId) {
|
|
18256
|
+
return asEvaluationModel(this.decisionModel(modelId));
|
|
18257
|
+
},
|
|
18103
18258
|
videoModel(modelId) {
|
|
18104
18259
|
if (videoModels != null && modelId in videoModels) return resolveVideoModel(videoModels[modelId]);
|
|
18105
18260
|
const provider = fallbackProviderArg;
|
|
@@ -18182,12 +18337,13 @@ var DefaultProviderRegistry = class {
|
|
|
18182
18337
|
registerProvider({ id, provider }) {
|
|
18183
18338
|
const providerV4 = asProviderV4(provider);
|
|
18184
18339
|
const videoModel = provider.videoModel?.bind(provider);
|
|
18185
|
-
const
|
|
18340
|
+
const decisionProvider = provider;
|
|
18341
|
+
const decisionModel = (decisionProvider.decisionModel ?? decisionProvider.evaluationModel)?.bind(provider);
|
|
18186
18342
|
const registeredProvider = videoModel == null ? providerV4 : Object.assign(Object.create(Object.getPrototypeOf(providerV4)), {
|
|
18187
18343
|
...providerV4,
|
|
18188
18344
|
videoModel: (modelId) => asVideoModelV4(videoModel(modelId))
|
|
18189
18345
|
});
|
|
18190
|
-
if (registeredProvider !== provider &&
|
|
18346
|
+
if (registeredProvider !== provider && decisionModel != null) Object.assign(registeredProvider, { decisionModel });
|
|
18191
18347
|
this.providers[id] = registeredProvider;
|
|
18192
18348
|
}
|
|
18193
18349
|
getProvider(id, modelType) {
|
|
@@ -18280,14 +18436,19 @@ var DefaultProviderRegistry = class {
|
|
|
18280
18436
|
});
|
|
18281
18437
|
return asVideoModelV4(model);
|
|
18282
18438
|
}
|
|
18283
|
-
|
|
18284
|
-
const [providerId, modelId] = this.splitId(id, "
|
|
18285
|
-
const
|
|
18439
|
+
decisionModel(id) {
|
|
18440
|
+
const [providerId, modelId] = this.splitId(id, "decisionModel");
|
|
18441
|
+
const provider = this.getProvider(providerId, "decisionModel");
|
|
18442
|
+
const model = (provider.decisionModel ?? provider.evaluationModel)?.call(provider, modelId);
|
|
18286
18443
|
if (model == null) throw new NoSuchModelError$1({
|
|
18287
18444
|
modelId: id,
|
|
18288
|
-
modelType: "
|
|
18445
|
+
modelType: "decisionModel"
|
|
18289
18446
|
});
|
|
18290
|
-
return
|
|
18447
|
+
return resolveDecisionModel(model);
|
|
18448
|
+
}
|
|
18449
|
+
/** @deprecated Use `decisionModel` instead. */
|
|
18450
|
+
evaluationModel(id) {
|
|
18451
|
+
return asEvaluationModel(this.decisionModel(id));
|
|
18291
18452
|
}
|
|
18292
18453
|
files(id) {
|
|
18293
18454
|
const files = this.getProvider(id, "languageModel").files?.();
|
|
@@ -18673,7 +18834,7 @@ async function transcribe({ model, audio, providerOptions = {}, maxRetries: maxR
|
|
|
18673
18834
|
provider: resolvedModel.provider,
|
|
18674
18835
|
model: resolvedModel.modelId
|
|
18675
18836
|
});
|
|
18676
|
-
if (
|
|
18837
|
+
if (result.text == null) throw new NoTranscriptGeneratedError({ responses: [result.response] });
|
|
18677
18838
|
await notify({
|
|
18678
18839
|
event: {
|
|
18679
18840
|
callId,
|
|
@@ -18991,7 +19152,14 @@ function getBase64ByteLength(value) {
|
|
|
18991
19152
|
/**
|
|
18992
19153
|
* @deprecated Use `transcribe` instead.
|
|
18993
19154
|
*/
|
|
18994
|
-
const experimental_transcribe =
|
|
19155
|
+
const experimental_transcribe = (options) => {
|
|
19156
|
+
logWarnings({ warnings: [{
|
|
19157
|
+
type: "deprecated",
|
|
19158
|
+
setting: "experimental_transcribe",
|
|
19159
|
+
message: "Use transcribe instead."
|
|
19160
|
+
}] });
|
|
19161
|
+
return transcribe(options);
|
|
19162
|
+
};
|
|
18995
19163
|
//#endregion
|
|
18996
19164
|
//#region src/translate/stream-translate.ts
|
|
18997
19165
|
/**
|
|
@@ -19306,7 +19474,9 @@ async function convertFileListToFileUIParts(files) {
|
|
|
19306
19474
|
//#region src/ui/http-chat-transport.ts
|
|
19307
19475
|
function appendPathToUrl(url, path) {
|
|
19308
19476
|
const queryOrFragmentStart = url.search(/[?#]/);
|
|
19309
|
-
|
|
19477
|
+
const urlPath = queryOrFragmentStart === -1 ? url : url.slice(0, queryOrFragmentStart);
|
|
19478
|
+
const suffix = queryOrFragmentStart === -1 ? "" : url.slice(queryOrFragmentStart);
|
|
19479
|
+
return `${urlPath.endsWith("/") && path.startsWith("/") ? urlPath.slice(0, -1) : urlPath}${path}${suffix}`;
|
|
19310
19480
|
}
|
|
19311
19481
|
var HttpChatTransport = class {
|
|
19312
19482
|
constructor({ api = "/api/chat", credentials, headers, body, fetch, prepareSendMessagesRequest, prepareReconnectToStreamRequest }) {
|
|
@@ -19636,7 +19806,10 @@ var AbstractChat = class {
|
|
|
19636
19806
|
return this.state.status;
|
|
19637
19807
|
}
|
|
19638
19808
|
setStatus({ status, error }) {
|
|
19639
|
-
if (this.status === status)
|
|
19809
|
+
if (this.status === status) {
|
|
19810
|
+
if (this.error !== error) this.state.error = error;
|
|
19811
|
+
return;
|
|
19812
|
+
}
|
|
19640
19813
|
this.state.status = status;
|
|
19641
19814
|
this.state.error = error;
|
|
19642
19815
|
}
|
|
@@ -19730,7 +19903,7 @@ var AbstractChat = class {
|
|
|
19730
19903
|
const lastMessage = this.lastMessage;
|
|
19731
19904
|
const responseMessageIndex = trigger === "submit-message" && messageId != null ? this.state.messages.findIndex((message) => message.id === messageId) : this.state.messages.length - 1;
|
|
19732
19905
|
const responseMessage = responseMessageIndex === -1 ? lastMessage : this.state.messages[responseMessageIndex];
|
|
19733
|
-
const resumableResponseMessage = trigger === "resume-stream" && responseMessage?.role === "assistant" && responseMessage.parts.some((part) => isToolUIPart(part) && part.state === "input-streaming") ? this.state.snapshot(responseMessage) : void 0;
|
|
19906
|
+
const resumableResponseMessage = trigger === "resume-stream" && responseMessage?.role === "assistant" && responseMessage.parts.some((part) => isToolUIPart(part) && (part.state === "input-streaming" || part.state === "approval-responded")) ? this.state.snapshot(responseMessage) : void 0;
|
|
19734
19907
|
const usesEarlierAssistantMessage = responseMessageIndex !== -1 && responseMessageIndex < this.state.messages.length - 1 && responseMessage?.role === "assistant";
|
|
19735
19908
|
let isAbort = false;
|
|
19736
19909
|
let isDisconnect = false;
|
|
@@ -19777,6 +19950,7 @@ var AbstractChat = class {
|
|
|
19777
19950
|
await consumeStream({
|
|
19778
19951
|
stream: processUIMessageStream({
|
|
19779
19952
|
stream,
|
|
19953
|
+
resetStateOnMessageIdChange: trigger === "resume-stream",
|
|
19780
19954
|
onToolCall: this.onToolCall,
|
|
19781
19955
|
onData: this.onData,
|
|
19782
19956
|
messageMetadataSchema: this.messageMetadataSchema,
|
|
@@ -19813,7 +19987,10 @@ var AbstractChat = class {
|
|
|
19813
19987
|
}
|
|
19814
19988
|
if (!isCurrentRequest()) return null;
|
|
19815
19989
|
isError = true;
|
|
19816
|
-
if (err instanceof TypeError
|
|
19990
|
+
if (err instanceof TypeError) {
|
|
19991
|
+
const message = err.message.toLowerCase();
|
|
19992
|
+
isDisconnect = message.includes("fetch") || message.includes("network") || message === "load failed";
|
|
19993
|
+
}
|
|
19817
19994
|
if (isDisconnect) this.resumableStreamState = activeResponse?.state;
|
|
19818
19995
|
else if (this.resumableStreamState === activeResponse?.state) this.resumableStreamState = void 0;
|
|
19819
19996
|
if (this.onError && err instanceof Error) this.onError(err);
|
|
@@ -20077,6 +20254,6 @@ async function uploadSkill({ api, files, displayTitle, providerOptions }) {
|
|
|
20077
20254
|
});
|
|
20078
20255
|
}
|
|
20079
20256
|
//#endregion
|
|
20080
|
-
export { AISDKError, AI_SDK_TELEMETRY_TRACING_CHANNEL, APICallError, AbstractChat, DefaultChatTransport, DefaultGeneratedFile, DirectChatTransport, DownloadError, EmptyResponseBodyError, AbstractRealtimeSession as Experimental_AbstractRealtimeSession, ToolLoopAgent as Experimental_Agent, ToolLoopAgent, Experimental_EvaluationUnsupportedQuestionTypeError, HttpChatTransport, InvalidArgumentError, InvalidDataContentError, InvalidMessageRoleError, InvalidPromptError, InvalidResponseDataError, InvalidStreamPartError, InvalidToolApprovalError, InvalidToolApprovalSignatureError, InvalidToolInputError, JSONParseError, JsonToSseTransformStream, LoadAPIKeyError, LoadSettingError, MessageConversionError, MissingToolResultsError, NoContentGeneratedError, NoImageGeneratedError, NoObjectGeneratedError, NoOutputGeneratedError, NoSpeechGeneratedError, NoSuchModelError, NoSuchProviderError, NoSuchProviderReferenceError, NoSuchToolError, NoTranscriptGeneratedError, NoTranslationGeneratedError, NoVideoGeneratedError, output_exports as Output, RetryError, SerialJobExecutor, StreamProviderError, TextStreamChatTransport, TooManyEmbeddingValuesForCallError, ToolCallNotFoundForApprovalError, ToolCallRepairError, ToolChoiceViolationError, TypeValidationError, UIMessageStreamError, UI_MESSAGE_STREAM_HEADERS, UnsupportedFunctionalityError, UnsupportedModelVersionError, addToolInputExamplesMiddleware, asSchema, assistantModelMessageSchema, callCompletionApi, consumeStream, convertDataContentToBase64String, convertFileListToFileUIParts, convertToModelMessages, cosineSimilarity, createAgentUIStream, createAgentUIStreamResponse, createDownload, createGateway, createIdGenerator, createProviderRegistry, createTextStreamResponse, createUIMessageStream, createUIMessageStreamResponse, customProvider, defaultEmbeddingSettingsMiddleware, defaultInstructionsMiddleware, defaultSettingsMiddleware, detectToolDrift, dynamicTool, embed, embedMany, cancelBatch as experimental_cancelBatch, experimental_createProviderRegistry, decodeRealtimeAudio as experimental_decodeRealtimeAudio, encodeRealtimeAudio as experimental_encodeRealtimeAudio,
|
|
20257
|
+
export { AISDKError, AI_SDK_TELEMETRY_TRACING_CHANNEL, APICallError, AbstractChat, DefaultChatTransport, DefaultGeneratedFile, DirectChatTransport, DownloadError, EmptyResponseBodyError, AbstractRealtimeSession as Experimental_AbstractRealtimeSession, ToolLoopAgent as Experimental_Agent, ToolLoopAgent, Experimental_DecisionUnsupportedQuestionTypeError, Experimental_EvaluationUnsupportedQuestionTypeError, HttpChatTransport, InvalidArgumentError, InvalidDataContentError, InvalidMessageRoleError, InvalidPromptError, InvalidResponseDataError, InvalidStreamPartError, InvalidToolApprovalError, InvalidToolApprovalSignatureError, InvalidToolInputError, JSONParseError, JsonToSseTransformStream, LoadAPIKeyError, LoadSettingError, MessageConversionError, MissingToolResultsError, NoContentGeneratedError, NoImageGeneratedError, NoObjectGeneratedError, NoOutputGeneratedError, NoSpeechGeneratedError, NoSuchModelError, NoSuchProviderError, NoSuchProviderReferenceError, NoSuchToolError, NoTranscriptGeneratedError, NoTranslationGeneratedError, NoVideoGeneratedError, output_exports as Output, RetryError, SerialJobExecutor, StreamProviderError, TextStreamChatTransport, TooManyEmbeddingValuesForCallError, ToolCallNotFoundForApprovalError, ToolCallRepairError, ToolChoiceViolationError, TypeValidationError, UIMessageStreamError, UI_MESSAGE_STREAM_HEADERS, UnsupportedFunctionalityError, UnsupportedModelVersionError, addToolInputExamplesMiddleware, asSchema, assistantModelMessageSchema, callCompletionApi, consumeStream, convertDataContentToBase64String, convertFileListToFileUIParts, convertToModelMessages, cosineSimilarity, createAgentUIStream, createAgentUIStreamResponse, createDownload, createGateway, createIdGenerator, createProviderRegistry, createTextStreamResponse, createUIMessageStream, createUIMessageStreamResponse, customProvider, defaultEmbeddingSettingsMiddleware, defaultInstructionsMiddleware, defaultSettingsMiddleware, detectToolDrift, dynamicTool, embed, embedMany, cancelBatch as experimental_cancelBatch, experimental_createProviderRegistry, decide as experimental_decide, decodeRealtimeAudio as experimental_decodeRealtimeAudio, encodeRealtimeAudio as experimental_encodeRealtimeAudio, experimental_evaluate, filterActiveTools as experimental_filterActiveTools, experimental_generateSpeech, experimental_generateVideo, getBatchResults as experimental_getBatchResults, getBatchStatus as experimental_getBatchStatus, getRealtimeToolDefinitions as experimental_getRealtimeToolDefinitions, experimental_getVideoStatus, listBatches as experimental_listBatches, resampleAudio as experimental_resampleAudio, startBatch as experimental_startBatch, experimental_startVideo, streamLanguageModelCall as experimental_streamLanguageModelCall, streamTranscribe as experimental_streamTranscribe, streamTranslate as experimental_streamTranslate, experimental_toolCaller, experimental_transcribe, extractJsonMiddleware, extractReasoningMiddleware, fingerprintTools, gateway, generateId, generateImage, generateObject, generateSpeech, generateText, getChunkTimeoutMs, getFirstChunkTimeoutMs, getStaticToolName, getStepTimeoutMs, getTextFromDataUrl, getToolName, getToolOrDynamicToolName, getToolTimeoutMs, getTotalTimeoutMs, hasToolCall, isCustomContentUIPart, isDataUIPart, isDeepEqualData, isDynamicToolUIPart, isFileUIPart, isLoopFinished, isReasoningFileUIPart, isReasoningUIPart, isStaticToolUIPart, isStepCount, isStepCount as stepCountIs, isTextUIPart, isToolOutputErrorUIPart, isToolUIPart, jsonSchema, lastAssistantMessageIsCompleteWithApprovalResponses, lastAssistantMessageIsCompleteWithToolCalls, modelMessageSchema, parseJsonEventStream, parsePartialJson, pipeAgentUIStreamToResponse, pipeTextStreamToResponse, pipeUIMessageStreamToResponse, pruneMessages, readUIMessageStream, registerTelemetry, rerank, safeValidateUIMessages, simulateReadableStream, simulateStreamingMiddleware, smoothStream, streamObject, streamText, systemModelMessageSchema, toTextStream, toUIMessageChunk, toUIMessageStream, tool, toolModelMessageSchema, toolSearch, transcribe, uiMessageChunkSchema, uploadFile, uploadSkill, userModelMessageSchema, validateUIMessages, wrapEmbeddingModel, wrapImageModel, wrapLanguageModel, wrapProvider, zodSchema };
|
|
20081
20258
|
|
|
20082
20259
|
//# sourceMappingURL=index.js.map
|