/** iframe → parent RPC request */ interface RpcMessage { type: '__charx_rpc__'; iframeId: string; id?: string; method: string; args?: unknown[]; } /** parent → iframe RPC response */ interface RpcResponse { type: '__charx_rpc_response__'; iframeId: string; id: string; result: unknown; } /** parent → iframe push notification */ interface PushMessage { type: '__charx_push__'; iframeId?: string; event: string; data: unknown; } interface Message { id: string; role: 'user' | 'assistant' | 'system'; content: string; createdAt: number; tokenCount?: number; swipes?: string[]; activeSwipe?: number; variables?: Record; } interface SendOptions { onData?: (chunk: string) => void; onComplete?: (message: Message) => void; onError?: (error: Error) => void; onStart?: (payload: ChatStreamStartPayload) => void; model?: string; temperature?: number; injectedSystemPrompts?: string[]; timeoutMs?: number; requestId?: string; } /** Options for sdk.chat.generateRaw() — silent background LLM call */ interface GenerateRawOptions { /** Override the model for this call */ model?: string; temperature?: number; maxTokens?: number; /** * When true, prepend the character context (system prompt, worldbook, etc.) * from the current conversation. Defaults to true when conversationId is available. */ includeCharacterContext?: boolean; timeoutMs?: number; } /** A message passed to generateRaw() as part of the messages array */ interface GenerateRawMessage { role: 'system' | 'user' | 'assistant'; content: string; } interface ChatHistoryOptions { limit?: number; offset?: number; page?: number; pageSize?: number; } interface MessagesModule { list(params?: ChatHistoryOptions): Promise; getAll(): Promise; delete(id: string): Promise; edit(id: string, content: string): Promise; /** * @deprecated Compatibility placeholder only. * Current creator preview and web chat hosts may reject this call. * Prefer regenerate(), continue(), edit(), or explicit message state in variables. */ swipe(id: string, direction: 'left' | 'right'): Promise; } interface ChatStreamStartPayload { requestId?: string; userMessageId?: string | number; assistantMessageId?: string | number; } interface ChatStreamChunkPayload { requestId?: string; chunk: string; done: false; messageId?: string | number; assistantMessageId?: string | number; } interface ChatStreamDonePayload { requestId?: string; chunk: ''; done: true; messageId?: string | number; assistantMessageId?: string | number; fullContent?: string; interrupted?: boolean; } interface ChatErrorPayload { requestId?: string; message?: string; error?: string; code?: string; } type ChatStreamPayload = ChatStreamChunkPayload | ChatStreamDonePayload; interface ChatSendTask { requestId: string; done: Promise; stop(): Promise; } interface CharacterInfo { id: string | number; name: string; avatar?: string; displayIntro?: string; firstMes?: string; alternateGreetings?: string[]; tags?: string[]; creator?: string; version?: string | number; } interface PersonaInfo { id?: string | number; name?: string; avatar?: string; callName?: string; gender?: string; description?: string; } interface CharacterSettings { model?: string | null; } type VariableMap = Record; type Unsubscribe = () => void; interface ToastOptions { text: string; type?: 'success' | 'error' | 'warning' | 'info'; duration?: number; icon?: string; } /** ToastOptions 或可直接展示的简短文本值。 */ type ToastInput = ToastOptions | string | number | boolean; interface PanelOptions { url: string; title?: string; mode?: 'fullscreen' | 'sidebar' | 'modal'; width?: number | string; } /** PanelOptions 或扩展面板 URL 简写。 */ type PanelInput = PanelOptions | string; interface AlertOptions { message: string; title?: string; confirmText?: string; } /** AlertOptions 或提示文案简写。 */ type AlertInput = AlertOptions | string; interface ConfirmOptions { message: string; title?: string; confirmText?: string; cancelText?: string; } /** ConfirmOptions 或确认文案简写。 */ type ConfirmInput = ConfirmOptions | string; interface PromptOptions { message: string; title?: string; placeholder?: string; defaultValue?: string; } /** PromptOptions 或提示文案简写。 */ type PromptInput = PromptOptions | string; interface SpeakOptions { voice?: 'character' | 'system' | string; speed?: number; pitch?: number; } interface BgmOptions { loop?: boolean; volume?: number; fadeIn?: number; } interface BgmStopOptions { fadeOut?: number; } interface SfxOptions { volume?: number; } interface SaveSlot { slot: number; description?: string; savedAt: number; snapshot?: Record; } interface Achievement { id: string; name: string; description: string; unlockedAt?: number; } interface RankEntry { userId: string; username: string; score: number; rank: number; } interface WorldbookEntryState { entryKey: string; comment: string; /** The full text content of the entry — now included in getAll() response */ content: string; /** Trigger keywords for this entry */ keys: string[]; enabled: boolean; baseEnabled: boolean; isOverridden: boolean; constant: boolean; insertionOrder: number; } interface ConversationWorldbookResponse { conversationId: number; characterId: number; entries: WorldbookEntryState[]; totalCount: number; enabledCount: number; } type ChatStatus = 'idle' | 'sending' | 'streaming' | 'error'; interface UseChatReturn { messages: Message[]; status: ChatStatus; error: Error | null; currentRequestId: string | null; currentAssistantMessageId: string | null; send: (message: string, options?: SendOptions) => void; sendStream: (message: string, options?: SendOptions) => ChatSendTask; stop: () => Promise; regenerate: () => Promise; continue: () => Promise; deleteMessage: (id: string) => Promise; editMessage: (id: string, content: string) => Promise; /** * @deprecated Compatibility placeholder only. * Current creator preview and web chat hosts may reject this call. */ swipeMessage: (id: string, direction: 'left' | 'right') => Promise; generateRaw: (messages: GenerateRawMessage[], options?: GenerateRawOptions) => Promise; injectPrompt: (content: string) => Promise; insertSystemMessage: (content: string) => Promise; getConversationId: () => Promise; loadMore: () => Promise; hasMore: boolean; } export type { Achievement, AlertInput, AlertOptions, BgmOptions, BgmStopOptions, CharacterInfo, CharacterSettings, ChatErrorPayload, ChatHistoryOptions, ChatSendTask, ChatStatus, ChatStreamChunkPayload, ChatStreamDonePayload, ChatStreamPayload, ChatStreamStartPayload, ConfirmInput, ConfirmOptions, ConversationWorldbookResponse, GenerateRawMessage, GenerateRawOptions, Message, MessagesModule, PanelInput, PanelOptions, PersonaInfo, PromptInput, PromptOptions, PushMessage, RankEntry, RpcMessage, RpcResponse, SaveSlot, SendOptions, SfxOptions, SpeakOptions, ToastInput, ToastOptions, Unsubscribe, UseChatReturn, VariableMap, WorldbookEntryState };