1 |
- {"ast":null,"code":"import _asyncToGenerator from \"F:/workspace/202226701027/huinongbao-app/node_modules/@babel/runtime/helpers/esm/asyncToGenerator.js\";\nimport pRetry from \"p-retry\";\nimport PQueueMod from \"p-queue\";\nimport { _getFetchImplementation } from \"../singletons/fetch.js\";\nconst STATUS_NO_RETRY = [400,\n// Bad Request\n401,\n// Unauthorized\n403,\n// Forbidden\n404,\n// Not Found\n405,\n// Method Not Allowed\n406,\n// Not Acceptable\n407,\n// Proxy Authentication Required\n408 // Request Timeout\n];\nconst STATUS_IGNORE = [409 // Conflict\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;\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, \"queue\", {\n enumerable: true,\n configurable: true,\n writable: true,\n value: void 0\n });\n Object.defineProperty(this, \"onFailedResponseHook\", {\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 if (\"default\" in PQueueMod) {\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n this.queue = new PQueueMod.default({\n concurrency: this.maxConcurrency\n });\n } else {\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n this.queue = new PQueueMod({\n concurrency: this.maxConcurrency\n });\n }\n this.onFailedResponseHook = params === null || params === void 0 ? void 0 : params.onFailedResponseHook;\n }\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n call(callable, ...args) {\n const onFailedResponseHook = this.onFailedResponseHook;\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(error) {\n return _asyncToGenerator(function* () {\n if (error.message.startsWith(\"Cancel\") || error.message.startsWith(\"TimeoutError\") || error.message.startsWith(\"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 // eslint-disable-next-line @typescript-eslint/no-explicit-any\n const response = error === null || error === void 0 ? void 0 : error.response;\n const status = response === null || response === void 0 ? void 0 : response.status;\n if (status) {\n if (STATUS_NO_RETRY.includes(+status)) {\n throw error;\n } else if (STATUS_IGNORE.includes(+status)) {\n return;\n }\n if (onFailedResponseHook) {\n yield onFailedResponseHook(response);\n }\n }\n })();\n },\n // If needed we can change some of the defaults here,\n // but they're quite sensible.\n retries: this.maxRetries,\n randomize: true\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(() => _getFetchImplementation()(...args).then(res => res.ok ? res : Promise.reject(res)));\n }\n}","map":{"version":3,"names":["pRetry","PQueueMod","_getFetchImplementation","STATUS_NO_RETRY","STATUS_IGNORE","AsyncCaller","constructor","params","_params$maxConcurrenc","_params$maxRetries","Object","defineProperty","enumerable","configurable","writable","value","maxConcurrency","Infinity","maxRetries","queue","default","concurrency","onFailedResponseHook","call","callable","args","add","catch","error","Error","onFailedAttempt","_asyncToGenerator","message","startsWith","code","response","status","includes","retries","randomize","throwOnTimeout","callWithOptions","options","signal","Promise","race","_","reject","_options$signal","addEventListener","fetch","then","res","ok"],"sources":["F:/workspace/202226701027/huinongbao-app/node_modules/langsmith/dist/utils/async_caller.js"],"sourcesContent":["import pRetry from \"p-retry\";\nimport PQueueMod from \"p-queue\";\nimport { _getFetchImplementation } from \"../singletons/fetch.js\";\nconst STATUS_NO_RETRY = [\n 400, // Bad Request\n 401, // Unauthorized\n 403, // Forbidden\n 404, // Not Found\n 405, // Method Not Allowed\n 406, // Not Acceptable\n 407, // Proxy Authentication Required\n 408, // Request Timeout\n];\nconst STATUS_IGNORE = [\n 409, // Conflict\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, \"queue\", {\n enumerable: true,\n configurable: true,\n writable: true,\n value: void 0\n });\n Object.defineProperty(this, \"onFailedResponseHook\", {\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 if (\"default\" in PQueueMod) {\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n this.queue = new PQueueMod.default({\n concurrency: this.maxConcurrency,\n });\n }\n else {\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n this.queue = new PQueueMod({ concurrency: this.maxConcurrency });\n }\n this.onFailedResponseHook = params?.onFailedResponseHook;\n }\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n call(callable, ...args) {\n const onFailedResponseHook = this.onFailedResponseHook;\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 async onFailedAttempt(error) {\n if (error.message.startsWith(\"Cancel\") ||\n error.message.startsWith(\"TimeoutError\") ||\n error.message.startsWith(\"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 // eslint-disable-next-line @typescript-eslint/no-explicit-any\n const response = error?.response;\n const status = response?.status;\n if (status) {\n if (STATUS_NO_RETRY.includes(+status)) {\n throw error;\n }\n else if (STATUS_IGNORE.includes(+status)) {\n return;\n }\n if (onFailedResponseHook) {\n await onFailedResponseHook(response);\n }\n }\n },\n // If needed we can change some of the defaults here,\n // but they're quite sensible.\n retries: this.maxRetries,\n randomize: true,\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(() => _getFetchImplementation()(...args).then((res) => res.ok ? res : Promise.reject(res)));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