ai 7.0.103 → 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 +17 -0
- package/dist/index.d.ts +37 -7
- package/dist/index.js +522 -298
- package/dist/index.js.map +1 -1
- package/dist/internal/index.d.ts +1 -0
- package/dist/internal/index.js +4 -1
- package/dist/internal/index.js.map +1 -1
- package/docs/03-ai-sdk-core/18-code-mode.mdx +11 -0
- package/docs/03-ai-sdk-core/19-tool-search.mdx +80 -0
- package/docs/03-ai-sdk-core/32-evaluation.mdx +152 -7
- package/docs/03-ai-sdk-core/45-provider-management.mdx +10 -0
- package/docs/03-ai-sdk-core/index.mdx +6 -0
- package/docs/07-reference/01-ai-sdk-core/14-evaluate.mdx +22 -9
- 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/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/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/evaluate/evaluate.ts +4 -10
- package/src/evaluate/evaluation-provider.ts +6 -0
- package/src/evaluate/evaluation-result.ts +1 -1
- package/src/generate-text/generate-text.ts +9 -1
- package/src/generate-text/stream-text.ts +9 -1
- package/src/generate-text/tool-caller-configuration.ts +1 -1
- package/src/global.ts +1 -0
- package/src/index.ts +1 -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/tool-search/prepare-tool-search.ts +143 -0
- package/src/tool-search/tool-search.ts +59 -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
|
|
|
@@ -690,6 +690,9 @@ var logWarnings = (options) => {
|
|
|
690
690
|
|
|
691
691
|
// src/model/resolve-model.ts
|
|
692
692
|
import { gateway } from "@ai-sdk/gateway";
|
|
693
|
+
import {
|
|
694
|
+
NoSuchModelError as NoSuchModelError2
|
|
695
|
+
} from "@ai-sdk/provider";
|
|
693
696
|
|
|
694
697
|
// src/util/log-v2-compatibility-warning.ts
|
|
695
698
|
function logV2CompatibilityWarning({
|
|
@@ -1125,6 +1128,34 @@ function resolveRerankingModel(model) {
|
|
|
1125
1128
|
}
|
|
1126
1129
|
return asRerankingModelV4(model);
|
|
1127
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
|
+
}
|
|
1128
1159
|
function getGlobalProvider() {
|
|
1129
1160
|
var _a25;
|
|
1130
1161
|
const provider = (_a25 = globalThis.AI_SDK_DEFAULT_PROVIDER) != null ? _a25 : gateway;
|
|
@@ -1179,7 +1210,7 @@ import {
|
|
|
1179
1210
|
} from "@ai-sdk/provider-utils";
|
|
1180
1211
|
|
|
1181
1212
|
// src/version.ts
|
|
1182
|
-
var VERSION = true ? "7.0.
|
|
1213
|
+
var VERSION = true ? "7.0.104" : "0.0.0-test";
|
|
1183
1214
|
|
|
1184
1215
|
// src/util/download/download.ts
|
|
1185
1216
|
var download = async ({
|
|
@@ -2015,7 +2046,7 @@ async function createToolModelOutput({
|
|
|
2015
2046
|
toolCallId,
|
|
2016
2047
|
input,
|
|
2017
2048
|
output,
|
|
2018
|
-
tool:
|
|
2049
|
+
tool: tool3,
|
|
2019
2050
|
errorMode
|
|
2020
2051
|
}) {
|
|
2021
2052
|
if (errorMode === "text") {
|
|
@@ -2023,8 +2054,8 @@ async function createToolModelOutput({
|
|
|
2023
2054
|
} else if (errorMode === "json") {
|
|
2024
2055
|
return { type: "error-json", value: await toJSONValue(output) };
|
|
2025
2056
|
}
|
|
2026
|
-
if (
|
|
2027
|
-
return await
|
|
2057
|
+
if (tool3 == null ? void 0 : tool3.toModelOutput) {
|
|
2058
|
+
return await tool3.toModelOutput({ toolCallId, input, output });
|
|
2028
2059
|
}
|
|
2029
2060
|
return typeof output === "string" ? { type: "text", value: output } : { type: "json", value: await toJSONValue(output) };
|
|
2030
2061
|
}
|
|
@@ -2159,25 +2190,25 @@ async function prepareTools({
|
|
|
2159
2190
|
return void 0;
|
|
2160
2191
|
}
|
|
2161
2192
|
const languageModelTools = [];
|
|
2162
|
-
for (const [name25,
|
|
2163
|
-
const toolType =
|
|
2193
|
+
for (const [name25, tool3] of orderToolEntries({ tools, toolOrder })) {
|
|
2194
|
+
const toolType = tool3.type;
|
|
2164
2195
|
switch (toolType) {
|
|
2165
2196
|
case void 0:
|
|
2166
2197
|
case "dynamic":
|
|
2167
2198
|
case "function": {
|
|
2168
2199
|
const description = resolveToolDescription({
|
|
2169
|
-
tool:
|
|
2200
|
+
tool: tool3,
|
|
2170
2201
|
toolName: name25,
|
|
2171
2202
|
toolsContext,
|
|
2172
2203
|
experimental_sandbox: sandbox
|
|
2173
2204
|
});
|
|
2174
|
-
const providerOptions =
|
|
2175
|
-
const inputExamples =
|
|
2176
|
-
const strict =
|
|
2205
|
+
const providerOptions = tool3.providerOptions;
|
|
2206
|
+
const inputExamples = tool3.inputExamples;
|
|
2207
|
+
const strict = tool3.strict;
|
|
2177
2208
|
languageModelTools.push({
|
|
2178
2209
|
type: "function",
|
|
2179
2210
|
name: name25,
|
|
2180
|
-
inputSchema: await asSchema(
|
|
2211
|
+
inputSchema: await asSchema(tool3.inputSchema).jsonSchema,
|
|
2181
2212
|
...description != null ? { description } : {},
|
|
2182
2213
|
...inputExamples != null ? { inputExamples } : {},
|
|
2183
2214
|
...providerOptions != null ? { providerOptions } : {},
|
|
@@ -2189,8 +2220,8 @@ async function prepareTools({
|
|
|
2189
2220
|
languageModelTools.push({
|
|
2190
2221
|
type: "provider",
|
|
2191
2222
|
name: name25,
|
|
2192
|
-
id:
|
|
2193
|
-
args:
|
|
2223
|
+
id: tool3.id,
|
|
2224
|
+
args: tool3.args
|
|
2194
2225
|
});
|
|
2195
2226
|
break;
|
|
2196
2227
|
}
|
|
@@ -2217,12 +2248,12 @@ function orderToolEntries({
|
|
|
2217
2248
|
return [...orderedTools, ...unorderedTools];
|
|
2218
2249
|
}
|
|
2219
2250
|
function resolveToolDescription({
|
|
2220
|
-
tool:
|
|
2251
|
+
tool: tool3,
|
|
2221
2252
|
toolName,
|
|
2222
2253
|
toolsContext,
|
|
2223
2254
|
experimental_sandbox: sandbox
|
|
2224
2255
|
}) {
|
|
2225
|
-
return
|
|
2256
|
+
return tool3.description === void 0 ? void 0 : typeof tool3.description === "string" ? tool3.description : tool3.description({
|
|
2226
2257
|
context: toolsContext[toolName],
|
|
2227
2258
|
experimental_sandbox: sandbox
|
|
2228
2259
|
});
|
|
@@ -3068,8 +3099,8 @@ function convertLanguageModelContent({
|
|
|
3068
3099
|
(toolCall2) => toolCall2.toolCallId === part.toolCallId
|
|
3069
3100
|
);
|
|
3070
3101
|
if (toolCall == null) {
|
|
3071
|
-
const
|
|
3072
|
-
const supportsDeferredResults = (
|
|
3102
|
+
const tool3 = getOwn(tools, part.toolName);
|
|
3103
|
+
const supportsDeferredResults = (tool3 == null ? void 0 : tool3.type) === "provider" && tool3.supportsDeferredResults;
|
|
3073
3104
|
if (!supportsDeferredResults) {
|
|
3074
3105
|
throw new Error(`Tool call ${part.toolCallId} not found.`);
|
|
3075
3106
|
}
|
|
@@ -3083,7 +3114,7 @@ function convertLanguageModelContent({
|
|
|
3083
3114
|
providerExecuted: true,
|
|
3084
3115
|
dynamic: part.dynamic,
|
|
3085
3116
|
...part.providerMetadata != null ? { providerMetadata: part.providerMetadata } : {},
|
|
3086
|
-
...(
|
|
3117
|
+
...(tool3 == null ? void 0 : tool3.metadata) != null ? { toolMetadata: tool3.metadata } : {}
|
|
3087
3118
|
});
|
|
3088
3119
|
} else {
|
|
3089
3120
|
contentParts.push({
|
|
@@ -3095,7 +3126,7 @@ function convertLanguageModelContent({
|
|
|
3095
3126
|
providerExecuted: true,
|
|
3096
3127
|
dynamic: part.dynamic,
|
|
3097
3128
|
...part.providerMetadata != null ? { providerMetadata: part.providerMetadata } : {},
|
|
3098
|
-
...(
|
|
3129
|
+
...(tool3 == null ? void 0 : tool3.metadata) != null ? { toolMetadata: tool3.metadata } : {}
|
|
3099
3130
|
});
|
|
3100
3131
|
}
|
|
3101
3132
|
break;
|
|
@@ -3162,6 +3193,287 @@ function convertLanguageModelContent({
|
|
|
3162
3193
|
];
|
|
3163
3194
|
}
|
|
3164
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
|
+
|
|
3165
3477
|
// src/generate-text/execute-tool-call.ts
|
|
3166
3478
|
import {
|
|
3167
3479
|
executeTool,
|
|
@@ -3205,14 +3517,14 @@ async function executeToolCall({
|
|
|
3205
3517
|
runInTracingChannelSpan = async ({ execute }) => await execute()
|
|
3206
3518
|
}) {
|
|
3207
3519
|
const { toolName, toolCallId, input } = toolCall;
|
|
3208
|
-
const
|
|
3209
|
-
if (!isExecutableTool(
|
|
3520
|
+
const tool3 = getOwn(tools, toolName);
|
|
3521
|
+
if (!isExecutableTool(tool3)) {
|
|
3210
3522
|
return void 0;
|
|
3211
3523
|
}
|
|
3212
3524
|
const context = await validateToolContext({
|
|
3213
3525
|
toolName,
|
|
3214
3526
|
context: getOwn(toolsContext, toolName),
|
|
3215
|
-
contextSchema:
|
|
3527
|
+
contextSchema: tool3.contextSchema
|
|
3216
3528
|
});
|
|
3217
3529
|
const toolExecutionContext = {
|
|
3218
3530
|
toolCall,
|
|
@@ -3244,7 +3556,7 @@ async function executeToolCall({
|
|
|
3244
3556
|
const startTime = now();
|
|
3245
3557
|
try {
|
|
3246
3558
|
const stream = executeTool({
|
|
3247
|
-
tool:
|
|
3559
|
+
tool: tool3,
|
|
3248
3560
|
input,
|
|
3249
3561
|
options: {
|
|
3250
3562
|
toolCallId,
|
|
@@ -3278,7 +3590,7 @@ async function executeToolCall({
|
|
|
3278
3590
|
toolName,
|
|
3279
3591
|
input,
|
|
3280
3592
|
error,
|
|
3281
|
-
dynamic:
|
|
3593
|
+
dynamic: tool3.type === "dynamic",
|
|
3282
3594
|
...toolCall.providerMetadata != null ? { providerMetadata: toolCall.providerMetadata } : {},
|
|
3283
3595
|
...toolCall.toolMetadata != null ? { toolMetadata: toolCall.toolMetadata } : {}
|
|
3284
3596
|
};
|
|
@@ -3301,7 +3613,7 @@ async function executeToolCall({
|
|
|
3301
3613
|
toolName,
|
|
3302
3614
|
input,
|
|
3303
3615
|
output,
|
|
3304
|
-
dynamic:
|
|
3616
|
+
dynamic: tool3.type === "dynamic",
|
|
3305
3617
|
...toolCall.providerMetadata != null ? { providerMetadata: toolCall.providerMetadata } : {},
|
|
3306
3618
|
...toolCall.toolMetadata != null ? { toolMetadata: toolCall.toolMetadata } : {}
|
|
3307
3619
|
};
|
|
@@ -3736,9 +4048,9 @@ var object2 = ({
|
|
|
3736
4048
|
const schema = asSchema2(inputSchema);
|
|
3737
4049
|
return {
|
|
3738
4050
|
name: "object",
|
|
3739
|
-
responseFormat: resolve(schema.jsonSchema).then((
|
|
4051
|
+
responseFormat: resolve(schema.jsonSchema).then((jsonSchema3) => ({
|
|
3740
4052
|
type: "json",
|
|
3741
|
-
schema:
|
|
4053
|
+
schema: jsonSchema3,
|
|
3742
4054
|
...name25 != null && { name: name25 },
|
|
3743
4055
|
...description != null && { description }
|
|
3744
4056
|
})),
|
|
@@ -3811,13 +4123,13 @@ var array2 = ({
|
|
|
3811
4123
|
return {
|
|
3812
4124
|
name: "array",
|
|
3813
4125
|
// JSON schema that describes an array of elements:
|
|
3814
|
-
responseFormat: resolve(elementSchema.jsonSchema).then((
|
|
4126
|
+
responseFormat: resolve(elementSchema.jsonSchema).then((jsonSchema3) => {
|
|
3815
4127
|
const {
|
|
3816
4128
|
$schema: _$schema,
|
|
3817
4129
|
definitions,
|
|
3818
4130
|
$defs,
|
|
3819
4131
|
...itemSchema
|
|
3820
|
-
} =
|
|
4132
|
+
} = jsonSchema3;
|
|
3821
4133
|
return {
|
|
3822
4134
|
type: "json",
|
|
3823
4135
|
schema: {
|
|
@@ -4181,7 +4493,7 @@ async function parseToolCall({
|
|
|
4181
4493
|
} catch (error) {
|
|
4182
4494
|
const parsedInput = await safeParseJSON3({ text: toolCall.input });
|
|
4183
4495
|
const input = parsedInput.success ? parsedInput.value : toolCall.input;
|
|
4184
|
-
const
|
|
4496
|
+
const tool3 = getOwn(tools, toolCall.toolName);
|
|
4185
4497
|
return {
|
|
4186
4498
|
type: "tool-call",
|
|
4187
4499
|
toolCallId: toolCall.toolCallId,
|
|
@@ -4190,10 +4502,10 @@ async function parseToolCall({
|
|
|
4190
4502
|
dynamic: true,
|
|
4191
4503
|
invalid: true,
|
|
4192
4504
|
error,
|
|
4193
|
-
title:
|
|
4505
|
+
title: tool3 == null ? void 0 : tool3.title,
|
|
4194
4506
|
providerExecuted: toolCall.providerExecuted,
|
|
4195
4507
|
providerMetadata: toolCall.providerMetadata,
|
|
4196
|
-
...(
|
|
4508
|
+
...(tool3 == null ? void 0 : tool3.metadata) != null ? { toolMetadata: tool3.metadata } : {}
|
|
4197
4509
|
};
|
|
4198
4510
|
}
|
|
4199
4511
|
}
|
|
@@ -4234,8 +4546,8 @@ async function doParseToolCall({
|
|
|
4234
4546
|
tools
|
|
4235
4547
|
}) {
|
|
4236
4548
|
const toolName = toolCall.toolName;
|
|
4237
|
-
const
|
|
4238
|
-
if (
|
|
4549
|
+
const tool3 = getOwn(tools, toolName);
|
|
4550
|
+
if (tool3 == null) {
|
|
4239
4551
|
if (toolCall.providerExecuted && toolCall.dynamic) {
|
|
4240
4552
|
return await parseProviderExecutedDynamicToolCall(toolCall);
|
|
4241
4553
|
}
|
|
@@ -4244,7 +4556,7 @@ async function doParseToolCall({
|
|
|
4244
4556
|
availableTools: Object.keys(tools)
|
|
4245
4557
|
});
|
|
4246
4558
|
}
|
|
4247
|
-
const schema = asSchema3(
|
|
4559
|
+
const schema = asSchema3(tool3.inputSchema);
|
|
4248
4560
|
const parseResult = toolCall.input.trim() === "" ? await safeValidateTypes3({ value: {}, schema }) : await safeParseJSON3({ text: toolCall.input, schema });
|
|
4249
4561
|
if (parseResult.success === false) {
|
|
4250
4562
|
throw new InvalidToolInputError({
|
|
@@ -4253,16 +4565,16 @@ async function doParseToolCall({
|
|
|
4253
4565
|
cause: parseResult.error
|
|
4254
4566
|
});
|
|
4255
4567
|
}
|
|
4256
|
-
return
|
|
4568
|
+
return tool3.type === "dynamic" ? {
|
|
4257
4569
|
type: "tool-call",
|
|
4258
4570
|
toolCallId: toolCall.toolCallId,
|
|
4259
4571
|
toolName: toolCall.toolName,
|
|
4260
4572
|
input: parseResult.value,
|
|
4261
4573
|
providerExecuted: toolCall.providerExecuted,
|
|
4262
4574
|
providerMetadata: toolCall.providerMetadata,
|
|
4263
|
-
...
|
|
4575
|
+
...tool3.metadata != null ? { toolMetadata: tool3.metadata } : {},
|
|
4264
4576
|
dynamic: true,
|
|
4265
|
-
title:
|
|
4577
|
+
title: tool3.title
|
|
4266
4578
|
} : {
|
|
4267
4579
|
type: "tool-call",
|
|
4268
4580
|
toolCallId: toolCall.toolCallId,
|
|
@@ -4270,8 +4582,8 @@ async function doParseToolCall({
|
|
|
4270
4582
|
input: parseResult.value,
|
|
4271
4583
|
providerExecuted: toolCall.providerExecuted,
|
|
4272
4584
|
providerMetadata: toolCall.providerMetadata,
|
|
4273
|
-
...
|
|
4274
|
-
title:
|
|
4585
|
+
...tool3.metadata != null ? { toolMetadata: tool3.metadata } : {},
|
|
4586
|
+
title: tool3.title
|
|
4275
4587
|
};
|
|
4276
4588
|
}
|
|
4277
4589
|
|
|
@@ -4361,7 +4673,7 @@ async function resolveToolApproval({
|
|
|
4361
4673
|
);
|
|
4362
4674
|
}
|
|
4363
4675
|
const toolName = toolCall.toolName;
|
|
4364
|
-
const
|
|
4676
|
+
const tool3 = getOwn(tools, toolName);
|
|
4365
4677
|
const input = toolCall.input;
|
|
4366
4678
|
const userDefinedToolApprovalStatus = getOwn(toolApproval, toolName);
|
|
4367
4679
|
if (userDefinedToolApprovalStatus != null) {
|
|
@@ -4371,24 +4683,24 @@ async function resolveToolApproval({
|
|
|
4371
4683
|
toolContext: await validateToolContext({
|
|
4372
4684
|
toolName,
|
|
4373
4685
|
context: getOwn(toolsContext, toolName),
|
|
4374
|
-
contextSchema:
|
|
4686
|
+
contextSchema: tool3 == null ? void 0 : tool3.contextSchema
|
|
4375
4687
|
}),
|
|
4376
4688
|
runtimeContext
|
|
4377
4689
|
}) : userDefinedToolApprovalStatus;
|
|
4378
4690
|
return normalizeToolApprovalStatus(approvalStatus);
|
|
4379
4691
|
}
|
|
4380
|
-
if ((
|
|
4692
|
+
if ((tool3 == null ? void 0 : tool3.needsApproval) == null) {
|
|
4381
4693
|
return { type: "not-applicable" };
|
|
4382
4694
|
}
|
|
4383
|
-
const needsApproval = typeof
|
|
4695
|
+
const needsApproval = typeof tool3.needsApproval === "function" ? await tool3.needsApproval(input, {
|
|
4384
4696
|
toolCallId: toolCall.toolCallId,
|
|
4385
4697
|
messages,
|
|
4386
4698
|
context: await validateToolContext({
|
|
4387
4699
|
toolName,
|
|
4388
4700
|
context: getOwn(toolsContext, toolName),
|
|
4389
|
-
contextSchema:
|
|
4701
|
+
contextSchema: tool3 == null ? void 0 : tool3.contextSchema
|
|
4390
4702
|
})
|
|
4391
|
-
}) :
|
|
4703
|
+
}) : tool3.needsApproval;
|
|
4392
4704
|
return needsApproval ? { type: "user-approval" } : { type: "not-applicable" };
|
|
4393
4705
|
}
|
|
4394
4706
|
function normalizeToolApprovalStatus(status) {
|
|
@@ -5199,149 +5511,6 @@ function sortToolResultContentByToolCallOrder({
|
|
|
5199
5511
|
);
|
|
5200
5512
|
}
|
|
5201
5513
|
|
|
5202
|
-
// src/generate-text/tool-caller-configuration.ts
|
|
5203
|
-
import {
|
|
5204
|
-
experimental_getToolCaller
|
|
5205
|
-
} from "@ai-sdk/provider-utils";
|
|
5206
|
-
var DIRECT_TOOL_CALL = "AI_SDK_DIRECT_TOOL_CALL";
|
|
5207
|
-
function resolveToolCallerConfiguration({
|
|
5208
|
-
tools,
|
|
5209
|
-
toolCallers
|
|
5210
|
-
}) {
|
|
5211
|
-
if (tools == null || toolCallers == null) {
|
|
5212
|
-
return void 0;
|
|
5213
|
-
}
|
|
5214
|
-
const resolved = {};
|
|
5215
|
-
for (const [toolName, callers] of Object.entries(toolCallers)) {
|
|
5216
|
-
if (!Object.prototype.hasOwnProperty.call(tools, toolName)) {
|
|
5217
|
-
throw new InvalidArgumentError({
|
|
5218
|
-
parameter: "experimental_toolCallers",
|
|
5219
|
-
value: toolCallers,
|
|
5220
|
-
message: `unknown tool "${toolName}".`
|
|
5221
|
-
});
|
|
5222
|
-
}
|
|
5223
|
-
if (!Array.isArray(callers)) {
|
|
5224
|
-
throw new InvalidArgumentError({
|
|
5225
|
-
parameter: "experimental_toolCallers",
|
|
5226
|
-
value: toolCallers,
|
|
5227
|
-
message: `callers for tool "${toolName}" must be an array.`
|
|
5228
|
-
});
|
|
5229
|
-
}
|
|
5230
|
-
resolved[toolName] = callers.map((caller) => {
|
|
5231
|
-
if (caller === DIRECT_TOOL_CALL) {
|
|
5232
|
-
return caller;
|
|
5233
|
-
}
|
|
5234
|
-
if (typeof caller !== "string" || !Object.prototype.hasOwnProperty.call(tools, caller) || experimental_getToolCaller(tools[caller]) == null) {
|
|
5235
|
-
throw new InvalidArgumentError({
|
|
5236
|
-
parameter: "experimental_toolCallers",
|
|
5237
|
-
value: toolCallers,
|
|
5238
|
-
message: `tool "${toolName}" contains an invalid caller.`
|
|
5239
|
-
});
|
|
5240
|
-
}
|
|
5241
|
-
return caller;
|
|
5242
|
-
});
|
|
5243
|
-
}
|
|
5244
|
-
return resolved;
|
|
5245
|
-
}
|
|
5246
|
-
function prepareToolsForToolCallers({
|
|
5247
|
-
tools,
|
|
5248
|
-
toolCallers
|
|
5249
|
-
}) {
|
|
5250
|
-
var _a25, _b25;
|
|
5251
|
-
if (tools == null || toolCallers == null) {
|
|
5252
|
-
return {
|
|
5253
|
-
executionTools: tools,
|
|
5254
|
-
modelTools: tools,
|
|
5255
|
-
toolCallerMessages: []
|
|
5256
|
-
};
|
|
5257
|
-
}
|
|
5258
|
-
const executionTools = { ...tools };
|
|
5259
|
-
const modelTools = { ...tools };
|
|
5260
|
-
const localToolsByCaller = /* @__PURE__ */ new Map();
|
|
5261
|
-
const toolCallerMessages = [];
|
|
5262
|
-
for (const [toolName, callerNames] of Object.entries(toolCallers)) {
|
|
5263
|
-
const tool2 = executionTools[toolName];
|
|
5264
|
-
if (tool2 == null) {
|
|
5265
|
-
continue;
|
|
5266
|
-
}
|
|
5267
|
-
let availableDirectly = false;
|
|
5268
|
-
let availableToProvider = false;
|
|
5269
|
-
let preparedTool = tool2;
|
|
5270
|
-
for (const callerName of callerNames) {
|
|
5271
|
-
if (callerName === DIRECT_TOOL_CALL) {
|
|
5272
|
-
availableDirectly = true;
|
|
5273
|
-
continue;
|
|
5274
|
-
}
|
|
5275
|
-
const caller = experimental_getToolCaller(executionTools[callerName]);
|
|
5276
|
-
if (caller == null) {
|
|
5277
|
-
continue;
|
|
5278
|
-
}
|
|
5279
|
-
if (caller.type === "provider") {
|
|
5280
|
-
availableToProvider = true;
|
|
5281
|
-
preparedTool = {
|
|
5282
|
-
...preparedTool,
|
|
5283
|
-
providerOptions: caller.prepareProviderOptions(
|
|
5284
|
-
preparedTool.providerOptions
|
|
5285
|
-
)
|
|
5286
|
-
};
|
|
5287
|
-
} else {
|
|
5288
|
-
const localTools = (_a25 = localToolsByCaller.get(callerName)) != null ? _a25 : {};
|
|
5289
|
-
localTools[toolName] = preparedTool;
|
|
5290
|
-
localToolsByCaller.set(callerName, localTools);
|
|
5291
|
-
}
|
|
5292
|
-
}
|
|
5293
|
-
executionTools[toolName] = preparedTool;
|
|
5294
|
-
if (availableDirectly || availableToProvider) {
|
|
5295
|
-
modelTools[toolName] = preparedTool;
|
|
5296
|
-
} else {
|
|
5297
|
-
delete modelTools[toolName];
|
|
5298
|
-
}
|
|
5299
|
-
}
|
|
5300
|
-
for (const [callerName, callerTool] of Object.entries(executionTools)) {
|
|
5301
|
-
const caller = experimental_getToolCaller(callerTool);
|
|
5302
|
-
if ((caller == null ? void 0 : caller.type) !== "local") {
|
|
5303
|
-
continue;
|
|
5304
|
-
}
|
|
5305
|
-
const callerTools = (_b25 = localToolsByCaller.get(callerName)) != null ? _b25 : {};
|
|
5306
|
-
const boundCaller = caller.bind(callerTools);
|
|
5307
|
-
executionTools[callerName] = boundCaller;
|
|
5308
|
-
if (Object.prototype.hasOwnProperty.call(modelTools, callerName)) {
|
|
5309
|
-
if (caller.prepareModelMessage == null) {
|
|
5310
|
-
modelTools[callerName] = boundCaller;
|
|
5311
|
-
} else {
|
|
5312
|
-
const content = caller.prepareModelMessage(callerTools);
|
|
5313
|
-
if (content != null) {
|
|
5314
|
-
toolCallerMessages.push({ role: "user", content });
|
|
5315
|
-
}
|
|
5316
|
-
}
|
|
5317
|
-
}
|
|
5318
|
-
}
|
|
5319
|
-
return { executionTools, modelTools, toolCallerMessages };
|
|
5320
|
-
}
|
|
5321
|
-
function appendToolCallerMessages({
|
|
5322
|
-
messages,
|
|
5323
|
-
toolCallerMessages
|
|
5324
|
-
}) {
|
|
5325
|
-
var _a25;
|
|
5326
|
-
if (toolCallerMessages.length === 0) {
|
|
5327
|
-
return messages;
|
|
5328
|
-
}
|
|
5329
|
-
const latestUserText = (_a25 = messages.findLast(
|
|
5330
|
-
(message) => message.role === "user" && typeof message.content === "string"
|
|
5331
|
-
)) == null ? void 0 : _a25.content;
|
|
5332
|
-
const existingUserText = new Set(
|
|
5333
|
-
latestUserText == null ? [] : [latestUserText]
|
|
5334
|
-
);
|
|
5335
|
-
const additions = toolCallerMessages.filter((message) => {
|
|
5336
|
-
if (typeof message.content !== "string" || existingUserText.has(message.content)) {
|
|
5337
|
-
return false;
|
|
5338
|
-
}
|
|
5339
|
-
existingUserText.add(message.content);
|
|
5340
|
-
return true;
|
|
5341
|
-
});
|
|
5342
|
-
return additions.length === 0 ? messages : [...messages, ...additions];
|
|
5343
|
-
}
|
|
5344
|
-
|
|
5345
5514
|
// src/generate-text/tool-approval-signature.ts
|
|
5346
5515
|
import { convertBase64ToUint8Array as convertBase64ToUint8Array2 } from "@ai-sdk/provider-utils";
|
|
5347
5516
|
|
|
@@ -5480,7 +5649,7 @@ async function validateApprovedToolApprovals({
|
|
|
5480
5649
|
const invalid = [];
|
|
5481
5650
|
for (const approval of approvedToolApprovals) {
|
|
5482
5651
|
const { toolCall, approvalRequest } = approval;
|
|
5483
|
-
const
|
|
5652
|
+
const tool3 = getOwn(tools, toolCall.toolName);
|
|
5484
5653
|
if (toolApprovalSecret != null) {
|
|
5485
5654
|
if (approvalRequest.signature == null) {
|
|
5486
5655
|
throw new InvalidToolApprovalSignatureError({
|
|
@@ -5505,10 +5674,10 @@ async function validateApprovedToolApprovals({
|
|
|
5505
5674
|
});
|
|
5506
5675
|
}
|
|
5507
5676
|
}
|
|
5508
|
-
if (isExecutableTool2(
|
|
5677
|
+
if (isExecutableTool2(tool3) && tool3.inputSchema != null) {
|
|
5509
5678
|
const validation = await safeValidateTypes4({
|
|
5510
5679
|
value: toolCall.input,
|
|
5511
|
-
schema: asSchema4(
|
|
5680
|
+
schema: asSchema4(tool3.inputSchema)
|
|
5512
5681
|
});
|
|
5513
5682
|
if (!validation.success) {
|
|
5514
5683
|
invalid.push({
|
|
@@ -5626,6 +5795,10 @@ async function generateText({
|
|
|
5626
5795
|
tools,
|
|
5627
5796
|
toolCallers: experimental_toolCallers
|
|
5628
5797
|
});
|
|
5798
|
+
const prepareToolSearch = createToolSearchState({
|
|
5799
|
+
tools,
|
|
5800
|
+
toolCallers: resolvedToolCallers
|
|
5801
|
+
});
|
|
5629
5802
|
const stopConditions = asArray5(stopWhen);
|
|
5630
5803
|
const resolvedOnStart = onStart != null ? onStart : experimental_onStart;
|
|
5631
5804
|
const resolvedOnStepStart = onStepStart != null ? onStepStart : experimental_onStepStart;
|
|
@@ -5897,7 +6070,10 @@ async function generateText({
|
|
|
5897
6070
|
modelTools: stepModelTools,
|
|
5898
6071
|
toolCallerMessages
|
|
5899
6072
|
} = prepareToolsForToolCallers({
|
|
5900
|
-
tools: stepActiveTools,
|
|
6073
|
+
tools: prepareToolSearch(stepActiveTools, {
|
|
6074
|
+
toolsContext,
|
|
6075
|
+
experimental_sandbox: stepSandbox
|
|
6076
|
+
}),
|
|
5901
6077
|
toolCallers: resolvedToolCallers
|
|
5902
6078
|
});
|
|
5903
6079
|
const stepToolOrder = (_h = prepareStepResult == null ? void 0 : prepareStepResult.toolOrder) != null ? _h : toolOrder;
|
|
@@ -6085,20 +6261,20 @@ async function generateText({
|
|
|
6085
6261
|
if (toolCall.invalid) {
|
|
6086
6262
|
continue;
|
|
6087
6263
|
}
|
|
6088
|
-
const
|
|
6089
|
-
if (
|
|
6264
|
+
const tool3 = getOwn(stepExecutionTools, toolCall.toolName);
|
|
6265
|
+
if (tool3 == null) {
|
|
6090
6266
|
continue;
|
|
6091
6267
|
}
|
|
6092
|
-
if (
|
|
6093
|
-
await
|
|
6268
|
+
if (tool3.onInputStart != null) {
|
|
6269
|
+
await tool3.onInputStart({
|
|
6094
6270
|
toolCallId: toolCall.toolCallId,
|
|
6095
6271
|
messages: stepMessages,
|
|
6096
6272
|
abortSignal: mergedAbortSignal,
|
|
6097
6273
|
context: runtimeContext
|
|
6098
6274
|
});
|
|
6099
6275
|
}
|
|
6100
|
-
if ((
|
|
6101
|
-
await
|
|
6276
|
+
if ((tool3 == null ? void 0 : tool3.onInputAvailable) != null) {
|
|
6277
|
+
await tool3.onInputAvailable({
|
|
6102
6278
|
input: toolCall.input,
|
|
6103
6279
|
toolCallId: toolCall.toolCallId,
|
|
6104
6280
|
messages: stepMessages,
|
|
@@ -6256,8 +6432,8 @@ async function generateText({
|
|
|
6256
6432
|
};
|
|
6257
6433
|
for (const toolCall of stepToolCalls) {
|
|
6258
6434
|
if (!toolCall.providerExecuted) continue;
|
|
6259
|
-
const
|
|
6260
|
-
if ((
|
|
6435
|
+
const tool3 = getOwn(stepExecutionTools, toolCall.toolName);
|
|
6436
|
+
if ((tool3 == null ? void 0 : tool3.type) === "provider" && tool3.supportsDeferredResults) {
|
|
6261
6437
|
const hasResultInResponse = currentModelResponse.content.some(
|
|
6262
6438
|
(part) => part.type === "tool-result" && part.toolCallId === toolCall.toolCallId
|
|
6263
6439
|
);
|
|
@@ -7842,11 +8018,11 @@ function toUIMessageChunk(part, {
|
|
|
7842
8018
|
responseMessageId
|
|
7843
8019
|
} = {}) {
|
|
7844
8020
|
const isDynamic = (toolPart) => {
|
|
7845
|
-
const
|
|
7846
|
-
if (
|
|
8021
|
+
const tool3 = tools == null ? void 0 : tools[toolPart.toolName];
|
|
8022
|
+
if (tool3 == null) {
|
|
7847
8023
|
return toolPart.dynamic;
|
|
7848
8024
|
}
|
|
7849
|
-
return (
|
|
8025
|
+
return (tool3 == null ? void 0 : tool3.type) === "dynamic" ? true : void 0;
|
|
7850
8026
|
};
|
|
7851
8027
|
const partType = part.type;
|
|
7852
8028
|
switch (partType) {
|
|
@@ -8482,8 +8658,8 @@ function executeToolsFromStream({
|
|
|
8482
8658
|
if (chunk.invalid) {
|
|
8483
8659
|
return;
|
|
8484
8660
|
}
|
|
8485
|
-
const
|
|
8486
|
-
if (
|
|
8661
|
+
const tool3 = getOwn(tools, chunk.toolName);
|
|
8662
|
+
if (tool3 == null) {
|
|
8487
8663
|
return;
|
|
8488
8664
|
}
|
|
8489
8665
|
const toolApprovalStatus = await resolveToolApproval({
|
|
@@ -8495,7 +8671,7 @@ function executeToolsFromStream({
|
|
|
8495
8671
|
runtimeContext
|
|
8496
8672
|
});
|
|
8497
8673
|
if (toolApprovalStatus.type === "not-applicable") {
|
|
8498
|
-
if (
|
|
8674
|
+
if (tool3.execute != null && chunk.providerExecuted !== true) {
|
|
8499
8675
|
toolCallsToExecute.push(chunk);
|
|
8500
8676
|
}
|
|
8501
8677
|
return;
|
|
@@ -8561,7 +8737,7 @@ function executeToolsFromStream({
|
|
|
8561
8737
|
break;
|
|
8562
8738
|
}
|
|
8563
8739
|
}
|
|
8564
|
-
if (
|
|
8740
|
+
if (tool3.execute != null && chunk.providerExecuted !== true) {
|
|
8565
8741
|
toolCallsToExecute.push(chunk);
|
|
8566
8742
|
}
|
|
8567
8743
|
return;
|
|
@@ -8634,9 +8810,9 @@ function invokeToolCallbacksFromStream({
|
|
|
8634
8810
|
switch (chunk.type) {
|
|
8635
8811
|
case "tool-input-start": {
|
|
8636
8812
|
ongoingToolCallToolNames[chunk.id] = chunk.toolName;
|
|
8637
|
-
const
|
|
8638
|
-
if ((
|
|
8639
|
-
await
|
|
8813
|
+
const tool3 = getOwn(tools, chunk.toolName);
|
|
8814
|
+
if ((tool3 == null ? void 0 : tool3.onInputStart) != null) {
|
|
8815
|
+
await tool3.onInputStart({
|
|
8640
8816
|
toolCallId: chunk.id,
|
|
8641
8817
|
messages: stepInputMessages,
|
|
8642
8818
|
abortSignal,
|
|
@@ -8647,9 +8823,9 @@ function invokeToolCallbacksFromStream({
|
|
|
8647
8823
|
}
|
|
8648
8824
|
case "tool-input-delta": {
|
|
8649
8825
|
const toolName = ongoingToolCallToolNames[chunk.id];
|
|
8650
|
-
const
|
|
8651
|
-
if ((
|
|
8652
|
-
await
|
|
8826
|
+
const tool3 = getOwn(tools, toolName);
|
|
8827
|
+
if ((tool3 == null ? void 0 : tool3.onInputDelta) != null) {
|
|
8828
|
+
await tool3.onInputDelta({
|
|
8653
8829
|
inputTextDelta: chunk.delta,
|
|
8654
8830
|
toolCallId: chunk.id,
|
|
8655
8831
|
messages: stepInputMessages,
|
|
@@ -8661,10 +8837,10 @@ function invokeToolCallbacksFromStream({
|
|
|
8661
8837
|
}
|
|
8662
8838
|
case "tool-call": {
|
|
8663
8839
|
const toolName = ongoingToolCallToolNames[chunk.toolCallId];
|
|
8664
|
-
const
|
|
8840
|
+
const tool3 = getOwn(tools, toolName);
|
|
8665
8841
|
delete ongoingToolCallToolNames[chunk.toolCallId];
|
|
8666
|
-
if ((
|
|
8667
|
-
await
|
|
8842
|
+
if ((tool3 == null ? void 0 : tool3.onInputAvailable) != null) {
|
|
8843
|
+
await tool3.onInputAvailable({
|
|
8668
8844
|
input: chunk.input,
|
|
8669
8845
|
toolCallId: chunk.toolCallId,
|
|
8670
8846
|
messages: stepInputMessages,
|
|
@@ -9191,12 +9367,12 @@ function createLanguageModelV4StreamPartToLanguageModelStreamPartTransform({
|
|
|
9191
9367
|
break;
|
|
9192
9368
|
}
|
|
9193
9369
|
case "tool-input-start": {
|
|
9194
|
-
const
|
|
9370
|
+
const tool3 = getOwn(tools, chunk.toolName);
|
|
9195
9371
|
controller.enqueue({
|
|
9196
9372
|
...chunk,
|
|
9197
|
-
dynamic: (_a25 = chunk.dynamic) != null ? _a25 : (
|
|
9198
|
-
title:
|
|
9199
|
-
...(
|
|
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 } : {}
|
|
9200
9376
|
});
|
|
9201
9377
|
break;
|
|
9202
9378
|
}
|
|
@@ -9736,6 +9912,10 @@ var DefaultStreamTextResult = class {
|
|
|
9736
9912
|
tools,
|
|
9737
9913
|
toolCallers: experimental_toolCallers
|
|
9738
9914
|
});
|
|
9915
|
+
const prepareToolSearch = createToolSearchState({
|
|
9916
|
+
tools,
|
|
9917
|
+
toolCallers: resolvedToolCallers
|
|
9918
|
+
});
|
|
9739
9919
|
const telemetryDispatcher = createRestrictedTelemetryDispatcher({
|
|
9740
9920
|
telemetry,
|
|
9741
9921
|
includeRuntimeContext: telemetry == null ? void 0 : telemetry.includeRuntimeContext,
|
|
@@ -10444,7 +10624,10 @@ var DefaultStreamTextResult = class {
|
|
|
10444
10624
|
modelTools: stepModelTools,
|
|
10445
10625
|
toolCallerMessages
|
|
10446
10626
|
} = prepareToolsForToolCallers({
|
|
10447
|
-
tools: stepActiveTools,
|
|
10627
|
+
tools: prepareToolSearch(stepActiveTools, {
|
|
10628
|
+
toolsContext,
|
|
10629
|
+
experimental_sandbox: stepSandbox
|
|
10630
|
+
}),
|
|
10448
10631
|
toolCallers: resolvedToolCallers
|
|
10449
10632
|
});
|
|
10450
10633
|
const stepToolOrder = (_g = prepareStepResult == null ? void 0 : prepareStepResult.toolOrder) != null ? _g : toolOrder;
|
|
@@ -10962,8 +11145,8 @@ var DefaultStreamTextResult = class {
|
|
|
10962
11145
|
);
|
|
10963
11146
|
for (const toolCall of stepToolCalls) {
|
|
10964
11147
|
if (toolCall.providerExecuted !== true) continue;
|
|
10965
|
-
const
|
|
10966
|
-
if ((
|
|
11148
|
+
const tool3 = getOwn(stepExecutionTools, toolCall.toolName);
|
|
11149
|
+
if ((tool3 == null ? void 0 : tool3.type) === "provider" && tool3.supportsDeferredResults) {
|
|
10967
11150
|
const hasResultInStep = stepToolOutputs.some(
|
|
10968
11151
|
(output2) => (output2.type === "tool-result" || output2.type === "tool-error") && output2.toolCallId === toolCall.toolCallId
|
|
10969
11152
|
);
|
|
@@ -12471,9 +12654,9 @@ async function safeValidateUIMessagesInternal({
|
|
|
12471
12654
|
if (shouldValidateToolParts && part.type.startsWith("tool-")) {
|
|
12472
12655
|
const toolPart = part;
|
|
12473
12656
|
const toolName = toolPart.type.slice(5);
|
|
12474
|
-
const
|
|
12657
|
+
const tool3 = tools == null ? void 0 : getOwn(tools, toolName);
|
|
12475
12658
|
const isTerminal = toolPart.state === "output-available" || toolPart.state === "output-error" || toolPart.state === "output-denied";
|
|
12476
|
-
if (!
|
|
12659
|
+
if (!tool3 && isTerminal) {
|
|
12477
12660
|
if (tools != null || convertMissingTerminalToolsToDynamic) {
|
|
12478
12661
|
message.parts[partIdx] = asDynamicToolPart(
|
|
12479
12662
|
toolPart
|
|
@@ -12481,7 +12664,7 @@ async function safeValidateUIMessagesInternal({
|
|
|
12481
12664
|
}
|
|
12482
12665
|
continue;
|
|
12483
12666
|
}
|
|
12484
|
-
if (!
|
|
12667
|
+
if (!tool3) {
|
|
12485
12668
|
return {
|
|
12486
12669
|
success: false,
|
|
12487
12670
|
error: new TypeValidationError3({
|
|
@@ -12505,7 +12688,7 @@ async function safeValidateUIMessagesInternal({
|
|
|
12505
12688
|
if (toolPart.input !== void 0) {
|
|
12506
12689
|
const result = await safeValidateTypes5({
|
|
12507
12690
|
value: toolPart.input,
|
|
12508
|
-
schema:
|
|
12691
|
+
schema: tool3.inputSchema,
|
|
12509
12692
|
context: inputValidationContext
|
|
12510
12693
|
});
|
|
12511
12694
|
convertToDynamic = !result.success;
|
|
@@ -12513,7 +12696,7 @@ async function safeValidateUIMessagesInternal({
|
|
|
12513
12696
|
} else if (toolPart.state === "output-available") {
|
|
12514
12697
|
const result = await safeValidateTypes5({
|
|
12515
12698
|
value: toolPart.input,
|
|
12516
|
-
schema:
|
|
12699
|
+
schema: tool3.inputSchema,
|
|
12517
12700
|
context: inputValidationContext
|
|
12518
12701
|
});
|
|
12519
12702
|
if (!result.success) {
|
|
@@ -12526,14 +12709,14 @@ async function safeValidateUIMessagesInternal({
|
|
|
12526
12709
|
} else if (toolPart.state === "input-available" || toolPart.state === "approval-requested" || toolPart.state === "approval-responded" || toolPart.state === "output-denied") {
|
|
12527
12710
|
await validateTypes4({
|
|
12528
12711
|
value: toolPart.input,
|
|
12529
|
-
schema:
|
|
12712
|
+
schema: tool3.inputSchema,
|
|
12530
12713
|
context: inputValidationContext
|
|
12531
12714
|
});
|
|
12532
12715
|
}
|
|
12533
|
-
if (toolPart.state === "output-available" &&
|
|
12716
|
+
if (toolPart.state === "output-available" && tool3.outputSchema) {
|
|
12534
12717
|
await validateTypes4({
|
|
12535
12718
|
value: toolPart.output,
|
|
12536
|
-
schema:
|
|
12719
|
+
schema: tool3.outputSchema,
|
|
12537
12720
|
context: {
|
|
12538
12721
|
field: `messages[${msgIdx}].parts[${partIdx}].output`,
|
|
12539
12722
|
entityName: toolName,
|
|
@@ -13216,16 +13399,16 @@ function validateCompatibleTools({
|
|
|
13216
13399
|
tools,
|
|
13217
13400
|
toolsByName
|
|
13218
13401
|
}) {
|
|
13219
|
-
for (const
|
|
13220
|
-
const previousTool = toolsByName.get(
|
|
13221
|
-
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)) {
|
|
13222
13405
|
throw new InvalidArgumentError({
|
|
13223
13406
|
parameter: "requests",
|
|
13224
13407
|
value: requestId,
|
|
13225
|
-
message: `tool "${
|
|
13408
|
+
message: `tool "${tool3.name}" must have the same definition in every batch request`
|
|
13226
13409
|
});
|
|
13227
13410
|
}
|
|
13228
|
-
toolsByName.set(
|
|
13411
|
+
toolsByName.set(tool3.name, tool3);
|
|
13229
13412
|
}
|
|
13230
13413
|
}
|
|
13231
13414
|
async function getBatchStatus({
|
|
@@ -14295,7 +14478,7 @@ function validateEvaluationAnswers({
|
|
|
14295
14478
|
|
|
14296
14479
|
// src/evaluate/evaluate.ts
|
|
14297
14480
|
async function evaluate({
|
|
14298
|
-
model,
|
|
14481
|
+
model: modelArg,
|
|
14299
14482
|
state,
|
|
14300
14483
|
questions,
|
|
14301
14484
|
maxRetries,
|
|
@@ -14304,13 +14487,7 @@ async function evaluate({
|
|
|
14304
14487
|
providerOptions = {}
|
|
14305
14488
|
}) {
|
|
14306
14489
|
var _a25, _b25, _c, _d, _e, _f;
|
|
14307
|
-
|
|
14308
|
-
throw new UnsupportedModelVersionError({
|
|
14309
|
-
version: model.specificationVersion,
|
|
14310
|
-
provider: model.provider,
|
|
14311
|
-
modelId: model.modelId
|
|
14312
|
-
});
|
|
14313
|
-
}
|
|
14490
|
+
const model = resolveEvaluationModel(modelArg);
|
|
14314
14491
|
validateEvaluationInput({ state, questions });
|
|
14315
14492
|
for (const [questionId, question] of Object.entries(questions)) {
|
|
14316
14493
|
if (!model.supportedQuestionTypes.includes(question.type)) {
|
|
@@ -14909,7 +15086,7 @@ async function generateObject(options) {
|
|
|
14909
15086
|
const resolvedOnStart = onStart != null ? onStart : experimental_onStart;
|
|
14910
15087
|
const resolvedOnStepStart = onStepStart != null ? onStepStart : experimental_onStepStart;
|
|
14911
15088
|
const resolvedOnStepEnd = onStepEnd != null ? onStepEnd : onStepFinish;
|
|
14912
|
-
const
|
|
15089
|
+
const jsonSchema3 = await outputStrategy.jsonSchema();
|
|
14913
15090
|
const callId = generateId5();
|
|
14914
15091
|
await notify({
|
|
14915
15092
|
event: {
|
|
@@ -14931,7 +15108,7 @@ async function generateObject(options) {
|
|
|
14931
15108
|
headers: headersWithUserAgent,
|
|
14932
15109
|
providerOptions,
|
|
14933
15110
|
output: outputStrategy.type,
|
|
14934
|
-
schema:
|
|
15111
|
+
schema: jsonSchema3,
|
|
14935
15112
|
schemaName,
|
|
14936
15113
|
schemaDescription
|
|
14937
15114
|
},
|
|
@@ -14967,7 +15144,7 @@ async function generateObject(options) {
|
|
|
14967
15144
|
() => model.doGenerate({
|
|
14968
15145
|
responseFormat: {
|
|
14969
15146
|
type: "json",
|
|
14970
|
-
schema:
|
|
15147
|
+
schema: jsonSchema3,
|
|
14971
15148
|
name: schemaName,
|
|
14972
15149
|
description: schemaDescription
|
|
14973
15150
|
},
|
|
@@ -15351,7 +15528,7 @@ var DefaultStreamObjectResult = class {
|
|
|
15351
15528
|
this.baseStream = stitchableStream.stream.pipeThrough(eventProcessor);
|
|
15352
15529
|
const callId = generateId5();
|
|
15353
15530
|
(async () => {
|
|
15354
|
-
const
|
|
15531
|
+
const jsonSchema3 = await outputStrategy.jsonSchema();
|
|
15355
15532
|
await notify({
|
|
15356
15533
|
event: {
|
|
15357
15534
|
callId,
|
|
@@ -15372,7 +15549,7 @@ var DefaultStreamObjectResult = class {
|
|
|
15372
15549
|
headers,
|
|
15373
15550
|
providerOptions,
|
|
15374
15551
|
output: outputStrategy.type,
|
|
15375
|
-
schema:
|
|
15552
|
+
schema: jsonSchema3,
|
|
15376
15553
|
schemaName,
|
|
15377
15554
|
schemaDescription
|
|
15378
15555
|
},
|
|
@@ -15388,7 +15565,7 @@ var DefaultStreamObjectResult = class {
|
|
|
15388
15565
|
const callOptions = {
|
|
15389
15566
|
responseFormat: {
|
|
15390
15567
|
type: "json",
|
|
15391
|
-
schema:
|
|
15568
|
+
schema: jsonSchema3,
|
|
15392
15569
|
name: schemaName,
|
|
15393
15570
|
description: schemaDescription
|
|
15394
15571
|
},
|
|
@@ -16085,11 +16262,11 @@ function tagDescription(description) {
|
|
|
16085
16262
|
async function fingerprintTools(tools) {
|
|
16086
16263
|
const entries = await Promise.all(
|
|
16087
16264
|
Object.keys(tools).map(async (name25) => {
|
|
16088
|
-
const
|
|
16265
|
+
const tool3 = tools[name25];
|
|
16089
16266
|
const digest = await hashCanonical({
|
|
16090
|
-
description: tagDescription(
|
|
16091
|
-
inputSchema: await asSchema6(
|
|
16092
|
-
title:
|
|
16267
|
+
description: tagDescription(tool3.description),
|
|
16268
|
+
inputSchema: await asSchema6(tool3.inputSchema).jsonSchema,
|
|
16269
|
+
title: tool3.title
|
|
16093
16270
|
});
|
|
16094
16271
|
return [name25, digest];
|
|
16095
16272
|
})
|
|
@@ -17099,21 +17276,21 @@ function addToolInputExamplesMiddleware({
|
|
|
17099
17276
|
if (!((_a25 = params.tools) == null ? void 0 : _a25.length)) {
|
|
17100
17277
|
return params;
|
|
17101
17278
|
}
|
|
17102
|
-
const transformedTools = params.tools.map((
|
|
17279
|
+
const transformedTools = params.tools.map((tool3) => {
|
|
17103
17280
|
var _a26;
|
|
17104
|
-
if (
|
|
17105
|
-
return
|
|
17281
|
+
if (tool3.type !== "function" || !((_a26 = tool3.inputExamples) == null ? void 0 : _a26.length)) {
|
|
17282
|
+
return tool3;
|
|
17106
17283
|
}
|
|
17107
|
-
const formattedExamples =
|
|
17284
|
+
const formattedExamples = tool3.inputExamples.map((example, index) => format(example, index)).join("\n");
|
|
17108
17285
|
const examplesSection = `${prefix}
|
|
17109
17286
|
${formattedExamples}`;
|
|
17110
|
-
const toolDescription =
|
|
17287
|
+
const toolDescription = tool3.description ? `${tool3.description}
|
|
17111
17288
|
|
|
17112
17289
|
${examplesSection}` : examplesSection;
|
|
17113
17290
|
return {
|
|
17114
|
-
...
|
|
17291
|
+
...tool3,
|
|
17115
17292
|
description: toolDescription,
|
|
17116
|
-
inputExamples: remove ? void 0 :
|
|
17293
|
+
inputExamples: remove ? void 0 : tool3.inputExamples
|
|
17117
17294
|
};
|
|
17118
17295
|
});
|
|
17119
17296
|
return {
|
|
@@ -17372,14 +17549,14 @@ async function getRealtimeToolDefinitions({
|
|
|
17372
17549
|
toolsContext = {}
|
|
17373
17550
|
}) {
|
|
17374
17551
|
const definitions = [];
|
|
17375
|
-
for (const [name25,
|
|
17376
|
-
const toolType =
|
|
17552
|
+
for (const [name25, tool3] of Object.entries(tools)) {
|
|
17553
|
+
const toolType = tool3.type;
|
|
17377
17554
|
switch (toolType) {
|
|
17378
17555
|
case void 0:
|
|
17379
17556
|
case "function":
|
|
17380
17557
|
case "dynamic": {
|
|
17381
17558
|
const description = resolveRealtimeToolDescription({
|
|
17382
|
-
tool:
|
|
17559
|
+
tool: tool3,
|
|
17383
17560
|
toolName: name25,
|
|
17384
17561
|
toolsContext
|
|
17385
17562
|
});
|
|
@@ -17387,7 +17564,7 @@ async function getRealtimeToolDefinitions({
|
|
|
17387
17564
|
type: "function",
|
|
17388
17565
|
name: name25,
|
|
17389
17566
|
description,
|
|
17390
|
-
parameters: await asSchema7(
|
|
17567
|
+
parameters: await asSchema7(tool3.inputSchema).jsonSchema
|
|
17391
17568
|
});
|
|
17392
17569
|
break;
|
|
17393
17570
|
}
|
|
@@ -17402,11 +17579,11 @@ async function getRealtimeToolDefinitions({
|
|
|
17402
17579
|
return definitions;
|
|
17403
17580
|
}
|
|
17404
17581
|
function resolveRealtimeToolDescription({
|
|
17405
|
-
tool:
|
|
17582
|
+
tool: tool3,
|
|
17406
17583
|
toolName,
|
|
17407
17584
|
toolsContext
|
|
17408
17585
|
}) {
|
|
17409
|
-
return
|
|
17586
|
+
return tool3.description === void 0 ? void 0 : typeof tool3.description === "string" ? tool3.description : tool3.description({
|
|
17410
17587
|
context: toolsContext[toolName]
|
|
17411
17588
|
});
|
|
17412
17589
|
}
|
|
@@ -17652,6 +17829,9 @@ var RealtimeEventChannel = class {
|
|
|
17652
17829
|
var _a25, _b25, _c;
|
|
17653
17830
|
this.parse = (_c = (_b25 = (_a25 = options.model).createServerEventParser) == null ? void 0 : _b25.call(_a25)) != null ? _c : options.model.parseServerEvent.bind(options.model);
|
|
17654
17831
|
}
|
|
17832
|
+
get hasPendingIncoming() {
|
|
17833
|
+
return this.incomingCount > 0;
|
|
17834
|
+
}
|
|
17655
17835
|
dispose() {
|
|
17656
17836
|
this.active = false;
|
|
17657
17837
|
}
|
|
@@ -17896,9 +18076,18 @@ var BrowserRealtimeTransport = class {
|
|
|
17896
18076
|
if (this.ws === ws) {
|
|
17897
18077
|
this.ws = null;
|
|
17898
18078
|
const closeError = (_a26 = getCloseError(event)) != null ? _a26 : connectionError;
|
|
18079
|
+
const reportCloseErrorImmediately = closeError != null && !codec.hasPendingIncoming;
|
|
17899
18080
|
codec.stopWriting();
|
|
17900
18081
|
this.notifyClosing();
|
|
17901
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
|
+
}
|
|
17902
18091
|
const complete = () => {
|
|
17903
18092
|
if (this.epoch !== epoch) return;
|
|
17904
18093
|
clearTimeout(this.drainTimer);
|
|
@@ -17911,7 +18100,7 @@ var BrowserRealtimeTransport = class {
|
|
|
17911
18100
|
}
|
|
17912
18101
|
};
|
|
17913
18102
|
this.drainTimer = setTimeout(complete, 1e3);
|
|
17914
|
-
void this.awaitDrain(
|
|
18103
|
+
void this.awaitDrain(drain, complete);
|
|
17915
18104
|
}
|
|
17916
18105
|
};
|
|
17917
18106
|
}
|
|
@@ -19354,6 +19543,7 @@ var AbstractRealtimeSession = class {
|
|
|
19354
19543
|
if (current())
|
|
19355
19544
|
this.fail(new Error("Realtime session startup timed out"));
|
|
19356
19545
|
});
|
|
19546
|
+
const reportedTransportErrors = /* @__PURE__ */ new WeakSet();
|
|
19357
19547
|
const callbacks = {
|
|
19358
19548
|
model,
|
|
19359
19549
|
onEvent: async (event) => {
|
|
@@ -19370,7 +19560,10 @@ var AbstractRealtimeSession = class {
|
|
|
19370
19560
|
}
|
|
19371
19561
|
},
|
|
19372
19562
|
onError: (error) => {
|
|
19373
|
-
if (current())
|
|
19563
|
+
if (current()) {
|
|
19564
|
+
reportedTransportErrors.add(error);
|
|
19565
|
+
void this.reportError(error, attempt);
|
|
19566
|
+
}
|
|
19374
19567
|
},
|
|
19375
19568
|
onFatalError: (error, drain) => {
|
|
19376
19569
|
if (current()) this.fail(error, drain);
|
|
@@ -19392,7 +19585,8 @@ var AbstractRealtimeSession = class {
|
|
|
19392
19585
|
var _a26, _b26;
|
|
19393
19586
|
if (!current()) return;
|
|
19394
19587
|
const finalizationConfirmed = ((_a26 = model.capabilities) == null ? void 0 : _a26.finalization) === "session-close" && ((_b26 = this.state.session) == null ? void 0 : _b26.finalization) === "confirmed";
|
|
19395
|
-
if (error != null && !finalizationConfirmed)
|
|
19588
|
+
if (error != null && !finalizationConfirmed)
|
|
19589
|
+
this.fail(error, void 0, !reportedTransportErrors.has(error));
|
|
19396
19590
|
else if (!attempt.ready && !finalizationConfirmed)
|
|
19397
19591
|
this.fail(
|
|
19398
19592
|
new Error("Realtime connection closed before becoming ready")
|
|
@@ -19490,7 +19684,7 @@ var AbstractRealtimeSession = class {
|
|
|
19490
19684
|
if (current()) this.fail(error);
|
|
19491
19685
|
}
|
|
19492
19686
|
}
|
|
19493
|
-
fail(error, drain) {
|
|
19687
|
+
fail(error, drain, report = true) {
|
|
19494
19688
|
const attempt = this.attempt;
|
|
19495
19689
|
if (attempt == null || !attempt.active || attempt.cause != null) return;
|
|
19496
19690
|
attempt.cause = error instanceof Error ? error : new Error(String(error));
|
|
@@ -19501,7 +19695,7 @@ var AbstractRealtimeSession = class {
|
|
|
19501
19695
|
if (this.attempt !== attempt || !attempt.active) return;
|
|
19502
19696
|
if (drain == null) this.disconnect();
|
|
19503
19697
|
else void this.drainAttempt(attempt, drain);
|
|
19504
|
-
void this.reportError(attempt.cause, attempt);
|
|
19698
|
+
if (report) void this.reportError(attempt.cause, attempt);
|
|
19505
19699
|
}
|
|
19506
19700
|
async drainAttempt(attempt, drain) {
|
|
19507
19701
|
if (this.attempt === attempt && attempt.active)
|
|
@@ -19956,7 +20150,7 @@ var AbstractRealtimeSession = class {
|
|
|
19956
20150
|
|
|
19957
20151
|
// src/registry/custom-provider.ts
|
|
19958
20152
|
import {
|
|
19959
|
-
NoSuchModelError as
|
|
20153
|
+
NoSuchModelError as NoSuchModelError3
|
|
19960
20154
|
} from "@ai-sdk/provider";
|
|
19961
20155
|
function customProvider({
|
|
19962
20156
|
languageModels,
|
|
@@ -19966,6 +20160,7 @@ function customProvider({
|
|
|
19966
20160
|
speechModels,
|
|
19967
20161
|
rerankingModels,
|
|
19968
20162
|
videoModels,
|
|
20163
|
+
evaluationModels,
|
|
19969
20164
|
files,
|
|
19970
20165
|
skills,
|
|
19971
20166
|
fallbackProvider: fallbackProviderArg
|
|
@@ -19980,7 +20175,7 @@ function customProvider({
|
|
|
19980
20175
|
if (fallbackProvider) {
|
|
19981
20176
|
return fallbackProvider.languageModel(modelId);
|
|
19982
20177
|
}
|
|
19983
|
-
throw new
|
|
20178
|
+
throw new NoSuchModelError3({ modelId, modelType: "languageModel" });
|
|
19984
20179
|
},
|
|
19985
20180
|
embeddingModel(modelId) {
|
|
19986
20181
|
if (embeddingModels != null && modelId in embeddingModels) {
|
|
@@ -19989,7 +20184,7 @@ function customProvider({
|
|
|
19989
20184
|
if (fallbackProvider) {
|
|
19990
20185
|
return fallbackProvider.embeddingModel(modelId);
|
|
19991
20186
|
}
|
|
19992
|
-
throw new
|
|
20187
|
+
throw new NoSuchModelError3({ modelId, modelType: "embeddingModel" });
|
|
19993
20188
|
},
|
|
19994
20189
|
imageModel(modelId) {
|
|
19995
20190
|
if (imageModels != null && modelId in imageModels) {
|
|
@@ -19998,7 +20193,7 @@ function customProvider({
|
|
|
19998
20193
|
if (fallbackProvider == null ? void 0 : fallbackProvider.imageModel) {
|
|
19999
20194
|
return fallbackProvider.imageModel(modelId);
|
|
20000
20195
|
}
|
|
20001
|
-
throw new
|
|
20196
|
+
throw new NoSuchModelError3({ modelId, modelType: "imageModel" });
|
|
20002
20197
|
},
|
|
20003
20198
|
transcriptionModel(modelId) {
|
|
20004
20199
|
if (transcriptionModels != null && modelId in transcriptionModels) {
|
|
@@ -20010,7 +20205,7 @@ function customProvider({
|
|
|
20010
20205
|
if (fallbackProvider == null ? void 0 : fallbackProvider.transcriptionModel) {
|
|
20011
20206
|
return fallbackProvider.transcriptionModel(modelId);
|
|
20012
20207
|
}
|
|
20013
|
-
throw new
|
|
20208
|
+
throw new NoSuchModelError3({ modelId, modelType: "transcriptionModel" });
|
|
20014
20209
|
},
|
|
20015
20210
|
speechModel(modelId) {
|
|
20016
20211
|
if (speechModels != null && modelId in speechModels) {
|
|
@@ -20022,7 +20217,7 @@ function customProvider({
|
|
|
20022
20217
|
if (fallbackProvider == null ? void 0 : fallbackProvider.speechModel) {
|
|
20023
20218
|
return fallbackProvider.speechModel(modelId);
|
|
20024
20219
|
}
|
|
20025
|
-
throw new
|
|
20220
|
+
throw new NoSuchModelError3({ modelId, modelType: "speechModel" });
|
|
20026
20221
|
},
|
|
20027
20222
|
rerankingModel(modelId) {
|
|
20028
20223
|
if (rerankingModels != null && modelId in rerankingModels) {
|
|
@@ -20031,7 +20226,20 @@ function customProvider({
|
|
|
20031
20226
|
if (fallbackProvider == null ? void 0 : fallbackProvider.rerankingModel) {
|
|
20032
20227
|
return fallbackProvider.rerankingModel(modelId);
|
|
20033
20228
|
}
|
|
20034
|
-
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" });
|
|
20035
20243
|
},
|
|
20036
20244
|
videoModel(modelId) {
|
|
20037
20245
|
if (videoModels != null && modelId in videoModels) {
|
|
@@ -20041,7 +20249,7 @@ function customProvider({
|
|
|
20041
20249
|
if (videoModel) {
|
|
20042
20250
|
return videoModel(modelId);
|
|
20043
20251
|
}
|
|
20044
|
-
throw new
|
|
20252
|
+
throw new NoSuchModelError3({ modelId, modelType: "videoModel" });
|
|
20045
20253
|
}
|
|
20046
20254
|
};
|
|
20047
20255
|
const filesAndSkills = {
|
|
@@ -20060,12 +20268,12 @@ function customProvider({
|
|
|
20060
20268
|
}
|
|
20061
20269
|
|
|
20062
20270
|
// src/registry/no-such-provider-error.ts
|
|
20063
|
-
import { AISDKError as AISDKError28, NoSuchModelError as
|
|
20271
|
+
import { AISDKError as AISDKError28, NoSuchModelError as NoSuchModelError4 } from "@ai-sdk/provider";
|
|
20064
20272
|
var name24 = "AI_NoSuchProviderError";
|
|
20065
20273
|
var marker24 = `vercel.ai.error.${name24}`;
|
|
20066
20274
|
var symbol24 = Symbol.for(marker24);
|
|
20067
20275
|
var _a24, _b24;
|
|
20068
|
-
var NoSuchProviderError = class extends (_b24 =
|
|
20276
|
+
var NoSuchProviderError = class extends (_b24 = NoSuchModelError4, _a24 = symbol24, _b24) {
|
|
20069
20277
|
constructor({
|
|
20070
20278
|
modelId,
|
|
20071
20279
|
modelType,
|
|
@@ -20085,7 +20293,7 @@ var NoSuchProviderError = class extends (_b24 = NoSuchModelError3, _a24 = symbol
|
|
|
20085
20293
|
|
|
20086
20294
|
// src/registry/provider-registry.ts
|
|
20087
20295
|
import {
|
|
20088
|
-
NoSuchModelError as
|
|
20296
|
+
NoSuchModelError as NoSuchModelError5
|
|
20089
20297
|
} from "@ai-sdk/provider";
|
|
20090
20298
|
function createProviderRegistry(providers, {
|
|
20091
20299
|
separator = ":",
|
|
@@ -20118,13 +20326,18 @@ var DefaultProviderRegistry = class {
|
|
|
20118
20326
|
id,
|
|
20119
20327
|
provider
|
|
20120
20328
|
}) {
|
|
20121
|
-
var _a25;
|
|
20329
|
+
var _a25, _b25;
|
|
20122
20330
|
const providerV4 = asProviderV4(provider);
|
|
20123
20331
|
const videoModel = (_a25 = provider.videoModel) == null ? void 0 : _a25.bind(provider);
|
|
20124
|
-
|
|
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)), {
|
|
20125
20334
|
...providerV4,
|
|
20126
20335
|
videoModel: (modelId) => asVideoModelV4(videoModel(modelId))
|
|
20127
20336
|
});
|
|
20337
|
+
if (registeredProvider !== provider && evaluationModel != null) {
|
|
20338
|
+
Object.assign(registeredProvider, { evaluationModel });
|
|
20339
|
+
}
|
|
20340
|
+
this.providers[id] = registeredProvider;
|
|
20128
20341
|
}
|
|
20129
20342
|
getProvider(id, modelType) {
|
|
20130
20343
|
const provider = this.providers[id];
|
|
@@ -20141,7 +20354,7 @@ var DefaultProviderRegistry = class {
|
|
|
20141
20354
|
splitId(id, modelType) {
|
|
20142
20355
|
const index = id.indexOf(this.separator);
|
|
20143
20356
|
if (index === -1) {
|
|
20144
|
-
throw new
|
|
20357
|
+
throw new NoSuchModelError5({
|
|
20145
20358
|
modelId: id,
|
|
20146
20359
|
modelType,
|
|
20147
20360
|
message: `Invalid ${modelType} id for registry: ${id} (must be in the format "providerId${this.separator}modelId")`
|
|
@@ -20157,7 +20370,7 @@ var DefaultProviderRegistry = class {
|
|
|
20157
20370
|
modelId
|
|
20158
20371
|
);
|
|
20159
20372
|
if (model == null) {
|
|
20160
|
-
throw new
|
|
20373
|
+
throw new NoSuchModelError5({ modelId: id, modelType: "languageModel" });
|
|
20161
20374
|
}
|
|
20162
20375
|
if (this.languageModelMiddleware != null) {
|
|
20163
20376
|
model = wrapLanguageModel({
|
|
@@ -20173,7 +20386,7 @@ var DefaultProviderRegistry = class {
|
|
|
20173
20386
|
const provider = this.getProvider(providerId, "embeddingModel");
|
|
20174
20387
|
const model = (_a25 = provider.embeddingModel) == null ? void 0 : _a25.call(provider, modelId);
|
|
20175
20388
|
if (model == null) {
|
|
20176
|
-
throw new
|
|
20389
|
+
throw new NoSuchModelError5({
|
|
20177
20390
|
modelId: id,
|
|
20178
20391
|
modelType: "embeddingModel"
|
|
20179
20392
|
});
|
|
@@ -20186,7 +20399,7 @@ var DefaultProviderRegistry = class {
|
|
|
20186
20399
|
const provider = this.getProvider(providerId, "imageModel");
|
|
20187
20400
|
let model = (_a25 = provider.imageModel) == null ? void 0 : _a25.call(provider, modelId);
|
|
20188
20401
|
if (model == null) {
|
|
20189
|
-
throw new
|
|
20402
|
+
throw new NoSuchModelError5({ modelId: id, modelType: "imageModel" });
|
|
20190
20403
|
}
|
|
20191
20404
|
if (this.imageModelMiddleware != null) {
|
|
20192
20405
|
model = wrapImageModel({
|
|
@@ -20202,7 +20415,7 @@ var DefaultProviderRegistry = class {
|
|
|
20202
20415
|
const provider = this.getProvider(providerId, "transcriptionModel");
|
|
20203
20416
|
const model = (_a25 = provider.transcriptionModel) == null ? void 0 : _a25.call(provider, modelId);
|
|
20204
20417
|
if (model == null) {
|
|
20205
|
-
throw new
|
|
20418
|
+
throw new NoSuchModelError5({
|
|
20206
20419
|
modelId: id,
|
|
20207
20420
|
modelType: "transcriptionModel"
|
|
20208
20421
|
});
|
|
@@ -20215,7 +20428,7 @@ var DefaultProviderRegistry = class {
|
|
|
20215
20428
|
const provider = this.getProvider(providerId, "speechModel");
|
|
20216
20429
|
const model = (_a25 = provider.speechModel) == null ? void 0 : _a25.call(provider, modelId);
|
|
20217
20430
|
if (model == null) {
|
|
20218
|
-
throw new
|
|
20431
|
+
throw new NoSuchModelError5({ modelId: id, modelType: "speechModel" });
|
|
20219
20432
|
}
|
|
20220
20433
|
return model;
|
|
20221
20434
|
}
|
|
@@ -20225,7 +20438,7 @@ var DefaultProviderRegistry = class {
|
|
|
20225
20438
|
const provider = this.getProvider(providerId, "rerankingModel");
|
|
20226
20439
|
const model = (_a25 = provider.rerankingModel) == null ? void 0 : _a25.call(provider, modelId);
|
|
20227
20440
|
if (model == null) {
|
|
20228
|
-
throw new
|
|
20441
|
+
throw new NoSuchModelError5({ modelId: id, modelType: "rerankingModel" });
|
|
20229
20442
|
}
|
|
20230
20443
|
return model;
|
|
20231
20444
|
}
|
|
@@ -20235,10 +20448,20 @@ var DefaultProviderRegistry = class {
|
|
|
20235
20448
|
const provider = this.getProvider(providerId, "videoModel");
|
|
20236
20449
|
const model = (_a25 = provider.videoModel) == null ? void 0 : _a25.call(provider, modelId);
|
|
20237
20450
|
if (model == null) {
|
|
20238
|
-
throw new
|
|
20451
|
+
throw new NoSuchModelError5({ modelId: id, modelType: "videoModel" });
|
|
20239
20452
|
}
|
|
20240
20453
|
return asVideoModelV4(model);
|
|
20241
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
|
+
}
|
|
20242
20465
|
files(id) {
|
|
20243
20466
|
var _a25;
|
|
20244
20467
|
const provider = this.getProvider(id, "languageModel");
|
|
@@ -22224,7 +22447,7 @@ export {
|
|
|
22224
22447
|
isTextUIPart,
|
|
22225
22448
|
isToolOutputErrorUIPart,
|
|
22226
22449
|
isToolUIPart,
|
|
22227
|
-
jsonSchema,
|
|
22450
|
+
jsonSchema2 as jsonSchema,
|
|
22228
22451
|
lastAssistantMessageIsCompleteWithApprovalResponses,
|
|
22229
22452
|
lastAssistantMessageIsCompleteWithToolCalls,
|
|
22230
22453
|
modelMessageSchema,
|
|
@@ -22248,8 +22471,9 @@ export {
|
|
|
22248
22471
|
toTextStream,
|
|
22249
22472
|
toUIMessageChunk,
|
|
22250
22473
|
toUIMessageStream,
|
|
22251
|
-
tool,
|
|
22474
|
+
tool2 as tool,
|
|
22252
22475
|
toolModelMessageSchema,
|
|
22476
|
+
toolSearch,
|
|
22253
22477
|
transcribe,
|
|
22254
22478
|
uiMessageChunkSchema,
|
|
22255
22479
|
uploadFile,
|