@ai-sdk/provider-utils 2.1.1 → 2.1.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +14 -0
- package/dist/index.d.mts +56 -38
- package/dist/index.d.ts +56 -38
- package/dist/index.js +177 -43
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +154 -23
- package/dist/index.mjs.map +1 -1
- package/package.json +2 -2
package/CHANGELOG.md
CHANGED
@@ -1,5 +1,19 @@
|
|
1
1
|
# @ai-sdk/provider-utils
|
2
2
|
|
3
|
+
## 2.1.3
|
4
|
+
|
5
|
+
### Patch Changes
|
6
|
+
|
7
|
+
- 39e5c1f: feat (provider-utils): add getFromApi and response handlers for binary responses and status-code errors
|
8
|
+
|
9
|
+
## 2.1.2
|
10
|
+
|
11
|
+
### Patch Changes
|
12
|
+
|
13
|
+
- ed012d2: feat (provider): add metadata extraction mechanism to openai-compatible providers
|
14
|
+
- Updated dependencies [3a58a2e]
|
15
|
+
- @ai-sdk/provider@1.0.6
|
16
|
+
|
3
17
|
## 2.1.1
|
4
18
|
|
5
19
|
### Patch Changes
|
package/dist/index.d.mts
CHANGED
@@ -54,43 +54,6 @@ declare const generateId: (size?: number) => string;
|
|
54
54
|
|
55
55
|
declare function getErrorMessage(error: unknown | undefined): string;
|
56
56
|
|
57
|
-
declare function isAbortError(error: unknown): error is Error;
|
58
|
-
|
59
|
-
declare function loadApiKey({ apiKey, environmentVariableName, apiKeyParameterName, description, }: {
|
60
|
-
apiKey: string | undefined;
|
61
|
-
environmentVariableName: string;
|
62
|
-
apiKeyParameterName?: string;
|
63
|
-
description: string;
|
64
|
-
}): string;
|
65
|
-
|
66
|
-
/**
|
67
|
-
* Loads an optional `string` setting from the environment or a parameter.
|
68
|
-
*
|
69
|
-
* @param settingValue - The setting value.
|
70
|
-
* @param environmentVariableName - The environment variable name.
|
71
|
-
* @returns The setting value.
|
72
|
-
*/
|
73
|
-
declare function loadOptionalSetting({ settingValue, environmentVariableName, }: {
|
74
|
-
settingValue: string | undefined;
|
75
|
-
environmentVariableName: string;
|
76
|
-
}): string | undefined;
|
77
|
-
|
78
|
-
/**
|
79
|
-
* Loads a `string` setting from the environment or a parameter.
|
80
|
-
*
|
81
|
-
* @param settingValue - The setting value.
|
82
|
-
* @param environmentVariableName - The environment variable name.
|
83
|
-
* @param settingName - The setting name.
|
84
|
-
* @param description - The description of the setting.
|
85
|
-
* @returns The setting value.
|
86
|
-
*/
|
87
|
-
declare function loadSetting({ settingValue, environmentVariableName, settingName, description, }: {
|
88
|
-
settingValue: string | undefined;
|
89
|
-
environmentVariableName: string;
|
90
|
-
settingName: string;
|
91
|
-
description: string;
|
92
|
-
}): string;
|
93
|
-
|
94
57
|
/**
|
95
58
|
* Used to mark validator functions so we can support both Zod and custom schemas.
|
96
59
|
*/
|
@@ -183,6 +146,7 @@ type ResponseHandler<RETURN_TYPE> = (options: {
|
|
183
146
|
response: Response;
|
184
147
|
}) => PromiseLike<{
|
185
148
|
value: RETURN_TYPE;
|
149
|
+
rawValue?: unknown;
|
186
150
|
responseHeaders?: Record<string, string>;
|
187
151
|
}>;
|
188
152
|
declare const createJsonErrorResponseHandler: <T>({ errorSchema, errorToMessage, isRetryable, }: {
|
@@ -193,6 +157,58 @@ declare const createJsonErrorResponseHandler: <T>({ errorSchema, errorToMessage,
|
|
193
157
|
declare const createEventSourceResponseHandler: <T>(chunkSchema: ZodSchema<T>) => ResponseHandler<ReadableStream<ParseResult<T>>>;
|
194
158
|
declare const createJsonStreamResponseHandler: <T>(chunkSchema: ZodSchema<T>) => ResponseHandler<ReadableStream<ParseResult<T>>>;
|
195
159
|
declare const createJsonResponseHandler: <T>(responseSchema: ZodSchema<T>) => ResponseHandler<T>;
|
160
|
+
declare const createBinaryResponseHandler: () => ResponseHandler<Uint8Array>;
|
161
|
+
declare const createStatusCodeErrorResponseHandler: () => ResponseHandler<APICallError>;
|
162
|
+
|
163
|
+
declare const getFromApi: <T>({ url, headers, successfulResponseHandler, failedResponseHandler, abortSignal, fetch, }: {
|
164
|
+
url: string;
|
165
|
+
headers?: Record<string, string | undefined>;
|
166
|
+
failedResponseHandler: ResponseHandler<Error>;
|
167
|
+
successfulResponseHandler: ResponseHandler<T>;
|
168
|
+
abortSignal?: AbortSignal;
|
169
|
+
fetch?: FetchFunction;
|
170
|
+
}) => Promise<{
|
171
|
+
value: T;
|
172
|
+
rawValue?: unknown;
|
173
|
+
responseHeaders?: Record<string, string>;
|
174
|
+
}>;
|
175
|
+
|
176
|
+
declare function isAbortError(error: unknown): error is Error;
|
177
|
+
|
178
|
+
declare function loadApiKey({ apiKey, environmentVariableName, apiKeyParameterName, description, }: {
|
179
|
+
apiKey: string | undefined;
|
180
|
+
environmentVariableName: string;
|
181
|
+
apiKeyParameterName?: string;
|
182
|
+
description: string;
|
183
|
+
}): string;
|
184
|
+
|
185
|
+
/**
|
186
|
+
* Loads an optional `string` setting from the environment or a parameter.
|
187
|
+
*
|
188
|
+
* @param settingValue - The setting value.
|
189
|
+
* @param environmentVariableName - The environment variable name.
|
190
|
+
* @returns The setting value.
|
191
|
+
*/
|
192
|
+
declare function loadOptionalSetting({ settingValue, environmentVariableName, }: {
|
193
|
+
settingValue: string | undefined;
|
194
|
+
environmentVariableName: string;
|
195
|
+
}): string | undefined;
|
196
|
+
|
197
|
+
/**
|
198
|
+
* Loads a `string` setting from the environment or a parameter.
|
199
|
+
*
|
200
|
+
* @param settingValue - The setting value.
|
201
|
+
* @param environmentVariableName - The environment variable name.
|
202
|
+
* @param settingName - The setting name.
|
203
|
+
* @param description - The description of the setting.
|
204
|
+
* @returns The setting value.
|
205
|
+
*/
|
206
|
+
declare function loadSetting({ settingValue, environmentVariableName, settingName, description, }: {
|
207
|
+
settingValue: string | undefined;
|
208
|
+
environmentVariableName: string;
|
209
|
+
settingName: string;
|
210
|
+
description: string;
|
211
|
+
}): string;
|
196
212
|
|
197
213
|
declare const postJsonToApi: <T>({ url, headers, body, failedResponseHandler, successfulResponseHandler, abortSignal, fetch, }: {
|
198
214
|
url: string;
|
@@ -204,6 +220,7 @@ declare const postJsonToApi: <T>({ url, headers, body, failedResponseHandler, su
|
|
204
220
|
fetch?: FetchFunction;
|
205
221
|
}) => Promise<{
|
206
222
|
value: T;
|
223
|
+
rawValue?: unknown;
|
207
224
|
responseHeaders?: Record<string, string>;
|
208
225
|
}>;
|
209
226
|
declare const postToApi: <T>({ url, headers, body, successfulResponseHandler, failedResponseHandler, abortSignal, fetch, }: {
|
@@ -219,6 +236,7 @@ declare const postToApi: <T>({ url, headers, body, successfulResponseHandler, fa
|
|
219
236
|
fetch?: FetchFunction;
|
220
237
|
}) => Promise<{
|
221
238
|
value: T;
|
239
|
+
rawValue?: unknown;
|
222
240
|
responseHeaders?: Record<string, string>;
|
223
241
|
}>;
|
224
242
|
|
@@ -309,4 +327,4 @@ interface ToolResult<NAME extends string, ARGS, RESULT> {
|
|
309
327
|
result: RESULT;
|
310
328
|
}
|
311
329
|
|
312
|
-
export { type FetchFunction, type IDGenerator, type ParseResult, type Resolvable, type ResponseHandler, type ToolCall, type ToolResult, type ValidationResult, type Validator, asValidator, combineHeaders, convertAsyncIteratorToReadableStream, convertBase64ToUint8Array, convertUint8ArrayToBase64, createEventSourceResponseHandler, createIdGenerator, createJsonErrorResponseHandler, createJsonResponseHandler, createJsonStreamResponseHandler, extractResponseHeaders, generateId, getErrorMessage, isAbortError, isParsableJson, isValidator, loadApiKey, loadOptionalSetting, loadSetting, parseJSON, postJsonToApi, postToApi, resolve, safeParseJSON, safeValidateTypes, validateTypes, validator, validatorSymbol, withoutTrailingSlash, zodValidator };
|
330
|
+
export { type FetchFunction, type IDGenerator, type ParseResult, type Resolvable, type ResponseHandler, type ToolCall, type ToolResult, type ValidationResult, type Validator, asValidator, combineHeaders, convertAsyncIteratorToReadableStream, convertBase64ToUint8Array, convertUint8ArrayToBase64, createBinaryResponseHandler, createEventSourceResponseHandler, createIdGenerator, createJsonErrorResponseHandler, createJsonResponseHandler, createJsonStreamResponseHandler, createStatusCodeErrorResponseHandler, extractResponseHeaders, generateId, getErrorMessage, getFromApi, isAbortError, isParsableJson, isValidator, loadApiKey, loadOptionalSetting, loadSetting, parseJSON, postJsonToApi, postToApi, resolve, safeParseJSON, safeValidateTypes, validateTypes, validator, validatorSymbol, withoutTrailingSlash, zodValidator };
|
package/dist/index.d.ts
CHANGED
@@ -54,43 +54,6 @@ declare const generateId: (size?: number) => string;
|
|
54
54
|
|
55
55
|
declare function getErrorMessage(error: unknown | undefined): string;
|
56
56
|
|
57
|
-
declare function isAbortError(error: unknown): error is Error;
|
58
|
-
|
59
|
-
declare function loadApiKey({ apiKey, environmentVariableName, apiKeyParameterName, description, }: {
|
60
|
-
apiKey: string | undefined;
|
61
|
-
environmentVariableName: string;
|
62
|
-
apiKeyParameterName?: string;
|
63
|
-
description: string;
|
64
|
-
}): string;
|
65
|
-
|
66
|
-
/**
|
67
|
-
* Loads an optional `string` setting from the environment or a parameter.
|
68
|
-
*
|
69
|
-
* @param settingValue - The setting value.
|
70
|
-
* @param environmentVariableName - The environment variable name.
|
71
|
-
* @returns The setting value.
|
72
|
-
*/
|
73
|
-
declare function loadOptionalSetting({ settingValue, environmentVariableName, }: {
|
74
|
-
settingValue: string | undefined;
|
75
|
-
environmentVariableName: string;
|
76
|
-
}): string | undefined;
|
77
|
-
|
78
|
-
/**
|
79
|
-
* Loads a `string` setting from the environment or a parameter.
|
80
|
-
*
|
81
|
-
* @param settingValue - The setting value.
|
82
|
-
* @param environmentVariableName - The environment variable name.
|
83
|
-
* @param settingName - The setting name.
|
84
|
-
* @param description - The description of the setting.
|
85
|
-
* @returns The setting value.
|
86
|
-
*/
|
87
|
-
declare function loadSetting({ settingValue, environmentVariableName, settingName, description, }: {
|
88
|
-
settingValue: string | undefined;
|
89
|
-
environmentVariableName: string;
|
90
|
-
settingName: string;
|
91
|
-
description: string;
|
92
|
-
}): string;
|
93
|
-
|
94
57
|
/**
|
95
58
|
* Used to mark validator functions so we can support both Zod and custom schemas.
|
96
59
|
*/
|
@@ -183,6 +146,7 @@ type ResponseHandler<RETURN_TYPE> = (options: {
|
|
183
146
|
response: Response;
|
184
147
|
}) => PromiseLike<{
|
185
148
|
value: RETURN_TYPE;
|
149
|
+
rawValue?: unknown;
|
186
150
|
responseHeaders?: Record<string, string>;
|
187
151
|
}>;
|
188
152
|
declare const createJsonErrorResponseHandler: <T>({ errorSchema, errorToMessage, isRetryable, }: {
|
@@ -193,6 +157,58 @@ declare const createJsonErrorResponseHandler: <T>({ errorSchema, errorToMessage,
|
|
193
157
|
declare const createEventSourceResponseHandler: <T>(chunkSchema: ZodSchema<T>) => ResponseHandler<ReadableStream<ParseResult<T>>>;
|
194
158
|
declare const createJsonStreamResponseHandler: <T>(chunkSchema: ZodSchema<T>) => ResponseHandler<ReadableStream<ParseResult<T>>>;
|
195
159
|
declare const createJsonResponseHandler: <T>(responseSchema: ZodSchema<T>) => ResponseHandler<T>;
|
160
|
+
declare const createBinaryResponseHandler: () => ResponseHandler<Uint8Array>;
|
161
|
+
declare const createStatusCodeErrorResponseHandler: () => ResponseHandler<APICallError>;
|
162
|
+
|
163
|
+
declare const getFromApi: <T>({ url, headers, successfulResponseHandler, failedResponseHandler, abortSignal, fetch, }: {
|
164
|
+
url: string;
|
165
|
+
headers?: Record<string, string | undefined>;
|
166
|
+
failedResponseHandler: ResponseHandler<Error>;
|
167
|
+
successfulResponseHandler: ResponseHandler<T>;
|
168
|
+
abortSignal?: AbortSignal;
|
169
|
+
fetch?: FetchFunction;
|
170
|
+
}) => Promise<{
|
171
|
+
value: T;
|
172
|
+
rawValue?: unknown;
|
173
|
+
responseHeaders?: Record<string, string>;
|
174
|
+
}>;
|
175
|
+
|
176
|
+
declare function isAbortError(error: unknown): error is Error;
|
177
|
+
|
178
|
+
declare function loadApiKey({ apiKey, environmentVariableName, apiKeyParameterName, description, }: {
|
179
|
+
apiKey: string | undefined;
|
180
|
+
environmentVariableName: string;
|
181
|
+
apiKeyParameterName?: string;
|
182
|
+
description: string;
|
183
|
+
}): string;
|
184
|
+
|
185
|
+
/**
|
186
|
+
* Loads an optional `string` setting from the environment or a parameter.
|
187
|
+
*
|
188
|
+
* @param settingValue - The setting value.
|
189
|
+
* @param environmentVariableName - The environment variable name.
|
190
|
+
* @returns The setting value.
|
191
|
+
*/
|
192
|
+
declare function loadOptionalSetting({ settingValue, environmentVariableName, }: {
|
193
|
+
settingValue: string | undefined;
|
194
|
+
environmentVariableName: string;
|
195
|
+
}): string | undefined;
|
196
|
+
|
197
|
+
/**
|
198
|
+
* Loads a `string` setting from the environment or a parameter.
|
199
|
+
*
|
200
|
+
* @param settingValue - The setting value.
|
201
|
+
* @param environmentVariableName - The environment variable name.
|
202
|
+
* @param settingName - The setting name.
|
203
|
+
* @param description - The description of the setting.
|
204
|
+
* @returns The setting value.
|
205
|
+
*/
|
206
|
+
declare function loadSetting({ settingValue, environmentVariableName, settingName, description, }: {
|
207
|
+
settingValue: string | undefined;
|
208
|
+
environmentVariableName: string;
|
209
|
+
settingName: string;
|
210
|
+
description: string;
|
211
|
+
}): string;
|
196
212
|
|
197
213
|
declare const postJsonToApi: <T>({ url, headers, body, failedResponseHandler, successfulResponseHandler, abortSignal, fetch, }: {
|
198
214
|
url: string;
|
@@ -204,6 +220,7 @@ declare const postJsonToApi: <T>({ url, headers, body, failedResponseHandler, su
|
|
204
220
|
fetch?: FetchFunction;
|
205
221
|
}) => Promise<{
|
206
222
|
value: T;
|
223
|
+
rawValue?: unknown;
|
207
224
|
responseHeaders?: Record<string, string>;
|
208
225
|
}>;
|
209
226
|
declare const postToApi: <T>({ url, headers, body, successfulResponseHandler, failedResponseHandler, abortSignal, fetch, }: {
|
@@ -219,6 +236,7 @@ declare const postToApi: <T>({ url, headers, body, successfulResponseHandler, fa
|
|
219
236
|
fetch?: FetchFunction;
|
220
237
|
}) => Promise<{
|
221
238
|
value: T;
|
239
|
+
rawValue?: unknown;
|
222
240
|
responseHeaders?: Record<string, string>;
|
223
241
|
}>;
|
224
242
|
|
@@ -309,4 +327,4 @@ interface ToolResult<NAME extends string, ARGS, RESULT> {
|
|
309
327
|
result: RESULT;
|
310
328
|
}
|
311
329
|
|
312
|
-
export { type FetchFunction, type IDGenerator, type ParseResult, type Resolvable, type ResponseHandler, type ToolCall, type ToolResult, type ValidationResult, type Validator, asValidator, combineHeaders, convertAsyncIteratorToReadableStream, convertBase64ToUint8Array, convertUint8ArrayToBase64, createEventSourceResponseHandler, createIdGenerator, createJsonErrorResponseHandler, createJsonResponseHandler, createJsonStreamResponseHandler, extractResponseHeaders, generateId, getErrorMessage, isAbortError, isParsableJson, isValidator, loadApiKey, loadOptionalSetting, loadSetting, parseJSON, postJsonToApi, postToApi, resolve, safeParseJSON, safeValidateTypes, validateTypes, validator, validatorSymbol, withoutTrailingSlash, zodValidator };
|
330
|
+
export { type FetchFunction, type IDGenerator, type ParseResult, type Resolvable, type ResponseHandler, type ToolCall, type ToolResult, type ValidationResult, type Validator, asValidator, combineHeaders, convertAsyncIteratorToReadableStream, convertBase64ToUint8Array, convertUint8ArrayToBase64, createBinaryResponseHandler, createEventSourceResponseHandler, createIdGenerator, createJsonErrorResponseHandler, createJsonResponseHandler, createJsonStreamResponseHandler, createStatusCodeErrorResponseHandler, extractResponseHeaders, generateId, getErrorMessage, getFromApi, isAbortError, isParsableJson, isValidator, loadApiKey, loadOptionalSetting, loadSetting, parseJSON, postJsonToApi, postToApi, resolve, safeParseJSON, safeValidateTypes, validateTypes, validator, validatorSymbol, withoutTrailingSlash, zodValidator };
|