ai 6.0.0-beta.49 → 6.0.0-beta.50

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,16 @@
1
1
  # ai
2
2
 
3
+ ## 6.0.0-beta.50
4
+
5
+ ### Patch Changes
6
+
7
+ - 4812235: fix(ai): add missing export for `LoadSettingError`
8
+ - 81d4308: feat: provider-executed dynamic tools
9
+ - Updated dependencies [81d4308]
10
+ - @ai-sdk/provider@3.0.0-beta.7
11
+ - @ai-sdk/gateway@2.0.0-beta.32
12
+ - @ai-sdk/provider-utils@4.0.0-beta.18
13
+
3
14
  ## 6.0.0-beta.49
4
15
 
5
16
  ### Patch Changes
package/dist/index.d.mts CHANGED
@@ -4,7 +4,7 @@ import { Tool, InferToolInput, InferToolOutput, AssistantModelMessage, ToolModel
4
4
  export { AssistantContent, AssistantModelMessage, DataContent, FilePart, FlexibleSchema, IdGenerator, ImagePart, InferSchema, InferToolInput, InferToolOutput, ModelMessage, Schema, SystemModelMessage, TextPart, Tool, ToolApprovalRequest, ToolApprovalResponse, ToolCallOptions, ToolCallPart, ToolContent, ToolExecuteFunction, ToolModelMessage, ToolResultPart, UserContent, UserModelMessage, asSchema, createIdGenerator, dynamicTool, generateId, jsonSchema, parseJsonEventStream, tool, zodSchema } from '@ai-sdk/provider-utils';
5
5
  import * as _ai_sdk_provider from '@ai-sdk/provider';
6
6
  import { EmbeddingModelV3, EmbeddingModelV2, EmbeddingModelV3Embedding, ImageModelV3, ImageModelV3CallWarning, ImageModelV3ProviderMetadata, JSONValue as JSONValue$1, LanguageModelV3, LanguageModelV2, LanguageModelV3FinishReason, LanguageModelV3CallWarning, LanguageModelV3Source, LanguageModelV3Middleware, SharedV3ProviderMetadata, SpeechModelV3, SpeechModelV2, SpeechModelV3CallWarning, TranscriptionModelV3, TranscriptionModelV2, TranscriptionModelV3CallWarning, LanguageModelV3Usage, LanguageModelV3CallOptions, AISDKError, LanguageModelV3ToolCall, JSONSchema7, JSONParseError, TypeValidationError, ProviderV3, ProviderV2, NoSuchModelError, JSONObject } from '@ai-sdk/provider';
7
- export { AISDKError, APICallError, EmptyResponseBodyError, InvalidPromptError, InvalidResponseDataError, JSONParseError, JSONSchema7, LoadAPIKeyError, NoContentGeneratedError, NoSuchModelError, TooManyEmbeddingValuesForCallError, TypeValidationError, UnsupportedFunctionalityError } from '@ai-sdk/provider';
7
+ export { AISDKError, APICallError, EmptyResponseBodyError, InvalidPromptError, InvalidResponseDataError, JSONParseError, JSONSchema7, LoadAPIKeyError, LoadSettingError, NoContentGeneratedError, NoSuchModelError, TooManyEmbeddingValuesForCallError, TypeValidationError, UnsupportedFunctionalityError } from '@ai-sdk/provider';
8
8
  import { ServerResponse } from 'node:http';
9
9
  import { AttributeValue, Tracer } from '@opentelemetry/api';
10
10
  import { ServerResponse as ServerResponse$1 } from 'http';
@@ -1580,18 +1580,23 @@ type asUITool<TOOL extends UITool | Tool> = TOOL extends Tool ? InferUITool<TOOL
1580
1580
  * UI components for the tool.
1581
1581
  */
1582
1582
  type UIToolInvocation<TOOL extends UITool | Tool> = {
1583
+ /**
1584
+ * ID of the tool call.
1585
+ */
1583
1586
  toolCallId: string;
1587
+ /**
1588
+ * Whether the tool call was executed by the provider.
1589
+ */
1590
+ providerExecuted?: boolean;
1584
1591
  } & ({
1585
1592
  state: 'input-streaming';
1586
1593
  input: DeepPartial<asUITool<TOOL>['input']> | undefined;
1587
- providerExecuted?: boolean;
1588
1594
  output?: never;
1589
1595
  errorText?: never;
1590
1596
  approval?: never;
1591
1597
  } | {
1592
1598
  state: 'input-available';
1593
1599
  input: asUITool<TOOL>['input'];
1594
- providerExecuted?: boolean;
1595
1600
  output?: never;
1596
1601
  errorText?: never;
1597
1602
  callProviderMetadata?: ProviderMetadata;
@@ -1599,7 +1604,6 @@ type UIToolInvocation<TOOL extends UITool | Tool> = {
1599
1604
  } | {
1600
1605
  state: 'approval-requested';
1601
1606
  input: asUITool<TOOL>['input'];
1602
- providerExecuted?: boolean;
1603
1607
  output?: never;
1604
1608
  errorText?: never;
1605
1609
  callProviderMetadata?: ProviderMetadata;
@@ -1611,7 +1615,6 @@ type UIToolInvocation<TOOL extends UITool | Tool> = {
1611
1615
  } | {
1612
1616
  state: 'approval-responded';
1613
1617
  input: asUITool<TOOL>['input'];
1614
- providerExecuted?: boolean;
1615
1618
  output?: never;
1616
1619
  errorText?: never;
1617
1620
  callProviderMetadata?: ProviderMetadata;
@@ -1625,7 +1628,6 @@ type UIToolInvocation<TOOL extends UITool | Tool> = {
1625
1628
  input: asUITool<TOOL>['input'];
1626
1629
  output: asUITool<TOOL>['output'];
1627
1630
  errorText?: never;
1628
- providerExecuted?: boolean;
1629
1631
  callProviderMetadata?: ProviderMetadata;
1630
1632
  preliminary?: boolean;
1631
1633
  approval?: {
@@ -1639,7 +1641,6 @@ type UIToolInvocation<TOOL extends UITool | Tool> = {
1639
1641
  rawInput?: unknown;
1640
1642
  output?: never;
1641
1643
  errorText: string;
1642
- providerExecuted?: boolean;
1643
1644
  callProviderMetadata?: ProviderMetadata;
1644
1645
  approval?: {
1645
1646
  id: string;
@@ -1649,7 +1650,6 @@ type UIToolInvocation<TOOL extends UITool | Tool> = {
1649
1650
  } | {
1650
1651
  state: 'output-denied';
1651
1652
  input: asUITool<TOOL>['input'];
1652
- providerExecuted?: boolean;
1653
1653
  output?: never;
1654
1654
  errorText?: never;
1655
1655
  callProviderMetadata?: ProviderMetadata;
@@ -1666,8 +1666,18 @@ type ToolUIPart<TOOLS extends UITools = UITools> = ValueOf<{
1666
1666
  }>;
1667
1667
  type DynamicToolUIPart = {
1668
1668
  type: 'dynamic-tool';
1669
+ /**
1670
+ * Name of the tool that is being called.
1671
+ */
1669
1672
  toolName: string;
1673
+ /**
1674
+ * ID of the tool call.
1675
+ */
1670
1676
  toolCallId: string;
1677
+ /**
1678
+ * Whether the tool call was executed by the provider.
1679
+ */
1680
+ providerExecuted?: boolean;
1671
1681
  } & ({
1672
1682
  state: 'input-streaming';
1673
1683
  input: unknown | undefined;
@@ -2760,6 +2770,7 @@ type SingleRequestTextStreamPart<TOOLS extends ToolSet> = {
2760
2770
  id: string;
2761
2771
  toolName: string;
2762
2772
  providerMetadata?: ProviderMetadata;
2773
+ dynamic?: boolean;
2763
2774
  } | {
2764
2775
  type: 'tool-input-delta';
2765
2776
  id: string;
@@ -4601,12 +4612,14 @@ declare abstract class AbstractChat<UI_MESSAGE extends UIMessage> {
4601
4612
  declare function convertFileListToFileUIParts(files: FileList | undefined): Promise<Array<FileUIPart>>;
4602
4613
 
4603
4614
  /**
4604
- Converts an array of messages from useChat into an array of CoreMessages that can be used
4605
- with the AI core functions (e.g. `streamText`).
4615
+ Converts an array of UI messages from useChat into an array of ModelMessages that can be used
4616
+ with the AI functions (e.g. `streamText`, `generateText`).
4606
4617
 
4607
- @param messages - The messages to convert.
4618
+ @param messages - The UI messages to convert.
4608
4619
  @param options.tools - The tools to use.
4609
4620
  @param options.ignoreIncompleteToolCalls - Whether to ignore incomplete tool calls. Default is `false`.
4621
+
4622
+ @returns An array of ModelMessages.
4610
4623
  */
4611
4624
  declare function convertToModelMessages(messages: Array<Omit<UIMessage, 'id'>>, options?: {
4612
4625
  tools?: ToolSet;
package/dist/index.d.ts CHANGED
@@ -4,7 +4,7 @@ import { Tool, InferToolInput, InferToolOutput, AssistantModelMessage, ToolModel
4
4
  export { AssistantContent, AssistantModelMessage, DataContent, FilePart, FlexibleSchema, IdGenerator, ImagePart, InferSchema, InferToolInput, InferToolOutput, ModelMessage, Schema, SystemModelMessage, TextPart, Tool, ToolApprovalRequest, ToolApprovalResponse, ToolCallOptions, ToolCallPart, ToolContent, ToolExecuteFunction, ToolModelMessage, ToolResultPart, UserContent, UserModelMessage, asSchema, createIdGenerator, dynamicTool, generateId, jsonSchema, parseJsonEventStream, tool, zodSchema } from '@ai-sdk/provider-utils';
5
5
  import * as _ai_sdk_provider from '@ai-sdk/provider';
6
6
  import { EmbeddingModelV3, EmbeddingModelV2, EmbeddingModelV3Embedding, ImageModelV3, ImageModelV3CallWarning, ImageModelV3ProviderMetadata, JSONValue as JSONValue$1, LanguageModelV3, LanguageModelV2, LanguageModelV3FinishReason, LanguageModelV3CallWarning, LanguageModelV3Source, LanguageModelV3Middleware, SharedV3ProviderMetadata, SpeechModelV3, SpeechModelV2, SpeechModelV3CallWarning, TranscriptionModelV3, TranscriptionModelV2, TranscriptionModelV3CallWarning, LanguageModelV3Usage, LanguageModelV3CallOptions, AISDKError, LanguageModelV3ToolCall, JSONSchema7, JSONParseError, TypeValidationError, ProviderV3, ProviderV2, NoSuchModelError, JSONObject } from '@ai-sdk/provider';
7
- export { AISDKError, APICallError, EmptyResponseBodyError, InvalidPromptError, InvalidResponseDataError, JSONParseError, JSONSchema7, LoadAPIKeyError, NoContentGeneratedError, NoSuchModelError, TooManyEmbeddingValuesForCallError, TypeValidationError, UnsupportedFunctionalityError } from '@ai-sdk/provider';
7
+ export { AISDKError, APICallError, EmptyResponseBodyError, InvalidPromptError, InvalidResponseDataError, JSONParseError, JSONSchema7, LoadAPIKeyError, LoadSettingError, NoContentGeneratedError, NoSuchModelError, TooManyEmbeddingValuesForCallError, TypeValidationError, UnsupportedFunctionalityError } from '@ai-sdk/provider';
8
8
  import { ServerResponse } from 'node:http';
9
9
  import { AttributeValue, Tracer } from '@opentelemetry/api';
10
10
  import { ServerResponse as ServerResponse$1 } from 'http';
@@ -1580,18 +1580,23 @@ type asUITool<TOOL extends UITool | Tool> = TOOL extends Tool ? InferUITool<TOOL
1580
1580
  * UI components for the tool.
1581
1581
  */
1582
1582
  type UIToolInvocation<TOOL extends UITool | Tool> = {
1583
+ /**
1584
+ * ID of the tool call.
1585
+ */
1583
1586
  toolCallId: string;
1587
+ /**
1588
+ * Whether the tool call was executed by the provider.
1589
+ */
1590
+ providerExecuted?: boolean;
1584
1591
  } & ({
1585
1592
  state: 'input-streaming';
1586
1593
  input: DeepPartial<asUITool<TOOL>['input']> | undefined;
1587
- providerExecuted?: boolean;
1588
1594
  output?: never;
1589
1595
  errorText?: never;
1590
1596
  approval?: never;
1591
1597
  } | {
1592
1598
  state: 'input-available';
1593
1599
  input: asUITool<TOOL>['input'];
1594
- providerExecuted?: boolean;
1595
1600
  output?: never;
1596
1601
  errorText?: never;
1597
1602
  callProviderMetadata?: ProviderMetadata;
@@ -1599,7 +1604,6 @@ type UIToolInvocation<TOOL extends UITool | Tool> = {
1599
1604
  } | {
1600
1605
  state: 'approval-requested';
1601
1606
  input: asUITool<TOOL>['input'];
1602
- providerExecuted?: boolean;
1603
1607
  output?: never;
1604
1608
  errorText?: never;
1605
1609
  callProviderMetadata?: ProviderMetadata;
@@ -1611,7 +1615,6 @@ type UIToolInvocation<TOOL extends UITool | Tool> = {
1611
1615
  } | {
1612
1616
  state: 'approval-responded';
1613
1617
  input: asUITool<TOOL>['input'];
1614
- providerExecuted?: boolean;
1615
1618
  output?: never;
1616
1619
  errorText?: never;
1617
1620
  callProviderMetadata?: ProviderMetadata;
@@ -1625,7 +1628,6 @@ type UIToolInvocation<TOOL extends UITool | Tool> = {
1625
1628
  input: asUITool<TOOL>['input'];
1626
1629
  output: asUITool<TOOL>['output'];
1627
1630
  errorText?: never;
1628
- providerExecuted?: boolean;
1629
1631
  callProviderMetadata?: ProviderMetadata;
1630
1632
  preliminary?: boolean;
1631
1633
  approval?: {
@@ -1639,7 +1641,6 @@ type UIToolInvocation<TOOL extends UITool | Tool> = {
1639
1641
  rawInput?: unknown;
1640
1642
  output?: never;
1641
1643
  errorText: string;
1642
- providerExecuted?: boolean;
1643
1644
  callProviderMetadata?: ProviderMetadata;
1644
1645
  approval?: {
1645
1646
  id: string;
@@ -1649,7 +1650,6 @@ type UIToolInvocation<TOOL extends UITool | Tool> = {
1649
1650
  } | {
1650
1651
  state: 'output-denied';
1651
1652
  input: asUITool<TOOL>['input'];
1652
- providerExecuted?: boolean;
1653
1653
  output?: never;
1654
1654
  errorText?: never;
1655
1655
  callProviderMetadata?: ProviderMetadata;
@@ -1666,8 +1666,18 @@ type ToolUIPart<TOOLS extends UITools = UITools> = ValueOf<{
1666
1666
  }>;
1667
1667
  type DynamicToolUIPart = {
1668
1668
  type: 'dynamic-tool';
1669
+ /**
1670
+ * Name of the tool that is being called.
1671
+ */
1669
1672
  toolName: string;
1673
+ /**
1674
+ * ID of the tool call.
1675
+ */
1670
1676
  toolCallId: string;
1677
+ /**
1678
+ * Whether the tool call was executed by the provider.
1679
+ */
1680
+ providerExecuted?: boolean;
1671
1681
  } & ({
1672
1682
  state: 'input-streaming';
1673
1683
  input: unknown | undefined;
@@ -2760,6 +2770,7 @@ type SingleRequestTextStreamPart<TOOLS extends ToolSet> = {
2760
2770
  id: string;
2761
2771
  toolName: string;
2762
2772
  providerMetadata?: ProviderMetadata;
2773
+ dynamic?: boolean;
2763
2774
  } | {
2764
2775
  type: 'tool-input-delta';
2765
2776
  id: string;
@@ -4601,12 +4612,14 @@ declare abstract class AbstractChat<UI_MESSAGE extends UIMessage> {
4601
4612
  declare function convertFileListToFileUIParts(files: FileList | undefined): Promise<Array<FileUIPart>>;
4602
4613
 
4603
4614
  /**
4604
- Converts an array of messages from useChat into an array of CoreMessages that can be used
4605
- with the AI core functions (e.g. `streamText`).
4615
+ Converts an array of UI messages from useChat into an array of ModelMessages that can be used
4616
+ with the AI functions (e.g. `streamText`, `generateText`).
4606
4617
 
4607
- @param messages - The messages to convert.
4618
+ @param messages - The UI messages to convert.
4608
4619
  @param options.tools - The tools to use.
4609
4620
  @param options.ignoreIncompleteToolCalls - Whether to ignore incomplete tool calls. Default is `false`.
4621
+
4622
+ @returns An array of ModelMessages.
4610
4623
  */
4611
4624
  declare function convertToModelMessages(messages: Array<Omit<UIMessage, 'id'>>, options?: {
4612
4625
  tools?: ToolSet;
package/dist/index.js CHANGED
@@ -39,6 +39,7 @@ __export(src_exports, {
39
39
  JSONParseError: () => import_provider18.JSONParseError,
40
40
  JsonToSseTransformStream: () => JsonToSseTransformStream,
41
41
  LoadAPIKeyError: () => import_provider18.LoadAPIKeyError,
42
+ LoadSettingError: () => import_provider18.LoadSettingError,
42
43
  MCPClientError: () => MCPClientError,
43
44
  MessageConversionError: () => MessageConversionError,
44
45
  NoContentGeneratedError: () => import_provider18.NoContentGeneratedError,
@@ -868,7 +869,7 @@ function detectMediaType({
868
869
  var import_provider_utils2 = require("@ai-sdk/provider-utils");
869
870
 
870
871
  // src/version.ts
871
- var VERSION = true ? "6.0.0-beta.49" : "0.0.0-test";
872
+ var VERSION = true ? "6.0.0-beta.50" : "0.0.0-test";
872
873
 
873
874
  // src/util/download/download.ts
874
875
  var download = async ({ url }) => {
@@ -2265,6 +2266,9 @@ async function parseToolCall({
2265
2266
  }) {
2266
2267
  try {
2267
2268
  if (tools == null) {
2269
+ if (toolCall.providerExecuted && toolCall.dynamic) {
2270
+ return await parseProviderExecutedDynamicToolCall(toolCall);
2271
+ }
2268
2272
  throw new NoSuchToolError({ toolName: toolCall.toolName });
2269
2273
  }
2270
2274
  try {
@@ -2311,6 +2315,25 @@ async function parseToolCall({
2311
2315
  };
2312
2316
  }
2313
2317
  }
2318
+ async function parseProviderExecutedDynamicToolCall(toolCall) {
2319
+ const parseResult = toolCall.input.trim() === "" ? { success: true, value: {} } : await (0, import_provider_utils10.safeParseJSON)({ text: toolCall.input });
2320
+ if (parseResult.success === false) {
2321
+ throw new InvalidToolInputError({
2322
+ toolName: toolCall.toolName,
2323
+ toolInput: toolCall.input,
2324
+ cause: parseResult.error
2325
+ });
2326
+ }
2327
+ return {
2328
+ type: "tool-call",
2329
+ toolCallId: toolCall.toolCallId,
2330
+ toolName: toolCall.toolName,
2331
+ input: parseResult.value,
2332
+ providerExecuted: true,
2333
+ dynamic: true,
2334
+ providerMetadata: toolCall.providerMetadata
2335
+ };
2336
+ }
2314
2337
  async function doParseToolCall({
2315
2338
  toolCall,
2316
2339
  tools
@@ -2318,6 +2341,9 @@ async function doParseToolCall({
2318
2341
  const toolName = toolCall.toolName;
2319
2342
  const tool3 = tools[toolName];
2320
2343
  if (tool3 == null) {
2344
+ if (toolCall.providerExecuted && toolCall.dynamic) {
2345
+ return await parseProviderExecutedDynamicToolCall(toolCall);
2346
+ }
2321
2347
  throw new NoSuchToolError({
2322
2348
  toolName: toolCall.toolName,
2323
2349
  availableTools: Object.keys(tools)
@@ -2792,7 +2818,10 @@ async function generateText({
2792
2818
  if (toolCall.invalid) {
2793
2819
  continue;
2794
2820
  }
2795
- const tool3 = tools[toolCall.toolName];
2821
+ const tool3 = tools == null ? void 0 : tools[toolCall.toolName];
2822
+ if (tool3 == null) {
2823
+ continue;
2824
+ }
2796
2825
  if ((tool3 == null ? void 0 : tool3.onInputAvailable) != null) {
2797
2826
  await tool3.onInputAvailable({
2798
2827
  input: toolCall.input,
@@ -3897,7 +3926,7 @@ function processUIMessageStream({
3897
3926
  }
3898
3927
  }
3899
3928
  function updateDynamicToolPart(options) {
3900
- var _a18;
3929
+ var _a18, _b2;
3901
3930
  const part = state.message.parts.find(
3902
3931
  (part2) => part2.type === "dynamic-tool" && part2.toolCallId === options.toolCallId
3903
3932
  );
@@ -3911,6 +3940,7 @@ function processUIMessageStream({
3911
3940
  anyPart.errorText = anyOptions.errorText;
3912
3941
  anyPart.rawInput = (_a18 = anyOptions.rawInput) != null ? _a18 : anyPart.rawInput;
3913
3942
  anyPart.preliminary = anyOptions.preliminary;
3943
+ anyPart.providerExecuted = (_b2 = anyOptions.providerExecuted) != null ? _b2 : part.providerExecuted;
3914
3944
  if (anyOptions.providerMetadata != null && part.state === "input-available") {
3915
3945
  part.callProviderMetadata = anyOptions.providerMetadata;
3916
3946
  }
@@ -3924,6 +3954,7 @@ function processUIMessageStream({
3924
3954
  output: anyOptions.output,
3925
3955
  errorText: anyOptions.errorText,
3926
3956
  preliminary: anyOptions.preliminary,
3957
+ providerExecuted: anyOptions.providerExecuted,
3927
3958
  ...anyOptions.providerMetadata != null ? { callProviderMetadata: anyOptions.providerMetadata } : {}
3928
3959
  });
3929
3960
  }
@@ -4040,7 +4071,8 @@ function processUIMessageStream({
4040
4071
  toolCallId: chunk.toolCallId,
4041
4072
  toolName: chunk.toolName,
4042
4073
  state: "input-streaming",
4043
- input: void 0
4074
+ input: void 0,
4075
+ providerExecuted: chunk.providerExecuted
4044
4076
  });
4045
4077
  } else {
4046
4078
  updateToolPart({
@@ -4085,6 +4117,7 @@ function processUIMessageStream({
4085
4117
  toolName: chunk.toolName,
4086
4118
  state: "input-available",
4087
4119
  input: chunk.input,
4120
+ providerExecuted: chunk.providerExecuted,
4088
4121
  providerMetadata: chunk.providerMetadata
4089
4122
  });
4090
4123
  } else {
@@ -4113,6 +4146,7 @@ function processUIMessageStream({
4113
4146
  state: "output-error",
4114
4147
  input: chunk.input,
4115
4148
  errorText: chunk.errorText,
4149
+ providerExecuted: chunk.providerExecuted,
4116
4150
  providerMetadata: chunk.providerMetadata
4117
4151
  });
4118
4152
  } else {
@@ -4152,7 +4186,8 @@ function processUIMessageStream({
4152
4186
  state: "output-available",
4153
4187
  input: toolInvocation.input,
4154
4188
  output: chunk.output,
4155
- preliminary: chunk.preliminary
4189
+ preliminary: chunk.preliminary,
4190
+ providerExecuted: chunk.providerExecuted
4156
4191
  });
4157
4192
  } else {
4158
4193
  updateToolPart({
@@ -4176,7 +4211,8 @@ function processUIMessageStream({
4176
4211
  toolName: toolInvocation.toolName,
4177
4212
  state: "output-error",
4178
4213
  input: toolInvocation.input,
4179
- errorText: chunk.errorText
4214
+ errorText: chunk.errorText,
4215
+ providerExecuted: chunk.providerExecuted
4180
4216
  });
4181
4217
  } else {
4182
4218
  updateToolPart({
@@ -4185,7 +4221,8 @@ function processUIMessageStream({
4185
4221
  state: "output-error",
4186
4222
  input: toolInvocation.input,
4187
4223
  rawInput: toolInvocation.rawInput,
4188
- errorText: chunk.errorText
4224
+ errorText: chunk.errorText,
4225
+ providerExecuted: chunk.providerExecuted
4189
4226
  });
4190
4227
  }
4191
4228
  write();
@@ -4679,7 +4716,10 @@ function runToolsTransformation({
4679
4716
  });
4680
4717
  break;
4681
4718
  }
4682
- const tool3 = tools[toolCall.toolName];
4719
+ const tool3 = tools == null ? void 0 : tools[toolCall.toolName];
4720
+ if (tool3 == null) {
4721
+ break;
4722
+ }
4683
4723
  if (tool3.onInputAvailable != null) {
4684
4724
  await tool3.onInputAvailable({
4685
4725
  input: toolCall.input,
@@ -4737,7 +4777,8 @@ function runToolsTransformation({
4737
4777
  toolName,
4738
4778
  input: toolInputs.get(chunk.toolCallId),
4739
4779
  providerExecuted: chunk.providerExecuted,
4740
- error: chunk.result
4780
+ error: chunk.result,
4781
+ dynamic: chunk.dynamic
4741
4782
  });
4742
4783
  } else {
4743
4784
  controller.enqueue({
@@ -4746,7 +4787,8 @@ function runToolsTransformation({
4746
4787
  toolName,
4747
4788
  input: toolInputs.get(chunk.toolCallId),
4748
4789
  output: chunk.result,
4749
- providerExecuted: chunk.providerExecuted
4790
+ providerExecuted: chunk.providerExecuted,
4791
+ dynamic: chunk.dynamic
4750
4792
  });
4751
4793
  }
4752
4794
  break;
@@ -5470,7 +5512,7 @@ var DefaultStreamTextResult = class {
5470
5512
  streamWithToolResults.pipeThrough(
5471
5513
  new TransformStream({
5472
5514
  async transform(chunk, controller) {
5473
- var _a18, _b2, _c2, _d2;
5515
+ var _a18, _b2, _c2, _d2, _e2;
5474
5516
  if (chunk.type === "stream-start") {
5475
5517
  warnings = chunk.warnings;
5476
5518
  return;
@@ -5582,7 +5624,7 @@ var DefaultStreamTextResult = class {
5582
5624
  }
5583
5625
  controller.enqueue({
5584
5626
  ...chunk,
5585
- dynamic: (tool3 == null ? void 0 : tool3.type) === "dynamic"
5627
+ dynamic: (_e2 = chunk.dynamic) != null ? _e2 : (tool3 == null ? void 0 : tool3.type) === "dynamic"
5586
5628
  });
5587
5629
  break;
5588
5630
  }
@@ -5886,12 +5928,13 @@ var DefaultStreamTextResult = class {
5886
5928
  originalMessages,
5887
5929
  responseMessageId: generateMessageId
5888
5930
  }) : void 0;
5889
- const toolNamesByCallId = {};
5890
- const isDynamic = (toolCallId) => {
5891
- var _a17, _b;
5892
- const toolName = toolNamesByCallId[toolCallId];
5893
- const dynamic = ((_b = (_a17 = this.tools) == null ? void 0 : _a17[toolName]) == null ? void 0 : _b.type) === "dynamic";
5894
- return dynamic ? true : void 0;
5931
+ const isDynamic = (part) => {
5932
+ var _a17;
5933
+ const tool3 = (_a17 = this.tools) == null ? void 0 : _a17[part.toolName];
5934
+ if (tool3 == null) {
5935
+ return part.dynamic;
5936
+ }
5937
+ return (tool3 == null ? void 0 : tool3.type) === "dynamic" ? true : void 0;
5895
5938
  };
5896
5939
  const baseStream = this.fullStream.pipeThrough(
5897
5940
  new TransformStream({
@@ -5982,8 +6025,7 @@ var DefaultStreamTextResult = class {
5982
6025
  break;
5983
6026
  }
5984
6027
  case "tool-input-start": {
5985
- toolNamesByCallId[part.id] = part.toolName;
5986
- const dynamic = isDynamic(part.id);
6028
+ const dynamic = isDynamic(part);
5987
6029
  controller.enqueue({
5988
6030
  type: "tool-input-start",
5989
6031
  toolCallId: part.id,
@@ -6002,8 +6044,7 @@ var DefaultStreamTextResult = class {
6002
6044
  break;
6003
6045
  }
6004
6046
  case "tool-call": {
6005
- toolNamesByCallId[part.toolCallId] = part.toolName;
6006
- const dynamic = isDynamic(part.toolCallId);
6047
+ const dynamic = isDynamic(part);
6007
6048
  if (part.invalid) {
6008
6049
  controller.enqueue({
6009
6050
  type: "tool-input-error",
@@ -6037,7 +6078,7 @@ var DefaultStreamTextResult = class {
6037
6078
  break;
6038
6079
  }
6039
6080
  case "tool-result": {
6040
- const dynamic = isDynamic(part.toolCallId);
6081
+ const dynamic = isDynamic(part);
6041
6082
  controller.enqueue({
6042
6083
  type: "tool-output-available",
6043
6084
  toolCallId: part.toolCallId,
@@ -6049,7 +6090,7 @@ var DefaultStreamTextResult = class {
6049
6090
  break;
6050
6091
  }
6051
6092
  case "tool-error": {
6052
- const dynamic = isDynamic(part.toolCallId);
6093
+ const dynamic = isDynamic(part);
6053
6094
  controller.enqueue({
6054
6095
  type: "tool-output-error",
6055
6096
  toolCallId: part.toolCallId,
@@ -6288,32 +6329,14 @@ function convertToModelMessages(messages, options) {
6288
6329
  text: part.text,
6289
6330
  providerOptions: part.providerMetadata
6290
6331
  });
6291
- } else if (part.type === "dynamic-tool") {
6292
- const toolName = part.toolName;
6332
+ } else if (isToolOrDynamicToolUIPart(part)) {
6333
+ const toolName = getToolOrDynamicToolName(part);
6293
6334
  if (part.state !== "input-streaming") {
6294
6335
  content.push({
6295
6336
  type: "tool-call",
6296
6337
  toolCallId: part.toolCallId,
6297
6338
  toolName,
6298
- input: part.input,
6299
- ...part.callProviderMetadata != null ? { providerOptions: part.callProviderMetadata } : {}
6300
- });
6301
- }
6302
- if (part.approval != null) {
6303
- content.push({
6304
- type: "tool-approval-request",
6305
- approvalId: part.approval.id,
6306
- toolCallId: part.toolCallId
6307
- });
6308
- }
6309
- } else if (isToolUIPart(part)) {
6310
- const toolName = getToolName(part);
6311
- if (part.state !== "input-streaming") {
6312
- content.push({
6313
- type: "tool-call",
6314
- toolCallId: part.toolCallId,
6315
- toolName,
6316
- input: part.state === "output-error" ? (_a17 = part.input) != null ? _a17 : part.rawInput : part.input,
6339
+ input: part.state === "output-error" ? (_a17 = part.input) != null ? _a17 : "rawInput" in part ? part.rawInput : void 0 : part.input,
6317
6340
  providerExecuted: part.providerExecuted,
6318
6341
  ...part.callProviderMetadata != null ? { providerOptions: part.callProviderMetadata } : {}
6319
6342
  });
@@ -6347,7 +6370,7 @@ function convertToModelMessages(messages, options) {
6347
6370
  content
6348
6371
  });
6349
6372
  const toolParts = block.filter(
6350
- (part) => isToolUIPart(part) && part.providerExecuted !== true || part.type === "dynamic-tool"
6373
+ (part) => isToolOrDynamicToolUIPart(part) && part.providerExecuted !== true
6351
6374
  );
6352
6375
  if (toolParts.length > 0) {
6353
6376
  modelMessages.push({
@@ -10642,6 +10665,7 @@ var uiMessagesSchema = (0, import_provider_utils35.lazySchema)(
10642
10665
  toolCallId: import_v410.z.string(),
10643
10666
  state: import_v410.z.literal("input-streaming"),
10644
10667
  input: import_v410.z.unknown().optional(),
10668
+ providerExecuted: import_v410.z.boolean().optional(),
10645
10669
  output: import_v410.z.never().optional(),
10646
10670
  errorText: import_v410.z.never().optional(),
10647
10671
  approval: import_v410.z.never().optional()
@@ -10652,6 +10676,7 @@ var uiMessagesSchema = (0, import_provider_utils35.lazySchema)(
10652
10676
  toolCallId: import_v410.z.string(),
10653
10677
  state: import_v410.z.literal("input-available"),
10654
10678
  input: import_v410.z.unknown(),
10679
+ providerExecuted: import_v410.z.boolean().optional(),
10655
10680
  output: import_v410.z.never().optional(),
10656
10681
  errorText: import_v410.z.never().optional(),
10657
10682
  callProviderMetadata: providerMetadataSchema.optional(),
@@ -10663,6 +10688,7 @@ var uiMessagesSchema = (0, import_provider_utils35.lazySchema)(
10663
10688
  toolCallId: import_v410.z.string(),
10664
10689
  state: import_v410.z.literal("approval-requested"),
10665
10690
  input: import_v410.z.unknown(),
10691
+ providerExecuted: import_v410.z.boolean().optional(),
10666
10692
  output: import_v410.z.never().optional(),
10667
10693
  errorText: import_v410.z.never().optional(),
10668
10694
  callProviderMetadata: providerMetadataSchema.optional(),
@@ -10678,6 +10704,7 @@ var uiMessagesSchema = (0, import_provider_utils35.lazySchema)(
10678
10704
  toolCallId: import_v410.z.string(),
10679
10705
  state: import_v410.z.literal("approval-responded"),
10680
10706
  input: import_v410.z.unknown(),
10707
+ providerExecuted: import_v410.z.boolean().optional(),
10681
10708
  output: import_v410.z.never().optional(),
10682
10709
  errorText: import_v410.z.never().optional(),
10683
10710
  callProviderMetadata: providerMetadataSchema.optional(),
@@ -10693,6 +10720,7 @@ var uiMessagesSchema = (0, import_provider_utils35.lazySchema)(
10693
10720
  toolCallId: import_v410.z.string(),
10694
10721
  state: import_v410.z.literal("output-available"),
10695
10722
  input: import_v410.z.unknown(),
10723
+ providerExecuted: import_v410.z.boolean().optional(),
10696
10724
  output: import_v410.z.unknown(),
10697
10725
  errorText: import_v410.z.never().optional(),
10698
10726
  callProviderMetadata: providerMetadataSchema.optional(),
@@ -10709,6 +10737,7 @@ var uiMessagesSchema = (0, import_provider_utils35.lazySchema)(
10709
10737
  toolCallId: import_v410.z.string(),
10710
10738
  state: import_v410.z.literal("output-error"),
10711
10739
  input: import_v410.z.unknown(),
10740
+ providerExecuted: import_v410.z.boolean().optional(),
10712
10741
  output: import_v410.z.never().optional(),
10713
10742
  errorText: import_v410.z.string(),
10714
10743
  callProviderMetadata: providerMetadataSchema.optional(),
@@ -10724,6 +10753,7 @@ var uiMessagesSchema = (0, import_provider_utils35.lazySchema)(
10724
10753
  toolCallId: import_v410.z.string(),
10725
10754
  state: import_v410.z.literal("output-denied"),
10726
10755
  input: import_v410.z.unknown(),
10756
+ providerExecuted: import_v410.z.boolean().optional(),
10727
10757
  output: import_v410.z.never().optional(),
10728
10758
  errorText: import_v410.z.never().optional(),
10729
10759
  callProviderMetadata: providerMetadataSchema.optional(),
@@ -11104,6 +11134,7 @@ function readUIMessageStream({
11104
11134
  JSONParseError,
11105
11135
  JsonToSseTransformStream,
11106
11136
  LoadAPIKeyError,
11137
+ LoadSettingError,
11107
11138
  MCPClientError,
11108
11139
  MessageConversionError,
11109
11140
  NoContentGeneratedError,