@langchain/core 1.1.3 → 1.1.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (190) hide show
  1. package/CHANGELOG.md +8 -0
  2. package/dist/agents.d.cts +2 -0
  3. package/dist/agents.d.ts +2 -0
  4. package/dist/callbacks/base.d.cts +60 -22
  5. package/dist/callbacks/base.d.ts +60 -22
  6. package/dist/callbacks/dispatch/index.d.cts +3 -1
  7. package/dist/callbacks/dispatch/index.d.ts +3 -1
  8. package/dist/callbacks/dispatch/web.d.cts +3 -1
  9. package/dist/callbacks/dispatch/web.d.ts +3 -1
  10. package/dist/callbacks/manager.d.cts +12 -2
  11. package/dist/callbacks/manager.d.ts +12 -2
  12. package/dist/chat_history.d.cts +1 -0
  13. package/dist/chat_history.d.ts +1 -0
  14. package/dist/document_loaders/langsmith.d.cts +3 -0
  15. package/dist/document_loaders/langsmith.d.ts +3 -0
  16. package/dist/documents/document.d.cts +12 -3
  17. package/dist/documents/document.d.ts +12 -3
  18. package/dist/example_selectors/length_based.d.cts +1 -1
  19. package/dist/example_selectors/length_based.d.ts +1 -1
  20. package/dist/indexing/base.d.cts +1 -0
  21. package/dist/indexing/base.d.ts +1 -0
  22. package/dist/indexing/record_manager.d.cts +1 -0
  23. package/dist/indexing/record_manager.d.ts +1 -0
  24. package/dist/language_models/base.d.cts +38 -8
  25. package/dist/language_models/base.d.ts +38 -8
  26. package/dist/language_models/chat_models.d.cts +33 -6
  27. package/dist/language_models/chat_models.d.ts +33 -6
  28. package/dist/language_models/llms.d.cts +6 -0
  29. package/dist/language_models/llms.d.ts +6 -0
  30. package/dist/load/import_type.d.cts +1 -0
  31. package/dist/load/import_type.d.ts +1 -0
  32. package/dist/load/map_keys.cjs +5 -4
  33. package/dist/load/map_keys.cjs.map +1 -1
  34. package/dist/load/map_keys.d.cts +1 -0
  35. package/dist/load/map_keys.d.ts +1 -0
  36. package/dist/load/map_keys.js +3 -3
  37. package/dist/load/map_keys.js.map +1 -1
  38. package/dist/load/serializable.d.cts +1 -0
  39. package/dist/load/serializable.d.ts +1 -0
  40. package/dist/memory.d.cts +3 -0
  41. package/dist/memory.d.ts +3 -0
  42. package/dist/messages/base.d.cts +13 -1
  43. package/dist/messages/base.d.ts +13 -1
  44. package/dist/messages/content/data.d.cts +7 -2
  45. package/dist/messages/content/data.d.ts +7 -2
  46. package/dist/messages/content/index.d.cts +4 -1
  47. package/dist/messages/content/index.d.ts +4 -1
  48. package/dist/messages/content/multimodal.d.cts +1 -0
  49. package/dist/messages/content/multimodal.d.ts +1 -0
  50. package/dist/messages/content/tools.d.cts +1 -0
  51. package/dist/messages/content/tools.d.ts +1 -0
  52. package/dist/messages/tool.d.cts +9 -2
  53. package/dist/messages/tool.d.ts +9 -2
  54. package/dist/messages/transformers.d.cts +3 -0
  55. package/dist/messages/transformers.d.ts +3 -0
  56. package/dist/messages/utils.d.cts +5 -2
  57. package/dist/messages/utils.d.ts +5 -2
  58. package/dist/output_parsers/json.d.cts +5 -1
  59. package/dist/output_parsers/json.d.ts +5 -1
  60. package/dist/output_parsers/openai_functions/json_output_functions_parsers.d.cts +6 -2
  61. package/dist/output_parsers/openai_functions/json_output_functions_parsers.d.ts +6 -2
  62. package/dist/output_parsers/openai_tools/json_output_tools_parsers.d.cts +34 -10
  63. package/dist/output_parsers/openai_tools/json_output_tools_parsers.d.ts +34 -10
  64. package/dist/output_parsers/transform.d.cts +1 -0
  65. package/dist/output_parsers/transform.d.ts +1 -0
  66. package/dist/outputs.d.cts +6 -0
  67. package/dist/outputs.d.ts +6 -0
  68. package/dist/prompts/base.d.cts +10 -2
  69. package/dist/prompts/base.d.ts +10 -2
  70. package/dist/prompts/chat.d.cts +51 -13
  71. package/dist/prompts/chat.d.ts +51 -13
  72. package/dist/prompts/few_shot.d.cts +5 -1
  73. package/dist/prompts/few_shot.d.ts +5 -1
  74. package/dist/prompts/image.d.cts +10 -2
  75. package/dist/prompts/image.d.ts +10 -2
  76. package/dist/prompts/prompt.d.cts +15 -4
  77. package/dist/prompts/prompt.d.ts +16 -4
  78. package/dist/prompts/serde.d.cts +1 -0
  79. package/dist/prompts/serde.d.ts +1 -0
  80. package/dist/prompts/string.d.cts +5 -1
  81. package/dist/prompts/string.d.ts +5 -1
  82. package/dist/prompts/structured.d.cts +16 -3
  83. package/dist/prompts/structured.d.ts +16 -3
  84. package/dist/retrievers/document_compressors/index.d.cts +1 -0
  85. package/dist/retrievers/document_compressors/index.d.ts +1 -0
  86. package/dist/retrievers/index.d.cts +6 -2
  87. package/dist/retrievers/index.d.ts +6 -2
  88. package/dist/runnables/base.cjs +7 -7
  89. package/dist/runnables/base.cjs.map +1 -1
  90. package/dist/runnables/base.d.cts +64 -12
  91. package/dist/runnables/base.d.ts +64 -12
  92. package/dist/runnables/base.js +1 -1
  93. package/dist/runnables/base.js.map +1 -1
  94. package/dist/runnables/branch.d.cts +2 -0
  95. package/dist/runnables/branch.d.ts +2 -0
  96. package/dist/runnables/config.d.cts +1 -0
  97. package/dist/runnables/config.d.ts +1 -0
  98. package/dist/runnables/graph.d.cts +5 -1
  99. package/dist/runnables/graph.d.ts +5 -1
  100. package/dist/runnables/history.d.cts +12 -4
  101. package/dist/runnables/history.d.ts +12 -4
  102. package/dist/runnables/passthrough.d.cts +2 -0
  103. package/dist/runnables/passthrough.d.ts +2 -0
  104. package/dist/runnables/router.d.cts +1 -0
  105. package/dist/runnables/router.d.ts +1 -0
  106. package/dist/runnables/types.d.cts +9 -2
  107. package/dist/runnables/types.d.ts +9 -2
  108. package/dist/singletons/async_local_storage/context.d.cts +2 -0
  109. package/dist/singletons/async_local_storage/context.d.ts +2 -0
  110. package/dist/singletons/async_local_storage/globals.d.cts +1 -0
  111. package/dist/singletons/async_local_storage/globals.d.ts +1 -0
  112. package/dist/singletons/callbacks.cjs.map +1 -1
  113. package/dist/singletons/callbacks.js.map +1 -1
  114. package/dist/stores.d.cts +1 -0
  115. package/dist/stores.d.ts +1 -0
  116. package/dist/structured_query/utils.d.cts +4 -1
  117. package/dist/structured_query/utils.d.ts +4 -1
  118. package/dist/tools/index.d.cts +6 -1
  119. package/dist/tools/index.d.ts +6 -1
  120. package/dist/tools/types.d.cts +13 -3
  121. package/dist/tools/types.d.ts +13 -3
  122. package/dist/tracers/base.d.cts +20 -1
  123. package/dist/tracers/base.d.ts +20 -1
  124. package/dist/tracers/console.cjs +3 -3
  125. package/dist/tracers/console.cjs.map +1 -1
  126. package/dist/tracers/console.d.cts +2 -0
  127. package/dist/tracers/console.d.ts +2 -0
  128. package/dist/tracers/console.js +3 -3
  129. package/dist/tracers/console.js.map +1 -1
  130. package/dist/tracers/event_stream.d.cts +4 -0
  131. package/dist/tracers/event_stream.d.ts +4 -0
  132. package/dist/tracers/log_stream.d.cts +6 -0
  133. package/dist/tracers/log_stream.d.ts +6 -0
  134. package/dist/types/_internal.d.cts +3 -0
  135. package/dist/types/_internal.d.ts +3 -0
  136. package/dist/types/type-utils.d.cts +2 -0
  137. package/dist/types/type-utils.d.ts +2 -0
  138. package/dist/utils/async_caller.cjs +1 -1
  139. package/dist/utils/async_caller.cjs.map +1 -1
  140. package/dist/utils/async_caller.d.cts +3 -0
  141. package/dist/utils/async_caller.d.ts +3 -0
  142. package/dist/utils/async_caller.js +1 -1
  143. package/dist/utils/async_caller.js.map +1 -1
  144. package/dist/utils/env.d.cts +4 -0
  145. package/dist/utils/env.d.ts +4 -0
  146. package/dist/utils/event_source_parse.d.cts +4 -1
  147. package/dist/utils/event_source_parse.d.ts +4 -1
  148. package/dist/utils/function_calling.d.cts +3 -1
  149. package/dist/utils/function_calling.d.ts +3 -1
  150. package/dist/{node_modules/.pnpm/is-network-error@1.3.0/node_modules → utils}/is-network-error/index.cjs +1 -1
  151. package/dist/utils/is-network-error/index.cjs.map +1 -0
  152. package/dist/{node_modules/.pnpm/is-network-error@1.3.0/node_modules → utils}/is-network-error/index.js +1 -1
  153. package/dist/utils/is-network-error/index.js.map +1 -0
  154. package/dist/utils/json.d.cts +1 -0
  155. package/dist/utils/json.d.ts +1 -0
  156. package/dist/{node_modules/.pnpm/p-retry@7.1.0/node_modules → utils}/p-retry/index.cjs +2 -2
  157. package/dist/utils/p-retry/index.cjs.map +1 -0
  158. package/dist/{node_modules/.pnpm/p-retry@7.1.0/node_modules → utils}/p-retry/index.js +2 -2
  159. package/dist/utils/p-retry/index.js.map +1 -0
  160. package/dist/utils/stream.d.cts +13 -1
  161. package/dist/utils/stream.d.ts +13 -1
  162. package/dist/utils/testing/chat_models.d.cts +11 -3
  163. package/dist/utils/testing/chat_models.d.ts +11 -3
  164. package/dist/utils/testing/retrievers.d.cts +3 -1
  165. package/dist/utils/testing/retrievers.d.ts +3 -1
  166. package/dist/utils/testing/vectorstores.d.cts +1 -0
  167. package/dist/utils/testing/vectorstores.d.ts +1 -0
  168. package/dist/utils/types/index.d.cts +2 -0
  169. package/dist/utils/types/index.d.ts +2 -0
  170. package/dist/utils/types/zod.d.cts +3 -0
  171. package/dist/utils/types/zod.d.ts +3 -0
  172. package/dist/vectorstores.d.cts +17 -5
  173. package/dist/vectorstores.d.ts +17 -5
  174. package/package.json +5 -6
  175. package/dist/node_modules/.pnpm/ansi-styles@6.2.3/node_modules/ansi-styles/index.cjs +0 -169
  176. package/dist/node_modules/.pnpm/ansi-styles@6.2.3/node_modules/ansi-styles/index.cjs.map +0 -1
  177. package/dist/node_modules/.pnpm/ansi-styles@6.2.3/node_modules/ansi-styles/index.js +0 -168
  178. package/dist/node_modules/.pnpm/ansi-styles@6.2.3/node_modules/ansi-styles/index.js.map +0 -1
  179. package/dist/node_modules/.pnpm/camelcase@9.0.0/node_modules/camelcase/index.cjs +0 -122
  180. package/dist/node_modules/.pnpm/camelcase@9.0.0/node_modules/camelcase/index.cjs.map +0 -1
  181. package/dist/node_modules/.pnpm/camelcase@9.0.0/node_modules/camelcase/index.js +0 -121
  182. package/dist/node_modules/.pnpm/camelcase@9.0.0/node_modules/camelcase/index.js.map +0 -1
  183. package/dist/node_modules/.pnpm/decamelize@6.0.1/node_modules/decamelize/index.cjs +0 -18
  184. package/dist/node_modules/.pnpm/decamelize@6.0.1/node_modules/decamelize/index.cjs.map +0 -1
  185. package/dist/node_modules/.pnpm/decamelize@6.0.1/node_modules/decamelize/index.js +0 -17
  186. package/dist/node_modules/.pnpm/decamelize@6.0.1/node_modules/decamelize/index.js.map +0 -1
  187. package/dist/node_modules/.pnpm/is-network-error@1.3.0/node_modules/is-network-error/index.cjs.map +0 -1
  188. package/dist/node_modules/.pnpm/is-network-error@1.3.0/node_modules/is-network-error/index.js.map +0 -1
  189. package/dist/node_modules/.pnpm/p-retry@7.1.0/node_modules/p-retry/index.cjs.map +0 -1
  190. package/dist/node_modules/.pnpm/p-retry@7.1.0/node_modules/p-retry/index.js.map +0 -1
@@ -1 +1 @@
1
- {"version":3,"file":"async_caller.cjs","names":["error: any","params: AsyncCallerParams","PQueueMod","callable: T","pRetry","options: AsyncCallerCallOptions","listener: (() => void) | undefined","getAbortSignalError"],"sources":["../../src/utils/async_caller.ts"],"sourcesContent":["import PQueueMod from \"p-queue\";\nimport pRetry from \"p-retry\";\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 async 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: ({ error }) => this.onFailedAttempt?.(error),\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,gBA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UAAU,GAAG,KAAK;CAC1C;CAED,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"}
1
+ {"version":3,"file":"async_caller.cjs","names":["error: any","params: AsyncCallerParams","PQueueMod","callable: T","pRetry","options: AsyncCallerCallOptions","listener: (() => void) | undefined","getAbortSignalError"],"sources":["../../src/utils/async_caller.ts"],"sourcesContent":["import PQueueMod from \"p-queue\";\n\nimport { getAbortSignalError } from \"./signal.js\";\nimport pRetry from \"./p-retry/index.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 async 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: ({ error }) => this.onFailedAttempt?.(error),\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;CAER,YAAYC,QAA2B;EACrC,KAAK,iBAAiB,OAAO,kBAAkB;EAC/C,KAAK,aAAa,OAAO,cAAc;EACvC,KAAK,kBACH,OAAO,mBAAmB;EAE5B,MAAM,SACJ,aAAaC,kBAAYA,gBAAU,UAAUA;EAE/C,KAAK,QAAQ,IAAI,OAAO,EAAE,aAAa,KAAK,eAAgB;CAC7D;CAGD,MAAM,KACJC,UACA,GAAG,MAC8B;AACjC,SAAO,KAAK,MAAM,IAChB,MACEC,qBACE,MACE,SAAS,GAAG,KAAK,CAAC,MAAM,CAAC,UAAU;AAEjC,OAAI,iBAAiB,MACnB,OAAM;OAEN,OAAM,IAAI,MAAM;EAEnB,EAAC,EACJ;GACE,iBAAiB,CAAC,EAAE,OAAO,KAAK,KAAK,kBAAkB,MAAM;GAC7D,SAAS,KAAK;GACd,WAAW;EAGZ,EACF,EACH,EAAE,gBAAgB,KAAM,EACzB;CACF;CAGD,gBACEC,SACAF,UACA,GAAG,MAC8B;AAGjC,MAAI,QAAQ,QAAQ;GAClB,IAAIG;AACJ,UAAO,QAAQ,KAAK,CAClB,KAAK,KAAW,UAAU,GAAG,KAAK,EAClC,IAAI,QAAe,CAAC,GAAG,WAAW;IAChC,WAAW,MAAM;KACf,OAAOC,mCAAoB,QAAQ,OAAO,CAAC;IAC5C;IACD,QAAQ,QAAQ,iBAAiB,SAAS,SAAS;GACpD,EACF,EAAC,CAAC,QAAQ,MAAM;AACf,QAAI,QAAQ,UAAU,UACpB,QAAQ,OAAO,oBAAoB,SAAS,SAAS;GAExD,EAAC;EACH;AACD,SAAO,KAAK,KAAW,UAAU,GAAG,KAAK;CAC1C;CAED,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"}
@@ -1,4 +1,5 @@
1
1
  //#region src/utils/async_caller.d.ts
2
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
2
3
  type FailedAttemptHandler = (error: any) => any;
3
4
  interface AsyncCallerParams {
4
5
  /**
@@ -40,7 +41,9 @@ declare class AsyncCaller {
40
41
  protected onFailedAttempt: AsyncCallerParams["onFailedAttempt"];
41
42
  private queue;
42
43
  constructor(params: AsyncCallerParams);
44
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
43
45
  call<A extends any[], T extends (...args: A) => Promise<any>>(callable: T, ...args: Parameters<T>): Promise<Awaited<ReturnType<T>>>;
46
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
44
47
  callWithOptions<A extends any[], T extends (...args: A) => Promise<any>>(options: AsyncCallerCallOptions, callable: T, ...args: Parameters<T>): Promise<Awaited<ReturnType<T>>>;
45
48
  fetch(...args: Parameters<typeof fetch>): ReturnType<typeof fetch>;
46
49
  }
@@ -1,4 +1,5 @@
1
1
  //#region src/utils/async_caller.d.ts
2
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
2
3
  type FailedAttemptHandler = (error: any) => any;
3
4
  interface AsyncCallerParams {
4
5
  /**
@@ -40,7 +41,9 @@ declare class AsyncCaller {
40
41
  protected onFailedAttempt: AsyncCallerParams["onFailedAttempt"];
41
42
  private queue;
42
43
  constructor(params: AsyncCallerParams);
44
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
43
45
  call<A extends any[], T extends (...args: A) => Promise<any>>(callable: T, ...args: Parameters<T>): Promise<Awaited<ReturnType<T>>>;
46
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
44
47
  callWithOptions<A extends any[], T extends (...args: A) => Promise<any>>(options: AsyncCallerCallOptions, callable: T, ...args: Parameters<T>): Promise<Awaited<ReturnType<T>>>;
45
48
  fetch(...args: Parameters<typeof fetch>): ReturnType<typeof fetch>;
46
49
  }
@@ -1,6 +1,6 @@
1
1
  import { __export } from "../_virtual/rolldown_runtime.js";
2
- import { pRetry } from "../node_modules/.pnpm/p-retry@7.1.0/node_modules/p-retry/index.js";
3
2
  import { getAbortSignalError } from "./signal.js";
3
+ import { pRetry } from "./p-retry/index.js";
4
4
  import PQueueMod from "p-queue";
5
5
 
6
6
  //#region src/utils/async_caller.ts
@@ -1 +1 @@
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 PQueueMod from \"p-queue\";\nimport pRetry from \"p-retry\";\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 async 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: ({ error }) => this.onFailedAttempt?.(error),\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;CAER,YAAYC,QAA2B;EACrC,KAAK,iBAAiB,OAAO,kBAAkB;EAC/C,KAAK,aAAa,OAAO,cAAc;EACvC,KAAK,kBACH,OAAO,mBAAmB;EAE5B,MAAM,SACJ,aAAa,YAAY,UAAU,UAAU;EAE/C,KAAK,QAAQ,IAAI,OAAO,EAAE,aAAa,KAAK,eAAgB;CAC7D;CAGD,MAAM,KACJC,UACA,GAAG,MAC8B;AACjC,SAAO,KAAK,MAAM,IAChB,MACE,OACE,MACE,SAAS,GAAG,KAAK,CAAC,MAAM,CAAC,UAAU;AAEjC,OAAI,iBAAiB,MACnB,OAAM;OAEN,OAAM,IAAI,MAAM;EAEnB,EAAC,EACJ;GACE,iBAAiB,CAAC,EAAE,OAAO,KAAK,KAAK,kBAAkB,MAAM;GAC7D,SAAS,KAAK;GACd,WAAW;EAGZ,EACF,EACH,EAAE,gBAAgB,KAAM,EACzB;CACF;CAGD,gBACEC,SACAD,UACA,GAAG,MAC8B;AAGjC,MAAI,QAAQ,QAAQ;GAClB,IAAIE;AACJ,UAAO,QAAQ,KAAK,CAClB,KAAK,KAAW,UAAU,GAAG,KAAK,EAClC,IAAI,QAAe,CAAC,GAAG,WAAW;IAChC,WAAW,MAAM;KACf,OAAO,oBAAoB,QAAQ,OAAO,CAAC;IAC5C;IACD,QAAQ,QAAQ,iBAAiB,SAAS,SAAS;GACpD,EACF,EAAC,CAAC,QAAQ,MAAM;AACf,QAAI,QAAQ,UAAU,UACpB,QAAQ,OAAO,oBAAoB,SAAS,SAAS;GAExD,EAAC;EACH;AACD,SAAO,KAAK,KAAW,UAAU,GAAG,KAAK;CAC1C;CAED,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"}
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 PQueueMod from \"p-queue\";\n\nimport { getAbortSignalError } from \"./signal.js\";\nimport pRetry from \"./p-retry/index.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 async 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: ({ error }) => this.onFailedAttempt?.(error),\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;CAER,YAAYC,QAA2B;EACrC,KAAK,iBAAiB,OAAO,kBAAkB;EAC/C,KAAK,aAAa,OAAO,cAAc;EACvC,KAAK,kBACH,OAAO,mBAAmB;EAE5B,MAAM,SACJ,aAAa,YAAY,UAAU,UAAU;EAE/C,KAAK,QAAQ,IAAI,OAAO,EAAE,aAAa,KAAK,eAAgB;CAC7D;CAGD,MAAM,KACJC,UACA,GAAG,MAC8B;AACjC,SAAO,KAAK,MAAM,IAChB,MACE,OACE,MACE,SAAS,GAAG,KAAK,CAAC,MAAM,CAAC,UAAU;AAEjC,OAAI,iBAAiB,MACnB,OAAM;OAEN,OAAM,IAAI,MAAM;EAEnB,EAAC,EACJ;GACE,iBAAiB,CAAC,EAAE,OAAO,KAAK,KAAK,kBAAkB,MAAM;GAC7D,SAAS,KAAK;GACd,WAAW;EAGZ,EACF,EACH,EAAE,gBAAgB,KAAM,EACzB;CACF;CAGD,gBACEC,SACAD,UACA,GAAG,MAC8B;AAGjC,MAAI,QAAQ,QAAQ;GAClB,IAAIE;AACJ,UAAO,QAAQ,KAAK,CAClB,KAAK,KAAW,UAAU,GAAG,KAAK,EAClC,IAAI,QAAe,CAAC,GAAG,WAAW;IAChC,WAAW,MAAM;KACf,OAAO,oBAAoB,QAAQ,OAAO,CAAC;IAC5C;IACD,QAAQ,QAAQ,iBAAiB,SAAS,SAAS;GACpD,EACF,EAAC,CAAC,QAAQ,MAAM;AACf,QAAI,QAAQ,UAAU,UACpB,QAAQ,OAAO,oBAAoB,SAAS,SAAS;GAExD,EAAC;EACH;AACD,SAAO,KAAK,KAAW,UAAU,GAAG,KAAK;CAC1C;CAED,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"}
@@ -1,4 +1,5 @@
1
1
  //#region src/utils/env.d.ts
2
+ // Inlined from https://github.com/flexdinesh/browser-or-node
2
3
  declare global {
3
4
  const Deno: {
4
5
  version: {
@@ -12,7 +13,10 @@ declare global {
12
13
  declare const isBrowser: () => boolean;
13
14
  declare const isWebWorker: () => boolean;
14
15
  declare const isJsDom: () => boolean;
16
+ // Supabase Edge Function provides a `Deno` global object
17
+ // without `version` property
15
18
  declare const isDeno: () => boolean;
19
+ // Mark not-as-node if in Supabase Edge Function
16
20
  declare const isNode: () => boolean;
17
21
  declare const getEnv: () => string;
18
22
  type RuntimeEnvironment = {
@@ -1,4 +1,5 @@
1
1
  //#region src/utils/env.d.ts
2
+ // Inlined from https://github.com/flexdinesh/browser-or-node
2
3
  declare global {
3
4
  const Deno: {
4
5
  version: {
@@ -12,7 +13,10 @@ declare global {
12
13
  declare const isBrowser: () => boolean;
13
14
  declare const isWebWorker: () => boolean;
14
15
  declare const isJsDom: () => boolean;
16
+ // Supabase Edge Function provides a `Deno` global object
17
+ // without `version` property
15
18
  declare const isDeno: () => boolean;
19
+ // Mark not-as-node if in Supabase Edge Function
16
20
  declare const isNode: () => boolean;
17
21
  declare const getEnv: () => string;
18
22
  type RuntimeEnvironment = {
@@ -1,6 +1,7 @@
1
1
  import { IterableReadableStream } from "./stream.cjs";
2
2
 
3
3
  //#region src/utils/event_source_parse.d.ts
4
+
4
5
  declare const EventStreamContentType = "text/event-stream";
5
6
  /**
6
7
  * Represents a message sent in an event stream
@@ -22,7 +23,9 @@ interface EventSourceMessage {
22
23
  * @param onChunk A function that will be called on each new byte chunk in the stream.
23
24
  * @returns {Promise<void>} A promise that will be resolved when the stream closes.
24
25
  */
25
- declare function getBytes(stream: ReadableStream<Uint8Array> | AsyncIterable<any>, onChunk: (arr: Uint8Array, flush?: boolean) => void): Promise<void>;
26
+ declare function getBytes(
27
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
28
+ stream: ReadableStream<Uint8Array> | AsyncIterable<any>, onChunk: (arr: Uint8Array, flush?: boolean) => void): Promise<void>;
26
29
  /**
27
30
  * Parses arbitary byte chunks into EventSource line buffers.
28
31
  * Each line should be of the format "field: value" and ends with \r, \n, or \r\n.
@@ -1,6 +1,7 @@
1
1
  import { IterableReadableStream } from "./stream.js";
2
2
 
3
3
  //#region src/utils/event_source_parse.d.ts
4
+
4
5
  declare const EventStreamContentType = "text/event-stream";
5
6
  /**
6
7
  * Represents a message sent in an event stream
@@ -22,7 +23,9 @@ interface EventSourceMessage {
22
23
  * @param onChunk A function that will be called on each new byte chunk in the stream.
23
24
  * @returns {Promise<void>} A promise that will be resolved when the stream closes.
24
25
  */
25
- declare function getBytes(stream: ReadableStream<Uint8Array> | AsyncIterable<any>, onChunk: (arr: Uint8Array, flush?: boolean) => void): Promise<void>;
26
+ declare function getBytes(
27
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
28
+ stream: ReadableStream<Uint8Array> | AsyncIterable<any>, onChunk: (arr: Uint8Array, flush?: boolean) => void): Promise<void>;
26
29
  /**
27
30
  * Parses arbitary byte chunks into EventSource line buffers.
28
31
  * Each line should be of the format "field: value" and ends with \r, \n, or \r\n.
@@ -29,7 +29,9 @@ declare function convertToOpenAIFunction(tool: StructuredToolInterface | Runnabl
29
29
  * @param {StructuredToolInterface | Record<string, any> | RunnableToolLike} tool The tool to convert to an OpenAI tool.
30
30
  * @returns {ToolDefinition} The inputted tool in OpenAI tool format.
31
31
  */
32
- declare function convertToOpenAITool(tool: StructuredToolInterface | Record<string, any> | RunnableToolLike, fields?: {
32
+ declare function convertToOpenAITool(
33
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
34
+ tool: StructuredToolInterface | Record<string, any> | RunnableToolLike, fields?: {
33
35
  /**
34
36
  * If `true`, model output is guaranteed to exactly match the JSON Schema
35
37
  * provided in the function definition.
@@ -29,7 +29,9 @@ declare function convertToOpenAIFunction(tool: StructuredToolInterface | Runnabl
29
29
  * @param {StructuredToolInterface | Record<string, any> | RunnableToolLike} tool The tool to convert to an OpenAI tool.
30
30
  * @returns {ToolDefinition} The inputted tool in OpenAI tool format.
31
31
  */
32
- declare function convertToOpenAITool(tool: StructuredToolInterface | Record<string, any> | RunnableToolLike, fields?: {
32
+ declare function convertToOpenAITool(
33
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
34
+ tool: StructuredToolInterface | Record<string, any> | RunnableToolLike, fields?: {
33
35
  /**
34
36
  * If `true`, model output is guaranteed to exactly match the JSON Schema
35
37
  * provided in the function definition.
@@ -1,5 +1,5 @@
1
1
 
2
- //#region ../../node_modules/.pnpm/is-network-error@1.3.0/node_modules/is-network-error/index.js
2
+ //#region src/utils/is-network-error/index.js
3
3
  const objectToString = Object.prototype.toString;
4
4
  const isError = (value) => objectToString.call(value) === "[object Error]";
5
5
  const errorMessages = new Set([
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.cjs","names":[],"sources":["../../../src/utils/is-network-error/index.js"],"sourcesContent":["/* eslint-disable */\nconst objectToString = Object.prototype.toString;\n\nconst isError = (value) => objectToString.call(value) === \"[object Error]\";\n\nconst errorMessages = new Set([\n \"network error\", // Chrome\n \"Failed to fetch\", // Chrome\n \"NetworkError when attempting to fetch resource.\", // Firefox\n \"The Internet connection appears to be offline.\", // Safari 16\n \"Network request failed\", // `cross-fetch`\n \"fetch failed\", // Undici (Node.js)\n \"terminated\", // Undici (Node.js)\n \" A network error occurred.\", // Bun (WebKit)\n \"Network connection lost\", // Cloudflare Workers (fetch)\n]);\n\nexport default function isNetworkError(error) {\n const isValid =\n error &&\n isError(error) &&\n error.name === \"TypeError\" &&\n typeof error.message === \"string\";\n\n if (!isValid) {\n return false;\n }\n\n const { message, stack } = error;\n\n // Safari 17+ has generic message but no stack for network errors\n if (message === \"Load failed\") {\n return (\n stack === undefined ||\n // Sentry adds its own stack trace to the fetch error, so also check for that\n \"__sentry_captured__\" in error\n );\n }\n\n // Deno network errors start with specific text\n if (message.startsWith(\"error sending request for url\")) {\n return true;\n }\n\n // Standard network error messages\n return errorMessages.has(message);\n}\n"],"mappings":";;AACA,MAAM,iBAAiB,OAAO,UAAU;AAExC,MAAM,UAAU,CAAC,UAAU,eAAe,KAAK,MAAM,KAAK;AAE1D,MAAM,gBAAgB,IAAI,IAAI;CAC5B;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;AACD;AAED,SAAwB,eAAe,OAAO;CAC5C,MAAM,UACJ,SACA,QAAQ,MAAM,IACd,MAAM,SAAS,eACf,OAAO,MAAM,YAAY;AAE3B,KAAI,CAAC,QACH,QAAO;CAGT,MAAM,EAAE,SAAS,OAAO,GAAG;AAG3B,KAAI,YAAY,cACd,QACE,UAAU,UAEV,yBAAyB;AAK7B,KAAI,QAAQ,WAAW,gCAAgC,CACrD,QAAO;AAIT,QAAO,cAAc,IAAI,QAAQ;AAClC"}
@@ -1,4 +1,4 @@
1
- //#region ../../node_modules/.pnpm/is-network-error@1.3.0/node_modules/is-network-error/index.js
1
+ //#region src/utils/is-network-error/index.js
2
2
  const objectToString = Object.prototype.toString;
3
3
  const isError = (value) => objectToString.call(value) === "[object Error]";
4
4
  const errorMessages = new Set([
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","names":[],"sources":["../../../src/utils/is-network-error/index.js"],"sourcesContent":["/* eslint-disable */\nconst objectToString = Object.prototype.toString;\n\nconst isError = (value) => objectToString.call(value) === \"[object Error]\";\n\nconst errorMessages = new Set([\n \"network error\", // Chrome\n \"Failed to fetch\", // Chrome\n \"NetworkError when attempting to fetch resource.\", // Firefox\n \"The Internet connection appears to be offline.\", // Safari 16\n \"Network request failed\", // `cross-fetch`\n \"fetch failed\", // Undici (Node.js)\n \"terminated\", // Undici (Node.js)\n \" A network error occurred.\", // Bun (WebKit)\n \"Network connection lost\", // Cloudflare Workers (fetch)\n]);\n\nexport default function isNetworkError(error) {\n const isValid =\n error &&\n isError(error) &&\n error.name === \"TypeError\" &&\n typeof error.message === \"string\";\n\n if (!isValid) {\n return false;\n }\n\n const { message, stack } = error;\n\n // Safari 17+ has generic message but no stack for network errors\n if (message === \"Load failed\") {\n return (\n stack === undefined ||\n // Sentry adds its own stack trace to the fetch error, so also check for that\n \"__sentry_captured__\" in error\n );\n }\n\n // Deno network errors start with specific text\n if (message.startsWith(\"error sending request for url\")) {\n return true;\n }\n\n // Standard network error messages\n return errorMessages.has(message);\n}\n"],"mappings":";AACA,MAAM,iBAAiB,OAAO,UAAU;AAExC,MAAM,UAAU,CAAC,UAAU,eAAe,KAAK,MAAM,KAAK;AAE1D,MAAM,gBAAgB,IAAI,IAAI;CAC5B;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;AACD;AAED,SAAwB,eAAe,OAAO;CAC5C,MAAM,UACJ,SACA,QAAQ,MAAM,IACd,MAAM,SAAS,eACf,OAAO,MAAM,YAAY;AAE3B,KAAI,CAAC,QACH,QAAO;CAGT,MAAM,EAAE,SAAS,OAAO,GAAG;AAG3B,KAAI,YAAY,cACd,QACE,UAAU,UAEV,yBAAyB;AAK7B,KAAI,QAAQ,WAAW,gCAAgC,CACrD,QAAO;AAIT,QAAO,cAAc,IAAI,QAAQ;AAClC"}
@@ -1,5 +1,6 @@
1
1
  //#region src/utils/json.d.ts
2
2
  declare function parseJsonMarkdown(s: string, parser?: typeof parsePartialJson): any;
3
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
3
4
  declare function parsePartialJson(s: string): any | null;
4
5
  //#endregion
5
6
  export { parseJsonMarkdown, parsePartialJson };
@@ -1,5 +1,6 @@
1
1
  //#region src/utils/json.d.ts
2
2
  declare function parseJsonMarkdown(s: string, parser?: typeof parsePartialJson): any;
3
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
3
4
  declare function parsePartialJson(s: string): any | null;
4
5
  //#endregion
5
6
  export { parseJsonMarkdown, parsePartialJson };
@@ -1,6 +1,6 @@
1
- const require_index = require('../../../is-network-error@1.3.0/node_modules/is-network-error/index.cjs');
1
+ const require_index = require('../is-network-error/index.cjs');
2
2
 
3
- //#region ../../node_modules/.pnpm/p-retry@7.1.0/node_modules/p-retry/index.js
3
+ //#region src/utils/p-retry/index.js
4
4
  function validateRetries(retries) {
5
5
  if (typeof retries === "number") {
6
6
  if (retries < 0) throw new TypeError("Expected `retries` to be a non-negative number.");
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.cjs","names":["isNetworkError"],"sources":["../../../src/utils/p-retry/index.js"],"sourcesContent":["/* eslint-disable */\nimport isNetworkError from \"../is-network-error/index.js\";\n\nfunction validateRetries(retries) {\n if (typeof retries === \"number\") {\n if (retries < 0) {\n throw new TypeError(\"Expected `retries` to be a non-negative number.\");\n }\n\n if (Number.isNaN(retries)) {\n throw new TypeError(\n \"Expected `retries` to be a valid number or Infinity, got NaN.\"\n );\n }\n } else if (retries !== undefined) {\n throw new TypeError(\"Expected `retries` to be a number or Infinity.\");\n }\n}\n\nfunction validateNumberOption(\n name,\n value,\n { min = 0, allowInfinity = false } = {}\n) {\n if (value === undefined) {\n return;\n }\n\n if (typeof value !== \"number\" || Number.isNaN(value)) {\n throw new TypeError(\n `Expected \\`${name}\\` to be a number${\n allowInfinity ? \" or Infinity\" : \"\"\n }.`\n );\n }\n\n if (!allowInfinity && !Number.isFinite(value)) {\n throw new TypeError(`Expected \\`${name}\\` to be a finite number.`);\n }\n\n if (value < min) {\n throw new TypeError(`Expected \\`${name}\\` to be \\u2265 ${min}.`);\n }\n}\n\nexport class AbortError extends Error {\n constructor(message) {\n super();\n\n if (message instanceof Error) {\n this.originalError = message;\n ({ message } = message);\n } else {\n this.originalError = new Error(message);\n this.originalError.stack = this.stack;\n }\n\n this.name = \"AbortError\";\n this.message = message;\n }\n}\n\nfunction calculateDelay(retriesConsumed, options) {\n const attempt = Math.max(1, retriesConsumed + 1);\n const random = options.randomize ? Math.random() + 1 : 1;\n\n let timeout = Math.round(\n random * options.minTimeout * options.factor ** (attempt - 1)\n );\n timeout = Math.min(timeout, options.maxTimeout);\n\n return timeout;\n}\n\nfunction calculateRemainingTime(start, max) {\n if (!Number.isFinite(max)) {\n return max;\n }\n\n return max - (performance.now() - start);\n}\n\nasync function onAttemptFailure({\n error,\n attemptNumber,\n retriesConsumed,\n startTime,\n options,\n}) {\n const normalizedError =\n error instanceof Error\n ? error\n : new TypeError(\n `Non-error was thrown: \"${error}\". You should only throw errors.`\n );\n\n if (normalizedError instanceof AbortError) {\n throw normalizedError.originalError;\n }\n\n const retriesLeft = Number.isFinite(options.retries)\n ? Math.max(0, options.retries - retriesConsumed)\n : options.retries;\n\n const maxRetryTime = options.maxRetryTime ?? Number.POSITIVE_INFINITY;\n\n const context = Object.freeze({\n error: normalizedError,\n attemptNumber,\n retriesLeft,\n retriesConsumed,\n });\n\n await options.onFailedAttempt(context);\n\n if (calculateRemainingTime(startTime, maxRetryTime) <= 0) {\n throw normalizedError;\n }\n\n const consumeRetry = await options.shouldConsumeRetry(context);\n\n const remainingTime = calculateRemainingTime(startTime, maxRetryTime);\n\n if (remainingTime <= 0 || retriesLeft <= 0) {\n throw normalizedError;\n }\n\n if (\n normalizedError instanceof TypeError &&\n !isNetworkError(normalizedError)\n ) {\n if (consumeRetry) {\n throw normalizedError;\n }\n\n options.signal?.throwIfAborted();\n return false;\n }\n\n if (!(await options.shouldRetry(context))) {\n throw normalizedError;\n }\n\n if (!consumeRetry) {\n options.signal?.throwIfAborted();\n return false;\n }\n\n const delayTime = calculateDelay(retriesConsumed, options);\n const finalDelay = Math.min(delayTime, remainingTime);\n\n if (finalDelay > 0) {\n await new Promise((resolve, reject) => {\n const onAbort = () => {\n clearTimeout(timeoutToken);\n options.signal?.removeEventListener(\"abort\", onAbort);\n reject(options.signal.reason);\n };\n\n const timeoutToken = setTimeout(() => {\n options.signal?.removeEventListener(\"abort\", onAbort);\n resolve();\n }, finalDelay);\n\n if (options.unref) {\n timeoutToken.unref?.();\n }\n\n options.signal?.addEventListener(\"abort\", onAbort, { once: true });\n });\n }\n\n options.signal?.throwIfAborted();\n\n return true;\n}\n\nexport default async function pRetry(input, options = {}) {\n options = { ...options };\n\n validateRetries(options.retries);\n\n if (Object.hasOwn(options, \"forever\")) {\n throw new Error(\n \"The `forever` option is no longer supported. For many use-cases, you can set `retries: Infinity` instead.\"\n );\n }\n\n options.retries ??= 10;\n options.factor ??= 2;\n options.minTimeout ??= 1000;\n options.maxTimeout ??= Number.POSITIVE_INFINITY;\n options.maxRetryTime ??= Number.POSITIVE_INFINITY;\n options.randomize ??= false;\n options.onFailedAttempt ??= () => {};\n options.shouldRetry ??= () => true;\n options.shouldConsumeRetry ??= () => true;\n\n // Validate numeric options and normalize edge cases\n validateNumberOption(\"factor\", options.factor, {\n min: 0,\n allowInfinity: false,\n });\n validateNumberOption(\"minTimeout\", options.minTimeout, {\n min: 0,\n allowInfinity: false,\n });\n validateNumberOption(\"maxTimeout\", options.maxTimeout, {\n min: 0,\n allowInfinity: true,\n });\n validateNumberOption(\"maxRetryTime\", options.maxRetryTime, {\n min: 0,\n allowInfinity: true,\n });\n\n // Treat non-positive factor as 1 to avoid zero backoff or negative behavior\n if (!(options.factor > 0)) {\n options.factor = 1;\n }\n\n options.signal?.throwIfAborted();\n\n let attemptNumber = 0;\n let retriesConsumed = 0;\n const startTime = performance.now();\n\n while (\n Number.isFinite(options.retries) ? retriesConsumed <= options.retries : true\n ) {\n attemptNumber++;\n\n try {\n options.signal?.throwIfAborted();\n\n const result = await input(attemptNumber);\n\n options.signal?.throwIfAborted();\n\n return result;\n } catch (error) {\n if (\n await onAttemptFailure({\n error,\n attemptNumber,\n retriesConsumed,\n startTime,\n options,\n })\n ) {\n retriesConsumed++;\n }\n }\n }\n\n // Should not reach here, but in case it does, throw an error\n throw new Error(\"Retry attempts exhausted without throwing an error.\");\n}\n\nexport function makeRetriable(function_, options) {\n return function (...arguments_) {\n return pRetry(() => function_.apply(this, arguments_), options);\n };\n}\n"],"mappings":";;;AAGA,SAAS,gBAAgB,SAAS;AAChC,KAAI,OAAO,YAAY,UAAU;AAC/B,MAAI,UAAU,EACZ,OAAM,IAAI,UAAU;AAGtB,MAAI,OAAO,MAAM,QAAQ,CACvB,OAAM,IAAI,UACR;CAGL,WAAU,YAAY,OACrB,OAAM,IAAI,UAAU;AAEvB;AAED,SAAS,qBACP,MACA,OACA,EAAE,MAAM,GAAG,gBAAgB,OAAO,GAAG,CAAE,GACvC;AACA,KAAI,UAAU,OACZ;AAGF,KAAI,OAAO,UAAU,YAAY,OAAO,MAAM,MAAM,CAClD,OAAM,IAAI,UACR,CAAC,WAAW,EAAE,KAAK,iBAAiB,EAClC,gBAAgB,iBAAiB,GAClC,CAAC,CAAC;AAIP,KAAI,CAAC,iBAAiB,CAAC,OAAO,SAAS,MAAM,CAC3C,OAAM,IAAI,UAAU,CAAC,WAAW,EAAE,KAAK,yBAAyB,CAAC;AAGnE,KAAI,QAAQ,IACV,OAAM,IAAI,UAAU,CAAC,WAAW,EAAE,KAAK,gBAAgB,EAAE,IAAI,CAAC,CAAC;AAElE;AAED,IAAa,aAAb,cAAgC,MAAM;CACpC,YAAY,SAAS;EACnB,OAA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cAAc,QAAQ,YAAY;EACrD,KAAK;EACL,eAAe;CAChB,EAAC;CACF,qBAAqB,cAAc,QAAQ,YAAY;EACrD,KAAK;EACL,eAAe;CAChB,EAAC;CACF,qBAAqB,gBAAgB,QAAQ,cAAc;EACzD,KAAK;EACL,eAAe;CAChB,EAAC;AAGF,KAAI,EAAE,QAAQ,SAAS,IACrB,QAAQ,SAAS;CAGnB,QAAQ,QAAQ,gBAAgB;CAEhC,IAAI,gBAAgB;CACpB,IAAI,kBAAkB;CACtB,MAAM,YAAY,YAAY,KAAK;AAEnC,QACE,OAAO,SAAS,QAAQ,QAAQ,GAAG,mBAAmB,QAAQ,UAAU,MACxE;EACA;AAEA,MAAI;GACF,QAAQ,QAAQ,gBAAgB;GAEhC,MAAM,SAAS,MAAM,MAAM,cAAc;GAEzC,QAAQ,QAAQ,gBAAgB;AAEhC,UAAO;EACR,SAAQ,OAAO;AACd,OACE,MAAM,iBAAiB;IACrB;IACA;IACA;IACA;IACA;GACD,EAAC,EAEF;EAEH;CACF;AAGD,OAAM,IAAI,MAAM;AACjB"}
@@ -1,6 +1,6 @@
1
- import { isNetworkError } from "../../../is-network-error@1.3.0/node_modules/is-network-error/index.js";
1
+ import { isNetworkError } from "../is-network-error/index.js";
2
2
 
3
- //#region ../../node_modules/.pnpm/p-retry@7.1.0/node_modules/p-retry/index.js
3
+ //#region src/utils/p-retry/index.js
4
4
  function validateRetries(retries) {
5
5
  if (typeof retries === "number") {
6
6
  if (retries < 0) throw new TypeError("Expected `retries` to be a non-negative number.");
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","names":[],"sources":["../../../src/utils/p-retry/index.js"],"sourcesContent":["/* eslint-disable */\nimport isNetworkError from \"../is-network-error/index.js\";\n\nfunction validateRetries(retries) {\n if (typeof retries === \"number\") {\n if (retries < 0) {\n throw new TypeError(\"Expected `retries` to be a non-negative number.\");\n }\n\n if (Number.isNaN(retries)) {\n throw new TypeError(\n \"Expected `retries` to be a valid number or Infinity, got NaN.\"\n );\n }\n } else if (retries !== undefined) {\n throw new TypeError(\"Expected `retries` to be a number or Infinity.\");\n }\n}\n\nfunction validateNumberOption(\n name,\n value,\n { min = 0, allowInfinity = false } = {}\n) {\n if (value === undefined) {\n return;\n }\n\n if (typeof value !== \"number\" || Number.isNaN(value)) {\n throw new TypeError(\n `Expected \\`${name}\\` to be a number${\n allowInfinity ? \" or Infinity\" : \"\"\n }.`\n );\n }\n\n if (!allowInfinity && !Number.isFinite(value)) {\n throw new TypeError(`Expected \\`${name}\\` to be a finite number.`);\n }\n\n if (value < min) {\n throw new TypeError(`Expected \\`${name}\\` to be \\u2265 ${min}.`);\n }\n}\n\nexport class AbortError extends Error {\n constructor(message) {\n super();\n\n if (message instanceof Error) {\n this.originalError = message;\n ({ message } = message);\n } else {\n this.originalError = new Error(message);\n this.originalError.stack = this.stack;\n }\n\n this.name = \"AbortError\";\n this.message = message;\n }\n}\n\nfunction calculateDelay(retriesConsumed, options) {\n const attempt = Math.max(1, retriesConsumed + 1);\n const random = options.randomize ? Math.random() + 1 : 1;\n\n let timeout = Math.round(\n random * options.minTimeout * options.factor ** (attempt - 1)\n );\n timeout = Math.min(timeout, options.maxTimeout);\n\n return timeout;\n}\n\nfunction calculateRemainingTime(start, max) {\n if (!Number.isFinite(max)) {\n return max;\n }\n\n return max - (performance.now() - start);\n}\n\nasync function onAttemptFailure({\n error,\n attemptNumber,\n retriesConsumed,\n startTime,\n options,\n}) {\n const normalizedError =\n error instanceof Error\n ? error\n : new TypeError(\n `Non-error was thrown: \"${error}\". You should only throw errors.`\n );\n\n if (normalizedError instanceof AbortError) {\n throw normalizedError.originalError;\n }\n\n const retriesLeft = Number.isFinite(options.retries)\n ? Math.max(0, options.retries - retriesConsumed)\n : options.retries;\n\n const maxRetryTime = options.maxRetryTime ?? Number.POSITIVE_INFINITY;\n\n const context = Object.freeze({\n error: normalizedError,\n attemptNumber,\n retriesLeft,\n retriesConsumed,\n });\n\n await options.onFailedAttempt(context);\n\n if (calculateRemainingTime(startTime, maxRetryTime) <= 0) {\n throw normalizedError;\n }\n\n const consumeRetry = await options.shouldConsumeRetry(context);\n\n const remainingTime = calculateRemainingTime(startTime, maxRetryTime);\n\n if (remainingTime <= 0 || retriesLeft <= 0) {\n throw normalizedError;\n }\n\n if (\n normalizedError instanceof TypeError &&\n !isNetworkError(normalizedError)\n ) {\n if (consumeRetry) {\n throw normalizedError;\n }\n\n options.signal?.throwIfAborted();\n return false;\n }\n\n if (!(await options.shouldRetry(context))) {\n throw normalizedError;\n }\n\n if (!consumeRetry) {\n options.signal?.throwIfAborted();\n return false;\n }\n\n const delayTime = calculateDelay(retriesConsumed, options);\n const finalDelay = Math.min(delayTime, remainingTime);\n\n if (finalDelay > 0) {\n await new Promise((resolve, reject) => {\n const onAbort = () => {\n clearTimeout(timeoutToken);\n options.signal?.removeEventListener(\"abort\", onAbort);\n reject(options.signal.reason);\n };\n\n const timeoutToken = setTimeout(() => {\n options.signal?.removeEventListener(\"abort\", onAbort);\n resolve();\n }, finalDelay);\n\n if (options.unref) {\n timeoutToken.unref?.();\n }\n\n options.signal?.addEventListener(\"abort\", onAbort, { once: true });\n });\n }\n\n options.signal?.throwIfAborted();\n\n return true;\n}\n\nexport default async function pRetry(input, options = {}) {\n options = { ...options };\n\n validateRetries(options.retries);\n\n if (Object.hasOwn(options, \"forever\")) {\n throw new Error(\n \"The `forever` option is no longer supported. For many use-cases, you can set `retries: Infinity` instead.\"\n );\n }\n\n options.retries ??= 10;\n options.factor ??= 2;\n options.minTimeout ??= 1000;\n options.maxTimeout ??= Number.POSITIVE_INFINITY;\n options.maxRetryTime ??= Number.POSITIVE_INFINITY;\n options.randomize ??= false;\n options.onFailedAttempt ??= () => {};\n options.shouldRetry ??= () => true;\n options.shouldConsumeRetry ??= () => true;\n\n // Validate numeric options and normalize edge cases\n validateNumberOption(\"factor\", options.factor, {\n min: 0,\n allowInfinity: false,\n });\n validateNumberOption(\"minTimeout\", options.minTimeout, {\n min: 0,\n allowInfinity: false,\n });\n validateNumberOption(\"maxTimeout\", options.maxTimeout, {\n min: 0,\n allowInfinity: true,\n });\n validateNumberOption(\"maxRetryTime\", options.maxRetryTime, {\n min: 0,\n allowInfinity: true,\n });\n\n // Treat non-positive factor as 1 to avoid zero backoff or negative behavior\n if (!(options.factor > 0)) {\n options.factor = 1;\n }\n\n options.signal?.throwIfAborted();\n\n let attemptNumber = 0;\n let retriesConsumed = 0;\n const startTime = performance.now();\n\n while (\n Number.isFinite(options.retries) ? retriesConsumed <= options.retries : true\n ) {\n attemptNumber++;\n\n try {\n options.signal?.throwIfAborted();\n\n const result = await input(attemptNumber);\n\n options.signal?.throwIfAborted();\n\n return result;\n } catch (error) {\n if (\n await onAttemptFailure({\n error,\n attemptNumber,\n retriesConsumed,\n startTime,\n options,\n })\n ) {\n retriesConsumed++;\n }\n }\n }\n\n // Should not reach here, but in case it does, throw an error\n throw new Error(\"Retry attempts exhausted without throwing an error.\");\n}\n\nexport function makeRetriable(function_, options) {\n return function (...arguments_) {\n return pRetry(() => function_.apply(this, arguments_), options);\n };\n}\n"],"mappings":";;;AAGA,SAAS,gBAAgB,SAAS;AAChC,KAAI,OAAO,YAAY,UAAU;AAC/B,MAAI,UAAU,EACZ,OAAM,IAAI,UAAU;AAGtB,MAAI,OAAO,MAAM,QAAQ,CACvB,OAAM,IAAI,UACR;CAGL,WAAU,YAAY,OACrB,OAAM,IAAI,UAAU;AAEvB;AAED,SAAS,qBACP,MACA,OACA,EAAE,MAAM,GAAG,gBAAgB,OAAO,GAAG,CAAE,GACvC;AACA,KAAI,UAAU,OACZ;AAGF,KAAI,OAAO,UAAU,YAAY,OAAO,MAAM,MAAM,CAClD,OAAM,IAAI,UACR,CAAC,WAAW,EAAE,KAAK,iBAAiB,EAClC,gBAAgB,iBAAiB,GAClC,CAAC,CAAC;AAIP,KAAI,CAAC,iBAAiB,CAAC,OAAO,SAAS,MAAM,CAC3C,OAAM,IAAI,UAAU,CAAC,WAAW,EAAE,KAAK,yBA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tB,QAAQ,oBAAoB,MAAM,CAAE;CACpC,QAAQ,gBAAgB,MAAM;CAC9B,QAAQ,uBAAuB,MAAM;CAGrC,qBAAqB,UAAU,QAAQ,QAAQ;EAC7C,KAAK;EACL,eAAe;CAChB,EAAC;CACF,qBAAqB,cAAc,QAAQ,YAAY;EACrD,KAAK;EACL,eAAe;CAChB,EAAC;CACF,qBAAqB,cAAc,QAAQ,YAAY;EACrD,KAAK;EACL,eAAe;CAChB,EAAC;CACF,qBAAqB,gBAAgB,QAAQ,cAAc;EACzD,KAAK;EACL,eAAe;CAChB,EAAC;AAGF,KAAI,EAAE,QAAQ,SAAS,IACrB,QAAQ,SAAS;CAGnB,QAAQ,QAAQ,gBAAgB;CAEhC,IAAI,gBAAgB;CACpB,IAAI,kBAAkB;CACtB,MAAM,YAAY,YAAY,KAAK;AAEnC,QACE,OAAO,SAAS,QAAQ,QAAQ,GAAG,mBAAmB,QAAQ,UAAU,MACxE;EACA;AAEA,MAAI;GACF,QAAQ,QAAQ,gBAAgB;GAEhC,MAAM,SAAS,MAAM,MAAM,cAAc;GAEzC,QAAQ,QAAQ,gBAAgB;AAEhC,UAAO;EACR,SAAQ,OAAO;AACd,OACE,MAAM,iBAAiB;IACrB;IACA;IACA;IACA;IACA;GACD,EAAC,EAEF;EAEH;CACF;AAGD,OAAM,IAAI,MAAM;AACjB"}
@@ -1,19 +1,29 @@
1
1
  import { IterableReadableStreamInterface } from "../types/_internal.cjs";
2
2
 
3
3
  //#region src/utils/stream.d.ts
4
+
5
+ /*
6
+ * Support async iterator syntax for ReadableStreams in all environments.
7
+ * Source: https://github.com/MattiasBuelens/web-streams-polyfill/pull/122#issuecomment-1627354490
8
+ */
4
9
  declare class IterableReadableStream<T> extends ReadableStream<T> implements IterableReadableStreamInterface<T> {
5
10
  reader: ReadableStreamDefaultReader<T>;
6
11
  ensureReader(): void;
7
12
  next(): Promise<IteratorResult<T>>;
8
13
  return(): Promise<IteratorResult<T>>;
14
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
9
15
  throw(e: any): Promise<IteratorResult<T>>;
10
16
  [Symbol.asyncIterator](): this;
17
+ // eslint-disable-next-line @typescript-eslint/ban-ts-comment
18
+ // @ts-ignore Not present in Node 18 types, required in latest Node 22
11
19
  [Symbol.asyncDispose](): Promise<void>;
12
20
  static fromReadableStream<T>(stream: ReadableStream<T>): IterableReadableStream<T>;
13
21
  static fromAsyncGenerator<T>(generator: AsyncGenerator<T>): IterableReadableStream<T>;
14
22
  }
15
23
  declare function atee<T>(iter: AsyncGenerator<T>, length?: number): AsyncGenerator<T>[];
16
- declare function concat<T extends Array<any> | string | number | Record<string, any> | any>(first: T, second: T): T;
24
+ declare function concat<
25
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
26
+ T extends Array<any> | string | number | Record<string, any> | any>(first: T, second: T): T;
17
27
  declare class AsyncGeneratorWithSetup<S = unknown, T = unknown, TReturn = unknown, TNext = unknown> implements AsyncGenerator<T, TReturn, TNext> {
18
28
  private generator;
19
29
  setup: Promise<S>;
@@ -31,6 +41,8 @@ declare class AsyncGeneratorWithSetup<S = unknown, T = unknown, TReturn = unknow
31
41
  return(value?: TReturn | PromiseLike<TReturn>): Promise<IteratorResult<T>>;
32
42
  throw(e: Error): Promise<IteratorResult<T>>;
33
43
  [Symbol.asyncIterator](): this;
44
+ // eslint-disable-next-line @typescript-eslint/ban-ts-comment
45
+ // @ts-ignore Not present in Node 18 types, required in latest Node 22
34
46
  [Symbol.asyncDispose](): Promise<void>;
35
47
  }
36
48
  declare function pipeGeneratorWithSetup<S, A extends unknown[], T, TReturn, TNext, U, UReturn, UNext>(to: (g: AsyncGenerator<T, TReturn, TNext>, s: S, ...args: A) => AsyncGenerator<U, UReturn, UNext>, generator: AsyncGenerator<T, TReturn, TNext>, startSetup: () => Promise<S>, signal: AbortSignal | undefined, ...args: A): Promise<{
@@ -1,19 +1,29 @@
1
1
  import { IterableReadableStreamInterface } from "../types/_internal.js";
2
2
 
3
3
  //#region src/utils/stream.d.ts
4
+
5
+ /*
6
+ * Support async iterator syntax for ReadableStreams in all environments.
7
+ * Source: https://github.com/MattiasBuelens/web-streams-polyfill/pull/122#issuecomment-1627354490
8
+ */
4
9
  declare class IterableReadableStream<T> extends ReadableStream<T> implements IterableReadableStreamInterface<T> {
5
10
  reader: ReadableStreamDefaultReader<T>;
6
11
  ensureReader(): void;
7
12
  next(): Promise<IteratorResult<T>>;
8
13
  return(): Promise<IteratorResult<T>>;
14
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
9
15
  throw(e: any): Promise<IteratorResult<T>>;
10
16
  [Symbol.asyncIterator](): this;
17
+ // eslint-disable-next-line @typescript-eslint/ban-ts-comment
18
+ // @ts-ignore Not present in Node 18 types, required in latest Node 22
11
19
  [Symbol.asyncDispose](): Promise<void>;
12
20
  static fromReadableStream<T>(stream: ReadableStream<T>): IterableReadableStream<T>;
13
21
  static fromAsyncGenerator<T>(generator: AsyncGenerator<T>): IterableReadableStream<T>;
14
22
  }
15
23
  declare function atee<T>(iter: AsyncGenerator<T>, length?: number): AsyncGenerator<T>[];
16
- declare function concat<T extends Array<any> | string | number | Record<string, any> | any>(first: T, second: T): T;
24
+ declare function concat<
25
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
26
+ T extends Array<any> | string | number | Record<string, any> | any>(first: T, second: T): T;
17
27
  declare class AsyncGeneratorWithSetup<S = unknown, T = unknown, TReturn = unknown, TNext = unknown> implements AsyncGenerator<T, TReturn, TNext> {
18
28
  private generator;
19
29
  setup: Promise<S>;
@@ -31,6 +41,8 @@ declare class AsyncGeneratorWithSetup<S = unknown, T = unknown, TReturn = unknow
31
41
  return(value?: TReturn | PromiseLike<TReturn>): Promise<IteratorResult<T>>;
32
42
  throw(e: Error): Promise<IteratorResult<T>>;
33
43
  [Symbol.asyncIterator](): this;
44
+ // eslint-disable-next-line @typescript-eslint/ban-ts-comment
45
+ // @ts-ignore Not present in Node 18 types, required in latest Node 22
34
46
  [Symbol.asyncDispose](): Promise<void>;
35
47
  }
36
48
  declare function pipeGeneratorWithSetup<S, A extends unknown[], T, TReturn, TNext, U, UReturn, UNext>(to: (g: AsyncGenerator<T, TReturn, TNext>, s: S, ...args: A) => AsyncGenerator<U, UReturn, UNext>, generator: AsyncGenerator<T, TReturn, TNext>, startSetup: () => Promise<S>, signal: AbortSignal | undefined, ...args: A): Promise<{
@@ -15,7 +15,7 @@ import { BaseLLMParams } from "../../language_models/llms.cjs";
15
15
  interface ToolSpec {
16
16
  name: string;
17
17
  description?: string;
18
- schema: InteropZodType | Record<string, unknown>;
18
+ schema: InteropZodType | Record<string, unknown>; // Either a Zod schema *or* a plain JSON-Schema object
19
19
  }
20
20
  /**
21
21
  * Interface specific to the Fake Streaming Chat model.
@@ -115,8 +115,16 @@ declare class FakeListChatModel extends BaseChatModel<FakeListChatModelCallOptio
115
115
  _createResponseChunk(text: string): ChatGenerationChunk;
116
116
  _currentResponse(): string;
117
117
  _incrementResponse(): void;
118
- withStructuredOutput<RunOutput extends Record<string, any> = Record<string, any>>(_params: StructuredOutputMethodParams<RunOutput, false> | InteropZodType<RunOutput> | Record<string, any>, config?: StructuredOutputMethodOptions<false>): Runnable<BaseLanguageModelInput, RunOutput>;
119
- withStructuredOutput<RunOutput extends Record<string, any> = Record<string, any>>(_params: StructuredOutputMethodParams<RunOutput, true> | InteropZodType<RunOutput> | Record<string, any>, config?: StructuredOutputMethodOptions<true>): Runnable<BaseLanguageModelInput, {
118
+ withStructuredOutput<
119
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
120
+ RunOutput extends Record<string, any> = Record<string, any>>(_params: StructuredOutputMethodParams<RunOutput, false> | InteropZodType<RunOutput>
121
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
122
+ | Record<string, any>, config?: StructuredOutputMethodOptions<false>): Runnable<BaseLanguageModelInput, RunOutput>;
123
+ withStructuredOutput<
124
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
125
+ RunOutput extends Record<string, any> = Record<string, any>>(_params: StructuredOutputMethodParams<RunOutput, true> | InteropZodType<RunOutput>
126
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
127
+ | Record<string, any>, config?: StructuredOutputMethodOptions<true>): Runnable<BaseLanguageModelInput, {
120
128
  raw: BaseMessage;
121
129
  parsed: RunOutput;
122
130
  }>;
@@ -16,7 +16,7 @@ import { BaseLLMParams } from "../../language_models/llms.js";
16
16
  interface ToolSpec {
17
17
  name: string;
18
18
  description?: string;
19
- schema: InteropZodType | Record<string, unknown>;
19
+ schema: InteropZodType | Record<string, unknown>; // Either a Zod schema *or* a plain JSON-Schema object
20
20
  }
21
21
  /**
22
22
  * Interface specific to the Fake Streaming Chat model.
@@ -116,8 +116,16 @@ declare class FakeListChatModel extends BaseChatModel<FakeListChatModelCallOptio
116
116
  _createResponseChunk(text: string): ChatGenerationChunk;
117
117
  _currentResponse(): string;
118
118
  _incrementResponse(): void;
119
- withStructuredOutput<RunOutput extends Record<string, any> = Record<string, any>>(_params: StructuredOutputMethodParams<RunOutput, false> | InteropZodType<RunOutput> | Record<string, any>, config?: StructuredOutputMethodOptions<false>): Runnable<BaseLanguageModelInput, RunOutput>;
120
- withStructuredOutput<RunOutput extends Record<string, any> = Record<string, any>>(_params: StructuredOutputMethodParams<RunOutput, true> | InteropZodType<RunOutput> | Record<string, any>, config?: StructuredOutputMethodOptions<true>): Runnable<BaseLanguageModelInput, {
119
+ withStructuredOutput<
120
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
121
+ RunOutput extends Record<string, any> = Record<string, any>>(_params: StructuredOutputMethodParams<RunOutput, false> | InteropZodType<RunOutput>
122
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
123
+ | Record<string, any>, config?: StructuredOutputMethodOptions<false>): Runnable<BaseLanguageModelInput, RunOutput>;
124
+ withStructuredOutput<
125
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
126
+ RunOutput extends Record<string, any> = Record<string, any>>(_params: StructuredOutputMethodParams<RunOutput, true> | InteropZodType<RunOutput>
127
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
128
+ | Record<string, any>, config?: StructuredOutputMethodOptions<true>): Runnable<BaseLanguageModelInput, {
121
129
  raw: BaseMessage;
122
130
  parsed: RunOutput;
123
131
  }>;
@@ -8,7 +8,9 @@ declare class FakeRetriever extends BaseRetriever {
8
8
  constructor(fields?: {
9
9
  output: Document[];
10
10
  });
11
- _getRelevantDocuments(_query: string): Promise<Document<Record<string, any>>[]>;
11
+ _getRelevantDocuments(_query: string
12
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
13
+ ): Promise<Document<Record<string, any>>[]>;
12
14
  }
13
15
  //#endregion
14
16
  export { FakeRetriever };
@@ -8,7 +8,9 @@ declare class FakeRetriever extends BaseRetriever {
8
8
  constructor(fields?: {
9
9
  output: Document[];
10
10
  });
11
- _getRelevantDocuments(_query: string): Promise<Document<Record<string, any>>[]>;
11
+ _getRelevantDocuments(_query: string
12
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
13
+ ): Promise<Document<Record<string, any>>[]>;
12
14
  }
13
15
  //#endregion
14
16
  export { FakeRetriever };
@@ -13,6 +13,7 @@ import { cosine } from "../ml-distance/similarities.cjs";
13
13
  interface MemoryVector {
14
14
  content: string;
15
15
  embedding: number[];
16
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
16
17
  metadata: Record<string, any>;
17
18
  }
18
19
  /**
@@ -13,6 +13,7 @@ import { cosine } from "../ml-distance/similarities.js";
13
13
  interface MemoryVector {
14
14
  content: string;
15
15
  embedding: number[];
16
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
16
17
  metadata: Record<string, any>;
17
18
  }
18
19
  /**
@@ -6,8 +6,10 @@ import { InferInteropZodInput, InferInteropZodOutput, InteropZodDefault, Interop
6
6
  * Represents a string value with autocompleted, but not required, suggestions.
7
7
  */
8
8
  type StringWithAutocomplete<T> = T | (string & Record<never, never>);
9
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
9
10
  type InputValues<K extends string = string> = Record<K, any>;
10
11
  type PartialValues<K extends string = string> = Record<K, string | (() => Promise<string>) | (() => string)>;
12
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
11
13
  type ChainValues = Record<string, any>;
12
14
  //#endregion
13
15
  export { ChainValues, InferInteropZodInput, InferInteropZodOutput, InputValues, InteropZodDefault, InteropZodIssue, InteropZodLiteral, InteropZodObject, InteropZodObjectShape, InteropZodOptional, InteropZodType, Mutable, PartialValues, StringWithAutocomplete, ZodDefaultV3, ZodDefaultV4, ZodNullableV4, ZodObjectV3, ZodObjectV4, ZodOptionalV3, ZodOptionalV4, ZodStringV3, ZodStringV4, extendInteropZodObject, getInteropZodDefaultGetter, getInteropZodObjectShape, getSchemaDescription, interopParse, interopParseAsync, interopSafeParse, interopSafeParseAsync, interopZodObjectMakeFieldsOptional, interopZodObjectPartial, interopZodObjectPassthrough, interopZodObjectStrict, interopZodTransformInputSchema, isInteropZodError, isInteropZodLiteral, isInteropZodObject, isInteropZodSchema, isShapelessZodSchema, isSimpleStringZodSchema, isZodArrayV4, isZodLiteralV3, isZodLiteralV4, isZodNullableV4, isZodObjectV3, isZodObjectV4, isZodOptionalV4, isZodSchema, isZodSchemaV3, isZodSchemaV4 };
@@ -6,8 +6,10 @@ import { InferInteropZodInput, InferInteropZodOutput, InteropZodDefault, Interop
6
6
  * Represents a string value with autocompleted, but not required, suggestions.
7
7
  */
8
8
  type StringWithAutocomplete<T> = T | (string & Record<never, never>);
9
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
9
10
  type InputValues<K extends string = string> = Record<K, any>;
10
11
  type PartialValues<K extends string = string> = Record<K, string | (() => Promise<string>) | (() => string)>;
12
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
11
13
  type ChainValues = Record<string, any>;
12
14
  //#endregion
13
15
  export { ChainValues, InferInteropZodInput, InferInteropZodOutput, InputValues, InteropZodDefault, InteropZodIssue, InteropZodLiteral, InteropZodObject, InteropZodObjectShape, InteropZodOptional, InteropZodType, Mutable, PartialValues, StringWithAutocomplete, ZodDefaultV3, ZodDefaultV4, ZodNullableV4, ZodObjectV3, ZodObjectV4, ZodOptionalV3, ZodOptionalV4, ZodStringV3, ZodStringV4, extendInteropZodObject, getInteropZodDefaultGetter, getInteropZodObjectShape, getSchemaDescription, interopParse, interopParseAsync, interopSafeParse, interopSafeParseAsync, interopZodObjectMakeFieldsOptional, interopZodObjectPartial, interopZodObjectPassthrough, interopZodObjectStrict, interopZodTransformInputSchema, isInteropZodError, isInteropZodLiteral, isInteropZodObject, isInteropZodSchema, isShapelessZodSchema, isSimpleStringZodSchema, isZodArrayV4, isZodLiteralV3, isZodLiteralV4, isZodNullableV4, isZodObjectV3, isZodObjectV4, isZodOptionalV4, isZodSchema, isZodSchemaV3, isZodSchemaV4 };
@@ -4,6 +4,7 @@ import * as z4 from "zod/v4/core";
4
4
  //#region src/utils/types/zod.d.ts
5
5
  type ZodStringV3 = z3.ZodString;
6
6
  type ZodStringV4 = z4.$ZodType<string, unknown>;
7
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
7
8
  type ZodObjectV3 = z3.ZodObject<any, any, any, any>;
8
9
  type ZodObjectV4 = z4.$ZodObject;
9
10
  type ZodDefaultV3<T extends z3.ZodTypeAny> = z3.ZodDefault<T>;
@@ -11,12 +12,14 @@ type ZodDefaultV4<T extends z4.SomeType> = z4.$ZodDefault<T>;
11
12
  type ZodOptionalV3<T extends z3.ZodTypeAny> = z3.ZodOptional<T>;
12
13
  type ZodOptionalV4<T extends z4.SomeType> = z4.$ZodOptional<T>;
13
14
  type ZodNullableV4<T extends z4.SomeType> = z4.$ZodNullable<T>;
15
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
14
16
  type InteropZodType<Output$1 = any, Input$1 = Output$1> = z3.ZodType<Output$1, z3.ZodTypeDef, Input$1> | z4.$ZodType<Output$1, Input$1>;
15
17
  type InteropZodObject = ZodObjectV3 | ZodObjectV4;
16
18
  type InteropZodDefault<T = InteropZodObjectShape> = T extends z3.ZodTypeAny ? ZodDefaultV3<T> : T extends z4.SomeType ? ZodDefaultV4<T> : never;
17
19
  type InteropZodOptional<T = InteropZodObjectShape> = T extends z3.ZodTypeAny ? ZodOptionalV3<T> : T extends z4.SomeType ? ZodOptionalV4<T> : never;
18
20
  type InteropZodObjectShape<T extends InteropZodObject = InteropZodObject> = T extends z3.ZodObject<infer Shape> ? { [K in keyof Shape]: Shape[K] } : T extends z4.$ZodObject<infer Shape> ? { [K in keyof Shape]: Shape[K] } : never;
19
21
  type InteropZodIssue = z3.ZodIssue | z4.$ZodIssue;
22
+ // Simplified type inference to avoid circular dependencies
20
23
  type InferInteropZodInput<T> = T extends z3.ZodType<unknown, z3.ZodTypeDef, infer Input> ? Input : T extends z4.$ZodType<unknown, infer Input> ? Input : T extends {
21
24
  _zod: {
22
25
  input: infer Input;
@@ -4,6 +4,7 @@ import * as z4 from "zod/v4/core";
4
4
  //#region src/utils/types/zod.d.ts
5
5
  type ZodStringV3 = z3.ZodString;
6
6
  type ZodStringV4 = z4.$ZodType<string, unknown>;
7
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
7
8
  type ZodObjectV3 = z3.ZodObject<any, any, any, any>;
8
9
  type ZodObjectV4 = z4.$ZodObject;
9
10
  type ZodDefaultV3<T extends z3.ZodTypeAny> = z3.ZodDefault<T>;
@@ -11,12 +12,14 @@ type ZodDefaultV4<T extends z4.SomeType> = z4.$ZodDefault<T>;
11
12
  type ZodOptionalV3<T extends z3.ZodTypeAny> = z3.ZodOptional<T>;
12
13
  type ZodOptionalV4<T extends z4.SomeType> = z4.$ZodOptional<T>;
13
14
  type ZodNullableV4<T extends z4.SomeType> = z4.$ZodNullable<T>;
15
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
14
16
  type InteropZodType<Output$1 = any, Input$1 = Output$1> = z3.ZodType<Output$1, z3.ZodTypeDef, Input$1> | z4.$ZodType<Output$1, Input$1>;
15
17
  type InteropZodObject = ZodObjectV3 | ZodObjectV4;
16
18
  type InteropZodDefault<T = InteropZodObjectShape> = T extends z3.ZodTypeAny ? ZodDefaultV3<T> : T extends z4.SomeType ? ZodDefaultV4<T> : never;
17
19
  type InteropZodOptional<T = InteropZodObjectShape> = T extends z3.ZodTypeAny ? ZodOptionalV3<T> : T extends z4.SomeType ? ZodOptionalV4<T> : never;
18
20
  type InteropZodObjectShape<T extends InteropZodObject = InteropZodObject> = T extends z3.ZodObject<infer Shape> ? { [K in keyof Shape]: Shape[K] } : T extends z4.$ZodObject<infer Shape> ? { [K in keyof Shape]: Shape[K] } : never;
19
21
  type InteropZodIssue = z3.ZodIssue | z4.$ZodIssue;
22
+ // Simplified type inference to avoid circular dependencies
20
23
  type InferInteropZodInput<T> = T extends z3.ZodType<unknown, z3.ZodTypeDef, infer Input> ? Input : T extends z4.$ZodType<unknown, infer Input> ? Input : T extends {
21
24
  _zod: {
22
25
  input: infer Input;