ai 5.0.0-beta.27 → 5.0.0-beta.29

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/dist/index.js CHANGED
@@ -56,7 +56,7 @@ __export(src_exports, {
56
56
  UI_MESSAGE_STREAM_HEADERS: () => UI_MESSAGE_STREAM_HEADERS,
57
57
  UnsupportedFunctionalityError: () => import_provider18.UnsupportedFunctionalityError,
58
58
  UnsupportedModelVersionError: () => UnsupportedModelVersionError,
59
- asSchema: () => import_provider_utils29.asSchema,
59
+ asSchema: () => import_provider_utils27.asSchema,
60
60
  assistantModelMessageSchema: () => assistantModelMessageSchema,
61
61
  callCompletionApi: () => callCompletionApi,
62
62
  consumeStream: () => consumeStream,
@@ -69,13 +69,14 @@ __export(src_exports, {
69
69
  coreToolMessageSchema: () => coreToolMessageSchema,
70
70
  coreUserMessageSchema: () => coreUserMessageSchema,
71
71
  cosineSimilarity: () => cosineSimilarity,
72
- createIdGenerator: () => import_provider_utils29.createIdGenerator,
72
+ createIdGenerator: () => import_provider_utils27.createIdGenerator,
73
73
  createProviderRegistry: () => createProviderRegistry,
74
74
  createTextStreamResponse: () => createTextStreamResponse,
75
75
  createUIMessageStream: () => createUIMessageStream,
76
76
  createUIMessageStreamResponse: () => createUIMessageStreamResponse,
77
77
  customProvider: () => customProvider,
78
78
  defaultSettingsMiddleware: () => defaultSettingsMiddleware,
79
+ dynamicTool: () => import_provider_utils27.dynamicTool,
79
80
  embed: () => embed,
80
81
  embedMany: () => embedMany,
81
82
  experimental_createMCPClient: () => createMCPClient,
@@ -85,7 +86,7 @@ __export(src_exports, {
85
86
  experimental_generateSpeech: () => generateSpeech,
86
87
  experimental_transcribe: () => transcribe,
87
88
  extractReasoningMiddleware: () => extractReasoningMiddleware,
88
- generateId: () => import_provider_utils29.generateId,
89
+ generateId: () => import_provider_utils27.generateId,
89
90
  generateObject: () => generateObject,
90
91
  generateText: () => generateText,
91
92
  getTextFromDataUrl: () => getTextFromDataUrl,
@@ -93,7 +94,7 @@ __export(src_exports, {
93
94
  hasToolCall: () => hasToolCall,
94
95
  isDeepEqualData: () => isDeepEqualData,
95
96
  isToolUIPart: () => isToolUIPart,
96
- jsonSchema: () => import_provider_utils29.jsonSchema,
97
+ jsonSchema: () => import_provider_utils27.jsonSchema,
97
98
  lastAssistantMessageIsCompleteWithToolCalls: () => lastAssistantMessageIsCompleteWithToolCalls,
98
99
  modelMessageSchema: () => modelMessageSchema,
99
100
  parsePartialJson: () => parsePartialJson,
@@ -107,14 +108,14 @@ __export(src_exports, {
107
108
  streamObject: () => streamObject,
108
109
  streamText: () => streamText,
109
110
  systemModelMessageSchema: () => systemModelMessageSchema,
110
- tool: () => import_provider_utils23.tool,
111
+ tool: () => import_provider_utils27.tool,
111
112
  toolModelMessageSchema: () => toolModelMessageSchema,
112
113
  userModelMessageSchema: () => userModelMessageSchema,
113
114
  wrapLanguageModel: () => wrapLanguageModel,
114
115
  wrapProvider: () => wrapProvider
115
116
  });
116
117
  module.exports = __toCommonJS(src_exports);
117
- var import_provider_utils29 = require("@ai-sdk/provider-utils");
118
+ var import_provider_utils27 = require("@ai-sdk/provider-utils");
118
119
 
119
120
  // src/generate-text/generate-text.ts
120
121
  var import_provider_utils9 = require("@ai-sdk/provider-utils");
@@ -971,12 +972,14 @@ function prepareToolsAndToolChoice({
971
972
  const toolType = tool3.type;
972
973
  switch (toolType) {
973
974
  case void 0:
975
+ case "dynamic":
974
976
  case "function":
975
977
  return {
976
978
  type: "function",
977
979
  name: name16,
978
980
  description: tool3.description,
979
- inputSchema: (0, import_provider_utils5.asSchema)(tool3.inputSchema).jsonSchema
981
+ inputSchema: (0, import_provider_utils5.asSchema)(tool3.inputSchema).jsonSchema,
982
+ providerOptions: tool3.providerOptions
980
983
  };
981
984
  case "provider-defined":
982
985
  return {
@@ -1777,7 +1780,15 @@ async function doParseToolCall({
1777
1780
  cause: parseResult.error
1778
1781
  });
1779
1782
  }
1780
- return {
1783
+ return tool3.type === "dynamic" ? {
1784
+ type: "tool-call",
1785
+ toolCallId: toolCall.toolCallId,
1786
+ toolName: toolCall.toolName,
1787
+ input: parseResult.value,
1788
+ providerExecuted: toolCall.providerExecuted,
1789
+ providerMetadata: toolCall.providerMetadata,
1790
+ dynamic: true
1791
+ } : {
1781
1792
  type: "tool-call",
1782
1793
  toolCallId: toolCall.toolCallId,
1783
1794
  toolName,
@@ -2318,7 +2329,8 @@ async function executeTools({
2318
2329
  toolCallId,
2319
2330
  toolName,
2320
2331
  input,
2321
- output: result
2332
+ output: result,
2333
+ dynamic: tool3.type === "dynamic"
2322
2334
  };
2323
2335
  } catch (error) {
2324
2336
  recordErrorOnSpan(span, error);
@@ -2327,7 +2339,8 @@ async function executeTools({
2327
2339
  toolCallId,
2328
2340
  toolName,
2329
2341
  input,
2330
- error
2342
+ error,
2343
+ dynamic: tool3.type === "dynamic"
2331
2344
  };
2332
2345
  }
2333
2346
  }
@@ -2459,7 +2472,8 @@ function asContent({
2459
2472
  toolName: part.toolName,
2460
2473
  input: toolCall.input,
2461
2474
  error: part.result,
2462
- providerExecuted: true
2475
+ providerExecuted: true,
2476
+ dynamic: toolCall.dynamic
2463
2477
  };
2464
2478
  }
2465
2479
  return {
@@ -2468,7 +2482,8 @@ function asContent({
2468
2482
  toolName: part.toolName,
2469
2483
  input: toolCall.input,
2470
2484
  output: part.result,
2471
- providerExecuted: true
2485
+ providerExecuted: true,
2486
+ dynamic: toolCall.dynamic
2472
2487
  };
2473
2488
  }
2474
2489
  }
@@ -2645,7 +2660,8 @@ var uiMessageChunkSchema = import_v47.z.union([
2645
2660
  type: import_v47.z.literal("tool-input-start"),
2646
2661
  toolCallId: import_v47.z.string(),
2647
2662
  toolName: import_v47.z.string(),
2648
- providerExecuted: import_v47.z.boolean().optional()
2663
+ providerExecuted: import_v47.z.boolean().optional(),
2664
+ dynamic: import_v47.z.boolean().optional()
2649
2665
  }),
2650
2666
  import_v47.z.strictObject({
2651
2667
  type: import_v47.z.literal("tool-input-delta"),
@@ -2658,19 +2674,22 @@ var uiMessageChunkSchema = import_v47.z.union([
2658
2674
  toolName: import_v47.z.string(),
2659
2675
  input: import_v47.z.unknown(),
2660
2676
  providerExecuted: import_v47.z.boolean().optional(),
2661
- providerMetadata: providerMetadataSchema.optional()
2677
+ providerMetadata: providerMetadataSchema.optional(),
2678
+ dynamic: import_v47.z.boolean().optional()
2662
2679
  }),
2663
2680
  import_v47.z.strictObject({
2664
2681
  type: import_v47.z.literal("tool-output-available"),
2665
2682
  toolCallId: import_v47.z.string(),
2666
2683
  output: import_v47.z.unknown(),
2667
- providerExecuted: import_v47.z.boolean().optional()
2684
+ providerExecuted: import_v47.z.boolean().optional(),
2685
+ dynamic: import_v47.z.boolean().optional()
2668
2686
  }),
2669
2687
  import_v47.z.strictObject({
2670
2688
  type: import_v47.z.literal("tool-output-error"),
2671
2689
  toolCallId: import_v47.z.string(),
2672
2690
  errorText: import_v47.z.string(),
2673
- providerExecuted: import_v47.z.boolean().optional()
2691
+ providerExecuted: import_v47.z.boolean().optional(),
2692
+ dynamic: import_v47.z.boolean().optional()
2674
2693
  }),
2675
2694
  import_v47.z.strictObject({
2676
2695
  type: import_v47.z.literal("reasoning"),
@@ -3159,7 +3178,33 @@ function processUIMessageStream({
3159
3178
  async transform(chunk, controller) {
3160
3179
  await runUpdateMessageJob(async ({ state, write }) => {
3161
3180
  var _a16, _b, _c, _d;
3162
- function updateToolInvocationPart(options) {
3181
+ function getToolInvocation(toolCallId) {
3182
+ const toolInvocations = state.message.parts.filter(isToolUIPart);
3183
+ const toolInvocation = toolInvocations.find(
3184
+ (invocation) => invocation.toolCallId === toolCallId
3185
+ );
3186
+ if (toolInvocation == null) {
3187
+ throw new Error(
3188
+ "tool-output-error must be preceded by a tool-input-available"
3189
+ );
3190
+ }
3191
+ return toolInvocation;
3192
+ }
3193
+ function getDynamicToolInvocation(toolCallId) {
3194
+ const toolInvocations = state.message.parts.filter(
3195
+ (part) => part.type === "dynamic-tool"
3196
+ );
3197
+ const toolInvocation = toolInvocations.find(
3198
+ (invocation) => invocation.toolCallId === toolCallId
3199
+ );
3200
+ if (toolInvocation == null) {
3201
+ throw new Error(
3202
+ "tool-output-error must be preceded by a tool-input-available"
3203
+ );
3204
+ }
3205
+ return toolInvocation;
3206
+ }
3207
+ function updateToolPart(options) {
3163
3208
  var _a17;
3164
3209
  const part = state.message.parts.find(
3165
3210
  (part2) => isToolUIPart(part2) && part2.toolCallId === options.toolCallId
@@ -3188,6 +3233,34 @@ function processUIMessageStream({
3188
3233
  });
3189
3234
  }
3190
3235
  }
3236
+ function updateDynamicToolPart(options) {
3237
+ const part = state.message.parts.find(
3238
+ (part2) => part2.type === "dynamic-tool" && part2.toolCallId === options.toolCallId
3239
+ );
3240
+ const anyOptions = options;
3241
+ const anyPart = part;
3242
+ if (part != null) {
3243
+ part.state = options.state;
3244
+ anyPart.toolName = options.toolName;
3245
+ anyPart.input = anyOptions.input;
3246
+ anyPart.output = anyOptions.output;
3247
+ anyPart.errorText = anyOptions.errorText;
3248
+ if (anyOptions.providerMetadata != null && part.state === "input-available") {
3249
+ part.callProviderMetadata = anyOptions.providerMetadata;
3250
+ }
3251
+ } else {
3252
+ state.message.parts.push({
3253
+ type: "dynamic-tool",
3254
+ toolName: options.toolName,
3255
+ toolCallId: options.toolCallId,
3256
+ state: options.state,
3257
+ input: anyOptions.input,
3258
+ output: anyOptions.output,
3259
+ errorText: anyOptions.errorText,
3260
+ ...anyOptions.providerMetadata != null ? { callProviderMetadata: anyOptions.providerMetadata } : {}
3261
+ });
3262
+ }
3263
+ }
3191
3264
  async function updateMessageMetadata(metadata) {
3192
3265
  if (metadata != null) {
3193
3266
  const mergedMetadata = state.message.metadata != null ? mergeObjects(state.message.metadata, metadata) : metadata;
@@ -3292,15 +3365,25 @@ function processUIMessageStream({
3292
3365
  state.partialToolCalls[chunk.toolCallId] = {
3293
3366
  text: "",
3294
3367
  toolName: chunk.toolName,
3295
- index: toolInvocations.length
3368
+ index: toolInvocations.length,
3369
+ dynamic: chunk.dynamic
3296
3370
  };
3297
- updateToolInvocationPart({
3298
- toolCallId: chunk.toolCallId,
3299
- toolName: chunk.toolName,
3300
- state: "input-streaming",
3301
- input: void 0,
3302
- providerExecuted: chunk.providerExecuted
3303
- });
3371
+ if (chunk.dynamic) {
3372
+ updateDynamicToolPart({
3373
+ toolCallId: chunk.toolCallId,
3374
+ toolName: chunk.toolName,
3375
+ state: "input-streaming",
3376
+ input: void 0
3377
+ });
3378
+ } else {
3379
+ updateToolPart({
3380
+ toolCallId: chunk.toolCallId,
3381
+ toolName: chunk.toolName,
3382
+ state: "input-streaming",
3383
+ input: void 0,
3384
+ providerExecuted: chunk.providerExecuted
3385
+ });
3386
+ }
3304
3387
  write();
3305
3388
  break;
3306
3389
  }
@@ -3310,26 +3393,45 @@ function processUIMessageStream({
3310
3393
  const { value: partialArgs } = await parsePartialJson(
3311
3394
  partialToolCall.text
3312
3395
  );
3313
- updateToolInvocationPart({
3314
- toolCallId: chunk.toolCallId,
3315
- toolName: partialToolCall.toolName,
3316
- state: "input-streaming",
3317
- input: partialArgs
3318
- });
3396
+ if (partialToolCall.dynamic) {
3397
+ updateDynamicToolPart({
3398
+ toolCallId: chunk.toolCallId,
3399
+ toolName: partialToolCall.toolName,
3400
+ state: "input-streaming",
3401
+ input: partialArgs
3402
+ });
3403
+ } else {
3404
+ updateToolPart({
3405
+ toolCallId: chunk.toolCallId,
3406
+ toolName: partialToolCall.toolName,
3407
+ state: "input-streaming",
3408
+ input: partialArgs
3409
+ });
3410
+ }
3319
3411
  write();
3320
3412
  break;
3321
3413
  }
3322
3414
  case "tool-input-available": {
3323
- updateToolInvocationPart({
3324
- toolCallId: chunk.toolCallId,
3325
- toolName: chunk.toolName,
3326
- state: "input-available",
3327
- input: chunk.input,
3328
- providerExecuted: chunk.providerExecuted,
3329
- providerMetadata: chunk.providerMetadata
3330
- });
3415
+ if (chunk.dynamic) {
3416
+ updateDynamicToolPart({
3417
+ toolCallId: chunk.toolCallId,
3418
+ toolName: chunk.toolName,
3419
+ state: "input-available",
3420
+ input: chunk.input,
3421
+ providerMetadata: chunk.providerMetadata
3422
+ });
3423
+ } else {
3424
+ updateToolPart({
3425
+ toolCallId: chunk.toolCallId,
3426
+ toolName: chunk.toolName,
3427
+ state: "input-available",
3428
+ input: chunk.input,
3429
+ providerExecuted: chunk.providerExecuted,
3430
+ providerMetadata: chunk.providerMetadata
3431
+ });
3432
+ }
3331
3433
  write();
3332
- if (onToolCall && !chunk.providerExecuted) {
3434
+ if (onToolCall && !chunk.providerExecuted && !chunk.dynamic) {
3333
3435
  await onToolCall({
3334
3436
  toolCall: chunk
3335
3437
  });
@@ -3337,56 +3439,53 @@ function processUIMessageStream({
3337
3439
  break;
3338
3440
  }
3339
3441
  case "tool-output-available": {
3340
- const toolInvocations = state.message.parts.filter(isToolUIPart);
3341
- if (toolInvocations == null) {
3342
- throw new Error("tool_result must be preceded by a tool_call");
3343
- }
3344
- const toolInvocationIndex = toolInvocations.findIndex(
3345
- (invocation) => invocation.toolCallId === chunk.toolCallId
3346
- );
3347
- if (toolInvocationIndex === -1) {
3348
- throw new Error(
3349
- "tool_result must be preceded by a tool_call with the same toolCallId"
3442
+ if (chunk.dynamic) {
3443
+ const toolInvocation = getDynamicToolInvocation(
3444
+ chunk.toolCallId
3350
3445
  );
3446
+ updateDynamicToolPart({
3447
+ toolCallId: chunk.toolCallId,
3448
+ toolName: toolInvocation.toolName,
3449
+ state: "output-available",
3450
+ input: toolInvocation.input,
3451
+ output: chunk.output
3452
+ });
3453
+ } else {
3454
+ const toolInvocation = getToolInvocation(chunk.toolCallId);
3455
+ updateToolPart({
3456
+ toolCallId: chunk.toolCallId,
3457
+ toolName: getToolName(toolInvocation),
3458
+ state: "output-available",
3459
+ input: toolInvocation.input,
3460
+ output: chunk.output,
3461
+ providerExecuted: chunk.providerExecuted
3462
+ });
3351
3463
  }
3352
- const toolName = getToolName(
3353
- toolInvocations[toolInvocationIndex]
3354
- );
3355
- updateToolInvocationPart({
3356
- toolCallId: chunk.toolCallId,
3357
- toolName,
3358
- state: "output-available",
3359
- input: toolInvocations[toolInvocationIndex].input,
3360
- output: chunk.output,
3361
- providerExecuted: chunk.providerExecuted
3362
- });
3363
3464
  write();
3364
3465
  break;
3365
3466
  }
3366
3467
  case "tool-output-error": {
3367
- const toolInvocations = state.message.parts.filter(isToolUIPart);
3368
- if (toolInvocations == null) {
3369
- throw new Error("tool_result must be preceded by a tool_call");
3370
- }
3371
- const toolInvocationIndex = toolInvocations.findIndex(
3372
- (invocation) => invocation.toolCallId === chunk.toolCallId
3373
- );
3374
- if (toolInvocationIndex === -1) {
3375
- throw new Error(
3376
- "tool_result must be preceded by a tool_call with the same toolCallId"
3468
+ if (chunk.dynamic) {
3469
+ const toolInvocation = getDynamicToolInvocation(
3470
+ chunk.toolCallId
3377
3471
  );
3472
+ updateDynamicToolPart({
3473
+ toolCallId: chunk.toolCallId,
3474
+ toolName: toolInvocation.toolName,
3475
+ state: "output-error",
3476
+ input: toolInvocation.input,
3477
+ errorText: chunk.errorText
3478
+ });
3479
+ } else {
3480
+ const toolInvocation = getToolInvocation(chunk.toolCallId);
3481
+ updateToolPart({
3482
+ toolCallId: chunk.toolCallId,
3483
+ toolName: getToolName(toolInvocation),
3484
+ state: "output-error",
3485
+ input: toolInvocation.input,
3486
+ errorText: chunk.errorText
3487
+ });
3378
3488
  }
3379
- const toolName = getToolName(
3380
- toolInvocations[toolInvocationIndex]
3381
- );
3382
- updateToolInvocationPart({
3383
- toolCallId: chunk.toolCallId,
3384
- toolName,
3385
- state: "output-error",
3386
- input: toolInvocations[toolInvocationIndex].input,
3387
- errorText: chunk.errorText,
3388
- providerExecuted: chunk.providerExecuted
3389
- });
3390
3489
  write();
3391
3490
  break;
3392
3491
  }
@@ -4637,7 +4736,10 @@ var DefaultStreamTextResult = class {
4637
4736
  abortSignal
4638
4737
  });
4639
4738
  }
4640
- controller.enqueue(chunk);
4739
+ controller.enqueue({
4740
+ ...chunk,
4741
+ dynamic: (tool3 == null ? void 0 : tool3.type) === "dynamic"
4742
+ });
4641
4743
  break;
4642
4744
  }
4643
4745
  case "tool-input-end": {
@@ -5017,7 +5119,8 @@ var DefaultStreamTextResult = class {
5017
5119
  type: "tool-input-start",
5018
5120
  toolCallId: part.id,
5019
5121
  toolName: part.toolName,
5020
- providerExecuted: part.providerExecuted
5122
+ ...part.providerExecuted != null ? { providerExecuted: part.providerExecuted } : {},
5123
+ ...part.dynamic != null ? { dynamic: part.dynamic } : {}
5021
5124
  });
5022
5125
  break;
5023
5126
  }
@@ -5035,8 +5138,9 @@ var DefaultStreamTextResult = class {
5035
5138
  toolCallId: part.toolCallId,
5036
5139
  toolName: part.toolName,
5037
5140
  input: part.input,
5038
- providerExecuted: part.providerExecuted,
5039
- providerMetadata: part.providerMetadata
5141
+ ...part.providerExecuted != null ? { providerExecuted: part.providerExecuted } : {},
5142
+ ...part.providerMetadata != null ? { providerMetadata: part.providerMetadata } : {},
5143
+ ...part.dynamic != null ? { dynamic: part.dynamic } : {}
5040
5144
  });
5041
5145
  break;
5042
5146
  }
@@ -5045,7 +5149,8 @@ var DefaultStreamTextResult = class {
5045
5149
  type: "tool-output-available",
5046
5150
  toolCallId: part.toolCallId,
5047
5151
  output: part.output,
5048
- providerExecuted: part.providerExecuted
5152
+ ...part.providerExecuted != null ? { providerExecuted: part.providerExecuted } : {},
5153
+ ...part.dynamic != null ? { dynamic: part.dynamic } : {}
5049
5154
  });
5050
5155
  break;
5051
5156
  }
@@ -5054,7 +5159,8 @@ var DefaultStreamTextResult = class {
5054
5159
  type: "tool-output-error",
5055
5160
  toolCallId: part.toolCallId,
5056
5161
  errorText: onError(part.error),
5057
- providerExecuted: part.providerExecuted
5162
+ ...part.providerExecuted != null ? { providerExecuted: part.providerExecuted } : {},
5163
+ ...part.dynamic != null ? { dynamic: part.dynamic } : {}
5058
5164
  });
5059
5165
  break;
5060
5166
  }
@@ -7729,7 +7835,6 @@ var DefaultProviderRegistry = class {
7729
7835
 
7730
7836
  // src/tool/mcp/mcp-client.ts
7731
7837
  var import_provider_utils21 = require("@ai-sdk/provider-utils");
7732
- var import_provider_utils22 = require("@ai-sdk/provider-utils");
7733
7838
 
7734
7839
  // src/tool/mcp/mcp-sse-transport.ts
7735
7840
  var import_provider_utils20 = require("@ai-sdk/provider-utils");
@@ -7739,9 +7844,10 @@ var import_v49 = require("zod/v4");
7739
7844
 
7740
7845
  // src/tool/mcp/types.ts
7741
7846
  var import_v48 = require("zod/v4");
7742
- var LATEST_PROTOCOL_VERSION = "2025-03-26";
7847
+ var LATEST_PROTOCOL_VERSION = "2025-06-18";
7743
7848
  var SUPPORTED_PROTOCOL_VERSIONS = [
7744
7849
  LATEST_PROTOCOL_VERSION,
7850
+ "2025-03-26",
7745
7851
  "2024-11-05"
7746
7852
  ];
7747
7853
  var ClientOrServerImplementationSchema = import_v48.z.object({
@@ -8228,22 +8334,23 @@ var MCPClient = class {
8228
8334
  continue;
8229
8335
  }
8230
8336
  const self = this;
8231
- const toolWithExecute = (0, import_provider_utils22.tool)({
8337
+ const execute = async (args, options) => {
8338
+ var _a17;
8339
+ (_a17 = options == null ? void 0 : options.abortSignal) == null ? void 0 : _a17.throwIfAborted();
8340
+ return self.callTool({ name: name16, args, options });
8341
+ };
8342
+ const toolWithExecute = schemas === "automatic" ? (0, import_provider_utils21.dynamicTool)({
8232
8343
  description,
8233
- inputSchema: schemas === "automatic" ? (0, import_provider_utils21.jsonSchema)({
8344
+ inputSchema: (0, import_provider_utils21.jsonSchema)({
8234
8345
  ...inputSchema,
8235
8346
  properties: (_a16 = inputSchema.properties) != null ? _a16 : {},
8236
8347
  additionalProperties: false
8237
- }) : schemas[name16].inputSchema,
8238
- execute: async (args, options) => {
8239
- var _a17;
8240
- (_a17 = options == null ? void 0 : options.abortSignal) == null ? void 0 : _a17.throwIfAborted();
8241
- return self.callTool({
8242
- name: name16,
8243
- args,
8244
- options
8245
- });
8246
- }
8348
+ }),
8349
+ execute
8350
+ }) : (0, import_provider_utils21.tool)({
8351
+ description,
8352
+ inputSchema: schemas[name16].inputSchema,
8353
+ execute
8247
8354
  });
8248
8355
  tools[name16] = toolWithExecute;
8249
8356
  }
@@ -8289,9 +8396,6 @@ var MCPClient = class {
8289
8396
  }
8290
8397
  };
8291
8398
 
8292
- // src/tool/index.ts
8293
- var import_provider_utils23 = require("@ai-sdk/provider-utils");
8294
-
8295
8399
  // src/error/no-transcript-generated-error.ts
8296
8400
  var import_provider30 = require("@ai-sdk/provider");
8297
8401
  var NoTranscriptGeneratedError = class extends import_provider30.AISDKError {
@@ -8364,7 +8468,7 @@ var DefaultTranscriptionResult = class {
8364
8468
  };
8365
8469
 
8366
8470
  // src/ui/call-completion-api.ts
8367
- var import_provider_utils24 = require("@ai-sdk/provider-utils");
8471
+ var import_provider_utils22 = require("@ai-sdk/provider-utils");
8368
8472
 
8369
8473
  // src/ui/process-text-stream.ts
8370
8474
  async function processTextStream({
@@ -8442,7 +8546,7 @@ async function callCompletionApi({
8442
8546
  }
8443
8547
  case "data": {
8444
8548
  await consumeStream({
8445
- stream: (0, import_provider_utils24.parseJsonEventStream)({
8549
+ stream: (0, import_provider_utils22.parseJsonEventStream)({
8446
8550
  stream: response.body,
8447
8551
  schema: uiMessageChunkSchema
8448
8552
  }).pipeThrough(
@@ -8494,7 +8598,7 @@ async function callCompletionApi({
8494
8598
  }
8495
8599
 
8496
8600
  // src/ui/chat.ts
8497
- var import_provider_utils27 = require("@ai-sdk/provider-utils");
8601
+ var import_provider_utils25 = require("@ai-sdk/provider-utils");
8498
8602
 
8499
8603
  // src/ui/convert-file-list-to-file-ui-parts.ts
8500
8604
  async function convertFileListToFileUIParts(files) {
@@ -8527,10 +8631,10 @@ async function convertFileListToFileUIParts(files) {
8527
8631
  }
8528
8632
 
8529
8633
  // src/ui/default-chat-transport.ts
8530
- var import_provider_utils26 = require("@ai-sdk/provider-utils");
8634
+ var import_provider_utils24 = require("@ai-sdk/provider-utils");
8531
8635
 
8532
8636
  // src/ui/http-chat-transport.ts
8533
- var import_provider_utils25 = require("@ai-sdk/provider-utils");
8637
+ var import_provider_utils23 = require("@ai-sdk/provider-utils");
8534
8638
  var HttpChatTransport = class {
8535
8639
  constructor({
8536
8640
  api = "/api/chat",
@@ -8554,9 +8658,9 @@ var HttpChatTransport = class {
8554
8658
  ...options
8555
8659
  }) {
8556
8660
  var _a16, _b, _c, _d, _e;
8557
- const resolvedBody = await (0, import_provider_utils25.resolve)(this.body);
8558
- const resolvedHeaders = await (0, import_provider_utils25.resolve)(this.headers);
8559
- const resolvedCredentials = await (0, import_provider_utils25.resolve)(this.credentials);
8661
+ const resolvedBody = await (0, import_provider_utils23.resolve)(this.body);
8662
+ const resolvedHeaders = await (0, import_provider_utils23.resolve)(this.headers);
8663
+ const resolvedCredentials = await (0, import_provider_utils23.resolve)(this.credentials);
8560
8664
  const preparedRequest = await ((_a16 = this.prepareSendMessagesRequest) == null ? void 0 : _a16.call(this, {
8561
8665
  api: this.api,
8562
8666
  id: options.chatId,
@@ -8602,9 +8706,9 @@ var HttpChatTransport = class {
8602
8706
  }
8603
8707
  async reconnectToStream(options) {
8604
8708
  var _a16, _b, _c, _d, _e;
8605
- const resolvedBody = await (0, import_provider_utils25.resolve)(this.body);
8606
- const resolvedHeaders = await (0, import_provider_utils25.resolve)(this.headers);
8607
- const resolvedCredentials = await (0, import_provider_utils25.resolve)(this.credentials);
8709
+ const resolvedBody = await (0, import_provider_utils23.resolve)(this.body);
8710
+ const resolvedHeaders = await (0, import_provider_utils23.resolve)(this.headers);
8711
+ const resolvedCredentials = await (0, import_provider_utils23.resolve)(this.credentials);
8608
8712
  const preparedRequest = await ((_a16 = this.prepareReconnectToStreamRequest) == null ? void 0 : _a16.call(this, {
8609
8713
  api: this.api,
8610
8714
  id: options.chatId,
@@ -8643,7 +8747,7 @@ var DefaultChatTransport = class extends HttpChatTransport {
8643
8747
  super(options);
8644
8748
  }
8645
8749
  processResponseStream(stream) {
8646
- return (0, import_provider_utils26.parseJsonEventStream)({
8750
+ return (0, import_provider_utils24.parseJsonEventStream)({
8647
8751
  stream,
8648
8752
  schema: uiMessageChunkSchema
8649
8753
  }).pipeThrough(
@@ -8662,7 +8766,7 @@ var DefaultChatTransport = class extends HttpChatTransport {
8662
8766
  // src/ui/chat.ts
8663
8767
  var AbstractChat = class {
8664
8768
  constructor({
8665
- generateId: generateId3 = import_provider_utils27.generateId,
8769
+ generateId: generateId3 = import_provider_utils25.generateId,
8666
8770
  id = generateId3(),
8667
8771
  transport = new DefaultChatTransport(),
8668
8772
  messageMetadataSchema,
@@ -8790,8 +8894,8 @@ var AbstractChat = class {
8790
8894
  } : part
8791
8895
  );
8792
8896
  }
8793
- if (this.status !== "streaming" && this.status !== "submitted" && ((_a16 = this.sendAutomaticallyWhen) == null ? void 0 : _a16.call(this, { messages }))) {
8794
- await this.makeRequest({
8897
+ if (this.status !== "streaming" && this.status !== "submitted" && ((_a16 = this.sendAutomaticallyWhen) == null ? void 0 : _a16.call(this, { messages: this.state.messages }))) {
8898
+ this.makeRequest({
8795
8899
  trigger: "submit-message",
8796
8900
  messageId: (_b = this.lastMessage) == null ? void 0 : _b.id
8797
8901
  });
@@ -9031,6 +9135,22 @@ function convertToModelMessages(messages, options) {
9031
9135
  text: part.text,
9032
9136
  providerOptions: part.providerMetadata
9033
9137
  });
9138
+ } else if (part.type === "dynamic-tool") {
9139
+ const toolName = part.toolName;
9140
+ if (part.state === "input-streaming") {
9141
+ throw new MessageConversionError({
9142
+ originalMessage: message,
9143
+ message: `incomplete tool input is not supported: ${part.toolCallId}`
9144
+ });
9145
+ } else {
9146
+ content.push({
9147
+ type: "tool-call",
9148
+ toolCallId: part.toolCallId,
9149
+ toolName,
9150
+ input: part.input,
9151
+ ...part.callProviderMetadata != null ? { providerOptions: part.callProviderMetadata } : {}
9152
+ });
9153
+ }
9034
9154
  } else if (isToolUIPart(part)) {
9035
9155
  const toolName = getToolName(part);
9036
9156
  if (part.state === "input-streaming") {
@@ -9069,7 +9189,9 @@ function convertToModelMessages(messages, options) {
9069
9189
  role: "assistant",
9070
9190
  content
9071
9191
  });
9072
- const toolParts = block.filter(isToolUIPart).filter((part) => part.providerExecuted !== true);
9192
+ const toolParts = block.filter(
9193
+ (part) => isToolUIPart(part) && part.providerExecuted !== true || part.type === "dynamic-tool"
9194
+ );
9073
9195
  if (toolParts.length > 0) {
9074
9196
  modelMessages.push({
9075
9197
  role: "tool",
@@ -9078,7 +9200,7 @@ function convertToModelMessages(messages, options) {
9078
9200
  switch (toolPart.state) {
9079
9201
  case "output-error":
9080
9202
  case "output-available": {
9081
- const toolName = getToolName(toolPart);
9203
+ const toolName = toolPart.type === "dynamic-tool" ? toolPart.toolName : getToolName(toolPart);
9082
9204
  return {
9083
9205
  type: "tool-result",
9084
9206
  toolCallId: toolPart.toolCallId,
@@ -9105,7 +9227,7 @@ function convertToModelMessages(messages, options) {
9105
9227
  var processBlock = processBlock2;
9106
9228
  let block = [];
9107
9229
  for (const part of message.parts) {
9108
- if (part.type === "text" || part.type === "reasoning" || part.type === "file" || isToolUIPart(part)) {
9230
+ if (part.type === "text" || part.type === "reasoning" || part.type === "file" || part.type === "dynamic-tool" || isToolUIPart(part)) {
9109
9231
  block.push(part);
9110
9232
  } else if (part.type === "step-start") {
9111
9233
  processBlock2();
@@ -9183,13 +9305,13 @@ var TextStreamChatTransport = class extends HttpChatTransport {
9183
9305
  };
9184
9306
 
9185
9307
  // src/ui-message-stream/create-ui-message-stream.ts
9186
- var import_provider_utils28 = require("@ai-sdk/provider-utils");
9308
+ var import_provider_utils26 = require("@ai-sdk/provider-utils");
9187
9309
  function createUIMessageStream({
9188
9310
  execute,
9189
- onError = import_provider_utils28.getErrorMessage,
9311
+ onError = import_provider_utils26.getErrorMessage,
9190
9312
  originalMessages,
9191
9313
  onFinish,
9192
- generateId: generateId3 = import_provider_utils28.generateId
9314
+ generateId: generateId3 = import_provider_utils26.generateId
9193
9315
  }) {
9194
9316
  let controller;
9195
9317
  const ongoingStreamPromises = [];
@@ -9373,6 +9495,7 @@ function readUIMessageStream({
9373
9495
  createUIMessageStreamResponse,
9374
9496
  customProvider,
9375
9497
  defaultSettingsMiddleware,
9498
+ dynamicTool,
9376
9499
  embed,
9377
9500
  embedMany,
9378
9501
  experimental_createMCPClient,