@charivo/core 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +291 -0
- package/dist/index.cjs +338 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +292 -0
- package/dist/index.d.ts +292 -0
- package/dist/index.js +331 -0
- package/dist/index.js.map +1 -0
- package/package.json +46 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/bus.ts","../src/types.ts","../src/emotion-parser.ts","../src/index.ts"],"names":["Emotion"],"mappings":";;;AAEO,IAAM,WAAN,MAAe;AAAA,EACZ,SAAA,uBACF,GAAA,EAAI;AAAA,EAEV,EAAA,CACE,OACA,QAAA,EACM;AACN,IAAA,IAAI,CAAC,IAAA,CAAK,SAAA,CAAU,GAAA,CAAI,KAAK,CAAA,EAAG;AAC9B,MAAA,IAAA,CAAK,SAAA,CAAU,GAAA,CAAI,KAAA,EAAO,EAAE,CAAA;AAAA,IAC9B;AACA,IAAA,IAAA,CAAK,SAAA,CAAU,GAAA,CAAI,KAAK,CAAA,CAAG,KAAK,QAAQ,CAAA;AAAA,EAC1C;AAAA,EAEA,IAAA,CAA+B,OAAU,IAAA,EAAyB;AAChE,IAAA,MAAM,cAAA,GAAiB,IAAA,CAAK,SAAA,CAAU,GAAA,CAAI,KAAK,CAAA;AAC/C,IAAA,IAAI,cAAA,EAAgB;AAClB,MAAA,cAAA,CAAe,OAAA,CAAQ,CAAC,QAAA,KAAa,QAAA,CAAS,IAAI,CAAC,CAAA;AAAA,IACrD;AAAA,EACF;AAAA,EAEA,GAAA,CACE,OACA,QAAA,EACM;AACN,IAAA,MAAM,cAAA,GAAiB,IAAA,CAAK,SAAA,CAAU,GAAA,CAAI,KAAK,CAAA;AAC/C,IAAA,IAAI,cAAA,EAAgB;AAClB,MAAA,MAAM,KAAA,GAAQ,cAAA,CAAe,OAAA,CAAQ,QAAQ,CAAA;AAC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A,IAAa,IAAA;AAAA,EAC3B;AAAA;AAAA;AAAA;AAAA,EAKA,EAAA,CACE,OACA,QAAA,EACM;AACN,IAAA,IAAA,CAAK,QAAA,CAAS,EAAA,CAAG,KAAA,EAAO,QAAQ,CAAA;AAAA,EAClC;AAAA;AAAA;AAAA;AAAA,EAKA,IAAA,CACE,OACA,IAAA,EACM;AACN,IAAA,IAAA,CAAK,QAAA,CAAS,IAAA,CAAK,KAAA,EAAO,IAAI,CAAA;AAAA,EAChC;AACF","file":"index.cjs","sourcesContent":["import { EventMap } from \"./types\";\n\nexport class EventBus {\n private listeners: Map<keyof EventMap, Array<(data: any) => void>> =\n new Map();\n\n on<K extends keyof EventMap>(\n event: K,\n listener: (data: EventMap[K]) => void,\n ): void {\n if (!this.listeners.has(event)) {\n this.listeners.set(event, []);\n }\n this.listeners.get(event)!.push(listener);\n }\n\n emit<K extends keyof EventMap>(event: K, data: EventMap[K]): void {\n const eventListeners = this.listeners.get(event);\n if (eventListeners) {\n eventListeners.forEach((listener) => listener(data));\n }\n }\n\n off<K extends keyof EventMap>(\n event: K,\n listener: (data: EventMap[K]) => void,\n ): void {\n const eventListeners = this.listeners.get(event);\n if (eventListeners) {\n const index = eventListeners.indexOf(listener);\n if (index > -1) {\n eventListeners.splice(index, 1);\n }\n }\n }\n\n clear(): void {\n this.listeners.clear();\n }\n}\n","/**\n * Standard emotion types for character expressions\n */\nexport enum Emotion {\n NEUTRAL = \"neutral\",\n HAPPY = \"happy\",\n SAD = \"sad\",\n ANGRY = \"angry\",\n SURPRISED = \"surprised\",\n THINKING = \"thinking\",\n EXCITED = \"excited\",\n SHY = \"shy\",\n}\n\n/**\n * Mapping between emotion and Live2D model animations\n */\nexport interface EmotionMapping {\n emotion: Emotion;\n expression?: string; // Live2D expression ID (e.g., \"smile\", \"angry\")\n motion?: {\n group: string; // Live2D motion group (e.g., \"Idle\", \"TapBody\")\n index?: number; // Motion index within group\n };\n}\n\nexport interface Character {\n id: string;\n name: string;\n description?: string;\n personality?: string;\n avatar?: string;\n voice?: {\n voiceId?: string;\n rate?: number;\n pitch?: number;\n volume?: number;\n };\n /**\n * Custom emotion mappings for this character's Live2D model\n * If not specified, default mappings will be used\n */\n emotionMappings?: EmotionMapping[];\n}\n\nexport interface Message {\n id: string;\n content: string;\n timestamp: Date;\n characterId?: string;\n type: \"user\" | \"character\" | \"system\";\n /**\n * Parsed emotion from message content (if any)\n */\n emotion?: Emotion;\n}\n\nexport interface Conversation {\n id: string;\n messages: Message[];\n characterId?: string;\n createdAt: Date;\n updatedAt: Date;\n}\n\nexport interface Plugin {\n id: string;\n name: string;\n version: string;\n enabled: boolean;\n}\n\nexport interface CharivoConfig {\n characters: Character[];\n plugins: Plugin[];\n llmProvider?: string;\n renderProvider?: string;\n}\n\nexport interface LLMAdapter {\n generateResponse(message: Message): Promise<string>;\n setCharacter(character: Character): void;\n clearHistory(): void;\n}\n\n// LLM 제공자 (서버사이드에서 LLM 응답 생성)\nexport interface LLMProvider {\n generateResponse(\n messages: Array<{ role: string; content: string }>,\n ): Promise<string>;\n}\n\n// 단순한 LLM 호출 클라이언트 (stateless)\nexport interface LLMClient {\n call(messages: Array<{ role: string; content: string }>): Promise<string>;\n}\n\n// LLM 매니저 (세션 관리, 히스토리, 캐릭터 관리)\nexport interface LLMManager {\n setCharacter(character: Character): void;\n getCharacter(): Character | null;\n clearHistory(): void;\n getHistory(): Message[];\n generateResponse(message: Message): Promise<string>;\n}\n\n// Renderer 인터페이스 (stateless renderer)\nexport interface Renderer {\n initialize(): Promise<void>;\n destroy(): Promise<void>;\n render(message: Message, character?: Character): Promise<void>;\n loadModel?(modelPath: string): Promise<void>;\n setRealtimeLipSync?(enabled: boolean): void;\n updateRealtimeLipSyncRms?(rms: number): void;\n}\n\n// Render 매니저 (세션 관리, 립싱크, 모션 제어)\nexport interface RenderManager {\n initialize(): Promise<void>;\n destroy(): Promise<void>;\n setCharacter(character: Character): void;\n render(message: Message, character?: Character): Promise<void>;\n loadModel?(modelPath: string): Promise<void>;\n setMessageCallback?(\n callback: (message: Message, character?: Character) => void,\n ): void;\n}\n\nexport interface TTSOptions {\n rate?: number;\n pitch?: number;\n volume?: number;\n voice?: string;\n}\n\n// TTS 플레이어 (브라우저에서 음성 재생)\nexport interface TTSPlayer {\n speak(text: string, options?: TTSOptions): Promise<void>;\n stop(): Promise<void>;\n setVoice(voice: string): void;\n isSupported(): boolean;\n // Stateless audio generation (optional)\n generateAudio?(text: string, options?: TTSOptions): Promise<ArrayBuffer>;\n}\n\n// TTS 제공자 (오디오 데이터 생성)\nexport interface TTSProvider {\n generateSpeech(text: string, options?: TTSOptions): Promise<ArrayBuffer>;\n setVoice(voice: string): void;\n}\n\n// TTS Manager - TTS 세션의 상태 관리를 담당하는 인터페이스\nexport interface TTSManager {\n speak(text: string, options?: TTSOptions): Promise<void>;\n stop(): Promise<void>;\n setVoice(voice: string): void;\n isSupported(): boolean;\n setEventEmitter?(eventEmitter: {\n emit: (event: string, data: any) => void;\n }): void;\n}\n\nexport type EventMap = {\n \"message:sent\": { message: Message };\n \"message:received\": { message: Message };\n \"character:speak\": { character: Character; message: string };\n \"tts:start\": { text: string; characterId?: string };\n \"tts:end\": { characterId?: string };\n \"tts:error\": { error: Error };\n \"tts:audio:start\": { audioElement: HTMLAudioElement; characterId?: string };\n \"tts:audio:end\": { characterId?: string };\n \"tts:lipsync:update\": { rms: number; characterId?: string };\n error: { error: Error };\n};\n","import { Emotion } from \"./types\";\n\n/**\n * Result of parsing emotion tags from text\n */\nexport interface ParsedEmotion {\n /** The cleaned text with emotion tags removed */\n text: string;\n /** The detected emotion (if any) */\n emotion?: Emotion;\n}\n\n/**\n * Regular expression to match emotion tags in format [emotion] or [EMOTION]\n * Examples: [happy], [HAPPY], [sad]\n */\nconst EMOTION_TAG_REGEX = /\\[([a-zA-Z]+)\\]/g;\n\n/**\n * Map of emotion keywords to standard Emotion enum\n * Supports various aliases and common variations\n */\nconst EMOTION_KEYWORD_MAP: Record<string, Emotion> = {\n // Neutral\n neutral: Emotion.NEUTRAL,\n normal: Emotion.NEUTRAL,\n calm: Emotion.NEUTRAL,\n\n // Happy\n happy: Emotion.HAPPY,\n joy: Emotion.HAPPY,\n joyful: Emotion.HAPPY,\n cheerful: Emotion.HAPPY,\n smile: Emotion.HAPPY,\n\n // Sad\n sad: Emotion.SAD,\n unhappy: Emotion.SAD,\n depressed: Emotion.SAD,\n down: Emotion.SAD,\n cry: Emotion.SAD,\n\n // Angry\n angry: Emotion.ANGRY,\n mad: Emotion.ANGRY,\n furious: Emotion.ANGRY,\n annoyed: Emotion.ANGRY,\n\n // Surprised\n surprised: Emotion.SURPRISED,\n shock: Emotion.SURPRISED,\n shocked: Emotion.SURPRISED,\n amazed: Emotion.SURPRISED,\n wow: Emotion.SURPRISED,\n\n // Thinking\n thinking: Emotion.THINKING,\n wonder: Emotion.THINKING,\n curious: Emotion.THINKING,\n hmm: Emotion.THINKING,\n\n // Excited\n excited: Emotion.EXCITED,\n energetic: Emotion.EXCITED,\n hyper: Emotion.EXCITED,\n enthusiastic: Emotion.EXCITED,\n\n // Shy\n shy: Emotion.SHY,\n embarrassed: Emotion.SHY,\n blush: Emotion.SHY,\n timid: Emotion.SHY,\n};\n\n/**\n * Parse emotion tags from text and return cleaned text with detected emotion\n *\n * @param text - The text containing potential emotion tags (e.g., \"Hello! [happy] How are you?\")\n * @returns ParsedEmotion object with cleaned text and detected emotion\n *\n * @example\n * ```typescript\n * parseEmotion(\"Hello! [happy] Nice to meet you!\")\n * // Returns: { text: \"Hello! Nice to meet you!\", emotion: Emotion.HAPPY }\n *\n * parseEmotion(\"I'm feeling [sad] today...\")\n * // Returns: { text: \"I'm feeling today...\", emotion: Emotion.SAD }\n *\n * parseEmotion(\"Just a normal message\")\n * // Returns: { text: \"Just a normal message\", emotion: undefined }\n * ```\n */\nexport function parseEmotion(text: string): ParsedEmotion {\n let detectedEmotion: Emotion | undefined;\n let cleanedText = text;\n\n // Find all emotion tags\n const matches = Array.from(text.matchAll(EMOTION_TAG_REGEX));\n\n // Process each match (use the last one if multiple)\n for (const match of matches) {\n const keyword = match[1].toLowerCase();\n const emotion = EMOTION_KEYWORD_MAP[keyword];\n\n if (emotion) {\n detectedEmotion = emotion;\n } else {\n console.warn(`⚠️ [Emotion] Unknown keyword: [${match[1]}]`);\n }\n\n // Remove the tag from text\n cleanedText = cleanedText.replace(match[0], \"\");\n }\n\n // Clean up extra spaces\n cleanedText = cleanedText.replace(/\\s+/g, \" \").trim();\n\n if (detectedEmotion) {\n console.log(`🎭 [Emotion] ${detectedEmotion} → \"${cleanedText}\"`);\n }\n\n return {\n text: cleanedText,\n emotion: detectedEmotion,\n };\n}\n\n/**\n * Check if text contains any emotion tags\n *\n * @param text - The text to check\n * @returns true if text contains emotion tags\n */\nexport function hasEmotionTag(text: string): boolean {\n return EMOTION_TAG_REGEX.test(text);\n}\n\n/**\n * Get all supported emotion keywords\n *\n * @returns Array of supported emotion keywords\n */\nexport function getSupportedEmotionKeywords(): string[] {\n return Object.keys(EMOTION_KEYWORD_MAP);\n}\n","import { EventBus } from \"./bus\";\nimport {\n Character,\n Message,\n RenderManager,\n TTSManager,\n LLMManager,\n} from \"./types\";\nimport { parseEmotion } from \"./emotion-parser\";\n\nexport * from \"./types\";\nexport * from \"./bus\";\nexport * from \"./emotion-parser\";\n\nexport class Charivo {\n private eventBus: EventBus;\n private llmManager?: LLMManager;\n private renderManager?: RenderManager;\n private ttsManager?: TTSManager;\n private character?: Character;\n\n constructor() {\n this.eventBus = new EventBus();\n }\n\n /**\n * Attach a render manager to handle character visualization.\n * Automatically connects the event bus and sets the current character if available.\n */\n attachRenderer(renderManager: RenderManager): void {\n console.log(\n \"🎭 Charivo: Attaching render manager\",\n renderManager.constructor.name,\n );\n this.renderManager = renderManager;\n\n this.connectRenderManagerEventBus(renderManager);\n\n // Set character if it was already configured\n if (this.character) {\n renderManager.setCharacter(this.character);\n }\n }\n\n /**\n * Connects the render manager to the event bus for bidirectional communication.\n */\n private connectRenderManagerEventBus(renderManager: RenderManager): void {\n if (\n \"setEventBus\" in renderManager &&\n typeof renderManager.setEventBus === \"function\"\n ) {\n console.log(\n \"🔗 Charivo: ✅ Render manager supports event bus - connecting\",\n );\n (renderManager as any).setEventBus({\n on: (event: string, callback: (...args: any[]) => void) => {\n console.log(\n `🔗 Charivo: Render manager subscribing to event: ${event}`,\n );\n this.eventBus.on(event as any, callback as any);\n },\n emit: (event: string, data: any) => {\n console.log(\n `🔗 Charivo: Render manager emitting event: ${event}`,\n data,\n );\n this.eventBus.emit(event as any, data);\n },\n });\n console.log(\"🔗 Charivo: Event bus connection completed\");\n } else {\n console.warn(\n \"⚠️ Charivo: Render manager doesn't support event bus connection\",\n {\n hasSetEventBus: \"setEventBus\" in renderManager,\n setEventBusType: typeof (renderManager as any).setEventBus,\n },\n );\n }\n }\n\n /**\n * Attach an LLM manager to handle conversation generation.\n * Automatically sets the current character if available.\n */\n attachLLM(manager: LLMManager): void {\n this.llmManager = manager;\n\n // Set character if it was already configured\n if (this.character) {\n manager.setCharacter(this.character);\n }\n }\n\n /**\n * Attach a TTS manager to handle voice synthesis.\n * Automatically connects the event emitter for audio events.\n */\n attachTTS(manager: TTSManager): void {\n console.log(\"🔊 Charivo: Attaching TTS manager\", manager.constructor.name);\n this.ttsManager = manager;\n\n this.connectTTSManagerEventEmitter(manager);\n }\n\n /**\n * Detach the TTS manager to disable voice synthesis.\n */\n detachTTS(): void {\n console.log(\"🔇 Charivo: Detaching TTS manager\");\n this.ttsManager = undefined;\n }\n\n /**\n * Connects the TTS manager to the event bus for audio event emission.\n */\n private connectTTSManagerEventEmitter(manager: TTSManager): void {\n if (manager.setEventEmitter) {\n console.log(\n \"🔗 Charivo: ✅ TTS manager supports event emitter - connecting\",\n );\n manager.setEventEmitter({\n emit: (event: string, data: any) => {\n console.log(`🎵 Charivo: ✅ TTS EMITTING EVENT: ${event}`, data);\n this.eventBus.emit(event as any, data);\n console.log(`🎵 Charivo: ✅ Event ${event} emitted to event bus`);\n },\n });\n console.log(\"🔗 Charivo: TTS Manager connection completed\");\n } else {\n console.warn(\"⚠️ Charivo: TTS manager doesn't support event emitter\", {\n managerType: manager.constructor.name,\n });\n }\n }\n\n /**\n * Set the character for this Charivo instance.\n * Automatically propagates to all attached managers (LLM, Renderer).\n */\n setCharacter(character: Character): void {\n this.character = character;\n\n if (this.llmManager) {\n this.llmManager.setCharacter(character);\n }\n\n if (this.renderManager) {\n this.renderManager.setCharacter(character);\n }\n }\n\n /**\n * Process a user message and generate a character response.\n * Orchestrates the full conversation flow: rendering, LLM generation, and TTS playback.\n */\n async userSay(content: string): Promise<void> {\n const userMessage: Message = {\n id: Date.now().toString(),\n content,\n timestamp: new Date(),\n type: \"user\",\n };\n\n this.eventBus.emit(\"message:sent\", { message: userMessage });\n\n // Render user message\n if (this.renderManager) {\n await this.renderManager.render(userMessage);\n }\n\n // Generate and render character response\n if (this.llmManager && this.character) {\n const response = await this.llmManager.generateResponse(userMessage);\n\n // Parse emotion tags from response\n const parsed = parseEmotion(response);\n\n const characterMessage: Message = {\n id: Date.now().toString() + \"_response\",\n content: parsed.text, // Use cleaned text without emotion tags\n timestamp: new Date(),\n characterId: this.character.id,\n type: \"character\",\n emotion: parsed.emotion, // Add parsed emotion\n };\n\n this.eventBus.emit(\"message:received\", { message: characterMessage });\n this.eventBus.emit(\"character:speak\", {\n character: this.character,\n message: parsed.text,\n });\n\n if (this.renderManager) {\n await this.renderManager.render(characterMessage, this.character);\n }\n\n // Play character voice with TTS (using cleaned text)\n if (this.ttsManager) {\n try {\n this.eventBus.emit(\"tts:start\", {\n text: parsed.text,\n characterId: this.character.id,\n });\n\n const ttsOptions = this.character.voice\n ? {\n rate: this.character.voice.rate,\n pitch: this.character.voice.pitch,\n volume: this.character.voice.volume,\n voice: this.character.voice.voiceId,\n }\n : undefined;\n\n await this.ttsManager.speak(parsed.text, ttsOptions);\n this.eventBus.emit(\"tts:end\", { characterId: this.character.id });\n } catch (error) {\n this.eventBus.emit(\"tts:error\", { error: error as Error });\n }\n }\n }\n }\n\n /**\n * Clear the conversation history from the LLM manager.\n */\n clearHistory(): void {\n if (this.llmManager) {\n this.llmManager.clearHistory();\n }\n }\n\n /**\n * Get the conversation history from the LLM manager.\n */\n getHistory(): Message[] {\n return this.llmManager ? this.llmManager.getHistory() : [];\n }\n\n /**\n * Get the currently configured character.\n */\n getCurrentCharacter(): Character | null {\n return this.character ?? null;\n }\n\n /**\n * Subscribe to events from the event bus.\n */\n on<K extends keyof import(\"./types\").EventMap>(\n event: K,\n listener: (data: import(\"./types\").EventMap[K]) => void,\n ): void {\n this.eventBus.on(event, listener);\n }\n\n /**\n * Emit events to the event bus.\n */\n emit<K extends keyof import(\"./types\").EventMap>(\n event: K,\n data: import(\"./types\").EventMap[K],\n ): void {\n this.eventBus.emit(event, data);\n }\n}\n"]}
|
package/dist/index.d.cts
ADDED
|
@@ -0,0 +1,292 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Standard emotion types for character expressions
|
|
3
|
+
*/
|
|
4
|
+
declare enum Emotion {
|
|
5
|
+
NEUTRAL = "neutral",
|
|
6
|
+
HAPPY = "happy",
|
|
7
|
+
SAD = "sad",
|
|
8
|
+
ANGRY = "angry",
|
|
9
|
+
SURPRISED = "surprised",
|
|
10
|
+
THINKING = "thinking",
|
|
11
|
+
EXCITED = "excited",
|
|
12
|
+
SHY = "shy"
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* Mapping between emotion and Live2D model animations
|
|
16
|
+
*/
|
|
17
|
+
interface EmotionMapping {
|
|
18
|
+
emotion: Emotion;
|
|
19
|
+
expression?: string;
|
|
20
|
+
motion?: {
|
|
21
|
+
group: string;
|
|
22
|
+
index?: number;
|
|
23
|
+
};
|
|
24
|
+
}
|
|
25
|
+
interface Character {
|
|
26
|
+
id: string;
|
|
27
|
+
name: string;
|
|
28
|
+
description?: string;
|
|
29
|
+
personality?: string;
|
|
30
|
+
avatar?: string;
|
|
31
|
+
voice?: {
|
|
32
|
+
voiceId?: string;
|
|
33
|
+
rate?: number;
|
|
34
|
+
pitch?: number;
|
|
35
|
+
volume?: number;
|
|
36
|
+
};
|
|
37
|
+
/**
|
|
38
|
+
* Custom emotion mappings for this character's Live2D model
|
|
39
|
+
* If not specified, default mappings will be used
|
|
40
|
+
*/
|
|
41
|
+
emotionMappings?: EmotionMapping[];
|
|
42
|
+
}
|
|
43
|
+
interface Message {
|
|
44
|
+
id: string;
|
|
45
|
+
content: string;
|
|
46
|
+
timestamp: Date;
|
|
47
|
+
characterId?: string;
|
|
48
|
+
type: "user" | "character" | "system";
|
|
49
|
+
/**
|
|
50
|
+
* Parsed emotion from message content (if any)
|
|
51
|
+
*/
|
|
52
|
+
emotion?: Emotion;
|
|
53
|
+
}
|
|
54
|
+
interface Conversation {
|
|
55
|
+
id: string;
|
|
56
|
+
messages: Message[];
|
|
57
|
+
characterId?: string;
|
|
58
|
+
createdAt: Date;
|
|
59
|
+
updatedAt: Date;
|
|
60
|
+
}
|
|
61
|
+
interface Plugin {
|
|
62
|
+
id: string;
|
|
63
|
+
name: string;
|
|
64
|
+
version: string;
|
|
65
|
+
enabled: boolean;
|
|
66
|
+
}
|
|
67
|
+
interface CharivoConfig {
|
|
68
|
+
characters: Character[];
|
|
69
|
+
plugins: Plugin[];
|
|
70
|
+
llmProvider?: string;
|
|
71
|
+
renderProvider?: string;
|
|
72
|
+
}
|
|
73
|
+
interface LLMAdapter {
|
|
74
|
+
generateResponse(message: Message): Promise<string>;
|
|
75
|
+
setCharacter(character: Character): void;
|
|
76
|
+
clearHistory(): void;
|
|
77
|
+
}
|
|
78
|
+
interface LLMProvider {
|
|
79
|
+
generateResponse(messages: Array<{
|
|
80
|
+
role: string;
|
|
81
|
+
content: string;
|
|
82
|
+
}>): Promise<string>;
|
|
83
|
+
}
|
|
84
|
+
interface LLMClient {
|
|
85
|
+
call(messages: Array<{
|
|
86
|
+
role: string;
|
|
87
|
+
content: string;
|
|
88
|
+
}>): Promise<string>;
|
|
89
|
+
}
|
|
90
|
+
interface LLMManager {
|
|
91
|
+
setCharacter(character: Character): void;
|
|
92
|
+
getCharacter(): Character | null;
|
|
93
|
+
clearHistory(): void;
|
|
94
|
+
getHistory(): Message[];
|
|
95
|
+
generateResponse(message: Message): Promise<string>;
|
|
96
|
+
}
|
|
97
|
+
interface Renderer {
|
|
98
|
+
initialize(): Promise<void>;
|
|
99
|
+
destroy(): Promise<void>;
|
|
100
|
+
render(message: Message, character?: Character): Promise<void>;
|
|
101
|
+
loadModel?(modelPath: string): Promise<void>;
|
|
102
|
+
setRealtimeLipSync?(enabled: boolean): void;
|
|
103
|
+
updateRealtimeLipSyncRms?(rms: number): void;
|
|
104
|
+
}
|
|
105
|
+
interface RenderManager {
|
|
106
|
+
initialize(): Promise<void>;
|
|
107
|
+
destroy(): Promise<void>;
|
|
108
|
+
setCharacter(character: Character): void;
|
|
109
|
+
render(message: Message, character?: Character): Promise<void>;
|
|
110
|
+
loadModel?(modelPath: string): Promise<void>;
|
|
111
|
+
setMessageCallback?(callback: (message: Message, character?: Character) => void): void;
|
|
112
|
+
}
|
|
113
|
+
interface TTSOptions {
|
|
114
|
+
rate?: number;
|
|
115
|
+
pitch?: number;
|
|
116
|
+
volume?: number;
|
|
117
|
+
voice?: string;
|
|
118
|
+
}
|
|
119
|
+
interface TTSPlayer {
|
|
120
|
+
speak(text: string, options?: TTSOptions): Promise<void>;
|
|
121
|
+
stop(): Promise<void>;
|
|
122
|
+
setVoice(voice: string): void;
|
|
123
|
+
isSupported(): boolean;
|
|
124
|
+
generateAudio?(text: string, options?: TTSOptions): Promise<ArrayBuffer>;
|
|
125
|
+
}
|
|
126
|
+
interface TTSProvider {
|
|
127
|
+
generateSpeech(text: string, options?: TTSOptions): Promise<ArrayBuffer>;
|
|
128
|
+
setVoice(voice: string): void;
|
|
129
|
+
}
|
|
130
|
+
interface TTSManager {
|
|
131
|
+
speak(text: string, options?: TTSOptions): Promise<void>;
|
|
132
|
+
stop(): Promise<void>;
|
|
133
|
+
setVoice(voice: string): void;
|
|
134
|
+
isSupported(): boolean;
|
|
135
|
+
setEventEmitter?(eventEmitter: {
|
|
136
|
+
emit: (event: string, data: any) => void;
|
|
137
|
+
}): void;
|
|
138
|
+
}
|
|
139
|
+
type EventMap = {
|
|
140
|
+
"message:sent": {
|
|
141
|
+
message: Message;
|
|
142
|
+
};
|
|
143
|
+
"message:received": {
|
|
144
|
+
message: Message;
|
|
145
|
+
};
|
|
146
|
+
"character:speak": {
|
|
147
|
+
character: Character;
|
|
148
|
+
message: string;
|
|
149
|
+
};
|
|
150
|
+
"tts:start": {
|
|
151
|
+
text: string;
|
|
152
|
+
characterId?: string;
|
|
153
|
+
};
|
|
154
|
+
"tts:end": {
|
|
155
|
+
characterId?: string;
|
|
156
|
+
};
|
|
157
|
+
"tts:error": {
|
|
158
|
+
error: Error;
|
|
159
|
+
};
|
|
160
|
+
"tts:audio:start": {
|
|
161
|
+
audioElement: HTMLAudioElement;
|
|
162
|
+
characterId?: string;
|
|
163
|
+
};
|
|
164
|
+
"tts:audio:end": {
|
|
165
|
+
characterId?: string;
|
|
166
|
+
};
|
|
167
|
+
"tts:lipsync:update": {
|
|
168
|
+
rms: number;
|
|
169
|
+
characterId?: string;
|
|
170
|
+
};
|
|
171
|
+
error: {
|
|
172
|
+
error: Error;
|
|
173
|
+
};
|
|
174
|
+
};
|
|
175
|
+
|
|
176
|
+
declare class EventBus {
|
|
177
|
+
private listeners;
|
|
178
|
+
on<K extends keyof EventMap>(event: K, listener: (data: EventMap[K]) => void): void;
|
|
179
|
+
emit<K extends keyof EventMap>(event: K, data: EventMap[K]): void;
|
|
180
|
+
off<K extends keyof EventMap>(event: K, listener: (data: EventMap[K]) => void): void;
|
|
181
|
+
clear(): void;
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
/**
|
|
185
|
+
* Result of parsing emotion tags from text
|
|
186
|
+
*/
|
|
187
|
+
interface ParsedEmotion {
|
|
188
|
+
/** The cleaned text with emotion tags removed */
|
|
189
|
+
text: string;
|
|
190
|
+
/** The detected emotion (if any) */
|
|
191
|
+
emotion?: Emotion;
|
|
192
|
+
}
|
|
193
|
+
/**
|
|
194
|
+
* Parse emotion tags from text and return cleaned text with detected emotion
|
|
195
|
+
*
|
|
196
|
+
* @param text - The text containing potential emotion tags (e.g., "Hello! [happy] How are you?")
|
|
197
|
+
* @returns ParsedEmotion object with cleaned text and detected emotion
|
|
198
|
+
*
|
|
199
|
+
* @example
|
|
200
|
+
* ```typescript
|
|
201
|
+
* parseEmotion("Hello! [happy] Nice to meet you!")
|
|
202
|
+
* // Returns: { text: "Hello! Nice to meet you!", emotion: Emotion.HAPPY }
|
|
203
|
+
*
|
|
204
|
+
* parseEmotion("I'm feeling [sad] today...")
|
|
205
|
+
* // Returns: { text: "I'm feeling today...", emotion: Emotion.SAD }
|
|
206
|
+
*
|
|
207
|
+
* parseEmotion("Just a normal message")
|
|
208
|
+
* // Returns: { text: "Just a normal message", emotion: undefined }
|
|
209
|
+
* ```
|
|
210
|
+
*/
|
|
211
|
+
declare function parseEmotion(text: string): ParsedEmotion;
|
|
212
|
+
/**
|
|
213
|
+
* Check if text contains any emotion tags
|
|
214
|
+
*
|
|
215
|
+
* @param text - The text to check
|
|
216
|
+
* @returns true if text contains emotion tags
|
|
217
|
+
*/
|
|
218
|
+
declare function hasEmotionTag(text: string): boolean;
|
|
219
|
+
/**
|
|
220
|
+
* Get all supported emotion keywords
|
|
221
|
+
*
|
|
222
|
+
* @returns Array of supported emotion keywords
|
|
223
|
+
*/
|
|
224
|
+
declare function getSupportedEmotionKeywords(): string[];
|
|
225
|
+
|
|
226
|
+
declare class Charivo {
|
|
227
|
+
private eventBus;
|
|
228
|
+
private llmManager?;
|
|
229
|
+
private renderManager?;
|
|
230
|
+
private ttsManager?;
|
|
231
|
+
private character?;
|
|
232
|
+
constructor();
|
|
233
|
+
/**
|
|
234
|
+
* Attach a render manager to handle character visualization.
|
|
235
|
+
* Automatically connects the event bus and sets the current character if available.
|
|
236
|
+
*/
|
|
237
|
+
attachRenderer(renderManager: RenderManager): void;
|
|
238
|
+
/**
|
|
239
|
+
* Connects the render manager to the event bus for bidirectional communication.
|
|
240
|
+
*/
|
|
241
|
+
private connectRenderManagerEventBus;
|
|
242
|
+
/**
|
|
243
|
+
* Attach an LLM manager to handle conversation generation.
|
|
244
|
+
* Automatically sets the current character if available.
|
|
245
|
+
*/
|
|
246
|
+
attachLLM(manager: LLMManager): void;
|
|
247
|
+
/**
|
|
248
|
+
* Attach a TTS manager to handle voice synthesis.
|
|
249
|
+
* Automatically connects the event emitter for audio events.
|
|
250
|
+
*/
|
|
251
|
+
attachTTS(manager: TTSManager): void;
|
|
252
|
+
/**
|
|
253
|
+
* Detach the TTS manager to disable voice synthesis.
|
|
254
|
+
*/
|
|
255
|
+
detachTTS(): void;
|
|
256
|
+
/**
|
|
257
|
+
* Connects the TTS manager to the event bus for audio event emission.
|
|
258
|
+
*/
|
|
259
|
+
private connectTTSManagerEventEmitter;
|
|
260
|
+
/**
|
|
261
|
+
* Set the character for this Charivo instance.
|
|
262
|
+
* Automatically propagates to all attached managers (LLM, Renderer).
|
|
263
|
+
*/
|
|
264
|
+
setCharacter(character: Character): void;
|
|
265
|
+
/**
|
|
266
|
+
* Process a user message and generate a character response.
|
|
267
|
+
* Orchestrates the full conversation flow: rendering, LLM generation, and TTS playback.
|
|
268
|
+
*/
|
|
269
|
+
userSay(content: string): Promise<void>;
|
|
270
|
+
/**
|
|
271
|
+
* Clear the conversation history from the LLM manager.
|
|
272
|
+
*/
|
|
273
|
+
clearHistory(): void;
|
|
274
|
+
/**
|
|
275
|
+
* Get the conversation history from the LLM manager.
|
|
276
|
+
*/
|
|
277
|
+
getHistory(): Message[];
|
|
278
|
+
/**
|
|
279
|
+
* Get the currently configured character.
|
|
280
|
+
*/
|
|
281
|
+
getCurrentCharacter(): Character | null;
|
|
282
|
+
/**
|
|
283
|
+
* Subscribe to events from the event bus.
|
|
284
|
+
*/
|
|
285
|
+
on<K extends keyof EventMap>(event: K, listener: (data: EventMap[K]) => void): void;
|
|
286
|
+
/**
|
|
287
|
+
* Emit events to the event bus.
|
|
288
|
+
*/
|
|
289
|
+
emit<K extends keyof EventMap>(event: K, data: EventMap[K]): void;
|
|
290
|
+
}
|
|
291
|
+
|
|
292
|
+
export { type Character, Charivo, type CharivoConfig, type Conversation, Emotion, type EmotionMapping, EventBus, type EventMap, type LLMAdapter, type LLMClient, type LLMManager, type LLMProvider, type Message, type ParsedEmotion, type Plugin, type RenderManager, type Renderer, type TTSManager, type TTSOptions, type TTSPlayer, type TTSProvider, getSupportedEmotionKeywords, hasEmotionTag, parseEmotion };
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,292 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Standard emotion types for character expressions
|
|
3
|
+
*/
|
|
4
|
+
declare enum Emotion {
|
|
5
|
+
NEUTRAL = "neutral",
|
|
6
|
+
HAPPY = "happy",
|
|
7
|
+
SAD = "sad",
|
|
8
|
+
ANGRY = "angry",
|
|
9
|
+
SURPRISED = "surprised",
|
|
10
|
+
THINKING = "thinking",
|
|
11
|
+
EXCITED = "excited",
|
|
12
|
+
SHY = "shy"
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* Mapping between emotion and Live2D model animations
|
|
16
|
+
*/
|
|
17
|
+
interface EmotionMapping {
|
|
18
|
+
emotion: Emotion;
|
|
19
|
+
expression?: string;
|
|
20
|
+
motion?: {
|
|
21
|
+
group: string;
|
|
22
|
+
index?: number;
|
|
23
|
+
};
|
|
24
|
+
}
|
|
25
|
+
interface Character {
|
|
26
|
+
id: string;
|
|
27
|
+
name: string;
|
|
28
|
+
description?: string;
|
|
29
|
+
personality?: string;
|
|
30
|
+
avatar?: string;
|
|
31
|
+
voice?: {
|
|
32
|
+
voiceId?: string;
|
|
33
|
+
rate?: number;
|
|
34
|
+
pitch?: number;
|
|
35
|
+
volume?: number;
|
|
36
|
+
};
|
|
37
|
+
/**
|
|
38
|
+
* Custom emotion mappings for this character's Live2D model
|
|
39
|
+
* If not specified, default mappings will be used
|
|
40
|
+
*/
|
|
41
|
+
emotionMappings?: EmotionMapping[];
|
|
42
|
+
}
|
|
43
|
+
interface Message {
|
|
44
|
+
id: string;
|
|
45
|
+
content: string;
|
|
46
|
+
timestamp: Date;
|
|
47
|
+
characterId?: string;
|
|
48
|
+
type: "user" | "character" | "system";
|
|
49
|
+
/**
|
|
50
|
+
* Parsed emotion from message content (if any)
|
|
51
|
+
*/
|
|
52
|
+
emotion?: Emotion;
|
|
53
|
+
}
|
|
54
|
+
interface Conversation {
|
|
55
|
+
id: string;
|
|
56
|
+
messages: Message[];
|
|
57
|
+
characterId?: string;
|
|
58
|
+
createdAt: Date;
|
|
59
|
+
updatedAt: Date;
|
|
60
|
+
}
|
|
61
|
+
interface Plugin {
|
|
62
|
+
id: string;
|
|
63
|
+
name: string;
|
|
64
|
+
version: string;
|
|
65
|
+
enabled: boolean;
|
|
66
|
+
}
|
|
67
|
+
interface CharivoConfig {
|
|
68
|
+
characters: Character[];
|
|
69
|
+
plugins: Plugin[];
|
|
70
|
+
llmProvider?: string;
|
|
71
|
+
renderProvider?: string;
|
|
72
|
+
}
|
|
73
|
+
interface LLMAdapter {
|
|
74
|
+
generateResponse(message: Message): Promise<string>;
|
|
75
|
+
setCharacter(character: Character): void;
|
|
76
|
+
clearHistory(): void;
|
|
77
|
+
}
|
|
78
|
+
interface LLMProvider {
|
|
79
|
+
generateResponse(messages: Array<{
|
|
80
|
+
role: string;
|
|
81
|
+
content: string;
|
|
82
|
+
}>): Promise<string>;
|
|
83
|
+
}
|
|
84
|
+
interface LLMClient {
|
|
85
|
+
call(messages: Array<{
|
|
86
|
+
role: string;
|
|
87
|
+
content: string;
|
|
88
|
+
}>): Promise<string>;
|
|
89
|
+
}
|
|
90
|
+
interface LLMManager {
|
|
91
|
+
setCharacter(character: Character): void;
|
|
92
|
+
getCharacter(): Character | null;
|
|
93
|
+
clearHistory(): void;
|
|
94
|
+
getHistory(): Message[];
|
|
95
|
+
generateResponse(message: Message): Promise<string>;
|
|
96
|
+
}
|
|
97
|
+
interface Renderer {
|
|
98
|
+
initialize(): Promise<void>;
|
|
99
|
+
destroy(): Promise<void>;
|
|
100
|
+
render(message: Message, character?: Character): Promise<void>;
|
|
101
|
+
loadModel?(modelPath: string): Promise<void>;
|
|
102
|
+
setRealtimeLipSync?(enabled: boolean): void;
|
|
103
|
+
updateRealtimeLipSyncRms?(rms: number): void;
|
|
104
|
+
}
|
|
105
|
+
interface RenderManager {
|
|
106
|
+
initialize(): Promise<void>;
|
|
107
|
+
destroy(): Promise<void>;
|
|
108
|
+
setCharacter(character: Character): void;
|
|
109
|
+
render(message: Message, character?: Character): Promise<void>;
|
|
110
|
+
loadModel?(modelPath: string): Promise<void>;
|
|
111
|
+
setMessageCallback?(callback: (message: Message, character?: Character) => void): void;
|
|
112
|
+
}
|
|
113
|
+
interface TTSOptions {
|
|
114
|
+
rate?: number;
|
|
115
|
+
pitch?: number;
|
|
116
|
+
volume?: number;
|
|
117
|
+
voice?: string;
|
|
118
|
+
}
|
|
119
|
+
interface TTSPlayer {
|
|
120
|
+
speak(text: string, options?: TTSOptions): Promise<void>;
|
|
121
|
+
stop(): Promise<void>;
|
|
122
|
+
setVoice(voice: string): void;
|
|
123
|
+
isSupported(): boolean;
|
|
124
|
+
generateAudio?(text: string, options?: TTSOptions): Promise<ArrayBuffer>;
|
|
125
|
+
}
|
|
126
|
+
interface TTSProvider {
|
|
127
|
+
generateSpeech(text: string, options?: TTSOptions): Promise<ArrayBuffer>;
|
|
128
|
+
setVoice(voice: string): void;
|
|
129
|
+
}
|
|
130
|
+
interface TTSManager {
|
|
131
|
+
speak(text: string, options?: TTSOptions): Promise<void>;
|
|
132
|
+
stop(): Promise<void>;
|
|
133
|
+
setVoice(voice: string): void;
|
|
134
|
+
isSupported(): boolean;
|
|
135
|
+
setEventEmitter?(eventEmitter: {
|
|
136
|
+
emit: (event: string, data: any) => void;
|
|
137
|
+
}): void;
|
|
138
|
+
}
|
|
139
|
+
type EventMap = {
|
|
140
|
+
"message:sent": {
|
|
141
|
+
message: Message;
|
|
142
|
+
};
|
|
143
|
+
"message:received": {
|
|
144
|
+
message: Message;
|
|
145
|
+
};
|
|
146
|
+
"character:speak": {
|
|
147
|
+
character: Character;
|
|
148
|
+
message: string;
|
|
149
|
+
};
|
|
150
|
+
"tts:start": {
|
|
151
|
+
text: string;
|
|
152
|
+
characterId?: string;
|
|
153
|
+
};
|
|
154
|
+
"tts:end": {
|
|
155
|
+
characterId?: string;
|
|
156
|
+
};
|
|
157
|
+
"tts:error": {
|
|
158
|
+
error: Error;
|
|
159
|
+
};
|
|
160
|
+
"tts:audio:start": {
|
|
161
|
+
audioElement: HTMLAudioElement;
|
|
162
|
+
characterId?: string;
|
|
163
|
+
};
|
|
164
|
+
"tts:audio:end": {
|
|
165
|
+
characterId?: string;
|
|
166
|
+
};
|
|
167
|
+
"tts:lipsync:update": {
|
|
168
|
+
rms: number;
|
|
169
|
+
characterId?: string;
|
|
170
|
+
};
|
|
171
|
+
error: {
|
|
172
|
+
error: Error;
|
|
173
|
+
};
|
|
174
|
+
};
|
|
175
|
+
|
|
176
|
+
declare class EventBus {
|
|
177
|
+
private listeners;
|
|
178
|
+
on<K extends keyof EventMap>(event: K, listener: (data: EventMap[K]) => void): void;
|
|
179
|
+
emit<K extends keyof EventMap>(event: K, data: EventMap[K]): void;
|
|
180
|
+
off<K extends keyof EventMap>(event: K, listener: (data: EventMap[K]) => void): void;
|
|
181
|
+
clear(): void;
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
/**
|
|
185
|
+
* Result of parsing emotion tags from text
|
|
186
|
+
*/
|
|
187
|
+
interface ParsedEmotion {
|
|
188
|
+
/** The cleaned text with emotion tags removed */
|
|
189
|
+
text: string;
|
|
190
|
+
/** The detected emotion (if any) */
|
|
191
|
+
emotion?: Emotion;
|
|
192
|
+
}
|
|
193
|
+
/**
|
|
194
|
+
* Parse emotion tags from text and return cleaned text with detected emotion
|
|
195
|
+
*
|
|
196
|
+
* @param text - The text containing potential emotion tags (e.g., "Hello! [happy] How are you?")
|
|
197
|
+
* @returns ParsedEmotion object with cleaned text and detected emotion
|
|
198
|
+
*
|
|
199
|
+
* @example
|
|
200
|
+
* ```typescript
|
|
201
|
+
* parseEmotion("Hello! [happy] Nice to meet you!")
|
|
202
|
+
* // Returns: { text: "Hello! Nice to meet you!", emotion: Emotion.HAPPY }
|
|
203
|
+
*
|
|
204
|
+
* parseEmotion("I'm feeling [sad] today...")
|
|
205
|
+
* // Returns: { text: "I'm feeling today...", emotion: Emotion.SAD }
|
|
206
|
+
*
|
|
207
|
+
* parseEmotion("Just a normal message")
|
|
208
|
+
* // Returns: { text: "Just a normal message", emotion: undefined }
|
|
209
|
+
* ```
|
|
210
|
+
*/
|
|
211
|
+
declare function parseEmotion(text: string): ParsedEmotion;
|
|
212
|
+
/**
|
|
213
|
+
* Check if text contains any emotion tags
|
|
214
|
+
*
|
|
215
|
+
* @param text - The text to check
|
|
216
|
+
* @returns true if text contains emotion tags
|
|
217
|
+
*/
|
|
218
|
+
declare function hasEmotionTag(text: string): boolean;
|
|
219
|
+
/**
|
|
220
|
+
* Get all supported emotion keywords
|
|
221
|
+
*
|
|
222
|
+
* @returns Array of supported emotion keywords
|
|
223
|
+
*/
|
|
224
|
+
declare function getSupportedEmotionKeywords(): string[];
|
|
225
|
+
|
|
226
|
+
declare class Charivo {
|
|
227
|
+
private eventBus;
|
|
228
|
+
private llmManager?;
|
|
229
|
+
private renderManager?;
|
|
230
|
+
private ttsManager?;
|
|
231
|
+
private character?;
|
|
232
|
+
constructor();
|
|
233
|
+
/**
|
|
234
|
+
* Attach a render manager to handle character visualization.
|
|
235
|
+
* Automatically connects the event bus and sets the current character if available.
|
|
236
|
+
*/
|
|
237
|
+
attachRenderer(renderManager: RenderManager): void;
|
|
238
|
+
/**
|
|
239
|
+
* Connects the render manager to the event bus for bidirectional communication.
|
|
240
|
+
*/
|
|
241
|
+
private connectRenderManagerEventBus;
|
|
242
|
+
/**
|
|
243
|
+
* Attach an LLM manager to handle conversation generation.
|
|
244
|
+
* Automatically sets the current character if available.
|
|
245
|
+
*/
|
|
246
|
+
attachLLM(manager: LLMManager): void;
|
|
247
|
+
/**
|
|
248
|
+
* Attach a TTS manager to handle voice synthesis.
|
|
249
|
+
* Automatically connects the event emitter for audio events.
|
|
250
|
+
*/
|
|
251
|
+
attachTTS(manager: TTSManager): void;
|
|
252
|
+
/**
|
|
253
|
+
* Detach the TTS manager to disable voice synthesis.
|
|
254
|
+
*/
|
|
255
|
+
detachTTS(): void;
|
|
256
|
+
/**
|
|
257
|
+
* Connects the TTS manager to the event bus for audio event emission.
|
|
258
|
+
*/
|
|
259
|
+
private connectTTSManagerEventEmitter;
|
|
260
|
+
/**
|
|
261
|
+
* Set the character for this Charivo instance.
|
|
262
|
+
* Automatically propagates to all attached managers (LLM, Renderer).
|
|
263
|
+
*/
|
|
264
|
+
setCharacter(character: Character): void;
|
|
265
|
+
/**
|
|
266
|
+
* Process a user message and generate a character response.
|
|
267
|
+
* Orchestrates the full conversation flow: rendering, LLM generation, and TTS playback.
|
|
268
|
+
*/
|
|
269
|
+
userSay(content: string): Promise<void>;
|
|
270
|
+
/**
|
|
271
|
+
* Clear the conversation history from the LLM manager.
|
|
272
|
+
*/
|
|
273
|
+
clearHistory(): void;
|
|
274
|
+
/**
|
|
275
|
+
* Get the conversation history from the LLM manager.
|
|
276
|
+
*/
|
|
277
|
+
getHistory(): Message[];
|
|
278
|
+
/**
|
|
279
|
+
* Get the currently configured character.
|
|
280
|
+
*/
|
|
281
|
+
getCurrentCharacter(): Character | null;
|
|
282
|
+
/**
|
|
283
|
+
* Subscribe to events from the event bus.
|
|
284
|
+
*/
|
|
285
|
+
on<K extends keyof EventMap>(event: K, listener: (data: EventMap[K]) => void): void;
|
|
286
|
+
/**
|
|
287
|
+
* Emit events to the event bus.
|
|
288
|
+
*/
|
|
289
|
+
emit<K extends keyof EventMap>(event: K, data: EventMap[K]): void;
|
|
290
|
+
}
|
|
291
|
+
|
|
292
|
+
export { type Character, Charivo, type CharivoConfig, type Conversation, Emotion, type EmotionMapping, EventBus, type EventMap, type LLMAdapter, type LLMClient, type LLMManager, type LLMProvider, type Message, type ParsedEmotion, type Plugin, type RenderManager, type Renderer, type TTSManager, type TTSOptions, type TTSPlayer, type TTSProvider, getSupportedEmotionKeywords, hasEmotionTag, parseEmotion };
|