ai 7.0.103 → 7.0.105

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.
Files changed (41) hide show
  1. package/CHANGELOG.md +26 -0
  2. package/dist/index.d.ts +37 -7
  3. package/dist/index.js +523 -298
  4. package/dist/index.js.map +1 -1
  5. package/dist/internal/index.d.ts +1 -0
  6. package/dist/internal/index.js +4 -1
  7. package/dist/internal/index.js.map +1 -1
  8. package/docs/03-ai-sdk-core/18-code-mode.mdx +11 -0
  9. package/docs/03-ai-sdk-core/19-tool-search.mdx +80 -0
  10. package/docs/03-ai-sdk-core/32-evaluation.mdx +171 -7
  11. package/docs/03-ai-sdk-core/45-provider-management.mdx +10 -0
  12. package/docs/03-ai-sdk-core/index.mdx +6 -0
  13. package/docs/07-reference/01-ai-sdk-core/14-evaluate.mdx +22 -9
  14. package/docs/07-reference/01-ai-sdk-core/20-tool.mdx +7 -0
  15. package/docs/07-reference/01-ai-sdk-core/22-dynamic-tool.mdx +7 -0
  16. package/docs/07-reference/01-ai-sdk-core/23-tool-search.mdx +75 -0
  17. package/docs/07-reference/01-ai-sdk-core/40-provider-registry.mdx +18 -0
  18. package/docs/07-reference/01-ai-sdk-core/42-custom-provider.mdx +18 -0
  19. package/docs/07-reference/01-ai-sdk-core/index.mdx +6 -0
  20. package/docs/07-reference/05-ai-sdk-errors/ai-no-such-model-error.mdx +4 -0
  21. package/docs/07-reference/05-ai-sdk-errors/ai-no-such-provider-error.mdx +4 -0
  22. package/package.json +12 -12
  23. package/src/evaluate/evaluate.ts +4 -10
  24. package/src/evaluate/evaluation-provider.ts +6 -0
  25. package/src/evaluate/evaluation-result.ts +1 -1
  26. package/src/generate-text/generate-text.ts +9 -1
  27. package/src/generate-text/stream-text.ts +9 -1
  28. package/src/generate-text/tool-caller-configuration.ts +1 -1
  29. package/src/global.ts +1 -0
  30. package/src/index.ts +1 -0
  31. package/src/model/resolve-model.ts +53 -10
  32. package/src/prompt/prepare-tools.ts +1 -1
  33. package/src/realtime/browser-realtime-transport.ts +12 -1
  34. package/src/realtime/realtime-event-channel.ts +4 -0
  35. package/src/realtime/realtime-session.ts +9 -4
  36. package/src/registry/custom-provider.ts +37 -0
  37. package/src/registry/index.ts +2 -0
  38. package/src/registry/no-such-provider-error.ts +2 -1
  39. package/src/registry/provider-registry.ts +65 -6
  40. package/src/tool-search/prepare-tool-search.ts +143 -0
  41. 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,35 @@ function resolveRerankingModel(model) {
1125
1128
  }
1126
1129
  return asRerankingModelV4(model);
1127
1130
  }
1131
+ function resolveEvaluationModel(model) {
1132
+ var _a25;
1133
+ if (typeof model === "string") {
1134
+ const provider = (_a25 = globalThis.AI_SDK_DEFAULT_PROVIDER) != null ? _a25 : gateway;
1135
+ if (typeof (provider == null ? void 0 : provider.evaluationModel) !== "function") {
1136
+ throw new NoSuchModelError2({
1137
+ modelId: model,
1138
+ modelType: "evaluationModel",
1139
+ message: "The default provider does not support evaluation models. Pass an evaluation model instance or configure AI_SDK_DEFAULT_PROVIDER with an evaluationModel method."
1140
+ });
1141
+ }
1142
+ const resolvedModel = provider.evaluationModel(model);
1143
+ if (resolvedModel == null) {
1144
+ throw new NoSuchModelError2({
1145
+ modelId: model,
1146
+ modelType: "evaluationModel"
1147
+ });
1148
+ }
1149
+ model = resolvedModel;
1150
+ }
1151
+ if (model.specificationVersion !== "v4") {
1152
+ throw new UnsupportedModelVersionError({
1153
+ version: model.specificationVersion,
1154
+ provider: model.provider,
1155
+ modelId: model.modelId
1156
+ });
1157
+ }
1158
+ return model;
1159
+ }
1128
1160
  function getGlobalProvider() {
1129
1161
  var _a25;
1130
1162
  const provider = (_a25 = globalThis.AI_SDK_DEFAULT_PROVIDER) != null ? _a25 : gateway;
@@ -1179,7 +1211,7 @@ import {
1179
1211
  } from "@ai-sdk/provider-utils";
1180
1212
 
1181
1213
  // src/version.ts
1182
- var VERSION = true ? "7.0.103" : "0.0.0-test";
1214
+ var VERSION = true ? "7.0.105" : "0.0.0-test";
1183
1215
 
1184
1216
  // src/util/download/download.ts
1185
1217
  var download = async ({
@@ -2015,7 +2047,7 @@ async function createToolModelOutput({
2015
2047
  toolCallId,
2016
2048
  input,
2017
2049
  output,
2018
- tool: tool2,
2050
+ tool: tool3,
2019
2051
  errorMode
2020
2052
  }) {
2021
2053
  if (errorMode === "text") {
@@ -2023,8 +2055,8 @@ async function createToolModelOutput({
2023
2055
  } else if (errorMode === "json") {
2024
2056
  return { type: "error-json", value: await toJSONValue(output) };
2025
2057
  }
2026
- if (tool2 == null ? void 0 : tool2.toModelOutput) {
2027
- return await tool2.toModelOutput({ toolCallId, input, output });
2058
+ if (tool3 == null ? void 0 : tool3.toModelOutput) {
2059
+ return await tool3.toModelOutput({ toolCallId, input, output });
2028
2060
  }
2029
2061
  return typeof output === "string" ? { type: "text", value: output } : { type: "json", value: await toJSONValue(output) };
2030
2062
  }
@@ -2159,25 +2191,25 @@ async function prepareTools({
2159
2191
  return void 0;
2160
2192
  }
2161
2193
  const languageModelTools = [];
2162
- for (const [name25, tool2] of orderToolEntries({ tools, toolOrder })) {
2163
- const toolType = tool2.type;
2194
+ for (const [name25, tool3] of orderToolEntries({ tools, toolOrder })) {
2195
+ const toolType = tool3.type;
2164
2196
  switch (toolType) {
2165
2197
  case void 0:
2166
2198
  case "dynamic":
2167
2199
  case "function": {
2168
2200
  const description = resolveToolDescription({
2169
- tool: tool2,
2201
+ tool: tool3,
2170
2202
  toolName: name25,
2171
2203
  toolsContext,
2172
2204
  experimental_sandbox: sandbox
2173
2205
  });
2174
- const providerOptions = tool2.providerOptions;
2175
- const inputExamples = tool2.inputExamples;
2176
- const strict = tool2.strict;
2206
+ const providerOptions = tool3.providerOptions;
2207
+ const inputExamples = tool3.inputExamples;
2208
+ const strict = tool3.strict;
2177
2209
  languageModelTools.push({
2178
2210
  type: "function",
2179
2211
  name: name25,
2180
- inputSchema: await asSchema(tool2.inputSchema).jsonSchema,
2212
+ inputSchema: await asSchema(tool3.inputSchema).jsonSchema,
2181
2213
  ...description != null ? { description } : {},
2182
2214
  ...inputExamples != null ? { inputExamples } : {},
2183
2215
  ...providerOptions != null ? { providerOptions } : {},
@@ -2189,8 +2221,8 @@ async function prepareTools({
2189
2221
  languageModelTools.push({
2190
2222
  type: "provider",
2191
2223
  name: name25,
2192
- id: tool2.id,
2193
- args: tool2.args
2224
+ id: tool3.id,
2225
+ args: tool3.args
2194
2226
  });
2195
2227
  break;
2196
2228
  }
@@ -2217,12 +2249,12 @@ function orderToolEntries({
2217
2249
  return [...orderedTools, ...unorderedTools];
2218
2250
  }
2219
2251
  function resolveToolDescription({
2220
- tool: tool2,
2252
+ tool: tool3,
2221
2253
  toolName,
2222
2254
  toolsContext,
2223
2255
  experimental_sandbox: sandbox
2224
2256
  }) {
2225
- return tool2.description === void 0 ? void 0 : typeof tool2.description === "string" ? tool2.description : tool2.description({
2257
+ return tool3.description === void 0 ? void 0 : typeof tool3.description === "string" ? tool3.description : tool3.description({
2226
2258
  context: toolsContext[toolName],
2227
2259
  experimental_sandbox: sandbox
2228
2260
  });
@@ -3068,8 +3100,8 @@ function convertLanguageModelContent({
3068
3100
  (toolCall2) => toolCall2.toolCallId === part.toolCallId
3069
3101
  );
3070
3102
  if (toolCall == null) {
3071
- const tool2 = getOwn(tools, part.toolName);
3072
- const supportsDeferredResults = (tool2 == null ? void 0 : tool2.type) === "provider" && tool2.supportsDeferredResults;
3103
+ const tool3 = getOwn(tools, part.toolName);
3104
+ const supportsDeferredResults = (tool3 == null ? void 0 : tool3.type) === "provider" && tool3.supportsDeferredResults;
3073
3105
  if (!supportsDeferredResults) {
3074
3106
  throw new Error(`Tool call ${part.toolCallId} not found.`);
3075
3107
  }
@@ -3083,7 +3115,7 @@ function convertLanguageModelContent({
3083
3115
  providerExecuted: true,
3084
3116
  dynamic: part.dynamic,
3085
3117
  ...part.providerMetadata != null ? { providerMetadata: part.providerMetadata } : {},
3086
- ...(tool2 == null ? void 0 : tool2.metadata) != null ? { toolMetadata: tool2.metadata } : {}
3118
+ ...(tool3 == null ? void 0 : tool3.metadata) != null ? { toolMetadata: tool3.metadata } : {}
3087
3119
  });
3088
3120
  } else {
3089
3121
  contentParts.push({
@@ -3095,7 +3127,7 @@ function convertLanguageModelContent({
3095
3127
  providerExecuted: true,
3096
3128
  dynamic: part.dynamic,
3097
3129
  ...part.providerMetadata != null ? { providerMetadata: part.providerMetadata } : {},
3098
- ...(tool2 == null ? void 0 : tool2.metadata) != null ? { toolMetadata: tool2.metadata } : {}
3130
+ ...(tool3 == null ? void 0 : tool3.metadata) != null ? { toolMetadata: tool3.metadata } : {}
3099
3131
  });
3100
3132
  }
3101
3133
  break;
@@ -3162,6 +3194,287 @@ function convertLanguageModelContent({
3162
3194
  ];
3163
3195
  }
3164
3196
 
3197
+ // src/tool-search/prepare-tool-search.ts
3198
+ import {
3199
+ experimental_getToolCaller as experimental_getToolCaller2
3200
+ } from "@ai-sdk/provider-utils";
3201
+
3202
+ // src/generate-text/tool-caller-configuration.ts
3203
+ import {
3204
+ experimental_getToolCaller
3205
+ } from "@ai-sdk/provider-utils";
3206
+ var DIRECT_TOOL_CALL = "AI_SDK_DIRECT_TOOL_CALL";
3207
+ function resolveToolCallerConfiguration({
3208
+ tools,
3209
+ toolCallers
3210
+ }) {
3211
+ if (tools == null || toolCallers == null) {
3212
+ return void 0;
3213
+ }
3214
+ const resolved = {};
3215
+ for (const [toolName, callers] of Object.entries(toolCallers)) {
3216
+ if (!Object.prototype.hasOwnProperty.call(tools, toolName)) {
3217
+ throw new InvalidArgumentError({
3218
+ parameter: "experimental_toolCallers",
3219
+ value: toolCallers,
3220
+ message: `unknown tool "${toolName}".`
3221
+ });
3222
+ }
3223
+ if (!Array.isArray(callers)) {
3224
+ throw new InvalidArgumentError({
3225
+ parameter: "experimental_toolCallers",
3226
+ value: toolCallers,
3227
+ message: `callers for tool "${toolName}" must be an array.`
3228
+ });
3229
+ }
3230
+ resolved[toolName] = callers.map((caller) => {
3231
+ if (caller === DIRECT_TOOL_CALL) {
3232
+ return caller;
3233
+ }
3234
+ if (typeof caller !== "string" || !Object.prototype.hasOwnProperty.call(tools, caller) || experimental_getToolCaller(tools[caller]) == null) {
3235
+ throw new InvalidArgumentError({
3236
+ parameter: "experimental_toolCallers",
3237
+ value: toolCallers,
3238
+ message: `tool "${toolName}" contains an invalid caller.`
3239
+ });
3240
+ }
3241
+ return caller;
3242
+ });
3243
+ }
3244
+ return resolved;
3245
+ }
3246
+ function prepareToolsForToolCallers({
3247
+ tools,
3248
+ toolCallers
3249
+ }) {
3250
+ var _a25, _b25;
3251
+ if (tools == null || toolCallers == null) {
3252
+ return {
3253
+ executionTools: tools,
3254
+ modelTools: tools,
3255
+ toolCallerMessages: []
3256
+ };
3257
+ }
3258
+ const executionTools = { ...tools };
3259
+ const modelTools = { ...tools };
3260
+ const localToolsByCaller = /* @__PURE__ */ new Map();
3261
+ const toolCallerMessages = [];
3262
+ for (const [toolName, callerNames] of Object.entries(toolCallers)) {
3263
+ const tool3 = executionTools[toolName];
3264
+ if (tool3 == null) {
3265
+ continue;
3266
+ }
3267
+ let availableDirectly = false;
3268
+ let availableToProvider = false;
3269
+ let preparedTool = tool3;
3270
+ for (const callerName of callerNames) {
3271
+ if (callerName === DIRECT_TOOL_CALL) {
3272
+ availableDirectly = true;
3273
+ continue;
3274
+ }
3275
+ const caller = experimental_getToolCaller(executionTools[callerName]);
3276
+ if (caller == null) {
3277
+ continue;
3278
+ }
3279
+ if (caller.type === "provider") {
3280
+ availableToProvider = true;
3281
+ preparedTool = {
3282
+ ...preparedTool,
3283
+ providerOptions: caller.prepareProviderOptions(
3284
+ preparedTool.providerOptions
3285
+ )
3286
+ };
3287
+ } else {
3288
+ const localTools = (_a25 = localToolsByCaller.get(callerName)) != null ? _a25 : {};
3289
+ localTools[toolName] = preparedTool;
3290
+ localToolsByCaller.set(callerName, localTools);
3291
+ }
3292
+ }
3293
+ executionTools[toolName] = preparedTool;
3294
+ if (availableDirectly || availableToProvider) {
3295
+ modelTools[toolName] = preparedTool;
3296
+ } else {
3297
+ delete modelTools[toolName];
3298
+ }
3299
+ }
3300
+ for (const [callerName, callerTool] of Object.entries(executionTools)) {
3301
+ const caller = experimental_getToolCaller(callerTool);
3302
+ if ((caller == null ? void 0 : caller.type) !== "local") {
3303
+ continue;
3304
+ }
3305
+ const callerTools = (_b25 = localToolsByCaller.get(callerName)) != null ? _b25 : {};
3306
+ const boundCaller = caller.bind(callerTools);
3307
+ executionTools[callerName] = boundCaller;
3308
+ if (Object.prototype.hasOwnProperty.call(modelTools, callerName)) {
3309
+ if (caller.prepareModelMessage == null) {
3310
+ modelTools[callerName] = boundCaller;
3311
+ } else {
3312
+ const content = caller.prepareModelMessage(callerTools);
3313
+ if (content != null) {
3314
+ toolCallerMessages.push({ role: "user", content });
3315
+ }
3316
+ }
3317
+ }
3318
+ }
3319
+ return { executionTools, modelTools, toolCallerMessages };
3320
+ }
3321
+ function appendToolCallerMessages({
3322
+ messages,
3323
+ toolCallerMessages
3324
+ }) {
3325
+ var _a25;
3326
+ if (toolCallerMessages.length === 0) {
3327
+ return messages;
3328
+ }
3329
+ const latestUserText = (_a25 = messages.findLast(
3330
+ (message) => message.role === "user" && typeof message.content === "string"
3331
+ )) == null ? void 0 : _a25.content;
3332
+ const existingUserText = new Set(
3333
+ latestUserText == null ? [] : [latestUserText]
3334
+ );
3335
+ const additions = toolCallerMessages.filter((message) => {
3336
+ if (typeof message.content !== "string" || existingUserText.has(message.content)) {
3337
+ return false;
3338
+ }
3339
+ existingUserText.add(message.content);
3340
+ return true;
3341
+ });
3342
+ return additions.length === 0 ? messages : [...messages, ...additions];
3343
+ }
3344
+
3345
+ // src/tool-search/tool-search.ts
3346
+ import { jsonSchema, tool } from "@ai-sdk/provider-utils";
3347
+ var toolSearchSymbol = /* @__PURE__ */ Symbol.for("vercel.ai.toolSearch");
3348
+ function toolSearch() {
3349
+ return Object.assign(
3350
+ tool({
3351
+ 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.",
3352
+ inputSchema: jsonSchema({
3353
+ type: "object",
3354
+ properties: { query: { type: "string", minLength: 1 } },
3355
+ required: ["query"],
3356
+ additionalProperties: false
3357
+ }),
3358
+ outputSchema: jsonSchema({
3359
+ type: "object",
3360
+ properties: {
3361
+ tools: {
3362
+ type: "array",
3363
+ items: {
3364
+ type: "object",
3365
+ properties: {
3366
+ name: { type: "string" },
3367
+ description: { type: "string" }
3368
+ },
3369
+ required: ["name"],
3370
+ additionalProperties: false
3371
+ }
3372
+ }
3373
+ },
3374
+ required: ["tools"],
3375
+ additionalProperties: false
3376
+ }),
3377
+ execute: () => {
3378
+ throw new Error("toolSearch must be bound by an AI SDK generation.");
3379
+ }
3380
+ }),
3381
+ { type: "function", [toolSearchSymbol]: true }
3382
+ );
3383
+ }
3384
+ function isToolSearch(tool3) {
3385
+ return tool3[toolSearchSymbol] === true;
3386
+ }
3387
+
3388
+ // src/tool-search/prepare-tool-search.ts
3389
+ function createToolSearchState({
3390
+ tools,
3391
+ toolCallers
3392
+ }) {
3393
+ const searchTools = Object.entries(tools != null ? tools : {}).filter(
3394
+ ([, tool3]) => tool3.deferLoading || isToolSearch(tool3)
3395
+ );
3396
+ if (searchTools.length === 0) {
3397
+ return (activeTools) => activeTools;
3398
+ }
3399
+ const discovered = /* @__PURE__ */ new Set();
3400
+ const getCallers = (name25) => {
3401
+ var _a25;
3402
+ return (_a25 = getOwn(toolCallers, name25)) != null ? _a25 : [DIRECT_TOOL_CALL];
3403
+ };
3404
+ for (const [name25, tool3] of searchTools) {
3405
+ const callers = getCallers(name25);
3406
+ if (callers.some((name26) => {
3407
+ if (name26 === DIRECT_TOOL_CALL) {
3408
+ return false;
3409
+ }
3410
+ const caller = experimental_getToolCaller2(tools == null ? void 0 : tools[name26]);
3411
+ return (caller == null ? void 0 : caller.type) !== "local" || caller.prepareModelMessage == null;
3412
+ }) || isToolSearch(tool3) && tool3.deferLoading) {
3413
+ throw new InvalidArgumentError({
3414
+ parameter: "tools",
3415
+ value: name25,
3416
+ message: `tool "${name25}" must be callable directly or through code mode with toolDiscovery: 'conversation'. The search tool itself must not defer loading.`
3417
+ });
3418
+ }
3419
+ }
3420
+ return (activeTools, { toolsContext = {}, experimental_sandbox } = {}) => {
3421
+ if (activeTools == null) {
3422
+ return void 0;
3423
+ }
3424
+ const entries = Object.entries(activeTools);
3425
+ return Object.fromEntries(
3426
+ entries.filter(([name25, tool3]) => !tool3.deferLoading || discovered.has(name25)).map(([searchName, tool3]) => {
3427
+ if (!isToolSearch(tool3)) {
3428
+ return [searchName, tool3];
3429
+ }
3430
+ const callers = getCallers(searchName).filter(
3431
+ (name25) => name25 === DIRECT_TOOL_CALL || Object.hasOwn(activeTools, name25)
3432
+ );
3433
+ const candidates = entries.filter(
3434
+ ([name25, candidate]) => candidate.deferLoading && !isToolSearch(candidate) && callers.some((caller) => getCallers(name25).includes(caller))
3435
+ );
3436
+ return [
3437
+ searchName,
3438
+ {
3439
+ ...tool3,
3440
+ execute: ({ query }) => {
3441
+ const terms = [...new Set(tokenize(query))];
3442
+ const matches = candidates.map(([name25, candidate]) => {
3443
+ const description = resolveToolDescription({
3444
+ tool: candidate,
3445
+ toolName: name25,
3446
+ toolsContext,
3447
+ experimental_sandbox
3448
+ });
3449
+ const nameTerms = tokenize(name25);
3450
+ const descriptionTerms = tokenize(description != null ? description : "");
3451
+ const score = terms.reduce(
3452
+ (score2, term) => score2 + (nameTerms.includes(term) ? 2 : 0) + (descriptionTerms.includes(term) ? 1 : 0),
3453
+ 0
3454
+ );
3455
+ return { name: name25, description, score };
3456
+ }).filter((match) => match.score > 0).sort((a, b) => b.score - a.score).slice(0, 5);
3457
+ for (const { name: name25 } of matches) {
3458
+ discovered.add(name25);
3459
+ }
3460
+ return {
3461
+ tools: matches.map(({ name: name25, description }) => ({
3462
+ name: name25,
3463
+ ...description == null ? {} : { description }
3464
+ }))
3465
+ };
3466
+ }
3467
+ }
3468
+ ];
3469
+ })
3470
+ );
3471
+ };
3472
+ }
3473
+ function tokenize(text2) {
3474
+ var _a25;
3475
+ return (_a25 = text2.replace(/([a-z\d])([A-Z])/g, "$1 $2").toLowerCase().match(/[\p{L}\p{N}]+/gu)) != null ? _a25 : [];
3476
+ }
3477
+
3165
3478
  // src/generate-text/execute-tool-call.ts
3166
3479
  import {
3167
3480
  executeTool,
@@ -3205,14 +3518,14 @@ async function executeToolCall({
3205
3518
  runInTracingChannelSpan = async ({ execute }) => await execute()
3206
3519
  }) {
3207
3520
  const { toolName, toolCallId, input } = toolCall;
3208
- const tool2 = getOwn(tools, toolName);
3209
- if (!isExecutableTool(tool2)) {
3521
+ const tool3 = getOwn(tools, toolName);
3522
+ if (!isExecutableTool(tool3)) {
3210
3523
  return void 0;
3211
3524
  }
3212
3525
  const context = await validateToolContext({
3213
3526
  toolName,
3214
3527
  context: getOwn(toolsContext, toolName),
3215
- contextSchema: tool2.contextSchema
3528
+ contextSchema: tool3.contextSchema
3216
3529
  });
3217
3530
  const toolExecutionContext = {
3218
3531
  toolCall,
@@ -3244,7 +3557,7 @@ async function executeToolCall({
3244
3557
  const startTime = now();
3245
3558
  try {
3246
3559
  const stream = executeTool({
3247
- tool: tool2,
3560
+ tool: tool3,
3248
3561
  input,
3249
3562
  options: {
3250
3563
  toolCallId,
@@ -3278,7 +3591,7 @@ async function executeToolCall({
3278
3591
  toolName,
3279
3592
  input,
3280
3593
  error,
3281
- dynamic: tool2.type === "dynamic",
3594
+ dynamic: tool3.type === "dynamic",
3282
3595
  ...toolCall.providerMetadata != null ? { providerMetadata: toolCall.providerMetadata } : {},
3283
3596
  ...toolCall.toolMetadata != null ? { toolMetadata: toolCall.toolMetadata } : {}
3284
3597
  };
@@ -3301,7 +3614,7 @@ async function executeToolCall({
3301
3614
  toolName,
3302
3615
  input,
3303
3616
  output,
3304
- dynamic: tool2.type === "dynamic",
3617
+ dynamic: tool3.type === "dynamic",
3305
3618
  ...toolCall.providerMetadata != null ? { providerMetadata: toolCall.providerMetadata } : {},
3306
3619
  ...toolCall.toolMetadata != null ? { toolMetadata: toolCall.toolMetadata } : {}
3307
3620
  };
@@ -3736,9 +4049,9 @@ var object2 = ({
3736
4049
  const schema = asSchema2(inputSchema);
3737
4050
  return {
3738
4051
  name: "object",
3739
- responseFormat: resolve(schema.jsonSchema).then((jsonSchema2) => ({
4052
+ responseFormat: resolve(schema.jsonSchema).then((jsonSchema3) => ({
3740
4053
  type: "json",
3741
- schema: jsonSchema2,
4054
+ schema: jsonSchema3,
3742
4055
  ...name25 != null && { name: name25 },
3743
4056
  ...description != null && { description }
3744
4057
  })),
@@ -3811,13 +4124,13 @@ var array2 = ({
3811
4124
  return {
3812
4125
  name: "array",
3813
4126
  // JSON schema that describes an array of elements:
3814
- responseFormat: resolve(elementSchema.jsonSchema).then((jsonSchema2) => {
4127
+ responseFormat: resolve(elementSchema.jsonSchema).then((jsonSchema3) => {
3815
4128
  const {
3816
4129
  $schema: _$schema,
3817
4130
  definitions,
3818
4131
  $defs,
3819
4132
  ...itemSchema
3820
- } = jsonSchema2;
4133
+ } = jsonSchema3;
3821
4134
  return {
3822
4135
  type: "json",
3823
4136
  schema: {
@@ -4181,7 +4494,7 @@ async function parseToolCall({
4181
4494
  } catch (error) {
4182
4495
  const parsedInput = await safeParseJSON3({ text: toolCall.input });
4183
4496
  const input = parsedInput.success ? parsedInput.value : toolCall.input;
4184
- const tool2 = getOwn(tools, toolCall.toolName);
4497
+ const tool3 = getOwn(tools, toolCall.toolName);
4185
4498
  return {
4186
4499
  type: "tool-call",
4187
4500
  toolCallId: toolCall.toolCallId,
@@ -4190,10 +4503,10 @@ async function parseToolCall({
4190
4503
  dynamic: true,
4191
4504
  invalid: true,
4192
4505
  error,
4193
- title: tool2 == null ? void 0 : tool2.title,
4506
+ title: tool3 == null ? void 0 : tool3.title,
4194
4507
  providerExecuted: toolCall.providerExecuted,
4195
4508
  providerMetadata: toolCall.providerMetadata,
4196
- ...(tool2 == null ? void 0 : tool2.metadata) != null ? { toolMetadata: tool2.metadata } : {}
4509
+ ...(tool3 == null ? void 0 : tool3.metadata) != null ? { toolMetadata: tool3.metadata } : {}
4197
4510
  };
4198
4511
  }
4199
4512
  }
@@ -4234,8 +4547,8 @@ async function doParseToolCall({
4234
4547
  tools
4235
4548
  }) {
4236
4549
  const toolName = toolCall.toolName;
4237
- const tool2 = getOwn(tools, toolName);
4238
- if (tool2 == null) {
4550
+ const tool3 = getOwn(tools, toolName);
4551
+ if (tool3 == null) {
4239
4552
  if (toolCall.providerExecuted && toolCall.dynamic) {
4240
4553
  return await parseProviderExecutedDynamicToolCall(toolCall);
4241
4554
  }
@@ -4244,7 +4557,7 @@ async function doParseToolCall({
4244
4557
  availableTools: Object.keys(tools)
4245
4558
  });
4246
4559
  }
4247
- const schema = asSchema3(tool2.inputSchema);
4560
+ const schema = asSchema3(tool3.inputSchema);
4248
4561
  const parseResult = toolCall.input.trim() === "" ? await safeValidateTypes3({ value: {}, schema }) : await safeParseJSON3({ text: toolCall.input, schema });
4249
4562
  if (parseResult.success === false) {
4250
4563
  throw new InvalidToolInputError({
@@ -4253,16 +4566,16 @@ async function doParseToolCall({
4253
4566
  cause: parseResult.error
4254
4567
  });
4255
4568
  }
4256
- return tool2.type === "dynamic" ? {
4569
+ return tool3.type === "dynamic" ? {
4257
4570
  type: "tool-call",
4258
4571
  toolCallId: toolCall.toolCallId,
4259
4572
  toolName: toolCall.toolName,
4260
4573
  input: parseResult.value,
4261
4574
  providerExecuted: toolCall.providerExecuted,
4262
4575
  providerMetadata: toolCall.providerMetadata,
4263
- ...tool2.metadata != null ? { toolMetadata: tool2.metadata } : {},
4576
+ ...tool3.metadata != null ? { toolMetadata: tool3.metadata } : {},
4264
4577
  dynamic: true,
4265
- title: tool2.title
4578
+ title: tool3.title
4266
4579
  } : {
4267
4580
  type: "tool-call",
4268
4581
  toolCallId: toolCall.toolCallId,
@@ -4270,8 +4583,8 @@ async function doParseToolCall({
4270
4583
  input: parseResult.value,
4271
4584
  providerExecuted: toolCall.providerExecuted,
4272
4585
  providerMetadata: toolCall.providerMetadata,
4273
- ...tool2.metadata != null ? { toolMetadata: tool2.metadata } : {},
4274
- title: tool2.title
4586
+ ...tool3.metadata != null ? { toolMetadata: tool3.metadata } : {},
4587
+ title: tool3.title
4275
4588
  };
4276
4589
  }
4277
4590
 
@@ -4361,7 +4674,7 @@ async function resolveToolApproval({
4361
4674
  );
4362
4675
  }
4363
4676
  const toolName = toolCall.toolName;
4364
- const tool2 = getOwn(tools, toolName);
4677
+ const tool3 = getOwn(tools, toolName);
4365
4678
  const input = toolCall.input;
4366
4679
  const userDefinedToolApprovalStatus = getOwn(toolApproval, toolName);
4367
4680
  if (userDefinedToolApprovalStatus != null) {
@@ -4371,24 +4684,24 @@ async function resolveToolApproval({
4371
4684
  toolContext: await validateToolContext({
4372
4685
  toolName,
4373
4686
  context: getOwn(toolsContext, toolName),
4374
- contextSchema: tool2 == null ? void 0 : tool2.contextSchema
4687
+ contextSchema: tool3 == null ? void 0 : tool3.contextSchema
4375
4688
  }),
4376
4689
  runtimeContext
4377
4690
  }) : userDefinedToolApprovalStatus;
4378
4691
  return normalizeToolApprovalStatus(approvalStatus);
4379
4692
  }
4380
- if ((tool2 == null ? void 0 : tool2.needsApproval) == null) {
4693
+ if ((tool3 == null ? void 0 : tool3.needsApproval) == null) {
4381
4694
  return { type: "not-applicable" };
4382
4695
  }
4383
- const needsApproval = typeof tool2.needsApproval === "function" ? await tool2.needsApproval(input, {
4696
+ const needsApproval = typeof tool3.needsApproval === "function" ? await tool3.needsApproval(input, {
4384
4697
  toolCallId: toolCall.toolCallId,
4385
4698
  messages,
4386
4699
  context: await validateToolContext({
4387
4700
  toolName,
4388
4701
  context: getOwn(toolsContext, toolName),
4389
- contextSchema: tool2 == null ? void 0 : tool2.contextSchema
4702
+ contextSchema: tool3 == null ? void 0 : tool3.contextSchema
4390
4703
  })
4391
- }) : tool2.needsApproval;
4704
+ }) : tool3.needsApproval;
4392
4705
  return needsApproval ? { type: "user-approval" } : { type: "not-applicable" };
4393
4706
  }
4394
4707
  function normalizeToolApprovalStatus(status) {
@@ -5199,149 +5512,6 @@ function sortToolResultContentByToolCallOrder({
5199
5512
  );
5200
5513
  }
5201
5514
 
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
5515
  // src/generate-text/tool-approval-signature.ts
5346
5516
  import { convertBase64ToUint8Array as convertBase64ToUint8Array2 } from "@ai-sdk/provider-utils";
5347
5517
 
@@ -5480,7 +5650,7 @@ async function validateApprovedToolApprovals({
5480
5650
  const invalid = [];
5481
5651
  for (const approval of approvedToolApprovals) {
5482
5652
  const { toolCall, approvalRequest } = approval;
5483
- const tool2 = getOwn(tools, toolCall.toolName);
5653
+ const tool3 = getOwn(tools, toolCall.toolName);
5484
5654
  if (toolApprovalSecret != null) {
5485
5655
  if (approvalRequest.signature == null) {
5486
5656
  throw new InvalidToolApprovalSignatureError({
@@ -5505,10 +5675,10 @@ async function validateApprovedToolApprovals({
5505
5675
  });
5506
5676
  }
5507
5677
  }
5508
- if (isExecutableTool2(tool2) && tool2.inputSchema != null) {
5678
+ if (isExecutableTool2(tool3) && tool3.inputSchema != null) {
5509
5679
  const validation = await safeValidateTypes4({
5510
5680
  value: toolCall.input,
5511
- schema: asSchema4(tool2.inputSchema)
5681
+ schema: asSchema4(tool3.inputSchema)
5512
5682
  });
5513
5683
  if (!validation.success) {
5514
5684
  invalid.push({
@@ -5626,6 +5796,10 @@ async function generateText({
5626
5796
  tools,
5627
5797
  toolCallers: experimental_toolCallers
5628
5798
  });
5799
+ const prepareToolSearch = createToolSearchState({
5800
+ tools,
5801
+ toolCallers: resolvedToolCallers
5802
+ });
5629
5803
  const stopConditions = asArray5(stopWhen);
5630
5804
  const resolvedOnStart = onStart != null ? onStart : experimental_onStart;
5631
5805
  const resolvedOnStepStart = onStepStart != null ? onStepStart : experimental_onStepStart;
@@ -5897,7 +6071,10 @@ async function generateText({
5897
6071
  modelTools: stepModelTools,
5898
6072
  toolCallerMessages
5899
6073
  } = prepareToolsForToolCallers({
5900
- tools: stepActiveTools,
6074
+ tools: prepareToolSearch(stepActiveTools, {
6075
+ toolsContext,
6076
+ experimental_sandbox: stepSandbox
6077
+ }),
5901
6078
  toolCallers: resolvedToolCallers
5902
6079
  });
5903
6080
  const stepToolOrder = (_h = prepareStepResult == null ? void 0 : prepareStepResult.toolOrder) != null ? _h : toolOrder;
@@ -6085,20 +6262,20 @@ async function generateText({
6085
6262
  if (toolCall.invalid) {
6086
6263
  continue;
6087
6264
  }
6088
- const tool2 = getOwn(stepExecutionTools, toolCall.toolName);
6089
- if (tool2 == null) {
6265
+ const tool3 = getOwn(stepExecutionTools, toolCall.toolName);
6266
+ if (tool3 == null) {
6090
6267
  continue;
6091
6268
  }
6092
- if (tool2.onInputStart != null) {
6093
- await tool2.onInputStart({
6269
+ if (tool3.onInputStart != null) {
6270
+ await tool3.onInputStart({
6094
6271
  toolCallId: toolCall.toolCallId,
6095
6272
  messages: stepMessages,
6096
6273
  abortSignal: mergedAbortSignal,
6097
6274
  context: runtimeContext
6098
6275
  });
6099
6276
  }
6100
- if ((tool2 == null ? void 0 : tool2.onInputAvailable) != null) {
6101
- await tool2.onInputAvailable({
6277
+ if ((tool3 == null ? void 0 : tool3.onInputAvailable) != null) {
6278
+ await tool3.onInputAvailable({
6102
6279
  input: toolCall.input,
6103
6280
  toolCallId: toolCall.toolCallId,
6104
6281
  messages: stepMessages,
@@ -6256,8 +6433,8 @@ async function generateText({
6256
6433
  };
6257
6434
  for (const toolCall of stepToolCalls) {
6258
6435
  if (!toolCall.providerExecuted) continue;
6259
- const tool2 = getOwn(stepExecutionTools, toolCall.toolName);
6260
- if ((tool2 == null ? void 0 : tool2.type) === "provider" && tool2.supportsDeferredResults) {
6436
+ const tool3 = getOwn(stepExecutionTools, toolCall.toolName);
6437
+ if ((tool3 == null ? void 0 : tool3.type) === "provider" && tool3.supportsDeferredResults) {
6261
6438
  const hasResultInResponse = currentModelResponse.content.some(
6262
6439
  (part) => part.type === "tool-result" && part.toolCallId === toolCall.toolCallId
6263
6440
  );
@@ -7842,11 +8019,11 @@ function toUIMessageChunk(part, {
7842
8019
  responseMessageId
7843
8020
  } = {}) {
7844
8021
  const isDynamic = (toolPart) => {
7845
- const tool2 = tools == null ? void 0 : tools[toolPart.toolName];
7846
- if (tool2 == null) {
8022
+ const tool3 = tools == null ? void 0 : tools[toolPart.toolName];
8023
+ if (tool3 == null) {
7847
8024
  return toolPart.dynamic;
7848
8025
  }
7849
- return (tool2 == null ? void 0 : tool2.type) === "dynamic" ? true : void 0;
8026
+ return (tool3 == null ? void 0 : tool3.type) === "dynamic" ? true : void 0;
7850
8027
  };
7851
8028
  const partType = part.type;
7852
8029
  switch (partType) {
@@ -8482,8 +8659,8 @@ function executeToolsFromStream({
8482
8659
  if (chunk.invalid) {
8483
8660
  return;
8484
8661
  }
8485
- const tool2 = getOwn(tools, chunk.toolName);
8486
- if (tool2 == null) {
8662
+ const tool3 = getOwn(tools, chunk.toolName);
8663
+ if (tool3 == null) {
8487
8664
  return;
8488
8665
  }
8489
8666
  const toolApprovalStatus = await resolveToolApproval({
@@ -8495,7 +8672,7 @@ function executeToolsFromStream({
8495
8672
  runtimeContext
8496
8673
  });
8497
8674
  if (toolApprovalStatus.type === "not-applicable") {
8498
- if (tool2.execute != null && chunk.providerExecuted !== true) {
8675
+ if (tool3.execute != null && chunk.providerExecuted !== true) {
8499
8676
  toolCallsToExecute.push(chunk);
8500
8677
  }
8501
8678
  return;
@@ -8561,7 +8738,7 @@ function executeToolsFromStream({
8561
8738
  break;
8562
8739
  }
8563
8740
  }
8564
- if (tool2.execute != null && chunk.providerExecuted !== true) {
8741
+ if (tool3.execute != null && chunk.providerExecuted !== true) {
8565
8742
  toolCallsToExecute.push(chunk);
8566
8743
  }
8567
8744
  return;
@@ -8634,9 +8811,9 @@ function invokeToolCallbacksFromStream({
8634
8811
  switch (chunk.type) {
8635
8812
  case "tool-input-start": {
8636
8813
  ongoingToolCallToolNames[chunk.id] = chunk.toolName;
8637
- const tool2 = getOwn(tools, chunk.toolName);
8638
- if ((tool2 == null ? void 0 : tool2.onInputStart) != null) {
8639
- await tool2.onInputStart({
8814
+ const tool3 = getOwn(tools, chunk.toolName);
8815
+ if ((tool3 == null ? void 0 : tool3.onInputStart) != null) {
8816
+ await tool3.onInputStart({
8640
8817
  toolCallId: chunk.id,
8641
8818
  messages: stepInputMessages,
8642
8819
  abortSignal,
@@ -8647,9 +8824,9 @@ function invokeToolCallbacksFromStream({
8647
8824
  }
8648
8825
  case "tool-input-delta": {
8649
8826
  const toolName = ongoingToolCallToolNames[chunk.id];
8650
- const tool2 = getOwn(tools, toolName);
8651
- if ((tool2 == null ? void 0 : tool2.onInputDelta) != null) {
8652
- await tool2.onInputDelta({
8827
+ const tool3 = getOwn(tools, toolName);
8828
+ if ((tool3 == null ? void 0 : tool3.onInputDelta) != null) {
8829
+ await tool3.onInputDelta({
8653
8830
  inputTextDelta: chunk.delta,
8654
8831
  toolCallId: chunk.id,
8655
8832
  messages: stepInputMessages,
@@ -8661,10 +8838,10 @@ function invokeToolCallbacksFromStream({
8661
8838
  }
8662
8839
  case "tool-call": {
8663
8840
  const toolName = ongoingToolCallToolNames[chunk.toolCallId];
8664
- const tool2 = getOwn(tools, toolName);
8841
+ const tool3 = getOwn(tools, toolName);
8665
8842
  delete ongoingToolCallToolNames[chunk.toolCallId];
8666
- if ((tool2 == null ? void 0 : tool2.onInputAvailable) != null) {
8667
- await tool2.onInputAvailable({
8843
+ if ((tool3 == null ? void 0 : tool3.onInputAvailable) != null) {
8844
+ await tool3.onInputAvailable({
8668
8845
  input: chunk.input,
8669
8846
  toolCallId: chunk.toolCallId,
8670
8847
  messages: stepInputMessages,
@@ -9191,12 +9368,12 @@ function createLanguageModelV4StreamPartToLanguageModelStreamPartTransform({
9191
9368
  break;
9192
9369
  }
9193
9370
  case "tool-input-start": {
9194
- const tool2 = getOwn(tools, chunk.toolName);
9371
+ const tool3 = getOwn(tools, chunk.toolName);
9195
9372
  controller.enqueue({
9196
9373
  ...chunk,
9197
- dynamic: (_a25 = chunk.dynamic) != null ? _a25 : (tool2 == null ? void 0 : tool2.type) === "dynamic",
9198
- title: tool2 == null ? void 0 : tool2.title,
9199
- ...(tool2 == null ? void 0 : tool2.metadata) != null ? { toolMetadata: tool2.metadata } : {}
9374
+ dynamic: (_a25 = chunk.dynamic) != null ? _a25 : (tool3 == null ? void 0 : tool3.type) === "dynamic",
9375
+ title: tool3 == null ? void 0 : tool3.title,
9376
+ ...(tool3 == null ? void 0 : tool3.metadata) != null ? { toolMetadata: tool3.metadata } : {}
9200
9377
  });
9201
9378
  break;
9202
9379
  }
@@ -9736,6 +9913,10 @@ var DefaultStreamTextResult = class {
9736
9913
  tools,
9737
9914
  toolCallers: experimental_toolCallers
9738
9915
  });
9916
+ const prepareToolSearch = createToolSearchState({
9917
+ tools,
9918
+ toolCallers: resolvedToolCallers
9919
+ });
9739
9920
  const telemetryDispatcher = createRestrictedTelemetryDispatcher({
9740
9921
  telemetry,
9741
9922
  includeRuntimeContext: telemetry == null ? void 0 : telemetry.includeRuntimeContext,
@@ -10444,7 +10625,10 @@ var DefaultStreamTextResult = class {
10444
10625
  modelTools: stepModelTools,
10445
10626
  toolCallerMessages
10446
10627
  } = prepareToolsForToolCallers({
10447
- tools: stepActiveTools,
10628
+ tools: prepareToolSearch(stepActiveTools, {
10629
+ toolsContext,
10630
+ experimental_sandbox: stepSandbox
10631
+ }),
10448
10632
  toolCallers: resolvedToolCallers
10449
10633
  });
10450
10634
  const stepToolOrder = (_g = prepareStepResult == null ? void 0 : prepareStepResult.toolOrder) != null ? _g : toolOrder;
@@ -10962,8 +11146,8 @@ var DefaultStreamTextResult = class {
10962
11146
  );
10963
11147
  for (const toolCall of stepToolCalls) {
10964
11148
  if (toolCall.providerExecuted !== true) continue;
10965
- const tool2 = getOwn(stepExecutionTools, toolCall.toolName);
10966
- if ((tool2 == null ? void 0 : tool2.type) === "provider" && tool2.supportsDeferredResults) {
11149
+ const tool3 = getOwn(stepExecutionTools, toolCall.toolName);
11150
+ if ((tool3 == null ? void 0 : tool3.type) === "provider" && tool3.supportsDeferredResults) {
10967
11151
  const hasResultInStep = stepToolOutputs.some(
10968
11152
  (output2) => (output2.type === "tool-result" || output2.type === "tool-error") && output2.toolCallId === toolCall.toolCallId
10969
11153
  );
@@ -12471,9 +12655,9 @@ async function safeValidateUIMessagesInternal({
12471
12655
  if (shouldValidateToolParts && part.type.startsWith("tool-")) {
12472
12656
  const toolPart = part;
12473
12657
  const toolName = toolPart.type.slice(5);
12474
- const tool2 = tools == null ? void 0 : getOwn(tools, toolName);
12658
+ const tool3 = tools == null ? void 0 : getOwn(tools, toolName);
12475
12659
  const isTerminal = toolPart.state === "output-available" || toolPart.state === "output-error" || toolPart.state === "output-denied";
12476
- if (!tool2 && isTerminal) {
12660
+ if (!tool3 && isTerminal) {
12477
12661
  if (tools != null || convertMissingTerminalToolsToDynamic) {
12478
12662
  message.parts[partIdx] = asDynamicToolPart(
12479
12663
  toolPart
@@ -12481,7 +12665,7 @@ async function safeValidateUIMessagesInternal({
12481
12665
  }
12482
12666
  continue;
12483
12667
  }
12484
- if (!tool2) {
12668
+ if (!tool3) {
12485
12669
  return {
12486
12670
  success: false,
12487
12671
  error: new TypeValidationError3({
@@ -12505,7 +12689,7 @@ async function safeValidateUIMessagesInternal({
12505
12689
  if (toolPart.input !== void 0) {
12506
12690
  const result = await safeValidateTypes5({
12507
12691
  value: toolPart.input,
12508
- schema: tool2.inputSchema,
12692
+ schema: tool3.inputSchema,
12509
12693
  context: inputValidationContext
12510
12694
  });
12511
12695
  convertToDynamic = !result.success;
@@ -12513,7 +12697,7 @@ async function safeValidateUIMessagesInternal({
12513
12697
  } else if (toolPart.state === "output-available") {
12514
12698
  const result = await safeValidateTypes5({
12515
12699
  value: toolPart.input,
12516
- schema: tool2.inputSchema,
12700
+ schema: tool3.inputSchema,
12517
12701
  context: inputValidationContext
12518
12702
  });
12519
12703
  if (!result.success) {
@@ -12526,14 +12710,14 @@ async function safeValidateUIMessagesInternal({
12526
12710
  } else if (toolPart.state === "input-available" || toolPart.state === "approval-requested" || toolPart.state === "approval-responded" || toolPart.state === "output-denied") {
12527
12711
  await validateTypes4({
12528
12712
  value: toolPart.input,
12529
- schema: tool2.inputSchema,
12713
+ schema: tool3.inputSchema,
12530
12714
  context: inputValidationContext
12531
12715
  });
12532
12716
  }
12533
- if (toolPart.state === "output-available" && tool2.outputSchema) {
12717
+ if (toolPart.state === "output-available" && tool3.outputSchema) {
12534
12718
  await validateTypes4({
12535
12719
  value: toolPart.output,
12536
- schema: tool2.outputSchema,
12720
+ schema: tool3.outputSchema,
12537
12721
  context: {
12538
12722
  field: `messages[${msgIdx}].parts[${partIdx}].output`,
12539
12723
  entityName: toolName,
@@ -13216,16 +13400,16 @@ function validateCompatibleTools({
13216
13400
  tools,
13217
13401
  toolsByName
13218
13402
  }) {
13219
- for (const tool2 of tools != null ? tools : []) {
13220
- const previousTool = toolsByName.get(tool2.name);
13221
- if (previousTool != null && !isDeepEqualData(previousTool, tool2)) {
13403
+ for (const tool3 of tools != null ? tools : []) {
13404
+ const previousTool = toolsByName.get(tool3.name);
13405
+ if (previousTool != null && !isDeepEqualData(previousTool, tool3)) {
13222
13406
  throw new InvalidArgumentError({
13223
13407
  parameter: "requests",
13224
13408
  value: requestId,
13225
- message: `tool "${tool2.name}" must have the same definition in every batch request`
13409
+ message: `tool "${tool3.name}" must have the same definition in every batch request`
13226
13410
  });
13227
13411
  }
13228
- toolsByName.set(tool2.name, tool2);
13412
+ toolsByName.set(tool3.name, tool3);
13229
13413
  }
13230
13414
  }
13231
13415
  async function getBatchStatus({
@@ -14295,7 +14479,7 @@ function validateEvaluationAnswers({
14295
14479
 
14296
14480
  // src/evaluate/evaluate.ts
14297
14481
  async function evaluate({
14298
- model,
14482
+ model: modelArg,
14299
14483
  state,
14300
14484
  questions,
14301
14485
  maxRetries,
@@ -14304,13 +14488,7 @@ async function evaluate({
14304
14488
  providerOptions = {}
14305
14489
  }) {
14306
14490
  var _a25, _b25, _c, _d, _e, _f;
14307
- if (model.specificationVersion !== "v4") {
14308
- throw new UnsupportedModelVersionError({
14309
- version: model.specificationVersion,
14310
- provider: model.provider,
14311
- modelId: model.modelId
14312
- });
14313
- }
14491
+ const model = resolveEvaluationModel(modelArg);
14314
14492
  validateEvaluationInput({ state, questions });
14315
14493
  for (const [questionId, question] of Object.entries(questions)) {
14316
14494
  if (!model.supportedQuestionTypes.includes(question.type)) {
@@ -14909,7 +15087,7 @@ async function generateObject(options) {
14909
15087
  const resolvedOnStart = onStart != null ? onStart : experimental_onStart;
14910
15088
  const resolvedOnStepStart = onStepStart != null ? onStepStart : experimental_onStepStart;
14911
15089
  const resolvedOnStepEnd = onStepEnd != null ? onStepEnd : onStepFinish;
14912
- const jsonSchema2 = await outputStrategy.jsonSchema();
15090
+ const jsonSchema3 = await outputStrategy.jsonSchema();
14913
15091
  const callId = generateId5();
14914
15092
  await notify({
14915
15093
  event: {
@@ -14931,7 +15109,7 @@ async function generateObject(options) {
14931
15109
  headers: headersWithUserAgent,
14932
15110
  providerOptions,
14933
15111
  output: outputStrategy.type,
14934
- schema: jsonSchema2,
15112
+ schema: jsonSchema3,
14935
15113
  schemaName,
14936
15114
  schemaDescription
14937
15115
  },
@@ -14967,7 +15145,7 @@ async function generateObject(options) {
14967
15145
  () => model.doGenerate({
14968
15146
  responseFormat: {
14969
15147
  type: "json",
14970
- schema: jsonSchema2,
15148
+ schema: jsonSchema3,
14971
15149
  name: schemaName,
14972
15150
  description: schemaDescription
14973
15151
  },
@@ -15351,7 +15529,7 @@ var DefaultStreamObjectResult = class {
15351
15529
  this.baseStream = stitchableStream.stream.pipeThrough(eventProcessor);
15352
15530
  const callId = generateId5();
15353
15531
  (async () => {
15354
- const jsonSchema2 = await outputStrategy.jsonSchema();
15532
+ const jsonSchema3 = await outputStrategy.jsonSchema();
15355
15533
  await notify({
15356
15534
  event: {
15357
15535
  callId,
@@ -15372,7 +15550,7 @@ var DefaultStreamObjectResult = class {
15372
15550
  headers,
15373
15551
  providerOptions,
15374
15552
  output: outputStrategy.type,
15375
- schema: jsonSchema2,
15553
+ schema: jsonSchema3,
15376
15554
  schemaName,
15377
15555
  schemaDescription
15378
15556
  },
@@ -15388,7 +15566,7 @@ var DefaultStreamObjectResult = class {
15388
15566
  const callOptions = {
15389
15567
  responseFormat: {
15390
15568
  type: "json",
15391
- schema: jsonSchema2,
15569
+ schema: jsonSchema3,
15392
15570
  name: schemaName,
15393
15571
  description: schemaDescription
15394
15572
  },
@@ -16085,11 +16263,11 @@ function tagDescription(description) {
16085
16263
  async function fingerprintTools(tools) {
16086
16264
  const entries = await Promise.all(
16087
16265
  Object.keys(tools).map(async (name25) => {
16088
- const tool2 = tools[name25];
16266
+ const tool3 = tools[name25];
16089
16267
  const digest = await hashCanonical({
16090
- description: tagDescription(tool2.description),
16091
- inputSchema: await asSchema6(tool2.inputSchema).jsonSchema,
16092
- title: tool2.title
16268
+ description: tagDescription(tool3.description),
16269
+ inputSchema: await asSchema6(tool3.inputSchema).jsonSchema,
16270
+ title: tool3.title
16093
16271
  });
16094
16272
  return [name25, digest];
16095
16273
  })
@@ -17099,21 +17277,21 @@ function addToolInputExamplesMiddleware({
17099
17277
  if (!((_a25 = params.tools) == null ? void 0 : _a25.length)) {
17100
17278
  return params;
17101
17279
  }
17102
- const transformedTools = params.tools.map((tool2) => {
17280
+ const transformedTools = params.tools.map((tool3) => {
17103
17281
  var _a26;
17104
- if (tool2.type !== "function" || !((_a26 = tool2.inputExamples) == null ? void 0 : _a26.length)) {
17105
- return tool2;
17282
+ if (tool3.type !== "function" || !((_a26 = tool3.inputExamples) == null ? void 0 : _a26.length)) {
17283
+ return tool3;
17106
17284
  }
17107
- const formattedExamples = tool2.inputExamples.map((example, index) => format(example, index)).join("\n");
17285
+ const formattedExamples = tool3.inputExamples.map((example, index) => format(example, index)).join("\n");
17108
17286
  const examplesSection = `${prefix}
17109
17287
  ${formattedExamples}`;
17110
- const toolDescription = tool2.description ? `${tool2.description}
17288
+ const toolDescription = tool3.description ? `${tool3.description}
17111
17289
 
17112
17290
  ${examplesSection}` : examplesSection;
17113
17291
  return {
17114
- ...tool2,
17292
+ ...tool3,
17115
17293
  description: toolDescription,
17116
- inputExamples: remove ? void 0 : tool2.inputExamples
17294
+ inputExamples: remove ? void 0 : tool3.inputExamples
17117
17295
  };
17118
17296
  });
17119
17297
  return {
@@ -17372,14 +17550,14 @@ async function getRealtimeToolDefinitions({
17372
17550
  toolsContext = {}
17373
17551
  }) {
17374
17552
  const definitions = [];
17375
- for (const [name25, tool2] of Object.entries(tools)) {
17376
- const toolType = tool2.type;
17553
+ for (const [name25, tool3] of Object.entries(tools)) {
17554
+ const toolType = tool3.type;
17377
17555
  switch (toolType) {
17378
17556
  case void 0:
17379
17557
  case "function":
17380
17558
  case "dynamic": {
17381
17559
  const description = resolveRealtimeToolDescription({
17382
- tool: tool2,
17560
+ tool: tool3,
17383
17561
  toolName: name25,
17384
17562
  toolsContext
17385
17563
  });
@@ -17387,7 +17565,7 @@ async function getRealtimeToolDefinitions({
17387
17565
  type: "function",
17388
17566
  name: name25,
17389
17567
  description,
17390
- parameters: await asSchema7(tool2.inputSchema).jsonSchema
17568
+ parameters: await asSchema7(tool3.inputSchema).jsonSchema
17391
17569
  });
17392
17570
  break;
17393
17571
  }
@@ -17402,11 +17580,11 @@ async function getRealtimeToolDefinitions({
17402
17580
  return definitions;
17403
17581
  }
17404
17582
  function resolveRealtimeToolDescription({
17405
- tool: tool2,
17583
+ tool: tool3,
17406
17584
  toolName,
17407
17585
  toolsContext
17408
17586
  }) {
17409
- return tool2.description === void 0 ? void 0 : typeof tool2.description === "string" ? tool2.description : tool2.description({
17587
+ return tool3.description === void 0 ? void 0 : typeof tool3.description === "string" ? tool3.description : tool3.description({
17410
17588
  context: toolsContext[toolName]
17411
17589
  });
17412
17590
  }
@@ -17652,6 +17830,9 @@ var RealtimeEventChannel = class {
17652
17830
  var _a25, _b25, _c;
17653
17831
  this.parse = (_c = (_b25 = (_a25 = options.model).createServerEventParser) == null ? void 0 : _b25.call(_a25)) != null ? _c : options.model.parseServerEvent.bind(options.model);
17654
17832
  }
17833
+ get hasPendingIncoming() {
17834
+ return this.incomingCount > 0;
17835
+ }
17655
17836
  dispose() {
17656
17837
  this.active = false;
17657
17838
  }
@@ -17896,9 +18077,18 @@ var BrowserRealtimeTransport = class {
17896
18077
  if (this.ws === ws) {
17897
18078
  this.ws = null;
17898
18079
  const closeError = (_a26 = getCloseError(event)) != null ? _a26 : connectionError;
18080
+ const reportCloseErrorImmediately = closeError != null && !codec.hasPendingIncoming;
17899
18081
  codec.stopWriting();
17900
18082
  this.notifyClosing();
17901
18083
  if (this.epoch !== epoch) return;
18084
+ const drain = codec.finish();
18085
+ if (reportCloseErrorImmediately) {
18086
+ try {
18087
+ this.onError(closeError);
18088
+ } catch (e) {
18089
+ }
18090
+ if (this.epoch !== epoch) return;
18091
+ }
17902
18092
  const complete = () => {
17903
18093
  if (this.epoch !== epoch) return;
17904
18094
  clearTimeout(this.drainTimer);
@@ -17911,7 +18101,7 @@ var BrowserRealtimeTransport = class {
17911
18101
  }
17912
18102
  };
17913
18103
  this.drainTimer = setTimeout(complete, 1e3);
17914
- void this.awaitDrain(codec.finish(), complete);
18104
+ void this.awaitDrain(drain, complete);
17915
18105
  }
17916
18106
  };
17917
18107
  }
@@ -19354,6 +19544,7 @@ var AbstractRealtimeSession = class {
19354
19544
  if (current())
19355
19545
  this.fail(new Error("Realtime session startup timed out"));
19356
19546
  });
19547
+ const reportedTransportErrors = /* @__PURE__ */ new WeakSet();
19357
19548
  const callbacks = {
19358
19549
  model,
19359
19550
  onEvent: async (event) => {
@@ -19370,7 +19561,10 @@ var AbstractRealtimeSession = class {
19370
19561
  }
19371
19562
  },
19372
19563
  onError: (error) => {
19373
- if (current()) void this.reportError(error, attempt);
19564
+ if (current()) {
19565
+ reportedTransportErrors.add(error);
19566
+ void this.reportError(error, attempt);
19567
+ }
19374
19568
  },
19375
19569
  onFatalError: (error, drain) => {
19376
19570
  if (current()) this.fail(error, drain);
@@ -19392,7 +19586,8 @@ var AbstractRealtimeSession = class {
19392
19586
  var _a26, _b26;
19393
19587
  if (!current()) return;
19394
19588
  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) this.fail(error);
19589
+ if (error != null && !finalizationConfirmed)
19590
+ this.fail(error, void 0, !reportedTransportErrors.has(error));
19396
19591
  else if (!attempt.ready && !finalizationConfirmed)
19397
19592
  this.fail(
19398
19593
  new Error("Realtime connection closed before becoming ready")
@@ -19490,7 +19685,7 @@ var AbstractRealtimeSession = class {
19490
19685
  if (current()) this.fail(error);
19491
19686
  }
19492
19687
  }
19493
- fail(error, drain) {
19688
+ fail(error, drain, report = true) {
19494
19689
  const attempt = this.attempt;
19495
19690
  if (attempt == null || !attempt.active || attempt.cause != null) return;
19496
19691
  attempt.cause = error instanceof Error ? error : new Error(String(error));
@@ -19501,7 +19696,7 @@ var AbstractRealtimeSession = class {
19501
19696
  if (this.attempt !== attempt || !attempt.active) return;
19502
19697
  if (drain == null) this.disconnect();
19503
19698
  else void this.drainAttempt(attempt, drain);
19504
- void this.reportError(attempt.cause, attempt);
19699
+ if (report) void this.reportError(attempt.cause, attempt);
19505
19700
  }
19506
19701
  async drainAttempt(attempt, drain) {
19507
19702
  if (this.attempt === attempt && attempt.active)
@@ -19956,7 +20151,7 @@ var AbstractRealtimeSession = class {
19956
20151
 
19957
20152
  // src/registry/custom-provider.ts
19958
20153
  import {
19959
- NoSuchModelError as NoSuchModelError2
20154
+ NoSuchModelError as NoSuchModelError3
19960
20155
  } from "@ai-sdk/provider";
19961
20156
  function customProvider({
19962
20157
  languageModels,
@@ -19966,6 +20161,7 @@ function customProvider({
19966
20161
  speechModels,
19967
20162
  rerankingModels,
19968
20163
  videoModels,
20164
+ evaluationModels,
19969
20165
  files,
19970
20166
  skills,
19971
20167
  fallbackProvider: fallbackProviderArg
@@ -19980,7 +20176,7 @@ function customProvider({
19980
20176
  if (fallbackProvider) {
19981
20177
  return fallbackProvider.languageModel(modelId);
19982
20178
  }
19983
- throw new NoSuchModelError2({ modelId, modelType: "languageModel" });
20179
+ throw new NoSuchModelError3({ modelId, modelType: "languageModel" });
19984
20180
  },
19985
20181
  embeddingModel(modelId) {
19986
20182
  if (embeddingModels != null && modelId in embeddingModels) {
@@ -19989,7 +20185,7 @@ function customProvider({
19989
20185
  if (fallbackProvider) {
19990
20186
  return fallbackProvider.embeddingModel(modelId);
19991
20187
  }
19992
- throw new NoSuchModelError2({ modelId, modelType: "embeddingModel" });
20188
+ throw new NoSuchModelError3({ modelId, modelType: "embeddingModel" });
19993
20189
  },
19994
20190
  imageModel(modelId) {
19995
20191
  if (imageModels != null && modelId in imageModels) {
@@ -19998,7 +20194,7 @@ function customProvider({
19998
20194
  if (fallbackProvider == null ? void 0 : fallbackProvider.imageModel) {
19999
20195
  return fallbackProvider.imageModel(modelId);
20000
20196
  }
20001
- throw new NoSuchModelError2({ modelId, modelType: "imageModel" });
20197
+ throw new NoSuchModelError3({ modelId, modelType: "imageModel" });
20002
20198
  },
20003
20199
  transcriptionModel(modelId) {
20004
20200
  if (transcriptionModels != null && modelId in transcriptionModels) {
@@ -20010,7 +20206,7 @@ function customProvider({
20010
20206
  if (fallbackProvider == null ? void 0 : fallbackProvider.transcriptionModel) {
20011
20207
  return fallbackProvider.transcriptionModel(modelId);
20012
20208
  }
20013
- throw new NoSuchModelError2({ modelId, modelType: "transcriptionModel" });
20209
+ throw new NoSuchModelError3({ modelId, modelType: "transcriptionModel" });
20014
20210
  },
20015
20211
  speechModel(modelId) {
20016
20212
  if (speechModels != null && modelId in speechModels) {
@@ -20022,7 +20218,7 @@ function customProvider({
20022
20218
  if (fallbackProvider == null ? void 0 : fallbackProvider.speechModel) {
20023
20219
  return fallbackProvider.speechModel(modelId);
20024
20220
  }
20025
- throw new NoSuchModelError2({ modelId, modelType: "speechModel" });
20221
+ throw new NoSuchModelError3({ modelId, modelType: "speechModel" });
20026
20222
  },
20027
20223
  rerankingModel(modelId) {
20028
20224
  if (rerankingModels != null && modelId in rerankingModels) {
@@ -20031,7 +20227,20 @@ function customProvider({
20031
20227
  if (fallbackProvider == null ? void 0 : fallbackProvider.rerankingModel) {
20032
20228
  return fallbackProvider.rerankingModel(modelId);
20033
20229
  }
20034
- throw new NoSuchModelError2({ modelId, modelType: "rerankingModel" });
20230
+ throw new NoSuchModelError3({ modelId, modelType: "rerankingModel" });
20231
+ },
20232
+ evaluationModel(modelId) {
20233
+ if (evaluationModels != null && Object.hasOwn(evaluationModels, modelId)) {
20234
+ return resolveEvaluationModel(evaluationModels[modelId]);
20235
+ }
20236
+ const provider = fallbackProviderArg;
20237
+ if (typeof (provider == null ? void 0 : provider.evaluationModel) === "function") {
20238
+ const model = provider.evaluationModel(modelId);
20239
+ if (model != null) {
20240
+ return resolveEvaluationModel(model);
20241
+ }
20242
+ }
20243
+ throw new NoSuchModelError3({ modelId, modelType: "evaluationModel" });
20035
20244
  },
20036
20245
  videoModel(modelId) {
20037
20246
  if (videoModels != null && modelId in videoModels) {
@@ -20041,7 +20250,7 @@ function customProvider({
20041
20250
  if (videoModel) {
20042
20251
  return videoModel(modelId);
20043
20252
  }
20044
- throw new NoSuchModelError2({ modelId, modelType: "videoModel" });
20253
+ throw new NoSuchModelError3({ modelId, modelType: "videoModel" });
20045
20254
  }
20046
20255
  };
20047
20256
  const filesAndSkills = {
@@ -20060,12 +20269,12 @@ function customProvider({
20060
20269
  }
20061
20270
 
20062
20271
  // src/registry/no-such-provider-error.ts
20063
- import { AISDKError as AISDKError28, NoSuchModelError as NoSuchModelError3 } from "@ai-sdk/provider";
20272
+ import { AISDKError as AISDKError28, NoSuchModelError as NoSuchModelError4 } from "@ai-sdk/provider";
20064
20273
  var name24 = "AI_NoSuchProviderError";
20065
20274
  var marker24 = `vercel.ai.error.${name24}`;
20066
20275
  var symbol24 = Symbol.for(marker24);
20067
20276
  var _a24, _b24;
20068
- var NoSuchProviderError = class extends (_b24 = NoSuchModelError3, _a24 = symbol24, _b24) {
20277
+ var NoSuchProviderError = class extends (_b24 = NoSuchModelError4, _a24 = symbol24, _b24) {
20069
20278
  constructor({
20070
20279
  modelId,
20071
20280
  modelType,
@@ -20085,7 +20294,7 @@ var NoSuchProviderError = class extends (_b24 = NoSuchModelError3, _a24 = symbol
20085
20294
 
20086
20295
  // src/registry/provider-registry.ts
20087
20296
  import {
20088
- NoSuchModelError as NoSuchModelError4
20297
+ NoSuchModelError as NoSuchModelError5
20089
20298
  } from "@ai-sdk/provider";
20090
20299
  function createProviderRegistry(providers, {
20091
20300
  separator = ":",
@@ -20118,13 +20327,18 @@ var DefaultProviderRegistry = class {
20118
20327
  id,
20119
20328
  provider
20120
20329
  }) {
20121
- var _a25;
20330
+ var _a25, _b25;
20122
20331
  const providerV4 = asProviderV4(provider);
20123
20332
  const videoModel = (_a25 = provider.videoModel) == null ? void 0 : _a25.bind(provider);
20124
- this.providers[id] = videoModel == null ? providerV4 : Object.assign(Object.create(Object.getPrototypeOf(providerV4)), {
20333
+ const evaluationModel = (_b25 = provider.evaluationModel) == null ? void 0 : _b25.bind(provider);
20334
+ const registeredProvider = videoModel == null ? providerV4 : Object.assign(Object.create(Object.getPrototypeOf(providerV4)), {
20125
20335
  ...providerV4,
20126
20336
  videoModel: (modelId) => asVideoModelV4(videoModel(modelId))
20127
20337
  });
20338
+ if (registeredProvider !== provider && evaluationModel != null) {
20339
+ Object.assign(registeredProvider, { evaluationModel });
20340
+ }
20341
+ this.providers[id] = registeredProvider;
20128
20342
  }
20129
20343
  getProvider(id, modelType) {
20130
20344
  const provider = this.providers[id];
@@ -20141,7 +20355,7 @@ var DefaultProviderRegistry = class {
20141
20355
  splitId(id, modelType) {
20142
20356
  const index = id.indexOf(this.separator);
20143
20357
  if (index === -1) {
20144
- throw new NoSuchModelError4({
20358
+ throw new NoSuchModelError5({
20145
20359
  modelId: id,
20146
20360
  modelType,
20147
20361
  message: `Invalid ${modelType} id for registry: ${id} (must be in the format "providerId${this.separator}modelId")`
@@ -20157,7 +20371,7 @@ var DefaultProviderRegistry = class {
20157
20371
  modelId
20158
20372
  );
20159
20373
  if (model == null) {
20160
- throw new NoSuchModelError4({ modelId: id, modelType: "languageModel" });
20374
+ throw new NoSuchModelError5({ modelId: id, modelType: "languageModel" });
20161
20375
  }
20162
20376
  if (this.languageModelMiddleware != null) {
20163
20377
  model = wrapLanguageModel({
@@ -20173,7 +20387,7 @@ var DefaultProviderRegistry = class {
20173
20387
  const provider = this.getProvider(providerId, "embeddingModel");
20174
20388
  const model = (_a25 = provider.embeddingModel) == null ? void 0 : _a25.call(provider, modelId);
20175
20389
  if (model == null) {
20176
- throw new NoSuchModelError4({
20390
+ throw new NoSuchModelError5({
20177
20391
  modelId: id,
20178
20392
  modelType: "embeddingModel"
20179
20393
  });
@@ -20186,7 +20400,7 @@ var DefaultProviderRegistry = class {
20186
20400
  const provider = this.getProvider(providerId, "imageModel");
20187
20401
  let model = (_a25 = provider.imageModel) == null ? void 0 : _a25.call(provider, modelId);
20188
20402
  if (model == null) {
20189
- throw new NoSuchModelError4({ modelId: id, modelType: "imageModel" });
20403
+ throw new NoSuchModelError5({ modelId: id, modelType: "imageModel" });
20190
20404
  }
20191
20405
  if (this.imageModelMiddleware != null) {
20192
20406
  model = wrapImageModel({
@@ -20202,7 +20416,7 @@ var DefaultProviderRegistry = class {
20202
20416
  const provider = this.getProvider(providerId, "transcriptionModel");
20203
20417
  const model = (_a25 = provider.transcriptionModel) == null ? void 0 : _a25.call(provider, modelId);
20204
20418
  if (model == null) {
20205
- throw new NoSuchModelError4({
20419
+ throw new NoSuchModelError5({
20206
20420
  modelId: id,
20207
20421
  modelType: "transcriptionModel"
20208
20422
  });
@@ -20215,7 +20429,7 @@ var DefaultProviderRegistry = class {
20215
20429
  const provider = this.getProvider(providerId, "speechModel");
20216
20430
  const model = (_a25 = provider.speechModel) == null ? void 0 : _a25.call(provider, modelId);
20217
20431
  if (model == null) {
20218
- throw new NoSuchModelError4({ modelId: id, modelType: "speechModel" });
20432
+ throw new NoSuchModelError5({ modelId: id, modelType: "speechModel" });
20219
20433
  }
20220
20434
  return model;
20221
20435
  }
@@ -20225,7 +20439,7 @@ var DefaultProviderRegistry = class {
20225
20439
  const provider = this.getProvider(providerId, "rerankingModel");
20226
20440
  const model = (_a25 = provider.rerankingModel) == null ? void 0 : _a25.call(provider, modelId);
20227
20441
  if (model == null) {
20228
- throw new NoSuchModelError4({ modelId: id, modelType: "rerankingModel" });
20442
+ throw new NoSuchModelError5({ modelId: id, modelType: "rerankingModel" });
20229
20443
  }
20230
20444
  return model;
20231
20445
  }
@@ -20235,10 +20449,20 @@ var DefaultProviderRegistry = class {
20235
20449
  const provider = this.getProvider(providerId, "videoModel");
20236
20450
  const model = (_a25 = provider.videoModel) == null ? void 0 : _a25.call(provider, modelId);
20237
20451
  if (model == null) {
20238
- throw new NoSuchModelError4({ modelId: id, modelType: "videoModel" });
20452
+ throw new NoSuchModelError5({ modelId: id, modelType: "videoModel" });
20239
20453
  }
20240
20454
  return asVideoModelV4(model);
20241
20455
  }
20456
+ evaluationModel(id) {
20457
+ var _a25;
20458
+ const [providerId, modelId] = this.splitId(id, "evaluationModel");
20459
+ const provider = this.getProvider(providerId, "evaluationModel");
20460
+ const model = (_a25 = provider.evaluationModel) == null ? void 0 : _a25.call(provider, modelId);
20461
+ if (model == null) {
20462
+ throw new NoSuchModelError5({ modelId: id, modelType: "evaluationModel" });
20463
+ }
20464
+ return resolveEvaluationModel(model);
20465
+ }
20242
20466
  files(id) {
20243
20467
  var _a25;
20244
20468
  const provider = this.getProvider(id, "languageModel");
@@ -22224,7 +22448,7 @@ export {
22224
22448
  isTextUIPart,
22225
22449
  isToolOutputErrorUIPart,
22226
22450
  isToolUIPart,
22227
- jsonSchema,
22451
+ jsonSchema2 as jsonSchema,
22228
22452
  lastAssistantMessageIsCompleteWithApprovalResponses,
22229
22453
  lastAssistantMessageIsCompleteWithToolCalls,
22230
22454
  modelMessageSchema,
@@ -22248,8 +22472,9 @@ export {
22248
22472
  toTextStream,
22249
22473
  toUIMessageChunk,
22250
22474
  toUIMessageStream,
22251
- tool,
22475
+ tool2 as tool,
22252
22476
  toolModelMessageSchema,
22477
+ toolSearch,
22253
22478
  transcribe,
22254
22479
  uiMessageChunkSchema,
22255
22480
  uploadFile,