23 lines
585 B
TypeScript
23 lines
585 B
TypeScript
import type { UseStream } from "@langchain/langgraph-sdk/react";
|
|
import { createContext, useContext } from "react";
|
|
|
|
import type { AgentThreadState } from "@/core/threads";
|
|
|
|
export interface ThreadContextType {
|
|
thread: UseStream<AgentThreadState>;
|
|
threadId: string;
|
|
isMock?: boolean;
|
|
}
|
|
|
|
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;
|
|
}
|