@ai-sdk/provider-utils 3.0.6 → 3.0.8

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,17 @@
1
1
  # @ai-sdk/provider-utils
2
2
 
3
+ ## 3.0.8
4
+
5
+ ### Patch Changes
6
+
7
+ - 99964ed: fix(provider-utils): fix type inference for toModelOutput
8
+
9
+ ## 3.0.7
10
+
11
+ ### Patch Changes
12
+
13
+ - 886e7cd: chore(provider-utils): upgrade event-source parser to 3.0.5
14
+
3
15
  ## 3.0.6
4
16
 
5
17
  ### Patch Changes
package/dist/index.d.mts CHANGED
@@ -608,6 +608,20 @@ interface ToolCallOptions {
608
608
  }
609
609
  type ToolExecuteFunction<INPUT, OUTPUT> = (input: INPUT, options: ToolCallOptions) => AsyncIterable<OUTPUT> | PromiseLike<OUTPUT> | OUTPUT;
610
610
  type NeverOptional<N, T> = 0 extends 1 & N ? Partial<T> : [N] extends [never] ? Partial<Record<keyof T, undefined>> : T;
611
+ type ToolOutputProperties<INPUT, OUTPUT> = NeverOptional<OUTPUT, {
612
+ /**
613
+ An async function that is called with the arguments from the tool call and produces a result.
614
+ If not provided, the tool will not be executed automatically.
615
+
616
+ @args is the input of the tool call.
617
+ @options.abortSignal is a signal that can be used to abort the tool call.
618
+ */
619
+ execute: ToolExecuteFunction<INPUT, OUTPUT>;
620
+ outputSchema?: FlexibleSchema<OUTPUT>;
621
+ } | {
622
+ outputSchema: FlexibleSchema<OUTPUT>;
623
+ execute?: never;
624
+ }>;
611
625
  /**
612
626
  A tool contains the description and the schema of the input that the tool expects.
613
627
  This enables the language model to generate the input.
@@ -652,27 +666,14 @@ type Tool<INPUT extends JSONValue | unknown | never = any, OUTPUT extends JSONVa
652
666
  onInputAvailable?: (options: {
653
667
  input: [INPUT] extends [never] ? undefined : INPUT;
654
668
  } & ToolCallOptions) => void | PromiseLike<void>;
655
- } & NeverOptional<OUTPUT, {
669
+ } & ToolOutputProperties<INPUT, OUTPUT> & {
656
670
  /**
657
671
  Optional conversion function that maps the tool result to an output that can be used by the language model.
658
672
 
659
673
  If not provided, the tool result will be sent as a JSON object.
660
- */
661
- toModelOutput?: (output: OUTPUT) => LanguageModelV2ToolResultPart['output'];
662
- } & ({
663
- /**
664
- An async function that is called with the arguments from the tool call and produces a result.
665
- If not provided, the tool will not be executed automatically.
666
-
667
- @args is the input of the tool call.
668
- @options.abortSignal is a signal that can be used to abort the tool call.
669
674
  */
670
- execute: ToolExecuteFunction<INPUT, OUTPUT>;
671
- outputSchema?: FlexibleSchema<OUTPUT>;
672
- } | {
673
- outputSchema: FlexibleSchema<OUTPUT>;
674
- execute?: never;
675
- })> & ({
675
+ toModelOutput?: (output: 0 extends 1 & OUTPUT ? any : [OUTPUT] extends [never] ? any : NoInfer<OUTPUT>) => LanguageModelV2ToolResultPart['output'];
676
+ } & ({
676
677
  /**
677
678
  Tool with user-defined input and output schemas.
678
679
  */
package/dist/index.d.ts CHANGED
@@ -608,6 +608,20 @@ interface ToolCallOptions {
608
608
  }
609
609
  type ToolExecuteFunction<INPUT, OUTPUT> = (input: INPUT, options: ToolCallOptions) => AsyncIterable<OUTPUT> | PromiseLike<OUTPUT> | OUTPUT;
610
610
  type NeverOptional<N, T> = 0 extends 1 & N ? Partial<T> : [N] extends [never] ? Partial<Record<keyof T, undefined>> : T;
611
+ type ToolOutputProperties<INPUT, OUTPUT> = NeverOptional<OUTPUT, {
612
+ /**
613
+ An async function that is called with the arguments from the tool call and produces a result.
614
+ If not provided, the tool will not be executed automatically.
615
+
616
+ @args is the input of the tool call.
617
+ @options.abortSignal is a signal that can be used to abort the tool call.
618
+ */
619
+ execute: ToolExecuteFunction<INPUT, OUTPUT>;
620
+ outputSchema?: FlexibleSchema<OUTPUT>;
621
+ } | {
622
+ outputSchema: FlexibleSchema<OUTPUT>;
623
+ execute?: never;
624
+ }>;
611
625
  /**
612
626
  A tool contains the description and the schema of the input that the tool expects.
613
627
  This enables the language model to generate the input.
@@ -652,27 +666,14 @@ type Tool<INPUT extends JSONValue | unknown | never = any, OUTPUT extends JSONVa
652
666
  onInputAvailable?: (options: {
653
667
  input: [INPUT] extends [never] ? undefined : INPUT;
654
668
  } & ToolCallOptions) => void | PromiseLike<void>;
655
- } & NeverOptional<OUTPUT, {
669
+ } & ToolOutputProperties<INPUT, OUTPUT> & {
656
670
  /**
657
671
  Optional conversion function that maps the tool result to an output that can be used by the language model.
658
672
 
659
673
  If not provided, the tool result will be sent as a JSON object.
660
- */
661
- toModelOutput?: (output: OUTPUT) => LanguageModelV2ToolResultPart['output'];
662
- } & ({
663
- /**
664
- An async function that is called with the arguments from the tool call and produces a result.
665
- If not provided, the tool will not be executed automatically.
666
-
667
- @args is the input of the tool call.
668
- @options.abortSignal is a signal that can be used to abort the tool call.
669
674
  */
670
- execute: ToolExecuteFunction<INPUT, OUTPUT>;
671
- outputSchema?: FlexibleSchema<OUTPUT>;
672
- } | {
673
- outputSchema: FlexibleSchema<OUTPUT>;
674
- execute?: never;
675
- })> & ({
675
+ toModelOutput?: (output: 0 extends 1 & OUTPUT ? any : [OUTPUT] extends [never] ? any : NoInfer<OUTPUT>) => LanguageModelV2ToolResultPart['output'];
676
+ } & ({
676
677
  /**
677
678
  Tool with user-defined input and output schemas.
678
679
  */