From 77a3cffa7fbb4c167551d11bf9c3f2c7999ffc26 Mon Sep 17 00:00:00 2001 From: Tat Dat Duong Date: Wed, 12 Feb 2025 08:50:01 -0800 Subject: [PATCH] Allow omitting client --- libs/sdk-js/src/react/stream.tsx | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/libs/sdk-js/src/react/stream.tsx b/libs/sdk-js/src/react/stream.tsx index a8df9e626..01a7811be 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 } from "../client.js"; +import { Client, ClientConfig } from "../client.js"; import type { Command, DisconnectMode, @@ -185,7 +185,12 @@ export function useStream< CustomType = unknown, >(options: { assistantId: string; - client: Client; + + apiUrl: ClientConfig["apiUrl"]; + apiKey?: ClientConfig["apiKey"]; + callerOptions?: ClientConfig["callerOptions"]; + timeoutMs?: ClientConfig["timeoutMs"]; + defaultHeaders?: ClientConfig["defaultHeaders"]; withMessages?: string; @@ -208,8 +213,17 @@ export function useStream< | ErrorStreamEvent | FeedbackStreamEvent; - const { assistantId, threadId, client, withMessages, onError, onFinish } = - options; + const { assistantId, threadId, withMessages, onError, onFinish } = options; + const [client] = useState( + () => + new Client({ + apiUrl: options.apiUrl, + apiKey: options.apiKey, + callerOptions: options.callerOptions, + timeoutMs: options.timeoutMs, + defaultHeaders: options.defaultHeaders, + }), + ); if (client == null) { throw new Error(