mirror of
https://github.com/langchain-ai/langgraph.git
synced 2026-09-09 11:17:53 +02:00
feat(js): add ability to specify custom fetch (#783)
* feat(js): add ability to specify custom fetch * Bump to 0.0.1-rc.14 * Fix format
This commit is contained in:
@@ -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",
|
||||
|
||||
@@ -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<typeof fetch>): ReturnType<typeof fetch> {
|
||||
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))),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user