File tree Expand file tree Collapse file tree 2 files changed +20
-2
lines changed
libs/langchain-core/src/utils Expand file tree Collapse file tree 2 files changed +20
-2
lines changed Original file line number Diff line number Diff line change 1+ ---
2+ " @langchain/core " : patch
3+ ---
4+
5+ fix: use dynamic import for p-retry to support CommonJS environments
Original file line number Diff line number Diff line change 1- import pRetry from "p-retry" ;
21import PQueueMod from "p-queue" ;
32
43import { getAbortSignalError } from "./signal.js" ;
54
5+ // p-retry is ESM-only, so we use dynamic import for CJS compatibility.
6+ // The module is cached after first import, so subsequent calls are essentially free.
7+ // This approach is recommended by the p-retry author for async contexts:
8+ // https://gist.github.com/sindresorhus/a39789f98801d908bbc7ff3ecc99d99c
9+ let pRetryModule : typeof import ( "p-retry" ) | null = null ;
10+
11+ async function getPRetry ( ) {
12+ if ( ! pRetryModule ) {
13+ pRetryModule = await import ( "p-retry" ) ;
14+ }
15+ return pRetryModule . default ;
16+ }
17+
618const STATUS_NO_RETRY = [
719 400 , // Bad Request
820 401 , // Unauthorized
@@ -103,10 +115,11 @@ export class AsyncCaller {
103115 }
104116
105117 // eslint-disable-next-line @typescript-eslint/no-explicit-any
106- call < A extends any [ ] , T extends ( ...args : A ) => Promise < any > > (
118+ async call < A extends any [ ] , T extends ( ...args : A ) => Promise < any > > (
107119 callable : T ,
108120 ...args : Parameters < T >
109121 ) : Promise < Awaited < ReturnType < T > > > {
122+ const pRetry = await getPRetry ( ) ;
110123 return this . queue . add (
111124 ( ) =>
112125 pRetry (
You can’t perform that action at this time.
0 commit comments