diff --git a/libs/sdk-js/package.json b/libs/sdk-js/package.json index 3ef62b80d..26406d2df 100644 --- a/libs/sdk-js/package.json +++ b/libs/sdk-js/package.json @@ -1,6 +1,6 @@ { "name": "@langchain/langgraph-sdk", - "version": "0.0.1-rc.13", + "version": "0.0.1-rc.14", "description": "Client library for interacting with the LangGraph API", "type": "module", "packageManager": "yarn@1.22.19", diff --git a/libs/sdk-js/src/utils/async_caller.mts b/libs/sdk-js/src/utils/async_caller.mts index 1774b9609..3658b85a1 100644 --- a/libs/sdk-js/src/utils/async_caller.mts +++ b/libs/sdk-js/src/utils/async_caller.mts @@ -31,6 +31,13 @@ export interface AsyncCallerParams { maxRetries?: number; onFailedResponseHook?: ResponseCallback; + + /** + * Specify a custom fetch implementation. + * + * By default we expect the `fetch` is available in the global scope. + */ + fetch?: typeof fetch; } export interface AsyncCallerCallOptions { @@ -104,6 +111,8 @@ export class AsyncCaller { private onFailedResponseHook?: ResponseCallback; + private customFetch?: typeof fetch; + constructor(params: AsyncCallerParams) { this.maxConcurrency = params.maxConcurrency ?? Infinity; this.maxRetries = params.maxRetries ?? 4; @@ -118,6 +127,7 @@ export class AsyncCaller { this.queue = new (PQueueMod as any)({ concurrency: this.maxConcurrency }); } this.onFailedResponseHook = params?.onFailedResponseHook; + this.customFetch = params.fetch; } // eslint-disable-next-line @typescript-eslint/no-explicit-any @@ -199,8 +209,9 @@ export class AsyncCaller { } fetch(...args: Parameters): ReturnType { + const fetchFn = this.customFetch ?? fetch; return this.call(() => - fetch(...args).then((res) => (res.ok ? res : Promise.reject(res))), + fetchFn(...args).then((res) => (res.ok ? res : Promise.reject(res))), ); } }