@ai-sdk/provider-utils 5.0.24 → 5.0.26
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 +3 -3
- package/dist/index.js +8 -4
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
- package/src/safe-node-fetch.ts +5 -1
- package/src/schema.ts +9 -10
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ai-sdk/provider-utils",
|
|
3
|
-
"version": "5.0.
|
|
3
|
+
"version": "5.0.26",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"sideEffects": false,
|
|
@@ -36,7 +36,7 @@
|
|
|
36
36
|
"@workflow/serde": "4.1.0",
|
|
37
37
|
"eventsource-parser": "^3.0.8",
|
|
38
38
|
"undici": "^7.28.0",
|
|
39
|
-
"@ai-sdk/provider": "4.0.
|
|
39
|
+
"@ai-sdk/provider": "4.0.7"
|
|
40
40
|
},
|
|
41
41
|
"devDependencies": {
|
|
42
42
|
"@types/node": "22.19.19",
|
package/src/safe-node-fetch.ts
CHANGED
|
@@ -131,7 +131,11 @@ export async function getDefaultDownloadFetch(): Promise<FetchFunction> {
|
|
|
131
131
|
return (safeNodeFetchPromise ??= Promise.resolve().then(createSafeNodeFetch));
|
|
132
132
|
}
|
|
133
133
|
|
|
134
|
-
function isNodeDefaultFetch(fetch:
|
|
134
|
+
function isNodeDefaultFetch(fetch: unknown): boolean {
|
|
135
|
+
if (typeof fetch !== 'function') {
|
|
136
|
+
return false;
|
|
137
|
+
}
|
|
138
|
+
|
|
135
139
|
const source = Function.prototype.toString.call(fetch);
|
|
136
140
|
return (
|
|
137
141
|
source.includes('internal/deps/undici') ||
|
package/src/schema.ts
CHANGED
|
@@ -4,7 +4,8 @@ import type {
|
|
|
4
4
|
StandardJSONSchemaV1,
|
|
5
5
|
} from '@standard-schema/spec';
|
|
6
6
|
import type * as z3 from 'zod/v3';
|
|
7
|
-
import
|
|
7
|
+
import { safeParseAsync } from 'zod/v4';
|
|
8
|
+
import { toJSONSchema, type $ZodType } from 'zod/v4/core';
|
|
8
9
|
import { addAdditionalPropertiesToJsonSchema } from './add-additional-properties-to-json-schema';
|
|
9
10
|
import { zod3ToJsonSchema } from './to-json-schema/zod3-to-json-schema';
|
|
10
11
|
|
|
@@ -67,7 +68,7 @@ export type LazySchema<SCHEMA> = () => Schema<SCHEMA>;
|
|
|
67
68
|
|
|
68
69
|
export type ZodSchema<SCHEMA = any> =
|
|
69
70
|
| z3.Schema<SCHEMA, z3.ZodTypeDef, any>
|
|
70
|
-
|
|
|
71
|
+
| $ZodType<SCHEMA, any>;
|
|
71
72
|
|
|
72
73
|
export type StandardSchema<SCHEMA = any> = StandardSchemaV1<unknown, SCHEMA> & {
|
|
73
74
|
readonly '~standard': StandardSchemaV1.Props<unknown, SCHEMA> & {
|
|
@@ -229,7 +230,7 @@ export function zod3Schema<OBJECT>(
|
|
|
229
230
|
}
|
|
230
231
|
|
|
231
232
|
export function zod4Schema<OBJECT>(
|
|
232
|
-
zodSchema:
|
|
233
|
+
zodSchema: $ZodType<OBJECT, any>,
|
|
233
234
|
options?: {
|
|
234
235
|
/**
|
|
235
236
|
* Enables support for references in the schema.
|
|
@@ -247,7 +248,7 @@ export function zod4Schema<OBJECT>(
|
|
|
247
248
|
// defer json schema creation to avoid unnecessary computation when only validation is needed
|
|
248
249
|
() =>
|
|
249
250
|
addAdditionalPropertiesToJsonSchema(
|
|
250
|
-
|
|
251
|
+
toJSONSchema(zodSchema, {
|
|
251
252
|
target: 'draft-7',
|
|
252
253
|
io: 'input',
|
|
253
254
|
reused: useReferences ? 'ref' : 'inline',
|
|
@@ -255,7 +256,7 @@ export function zod4Schema<OBJECT>(
|
|
|
255
256
|
),
|
|
256
257
|
{
|
|
257
258
|
validate: async value => {
|
|
258
|
-
const result = await
|
|
259
|
+
const result = await safeParseAsync(zodSchema, value);
|
|
259
260
|
return result.success
|
|
260
261
|
? { success: true, value: result.data }
|
|
261
262
|
: { success: false, error: result.error };
|
|
@@ -265,16 +266,14 @@ export function zod4Schema<OBJECT>(
|
|
|
265
266
|
}
|
|
266
267
|
|
|
267
268
|
export function isZod4Schema(
|
|
268
|
-
zodSchema:
|
|
269
|
-
): zodSchema is
|
|
269
|
+
zodSchema: $ZodType<any, any> | z3.Schema<any, z3.ZodTypeDef, any>,
|
|
270
|
+
): zodSchema is $ZodType<any, any> {
|
|
270
271
|
// https://zod.dev/library-authors?id=how-to-support-zod-3-and-zod-4-simultaneously
|
|
271
272
|
return '_zod' in zodSchema;
|
|
272
273
|
}
|
|
273
274
|
|
|
274
275
|
export function zodSchema<OBJECT>(
|
|
275
|
-
zodSchema:
|
|
276
|
-
| z4.core.$ZodType<OBJECT, any>
|
|
277
|
-
| z3.Schema<OBJECT, z3.ZodTypeDef, any>,
|
|
276
|
+
zodSchema: $ZodType<OBJECT, any> | z3.Schema<OBJECT, z3.ZodTypeDef, any>,
|
|
278
277
|
options?: {
|
|
279
278
|
/**
|
|
280
279
|
* Enables support for references in the schema.
|