From 1ff5e2966b7000bc1f8fa2bebfc432fd9cc7dce0 Mon Sep 17 00:00:00 2001 From: Tat Dat Duong Date: Thu, 22 May 2025 19:07:01 +0200 Subject: [PATCH] Add joinStream method --- libs/sdk-js/src/react/stream.tsx | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/libs/sdk-js/src/react/stream.tsx b/libs/sdk-js/src/react/stream.tsx index cb3e5f3bf..ba65c50c9 100644 --- a/libs/sdk-js/src/react/stream.tsx +++ b/libs/sdk-js/src/react/stream.tsx @@ -604,6 +604,11 @@ export interface UseStream< * The ID of the assistant to use. */ assistantId: string; + + /** + * Join an active stream. + */ + joinStream: (runId: string) => Promise; } type ConfigWithConfigurable> = @@ -933,10 +938,8 @@ export function useStream< } } - const joinStream = async ( - runId: string, - lastEventId: (string & {}) | "-1", - ) => { + const joinStream = async (runId: string, lastEventId?: string) => { + lastEventId ??= "-1"; if (!threadId) return; await consumeStream(async (signal: AbortSignal) => { const stream = client.runs.joinStream(threadId, runId, { @@ -1069,7 +1072,7 @@ export function useStream< useEffect(() => { if (reconnectKey && reconnectRef.current.shouldReconnect) { reconnectRef.current.shouldReconnect = false; - joinStreamRef.current?.(reconnectKey.runId, "-1"); + joinStreamRef.current?.(reconnectKey.runId); } }, [reconnectKey]); @@ -1091,6 +1094,8 @@ export function useStream< stop, submit, + joinStream, + branch, setBranch,