/** * Chat event key enum — mirrors the SDK's ChatEventKey */ export declare enum ChatEventKey { READY = "ready", CLOSE = "close", SEND_PROMPT = "send-prompt", STREAMING_START = "streaming-start", STREAMING_STOP = "streaming-stop", REPORT = "report", NEW_CONVERSATION = "new-conversation", CHANGE_CONVERSATION = "change-conversation", ADD_ADDITION_CONTEXT = "add-addition-context", REMOVE_ADDITION_CONTEXT = "remove-addition-context", SKILL_SETTLED = "skill-settled", SKILL_REMOVED = "skill-removed", SHARE = "share" } /** * Message interface returned by SDK events */ export interface ChatMessage { id: string; conversationId: string; requestId: string; role: 'user' | 'assistant' | 'system' | 'error'; content: string; status: string; createdAt: string; updatedAt: string; attachments?: unknown[]; } /** * Conversation interface */ export interface ChatConversation { id: string; title: string; messages: ChatMessage[]; createdAt: string; updatedAt: string; } /** * ChatSDK 配置接口 */ export interface ChatSDKConfig { header: { logo?: string; title: string; }; empty: string; streamingTimeout: number; initialConversation: boolean; service: { agentId: string; baseURL: string; }; } /** * ChatSDK 实例接口 */ export interface ChatInstance { appendTo: (element: Element | null) => void; show: (element: HTMLElement) => void; hide: () => void; dispose: () => Promise; getCurrentConversation: () => Promise; sendUserPrompt: (prompt: string) => Promise; cancelRequest: () => Promise; on: (event: string, handler: (...args: any[]) => void) => void; off: (event: string, handler: (...args: any[]) => void) => void; } /** * ChatSDK 全局对象接口 */ export interface ChatSDK { init: (config: ChatSDKConfig) => Promise; ChatEventKey: Record | undefined; } /** * 悬浮按钮初始位置 */ export interface ButtonPosition { /** 距离视口右侧的距离(px) */ right?: number; /** 距离视口底部的距离(px) */ bottom?: number; } /** * Knot Agent Chat 组件 Props */ export type KnotAgentChatProps = { /** Knot Agent ID(必填),为空字符串时不渲染聊天组件,仅透传 slot */ agentId: string; /** 对话框标题 */ title?: string; /** Logo 图片地址 */ logo?: string; /** 空状态提示文本 */ empty?: string; /** 流式传输超时时间(秒) */ streamingTimeout?: number; /** 是否显示初始对话 */ initialConversation?: boolean; /** Knot API 基础地址 */ baseURL?: string; /** SDK 脚本地址 */ sdkURL?: string; /** 是否使用暗黑模式,不传则不自动设置 */ dark?: boolean; /** 悬浮按钮初始位置,默认 { right: 20, bottom: 20 } */ initialPosition?: ButtonPosition; /** 容器的 z-index 层级,默认 200 */ zIndex?: number; }; /** * Knot Agent Chat 组件 Emits */ export interface KnotAgentChatEmits { (e: 'ready' | 'close' | 'new-conversation'): void; (e: 'send-prompt', payload: { message: ChatMessage; }): void; (e: 'streaming-start' | 'streaming-stop', payload: { messages: ChatMessage[]; }): void; (e: 'report', payload: { data: unknown; }): void; (e: 'change-conversation', payload: ChatConversation | null): void; } /** * 扩展 Window 接口 */ declare global { interface Window { ChatSDK?: ChatSDK; } }