mirror of
https://github.com/langchain-ai/langgraph.git
synced 2026-08-25 00:52:25 +02:00
Add joinStream method
This commit is contained in:
@@ -604,6 +604,11 @@ export interface UseStream<
|
||||
* The ID of the assistant to use.
|
||||
*/
|
||||
assistantId: string;
|
||||
|
||||
/**
|
||||
* Join an active stream.
|
||||
*/
|
||||
joinStream: (runId: string) => Promise<void>;
|
||||
}
|
||||
|
||||
type ConfigWithConfigurable<ConfigurableType extends Record<string, unknown>> =
|
||||
@@ -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,
|
||||
|
||||
|
||||
Reference in New Issue
Block a user