@langchain/core 1.0.3 → 1.0.5
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/agents.d.cts.map +1 -1
- package/dist/agents.d.ts.map +1 -1
- package/dist/errors/index.cjs +1 -1
- package/dist/errors/index.cjs.map +1 -1
- package/dist/errors/index.js +1 -1
- package/dist/errors/index.js.map +1 -1
- package/dist/language_models/base.cjs +68 -9
- package/dist/language_models/base.cjs.map +1 -1
- package/dist/language_models/base.d.cts +18 -0
- package/dist/language_models/base.d.cts.map +1 -1
- package/dist/language_models/base.d.ts +18 -0
- package/dist/language_models/base.d.ts.map +1 -1
- package/dist/language_models/base.js +68 -9
- package/dist/language_models/base.js.map +1 -1
- package/dist/language_models/profile.cjs +12 -0
- package/dist/language_models/profile.cjs.map +1 -0
- package/dist/language_models/profile.d.cts +174 -0
- package/dist/language_models/profile.d.cts.map +1 -0
- package/dist/language_models/profile.d.ts +174 -0
- package/dist/language_models/profile.d.ts.map +1 -0
- package/dist/language_models/profile.js +6 -0
- package/dist/language_models/profile.js.map +1 -0
- package/dist/load/import_map.cjs +5 -1
- package/dist/load/import_map.cjs.map +1 -1
- package/dist/load/import_map.js +5 -1
- package/dist/load/import_map.js.map +1 -1
- package/dist/tools/index.cjs +17 -4
- package/dist/tools/index.cjs.map +1 -1
- package/dist/tools/index.js +17 -4
- package/dist/tools/index.js.map +1 -1
- package/dist/utils/async_caller.cjs +10 -4
- package/dist/utils/async_caller.cjs.map +1 -1
- package/dist/utils/async_caller.js +10 -4
- package/dist/utils/async_caller.js.map +1 -1
- package/dist/utils/format.cjs +12 -0
- package/dist/utils/format.cjs.map +1 -0
- package/dist/utils/format.d.cts +58 -0
- package/dist/utils/format.d.cts.map +1 -0
- package/dist/utils/format.d.ts +58 -0
- package/dist/utils/format.d.ts.map +1 -0
- package/dist/utils/format.js +6 -0
- package/dist/utils/format.js.map +1 -0
- package/dist/utils/types/zod.cjs +21 -14
- package/dist/utils/types/zod.cjs.map +1 -1
- package/dist/utils/types/zod.js +21 -14
- package/dist/utils/types/zod.js.map +1 -1
- package/package.json +25 -2
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"async_caller.cjs","names":["error: any","params: AsyncCallerParams","PQueueMod","callable: T","options: AsyncCallerCallOptions","getAbortSignalError"],"sources":["../../src/utils/async_caller.ts"],"sourcesContent":["import pRetry from \"p-retry\";\nimport PQueueMod from \"p-queue\";\n\nimport { getAbortSignalError } from \"./signal.js\";\n\nconst STATUS_NO_RETRY = [\n 400, // Bad Request\n 401, // Unauthorized\n 402, // Payment Required\n 403, // Forbidden\n 404, // Not Found\n 405, // Method Not Allowed\n 406, // Not Acceptable\n 407, // Proxy Authentication Required\n 409, // Conflict\n];\n\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nconst defaultFailedAttemptHandler = (error: any) => {\n if (\n error.message.startsWith(\"Cancel\") ||\n error.message.startsWith(\"AbortError\") ||\n error.name === \"AbortError\"\n ) {\n throw error;\n }\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n if ((error as any)?.code === \"ECONNABORTED\") {\n throw error;\n }\n const status =\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n (error as any)?.response?.status ?? (error as any)?.status;\n if (status && STATUS_NO_RETRY.includes(+status)) {\n throw error;\n }\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n if ((error as any)?.error?.code === \"insufficient_quota\") {\n const err = new Error(error?.message);\n err.name = \"InsufficientQuotaError\";\n throw err;\n }\n};\n\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nexport type FailedAttemptHandler = (error: any) => any;\n\nexport interface AsyncCallerParams {\n /**\n * The maximum number of concurrent calls that can be made.\n * Defaults to `Infinity`, which means no limit.\n */\n maxConcurrency?: number;\n /**\n * The maximum number of retries that can be made for a single call,\n * with an exponential backoff between each attempt. Defaults to 6.\n */\n maxRetries?: number;\n /**\n * Custom handler to handle failed attempts. Takes the originally thrown\n * error object as input, and should itself throw an error if the input\n * error is not retryable.\n */\n onFailedAttempt?: FailedAttemptHandler;\n}\n\nexport interface AsyncCallerCallOptions {\n signal?: AbortSignal;\n}\n\n/**\n * A class that can be used to make async calls with concurrency and retry logic.\n *\n * This is useful for making calls to any kind of \"expensive\" external resource,\n * be it because it's rate-limited, subject to network issues, etc.\n *\n * Concurrent calls are limited by the `maxConcurrency` parameter, which defaults\n * to `Infinity`. This means that by default, all calls will be made in parallel.\n *\n * Retries are limited by the `maxRetries` parameter, which defaults to 6. This\n * means that by default, each call will be retried up to 6 times, with an\n * exponential backoff between each attempt.\n */\nexport class AsyncCaller {\n protected maxConcurrency: AsyncCallerParams[\"maxConcurrency\"];\n\n protected maxRetries: AsyncCallerParams[\"maxRetries\"];\n\n protected onFailedAttempt: AsyncCallerParams[\"onFailedAttempt\"];\n\n private queue: typeof import(\"p-queue\")[\"default\"][\"prototype\"];\n\n constructor(params: AsyncCallerParams) {\n this.maxConcurrency = params.maxConcurrency ?? Infinity;\n this.maxRetries = params.maxRetries ?? 6;\n this.onFailedAttempt =\n params.onFailedAttempt ?? defaultFailedAttemptHandler;\n\n const PQueue = (\n \"default\" in PQueueMod ? PQueueMod.default : PQueueMod\n ) as typeof PQueueMod;\n this.queue = new PQueue({ concurrency: this.maxConcurrency });\n }\n\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n call<A extends any[], T extends (...args: A) => Promise<any>>(\n callable: T,\n ...args: Parameters<T>\n ): Promise<Awaited<ReturnType<T>>> {\n return this.queue.add(\n () =>\n pRetry(\n () =>\n callable(...args).catch((error) => {\n // eslint-disable-next-line no-instanceof/no-instanceof\n if (error instanceof Error) {\n throw error;\n } else {\n throw new Error(error);\n }\n }),\n {\n onFailedAttempt: this.onFailedAttempt,\n retries: this.maxRetries,\n randomize: true,\n // If needed we can change some of the defaults here,\n // but they're quite sensible.\n }\n ),\n { throwOnTimeout: true }\n );\n }\n\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n callWithOptions<A extends any[], T extends (...args: A) => Promise<any>>(\n options: AsyncCallerCallOptions,\n callable: T,\n ...args: Parameters<T>\n ): Promise<Awaited<ReturnType<T>>> {\n // Note this doesn't cancel the underlying request,\n // when available prefer to use the signal option of the underlying call\n if (options.signal) {\n return Promise.race([\n this.call<A, T>(callable, ...args),\n new Promise<never>((_, reject) => {\n options.signal?.addEventListener(\"abort\", () => {\n
|
|
1
|
+
{"version":3,"file":"async_caller.cjs","names":["error: any","params: AsyncCallerParams","PQueueMod","callable: T","options: AsyncCallerCallOptions","listener: (() => void) | undefined","getAbortSignalError"],"sources":["../../src/utils/async_caller.ts"],"sourcesContent":["import pRetry from \"p-retry\";\nimport PQueueMod from \"p-queue\";\n\nimport { getAbortSignalError } from \"./signal.js\";\n\nconst STATUS_NO_RETRY = [\n 400, // Bad Request\n 401, // Unauthorized\n 402, // Payment Required\n 403, // Forbidden\n 404, // Not Found\n 405, // Method Not Allowed\n 406, // Not Acceptable\n 407, // Proxy Authentication Required\n 409, // Conflict\n];\n\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nconst defaultFailedAttemptHandler = (error: any) => {\n if (\n error.message.startsWith(\"Cancel\") ||\n error.message.startsWith(\"AbortError\") ||\n error.name === \"AbortError\"\n ) {\n throw error;\n }\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n if ((error as any)?.code === \"ECONNABORTED\") {\n throw error;\n }\n const status =\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n (error as any)?.response?.status ?? (error as any)?.status;\n if (status && STATUS_NO_RETRY.includes(+status)) {\n throw error;\n }\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n if ((error as any)?.error?.code === \"insufficient_quota\") {\n const err = new Error(error?.message);\n err.name = \"InsufficientQuotaError\";\n throw err;\n }\n};\n\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nexport type FailedAttemptHandler = (error: any) => any;\n\nexport interface AsyncCallerParams {\n /**\n * The maximum number of concurrent calls that can be made.\n * Defaults to `Infinity`, which means no limit.\n */\n maxConcurrency?: number;\n /**\n * The maximum number of retries that can be made for a single call,\n * with an exponential backoff between each attempt. Defaults to 6.\n */\n maxRetries?: number;\n /**\n * Custom handler to handle failed attempts. Takes the originally thrown\n * error object as input, and should itself throw an error if the input\n * error is not retryable.\n */\n onFailedAttempt?: FailedAttemptHandler;\n}\n\nexport interface AsyncCallerCallOptions {\n signal?: AbortSignal;\n}\n\n/**\n * A class that can be used to make async calls with concurrency and retry logic.\n *\n * This is useful for making calls to any kind of \"expensive\" external resource,\n * be it because it's rate-limited, subject to network issues, etc.\n *\n * Concurrent calls are limited by the `maxConcurrency` parameter, which defaults\n * to `Infinity`. This means that by default, all calls will be made in parallel.\n *\n * Retries are limited by the `maxRetries` parameter, which defaults to 6. This\n * means that by default, each call will be retried up to 6 times, with an\n * exponential backoff between each attempt.\n */\nexport class AsyncCaller {\n protected maxConcurrency: AsyncCallerParams[\"maxConcurrency\"];\n\n protected maxRetries: AsyncCallerParams[\"maxRetries\"];\n\n protected onFailedAttempt: AsyncCallerParams[\"onFailedAttempt\"];\n\n private queue: typeof import(\"p-queue\")[\"default\"][\"prototype\"];\n\n constructor(params: AsyncCallerParams) {\n this.maxConcurrency = params.maxConcurrency ?? Infinity;\n this.maxRetries = params.maxRetries ?? 6;\n this.onFailedAttempt =\n params.onFailedAttempt ?? defaultFailedAttemptHandler;\n\n const PQueue = (\n \"default\" in PQueueMod ? PQueueMod.default : PQueueMod\n ) as typeof PQueueMod;\n this.queue = new PQueue({ concurrency: this.maxConcurrency });\n }\n\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n call<A extends any[], T extends (...args: A) => Promise<any>>(\n callable: T,\n ...args: Parameters<T>\n ): Promise<Awaited<ReturnType<T>>> {\n return this.queue.add(\n () =>\n pRetry(\n () =>\n callable(...args).catch((error) => {\n // eslint-disable-next-line no-instanceof/no-instanceof\n if (error instanceof Error) {\n throw error;\n } else {\n throw new Error(error);\n }\n }),\n {\n onFailedAttempt: this.onFailedAttempt,\n retries: this.maxRetries,\n randomize: true,\n // If needed we can change some of the defaults here,\n // but they're quite sensible.\n }\n ),\n { throwOnTimeout: true }\n );\n }\n\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n callWithOptions<A extends any[], T extends (...args: A) => Promise<any>>(\n options: AsyncCallerCallOptions,\n callable: T,\n ...args: Parameters<T>\n ): Promise<Awaited<ReturnType<T>>> {\n // Note this doesn't cancel the underlying request,\n // when available prefer to use the signal option of the underlying call\n if (options.signal) {\n let listener: (() => void) | undefined;\n return Promise.race([\n this.call<A, T>(callable, ...args),\n new Promise<never>((_, reject) => {\n listener = () => {\n reject(getAbortSignalError(options.signal));\n };\n options.signal?.addEventListener(\"abort\", listener);\n }),\n ]).finally(() => {\n if (options.signal && listener) {\n options.signal.removeEventListener(\"abort\", listener);\n }\n });\n }\n return this.call<A, T>(callable, ...args);\n }\n\n fetch(...args: Parameters<typeof fetch>): ReturnType<typeof fetch> {\n return this.call(() =>\n fetch(...args).then((res) => (res.ok ? res : Promise.reject(res)))\n );\n }\n}\n"],"mappings":";;;;;;;;AAKA,MAAM,kBAAkB;CACtB;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;AACD;AAGD,MAAM,8BAA8B,CAACA,UAAe;AAClD,KACE,MAAM,QAAQ,WAAW,SAAS,IAClC,MAAM,QAAQ,WAAW,aAAa,IACtC,MAAM,SAAS,aAEf,OAAM;AAGR,KAAK,OAAe,SAAS,eAC3B,OAAM;CAER,MAAM,SAEH,OAAe,UAAU,UAAW,OAAe;AACtD,KAAI,UAAU,gBAAgB,SAAS,CAAC,OAAO,CAC7C,OAAM;AAGR,KAAK,OAAe,OAAO,SAAS,sBAAsB;EACxD,MAAM,MAAM,IAAI,MAAM,OAAO;EAC7B,IAAI,OAAO;AACX,QAAM;CACP;AACF;;;;;;;;;;;;;;AAyCD,IAAa,cAAb,MAAyB;CACvB,AAAU;CAEV,AAAU;CAEV,AAAU;CAEV,AAAQ;C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...args) {
|
|
67
|
-
if (options.signal)
|
|
68
|
-
|
|
69
|
-
|
|
67
|
+
if (options.signal) {
|
|
68
|
+
let listener;
|
|
69
|
+
return Promise.race([this.call(callable, ...args), new Promise((_, reject) => {
|
|
70
|
+
listener = () => {
|
|
71
|
+
reject(getAbortSignalError(options.signal));
|
|
72
|
+
};
|
|
73
|
+
options.signal?.addEventListener("abort", listener);
|
|
74
|
+
})]).finally(() => {
|
|
75
|
+
if (options.signal && listener) options.signal.removeEventListener("abort", listener);
|
|
70
76
|
});
|
|
71
|
-
}
|
|
77
|
+
}
|
|
72
78
|
return this.call(callable, ...args);
|
|
73
79
|
}
|
|
74
80
|
fetch(...args) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"async_caller.js","names":["error: any","params: AsyncCallerParams","callable: T","options: AsyncCallerCallOptions"],"sources":["../../src/utils/async_caller.ts"],"sourcesContent":["import pRetry from \"p-retry\";\nimport PQueueMod from \"p-queue\";\n\nimport { getAbortSignalError } from \"./signal.js\";\n\nconst STATUS_NO_RETRY = [\n 400, // Bad Request\n 401, // Unauthorized\n 402, // Payment Required\n 403, // Forbidden\n 404, // Not Found\n 405, // Method Not Allowed\n 406, // Not Acceptable\n 407, // Proxy Authentication Required\n 409, // Conflict\n];\n\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nconst defaultFailedAttemptHandler = (error: any) => {\n if (\n error.message.startsWith(\"Cancel\") ||\n error.message.startsWith(\"AbortError\") ||\n error.name === \"AbortError\"\n ) {\n throw error;\n }\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n if ((error as any)?.code === \"ECONNABORTED\") {\n throw error;\n }\n const status =\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n (error as any)?.response?.status ?? (error as any)?.status;\n if (status && STATUS_NO_RETRY.includes(+status)) {\n throw error;\n }\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n if ((error as any)?.error?.code === \"insufficient_quota\") {\n const err = new Error(error?.message);\n err.name = \"InsufficientQuotaError\";\n throw err;\n }\n};\n\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nexport type FailedAttemptHandler = (error: any) => any;\n\nexport interface AsyncCallerParams {\n /**\n * The maximum number of concurrent calls that can be made.\n * Defaults to `Infinity`, which means no limit.\n */\n maxConcurrency?: number;\n /**\n * The maximum number of retries that can be made for a single call,\n * with an exponential backoff between each attempt. Defaults to 6.\n */\n maxRetries?: number;\n /**\n * Custom handler to handle failed attempts. Takes the originally thrown\n * error object as input, and should itself throw an error if the input\n * error is not retryable.\n */\n onFailedAttempt?: FailedAttemptHandler;\n}\n\nexport interface AsyncCallerCallOptions {\n signal?: AbortSignal;\n}\n\n/**\n * A class that can be used to make async calls with concurrency and retry logic.\n *\n * This is useful for making calls to any kind of \"expensive\" external resource,\n * be it because it's rate-limited, subject to network issues, etc.\n *\n * Concurrent calls are limited by the `maxConcurrency` parameter, which defaults\n * to `Infinity`. This means that by default, all calls will be made in parallel.\n *\n * Retries are limited by the `maxRetries` parameter, which defaults to 6. This\n * means that by default, each call will be retried up to 6 times, with an\n * exponential backoff between each attempt.\n */\nexport class AsyncCaller {\n protected maxConcurrency: AsyncCallerParams[\"maxConcurrency\"];\n\n protected maxRetries: AsyncCallerParams[\"maxRetries\"];\n\n protected onFailedAttempt: AsyncCallerParams[\"onFailedAttempt\"];\n\n private queue: typeof import(\"p-queue\")[\"default\"][\"prototype\"];\n\n constructor(params: AsyncCallerParams) {\n this.maxConcurrency = params.maxConcurrency ?? Infinity;\n this.maxRetries = params.maxRetries ?? 6;\n this.onFailedAttempt =\n params.onFailedAttempt ?? defaultFailedAttemptHandler;\n\n const PQueue = (\n \"default\" in PQueueMod ? PQueueMod.default : PQueueMod\n ) as typeof PQueueMod;\n this.queue = new PQueue({ concurrency: this.maxConcurrency });\n }\n\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n call<A extends any[], T extends (...args: A) => Promise<any>>(\n callable: T,\n ...args: Parameters<T>\n ): Promise<Awaited<ReturnType<T>>> {\n return this.queue.add(\n () =>\n pRetry(\n () =>\n callable(...args).catch((error) => {\n // eslint-disable-next-line no-instanceof/no-instanceof\n if (error instanceof Error) {\n throw error;\n } else {\n throw new Error(error);\n }\n }),\n {\n onFailedAttempt: this.onFailedAttempt,\n retries: this.maxRetries,\n randomize: true,\n // If needed we can change some of the defaults here,\n // but they're quite sensible.\n }\n ),\n { throwOnTimeout: true }\n );\n }\n\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n callWithOptions<A extends any[], T extends (...args: A) => Promise<any>>(\n options: AsyncCallerCallOptions,\n callable: T,\n ...args: Parameters<T>\n ): Promise<Awaited<ReturnType<T>>> {\n // Note this doesn't cancel the underlying request,\n // when available prefer to use the signal option of the underlying call\n if (options.signal) {\n return Promise.race([\n this.call<A, T>(callable, ...args),\n new Promise<never>((_, reject) => {\n options.signal?.addEventListener(\"abort\", () => {\n
|
|
1
|
+
{"version":3,"file":"async_caller.js","names":["error: any","params: AsyncCallerParams","callable: T","options: AsyncCallerCallOptions","listener: (() => void) | undefined"],"sources":["../../src/utils/async_caller.ts"],"sourcesContent":["import pRetry from \"p-retry\";\nimport PQueueMod from \"p-queue\";\n\nimport { getAbortSignalError } from \"./signal.js\";\n\nconst STATUS_NO_RETRY = [\n 400, // Bad Request\n 401, // Unauthorized\n 402, // Payment Required\n 403, // Forbidden\n 404, // Not Found\n 405, // Method Not Allowed\n 406, // Not Acceptable\n 407, // Proxy Authentication Required\n 409, // Conflict\n];\n\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nconst defaultFailedAttemptHandler = (error: any) => {\n if (\n error.message.startsWith(\"Cancel\") ||\n error.message.startsWith(\"AbortError\") ||\n error.name === \"AbortError\"\n ) {\n throw error;\n }\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n if ((error as any)?.code === \"ECONNABORTED\") {\n throw error;\n }\n const status =\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n (error as any)?.response?.status ?? (error as any)?.status;\n if (status && STATUS_NO_RETRY.includes(+status)) {\n throw error;\n }\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n if ((error as any)?.error?.code === \"insufficient_quota\") {\n const err = new Error(error?.message);\n err.name = \"InsufficientQuotaError\";\n throw err;\n }\n};\n\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nexport type FailedAttemptHandler = (error: any) => any;\n\nexport interface AsyncCallerParams {\n /**\n * The maximum number of concurrent calls that can be made.\n * Defaults to `Infinity`, which means no limit.\n */\n maxConcurrency?: number;\n /**\n * The maximum number of retries that can be made for a single call,\n * with an exponential backoff between each attempt. Defaults to 6.\n */\n maxRetries?: number;\n /**\n * Custom handler to handle failed attempts. Takes the originally thrown\n * error object as input, and should itself throw an error if the input\n * error is not retryable.\n */\n onFailedAttempt?: FailedAttemptHandler;\n}\n\nexport interface AsyncCallerCallOptions {\n signal?: AbortSignal;\n}\n\n/**\n * A class that can be used to make async calls with concurrency and retry logic.\n *\n * This is useful for making calls to any kind of \"expensive\" external resource,\n * be it because it's rate-limited, subject to network issues, etc.\n *\n * Concurrent calls are limited by the `maxConcurrency` parameter, which defaults\n * to `Infinity`. This means that by default, all calls will be made in parallel.\n *\n * Retries are limited by the `maxRetries` parameter, which defaults to 6. This\n * means that by default, each call will be retried up to 6 times, with an\n * exponential backoff between each attempt.\n */\nexport class AsyncCaller {\n protected maxConcurrency: AsyncCallerParams[\"maxConcurrency\"];\n\n protected maxRetries: AsyncCallerParams[\"maxRetries\"];\n\n protected onFailedAttempt: AsyncCallerParams[\"onFailedAttempt\"];\n\n private queue: typeof import(\"p-queue\")[\"default\"][\"prototype\"];\n\n constructor(params: AsyncCallerParams) {\n this.maxConcurrency = params.maxConcurrency ?? Infinity;\n this.maxRetries = params.maxRetries ?? 6;\n this.onFailedAttempt =\n params.onFailedAttempt ?? defaultFailedAttemptHandler;\n\n const PQueue = (\n \"default\" in PQueueMod ? PQueueMod.default : PQueueMod\n ) as typeof PQueueMod;\n this.queue = new PQueue({ concurrency: this.maxConcurrency });\n }\n\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n call<A extends any[], T extends (...args: A) => Promise<any>>(\n callable: T,\n ...args: Parameters<T>\n ): Promise<Awaited<ReturnType<T>>> {\n return this.queue.add(\n () =>\n pRetry(\n () =>\n callable(...args).catch((error) => {\n // eslint-disable-next-line no-instanceof/no-instanceof\n if (error instanceof Error) {\n throw error;\n } else {\n throw new Error(error);\n }\n }),\n {\n onFailedAttempt: this.onFailedAttempt,\n retries: this.maxRetries,\n randomize: true,\n // If needed we can change some of the defaults here,\n // but they're quite sensible.\n }\n ),\n { throwOnTimeout: true }\n );\n }\n\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n callWithOptions<A extends any[], T extends (...args: A) => Promise<any>>(\n options: AsyncCallerCallOptions,\n callable: T,\n ...args: Parameters<T>\n ): Promise<Awaited<ReturnType<T>>> {\n // Note this doesn't cancel the underlying request,\n // when available prefer to use the signal option of the underlying call\n if (options.signal) {\n let listener: (() => void) | undefined;\n return Promise.race([\n this.call<A, T>(callable, ...args),\n new Promise<never>((_, reject) => {\n listener = () => {\n reject(getAbortSignalError(options.signal));\n };\n options.signal?.addEventListener(\"abort\", listener);\n }),\n ]).finally(() => {\n if (options.signal && listener) {\n options.signal.removeEventListener(\"abort\", listener);\n }\n });\n }\n return this.call<A, T>(callable, ...args);\n }\n\n fetch(...args: Parameters<typeof fetch>): ReturnType<typeof fetch> {\n return this.call(() =>\n fetch(...args).then((res) => (res.ok ? res : Promise.reject(res)))\n );\n }\n}\n"],"mappings":";;;;;;;;AAKA,MAAM,kBAAkB;CACtB;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;AACD;AAGD,MAAM,8BAA8B,CAACA,UAAe;AAClD,KACE,MAAM,QAAQ,WAAW,SAAS,IAClC,MAAM,QAAQ,WAAW,aAAa,IACtC,MAAM,SAAS,aAEf,OAAM;AAGR,KAAK,OAAe,SAAS,eAC3B,OAAM;CAER,MAAM,SAEH,OAAe,UAAU,UAAW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AED,MAAM,GAAG,MAA0D;AACjE,SAAO,KAAK,KAAK,MACf,MAAM,GAAG,KAAK,CAAC,KAAK,CAAC,QAAS,IAAI,KAAK,MAAM,QAAQ,OAAO,IAAI,CAAE,CACnE;CACF;AACF"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"format.cjs","names":[],"sources":["../../src/utils/format.ts"],"sourcesContent":["/**\n * A function that converts data from one format to another.\n *\n * This is commonly used for transforming message content blocks between different\n * provider-specific formats and standardized internal representations.\n *\n * @template T - The input type to convert from\n * @template U - The output type to convert to\n *\n * @param input - The data to convert\n * @returns The converted data in the target format\n *\n * @example\n * ```typescript\n * // Convert from OpenAI format to standard format\n * const converter: Converter<OpenAIBlock, ContentBlock.Standard> = (block) => {\n * return { type: \"text\", text: block.text };\n * };\n * ```\n */\nexport type Converter<T, U> = (input: T) => U;\n\n/**\n * A pair of bidirectional conversion functions for transforming data between two formats.\n *\n * This type is used throughout the message system to enable conversion between\n * provider-specific message formats (like OpenAI, Anthropic, Google, etc.) and\n * standardized internal content block representations. The `encode` function\n * typically converts from a standard format to a provider-specific format, while\n * `decode` converts from a provider-specific format back to the standard format.\n *\n * @template T - The first format (typically the standard/internal format)\n * @template U - The second format (typically the provider-specific format)\n *\n * @property encode - Converts from format T to format U\n * @property decode - Converts from format U back to format T\n *\n * @example\n * ```typescript\n * // Converter pair for OpenAI message blocks\n * const openAIConverter: ConverterPair<ContentBlock.Standard, OpenAIBlock> = {\n * encode: (standard) => ({ text: standard.text }),\n * decode: (openai) => ({ type: \"text\", text: openai.text })\n * };\n *\n * // Usage\n * const standardBlock = { type: \"text\", text: \"Hello\" };\n * const openaiBlock = openAIConverter.encode(standardBlock);\n * const backToStandard = openAIConverter.decode(openaiBlock);\n * ```\n */\nexport type ConverterPair<T, U> = {\n encode: Converter<T, U>;\n decode: Converter<U, T>;\n};\n"],"mappings":""}
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
//#region src/utils/format.d.ts
|
|
2
|
+
/**
|
|
3
|
+
* A function that converts data from one format to another.
|
|
4
|
+
*
|
|
5
|
+
* This is commonly used for transforming message content blocks between different
|
|
6
|
+
* provider-specific formats and standardized internal representations.
|
|
7
|
+
*
|
|
8
|
+
* @template T - The input type to convert from
|
|
9
|
+
* @template U - The output type to convert to
|
|
10
|
+
*
|
|
11
|
+
* @param input - The data to convert
|
|
12
|
+
* @returns The converted data in the target format
|
|
13
|
+
*
|
|
14
|
+
* @example
|
|
15
|
+
* ```typescript
|
|
16
|
+
* // Convert from OpenAI format to standard format
|
|
17
|
+
* const converter: Converter<OpenAIBlock, ContentBlock.Standard> = (block) => {
|
|
18
|
+
* return { type: "text", text: block.text };
|
|
19
|
+
* };
|
|
20
|
+
* ```
|
|
21
|
+
*/
|
|
22
|
+
type Converter<T, U> = (input: T) => U;
|
|
23
|
+
/**
|
|
24
|
+
* A pair of bidirectional conversion functions for transforming data between two formats.
|
|
25
|
+
*
|
|
26
|
+
* This type is used throughout the message system to enable conversion between
|
|
27
|
+
* provider-specific message formats (like OpenAI, Anthropic, Google, etc.) and
|
|
28
|
+
* standardized internal content block representations. The `encode` function
|
|
29
|
+
* typically converts from a standard format to a provider-specific format, while
|
|
30
|
+
* `decode` converts from a provider-specific format back to the standard format.
|
|
31
|
+
*
|
|
32
|
+
* @template T - The first format (typically the standard/internal format)
|
|
33
|
+
* @template U - The second format (typically the provider-specific format)
|
|
34
|
+
*
|
|
35
|
+
* @property encode - Converts from format T to format U
|
|
36
|
+
* @property decode - Converts from format U back to format T
|
|
37
|
+
*
|
|
38
|
+
* @example
|
|
39
|
+
* ```typescript
|
|
40
|
+
* // Converter pair for OpenAI message blocks
|
|
41
|
+
* const openAIConverter: ConverterPair<ContentBlock.Standard, OpenAIBlock> = {
|
|
42
|
+
* encode: (standard) => ({ text: standard.text }),
|
|
43
|
+
* decode: (openai) => ({ type: "text", text: openai.text })
|
|
44
|
+
* };
|
|
45
|
+
*
|
|
46
|
+
* // Usage
|
|
47
|
+
* const standardBlock = { type: "text", text: "Hello" };
|
|
48
|
+
* const openaiBlock = openAIConverter.encode(standardBlock);
|
|
49
|
+
* const backToStandard = openAIConverter.decode(openaiBlock);
|
|
50
|
+
* ```
|
|
51
|
+
*/
|
|
52
|
+
type ConverterPair<T, U> = {
|
|
53
|
+
encode: Converter<T, U>;
|
|
54
|
+
decode: Converter<U, T>;
|
|
55
|
+
};
|
|
56
|
+
//#endregion
|
|
57
|
+
export { Converter, ConverterPair };
|
|
58
|
+
//# sourceMappingURL=format.d.cts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"format.d.cts","names":["Converter","T","U","ConverterPair"],"sources":["../../src/utils/format.d.ts"],"sourcesContent":["/**\n * A function that converts data from one format to another.\n *\n * This is commonly used for transforming message content blocks between different\n * provider-specific formats and standardized internal representations.\n *\n * @template T - The input type to convert from\n * @template U - The output type to convert to\n *\n * @param input - The data to convert\n * @returns The converted data in the target format\n *\n * @example\n * ```typescript\n * // Convert from OpenAI format to standard format\n * const converter: Converter<OpenAIBlock, ContentBlock.Standard> = (block) => {\n * return { type: \"text\", text: block.text };\n * };\n * ```\n */\nexport type Converter<T, U> = (input: T) => U;\n/**\n * A pair of bidirectional conversion functions for transforming data between two formats.\n *\n * This type is used throughout the message system to enable conversion between\n * provider-specific message formats (like OpenAI, Anthropic, Google, etc.) and\n * standardized internal content block representations. The `encode` function\n * typically converts from a standard format to a provider-specific format, while\n * `decode` converts from a provider-specific format back to the standard format.\n *\n * @template T - The first format (typically the standard/internal format)\n * @template U - The second format (typically the provider-specific format)\n *\n * @property encode - Converts from format T to format U\n * @property decode - Converts from format U back to format T\n *\n * @example\n * ```typescript\n * // Converter pair for OpenAI message blocks\n * const openAIConverter: ConverterPair<ContentBlock.Standard, OpenAIBlock> = {\n * encode: (standard) => ({ text: standard.text }),\n * decode: (openai) => ({ type: \"text\", text: openai.text })\n * };\n *\n * // Usage\n * const standardBlock = { type: \"text\", text: \"Hello\" };\n * const openaiBlock = openAIConverter.encode(standardBlock);\n * const backToStandard = openAIConverter.decode(openaiBlock);\n * ```\n */\nexport type ConverterPair<T, U> = {\n encode: Converter<T, U>;\n decode: Converter<U, T>;\n};\n"],"mappings":";;AAoBA;;;;AAA6C;AA8B7C;;;;;;;;AAEqB;;;;;;KAhCTA,0BAA0BC,MAAMC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;KA8BhCC;UACAH,UAAUC,GAAGC;UACbF,UAAUE,GAAGD"}
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
//#region src/utils/format.d.ts
|
|
2
|
+
/**
|
|
3
|
+
* A function that converts data from one format to another.
|
|
4
|
+
*
|
|
5
|
+
* This is commonly used for transforming message content blocks between different
|
|
6
|
+
* provider-specific formats and standardized internal representations.
|
|
7
|
+
*
|
|
8
|
+
* @template T - The input type to convert from
|
|
9
|
+
* @template U - The output type to convert to
|
|
10
|
+
*
|
|
11
|
+
* @param input - The data to convert
|
|
12
|
+
* @returns The converted data in the target format
|
|
13
|
+
*
|
|
14
|
+
* @example
|
|
15
|
+
* ```typescript
|
|
16
|
+
* // Convert from OpenAI format to standard format
|
|
17
|
+
* const converter: Converter<OpenAIBlock, ContentBlock.Standard> = (block) => {
|
|
18
|
+
* return { type: "text", text: block.text };
|
|
19
|
+
* };
|
|
20
|
+
* ```
|
|
21
|
+
*/
|
|
22
|
+
type Converter<T, U> = (input: T) => U;
|
|
23
|
+
/**
|
|
24
|
+
* A pair of bidirectional conversion functions for transforming data between two formats.
|
|
25
|
+
*
|
|
26
|
+
* This type is used throughout the message system to enable conversion between
|
|
27
|
+
* provider-specific message formats (like OpenAI, Anthropic, Google, etc.) and
|
|
28
|
+
* standardized internal content block representations. The `encode` function
|
|
29
|
+
* typically converts from a standard format to a provider-specific format, while
|
|
30
|
+
* `decode` converts from a provider-specific format back to the standard format.
|
|
31
|
+
*
|
|
32
|
+
* @template T - The first format (typically the standard/internal format)
|
|
33
|
+
* @template U - The second format (typically the provider-specific format)
|
|
34
|
+
*
|
|
35
|
+
* @property encode - Converts from format T to format U
|
|
36
|
+
* @property decode - Converts from format U back to format T
|
|
37
|
+
*
|
|
38
|
+
* @example
|
|
39
|
+
* ```typescript
|
|
40
|
+
* // Converter pair for OpenAI message blocks
|
|
41
|
+
* const openAIConverter: ConverterPair<ContentBlock.Standard, OpenAIBlock> = {
|
|
42
|
+
* encode: (standard) => ({ text: standard.text }),
|
|
43
|
+
* decode: (openai) => ({ type: "text", text: openai.text })
|
|
44
|
+
* };
|
|
45
|
+
*
|
|
46
|
+
* // Usage
|
|
47
|
+
* const standardBlock = { type: "text", text: "Hello" };
|
|
48
|
+
* const openaiBlock = openAIConverter.encode(standardBlock);
|
|
49
|
+
* const backToStandard = openAIConverter.decode(openaiBlock);
|
|
50
|
+
* ```
|
|
51
|
+
*/
|
|
52
|
+
type ConverterPair<T, U> = {
|
|
53
|
+
encode: Converter<T, U>;
|
|
54
|
+
decode: Converter<U, T>;
|
|
55
|
+
};
|
|
56
|
+
//#endregion
|
|
57
|
+
export { Converter, ConverterPair };
|
|
58
|
+
//# sourceMappingURL=format.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"format.d.ts","names":["Converter","T","U","ConverterPair"],"sources":["../../src/utils/format.d.ts"],"sourcesContent":["/**\n * A function that converts data from one format to another.\n *\n * This is commonly used for transforming message content blocks between different\n * provider-specific formats and standardized internal representations.\n *\n * @template T - The input type to convert from\n * @template U - The output type to convert to\n *\n * @param input - The data to convert\n * @returns The converted data in the target format\n *\n * @example\n * ```typescript\n * // Convert from OpenAI format to standard format\n * const converter: Converter<OpenAIBlock, ContentBlock.Standard> = (block) => {\n * return { type: \"text\", text: block.text };\n * };\n * ```\n */\nexport type Converter<T, U> = (input: T) => U;\n/**\n * A pair of bidirectional conversion functions for transforming data between two formats.\n *\n * This type is used throughout the message system to enable conversion between\n * provider-specific message formats (like OpenAI, Anthropic, Google, etc.) and\n * standardized internal content block representations. The `encode` function\n * typically converts from a standard format to a provider-specific format, while\n * `decode` converts from a provider-specific format back to the standard format.\n *\n * @template T - The first format (typically the standard/internal format)\n * @template U - The second format (typically the provider-specific format)\n *\n * @property encode - Converts from format T to format U\n * @property decode - Converts from format U back to format T\n *\n * @example\n * ```typescript\n * // Converter pair for OpenAI message blocks\n * const openAIConverter: ConverterPair<ContentBlock.Standard, OpenAIBlock> = {\n * encode: (standard) => ({ text: standard.text }),\n * decode: (openai) => ({ type: \"text\", text: openai.text })\n * };\n *\n * // Usage\n * const standardBlock = { type: \"text\", text: \"Hello\" };\n * const openaiBlock = openAIConverter.encode(standardBlock);\n * const backToStandard = openAIConverter.decode(openaiBlock);\n * ```\n */\nexport type ConverterPair<T, U> = {\n encode: Converter<T, U>;\n decode: Converter<U, T>;\n};\n"],"mappings":";;AAoBA;;;;AAA6C;AA8B7C;;;;;;;;AAEqB;;;;;;KAhCTA,0BAA0BC,MAAMC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;KA8BhCC;UACAH,UAAUC,GAAGC;UACbF,UAAUE,GAAGD"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"format.js","names":[],"sources":["../../src/utils/format.ts"],"sourcesContent":["/**\n * A function that converts data from one format to another.\n *\n * This is commonly used for transforming message content blocks between different\n * provider-specific formats and standardized internal representations.\n *\n * @template T - The input type to convert from\n * @template U - The output type to convert to\n *\n * @param input - The data to convert\n * @returns The converted data in the target format\n *\n * @example\n * ```typescript\n * // Convert from OpenAI format to standard format\n * const converter: Converter<OpenAIBlock, ContentBlock.Standard> = (block) => {\n * return { type: \"text\", text: block.text };\n * };\n * ```\n */\nexport type Converter<T, U> = (input: T) => U;\n\n/**\n * A pair of bidirectional conversion functions for transforming data between two formats.\n *\n * This type is used throughout the message system to enable conversion between\n * provider-specific message formats (like OpenAI, Anthropic, Google, etc.) and\n * standardized internal content block representations. The `encode` function\n * typically converts from a standard format to a provider-specific format, while\n * `decode` converts from a provider-specific format back to the standard format.\n *\n * @template T - The first format (typically the standard/internal format)\n * @template U - The second format (typically the provider-specific format)\n *\n * @property encode - Converts from format T to format U\n * @property decode - Converts from format U back to format T\n *\n * @example\n * ```typescript\n * // Converter pair for OpenAI message blocks\n * const openAIConverter: ConverterPair<ContentBlock.Standard, OpenAIBlock> = {\n * encode: (standard) => ({ text: standard.text }),\n * decode: (openai) => ({ type: \"text\", text: openai.text })\n * };\n *\n * // Usage\n * const standardBlock = { type: \"text\", text: \"Hello\" };\n * const openaiBlock = openAIConverter.encode(standardBlock);\n * const backToStandard = openAIConverter.decode(openaiBlock);\n * ```\n */\nexport type ConverterPair<T, U> = {\n encode: Converter<T, U>;\n decode: Converter<U, T>;\n};\n"],"mappings":""}
|
package/dist/utils/types/zod.cjs
CHANGED
|
@@ -395,33 +395,26 @@ function isZodTransformV3(schema) {
|
|
|
395
395
|
function isZodTransformV4(schema) {
|
|
396
396
|
return isZodSchemaV4(schema) && schema._zod.def.type === "pipe";
|
|
397
397
|
}
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
* recursively processes nested object schemas and arrays of object schemas.
|
|
402
|
-
*
|
|
403
|
-
* @param schema - The Zod schema instance (v3 or v4)
|
|
404
|
-
* @param {boolean} [recursive=false] - Whether to recursively process nested objects/arrays.
|
|
405
|
-
* @returns The input Zod schema of the transform, or undefined if not a transform
|
|
406
|
-
*/
|
|
407
|
-
function interopZodTransformInputSchema(schema, recursive = false) {
|
|
398
|
+
function interopZodTransformInputSchemaImpl(schema, recursive, cache) {
|
|
399
|
+
const cached = cache.get(schema);
|
|
400
|
+
if (cached !== void 0) return cached;
|
|
408
401
|
if (isZodSchemaV3(schema)) {
|
|
409
|
-
if (isZodTransformV3(schema)) return
|
|
402
|
+
if (isZodTransformV3(schema)) return interopZodTransformInputSchemaImpl(schema._def.schema, recursive, cache);
|
|
410
403
|
return schema;
|
|
411
404
|
}
|
|
412
405
|
if (isZodSchemaV4(schema)) {
|
|
413
406
|
let outputSchema = schema;
|
|
414
|
-
if (isZodTransformV4(schema)) outputSchema =
|
|
407
|
+
if (isZodTransformV4(schema)) outputSchema = interopZodTransformInputSchemaImpl(schema._zod.def.in, recursive, cache);
|
|
415
408
|
if (recursive) {
|
|
416
409
|
if (isZodObjectV4(outputSchema)) {
|
|
417
410
|
const outputShape = outputSchema._zod.def.shape;
|
|
418
|
-
for (const [key, keySchema] of Object.entries(outputSchema._zod.def.shape)) outputShape[key] =
|
|
411
|
+
for (const [key, keySchema] of Object.entries(outputSchema._zod.def.shape)) outputShape[key] = interopZodTransformInputSchemaImpl(keySchema, recursive, cache);
|
|
419
412
|
outputSchema = (0, zod_v4_core.clone)(outputSchema, {
|
|
420
413
|
...outputSchema._zod.def,
|
|
421
414
|
shape: outputShape
|
|
422
415
|
});
|
|
423
416
|
} else if (isZodArrayV4(outputSchema)) {
|
|
424
|
-
const elementSchema =
|
|
417
|
+
const elementSchema = interopZodTransformInputSchemaImpl(outputSchema._zod.def.element, recursive, cache);
|
|
425
418
|
outputSchema = (0, zod_v4_core.clone)(outputSchema, {
|
|
426
419
|
...outputSchema._zod.def,
|
|
427
420
|
element: elementSchema
|
|
@@ -430,11 +423,25 @@ function interopZodTransformInputSchema(schema, recursive = false) {
|
|
|
430
423
|
}
|
|
431
424
|
const meta = zod_v4_core.globalRegistry.get(schema);
|
|
432
425
|
if (meta) zod_v4_core.globalRegistry.add(outputSchema, meta);
|
|
426
|
+
cache.set(schema, outputSchema);
|
|
433
427
|
return outputSchema;
|
|
434
428
|
}
|
|
435
429
|
throw new Error("Schema must be an instance of z3.ZodType or z4.$ZodType");
|
|
436
430
|
}
|
|
437
431
|
/**
|
|
432
|
+
* Returns the input type of a Zod transform schema, for both v3 and v4.
|
|
433
|
+
* If the schema is not a transform, returns undefined. If `recursive` is true,
|
|
434
|
+
* recursively processes nested object schemas and arrays of object schemas.
|
|
435
|
+
*
|
|
436
|
+
* @param schema - The Zod schema instance (v3 or v4)
|
|
437
|
+
* @param {boolean} [recursive=false] - Whether to recursively process nested objects/arrays.
|
|
438
|
+
* @returns The input Zod schema of the transform, or undefined if not a transform
|
|
439
|
+
*/
|
|
440
|
+
function interopZodTransformInputSchema(schema, recursive = false) {
|
|
441
|
+
const cache = /* @__PURE__ */ new WeakMap();
|
|
442
|
+
return interopZodTransformInputSchemaImpl(schema, recursive, cache);
|
|
443
|
+
}
|
|
444
|
+
/**
|
|
438
445
|
* Creates a modified version of a Zod object schema where fields matching a predicate are made optional.
|
|
439
446
|
* Supports both Zod v3 and v4 schemas and preserves the original schema version.
|
|
440
447
|
*
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"zod.cjs","names":["schema: unknown","schema: z3.ZodType<RunOutput> | Record<string, unknown>","input: unknown","obj: unknown","schema: InteropZodType<T>","schema: InteropZodType<unknown> | Record<string, unknown>","globalRegistry","schema: T","extension: InteropZodObjectShape","util","$ZodOptional","outputShape: Mutable<z4.$ZodShape>","meta","$ZodNever","$ZodUnknown","schema: InteropZodType","outputSchema: InteropZodType","predicate: (key: string, value: InteropZodType) => boolean","modifiedShape: Record<string, z3.ZodTypeAny>"],"sources":["../../../src/utils/types/zod.ts"],"sourcesContent":["import type * as z3 from \"zod/v3\";\nimport type * as z4 from \"zod/v4/core\";\nimport {\n parse,\n parseAsync,\n globalRegistry,\n util,\n clone,\n _unknown,\n _never,\n $ZodUnknown,\n $ZodNever,\n $ZodOptional,\n} from \"zod/v4/core\";\n\nexport type ZodStringV3 = z3.ZodString;\n\nexport type ZodStringV4 = z4.$ZodType<string, unknown>;\n\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nexport type ZodObjectV3 = z3.ZodObject<any, any, any, any>;\n\nexport type ZodObjectV4 = z4.$ZodObject;\n\nexport type ZodDefaultV3<T extends z3.ZodTypeAny> = z3.ZodDefault<T>;\nexport type ZodDefaultV4<T extends z4.SomeType> = z4.$ZodDefault<T>;\nexport type ZodOptionalV3<T extends z3.ZodTypeAny> = z3.ZodOptional<T>;\nexport type ZodOptionalV4<T extends z4.SomeType> = z4.$ZodOptional<T>;\n\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nexport type InteropZodType<Output = any, Input = Output> =\n | z3.ZodType<Output, z3.ZodTypeDef, Input>\n | z4.$ZodType<Output, Input>;\n\nexport type InteropZodObject = ZodObjectV3 | ZodObjectV4;\nexport type InteropZodDefault<T = InteropZodObjectShape> =\n T extends z3.ZodTypeAny\n ? ZodDefaultV3<T>\n : T extends z4.SomeType\n ? ZodDefaultV4<T>\n : never;\nexport type InteropZodOptional<T = InteropZodObjectShape> =\n T extends z3.ZodTypeAny\n ? ZodOptionalV3<T>\n : T extends z4.SomeType\n ? ZodOptionalV4<T>\n : never;\n\nexport type InteropZodObjectShape<\n T extends InteropZodObject = InteropZodObject\n> = T extends z3.ZodObject<infer Shape>\n ? { [K in keyof Shape]: Shape[K] }\n : T extends z4.$ZodObject<infer Shape>\n ? { [K in keyof Shape]: Shape[K] }\n : never;\n\nexport type InteropZodIssue = z3.ZodIssue | z4.$ZodIssue;\n\n// Simplified type inference to avoid circular dependencies\nexport type InferInteropZodInput<T> = T extends z3.ZodType<\n unknown,\n z3.ZodTypeDef,\n infer Input\n>\n ? Input\n : T extends z4.$ZodType<unknown, infer Input>\n ? Input\n : T extends { _zod: { input: infer Input } }\n ? Input\n : never;\n\nexport type InferInteropZodOutput<T> = T extends z3.ZodType<\n infer Output,\n z3.ZodTypeDef,\n unknown\n>\n ? Output\n : T extends z4.$ZodType<infer Output, unknown>\n ? Output\n : T extends { _zod: { output: infer Output } }\n ? Output\n : never;\n\nexport type Mutable<T> = {\n -readonly [P in keyof T]: T[P];\n};\n\nexport function isZodSchemaV4(\n schema: unknown\n): schema is z4.$ZodType<unknown, unknown> {\n if (typeof schema !== \"object\" || schema === null) {\n return false;\n }\n\n const obj = schema as Record<string, unknown>;\n if (!(\"_zod\" in obj)) {\n return false;\n }\n\n const zod = obj._zod;\n return (\n typeof zod === \"object\" &&\n zod !== null &&\n \"def\" in (zod as Record<string, unknown>)\n );\n}\n\nexport function isZodSchemaV3(\n schema: unknown\n): schema is z3.ZodType<unknown, z3.ZodTypeDef, unknown> {\n if (typeof schema !== \"object\" || schema === null) {\n return false;\n }\n\n const obj = schema as Record<string, unknown>;\n if (!(\"_def\" in obj) || \"_zod\" in obj) {\n return false;\n }\n\n const def = obj._def;\n return (\n typeof def === \"object\" &&\n def != null &&\n \"typeName\" in (def as Record<string, unknown>)\n );\n}\n\n/** Backward compatible isZodSchema for Zod 3 */\nexport function isZodSchema<\n RunOutput extends Record<string, unknown> = Record<string, unknown>\n>(\n schema: z3.ZodType<RunOutput> | Record<string, unknown>\n): schema is z3.ZodType<RunOutput> {\n if (isZodSchemaV4(schema)) {\n console.warn(\n \"[WARNING] Attempting to use Zod 4 schema in a context where Zod 3 schema is expected. This may cause unexpected behavior.\"\n );\n }\n return isZodSchemaV3(schema);\n}\n\n/**\n * Given either a Zod schema, or plain object, determine if the input is a Zod schema.\n *\n * @param {unknown} input\n * @returns {boolean} Whether or not the provided input is a Zod schema.\n */\nexport function isInteropZodSchema(input: unknown): input is InteropZodType {\n if (!input) {\n return false;\n }\n if (typeof input !== \"object\") {\n return false;\n }\n if (Array.isArray(input)) {\n return false;\n }\n if (\n isZodSchemaV4(input) ||\n isZodSchemaV3(input as z3.ZodType<Record<string, unknown>>)\n ) {\n return true;\n }\n return false;\n}\n\nexport type InteropZodLiteral = z3.ZodLiteral<unknown> | z4.$ZodLiteral;\n\nexport function isZodLiteralV3(obj: unknown): obj is z3.ZodLiteral<unknown> {\n // Zod v3 literal schemas have _def.typeName === \"ZodLiteral\"\n if (\n typeof obj === \"object\" &&\n obj !== null &&\n \"_def\" in obj &&\n typeof obj._def === \"object\" &&\n obj._def !== null &&\n \"typeName\" in obj._def &&\n obj._def.typeName === \"ZodLiteral\"\n ) {\n return true;\n }\n return false;\n}\n\nexport function isZodLiteralV4(obj: unknown): obj is z4.$ZodLiteral {\n if (!isZodSchemaV4(obj)) return false;\n // Zod v4 literal schemas have _zod.def.type === \"literal\"\n if (\n typeof obj === \"object\" &&\n obj !== null &&\n \"_zod\" in obj &&\n typeof obj._zod === \"object\" &&\n obj._zod !== null &&\n \"def\" in obj._zod &&\n typeof obj._zod.def === \"object\" &&\n obj._zod.def !== null &&\n \"type\" in obj._zod.def &&\n obj._zod.def.type === \"literal\"\n ) {\n return true;\n }\n return false;\n}\n\n/**\n * Determines if the provided value is an InteropZodLiteral (Zod v3 or v4 literal schema).\n *\n * @param obj The value to check.\n * @returns {boolean} True if the value is a Zod v3 or v4 literal schema, false otherwise.\n */\nexport function isInteropZodLiteral(obj: unknown): obj is InteropZodLiteral {\n if (isZodLiteralV3(obj)) return true;\n if (isZodLiteralV4(obj)) return true;\n return false;\n}\n\ntype InteropZodSafeParseResult<T> = z3.SafeParseReturnType<T, T>;\n\n/**\n * Asynchronously parses the input using the provided Zod schema (v3 or v4) and returns a safe parse result.\n * This function handles both Zod v3 and v4 schemas, returning a result object indicating success or failure.\n *\n * @template T - The expected output type of the schema.\n * @param {InteropZodType<T>} schema - The Zod schema (v3 or v4) to use for parsing.\n * @param {unknown} input - The input value to parse.\n * @returns {Promise<InteropZodSafeParseResult<T>>} A promise that resolves to a safe parse result object.\n * @throws {Error} If the schema is not a recognized Zod v3 or v4 schema.\n */\nexport async function interopSafeParseAsync<T>(\n schema: InteropZodType<T>,\n input: unknown\n): Promise<InteropZodSafeParseResult<T>> {\n if (isZodSchemaV4(schema)) {\n try {\n const data = await parseAsync(schema, input);\n return {\n success: true,\n data,\n };\n } catch (error) {\n return {\n success: false,\n error: error as z3.ZodError<T>,\n };\n }\n }\n if (isZodSchemaV3(schema as z3.ZodType<Record<string, unknown>>)) {\n return await schema.safeParseAsync(input);\n }\n throw new Error(\"Schema must be an instance of z3.ZodType or z4.$ZodType\");\n}\n\n/**\n * Asynchronously parses the input using the provided Zod schema (v3 or v4) and returns the parsed value.\n * Throws an error if parsing fails or if the schema is not a recognized Zod v3 or v4 schema.\n *\n * @template T - The expected output type of the schema.\n * @param {InteropZodType<T>} schema - The Zod schema (v3 or v4) to use for parsing.\n * @param {unknown} input - The input value to parse.\n * @returns {Promise<T>} A promise that resolves to the parsed value.\n * @throws {Error} If parsing fails or the schema is not a recognized Zod v3 or v4 schema.\n */\nexport async function interopParseAsync<T>(\n schema: InteropZodType<T>,\n input: unknown\n): Promise<T> {\n if (isZodSchemaV4(schema)) {\n return await parseAsync(schema, input);\n }\n if (isZodSchemaV3(schema as z3.ZodType<Record<string, unknown>>)) {\n return await schema.parseAsync(input);\n }\n throw new Error(\"Schema must be an instance of z3.ZodType or z4.$ZodType\");\n}\n\n/**\n * Safely parses the input using the provided Zod schema (v3 or v4) and returns a result object\n * indicating success or failure. This function is compatible with both Zod v3 and v4 schemas.\n *\n * @template T - The expected output type of the schema.\n * @param {InteropZodType<T>} schema - The Zod schema (v3 or v4) to use for parsing.\n * @param {unknown} input - The input value to parse.\n * @returns {InteropZodSafeParseResult<T>} An object with either the parsed data (on success)\n * or the error (on failure).\n * @throws {Error} If the schema is not a recognized Zod v3 or v4 schema.\n */\nexport function interopSafeParse<T>(\n schema: InteropZodType<T>,\n input: unknown\n): InteropZodSafeParseResult<T> {\n if (isZodSchemaV4(schema)) {\n try {\n const data = parse(schema, input);\n return {\n success: true,\n data,\n };\n } catch (error) {\n return {\n success: false,\n error: error as z3.ZodError<T>,\n };\n }\n }\n if (isZodSchemaV3(schema as z3.ZodType<Record<string, unknown>>)) {\n return schema.safeParse(input);\n }\n throw new Error(\"Schema must be an instance of z3.ZodType or z4.$ZodType\");\n}\n\n/**\n * Parses the input using the provided Zod schema (v3 or v4) and returns the parsed value.\n * Throws an error if parsing fails or if the schema is not a recognized Zod v3 or v4 schema.\n *\n * @template T - The expected output type of the schema.\n * @param {InteropZodType<T>} schema - The Zod schema (v3 or v4) to use for parsing.\n * @param {unknown} input - The input value to parse.\n * @returns {T} The parsed value.\n * @throws {Error} If parsing fails or the schema is not a recognized Zod v3 or v4 schema.\n */\nexport function interopParse<T>(schema: InteropZodType<T>, input: unknown): T {\n if (isZodSchemaV4(schema)) {\n return parse(schema, input);\n }\n if (isZodSchemaV3(schema as z3.ZodType<Record<string, unknown>>)) {\n return schema.parse(input);\n }\n throw new Error(\"Schema must be an instance of z3.ZodType or z4.$ZodType\");\n}\n\n/**\n * Retrieves the description from a schema definition (v3, v4, or plain object), if available.\n *\n * @param {unknown} schema - The schema to extract the description from.\n * @returns {string | undefined} The description of the schema, or undefined if not present.\n */\nexport function getSchemaDescription(\n schema: InteropZodType<unknown> | Record<string, unknown>\n): string | undefined {\n if (isZodSchemaV4(schema)) {\n return globalRegistry.get(schema)?.description;\n }\n if (isZodSchemaV3(schema as z3.ZodType<Record<string, unknown>>)) {\n return schema.description as string | undefined;\n }\n if (\"description\" in schema && typeof schema.description === \"string\") {\n return schema.description;\n }\n return undefined;\n}\n\n/**\n * Determines if the provided Zod schema is \"shapeless\".\n * A shapeless schema is one that does not define any object shape,\n * such as ZodString, ZodNumber, ZodBoolean, ZodAny, etc.\n * For ZodObject, it must have no shape keys to be considered shapeless.\n * ZodRecord schemas are considered shapeless since they define dynamic\n * key-value mappings without fixed keys.\n *\n * @param schema The Zod schema to check.\n * @returns {boolean} True if the schema is shapeless, false otherwise.\n */\nexport function isShapelessZodSchema(schema: unknown): boolean {\n if (!isInteropZodSchema(schema)) {\n return false;\n }\n\n // Check for v3 schemas\n if (isZodSchemaV3(schema as z3.ZodType<Record<string, unknown>>)) {\n // @ts-expect-error - zod v3 types are not compatible with zod v4 types\n const def = schema._def as { typeName?: string };\n\n // ZodObject is only shaped if it has actual shape keys\n if (def.typeName === \"ZodObject\") {\n const obj = schema as { shape?: Record<string, unknown> };\n return !obj.shape || Object.keys(obj.shape).length === 0;\n }\n\n // ZodRecord is shapeless (dynamic key-value mapping)\n if (def.typeName === \"ZodRecord\") {\n return true;\n }\n }\n\n // Check for v4 schemas\n if (isZodSchemaV4(schema)) {\n const def = schema._zod.def;\n\n // Object type is only shaped if it has actual shape keys\n if (def.type === \"object\") {\n const obj = schema as { shape?: Record<string, unknown> };\n return !obj.shape || Object.keys(obj.shape).length === 0;\n }\n\n // Record type is shapeless (dynamic key-value mapping)\n if (def.type === \"record\") {\n return true;\n }\n }\n\n // For other schemas, check if they have a `shape` property\n // If they don't have shape, they're likely shapeless\n if (typeof schema === \"object\" && schema !== null && !(\"shape\" in schema)) {\n return true;\n }\n\n return false;\n}\n\n/**\n * Determines if the provided Zod schema should be treated as a simple string schema\n * that maps to DynamicTool. This aligns with the type-level constraint of\n * InteropZodType<string | undefined> which only matches basic string schemas.\n * If the provided schema is just z.string(), we can make the determination that\n * the tool is just a generic string tool that doesn't require any input validation.\n *\n * This function only returns true for basic ZodString schemas, including:\n * - Basic string schemas (z.string())\n * - String schemas with validations (z.string().min(1), z.string().email(), etc.)\n *\n * This function returns false for everything else, including:\n * - String schemas with defaults (z.string().default(\"value\"))\n * - Branded string schemas (z.string().brand<\"UserId\">())\n * - String schemas with catch operations (z.string().catch(\"default\"))\n * - Optional/nullable string schemas (z.string().optional())\n * - Transformed schemas (z.string().transform() or z.object().transform())\n * - Object or record schemas, even if they're empty\n * - Any other schema type\n *\n * @param schema The Zod schema to check.\n * @returns {boolean} True if the schema is a basic ZodString, false otherwise.\n */\nexport function isSimpleStringZodSchema(\n schema: unknown\n): schema is InteropZodType<string | undefined> {\n if (!isInteropZodSchema(schema)) {\n return false;\n }\n\n // For v3 schemas\n if (isZodSchemaV3(schema as z3.ZodType<Record<string, unknown>>)) {\n // @ts-expect-error - zod v3 types are not compatible with zod v4 types\n const def = schema._def as { typeName?: string };\n\n // Only accept basic ZodString\n return def.typeName === \"ZodString\";\n }\n\n // For v4 schemas\n if (isZodSchemaV4(schema)) {\n const def = schema._zod.def;\n\n // Only accept basic string type\n return def.type === \"string\";\n }\n\n return false;\n}\n\nexport function isZodObjectV3(obj: unknown): obj is ZodObjectV3 {\n // Zod v3 object schemas have _def.typeName === \"ZodObject\"\n if (\n typeof obj === \"object\" &&\n obj !== null &&\n \"_def\" in obj &&\n typeof obj._def === \"object\" &&\n obj._def !== null &&\n \"typeName\" in obj._def &&\n obj._def.typeName === \"ZodObject\"\n ) {\n return true;\n }\n return false;\n}\n\nexport function isZodObjectV4(obj: unknown): obj is z4.$ZodObject {\n if (!isZodSchemaV4(obj)) return false;\n // Zod v4 object schemas have _zod.def.type === \"object\"\n if (\n typeof obj === \"object\" &&\n obj !== null &&\n \"_zod\" in obj &&\n typeof obj._zod === \"object\" &&\n obj._zod !== null &&\n \"def\" in obj._zod &&\n typeof obj._zod.def === \"object\" &&\n obj._zod.def !== null &&\n \"type\" in obj._zod.def &&\n obj._zod.def.type === \"object\"\n ) {\n return true;\n }\n return false;\n}\n\nexport function isZodArrayV4(obj: unknown): obj is z4.$ZodArray {\n if (!isZodSchemaV4(obj)) return false;\n // Zod v4 array schemas have _zod.def.type === \"array\"\n if (\n typeof obj === \"object\" &&\n obj !== null &&\n \"_zod\" in obj &&\n typeof obj._zod === \"object\" &&\n obj._zod !== null &&\n \"def\" in obj._zod &&\n typeof obj._zod.def === \"object\" &&\n obj._zod.def !== null &&\n \"type\" in obj._zod.def &&\n obj._zod.def.type === \"array\"\n ) {\n return true;\n }\n return false;\n}\n\n/**\n * Determines if the provided value is an InteropZodObject (Zod v3 or v4 object schema).\n *\n * @param obj The value to check.\n * @returns {boolean} True if the value is a Zod v3 or v4 object schema, false otherwise.\n */\nexport function isInteropZodObject(obj: unknown): obj is InteropZodObject {\n if (isZodObjectV3(obj)) return true;\n if (isZodObjectV4(obj)) return true;\n return false;\n}\n\n/**\n * Retrieves the shape (fields) of a Zod object schema, supporting both Zod v3 and v4.\n *\n * @template T - The type of the Zod object schema.\n * @param {T} schema - The Zod object schema instance (either v3 or v4).\n * @returns {InteropZodObjectShape<T>} The shape of the object schema.\n * @throws {Error} If the schema is not a Zod v3 or v4 object.\n */\nexport function getInteropZodObjectShape<T extends InteropZodObject>(\n schema: T\n): InteropZodObjectShape<T> {\n if (isZodSchemaV3(schema)) {\n return schema.shape;\n }\n if (isZodSchemaV4(schema)) {\n return schema._zod.def.shape as InteropZodObjectShape<T>;\n }\n throw new Error(\n \"Schema must be an instance of z3.ZodObject or z4.$ZodObject\"\n );\n}\n\n/**\n * Extends a Zod object schema with additional fields, supporting both Zod v3 and v4.\n *\n * @template T - The type of the Zod object schema.\n * @param {T} schema - The Zod object schema instance (either v3 or v4).\n * @param {InteropZodObjectShape} extension - The fields to add to the schema.\n * @returns {InteropZodObject} The extended Zod object schema.\n * @throws {Error} If the schema is not a Zod v3 or v4 object.\n */\nexport function extendInteropZodObject<T extends InteropZodObject>(\n schema: T,\n extension: InteropZodObjectShape\n): InteropZodObject {\n if (isZodSchemaV3(schema)) {\n return schema.extend(extension as z3.ZodRawShape);\n }\n if (isZodSchemaV4(schema)) {\n return util.extend(schema, extension);\n }\n throw new Error(\n \"Schema must be an instance of z3.ZodObject or z4.$ZodObject\"\n );\n}\n\n/**\n * Returns a partial version of a Zod object schema, making all fields optional.\n * Supports both Zod v3 and v4.\n *\n * @template T - The type of the Zod object schema.\n * @param {T} schema - The Zod object schema instance (either v3 or v4).\n * @returns {InteropZodObject} The partial Zod object schema.\n * @throws {Error} If the schema is not a Zod v3 or v4 object.\n */\nexport function interopZodObjectPartial<T extends InteropZodObject>(\n schema: T\n): InteropZodObject {\n if (isZodSchemaV3(schema)) {\n // z3: .partial() exists and works as expected\n return schema.partial();\n }\n if (isZodSchemaV4(schema)) {\n // z4: util.partial exists and works as expected\n return util.partial($ZodOptional, schema, undefined);\n }\n throw new Error(\n \"Schema must be an instance of z3.ZodObject or z4.$ZodObject\"\n );\n}\n\n/**\n * Returns a strict version of a Zod object schema, disallowing unknown keys.\n * Supports both Zod v3 and v4 object schemas. If `recursive` is true, applies strictness\n * recursively to all nested object schemas and arrays of object schemas.\n *\n * @template T - The type of the Zod object schema.\n * @param {T} schema - The Zod object schema instance (either v3 or v4).\n * @param {boolean} [recursive=false] - Whether to apply strictness recursively to nested objects/arrays.\n * @returns {InteropZodObject} The strict Zod object schema.\n * @throws {Error} If the schema is not a Zod v3 or v4 object.\n */\nexport function interopZodObjectStrict<T extends InteropZodObject>(\n schema: T,\n recursive = false\n): InteropZodObject {\n if (isZodSchemaV3(schema)) {\n // TODO: v3 schemas aren't recursively handled here\n // (currently not necessary since zodToJsonSchema handles this)\n return schema.strict();\n }\n if (isZodObjectV4(schema)) {\n const outputShape: Mutable<z4.$ZodShape> = schema._zod.def.shape;\n if (recursive) {\n for (const [key, keySchema] of Object.entries(schema._zod.def.shape)) {\n // If the shape key is a v4 object schema, we need to make it strict\n if (isZodObjectV4(keySchema)) {\n const outputSchema = interopZodObjectStrict(keySchema, recursive);\n outputShape[key] = outputSchema as ZodObjectV4;\n }\n // If the shape key is a v4 array schema, we need to make the element\n // schema strict if it's an object schema\n else if (isZodArrayV4(keySchema)) {\n let elementSchema = keySchema._zod.def.element;\n if (isZodObjectV4(elementSchema)) {\n elementSchema = interopZodObjectStrict(\n elementSchema,\n recursive\n ) as ZodObjectV4;\n }\n outputShape[key] = clone(keySchema, {\n ...keySchema._zod.def,\n element: elementSchema,\n });\n }\n // Otherwise, just use the keySchema\n else {\n outputShape[key] = keySchema;\n }\n // Assign meta fields to the keySchema\n const meta = globalRegistry.get(keySchema);\n if (meta) globalRegistry.add(outputShape[key], meta);\n }\n }\n const modifiedSchema = clone<ZodObjectV4>(schema, {\n ...schema._zod.def,\n shape: outputShape,\n catchall: _never($ZodNever),\n });\n const meta = globalRegistry.get(schema);\n if (meta) globalRegistry.add(modifiedSchema, meta);\n return modifiedSchema;\n }\n throw new Error(\n \"Schema must be an instance of z3.ZodObject or z4.$ZodObject\"\n );\n}\n\n/**\n * Returns a passthrough version of a Zod object schema, allowing unknown keys.\n * Supports both Zod v3 and v4 object schemas. If `recursive` is true, applies passthrough\n * recursively to all nested object schemas and arrays of object schemas.\n *\n * @template T - The type of the Zod object schema.\n * @param {T} schema - The Zod object schema instance (either v3 or v4).\n * @param {boolean} [recursive=false] - Whether to apply passthrough recursively to nested objects/arrays.\n * @returns {InteropZodObject} The passthrough Zod object schema.\n * @throws {Error} If the schema is not a Zod v3 or v4 object.\n */\nexport function interopZodObjectPassthrough<T extends InteropZodObject>(\n schema: T,\n recursive = false\n): InteropZodObject {\n if (isZodObjectV3(schema)) {\n // TODO: v3 schemas aren't recursively handled here\n // (currently not necessary since zodToJsonSchema handles this)\n return schema.passthrough();\n }\n if (isZodObjectV4(schema)) {\n const outputShape: Mutable<z4.$ZodShape> = schema._zod.def.shape;\n if (recursive) {\n for (const [key, keySchema] of Object.entries(schema._zod.def.shape)) {\n // If the shape key is a v4 object schema, we need to make it passthrough\n if (isZodObjectV4(keySchema)) {\n const outputSchema = interopZodObjectPassthrough(\n keySchema,\n recursive\n );\n outputShape[key] = outputSchema as ZodObjectV4;\n }\n // If the shape key is a v4 array schema, we need to make the element\n // schema passthrough if it's an object schema\n else if (isZodArrayV4(keySchema)) {\n let elementSchema = keySchema._zod.def.element;\n if (isZodObjectV4(elementSchema)) {\n elementSchema = interopZodObjectPassthrough(\n elementSchema,\n recursive\n ) as ZodObjectV4;\n }\n outputShape[key] = clone(keySchema, {\n ...keySchema._zod.def,\n element: elementSchema,\n });\n }\n // Otherwise, just use the keySchema\n else {\n outputShape[key] = keySchema;\n }\n // Assign meta fields to the keySchema\n const meta = globalRegistry.get(keySchema);\n if (meta) globalRegistry.add(outputShape[key], meta);\n }\n }\n const modifiedSchema = clone<ZodObjectV4>(schema, {\n ...schema._zod.def,\n shape: outputShape,\n catchall: _unknown($ZodUnknown),\n });\n const meta = globalRegistry.get(schema);\n if (meta) globalRegistry.add(modifiedSchema, meta);\n return modifiedSchema;\n }\n throw new Error(\n \"Schema must be an instance of z3.ZodObject or z4.$ZodObject\"\n );\n}\n\n/**\n * Returns a getter function for the default value of a Zod schema, if one is defined.\n * Supports both Zod v3 and v4 schemas. If the schema has a default value,\n * the returned function will return that value when called. If no default is defined,\n * returns undefined.\n *\n * @template T - The type of the Zod schema.\n * @param {T} schema - The Zod schema instance (either v3 or v4).\n * @returns {(() => InferInteropZodOutput<T>) | undefined} A function that returns the default value, or undefined if no default is set.\n */\nexport function getInteropZodDefaultGetter<T extends InteropZodType>(\n schema: T\n): (() => InferInteropZodOutput<T>) | undefined {\n if (isZodSchemaV3(schema)) {\n try {\n const defaultValue = schema.parse(undefined);\n return () => defaultValue as InferInteropZodOutput<T>;\n } catch {\n return undefined;\n }\n }\n if (isZodSchemaV4(schema)) {\n try {\n const defaultValue = parse(schema, undefined);\n return () => defaultValue as InferInteropZodOutput<T>;\n } catch {\n return undefined;\n }\n }\n return undefined;\n}\n\nfunction isZodTransformV3(\n schema: InteropZodType\n): schema is z3.ZodEffects<z3.ZodTypeAny> {\n return (\n isZodSchemaV3(schema) &&\n \"typeName\" in schema._def &&\n schema._def.typeName === \"ZodEffects\"\n );\n}\n\nfunction isZodTransformV4(schema: InteropZodType): schema is z4.$ZodPipe {\n return isZodSchemaV4(schema) && schema._zod.def.type === \"pipe\";\n}\n\n/**\n * Returns the input type of a Zod transform schema, for both v3 and v4.\n * If the schema is not a transform, returns undefined. If `recursive` is true,\n * recursively processes nested object schemas and arrays of object schemas.\n *\n * @param schema - The Zod schema instance (v3 or v4)\n * @param {boolean} [recursive=false] - Whether to recursively process nested objects/arrays.\n * @returns The input Zod schema of the transform, or undefined if not a transform\n */\nexport function interopZodTransformInputSchema(\n schema: InteropZodType,\n recursive = false\n): InteropZodType {\n // Zod v3: ._def.schema is the input schema for ZodEffects (transform)\n if (isZodSchemaV3(schema)) {\n if (isZodTransformV3(schema)) {\n return interopZodTransformInputSchema(schema._def.schema, recursive);\n }\n // TODO: v3 schemas aren't recursively handled here\n // (currently not necessary since zodToJsonSchema handles this)\n return schema;\n }\n\n // Zod v4: _def.type is the input schema for ZodEffects (transform)\n if (isZodSchemaV4(schema)) {\n let outputSchema: InteropZodType = schema;\n if (isZodTransformV4(schema)) {\n outputSchema = interopZodTransformInputSchema(\n schema._zod.def.in,\n recursive\n );\n }\n if (recursive) {\n // Handle nested object schemas\n if (isZodObjectV4(outputSchema)) {\n const outputShape: Mutable<z4.$ZodShape> = outputSchema._zod.def.shape;\n for (const [key, keySchema] of Object.entries(\n outputSchema._zod.def.shape\n )) {\n outputShape[key] = interopZodTransformInputSchema(\n keySchema,\n recursive\n ) as z4.$ZodType;\n }\n outputSchema = clone<ZodObjectV4>(outputSchema, {\n ...outputSchema._zod.def,\n shape: outputShape,\n });\n }\n // Handle nested array schemas\n else if (isZodArrayV4(outputSchema)) {\n const elementSchema = interopZodTransformInputSchema(\n outputSchema._zod.def.element,\n recursive\n );\n outputSchema = clone<z4.$ZodArray>(outputSchema, {\n ...outputSchema._zod.def,\n element: elementSchema as z4.$ZodType,\n });\n }\n }\n const meta = globalRegistry.get(schema);\n if (meta) globalRegistry.add(outputSchema as z4.$ZodType, meta);\n return outputSchema;\n }\n\n throw new Error(\"Schema must be an instance of z3.ZodType or z4.$ZodType\");\n}\n\n/**\n * Creates a modified version of a Zod object schema where fields matching a predicate are made optional.\n * Supports both Zod v3 and v4 schemas and preserves the original schema version.\n *\n * @template T - The type of the Zod object schema.\n * @param {T} schema - The Zod object schema instance (either v3 or v4).\n * @param {(key: string, value: InteropZodType) => boolean} predicate - Function to determine which fields should be optional.\n * @returns {InteropZodObject} The modified Zod object schema.\n * @throws {Error} If the schema is not a Zod v3 or v4 object.\n */\nexport function interopZodObjectMakeFieldsOptional<T extends InteropZodObject>(\n schema: T,\n predicate: (key: string, value: InteropZodType) => boolean\n): InteropZodObject {\n if (isZodSchemaV3(schema)) {\n const shape = getInteropZodObjectShape(schema);\n const modifiedShape: Record<string, z3.ZodTypeAny> = {};\n\n for (const [key, value] of Object.entries(shape)) {\n if (predicate(key, value)) {\n // Make this field optional using v3 methods\n modifiedShape[key] = (value as z3.ZodTypeAny).optional();\n } else {\n // Keep field as-is\n modifiedShape[key] = value;\n }\n }\n\n // Use v3's extend method to create a new schema with the modified shape\n return schema.extend(modifiedShape as z3.ZodRawShape);\n }\n\n if (isZodSchemaV4(schema)) {\n const shape = getInteropZodObjectShape(schema);\n const outputShape: Mutable<z4.$ZodShape> = { ...schema._zod.def.shape };\n\n for (const [key, value] of Object.entries(shape)) {\n if (predicate(key, value)) {\n // Make this field optional using v4 methods\n outputShape[key] = new $ZodOptional({\n type: \"optional\" as const,\n innerType: value as z4.$ZodType,\n });\n }\n // Otherwise keep the field as-is (already in outputShape)\n }\n\n const modifiedSchema = clone<ZodObjectV4>(schema, {\n ...schema._zod.def,\n shape: outputShape,\n });\n\n // Preserve metadata\n const meta = globalRegistry.get(schema);\n if (meta) globalRegistry.add(modifiedSchema, meta);\n\n return modifiedSchema;\n }\n\n throw new Error(\n \"Schema must be an instance of z3.ZodObject or z4.$ZodObject\"\n );\n}\n"],"mappings":";;;;AAuFA,SAAgB,cACdA,QACyC;AACzC,KAAI,OAAO,WAAW,YAAY,WAAW,KAC3C,QAAO;CAGT,MAAM,MAAM;AACZ,KAAI,EAAE,UAAU,KACd,QAAO;CAGT,MAAM,MAAM,IAAI;AAChB,QACE,OAAO,QAAQ,YACf,QAAQ,QACR,SAAU;AAEb;AAED,SAAgB,cACdA,QACuD;AACvD,KAAI,OAAO,WAAW,YAAY,WAAW,KAC3C,QAAO;CAGT,MAAM,MAAM;AACZ,KAAI,EAAE,UAAU,QAAQ,UAAU,IAChC,QAAO;CAGT,MAAM,MAAM,IAAI;AAChB,QACE,OAAO,QAAQ,YACf,OAAO,QACP,cAAe;AAElB;;AAGD,SAAgB,YAGdC,QACiC;AACjC,KAAI,cAAc,OAAO,EACvB,QAAQ,KACN,4HACD;AAEH,QAAO,cAAc,OAAO;AAC7B;;;;;;;AAQD,SAAgB,mBAAmBC,OAAyC;AAC1E,KAAI,CAAC,MACH,QAAO;AAET,KAAI,OAAO,UAAU,SACnB,QAAO;AAET,KAAI,MAAM,QAAQ,MAAM,CACtB,QAAO;AAET,KACE,cAAc,MAAM,IACpB,cAAc,MAA6C,CAE3D,QAAO;AAET,QAAO;AACR;AAID,SAAgB,eAA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I,cAAc,OAAO,EAAE;EACzB,MAAM,QAAQ,yBAAyB,OAAO;EAC9C,MAAMC,gBAA+C,CAAE;AAEvD,OAAK,MAAM,CAAC,KAAK,MAAM,IAAI,OAAO,QAAQ,MAAM,CAC9C,KAAI,UAAU,KAAK,MAAM,EAEvB,cAAc,OAAQ,MAAwB,UAAU;OAGxD,cAAc,OAAO;AAKzB,SAAO,OAAO,OAAO,cAAgC;CACtD;AAED,KAAI,cAAc,OAAO,EAAE;EACzB,MAAM,QAAQ,yBAAyB,OAAO;EAC9C,MAAMP,cAAqC,EAAE,GAAG,OAAO,KAAK,IAAI,MAAO;AAEvE,OAAK,MAAM,CAAC,KAAK,MAAM,IAAI,OAAO,QAAQ,MAAM,CAC9C,KAAI,UAAU,KAAK,MAAM,EAEvB,YAAY,OAAO,IAAID,yBAAa;GAClC,MAAM;GACN,WAAW;EACZ;EAKL,MAAM,wCAAoC,QAAQ;GAChD,GAAG,OAAO,KAAK;GACf,OAAO;EACR,EAAC;EAGF,MAAM,OAAOJ,2BAAe,IAAI,OAAO;AACvC,MAAI,MAAMA,2BAAe,IAAI,gBAAgB,KAAK;AAElD,SAAO;CACR;AAED,OAAM,IAAI,MACR;AAEH"}
|
|
1
|
+
{"version":3,"file":"zod.cjs","names":["schema: unknown","schema: z3.ZodType<RunOutput> | Record<string, unknown>","input: unknown","obj: unknown","schema: InteropZodType<T>","schema: InteropZodType<unknown> | Record<string, unknown>","globalRegistry","schema: T","extension: InteropZodObjectShape","util","$ZodOptional","outputShape: Mutable<z4.$ZodShape>","meta","$ZodNever","$ZodUnknown","schema: InteropZodType","recursive: boolean","cache: WeakMap<InteropZodType, InteropZodType>","outputSchema: InteropZodType","predicate: (key: string, value: InteropZodType) => boolean","modifiedShape: Record<string, z3.ZodTypeAny>"],"sources":["../../../src/utils/types/zod.ts"],"sourcesContent":["import type * as z3 from \"zod/v3\";\nimport type * as z4 from \"zod/v4/core\";\nimport {\n parse,\n parseAsync,\n globalRegistry,\n util,\n clone,\n _unknown,\n _never,\n $ZodUnknown,\n $ZodNever,\n $ZodOptional,\n} from \"zod/v4/core\";\n\nexport type ZodStringV3 = z3.ZodString;\n\nexport type ZodStringV4 = z4.$ZodType<string, unknown>;\n\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nexport type ZodObjectV3 = z3.ZodObject<any, any, any, any>;\n\nexport type ZodObjectV4 = z4.$ZodObject;\n\nexport type ZodDefaultV3<T extends z3.ZodTypeAny> = z3.ZodDefault<T>;\nexport type ZodDefaultV4<T extends z4.SomeType> = z4.$ZodDefault<T>;\nexport type ZodOptionalV3<T extends z3.ZodTypeAny> = z3.ZodOptional<T>;\nexport type ZodOptionalV4<T extends z4.SomeType> = z4.$ZodOptional<T>;\n\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nexport type InteropZodType<Output = any, Input = Output> =\n | z3.ZodType<Output, z3.ZodTypeDef, Input>\n | z4.$ZodType<Output, Input>;\n\nexport type InteropZodObject = ZodObjectV3 | ZodObjectV4;\nexport type InteropZodDefault<T = InteropZodObjectShape> =\n T extends z3.ZodTypeAny\n ? ZodDefaultV3<T>\n : T extends z4.SomeType\n ? ZodDefaultV4<T>\n : never;\nexport type InteropZodOptional<T = InteropZodObjectShape> =\n T extends z3.ZodTypeAny\n ? ZodOptionalV3<T>\n : T extends z4.SomeType\n ? ZodOptionalV4<T>\n : never;\n\nexport type InteropZodObjectShape<\n T extends InteropZodObject = InteropZodObject\n> = T extends z3.ZodObject<infer Shape>\n ? { [K in keyof Shape]: Shape[K] }\n : T extends z4.$ZodObject<infer Shape>\n ? { [K in keyof Shape]: Shape[K] }\n : never;\n\nexport type InteropZodIssue = z3.ZodIssue | z4.$ZodIssue;\n\n// Simplified type inference to avoid circular dependencies\nexport type InferInteropZodInput<T> = T extends z3.ZodType<\n unknown,\n z3.ZodTypeDef,\n infer Input\n>\n ? Input\n : T extends z4.$ZodType<unknown, infer Input>\n ? Input\n : T extends { _zod: { input: infer Input } }\n ? Input\n : never;\n\nexport type InferInteropZodOutput<T> = T extends z3.ZodType<\n infer Output,\n z3.ZodTypeDef,\n unknown\n>\n ? Output\n : T extends z4.$ZodType<infer Output, unknown>\n ? Output\n : T extends { _zod: { output: infer Output } }\n ? Output\n : never;\n\nexport type Mutable<T> = {\n -readonly [P in keyof T]: T[P];\n};\n\nexport function isZodSchemaV4(\n schema: unknown\n): schema is z4.$ZodType<unknown, unknown> {\n if (typeof schema !== \"object\" || schema === null) {\n return false;\n }\n\n const obj = schema as Record<string, unknown>;\n if (!(\"_zod\" in obj)) {\n return false;\n }\n\n const zod = obj._zod;\n return (\n typeof zod === \"object\" &&\n zod !== null &&\n \"def\" in (zod as Record<string, unknown>)\n );\n}\n\nexport function isZodSchemaV3(\n schema: unknown\n): schema is z3.ZodType<unknown, z3.ZodTypeDef, unknown> {\n if (typeof schema !== \"object\" || schema === null) {\n return false;\n }\n\n const obj = schema as Record<string, unknown>;\n if (!(\"_def\" in obj) || \"_zod\" in obj) {\n return false;\n }\n\n const def = obj._def;\n return (\n typeof def === \"object\" &&\n def != null &&\n \"typeName\" in (def as Record<string, unknown>)\n );\n}\n\n/** Backward compatible isZodSchema for Zod 3 */\nexport function isZodSchema<\n RunOutput extends Record<string, unknown> = Record<string, unknown>\n>(\n schema: z3.ZodType<RunOutput> | Record<string, unknown>\n): schema is z3.ZodType<RunOutput> {\n if (isZodSchemaV4(schema)) {\n console.warn(\n \"[WARNING] Attempting to use Zod 4 schema in a context where Zod 3 schema is expected. This may cause unexpected behavior.\"\n );\n }\n return isZodSchemaV3(schema);\n}\n\n/**\n * Given either a Zod schema, or plain object, determine if the input is a Zod schema.\n *\n * @param {unknown} input\n * @returns {boolean} Whether or not the provided input is a Zod schema.\n */\nexport function isInteropZodSchema(input: unknown): input is InteropZodType {\n if (!input) {\n return false;\n }\n if (typeof input !== \"object\") {\n return false;\n }\n if (Array.isArray(input)) {\n return false;\n }\n if (\n isZodSchemaV4(input) ||\n isZodSchemaV3(input as z3.ZodType<Record<string, unknown>>)\n ) {\n return true;\n }\n return false;\n}\n\nexport type InteropZodLiteral = z3.ZodLiteral<unknown> | z4.$ZodLiteral;\n\nexport function isZodLiteralV3(obj: unknown): obj is z3.ZodLiteral<unknown> {\n // Zod v3 literal schemas have _def.typeName === \"ZodLiteral\"\n if (\n typeof obj === \"object\" &&\n obj !== null &&\n \"_def\" in obj &&\n typeof obj._def === \"object\" &&\n obj._def !== null &&\n \"typeName\" in obj._def &&\n obj._def.typeName === \"ZodLiteral\"\n ) {\n return true;\n }\n return false;\n}\n\nexport function isZodLiteralV4(obj: unknown): obj is z4.$ZodLiteral {\n if (!isZodSchemaV4(obj)) return false;\n // Zod v4 literal schemas have _zod.def.type === \"literal\"\n if (\n typeof obj === \"object\" &&\n obj !== null &&\n \"_zod\" in obj &&\n typeof obj._zod === \"object\" &&\n obj._zod !== null &&\n \"def\" in obj._zod &&\n typeof obj._zod.def === \"object\" &&\n obj._zod.def !== null &&\n \"type\" in obj._zod.def &&\n obj._zod.def.type === \"literal\"\n ) {\n return true;\n }\n return false;\n}\n\n/**\n * Determines if the provided value is an InteropZodLiteral (Zod v3 or v4 literal schema).\n *\n * @param obj The value to check.\n * @returns {boolean} True if the value is a Zod v3 or v4 literal schema, false otherwise.\n */\nexport function isInteropZodLiteral(obj: unknown): obj is InteropZodLiteral {\n if (isZodLiteralV3(obj)) return true;\n if (isZodLiteralV4(obj)) return true;\n return false;\n}\n\ntype InteropZodSafeParseResult<T> = z3.SafeParseReturnType<T, T>;\n\n/**\n * Asynchronously parses the input using the provided Zod schema (v3 or v4) and returns a safe parse result.\n * This function handles both Zod v3 and v4 schemas, returning a result object indicating success or failure.\n *\n * @template T - The expected output type of the schema.\n * @param {InteropZodType<T>} schema - The Zod schema (v3 or v4) to use for parsing.\n * @param {unknown} input - The input value to parse.\n * @returns {Promise<InteropZodSafeParseResult<T>>} A promise that resolves to a safe parse result object.\n * @throws {Error} If the schema is not a recognized Zod v3 or v4 schema.\n */\nexport async function interopSafeParseAsync<T>(\n schema: InteropZodType<T>,\n input: unknown\n): Promise<InteropZodSafeParseResult<T>> {\n if (isZodSchemaV4(schema)) {\n try {\n const data = await parseAsync(schema, input);\n return {\n success: true,\n data,\n };\n } catch (error) {\n return {\n success: false,\n error: error as z3.ZodError<T>,\n };\n }\n }\n if (isZodSchemaV3(schema as z3.ZodType<Record<string, unknown>>)) {\n return await schema.safeParseAsync(input);\n }\n throw new Error(\"Schema must be an instance of z3.ZodType or z4.$ZodType\");\n}\n\n/**\n * Asynchronously parses the input using the provided Zod schema (v3 or v4) and returns the parsed value.\n * Throws an error if parsing fails or if the schema is not a recognized Zod v3 or v4 schema.\n *\n * @template T - The expected output type of the schema.\n * @param {InteropZodType<T>} schema - The Zod schema (v3 or v4) to use for parsing.\n * @param {unknown} input - The input value to parse.\n * @returns {Promise<T>} A promise that resolves to the parsed value.\n * @throws {Error} If parsing fails or the schema is not a recognized Zod v3 or v4 schema.\n */\nexport async function interopParseAsync<T>(\n schema: InteropZodType<T>,\n input: unknown\n): Promise<T> {\n if (isZodSchemaV4(schema)) {\n return await parseAsync(schema, input);\n }\n if (isZodSchemaV3(schema as z3.ZodType<Record<string, unknown>>)) {\n return await schema.parseAsync(input);\n }\n throw new Error(\"Schema must be an instance of z3.ZodType or z4.$ZodType\");\n}\n\n/**\n * Safely parses the input using the provided Zod schema (v3 or v4) and returns a result object\n * indicating success or failure. This function is compatible with both Zod v3 and v4 schemas.\n *\n * @template T - The expected output type of the schema.\n * @param {InteropZodType<T>} schema - The Zod schema (v3 or v4) to use for parsing.\n * @param {unknown} input - The input value to parse.\n * @returns {InteropZodSafeParseResult<T>} An object with either the parsed data (on success)\n * or the error (on failure).\n * @throws {Error} If the schema is not a recognized Zod v3 or v4 schema.\n */\nexport function interopSafeParse<T>(\n schema: InteropZodType<T>,\n input: unknown\n): InteropZodSafeParseResult<T> {\n if (isZodSchemaV4(schema)) {\n try {\n const data = parse(schema, input);\n return {\n success: true,\n data,\n };\n } catch (error) {\n return {\n success: false,\n error: error as z3.ZodError<T>,\n };\n }\n }\n if (isZodSchemaV3(schema as z3.ZodType<Record<string, unknown>>)) {\n return schema.safeParse(input);\n }\n throw new Error(\"Schema must be an instance of z3.ZodType or z4.$ZodType\");\n}\n\n/**\n * Parses the input using the provided Zod schema (v3 or v4) and returns the parsed value.\n * Throws an error if parsing fails or if the schema is not a recognized Zod v3 or v4 schema.\n *\n * @template T - The expected output type of the schema.\n * @param {InteropZodType<T>} schema - The Zod schema (v3 or v4) to use for parsing.\n * @param {unknown} input - The input value to parse.\n * @returns {T} The parsed value.\n * @throws {Error} If parsing fails or the schema is not a recognized Zod v3 or v4 schema.\n */\nexport function interopParse<T>(schema: InteropZodType<T>, input: unknown): T {\n if (isZodSchemaV4(schema)) {\n return parse(schema, input);\n }\n if (isZodSchemaV3(schema as z3.ZodType<Record<string, unknown>>)) {\n return schema.parse(input);\n }\n throw new Error(\"Schema must be an instance of z3.ZodType or z4.$ZodType\");\n}\n\n/**\n * Retrieves the description from a schema definition (v3, v4, or plain object), if available.\n *\n * @param {unknown} schema - The schema to extract the description from.\n * @returns {string | undefined} The description of the schema, or undefined if not present.\n */\nexport function getSchemaDescription(\n schema: InteropZodType<unknown> | Record<string, unknown>\n): string | undefined {\n if (isZodSchemaV4(schema)) {\n return globalRegistry.get(schema)?.description;\n }\n if (isZodSchemaV3(schema as z3.ZodType<Record<string, unknown>>)) {\n return schema.description as string | undefined;\n }\n if (\"description\" in schema && typeof schema.description === \"string\") {\n return schema.description;\n }\n return undefined;\n}\n\n/**\n * Determines if the provided Zod schema is \"shapeless\".\n * A shapeless schema is one that does not define any object shape,\n * such as ZodString, ZodNumber, ZodBoolean, ZodAny, etc.\n * For ZodObject, it must have no shape keys to be considered shapeless.\n * ZodRecord schemas are considered shapeless since they define dynamic\n * key-value mappings without fixed keys.\n *\n * @param schema The Zod schema to check.\n * @returns {boolean} True if the schema is shapeless, false otherwise.\n */\nexport function isShapelessZodSchema(schema: unknown): boolean {\n if (!isInteropZodSchema(schema)) {\n return false;\n }\n\n // Check for v3 schemas\n if (isZodSchemaV3(schema as z3.ZodType<Record<string, unknown>>)) {\n // @ts-expect-error - zod v3 types are not compatible with zod v4 types\n const def = schema._def as { typeName?: string };\n\n // ZodObject is only shaped if it has actual shape keys\n if (def.typeName === \"ZodObject\") {\n const obj = schema as { shape?: Record<string, unknown> };\n return !obj.shape || Object.keys(obj.shape).length === 0;\n }\n\n // ZodRecord is shapeless (dynamic key-value mapping)\n if (def.typeName === \"ZodRecord\") {\n return true;\n }\n }\n\n // Check for v4 schemas\n if (isZodSchemaV4(schema)) {\n const def = schema._zod.def;\n\n // Object type is only shaped if it has actual shape keys\n if (def.type === \"object\") {\n const obj = schema as { shape?: Record<string, unknown> };\n return !obj.shape || Object.keys(obj.shape).length === 0;\n }\n\n // Record type is shapeless (dynamic key-value mapping)\n if (def.type === \"record\") {\n return true;\n }\n }\n\n // For other schemas, check if they have a `shape` property\n // If they don't have shape, they're likely shapeless\n if (typeof schema === \"object\" && schema !== null && !(\"shape\" in schema)) {\n return true;\n }\n\n return false;\n}\n\n/**\n * Determines if the provided Zod schema should be treated as a simple string schema\n * that maps to DynamicTool. This aligns with the type-level constraint of\n * InteropZodType<string | undefined> which only matches basic string schemas.\n * If the provided schema is just z.string(), we can make the determination that\n * the tool is just a generic string tool that doesn't require any input validation.\n *\n * This function only returns true for basic ZodString schemas, including:\n * - Basic string schemas (z.string())\n * - String schemas with validations (z.string().min(1), z.string().email(), etc.)\n *\n * This function returns false for everything else, including:\n * - String schemas with defaults (z.string().default(\"value\"))\n * - Branded string schemas (z.string().brand<\"UserId\">())\n * - String schemas with catch operations (z.string().catch(\"default\"))\n * - Optional/nullable string schemas (z.string().optional())\n * - Transformed schemas (z.string().transform() or z.object().transform())\n * - Object or record schemas, even if they're empty\n * - Any other schema type\n *\n * @param schema The Zod schema to check.\n * @returns {boolean} True if the schema is a basic ZodString, false otherwise.\n */\nexport function isSimpleStringZodSchema(\n schema: unknown\n): schema is InteropZodType<string | undefined> {\n if (!isInteropZodSchema(schema)) {\n return false;\n }\n\n // For v3 schemas\n if (isZodSchemaV3(schema as z3.ZodType<Record<string, unknown>>)) {\n // @ts-expect-error - zod v3 types are not compatible with zod v4 types\n const def = schema._def as { typeName?: string };\n\n // Only accept basic ZodString\n return def.typeName === \"ZodString\";\n }\n\n // For v4 schemas\n if (isZodSchemaV4(schema)) {\n const def = schema._zod.def;\n\n // Only accept basic string type\n return def.type === \"string\";\n }\n\n return false;\n}\n\nexport function isZodObjectV3(obj: unknown): obj is ZodObjectV3 {\n // Zod v3 object schemas have _def.typeName === \"ZodObject\"\n if (\n typeof obj === \"object\" &&\n obj !== null &&\n \"_def\" in obj &&\n typeof obj._def === \"object\" &&\n obj._def !== null &&\n \"typeName\" in obj._def &&\n obj._def.typeName === \"ZodObject\"\n ) {\n return true;\n }\n return false;\n}\n\nexport function isZodObjectV4(obj: unknown): obj is z4.$ZodObject {\n if (!isZodSchemaV4(obj)) return false;\n // Zod v4 object schemas have _zod.def.type === \"object\"\n if (\n typeof obj === \"object\" &&\n obj !== null &&\n \"_zod\" in obj &&\n typeof obj._zod === \"object\" &&\n obj._zod !== null &&\n \"def\" in obj._zod &&\n typeof obj._zod.def === \"object\" &&\n obj._zod.def !== null &&\n \"type\" in obj._zod.def &&\n obj._zod.def.type === \"object\"\n ) {\n return true;\n }\n return false;\n}\n\nexport function isZodArrayV4(obj: unknown): obj is z4.$ZodArray {\n if (!isZodSchemaV4(obj)) return false;\n // Zod v4 array schemas have _zod.def.type === \"array\"\n if (\n typeof obj === \"object\" &&\n obj !== null &&\n \"_zod\" in obj &&\n typeof obj._zod === \"object\" &&\n obj._zod !== null &&\n \"def\" in obj._zod &&\n typeof obj._zod.def === \"object\" &&\n obj._zod.def !== null &&\n \"type\" in obj._zod.def &&\n obj._zod.def.type === \"array\"\n ) {\n return true;\n }\n return false;\n}\n\n/**\n * Determines if the provided value is an InteropZodObject (Zod v3 or v4 object schema).\n *\n * @param obj The value to check.\n * @returns {boolean} True if the value is a Zod v3 or v4 object schema, false otherwise.\n */\nexport function isInteropZodObject(obj: unknown): obj is InteropZodObject {\n if (isZodObjectV3(obj)) return true;\n if (isZodObjectV4(obj)) return true;\n return false;\n}\n\n/**\n * Retrieves the shape (fields) of a Zod object schema, supporting both Zod v3 and v4.\n *\n * @template T - The type of the Zod object schema.\n * @param {T} schema - The Zod object schema instance (either v3 or v4).\n * @returns {InteropZodObjectShape<T>} The shape of the object schema.\n * @throws {Error} If the schema is not a Zod v3 or v4 object.\n */\nexport function getInteropZodObjectShape<T extends InteropZodObject>(\n schema: T\n): InteropZodObjectShape<T> {\n if (isZodSchemaV3(schema)) {\n return schema.shape;\n }\n if (isZodSchemaV4(schema)) {\n return schema._zod.def.shape as InteropZodObjectShape<T>;\n }\n throw new Error(\n \"Schema must be an instance of z3.ZodObject or z4.$ZodObject\"\n );\n}\n\n/**\n * Extends a Zod object schema with additional fields, supporting both Zod v3 and v4.\n *\n * @template T - The type of the Zod object schema.\n * @param {T} schema - The Zod object schema instance (either v3 or v4).\n * @param {InteropZodObjectShape} extension - The fields to add to the schema.\n * @returns {InteropZodObject} The extended Zod object schema.\n * @throws {Error} If the schema is not a Zod v3 or v4 object.\n */\nexport function extendInteropZodObject<T extends InteropZodObject>(\n schema: T,\n extension: InteropZodObjectShape\n): InteropZodObject {\n if (isZodSchemaV3(schema)) {\n return schema.extend(extension as z3.ZodRawShape);\n }\n if (isZodSchemaV4(schema)) {\n return util.extend(schema, extension);\n }\n throw new Error(\n \"Schema must be an instance of z3.ZodObject or z4.$ZodObject\"\n );\n}\n\n/**\n * Returns a partial version of a Zod object schema, making all fields optional.\n * Supports both Zod v3 and v4.\n *\n * @template T - The type of the Zod object schema.\n * @param {T} schema - The Zod object schema instance (either v3 or v4).\n * @returns {InteropZodObject} The partial Zod object schema.\n * @throws {Error} If the schema is not a Zod v3 or v4 object.\n */\nexport function interopZodObjectPartial<T extends InteropZodObject>(\n schema: T\n): InteropZodObject {\n if (isZodSchemaV3(schema)) {\n // z3: .partial() exists and works as expected\n return schema.partial();\n }\n if (isZodSchemaV4(schema)) {\n // z4: util.partial exists and works as expected\n return util.partial($ZodOptional, schema, undefined);\n }\n throw new Error(\n \"Schema must be an instance of z3.ZodObject or z4.$ZodObject\"\n );\n}\n\n/**\n * Returns a strict version of a Zod object schema, disallowing unknown keys.\n * Supports both Zod v3 and v4 object schemas. If `recursive` is true, applies strictness\n * recursively to all nested object schemas and arrays of object schemas.\n *\n * @template T - The type of the Zod object schema.\n * @param {T} schema - The Zod object schema instance (either v3 or v4).\n * @param {boolean} [recursive=false] - Whether to apply strictness recursively to nested objects/arrays.\n * @returns {InteropZodObject} The strict Zod object schema.\n * @throws {Error} If the schema is not a Zod v3 or v4 object.\n */\nexport function interopZodObjectStrict<T extends InteropZodObject>(\n schema: T,\n recursive = false\n): InteropZodObject {\n if (isZodSchemaV3(schema)) {\n // TODO: v3 schemas aren't recursively handled here\n // (currently not necessary since zodToJsonSchema handles this)\n return schema.strict();\n }\n if (isZodObjectV4(schema)) {\n const outputShape: Mutable<z4.$ZodShape> = schema._zod.def.shape;\n if (recursive) {\n for (const [key, keySchema] of Object.entries(schema._zod.def.shape)) {\n // If the shape key is a v4 object schema, we need to make it strict\n if (isZodObjectV4(keySchema)) {\n const outputSchema = interopZodObjectStrict(keySchema, recursive);\n outputShape[key] = outputSchema as ZodObjectV4;\n }\n // If the shape key is a v4 array schema, we need to make the element\n // schema strict if it's an object schema\n else if (isZodArrayV4(keySchema)) {\n let elementSchema = keySchema._zod.def.element;\n if (isZodObjectV4(elementSchema)) {\n elementSchema = interopZodObjectStrict(\n elementSchema,\n recursive\n ) as ZodObjectV4;\n }\n outputShape[key] = clone(keySchema, {\n ...keySchema._zod.def,\n element: elementSchema,\n });\n }\n // Otherwise, just use the keySchema\n else {\n outputShape[key] = keySchema;\n }\n // Assign meta fields to the keySchema\n const meta = globalRegistry.get(keySchema);\n if (meta) globalRegistry.add(outputShape[key], meta);\n }\n }\n const modifiedSchema = clone<ZodObjectV4>(schema, {\n ...schema._zod.def,\n shape: outputShape,\n catchall: _never($ZodNever),\n });\n const meta = globalRegistry.get(schema);\n if (meta) globalRegistry.add(modifiedSchema, meta);\n return modifiedSchema;\n }\n throw new Error(\n \"Schema must be an instance of z3.ZodObject or z4.$ZodObject\"\n );\n}\n\n/**\n * Returns a passthrough version of a Zod object schema, allowing unknown keys.\n * Supports both Zod v3 and v4 object schemas. If `recursive` is true, applies passthrough\n * recursively to all nested object schemas and arrays of object schemas.\n *\n * @template T - The type of the Zod object schema.\n * @param {T} schema - The Zod object schema instance (either v3 or v4).\n * @param {boolean} [recursive=false] - Whether to apply passthrough recursively to nested objects/arrays.\n * @returns {InteropZodObject} The passthrough Zod object schema.\n * @throws {Error} If the schema is not a Zod v3 or v4 object.\n */\nexport function interopZodObjectPassthrough<T extends InteropZodObject>(\n schema: T,\n recursive = false\n): InteropZodObject {\n if (isZodObjectV3(schema)) {\n // TODO: v3 schemas aren't recursively handled here\n // (currently not necessary since zodToJsonSchema handles this)\n return schema.passthrough();\n }\n if (isZodObjectV4(schema)) {\n const outputShape: Mutable<z4.$ZodShape> = schema._zod.def.shape;\n if (recursive) {\n for (const [key, keySchema] of Object.entries(schema._zod.def.shape)) {\n // If the shape key is a v4 object schema, we need to make it passthrough\n if (isZodObjectV4(keySchema)) {\n const outputSchema = interopZodObjectPassthrough(\n keySchema,\n recursive\n );\n outputShape[key] = outputSchema as ZodObjectV4;\n }\n // If the shape key is a v4 array schema, we need to make the element\n // schema passthrough if it's an object schema\n else if (isZodArrayV4(keySchema)) {\n let elementSchema = keySchema._zod.def.element;\n if (isZodObjectV4(elementSchema)) {\n elementSchema = interopZodObjectPassthrough(\n elementSchema,\n recursive\n ) as ZodObjectV4;\n }\n outputShape[key] = clone(keySchema, {\n ...keySchema._zod.def,\n element: elementSchema,\n });\n }\n // Otherwise, just use the keySchema\n else {\n outputShape[key] = keySchema;\n }\n // Assign meta fields to the keySchema\n const meta = globalRegistry.get(keySchema);\n if (meta) globalRegistry.add(outputShape[key], meta);\n }\n }\n const modifiedSchema = clone<ZodObjectV4>(schema, {\n ...schema._zod.def,\n shape: outputShape,\n catchall: _unknown($ZodUnknown),\n });\n const meta = globalRegistry.get(schema);\n if (meta) globalRegistry.add(modifiedSchema, meta);\n return modifiedSchema;\n }\n throw new Error(\n \"Schema must be an instance of z3.ZodObject or z4.$ZodObject\"\n );\n}\n\n/**\n * Returns a getter function for the default value of a Zod schema, if one is defined.\n * Supports both Zod v3 and v4 schemas. If the schema has a default value,\n * the returned function will return that value when called. If no default is defined,\n * returns undefined.\n *\n * @template T - The type of the Zod schema.\n * @param {T} schema - The Zod schema instance (either v3 or v4).\n * @returns {(() => InferInteropZodOutput<T>) | undefined} A function that returns the default value, or undefined if no default is set.\n */\nexport function getInteropZodDefaultGetter<T extends InteropZodType>(\n schema: T\n): (() => InferInteropZodOutput<T>) | undefined {\n if (isZodSchemaV3(schema)) {\n try {\n const defaultValue = schema.parse(undefined);\n return () => defaultValue as InferInteropZodOutput<T>;\n } catch {\n return undefined;\n }\n }\n if (isZodSchemaV4(schema)) {\n try {\n const defaultValue = parse(schema, undefined);\n return () => defaultValue as InferInteropZodOutput<T>;\n } catch {\n return undefined;\n }\n }\n return undefined;\n}\n\nfunction isZodTransformV3(\n schema: InteropZodType\n): schema is z3.ZodEffects<z3.ZodTypeAny> {\n return (\n isZodSchemaV3(schema) &&\n \"typeName\" in schema._def &&\n schema._def.typeName === \"ZodEffects\"\n );\n}\n\nfunction isZodTransformV4(schema: InteropZodType): schema is z4.$ZodPipe {\n return isZodSchemaV4(schema) && schema._zod.def.type === \"pipe\";\n}\n\nfunction interopZodTransformInputSchemaImpl(\n schema: InteropZodType,\n recursive: boolean,\n cache: WeakMap<InteropZodType, InteropZodType>\n): InteropZodType {\n const cached = cache.get(schema);\n if (cached !== undefined) {\n return cached;\n }\n\n // Zod v3: ._def.schema is the input schema for ZodEffects (transform)\n if (isZodSchemaV3(schema)) {\n if (isZodTransformV3(schema)) {\n return interopZodTransformInputSchemaImpl(\n schema._def.schema,\n recursive,\n cache\n );\n }\n // TODO: v3 schemas aren't recursively handled here\n // (currently not necessary since zodToJsonSchema handles this)\n return schema;\n }\n\n // Zod v4: _def.type is the input schema for ZodEffects (transform)\n if (isZodSchemaV4(schema)) {\n let outputSchema: InteropZodType = schema;\n if (isZodTransformV4(schema)) {\n outputSchema = interopZodTransformInputSchemaImpl(\n schema._zod.def.in,\n recursive,\n cache\n );\n }\n if (recursive) {\n // Handle nested object schemas\n if (isZodObjectV4(outputSchema)) {\n const outputShape: Mutable<z4.$ZodShape> = outputSchema._zod.def.shape;\n for (const [key, keySchema] of Object.entries(\n outputSchema._zod.def.shape\n )) {\n outputShape[key] = interopZodTransformInputSchemaImpl(\n keySchema,\n recursive,\n cache\n ) as z4.$ZodType;\n }\n outputSchema = clone<ZodObjectV4>(outputSchema, {\n ...outputSchema._zod.def,\n shape: outputShape,\n });\n }\n // Handle nested array schemas\n else if (isZodArrayV4(outputSchema)) {\n const elementSchema = interopZodTransformInputSchemaImpl(\n outputSchema._zod.def.element,\n recursive,\n cache\n );\n outputSchema = clone<z4.$ZodArray>(outputSchema, {\n ...outputSchema._zod.def,\n element: elementSchema as z4.$ZodType,\n });\n }\n }\n const meta = globalRegistry.get(schema);\n if (meta) globalRegistry.add(outputSchema as z4.$ZodType, meta);\n cache.set(schema, outputSchema);\n return outputSchema;\n }\n\n throw new Error(\"Schema must be an instance of z3.ZodType or z4.$ZodType\");\n}\n\n/**\n * Returns the input type of a Zod transform schema, for both v3 and v4.\n * If the schema is not a transform, returns undefined. If `recursive` is true,\n * recursively processes nested object schemas and arrays of object schemas.\n *\n * @param schema - The Zod schema instance (v3 or v4)\n * @param {boolean} [recursive=false] - Whether to recursively process nested objects/arrays.\n * @returns The input Zod schema of the transform, or undefined if not a transform\n */\nexport function interopZodTransformInputSchema(\n schema: InteropZodType,\n recursive = false\n): InteropZodType {\n const cache = new WeakMap<InteropZodType, InteropZodType>();\n return interopZodTransformInputSchemaImpl(schema, recursive, cache);\n}\n\n/**\n * Creates a modified version of a Zod object schema where fields matching a predicate are made optional.\n * Supports both Zod v3 and v4 schemas and preserves the original schema version.\n *\n * @template T - The type of the Zod object schema.\n * @param {T} schema - The Zod object schema instance (either v3 or v4).\n * @param {(key: string, value: InteropZodType) => boolean} predicate - Function to determine which fields should be optional.\n * @returns {InteropZodObject} The modified Zod object schema.\n * @throws {Error} If the schema is not a Zod v3 or v4 object.\n */\nexport function interopZodObjectMakeFieldsOptional<T extends InteropZodObject>(\n schema: T,\n predicate: (key: string, value: InteropZodType) => boolean\n): InteropZodObject {\n if (isZodSchemaV3(schema)) {\n const shape = getInteropZodObjectShape(schema);\n const modifiedShape: Record<string, z3.ZodTypeAny> = {};\n\n for (const [key, value] of Object.entries(shape)) {\n if (predicate(key, value)) {\n // Make this field optional using v3 methods\n modifiedShape[key] = (value as z3.ZodTypeAny).optional();\n } else {\n // Keep field as-is\n modifiedShape[key] = value;\n }\n }\n\n // Use v3's extend method to create a new schema with the modified shape\n return schema.extend(modifiedShape as z3.ZodRawShape);\n }\n\n if (isZodSchemaV4(schema)) {\n const shape = getInteropZodObjectShape(schema);\n const outputShape: Mutable<z4.$ZodShape> = { ...schema._zod.def.shape };\n\n for (const [key, value] of Object.entries(shape)) {\n if (predicate(key, value)) {\n // Make this field optional using v4 methods\n outputShape[key] = new $ZodOptional({\n type: \"optional\" as const,\n innerType: value as z4.$ZodType,\n });\n }\n // Otherwise keep the field as-is (already in outputShape)\n }\n\n const modifiedSchema = clone<ZodObjectV4>(schema, {\n ...schema._zod.def,\n shape: outputShape,\n });\n\n // Preserve metadata\n const meta = globalRegistry.get(schema);\n if (meta) globalRegistry.add(modifiedSchema, meta);\n\n return modifiedSchema;\n }\n\n throw new Error(\n \"Schema must be an instance of z3.ZodObject or z4.$ZodObject\"\n );\n}\n"],"mappings":";;;;AAuFA,SAAgB,cACdA,QACyC;AACzC,KAAI,OAAO,WA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zB,MAAM,QAAQ,yBAAyB,OAAO;EAC9C,MAAMT,cAAqC,EAAE,GAAG,OAAO,KAAK,IAAI,MAAO;AAEvE,OAAK,MAAM,CAAC,KAAK,MAAM,IAAI,OAAO,QAAQ,MAAM,CAC9C,KAAI,UAAU,KAAK,MAAM,EAEvB,YAAY,OAAO,IAAID,yBAAa;GAClC,MAAM;GACN,WAAW;EACZ;EAKL,MAAM,wCAAoC,QAAQ;GAChD,GAAG,OAAO,KAAK;GACf,OAAO;EACR,EAAC;EAGF,MAAM,OAAOJ,2BAAe,IAAI,OAAO;AACvC,MAAI,MAAMA,2BAAe,IAAI,gBAAgB,KAAK;AAElD,SAAO;CACR;AAED,OAAM,IAAI,MACR;AAEH"}
|
package/dist/utils/types/zod.js
CHANGED
|
@@ -394,33 +394,26 @@ function isZodTransformV3(schema) {
|
|
|
394
394
|
function isZodTransformV4(schema) {
|
|
395
395
|
return isZodSchemaV4(schema) && schema._zod.def.type === "pipe";
|
|
396
396
|
}
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
* recursively processes nested object schemas and arrays of object schemas.
|
|
401
|
-
*
|
|
402
|
-
* @param schema - The Zod schema instance (v3 or v4)
|
|
403
|
-
* @param {boolean} [recursive=false] - Whether to recursively process nested objects/arrays.
|
|
404
|
-
* @returns The input Zod schema of the transform, or undefined if not a transform
|
|
405
|
-
*/
|
|
406
|
-
function interopZodTransformInputSchema(schema, recursive = false) {
|
|
397
|
+
function interopZodTransformInputSchemaImpl(schema, recursive, cache) {
|
|
398
|
+
const cached = cache.get(schema);
|
|
399
|
+
if (cached !== void 0) return cached;
|
|
407
400
|
if (isZodSchemaV3(schema)) {
|
|
408
|
-
if (isZodTransformV3(schema)) return
|
|
401
|
+
if (isZodTransformV3(schema)) return interopZodTransformInputSchemaImpl(schema._def.schema, recursive, cache);
|
|
409
402
|
return schema;
|
|
410
403
|
}
|
|
411
404
|
if (isZodSchemaV4(schema)) {
|
|
412
405
|
let outputSchema = schema;
|
|
413
|
-
if (isZodTransformV4(schema)) outputSchema =
|
|
406
|
+
if (isZodTransformV4(schema)) outputSchema = interopZodTransformInputSchemaImpl(schema._zod.def.in, recursive, cache);
|
|
414
407
|
if (recursive) {
|
|
415
408
|
if (isZodObjectV4(outputSchema)) {
|
|
416
409
|
const outputShape = outputSchema._zod.def.shape;
|
|
417
|
-
for (const [key, keySchema] of Object.entries(outputSchema._zod.def.shape)) outputShape[key] =
|
|
410
|
+
for (const [key, keySchema] of Object.entries(outputSchema._zod.def.shape)) outputShape[key] = interopZodTransformInputSchemaImpl(keySchema, recursive, cache);
|
|
418
411
|
outputSchema = clone(outputSchema, {
|
|
419
412
|
...outputSchema._zod.def,
|
|
420
413
|
shape: outputShape
|
|
421
414
|
});
|
|
422
415
|
} else if (isZodArrayV4(outputSchema)) {
|
|
423
|
-
const elementSchema =
|
|
416
|
+
const elementSchema = interopZodTransformInputSchemaImpl(outputSchema._zod.def.element, recursive, cache);
|
|
424
417
|
outputSchema = clone(outputSchema, {
|
|
425
418
|
...outputSchema._zod.def,
|
|
426
419
|
element: elementSchema
|
|
@@ -429,11 +422,25 @@ function interopZodTransformInputSchema(schema, recursive = false) {
|
|
|
429
422
|
}
|
|
430
423
|
const meta = globalRegistry.get(schema);
|
|
431
424
|
if (meta) globalRegistry.add(outputSchema, meta);
|
|
425
|
+
cache.set(schema, outputSchema);
|
|
432
426
|
return outputSchema;
|
|
433
427
|
}
|
|
434
428
|
throw new Error("Schema must be an instance of z3.ZodType or z4.$ZodType");
|
|
435
429
|
}
|
|
436
430
|
/**
|
|
431
|
+
* Returns the input type of a Zod transform schema, for both v3 and v4.
|
|
432
|
+
* If the schema is not a transform, returns undefined. If `recursive` is true,
|
|
433
|
+
* recursively processes nested object schemas and arrays of object schemas.
|
|
434
|
+
*
|
|
435
|
+
* @param schema - The Zod schema instance (v3 or v4)
|
|
436
|
+
* @param {boolean} [recursive=false] - Whether to recursively process nested objects/arrays.
|
|
437
|
+
* @returns The input Zod schema of the transform, or undefined if not a transform
|
|
438
|
+
*/
|
|
439
|
+
function interopZodTransformInputSchema(schema, recursive = false) {
|
|
440
|
+
const cache = /* @__PURE__ */ new WeakMap();
|
|
441
|
+
return interopZodTransformInputSchemaImpl(schema, recursive, cache);
|
|
442
|
+
}
|
|
443
|
+
/**
|
|
437
444
|
* Creates a modified version of a Zod object schema where fields matching a predicate are made optional.
|
|
438
445
|
* Supports both Zod v3 and v4 schemas and preserves the original schema version.
|
|
439
446
|
*
|