ai 3.3.16 → 3.3.18
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.d.mts +218 -269
- package/dist/index.d.ts +218 -269
- package/dist/index.js +396 -275
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +393 -267
- package/dist/index.mjs.map +1 -1
- package/package.json +8 -8
package/dist/index.d.ts
CHANGED
@@ -1,8 +1,8 @@
|
|
1
1
|
import { Schema, DeepPartial, Attachment, JSONValue as JSONValue$1, CreateMessage, FunctionCall as FunctionCall$1, AssistantMessage, DataMessage } from '@ai-sdk/ui-utils';
|
2
2
|
export { AssistantMessage, AssistantStatus, ChatRequest, ChatRequestOptions, CreateMessage, DataMessage, DeepPartial, Function, FunctionCall, FunctionCallHandler, IdGenerator, JSONValue, Message, RequestOptions, Schema, StreamPart, Tool, ToolCall, ToolCallHandler, ToolChoice, ToolInvocation, UseAssistantOptions, formatStreamPart, jsonSchema, parseComplexResponse, parseStreamPart, readDataStream } from '@ai-sdk/ui-utils';
|
3
|
-
import { AttributeValue
|
4
|
-
import { EmbeddingModelV1, EmbeddingModelV1Embedding, LanguageModelV1, LanguageModelV1FinishReason, LanguageModelV1LogProbs, LanguageModelV1CallWarning, LanguageModelV1ProviderMetadata, JSONValue,
|
5
|
-
export { AISDKError, APICallError, EmptyResponseBodyError, InvalidPromptError, InvalidResponseDataError, JSONParseError, LoadAPIKeyError, TypeValidationError, UnsupportedFunctionalityError } from '@ai-sdk/provider';
|
3
|
+
import { AttributeValue } from '@opentelemetry/api';
|
4
|
+
import { EmbeddingModelV1, EmbeddingModelV1Embedding, LanguageModelV1, LanguageModelV1FinishReason, LanguageModelV1LogProbs, LanguageModelV1CallWarning, LanguageModelV1ProviderMetadata, JSONValue, NoSuchModelError, AISDKError } from '@ai-sdk/provider';
|
5
|
+
export { AISDKError, APICallError, EmptyResponseBodyError, InvalidPromptError, InvalidResponseDataError, JSONParseError, LoadAPIKeyError, NoContentGeneratedError, NoSuchModelError, TypeValidationError, UnsupportedFunctionalityError } from '@ai-sdk/provider';
|
6
6
|
import { z } from 'zod';
|
7
7
|
import { ServerResponse } from 'http';
|
8
8
|
import { ServerResponse as ServerResponse$1 } from 'node:http';
|
@@ -115,6 +115,34 @@ type CoreToolChoice<TOOLS extends Record<string, unknown>> = 'auto' | 'none' | '
|
|
115
115
|
toolName: keyof TOOLS;
|
116
116
|
};
|
117
117
|
|
118
|
+
/**
|
119
|
+
* Provider for language and text embedding models.
|
120
|
+
*/
|
121
|
+
type Provider = {
|
122
|
+
/**
|
123
|
+
Returns the language model with the given id.
|
124
|
+
The model id is then passed to the provider function to get the model.
|
125
|
+
|
126
|
+
@param {string} id - The id of the model to return.
|
127
|
+
|
128
|
+
@returns {LanguageModel} The language model associated with the id
|
129
|
+
|
130
|
+
@throws {NoSuchModelError} If no such model exists.
|
131
|
+
*/
|
132
|
+
languageModel(modelId: string): LanguageModel;
|
133
|
+
/**
|
134
|
+
Returns the text embedding model with the given id.
|
135
|
+
The model id is then passed to the provider function to get the model.
|
136
|
+
|
137
|
+
@param {string} id - The id of the model to return.
|
138
|
+
|
139
|
+
@returns {LanguageModel} The language model associated with the id
|
140
|
+
|
141
|
+
@throws {NoSuchModelError} If no such model exists.
|
142
|
+
*/
|
143
|
+
textEmbeddingModel(modelId: string): EmbeddingModel<string>;
|
144
|
+
};
|
145
|
+
|
118
146
|
/**
|
119
147
|
Additional provider-specific metadata. They are passed through
|
120
148
|
to the provider from the AI SDK and enable provider-specific
|
@@ -595,7 +623,7 @@ This function does not stream the output. If you want to stream the output, use
|
|
595
623
|
@returns
|
596
624
|
A result object that contains the generated object, the finish reason, the token usage, and additional information.
|
597
625
|
*/
|
598
|
-
declare function generateObject<
|
626
|
+
declare function generateObject<OBJECT>(options: Omit<CallSettings, 'stopSequences'> & Prompt & {
|
599
627
|
output?: 'object' | undefined;
|
600
628
|
/**
|
601
629
|
The language model to use.
|
@@ -604,7 +632,7 @@ The language model to use.
|
|
604
632
|
/**
|
605
633
|
The schema of the object that the model should generate.
|
606
634
|
*/
|
607
|
-
schema: z.Schema<
|
635
|
+
schema: z.Schema<OBJECT, z.ZodTypeDef, any> | Schema<OBJECT>;
|
608
636
|
/**
|
609
637
|
Optional name of the output that should be generated.
|
610
638
|
Used by some providers for additional LLM guidance, e.g.
|
@@ -635,7 +663,56 @@ Default and recommended: 'auto' (best mode for the model).
|
|
635
663
|
Optional telemetry configuration (experimental).
|
636
664
|
*/
|
637
665
|
experimental_telemetry?: TelemetrySettings;
|
638
|
-
}): Promise<
|
666
|
+
}): Promise<GenerateObjectResult<OBJECT>>;
|
667
|
+
/**
|
668
|
+
Generate an array with structured, typed elements for a given prompt and element schema using a language model.
|
669
|
+
|
670
|
+
This function does not stream the output. If you want to stream the output, use `streamObject` instead.
|
671
|
+
|
672
|
+
@return
|
673
|
+
A result object that contains the generated object, the finish reason, the token usage, and additional information.
|
674
|
+
*/
|
675
|
+
declare function generateObject<ELEMENT>(options: Omit<CallSettings, 'stopSequences'> & Prompt & {
|
676
|
+
output: 'array';
|
677
|
+
/**
|
678
|
+
The language model to use.
|
679
|
+
*/
|
680
|
+
model: LanguageModel;
|
681
|
+
/**
|
682
|
+
The element schema of the array that the model should generate.
|
683
|
+
*/
|
684
|
+
schema: z.Schema<ELEMENT, z.ZodTypeDef, any> | Schema<ELEMENT>;
|
685
|
+
/**
|
686
|
+
Optional name of the array that should be generated.
|
687
|
+
Used by some providers for additional LLM guidance, e.g.
|
688
|
+
via tool or schema name.
|
689
|
+
*/
|
690
|
+
schemaName?: string;
|
691
|
+
/**
|
692
|
+
Optional description of the array that should be generated.
|
693
|
+
Used by some providers for additional LLM guidance, e.g.
|
694
|
+
via tool or schema description.
|
695
|
+
*/
|
696
|
+
schemaDescription?: string;
|
697
|
+
/**
|
698
|
+
The mode to use for object generation.
|
699
|
+
|
700
|
+
The schema is converted in a JSON schema and used in one of the following ways
|
701
|
+
|
702
|
+
- 'auto': The provider will choose the best mode for the model.
|
703
|
+
- 'tool': A tool with the JSON schema as parameters is is provided and the provider is instructed to use it.
|
704
|
+
- 'json': The JSON schema and an instruction is injected into the prompt. If the provider supports JSON mode, it is enabled. If the provider supports JSON grammars, the grammar is used.
|
705
|
+
|
706
|
+
Please note that most providers do not support all modes.
|
707
|
+
|
708
|
+
Default and recommended: 'auto' (best mode for the model).
|
709
|
+
*/
|
710
|
+
mode?: 'auto' | 'json' | 'tool';
|
711
|
+
/**
|
712
|
+
Optional telemetry configuration (experimental).
|
713
|
+
*/
|
714
|
+
experimental_telemetry?: TelemetrySettings;
|
715
|
+
}): Promise<GenerateObjectResult<Array<ELEMENT>>>;
|
639
716
|
/**
|
640
717
|
Generate JSON with any schema for a given prompt using a language model.
|
641
718
|
|
@@ -658,26 +735,7 @@ The mode to use for object generation. Must be "json" for no-schema output.
|
|
658
735
|
Optional telemetry configuration (experimental).
|
659
736
|
*/
|
660
737
|
experimental_telemetry?: TelemetrySettings;
|
661
|
-
}): Promise<
|
662
|
-
declare class DefaultGenerateObjectResult<T> implements GenerateObjectResult<T> {
|
663
|
-
readonly object: GenerateObjectResult<T>['object'];
|
664
|
-
readonly finishReason: GenerateObjectResult<T>['finishReason'];
|
665
|
-
readonly usage: GenerateObjectResult<T>['usage'];
|
666
|
-
readonly warnings: GenerateObjectResult<T>['warnings'];
|
667
|
-
readonly rawResponse: GenerateObjectResult<T>['rawResponse'];
|
668
|
-
readonly logprobs: GenerateObjectResult<T>['logprobs'];
|
669
|
-
readonly experimental_providerMetadata: GenerateObjectResult<T>['experimental_providerMetadata'];
|
670
|
-
constructor(options: {
|
671
|
-
object: GenerateObjectResult<T>['object'];
|
672
|
-
finishReason: GenerateObjectResult<T>['finishReason'];
|
673
|
-
usage: GenerateObjectResult<T>['usage'];
|
674
|
-
warnings: GenerateObjectResult<T>['warnings'];
|
675
|
-
rawResponse: GenerateObjectResult<T>['rawResponse'];
|
676
|
-
logprobs: GenerateObjectResult<T>['logprobs'];
|
677
|
-
providerMetadata: GenerateObjectResult<T>['experimental_providerMetadata'];
|
678
|
-
});
|
679
|
-
toJsonResponse(init?: ResponseInit): Response;
|
680
|
-
}
|
738
|
+
}): Promise<GenerateObjectResult<JSONValue>>;
|
681
739
|
/**
|
682
740
|
* @deprecated Use `generateObject` instead.
|
683
741
|
*/
|
@@ -688,7 +746,7 @@ type AsyncIterableStream<T> = AsyncIterable<T> & ReadableStream<T>;
|
|
688
746
|
/**
|
689
747
|
The result of a `streamObject` call that contains the partial object stream and additional information.
|
690
748
|
*/
|
691
|
-
interface StreamObjectResult<
|
749
|
+
interface StreamObjectResult<PARTIAL, RESULT, ELEMENT_STREAM> {
|
692
750
|
/**
|
693
751
|
Warnings from the model provider (e.g. unsupported settings)
|
694
752
|
*/
|
@@ -715,14 +773,18 @@ interface StreamObjectResult<T> {
|
|
715
773
|
/**
|
716
774
|
The generated object (typed according to the schema). Resolved when the response is finished.
|
717
775
|
*/
|
718
|
-
readonly object: Promise<
|
776
|
+
readonly object: Promise<RESULT>;
|
719
777
|
/**
|
720
778
|
Stream of partial objects. It gets more complete as the stream progresses.
|
721
779
|
|
722
780
|
Note that the partial object is not validated.
|
723
781
|
If you want to be certain that the actual content matches your schema, you need to implement your own validation for partial results.
|
724
782
|
*/
|
725
|
-
readonly partialObjectStream: AsyncIterableStream<
|
783
|
+
readonly partialObjectStream: AsyncIterableStream<PARTIAL>;
|
784
|
+
/**
|
785
|
+
* Stream over complete array elements. Only available if the output strategy is set to `array`.
|
786
|
+
*/
|
787
|
+
readonly elementStream: ELEMENT_STREAM;
|
726
788
|
/**
|
727
789
|
Text stream of the JSON representation of the generated object. It contains text chunks.
|
728
790
|
When the stream is finished, the object is valid JSON that can be parsed.
|
@@ -732,7 +794,7 @@ interface StreamObjectResult<T> {
|
|
732
794
|
Stream of different types of events, including partial objects, errors, and finish events.
|
733
795
|
Only errors that stop the stream, such as network errors, are thrown.
|
734
796
|
*/
|
735
|
-
readonly fullStream: AsyncIterableStream<ObjectStreamPart<
|
797
|
+
readonly fullStream: AsyncIterableStream<ObjectStreamPart<PARTIAL>>;
|
736
798
|
/**
|
737
799
|
Writes text delta output to a Node.js response-like object.
|
738
800
|
It sets a `Content-Type` header to `text/plain; charset=utf-8` and
|
@@ -769,14 +831,47 @@ type ObjectStreamInputPart = {
|
|
769
831
|
};
|
770
832
|
providerMetadata?: ProviderMetadata;
|
771
833
|
};
|
772
|
-
type ObjectStreamPart<
|
834
|
+
type ObjectStreamPart<PARTIAL> = ObjectStreamInputPart | {
|
773
835
|
type: 'object';
|
774
|
-
object:
|
836
|
+
object: PARTIAL;
|
775
837
|
} | {
|
776
838
|
type: 'text-delta';
|
777
839
|
textDelta: string;
|
778
840
|
};
|
779
841
|
|
842
|
+
type OnFinishCallback<RESULT> = (event: {
|
843
|
+
/**
|
844
|
+
The token usage of the generated response.
|
845
|
+
*/
|
846
|
+
usage: CompletionTokenUsage$1;
|
847
|
+
/**
|
848
|
+
The generated object. Can be undefined if the final object does not match the schema.
|
849
|
+
*/
|
850
|
+
object: RESULT | undefined;
|
851
|
+
/**
|
852
|
+
Optional error object. This is e.g. a TypeValidationError when the final object does not match the schema.
|
853
|
+
*/
|
854
|
+
error: unknown | undefined;
|
855
|
+
/**
|
856
|
+
Optional raw response data.
|
857
|
+
*/
|
858
|
+
rawResponse?: {
|
859
|
+
/**
|
860
|
+
Response headers.
|
861
|
+
*/
|
862
|
+
headers?: Record<string, string>;
|
863
|
+
};
|
864
|
+
/**
|
865
|
+
Warnings from the model provider (e.g. unsupported settings).
|
866
|
+
*/
|
867
|
+
warnings?: CallWarning[];
|
868
|
+
/**
|
869
|
+
Additional provider-specific metadata. They are passed through
|
870
|
+
from the provider to the AI SDK and enable provider-specific
|
871
|
+
results that can be fully encapsulated in the provider.
|
872
|
+
*/
|
873
|
+
experimental_providerMetadata: ProviderMetadata | undefined;
|
874
|
+
}) => Promise<void> | void;
|
780
875
|
/**
|
781
876
|
Generate a structured, typed object for a given prompt and schema using a language model.
|
782
877
|
|
@@ -785,7 +880,8 @@ This function streams the output. If you do not want to stream the output, use `
|
|
785
880
|
@return
|
786
881
|
A result object for accessing the partial object stream and additional information.
|
787
882
|
*/
|
788
|
-
declare function streamObject<
|
883
|
+
declare function streamObject<OBJECT>(options: Omit<CallSettings, 'stopSequences'> & Prompt & {
|
884
|
+
output?: 'object' | undefined;
|
789
885
|
/**
|
790
886
|
The language model to use.
|
791
887
|
*/
|
@@ -793,7 +889,7 @@ The language model to use.
|
|
793
889
|
/**
|
794
890
|
The schema of the object that the model should generate.
|
795
891
|
*/
|
796
|
-
schema: z.Schema<
|
892
|
+
schema: z.Schema<OBJECT, z.ZodTypeDef, any> | Schema<OBJECT>;
|
797
893
|
/**
|
798
894
|
Optional name of the output that should be generated.
|
799
895
|
Used by some providers for additional LLM guidance, e.g.
|
@@ -827,40 +923,61 @@ Optional telemetry configuration (experimental).
|
|
827
923
|
/**
|
828
924
|
Callback that is called when the LLM response and the final object validation are finished.
|
829
925
|
*/
|
830
|
-
onFinish?:
|
831
|
-
|
832
|
-
|
926
|
+
onFinish?: OnFinishCallback<OBJECT>;
|
927
|
+
}): Promise<StreamObjectResult<DeepPartial<OBJECT>, OBJECT, never>>;
|
928
|
+
/**
|
929
|
+
Generate an array with structured, typed elements for a given prompt and element schema using a language model.
|
930
|
+
|
931
|
+
This function streams the output. If you do not want to stream the output, use `generateObject` instead.
|
932
|
+
|
933
|
+
@return
|
934
|
+
A result object for accessing the partial object stream and additional information.
|
935
|
+
*/
|
936
|
+
declare function streamObject<ELEMENT>(options: Omit<CallSettings, 'stopSequences'> & Prompt & {
|
937
|
+
output: 'array';
|
938
|
+
/**
|
939
|
+
The language model to use.
|
940
|
+
*/
|
941
|
+
model: LanguageModel;
|
942
|
+
/**
|
943
|
+
The element schema of the array that the model should generate.
|
833
944
|
*/
|
834
|
-
|
835
|
-
|
836
|
-
|
945
|
+
schema: z.Schema<ELEMENT, z.ZodTypeDef, any> | Schema<ELEMENT>;
|
946
|
+
/**
|
947
|
+
Optional name of the array that should be generated.
|
948
|
+
Used by some providers for additional LLM guidance, e.g.
|
949
|
+
via tool or schema name.
|
837
950
|
*/
|
838
|
-
|
839
|
-
|
840
|
-
Optional
|
951
|
+
schemaName?: string;
|
952
|
+
/**
|
953
|
+
Optional description of the array that should be generated.
|
954
|
+
Used by some providers for additional LLM guidance, e.g.
|
955
|
+
via tool or schema description.
|
956
|
+
*/
|
957
|
+
schemaDescription?: string;
|
958
|
+
/**
|
959
|
+
The mode to use for object generation.
|
960
|
+
|
961
|
+
The schema is converted in a JSON schema and used in one of the following ways
|
962
|
+
|
963
|
+
- 'auto': The provider will choose the best mode for the model.
|
964
|
+
- 'tool': A tool with the JSON schema as parameters is is provided and the provider is instructed to use it.
|
965
|
+
- 'json': The JSON schema and an instruction is injected into the prompt. If the provider supports JSON mode, it is enabled. If the provider supports JSON grammars, the grammar is used.
|
966
|
+
|
967
|
+
Please note that most providers do not support all modes.
|
968
|
+
|
969
|
+
Default and recommended: 'auto' (best mode for the model).
|
841
970
|
*/
|
842
|
-
|
843
|
-
|
844
|
-
Optional
|
971
|
+
mode?: 'auto' | 'json' | 'tool';
|
972
|
+
/**
|
973
|
+
Optional telemetry configuration (experimental).
|
845
974
|
*/
|
846
|
-
|
847
|
-
|
848
|
-
|
849
|
-
*/
|
850
|
-
headers?: Record<string, string>;
|
851
|
-
};
|
852
|
-
/**
|
853
|
-
Warnings from the model provider (e.g. unsupported settings).
|
854
|
-
*/
|
855
|
-
warnings?: CallWarning[];
|
856
|
-
/**
|
857
|
-
Additional provider-specific metadata. They are passed through
|
858
|
-
from the provider to the AI SDK and enable provider-specific
|
859
|
-
results that can be fully encapsulated in the provider.
|
975
|
+
experimental_telemetry?: TelemetrySettings;
|
976
|
+
/**
|
977
|
+
Callback that is called when the LLM response and the final object validation are finished.
|
860
978
|
*/
|
861
|
-
|
862
|
-
|
863
|
-
}): Promise<DefaultStreamObjectResult<T>>;
|
979
|
+
onFinish?: OnFinishCallback<Array<ELEMENT>>;
|
980
|
+
}): Promise<StreamObjectResult<Array<ELEMENT>, Array<ELEMENT>, AsyncIterableStream<ELEMENT>>>;
|
864
981
|
/**
|
865
982
|
Generate JSON with any schema for a given prompt using a language model.
|
866
983
|
|
@@ -886,82 +1003,22 @@ Optional telemetry configuration (experimental).
|
|
886
1003
|
/**
|
887
1004
|
Callback that is called when the LLM response and the final object validation are finished.
|
888
1005
|
*/
|
889
|
-
onFinish?:
|
890
|
-
|
891
|
-
The token usage of the generated response.
|
892
|
-
*/
|
893
|
-
usage: CompletionTokenUsage$1;
|
894
|
-
/**
|
895
|
-
The generated object (typed according to the schema). Can be undefined if the final object does not match the schema.
|
896
|
-
*/
|
897
|
-
object: JSONValue | undefined;
|
898
|
-
/**
|
899
|
-
Optional error object. This is e.g. a TypeValidationError when the final object does not match the schema.
|
900
|
-
*/
|
901
|
-
error: unknown | undefined;
|
902
|
-
/**
|
903
|
-
Optional raw response data.
|
904
|
-
*/
|
905
|
-
rawResponse?: {
|
906
|
-
/**
|
907
|
-
Response headers.
|
908
|
-
*/
|
909
|
-
headers?: Record<string, string>;
|
910
|
-
};
|
911
|
-
/**
|
912
|
-
Warnings from the model provider (e.g. unsupported settings).
|
913
|
-
*/
|
914
|
-
warnings?: CallWarning[];
|
915
|
-
/**
|
916
|
-
Additional provider-specific metadata. They are passed through
|
917
|
-
from the provider to the AI SDK and enable provider-specific
|
918
|
-
results that can be fully encapsulated in the provider.
|
919
|
-
*/
|
920
|
-
experimental_providerMetadata: ProviderMetadata | undefined;
|
921
|
-
}) => Promise<void> | void;
|
922
|
-
}): Promise<DefaultStreamObjectResult<JSONValue>>;
|
923
|
-
declare class DefaultStreamObjectResult<T> implements StreamObjectResult<T> {
|
924
|
-
private readonly originalStream;
|
925
|
-
private readonly objectPromise;
|
926
|
-
readonly warnings: StreamObjectResult<T>['warnings'];
|
927
|
-
readonly usage: StreamObjectResult<T>['usage'];
|
928
|
-
readonly experimental_providerMetadata: StreamObjectResult<T>['experimental_providerMetadata'];
|
929
|
-
readonly rawResponse: StreamObjectResult<T>['rawResponse'];
|
930
|
-
constructor({ stream, warnings, rawResponse, schema, onFinish, rootSpan, doStreamSpan, telemetry, startTimestamp, }: {
|
931
|
-
stream: ReadableStream<string | Omit<LanguageModelV1StreamPart, 'text-delta'>>;
|
932
|
-
warnings: StreamObjectResult<T>['warnings'];
|
933
|
-
rawResponse?: StreamObjectResult<T>['rawResponse'];
|
934
|
-
schema: z.Schema<T, z.ZodTypeDef, any> | Schema<T>;
|
935
|
-
onFinish: Parameters<typeof streamObject<T>>[0]['onFinish'];
|
936
|
-
rootSpan: Span;
|
937
|
-
doStreamSpan: Span;
|
938
|
-
telemetry: TelemetrySettings | undefined;
|
939
|
-
startTimestamp: number;
|
940
|
-
});
|
941
|
-
get object(): Promise<T>;
|
942
|
-
get partialObjectStream(): AsyncIterableStream<DeepPartial<T>>;
|
943
|
-
get textStream(): AsyncIterableStream<string>;
|
944
|
-
get fullStream(): AsyncIterableStream<ObjectStreamPart<T>>;
|
945
|
-
pipeTextStreamToResponse(response: ServerResponse, init?: {
|
946
|
-
headers?: Record<string, string>;
|
947
|
-
status?: number;
|
948
|
-
}): void;
|
949
|
-
toTextStreamResponse(init?: ResponseInit): Response;
|
950
|
-
}
|
1006
|
+
onFinish?: OnFinishCallback<JSONValue>;
|
1007
|
+
}): Promise<StreamObjectResult<JSONValue, JSONValue, never>>;
|
951
1008
|
/**
|
952
1009
|
* @deprecated Use `streamObject` instead.
|
953
1010
|
*/
|
954
1011
|
declare const experimental_streamObject: typeof streamObject;
|
955
1012
|
|
956
|
-
type Parameters
|
957
|
-
type inferParameters<PARAMETERS extends Parameters
|
1013
|
+
type Parameters = z.ZodTypeAny | Schema<any>;
|
1014
|
+
type inferParameters<PARAMETERS extends Parameters> = PARAMETERS extends Schema<any> ? PARAMETERS['_type'] : PARAMETERS extends z.ZodTypeAny ? z.infer<PARAMETERS> : never;
|
958
1015
|
/**
|
959
1016
|
A tool contains the description and the schema of the input that the tool expects.
|
960
1017
|
This enables the language model to generate the input.
|
961
1018
|
|
962
1019
|
The tool can also contain an optional execute function for the actual execution function of the tool.
|
963
1020
|
*/
|
964
|
-
interface CoreTool<PARAMETERS extends Parameters
|
1021
|
+
interface CoreTool<PARAMETERS extends Parameters = any, RESULT = any> {
|
965
1022
|
/**
|
966
1023
|
An optional description of what the tool does. Will be used by the language model to decide whether to use the tool.
|
967
1024
|
*/
|
@@ -981,12 +1038,12 @@ interface CoreTool<PARAMETERS extends Parameters$1 = any, RESULT = any> {
|
|
981
1038
|
/**
|
982
1039
|
Helper function for inferring the execute args of a tool.
|
983
1040
|
*/
|
984
|
-
declare function tool<PARAMETERS extends Parameters
|
1041
|
+
declare function tool<PARAMETERS extends Parameters, RESULT>(tool: CoreTool<PARAMETERS, RESULT> & {
|
985
1042
|
execute: (args: inferParameters<PARAMETERS>) => PromiseLike<RESULT>;
|
986
1043
|
}): CoreTool<PARAMETERS, RESULT> & {
|
987
1044
|
execute: (args: inferParameters<PARAMETERS>) => PromiseLike<RESULT>;
|
988
1045
|
};
|
989
|
-
declare function tool<PARAMETERS extends Parameters
|
1046
|
+
declare function tool<PARAMETERS extends Parameters, RESULT>(tool: CoreTool<PARAMETERS, RESULT> & {
|
990
1047
|
execute?: undefined;
|
991
1048
|
}): CoreTool<PARAMETERS, RESULT> & {
|
992
1049
|
execute: undefined;
|
@@ -1421,6 +1478,7 @@ interface StreamTextResult<TOOLS extends Record<string, CoreTool>> {
|
|
1421
1478
|
toDataStreamResponse(options?: ResponseInit | {
|
1422
1479
|
init?: ResponseInit;
|
1423
1480
|
data?: StreamData;
|
1481
|
+
getErrorMessage?: (error: unknown) => string;
|
1424
1482
|
}): Response;
|
1425
1483
|
/**
|
1426
1484
|
Creates a simple text stream response.
|
@@ -1580,127 +1638,37 @@ Callback that is called when the LLM response and all request tool executions
|
|
1580
1638
|
*/
|
1581
1639
|
readonly experimental_providerMetadata: ProviderMetadata | undefined;
|
1582
1640
|
}) => Promise<void> | void;
|
1583
|
-
}): Promise<
|
1584
|
-
declare class DefaultStreamTextResult<TOOLS extends Record<string, CoreTool>> implements StreamTextResult<TOOLS> {
|
1585
|
-
private originalStream;
|
1586
|
-
readonly warnings: StreamTextResult<TOOLS>['warnings'];
|
1587
|
-
readonly usage: StreamTextResult<TOOLS>['usage'];
|
1588
|
-
readonly finishReason: StreamTextResult<TOOLS>['finishReason'];
|
1589
|
-
readonly experimental_providerMetadata: StreamTextResult<TOOLS>['experimental_providerMetadata'];
|
1590
|
-
readonly text: StreamTextResult<TOOLS>['text'];
|
1591
|
-
readonly toolCalls: StreamTextResult<TOOLS>['toolCalls'];
|
1592
|
-
readonly toolResults: StreamTextResult<TOOLS>['toolResults'];
|
1593
|
-
readonly rawResponse: StreamTextResult<TOOLS>['rawResponse'];
|
1594
|
-
constructor({ stream, warnings, rawResponse, onChunk, onFinish, rootSpan, doStreamSpan, telemetry, startTimestamp, }: {
|
1595
|
-
stream: ReadableStream<TextStreamPart<TOOLS>>;
|
1596
|
-
warnings: StreamTextResult<TOOLS>['warnings'];
|
1597
|
-
rawResponse: StreamTextResult<TOOLS>['rawResponse'];
|
1598
|
-
onChunk: Parameters<typeof streamText>[0]['onChunk'];
|
1599
|
-
onFinish: Parameters<typeof streamText>[0]['onFinish'];
|
1600
|
-
rootSpan: Span;
|
1601
|
-
doStreamSpan: Span;
|
1602
|
-
telemetry: TelemetrySettings | undefined;
|
1603
|
-
startTimestamp: number;
|
1604
|
-
});
|
1605
|
-
/**
|
1606
|
-
Split out a new stream from the original stream.
|
1607
|
-
The original stream is replaced to allow for further splitting,
|
1608
|
-
since we do not know how many times the stream will be split.
|
1609
|
-
|
1610
|
-
Note: this leads to buffering the stream content on the server.
|
1611
|
-
However, the LLM results are expected to be small enough to not cause issues.
|
1612
|
-
*/
|
1613
|
-
private teeStream;
|
1614
|
-
get textStream(): AsyncIterableStream<string>;
|
1615
|
-
get fullStream(): AsyncIterableStream<TextStreamPart<TOOLS>>;
|
1616
|
-
toAIStream(callbacks?: AIStreamCallbacksAndOptions): ReadableStream<Uint8Array>;
|
1617
|
-
private toDataStream;
|
1618
|
-
pipeAIStreamToResponse(response: ServerResponse$1, init?: {
|
1619
|
-
headers?: Record<string, string>;
|
1620
|
-
status?: number;
|
1621
|
-
}): void;
|
1622
|
-
pipeDataStreamToResponse(response: ServerResponse$1, init?: {
|
1623
|
-
headers?: Record<string, string>;
|
1624
|
-
status?: number;
|
1625
|
-
}): void;
|
1626
|
-
pipeTextStreamToResponse(response: ServerResponse$1, init?: {
|
1627
|
-
headers?: Record<string, string>;
|
1628
|
-
status?: number;
|
1629
|
-
}): void;
|
1630
|
-
toAIStreamResponse(options?: ResponseInit | {
|
1631
|
-
init?: ResponseInit;
|
1632
|
-
data?: StreamData;
|
1633
|
-
}): Response;
|
1634
|
-
toDataStreamResponse(options?: ResponseInit | {
|
1635
|
-
init?: ResponseInit;
|
1636
|
-
data?: StreamData;
|
1637
|
-
getErrorMessage?: (error: unknown) => string;
|
1638
|
-
}): Response;
|
1639
|
-
toTextStreamResponse(init?: ResponseInit): Response;
|
1640
|
-
}
|
1641
|
+
}): Promise<StreamTextResult<TOOLS>>;
|
1641
1642
|
/**
|
1642
1643
|
* @deprecated Use `streamText` instead.
|
1643
1644
|
*/
|
1644
1645
|
declare const experimental_streamText: typeof streamText;
|
1645
1646
|
|
1646
|
-
|
1647
|
-
|
1648
|
-
|
1649
|
-
|
1650
|
-
|
1651
|
-
|
1652
|
-
|
1653
|
-
|
1654
|
-
|
1655
|
-
|
1656
|
-
|
1657
|
-
|
1658
|
-
|
1659
|
-
|
1660
|
-
|
1661
|
-
|
1662
|
-
toJSON(): {
|
1663
|
-
name: string;
|
1664
|
-
message: string;
|
1665
|
-
stack: string | undefined;
|
1666
|
-
id: string;
|
1667
|
-
};
|
1668
|
-
}
|
1669
|
-
|
1670
|
-
declare const symbol$9: unique symbol;
|
1671
|
-
type ModelType = 'languageModel' | 'textEmbeddingModel';
|
1672
|
-
declare class NoSuchModelError extends AISDKError {
|
1673
|
-
private readonly [symbol$9];
|
1674
|
-
readonly modelId: string;
|
1675
|
-
readonly modelType: ModelType;
|
1676
|
-
constructor({ modelId, modelType, message, }: {
|
1677
|
-
modelId: string;
|
1678
|
-
modelType: ModelType;
|
1679
|
-
message?: string;
|
1680
|
-
});
|
1681
|
-
static isInstance(error: unknown): error is NoSuchModelError;
|
1682
|
-
/**
|
1683
|
-
* @deprecated use `isInstance` instead
|
1684
|
-
*/
|
1685
|
-
static isNoSuchModelError(error: unknown): error is NoSuchModelError;
|
1686
|
-
/**
|
1687
|
-
* @deprecated Do not use this method. It will be removed in the next major version.
|
1688
|
-
*/
|
1689
|
-
toJSON(): {
|
1690
|
-
name: string;
|
1691
|
-
message: string;
|
1692
|
-
stack: string | undefined;
|
1693
|
-
modelId: string;
|
1694
|
-
modelType: ModelType;
|
1695
|
-
};
|
1696
|
-
}
|
1647
|
+
/**
|
1648
|
+
* Creates a custom provider with specified language models, text embedding models, and an optional fallback provider.
|
1649
|
+
*
|
1650
|
+
* @param {Object} options - The options for creating the custom provider.
|
1651
|
+
* @param {Record<string, LanguageModelV1>} [options.languageModels] - A record of language models, where keys are model IDs and values are LanguageModelV1 instances.
|
1652
|
+
* @param {Record<string, EmbeddingModelV1<string>>} [options.textEmbeddingModels] - A record of text embedding models, where keys are model IDs and values are EmbeddingModelV1<string> instances.
|
1653
|
+
* @param {Provider} [options.fallbackProvider] - An optional fallback provider to use when a requested model is not found in the custom provider.
|
1654
|
+
* @returns {Provider} A Provider object with languageModel and textEmbeddingModel methods.
|
1655
|
+
*
|
1656
|
+
* @throws {NoSuchModelError} Throws when a requested model is not found and no fallback provider is available.
|
1657
|
+
*/
|
1658
|
+
declare function experimental_customProvider({ languageModels, textEmbeddingModels, fallbackProvider, }: {
|
1659
|
+
languageModels?: Record<string, LanguageModelV1>;
|
1660
|
+
textEmbeddingModels?: Record<string, EmbeddingModelV1<string>>;
|
1661
|
+
fallbackProvider?: Provider;
|
1662
|
+
}): Provider;
|
1697
1663
|
|
1698
1664
|
declare const symbol$8: unique symbol;
|
1699
|
-
declare class NoSuchProviderError extends
|
1665
|
+
declare class NoSuchProviderError extends NoSuchModelError {
|
1700
1666
|
private readonly [symbol$8];
|
1701
1667
|
readonly providerId: string;
|
1702
1668
|
readonly availableProviders: string[];
|
1703
|
-
constructor({ providerId, availableProviders, message, }: {
|
1669
|
+
constructor({ modelId, modelType, providerId, availableProviders, message, }: {
|
1670
|
+
modelId: string;
|
1671
|
+
modelType: 'languageModel' | 'textEmbeddingModel';
|
1704
1672
|
providerId: string;
|
1705
1673
|
availableProviders: string[];
|
1706
1674
|
message?: string;
|
@@ -1717,6 +1685,8 @@ declare class NoSuchProviderError extends AISDKError {
|
|
1717
1685
|
name: string;
|
1718
1686
|
message: string;
|
1719
1687
|
stack: string | undefined;
|
1688
|
+
modelId: string;
|
1689
|
+
modelType: "languageModel" | "textEmbeddingModel";
|
1720
1690
|
providerId: string;
|
1721
1691
|
availableProviders: string[];
|
1722
1692
|
};
|
@@ -1724,6 +1694,8 @@ declare class NoSuchProviderError extends AISDKError {
|
|
1724
1694
|
|
1725
1695
|
/**
|
1726
1696
|
* Provides for language and text embedding models.
|
1697
|
+
*
|
1698
|
+
* @deprecated Use `ProviderV1` instead.
|
1727
1699
|
*/
|
1728
1700
|
interface experimental_Provider {
|
1729
1701
|
/**
|
@@ -1768,33 +1740,10 @@ interface experimental_Provider {
|
|
1768
1740
|
|
1769
1741
|
/**
|
1770
1742
|
Registry for managing models. It enables getting a model with a string id.
|
1743
|
+
|
1744
|
+
@deprecated Use `experimental_Provider` instead.
|
1771
1745
|
*/
|
1772
|
-
type experimental_ProviderRegistry =
|
1773
|
-
/**
|
1774
|
-
Returns the language model with the given id in the format `providerId:modelId`.
|
1775
|
-
The model id is then passed to the provider function to get the model.
|
1776
|
-
|
1777
|
-
@param {string} id - The id of the model to return.
|
1778
|
-
|
1779
|
-
@throws {NoSuchModelError} If no model with the given id exists.
|
1780
|
-
@throws {NoSuchProviderError} If no provider with the given id exists.
|
1781
|
-
|
1782
|
-
@returns {LanguageModel} The language model associated with the id.
|
1783
|
-
*/
|
1784
|
-
languageModel(id: string): LanguageModel;
|
1785
|
-
/**
|
1786
|
-
Returns the text embedding model with the given id in the format `providerId:modelId`.
|
1787
|
-
The model id is then passed to the provider function to get the model.
|
1788
|
-
|
1789
|
-
@param {string} id - The id of the model to return.
|
1790
|
-
|
1791
|
-
@throws {NoSuchModelError} If no model with the given id exists.
|
1792
|
-
@throws {NoSuchProviderError} If no provider with the given id exists.
|
1793
|
-
|
1794
|
-
@returns {LanguageModel} The language model associated with the id.
|
1795
|
-
*/
|
1796
|
-
textEmbeddingModel(id: string): EmbeddingModel<string>;
|
1797
|
-
};
|
1746
|
+
type experimental_ProviderRegistry = Provider;
|
1798
1747
|
/**
|
1799
1748
|
* @deprecated Use `experimental_ProviderRegistry` instead.
|
1800
1749
|
*/
|
@@ -1802,7 +1751,7 @@ type experimental_ModelRegistry = experimental_ProviderRegistry;
|
|
1802
1751
|
/**
|
1803
1752
|
* Creates a registry for the given providers.
|
1804
1753
|
*/
|
1805
|
-
declare function experimental_createProviderRegistry(providers: Record<string, experimental_Provider>):
|
1754
|
+
declare function experimental_createProviderRegistry(providers: Record<string, experimental_Provider | Provider>): Provider;
|
1806
1755
|
/**
|
1807
1756
|
* @deprecated Use `experimental_createProviderRegistry` instead.
|
1808
1757
|
*/
|
@@ -2796,4 +2745,4 @@ declare const generateId: (size?: number) => string;
|
|
2796
2745
|
*/
|
2797
2746
|
declare const nanoid: (size?: number) => string;
|
2798
2747
|
|
2799
|
-
export { AIStream, AIStreamCallbacksAndOptions, AIStreamParser, AIStreamParserOptions, AWSBedrockAnthropicMessagesStream, AWSBedrockAnthropicStream, AWSBedrockCohereStream, AWSBedrockLlama2Stream, AWSBedrockStream, AnthropicStream, AssistantContent, AssistantResponse, CallWarning, CohereStream, CompletionTokenUsage, CompletionUsage, CoreAssistantMessage, CoreMessage, CoreSystemMessage, CoreTool, CoreToolChoice, CoreToolMessage, CoreUserMessage, DataContent, DownloadError, EmbedManyResult, EmbedResult, Embedding, EmbeddingModel, EmbeddingTokenUsage, ExperimentalAssistantMessage, ExperimentalMessage, ExperimentalTool, ExperimentalToolMessage, ExperimentalUserMessage, FinishReason, FunctionCallPayload, GenerateObjectResult, GenerateTextResult, GoogleGenerativeAIStream, HuggingFaceStream, ImagePart, InkeepAIStreamCallbacksAndOptions, InkeepChatResultCallbacks, InkeepOnFinalMetadata, InkeepStream, InvalidArgumentError, InvalidDataContentError, InvalidMessageRoleError,
|
2748
|
+
export { AIStream, AIStreamCallbacksAndOptions, AIStreamParser, AIStreamParserOptions, AWSBedrockAnthropicMessagesStream, AWSBedrockAnthropicStream, AWSBedrockCohereStream, AWSBedrockLlama2Stream, AWSBedrockStream, AnthropicStream, AssistantContent, AssistantResponse, CallWarning, CohereStream, CompletionTokenUsage, CompletionUsage, CoreAssistantMessage, CoreMessage, CoreSystemMessage, CoreTool, CoreToolChoice, CoreToolMessage, CoreUserMessage, DataContent, DownloadError, EmbedManyResult, EmbedResult, Embedding, EmbeddingModel, EmbeddingTokenUsage, ExperimentalAssistantMessage, ExperimentalMessage, ExperimentalTool, ExperimentalToolMessage, ExperimentalUserMessage, FinishReason, FunctionCallPayload, GenerateObjectResult, GenerateTextResult, GoogleGenerativeAIStream, HuggingFaceStream, ImagePart, InkeepAIStreamCallbacksAndOptions, InkeepChatResultCallbacks, InkeepOnFinalMetadata, InkeepStream, InvalidArgumentError, InvalidDataContentError, InvalidMessageRoleError, InvalidToolArgumentsError, langchainAdapter as LangChainAdapter, LangChainStream, LanguageModel, LogProbs, MistralStream, NoObjectGeneratedError, NoSuchProviderError, NoSuchToolError, ObjectStreamInputPart, ObjectStreamPart, OpenAIStream, OpenAIStreamCallbacks, Provider, ProviderMetadata, ReplicateStream, RetryError, StreamData, StreamObjectResult, StreamTextResult, StreamingTextResponse, TextPart$1 as TextPart, TextStreamPart, TokenUsage, ToolCallPart, ToolCallPayload, ToolContent, ToolResultPart, UserContent, convertToCoreMessages, cosineSimilarity, createCallbacksTransformer, createEventStreamTransformer, createStreamDataTransformer, embed, embedMany, experimental_AssistantResponse, experimental_ModelRegistry, experimental_Provider, experimental_ProviderRegistry, experimental_StreamData, experimental_createModelRegistry, experimental_createProviderRegistry, experimental_customProvider, experimental_generateObject, experimental_generateText, experimental_streamObject, experimental_streamText, generateId, generateObject, generateText, nanoid, readableFromAsyncIterable, streamObject, streamText, streamToResponse, tool, trimStartOfStreamHelper };
|