ai 7.0.102 → 7.0.104
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 +36 -0
- package/dist/index.d.ts +90 -6
- package/dist/index.js +900 -299
- package/dist/index.js.map +1 -1
- package/dist/internal/index.d.ts +1 -0
- package/dist/internal/index.js +5 -1
- package/dist/internal/index.js.map +1 -1
- package/dist/test/index.d.ts +16 -2
- package/dist/test/index.js +17 -0
- package/dist/test/index.js.map +1 -1
- package/docs/03-ai-sdk-core/18-code-mode.mdx +50 -0
- package/docs/03-ai-sdk-core/19-tool-search.mdx +80 -0
- package/docs/03-ai-sdk-core/32-evaluation.mdx +255 -0
- package/docs/03-ai-sdk-core/42-batch.mdx +1 -2
- package/docs/03-ai-sdk-core/45-provider-management.mdx +10 -0
- package/docs/03-ai-sdk-core/index.mdx +6 -0
- package/docs/04-ai-sdk-ui/03-chatbot-message-persistence.mdx +35 -0
- package/docs/06-advanced/11-secure-url-fetching.mdx +8 -2
- package/docs/07-reference/01-ai-sdk-core/14-evaluate.mdx +67 -0
- package/docs/07-reference/01-ai-sdk-core/20-tool.mdx +7 -0
- package/docs/07-reference/01-ai-sdk-core/22-dynamic-tool.mdx +7 -0
- package/docs/07-reference/01-ai-sdk-core/23-tool-search.mdx +75 -0
- package/docs/07-reference/01-ai-sdk-core/32-validate-ui-messages.mdx +12 -0
- package/docs/07-reference/01-ai-sdk-core/33-safe-validate-ui-messages.mdx +12 -0
- package/docs/07-reference/01-ai-sdk-core/40-provider-registry.mdx +17 -0
- package/docs/07-reference/01-ai-sdk-core/42-custom-provider.mdx +16 -0
- package/docs/07-reference/01-ai-sdk-core/index.mdx +6 -0
- package/docs/07-reference/02-ai-sdk-ui/31-convert-to-model-messages.mdx +12 -0
- package/docs/07-reference/05-ai-sdk-errors/ai-evaluation-unsupported-question-type-error.mdx +31 -0
- package/docs/07-reference/05-ai-sdk-errors/ai-no-such-model-error.mdx +4 -0
- package/docs/07-reference/05-ai-sdk-errors/ai-no-such-provider-error.mdx +4 -0
- package/package.json +12 -12
- package/src/error/index.ts +1 -0
- package/src/evaluate/evaluate.ts +106 -0
- package/src/evaluate/evaluation-provider.ts +6 -0
- package/src/evaluate/evaluation-result.ts +39 -0
- package/src/evaluate/index.ts +7 -0
- package/src/evaluate/validate-evaluation.ts +298 -0
- package/src/generate-text/generate-text.ts +25 -13
- package/src/generate-text/stream-text.ts +15 -2
- package/src/generate-text/tool-caller-configuration.ts +59 -5
- package/src/global.ts +1 -0
- package/src/index.ts +2 -0
- package/src/model/resolve-model.ts +55 -10
- package/src/prompt/prepare-tools.ts +1 -1
- package/src/realtime/browser-realtime-transport.ts +12 -1
- package/src/realtime/realtime-event-channel.ts +4 -0
- package/src/realtime/realtime-session.ts +9 -4
- package/src/registry/custom-provider.ts +37 -0
- package/src/registry/index.ts +2 -0
- package/src/registry/no-such-provider-error.ts +2 -1
- package/src/registry/provider-registry.ts +65 -6
- package/src/test/evaluation-mock-model-v4.ts +27 -0
- package/src/tool-search/prepare-tool-search.ts +143 -0
- package/src/tool-search/tool-search.ts +59 -0
- package/src/ui/convert-to-model-messages.ts +3 -0
- package/src/ui/process-ui-message-stream.ts +4 -0
- package/src/ui/ui-messages.ts +5 -1
- package/src/ui/validate-ui-messages.ts +3 -0
- package/src/ui/warn-if-ui-message-has-deprecated-raw-input.ts +36 -0
package/dist/index.js
CHANGED
|
@@ -15,9 +15,9 @@ import {
|
|
|
15
15
|
dynamicTool,
|
|
16
16
|
experimental_toolCaller,
|
|
17
17
|
generateId as generateId4,
|
|
18
|
-
jsonSchema,
|
|
18
|
+
jsonSchema as jsonSchema2,
|
|
19
19
|
parseJsonEventStream as parseJsonEventStream3,
|
|
20
|
-
tool,
|
|
20
|
+
tool as tool2,
|
|
21
21
|
zodSchema as zodSchema3
|
|
22
22
|
} from "@ai-sdk/provider-utils";
|
|
23
23
|
|
|
@@ -40,6 +40,7 @@ import {
|
|
|
40
40
|
AISDKError as AISDKError25,
|
|
41
41
|
APICallError,
|
|
42
42
|
EmptyResponseBodyError,
|
|
43
|
+
Experimental_EvaluationUnsupportedQuestionTypeError,
|
|
43
44
|
InvalidPromptError,
|
|
44
45
|
InvalidResponseDataError,
|
|
45
46
|
JSONParseError,
|
|
@@ -689,6 +690,9 @@ var logWarnings = (options) => {
|
|
|
689
690
|
|
|
690
691
|
// src/model/resolve-model.ts
|
|
691
692
|
import { gateway } from "@ai-sdk/gateway";
|
|
693
|
+
import {
|
|
694
|
+
NoSuchModelError as NoSuchModelError2
|
|
695
|
+
} from "@ai-sdk/provider";
|
|
692
696
|
|
|
693
697
|
// src/util/log-v2-compatibility-warning.ts
|
|
694
698
|
function logV2CompatibilityWarning({
|
|
@@ -1124,6 +1128,34 @@ function resolveRerankingModel(model) {
|
|
|
1124
1128
|
}
|
|
1125
1129
|
return asRerankingModelV4(model);
|
|
1126
1130
|
}
|
|
1131
|
+
function resolveEvaluationModel(model) {
|
|
1132
|
+
if (typeof model === "string") {
|
|
1133
|
+
const provider = globalThis.AI_SDK_DEFAULT_PROVIDER;
|
|
1134
|
+
if (typeof (provider == null ? void 0 : provider.evaluationModel) !== "function") {
|
|
1135
|
+
throw new NoSuchModelError2({
|
|
1136
|
+
modelId: model,
|
|
1137
|
+
modelType: "evaluationModel",
|
|
1138
|
+
message: "The default provider does not support evaluation models. Pass an evaluation model instance or configure AI_SDK_DEFAULT_PROVIDER with an evaluationModel method."
|
|
1139
|
+
});
|
|
1140
|
+
}
|
|
1141
|
+
const resolvedModel = provider.evaluationModel(model);
|
|
1142
|
+
if (resolvedModel == null) {
|
|
1143
|
+
throw new NoSuchModelError2({
|
|
1144
|
+
modelId: model,
|
|
1145
|
+
modelType: "evaluationModel"
|
|
1146
|
+
});
|
|
1147
|
+
}
|
|
1148
|
+
model = resolvedModel;
|
|
1149
|
+
}
|
|
1150
|
+
if (model.specificationVersion !== "v4") {
|
|
1151
|
+
throw new UnsupportedModelVersionError({
|
|
1152
|
+
version: model.specificationVersion,
|
|
1153
|
+
provider: model.provider,
|
|
1154
|
+
modelId: model.modelId
|
|
1155
|
+
});
|
|
1156
|
+
}
|
|
1157
|
+
return model;
|
|
1158
|
+
}
|
|
1127
1159
|
function getGlobalProvider() {
|
|
1128
1160
|
var _a25;
|
|
1129
1161
|
const provider = (_a25 = globalThis.AI_SDK_DEFAULT_PROVIDER) != null ? _a25 : gateway;
|
|
@@ -1178,7 +1210,7 @@ import {
|
|
|
1178
1210
|
} from "@ai-sdk/provider-utils";
|
|
1179
1211
|
|
|
1180
1212
|
// src/version.ts
|
|
1181
|
-
var VERSION = true ? "7.0.
|
|
1213
|
+
var VERSION = true ? "7.0.104" : "0.0.0-test";
|
|
1182
1214
|
|
|
1183
1215
|
// src/util/download/download.ts
|
|
1184
1216
|
var download = async ({
|
|
@@ -2014,7 +2046,7 @@ async function createToolModelOutput({
|
|
|
2014
2046
|
toolCallId,
|
|
2015
2047
|
input,
|
|
2016
2048
|
output,
|
|
2017
|
-
tool:
|
|
2049
|
+
tool: tool3,
|
|
2018
2050
|
errorMode
|
|
2019
2051
|
}) {
|
|
2020
2052
|
if (errorMode === "text") {
|
|
@@ -2022,8 +2054,8 @@ async function createToolModelOutput({
|
|
|
2022
2054
|
} else if (errorMode === "json") {
|
|
2023
2055
|
return { type: "error-json", value: await toJSONValue(output) };
|
|
2024
2056
|
}
|
|
2025
|
-
if (
|
|
2026
|
-
return await
|
|
2057
|
+
if (tool3 == null ? void 0 : tool3.toModelOutput) {
|
|
2058
|
+
return await tool3.toModelOutput({ toolCallId, input, output });
|
|
2027
2059
|
}
|
|
2028
2060
|
return typeof output === "string" ? { type: "text", value: output } : { type: "json", value: await toJSONValue(output) };
|
|
2029
2061
|
}
|
|
@@ -2158,25 +2190,25 @@ async function prepareTools({
|
|
|
2158
2190
|
return void 0;
|
|
2159
2191
|
}
|
|
2160
2192
|
const languageModelTools = [];
|
|
2161
|
-
for (const [name25,
|
|
2162
|
-
const toolType =
|
|
2193
|
+
for (const [name25, tool3] of orderToolEntries({ tools, toolOrder })) {
|
|
2194
|
+
const toolType = tool3.type;
|
|
2163
2195
|
switch (toolType) {
|
|
2164
2196
|
case void 0:
|
|
2165
2197
|
case "dynamic":
|
|
2166
2198
|
case "function": {
|
|
2167
2199
|
const description = resolveToolDescription({
|
|
2168
|
-
tool:
|
|
2200
|
+
tool: tool3,
|
|
2169
2201
|
toolName: name25,
|
|
2170
2202
|
toolsContext,
|
|
2171
2203
|
experimental_sandbox: sandbox
|
|
2172
2204
|
});
|
|
2173
|
-
const providerOptions =
|
|
2174
|
-
const inputExamples =
|
|
2175
|
-
const strict =
|
|
2205
|
+
const providerOptions = tool3.providerOptions;
|
|
2206
|
+
const inputExamples = tool3.inputExamples;
|
|
2207
|
+
const strict = tool3.strict;
|
|
2176
2208
|
languageModelTools.push({
|
|
2177
2209
|
type: "function",
|
|
2178
2210
|
name: name25,
|
|
2179
|
-
inputSchema: await asSchema(
|
|
2211
|
+
inputSchema: await asSchema(tool3.inputSchema).jsonSchema,
|
|
2180
2212
|
...description != null ? { description } : {},
|
|
2181
2213
|
...inputExamples != null ? { inputExamples } : {},
|
|
2182
2214
|
...providerOptions != null ? { providerOptions } : {},
|
|
@@ -2188,8 +2220,8 @@ async function prepareTools({
|
|
|
2188
2220
|
languageModelTools.push({
|
|
2189
2221
|
type: "provider",
|
|
2190
2222
|
name: name25,
|
|
2191
|
-
id:
|
|
2192
|
-
args:
|
|
2223
|
+
id: tool3.id,
|
|
2224
|
+
args: tool3.args
|
|
2193
2225
|
});
|
|
2194
2226
|
break;
|
|
2195
2227
|
}
|
|
@@ -2216,12 +2248,12 @@ function orderToolEntries({
|
|
|
2216
2248
|
return [...orderedTools, ...unorderedTools];
|
|
2217
2249
|
}
|
|
2218
2250
|
function resolveToolDescription({
|
|
2219
|
-
tool:
|
|
2251
|
+
tool: tool3,
|
|
2220
2252
|
toolName,
|
|
2221
2253
|
toolsContext,
|
|
2222
2254
|
experimental_sandbox: sandbox
|
|
2223
2255
|
}) {
|
|
2224
|
-
return
|
|
2256
|
+
return tool3.description === void 0 ? void 0 : typeof tool3.description === "string" ? tool3.description : tool3.description({
|
|
2225
2257
|
context: toolsContext[toolName],
|
|
2226
2258
|
experimental_sandbox: sandbox
|
|
2227
2259
|
});
|
|
@@ -3067,8 +3099,8 @@ function convertLanguageModelContent({
|
|
|
3067
3099
|
(toolCall2) => toolCall2.toolCallId === part.toolCallId
|
|
3068
3100
|
);
|
|
3069
3101
|
if (toolCall == null) {
|
|
3070
|
-
const
|
|
3071
|
-
const supportsDeferredResults = (
|
|
3102
|
+
const tool3 = getOwn(tools, part.toolName);
|
|
3103
|
+
const supportsDeferredResults = (tool3 == null ? void 0 : tool3.type) === "provider" && tool3.supportsDeferredResults;
|
|
3072
3104
|
if (!supportsDeferredResults) {
|
|
3073
3105
|
throw new Error(`Tool call ${part.toolCallId} not found.`);
|
|
3074
3106
|
}
|
|
@@ -3082,7 +3114,7 @@ function convertLanguageModelContent({
|
|
|
3082
3114
|
providerExecuted: true,
|
|
3083
3115
|
dynamic: part.dynamic,
|
|
3084
3116
|
...part.providerMetadata != null ? { providerMetadata: part.providerMetadata } : {},
|
|
3085
|
-
...(
|
|
3117
|
+
...(tool3 == null ? void 0 : tool3.metadata) != null ? { toolMetadata: tool3.metadata } : {}
|
|
3086
3118
|
});
|
|
3087
3119
|
} else {
|
|
3088
3120
|
contentParts.push({
|
|
@@ -3094,7 +3126,7 @@ function convertLanguageModelContent({
|
|
|
3094
3126
|
providerExecuted: true,
|
|
3095
3127
|
dynamic: part.dynamic,
|
|
3096
3128
|
...part.providerMetadata != null ? { providerMetadata: part.providerMetadata } : {},
|
|
3097
|
-
...(
|
|
3129
|
+
...(tool3 == null ? void 0 : tool3.metadata) != null ? { toolMetadata: tool3.metadata } : {}
|
|
3098
3130
|
});
|
|
3099
3131
|
}
|
|
3100
3132
|
break;
|
|
@@ -3161,6 +3193,287 @@ function convertLanguageModelContent({
|
|
|
3161
3193
|
];
|
|
3162
3194
|
}
|
|
3163
3195
|
|
|
3196
|
+
// src/tool-search/prepare-tool-search.ts
|
|
3197
|
+
import {
|
|
3198
|
+
experimental_getToolCaller as experimental_getToolCaller2
|
|
3199
|
+
} from "@ai-sdk/provider-utils";
|
|
3200
|
+
|
|
3201
|
+
// src/generate-text/tool-caller-configuration.ts
|
|
3202
|
+
import {
|
|
3203
|
+
experimental_getToolCaller
|
|
3204
|
+
} from "@ai-sdk/provider-utils";
|
|
3205
|
+
var DIRECT_TOOL_CALL = "AI_SDK_DIRECT_TOOL_CALL";
|
|
3206
|
+
function resolveToolCallerConfiguration({
|
|
3207
|
+
tools,
|
|
3208
|
+
toolCallers
|
|
3209
|
+
}) {
|
|
3210
|
+
if (tools == null || toolCallers == null) {
|
|
3211
|
+
return void 0;
|
|
3212
|
+
}
|
|
3213
|
+
const resolved = {};
|
|
3214
|
+
for (const [toolName, callers] of Object.entries(toolCallers)) {
|
|
3215
|
+
if (!Object.prototype.hasOwnProperty.call(tools, toolName)) {
|
|
3216
|
+
throw new InvalidArgumentError({
|
|
3217
|
+
parameter: "experimental_toolCallers",
|
|
3218
|
+
value: toolCallers,
|
|
3219
|
+
message: `unknown tool "${toolName}".`
|
|
3220
|
+
});
|
|
3221
|
+
}
|
|
3222
|
+
if (!Array.isArray(callers)) {
|
|
3223
|
+
throw new InvalidArgumentError({
|
|
3224
|
+
parameter: "experimental_toolCallers",
|
|
3225
|
+
value: toolCallers,
|
|
3226
|
+
message: `callers for tool "${toolName}" must be an array.`
|
|
3227
|
+
});
|
|
3228
|
+
}
|
|
3229
|
+
resolved[toolName] = callers.map((caller) => {
|
|
3230
|
+
if (caller === DIRECT_TOOL_CALL) {
|
|
3231
|
+
return caller;
|
|
3232
|
+
}
|
|
3233
|
+
if (typeof caller !== "string" || !Object.prototype.hasOwnProperty.call(tools, caller) || experimental_getToolCaller(tools[caller]) == null) {
|
|
3234
|
+
throw new InvalidArgumentError({
|
|
3235
|
+
parameter: "experimental_toolCallers",
|
|
3236
|
+
value: toolCallers,
|
|
3237
|
+
message: `tool "${toolName}" contains an invalid caller.`
|
|
3238
|
+
});
|
|
3239
|
+
}
|
|
3240
|
+
return caller;
|
|
3241
|
+
});
|
|
3242
|
+
}
|
|
3243
|
+
return resolved;
|
|
3244
|
+
}
|
|
3245
|
+
function prepareToolsForToolCallers({
|
|
3246
|
+
tools,
|
|
3247
|
+
toolCallers
|
|
3248
|
+
}) {
|
|
3249
|
+
var _a25, _b25;
|
|
3250
|
+
if (tools == null || toolCallers == null) {
|
|
3251
|
+
return {
|
|
3252
|
+
executionTools: tools,
|
|
3253
|
+
modelTools: tools,
|
|
3254
|
+
toolCallerMessages: []
|
|
3255
|
+
};
|
|
3256
|
+
}
|
|
3257
|
+
const executionTools = { ...tools };
|
|
3258
|
+
const modelTools = { ...tools };
|
|
3259
|
+
const localToolsByCaller = /* @__PURE__ */ new Map();
|
|
3260
|
+
const toolCallerMessages = [];
|
|
3261
|
+
for (const [toolName, callerNames] of Object.entries(toolCallers)) {
|
|
3262
|
+
const tool3 = executionTools[toolName];
|
|
3263
|
+
if (tool3 == null) {
|
|
3264
|
+
continue;
|
|
3265
|
+
}
|
|
3266
|
+
let availableDirectly = false;
|
|
3267
|
+
let availableToProvider = false;
|
|
3268
|
+
let preparedTool = tool3;
|
|
3269
|
+
for (const callerName of callerNames) {
|
|
3270
|
+
if (callerName === DIRECT_TOOL_CALL) {
|
|
3271
|
+
availableDirectly = true;
|
|
3272
|
+
continue;
|
|
3273
|
+
}
|
|
3274
|
+
const caller = experimental_getToolCaller(executionTools[callerName]);
|
|
3275
|
+
if (caller == null) {
|
|
3276
|
+
continue;
|
|
3277
|
+
}
|
|
3278
|
+
if (caller.type === "provider") {
|
|
3279
|
+
availableToProvider = true;
|
|
3280
|
+
preparedTool = {
|
|
3281
|
+
...preparedTool,
|
|
3282
|
+
providerOptions: caller.prepareProviderOptions(
|
|
3283
|
+
preparedTool.providerOptions
|
|
3284
|
+
)
|
|
3285
|
+
};
|
|
3286
|
+
} else {
|
|
3287
|
+
const localTools = (_a25 = localToolsByCaller.get(callerName)) != null ? _a25 : {};
|
|
3288
|
+
localTools[toolName] = preparedTool;
|
|
3289
|
+
localToolsByCaller.set(callerName, localTools);
|
|
3290
|
+
}
|
|
3291
|
+
}
|
|
3292
|
+
executionTools[toolName] = preparedTool;
|
|
3293
|
+
if (availableDirectly || availableToProvider) {
|
|
3294
|
+
modelTools[toolName] = preparedTool;
|
|
3295
|
+
} else {
|
|
3296
|
+
delete modelTools[toolName];
|
|
3297
|
+
}
|
|
3298
|
+
}
|
|
3299
|
+
for (const [callerName, callerTool] of Object.entries(executionTools)) {
|
|
3300
|
+
const caller = experimental_getToolCaller(callerTool);
|
|
3301
|
+
if ((caller == null ? void 0 : caller.type) !== "local") {
|
|
3302
|
+
continue;
|
|
3303
|
+
}
|
|
3304
|
+
const callerTools = (_b25 = localToolsByCaller.get(callerName)) != null ? _b25 : {};
|
|
3305
|
+
const boundCaller = caller.bind(callerTools);
|
|
3306
|
+
executionTools[callerName] = boundCaller;
|
|
3307
|
+
if (Object.prototype.hasOwnProperty.call(modelTools, callerName)) {
|
|
3308
|
+
if (caller.prepareModelMessage == null) {
|
|
3309
|
+
modelTools[callerName] = boundCaller;
|
|
3310
|
+
} else {
|
|
3311
|
+
const content = caller.prepareModelMessage(callerTools);
|
|
3312
|
+
if (content != null) {
|
|
3313
|
+
toolCallerMessages.push({ role: "user", content });
|
|
3314
|
+
}
|
|
3315
|
+
}
|
|
3316
|
+
}
|
|
3317
|
+
}
|
|
3318
|
+
return { executionTools, modelTools, toolCallerMessages };
|
|
3319
|
+
}
|
|
3320
|
+
function appendToolCallerMessages({
|
|
3321
|
+
messages,
|
|
3322
|
+
toolCallerMessages
|
|
3323
|
+
}) {
|
|
3324
|
+
var _a25;
|
|
3325
|
+
if (toolCallerMessages.length === 0) {
|
|
3326
|
+
return messages;
|
|
3327
|
+
}
|
|
3328
|
+
const latestUserText = (_a25 = messages.findLast(
|
|
3329
|
+
(message) => message.role === "user" && typeof message.content === "string"
|
|
3330
|
+
)) == null ? void 0 : _a25.content;
|
|
3331
|
+
const existingUserText = new Set(
|
|
3332
|
+
latestUserText == null ? [] : [latestUserText]
|
|
3333
|
+
);
|
|
3334
|
+
const additions = toolCallerMessages.filter((message) => {
|
|
3335
|
+
if (typeof message.content !== "string" || existingUserText.has(message.content)) {
|
|
3336
|
+
return false;
|
|
3337
|
+
}
|
|
3338
|
+
existingUserText.add(message.content);
|
|
3339
|
+
return true;
|
|
3340
|
+
});
|
|
3341
|
+
return additions.length === 0 ? messages : [...messages, ...additions];
|
|
3342
|
+
}
|
|
3343
|
+
|
|
3344
|
+
// src/tool-search/tool-search.ts
|
|
3345
|
+
import { jsonSchema, tool } from "@ai-sdk/provider-utils";
|
|
3346
|
+
var toolSearchSymbol = /* @__PURE__ */ Symbol.for("vercel.ai.toolSearch");
|
|
3347
|
+
function toolSearch() {
|
|
3348
|
+
return Object.assign(
|
|
3349
|
+
tool({
|
|
3350
|
+
description: "Search for tools by keywords in their names and descriptions. Returns up to five matching tools. Matches become available on the next model step, after this execution finishes. Wait for their tool definitions before calling the discovered tools. If no tools match, try different keywords.",
|
|
3351
|
+
inputSchema: jsonSchema({
|
|
3352
|
+
type: "object",
|
|
3353
|
+
properties: { query: { type: "string", minLength: 1 } },
|
|
3354
|
+
required: ["query"],
|
|
3355
|
+
additionalProperties: false
|
|
3356
|
+
}),
|
|
3357
|
+
outputSchema: jsonSchema({
|
|
3358
|
+
type: "object",
|
|
3359
|
+
properties: {
|
|
3360
|
+
tools: {
|
|
3361
|
+
type: "array",
|
|
3362
|
+
items: {
|
|
3363
|
+
type: "object",
|
|
3364
|
+
properties: {
|
|
3365
|
+
name: { type: "string" },
|
|
3366
|
+
description: { type: "string" }
|
|
3367
|
+
},
|
|
3368
|
+
required: ["name"],
|
|
3369
|
+
additionalProperties: false
|
|
3370
|
+
}
|
|
3371
|
+
}
|
|
3372
|
+
},
|
|
3373
|
+
required: ["tools"],
|
|
3374
|
+
additionalProperties: false
|
|
3375
|
+
}),
|
|
3376
|
+
execute: () => {
|
|
3377
|
+
throw new Error("toolSearch must be bound by an AI SDK generation.");
|
|
3378
|
+
}
|
|
3379
|
+
}),
|
|
3380
|
+
{ type: "function", [toolSearchSymbol]: true }
|
|
3381
|
+
);
|
|
3382
|
+
}
|
|
3383
|
+
function isToolSearch(tool3) {
|
|
3384
|
+
return tool3[toolSearchSymbol] === true;
|
|
3385
|
+
}
|
|
3386
|
+
|
|
3387
|
+
// src/tool-search/prepare-tool-search.ts
|
|
3388
|
+
function createToolSearchState({
|
|
3389
|
+
tools,
|
|
3390
|
+
toolCallers
|
|
3391
|
+
}) {
|
|
3392
|
+
const searchTools = Object.entries(tools != null ? tools : {}).filter(
|
|
3393
|
+
([, tool3]) => tool3.deferLoading || isToolSearch(tool3)
|
|
3394
|
+
);
|
|
3395
|
+
if (searchTools.length === 0) {
|
|
3396
|
+
return (activeTools) => activeTools;
|
|
3397
|
+
}
|
|
3398
|
+
const discovered = /* @__PURE__ */ new Set();
|
|
3399
|
+
const getCallers = (name25) => {
|
|
3400
|
+
var _a25;
|
|
3401
|
+
return (_a25 = getOwn(toolCallers, name25)) != null ? _a25 : [DIRECT_TOOL_CALL];
|
|
3402
|
+
};
|
|
3403
|
+
for (const [name25, tool3] of searchTools) {
|
|
3404
|
+
const callers = getCallers(name25);
|
|
3405
|
+
if (callers.some((name26) => {
|
|
3406
|
+
if (name26 === DIRECT_TOOL_CALL) {
|
|
3407
|
+
return false;
|
|
3408
|
+
}
|
|
3409
|
+
const caller = experimental_getToolCaller2(tools == null ? void 0 : tools[name26]);
|
|
3410
|
+
return (caller == null ? void 0 : caller.type) !== "local" || caller.prepareModelMessage == null;
|
|
3411
|
+
}) || isToolSearch(tool3) && tool3.deferLoading) {
|
|
3412
|
+
throw new InvalidArgumentError({
|
|
3413
|
+
parameter: "tools",
|
|
3414
|
+
value: name25,
|
|
3415
|
+
message: `tool "${name25}" must be callable directly or through code mode with toolDiscovery: 'conversation'. The search tool itself must not defer loading.`
|
|
3416
|
+
});
|
|
3417
|
+
}
|
|
3418
|
+
}
|
|
3419
|
+
return (activeTools, { toolsContext = {}, experimental_sandbox } = {}) => {
|
|
3420
|
+
if (activeTools == null) {
|
|
3421
|
+
return void 0;
|
|
3422
|
+
}
|
|
3423
|
+
const entries = Object.entries(activeTools);
|
|
3424
|
+
return Object.fromEntries(
|
|
3425
|
+
entries.filter(([name25, tool3]) => !tool3.deferLoading || discovered.has(name25)).map(([searchName, tool3]) => {
|
|
3426
|
+
if (!isToolSearch(tool3)) {
|
|
3427
|
+
return [searchName, tool3];
|
|
3428
|
+
}
|
|
3429
|
+
const callers = getCallers(searchName).filter(
|
|
3430
|
+
(name25) => name25 === DIRECT_TOOL_CALL || Object.hasOwn(activeTools, name25)
|
|
3431
|
+
);
|
|
3432
|
+
const candidates = entries.filter(
|
|
3433
|
+
([name25, candidate]) => candidate.deferLoading && !isToolSearch(candidate) && callers.some((caller) => getCallers(name25).includes(caller))
|
|
3434
|
+
);
|
|
3435
|
+
return [
|
|
3436
|
+
searchName,
|
|
3437
|
+
{
|
|
3438
|
+
...tool3,
|
|
3439
|
+
execute: ({ query }) => {
|
|
3440
|
+
const terms = [...new Set(tokenize(query))];
|
|
3441
|
+
const matches = candidates.map(([name25, candidate]) => {
|
|
3442
|
+
const description = resolveToolDescription({
|
|
3443
|
+
tool: candidate,
|
|
3444
|
+
toolName: name25,
|
|
3445
|
+
toolsContext,
|
|
3446
|
+
experimental_sandbox
|
|
3447
|
+
});
|
|
3448
|
+
const nameTerms = tokenize(name25);
|
|
3449
|
+
const descriptionTerms = tokenize(description != null ? description : "");
|
|
3450
|
+
const score = terms.reduce(
|
|
3451
|
+
(score2, term) => score2 + (nameTerms.includes(term) ? 2 : 0) + (descriptionTerms.includes(term) ? 1 : 0),
|
|
3452
|
+
0
|
|
3453
|
+
);
|
|
3454
|
+
return { name: name25, description, score };
|
|
3455
|
+
}).filter((match) => match.score > 0).sort((a, b) => b.score - a.score).slice(0, 5);
|
|
3456
|
+
for (const { name: name25 } of matches) {
|
|
3457
|
+
discovered.add(name25);
|
|
3458
|
+
}
|
|
3459
|
+
return {
|
|
3460
|
+
tools: matches.map(({ name: name25, description }) => ({
|
|
3461
|
+
name: name25,
|
|
3462
|
+
...description == null ? {} : { description }
|
|
3463
|
+
}))
|
|
3464
|
+
};
|
|
3465
|
+
}
|
|
3466
|
+
}
|
|
3467
|
+
];
|
|
3468
|
+
})
|
|
3469
|
+
);
|
|
3470
|
+
};
|
|
3471
|
+
}
|
|
3472
|
+
function tokenize(text2) {
|
|
3473
|
+
var _a25;
|
|
3474
|
+
return (_a25 = text2.replace(/([a-z\d])([A-Z])/g, "$1 $2").toLowerCase().match(/[\p{L}\p{N}]+/gu)) != null ? _a25 : [];
|
|
3475
|
+
}
|
|
3476
|
+
|
|
3164
3477
|
// src/generate-text/execute-tool-call.ts
|
|
3165
3478
|
import {
|
|
3166
3479
|
executeTool,
|
|
@@ -3204,14 +3517,14 @@ async function executeToolCall({
|
|
|
3204
3517
|
runInTracingChannelSpan = async ({ execute }) => await execute()
|
|
3205
3518
|
}) {
|
|
3206
3519
|
const { toolName, toolCallId, input } = toolCall;
|
|
3207
|
-
const
|
|
3208
|
-
if (!isExecutableTool(
|
|
3520
|
+
const tool3 = getOwn(tools, toolName);
|
|
3521
|
+
if (!isExecutableTool(tool3)) {
|
|
3209
3522
|
return void 0;
|
|
3210
3523
|
}
|
|
3211
3524
|
const context = await validateToolContext({
|
|
3212
3525
|
toolName,
|
|
3213
3526
|
context: getOwn(toolsContext, toolName),
|
|
3214
|
-
contextSchema:
|
|
3527
|
+
contextSchema: tool3.contextSchema
|
|
3215
3528
|
});
|
|
3216
3529
|
const toolExecutionContext = {
|
|
3217
3530
|
toolCall,
|
|
@@ -3243,7 +3556,7 @@ async function executeToolCall({
|
|
|
3243
3556
|
const startTime = now();
|
|
3244
3557
|
try {
|
|
3245
3558
|
const stream = executeTool({
|
|
3246
|
-
tool:
|
|
3559
|
+
tool: tool3,
|
|
3247
3560
|
input,
|
|
3248
3561
|
options: {
|
|
3249
3562
|
toolCallId,
|
|
@@ -3277,7 +3590,7 @@ async function executeToolCall({
|
|
|
3277
3590
|
toolName,
|
|
3278
3591
|
input,
|
|
3279
3592
|
error,
|
|
3280
|
-
dynamic:
|
|
3593
|
+
dynamic: tool3.type === "dynamic",
|
|
3281
3594
|
...toolCall.providerMetadata != null ? { providerMetadata: toolCall.providerMetadata } : {},
|
|
3282
3595
|
...toolCall.toolMetadata != null ? { toolMetadata: toolCall.toolMetadata } : {}
|
|
3283
3596
|
};
|
|
@@ -3300,7 +3613,7 @@ async function executeToolCall({
|
|
|
3300
3613
|
toolName,
|
|
3301
3614
|
input,
|
|
3302
3615
|
output,
|
|
3303
|
-
dynamic:
|
|
3616
|
+
dynamic: tool3.type === "dynamic",
|
|
3304
3617
|
...toolCall.providerMetadata != null ? { providerMetadata: toolCall.providerMetadata } : {},
|
|
3305
3618
|
...toolCall.toolMetadata != null ? { toolMetadata: toolCall.toolMetadata } : {}
|
|
3306
3619
|
};
|
|
@@ -3735,9 +4048,9 @@ var object2 = ({
|
|
|
3735
4048
|
const schema = asSchema2(inputSchema);
|
|
3736
4049
|
return {
|
|
3737
4050
|
name: "object",
|
|
3738
|
-
responseFormat: resolve(schema.jsonSchema).then((
|
|
4051
|
+
responseFormat: resolve(schema.jsonSchema).then((jsonSchema3) => ({
|
|
3739
4052
|
type: "json",
|
|
3740
|
-
schema:
|
|
4053
|
+
schema: jsonSchema3,
|
|
3741
4054
|
...name25 != null && { name: name25 },
|
|
3742
4055
|
...description != null && { description }
|
|
3743
4056
|
})),
|
|
@@ -3810,13 +4123,13 @@ var array2 = ({
|
|
|
3810
4123
|
return {
|
|
3811
4124
|
name: "array",
|
|
3812
4125
|
// JSON schema that describes an array of elements:
|
|
3813
|
-
responseFormat: resolve(elementSchema.jsonSchema).then((
|
|
4126
|
+
responseFormat: resolve(elementSchema.jsonSchema).then((jsonSchema3) => {
|
|
3814
4127
|
const {
|
|
3815
4128
|
$schema: _$schema,
|
|
3816
4129
|
definitions,
|
|
3817
4130
|
$defs,
|
|
3818
4131
|
...itemSchema
|
|
3819
|
-
} =
|
|
4132
|
+
} = jsonSchema3;
|
|
3820
4133
|
return {
|
|
3821
4134
|
type: "json",
|
|
3822
4135
|
schema: {
|
|
@@ -4180,7 +4493,7 @@ async function parseToolCall({
|
|
|
4180
4493
|
} catch (error) {
|
|
4181
4494
|
const parsedInput = await safeParseJSON3({ text: toolCall.input });
|
|
4182
4495
|
const input = parsedInput.success ? parsedInput.value : toolCall.input;
|
|
4183
|
-
const
|
|
4496
|
+
const tool3 = getOwn(tools, toolCall.toolName);
|
|
4184
4497
|
return {
|
|
4185
4498
|
type: "tool-call",
|
|
4186
4499
|
toolCallId: toolCall.toolCallId,
|
|
@@ -4189,10 +4502,10 @@ async function parseToolCall({
|
|
|
4189
4502
|
dynamic: true,
|
|
4190
4503
|
invalid: true,
|
|
4191
4504
|
error,
|
|
4192
|
-
title:
|
|
4505
|
+
title: tool3 == null ? void 0 : tool3.title,
|
|
4193
4506
|
providerExecuted: toolCall.providerExecuted,
|
|
4194
4507
|
providerMetadata: toolCall.providerMetadata,
|
|
4195
|
-
...(
|
|
4508
|
+
...(tool3 == null ? void 0 : tool3.metadata) != null ? { toolMetadata: tool3.metadata } : {}
|
|
4196
4509
|
};
|
|
4197
4510
|
}
|
|
4198
4511
|
}
|
|
@@ -4233,8 +4546,8 @@ async function doParseToolCall({
|
|
|
4233
4546
|
tools
|
|
4234
4547
|
}) {
|
|
4235
4548
|
const toolName = toolCall.toolName;
|
|
4236
|
-
const
|
|
4237
|
-
if (
|
|
4549
|
+
const tool3 = getOwn(tools, toolName);
|
|
4550
|
+
if (tool3 == null) {
|
|
4238
4551
|
if (toolCall.providerExecuted && toolCall.dynamic) {
|
|
4239
4552
|
return await parseProviderExecutedDynamicToolCall(toolCall);
|
|
4240
4553
|
}
|
|
@@ -4243,7 +4556,7 @@ async function doParseToolCall({
|
|
|
4243
4556
|
availableTools: Object.keys(tools)
|
|
4244
4557
|
});
|
|
4245
4558
|
}
|
|
4246
|
-
const schema = asSchema3(
|
|
4559
|
+
const schema = asSchema3(tool3.inputSchema);
|
|
4247
4560
|
const parseResult = toolCall.input.trim() === "" ? await safeValidateTypes3({ value: {}, schema }) : await safeParseJSON3({ text: toolCall.input, schema });
|
|
4248
4561
|
if (parseResult.success === false) {
|
|
4249
4562
|
throw new InvalidToolInputError({
|
|
@@ -4252,16 +4565,16 @@ async function doParseToolCall({
|
|
|
4252
4565
|
cause: parseResult.error
|
|
4253
4566
|
});
|
|
4254
4567
|
}
|
|
4255
|
-
return
|
|
4568
|
+
return tool3.type === "dynamic" ? {
|
|
4256
4569
|
type: "tool-call",
|
|
4257
4570
|
toolCallId: toolCall.toolCallId,
|
|
4258
4571
|
toolName: toolCall.toolName,
|
|
4259
4572
|
input: parseResult.value,
|
|
4260
4573
|
providerExecuted: toolCall.providerExecuted,
|
|
4261
4574
|
providerMetadata: toolCall.providerMetadata,
|
|
4262
|
-
...
|
|
4575
|
+
...tool3.metadata != null ? { toolMetadata: tool3.metadata } : {},
|
|
4263
4576
|
dynamic: true,
|
|
4264
|
-
title:
|
|
4577
|
+
title: tool3.title
|
|
4265
4578
|
} : {
|
|
4266
4579
|
type: "tool-call",
|
|
4267
4580
|
toolCallId: toolCall.toolCallId,
|
|
@@ -4269,8 +4582,8 @@ async function doParseToolCall({
|
|
|
4269
4582
|
input: parseResult.value,
|
|
4270
4583
|
providerExecuted: toolCall.providerExecuted,
|
|
4271
4584
|
providerMetadata: toolCall.providerMetadata,
|
|
4272
|
-
...
|
|
4273
|
-
title:
|
|
4585
|
+
...tool3.metadata != null ? { toolMetadata: tool3.metadata } : {},
|
|
4586
|
+
title: tool3.title
|
|
4274
4587
|
};
|
|
4275
4588
|
}
|
|
4276
4589
|
|
|
@@ -4360,7 +4673,7 @@ async function resolveToolApproval({
|
|
|
4360
4673
|
);
|
|
4361
4674
|
}
|
|
4362
4675
|
const toolName = toolCall.toolName;
|
|
4363
|
-
const
|
|
4676
|
+
const tool3 = getOwn(tools, toolName);
|
|
4364
4677
|
const input = toolCall.input;
|
|
4365
4678
|
const userDefinedToolApprovalStatus = getOwn(toolApproval, toolName);
|
|
4366
4679
|
if (userDefinedToolApprovalStatus != null) {
|
|
@@ -4370,24 +4683,24 @@ async function resolveToolApproval({
|
|
|
4370
4683
|
toolContext: await validateToolContext({
|
|
4371
4684
|
toolName,
|
|
4372
4685
|
context: getOwn(toolsContext, toolName),
|
|
4373
|
-
contextSchema:
|
|
4686
|
+
contextSchema: tool3 == null ? void 0 : tool3.contextSchema
|
|
4374
4687
|
}),
|
|
4375
4688
|
runtimeContext
|
|
4376
4689
|
}) : userDefinedToolApprovalStatus;
|
|
4377
4690
|
return normalizeToolApprovalStatus(approvalStatus);
|
|
4378
4691
|
}
|
|
4379
|
-
if ((
|
|
4692
|
+
if ((tool3 == null ? void 0 : tool3.needsApproval) == null) {
|
|
4380
4693
|
return { type: "not-applicable" };
|
|
4381
4694
|
}
|
|
4382
|
-
const needsApproval = typeof
|
|
4695
|
+
const needsApproval = typeof tool3.needsApproval === "function" ? await tool3.needsApproval(input, {
|
|
4383
4696
|
toolCallId: toolCall.toolCallId,
|
|
4384
4697
|
messages,
|
|
4385
4698
|
context: await validateToolContext({
|
|
4386
4699
|
toolName,
|
|
4387
4700
|
context: getOwn(toolsContext, toolName),
|
|
4388
|
-
contextSchema:
|
|
4701
|
+
contextSchema: tool3 == null ? void 0 : tool3.contextSchema
|
|
4389
4702
|
})
|
|
4390
|
-
}) :
|
|
4703
|
+
}) : tool3.needsApproval;
|
|
4391
4704
|
return needsApproval ? { type: "user-approval" } : { type: "not-applicable" };
|
|
4392
4705
|
}
|
|
4393
4706
|
function normalizeToolApprovalStatus(status) {
|
|
@@ -5198,113 +5511,6 @@ function sortToolResultContentByToolCallOrder({
|
|
|
5198
5511
|
);
|
|
5199
5512
|
}
|
|
5200
5513
|
|
|
5201
|
-
// src/generate-text/tool-caller-configuration.ts
|
|
5202
|
-
import {
|
|
5203
|
-
experimental_getToolCaller
|
|
5204
|
-
} from "@ai-sdk/provider-utils";
|
|
5205
|
-
var DIRECT_TOOL_CALL = "AI_SDK_DIRECT_TOOL_CALL";
|
|
5206
|
-
function resolveToolCallerConfiguration({
|
|
5207
|
-
tools,
|
|
5208
|
-
toolCallers
|
|
5209
|
-
}) {
|
|
5210
|
-
if (tools == null || toolCallers == null) {
|
|
5211
|
-
return void 0;
|
|
5212
|
-
}
|
|
5213
|
-
const resolved = {};
|
|
5214
|
-
for (const [toolName, callers] of Object.entries(toolCallers)) {
|
|
5215
|
-
if (!Object.prototype.hasOwnProperty.call(tools, toolName)) {
|
|
5216
|
-
throw new InvalidArgumentError({
|
|
5217
|
-
parameter: "experimental_toolCallers",
|
|
5218
|
-
value: toolCallers,
|
|
5219
|
-
message: `unknown tool "${toolName}".`
|
|
5220
|
-
});
|
|
5221
|
-
}
|
|
5222
|
-
if (!Array.isArray(callers)) {
|
|
5223
|
-
throw new InvalidArgumentError({
|
|
5224
|
-
parameter: "experimental_toolCallers",
|
|
5225
|
-
value: toolCallers,
|
|
5226
|
-
message: `callers for tool "${toolName}" must be an array.`
|
|
5227
|
-
});
|
|
5228
|
-
}
|
|
5229
|
-
resolved[toolName] = callers.map((caller) => {
|
|
5230
|
-
if (caller === DIRECT_TOOL_CALL) {
|
|
5231
|
-
return caller;
|
|
5232
|
-
}
|
|
5233
|
-
if (typeof caller !== "string" || !Object.prototype.hasOwnProperty.call(tools, caller) || experimental_getToolCaller(tools[caller]) == null) {
|
|
5234
|
-
throw new InvalidArgumentError({
|
|
5235
|
-
parameter: "experimental_toolCallers",
|
|
5236
|
-
value: toolCallers,
|
|
5237
|
-
message: `tool "${toolName}" contains an invalid caller.`
|
|
5238
|
-
});
|
|
5239
|
-
}
|
|
5240
|
-
return caller;
|
|
5241
|
-
});
|
|
5242
|
-
}
|
|
5243
|
-
return resolved;
|
|
5244
|
-
}
|
|
5245
|
-
function prepareToolsForToolCallers({
|
|
5246
|
-
tools,
|
|
5247
|
-
toolCallers
|
|
5248
|
-
}) {
|
|
5249
|
-
var _a25, _b25;
|
|
5250
|
-
if (tools == null || toolCallers == null) {
|
|
5251
|
-
return { executionTools: tools, modelTools: tools };
|
|
5252
|
-
}
|
|
5253
|
-
const executionTools = { ...tools };
|
|
5254
|
-
const modelTools = { ...tools };
|
|
5255
|
-
const localToolsByCaller = /* @__PURE__ */ new Map();
|
|
5256
|
-
for (const [toolName, callerNames] of Object.entries(toolCallers)) {
|
|
5257
|
-
const tool2 = executionTools[toolName];
|
|
5258
|
-
if (tool2 == null) {
|
|
5259
|
-
continue;
|
|
5260
|
-
}
|
|
5261
|
-
let availableDirectly = false;
|
|
5262
|
-
let availableToProvider = false;
|
|
5263
|
-
let preparedTool = tool2;
|
|
5264
|
-
for (const callerName of callerNames) {
|
|
5265
|
-
if (callerName === DIRECT_TOOL_CALL) {
|
|
5266
|
-
availableDirectly = true;
|
|
5267
|
-
continue;
|
|
5268
|
-
}
|
|
5269
|
-
const caller = experimental_getToolCaller(executionTools[callerName]);
|
|
5270
|
-
if (caller == null) {
|
|
5271
|
-
continue;
|
|
5272
|
-
}
|
|
5273
|
-
if (caller.type === "provider") {
|
|
5274
|
-
availableToProvider = true;
|
|
5275
|
-
preparedTool = {
|
|
5276
|
-
...preparedTool,
|
|
5277
|
-
providerOptions: caller.prepareProviderOptions(
|
|
5278
|
-
preparedTool.providerOptions
|
|
5279
|
-
)
|
|
5280
|
-
};
|
|
5281
|
-
} else {
|
|
5282
|
-
const localTools = (_a25 = localToolsByCaller.get(callerName)) != null ? _a25 : {};
|
|
5283
|
-
localTools[toolName] = preparedTool;
|
|
5284
|
-
localToolsByCaller.set(callerName, localTools);
|
|
5285
|
-
}
|
|
5286
|
-
}
|
|
5287
|
-
executionTools[toolName] = preparedTool;
|
|
5288
|
-
if (availableDirectly || availableToProvider) {
|
|
5289
|
-
modelTools[toolName] = preparedTool;
|
|
5290
|
-
} else {
|
|
5291
|
-
delete modelTools[toolName];
|
|
5292
|
-
}
|
|
5293
|
-
}
|
|
5294
|
-
for (const [callerName, callerTool] of Object.entries(executionTools)) {
|
|
5295
|
-
const caller = experimental_getToolCaller(callerTool);
|
|
5296
|
-
if ((caller == null ? void 0 : caller.type) !== "local") {
|
|
5297
|
-
continue;
|
|
5298
|
-
}
|
|
5299
|
-
const boundCaller = caller.bind((_b25 = localToolsByCaller.get(callerName)) != null ? _b25 : {});
|
|
5300
|
-
executionTools[callerName] = boundCaller;
|
|
5301
|
-
if (Object.prototype.hasOwnProperty.call(modelTools, callerName)) {
|
|
5302
|
-
modelTools[callerName] = boundCaller;
|
|
5303
|
-
}
|
|
5304
|
-
}
|
|
5305
|
-
return { executionTools, modelTools };
|
|
5306
|
-
}
|
|
5307
|
-
|
|
5308
5514
|
// src/generate-text/tool-approval-signature.ts
|
|
5309
5515
|
import { convertBase64ToUint8Array as convertBase64ToUint8Array2 } from "@ai-sdk/provider-utils";
|
|
5310
5516
|
|
|
@@ -5443,7 +5649,7 @@ async function validateApprovedToolApprovals({
|
|
|
5443
5649
|
const invalid = [];
|
|
5444
5650
|
for (const approval of approvedToolApprovals) {
|
|
5445
5651
|
const { toolCall, approvalRequest } = approval;
|
|
5446
|
-
const
|
|
5652
|
+
const tool3 = getOwn(tools, toolCall.toolName);
|
|
5447
5653
|
if (toolApprovalSecret != null) {
|
|
5448
5654
|
if (approvalRequest.signature == null) {
|
|
5449
5655
|
throw new InvalidToolApprovalSignatureError({
|
|
@@ -5468,10 +5674,10 @@ async function validateApprovedToolApprovals({
|
|
|
5468
5674
|
});
|
|
5469
5675
|
}
|
|
5470
5676
|
}
|
|
5471
|
-
if (isExecutableTool2(
|
|
5677
|
+
if (isExecutableTool2(tool3) && tool3.inputSchema != null) {
|
|
5472
5678
|
const validation = await safeValidateTypes4({
|
|
5473
5679
|
value: toolCall.input,
|
|
5474
|
-
schema: asSchema4(
|
|
5680
|
+
schema: asSchema4(tool3.inputSchema)
|
|
5475
5681
|
});
|
|
5476
5682
|
if (!validation.success) {
|
|
5477
5683
|
invalid.push({
|
|
@@ -5589,6 +5795,10 @@ async function generateText({
|
|
|
5589
5795
|
tools,
|
|
5590
5796
|
toolCallers: experimental_toolCallers
|
|
5591
5797
|
});
|
|
5798
|
+
const prepareToolSearch = createToolSearchState({
|
|
5799
|
+
tools,
|
|
5800
|
+
toolCallers: resolvedToolCallers
|
|
5801
|
+
});
|
|
5592
5802
|
const stopConditions = asArray5(stopWhen);
|
|
5593
5803
|
const resolvedOnStart = onStart != null ? onStart : experimental_onStart;
|
|
5594
5804
|
const resolvedOnStepStart = onStepStart != null ? onStepStart : experimental_onStepStart;
|
|
@@ -5825,7 +6035,7 @@ async function generateText({
|
|
|
5825
6035
|
type: "step",
|
|
5826
6036
|
event: { callId, stepNumber },
|
|
5827
6037
|
execute: async () => {
|
|
5828
|
-
var _a27, _b26, _c2, _d2, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p
|
|
6038
|
+
var _a27, _b26, _c2, _d2, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p;
|
|
5829
6039
|
const accumulatedResponseMessages = [
|
|
5830
6040
|
...initialResponseMessages,
|
|
5831
6041
|
...steps.flatMap((step) => step.response.messages)
|
|
@@ -5849,29 +6059,24 @@ async function generateText({
|
|
|
5849
6059
|
(_b26 = prepareStepResult == null ? void 0 : prepareStepResult.model) != null ? _b26 : model
|
|
5850
6060
|
);
|
|
5851
6061
|
const stepInstructions = (_d2 = (_c2 = prepareStepResult == null ? void 0 : prepareStepResult.instructions) != null ? _c2 : prepareStepResult == null ? void 0 : prepareStepResult.system) != null ? _d2 : instructionsForNextStep;
|
|
5852
|
-
|
|
5853
|
-
|
|
5854
|
-
instructions: stepInstructions,
|
|
5855
|
-
messages: (_e = prepareStepResult == null ? void 0 : prepareStepResult.messages) != null ? _e : stepInputMessages
|
|
5856
|
-
},
|
|
5857
|
-
supportedUrls: await stepModel.supportedUrls,
|
|
5858
|
-
download: download2,
|
|
5859
|
-
provider: stepModel.provider.split(".")[0]
|
|
5860
|
-
});
|
|
5861
|
-
runtimeContext = (_f = prepareStepResult == null ? void 0 : prepareStepResult.runtimeContext) != null ? _f : runtimeContext;
|
|
5862
|
-
toolsContext = (_g = prepareStepResult == null ? void 0 : prepareStepResult.toolsContext) != null ? _g : toolsContext;
|
|
6062
|
+
runtimeContext = (_e = prepareStepResult == null ? void 0 : prepareStepResult.runtimeContext) != null ? _e : runtimeContext;
|
|
6063
|
+
toolsContext = (_f = prepareStepResult == null ? void 0 : prepareStepResult.toolsContext) != null ? _f : toolsContext;
|
|
5863
6064
|
const stepActiveTools = filterActiveTools({
|
|
5864
6065
|
tools,
|
|
5865
|
-
activeTools: (
|
|
6066
|
+
activeTools: (_g = prepareStepResult == null ? void 0 : prepareStepResult.activeTools) != null ? _g : activeTools
|
|
5866
6067
|
});
|
|
5867
6068
|
const {
|
|
5868
6069
|
executionTools: stepExecutionTools,
|
|
5869
|
-
modelTools: stepModelTools
|
|
6070
|
+
modelTools: stepModelTools,
|
|
6071
|
+
toolCallerMessages
|
|
5870
6072
|
} = prepareToolsForToolCallers({
|
|
5871
|
-
tools: stepActiveTools,
|
|
6073
|
+
tools: prepareToolSearch(stepActiveTools, {
|
|
6074
|
+
toolsContext,
|
|
6075
|
+
experimental_sandbox: stepSandbox
|
|
6076
|
+
}),
|
|
5872
6077
|
toolCallers: resolvedToolCallers
|
|
5873
6078
|
});
|
|
5874
|
-
const stepToolOrder = (
|
|
6079
|
+
const stepToolOrder = (_h = prepareStepResult == null ? void 0 : prepareStepResult.toolOrder) != null ? _h : toolOrder;
|
|
5875
6080
|
const stepTools = await prepareTools({
|
|
5876
6081
|
tools: stepModelTools,
|
|
5877
6082
|
toolOrder: stepToolOrder,
|
|
@@ -5880,9 +6085,21 @@ async function generateText({
|
|
|
5880
6085
|
experimental_sandbox: stepSandbox
|
|
5881
6086
|
});
|
|
5882
6087
|
const stepToolChoice = prepareToolChoice({
|
|
5883
|
-
toolChoice: (
|
|
6088
|
+
toolChoice: (_i = prepareStepResult == null ? void 0 : prepareStepResult.toolChoice) != null ? _i : toolChoice
|
|
6089
|
+
});
|
|
6090
|
+
const stepMessages = appendToolCallerMessages({
|
|
6091
|
+
messages: (_j = prepareStepResult == null ? void 0 : prepareStepResult.messages) != null ? _j : stepInputMessages,
|
|
6092
|
+
toolCallerMessages
|
|
6093
|
+
});
|
|
6094
|
+
const promptMessages = await convertToLanguageModelPrompt({
|
|
6095
|
+
prompt: {
|
|
6096
|
+
instructions: stepInstructions,
|
|
6097
|
+
messages: stepMessages
|
|
6098
|
+
},
|
|
6099
|
+
supportedUrls: await stepModel.supportedUrls,
|
|
6100
|
+
download: download2,
|
|
6101
|
+
provider: stepModel.provider.split(".")[0]
|
|
5884
6102
|
});
|
|
5885
|
-
const stepMessages = (_k = prepareStepResult == null ? void 0 : prepareStepResult.messages) != null ? _k : stepInputMessages;
|
|
5886
6103
|
const stepProviderOptions = mergeObjects(
|
|
5887
6104
|
providerOptions,
|
|
5888
6105
|
prepareStepResult == null ? void 0 : prepareStepResult.providerOptions
|
|
@@ -5900,8 +6117,8 @@ async function generateText({
|
|
|
5900
6117
|
instructions: stepInstructions,
|
|
5901
6118
|
messages: stepMessages,
|
|
5902
6119
|
tools,
|
|
5903
|
-
toolChoice: (
|
|
5904
|
-
activeTools: (
|
|
6120
|
+
toolChoice: (_k = prepareStepResult == null ? void 0 : prepareStepResult.toolChoice) != null ? _k : toolChoice,
|
|
6121
|
+
activeTools: (_l = prepareStepResult == null ? void 0 : prepareStepResult.activeTools) != null ? _l : activeTools,
|
|
5905
6122
|
toolOrder: stepToolOrder,
|
|
5906
6123
|
steps: [...steps],
|
|
5907
6124
|
providerOptions: stepProviderOptions,
|
|
@@ -5937,7 +6154,7 @@ async function generateText({
|
|
|
5937
6154
|
telemetryDispatcher.onLanguageModelCallStart
|
|
5938
6155
|
]
|
|
5939
6156
|
});
|
|
5940
|
-
const executeLanguageModelCallInTelemetryContext = (
|
|
6157
|
+
const executeLanguageModelCallInTelemetryContext = (_m = telemetryDispatcher.executeLanguageModelCall) != null ? _m : (async ({ execute }) => await execute());
|
|
5941
6158
|
currentModelResponse = await retry(async () => {
|
|
5942
6159
|
var _a28, _b27, _c3, _d3, _e2, _f2, _g2, _h2;
|
|
5943
6160
|
const result = await executeLanguageModelCallInTelemetryContext(
|
|
@@ -6044,20 +6261,20 @@ async function generateText({
|
|
|
6044
6261
|
if (toolCall.invalid) {
|
|
6045
6262
|
continue;
|
|
6046
6263
|
}
|
|
6047
|
-
const
|
|
6048
|
-
if (
|
|
6264
|
+
const tool3 = getOwn(stepExecutionTools, toolCall.toolName);
|
|
6265
|
+
if (tool3 == null) {
|
|
6049
6266
|
continue;
|
|
6050
6267
|
}
|
|
6051
|
-
if (
|
|
6052
|
-
await
|
|
6268
|
+
if (tool3.onInputStart != null) {
|
|
6269
|
+
await tool3.onInputStart({
|
|
6053
6270
|
toolCallId: toolCall.toolCallId,
|
|
6054
6271
|
messages: stepMessages,
|
|
6055
6272
|
abortSignal: mergedAbortSignal,
|
|
6056
6273
|
context: runtimeContext
|
|
6057
6274
|
});
|
|
6058
6275
|
}
|
|
6059
|
-
if ((
|
|
6060
|
-
await
|
|
6276
|
+
if ((tool3 == null ? void 0 : tool3.onInputAvailable) != null) {
|
|
6277
|
+
await tool3.onInputAvailable({
|
|
6061
6278
|
input: toolCall.input,
|
|
6062
6279
|
toolCallId: toolCall.toolCallId,
|
|
6063
6280
|
messages: stepMessages,
|
|
@@ -6215,8 +6432,8 @@ async function generateText({
|
|
|
6215
6432
|
};
|
|
6216
6433
|
for (const toolCall of stepToolCalls) {
|
|
6217
6434
|
if (!toolCall.providerExecuted) continue;
|
|
6218
|
-
const
|
|
6219
|
-
if ((
|
|
6435
|
+
const tool3 = getOwn(stepExecutionTools, toolCall.toolName);
|
|
6436
|
+
if ((tool3 == null ? void 0 : tool3.type) === "provider" && tool3.supportsDeferredResults) {
|
|
6220
6437
|
const hasResultInResponse = currentModelResponse.content.some(
|
|
6221
6438
|
(part) => part.type === "tool-result" && part.toolCallId === toolCall.toolCallId
|
|
6222
6439
|
);
|
|
@@ -6246,7 +6463,7 @@ async function generateText({
|
|
|
6246
6463
|
});
|
|
6247
6464
|
const stepRequest = {
|
|
6248
6465
|
...currentModelResponse.request,
|
|
6249
|
-
body: include.requestBody ? (
|
|
6466
|
+
body: include.requestBody ? (_n = currentModelResponse.request) == null ? void 0 : _n.body : void 0,
|
|
6250
6467
|
messages: include.requestMessages ? cloneModelMessages(stepMessages) : void 0
|
|
6251
6468
|
};
|
|
6252
6469
|
const stepResponse = {
|
|
@@ -6254,7 +6471,7 @@ async function generateText({
|
|
|
6254
6471
|
// deep clone msgs to avoid mutating step results in multi-step:
|
|
6255
6472
|
messages: cloneModelMessages(stepResponseMessages),
|
|
6256
6473
|
// Conditionally include response body:
|
|
6257
|
-
body: include.responseBody ? (
|
|
6474
|
+
body: include.responseBody ? (_o = currentModelResponse.response) == null ? void 0 : _o.body : void 0
|
|
6258
6475
|
};
|
|
6259
6476
|
const currentStepResult = new DefaultStepResult({
|
|
6260
6477
|
callId,
|
|
@@ -6274,7 +6491,7 @@ async function generateText({
|
|
|
6274
6491
|
toolsContext
|
|
6275
6492
|
});
|
|
6276
6493
|
logWarnings({
|
|
6277
|
-
warnings: (
|
|
6494
|
+
warnings: (_p = currentModelResponse.warnings) != null ? _p : [],
|
|
6278
6495
|
provider: stepModel.provider,
|
|
6279
6496
|
model: stepModel.modelId
|
|
6280
6497
|
});
|
|
@@ -6970,6 +7187,25 @@ function getToolName(part) {
|
|
|
6970
7187
|
}
|
|
6971
7188
|
var getToolOrDynamicToolName = getToolName;
|
|
6972
7189
|
|
|
7190
|
+
// src/ui/warn-if-ui-message-has-deprecated-raw-input.ts
|
|
7191
|
+
var rawInputDeprecationWarning = {
|
|
7192
|
+
type: "deprecated",
|
|
7193
|
+
setting: "rawInput in output-error UI message parts",
|
|
7194
|
+
message: 'Use the "input" field instead. The "rawInput" field will be removed in the next major version.'
|
|
7195
|
+
};
|
|
7196
|
+
function warnIfUIMessageHasDeprecatedRawInput(messages) {
|
|
7197
|
+
const hasDeprecatedRawInput = messages.some(
|
|
7198
|
+
(message) => message.parts.some(
|
|
7199
|
+
(part) => part != null && typeof part === "object" && "type" in part && typeof part.type === "string" && (part.type === "dynamic-tool" || part.type.startsWith("tool-")) && "state" in part && part.state === "output-error" && Object.prototype.hasOwnProperty.call(part, "rawInput") && "rawInput" in part && part.rawInput !== void 0
|
|
7200
|
+
)
|
|
7201
|
+
);
|
|
7202
|
+
if (hasDeprecatedRawInput) {
|
|
7203
|
+
logWarnings({
|
|
7204
|
+
warnings: [rawInputDeprecationWarning]
|
|
7205
|
+
});
|
|
7206
|
+
}
|
|
7207
|
+
}
|
|
7208
|
+
|
|
6973
7209
|
// src/ui/process-ui-message-stream.ts
|
|
6974
7210
|
function createStreamingUIMessageState({
|
|
6975
7211
|
lastMessage,
|
|
@@ -7423,6 +7659,7 @@ function processUIMessageStream({
|
|
|
7423
7659
|
providerMetadata: chunk.providerMetadata,
|
|
7424
7660
|
toolMetadata: chunk.toolMetadata
|
|
7425
7661
|
});
|
|
7662
|
+
warnIfUIMessageHasDeprecatedRawInput([state.message]);
|
|
7426
7663
|
}
|
|
7427
7664
|
write();
|
|
7428
7665
|
break;
|
|
@@ -7781,11 +8018,11 @@ function toUIMessageChunk(part, {
|
|
|
7781
8018
|
responseMessageId
|
|
7782
8019
|
} = {}) {
|
|
7783
8020
|
const isDynamic = (toolPart) => {
|
|
7784
|
-
const
|
|
7785
|
-
if (
|
|
8021
|
+
const tool3 = tools == null ? void 0 : tools[toolPart.toolName];
|
|
8022
|
+
if (tool3 == null) {
|
|
7786
8023
|
return toolPart.dynamic;
|
|
7787
8024
|
}
|
|
7788
|
-
return (
|
|
8025
|
+
return (tool3 == null ? void 0 : tool3.type) === "dynamic" ? true : void 0;
|
|
7789
8026
|
};
|
|
7790
8027
|
const partType = part.type;
|
|
7791
8028
|
switch (partType) {
|
|
@@ -8421,8 +8658,8 @@ function executeToolsFromStream({
|
|
|
8421
8658
|
if (chunk.invalid) {
|
|
8422
8659
|
return;
|
|
8423
8660
|
}
|
|
8424
|
-
const
|
|
8425
|
-
if (
|
|
8661
|
+
const tool3 = getOwn(tools, chunk.toolName);
|
|
8662
|
+
if (tool3 == null) {
|
|
8426
8663
|
return;
|
|
8427
8664
|
}
|
|
8428
8665
|
const toolApprovalStatus = await resolveToolApproval({
|
|
@@ -8434,7 +8671,7 @@ function executeToolsFromStream({
|
|
|
8434
8671
|
runtimeContext
|
|
8435
8672
|
});
|
|
8436
8673
|
if (toolApprovalStatus.type === "not-applicable") {
|
|
8437
|
-
if (
|
|
8674
|
+
if (tool3.execute != null && chunk.providerExecuted !== true) {
|
|
8438
8675
|
toolCallsToExecute.push(chunk);
|
|
8439
8676
|
}
|
|
8440
8677
|
return;
|
|
@@ -8500,7 +8737,7 @@ function executeToolsFromStream({
|
|
|
8500
8737
|
break;
|
|
8501
8738
|
}
|
|
8502
8739
|
}
|
|
8503
|
-
if (
|
|
8740
|
+
if (tool3.execute != null && chunk.providerExecuted !== true) {
|
|
8504
8741
|
toolCallsToExecute.push(chunk);
|
|
8505
8742
|
}
|
|
8506
8743
|
return;
|
|
@@ -8573,9 +8810,9 @@ function invokeToolCallbacksFromStream({
|
|
|
8573
8810
|
switch (chunk.type) {
|
|
8574
8811
|
case "tool-input-start": {
|
|
8575
8812
|
ongoingToolCallToolNames[chunk.id] = chunk.toolName;
|
|
8576
|
-
const
|
|
8577
|
-
if ((
|
|
8578
|
-
await
|
|
8813
|
+
const tool3 = getOwn(tools, chunk.toolName);
|
|
8814
|
+
if ((tool3 == null ? void 0 : tool3.onInputStart) != null) {
|
|
8815
|
+
await tool3.onInputStart({
|
|
8579
8816
|
toolCallId: chunk.id,
|
|
8580
8817
|
messages: stepInputMessages,
|
|
8581
8818
|
abortSignal,
|
|
@@ -8586,9 +8823,9 @@ function invokeToolCallbacksFromStream({
|
|
|
8586
8823
|
}
|
|
8587
8824
|
case "tool-input-delta": {
|
|
8588
8825
|
const toolName = ongoingToolCallToolNames[chunk.id];
|
|
8589
|
-
const
|
|
8590
|
-
if ((
|
|
8591
|
-
await
|
|
8826
|
+
const tool3 = getOwn(tools, toolName);
|
|
8827
|
+
if ((tool3 == null ? void 0 : tool3.onInputDelta) != null) {
|
|
8828
|
+
await tool3.onInputDelta({
|
|
8592
8829
|
inputTextDelta: chunk.delta,
|
|
8593
8830
|
toolCallId: chunk.id,
|
|
8594
8831
|
messages: stepInputMessages,
|
|
@@ -8600,10 +8837,10 @@ function invokeToolCallbacksFromStream({
|
|
|
8600
8837
|
}
|
|
8601
8838
|
case "tool-call": {
|
|
8602
8839
|
const toolName = ongoingToolCallToolNames[chunk.toolCallId];
|
|
8603
|
-
const
|
|
8840
|
+
const tool3 = getOwn(tools, toolName);
|
|
8604
8841
|
delete ongoingToolCallToolNames[chunk.toolCallId];
|
|
8605
|
-
if ((
|
|
8606
|
-
await
|
|
8842
|
+
if ((tool3 == null ? void 0 : tool3.onInputAvailable) != null) {
|
|
8843
|
+
await tool3.onInputAvailable({
|
|
8607
8844
|
input: chunk.input,
|
|
8608
8845
|
toolCallId: chunk.toolCallId,
|
|
8609
8846
|
messages: stepInputMessages,
|
|
@@ -9130,12 +9367,12 @@ function createLanguageModelV4StreamPartToLanguageModelStreamPartTransform({
|
|
|
9130
9367
|
break;
|
|
9131
9368
|
}
|
|
9132
9369
|
case "tool-input-start": {
|
|
9133
|
-
const
|
|
9370
|
+
const tool3 = getOwn(tools, chunk.toolName);
|
|
9134
9371
|
controller.enqueue({
|
|
9135
9372
|
...chunk,
|
|
9136
|
-
dynamic: (_a25 = chunk.dynamic) != null ? _a25 : (
|
|
9137
|
-
title:
|
|
9138
|
-
...(
|
|
9373
|
+
dynamic: (_a25 = chunk.dynamic) != null ? _a25 : (tool3 == null ? void 0 : tool3.type) === "dynamic",
|
|
9374
|
+
title: tool3 == null ? void 0 : tool3.title,
|
|
9375
|
+
...(tool3 == null ? void 0 : tool3.metadata) != null ? { toolMetadata: tool3.metadata } : {}
|
|
9139
9376
|
});
|
|
9140
9377
|
break;
|
|
9141
9378
|
}
|
|
@@ -9675,6 +9912,10 @@ var DefaultStreamTextResult = class {
|
|
|
9675
9912
|
tools,
|
|
9676
9913
|
toolCallers: experimental_toolCallers
|
|
9677
9914
|
});
|
|
9915
|
+
const prepareToolSearch = createToolSearchState({
|
|
9916
|
+
tools,
|
|
9917
|
+
toolCallers: resolvedToolCallers
|
|
9918
|
+
});
|
|
9678
9919
|
const telemetryDispatcher = createRestrictedTelemetryDispatcher({
|
|
9679
9920
|
telemetry,
|
|
9680
9921
|
includeRuntimeContext: telemetry == null ? void 0 : telemetry.includeRuntimeContext,
|
|
@@ -10380,9 +10621,13 @@ var DefaultStreamTextResult = class {
|
|
|
10380
10621
|
});
|
|
10381
10622
|
const {
|
|
10382
10623
|
executionTools: stepExecutionTools,
|
|
10383
|
-
modelTools: stepModelTools
|
|
10624
|
+
modelTools: stepModelTools,
|
|
10625
|
+
toolCallerMessages
|
|
10384
10626
|
} = prepareToolsForToolCallers({
|
|
10385
|
-
tools: stepActiveTools,
|
|
10627
|
+
tools: prepareToolSearch(stepActiveTools, {
|
|
10628
|
+
toolsContext,
|
|
10629
|
+
experimental_sandbox: stepSandbox
|
|
10630
|
+
}),
|
|
10386
10631
|
toolCallers: resolvedToolCallers
|
|
10387
10632
|
});
|
|
10388
10633
|
const stepToolOrder = (_g = prepareStepResult == null ? void 0 : prepareStepResult.toolOrder) != null ? _g : toolOrder;
|
|
@@ -10396,7 +10641,10 @@ var DefaultStreamTextResult = class {
|
|
|
10396
10641
|
const stepToolChoice = prepareToolChoice({
|
|
10397
10642
|
toolChoice: (_h = prepareStepResult == null ? void 0 : prepareStepResult.toolChoice) != null ? _h : toolChoice
|
|
10398
10643
|
});
|
|
10399
|
-
const stepMessages = (
|
|
10644
|
+
const stepMessages = appendToolCallerMessages({
|
|
10645
|
+
messages: (_i = prepareStepResult == null ? void 0 : prepareStepResult.messages) != null ? _i : stepInputMessages,
|
|
10646
|
+
toolCallerMessages
|
|
10647
|
+
});
|
|
10400
10648
|
currentStepMessages = stepMessages;
|
|
10401
10649
|
const stepInstructions = (_k = (_j = prepareStepResult == null ? void 0 : prepareStepResult.instructions) != null ? _j : prepareStepResult == null ? void 0 : prepareStepResult.system) != null ? _k : instructionsForNextStep;
|
|
10402
10650
|
instructionsForNextStep = stepInstructions;
|
|
@@ -10897,8 +11145,8 @@ var DefaultStreamTextResult = class {
|
|
|
10897
11145
|
);
|
|
10898
11146
|
for (const toolCall of stepToolCalls) {
|
|
10899
11147
|
if (toolCall.providerExecuted !== true) continue;
|
|
10900
|
-
const
|
|
10901
|
-
if ((
|
|
11148
|
+
const tool3 = getOwn(stepExecutionTools, toolCall.toolName);
|
|
11149
|
+
if ((tool3 == null ? void 0 : tool3.type) === "provider" && tool3.supportsDeferredResults) {
|
|
10902
11150
|
const hasResultInStep = stepToolOutputs.some(
|
|
10903
11151
|
(output2) => (output2.type === "tool-result" || output2.type === "tool-error") && output2.toolCallId === toolCall.toolCallId
|
|
10904
11152
|
);
|
|
@@ -11684,6 +11932,7 @@ import {
|
|
|
11684
11932
|
} from "@ai-sdk/provider-utils";
|
|
11685
11933
|
async function convertToModelMessages(messages, options) {
|
|
11686
11934
|
const modelMessages = [];
|
|
11935
|
+
warnIfUIMessageHasDeprecatedRawInput(messages);
|
|
11687
11936
|
if (options == null ? void 0 : options.ignoreIncompleteToolCalls) {
|
|
11688
11937
|
messages = messages.map((message) => ({
|
|
11689
11938
|
...message,
|
|
@@ -12357,6 +12606,7 @@ async function safeValidateUIMessagesInternal({
|
|
|
12357
12606
|
value: messages,
|
|
12358
12607
|
schema: uiMessagesSchema
|
|
12359
12608
|
});
|
|
12609
|
+
warnIfUIMessageHasDeprecatedRawInput(validatedMessages);
|
|
12360
12610
|
if (metadataSchema) {
|
|
12361
12611
|
for (const [msgIdx, message] of validatedMessages.entries()) {
|
|
12362
12612
|
await validateTypes4({
|
|
@@ -12404,9 +12654,9 @@ async function safeValidateUIMessagesInternal({
|
|
|
12404
12654
|
if (shouldValidateToolParts && part.type.startsWith("tool-")) {
|
|
12405
12655
|
const toolPart = part;
|
|
12406
12656
|
const toolName = toolPart.type.slice(5);
|
|
12407
|
-
const
|
|
12657
|
+
const tool3 = tools == null ? void 0 : getOwn(tools, toolName);
|
|
12408
12658
|
const isTerminal = toolPart.state === "output-available" || toolPart.state === "output-error" || toolPart.state === "output-denied";
|
|
12409
|
-
if (!
|
|
12659
|
+
if (!tool3 && isTerminal) {
|
|
12410
12660
|
if (tools != null || convertMissingTerminalToolsToDynamic) {
|
|
12411
12661
|
message.parts[partIdx] = asDynamicToolPart(
|
|
12412
12662
|
toolPart
|
|
@@ -12414,7 +12664,7 @@ async function safeValidateUIMessagesInternal({
|
|
|
12414
12664
|
}
|
|
12415
12665
|
continue;
|
|
12416
12666
|
}
|
|
12417
|
-
if (!
|
|
12667
|
+
if (!tool3) {
|
|
12418
12668
|
return {
|
|
12419
12669
|
success: false,
|
|
12420
12670
|
error: new TypeValidationError3({
|
|
@@ -12438,7 +12688,7 @@ async function safeValidateUIMessagesInternal({
|
|
|
12438
12688
|
if (toolPart.input !== void 0) {
|
|
12439
12689
|
const result = await safeValidateTypes5({
|
|
12440
12690
|
value: toolPart.input,
|
|
12441
|
-
schema:
|
|
12691
|
+
schema: tool3.inputSchema,
|
|
12442
12692
|
context: inputValidationContext
|
|
12443
12693
|
});
|
|
12444
12694
|
convertToDynamic = !result.success;
|
|
@@ -12446,7 +12696,7 @@ async function safeValidateUIMessagesInternal({
|
|
|
12446
12696
|
} else if (toolPart.state === "output-available") {
|
|
12447
12697
|
const result = await safeValidateTypes5({
|
|
12448
12698
|
value: toolPart.input,
|
|
12449
|
-
schema:
|
|
12699
|
+
schema: tool3.inputSchema,
|
|
12450
12700
|
context: inputValidationContext
|
|
12451
12701
|
});
|
|
12452
12702
|
if (!result.success) {
|
|
@@ -12459,14 +12709,14 @@ async function safeValidateUIMessagesInternal({
|
|
|
12459
12709
|
} else if (toolPart.state === "input-available" || toolPart.state === "approval-requested" || toolPart.state === "approval-responded" || toolPart.state === "output-denied") {
|
|
12460
12710
|
await validateTypes4({
|
|
12461
12711
|
value: toolPart.input,
|
|
12462
|
-
schema:
|
|
12712
|
+
schema: tool3.inputSchema,
|
|
12463
12713
|
context: inputValidationContext
|
|
12464
12714
|
});
|
|
12465
12715
|
}
|
|
12466
|
-
if (toolPart.state === "output-available" &&
|
|
12716
|
+
if (toolPart.state === "output-available" && tool3.outputSchema) {
|
|
12467
12717
|
await validateTypes4({
|
|
12468
12718
|
value: toolPart.output,
|
|
12469
|
-
schema:
|
|
12719
|
+
schema: tool3.outputSchema,
|
|
12470
12720
|
context: {
|
|
12471
12721
|
field: `messages[${msgIdx}].parts[${partIdx}].output`,
|
|
12472
12722
|
entityName: toolName,
|
|
@@ -13149,16 +13399,16 @@ function validateCompatibleTools({
|
|
|
13149
13399
|
tools,
|
|
13150
13400
|
toolsByName
|
|
13151
13401
|
}) {
|
|
13152
|
-
for (const
|
|
13153
|
-
const previousTool = toolsByName.get(
|
|
13154
|
-
if (previousTool != null && !isDeepEqualData(previousTool,
|
|
13402
|
+
for (const tool3 of tools != null ? tools : []) {
|
|
13403
|
+
const previousTool = toolsByName.get(tool3.name);
|
|
13404
|
+
if (previousTool != null && !isDeepEqualData(previousTool, tool3)) {
|
|
13155
13405
|
throw new InvalidArgumentError({
|
|
13156
13406
|
parameter: "requests",
|
|
13157
13407
|
value: requestId,
|
|
13158
|
-
message: `tool "${
|
|
13408
|
+
message: `tool "${tool3.name}" must have the same definition in every batch request`
|
|
13159
13409
|
});
|
|
13160
13410
|
}
|
|
13161
|
-
toolsByName.set(
|
|
13411
|
+
toolsByName.set(tool3.name, tool3);
|
|
13162
13412
|
}
|
|
13163
13413
|
}
|
|
13164
13414
|
async function getBatchStatus({
|
|
@@ -13989,10 +14239,312 @@ var DefaultEmbedManyResult = class {
|
|
|
13989
14239
|
}
|
|
13990
14240
|
};
|
|
13991
14241
|
|
|
14242
|
+
// src/evaluate/evaluate.ts
|
|
14243
|
+
import {
|
|
14244
|
+
Experimental_EvaluationUnsupportedQuestionTypeError as EvaluationUnsupportedQuestionTypeError
|
|
14245
|
+
} from "@ai-sdk/provider";
|
|
14246
|
+
import {
|
|
14247
|
+
withUserAgentSuffix as withUserAgentSuffix8
|
|
14248
|
+
} from "@ai-sdk/provider-utils";
|
|
14249
|
+
|
|
14250
|
+
// src/evaluate/validate-evaluation.ts
|
|
14251
|
+
import {
|
|
14252
|
+
InvalidResponseDataError as InvalidResponseDataError3
|
|
14253
|
+
} from "@ai-sdk/provider";
|
|
14254
|
+
var tolerance = 1e-6;
|
|
14255
|
+
function isRecord(value) {
|
|
14256
|
+
if (value == null || typeof value !== "object" || Array.isArray(value))
|
|
14257
|
+
return false;
|
|
14258
|
+
const prototype = Object.getPrototypeOf(value);
|
|
14259
|
+
return prototype === Object.prototype || prototype === null;
|
|
14260
|
+
}
|
|
14261
|
+
function isJSON(value, ancestors = /* @__PURE__ */ new Set()) {
|
|
14262
|
+
if (value === null || typeof value === "string" || typeof value === "boolean")
|
|
14263
|
+
return true;
|
|
14264
|
+
if (typeof value === "number") return Number.isFinite(value);
|
|
14265
|
+
if (typeof value !== "object" || !Array.isArray(value) && !isRecord(value))
|
|
14266
|
+
return false;
|
|
14267
|
+
if (ancestors.has(value)) return false;
|
|
14268
|
+
ancestors.add(value);
|
|
14269
|
+
const valid = Object.getOwnPropertySymbols(value).length === 0 && (Array.isArray(value) ? Array.from(value).every((item) => isJSON(item, ancestors)) : Object.values(value).every((item) => isJSON(item, ancestors)));
|
|
14270
|
+
ancestors.delete(value);
|
|
14271
|
+
return valid;
|
|
14272
|
+
}
|
|
14273
|
+
function isInput(value) {
|
|
14274
|
+
return (typeof value === "string" || Array.isArray(value) || isRecord(value)) && isJSON(value);
|
|
14275
|
+
}
|
|
14276
|
+
function invalidInput(parameter, value, message) {
|
|
14277
|
+
throw new InvalidArgumentError({ parameter, value, message });
|
|
14278
|
+
}
|
|
14279
|
+
function validateEvaluationInput({
|
|
14280
|
+
state,
|
|
14281
|
+
questions
|
|
14282
|
+
}) {
|
|
14283
|
+
if (!isInput(state)) {
|
|
14284
|
+
invalidInput(
|
|
14285
|
+
"state",
|
|
14286
|
+
state,
|
|
14287
|
+
"must be a JSON-compatible string, object, or array"
|
|
14288
|
+
);
|
|
14289
|
+
}
|
|
14290
|
+
if (!isRecord(questions) || Object.keys(questions).length === 0) {
|
|
14291
|
+
invalidInput("questions", questions, "must be a nonempty question map");
|
|
14292
|
+
}
|
|
14293
|
+
for (const [id, question] of Object.entries(questions)) {
|
|
14294
|
+
const parameter = `questions.${id}`;
|
|
14295
|
+
if (!isRecord(question) || !isInput(question.instructions)) {
|
|
14296
|
+
invalidInput(
|
|
14297
|
+
parameter,
|
|
14298
|
+
question,
|
|
14299
|
+
"instructions must be a JSON-compatible string, object, or array"
|
|
14300
|
+
);
|
|
14301
|
+
}
|
|
14302
|
+
const criteria = question.criteria;
|
|
14303
|
+
switch (question.type) {
|
|
14304
|
+
case "choice":
|
|
14305
|
+
if (!isRecord(criteria) || Object.keys(criteria).length === 0) {
|
|
14306
|
+
invalidInput(
|
|
14307
|
+
parameter,
|
|
14308
|
+
question,
|
|
14309
|
+
"choice criteria must be a nonempty option map"
|
|
14310
|
+
);
|
|
14311
|
+
}
|
|
14312
|
+
break;
|
|
14313
|
+
case "score":
|
|
14314
|
+
if (!Array.isArray(criteria) || criteria.length < 2) {
|
|
14315
|
+
invalidInput(
|
|
14316
|
+
parameter,
|
|
14317
|
+
question,
|
|
14318
|
+
"score criteria must contain at least two ordered levels"
|
|
14319
|
+
);
|
|
14320
|
+
}
|
|
14321
|
+
break;
|
|
14322
|
+
case "boolean":
|
|
14323
|
+
if (criteria === void 0) continue;
|
|
14324
|
+
if (!isRecord(criteria) || Object.keys(criteria).some((key) => key !== "true" && key !== "false")) {
|
|
14325
|
+
invalidInput(
|
|
14326
|
+
parameter,
|
|
14327
|
+
question,
|
|
14328
|
+
"boolean criteria may only describe true and false"
|
|
14329
|
+
);
|
|
14330
|
+
}
|
|
14331
|
+
break;
|
|
14332
|
+
default:
|
|
14333
|
+
invalidInput(
|
|
14334
|
+
parameter,
|
|
14335
|
+
question,
|
|
14336
|
+
"question type must be choice, score, or boolean"
|
|
14337
|
+
);
|
|
14338
|
+
}
|
|
14339
|
+
if (!isJSON(criteria) || Object.values(criteria).some((value) => value !== null && !isInput(value))) {
|
|
14340
|
+
invalidInput(
|
|
14341
|
+
parameter,
|
|
14342
|
+
question,
|
|
14343
|
+
"criteria descriptions must be JSON-compatible strings, objects, arrays, or null"
|
|
14344
|
+
);
|
|
14345
|
+
}
|
|
14346
|
+
}
|
|
14347
|
+
}
|
|
14348
|
+
function invalidAnswer(answers, message) {
|
|
14349
|
+
throw new InvalidResponseDataError3({ data: answers, message });
|
|
14350
|
+
}
|
|
14351
|
+
function isProbability(value) {
|
|
14352
|
+
return typeof value === "number" && Number.isFinite(value) && value >= 0 && value <= 1;
|
|
14353
|
+
}
|
|
14354
|
+
function hasExactKeys(value, keys) {
|
|
14355
|
+
return Object.keys(value).length === keys.length && keys.every((key) => Object.hasOwn(value, key));
|
|
14356
|
+
}
|
|
14357
|
+
function validateDistribution(value, keys, answers, id, roundingError) {
|
|
14358
|
+
if (!isRecord(value) || !hasExactKeys(value, keys) || !Object.values(value).every(isProbability)) {
|
|
14359
|
+
invalidAnswer(
|
|
14360
|
+
answers,
|
|
14361
|
+
`Question "${id}" must have a complete distribution of finite probabilities in [0, 1].`
|
|
14362
|
+
);
|
|
14363
|
+
}
|
|
14364
|
+
const sum = Object.values(value).reduce(
|
|
14365
|
+
(total, probability) => total + probability,
|
|
14366
|
+
0
|
|
14367
|
+
);
|
|
14368
|
+
if (Math.abs(sum - 1) > tolerance + keys.length * roundingError) {
|
|
14369
|
+
invalidAnswer(
|
|
14370
|
+
answers,
|
|
14371
|
+
`Question "${id}" probabilities must sum to 1 within the declared rounding precision.`
|
|
14372
|
+
);
|
|
14373
|
+
}
|
|
14374
|
+
}
|
|
14375
|
+
function validateEvaluationAnswers({
|
|
14376
|
+
questions,
|
|
14377
|
+
answers,
|
|
14378
|
+
rounding
|
|
14379
|
+
}) {
|
|
14380
|
+
function roundingError(decimals) {
|
|
14381
|
+
if (decimals === void 0) return 0;
|
|
14382
|
+
if (!Number.isInteger(decimals) || decimals < 0 || decimals > 15) {
|
|
14383
|
+
invalidAnswer(
|
|
14384
|
+
answers,
|
|
14385
|
+
"Evaluation rounding decimals must be integers between 0 and 15."
|
|
14386
|
+
);
|
|
14387
|
+
}
|
|
14388
|
+
return 0.5 * 10 ** -decimals;
|
|
14389
|
+
}
|
|
14390
|
+
const probabilityError = roundingError(rounding == null ? void 0 : rounding.probabilityDecimals);
|
|
14391
|
+
const scoreError = roundingError(rounding == null ? void 0 : rounding.scoreDecimals);
|
|
14392
|
+
if (!isRecord(answers) || !hasExactKeys(answers, Object.keys(questions))) {
|
|
14393
|
+
invalidAnswer(
|
|
14394
|
+
answers,
|
|
14395
|
+
"Evaluation must return exactly one answer for every question."
|
|
14396
|
+
);
|
|
14397
|
+
}
|
|
14398
|
+
for (const [id, question] of Object.entries(questions)) {
|
|
14399
|
+
const answer = answers[id];
|
|
14400
|
+
if (!isRecord(answer) || answer.type !== question.type) {
|
|
14401
|
+
invalidAnswer(
|
|
14402
|
+
answers,
|
|
14403
|
+
`Question "${id}" returned an answer with the wrong type.`
|
|
14404
|
+
);
|
|
14405
|
+
}
|
|
14406
|
+
switch (question.type) {
|
|
14407
|
+
case "choice": {
|
|
14408
|
+
if (typeof answer.choice !== "string" || !Object.hasOwn(question.criteria, answer.choice)) {
|
|
14409
|
+
invalidAnswer(
|
|
14410
|
+
answers,
|
|
14411
|
+
`Question "${id}" selected an unknown option.`
|
|
14412
|
+
);
|
|
14413
|
+
}
|
|
14414
|
+
if (answer.probabilities !== void 0) {
|
|
14415
|
+
validateDistribution(
|
|
14416
|
+
answer.probabilities,
|
|
14417
|
+
Object.keys(question.criteria),
|
|
14418
|
+
answers,
|
|
14419
|
+
id,
|
|
14420
|
+
probabilityError
|
|
14421
|
+
);
|
|
14422
|
+
const selected = answer.probabilities[answer.choice];
|
|
14423
|
+
if (Object.values(answer.probabilities).some(
|
|
14424
|
+
(probability) => probability > selected + tolerance
|
|
14425
|
+
)) {
|
|
14426
|
+
invalidAnswer(
|
|
14427
|
+
answers,
|
|
14428
|
+
`Question "${id}" did not select a highest-probability option.`
|
|
14429
|
+
);
|
|
14430
|
+
}
|
|
14431
|
+
}
|
|
14432
|
+
break;
|
|
14433
|
+
}
|
|
14434
|
+
case "score": {
|
|
14435
|
+
if (typeof answer.score !== "number" || !Number.isFinite(answer.score) || answer.score < 0 || answer.score > question.criteria.length - 1) {
|
|
14436
|
+
invalidAnswer(
|
|
14437
|
+
answers,
|
|
14438
|
+
`Question "${id}" score must be in [0, ${question.criteria.length - 1}].`
|
|
14439
|
+
);
|
|
14440
|
+
}
|
|
14441
|
+
if (answer.probabilities !== void 0) {
|
|
14442
|
+
const keys = question.criteria.map((_, index) => String(index));
|
|
14443
|
+
validateDistribution(
|
|
14444
|
+
answer.probabilities,
|
|
14445
|
+
keys,
|
|
14446
|
+
answers,
|
|
14447
|
+
id,
|
|
14448
|
+
probabilityError
|
|
14449
|
+
);
|
|
14450
|
+
const mean = Object.entries(answer.probabilities).reduce(
|
|
14451
|
+
(total, [index, probability]) => total + Number(index) * probability,
|
|
14452
|
+
0
|
|
14453
|
+
);
|
|
14454
|
+
const meanRoundingError = keys.reduce(
|
|
14455
|
+
(total, index) => total + Number(index) * probabilityError,
|
|
14456
|
+
0
|
|
14457
|
+
);
|
|
14458
|
+
if (Math.abs(mean - answer.score) > tolerance + meanRoundingError + scoreError) {
|
|
14459
|
+
invalidAnswer(
|
|
14460
|
+
answers,
|
|
14461
|
+
`Question "${id}" score must equal the probability-weighted mean within the declared rounding precision.`
|
|
14462
|
+
);
|
|
14463
|
+
}
|
|
14464
|
+
}
|
|
14465
|
+
break;
|
|
14466
|
+
}
|
|
14467
|
+
case "boolean":
|
|
14468
|
+
if (!isProbability(answer.probability)) {
|
|
14469
|
+
invalidAnswer(
|
|
14470
|
+
answers,
|
|
14471
|
+
`Question "${id}" must return P(true) as a finite probability in [0, 1].`
|
|
14472
|
+
);
|
|
14473
|
+
}
|
|
14474
|
+
break;
|
|
14475
|
+
}
|
|
14476
|
+
}
|
|
14477
|
+
}
|
|
14478
|
+
|
|
14479
|
+
// src/evaluate/evaluate.ts
|
|
14480
|
+
async function evaluate({
|
|
14481
|
+
model: modelArg,
|
|
14482
|
+
state,
|
|
14483
|
+
questions,
|
|
14484
|
+
maxRetries,
|
|
14485
|
+
abortSignal,
|
|
14486
|
+
headers,
|
|
14487
|
+
providerOptions = {}
|
|
14488
|
+
}) {
|
|
14489
|
+
var _a25, _b25, _c, _d, _e, _f;
|
|
14490
|
+
const model = resolveEvaluationModel(modelArg);
|
|
14491
|
+
validateEvaluationInput({ state, questions });
|
|
14492
|
+
for (const [questionId, question] of Object.entries(questions)) {
|
|
14493
|
+
if (!model.supportedQuestionTypes.includes(question.type)) {
|
|
14494
|
+
throw new EvaluationUnsupportedQuestionTypeError({
|
|
14495
|
+
questionId,
|
|
14496
|
+
questionType: question.type,
|
|
14497
|
+
provider: model.provider,
|
|
14498
|
+
modelId: model.modelId
|
|
14499
|
+
});
|
|
14500
|
+
}
|
|
14501
|
+
}
|
|
14502
|
+
const { retry } = prepareRetries({ maxRetries, abortSignal });
|
|
14503
|
+
const result = await retry(() => {
|
|
14504
|
+
abortSignal == null ? void 0 : abortSignal.throwIfAborted();
|
|
14505
|
+
return model.doEvaluate({
|
|
14506
|
+
state,
|
|
14507
|
+
questions,
|
|
14508
|
+
abortSignal,
|
|
14509
|
+
headers: withUserAgentSuffix8(headers != null ? headers : {}, `ai/${VERSION}`),
|
|
14510
|
+
providerOptions
|
|
14511
|
+
});
|
|
14512
|
+
});
|
|
14513
|
+
abortSignal == null ? void 0 : abortSignal.throwIfAborted();
|
|
14514
|
+
validateEvaluationAnswers({
|
|
14515
|
+
questions,
|
|
14516
|
+
answers: result.answers,
|
|
14517
|
+
rounding: result.rounding
|
|
14518
|
+
});
|
|
14519
|
+
logWarnings({
|
|
14520
|
+
warnings: result.warnings,
|
|
14521
|
+
provider: model.provider,
|
|
14522
|
+
model: model.modelId
|
|
14523
|
+
});
|
|
14524
|
+
const inputTokens = (_a25 = result.usage) == null ? void 0 : _a25.inputTokens;
|
|
14525
|
+
const outputTokens = (_b25 = result.usage) == null ? void 0 : _b25.outputTokens;
|
|
14526
|
+
return {
|
|
14527
|
+
answers: result.answers,
|
|
14528
|
+
usage: {
|
|
14529
|
+
inputTokens,
|
|
14530
|
+
outputTokens,
|
|
14531
|
+
totalTokens: inputTokens != null && outputTokens != null ? inputTokens + outputTokens : void 0
|
|
14532
|
+
},
|
|
14533
|
+
warnings: result.warnings,
|
|
14534
|
+
rounding: result.rounding,
|
|
14535
|
+
providerMetadata: result.providerMetadata,
|
|
14536
|
+
response: {
|
|
14537
|
+
...result.response,
|
|
14538
|
+
timestamp: (_d = (_c = result.response) == null ? void 0 : _c.timestamp) != null ? _d : /* @__PURE__ */ new Date(),
|
|
14539
|
+
modelId: (_f = (_e = result.response) == null ? void 0 : _e.modelId) != null ? _f : model.modelId
|
|
14540
|
+
}
|
|
14541
|
+
};
|
|
14542
|
+
}
|
|
14543
|
+
|
|
13992
14544
|
// src/generate-object/generate-object.ts
|
|
13993
14545
|
import {
|
|
13994
14546
|
createIdGenerator as createIdGenerator6,
|
|
13995
|
-
withUserAgentSuffix as
|
|
14547
|
+
withUserAgentSuffix as withUserAgentSuffix9
|
|
13996
14548
|
} from "@ai-sdk/provider-utils";
|
|
13997
14549
|
|
|
13998
14550
|
// src/generate-text/extract-reasoning-content.ts
|
|
@@ -14524,7 +15076,7 @@ async function generateObject(options) {
|
|
|
14524
15076
|
enumValues
|
|
14525
15077
|
});
|
|
14526
15078
|
const callSettings = prepareLanguageModelCallOptions(settings);
|
|
14527
|
-
const headersWithUserAgent =
|
|
15079
|
+
const headersWithUserAgent = withUserAgentSuffix9(
|
|
14528
15080
|
headers != null ? headers : {},
|
|
14529
15081
|
`ai/${VERSION}`
|
|
14530
15082
|
);
|
|
@@ -14534,7 +15086,7 @@ async function generateObject(options) {
|
|
|
14534
15086
|
const resolvedOnStart = onStart != null ? onStart : experimental_onStart;
|
|
14535
15087
|
const resolvedOnStepStart = onStepStart != null ? onStepStart : experimental_onStepStart;
|
|
14536
15088
|
const resolvedOnStepEnd = onStepEnd != null ? onStepEnd : onStepFinish;
|
|
14537
|
-
const
|
|
15089
|
+
const jsonSchema3 = await outputStrategy.jsonSchema();
|
|
14538
15090
|
const callId = generateId5();
|
|
14539
15091
|
await notify({
|
|
14540
15092
|
event: {
|
|
@@ -14556,7 +15108,7 @@ async function generateObject(options) {
|
|
|
14556
15108
|
headers: headersWithUserAgent,
|
|
14557
15109
|
providerOptions,
|
|
14558
15110
|
output: outputStrategy.type,
|
|
14559
|
-
schema:
|
|
15111
|
+
schema: jsonSchema3,
|
|
14560
15112
|
schemaName,
|
|
14561
15113
|
schemaDescription
|
|
14562
15114
|
},
|
|
@@ -14592,7 +15144,7 @@ async function generateObject(options) {
|
|
|
14592
15144
|
() => model.doGenerate({
|
|
14593
15145
|
responseFormat: {
|
|
14594
15146
|
type: "json",
|
|
14595
|
-
schema:
|
|
15147
|
+
schema: jsonSchema3,
|
|
14596
15148
|
name: schemaName,
|
|
14597
15149
|
description: schemaDescription
|
|
14598
15150
|
},
|
|
@@ -14976,7 +15528,7 @@ var DefaultStreamObjectResult = class {
|
|
|
14976
15528
|
this.baseStream = stitchableStream.stream.pipeThrough(eventProcessor);
|
|
14977
15529
|
const callId = generateId5();
|
|
14978
15530
|
(async () => {
|
|
14979
|
-
const
|
|
15531
|
+
const jsonSchema3 = await outputStrategy.jsonSchema();
|
|
14980
15532
|
await notify({
|
|
14981
15533
|
event: {
|
|
14982
15534
|
callId,
|
|
@@ -14997,7 +15549,7 @@ var DefaultStreamObjectResult = class {
|
|
|
14997
15549
|
headers,
|
|
14998
15550
|
providerOptions,
|
|
14999
15551
|
output: outputStrategy.type,
|
|
15000
|
-
schema:
|
|
15552
|
+
schema: jsonSchema3,
|
|
15001
15553
|
schemaName,
|
|
15002
15554
|
schemaDescription
|
|
15003
15555
|
},
|
|
@@ -15013,7 +15565,7 @@ var DefaultStreamObjectResult = class {
|
|
|
15013
15565
|
const callOptions = {
|
|
15014
15566
|
responseFormat: {
|
|
15015
15567
|
type: "json",
|
|
15016
|
-
schema:
|
|
15568
|
+
schema: jsonSchema3,
|
|
15017
15569
|
name: schemaName,
|
|
15018
15570
|
description: schemaDescription
|
|
15019
15571
|
},
|
|
@@ -15388,7 +15940,7 @@ var DefaultStreamObjectResult = class {
|
|
|
15388
15940
|
// src/generate-speech/generate-speech.ts
|
|
15389
15941
|
import {
|
|
15390
15942
|
detectMediaType as detectMediaType4,
|
|
15391
|
-
withUserAgentSuffix as
|
|
15943
|
+
withUserAgentSuffix as withUserAgentSuffix10
|
|
15392
15944
|
} from "@ai-sdk/provider-utils";
|
|
15393
15945
|
|
|
15394
15946
|
// src/generate-speech/generated-audio-file.ts
|
|
@@ -15435,7 +15987,7 @@ async function generateSpeech({
|
|
|
15435
15987
|
if (!resolvedModel) {
|
|
15436
15988
|
throw new Error("Model could not be resolved");
|
|
15437
15989
|
}
|
|
15438
|
-
const headersWithUserAgent =
|
|
15990
|
+
const headersWithUserAgent = withUserAgentSuffix10(
|
|
15439
15991
|
headers != null ? headers : {},
|
|
15440
15992
|
`ai/${VERSION}`
|
|
15441
15993
|
);
|
|
@@ -15710,11 +16262,11 @@ function tagDescription(description) {
|
|
|
15710
16262
|
async function fingerprintTools(tools) {
|
|
15711
16263
|
const entries = await Promise.all(
|
|
15712
16264
|
Object.keys(tools).map(async (name25) => {
|
|
15713
|
-
const
|
|
16265
|
+
const tool3 = tools[name25];
|
|
15714
16266
|
const digest = await hashCanonical({
|
|
15715
|
-
description: tagDescription(
|
|
15716
|
-
inputSchema: await asSchema6(
|
|
15717
|
-
title:
|
|
16267
|
+
description: tagDescription(tool3.description),
|
|
16268
|
+
inputSchema: await asSchema6(tool3.inputSchema).jsonSchema,
|
|
16269
|
+
title: tool3.title
|
|
15718
16270
|
});
|
|
15719
16271
|
return [name25, digest];
|
|
15720
16272
|
})
|
|
@@ -15745,7 +16297,7 @@ import {
|
|
|
15745
16297
|
convertBase64ToUint8Array as convertBase64ToUint8Array5,
|
|
15746
16298
|
delay as defaultDelay,
|
|
15747
16299
|
generateId,
|
|
15748
|
-
withUserAgentSuffix as
|
|
16300
|
+
withUserAgentSuffix as withUserAgentSuffix11,
|
|
15749
16301
|
detectMediaType as detectMediaType5
|
|
15750
16302
|
} from "@ai-sdk/provider-utils";
|
|
15751
16303
|
var defaultDownload = createDownload();
|
|
@@ -15772,7 +16324,7 @@ async function experimental_generateVideo({
|
|
|
15772
16324
|
}) {
|
|
15773
16325
|
var _a25;
|
|
15774
16326
|
const model = resolveVideoModel(modelArg);
|
|
15775
|
-
const headersWithUserAgent =
|
|
16327
|
+
const headersWithUserAgent = withUserAgentSuffix11(
|
|
15776
16328
|
headers != null ? headers : {},
|
|
15777
16329
|
`ai/${VERSION}`
|
|
15778
16330
|
);
|
|
@@ -16179,7 +16731,7 @@ async function invokeModelMaxVideosPerCall(model) {
|
|
|
16179
16731
|
// src/generate-video/start-video.ts
|
|
16180
16732
|
import {
|
|
16181
16733
|
generateId as generateId2,
|
|
16182
|
-
withUserAgentSuffix as
|
|
16734
|
+
withUserAgentSuffix as withUserAgentSuffix12
|
|
16183
16735
|
} from "@ai-sdk/provider-utils";
|
|
16184
16736
|
async function experimental_startVideo({
|
|
16185
16737
|
model: modelArg,
|
|
@@ -16245,7 +16797,7 @@ async function experimental_startVideo({
|
|
|
16245
16797
|
generateAudio,
|
|
16246
16798
|
providerOptions: providerOptions != null ? providerOptions : {},
|
|
16247
16799
|
headers: {
|
|
16248
|
-
...
|
|
16800
|
+
...withUserAgentSuffix12(headers != null ? headers : {}, `ai/${VERSION}`),
|
|
16249
16801
|
...callerIdempotencyKey ? {} : { "idempotency-key": `aisdk_vid_${generateId2()}` }
|
|
16250
16802
|
},
|
|
16251
16803
|
abortSignal,
|
|
@@ -16261,7 +16813,7 @@ async function experimental_startVideo({
|
|
|
16261
16813
|
}
|
|
16262
16814
|
|
|
16263
16815
|
// src/generate-video/get-video-status.ts
|
|
16264
|
-
import { withUserAgentSuffix as
|
|
16816
|
+
import { withUserAgentSuffix as withUserAgentSuffix13 } from "@ai-sdk/provider-utils";
|
|
16265
16817
|
async function experimental_getVideoStatus(modelArg, {
|
|
16266
16818
|
operation,
|
|
16267
16819
|
headers,
|
|
@@ -16281,7 +16833,7 @@ async function experimental_getVideoStatus(modelArg, {
|
|
|
16281
16833
|
return retry(
|
|
16282
16834
|
() => model.doStatus({
|
|
16283
16835
|
operation,
|
|
16284
|
-
headers:
|
|
16836
|
+
headers: withUserAgentSuffix13(headers != null ? headers : {}, `ai/${VERSION}`),
|
|
16285
16837
|
abortSignal
|
|
16286
16838
|
})
|
|
16287
16839
|
);
|
|
@@ -16724,21 +17276,21 @@ function addToolInputExamplesMiddleware({
|
|
|
16724
17276
|
if (!((_a25 = params.tools) == null ? void 0 : _a25.length)) {
|
|
16725
17277
|
return params;
|
|
16726
17278
|
}
|
|
16727
|
-
const transformedTools = params.tools.map((
|
|
17279
|
+
const transformedTools = params.tools.map((tool3) => {
|
|
16728
17280
|
var _a26;
|
|
16729
|
-
if (
|
|
16730
|
-
return
|
|
17281
|
+
if (tool3.type !== "function" || !((_a26 = tool3.inputExamples) == null ? void 0 : _a26.length)) {
|
|
17282
|
+
return tool3;
|
|
16731
17283
|
}
|
|
16732
|
-
const formattedExamples =
|
|
17284
|
+
const formattedExamples = tool3.inputExamples.map((example, index) => format(example, index)).join("\n");
|
|
16733
17285
|
const examplesSection = `${prefix}
|
|
16734
17286
|
${formattedExamples}`;
|
|
16735
|
-
const toolDescription =
|
|
17287
|
+
const toolDescription = tool3.description ? `${tool3.description}
|
|
16736
17288
|
|
|
16737
17289
|
${examplesSection}` : examplesSection;
|
|
16738
17290
|
return {
|
|
16739
|
-
...
|
|
17291
|
+
...tool3,
|
|
16740
17292
|
description: toolDescription,
|
|
16741
|
-
inputExamples: remove ? void 0 :
|
|
17293
|
+
inputExamples: remove ? void 0 : tool3.inputExamples
|
|
16742
17294
|
};
|
|
16743
17295
|
});
|
|
16744
17296
|
return {
|
|
@@ -16997,14 +17549,14 @@ async function getRealtimeToolDefinitions({
|
|
|
16997
17549
|
toolsContext = {}
|
|
16998
17550
|
}) {
|
|
16999
17551
|
const definitions = [];
|
|
17000
|
-
for (const [name25,
|
|
17001
|
-
const toolType =
|
|
17552
|
+
for (const [name25, tool3] of Object.entries(tools)) {
|
|
17553
|
+
const toolType = tool3.type;
|
|
17002
17554
|
switch (toolType) {
|
|
17003
17555
|
case void 0:
|
|
17004
17556
|
case "function":
|
|
17005
17557
|
case "dynamic": {
|
|
17006
17558
|
const description = resolveRealtimeToolDescription({
|
|
17007
|
-
tool:
|
|
17559
|
+
tool: tool3,
|
|
17008
17560
|
toolName: name25,
|
|
17009
17561
|
toolsContext
|
|
17010
17562
|
});
|
|
@@ -17012,7 +17564,7 @@ async function getRealtimeToolDefinitions({
|
|
|
17012
17564
|
type: "function",
|
|
17013
17565
|
name: name25,
|
|
17014
17566
|
description,
|
|
17015
|
-
parameters: await asSchema7(
|
|
17567
|
+
parameters: await asSchema7(tool3.inputSchema).jsonSchema
|
|
17016
17568
|
});
|
|
17017
17569
|
break;
|
|
17018
17570
|
}
|
|
@@ -17027,11 +17579,11 @@ async function getRealtimeToolDefinitions({
|
|
|
17027
17579
|
return definitions;
|
|
17028
17580
|
}
|
|
17029
17581
|
function resolveRealtimeToolDescription({
|
|
17030
|
-
tool:
|
|
17582
|
+
tool: tool3,
|
|
17031
17583
|
toolName,
|
|
17032
17584
|
toolsContext
|
|
17033
17585
|
}) {
|
|
17034
|
-
return
|
|
17586
|
+
return tool3.description === void 0 ? void 0 : typeof tool3.description === "string" ? tool3.description : tool3.description({
|
|
17035
17587
|
context: toolsContext[toolName]
|
|
17036
17588
|
});
|
|
17037
17589
|
}
|
|
@@ -17277,6 +17829,9 @@ var RealtimeEventChannel = class {
|
|
|
17277
17829
|
var _a25, _b25, _c;
|
|
17278
17830
|
this.parse = (_c = (_b25 = (_a25 = options.model).createServerEventParser) == null ? void 0 : _b25.call(_a25)) != null ? _c : options.model.parseServerEvent.bind(options.model);
|
|
17279
17831
|
}
|
|
17832
|
+
get hasPendingIncoming() {
|
|
17833
|
+
return this.incomingCount > 0;
|
|
17834
|
+
}
|
|
17280
17835
|
dispose() {
|
|
17281
17836
|
this.active = false;
|
|
17282
17837
|
}
|
|
@@ -17521,9 +18076,18 @@ var BrowserRealtimeTransport = class {
|
|
|
17521
18076
|
if (this.ws === ws) {
|
|
17522
18077
|
this.ws = null;
|
|
17523
18078
|
const closeError = (_a26 = getCloseError(event)) != null ? _a26 : connectionError;
|
|
18079
|
+
const reportCloseErrorImmediately = closeError != null && !codec.hasPendingIncoming;
|
|
17524
18080
|
codec.stopWriting();
|
|
17525
18081
|
this.notifyClosing();
|
|
17526
18082
|
if (this.epoch !== epoch) return;
|
|
18083
|
+
const drain = codec.finish();
|
|
18084
|
+
if (reportCloseErrorImmediately) {
|
|
18085
|
+
try {
|
|
18086
|
+
this.onError(closeError);
|
|
18087
|
+
} catch (e) {
|
|
18088
|
+
}
|
|
18089
|
+
if (this.epoch !== epoch) return;
|
|
18090
|
+
}
|
|
17527
18091
|
const complete = () => {
|
|
17528
18092
|
if (this.epoch !== epoch) return;
|
|
17529
18093
|
clearTimeout(this.drainTimer);
|
|
@@ -17536,7 +18100,7 @@ var BrowserRealtimeTransport = class {
|
|
|
17536
18100
|
}
|
|
17537
18101
|
};
|
|
17538
18102
|
this.drainTimer = setTimeout(complete, 1e3);
|
|
17539
|
-
void this.awaitDrain(
|
|
18103
|
+
void this.awaitDrain(drain, complete);
|
|
17540
18104
|
}
|
|
17541
18105
|
};
|
|
17542
18106
|
}
|
|
@@ -18979,6 +19543,7 @@ var AbstractRealtimeSession = class {
|
|
|
18979
19543
|
if (current())
|
|
18980
19544
|
this.fail(new Error("Realtime session startup timed out"));
|
|
18981
19545
|
});
|
|
19546
|
+
const reportedTransportErrors = /* @__PURE__ */ new WeakSet();
|
|
18982
19547
|
const callbacks = {
|
|
18983
19548
|
model,
|
|
18984
19549
|
onEvent: async (event) => {
|
|
@@ -18995,7 +19560,10 @@ var AbstractRealtimeSession = class {
|
|
|
18995
19560
|
}
|
|
18996
19561
|
},
|
|
18997
19562
|
onError: (error) => {
|
|
18998
|
-
if (current())
|
|
19563
|
+
if (current()) {
|
|
19564
|
+
reportedTransportErrors.add(error);
|
|
19565
|
+
void this.reportError(error, attempt);
|
|
19566
|
+
}
|
|
18999
19567
|
},
|
|
19000
19568
|
onFatalError: (error, drain) => {
|
|
19001
19569
|
if (current()) this.fail(error, drain);
|
|
@@ -19017,7 +19585,8 @@ var AbstractRealtimeSession = class {
|
|
|
19017
19585
|
var _a26, _b26;
|
|
19018
19586
|
if (!current()) return;
|
|
19019
19587
|
const finalizationConfirmed = ((_a26 = model.capabilities) == null ? void 0 : _a26.finalization) === "session-close" && ((_b26 = this.state.session) == null ? void 0 : _b26.finalization) === "confirmed";
|
|
19020
|
-
if (error != null && !finalizationConfirmed)
|
|
19588
|
+
if (error != null && !finalizationConfirmed)
|
|
19589
|
+
this.fail(error, void 0, !reportedTransportErrors.has(error));
|
|
19021
19590
|
else if (!attempt.ready && !finalizationConfirmed)
|
|
19022
19591
|
this.fail(
|
|
19023
19592
|
new Error("Realtime connection closed before becoming ready")
|
|
@@ -19115,7 +19684,7 @@ var AbstractRealtimeSession = class {
|
|
|
19115
19684
|
if (current()) this.fail(error);
|
|
19116
19685
|
}
|
|
19117
19686
|
}
|
|
19118
|
-
fail(error, drain) {
|
|
19687
|
+
fail(error, drain, report = true) {
|
|
19119
19688
|
const attempt = this.attempt;
|
|
19120
19689
|
if (attempt == null || !attempt.active || attempt.cause != null) return;
|
|
19121
19690
|
attempt.cause = error instanceof Error ? error : new Error(String(error));
|
|
@@ -19126,7 +19695,7 @@ var AbstractRealtimeSession = class {
|
|
|
19126
19695
|
if (this.attempt !== attempt || !attempt.active) return;
|
|
19127
19696
|
if (drain == null) this.disconnect();
|
|
19128
19697
|
else void this.drainAttempt(attempt, drain);
|
|
19129
|
-
void this.reportError(attempt.cause, attempt);
|
|
19698
|
+
if (report) void this.reportError(attempt.cause, attempt);
|
|
19130
19699
|
}
|
|
19131
19700
|
async drainAttempt(attempt, drain) {
|
|
19132
19701
|
if (this.attempt === attempt && attempt.active)
|
|
@@ -19581,7 +20150,7 @@ var AbstractRealtimeSession = class {
|
|
|
19581
20150
|
|
|
19582
20151
|
// src/registry/custom-provider.ts
|
|
19583
20152
|
import {
|
|
19584
|
-
NoSuchModelError as
|
|
20153
|
+
NoSuchModelError as NoSuchModelError3
|
|
19585
20154
|
} from "@ai-sdk/provider";
|
|
19586
20155
|
function customProvider({
|
|
19587
20156
|
languageModels,
|
|
@@ -19591,6 +20160,7 @@ function customProvider({
|
|
|
19591
20160
|
speechModels,
|
|
19592
20161
|
rerankingModels,
|
|
19593
20162
|
videoModels,
|
|
20163
|
+
evaluationModels,
|
|
19594
20164
|
files,
|
|
19595
20165
|
skills,
|
|
19596
20166
|
fallbackProvider: fallbackProviderArg
|
|
@@ -19605,7 +20175,7 @@ function customProvider({
|
|
|
19605
20175
|
if (fallbackProvider) {
|
|
19606
20176
|
return fallbackProvider.languageModel(modelId);
|
|
19607
20177
|
}
|
|
19608
|
-
throw new
|
|
20178
|
+
throw new NoSuchModelError3({ modelId, modelType: "languageModel" });
|
|
19609
20179
|
},
|
|
19610
20180
|
embeddingModel(modelId) {
|
|
19611
20181
|
if (embeddingModels != null && modelId in embeddingModels) {
|
|
@@ -19614,7 +20184,7 @@ function customProvider({
|
|
|
19614
20184
|
if (fallbackProvider) {
|
|
19615
20185
|
return fallbackProvider.embeddingModel(modelId);
|
|
19616
20186
|
}
|
|
19617
|
-
throw new
|
|
20187
|
+
throw new NoSuchModelError3({ modelId, modelType: "embeddingModel" });
|
|
19618
20188
|
},
|
|
19619
20189
|
imageModel(modelId) {
|
|
19620
20190
|
if (imageModels != null && modelId in imageModels) {
|
|
@@ -19623,7 +20193,7 @@ function customProvider({
|
|
|
19623
20193
|
if (fallbackProvider == null ? void 0 : fallbackProvider.imageModel) {
|
|
19624
20194
|
return fallbackProvider.imageModel(modelId);
|
|
19625
20195
|
}
|
|
19626
|
-
throw new
|
|
20196
|
+
throw new NoSuchModelError3({ modelId, modelType: "imageModel" });
|
|
19627
20197
|
},
|
|
19628
20198
|
transcriptionModel(modelId) {
|
|
19629
20199
|
if (transcriptionModels != null && modelId in transcriptionModels) {
|
|
@@ -19635,7 +20205,7 @@ function customProvider({
|
|
|
19635
20205
|
if (fallbackProvider == null ? void 0 : fallbackProvider.transcriptionModel) {
|
|
19636
20206
|
return fallbackProvider.transcriptionModel(modelId);
|
|
19637
20207
|
}
|
|
19638
|
-
throw new
|
|
20208
|
+
throw new NoSuchModelError3({ modelId, modelType: "transcriptionModel" });
|
|
19639
20209
|
},
|
|
19640
20210
|
speechModel(modelId) {
|
|
19641
20211
|
if (speechModels != null && modelId in speechModels) {
|
|
@@ -19647,7 +20217,7 @@ function customProvider({
|
|
|
19647
20217
|
if (fallbackProvider == null ? void 0 : fallbackProvider.speechModel) {
|
|
19648
20218
|
return fallbackProvider.speechModel(modelId);
|
|
19649
20219
|
}
|
|
19650
|
-
throw new
|
|
20220
|
+
throw new NoSuchModelError3({ modelId, modelType: "speechModel" });
|
|
19651
20221
|
},
|
|
19652
20222
|
rerankingModel(modelId) {
|
|
19653
20223
|
if (rerankingModels != null && modelId in rerankingModels) {
|
|
@@ -19656,7 +20226,20 @@ function customProvider({
|
|
|
19656
20226
|
if (fallbackProvider == null ? void 0 : fallbackProvider.rerankingModel) {
|
|
19657
20227
|
return fallbackProvider.rerankingModel(modelId);
|
|
19658
20228
|
}
|
|
19659
|
-
throw new
|
|
20229
|
+
throw new NoSuchModelError3({ modelId, modelType: "rerankingModel" });
|
|
20230
|
+
},
|
|
20231
|
+
evaluationModel(modelId) {
|
|
20232
|
+
if (evaluationModels != null && Object.hasOwn(evaluationModels, modelId)) {
|
|
20233
|
+
return resolveEvaluationModel(evaluationModels[modelId]);
|
|
20234
|
+
}
|
|
20235
|
+
const provider = fallbackProviderArg;
|
|
20236
|
+
if (typeof (provider == null ? void 0 : provider.evaluationModel) === "function") {
|
|
20237
|
+
const model = provider.evaluationModel(modelId);
|
|
20238
|
+
if (model != null) {
|
|
20239
|
+
return resolveEvaluationModel(model);
|
|
20240
|
+
}
|
|
20241
|
+
}
|
|
20242
|
+
throw new NoSuchModelError3({ modelId, modelType: "evaluationModel" });
|
|
19660
20243
|
},
|
|
19661
20244
|
videoModel(modelId) {
|
|
19662
20245
|
if (videoModels != null && modelId in videoModels) {
|
|
@@ -19666,7 +20249,7 @@ function customProvider({
|
|
|
19666
20249
|
if (videoModel) {
|
|
19667
20250
|
return videoModel(modelId);
|
|
19668
20251
|
}
|
|
19669
|
-
throw new
|
|
20252
|
+
throw new NoSuchModelError3({ modelId, modelType: "videoModel" });
|
|
19670
20253
|
}
|
|
19671
20254
|
};
|
|
19672
20255
|
const filesAndSkills = {
|
|
@@ -19685,12 +20268,12 @@ function customProvider({
|
|
|
19685
20268
|
}
|
|
19686
20269
|
|
|
19687
20270
|
// src/registry/no-such-provider-error.ts
|
|
19688
|
-
import { AISDKError as AISDKError28, NoSuchModelError as
|
|
20271
|
+
import { AISDKError as AISDKError28, NoSuchModelError as NoSuchModelError4 } from "@ai-sdk/provider";
|
|
19689
20272
|
var name24 = "AI_NoSuchProviderError";
|
|
19690
20273
|
var marker24 = `vercel.ai.error.${name24}`;
|
|
19691
20274
|
var symbol24 = Symbol.for(marker24);
|
|
19692
20275
|
var _a24, _b24;
|
|
19693
|
-
var NoSuchProviderError = class extends (_b24 =
|
|
20276
|
+
var NoSuchProviderError = class extends (_b24 = NoSuchModelError4, _a24 = symbol24, _b24) {
|
|
19694
20277
|
constructor({
|
|
19695
20278
|
modelId,
|
|
19696
20279
|
modelType,
|
|
@@ -19710,7 +20293,7 @@ var NoSuchProviderError = class extends (_b24 = NoSuchModelError3, _a24 = symbol
|
|
|
19710
20293
|
|
|
19711
20294
|
// src/registry/provider-registry.ts
|
|
19712
20295
|
import {
|
|
19713
|
-
NoSuchModelError as
|
|
20296
|
+
NoSuchModelError as NoSuchModelError5
|
|
19714
20297
|
} from "@ai-sdk/provider";
|
|
19715
20298
|
function createProviderRegistry(providers, {
|
|
19716
20299
|
separator = ":",
|
|
@@ -19743,13 +20326,18 @@ var DefaultProviderRegistry = class {
|
|
|
19743
20326
|
id,
|
|
19744
20327
|
provider
|
|
19745
20328
|
}) {
|
|
19746
|
-
var _a25;
|
|
20329
|
+
var _a25, _b25;
|
|
19747
20330
|
const providerV4 = asProviderV4(provider);
|
|
19748
20331
|
const videoModel = (_a25 = provider.videoModel) == null ? void 0 : _a25.bind(provider);
|
|
19749
|
-
|
|
20332
|
+
const evaluationModel = (_b25 = provider.evaluationModel) == null ? void 0 : _b25.bind(provider);
|
|
20333
|
+
const registeredProvider = videoModel == null ? providerV4 : Object.assign(Object.create(Object.getPrototypeOf(providerV4)), {
|
|
19750
20334
|
...providerV4,
|
|
19751
20335
|
videoModel: (modelId) => asVideoModelV4(videoModel(modelId))
|
|
19752
20336
|
});
|
|
20337
|
+
if (registeredProvider !== provider && evaluationModel != null) {
|
|
20338
|
+
Object.assign(registeredProvider, { evaluationModel });
|
|
20339
|
+
}
|
|
20340
|
+
this.providers[id] = registeredProvider;
|
|
19753
20341
|
}
|
|
19754
20342
|
getProvider(id, modelType) {
|
|
19755
20343
|
const provider = this.providers[id];
|
|
@@ -19766,7 +20354,7 @@ var DefaultProviderRegistry = class {
|
|
|
19766
20354
|
splitId(id, modelType) {
|
|
19767
20355
|
const index = id.indexOf(this.separator);
|
|
19768
20356
|
if (index === -1) {
|
|
19769
|
-
throw new
|
|
20357
|
+
throw new NoSuchModelError5({
|
|
19770
20358
|
modelId: id,
|
|
19771
20359
|
modelType,
|
|
19772
20360
|
message: `Invalid ${modelType} id for registry: ${id} (must be in the format "providerId${this.separator}modelId")`
|
|
@@ -19782,7 +20370,7 @@ var DefaultProviderRegistry = class {
|
|
|
19782
20370
|
modelId
|
|
19783
20371
|
);
|
|
19784
20372
|
if (model == null) {
|
|
19785
|
-
throw new
|
|
20373
|
+
throw new NoSuchModelError5({ modelId: id, modelType: "languageModel" });
|
|
19786
20374
|
}
|
|
19787
20375
|
if (this.languageModelMiddleware != null) {
|
|
19788
20376
|
model = wrapLanguageModel({
|
|
@@ -19798,7 +20386,7 @@ var DefaultProviderRegistry = class {
|
|
|
19798
20386
|
const provider = this.getProvider(providerId, "embeddingModel");
|
|
19799
20387
|
const model = (_a25 = provider.embeddingModel) == null ? void 0 : _a25.call(provider, modelId);
|
|
19800
20388
|
if (model == null) {
|
|
19801
|
-
throw new
|
|
20389
|
+
throw new NoSuchModelError5({
|
|
19802
20390
|
modelId: id,
|
|
19803
20391
|
modelType: "embeddingModel"
|
|
19804
20392
|
});
|
|
@@ -19811,7 +20399,7 @@ var DefaultProviderRegistry = class {
|
|
|
19811
20399
|
const provider = this.getProvider(providerId, "imageModel");
|
|
19812
20400
|
let model = (_a25 = provider.imageModel) == null ? void 0 : _a25.call(provider, modelId);
|
|
19813
20401
|
if (model == null) {
|
|
19814
|
-
throw new
|
|
20402
|
+
throw new NoSuchModelError5({ modelId: id, modelType: "imageModel" });
|
|
19815
20403
|
}
|
|
19816
20404
|
if (this.imageModelMiddleware != null) {
|
|
19817
20405
|
model = wrapImageModel({
|
|
@@ -19827,7 +20415,7 @@ var DefaultProviderRegistry = class {
|
|
|
19827
20415
|
const provider = this.getProvider(providerId, "transcriptionModel");
|
|
19828
20416
|
const model = (_a25 = provider.transcriptionModel) == null ? void 0 : _a25.call(provider, modelId);
|
|
19829
20417
|
if (model == null) {
|
|
19830
|
-
throw new
|
|
20418
|
+
throw new NoSuchModelError5({
|
|
19831
20419
|
modelId: id,
|
|
19832
20420
|
modelType: "transcriptionModel"
|
|
19833
20421
|
});
|
|
@@ -19840,7 +20428,7 @@ var DefaultProviderRegistry = class {
|
|
|
19840
20428
|
const provider = this.getProvider(providerId, "speechModel");
|
|
19841
20429
|
const model = (_a25 = provider.speechModel) == null ? void 0 : _a25.call(provider, modelId);
|
|
19842
20430
|
if (model == null) {
|
|
19843
|
-
throw new
|
|
20431
|
+
throw new NoSuchModelError5({ modelId: id, modelType: "speechModel" });
|
|
19844
20432
|
}
|
|
19845
20433
|
return model;
|
|
19846
20434
|
}
|
|
@@ -19850,7 +20438,7 @@ var DefaultProviderRegistry = class {
|
|
|
19850
20438
|
const provider = this.getProvider(providerId, "rerankingModel");
|
|
19851
20439
|
const model = (_a25 = provider.rerankingModel) == null ? void 0 : _a25.call(provider, modelId);
|
|
19852
20440
|
if (model == null) {
|
|
19853
|
-
throw new
|
|
20441
|
+
throw new NoSuchModelError5({ modelId: id, modelType: "rerankingModel" });
|
|
19854
20442
|
}
|
|
19855
20443
|
return model;
|
|
19856
20444
|
}
|
|
@@ -19860,10 +20448,20 @@ var DefaultProviderRegistry = class {
|
|
|
19860
20448
|
const provider = this.getProvider(providerId, "videoModel");
|
|
19861
20449
|
const model = (_a25 = provider.videoModel) == null ? void 0 : _a25.call(provider, modelId);
|
|
19862
20450
|
if (model == null) {
|
|
19863
|
-
throw new
|
|
20451
|
+
throw new NoSuchModelError5({ modelId: id, modelType: "videoModel" });
|
|
19864
20452
|
}
|
|
19865
20453
|
return asVideoModelV4(model);
|
|
19866
20454
|
}
|
|
20455
|
+
evaluationModel(id) {
|
|
20456
|
+
var _a25;
|
|
20457
|
+
const [providerId, modelId] = this.splitId(id, "evaluationModel");
|
|
20458
|
+
const provider = this.getProvider(providerId, "evaluationModel");
|
|
20459
|
+
const model = (_a25 = provider.evaluationModel) == null ? void 0 : _a25.call(provider, modelId);
|
|
20460
|
+
if (model == null) {
|
|
20461
|
+
throw new NoSuchModelError5({ modelId: id, modelType: "evaluationModel" });
|
|
20462
|
+
}
|
|
20463
|
+
return resolveEvaluationModel(model);
|
|
20464
|
+
}
|
|
19867
20465
|
files(id) {
|
|
19868
20466
|
var _a25;
|
|
19869
20467
|
const provider = this.getProvider(id, "languageModel");
|
|
@@ -19890,7 +20488,7 @@ var DefaultProviderRegistry = class {
|
|
|
19890
20488
|
|
|
19891
20489
|
// src/rerank/rerank.ts
|
|
19892
20490
|
import {
|
|
19893
|
-
InvalidResponseDataError as
|
|
20491
|
+
InvalidResponseDataError as InvalidResponseDataError4
|
|
19894
20492
|
} from "@ai-sdk/provider";
|
|
19895
20493
|
import {
|
|
19896
20494
|
createIdGenerator as createIdGenerator8
|
|
@@ -20136,7 +20734,7 @@ function validateRankingIndices({
|
|
|
20136
20734
|
}) {
|
|
20137
20735
|
for (const { index } of ranking) {
|
|
20138
20736
|
if (!Number.isInteger(index) || index < 0 || index >= documents.length) {
|
|
20139
|
-
throw new
|
|
20737
|
+
throw new InvalidResponseDataError4({
|
|
20140
20738
|
data: ranking,
|
|
20141
20739
|
message: `Invalid ranking index ${index}. Expected an integer between 0 and ${documents.length - 1}.`
|
|
20142
20740
|
});
|
|
@@ -20158,7 +20756,7 @@ var DefaultRerankResult = class {
|
|
|
20158
20756
|
// src/transcribe/transcribe.ts
|
|
20159
20757
|
import {
|
|
20160
20758
|
detectMediaType as detectMediaType6,
|
|
20161
|
-
withUserAgentSuffix as
|
|
20759
|
+
withUserAgentSuffix as withUserAgentSuffix14
|
|
20162
20760
|
} from "@ai-sdk/provider-utils";
|
|
20163
20761
|
var defaultDownload2 = createDownload();
|
|
20164
20762
|
async function transcribe({
|
|
@@ -20178,7 +20776,7 @@ async function transcribe({
|
|
|
20178
20776
|
maxRetries: maxRetriesArg,
|
|
20179
20777
|
abortSignal
|
|
20180
20778
|
});
|
|
20181
|
-
const headersWithUserAgent =
|
|
20779
|
+
const headersWithUserAgent = withUserAgentSuffix14(
|
|
20182
20780
|
headers != null ? headers : {},
|
|
20183
20781
|
`ai/${VERSION}`
|
|
20184
20782
|
);
|
|
@@ -20235,7 +20833,7 @@ import {
|
|
|
20235
20833
|
} from "@ai-sdk/provider";
|
|
20236
20834
|
import {
|
|
20237
20835
|
DelayedPromise as DelayedPromise3,
|
|
20238
|
-
withUserAgentSuffix as
|
|
20836
|
+
withUserAgentSuffix as withUserAgentSuffix15
|
|
20239
20837
|
} from "@ai-sdk/provider-utils";
|
|
20240
20838
|
function streamTranscribe({
|
|
20241
20839
|
model,
|
|
@@ -20259,7 +20857,7 @@ function streamTranscribe({
|
|
|
20259
20857
|
message: `The ${resolvedModel.provider} model "${resolvedModel.modelId}" does not support streaming transcription.` + (typeof model === "string" ? " String model IDs resolve through the global provider (AI Gateway by default). If that provider does not support streaming transcription, pass a provider model instance instead (e.g. openai.transcription('gpt-realtime-whisper')) or upgrade @ai-sdk/gateway to a version with streaming transcription support." : "")
|
|
20260
20858
|
});
|
|
20261
20859
|
}
|
|
20262
|
-
const headersWithUserAgent =
|
|
20860
|
+
const headersWithUserAgent = withUserAgentSuffix15(
|
|
20263
20861
|
headers != null ? headers : {},
|
|
20264
20862
|
`ai/${VERSION}`
|
|
20265
20863
|
);
|
|
@@ -20444,7 +21042,7 @@ var experimental_transcribe = transcribe;
|
|
|
20444
21042
|
// src/translate/stream-translate.ts
|
|
20445
21043
|
import {
|
|
20446
21044
|
DelayedPromise as DelayedPromise4,
|
|
20447
|
-
withUserAgentSuffix as
|
|
21045
|
+
withUserAgentSuffix as withUserAgentSuffix16
|
|
20448
21046
|
} from "@ai-sdk/provider-utils";
|
|
20449
21047
|
function streamTranslate({
|
|
20450
21048
|
model,
|
|
@@ -20461,7 +21059,7 @@ function streamTranslate({
|
|
|
20461
21059
|
}) {
|
|
20462
21060
|
const resolvedModel = resolveSpeechTranslationModel(model);
|
|
20463
21061
|
const doStream = resolvedModel.doStream.bind(resolvedModel);
|
|
20464
|
-
const headersWithUserAgent =
|
|
21062
|
+
const headersWithUserAgent = withUserAgentSuffix16(
|
|
20465
21063
|
headers != null ? headers : {},
|
|
20466
21064
|
`ai/${VERSION}`
|
|
20467
21065
|
);
|
|
@@ -20658,7 +21256,7 @@ function streamTranslate({
|
|
|
20658
21256
|
// src/ui/call-completion-api.ts
|
|
20659
21257
|
import {
|
|
20660
21258
|
parseJsonEventStream,
|
|
20661
|
-
withUserAgentSuffix as
|
|
21259
|
+
withUserAgentSuffix as withUserAgentSuffix17,
|
|
20662
21260
|
getRuntimeEnvironmentUserAgent as getRuntimeEnvironmentUserAgent2
|
|
20663
21261
|
} from "@ai-sdk/provider-utils";
|
|
20664
21262
|
import { EmptyResponseBodyError as EmptyResponseBodyError2 } from "@ai-sdk/provider";
|
|
@@ -20727,7 +21325,7 @@ async function callCompletionApi({
|
|
|
20727
21325
|
...body
|
|
20728
21326
|
}),
|
|
20729
21327
|
credentials,
|
|
20730
|
-
headers:
|
|
21328
|
+
headers: withUserAgentSuffix17(
|
|
20731
21329
|
{
|
|
20732
21330
|
"Content-Type": "application/json",
|
|
20733
21331
|
...headers
|
|
@@ -21726,6 +22324,7 @@ export {
|
|
|
21726
22324
|
EmptyResponseBodyError,
|
|
21727
22325
|
AbstractRealtimeSession as Experimental_AbstractRealtimeSession,
|
|
21728
22326
|
ToolLoopAgent as Experimental_Agent,
|
|
22327
|
+
Experimental_EvaluationUnsupportedQuestionTypeError,
|
|
21729
22328
|
HttpChatTransport,
|
|
21730
22329
|
InvalidArgumentError,
|
|
21731
22330
|
InvalidDataContentError,
|
|
@@ -21799,6 +22398,7 @@ export {
|
|
|
21799
22398
|
experimental_createProviderRegistry,
|
|
21800
22399
|
decodeRealtimeAudio as experimental_decodeRealtimeAudio,
|
|
21801
22400
|
encodeRealtimeAudio as experimental_encodeRealtimeAudio,
|
|
22401
|
+
evaluate as experimental_evaluate,
|
|
21802
22402
|
filterActiveTools as experimental_filterActiveTools,
|
|
21803
22403
|
experimental_generateSpeech,
|
|
21804
22404
|
experimental_generateVideo,
|
|
@@ -21847,7 +22447,7 @@ export {
|
|
|
21847
22447
|
isTextUIPart,
|
|
21848
22448
|
isToolOutputErrorUIPart,
|
|
21849
22449
|
isToolUIPart,
|
|
21850
|
-
jsonSchema,
|
|
22450
|
+
jsonSchema2 as jsonSchema,
|
|
21851
22451
|
lastAssistantMessageIsCompleteWithApprovalResponses,
|
|
21852
22452
|
lastAssistantMessageIsCompleteWithToolCalls,
|
|
21853
22453
|
modelMessageSchema,
|
|
@@ -21871,8 +22471,9 @@ export {
|
|
|
21871
22471
|
toTextStream,
|
|
21872
22472
|
toUIMessageChunk,
|
|
21873
22473
|
toUIMessageStream,
|
|
21874
|
-
tool,
|
|
22474
|
+
tool2 as tool,
|
|
21875
22475
|
toolModelMessageSchema,
|
|
22476
|
+
toolSearch,
|
|
21876
22477
|
transcribe,
|
|
21877
22478
|
uiMessageChunkSchema,
|
|
21878
22479
|
uploadFile,
|