diff --git a/libs/sdk-js/package.json b/libs/sdk-js/package.json index 758bced7f..3ead8faaa 100644 --- a/libs/sdk-js/package.json +++ b/libs/sdk-js/package.json @@ -1,6 +1,6 @@ { "name": "@langchain/langgraph-sdk", - "version": "0.0.86", + "version": "0.0.87", "description": "Client library for interacting with the LangGraph API", "type": "module", "packageManager": "yarn@1.22.19", diff --git a/libs/sdk-js/src/client.ts b/libs/sdk-js/src/client.ts index eb9a804f3..b2f1efc1d 100644 --- a/libs/sdk-js/src/client.ts +++ b/libs/sdk-js/src/client.ts @@ -1658,7 +1658,30 @@ export class Client< */ public "~ui": UiClient; + /** + * @internal Used to obtain a stable key representing the client. + */ + private "~configHash": string | undefined; + constructor(config?: ClientConfig) { + this["~configHash"] = (() => + JSON.stringify({ + apiUrl: config?.apiUrl, + apiKey: config?.apiKey, + timeoutMs: config?.timeoutMs, + defaultHeaders: config?.defaultHeaders, + + maxConcurrency: config?.callerOptions?.maxConcurrency, + maxRetries: config?.callerOptions?.maxRetries, + + callbacks: { + onFailedResponseHook: + config?.callerOptions?.onFailedResponseHook != null, + onRequest: config?.onRequest != null, + fetch: config?.callerOptions?.fetch != null, + }, + }))(); + this.assistants = new AssistantsClient(config); this.threads = new ThreadsClient(config); this.runs = new RunsClient(config); @@ -1667,3 +1690,10 @@ export class Client< this["~ui"] = new UiClient(config); } } + +/** + * @internal Used to obtain a stable key representing the client. + */ +export function getClientConfigHash(client: Client): string | undefined { + return client["~configHash"]; +} diff --git a/libs/sdk-js/src/react/stream.tsx b/libs/sdk-js/src/react/stream.tsx index 88a541f9a..8ac73ca9e 100644 --- a/libs/sdk-js/src/react/stream.tsx +++ b/libs/sdk-js/src/react/stream.tsx @@ -1,7 +1,7 @@ /* __LC_ALLOW_ENTRYPOINT_SIDE_EFFECTS__ */ "use client"; -import { Client, type ClientConfig } from "../client.js"; +import { Client, getClientConfigHash, type ClientConfig } from "../client.js"; import type { Command, DisconnectMode, @@ -321,11 +321,16 @@ function useThreadHistory>( ) { const [history, setHistory] = useState[]>([]); + const clientHash = getClientConfigHash(client); + const clientRef = useRef(client); + clientRef.current = client; + const fetcher = useCallback( ( threadId: string | undefined | null, ): Promise[]> => { if (threadId != null) { + const client = clientRef.current; return fetchHistory(client, threadId).then((history) => { setHistory(history); return history; @@ -342,7 +347,7 @@ function useThreadHistory>( useEffect(() => { if (submittingRef.current) return; fetcher(threadId); - }, [fetcher, submittingRef, threadId]); + }, [fetcher, clientHash, submittingRef, threadId]); return { data: history,