export type WidgetPosition = "bottom-right" | "bottom-left"; export type ChatWidgetDisplayMode = "widget" | "embedded"; export type ChatWidgetTheme = { accent: string; accentSoft: string; panelBackground: string; surfaceBackground: string; text: string; mutedText: string; borderColor: string; shadow: string; zIndex: number; fontFamily: string; }; export type UserInfo = { firstName?: string; lastName?: string; avatar?: string; }; export type KnowledgeRagConfig = { chatId?: string; chatIdFactory?: () => string; knowledgeNames?: string[]; sourceUuid?: string; enableThink?: boolean; useStreaming?: boolean; getKnowledgeNames?: (() => Promise | string[] | null) | undefined; enableReferences?: boolean; loadHistoryOnOpen?: boolean; }; export type KnowledgeGraphViewMode = "2d" | "3d"; export type KnowledgeGraphNode = { id: string; label: string; type?: string | null; description?: string | null; sourceCount?: number | null; degree?: number | null; weight?: number | null; color?: string | null; size?: number | null; metadata?: Record | null; }; export type KnowledgeGraphEdge = { id: string; source: string; target: string; label?: string | null; weight?: number | null; color?: string | null; metadata?: Record | null; }; export type KnowledgeGraphResponse = { kgStatus: "not_yet_started" | "processing" | "ready" | "failed" | "disabled"; nodes: KnowledgeGraphNode[]; edges: KnowledgeGraphEdge[]; nodeCount: number; edgeCount: number; isTruncated: boolean; sourceDocumentUuid: string; raw?: unknown; }; export type KnowledgeGraphConfig = { enabled?: boolean; documentUuid?: string; documentUuidFactory?: () => string | null | undefined; maxNodes?: number; maxEdges?: number; defaultViewMode?: KnowledgeGraphViewMode; title?: string; }; export type RagCitation = { id?: string | null; documentUuid?: string | null; documentName?: string | null; score?: number | null; pageNumber?: number | null; sheetName?: string | null; rowNumber?: number | null; text?: string | null; }; export type CitationClickEvent = RagCitation & { documentId: string; pageNumber: number; text: string; }; export type SendMessageRequest = { message: string; chatId: string; knowledgeNames: string[]; editLastQa?: boolean; enableReferences?: boolean; }; export type SendMessageResponse = { chatId: string; answer: string; suggestions?: string[]; citations?: RagCitation[]; }; export type StreamMessageChunk = ({ type: "answer"; content: string; } | { type: "references"; content: { citations?: RagCitation[]; }; } | { type: "metadata"; content?: unknown; } | { type: string; content?: unknown; }) & { modelName?: string | null; model_name?: string | null; messageId?: string | null; message_id?: string | null; userMessageId?: string | null; user_message_id?: string | null; assistantMessageId?: string | null; assistant_message_id?: string | null; }; export type StreamMessageHandlers = { signal?: AbortSignal; onAnswer: (content: string) => void; onReferences?: (citations: RagCitation[]) => void; onChunk?: (chunk: StreamMessageChunk) => void; }; export type ChatHistoryMessage = { messageId?: string | null; role: "user" | "assistant"; text: string; citations?: RagCitation[]; isLike?: boolean | null; }; export type ChatListItem = { chatId: string; title: string; pinned?: boolean; createdAt?: string; updatedAt?: string; }; export type ChatWidgetEndpoints = { ask: string; askStream?: string; history?: string; listChats?: string; createChat?: string; updateChat?: string; deleteChat?: string; deleteLastQa?: string; feedback?: string; upload?: string; index?: string; docs?: string; knowledgeGraph?: string; }; export type ChatWidgetConfig = { apiBaseUrl: string; endpoints?: Partial; mount?: HTMLElement; displayMode?: ChatWidgetDisplayMode; position?: WidgetPosition; title?: string; subtitle?: string; welcomeMessage?: string; inputPlaceholder?: string; launcherAriaLabel?: string; closeAriaLabel?: string; theme?: Partial; initialSuggestions?: string[]; sourceApp?: string; locale?: string; customHeaders?: Record; rag?: KnowledgeRagConfig; knowledgeGraph?: KnowledgeGraphConfig; getAccessToken?: () => Promise | string | null; userInfo?: () => Promise | UserInfo | null; onOpen?: () => void; onClose?: () => void; onError?: (error: Error) => void; onOpenAssistantPage?: () => Promise | void; onCitationClick?: (event: CitationClickEvent) => Promise | void; assistantPageUrl?: string; assistantAvatarUrl?: string; embedded?: { showHeader?: boolean; }; }; export type ChatWidgetInstance = { open: () => void; close: () => void; toggle: () => void; destroy: () => void; sendMessage: (message: string) => Promise; setAccessTokenProvider: (provider: ChatWidgetConfig["getAccessToken"]) => void; getChatId: () => string; loadChats: () => Promise; loadHistory: () => Promise; }; export type ResolvedChatWidgetConfig = Omit>, never> & { endpoints: ChatWidgetEndpoints; mount: HTMLElement; theme: ChatWidgetTheme; getAccessToken?: ChatWidgetConfig["getAccessToken"]; userInfo?: ChatWidgetConfig["userInfo"]; onOpen?: ChatWidgetConfig["onOpen"]; onClose?: ChatWidgetConfig["onClose"]; onError?: ChatWidgetConfig["onError"]; onOpenAssistantPage?: ChatWidgetConfig["onOpenAssistantPage"]; onCitationClick?: ChatWidgetConfig["onCitationClick"]; }; export type BrowserGlobal = { init: (config: ChatWidgetConfig) => ChatWidgetInstance; createChatWidget: (config: ChatWidgetConfig) => ChatWidgetInstance; version: string; };