@ai-sdk/provider 2.1.0-beta.1 → 2.1.0-beta.3
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 +13 -0
- package/dist/index.d.mts +1101 -56
- package/dist/index.d.ts +1101 -56
- package/package.json +1 -1
package/dist/index.d.mts
CHANGED
@@ -485,6 +485,158 @@ declare function isJSONValue(value: unknown): value is JSONValue;
|
|
485
485
|
declare function isJSONArray(value: unknown): value is JSONArray;
|
486
486
|
declare function isJSONObject(value: unknown): value is JSONObject;
|
487
487
|
|
488
|
+
type ImageModelV3CallOptions = {
|
489
|
+
/**
|
490
|
+
Prompt for the image generation.
|
491
|
+
*/
|
492
|
+
prompt: string;
|
493
|
+
/**
|
494
|
+
Number of images to generate.
|
495
|
+
*/
|
496
|
+
n: number;
|
497
|
+
/**
|
498
|
+
Size of the images to generate.
|
499
|
+
Must have the format `{width}x{height}`.
|
500
|
+
`undefined` will use the provider's default size.
|
501
|
+
*/
|
502
|
+
size: `${number}x${number}` | undefined;
|
503
|
+
/**
|
504
|
+
Aspect ratio of the images to generate.
|
505
|
+
Must have the format `{width}:{height}`.
|
506
|
+
`undefined` will use the provider's default aspect ratio.
|
507
|
+
*/
|
508
|
+
aspectRatio: `${number}:${number}` | undefined;
|
509
|
+
/**
|
510
|
+
Seed for the image generation.
|
511
|
+
`undefined` will use the provider's default seed.
|
512
|
+
*/
|
513
|
+
seed: number | undefined;
|
514
|
+
/**
|
515
|
+
Additional provider-specific options that are passed through to the provider
|
516
|
+
as body parameters.
|
517
|
+
|
518
|
+
The outer record is keyed by the provider name, and the inner
|
519
|
+
record is keyed by the provider-specific metadata key.
|
520
|
+
```ts
|
521
|
+
{
|
522
|
+
"openai": {
|
523
|
+
"style": "vivid"
|
524
|
+
}
|
525
|
+
}
|
526
|
+
```
|
527
|
+
*/
|
528
|
+
providerOptions: SharedV2ProviderOptions;
|
529
|
+
/**
|
530
|
+
Abort signal for cancelling the operation.
|
531
|
+
*/
|
532
|
+
abortSignal?: AbortSignal;
|
533
|
+
/**
|
534
|
+
Additional HTTP headers to be sent with the request.
|
535
|
+
Only applicable for HTTP-based providers.
|
536
|
+
*/
|
537
|
+
headers?: Record<string, string | undefined>;
|
538
|
+
};
|
539
|
+
|
540
|
+
/**
|
541
|
+
Warning from the model provider for this call. The call will proceed, but e.g.
|
542
|
+
some settings might not be supported, which can lead to suboptimal results.
|
543
|
+
*/
|
544
|
+
type ImageModelV3CallWarning = {
|
545
|
+
type: 'unsupported-setting';
|
546
|
+
setting: keyof ImageModelV3CallOptions;
|
547
|
+
details?: string;
|
548
|
+
} | {
|
549
|
+
type: 'other';
|
550
|
+
message: string;
|
551
|
+
};
|
552
|
+
|
553
|
+
type ImageModelV3ProviderMetadata = Record<string, {
|
554
|
+
images: JSONArray;
|
555
|
+
} & JSONValue>;
|
556
|
+
type GetMaxImagesPerCallFunction$1 = (options: {
|
557
|
+
modelId: string;
|
558
|
+
}) => PromiseLike<number | undefined> | number | undefined;
|
559
|
+
/**
|
560
|
+
Image generation model specification version 3.
|
561
|
+
*/
|
562
|
+
type ImageModelV3 = {
|
563
|
+
/**
|
564
|
+
The image model must specify which image model interface
|
565
|
+
version it implements. This will allow us to evolve the image
|
566
|
+
model interface and retain backwards compatibility. The different
|
567
|
+
implementation versions can be handled as a discriminated union
|
568
|
+
on our side.
|
569
|
+
*/
|
570
|
+
readonly specificationVersion: 'v3';
|
571
|
+
/**
|
572
|
+
Name of the provider for logging purposes.
|
573
|
+
*/
|
574
|
+
readonly provider: string;
|
575
|
+
/**
|
576
|
+
Provider-specific model ID for logging purposes.
|
577
|
+
*/
|
578
|
+
readonly modelId: string;
|
579
|
+
/**
|
580
|
+
Limit of how many images can be generated in a single API call.
|
581
|
+
Can be set to a number for a fixed limit, to undefined to use
|
582
|
+
the global limit, or a function that returns a number or undefined,
|
583
|
+
optionally as a promise.
|
584
|
+
*/
|
585
|
+
readonly maxImagesPerCall: number | undefined | GetMaxImagesPerCallFunction$1;
|
586
|
+
/**
|
587
|
+
Generates an array of images.
|
588
|
+
*/
|
589
|
+
doGenerate(options: ImageModelV3CallOptions): PromiseLike<{
|
590
|
+
/**
|
591
|
+
Generated images as base64 encoded strings or binary data.
|
592
|
+
The images should be returned without any unnecessary conversion.
|
593
|
+
If the API returns base64 encoded strings, the images should be returned
|
594
|
+
as base64 encoded strings. If the API returns binary data, the images should
|
595
|
+
be returned as binary data.
|
596
|
+
*/
|
597
|
+
images: Array<string> | Array<Uint8Array>;
|
598
|
+
/**
|
599
|
+
Warnings for the call, e.g. unsupported settings.
|
600
|
+
*/
|
601
|
+
warnings: Array<ImageModelV3CallWarning>;
|
602
|
+
/**
|
603
|
+
Additional provider-specific metadata. They are passed through
|
604
|
+
from the provider to the AI SDK and enable provider-specific
|
605
|
+
results that can be fully encapsulated in the provider.
|
606
|
+
|
607
|
+
The outer record is keyed by the provider name, and the inner
|
608
|
+
record is provider-specific metadata. It always includes an
|
609
|
+
`images` key with image-specific metadata
|
610
|
+
|
611
|
+
```ts
|
612
|
+
{
|
613
|
+
"openai": {
|
614
|
+
"images": ["revisedPrompt": "Revised prompt here."]
|
615
|
+
}
|
616
|
+
}
|
617
|
+
```
|
618
|
+
*/
|
619
|
+
providerMetadata?: ImageModelV3ProviderMetadata;
|
620
|
+
/**
|
621
|
+
Response information for telemetry and debugging purposes.
|
622
|
+
*/
|
623
|
+
response: {
|
624
|
+
/**
|
625
|
+
Timestamp for the start of the generated response.
|
626
|
+
*/
|
627
|
+
timestamp: Date;
|
628
|
+
/**
|
629
|
+
The ID of the response model that was used to generate the response.
|
630
|
+
*/
|
631
|
+
modelId: string;
|
632
|
+
/**
|
633
|
+
Response headers.
|
634
|
+
*/
|
635
|
+
headers: Record<string, string> | undefined;
|
636
|
+
};
|
637
|
+
}>;
|
638
|
+
};
|
639
|
+
|
488
640
|
type ImageModelV2CallOptions = {
|
489
641
|
/**
|
490
642
|
Prompt for the image generation.
|
@@ -546,28 +698,753 @@ type ImageModelV2CallWarning = {
|
|
546
698
|
setting: keyof ImageModelV2CallOptions;
|
547
699
|
details?: string;
|
548
700
|
} | {
|
549
|
-
type: 'other';
|
550
|
-
message: string;
|
701
|
+
type: 'other';
|
702
|
+
message: string;
|
703
|
+
};
|
704
|
+
|
705
|
+
type ImageModelV2ProviderMetadata = Record<string, {
|
706
|
+
images: JSONArray;
|
707
|
+
} & JSONValue>;
|
708
|
+
type GetMaxImagesPerCallFunction = (options: {
|
709
|
+
modelId: string;
|
710
|
+
}) => PromiseLike<number | undefined> | number | undefined;
|
711
|
+
/**
|
712
|
+
Image generation model specification version 2.
|
713
|
+
*/
|
714
|
+
type ImageModelV2 = {
|
715
|
+
/**
|
716
|
+
The image model must specify which image model interface
|
717
|
+
version it implements. This will allow us to evolve the image
|
718
|
+
model interface and retain backwards compatibility. The different
|
719
|
+
implementation versions can be handled as a discriminated union
|
720
|
+
on our side.
|
721
|
+
*/
|
722
|
+
readonly specificationVersion: 'v2';
|
723
|
+
/**
|
724
|
+
Name of the provider for logging purposes.
|
725
|
+
*/
|
726
|
+
readonly provider: string;
|
727
|
+
/**
|
728
|
+
Provider-specific model ID for logging purposes.
|
729
|
+
*/
|
730
|
+
readonly modelId: string;
|
731
|
+
/**
|
732
|
+
Limit of how many images can be generated in a single API call.
|
733
|
+
Can be set to a number for a fixed limit, to undefined to use
|
734
|
+
the global limit, or a function that returns a number or undefined,
|
735
|
+
optionally as a promise.
|
736
|
+
*/
|
737
|
+
readonly maxImagesPerCall: number | undefined | GetMaxImagesPerCallFunction;
|
738
|
+
/**
|
739
|
+
Generates an array of images.
|
740
|
+
*/
|
741
|
+
doGenerate(options: ImageModelV2CallOptions): PromiseLike<{
|
742
|
+
/**
|
743
|
+
Generated images as base64 encoded strings or binary data.
|
744
|
+
The images should be returned without any unnecessary conversion.
|
745
|
+
If the API returns base64 encoded strings, the images should be returned
|
746
|
+
as base64 encoded strings. If the API returns binary data, the images should
|
747
|
+
be returned as binary data.
|
748
|
+
*/
|
749
|
+
images: Array<string> | Array<Uint8Array>;
|
750
|
+
/**
|
751
|
+
Warnings for the call, e.g. unsupported settings.
|
752
|
+
*/
|
753
|
+
warnings: Array<ImageModelV2CallWarning>;
|
754
|
+
/**
|
755
|
+
Additional provider-specific metadata. They are passed through
|
756
|
+
from the provider to the AI SDK and enable provider-specific
|
757
|
+
results that can be fully encapsulated in the provider.
|
758
|
+
|
759
|
+
The outer record is keyed by the provider name, and the inner
|
760
|
+
record is provider-specific metadata. It always includes an
|
761
|
+
`images` key with image-specific metadata
|
762
|
+
|
763
|
+
```ts
|
764
|
+
{
|
765
|
+
"openai": {
|
766
|
+
"images": ["revisedPrompt": "Revised prompt here."]
|
767
|
+
}
|
768
|
+
}
|
769
|
+
```
|
770
|
+
*/
|
771
|
+
providerMetadata?: ImageModelV2ProviderMetadata;
|
772
|
+
/**
|
773
|
+
Response information for telemetry and debugging purposes.
|
774
|
+
*/
|
775
|
+
response: {
|
776
|
+
/**
|
777
|
+
Timestamp for the start of the generated response.
|
778
|
+
*/
|
779
|
+
timestamp: Date;
|
780
|
+
/**
|
781
|
+
The ID of the response model that was used to generate the response.
|
782
|
+
*/
|
783
|
+
modelId: string;
|
784
|
+
/**
|
785
|
+
Response headers.
|
786
|
+
*/
|
787
|
+
headers: Record<string, string> | undefined;
|
788
|
+
};
|
789
|
+
}>;
|
790
|
+
};
|
791
|
+
|
792
|
+
/**
|
793
|
+
A tool has a name, a description, and a set of parameters.
|
794
|
+
|
795
|
+
Note: this is **not** the user-facing tool definition. The AI SDK methods will
|
796
|
+
map the user-facing tool definitions to this format.
|
797
|
+
*/
|
798
|
+
type LanguageModelV3FunctionTool = {
|
799
|
+
/**
|
800
|
+
The type of the tool (always 'function').
|
801
|
+
*/
|
802
|
+
type: 'function';
|
803
|
+
/**
|
804
|
+
The name of the tool. Unique within this model call.
|
805
|
+
*/
|
806
|
+
name: string;
|
807
|
+
/**
|
808
|
+
A description of the tool. The language model uses this to understand the
|
809
|
+
tool's purpose and to provide better completion suggestions.
|
810
|
+
*/
|
811
|
+
description?: string;
|
812
|
+
/**
|
813
|
+
The parameters that the tool expects. The language model uses this to
|
814
|
+
understand the tool's input requirements and to provide matching suggestions.
|
815
|
+
*/
|
816
|
+
inputSchema: JSONSchema7;
|
817
|
+
/**
|
818
|
+
The provider-specific options for the tool.
|
819
|
+
*/
|
820
|
+
providerOptions?: SharedV2ProviderOptions;
|
821
|
+
};
|
822
|
+
|
823
|
+
/**
|
824
|
+
Data content. Can be a Uint8Array, base64 encoded data as a string or a URL.
|
825
|
+
*/
|
826
|
+
type LanguageModelV3DataContent = Uint8Array | string | URL;
|
827
|
+
|
828
|
+
/**
|
829
|
+
A prompt is a list of messages.
|
830
|
+
|
831
|
+
Note: Not all models and prompt formats support multi-modal inputs and
|
832
|
+
tool calls. The validation happens at runtime.
|
833
|
+
|
834
|
+
Note: This is not a user-facing prompt. The AI SDK methods will map the
|
835
|
+
user-facing prompt types such as chat or instruction prompts to this format.
|
836
|
+
*/
|
837
|
+
type LanguageModelV3Prompt = Array<LanguageModelV3Message>;
|
838
|
+
type LanguageModelV3Message = ({
|
839
|
+
role: 'system';
|
840
|
+
content: string;
|
841
|
+
} | {
|
842
|
+
role: 'user';
|
843
|
+
content: Array<LanguageModelV3TextPart | LanguageModelV3FilePart>;
|
844
|
+
} | {
|
845
|
+
role: 'assistant';
|
846
|
+
content: Array<LanguageModelV3TextPart | LanguageModelV3FilePart | LanguageModelV3ReasoningPart | LanguageModelV3ToolCallPart | LanguageModelV3ToolResultPart>;
|
847
|
+
} | {
|
848
|
+
role: 'tool';
|
849
|
+
content: Array<LanguageModelV3ToolResultPart>;
|
850
|
+
}) & {
|
851
|
+
/**
|
852
|
+
* Additional provider-specific options. They are passed through
|
853
|
+
* to the provider from the AI SDK and enable provider-specific
|
854
|
+
* functionality that can be fully encapsulated in the provider.
|
855
|
+
*/
|
856
|
+
providerOptions?: SharedV2ProviderOptions;
|
857
|
+
};
|
858
|
+
/**
|
859
|
+
Text content part of a prompt. It contains a string of text.
|
860
|
+
*/
|
861
|
+
interface LanguageModelV3TextPart {
|
862
|
+
type: 'text';
|
863
|
+
/**
|
864
|
+
The text content.
|
865
|
+
*/
|
866
|
+
text: string;
|
867
|
+
/**
|
868
|
+
* Additional provider-specific options. They are passed through
|
869
|
+
* to the provider from the AI SDK and enable provider-specific
|
870
|
+
* functionality that can be fully encapsulated in the provider.
|
871
|
+
*/
|
872
|
+
providerOptions?: SharedV2ProviderOptions;
|
873
|
+
}
|
874
|
+
/**
|
875
|
+
Reasoning content part of a prompt. It contains a string of reasoning text.
|
876
|
+
*/
|
877
|
+
interface LanguageModelV3ReasoningPart {
|
878
|
+
type: 'reasoning';
|
879
|
+
/**
|
880
|
+
The reasoning text.
|
881
|
+
*/
|
882
|
+
text: string;
|
883
|
+
/**
|
884
|
+
* Additional provider-specific options. They are passed through
|
885
|
+
* to the provider from the AI SDK and enable provider-specific
|
886
|
+
* functionality that can be fully encapsulated in the provider.
|
887
|
+
*/
|
888
|
+
providerOptions?: SharedV2ProviderOptions;
|
889
|
+
}
|
890
|
+
/**
|
891
|
+
File content part of a prompt. It contains a file.
|
892
|
+
*/
|
893
|
+
interface LanguageModelV3FilePart {
|
894
|
+
type: 'file';
|
895
|
+
/**
|
896
|
+
* Optional filename of the file.
|
897
|
+
*/
|
898
|
+
filename?: string;
|
899
|
+
/**
|
900
|
+
File data. Can be a Uint8Array, base64 encoded data as a string or a URL.
|
901
|
+
*/
|
902
|
+
data: LanguageModelV3DataContent;
|
903
|
+
/**
|
904
|
+
IANA media type of the file.
|
905
|
+
|
906
|
+
Can support wildcards, e.g. `image/*` (in which case the provider needs to take appropriate action).
|
907
|
+
|
908
|
+
@see https://www.iana.org/assignments/media-types/media-types.xhtml
|
909
|
+
*/
|
910
|
+
mediaType: string;
|
911
|
+
/**
|
912
|
+
* Additional provider-specific options. They are passed through
|
913
|
+
* to the provider from the AI SDK and enable provider-specific
|
914
|
+
* functionality that can be fully encapsulated in the provider.
|
915
|
+
*/
|
916
|
+
providerOptions?: SharedV2ProviderOptions;
|
917
|
+
}
|
918
|
+
/**
|
919
|
+
Tool call content part of a prompt. It contains a tool call (usually generated by the AI model).
|
920
|
+
*/
|
921
|
+
interface LanguageModelV3ToolCallPart {
|
922
|
+
type: 'tool-call';
|
923
|
+
/**
|
924
|
+
ID of the tool call. This ID is used to match the tool call with the tool result.
|
925
|
+
*/
|
926
|
+
toolCallId: string;
|
927
|
+
/**
|
928
|
+
Name of the tool that is being called.
|
929
|
+
*/
|
930
|
+
toolName: string;
|
931
|
+
/**
|
932
|
+
Arguments of the tool call. This is a JSON-serializable object that matches the tool's input schema.
|
933
|
+
*/
|
934
|
+
input: unknown;
|
935
|
+
/**
|
936
|
+
* Whether the tool call will be executed by the provider.
|
937
|
+
* If this flag is not set or is false, the tool call will be executed by the client.
|
938
|
+
*/
|
939
|
+
providerExecuted?: boolean;
|
940
|
+
/**
|
941
|
+
* Additional provider-specific options. They are passed through
|
942
|
+
* to the provider from the AI SDK and enable provider-specific
|
943
|
+
* functionality that can be fully encapsulated in the provider.
|
944
|
+
*/
|
945
|
+
providerOptions?: SharedV2ProviderOptions;
|
946
|
+
}
|
947
|
+
/**
|
948
|
+
Tool result content part of a prompt. It contains the result of the tool call with the matching ID.
|
949
|
+
*/
|
950
|
+
interface LanguageModelV3ToolResultPart {
|
951
|
+
type: 'tool-result';
|
952
|
+
/**
|
953
|
+
ID of the tool call that this result is associated with.
|
954
|
+
*/
|
955
|
+
toolCallId: string;
|
956
|
+
/**
|
957
|
+
Name of the tool that generated this result.
|
958
|
+
*/
|
959
|
+
toolName: string;
|
960
|
+
/**
|
961
|
+
Result of the tool call.
|
962
|
+
*/
|
963
|
+
output: LanguageModelV3ToolResultOutput;
|
964
|
+
/**
|
965
|
+
* Additional provider-specific options. They are passed through
|
966
|
+
* to the provider from the AI SDK and enable provider-specific
|
967
|
+
* functionality that can be fully encapsulated in the provider.
|
968
|
+
*/
|
969
|
+
providerOptions?: SharedV2ProviderOptions;
|
970
|
+
}
|
971
|
+
type LanguageModelV3ToolResultOutput = {
|
972
|
+
type: 'text';
|
973
|
+
value: string;
|
974
|
+
} | {
|
975
|
+
type: 'json';
|
976
|
+
value: JSONValue;
|
977
|
+
} | {
|
978
|
+
type: 'error-text';
|
979
|
+
value: string;
|
980
|
+
} | {
|
981
|
+
type: 'error-json';
|
982
|
+
value: JSONValue;
|
983
|
+
} | {
|
984
|
+
type: 'content';
|
985
|
+
value: Array<{
|
986
|
+
type: 'text';
|
987
|
+
/**
|
988
|
+
Text content.
|
989
|
+
*/
|
990
|
+
text: string;
|
991
|
+
} | {
|
992
|
+
type: 'media';
|
993
|
+
/**
|
994
|
+
Base-64 encoded media data.
|
995
|
+
*/
|
996
|
+
data: string;
|
997
|
+
/**
|
998
|
+
IANA media type.
|
999
|
+
@see https://www.iana.org/assignments/media-types/media-types.xhtml
|
1000
|
+
*/
|
1001
|
+
mediaType: string;
|
1002
|
+
}>;
|
1003
|
+
};
|
1004
|
+
|
1005
|
+
/**
|
1006
|
+
The configuration of a tool that is defined by the provider.
|
1007
|
+
*/
|
1008
|
+
type LanguageModelV3ProviderDefinedTool = {
|
1009
|
+
/**
|
1010
|
+
The type of the tool (always 'provider-defined').
|
1011
|
+
*/
|
1012
|
+
type: 'provider-defined';
|
1013
|
+
/**
|
1014
|
+
The ID of the tool. Should follow the format `<provider-name>.<unique-tool-name>`.
|
1015
|
+
*/
|
1016
|
+
id: `${string}.${string}`;
|
1017
|
+
/**
|
1018
|
+
The name of the tool that the user must use in the tool set.
|
1019
|
+
*/
|
1020
|
+
name: string;
|
1021
|
+
/**
|
1022
|
+
The arguments for configuring the tool. Must match the expected arguments defined by the provider for this tool.
|
1023
|
+
*/
|
1024
|
+
args: Record<string, unknown>;
|
1025
|
+
};
|
1026
|
+
|
1027
|
+
type LanguageModelV3ToolChoice = {
|
1028
|
+
type: 'auto';
|
1029
|
+
} | {
|
1030
|
+
type: 'none';
|
1031
|
+
} | {
|
1032
|
+
type: 'required';
|
1033
|
+
} | {
|
1034
|
+
type: 'tool';
|
1035
|
+
toolName: string;
|
1036
|
+
};
|
1037
|
+
|
1038
|
+
type LanguageModelV3CallOptions = {
|
1039
|
+
/**
|
1040
|
+
A language mode prompt is a standardized prompt type.
|
1041
|
+
|
1042
|
+
Note: This is **not** the user-facing prompt. The AI SDK methods will map the
|
1043
|
+
user-facing prompt types such as chat or instruction prompts to this format.
|
1044
|
+
That approach allows us to evolve the user facing prompts without breaking
|
1045
|
+
the language model interface.
|
1046
|
+
*/
|
1047
|
+
prompt: LanguageModelV3Prompt;
|
1048
|
+
/**
|
1049
|
+
Maximum number of tokens to generate.
|
1050
|
+
*/
|
1051
|
+
maxOutputTokens?: number;
|
1052
|
+
/**
|
1053
|
+
Temperature setting. The range depends on the provider and model.
|
1054
|
+
*/
|
1055
|
+
temperature?: number;
|
1056
|
+
/**
|
1057
|
+
Stop sequences.
|
1058
|
+
If set, the model will stop generating text when one of the stop sequences is generated.
|
1059
|
+
Providers may have limits on the number of stop sequences.
|
1060
|
+
*/
|
1061
|
+
stopSequences?: string[];
|
1062
|
+
/**
|
1063
|
+
Nucleus sampling.
|
1064
|
+
*/
|
1065
|
+
topP?: number;
|
1066
|
+
/**
|
1067
|
+
Only sample from the top K options for each subsequent token.
|
1068
|
+
|
1069
|
+
Used to remove "long tail" low probability responses.
|
1070
|
+
Recommended for advanced use cases only. You usually only need to use temperature.
|
1071
|
+
*/
|
1072
|
+
topK?: number;
|
1073
|
+
/**
|
1074
|
+
Presence penalty setting. It affects the likelihood of the model to
|
1075
|
+
repeat information that is already in the prompt.
|
1076
|
+
*/
|
1077
|
+
presencePenalty?: number;
|
1078
|
+
/**
|
1079
|
+
Frequency penalty setting. It affects the likelihood of the model
|
1080
|
+
to repeatedly use the same words or phrases.
|
1081
|
+
*/
|
1082
|
+
frequencyPenalty?: number;
|
1083
|
+
/**
|
1084
|
+
Response format. The output can either be text or JSON. Default is text.
|
1085
|
+
|
1086
|
+
If JSON is selected, a schema can optionally be provided to guide the LLM.
|
1087
|
+
*/
|
1088
|
+
responseFormat?: {
|
1089
|
+
type: 'text';
|
1090
|
+
} | {
|
1091
|
+
type: 'json';
|
1092
|
+
/**
|
1093
|
+
* JSON schema that the generated output should conform to.
|
1094
|
+
*/
|
1095
|
+
schema?: JSONSchema7;
|
1096
|
+
/**
|
1097
|
+
* Name of output that should be generated. Used by some providers for additional LLM guidance.
|
1098
|
+
*/
|
1099
|
+
name?: string;
|
1100
|
+
/**
|
1101
|
+
* Description of the output that should be generated. Used by some providers for additional LLM guidance.
|
1102
|
+
*/
|
1103
|
+
description?: string;
|
1104
|
+
};
|
1105
|
+
/**
|
1106
|
+
The seed (integer) to use for random sampling. If set and supported
|
1107
|
+
by the model, calls will generate deterministic results.
|
1108
|
+
*/
|
1109
|
+
seed?: number;
|
1110
|
+
/**
|
1111
|
+
The tools that are available for the model.
|
1112
|
+
*/
|
1113
|
+
tools?: Array<LanguageModelV3FunctionTool | LanguageModelV3ProviderDefinedTool>;
|
1114
|
+
/**
|
1115
|
+
Specifies how the tool should be selected. Defaults to 'auto'.
|
1116
|
+
*/
|
1117
|
+
toolChoice?: LanguageModelV3ToolChoice;
|
1118
|
+
/**
|
1119
|
+
Include raw chunks in the stream. Only applicable for streaming calls.
|
1120
|
+
*/
|
1121
|
+
includeRawChunks?: boolean;
|
1122
|
+
/**
|
1123
|
+
Abort signal for cancelling the operation.
|
1124
|
+
*/
|
1125
|
+
abortSignal?: AbortSignal;
|
1126
|
+
/**
|
1127
|
+
Additional HTTP headers to be sent with the request.
|
1128
|
+
Only applicable for HTTP-based providers.
|
1129
|
+
*/
|
1130
|
+
headers?: Record<string, string | undefined>;
|
1131
|
+
/**
|
1132
|
+
* Additional provider-specific options. They are passed through
|
1133
|
+
* to the provider from the AI SDK and enable provider-specific
|
1134
|
+
* functionality that can be fully encapsulated in the provider.
|
1135
|
+
*/
|
1136
|
+
providerOptions?: SharedV2ProviderOptions;
|
1137
|
+
};
|
1138
|
+
|
1139
|
+
/**
|
1140
|
+
Warning from the model provider for this call. The call will proceed, but e.g.
|
1141
|
+
some settings might not be supported, which can lead to suboptimal results.
|
1142
|
+
*/
|
1143
|
+
type LanguageModelV3CallWarning = {
|
1144
|
+
type: 'unsupported-setting';
|
1145
|
+
setting: Omit<keyof LanguageModelV3CallOptions, 'prompt'>;
|
1146
|
+
details?: string;
|
1147
|
+
} | {
|
1148
|
+
type: 'unsupported-tool';
|
1149
|
+
tool: LanguageModelV3FunctionTool | LanguageModelV3ProviderDefinedTool;
|
1150
|
+
details?: string;
|
1151
|
+
} | {
|
1152
|
+
type: 'other';
|
1153
|
+
message: string;
|
1154
|
+
};
|
1155
|
+
|
1156
|
+
/**
|
1157
|
+
A file that has been generated by the model.
|
1158
|
+
Generated files as base64 encoded strings or binary data.
|
1159
|
+
The files should be returned without any unnecessary conversion.
|
1160
|
+
*/
|
1161
|
+
type LanguageModelV3File = {
|
1162
|
+
type: 'file';
|
1163
|
+
/**
|
1164
|
+
The IANA media type of the file, e.g. `image/png` or `audio/mp3`.
|
1165
|
+
|
1166
|
+
@see https://www.iana.org/assignments/media-types/media-types.xhtml
|
1167
|
+
*/
|
1168
|
+
mediaType: string;
|
1169
|
+
/**
|
1170
|
+
Generated file data as base64 encoded strings or binary data.
|
1171
|
+
|
1172
|
+
The file data should be returned without any unnecessary conversion.
|
1173
|
+
If the API returns base64 encoded strings, the file data should be returned
|
1174
|
+
as base64 encoded strings. If the API returns binary data, the file data should
|
1175
|
+
be returned as binary data.
|
1176
|
+
*/
|
1177
|
+
data: string | Uint8Array;
|
1178
|
+
};
|
1179
|
+
|
1180
|
+
/**
|
1181
|
+
Reasoning that the model has generated.
|
1182
|
+
*/
|
1183
|
+
type LanguageModelV3Reasoning = {
|
1184
|
+
type: 'reasoning';
|
1185
|
+
text: string;
|
1186
|
+
/**
|
1187
|
+
* Optional provider-specific metadata for the reasoning part.
|
1188
|
+
*/
|
1189
|
+
providerMetadata?: SharedV2ProviderMetadata;
|
1190
|
+
};
|
1191
|
+
|
1192
|
+
/**
|
1193
|
+
A source that has been used as input to generate the response.
|
1194
|
+
*/
|
1195
|
+
type LanguageModelV3Source = {
|
1196
|
+
type: 'source';
|
1197
|
+
/**
|
1198
|
+
* The type of source - URL sources reference web content.
|
1199
|
+
*/
|
1200
|
+
sourceType: 'url';
|
1201
|
+
/**
|
1202
|
+
* The ID of the source.
|
1203
|
+
*/
|
1204
|
+
id: string;
|
1205
|
+
/**
|
1206
|
+
* The URL of the source.
|
1207
|
+
*/
|
1208
|
+
url: string;
|
1209
|
+
/**
|
1210
|
+
* The title of the source.
|
1211
|
+
*/
|
1212
|
+
title?: string;
|
1213
|
+
/**
|
1214
|
+
* Additional provider metadata for the source.
|
1215
|
+
*/
|
1216
|
+
providerMetadata?: SharedV2ProviderMetadata;
|
1217
|
+
} | {
|
1218
|
+
type: 'source';
|
1219
|
+
/**
|
1220
|
+
* The type of source - document sources reference files/documents.
|
1221
|
+
*/
|
1222
|
+
sourceType: 'document';
|
1223
|
+
/**
|
1224
|
+
* The ID of the source.
|
1225
|
+
*/
|
1226
|
+
id: string;
|
1227
|
+
/**
|
1228
|
+
* IANA media type of the document (e.g., 'application/pdf').
|
1229
|
+
*/
|
1230
|
+
mediaType: string;
|
1231
|
+
/**
|
1232
|
+
* The title of the document.
|
1233
|
+
*/
|
1234
|
+
title: string;
|
1235
|
+
/**
|
1236
|
+
* Optional filename of the document.
|
1237
|
+
*/
|
1238
|
+
filename?: string;
|
1239
|
+
/**
|
1240
|
+
* Additional provider metadata for the source.
|
1241
|
+
*/
|
1242
|
+
providerMetadata?: SharedV2ProviderMetadata;
|
1243
|
+
};
|
1244
|
+
|
1245
|
+
/**
|
1246
|
+
Text that the model has generated.
|
1247
|
+
*/
|
1248
|
+
type LanguageModelV3Text = {
|
1249
|
+
type: 'text';
|
1250
|
+
/**
|
1251
|
+
The text content.
|
1252
|
+
*/
|
1253
|
+
text: string;
|
1254
|
+
providerMetadata?: SharedV2ProviderMetadata;
|
1255
|
+
};
|
1256
|
+
|
1257
|
+
/**
|
1258
|
+
* Tool calls that the model has generated.
|
1259
|
+
*/
|
1260
|
+
type LanguageModelV3ToolCall = {
|
1261
|
+
type: 'tool-call';
|
1262
|
+
/**
|
1263
|
+
* The identifier of the tool call. It must be unique across all tool calls.
|
1264
|
+
*/
|
1265
|
+
toolCallId: string;
|
1266
|
+
/**
|
1267
|
+
* The name of the tool that should be called.
|
1268
|
+
*/
|
1269
|
+
toolName: string;
|
1270
|
+
/**
|
1271
|
+
* Stringified JSON object with the tool call arguments. Must match the
|
1272
|
+
* parameters schema of the tool.
|
1273
|
+
*/
|
1274
|
+
input: string;
|
1275
|
+
/**
|
1276
|
+
* Whether the tool call will be executed by the provider.
|
1277
|
+
* If this flag is not set or is false, the tool call will be executed by the client.
|
1278
|
+
*/
|
1279
|
+
providerExecuted?: boolean;
|
1280
|
+
/**
|
1281
|
+
* Additional provider-specific metadata for the tool call.
|
1282
|
+
*/
|
1283
|
+
providerMetadata?: SharedV2ProviderMetadata;
|
1284
|
+
};
|
1285
|
+
|
1286
|
+
/**
|
1287
|
+
Result of a tool call that has been executed by the provider.
|
1288
|
+
*/
|
1289
|
+
type LanguageModelV3ToolResult = {
|
1290
|
+
type: 'tool-result';
|
1291
|
+
/**
|
1292
|
+
* The ID of the tool call that this result is associated with.
|
1293
|
+
*/
|
1294
|
+
toolCallId: string;
|
1295
|
+
/**
|
1296
|
+
* Name of the tool that generated this result.
|
1297
|
+
*/
|
1298
|
+
toolName: string;
|
1299
|
+
/**
|
1300
|
+
* Result of the tool call. This is a JSON-serializable object.
|
1301
|
+
*/
|
1302
|
+
result: unknown;
|
1303
|
+
/**
|
1304
|
+
* Optional flag if the result is an error or an error message.
|
1305
|
+
*/
|
1306
|
+
isError?: boolean;
|
1307
|
+
/**
|
1308
|
+
* Whether the tool result was generated by the provider.
|
1309
|
+
* If this flag is set to true, the tool result was generated by the provider.
|
1310
|
+
* If this flag is not set or is false, the tool result was generated by the client.
|
1311
|
+
*/
|
1312
|
+
providerExecuted?: boolean;
|
1313
|
+
/**
|
1314
|
+
* Additional provider-specific metadata for the tool result.
|
1315
|
+
*/
|
1316
|
+
providerMetadata?: SharedV2ProviderMetadata;
|
1317
|
+
};
|
1318
|
+
|
1319
|
+
type LanguageModelV3Content = LanguageModelV3Text | LanguageModelV3Reasoning | LanguageModelV3File | LanguageModelV3Source | LanguageModelV3ToolCall | LanguageModelV3ToolResult;
|
1320
|
+
|
1321
|
+
/**
|
1322
|
+
Reason why a language model finished generating a response.
|
1323
|
+
|
1324
|
+
Can be one of the following:
|
1325
|
+
- `stop`: model generated stop sequence
|
1326
|
+
- `length`: model generated maximum number of tokens
|
1327
|
+
- `content-filter`: content filter violation stopped the model
|
1328
|
+
- `tool-calls`: model triggered tool calls
|
1329
|
+
- `error`: model stopped because of an error
|
1330
|
+
- `other`: model stopped for other reasons
|
1331
|
+
- `unknown`: the model has not transmitted a finish reason
|
1332
|
+
*/
|
1333
|
+
type LanguageModelV3FinishReason = 'stop' | 'length' | 'content-filter' | 'tool-calls' | 'error' | 'other' | 'unknown';
|
1334
|
+
|
1335
|
+
interface LanguageModelV3ResponseMetadata {
|
1336
|
+
/**
|
1337
|
+
ID for the generated response, if the provider sends one.
|
1338
|
+
*/
|
1339
|
+
id?: string;
|
1340
|
+
/**
|
1341
|
+
Timestamp for the start of the generated response, if the provider sends one.
|
1342
|
+
*/
|
1343
|
+
timestamp?: Date;
|
1344
|
+
/**
|
1345
|
+
The ID of the response model that was used to generate the response, if the provider sends one.
|
1346
|
+
*/
|
1347
|
+
modelId?: string;
|
1348
|
+
}
|
1349
|
+
|
1350
|
+
/**
|
1351
|
+
Usage information for a language model call.
|
1352
|
+
|
1353
|
+
If your API return additional usage information, you can add it to the
|
1354
|
+
provider metadata under your provider's key.
|
1355
|
+
*/
|
1356
|
+
type LanguageModelV3Usage = {
|
1357
|
+
/**
|
1358
|
+
The number of input (prompt) tokens used.
|
1359
|
+
*/
|
1360
|
+
inputTokens: number | undefined;
|
1361
|
+
/**
|
1362
|
+
The number of output (completion) tokens used.
|
1363
|
+
*/
|
1364
|
+
outputTokens: number | undefined;
|
1365
|
+
/**
|
1366
|
+
The total number of tokens as reported by the provider.
|
1367
|
+
This number might be different from the sum of `inputTokens` and `outputTokens`
|
1368
|
+
and e.g. include reasoning tokens or other overhead.
|
1369
|
+
*/
|
1370
|
+
totalTokens: number | undefined;
|
1371
|
+
/**
|
1372
|
+
The number of reasoning tokens used.
|
1373
|
+
*/
|
1374
|
+
reasoningTokens?: number | undefined;
|
1375
|
+
/**
|
1376
|
+
The number of cached input tokens.
|
1377
|
+
*/
|
1378
|
+
cachedInputTokens?: number | undefined;
|
1379
|
+
};
|
1380
|
+
|
1381
|
+
type LanguageModelV3StreamPart = {
|
1382
|
+
type: 'text-start';
|
1383
|
+
providerMetadata?: SharedV2ProviderMetadata;
|
1384
|
+
id: string;
|
1385
|
+
} | {
|
1386
|
+
type: 'text-delta';
|
1387
|
+
id: string;
|
1388
|
+
providerMetadata?: SharedV2ProviderMetadata;
|
1389
|
+
delta: string;
|
1390
|
+
} | {
|
1391
|
+
type: 'text-end';
|
1392
|
+
providerMetadata?: SharedV2ProviderMetadata;
|
1393
|
+
id: string;
|
1394
|
+
} | {
|
1395
|
+
type: 'reasoning-start';
|
1396
|
+
providerMetadata?: SharedV2ProviderMetadata;
|
1397
|
+
id: string;
|
1398
|
+
} | {
|
1399
|
+
type: 'reasoning-delta';
|
1400
|
+
id: string;
|
1401
|
+
providerMetadata?: SharedV2ProviderMetadata;
|
1402
|
+
delta: string;
|
1403
|
+
} | {
|
1404
|
+
type: 'reasoning-end';
|
1405
|
+
id: string;
|
1406
|
+
providerMetadata?: SharedV2ProviderMetadata;
|
1407
|
+
} | {
|
1408
|
+
type: 'tool-input-start';
|
1409
|
+
id: string;
|
1410
|
+
toolName: string;
|
1411
|
+
providerMetadata?: SharedV2ProviderMetadata;
|
1412
|
+
providerExecuted?: boolean;
|
1413
|
+
} | {
|
1414
|
+
type: 'tool-input-delta';
|
1415
|
+
id: string;
|
1416
|
+
delta: string;
|
1417
|
+
providerMetadata?: SharedV2ProviderMetadata;
|
1418
|
+
} | {
|
1419
|
+
type: 'tool-input-end';
|
1420
|
+
id: string;
|
1421
|
+
providerMetadata?: SharedV2ProviderMetadata;
|
1422
|
+
} | LanguageModelV3ToolCall | LanguageModelV3ToolResult | LanguageModelV3File | LanguageModelV3Source | {
|
1423
|
+
type: 'stream-start';
|
1424
|
+
warnings: Array<LanguageModelV3CallWarning>;
|
1425
|
+
} | ({
|
1426
|
+
type: 'response-metadata';
|
1427
|
+
} & LanguageModelV3ResponseMetadata) | {
|
1428
|
+
type: 'finish';
|
1429
|
+
usage: LanguageModelV3Usage;
|
1430
|
+
finishReason: LanguageModelV3FinishReason;
|
1431
|
+
providerMetadata?: SharedV2ProviderMetadata;
|
1432
|
+
} | {
|
1433
|
+
type: 'raw';
|
1434
|
+
rawValue: unknown;
|
1435
|
+
} | {
|
1436
|
+
type: 'error';
|
1437
|
+
error: unknown;
|
551
1438
|
};
|
552
1439
|
|
553
|
-
type ImageModelV2ProviderMetadata = Record<string, {
|
554
|
-
images: JSONArray;
|
555
|
-
} & JSONValue>;
|
556
|
-
type GetMaxImagesPerCallFunction = (options: {
|
557
|
-
modelId: string;
|
558
|
-
}) => PromiseLike<number | undefined> | number | undefined;
|
559
1440
|
/**
|
560
|
-
|
1441
|
+
Specification for a language model that implements the language model interface version 3.
|
561
1442
|
*/
|
562
|
-
type
|
1443
|
+
type LanguageModelV3 = {
|
563
1444
|
/**
|
564
|
-
The
|
565
|
-
version it implements. This will allow us to evolve the image
|
566
|
-
model interface and retain backwards compatibility. The different
|
567
|
-
implementation versions can be handled as a discriminated union
|
568
|
-
on our side.
|
1445
|
+
The language model must specify which language model interface version it implements.
|
569
1446
|
*/
|
570
|
-
readonly specificationVersion: '
|
1447
|
+
readonly specificationVersion: 'v3';
|
571
1448
|
/**
|
572
1449
|
Name of the provider for logging purposes.
|
573
1450
|
*/
|
@@ -577,66 +1454,179 @@ type ImageModelV2 = {
|
|
577
1454
|
*/
|
578
1455
|
readonly modelId: string;
|
579
1456
|
/**
|
580
|
-
|
581
|
-
|
582
|
-
|
583
|
-
|
1457
|
+
Supported URL patterns by media type for the provider.
|
1458
|
+
|
1459
|
+
The keys are media type patterns or full media types (e.g. `*\/*` for everything, `audio/*`, `video/*`, or `application/pdf`).
|
1460
|
+
and the values are arrays of regular expressions that match the URL paths.
|
1461
|
+
|
1462
|
+
The matching should be against lower-case URLs.
|
1463
|
+
|
1464
|
+
Matched URLs are supported natively by the model and are not downloaded.
|
1465
|
+
|
1466
|
+
@returns A map of supported URL patterns by media type (as a promise or a plain object).
|
584
1467
|
*/
|
585
|
-
|
1468
|
+
supportedUrls: PromiseLike<Record<string, RegExp[]>> | Record<string, RegExp[]>;
|
586
1469
|
/**
|
587
|
-
Generates
|
1470
|
+
Generates a language model output (non-streaming).
|
1471
|
+
|
1472
|
+
Naming: "do" prefix to prevent accidental direct usage of the method
|
1473
|
+
by the user.
|
588
1474
|
*/
|
589
|
-
doGenerate(options:
|
1475
|
+
doGenerate(options: LanguageModelV3CallOptions): PromiseLike<{
|
590
1476
|
/**
|
591
|
-
|
592
|
-
The images should be returned without any unnecessary conversion.
|
593
|
-
If the API returns base64 encoded strings, the images should be returned
|
594
|
-
as base64 encoded strings. If the API returns binary data, the images should
|
595
|
-
be returned as binary data.
|
1477
|
+
Ordered content that the model has generated.
|
596
1478
|
*/
|
597
|
-
|
1479
|
+
content: Array<LanguageModelV3Content>;
|
598
1480
|
/**
|
599
|
-
|
1481
|
+
Finish reason.
|
600
1482
|
*/
|
601
|
-
|
1483
|
+
finishReason: LanguageModelV3FinishReason;
|
1484
|
+
/**
|
1485
|
+
Usage information.
|
1486
|
+
*/
|
1487
|
+
usage: LanguageModelV3Usage;
|
602
1488
|
/**
|
603
1489
|
Additional provider-specific metadata. They are passed through
|
604
1490
|
from the provider to the AI SDK and enable provider-specific
|
605
1491
|
results that can be fully encapsulated in the provider.
|
606
|
-
|
607
|
-
|
608
|
-
record is provider-specific metadata. It always includes an
|
609
|
-
`images` key with image-specific metadata
|
610
|
-
|
611
|
-
```ts
|
612
|
-
{
|
613
|
-
"openai": {
|
614
|
-
"images": ["revisedPrompt": "Revised prompt here."]
|
615
|
-
}
|
616
|
-
}
|
617
|
-
```
|
618
|
-
*/
|
619
|
-
providerMetadata?: ImageModelV2ProviderMetadata;
|
1492
|
+
*/
|
1493
|
+
providerMetadata?: SharedV2ProviderMetadata;
|
620
1494
|
/**
|
621
|
-
|
1495
|
+
Optional request information for telemetry and debugging purposes.
|
622
1496
|
*/
|
623
|
-
|
1497
|
+
request?: {
|
624
1498
|
/**
|
625
|
-
|
626
|
-
|
627
|
-
|
1499
|
+
Request HTTP body that was sent to the provider API.
|
1500
|
+
*/
|
1501
|
+
body?: unknown;
|
1502
|
+
};
|
1503
|
+
/**
|
1504
|
+
Optional response information for telemetry and debugging purposes.
|
1505
|
+
*/
|
1506
|
+
response?: LanguageModelV3ResponseMetadata & {
|
628
1507
|
/**
|
629
|
-
|
1508
|
+
Response headers.
|
630
1509
|
*/
|
631
|
-
|
1510
|
+
headers?: SharedV2Headers;
|
1511
|
+
/**
|
1512
|
+
Response HTTP body.
|
1513
|
+
*/
|
1514
|
+
body?: unknown;
|
1515
|
+
};
|
1516
|
+
/**
|
1517
|
+
Warnings for the call, e.g. unsupported settings.
|
1518
|
+
*/
|
1519
|
+
warnings: Array<LanguageModelV3CallWarning>;
|
1520
|
+
}>;
|
1521
|
+
/**
|
1522
|
+
Generates a language model output (streaming).
|
1523
|
+
|
1524
|
+
Naming: "do" prefix to prevent accidental direct usage of the method
|
1525
|
+
by the user.
|
1526
|
+
*
|
1527
|
+
@return A stream of higher-level language model output parts.
|
1528
|
+
*/
|
1529
|
+
doStream(options: LanguageModelV3CallOptions): PromiseLike<{
|
1530
|
+
stream: ReadableStream<LanguageModelV3StreamPart>;
|
1531
|
+
/**
|
1532
|
+
Optional request information for telemetry and debugging purposes.
|
1533
|
+
*/
|
1534
|
+
request?: {
|
1535
|
+
/**
|
1536
|
+
Request HTTP body that was sent to the provider API.
|
1537
|
+
*/
|
1538
|
+
body?: unknown;
|
1539
|
+
};
|
1540
|
+
/**
|
1541
|
+
Optional response data.
|
1542
|
+
*/
|
1543
|
+
response?: {
|
632
1544
|
/**
|
633
1545
|
Response headers.
|
634
|
-
|
635
|
-
headers
|
1546
|
+
*/
|
1547
|
+
headers?: SharedV2Headers;
|
636
1548
|
};
|
637
1549
|
}>;
|
638
1550
|
};
|
639
1551
|
|
1552
|
+
/**
|
1553
|
+
* Experimental middleware for LanguageModelV3.
|
1554
|
+
* This type defines the structure for middleware that can be used to modify
|
1555
|
+
* the behavior of LanguageModelV3 operations.
|
1556
|
+
*/
|
1557
|
+
type LanguageModelV3Middleware = {
|
1558
|
+
/**
|
1559
|
+
* Middleware specification version. Use `v3` for the current version.
|
1560
|
+
*/
|
1561
|
+
middlewareVersion?: 'v3' | undefined;
|
1562
|
+
/**
|
1563
|
+
* Override the provider name if desired.
|
1564
|
+
* @param options.model - The language model instance.
|
1565
|
+
*/
|
1566
|
+
overrideProvider?: (options: {
|
1567
|
+
model: LanguageModelV3;
|
1568
|
+
}) => string;
|
1569
|
+
/**
|
1570
|
+
* Override the model ID if desired.
|
1571
|
+
* @param options.model - The language model instance.
|
1572
|
+
*/
|
1573
|
+
overrideModelId?: (options: {
|
1574
|
+
model: LanguageModelV3;
|
1575
|
+
}) => string;
|
1576
|
+
/**
|
1577
|
+
* Override the supported URLs if desired.
|
1578
|
+
* @param options.model - The language model instance.
|
1579
|
+
*/
|
1580
|
+
overrideSupportedUrls?: (options: {
|
1581
|
+
model: LanguageModelV3;
|
1582
|
+
}) => PromiseLike<Record<string, RegExp[]>> | Record<string, RegExp[]>;
|
1583
|
+
/**
|
1584
|
+
* Transforms the parameters before they are passed to the language model.
|
1585
|
+
* @param options - Object containing the type of operation and the parameters.
|
1586
|
+
* @param options.type - The type of operation ('generate' or 'stream').
|
1587
|
+
* @param options.params - The original parameters for the language model call.
|
1588
|
+
* @returns A promise that resolves to the transformed parameters.
|
1589
|
+
*/
|
1590
|
+
transformParams?: (options: {
|
1591
|
+
type: 'generate' | 'stream';
|
1592
|
+
params: LanguageModelV3CallOptions;
|
1593
|
+
model: LanguageModelV3;
|
1594
|
+
}) => PromiseLike<LanguageModelV3CallOptions>;
|
1595
|
+
/**
|
1596
|
+
* Wraps the generate operation of the language model.
|
1597
|
+
* @param options - Object containing the generate function, parameters, and model.
|
1598
|
+
* @param options.doGenerate - The original generate function.
|
1599
|
+
* @param options.doStream - The original stream function.
|
1600
|
+
* @param options.params - The parameters for the generate call. If the
|
1601
|
+
* `transformParams` middleware is used, this will be the transformed parameters.
|
1602
|
+
* @param options.model - The language model instance.
|
1603
|
+
* @returns A promise that resolves to the result of the generate operation.
|
1604
|
+
*/
|
1605
|
+
wrapGenerate?: (options: {
|
1606
|
+
doGenerate: () => ReturnType<LanguageModelV3['doGenerate']>;
|
1607
|
+
doStream: () => ReturnType<LanguageModelV3['doStream']>;
|
1608
|
+
params: LanguageModelV3CallOptions;
|
1609
|
+
model: LanguageModelV3;
|
1610
|
+
}) => Promise<Awaited<ReturnType<LanguageModelV3['doGenerate']>>>;
|
1611
|
+
/**
|
1612
|
+
* Wraps the stream operation of the language model.
|
1613
|
+
*
|
1614
|
+
* @param options - Object containing the stream function, parameters, and model.
|
1615
|
+
* @param options.doGenerate - The original generate function.
|
1616
|
+
* @param options.doStream - The original stream function.
|
1617
|
+
* @param options.params - The parameters for the stream call. If the
|
1618
|
+
* `transformParams` middleware is used, this will be the transformed parameters.
|
1619
|
+
* @param options.model - The language model instance.
|
1620
|
+
* @returns A promise that resolves to the result of the stream operation.
|
1621
|
+
*/
|
1622
|
+
wrapStream?: (options: {
|
1623
|
+
doGenerate: () => ReturnType<LanguageModelV3['doGenerate']>;
|
1624
|
+
doStream: () => ReturnType<LanguageModelV3['doStream']>;
|
1625
|
+
params: LanguageModelV3CallOptions;
|
1626
|
+
model: LanguageModelV3;
|
1627
|
+
}) => PromiseLike<Awaited<ReturnType<LanguageModelV3['doStream']>>>;
|
1628
|
+
};
|
1629
|
+
|
640
1630
|
/**
|
641
1631
|
A tool has a name, a description, and a set of parameters.
|
642
1632
|
|
@@ -1767,6 +2757,61 @@ type TranscriptionModelV2 = {
|
|
1767
2757
|
}>;
|
1768
2758
|
};
|
1769
2759
|
|
2760
|
+
/**
|
2761
|
+
* Provider for language, text embedding, and image generation models.
|
2762
|
+
*/
|
2763
|
+
interface ProviderV3 {
|
2764
|
+
/**
|
2765
|
+
Returns the language model with the given id.
|
2766
|
+
The model id is then passed to the provider function to get the model.
|
2767
|
+
|
2768
|
+
@param {string} modelId - The id of the model to return.
|
2769
|
+
|
2770
|
+
@returns {LanguageModel} The language model associated with the id
|
2771
|
+
|
2772
|
+
@throws {NoSuchModelError} If no such model exists.
|
2773
|
+
*/
|
2774
|
+
languageModel(modelId: string): LanguageModelV3;
|
2775
|
+
/**
|
2776
|
+
Returns the text embedding model with the given id.
|
2777
|
+
The model id is then passed to the provider function to get the model.
|
2778
|
+
|
2779
|
+
@param {string} modelId - The id of the model to return.
|
2780
|
+
|
2781
|
+
@returns {LanguageModel} The language model associated with the id
|
2782
|
+
|
2783
|
+
@throws {NoSuchModelError} If no such model exists.
|
2784
|
+
*/
|
2785
|
+
textEmbeddingModel(modelId: string): EmbeddingModelV3<string>;
|
2786
|
+
/**
|
2787
|
+
Returns the image model with the given id.
|
2788
|
+
The model id is then passed to the provider function to get the model.
|
2789
|
+
|
2790
|
+
@param {string} modelId - The id of the model to return.
|
2791
|
+
|
2792
|
+
@returns {ImageModel} The image model associated with the id
|
2793
|
+
*/
|
2794
|
+
imageModel(modelId: string): ImageModelV3;
|
2795
|
+
/**
|
2796
|
+
Returns the transcription model with the given id.
|
2797
|
+
The model id is then passed to the provider function to get the model.
|
2798
|
+
|
2799
|
+
@param {string} modelId - The id of the model to return.
|
2800
|
+
|
2801
|
+
@returns {TranscriptionModel} The transcription model associated with the id
|
2802
|
+
*/
|
2803
|
+
transcriptionModel?(modelId: string): TranscriptionModelV2;
|
2804
|
+
/**
|
2805
|
+
Returns the speech model with the given id.
|
2806
|
+
The model id is then passed to the provider function to get the model.
|
2807
|
+
|
2808
|
+
@param {string} modelId - The id of the model to return.
|
2809
|
+
|
2810
|
+
@returns {SpeechModel} The speech model associated with the id
|
2811
|
+
*/
|
2812
|
+
speechModel?(modelId: string): SpeechModelV2;
|
2813
|
+
}
|
2814
|
+
|
1770
2815
|
/**
|
1771
2816
|
* Provider for language, text embedding, and image generation models.
|
1772
2817
|
*/
|
@@ -1792,7 +2837,7 @@ interface ProviderV2 {
|
|
1792
2837
|
|
1793
2838
|
@throws {NoSuchModelError} If no such model exists.
|
1794
2839
|
*/
|
1795
|
-
textEmbeddingModel(modelId: string):
|
2840
|
+
textEmbeddingModel(modelId: string): EmbeddingModelV2<string>;
|
1796
2841
|
/**
|
1797
2842
|
Returns the image model with the given id.
|
1798
2843
|
The model id is then passed to the provider function to get the model.
|
@@ -1822,4 +2867,4 @@ interface ProviderV2 {
|
|
1822
2867
|
speechModel?(modelId: string): SpeechModelV2;
|
1823
2868
|
}
|
1824
2869
|
|
1825
|
-
export { AISDKError, APICallError, type EmbeddingModelV2, type EmbeddingModelV2Embedding, type EmbeddingModelV3, type EmbeddingModelV3Embedding, EmptyResponseBodyError, type ImageModelV2, type ImageModelV2CallOptions, type ImageModelV2CallWarning, type ImageModelV2ProviderMetadata, InvalidArgumentError, InvalidPromptError, InvalidResponseDataError, type JSONArray, type JSONObject, JSONParseError, type JSONValue, type LanguageModelV2, type LanguageModelV2CallOptions, type LanguageModelV2CallWarning, type LanguageModelV2Content, type LanguageModelV2DataContent, type LanguageModelV2File, type LanguageModelV2FilePart, type LanguageModelV2FinishReason, type LanguageModelV2FunctionTool, type LanguageModelV2Message, type LanguageModelV2Middleware, type LanguageModelV2Prompt, type LanguageModelV2ProviderDefinedTool, type LanguageModelV2Reasoning, type LanguageModelV2ReasoningPart, type LanguageModelV2ResponseMetadata, type LanguageModelV2Source, type LanguageModelV2StreamPart, type LanguageModelV2Text, type LanguageModelV2TextPart, type LanguageModelV2ToolCall, type LanguageModelV2ToolCallPart, type LanguageModelV2ToolChoice, type LanguageModelV2ToolResultOutput, type LanguageModelV2ToolResultPart, type LanguageModelV2Usage, LoadAPIKeyError, LoadSettingError, NoContentGeneratedError, NoSuchModelError, type ProviderV2, type SharedV2Headers, type SharedV2ProviderMetadata, type SharedV2ProviderOptions, type SpeechModelV2, type SpeechModelV2CallOptions, type SpeechModelV2CallWarning, TooManyEmbeddingValuesForCallError, type TranscriptionModelV2, type TranscriptionModelV2CallOptions, type TranscriptionModelV2CallWarning, TypeValidationError, UnsupportedFunctionalityError, getErrorMessage, isJSONArray, isJSONObject, isJSONValue };
|
2870
|
+
export { AISDKError, APICallError, type EmbeddingModelV2, type EmbeddingModelV2Embedding, type EmbeddingModelV3, type EmbeddingModelV3Embedding, EmptyResponseBodyError, type ImageModelV2, type ImageModelV2CallOptions, type ImageModelV2CallWarning, type ImageModelV2ProviderMetadata, type ImageModelV3, type ImageModelV3CallOptions, type ImageModelV3CallWarning, type ImageModelV3ProviderMetadata, InvalidArgumentError, InvalidPromptError, InvalidResponseDataError, type JSONArray, type JSONObject, JSONParseError, type JSONValue, type LanguageModelV2, type LanguageModelV2CallOptions, type LanguageModelV2CallWarning, type LanguageModelV2Content, type LanguageModelV2DataContent, type LanguageModelV2File, type LanguageModelV2FilePart, type LanguageModelV2FinishReason, type LanguageModelV2FunctionTool, type LanguageModelV2Message, type LanguageModelV2Middleware, type LanguageModelV2Prompt, type LanguageModelV2ProviderDefinedTool, type LanguageModelV2Reasoning, type LanguageModelV2ReasoningPart, type LanguageModelV2ResponseMetadata, type LanguageModelV2Source, type LanguageModelV2StreamPart, type LanguageModelV2Text, type LanguageModelV2TextPart, type LanguageModelV2ToolCall, type LanguageModelV2ToolCallPart, type LanguageModelV2ToolChoice, type LanguageModelV2ToolResultOutput, type LanguageModelV2ToolResultPart, type LanguageModelV2Usage, type LanguageModelV3, type LanguageModelV3CallOptions, type LanguageModelV3CallWarning, type LanguageModelV3Content, type LanguageModelV3DataContent, type LanguageModelV3File, type LanguageModelV3FilePart, type LanguageModelV3FinishReason, type LanguageModelV3FunctionTool, type LanguageModelV3Message, type LanguageModelV3Middleware, type LanguageModelV3Prompt, type LanguageModelV3ProviderDefinedTool, type LanguageModelV3Reasoning, type LanguageModelV3ReasoningPart, type LanguageModelV3ResponseMetadata, type LanguageModelV3Source, type LanguageModelV3StreamPart, type LanguageModelV3Text, type LanguageModelV3TextPart, type LanguageModelV3ToolCall, type LanguageModelV3ToolCallPart, type LanguageModelV3ToolChoice, type LanguageModelV3ToolResult, type LanguageModelV3ToolResultOutput, type LanguageModelV3ToolResultPart, type LanguageModelV3Usage, LoadAPIKeyError, LoadSettingError, NoContentGeneratedError, NoSuchModelError, type ProviderV2, type ProviderV3, type SharedV2Headers, type SharedV2ProviderMetadata, type SharedV2ProviderOptions, type SpeechModelV2, type SpeechModelV2CallOptions, type SpeechModelV2CallWarning, TooManyEmbeddingValuesForCallError, type TranscriptionModelV2, type TranscriptionModelV2CallOptions, type TranscriptionModelV2CallWarning, TypeValidationError, UnsupportedFunctionalityError, getErrorMessage, isJSONArray, isJSONObject, isJSONValue };
|