@ai-sdk/provider-utils 5.0.34 → 5.0.36
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 +14 -0
- package/dist/index.d.ts +220 -151
- package/dist/index.js +447 -172
- package/dist/index.js.map +1 -1
- package/package.json +3 -3
- package/src/convert-inline-file-data-to-uint8-array.ts +13 -1
- package/src/delete-from-api.ts +102 -0
- package/src/index.ts +2 -0
- package/src/post-multipart-stream-to-api.ts +268 -0
- package/src/response-handler.ts +26 -0
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,19 @@
|
|
|
1
1
|
# @ai-sdk/provider-utils
|
|
2
2
|
|
|
3
|
+
## 5.0.36
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- 6bcc0f8: Update Undici to a version patched for CVE-2026-13697.
|
|
8
|
+
|
|
9
|
+
## 5.0.35
|
|
10
|
+
|
|
11
|
+
### Patch Changes
|
|
12
|
+
|
|
13
|
+
- 5190b67: feat(provider): extend the FilesV4 interface with optional `getFileMetadata`, `downloadFile` (streaming), and `deleteFile` operations, plus `abortSignal`/`headers` call options and a `{ type: 'stream' }` upload data variant; upload results now expose `byteSize`, `createdAt`, and `expiresAt` (also surfaced by the core `uploadFile()` helper, which now forwards `abortSignal`/`headers`); add `postMultipartStreamToApi` (streaming multipart uploads with deterministic part ordering and failure-path stream teardown), `deleteFromApi`, and `createBinaryStreamResponseHandler` to provider-utils
|
|
14
|
+
- Updated dependencies [5190b67]
|
|
15
|
+
- @ai-sdk/provider@4.0.10
|
|
16
|
+
|
|
3
17
|
## 5.0.34
|
|
4
18
|
|
|
5
19
|
### Patch Changes
|
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { SharedV4FileDataUrl, SharedV4FileDataReference, SharedV4FileDataText, SharedV4ProviderOptions, SharedV4ProviderReference, JSONValue, ImageModelV4File, LanguageModelV4ResponseMetadata, LanguageModelV4Usage, LanguageModelV4FunctionTool, LanguageModelV4ProviderTool,
|
|
1
|
+
import { SharedV4FileDataUrl, SharedV4FileDataReference, SharedV4FileDataText, SharedV4ProviderOptions, SharedV4ProviderReference, JSONValue, ImageModelV4File, LanguageModelV4ResponseMetadata, LanguageModelV4Usage, LanguageModelV4FunctionTool, LanguageModelV4ProviderTool, JSONSchema7, JSONParseError, TypeValidationError, APICallError, AISDKError, LanguageModelV4Prompt, LanguageModelV4CallOptions, SharedV4Warning, Experimental_BatchV4Status, JSONObject, LanguageModelV4FilePart, LanguageModelV4StreamPart, SharedV4ProviderMetadata, Experimental_TranscriptionModelV4StreamPart, TypeValidationContext } from '@ai-sdk/provider';
|
|
2
2
|
export { getErrorMessage } from '@ai-sdk/provider';
|
|
3
3
|
import { StandardSchemaV1, StandardJSONSchemaV1 } from '@standard-schema/spec';
|
|
4
4
|
export * from '@standard-schema/spec';
|
|
@@ -632,8 +632,14 @@ type InlineFileData = Extract<FilePart['data'], {
|
|
|
632
632
|
* - `{ type: 'data', data: Uint8Array | Buffer }` → returned as-is
|
|
633
633
|
* - `{ type: 'data', data: ArrayBuffer }` → wrapped in a `Uint8Array`
|
|
634
634
|
* - `{ type: 'data', data: string }` → decoded as base64
|
|
635
|
+
*
|
|
636
|
+
* `{ type: 'stream' }` data is rejected: providers without streaming upload
|
|
637
|
+
* support funnel here and surface a clear `UnsupportedFunctionalityError`.
|
|
635
638
|
*/
|
|
636
|
-
declare function convertInlineFileDataToUint8Array(data: InlineFileData
|
|
639
|
+
declare function convertInlineFileDataToUint8Array(data: InlineFileData | {
|
|
640
|
+
type: 'stream';
|
|
641
|
+
stream: ReadableStream<Uint8Array>;
|
|
642
|
+
}): Uint8Array;
|
|
637
643
|
|
|
638
644
|
/**
|
|
639
645
|
* Convert an ImageModelV4File to a URL or data URI string.
|
|
@@ -781,6 +787,178 @@ declare class DelayedPromise<T> {
|
|
|
781
787
|
isPending(): boolean;
|
|
782
788
|
}
|
|
783
789
|
|
|
790
|
+
/**
|
|
791
|
+
* Fetch function type (standardizes the version of fetch used).
|
|
792
|
+
*/
|
|
793
|
+
type FetchFunction = typeof globalThis.fetch;
|
|
794
|
+
|
|
795
|
+
/**
|
|
796
|
+
* Used to mark schemas so we can support both Zod and custom schemas.
|
|
797
|
+
*/
|
|
798
|
+
declare const schemaSymbol: unique symbol;
|
|
799
|
+
type ValidationResult<OBJECT> = {
|
|
800
|
+
success: true;
|
|
801
|
+
value: OBJECT;
|
|
802
|
+
} | {
|
|
803
|
+
success: false;
|
|
804
|
+
error: Error;
|
|
805
|
+
};
|
|
806
|
+
type Schema<OBJECT = unknown> = {
|
|
807
|
+
/**
|
|
808
|
+
* Used to mark schemas so we can support both Zod and custom schemas.
|
|
809
|
+
*/
|
|
810
|
+
[schemaSymbol]: true;
|
|
811
|
+
/**
|
|
812
|
+
* Schema type for inference.
|
|
813
|
+
*/
|
|
814
|
+
_type: OBJECT;
|
|
815
|
+
/**
|
|
816
|
+
* Optional. Validates that the structure of a value matches this schema,
|
|
817
|
+
* and returns a typed version of the value if it does.
|
|
818
|
+
*/
|
|
819
|
+
readonly validate?: (value: unknown) => ValidationResult<OBJECT> | PromiseLike<ValidationResult<OBJECT>>;
|
|
820
|
+
/**
|
|
821
|
+
* The JSON Schema for the schema. It is passed to the providers.
|
|
822
|
+
*/
|
|
823
|
+
readonly jsonSchema: JSONSchema7 | PromiseLike<JSONSchema7>;
|
|
824
|
+
};
|
|
825
|
+
/**
|
|
826
|
+
* Creates a schema with deferred creation.
|
|
827
|
+
* This is important to reduce the startup time of the library
|
|
828
|
+
* and to avoid initializing unused validators.
|
|
829
|
+
*
|
|
830
|
+
* @param createValidator A function that creates a schema.
|
|
831
|
+
* @returns A function that returns a schema.
|
|
832
|
+
*/
|
|
833
|
+
declare function lazySchema<SCHEMA>(createSchema: () => Schema<SCHEMA>): LazySchema<SCHEMA>;
|
|
834
|
+
type LazySchema<SCHEMA> = () => Schema<SCHEMA>;
|
|
835
|
+
type ZodSchema<SCHEMA = any> = z3.Schema<SCHEMA, z3.ZodTypeDef, any> | $ZodType<SCHEMA, any>;
|
|
836
|
+
type StandardSchema<SCHEMA = any> = StandardSchemaV1<unknown, SCHEMA> & {
|
|
837
|
+
readonly '~standard': StandardSchemaV1.Props<unknown, SCHEMA> & {
|
|
838
|
+
readonly jsonSchema?: StandardJSONSchemaV1.Converter;
|
|
839
|
+
};
|
|
840
|
+
};
|
|
841
|
+
type FlexibleSchema<SCHEMA = any> = Schema<SCHEMA> | LazySchema<SCHEMA> | ZodSchema<SCHEMA> | StandardSchema<SCHEMA>;
|
|
842
|
+
type InferSchema<SCHEMA> = SCHEMA extends ZodSchema<infer T> ? T : SCHEMA extends StandardSchema<infer T> ? T : SCHEMA extends LazySchema<infer T> ? T : SCHEMA extends Schema<infer T> ? T : never;
|
|
843
|
+
/**
|
|
844
|
+
* Create a schema using a JSON Schema.
|
|
845
|
+
*
|
|
846
|
+
* @param jsonSchema The JSON Schema for the schema.
|
|
847
|
+
* @param options.validate Optional. A validation function for the schema.
|
|
848
|
+
*/
|
|
849
|
+
declare function jsonSchema<OBJECT = unknown>(jsonSchema: JSONSchema7 | PromiseLike<JSONSchema7> | (() => JSONSchema7 | PromiseLike<JSONSchema7>), { validate, }?: {
|
|
850
|
+
validate?: (value: unknown) => ValidationResult<OBJECT> | PromiseLike<ValidationResult<OBJECT>>;
|
|
851
|
+
}): Schema<OBJECT>;
|
|
852
|
+
declare function asSchema<OBJECT>(schema: FlexibleSchema<OBJECT> | undefined): Schema<OBJECT>;
|
|
853
|
+
declare function zodSchema<OBJECT>(zodSchema: $ZodType<OBJECT, any> | z3.Schema<OBJECT, z3.ZodTypeDef, any>, options?: {
|
|
854
|
+
/**
|
|
855
|
+
* Enables support for references in the schema.
|
|
856
|
+
* This is required for recursive schemas, e.g. with `z.lazy`.
|
|
857
|
+
* However, not all language models and providers support such references.
|
|
858
|
+
* Defaults to `false`.
|
|
859
|
+
*/
|
|
860
|
+
useReferences?: boolean;
|
|
861
|
+
}): Schema<OBJECT>;
|
|
862
|
+
|
|
863
|
+
/**
|
|
864
|
+
* Parses a JSON string into an unknown object.
|
|
865
|
+
*
|
|
866
|
+
* @param text - The JSON string to parse.
|
|
867
|
+
* @returns {JSONValue} - The parsed JSON object.
|
|
868
|
+
*/
|
|
869
|
+
declare function parseJSON(options: {
|
|
870
|
+
text: string;
|
|
871
|
+
schema?: undefined;
|
|
872
|
+
}): Promise<JSONValue>;
|
|
873
|
+
/**
|
|
874
|
+
* Parses a JSON string into a strongly-typed object using the provided schema.
|
|
875
|
+
*
|
|
876
|
+
* @template T - The type of the object to parse the JSON into.
|
|
877
|
+
* @param {string} text - The JSON string to parse.
|
|
878
|
+
* @param {Validator<T>} schema - The schema to use for parsing the JSON.
|
|
879
|
+
* @returns {Promise<T>} - The parsed object.
|
|
880
|
+
*/
|
|
881
|
+
declare function parseJSON<T>(options: {
|
|
882
|
+
text: string;
|
|
883
|
+
schema: FlexibleSchema<T>;
|
|
884
|
+
}): Promise<T>;
|
|
885
|
+
type ParseResult<T> = {
|
|
886
|
+
success: true;
|
|
887
|
+
value: T;
|
|
888
|
+
rawValue: unknown;
|
|
889
|
+
} | {
|
|
890
|
+
success: false;
|
|
891
|
+
error: JSONParseError | TypeValidationError;
|
|
892
|
+
rawValue: unknown;
|
|
893
|
+
};
|
|
894
|
+
/**
|
|
895
|
+
* Safely parses a JSON string and returns the result as an object of type `unknown`.
|
|
896
|
+
*
|
|
897
|
+
* @param text - The JSON string to parse.
|
|
898
|
+
* @returns {Promise<object>} Either an object with `success: true` and the parsed data, or an object with `success: false` and the error that occurred.
|
|
899
|
+
*/
|
|
900
|
+
declare function safeParseJSON(options: {
|
|
901
|
+
text: string;
|
|
902
|
+
schema?: undefined;
|
|
903
|
+
}): Promise<ParseResult<JSONValue>>;
|
|
904
|
+
/**
|
|
905
|
+
* Safely parses a JSON string into a strongly-typed object, using a provided schema to validate the object.
|
|
906
|
+
*
|
|
907
|
+
* @template T - The type of the object to parse the JSON into.
|
|
908
|
+
* @param {string} text - The JSON string to parse.
|
|
909
|
+
* @param {Validator<T>} schema - The schema to use for parsing the JSON.
|
|
910
|
+
* @returns An object with either a `success` flag and the parsed and typed data, or a `success` flag and an error object.
|
|
911
|
+
*/
|
|
912
|
+
declare function safeParseJSON<T>(options: {
|
|
913
|
+
text: string;
|
|
914
|
+
schema: FlexibleSchema<T>;
|
|
915
|
+
}): Promise<ParseResult<T>>;
|
|
916
|
+
declare function isParsableJson(input: string): boolean;
|
|
917
|
+
|
|
918
|
+
type ResponseHandler<RETURN_TYPE> = (options: {
|
|
919
|
+
url: string;
|
|
920
|
+
requestBodyValues: unknown;
|
|
921
|
+
response: Response;
|
|
922
|
+
}) => PromiseLike<{
|
|
923
|
+
value: RETURN_TYPE;
|
|
924
|
+
rawValue?: unknown;
|
|
925
|
+
responseHeaders?: Record<string, string>;
|
|
926
|
+
}>;
|
|
927
|
+
declare const createJsonErrorResponseHandler: <T>({ errorSchema, errorToMessage, isRetryable, }: {
|
|
928
|
+
errorSchema: FlexibleSchema<T>;
|
|
929
|
+
errorToMessage: (error: T) => string;
|
|
930
|
+
isRetryable?: (response: Response, error?: T) => boolean;
|
|
931
|
+
}) => ResponseHandler<APICallError>;
|
|
932
|
+
declare const createEventSourceResponseHandler: <T>(chunkSchema: FlexibleSchema<T>) => ResponseHandler<ReadableStream<ParseResult<T>>>;
|
|
933
|
+
declare const createJsonResponseHandler: <T>(responseSchema: FlexibleSchema<T>) => ResponseHandler<T>;
|
|
934
|
+
declare const createJsonLinesResponseHandler: <T>(responseSchema: FlexibleSchema<T>) => ResponseHandler<AsyncGenerator<T>>;
|
|
935
|
+
declare const createBinaryResponseHandler: () => ResponseHandler<Uint8Array>;
|
|
936
|
+
/**
|
|
937
|
+
* Passes the response body through as a `ReadableStream<Uint8Array>` without
|
|
938
|
+
* buffering it (unlike `createBinaryResponseHandler`). The consumer is
|
|
939
|
+
* responsible for draining or cancelling the stream.
|
|
940
|
+
*/
|
|
941
|
+
declare const createBinaryStreamResponseHandler: () => ResponseHandler<ReadableStream<Uint8Array>>;
|
|
942
|
+
declare const createStatusCodeErrorResponseHandler: () => ResponseHandler<APICallError>;
|
|
943
|
+
|
|
944
|
+
/**
|
|
945
|
+
* Sends a DELETE request. For URLs built from developer-configured endpoints
|
|
946
|
+
* only — there is no untrusted-URL validation path (use `getFromApi` with
|
|
947
|
+
* `validateUrl` for response-supplied URLs).
|
|
948
|
+
*/
|
|
949
|
+
declare const deleteFromApi: <T>({ url, headers, failedResponseHandler, successfulResponseHandler, abortSignal, fetch, }: {
|
|
950
|
+
url: string;
|
|
951
|
+
headers?: Record<string, string | undefined>;
|
|
952
|
+
failedResponseHandler: ResponseHandler<Error>;
|
|
953
|
+
successfulResponseHandler: ResponseHandler<T>;
|
|
954
|
+
abortSignal?: AbortSignal;
|
|
955
|
+
fetch?: FetchFunction;
|
|
956
|
+
}) => Promise<{
|
|
957
|
+
value: T;
|
|
958
|
+
rawValue?: unknown;
|
|
959
|
+
responseHeaders?: Record<string, string>;
|
|
960
|
+
}>;
|
|
961
|
+
|
|
784
962
|
/**
|
|
785
963
|
* Detect the IANA media type of a file from its raw bytes or base64 string.
|
|
786
964
|
*
|
|
@@ -861,11 +1039,6 @@ declare class DownloadError extends AISDKError {
|
|
|
861
1039
|
*/
|
|
862
1040
|
declare const EMBEDDING_MODEL_MAX_INPUT_BYTES_PER_CALL: unique symbol;
|
|
863
1041
|
|
|
864
|
-
/**
|
|
865
|
-
* Fetch function type (standardizes the version of fetch used).
|
|
866
|
-
*/
|
|
867
|
-
type FetchFunction = typeof globalThis.fetch;
|
|
868
|
-
|
|
869
1042
|
/**
|
|
870
1043
|
* Fetches a URL while enforcing the download guard on every hop.
|
|
871
1044
|
*
|
|
@@ -982,149 +1155,6 @@ type IdGenerator = () => string;
|
|
|
982
1155
|
*/
|
|
983
1156
|
declare const generateId: IdGenerator;
|
|
984
1157
|
|
|
985
|
-
/**
|
|
986
|
-
* Used to mark schemas so we can support both Zod and custom schemas.
|
|
987
|
-
*/
|
|
988
|
-
declare const schemaSymbol: unique symbol;
|
|
989
|
-
type ValidationResult<OBJECT> = {
|
|
990
|
-
success: true;
|
|
991
|
-
value: OBJECT;
|
|
992
|
-
} | {
|
|
993
|
-
success: false;
|
|
994
|
-
error: Error;
|
|
995
|
-
};
|
|
996
|
-
type Schema<OBJECT = unknown> = {
|
|
997
|
-
/**
|
|
998
|
-
* Used to mark schemas so we can support both Zod and custom schemas.
|
|
999
|
-
*/
|
|
1000
|
-
[schemaSymbol]: true;
|
|
1001
|
-
/**
|
|
1002
|
-
* Schema type for inference.
|
|
1003
|
-
*/
|
|
1004
|
-
_type: OBJECT;
|
|
1005
|
-
/**
|
|
1006
|
-
* Optional. Validates that the structure of a value matches this schema,
|
|
1007
|
-
* and returns a typed version of the value if it does.
|
|
1008
|
-
*/
|
|
1009
|
-
readonly validate?: (value: unknown) => ValidationResult<OBJECT> | PromiseLike<ValidationResult<OBJECT>>;
|
|
1010
|
-
/**
|
|
1011
|
-
* The JSON Schema for the schema. It is passed to the providers.
|
|
1012
|
-
*/
|
|
1013
|
-
readonly jsonSchema: JSONSchema7 | PromiseLike<JSONSchema7>;
|
|
1014
|
-
};
|
|
1015
|
-
/**
|
|
1016
|
-
* Creates a schema with deferred creation.
|
|
1017
|
-
* This is important to reduce the startup time of the library
|
|
1018
|
-
* and to avoid initializing unused validators.
|
|
1019
|
-
*
|
|
1020
|
-
* @param createValidator A function that creates a schema.
|
|
1021
|
-
* @returns A function that returns a schema.
|
|
1022
|
-
*/
|
|
1023
|
-
declare function lazySchema<SCHEMA>(createSchema: () => Schema<SCHEMA>): LazySchema<SCHEMA>;
|
|
1024
|
-
type LazySchema<SCHEMA> = () => Schema<SCHEMA>;
|
|
1025
|
-
type ZodSchema<SCHEMA = any> = z3.Schema<SCHEMA, z3.ZodTypeDef, any> | $ZodType<SCHEMA, any>;
|
|
1026
|
-
type StandardSchema<SCHEMA = any> = StandardSchemaV1<unknown, SCHEMA> & {
|
|
1027
|
-
readonly '~standard': StandardSchemaV1.Props<unknown, SCHEMA> & {
|
|
1028
|
-
readonly jsonSchema?: StandardJSONSchemaV1.Converter;
|
|
1029
|
-
};
|
|
1030
|
-
};
|
|
1031
|
-
type FlexibleSchema<SCHEMA = any> = Schema<SCHEMA> | LazySchema<SCHEMA> | ZodSchema<SCHEMA> | StandardSchema<SCHEMA>;
|
|
1032
|
-
type InferSchema<SCHEMA> = SCHEMA extends ZodSchema<infer T> ? T : SCHEMA extends StandardSchema<infer T> ? T : SCHEMA extends LazySchema<infer T> ? T : SCHEMA extends Schema<infer T> ? T : never;
|
|
1033
|
-
/**
|
|
1034
|
-
* Create a schema using a JSON Schema.
|
|
1035
|
-
*
|
|
1036
|
-
* @param jsonSchema The JSON Schema for the schema.
|
|
1037
|
-
* @param options.validate Optional. A validation function for the schema.
|
|
1038
|
-
*/
|
|
1039
|
-
declare function jsonSchema<OBJECT = unknown>(jsonSchema: JSONSchema7 | PromiseLike<JSONSchema7> | (() => JSONSchema7 | PromiseLike<JSONSchema7>), { validate, }?: {
|
|
1040
|
-
validate?: (value: unknown) => ValidationResult<OBJECT> | PromiseLike<ValidationResult<OBJECT>>;
|
|
1041
|
-
}): Schema<OBJECT>;
|
|
1042
|
-
declare function asSchema<OBJECT>(schema: FlexibleSchema<OBJECT> | undefined): Schema<OBJECT>;
|
|
1043
|
-
declare function zodSchema<OBJECT>(zodSchema: $ZodType<OBJECT, any> | z3.Schema<OBJECT, z3.ZodTypeDef, any>, options?: {
|
|
1044
|
-
/**
|
|
1045
|
-
* Enables support for references in the schema.
|
|
1046
|
-
* This is required for recursive schemas, e.g. with `z.lazy`.
|
|
1047
|
-
* However, not all language models and providers support such references.
|
|
1048
|
-
* Defaults to `false`.
|
|
1049
|
-
*/
|
|
1050
|
-
useReferences?: boolean;
|
|
1051
|
-
}): Schema<OBJECT>;
|
|
1052
|
-
|
|
1053
|
-
/**
|
|
1054
|
-
* Parses a JSON string into an unknown object.
|
|
1055
|
-
*
|
|
1056
|
-
* @param text - The JSON string to parse.
|
|
1057
|
-
* @returns {JSONValue} - The parsed JSON object.
|
|
1058
|
-
*/
|
|
1059
|
-
declare function parseJSON(options: {
|
|
1060
|
-
text: string;
|
|
1061
|
-
schema?: undefined;
|
|
1062
|
-
}): Promise<JSONValue>;
|
|
1063
|
-
/**
|
|
1064
|
-
* Parses a JSON string into a strongly-typed object using the provided schema.
|
|
1065
|
-
*
|
|
1066
|
-
* @template T - The type of the object to parse the JSON into.
|
|
1067
|
-
* @param {string} text - The JSON string to parse.
|
|
1068
|
-
* @param {Validator<T>} schema - The schema to use for parsing the JSON.
|
|
1069
|
-
* @returns {Promise<T>} - The parsed object.
|
|
1070
|
-
*/
|
|
1071
|
-
declare function parseJSON<T>(options: {
|
|
1072
|
-
text: string;
|
|
1073
|
-
schema: FlexibleSchema<T>;
|
|
1074
|
-
}): Promise<T>;
|
|
1075
|
-
type ParseResult<T> = {
|
|
1076
|
-
success: true;
|
|
1077
|
-
value: T;
|
|
1078
|
-
rawValue: unknown;
|
|
1079
|
-
} | {
|
|
1080
|
-
success: false;
|
|
1081
|
-
error: JSONParseError | TypeValidationError;
|
|
1082
|
-
rawValue: unknown;
|
|
1083
|
-
};
|
|
1084
|
-
/**
|
|
1085
|
-
* Safely parses a JSON string and returns the result as an object of type `unknown`.
|
|
1086
|
-
*
|
|
1087
|
-
* @param text - The JSON string to parse.
|
|
1088
|
-
* @returns {Promise<object>} Either an object with `success: true` and the parsed data, or an object with `success: false` and the error that occurred.
|
|
1089
|
-
*/
|
|
1090
|
-
declare function safeParseJSON(options: {
|
|
1091
|
-
text: string;
|
|
1092
|
-
schema?: undefined;
|
|
1093
|
-
}): Promise<ParseResult<JSONValue>>;
|
|
1094
|
-
/**
|
|
1095
|
-
* Safely parses a JSON string into a strongly-typed object, using a provided schema to validate the object.
|
|
1096
|
-
*
|
|
1097
|
-
* @template T - The type of the object to parse the JSON into.
|
|
1098
|
-
* @param {string} text - The JSON string to parse.
|
|
1099
|
-
* @param {Validator<T>} schema - The schema to use for parsing the JSON.
|
|
1100
|
-
* @returns An object with either a `success` flag and the parsed and typed data, or a `success` flag and an error object.
|
|
1101
|
-
*/
|
|
1102
|
-
declare function safeParseJSON<T>(options: {
|
|
1103
|
-
text: string;
|
|
1104
|
-
schema: FlexibleSchema<T>;
|
|
1105
|
-
}): Promise<ParseResult<T>>;
|
|
1106
|
-
declare function isParsableJson(input: string): boolean;
|
|
1107
|
-
|
|
1108
|
-
type ResponseHandler<RETURN_TYPE> = (options: {
|
|
1109
|
-
url: string;
|
|
1110
|
-
requestBodyValues: unknown;
|
|
1111
|
-
response: Response;
|
|
1112
|
-
}) => PromiseLike<{
|
|
1113
|
-
value: RETURN_TYPE;
|
|
1114
|
-
rawValue?: unknown;
|
|
1115
|
-
responseHeaders?: Record<string, string>;
|
|
1116
|
-
}>;
|
|
1117
|
-
declare const createJsonErrorResponseHandler: <T>({ errorSchema, errorToMessage, isRetryable, }: {
|
|
1118
|
-
errorSchema: FlexibleSchema<T>;
|
|
1119
|
-
errorToMessage: (error: T) => string;
|
|
1120
|
-
isRetryable?: (response: Response, error?: T) => boolean;
|
|
1121
|
-
}) => ResponseHandler<APICallError>;
|
|
1122
|
-
declare const createEventSourceResponseHandler: <T>(chunkSchema: FlexibleSchema<T>) => ResponseHandler<ReadableStream<ParseResult<T>>>;
|
|
1123
|
-
declare const createJsonResponseHandler: <T>(responseSchema: FlexibleSchema<T>) => ResponseHandler<T>;
|
|
1124
|
-
declare const createJsonLinesResponseHandler: <T>(responseSchema: FlexibleSchema<T>) => ResponseHandler<AsyncGenerator<T>>;
|
|
1125
|
-
declare const createBinaryResponseHandler: () => ResponseHandler<Uint8Array>;
|
|
1126
|
-
declare const createStatusCodeErrorResponseHandler: () => ResponseHandler<APICallError>;
|
|
1127
|
-
|
|
1128
1158
|
declare const getFromApi: <T>({ url, headers, successfulResponseHandler, failedResponseHandler, abortSignal, fetch, validateUrl, credentialedOrigin, trustedOrigin, }: {
|
|
1129
1159
|
url: string;
|
|
1130
1160
|
headers?: Record<string, string | undefined>;
|
|
@@ -1383,6 +1413,45 @@ declare function parseProviderOptions<OPTIONS>({ provider, providerOptions, sche
|
|
|
1383
1413
|
schema: FlexibleSchema<OPTIONS>;
|
|
1384
1414
|
}): Promise<OPTIONS | undefined>;
|
|
1385
1415
|
|
|
1416
|
+
/**
|
|
1417
|
+
* A part of a streaming multipart/form-data request body.
|
|
1418
|
+
*
|
|
1419
|
+
* Parts are emitted in array order, which providers may depend on
|
|
1420
|
+
* (e.g. xAI requires expiry fields to precede the file part).
|
|
1421
|
+
*/
|
|
1422
|
+
type MultipartStreamPart = {
|
|
1423
|
+
type: 'field';
|
|
1424
|
+
name: string;
|
|
1425
|
+
value: string;
|
|
1426
|
+
} | {
|
|
1427
|
+
type: 'file';
|
|
1428
|
+
name: string;
|
|
1429
|
+
filename?: string;
|
|
1430
|
+
mediaType?: string;
|
|
1431
|
+
content: ReadableStream<Uint8Array> | Uint8Array;
|
|
1432
|
+
};
|
|
1433
|
+
/**
|
|
1434
|
+
* POSTs a multipart/form-data body as a request stream, so file parts backed
|
|
1435
|
+
* by a `ReadableStream` are sent without buffering the full file in memory.
|
|
1436
|
+
*
|
|
1437
|
+
* Requires a fetch implementation that supports streaming request bodies
|
|
1438
|
+
* (`duplex: 'half'`). Callers with fully buffered payloads can keep using
|
|
1439
|
+
* `postFormDataToApi`.
|
|
1440
|
+
*/
|
|
1441
|
+
declare const postMultipartStreamToApi: <T>({ url, headers, parts, failedResponseHandler, successfulResponseHandler, abortSignal, fetch, }: {
|
|
1442
|
+
url: string;
|
|
1443
|
+
headers?: Record<string, string | undefined>;
|
|
1444
|
+
parts: Array<MultipartStreamPart>;
|
|
1445
|
+
failedResponseHandler: ResponseHandler<Error>;
|
|
1446
|
+
successfulResponseHandler: ResponseHandler<T>;
|
|
1447
|
+
abortSignal?: AbortSignal;
|
|
1448
|
+
fetch?: FetchFunction;
|
|
1449
|
+
}) => Promise<{
|
|
1450
|
+
value: T;
|
|
1451
|
+
rawValue?: unknown;
|
|
1452
|
+
responseHeaders?: Record<string, string>;
|
|
1453
|
+
}>;
|
|
1454
|
+
|
|
1386
1455
|
declare const postJsonToApi: <T>({ url, headers, body, failedResponseHandler, successfulResponseHandler, abortSignal, fetch, }: {
|
|
1387
1456
|
url: string;
|
|
1388
1457
|
headers?: Record<string, string | undefined>;
|
|
@@ -2719,4 +2788,4 @@ interface ToolResult<NAME extends string, INPUT, OUTPUT> {
|
|
|
2719
2788
|
dynamic?: boolean;
|
|
2720
2789
|
}
|
|
2721
2790
|
|
|
2722
|
-
export { type Arrayable, type AssistantContent, type AssistantModelMessage, type Context, type CustomPart, DEFAULT_MAX_DOWNLOAD_SIZE, type DataContent, DelayedPromise, DownloadError, type DynamicTool, EMBEDDING_MODEL_MAX_INPUT_BYTES_PER_CALL as EXPERIMENTAL_EMBEDDING_MODEL_MAX_INPUT_BYTES_PER_CALL, TRANSCRIPTION_STREAM_AUDIO_DONE_FRAME_TYPE as EXPERIMENTAL_TRANSCRIPTION_STREAM_AUDIO_DONE_FRAME_TYPE, TRANSCRIPTION_STREAM_START_FRAME_TYPE as EXPERIMENTAL_TRANSCRIPTION_STREAM_START_FRAME_TYPE, type ExecutableTool, type SandboxProcess as Experimental_SandboxProcess, type SandboxSession as Experimental_SandboxSession, type ToolCallerDefinition as Experimental_ToolCallerDefinition, type ToolCallerTool as Experimental_ToolCallerTool, type TranscriptionStreamClientFrame as Experimental_TranscriptionStreamClientFrame, type TranscriptionStreamStartFrame as Experimental_TranscriptionStreamStartFrame, type FetchFunction, type FileData, type FileDataData, type FileDataReference, type FileDataText, type FileDataUrl, type FilePart, type FlexibleSchema, type FunctionTool, type HasRequiredKey, type IdGenerator, type ImagePart, type InferSchema, type InferToolContext, type InferToolInput, type InferToolOutput, type InferToolSetContext, type LazySchema, type MaybePromiseLike, type ModelMessage, type ParseResult, type ProviderDefinedTool, type ProviderDefinedToolFactory, type ProviderDefinedToolFactoryWithOutputSchema, type ProviderExecutedTool, type ProviderExecutedToolFactory, type ProviderOptions, type ProviderReference, type ProviderStreamError, type ReasoningFilePart, type ReasoningPart, type Resolvable, type ResponseHandler, type RetryDelayProvider, type RetryErrorFactory, type RetryErrorReason, type RetryFunction, type Schema, SerializationError, type ShouldRetryFunction, type StreamingToolCallDelta, StreamingToolCallTracker, type StreamingToolCallTrackerOptions, type SystemModelMessage, type TextPart, type Tool, type ToolApprovalRequest, type ToolApprovalResponse, type ToolCall, type ToolCallPart, type ToolContent, type ToolExecuteFunction, type ToolExecutionOptions, type ToolModelMessage, type ToolNameMapping, type ToolNeedsApprovalFunction, type ToolResult, type ToolResultOutput, type ToolResultPart, type ToolSet, type UserContent, type UserModelMessage, VERSION, type ValidationResult, type WebSocketConnection, type WebSocketConstructor, type WebSocketLike, asArray, asSchema, cancelResponseBody, combineHeaders, connectToWebSocket, convertAsyncIteratorToReadableStream, convertBase64ToUint8Array, convertImageModelFileToDataUri, convertInlineFileDataToUint8Array, convertToBase64, convertToFormData, convertUint8ArrayToBase64, createBinaryResponseHandler, createEventSourceResponseHandler, createIdGenerator, createJsonErrorResponseHandler, createJsonLinesResponseHandler, createJsonResponseHandler, createLanguageModelResponseMetadata, createNullLanguageModelUsage, createProviderDefinedToolFactory, createProviderDefinedToolFactoryWithOutputSchema, createProviderExecutedToolFactory, createProviderStreamError, createStatusCodeErrorResponseHandler, createToolNameMapping, delay, detectMediaType, downloadBlob, dynamicTool, executeTool, getToolCaller as experimental_getToolCaller, parseTranscriptionStreamClientFrame as experimental_parseTranscriptionStreamClientFrame, parseTranscriptionStreamPart as experimental_parseTranscriptionStreamPart, serializeTranscriptionStreamPart as experimental_serializeTranscriptionStreamPart, toolCaller as experimental_toolCaller, extractLines, extractResponseHeaders, fetchWithValidatedRedirects, filterNullable, generateId, getFromApi, getRuntimeEnvironmentUserAgent, getTopLevelMediaType, getWebSocketConstructor, injectJsonInstructionIntoMessages, isAbortError, isBrowserRuntime, isBuffer, isCustomReasoning, isExecutableTool, isFullMediaType, isNonNullable, isParsableJson, isProviderReference, isProviderStreamError, isRecord, isSameOrigin, isUrlSupported, jsonSchema, lazySchema, loadApiKey, loadOptionalSetting, loadSetting, mapReasoningToProviderBudget, mapReasoningToProviderEffort, mediaTypeToExtension, normalizeBatchRequestCounts, normalizeHeaders, parseJSON, parseJsonEventStream, parseProviderOptions, postFormDataToApi, postJsonToApi, postToApi, readResponseWithSizeLimit, readWebSocketMessageText, removeUndefinedEntries, resolve, resolveFullMediaType, resolveProviderReference, retryWithExponentialBackoff, safeParseJSON, safeValidateTypes, secureJsonParse, serializeModelOptions, stripFileExtension, toWebSocketUrl, tool, validateBaseURL, validateDownloadUrl, validateTypes, waitForWebSocketBufferDrain, withUserAgentSuffix, withoutTrailingSlash, zodSchema };
|
|
2791
|
+
export { type Arrayable, type AssistantContent, type AssistantModelMessage, type Context, type CustomPart, DEFAULT_MAX_DOWNLOAD_SIZE, type DataContent, DelayedPromise, DownloadError, type DynamicTool, EMBEDDING_MODEL_MAX_INPUT_BYTES_PER_CALL as EXPERIMENTAL_EMBEDDING_MODEL_MAX_INPUT_BYTES_PER_CALL, TRANSCRIPTION_STREAM_AUDIO_DONE_FRAME_TYPE as EXPERIMENTAL_TRANSCRIPTION_STREAM_AUDIO_DONE_FRAME_TYPE, TRANSCRIPTION_STREAM_START_FRAME_TYPE as EXPERIMENTAL_TRANSCRIPTION_STREAM_START_FRAME_TYPE, type ExecutableTool, type SandboxProcess as Experimental_SandboxProcess, type SandboxSession as Experimental_SandboxSession, type ToolCallerDefinition as Experimental_ToolCallerDefinition, type ToolCallerTool as Experimental_ToolCallerTool, type TranscriptionStreamClientFrame as Experimental_TranscriptionStreamClientFrame, type TranscriptionStreamStartFrame as Experimental_TranscriptionStreamStartFrame, type FetchFunction, type FileData, type FileDataData, type FileDataReference, type FileDataText, type FileDataUrl, type FilePart, type FlexibleSchema, type FunctionTool, type HasRequiredKey, type IdGenerator, type ImagePart, type InferSchema, type InferToolContext, type InferToolInput, type InferToolOutput, type InferToolSetContext, type LazySchema, type MaybePromiseLike, type ModelMessage, type MultipartStreamPart, type ParseResult, type ProviderDefinedTool, type ProviderDefinedToolFactory, type ProviderDefinedToolFactoryWithOutputSchema, type ProviderExecutedTool, type ProviderExecutedToolFactory, type ProviderOptions, type ProviderReference, type ProviderStreamError, type ReasoningFilePart, type ReasoningPart, type Resolvable, type ResponseHandler, type RetryDelayProvider, type RetryErrorFactory, type RetryErrorReason, type RetryFunction, type Schema, SerializationError, type ShouldRetryFunction, type StreamingToolCallDelta, StreamingToolCallTracker, type StreamingToolCallTrackerOptions, type SystemModelMessage, type TextPart, type Tool, type ToolApprovalRequest, type ToolApprovalResponse, type ToolCall, type ToolCallPart, type ToolContent, type ToolExecuteFunction, type ToolExecutionOptions, type ToolModelMessage, type ToolNameMapping, type ToolNeedsApprovalFunction, type ToolResult, type ToolResultOutput, type ToolResultPart, type ToolSet, type UserContent, type UserModelMessage, VERSION, type ValidationResult, type WebSocketConnection, type WebSocketConstructor, type WebSocketLike, asArray, asSchema, cancelResponseBody, combineHeaders, connectToWebSocket, convertAsyncIteratorToReadableStream, convertBase64ToUint8Array, convertImageModelFileToDataUri, convertInlineFileDataToUint8Array, convertToBase64, convertToFormData, convertUint8ArrayToBase64, createBinaryResponseHandler, createBinaryStreamResponseHandler, createEventSourceResponseHandler, createIdGenerator, createJsonErrorResponseHandler, createJsonLinesResponseHandler, createJsonResponseHandler, createLanguageModelResponseMetadata, createNullLanguageModelUsage, createProviderDefinedToolFactory, createProviderDefinedToolFactoryWithOutputSchema, createProviderExecutedToolFactory, createProviderStreamError, createStatusCodeErrorResponseHandler, createToolNameMapping, delay, deleteFromApi, detectMediaType, downloadBlob, dynamicTool, executeTool, getToolCaller as experimental_getToolCaller, parseTranscriptionStreamClientFrame as experimental_parseTranscriptionStreamClientFrame, parseTranscriptionStreamPart as experimental_parseTranscriptionStreamPart, serializeTranscriptionStreamPart as experimental_serializeTranscriptionStreamPart, toolCaller as experimental_toolCaller, extractLines, extractResponseHeaders, fetchWithValidatedRedirects, filterNullable, generateId, getFromApi, getRuntimeEnvironmentUserAgent, getTopLevelMediaType, getWebSocketConstructor, injectJsonInstructionIntoMessages, isAbortError, isBrowserRuntime, isBuffer, isCustomReasoning, isExecutableTool, isFullMediaType, isNonNullable, isParsableJson, isProviderReference, isProviderStreamError, isRecord, isSameOrigin, isUrlSupported, jsonSchema, lazySchema, loadApiKey, loadOptionalSetting, loadSetting, mapReasoningToProviderBudget, mapReasoningToProviderEffort, mediaTypeToExtension, normalizeBatchRequestCounts, normalizeHeaders, parseJSON, parseJsonEventStream, parseProviderOptions, postFormDataToApi, postJsonToApi, postMultipartStreamToApi, postToApi, readResponseWithSizeLimit, readWebSocketMessageText, removeUndefinedEntries, resolve, resolveFullMediaType, resolveProviderReference, retryWithExponentialBackoff, safeParseJSON, safeValidateTypes, secureJsonParse, serializeModelOptions, stripFileExtension, toWebSocketUrl, tool, validateBaseURL, validateDownloadUrl, validateTypes, waitForWebSocketBufferDrain, withUserAgentSuffix, withoutTrailingSlash, zodSchema };
|