@ai-sdk/provider-utils 5.0.0-beta.9 → 5.0.0-canary.32

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.
Files changed (105) hide show
  1. package/CHANGELOG.md +184 -0
  2. package/dist/index.d.ts +1346 -878
  3. package/dist/index.js +813 -325
  4. package/dist/index.js.map +1 -1
  5. package/dist/test/index.d.ts +2 -1
  6. package/dist/test/index.js +18 -37
  7. package/dist/test/index.js.map +1 -1
  8. package/package.json +13 -11
  9. package/src/add-additional-properties-to-json-schema.ts +1 -1
  10. package/src/as-array.ts +12 -0
  11. package/src/convert-image-model-file-to-data-uri.ts +1 -1
  12. package/src/convert-inline-file-data-to-uint8-array.ts +30 -0
  13. package/src/create-tool-name-mapping.ts +1 -1
  14. package/src/detect-media-type.ts +312 -0
  15. package/src/filter-nullable.ts +11 -0
  16. package/src/get-error-message.ts +1 -15
  17. package/src/get-from-api.ts +2 -2
  18. package/src/has-required-key.ts +6 -0
  19. package/src/index.ts +39 -14
  20. package/src/inject-json-instruction.ts +1 -1
  21. package/src/is-buffer.ts +9 -0
  22. package/src/is-json-serializable.ts +29 -0
  23. package/src/is-provider-reference.ts +21 -0
  24. package/src/is-url-supported.ts +17 -2
  25. package/src/load-api-key.ts +1 -1
  26. package/src/load-setting.ts +1 -1
  27. package/src/map-reasoning-to-provider.ts +4 -1
  28. package/src/maybe-promise-like.ts +3 -0
  29. package/src/parse-json-event-stream.ts +3 -3
  30. package/src/parse-json.ts +3 -3
  31. package/src/parse-provider-options.ts +1 -1
  32. package/src/post-to-api.ts +4 -4
  33. package/src/{provider-tool-factory.ts → provider-defined-tool-factory.ts} +22 -29
  34. package/src/provider-executed-tool-factory.ts +69 -0
  35. package/src/resolve-full-media-type.ts +49 -0
  36. package/src/resolve-provider-reference.ts +26 -0
  37. package/src/resolve.ts +16 -1
  38. package/src/response-handler.ts +3 -3
  39. package/src/schema.ts +6 -3
  40. package/src/secure-json-parse.ts +1 -1
  41. package/src/serialize-model-options.ts +63 -0
  42. package/src/streaming-tool-call-tracker.ts +241 -0
  43. package/src/test/convert-response-stream-to-array.ts +1 -1
  44. package/src/test/is-node-version.ts +22 -1
  45. package/src/to-json-schema/zod3-to-json-schema/options.ts +3 -3
  46. package/src/to-json-schema/zod3-to-json-schema/parse-def.ts +3 -3
  47. package/src/to-json-schema/zod3-to-json-schema/parse-types.ts +22 -22
  48. package/src/to-json-schema/zod3-to-json-schema/parsers/array.ts +3 -3
  49. package/src/to-json-schema/zod3-to-json-schema/parsers/bigint.ts +1 -1
  50. package/src/to-json-schema/zod3-to-json-schema/parsers/branded.ts +2 -2
  51. package/src/to-json-schema/zod3-to-json-schema/parsers/catch.ts +2 -2
  52. package/src/to-json-schema/zod3-to-json-schema/parsers/date.ts +4 -4
  53. package/src/to-json-schema/zod3-to-json-schema/parsers/default.ts +3 -3
  54. package/src/to-json-schema/zod3-to-json-schema/parsers/effects.ts +3 -3
  55. package/src/to-json-schema/zod3-to-json-schema/parsers/enum.ts +1 -1
  56. package/src/to-json-schema/zod3-to-json-schema/parsers/intersection.ts +5 -5
  57. package/src/to-json-schema/zod3-to-json-schema/parsers/literal.ts +1 -1
  58. package/src/to-json-schema/zod3-to-json-schema/parsers/map.ts +4 -5
  59. package/src/to-json-schema/zod3-to-json-schema/parsers/native-enum.ts +1 -1
  60. package/src/to-json-schema/zod3-to-json-schema/parsers/never.ts +1 -2
  61. package/src/to-json-schema/zod3-to-json-schema/parsers/nullable.ts +4 -4
  62. package/src/to-json-schema/zod3-to-json-schema/parsers/number.ts +1 -1
  63. package/src/to-json-schema/zod3-to-json-schema/parsers/object.ts +3 -3
  64. package/src/to-json-schema/zod3-to-json-schema/parsers/optional.ts +3 -3
  65. package/src/to-json-schema/zod3-to-json-schema/parsers/pipeline.ts +4 -4
  66. package/src/to-json-schema/zod3-to-json-schema/parsers/promise.ts +3 -3
  67. package/src/to-json-schema/zod3-to-json-schema/parsers/readonly.ts +2 -2
  68. package/src/to-json-schema/zod3-to-json-schema/parsers/record.ts +9 -10
  69. package/src/to-json-schema/zod3-to-json-schema/parsers/set.ts +3 -3
  70. package/src/to-json-schema/zod3-to-json-schema/parsers/string.ts +2 -2
  71. package/src/to-json-schema/zod3-to-json-schema/parsers/tuple.ts +3 -3
  72. package/src/to-json-schema/zod3-to-json-schema/parsers/undefined.ts +1 -2
  73. package/src/to-json-schema/zod3-to-json-schema/parsers/union.ts +3 -3
  74. package/src/to-json-schema/zod3-to-json-schema/parsers/unknown.ts +1 -2
  75. package/src/to-json-schema/zod3-to-json-schema/refs.ts +3 -3
  76. package/src/to-json-schema/zod3-to-json-schema/select-parser.ts +2 -2
  77. package/src/to-json-schema/zod3-to-json-schema/zod3-to-json-schema.ts +3 -3
  78. package/src/types/assistant-model-message.ts +3 -3
  79. package/src/types/content-part.ts +138 -19
  80. package/src/types/executable-tool.ts +17 -0
  81. package/src/types/execute-tool.ts +23 -23
  82. package/src/types/file-data.ts +48 -0
  83. package/src/types/index.ts +19 -3
  84. package/src/types/infer-tool-context.ts +7 -2
  85. package/src/types/infer-tool-set-context.ts +7 -9
  86. package/src/types/model-message.ts +4 -4
  87. package/src/types/never-optional.ts +7 -0
  88. package/src/types/provider-options.ts +1 -1
  89. package/src/types/provider-reference.ts +10 -0
  90. package/src/types/sensitive-context.ts +9 -0
  91. package/src/types/system-model-message.ts +1 -1
  92. package/src/types/tool-approval-request.ts +7 -0
  93. package/src/types/tool-execute-function.ts +50 -0
  94. package/src/types/tool-model-message.ts +3 -3
  95. package/src/types/tool-needs-approval-function.ts +39 -0
  96. package/src/types/tool.ts +236 -223
  97. package/src/types/user-model-message.ts +2 -2
  98. package/src/validate-types.ts +5 -3
  99. package/dist/index.d.mts +0 -1578
  100. package/dist/index.mjs +0 -2817
  101. package/dist/index.mjs.map +0 -1
  102. package/dist/test/index.d.mts +0 -17
  103. package/dist/test/index.mjs +0 -77
  104. package/dist/test/index.mjs.map +0 -1
  105. package/src/types/union-to-intersection.ts +0 -17
@@ -0,0 +1,63 @@
1
+ import type { JSONObject } from '@ai-sdk/provider';
2
+ import { isJSONSerializable } from './is-json-serializable';
3
+ import type { Resolvable } from './resolve';
4
+
5
+ /**
6
+ * Serializes a model instance for workflow step boundaries.
7
+ * Returns the `modelId` plus the JSON-serializable config properties.
8
+ *
9
+ * Non-serializable values are omitted. As a special case, a
10
+ * function-valued `headers` property is resolved during serialization
11
+ * and included if the returned value is JSON-serializable.
12
+ *
13
+ * Used as the body of `static [WORKFLOW_SERIALIZE]` in provider models.
14
+ *
15
+ * @example
16
+ * ```ts
17
+ * static [WORKFLOW_SERIALIZE](model: MyLanguageModel) {
18
+ * return serializeModelOptions({
19
+ * modelId: model.modelId,
20
+ * config: model.config,
21
+ * });
22
+ * }
23
+ * ```
24
+ */
25
+ export function serializeModelOptions<
26
+ CONFIG extends {
27
+ headers?: Resolvable<Record<string, string | undefined>>;
28
+ },
29
+ >(options: {
30
+ modelId: string;
31
+ config: CONFIG;
32
+ }): {
33
+ modelId: string;
34
+ config: JSONObject;
35
+ } {
36
+ const serializableConfig: JSONObject = {};
37
+ for (const [key, value] of Object.entries(options.config)) {
38
+ if (key === 'headers') {
39
+ const resolvedHeaders = resolveSync(value);
40
+ if (isJSONSerializable(resolvedHeaders)) {
41
+ serializableConfig[key] = resolvedHeaders;
42
+ }
43
+ } else if (isJSONSerializable(value)) {
44
+ serializableConfig[key] = value;
45
+ }
46
+ }
47
+ return { modelId: options.modelId, config: serializableConfig };
48
+ }
49
+
50
+ function resolveSync<T>(value: Resolvable<T>): T {
51
+ let next: unknown = value;
52
+ if (typeof value === 'function') {
53
+ next = (value as () => unknown)();
54
+ }
55
+
56
+ // the serialization for workflows currently only supports synchronous values
57
+ // TODO introduce SerializationError
58
+ if (next instanceof Promise) {
59
+ throw new Error('Promise returned from resolveSync');
60
+ }
61
+
62
+ return next as T;
63
+ }
@@ -0,0 +1,241 @@
1
+ import {
2
+ InvalidResponseDataError,
3
+ type LanguageModelV4StreamPart,
4
+ type SharedV4ProviderMetadata,
5
+ } from '@ai-sdk/provider';
6
+ import { generateId as defaultGenerateId } from './generate-id';
7
+ import { isParsableJson } from './parse-json';
8
+
9
+ /**
10
+ * Minimal interface for a streaming tool call delta from an OpenAI-compatible API.
11
+ */
12
+ export interface StreamingToolCallDelta {
13
+ index?: number | null;
14
+ id?: string | null;
15
+ type?: string | null;
16
+ function?: {
17
+ name?: string | null;
18
+ arguments?: string | null;
19
+ } | null;
20
+ }
21
+
22
+ export interface StreamingToolCallTrackerOptions<
23
+ DELTA extends StreamingToolCallDelta = StreamingToolCallDelta,
24
+ > {
25
+ /**
26
+ * ID generator function for tool call IDs.
27
+ * Defaults to the standard generateId.
28
+ */
29
+ generateId?: () => string;
30
+
31
+ /**
32
+ * How to validate the `type` field on new tool call deltas.
33
+ * - `'none'`: no validation (default)
34
+ * - `'if-present'`: throw if type is present and not `'function'`
35
+ * - `'required'`: throw if type is not exactly `'function'`
36
+ */
37
+ typeValidation?: 'none' | 'if-present' | 'required';
38
+
39
+ /**
40
+ * Extract provider-specific metadata from a tool call delta.
41
+ * Called once when a new tool call is detected.
42
+ * The returned metadata is stored on the tool call and passed to
43
+ * `buildToolCallProviderMetadata` when the tool call is finalized.
44
+ */
45
+ extractMetadata?: (delta: DELTA) => SharedV4ProviderMetadata | undefined;
46
+
47
+ /**
48
+ * Build the `providerMetadata` object for a `tool-call` event.
49
+ * Receives the metadata previously extracted via `extractMetadata`.
50
+ * If `undefined` is returned, no `providerMetadata` is included in the event.
51
+ */
52
+ buildToolCallProviderMetadata?: (
53
+ metadata: SharedV4ProviderMetadata | undefined,
54
+ ) => SharedV4ProviderMetadata | undefined;
55
+ }
56
+
57
+ interface TrackedToolCall {
58
+ id: string;
59
+ type: 'function';
60
+ function: { name: string; arguments: string };
61
+ hasFinished: boolean;
62
+ metadata?: SharedV4ProviderMetadata;
63
+ }
64
+
65
+ type StreamingToolCallTrackerController = Pick<
66
+ TransformStreamDefaultController<LanguageModelV4StreamPart>,
67
+ 'enqueue'
68
+ >;
69
+
70
+ /**
71
+ * Tracks streaming tool call state across multiple deltas from an
72
+ * OpenAI-compatible chat completion stream. Handles argument accumulation,
73
+ * emits tool-input-start/delta/end and tool-call events, and finalizes
74
+ * unfinished tool calls on flush.
75
+ *
76
+ * Used by openai, openai-compatible, groq, deepseek, and alibaba providers.
77
+ */
78
+ export class StreamingToolCallTracker<
79
+ DELTA extends StreamingToolCallDelta = StreamingToolCallDelta,
80
+ > {
81
+ private toolCalls: TrackedToolCall[] = [];
82
+ private readonly controller: StreamingToolCallTrackerController;
83
+ private readonly _generateId: () => string;
84
+ private readonly typeValidation: 'none' | 'if-present' | 'required';
85
+ private readonly extractMetadata?: (
86
+ delta: DELTA,
87
+ ) => SharedV4ProviderMetadata | undefined;
88
+ private readonly buildToolCallProviderMetadata?: (
89
+ metadata: SharedV4ProviderMetadata | undefined,
90
+ ) => SharedV4ProviderMetadata | undefined;
91
+
92
+ constructor(
93
+ controller: StreamingToolCallTrackerController,
94
+ options: StreamingToolCallTrackerOptions<DELTA> = {},
95
+ ) {
96
+ this.controller = controller;
97
+ this._generateId = options.generateId ?? defaultGenerateId;
98
+ this.typeValidation = options.typeValidation ?? 'none';
99
+ this.extractMetadata = options.extractMetadata;
100
+ this.buildToolCallProviderMetadata = options.buildToolCallProviderMetadata;
101
+ }
102
+
103
+ /**
104
+ * Process a tool call delta from a streaming response chunk.
105
+ * Emits tool-input-start, tool-input-delta, tool-input-end, and tool-call
106
+ * events as appropriate.
107
+ */
108
+ processDelta(toolCallDelta: DELTA): void {
109
+ const index = toolCallDelta.index ?? this.toolCalls.length;
110
+
111
+ if (this.toolCalls[index] == null) {
112
+ this.processNewToolCall(index, toolCallDelta);
113
+ } else {
114
+ this.processExistingToolCall(index, toolCallDelta);
115
+ }
116
+ }
117
+
118
+ /**
119
+ * Finalize any unfinished tool calls. Should be called during the stream's
120
+ * flush handler to ensure all tool calls are properly completed.
121
+ */
122
+ flush(): void {
123
+ for (const toolCall of this.toolCalls) {
124
+ if (!toolCall.hasFinished) {
125
+ this.finishToolCall(toolCall);
126
+ }
127
+ }
128
+ }
129
+
130
+ private processNewToolCall(index: number, toolCallDelta: DELTA): void {
131
+ if (this.typeValidation === 'required') {
132
+ if (toolCallDelta.type !== 'function') {
133
+ throw new InvalidResponseDataError({
134
+ data: toolCallDelta,
135
+ message: `Expected 'function' type.`,
136
+ });
137
+ }
138
+ } else if (this.typeValidation === 'if-present') {
139
+ if (toolCallDelta.type != null && toolCallDelta.type !== 'function') {
140
+ throw new InvalidResponseDataError({
141
+ data: toolCallDelta,
142
+ message: `Expected 'function' type.`,
143
+ });
144
+ }
145
+ }
146
+
147
+ if (toolCallDelta.id == null) {
148
+ throw new InvalidResponseDataError({
149
+ data: toolCallDelta,
150
+ message: `Expected 'id' to be a string.`,
151
+ });
152
+ }
153
+
154
+ if (toolCallDelta.function?.name == null) {
155
+ throw new InvalidResponseDataError({
156
+ data: toolCallDelta,
157
+ message: `Expected 'function.name' to be a string.`,
158
+ });
159
+ }
160
+
161
+ this.controller.enqueue({
162
+ type: 'tool-input-start',
163
+ id: toolCallDelta.id,
164
+ toolName: toolCallDelta.function.name,
165
+ });
166
+
167
+ const metadata = this.extractMetadata?.(toolCallDelta);
168
+
169
+ this.toolCalls[index] = {
170
+ id: toolCallDelta.id,
171
+ type: 'function',
172
+ function: {
173
+ name: toolCallDelta.function.name,
174
+ arguments: toolCallDelta.function.arguments ?? '',
175
+ },
176
+ hasFinished: false,
177
+ metadata,
178
+ };
179
+
180
+ const toolCall = this.toolCalls[index];
181
+
182
+ // Emit initial delta if arguments already present
183
+ if (toolCall.function.arguments.length > 0) {
184
+ this.controller.enqueue({
185
+ type: 'tool-input-delta',
186
+ id: toolCall.id,
187
+ delta: toolCall.function.arguments,
188
+ });
189
+ }
190
+
191
+ // Check if tool call is complete
192
+ // (some providers send the full tool call in one chunk)
193
+ if (isParsableJson(toolCall.function.arguments)) {
194
+ this.finishToolCall(toolCall);
195
+ }
196
+ }
197
+
198
+ private processExistingToolCall(index: number, toolCallDelta: DELTA): void {
199
+ const toolCall = this.toolCalls[index];
200
+
201
+ if (toolCall.hasFinished) {
202
+ return;
203
+ }
204
+
205
+ if (toolCallDelta.function?.arguments != null) {
206
+ toolCall.function.arguments += toolCallDelta.function.arguments;
207
+
208
+ this.controller.enqueue({
209
+ type: 'tool-input-delta',
210
+ id: toolCall.id,
211
+ delta: toolCallDelta.function.arguments,
212
+ });
213
+ }
214
+
215
+ // Check if tool call is complete
216
+ if (isParsableJson(toolCall.function.arguments)) {
217
+ this.finishToolCall(toolCall);
218
+ }
219
+ }
220
+
221
+ private finishToolCall(toolCall: TrackedToolCall): void {
222
+ this.controller.enqueue({
223
+ type: 'tool-input-end',
224
+ id: toolCall.id,
225
+ });
226
+
227
+ const providerMetadata = this.buildToolCallProviderMetadata?.(
228
+ toolCall.metadata,
229
+ );
230
+
231
+ this.controller.enqueue({
232
+ type: 'tool-call',
233
+ toolCallId: toolCall.id ?? this._generateId(),
234
+ toolName: toolCall.function.name,
235
+ input: toolCall.function.arguments,
236
+ ...(providerMetadata ? { providerMetadata } : {}),
237
+ });
238
+
239
+ toolCall.hasFinished = true;
240
+ }
241
+ }
@@ -3,7 +3,7 @@ import { convertReadableStreamToArray } from './convert-readable-stream-to-array
3
3
  export async function convertResponseStreamToArray(
4
4
  response: Response,
5
5
  ): Promise<string[]> {
6
- return convertReadableStreamToArray(
6
+ return await convertReadableStreamToArray(
7
7
  response.body!.pipeThrough(new TextDecoderStream()),
8
8
  );
9
9
  }
@@ -1,4 +1,25 @@
1
+ function getNodeVersionParts() {
2
+ return process.versions.node
3
+ .split('.')
4
+ .map(version => Number.parseInt(version, 10));
5
+ }
6
+
1
7
  export function isNodeVersion(version: number) {
2
- const nodeMajorVersion = parseInt(process.version.slice(1).split('.')[0], 10);
8
+ const [nodeMajorVersion] = getNodeVersionParts();
3
9
  return nodeMajorVersion === version;
4
10
  }
11
+
12
+ export function isNodeVersionAtLeast(major: number, minor = 0, patch = 0) {
13
+ const [nodeMajorVersion, nodeMinorVersion, nodePatchVersion] =
14
+ getNodeVersionParts();
15
+
16
+ if (nodeMajorVersion !== major) {
17
+ return nodeMajorVersion > major;
18
+ }
19
+
20
+ if (nodeMinorVersion !== minor) {
21
+ return nodeMinorVersion > minor;
22
+ }
23
+
24
+ return nodePatchVersion >= patch;
25
+ }
@@ -1,6 +1,6 @@
1
- import { ZodSchema, ZodTypeDef } from 'zod/v3';
2
- import { Refs, Seen } from './refs';
3
- import { JsonSchema7Type } from './parse-types';
1
+ import type { ZodSchema, ZodTypeDef } from 'zod/v3';
2
+ import type { Refs, Seen } from './refs';
3
+ import type { JsonSchema7Type } from './parse-types';
4
4
 
5
5
  export type DateStrategy =
6
6
  | 'format:date-time'
@@ -1,7 +1,7 @@
1
- import { ZodTypeDef } from 'zod/v3';
2
- import { Refs, Seen } from './refs';
1
+ import type { ZodTypeDef } from 'zod/v3';
2
+ import type { Refs, Seen } from './refs';
3
3
  import { ignoreOverride } from './options';
4
- import { JsonSchema7Type } from './parse-types';
4
+ import type { JsonSchema7Type } from './parse-types';
5
5
  import { selectParser } from './select-parser';
6
6
  import { getRelativePath } from './get-relative-path';
7
7
  import { parseAnyDef } from './parsers/any';
@@ -1,25 +1,25 @@
1
- import { JsonSchema7AnyType } from './parsers/any';
2
- import { JsonSchema7ArrayType } from './parsers/array';
3
- import { JsonSchema7BigintType } from './parsers/bigint';
4
- import { JsonSchema7BooleanType } from './parsers/boolean';
5
- import { JsonSchema7DateType } from './parsers/date';
6
- import { JsonSchema7EnumType } from './parsers/enum';
7
- import { JsonSchema7AllOfType } from './parsers/intersection';
8
- import { JsonSchema7LiteralType } from './parsers/literal';
9
- import { JsonSchema7MapType } from './parsers/map';
10
- import { JsonSchema7NativeEnumType } from './parsers/native-enum';
11
- import { JsonSchema7NeverType } from './parsers/never';
12
- import { JsonSchema7NullType } from './parsers/null';
13
- import { JsonSchema7NullableType } from './parsers/nullable';
14
- import { JsonSchema7NumberType } from './parsers/number';
15
- import { JsonSchema7ObjectType } from './parsers/object';
16
- import { JsonSchema7RecordType } from './parsers/record';
17
- import { JsonSchema7SetType } from './parsers/set';
18
- import { JsonSchema7StringType } from './parsers/string';
19
- import { JsonSchema7TupleType } from './parsers/tuple';
20
- import { JsonSchema7UndefinedType } from './parsers/undefined';
21
- import { JsonSchema7UnionType } from './parsers/union';
22
- import { JsonSchema7UnknownType } from './parsers/unknown';
1
+ import type { JsonSchema7AnyType } from './parsers/any';
2
+ import type { JsonSchema7ArrayType } from './parsers/array';
3
+ import type { JsonSchema7BigintType } from './parsers/bigint';
4
+ import type { JsonSchema7BooleanType } from './parsers/boolean';
5
+ import type { JsonSchema7DateType } from './parsers/date';
6
+ import type { JsonSchema7EnumType } from './parsers/enum';
7
+ import type { JsonSchema7AllOfType } from './parsers/intersection';
8
+ import type { JsonSchema7LiteralType } from './parsers/literal';
9
+ import type { JsonSchema7MapType } from './parsers/map';
10
+ import type { JsonSchema7NativeEnumType } from './parsers/native-enum';
11
+ import type { JsonSchema7NeverType } from './parsers/never';
12
+ import type { JsonSchema7NullType } from './parsers/null';
13
+ import type { JsonSchema7NullableType } from './parsers/nullable';
14
+ import type { JsonSchema7NumberType } from './parsers/number';
15
+ import type { JsonSchema7ObjectType } from './parsers/object';
16
+ import type { JsonSchema7RecordType } from './parsers/record';
17
+ import type { JsonSchema7SetType } from './parsers/set';
18
+ import type { JsonSchema7StringType } from './parsers/string';
19
+ import type { JsonSchema7TupleType } from './parsers/tuple';
20
+ import type { JsonSchema7UndefinedType } from './parsers/undefined';
21
+ import type { JsonSchema7UnionType } from './parsers/union';
22
+ import type { JsonSchema7UnknownType } from './parsers/unknown';
23
23
 
24
24
  type JsonSchema7RefType = { $ref: string };
25
25
  type JsonSchema7Meta = {
@@ -1,7 +1,7 @@
1
- import { ZodArrayDef, ZodFirstPartyTypeKind } from 'zod/v3';
1
+ import { ZodFirstPartyTypeKind, type ZodArrayDef } from 'zod/v3';
2
2
  import { parseDef } from '../parse-def';
3
- import { JsonSchema7Type } from '../parse-types';
4
- import { Refs } from '../refs';
3
+ import type { JsonSchema7Type } from '../parse-types';
4
+ import type { Refs } from '../refs';
5
5
 
6
6
  export type JsonSchema7ArrayType = {
7
7
  type: 'array';
@@ -1,4 +1,4 @@
1
- import { ZodBigIntDef } from 'zod/v3';
1
+ import type { ZodBigIntDef } from 'zod/v3';
2
2
 
3
3
  export type JsonSchema7BigintType = {
4
4
  type: 'integer';
@@ -1,6 +1,6 @@
1
- import { ZodBrandedDef } from 'zod/v3';
1
+ import type { ZodBrandedDef } from 'zod/v3';
2
2
  import { parseDef } from '../parse-def';
3
- import { Refs } from '../refs';
3
+ import type { Refs } from '../refs';
4
4
 
5
5
  export function parseBrandedDef(_def: ZodBrandedDef<any>, refs: Refs) {
6
6
  return parseDef(_def.type._def, refs);
@@ -1,6 +1,6 @@
1
- import { ZodCatchDef } from 'zod/v3';
1
+ import type { ZodCatchDef } from 'zod/v3';
2
2
  import { parseDef } from '../parse-def';
3
- import { Refs } from '../refs';
3
+ import type { Refs } from '../refs';
4
4
 
5
5
  export const parseCatchDef = (def: ZodCatchDef<any>, refs: Refs) => {
6
6
  return parseDef(def.innerType._def, refs);
@@ -1,6 +1,6 @@
1
- import { ZodDateDef } from 'zod/v3';
2
- import { Refs } from '../refs';
3
- import { DateStrategy } from '../options';
1
+ import type { ZodDateDef } from 'zod/v3';
2
+ import type { Refs } from '../refs';
3
+ import type { DateStrategy } from '../options';
4
4
 
5
5
  export type JsonSchema7DateType =
6
6
  | {
@@ -22,7 +22,7 @@ export function parseDateDef(
22
22
 
23
23
  if (Array.isArray(strategy)) {
24
24
  return {
25
- anyOf: strategy.map((item, i) => parseDateDef(def, refs, item)),
25
+ anyOf: strategy.map(item => parseDateDef(def, refs, item)),
26
26
  };
27
27
  }
28
28
 
@@ -1,7 +1,7 @@
1
- import { ZodDefaultDef } from 'zod/v3';
1
+ import type { ZodDefaultDef } from 'zod/v3';
2
2
  import { parseDef } from '../parse-def';
3
- import { JsonSchema7Type } from '../parse-types';
4
- import { Refs } from '../refs';
3
+ import type { JsonSchema7Type } from '../parse-types';
4
+ import type { Refs } from '../refs';
5
5
 
6
6
  export function parseDefaultDef(
7
7
  _def: ZodDefaultDef,
@@ -1,7 +1,7 @@
1
- import { ZodEffectsDef } from 'zod/v3';
1
+ import type { ZodEffectsDef } from 'zod/v3';
2
2
  import { parseDef } from '../parse-def';
3
- import { JsonSchema7Type } from '../parse-types';
4
- import { Refs } from '../refs';
3
+ import type { JsonSchema7Type } from '../parse-types';
4
+ import type { Refs } from '../refs';
5
5
  import { parseAnyDef } from './any';
6
6
 
7
7
  export function parseEffectsDef(
@@ -1,4 +1,4 @@
1
- import { ZodEnumDef } from 'zod/v3';
1
+ import type { ZodEnumDef } from 'zod/v3';
2
2
 
3
3
  export type JsonSchema7EnumType = {
4
4
  type: 'string';
@@ -1,8 +1,8 @@
1
- import { ZodIntersectionDef } from 'zod/v3';
1
+ import type { ZodIntersectionDef } from 'zod/v3';
2
2
  import { parseDef } from '../parse-def';
3
- import { JsonSchema7Type } from '../parse-types';
4
- import { Refs } from '../refs';
5
- import { JsonSchema7StringType } from './string';
3
+ import type { JsonSchema7Type } from '../parse-types';
4
+ import type { Refs } from '../refs';
5
+ import type { JsonSchema7StringType } from './string';
6
6
 
7
7
  export type JsonSchema7AllOfType = {
8
8
  allOf: JsonSchema7Type[];
@@ -42,7 +42,7 @@ export function parseIntersectionDef(
42
42
  'additionalProperties' in schema &&
43
43
  schema.additionalProperties === false
44
44
  ) {
45
- const { additionalProperties, ...rest } = schema;
45
+ const { additionalProperties: _additionalProperties, ...rest } = schema;
46
46
  nestedSchema = rest;
47
47
  }
48
48
  mergedAllOf.push(nestedSchema);
@@ -1,4 +1,4 @@
1
- import { ZodLiteralDef } from 'zod/v3';
1
+ import type { ZodLiteralDef } from 'zod/v3';
2
2
 
3
3
  export type JsonSchema7LiteralType =
4
4
  | {
@@ -1,10 +1,9 @@
1
- import { ZodMapDef } from 'zod/v3';
1
+ import type { ZodMapDef } from 'zod/v3';
2
2
  import { parseDef } from '../parse-def';
3
- import { JsonSchema7Type } from '../parse-types';
4
- import { Refs } from '../refs';
3
+ import type { JsonSchema7Type } from '../parse-types';
4
+ import type { Refs } from '../refs';
5
5
  import { parseAnyDef } from './any';
6
- import { JsonSchema7RecordType, parseRecordDef } from './record';
7
-
6
+ import { parseRecordDef, type JsonSchema7RecordType } from './record';
8
7
  export type JsonSchema7MapType = {
9
8
  type: 'array';
10
9
  maxItems: 125;
@@ -1,4 +1,4 @@
1
- import { ZodNativeEnumDef } from 'zod/v3';
1
+ import type { ZodNativeEnumDef } from 'zod/v3';
2
2
 
3
3
  export type JsonSchema7NativeEnumType = {
4
4
  type: 'string' | 'number' | ['string', 'number'];
@@ -1,5 +1,4 @@
1
- import { JsonSchema7AnyType, parseAnyDef } from './any';
2
-
1
+ import { parseAnyDef, type JsonSchema7AnyType } from './any';
3
2
  export type JsonSchema7NeverType = {
4
3
  not: JsonSchema7AnyType;
5
4
  };
@@ -1,8 +1,8 @@
1
- import { ZodNullableDef } from 'zod/v3';
1
+ import type { ZodNullableDef } from 'zod/v3';
2
2
  import { parseDef } from '../parse-def';
3
- import { JsonSchema7Type } from '../parse-types';
4
- import { Refs } from '../refs';
5
- import { JsonSchema7NullType } from './null';
3
+ import type { JsonSchema7Type } from '../parse-types';
4
+ import type { Refs } from '../refs';
5
+ import type { JsonSchema7NullType } from './null';
6
6
  import { primitiveMappings } from './union';
7
7
 
8
8
  export type JsonSchema7NullableType =
@@ -1,4 +1,4 @@
1
- import { ZodNumberDef } from 'zod/v3';
1
+ import type { ZodNumberDef } from 'zod/v3';
2
2
 
3
3
  export type JsonSchema7NumberType = {
4
4
  type: 'number' | 'integer';
@@ -1,7 +1,7 @@
1
- import { ZodObjectDef, ZodTypeAny } from 'zod/v3';
1
+ import type { ZodObjectDef, ZodTypeAny } from 'zod/v3';
2
2
  import { parseDef } from '../parse-def';
3
- import { JsonSchema7Type } from '../parse-types';
4
- import { Refs } from '../refs';
3
+ import type { JsonSchema7Type } from '../parse-types';
4
+ import type { Refs } from '../refs';
5
5
 
6
6
  export type JsonSchema7ObjectType = {
7
7
  type: 'object';
@@ -1,7 +1,7 @@
1
- import { ZodOptionalDef } from 'zod/v3';
1
+ import type { ZodOptionalDef } from 'zod/v3';
2
2
  import { parseDef } from '../parse-def';
3
- import { JsonSchema7Type } from '../parse-types';
4
- import { Refs } from '../refs';
3
+ import type { JsonSchema7Type } from '../parse-types';
4
+ import type { Refs } from '../refs';
5
5
  import { parseAnyDef } from './any';
6
6
 
7
7
  export const parseOptionalDef = (
@@ -1,8 +1,8 @@
1
- import { ZodPipelineDef } from 'zod/v3';
1
+ import type { ZodPipelineDef } from 'zod/v3';
2
2
  import { parseDef } from '../parse-def';
3
- import { JsonSchema7Type } from '../parse-types';
4
- import { Refs } from '../refs';
5
- import { JsonSchema7AllOfType } from './intersection';
3
+ import type { JsonSchema7Type } from '../parse-types';
4
+ import type { Refs } from '../refs';
5
+ import type { JsonSchema7AllOfType } from './intersection';
6
6
 
7
7
  export const parsePipelineDef = (
8
8
  def: ZodPipelineDef<any, any>,
@@ -1,7 +1,7 @@
1
- import { ZodPromiseDef } from 'zod/v3';
1
+ import type { ZodPromiseDef } from 'zod/v3';
2
2
  import { parseDef } from '../parse-def';
3
- import { JsonSchema7Type } from '../parse-types';
4
- import { Refs } from '../refs';
3
+ import type { JsonSchema7Type } from '../parse-types';
4
+ import type { Refs } from '../refs';
5
5
 
6
6
  export function parsePromiseDef(
7
7
  def: ZodPromiseDef,
@@ -1,6 +1,6 @@
1
- import { ZodReadonlyDef } from 'zod/v3';
1
+ import type { ZodReadonlyDef } from 'zod/v3';
2
2
  import { parseDef } from '../parse-def';
3
- import { Refs } from '../refs';
3
+ import type { Refs } from '../refs';
4
4
 
5
5
  export const parseReadonlyDef = (def: ZodReadonlyDef<any>, refs: Refs) => {
6
6
  return parseDef(def.innerType._def, refs);