5dd7e891f20bf002e40aabcbd1a176ffb4e426b5a15449fc478abb2bd35ebac9.json 13 KB

1
  1. {"ast":null,"code":"import pRetry from \"p-retry\";\nimport PQueueMod from \"p-queue\";\nconst STATUS_NO_RETRY = [400, 401, 402, 403, 404, 405, 406, 407, 409 // Conflict\n];\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nconst defaultFailedAttemptHandler = error => {\n var _error$response$statu, _error$response, _error$error;\n if (error.message.startsWith(\"Cancel\") || error.message.startsWith(\"AbortError\") || error.name === \"AbortError\") {\n throw error;\n }\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n if ((error === null || error === void 0 ? void 0 : error.code) === \"ECONNABORTED\") {\n throw error;\n }\n const status = // eslint-disable-next-line @typescript-eslint/no-explicit-any\n (_error$response$statu = error === null || error === void 0 || (_error$response = error.response) === null || _error$response === void 0 ? void 0 : _error$response.status) !== null && _error$response$statu !== void 0 ? _error$response$statu : error === null || error === void 0 ? void 0 : error.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 === null || error === void 0 || (_error$error = error.error) === null || _error$error === void 0 ? void 0 : _error$error.code) === \"insufficient_quota\") {\n const err = new Error(error === null || error === void 0 ? void 0 : error.message);\n err.name = \"InsufficientQuotaError\";\n throw err;\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 constructor(params) {\n var _params$maxConcurrenc, _params$maxRetries, _params$onFailedAttem;\n Object.defineProperty(this, \"maxConcurrency\", {\n enumerable: true,\n configurable: true,\n writable: true,\n value: void 0\n });\n Object.defineProperty(this, \"maxRetries\", {\n enumerable: true,\n configurable: true,\n writable: true,\n value: void 0\n });\n Object.defineProperty(this, \"onFailedAttempt\", {\n enumerable: true,\n configurable: true,\n writable: true,\n value: void 0\n });\n Object.defineProperty(this, \"queue\", {\n enumerable: true,\n configurable: true,\n writable: true,\n value: void 0\n });\n this.maxConcurrency = (_params$maxConcurrenc = params.maxConcurrency) !== null && _params$maxConcurrenc !== void 0 ? _params$maxConcurrenc : Infinity;\n this.maxRetries = (_params$maxRetries = params.maxRetries) !== null && _params$maxRetries !== void 0 ? _params$maxRetries : 6;\n this.onFailedAttempt = (_params$onFailedAttem = params.onFailedAttempt) !== null && _params$onFailedAttem !== void 0 ? _params$onFailedAttem : defaultFailedAttemptHandler;\n const PQueue = \"default\" in PQueueMod ? PQueueMod.default : PQueueMod;\n this.queue = new PQueue({\n concurrency: this.maxConcurrency\n });\n }\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n call(callable, ...args) {\n return this.queue.add(() => pRetry(() => 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 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 throwOnTimeout: true\n });\n }\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n callWithOptions(options, callable, ...args) {\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([this.call(callable, ...args), new Promise((_, reject) => {\n var _options$signal;\n (_options$signal = options.signal) === null || _options$signal === void 0 || _options$signal.addEventListener(\"abort\", () => {\n reject(new Error(\"AbortError\"));\n });\n })]);\n }\n return this.call(callable, ...args);\n }\n fetch(...args) {\n return this.call(() => fetch(...args).then(res => res.ok ? res : Promise.reject(res)));\n }\n}","map":{"version":3,"names":["pRetry","PQueueMod","STATUS_NO_RETRY","defaultFailedAttemptHandler","error","_error$response$statu","_error$response","_error$error","message","startsWith","name","code","status","response","includes","err","Error","AsyncCaller","constructor","params","_params$maxConcurrenc","_params$maxRetries","_params$onFailedAttem","Object","defineProperty","enumerable","configurable","writable","value","maxConcurrency","Infinity","maxRetries","onFailedAttempt","PQueue","default","queue","concurrency","call","callable","args","add","catch","retries","randomize","throwOnTimeout","callWithOptions","options","signal","Promise","race","_","reject","_options$signal","addEventListener","fetch","then","res","ok"],"sources":["F:/workspace/202226701027/huinongbao-app/node_modules/@langchain/core/dist/utils/async_caller.js"],"sourcesContent":["import pRetry from \"p-retry\";\nimport PQueueMod from \"p-queue\";\nconst STATUS_NO_RETRY = [\n 400,\n 401,\n 402,\n 403,\n 404,\n 405,\n 406,\n 407,\n 409, // Conflict\n];\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nconst defaultFailedAttemptHandler = (error) => {\n if (error.message.startsWith(\"Cancel\") ||\n error.message.startsWith(\"AbortError\") ||\n error.name === \"AbortError\") {\n throw error;\n }\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n if (error?.code === \"ECONNABORTED\") {\n throw error;\n }\n const status = \n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n error?.response?.status ?? error?.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?.error?.code === \"insufficient_quota\") {\n const err = new Error(error?.message);\n err.name = \"InsufficientQuotaError\";\n throw err;\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 constructor(params) {\n Object.defineProperty(this, \"maxConcurrency\", {\n enumerable: true,\n configurable: true,\n writable: true,\n value: void 0\n });\n Object.defineProperty(this, \"maxRetries\", {\n enumerable: true,\n configurable: true,\n writable: true,\n value: void 0\n });\n Object.defineProperty(this, \"onFailedAttempt\", {\n enumerable: true,\n configurable: true,\n writable: true,\n value: void 0\n });\n Object.defineProperty(this, \"queue\", {\n enumerable: true,\n configurable: true,\n writable: true,\n value: void 0\n });\n this.maxConcurrency = params.maxConcurrency ?? Infinity;\n this.maxRetries = params.maxRetries ?? 6;\n this.onFailedAttempt =\n params.onFailedAttempt ?? defaultFailedAttemptHandler;\n const PQueue = \"default\" in PQueueMod ? PQueueMod.default : PQueueMod;\n this.queue = new PQueue({ concurrency: this.maxConcurrency });\n }\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n call(callable, ...args) {\n return this.queue.add(() => pRetry(() => callable(...args).catch((error) => {\n // eslint-disable-next-line no-instanceof/no-instanceof\n if (error instanceof Error) {\n throw error;\n }\n else {\n throw new Error(error);\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 }), { throwOnTimeout: true });\n }\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n callWithOptions(options, callable, ...args) {\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(callable, ...args),\n new Promise((_, reject) => {\n options.signal?.addEventListener(\"abort\", () => {\n reject(new Error(\"AbortError\"));\n });\n }),\n ]);\n }\n return this.call(callable, ...args);\n }\n fetch(...args) {\n return this.call(() => fetch(...args).then((res) => (res.ok ? res : Promise.reject(res))));\n }\n}\n"],"mappings":"AAAA,OAAOA,MAAM,MAAM,SAAS;AAC5B,OAAOC,SAAS,MAAM,SAAS;AAC/B,MAAMC,eAAe,GAAG,CACpB,GAAG,EACH,GAAG,EACH,GAAG,EACH,GAAG,EACH,GAAG,EACH,G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