@ai-sdk/provider-utils 4.0.4 → 4.0.6
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.js +6 -4
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +6 -4
- package/dist/index.mjs.map +1 -1
- package/package.json +4 -2
- package/src/__snapshots__/schema.test.ts.snap +346 -0
- package/src/add-additional-properties-to-json-schema.test.ts +289 -0
- package/src/add-additional-properties-to-json-schema.ts +53 -0
- package/src/combine-headers.ts +11 -0
- package/src/convert-async-iterator-to-readable-stream.test.ts +78 -0
- package/src/convert-async-iterator-to-readable-stream.ts +47 -0
- package/src/convert-image-model-file-to-data-uri.test.ts +85 -0
- package/src/convert-image-model-file-to-data-uri.ts +19 -0
- package/src/convert-to-form-data.test.ts +167 -0
- package/src/convert-to-form-data.ts +61 -0
- package/src/create-tool-name-mapping.test.ts +163 -0
- package/src/create-tool-name-mapping.ts +66 -0
- package/src/delay.test.ts +212 -0
- package/src/delay.ts +47 -0
- package/src/delayed-promise.test.ts +132 -0
- package/src/delayed-promise.ts +61 -0
- package/src/download-blob.test.ts +145 -0
- package/src/download-blob.ts +31 -0
- package/src/download-error.ts +39 -0
- package/src/extract-response-headers.ts +9 -0
- package/src/fetch-function.ts +4 -0
- package/src/generate-id.test.ts +31 -0
- package/src/generate-id.ts +57 -0
- package/src/get-error-message.ts +15 -0
- package/src/get-from-api.test.ts +199 -0
- package/src/get-from-api.ts +97 -0
- package/src/get-runtime-environment-user-agent.test.ts +47 -0
- package/src/get-runtime-environment-user-agent.ts +24 -0
- package/src/handle-fetch-error.ts +39 -0
- package/src/index.ts +67 -0
- package/src/inject-json-instruction.test.ts +404 -0
- package/src/inject-json-instruction.ts +63 -0
- package/src/is-abort-error.ts +8 -0
- package/src/is-async-iterable.ts +3 -0
- package/src/is-non-nullable.ts +12 -0
- package/src/is-url-supported.test.ts +282 -0
- package/src/is-url-supported.ts +40 -0
- package/src/load-api-key.ts +45 -0
- package/src/load-optional-setting.ts +30 -0
- package/src/load-setting.ts +62 -0
- package/src/maybe-promise-like.ts +3 -0
- package/src/media-type-to-extension.test.ts +26 -0
- package/src/media-type-to-extension.ts +22 -0
- package/src/normalize-headers.test.ts +64 -0
- package/src/normalize-headers.ts +38 -0
- package/src/parse-json-event-stream.ts +33 -0
- package/src/parse-json.test.ts +191 -0
- package/src/parse-json.ts +122 -0
- package/src/parse-provider-options.ts +32 -0
- package/src/post-to-api.ts +166 -0
- package/src/provider-tool-factory.ts +125 -0
- package/src/remove-undefined-entries.test.ts +57 -0
- package/src/remove-undefined-entries.ts +12 -0
- package/src/resolve.test.ts +125 -0
- package/src/resolve.ts +17 -0
- package/src/response-handler.test.ts +89 -0
- package/src/response-handler.ts +187 -0
- package/src/schema.test-d.ts +11 -0
- package/src/schema.test.ts +502 -0
- package/src/schema.ts +267 -0
- package/src/secure-json-parse.test.ts +59 -0
- package/src/secure-json-parse.ts +92 -0
- package/src/test/convert-array-to-async-iterable.ts +9 -0
- package/src/test/convert-array-to-readable-stream.ts +15 -0
- package/src/test/convert-async-iterable-to-array.ts +9 -0
- package/src/test/convert-readable-stream-to-array.ts +14 -0
- package/src/test/convert-response-stream-to-array.ts +9 -0
- package/src/test/index.ts +7 -0
- package/src/test/is-node-version.ts +4 -0
- package/src/test/mock-id.ts +8 -0
- package/src/to-json-schema/zod3-to-json-schema/LICENSE +16 -0
- package/src/to-json-schema/zod3-to-json-schema/README.md +24 -0
- package/src/to-json-schema/zod3-to-json-schema/get-relative-path.ts +7 -0
- package/src/to-json-schema/zod3-to-json-schema/index.ts +1 -0
- package/src/to-json-schema/zod3-to-json-schema/options.ts +98 -0
- package/src/to-json-schema/zod3-to-json-schema/parse-def.test.ts +224 -0
- package/src/to-json-schema/zod3-to-json-schema/parse-def.ts +109 -0
- package/src/to-json-schema/zod3-to-json-schema/parse-types.ts +57 -0
- package/src/to-json-schema/zod3-to-json-schema/parsers/any.ts +5 -0
- package/src/to-json-schema/zod3-to-json-schema/parsers/array.test.ts +98 -0
- package/src/to-json-schema/zod3-to-json-schema/parsers/array.ts +38 -0
- package/src/to-json-schema/zod3-to-json-schema/parsers/bigint.test.ts +51 -0
- package/src/to-json-schema/zod3-to-json-schema/parsers/bigint.ts +44 -0
- package/src/to-json-schema/zod3-to-json-schema/parsers/boolean.ts +7 -0
- package/src/to-json-schema/zod3-to-json-schema/parsers/branded.test.ts +16 -0
- package/src/to-json-schema/zod3-to-json-schema/parsers/branded.ts +7 -0
- package/src/to-json-schema/zod3-to-json-schema/parsers/catch.test.ts +15 -0
- package/src/to-json-schema/zod3-to-json-schema/parsers/catch.ts +7 -0
- package/src/to-json-schema/zod3-to-json-schema/parsers/date.test.ts +97 -0
- package/src/to-json-schema/zod3-to-json-schema/parsers/date.ts +64 -0
- package/src/to-json-schema/zod3-to-json-schema/parsers/default.test.ts +54 -0
- package/src/to-json-schema/zod3-to-json-schema/parsers/default.ts +14 -0
- package/src/to-json-schema/zod3-to-json-schema/parsers/effects.test.ts +41 -0
- package/src/to-json-schema/zod3-to-json-schema/parsers/effects.ts +14 -0
- package/src/to-json-schema/zod3-to-json-schema/parsers/enum.ts +13 -0
- package/src/to-json-schema/zod3-to-json-schema/parsers/intersection.test.ts +92 -0
- package/src/to-json-schema/zod3-to-json-schema/parsers/intersection.ts +52 -0
- package/src/to-json-schema/zod3-to-json-schema/parsers/literal.ts +29 -0
- package/src/to-json-schema/zod3-to-json-schema/parsers/map.test.ts +48 -0
- package/src/to-json-schema/zod3-to-json-schema/parsers/map.ts +47 -0
- package/src/to-json-schema/zod3-to-json-schema/parsers/native-enum.test.ts +102 -0
- package/src/to-json-schema/zod3-to-json-schema/parsers/native-enum.ts +31 -0
- package/src/to-json-schema/zod3-to-json-schema/parsers/never.ts +9 -0
- package/src/to-json-schema/zod3-to-json-schema/parsers/null.ts +9 -0
- package/src/to-json-schema/zod3-to-json-schema/parsers/nullable.test.ts +67 -0
- package/src/to-json-schema/zod3-to-json-schema/parsers/nullable.ts +42 -0
- package/src/to-json-schema/zod3-to-json-schema/parsers/number.test.ts +65 -0
- package/src/to-json-schema/zod3-to-json-schema/parsers/number.ts +44 -0
- package/src/to-json-schema/zod3-to-json-schema/parsers/object.test.ts +149 -0
- package/src/to-json-schema/zod3-to-json-schema/parsers/object.ts +88 -0
- package/src/to-json-schema/zod3-to-json-schema/parsers/optional.test.ts +147 -0
- package/src/to-json-schema/zod3-to-json-schema/parsers/optional.ts +23 -0
- package/src/to-json-schema/zod3-to-json-schema/parsers/pipe.test.ts +35 -0
- package/src/to-json-schema/zod3-to-json-schema/parsers/pipeline.ts +29 -0
- package/src/to-json-schema/zod3-to-json-schema/parsers/promise.test.ts +15 -0
- package/src/to-json-schema/zod3-to-json-schema/parsers/promise.ts +11 -0
- package/src/to-json-schema/zod3-to-json-schema/parsers/readonly.test.ts +20 -0
- package/src/to-json-schema/zod3-to-json-schema/parsers/readonly.ts +7 -0
- package/src/to-json-schema/zod3-to-json-schema/parsers/record.test.ts +108 -0
- package/src/to-json-schema/zod3-to-json-schema/parsers/record.ts +71 -0
- package/src/to-json-schema/zod3-to-json-schema/parsers/set.test.ts +20 -0
- package/src/to-json-schema/zod3-to-json-schema/parsers/set.ts +35 -0
- package/src/to-json-schema/zod3-to-json-schema/parsers/string.test.ts +438 -0
- package/src/to-json-schema/zod3-to-json-schema/parsers/string.ts +426 -0
- package/src/to-json-schema/zod3-to-json-schema/parsers/tuple.test.ts +33 -0
- package/src/to-json-schema/zod3-to-json-schema/parsers/tuple.ts +61 -0
- package/src/to-json-schema/zod3-to-json-schema/parsers/undefined.ts +11 -0
- package/src/to-json-schema/zod3-to-json-schema/parsers/union.test.ts +226 -0
- package/src/to-json-schema/zod3-to-json-schema/parsers/union.ts +144 -0
- package/src/to-json-schema/zod3-to-json-schema/parsers/unknown.ts +7 -0
- package/src/to-json-schema/zod3-to-json-schema/refs.test.ts +919 -0
- package/src/to-json-schema/zod3-to-json-schema/refs.ts +39 -0
- package/src/to-json-schema/zod3-to-json-schema/select-parser.ts +115 -0
- package/src/to-json-schema/zod3-to-json-schema/zod3-to-json-schema.test.ts +862 -0
- package/src/to-json-schema/zod3-to-json-schema/zod3-to-json-schema.ts +93 -0
- package/src/types/assistant-model-message.ts +39 -0
- package/src/types/content-part.ts +379 -0
- package/src/types/data-content.ts +4 -0
- package/src/types/execute-tool.ts +27 -0
- package/src/types/index.ts +40 -0
- package/src/types/model-message.ts +14 -0
- package/src/types/provider-options.ts +9 -0
- package/src/types/system-model-message.ts +20 -0
- package/src/types/tool-approval-request.ts +16 -0
- package/src/types/tool-approval-response.ts +27 -0
- package/src/types/tool-call.ts +31 -0
- package/src/types/tool-model-message.ts +23 -0
- package/src/types/tool-result.ts +35 -0
- package/src/types/tool.test-d.ts +193 -0
- package/src/types/tool.ts +324 -0
- package/src/types/user-model-message.ts +22 -0
- package/src/uint8-utils.ts +26 -0
- package/src/validate-types.test.ts +105 -0
- package/src/validate-types.ts +81 -0
- package/src/version.ts +6 -0
- package/src/with-user-agent-suffix.test.ts +84 -0
- package/src/with-user-agent-suffix.ts +27 -0
- package/src/without-trailing-slash.ts +3 -0
- package/LICENSE +0 -13
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { ZodTypeDef } from 'zod/v3';
|
|
2
|
+
import { getDefaultOptions, Options } from './options';
|
|
3
|
+
import { JsonSchema7Type } from './parse-types';
|
|
4
|
+
|
|
5
|
+
export type Refs = {
|
|
6
|
+
seen: Map<ZodTypeDef, Seen>;
|
|
7
|
+
currentPath: string[];
|
|
8
|
+
propertyPath: string[] | undefined;
|
|
9
|
+
} & Options;
|
|
10
|
+
|
|
11
|
+
export type Seen = {
|
|
12
|
+
def: ZodTypeDef;
|
|
13
|
+
path: string[];
|
|
14
|
+
jsonSchema: JsonSchema7Type | undefined;
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
export const getRefs = (options?: string | Partial<Options>): Refs => {
|
|
18
|
+
const _options = getDefaultOptions(options);
|
|
19
|
+
const currentPath =
|
|
20
|
+
_options.name !== undefined
|
|
21
|
+
? [..._options.basePath, _options.definitionPath, _options.name]
|
|
22
|
+
: _options.basePath;
|
|
23
|
+
return {
|
|
24
|
+
..._options,
|
|
25
|
+
currentPath: currentPath,
|
|
26
|
+
propertyPath: undefined,
|
|
27
|
+
seen: new Map(
|
|
28
|
+
Object.entries(_options.definitions).map(([name, def]) => [
|
|
29
|
+
def._def,
|
|
30
|
+
{
|
|
31
|
+
def: def._def,
|
|
32
|
+
path: [..._options.basePath, _options.definitionPath, name],
|
|
33
|
+
// Resolution of references will be forced even though seen, so it's ok that the schema is undefined here for now.
|
|
34
|
+
jsonSchema: undefined,
|
|
35
|
+
},
|
|
36
|
+
]),
|
|
37
|
+
),
|
|
38
|
+
};
|
|
39
|
+
};
|
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
import { ZodFirstPartyTypeKind } from 'zod/v3';
|
|
2
|
+
import { parseAnyDef } from './parsers/any';
|
|
3
|
+
import { parseArrayDef } from './parsers/array';
|
|
4
|
+
import { parseBigintDef } from './parsers/bigint';
|
|
5
|
+
import { parseBooleanDef } from './parsers/boolean';
|
|
6
|
+
import { parseBrandedDef } from './parsers/branded';
|
|
7
|
+
import { parseCatchDef } from './parsers/catch';
|
|
8
|
+
import { parseDateDef } from './parsers/date';
|
|
9
|
+
import { parseDefaultDef } from './parsers/default';
|
|
10
|
+
import { parseEffectsDef } from './parsers/effects';
|
|
11
|
+
import { parseEnumDef } from './parsers/enum';
|
|
12
|
+
import { parseIntersectionDef } from './parsers/intersection';
|
|
13
|
+
import { parseLiteralDef } from './parsers/literal';
|
|
14
|
+
import { parseMapDef } from './parsers/map';
|
|
15
|
+
import { parseNativeEnumDef } from './parsers/native-enum';
|
|
16
|
+
import { parseNeverDef } from './parsers/never';
|
|
17
|
+
import { parseNullDef } from './parsers/null';
|
|
18
|
+
import { parseNullableDef } from './parsers/nullable';
|
|
19
|
+
import { parseNumberDef } from './parsers/number';
|
|
20
|
+
import { parseObjectDef } from './parsers/object';
|
|
21
|
+
import { parseOptionalDef } from './parsers/optional';
|
|
22
|
+
import { parsePipelineDef } from './parsers/pipeline';
|
|
23
|
+
import { parsePromiseDef } from './parsers/promise';
|
|
24
|
+
import { parseRecordDef } from './parsers/record';
|
|
25
|
+
import { parseSetDef } from './parsers/set';
|
|
26
|
+
import { parseStringDef } from './parsers/string';
|
|
27
|
+
import { parseTupleDef } from './parsers/tuple';
|
|
28
|
+
import { parseUndefinedDef } from './parsers/undefined';
|
|
29
|
+
import { parseUnionDef } from './parsers/union';
|
|
30
|
+
import { parseUnknownDef } from './parsers/unknown';
|
|
31
|
+
import { Refs } from './refs';
|
|
32
|
+
import { parseReadonlyDef } from './parsers/readonly';
|
|
33
|
+
import { JsonSchema7Type } from './parse-types';
|
|
34
|
+
|
|
35
|
+
export type InnerDefGetter = () => any;
|
|
36
|
+
|
|
37
|
+
export const selectParser = (
|
|
38
|
+
def: any,
|
|
39
|
+
typeName: ZodFirstPartyTypeKind,
|
|
40
|
+
refs: Refs,
|
|
41
|
+
): JsonSchema7Type | undefined | InnerDefGetter => {
|
|
42
|
+
switch (typeName) {
|
|
43
|
+
case ZodFirstPartyTypeKind.ZodString:
|
|
44
|
+
return parseStringDef(def, refs);
|
|
45
|
+
case ZodFirstPartyTypeKind.ZodNumber:
|
|
46
|
+
return parseNumberDef(def);
|
|
47
|
+
case ZodFirstPartyTypeKind.ZodObject:
|
|
48
|
+
return parseObjectDef(def, refs);
|
|
49
|
+
case ZodFirstPartyTypeKind.ZodBigInt:
|
|
50
|
+
return parseBigintDef(def);
|
|
51
|
+
case ZodFirstPartyTypeKind.ZodBoolean:
|
|
52
|
+
return parseBooleanDef();
|
|
53
|
+
case ZodFirstPartyTypeKind.ZodDate:
|
|
54
|
+
return parseDateDef(def, refs);
|
|
55
|
+
case ZodFirstPartyTypeKind.ZodUndefined:
|
|
56
|
+
return parseUndefinedDef();
|
|
57
|
+
case ZodFirstPartyTypeKind.ZodNull:
|
|
58
|
+
return parseNullDef();
|
|
59
|
+
case ZodFirstPartyTypeKind.ZodArray:
|
|
60
|
+
return parseArrayDef(def, refs);
|
|
61
|
+
case ZodFirstPartyTypeKind.ZodUnion:
|
|
62
|
+
case ZodFirstPartyTypeKind.ZodDiscriminatedUnion:
|
|
63
|
+
return parseUnionDef(def, refs);
|
|
64
|
+
case ZodFirstPartyTypeKind.ZodIntersection:
|
|
65
|
+
return parseIntersectionDef(def, refs);
|
|
66
|
+
case ZodFirstPartyTypeKind.ZodTuple:
|
|
67
|
+
return parseTupleDef(def, refs);
|
|
68
|
+
case ZodFirstPartyTypeKind.ZodRecord:
|
|
69
|
+
return parseRecordDef(def, refs);
|
|
70
|
+
case ZodFirstPartyTypeKind.ZodLiteral:
|
|
71
|
+
return parseLiteralDef(def);
|
|
72
|
+
case ZodFirstPartyTypeKind.ZodEnum:
|
|
73
|
+
return parseEnumDef(def);
|
|
74
|
+
case ZodFirstPartyTypeKind.ZodNativeEnum:
|
|
75
|
+
return parseNativeEnumDef(def);
|
|
76
|
+
case ZodFirstPartyTypeKind.ZodNullable:
|
|
77
|
+
return parseNullableDef(def, refs);
|
|
78
|
+
case ZodFirstPartyTypeKind.ZodOptional:
|
|
79
|
+
return parseOptionalDef(def, refs);
|
|
80
|
+
case ZodFirstPartyTypeKind.ZodMap:
|
|
81
|
+
return parseMapDef(def, refs);
|
|
82
|
+
case ZodFirstPartyTypeKind.ZodSet:
|
|
83
|
+
return parseSetDef(def, refs);
|
|
84
|
+
case ZodFirstPartyTypeKind.ZodLazy:
|
|
85
|
+
return () => (def as any).getter()._def;
|
|
86
|
+
case ZodFirstPartyTypeKind.ZodPromise:
|
|
87
|
+
return parsePromiseDef(def, refs);
|
|
88
|
+
case ZodFirstPartyTypeKind.ZodNaN:
|
|
89
|
+
case ZodFirstPartyTypeKind.ZodNever:
|
|
90
|
+
return parseNeverDef();
|
|
91
|
+
case ZodFirstPartyTypeKind.ZodEffects:
|
|
92
|
+
return parseEffectsDef(def, refs);
|
|
93
|
+
case ZodFirstPartyTypeKind.ZodAny:
|
|
94
|
+
return parseAnyDef();
|
|
95
|
+
case ZodFirstPartyTypeKind.ZodUnknown:
|
|
96
|
+
return parseUnknownDef();
|
|
97
|
+
case ZodFirstPartyTypeKind.ZodDefault:
|
|
98
|
+
return parseDefaultDef(def, refs);
|
|
99
|
+
case ZodFirstPartyTypeKind.ZodBranded:
|
|
100
|
+
return parseBrandedDef(def, refs);
|
|
101
|
+
case ZodFirstPartyTypeKind.ZodReadonly:
|
|
102
|
+
return parseReadonlyDef(def, refs);
|
|
103
|
+
case ZodFirstPartyTypeKind.ZodCatch:
|
|
104
|
+
return parseCatchDef(def, refs);
|
|
105
|
+
case ZodFirstPartyTypeKind.ZodPipeline:
|
|
106
|
+
return parsePipelineDef(def, refs);
|
|
107
|
+
case ZodFirstPartyTypeKind.ZodFunction:
|
|
108
|
+
case ZodFirstPartyTypeKind.ZodVoid:
|
|
109
|
+
case ZodFirstPartyTypeKind.ZodSymbol:
|
|
110
|
+
return undefined;
|
|
111
|
+
default:
|
|
112
|
+
/* c8 ignore next */
|
|
113
|
+
return ((_: never) => undefined)(typeName);
|
|
114
|
+
}
|
|
115
|
+
};
|