51 lines
1.7 KiB
TypeScript
51 lines
1.7 KiB
TypeScript
import type { BaseStream } from "@langchain/langgraph-sdk/react";
|
|
import { createContext, useContext } from "react";
|
|
|
|
import type { RuntimeDisplaySource } from "@/core/skill-display/runtime";
|
|
import type { AgentThreadState } from "@/core/threads";
|
|
|
|
export interface ThreadContextType {
|
|
thread: BaseStream<AgentThreadState>;
|
|
isMock?: boolean;
|
|
/**
|
|
* True when the active conversation has selected LLMWiki knowledge bases.
|
|
* Knowledge-base Q&A should always expose its source documents, independent
|
|
* from the admin-controlled manual reference-mode button.
|
|
*/
|
|
knowledgeReferencesEnabled?: boolean;
|
|
/**
|
|
* When set, the conversation is rendered from a public read-only share.
|
|
* Artifact/image URLs then resolve to the unauthenticated
|
|
* `/api/public/shares/{code}/files/...` endpoint instead of the
|
|
* auth-gated thread artifact route.
|
|
*/
|
|
publicShareCode?: string;
|
|
}
|
|
|
|
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;
|
|
}
|
|
|
|
/**
|
|
* One turn's reference sources, keyed to the assistant message that answered
|
|
* the turn. Provided by ChatBox so inline citation rendering and the
|
|
* right-side reference panel always resolve `[n]` against the SAME sources
|
|
* (the panel prefers backend reference batches, which the per-message
|
|
* frontend collection in MessageList knows nothing about).
|
|
*/
|
|
export interface ReferenceBatch {
|
|
id: string;
|
|
assistant_message_id?: string;
|
|
sources: RuntimeDisplaySource[];
|
|
}
|
|
|
|
export const ReferenceBatchesContext = createContext<ReferenceBatch[]>([]);
|