Files
deer-flow/frontend/src/components/workspace/messages/context.ts
2026-01-18 17:13:15 +08:00

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;
}