mirror of
https://gitee.com/wanwujie/deer-flow
synced 2026-04-28 00:04:47 +08:00
22 lines
565 B
TypeScript
22 lines
565 B
TypeScript
import type { UseStream } from "@langchain/langgraph-sdk/react";
|
|
import { createContext, useContext } from "react";
|
|
|
|
import type { AgentThreadState } from "@/core/threads";
|
|
|
|
export interface ThreadContextType {
|
|
threadId: string;
|
|
thread: UseStream<AgentThreadState>;
|
|
}
|
|
|
|
export const ThreadContext = createContext<ThreadContextType | undefined>(
|
|
undefined,
|
|
);
|
|
|
|
export function useThread() {
|
|
const context = useContext(ThreadContext);
|
|
if (context === undefined) {
|
|
throw new Error("useThread must be used within a ThreadContext");
|
|
}
|
|
return context;
|
|
}
|