@ai-sdk/provider-utils 2.2.8 → 3.0.0-alpha.10
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 +237 -14
- package/dist/index.d.mts +156 -72
- package/dist/index.d.ts +156 -72
- package/dist/index.js +243 -81
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +215 -61
- package/dist/index.mjs.map +1 -1
- package/dist/test/index.d.mts +87 -0
- package/dist/test/index.d.ts +87 -0
- package/{test/dist → dist/test}/index.js +66 -358
- package/dist/test/index.js.map +1 -0
- package/{test/dist → dist/test}/index.mjs +64 -353
- package/dist/test/index.mjs.map +1 -0
- package/package.json +19 -17
- package/test.d.ts +1 -0
- package/test/dist/index.d.mts +0 -162
- package/test/dist/index.d.ts +0 -162
- package/test/dist/index.js.map +0 -1
- package/test/dist/index.mjs.map +0 -1
- /package/{test/dist → dist/test}/chunk-D6YTI3O5.mjs +0 -0
- /package/{test/dist → dist/test}/chunk-D6YTI3O5.mjs.map +0 -0
- /package/{test/dist → dist/test}/graphql-6JDEV3ML.mjs +0 -0
- /package/{test/dist → dist/test}/graphql-6JDEV3ML.mjs.map +0 -0
package/CHANGELOG.md
CHANGED
@@ -1,38 +1,261 @@
|
|
1
1
|
# @ai-sdk/provider-utils
|
2
2
|
|
3
|
-
##
|
3
|
+
## 3.0.0-alpha.10
|
4
4
|
|
5
5
|
### Patch Changes
|
6
6
|
|
7
|
-
-
|
7
|
+
- Updated dependencies [c4df419]
|
8
|
+
- @ai-sdk/provider@2.0.0-alpha.10
|
8
9
|
|
9
|
-
##
|
10
|
+
## 3.0.0-alpha.9
|
10
11
|
|
11
12
|
### Patch Changes
|
12
13
|
|
13
|
-
- Updated dependencies [
|
14
|
-
- @ai-sdk/provider@
|
14
|
+
- Updated dependencies [811dff3]
|
15
|
+
- @ai-sdk/provider@2.0.0-alpha.9
|
15
16
|
|
16
|
-
##
|
17
|
+
## 3.0.0-alpha.8
|
17
18
|
|
18
19
|
### Patch Changes
|
19
20
|
|
20
|
-
-
|
21
|
-
- @ai-sdk/provider@1.1.2
|
21
|
+
- 4fef487: feat: support for zod v4 for schema validation
|
22
22
|
|
23
|
-
|
23
|
+
All these methods now accept both a zod v4 and zod v3 schemas for validation:
|
24
|
+
|
25
|
+
- `generateObject()`
|
26
|
+
- `streamObject()`
|
27
|
+
- `generateText()`
|
28
|
+
- `experimental_useObject()` from `@ai-sdk/react`
|
29
|
+
- `streamUI()` from `@ai-sdk/rsc`
|
30
|
+
|
31
|
+
- Updated dependencies [9222aeb]
|
32
|
+
- @ai-sdk/provider@2.0.0-alpha.8
|
33
|
+
|
34
|
+
## 3.0.0-alpha.7
|
35
|
+
|
36
|
+
### Patch Changes
|
37
|
+
|
38
|
+
- Updated dependencies [5c56081]
|
39
|
+
- @ai-sdk/provider@2.0.0-alpha.7
|
40
|
+
|
41
|
+
## 3.0.0-alpha.6
|
42
|
+
|
43
|
+
### Patch Changes
|
44
|
+
|
45
|
+
- Updated dependencies [0d2c085]
|
46
|
+
- @ai-sdk/provider@2.0.0-alpha.6
|
47
|
+
|
48
|
+
## 3.0.0-alpha.4
|
49
|
+
|
50
|
+
### Patch Changes
|
51
|
+
|
52
|
+
- Updated dependencies [dc714f3]
|
53
|
+
- @ai-sdk/provider@2.0.0-alpha.4
|
54
|
+
|
55
|
+
## 3.0.0-alpha.3
|
56
|
+
|
57
|
+
### Patch Changes
|
58
|
+
|
59
|
+
- Updated dependencies [6b98118]
|
60
|
+
- @ai-sdk/provider@2.0.0-alpha.3
|
61
|
+
|
62
|
+
## 3.0.0-alpha.2
|
63
|
+
|
64
|
+
### Patch Changes
|
65
|
+
|
66
|
+
- Updated dependencies [26535e0]
|
67
|
+
- @ai-sdk/provider@2.0.0-alpha.2
|
68
|
+
|
69
|
+
## 3.0.0-alpha.1
|
70
|
+
|
71
|
+
### Patch Changes
|
72
|
+
|
73
|
+
- Updated dependencies [3f2f00c]
|
74
|
+
- @ai-sdk/provider@2.0.0-alpha.1
|
75
|
+
|
76
|
+
## 3.0.0-canary.19
|
77
|
+
|
78
|
+
### Patch Changes
|
79
|
+
|
80
|
+
- faf8446: chore (provider-utils): switch to standard-schema
|
81
|
+
|
82
|
+
## 3.0.0-canary.18
|
83
|
+
|
84
|
+
### Major Changes
|
85
|
+
|
86
|
+
- 40acf9b: feat (ui): introduce ChatStore and ChatTransport
|
87
|
+
|
88
|
+
## 3.0.0-canary.17
|
89
|
+
|
90
|
+
### Major Changes
|
91
|
+
|
92
|
+
- ea7a7c9: feat (ui): UI message metadata
|
93
|
+
|
94
|
+
## 3.0.0-canary.16
|
95
|
+
|
96
|
+
### Patch Changes
|
97
|
+
|
98
|
+
- 87b828f: fix(provider-utils): fix SSE parser bug (CRLF)
|
99
|
+
|
100
|
+
## 3.0.0-canary.15
|
101
|
+
|
102
|
+
### Major Changes
|
103
|
+
|
104
|
+
- 41fa418: chore (provider-utils): return IdGenerator interface
|
105
|
+
|
106
|
+
### Patch Changes
|
107
|
+
|
108
|
+
- a571d6e: chore(provider-utils): move ToolResultContent to provider-utils
|
109
|
+
- Updated dependencies [a8c8bd5]
|
110
|
+
- Updated dependencies [7979f7f]
|
111
|
+
- @ai-sdk/provider@2.0.0-canary.14
|
112
|
+
|
113
|
+
## 3.0.0-canary.14
|
114
|
+
|
115
|
+
### Major Changes
|
116
|
+
|
117
|
+
- 957b739: chore (provider-utils): rename TestServerCall.requestBody to requestBodyJson
|
24
118
|
|
25
119
|
### Patch Changes
|
26
120
|
|
27
|
-
-
|
28
|
-
-
|
29
|
-
|
121
|
+
- Updated dependencies [9bd5ab5]
|
122
|
+
- @ai-sdk/provider@2.0.0-canary.13
|
123
|
+
|
124
|
+
## 3.0.0-canary.13
|
125
|
+
|
126
|
+
### Patch Changes
|
127
|
+
|
128
|
+
- 0ff02bb: chore(provider-utils): move over jsonSchema
|
129
|
+
- Updated dependencies [7b3ae3f]
|
130
|
+
- @ai-sdk/provider@2.0.0-canary.12
|
131
|
+
|
132
|
+
## 3.0.0-canary.12
|
133
|
+
|
134
|
+
### Patch Changes
|
135
|
+
|
136
|
+
- Updated dependencies [9bf7291]
|
137
|
+
- Updated dependencies [4617fab]
|
138
|
+
- Updated dependencies [e030615]
|
139
|
+
- @ai-sdk/provider@2.0.0-canary.11
|
140
|
+
|
141
|
+
## 3.0.0-canary.11
|
142
|
+
|
143
|
+
### Patch Changes
|
144
|
+
|
145
|
+
- 66962ed: fix(packages): export node10 compatible types
|
146
|
+
- Updated dependencies [9301f86]
|
147
|
+
- Updated dependencies [a3f768e]
|
148
|
+
- @ai-sdk/provider@2.0.0-canary.10
|
149
|
+
|
150
|
+
## 3.0.0-canary.10
|
151
|
+
|
152
|
+
### Patch Changes
|
153
|
+
|
154
|
+
- Updated dependencies [e86be6f]
|
155
|
+
- @ai-sdk/provider@2.0.0-canary.9
|
156
|
+
|
157
|
+
## 3.0.0-canary.9
|
158
|
+
|
159
|
+
### Patch Changes
|
160
|
+
|
161
|
+
- Updated dependencies [95857aa]
|
162
|
+
- Updated dependencies [7ea4132]
|
163
|
+
- @ai-sdk/provider@2.0.0-canary.8
|
164
|
+
|
165
|
+
## 3.0.0-canary.8
|
166
|
+
|
167
|
+
### Major Changes
|
168
|
+
|
169
|
+
- 5d142ab: remove deprecated `CoreToolCall` and `CoreToolResult` types
|
170
|
+
|
171
|
+
### Patch Changes
|
172
|
+
|
173
|
+
- Updated dependencies [b6b43c7]
|
174
|
+
- Updated dependencies [8aa9e20]
|
175
|
+
- Updated dependencies [3795467]
|
176
|
+
- @ai-sdk/provider@2.0.0-canary.7
|
177
|
+
|
178
|
+
## 3.0.0-canary.7
|
179
|
+
|
180
|
+
### Patch Changes
|
181
|
+
|
182
|
+
- Updated dependencies [26735b5]
|
183
|
+
- Updated dependencies [443d8ec]
|
184
|
+
- Updated dependencies [14c9410]
|
185
|
+
- Updated dependencies [d9c98f4]
|
186
|
+
- Updated dependencies [c4a2fec]
|
187
|
+
- Updated dependencies [0054544]
|
188
|
+
- Updated dependencies [9e9c809]
|
189
|
+
- Updated dependencies [32831c6]
|
190
|
+
- Updated dependencies [d0f9495]
|
191
|
+
- Updated dependencies [fd65bc6]
|
192
|
+
- Updated dependencies [393138b]
|
193
|
+
- Updated dependencies [7182d14]
|
194
|
+
- @ai-sdk/provider@2.0.0-canary.6
|
195
|
+
|
196
|
+
## 3.0.0-canary.6
|
197
|
+
|
198
|
+
### Patch Changes
|
199
|
+
|
200
|
+
- Updated dependencies [411e483]
|
201
|
+
- Updated dependencies [79457bd]
|
202
|
+
- Updated dependencies [ad80501]
|
203
|
+
- Updated dependencies [1766ede]
|
204
|
+
- Updated dependencies [f10304b]
|
205
|
+
- @ai-sdk/provider@2.0.0-canary.5
|
206
|
+
|
207
|
+
## 3.0.0-canary.5
|
208
|
+
|
209
|
+
### Patch Changes
|
210
|
+
|
211
|
+
- Updated dependencies [6f6bb89]
|
212
|
+
- @ai-sdk/provider@2.0.0-canary.4
|
213
|
+
|
214
|
+
## 3.0.0-canary.4
|
215
|
+
|
216
|
+
### Patch Changes
|
217
|
+
|
218
|
+
- Updated dependencies [d1a1aa1]
|
219
|
+
- @ai-sdk/provider@2.0.0-canary.3
|
220
|
+
|
221
|
+
## 3.0.0-canary.3
|
222
|
+
|
223
|
+
### Patch Changes
|
224
|
+
|
225
|
+
- a166433: feat: add transcription with experimental_transcribe
|
226
|
+
- 9f95b35: refactor (provider-utils): copy relevant code from `secure-json-parse` into codebase
|
227
|
+
- Updated dependencies [a166433]
|
228
|
+
- Updated dependencies [abf9a79]
|
229
|
+
- Updated dependencies [0a87932]
|
230
|
+
- Updated dependencies [6dc848c]
|
231
|
+
- @ai-sdk/provider@2.0.0-canary.2
|
232
|
+
|
233
|
+
## 3.0.0-canary.2
|
234
|
+
|
235
|
+
### Patch Changes
|
236
|
+
|
237
|
+
- Updated dependencies [c57e248]
|
238
|
+
- Updated dependencies [33f4a6a]
|
239
|
+
- @ai-sdk/provider@2.0.0-canary.1
|
240
|
+
|
241
|
+
## 3.0.0-canary.1
|
242
|
+
|
243
|
+
### Patch Changes
|
244
|
+
|
245
|
+
- 060370c: feat(provider-utils): add TestServerCall#requestCredentials
|
246
|
+
- 0c0c0b3: refactor (provider-utils): move `customAlphabet()` method from `nanoid` into codebase
|
247
|
+
- 63d791d: chore (utils): remove unused test helpers
|
248
|
+
|
249
|
+
## 3.0.0-canary.0
|
250
|
+
|
251
|
+
### Major Changes
|
30
252
|
|
31
|
-
|
253
|
+
- d5f588f: AI SDK 5
|
32
254
|
|
33
255
|
### Patch Changes
|
34
256
|
|
35
|
-
-
|
257
|
+
- Updated dependencies [d5f588f]
|
258
|
+
- @ai-sdk/provider@2.0.0-canary.0
|
36
259
|
|
37
260
|
## 2.2.3
|
38
261
|
|
package/dist/index.d.mts
CHANGED
@@ -1,5 +1,9 @@
|
|
1
|
-
import { JSONValue, JSONParseError, TypeValidationError, APICallError } from '@ai-sdk/provider';
|
2
|
-
import {
|
1
|
+
import { JSONSchema7, JSONValue, JSONParseError, TypeValidationError, APICallError } from '@ai-sdk/provider';
|
2
|
+
import { ZodSchema, z } from 'zod';
|
3
|
+
import * as z3 from 'zod/v3';
|
4
|
+
import * as z4 from 'zod/v4/core';
|
5
|
+
import { StandardSchemaV1 } from '@standard-schema/spec';
|
6
|
+
export * from '@standard-schema/spec';
|
3
7
|
|
4
8
|
declare function combineHeaders(...headers: Array<Record<string, string | undefined> | undefined>): Record<string, string | undefined>;
|
5
9
|
|
@@ -33,7 +37,9 @@ Extracts the headers from a response object and returns them as a key-value obje
|
|
33
37
|
@param response - The response object to extract headers from.
|
34
38
|
@returns The headers as a key-value object.
|
35
39
|
*/
|
36
|
-
declare function extractResponseHeaders(response: Response):
|
40
|
+
declare function extractResponseHeaders(response: Response): {
|
41
|
+
[k: string]: string;
|
42
|
+
};
|
37
43
|
|
38
44
|
/**
|
39
45
|
* Fetch function type (standardizes the version of fetch used).
|
@@ -43,29 +49,28 @@ type FetchFunction = typeof globalThis.fetch;
|
|
43
49
|
/**
|
44
50
|
Creates an ID generator.
|
45
51
|
The total length of the ID is the sum of the prefix, separator, and random part length.
|
46
|
-
|
52
|
+
Not cryptographically secure.
|
47
53
|
|
48
54
|
@param alphabet - The alphabet to use for the ID. Default: '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz'.
|
49
|
-
@param prefix - The prefix of the ID to generate.
|
55
|
+
@param prefix - The prefix of the ID to generate. Optional.
|
50
56
|
@param separator - The separator between the prefix and the random part of the ID. Default: '-'.
|
51
57
|
@param size - The size of the random part of the ID to generate. Default: 16.
|
52
58
|
*/
|
53
|
-
declare const createIdGenerator: ({ prefix, size
|
59
|
+
declare const createIdGenerator: ({ prefix, size, alphabet, separator, }?: {
|
54
60
|
prefix?: string;
|
55
61
|
separator?: string;
|
56
62
|
size?: number;
|
57
63
|
alphabet?: string;
|
58
|
-
}) =>
|
64
|
+
}) => IdGenerator;
|
59
65
|
/**
|
60
66
|
A function that generates an ID.
|
61
67
|
*/
|
62
|
-
type
|
68
|
+
type IdGenerator = () => string;
|
63
69
|
/**
|
64
|
-
Generates a 16-character random string to use for IDs.
|
65
|
-
|
66
|
-
@param size - The size of the ID to generate. Default: 16.
|
70
|
+
Generates a 16-character random string to use for IDs.
|
71
|
+
Not cryptographically secure.
|
67
72
|
*/
|
68
|
-
declare const generateId:
|
73
|
+
declare const generateId: IdGenerator;
|
69
74
|
|
70
75
|
declare function getErrorMessage(error: unknown | undefined): string;
|
71
76
|
|
@@ -89,17 +94,53 @@ type Validator<OBJECT = unknown> = {
|
|
89
94
|
* Optional. Validates that the structure of a value matches this schema,
|
90
95
|
* and returns a typed version of the value if it does.
|
91
96
|
*/
|
92
|
-
readonly validate?: (value: unknown) => ValidationResult<OBJECT
|
97
|
+
readonly validate?: (value: unknown) => ValidationResult<OBJECT> | PromiseLike<ValidationResult<OBJECT>>;
|
93
98
|
};
|
94
99
|
/**
|
95
100
|
* Create a validator.
|
96
101
|
*
|
97
102
|
* @param validate A validation function for the schema.
|
98
103
|
*/
|
99
|
-
declare function validator<OBJECT>(validate?: undefined | ((value: unknown) => ValidationResult<OBJECT>)): Validator<OBJECT>;
|
104
|
+
declare function validator<OBJECT>(validate?: undefined | ((value: unknown) => ValidationResult<OBJECT> | PromiseLike<ValidationResult<OBJECT>>)): Validator<OBJECT>;
|
100
105
|
declare function isValidator(value: unknown): value is Validator;
|
101
|
-
declare function asValidator<OBJECT>(value: Validator<OBJECT> |
|
102
|
-
declare function
|
106
|
+
declare function asValidator<OBJECT>(value: Validator<OBJECT> | StandardSchemaV1<OBJECT>): Validator<OBJECT>;
|
107
|
+
declare function standardSchemaValidator<OBJECT>(standardSchema: StandardSchemaV1<OBJECT>): Validator<OBJECT>;
|
108
|
+
|
109
|
+
/**
|
110
|
+
* Used to mark schemas so we can support both Zod and custom schemas.
|
111
|
+
*/
|
112
|
+
declare const schemaSymbol: unique symbol;
|
113
|
+
type Schema<OBJECT = unknown> = Validator<OBJECT> & {
|
114
|
+
/**
|
115
|
+
* Used to mark schemas so we can support both Zod and custom schemas.
|
116
|
+
*/
|
117
|
+
[schemaSymbol]: true;
|
118
|
+
/**
|
119
|
+
* Schema type for inference.
|
120
|
+
*/
|
121
|
+
_type: OBJECT;
|
122
|
+
/**
|
123
|
+
* The JSON Schema for the schema. It is passed to the providers.
|
124
|
+
*/
|
125
|
+
readonly jsonSchema: JSONSchema7;
|
126
|
+
};
|
127
|
+
type InferSchema<SCHEMA> = SCHEMA extends z3.Schema ? z3.infer<SCHEMA> : SCHEMA extends z4.$ZodType ? z4.infer<SCHEMA> : SCHEMA extends Schema<infer T> ? T : never;
|
128
|
+
/**
|
129
|
+
* Create a schema using a JSON Schema.
|
130
|
+
*
|
131
|
+
* @param jsonSchema The JSON Schema for the schema.
|
132
|
+
* @param options.validate Optional. A validation function for the schema.
|
133
|
+
*/
|
134
|
+
declare function jsonSchema<OBJECT = unknown>(jsonSchema: JSONSchema7, { validate, }?: {
|
135
|
+
validate?: (value: unknown) => {
|
136
|
+
success: true;
|
137
|
+
value: OBJECT;
|
138
|
+
} | {
|
139
|
+
success: false;
|
140
|
+
error: Error;
|
141
|
+
};
|
142
|
+
}): Schema<OBJECT>;
|
143
|
+
declare function asSchema<OBJECT>(schema: z4.$ZodType<OBJECT, any> | z3.Schema<OBJECT, z3.ZodTypeDef, any> | Schema<OBJECT> | undefined): Schema<OBJECT>;
|
103
144
|
|
104
145
|
/**
|
105
146
|
* Parses a JSON string into an unknown object.
|
@@ -110,19 +151,19 @@ declare function zodValidator<OBJECT>(zodSchema: z.Schema<OBJECT, z.ZodTypeDef,
|
|
110
151
|
declare function parseJSON(options: {
|
111
152
|
text: string;
|
112
153
|
schema?: undefined;
|
113
|
-
}): JSONValue
|
154
|
+
}): Promise<JSONValue>;
|
114
155
|
/**
|
115
156
|
* Parses a JSON string into a strongly-typed object using the provided schema.
|
116
157
|
*
|
117
158
|
* @template T - The type of the object to parse the JSON into.
|
118
159
|
* @param {string} text - The JSON string to parse.
|
119
160
|
* @param {Validator<T>} schema - The schema to use for parsing the JSON.
|
120
|
-
* @returns {T} - The parsed object.
|
161
|
+
* @returns {Promise<T>} - The parsed object.
|
121
162
|
*/
|
122
|
-
declare function parseJSON<
|
163
|
+
declare function parseJSON<SCHEMA extends z4.$ZodType | z3.Schema | Validator, VALUE = InferSchema<SCHEMA>>(options: {
|
123
164
|
text: string;
|
124
|
-
schema:
|
125
|
-
}):
|
165
|
+
schema: SCHEMA;
|
166
|
+
}): Promise<VALUE>;
|
126
167
|
type ParseResult<T> = {
|
127
168
|
success: true;
|
128
169
|
value: T;
|
@@ -130,17 +171,18 @@ type ParseResult<T> = {
|
|
130
171
|
} | {
|
131
172
|
success: false;
|
132
173
|
error: JSONParseError | TypeValidationError;
|
174
|
+
rawValue: unknown;
|
133
175
|
};
|
134
176
|
/**
|
135
177
|
* Safely parses a JSON string and returns the result as an object of type `unknown`.
|
136
178
|
*
|
137
179
|
* @param text - The JSON string to parse.
|
138
|
-
* @returns {object} Either an object with `success: true` and the parsed data, or an object with `success: false` and the error that occurred.
|
180
|
+
* @returns {Promise<object>} Either an object with `success: true` and the parsed data, or an object with `success: false` and the error that occurred.
|
139
181
|
*/
|
140
182
|
declare function safeParseJSON(options: {
|
141
183
|
text: string;
|
142
184
|
schema?: undefined;
|
143
|
-
}): ParseResult<JSONValue
|
185
|
+
}): Promise<ParseResult<JSONValue>>;
|
144
186
|
/**
|
145
187
|
* Safely parses a JSON string into a strongly-typed object, using a provided schema to validate the object.
|
146
188
|
*
|
@@ -149,10 +191,10 @@ declare function safeParseJSON(options: {
|
|
149
191
|
* @param {Validator<T>} schema - The schema to use for parsing the JSON.
|
150
192
|
* @returns An object with either a `success` flag and the parsed and typed data, or a `success` flag and an error object.
|
151
193
|
*/
|
152
|
-
declare function safeParseJSON<
|
194
|
+
declare function safeParseJSON<SCHEMA extends z4.$ZodType | z3.Schema | Validator, VALUE = InferSchema<SCHEMA>>(options: {
|
153
195
|
text: string;
|
154
|
-
schema:
|
155
|
-
}): ParseResult<
|
196
|
+
schema: SCHEMA;
|
197
|
+
}): Promise<ParseResult<VALUE>>;
|
156
198
|
declare function isParsableJson(input: string): boolean;
|
157
199
|
|
158
200
|
type ResponseHandler<RETURN_TYPE> = (options: {
|
@@ -190,6 +232,23 @@ declare const getFromApi: <T>({ url, headers, successfulResponseHandler, failedR
|
|
190
232
|
|
191
233
|
declare function isAbortError(error: unknown): error is Error;
|
192
234
|
|
235
|
+
/**
|
236
|
+
* Checks if the given URL is supported natively by the model.
|
237
|
+
*
|
238
|
+
* @param mediaType - The media type of the URL. Case-sensitive.
|
239
|
+
* @param url - The URL to check.
|
240
|
+
* @param supportedUrls - A record where keys are case-sensitive media types (or '*')
|
241
|
+
* and values are arrays of RegExp patterns for URLs.
|
242
|
+
*
|
243
|
+
* @returns `true` if the URL matches a pattern under the specific media type
|
244
|
+
* or the wildcard '*', `false` otherwise.
|
245
|
+
*/
|
246
|
+
declare function isUrlSupported({ mediaType, url, supportedUrls, }: {
|
247
|
+
mediaType: string;
|
248
|
+
url: string;
|
249
|
+
supportedUrls: Record<string, RegExp[]>;
|
250
|
+
}): boolean;
|
251
|
+
|
193
252
|
declare function loadApiKey({ apiKey, environmentVariableName, apiKeyParameterName, description, }: {
|
194
253
|
apiKey: string | undefined;
|
195
254
|
environmentVariableName: string;
|
@@ -225,11 +284,19 @@ declare function loadSetting({ settingValue, environmentVariableName, settingNam
|
|
225
284
|
description: string;
|
226
285
|
}): string;
|
227
286
|
|
287
|
+
/**
|
288
|
+
* Parses a JSON event stream into a stream of parsed JSON objects.
|
289
|
+
*/
|
290
|
+
declare function parseJsonEventStream<T>({ stream, schema, }: {
|
291
|
+
stream: ReadableStream<Uint8Array>;
|
292
|
+
schema: ZodSchema<T>;
|
293
|
+
}): ReadableStream<ParseResult<T>>;
|
294
|
+
|
228
295
|
declare function parseProviderOptions<T>({ provider, providerOptions, schema, }: {
|
229
296
|
provider: string;
|
230
297
|
providerOptions: Record<string, unknown> | undefined;
|
231
298
|
schema: z.ZodSchema<T>;
|
232
|
-
}): T | undefined
|
299
|
+
}): Promise<T | undefined>;
|
233
300
|
|
234
301
|
declare const postJsonToApi: <T>({ url, headers, body, failedResponseHandler, successfulResponseHandler, abortSignal, fetch, }: {
|
235
302
|
url: string;
|
@@ -288,44 +355,6 @@ type Resolvable<T> = T | Promise<T> | (() => T) | (() => Promise<T>);
|
|
288
355
|
*/
|
289
356
|
declare function resolve<T>(value: Resolvable<T>): Promise<T>;
|
290
357
|
|
291
|
-
declare function convertBase64ToUint8Array(base64String: string): Uint8Array;
|
292
|
-
declare function convertUint8ArrayToBase64(array: Uint8Array): string;
|
293
|
-
|
294
|
-
/**
|
295
|
-
* Validates the types of an unknown object using a schema and
|
296
|
-
* return a strongly-typed object.
|
297
|
-
*
|
298
|
-
* @template T - The type of the object to validate.
|
299
|
-
* @param {string} options.value - The object to validate.
|
300
|
-
* @param {Validator<T>} options.schema - The schema to use for validating the JSON.
|
301
|
-
* @returns {T} - The typed object.
|
302
|
-
*/
|
303
|
-
declare function validateTypes<T>({ value, schema: inputSchema, }: {
|
304
|
-
value: unknown;
|
305
|
-
schema: z.Schema<T, z.ZodTypeDef, any> | Validator<T>;
|
306
|
-
}): T;
|
307
|
-
/**
|
308
|
-
* Safely validates the types of an unknown object using a schema and
|
309
|
-
* return a strongly-typed object.
|
310
|
-
*
|
311
|
-
* @template T - The type of the object to validate.
|
312
|
-
* @param {string} options.value - The JSON object to validate.
|
313
|
-
* @param {Validator<T>} options.schema - The schema to use for validating the JSON.
|
314
|
-
* @returns An object with either a `success` flag and the parsed and typed data, or a `success` flag and an error object.
|
315
|
-
*/
|
316
|
-
declare function safeValidateTypes<T>({ value, schema, }: {
|
317
|
-
value: unknown;
|
318
|
-
schema: z.Schema<T, z.ZodTypeDef, any> | Validator<T>;
|
319
|
-
}): {
|
320
|
-
success: true;
|
321
|
-
value: T;
|
322
|
-
} | {
|
323
|
-
success: false;
|
324
|
-
error: TypeValidationError;
|
325
|
-
};
|
326
|
-
|
327
|
-
declare function withoutTrailingSlash(url: string | undefined): string | undefined;
|
328
|
-
|
329
358
|
/**
|
330
359
|
Typed tool call that is returned by generateText and streamText.
|
331
360
|
It contains the tool call ID, the tool name, and the tool arguments.
|
@@ -344,10 +373,6 @@ interface ToolCall<NAME extends string, ARGS> {
|
|
344
373
|
*/
|
345
374
|
args: ARGS;
|
346
375
|
}
|
347
|
-
/**
|
348
|
-
* @deprecated Use `ToolCall` instead.
|
349
|
-
*/
|
350
|
-
type CoreToolCall<NAME extends string, ARGS> = ToolCall<NAME, ARGS>;
|
351
376
|
|
352
377
|
/**
|
353
378
|
Typed tool result that is returned by `generateText` and `streamText`.
|
@@ -371,9 +396,68 @@ interface ToolResult<NAME extends string, ARGS, RESULT> {
|
|
371
396
|
*/
|
372
397
|
result: RESULT;
|
373
398
|
}
|
399
|
+
type ToolResultContent = Array<{
|
400
|
+
type: 'text';
|
401
|
+
text: string;
|
402
|
+
} | {
|
403
|
+
type: 'image';
|
404
|
+
data: string;
|
405
|
+
mediaType?: string;
|
406
|
+
/**
|
407
|
+
* @deprecated Use `mediaType` instead.
|
408
|
+
*/
|
409
|
+
mimeType?: string;
|
410
|
+
}>;
|
411
|
+
|
412
|
+
declare function convertBase64ToUint8Array(base64String: string): Uint8Array<ArrayBuffer>;
|
413
|
+
declare function convertUint8ArrayToBase64(array: Uint8Array): string;
|
414
|
+
declare function convertToBase64(value: string | Uint8Array): string;
|
415
|
+
|
416
|
+
/**
|
417
|
+
* Validates the types of an unknown object using a schema and
|
418
|
+
* return a strongly-typed object.
|
419
|
+
*
|
420
|
+
* @template T - The type of the object to validate.
|
421
|
+
* @param {string} options.value - The object to validate.
|
422
|
+
* @param {Validator<T>} options.schema - The schema to use for validating the JSON.
|
423
|
+
* @returns {Promise<T>} - The typed object.
|
424
|
+
*/
|
425
|
+
declare function validateTypes<OBJECT>({ value, schema, }: {
|
426
|
+
value: unknown;
|
427
|
+
schema: StandardSchemaV1<OBJECT> | Validator<OBJECT>;
|
428
|
+
}): Promise<OBJECT>;
|
374
429
|
/**
|
375
|
-
*
|
430
|
+
* Safely validates the types of an unknown object using a schema and
|
431
|
+
* return a strongly-typed object.
|
432
|
+
*
|
433
|
+
* @template T - The type of the object to validate.
|
434
|
+
* @param {string} options.value - The JSON object to validate.
|
435
|
+
* @param {Validator<T>} options.schema - The schema to use for validating the JSON.
|
436
|
+
* @returns An object with either a `success` flag and the parsed and typed data, or a `success` flag and an error object.
|
376
437
|
*/
|
377
|
-
|
438
|
+
declare function safeValidateTypes<OBJECT>({ value, schema, }: {
|
439
|
+
value: unknown;
|
440
|
+
schema: StandardSchemaV1<OBJECT> | Validator<OBJECT>;
|
441
|
+
}): Promise<{
|
442
|
+
success: true;
|
443
|
+
value: OBJECT;
|
444
|
+
rawValue: unknown;
|
445
|
+
} | {
|
446
|
+
success: false;
|
447
|
+
error: TypeValidationError;
|
448
|
+
rawValue: unknown;
|
449
|
+
}>;
|
450
|
+
|
451
|
+
declare function withoutTrailingSlash(url: string | undefined): string | undefined;
|
452
|
+
|
453
|
+
declare function zodSchema<OBJECT>(zodSchema: z4.$ZodType<OBJECT, any> | z3.Schema<OBJECT, z3.ZodTypeDef, any>, options?: {
|
454
|
+
/**
|
455
|
+
* Enables support for references in the schema.
|
456
|
+
* This is required for recursive schemas, e.g. with `z.lazy`.
|
457
|
+
* However, not all language models and providers support such references.
|
458
|
+
* Defaults to `false`.
|
459
|
+
*/
|
460
|
+
useReferences?: boolean;
|
461
|
+
}): Schema<OBJECT>;
|
378
462
|
|
379
|
-
export { type
|
463
|
+
export { type EventSourceChunk, type FetchFunction, type IdGenerator, type InferSchema, type ParseResult, type Resolvable, type ResponseHandler, type Schema, type ToolCall, type ToolResult, type ToolResultContent, type ValidationResult, type Validator, asSchema, asValidator, combineHeaders, convertAsyncIteratorToReadableStream, convertBase64ToUint8Array, convertToBase64, convertUint8ArrayToBase64, createBinaryResponseHandler, createEventSourceParserStream, createEventSourceResponseHandler, createIdGenerator, createJsonErrorResponseHandler, createJsonResponseHandler, createJsonStreamResponseHandler, createStatusCodeErrorResponseHandler, delay, extractResponseHeaders, generateId, getErrorMessage, getFromApi, isAbortError, isParsableJson, isUrlSupported, isValidator, jsonSchema, loadApiKey, loadOptionalSetting, loadSetting, parseJSON, parseJsonEventStream, parseProviderOptions, postFormDataToApi, postJsonToApi, postToApi, removeUndefinedEntries, resolve, safeParseJSON, safeValidateTypes, standardSchemaValidator, validateTypes, validator, validatorSymbol, withoutTrailingSlash, zodSchema };
|