@rimori/react-client 0.4.11-next.1 → 0.4.11-next.3

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.
@@ -0,0 +1,19 @@
1
+ import React from 'react';
2
+ import { Tool } from '@rimori/client';
3
+ export interface BuddyAssistantAutoStart {
4
+ /** Pre-written assistant message shown immediately (no AI call) */
5
+ assistantMessage?: string;
6
+ /** Silently sent as the first user message to trigger an AI-generated intro */
7
+ userMessage?: string;
8
+ }
9
+ export interface BuddyAssistantProps {
10
+ systemPrompt: string;
11
+ autoStartConversation?: BuddyAssistantAutoStart;
12
+ circleSize?: string;
13
+ chatPlaceholder?: string;
14
+ bottomAction?: React.ReactNode;
15
+ className?: string;
16
+ voiceSpeed?: number;
17
+ tools?: Tool[];
18
+ }
19
+ export declare function BuddyAssistant({ systemPrompt, autoStartConversation, circleSize, chatPlaceholder, bottomAction, className, voiceSpeed, tools, }: BuddyAssistantProps): JSX.Element;
@@ -0,0 +1,107 @@
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import { useState, useEffect, useMemo, useRef } from 'react';
3
+ import { CircleAudioAvatar } from './EmbeddedAssistent/CircleAudioAvatar';
4
+ import { VoiceRecorder } from './EmbeddedAssistent/VoiceRecorder';
5
+ import { MessageSender } from '@rimori/client';
6
+ import { useRimori } from '../../providers/PluginProvider';
7
+ import { useTheme } from '../../hooks/ThemeSetter';
8
+ import { HiMiniSpeakerWave, HiMiniSpeakerXMark } from 'react-icons/hi2';
9
+ import { BiSolidRightArrow } from 'react-icons/bi';
10
+ let idCounter = 0;
11
+ const genId = () => `ba-${++idCounter}`;
12
+ export function BuddyAssistant({ systemPrompt, autoStartConversation, circleSize = '160px', chatPlaceholder, bottomAction, className, voiceSpeed = 1, tools, }) {
13
+ var _a;
14
+ const { ai, event, plugin } = useRimori();
15
+ const { isDark } = useTheme(plugin.theme);
16
+ const buddy = (_a = plugin.getUserInfo()) === null || _a === void 0 ? void 0 : _a.study_buddy;
17
+ const [ttsEnabled, setTtsEnabled] = useState(true);
18
+ const [chatInput, setChatInput] = useState('');
19
+ const [messages, setMessages] = useState([]);
20
+ const [isLoading, setIsLoading] = useState(false);
21
+ const [isSpeaking, setIsSpeaking] = useState(false);
22
+ const ttsEnabledRef = useRef(ttsEnabled);
23
+ useEffect(() => {
24
+ ttsEnabledRef.current = ttsEnabled;
25
+ }, [ttsEnabled]);
26
+ const sender = useMemo(() => { var _a; return new MessageSender((...args) => ai.getVoice(...args), (_a = buddy === null || buddy === void 0 ? void 0 : buddy.voiceId) !== null && _a !== void 0 ? _a : ''); }, [buddy === null || buddy === void 0 ? void 0 : buddy.voiceId, ai]);
27
+ // Setup sender callbacks and cleanup
28
+ useEffect(() => {
29
+ sender.setVoiceSpeed(voiceSpeed);
30
+ sender.setOnLoudnessChange((value) => event.emit('self.avatar.triggerLoudness', { loudness: value }));
31
+ sender.setOnEndOfSpeech(() => setIsSpeaking(false));
32
+ return () => sender.cleanup();
33
+ }, [sender]);
34
+ // Build full API message list with system prompt
35
+ const buildApiMessages = (history) => [
36
+ { role: 'system', content: systemPrompt },
37
+ ...history.map((m) => ({ role: m.role, content: m.content })),
38
+ ];
39
+ const triggerAI = (history) => {
40
+ setIsLoading(true);
41
+ void ai.getSteamedText(buildApiMessages(history), (id, partial, finished) => {
42
+ setIsLoading(!finished);
43
+ const assistantId = `ai-${id}`;
44
+ setMessages((prev) => {
45
+ const last = prev[prev.length - 1];
46
+ if ((last === null || last === void 0 ? void 0 : last.id) === assistantId) {
47
+ return [...prev.slice(0, -1), Object.assign(Object.assign({}, last), { content: partial })];
48
+ }
49
+ return [...prev, { id: assistantId, role: 'assistant', content: partial }];
50
+ });
51
+ if (ttsEnabledRef.current) {
52
+ void sender.handleNewText(partial, !finished);
53
+ if (partial)
54
+ setIsSpeaking(true);
55
+ }
56
+ }, tools);
57
+ };
58
+ // Auto-start conversation on mount
59
+ const autoStartedRef = useRef(false);
60
+ useEffect(() => {
61
+ if (autoStartedRef.current)
62
+ return;
63
+ autoStartedRef.current = true;
64
+ if (autoStartConversation === null || autoStartConversation === void 0 ? void 0 : autoStartConversation.assistantMessage) {
65
+ const initMsg = { id: 'init', role: 'assistant', content: autoStartConversation.assistantMessage };
66
+ setMessages([initMsg]);
67
+ if (ttsEnabledRef.current) {
68
+ void sender.handleNewText(autoStartConversation.assistantMessage, false);
69
+ setIsSpeaking(true);
70
+ }
71
+ }
72
+ else if (autoStartConversation === null || autoStartConversation === void 0 ? void 0 : autoStartConversation.userMessage) {
73
+ const userMsg = { id: 'auto-start', role: 'user', content: autoStartConversation.userMessage };
74
+ setMessages([userMsg]);
75
+ triggerAI([userMsg]);
76
+ }
77
+ // eslint-disable-next-line react-hooks/exhaustive-deps
78
+ }, []);
79
+ if (!buddy)
80
+ return _jsx("div", {});
81
+ const sendMessage = (text) => {
82
+ if (!text.trim() || isLoading)
83
+ return;
84
+ const userMsg = { id: genId(), role: 'user', content: text };
85
+ const newMessages = [...messages, userMsg];
86
+ setMessages(newMessages);
87
+ triggerAI(newMessages);
88
+ };
89
+ const handleToggleTts = () => {
90
+ if (ttsEnabled && isSpeaking) {
91
+ sender.stop();
92
+ setIsSpeaking(false);
93
+ }
94
+ setTtsEnabled((prev) => !prev);
95
+ };
96
+ const lastAssistantMessage = [...messages].filter((m) => m.role === 'assistant').pop();
97
+ return (_jsxs("div", { className: `flex flex-col items-center ${className || ''}`, children: [_jsx(CircleAudioAvatar, { width: circleSize, imageUrl: buddy.avatarUrl, isDarkTheme: isDark, className: "mx-auto" }), _jsxs("div", { className: "flex items-center gap-2 pl-10", children: [_jsx("span", { className: "text-3xl font-semibold", children: buddy.name }), _jsx("button", { type: "button", onClick: handleToggleTts, className: "p-1 rounded-md hover:bg-gray-700/50 transition-colors", title: ttsEnabled ? 'Disable voice' : 'Enable voice', children: ttsEnabled ? (_jsx(HiMiniSpeakerWave, { className: `w-5 h-5 mt-0.5 ${isSpeaking ? 'text-blue-400' : 'text-gray-300'}` })) : (_jsx(HiMiniSpeakerXMark, { className: "w-5 h-5 mt-0.5 text-gray-500" })) })] }), !ttsEnabled && (_jsx("div", { className: "w-full max-w-md rounded-xl bg-gray-800/70 px-4 py-3 text-sm text-gray-200 leading-relaxed border border-gray-700/40 mt-4", children: !(lastAssistantMessage === null || lastAssistantMessage === void 0 ? void 0 : lastAssistantMessage.content) && isLoading ? (_jsxs("span", { className: "inline-flex gap-1 py-0.5", children: [_jsx("span", { className: "w-1.5 h-1.5 rounded-full bg-gray-400 animate-bounce" }), _jsx("span", { className: "w-1.5 h-1.5 rounded-full bg-gray-400 animate-bounce", style: { animationDelay: '0.15s' } }), _jsx("span", { className: "w-1.5 h-1.5 rounded-full bg-gray-400 animate-bounce", style: { animationDelay: '0.3s' } })] })) : (_jsx("span", { className: "whitespace-pre-wrap", children: lastAssistantMessage === null || lastAssistantMessage === void 0 ? void 0 : lastAssistantMessage.content })) })), _jsxs("div", { className: "w-full max-w-md relative mt-4", children: [_jsx("input", { value: chatInput, onChange: (e) => setChatInput(e.target.value), onKeyDown: (e) => {
98
+ if (e.key === 'Enter' && !e.shiftKey) {
99
+ e.preventDefault();
100
+ sendMessage(chatInput);
101
+ setChatInput('');
102
+ }
103
+ }, placeholder: chatPlaceholder !== null && chatPlaceholder !== void 0 ? chatPlaceholder : `Ask ${buddy.name} a question…`, disabled: isLoading, className: "w-full bg-gray-800/50 border border-gray-700 rounded-lg px-3 py-2 pr-16 text-sm text-gray-200 placeholder:text-gray-500 focus:outline-none focus:ring-1 focus:ring-blue-500 disabled:opacity-60" }), _jsxs("div", { className: "absolute right-2 top-1/2 -translate-y-1/2 flex items-center gap-1", children: [_jsx(VoiceRecorder, { iconSize: "14", className: "p-1 text-gray-400 hover:text-white transition-colors", disabled: isLoading, onVoiceRecorded: (text) => sendMessage(text), onRecordingStatusChange: () => { } }), _jsx("div", { className: "w-px h-3.5 bg-gray-600" }), _jsx("button", { type: "button", onClick: () => {
104
+ sendMessage(chatInput);
105
+ setChatInput('');
106
+ }, disabled: isLoading || !chatInput.trim(), className: "p-1 text-gray-400 hover:text-white disabled:opacity-40 transition-colors", children: _jsx(BiSolidRightArrow, { className: "w-4 h-4" }) })] })] }), bottomAction && _jsx("div", { className: "w-full max-w-md border-t border-gray-700/60 pt-3", children: bottomAction })] }));
107
+ }
@@ -9,6 +9,7 @@ type AudioPlayerProps = {
9
9
  initialSpeed?: number;
10
10
  enableSpeedAdjustment?: boolean;
11
11
  playListenerEvent?: string;
12
+ size?: string;
12
13
  };
13
14
  export declare const AudioPlayOptions: number[];
14
15
  export type AudioPlayOptionType = 0.8 | 0.9 | 1.0 | 1.1 | 1.2 | 1.5;
@@ -14,7 +14,7 @@ import { useRimori } from '../../providers/PluginProvider';
14
14
  import { EventBus } from '@rimori/client';
15
15
  export const AudioPlayOptions = [0.8, 0.9, 1.0, 1.1, 1.2, 1.5];
16
16
  let isFetchingAudio = false;
17
- export const AudioPlayer = ({ text, voice, language, hide, playListenerEvent, initialSpeed = 1.0, playOnMount = false, enableSpeedAdjustment = false, cache = true, }) => {
17
+ export const AudioPlayer = ({ text, voice, language, hide, playListenerEvent, initialSpeed = 1.0, playOnMount = false, enableSpeedAdjustment = false, cache = true, size = '25px', }) => {
18
18
  const [audioUrl, setAudioUrl] = useState(null);
19
19
  const [speed, setSpeed] = useState(initialSpeed);
20
20
  const [isPlaying, setIsPlaying] = useState(false);
@@ -129,7 +129,7 @@ export const AudioPlayer = ({ text, voice, language, hide, playListenerEvent, in
129
129
  // console.log("playOnMount", playOnMount);
130
130
  togglePlayback();
131
131
  }, [playOnMount]);
132
- return (_jsx("div", { className: "group relative", children: _jsxs("div", { className: "flex flex-row items-end", children: [!hide && (_jsx("button", { className: "text-gray-400", onClick: togglePlayback, disabled: isLoading, children: isLoading ? (_jsx(Spinner, { size: "25px" })) : isPlaying ? (_jsx(FaStopCircle, { size: "25px" })) : (_jsx(FaPlayCircle, { size: "25px" })) })), enableSpeedAdjustment && (_jsxs("div", { className: "ml-1 opacity-0 group-hover:opacity-100 transition-opacity duration-300 flex flex-row text-sm text-gray-500", children: [_jsx("span", { className: "pr-1", children: "Speed: " }), _jsx("select", { value: speed, className: "appearance-none cursor-pointer pr-0 p-0 rounded shadow leading-tight focus:outline-none focus:bg-gray-800 focus:ring bg-transparent border-0", onChange: (e) => setSpeed(parseFloat(e.target.value)), disabled: isLoading, children: AudioPlayOptions.map((s) => (_jsx("option", { value: s, children: s }, s))) })] }))] }) }));
132
+ return (_jsx("div", { className: "group relative", children: _jsxs("div", { className: "flex flex-row items-end", children: [!hide && (_jsx("button", { className: "text-gray-400", onClick: togglePlayback, disabled: isLoading, children: isLoading ? (_jsx(Spinner, { size: size })) : isPlaying ? (_jsx(FaStopCircle, { size: size })) : (_jsx(FaPlayCircle, { size: size })) })), enableSpeedAdjustment && (_jsxs("div", { className: "ml-1 opacity-0 group-hover:opacity-100 transition-opacity duration-300 flex flex-row text-sm text-gray-500", children: [_jsx("span", { className: "pr-1", children: "Speed: " }), _jsx("select", { value: speed, className: "appearance-none cursor-pointer pr-0 p-0 rounded shadow leading-tight focus:outline-none focus:bg-gray-800 focus:ring bg-transparent border-0", onChange: (e) => setSpeed(parseFloat(e.target.value)), disabled: isLoading, children: AudioPlayOptions.map((s) => (_jsx("option", { value: s, children: s }, s))) })] }))] }) }));
133
133
  };
134
134
  const Spinner = ({ text, className, size = '30px' }) => {
135
135
  return (_jsxs("div", { className: 'flex items-center space-x-2 ' + className, children: [_jsxs("svg", { style: { width: size, height: size }, className: "animate-spin -ml-1 mr-3 h-5 w-5 text-white", xmlns: "http://www.w3.org/2000/svg", fill: "none", viewBox: "0 0 24 24", children: [_jsx("circle", { className: "opacity-25", cx: "12", cy: "12", r: "10", stroke: "currentColor", strokeWidth: "4" }), _jsx("path", { className: "opacity-75", fill: "currentColor", d: "M4 12a8 8 0 018-8V0C5.373 0 0 5.373 0 12h4zm2 5.291A7.962 7.962 0 014 12H0c0 3.042 1.135 5.824 3 7.938l3-2.647z" })] }), text && _jsx("span", { className: "", children: text })] }));
package/dist/index.d.ts CHANGED
@@ -5,6 +5,8 @@ export * from './components/ai/Avatar';
5
5
  export { FirstMessages } from './components/ai/utils';
6
6
  export { useTranslation } from './hooks/I18nHooks';
7
7
  export { Avatar } from './components/ai/Avatar';
8
+ export { BuddyAssistant } from './components/ai/BuddyAssistant';
9
+ export type { BuddyAssistantProps, BuddyAssistantAutoStart } from './components/ai/BuddyAssistant';
8
10
  export { VoiceRecorder } from './components/ai/EmbeddedAssistent/VoiceRecorder';
9
11
  export { MarkdownEditor } from './components/editor/MarkdownEditor';
10
12
  export type { MarkdownEditorProps, EditorLabels } from './components/editor/MarkdownEditor';
package/dist/index.js CHANGED
@@ -5,6 +5,7 @@ export * from './components/audio/Playbutton';
5
5
  export * from './components/ai/Avatar';
6
6
  export { useTranslation } from './hooks/I18nHooks';
7
7
  export { Avatar } from './components/ai/Avatar';
8
+ export { BuddyAssistant } from './components/ai/BuddyAssistant';
8
9
  export { VoiceRecorder } from './components/ai/EmbeddedAssistent/VoiceRecorder';
9
10
  export { MarkdownEditor } from './components/editor/MarkdownEditor';
10
11
  export { extractImageUrls } from './components/editor/imageUtils';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rimori/react-client",
3
- "version": "0.4.11-next.1",
3
+ "version": "0.4.11-next.3",
4
4
  "license": "Apache-2.0",
5
5
  "repository": {
6
6
  "type": "git",
@@ -0,0 +1,227 @@
1
+ import React, { useState, useEffect, useMemo, useRef } from 'react';
2
+ import { CircleAudioAvatar } from './EmbeddedAssistent/CircleAudioAvatar';
3
+ import { VoiceRecorder } from './EmbeddedAssistent/VoiceRecorder';
4
+ import { MessageSender, Tool } from '@rimori/client';
5
+ import { useRimori } from '../../providers/PluginProvider';
6
+ import { useTheme } from '../../hooks/ThemeSetter';
7
+ import { HiMiniSpeakerWave, HiMiniSpeakerXMark } from 'react-icons/hi2';
8
+ import { BiSolidRightArrow } from 'react-icons/bi';
9
+
10
+ type ChatMessage = { id: string; role: 'user' | 'assistant'; content: string };
11
+
12
+ export interface BuddyAssistantAutoStart {
13
+ /** Pre-written assistant message shown immediately (no AI call) */
14
+ assistantMessage?: string;
15
+ /** Silently sent as the first user message to trigger an AI-generated intro */
16
+ userMessage?: string;
17
+ }
18
+
19
+ export interface BuddyAssistantProps {
20
+ systemPrompt: string;
21
+ autoStartConversation?: BuddyAssistantAutoStart;
22
+ circleSize?: string;
23
+ chatPlaceholder?: string;
24
+ bottomAction?: React.ReactNode;
25
+ className?: string;
26
+ voiceSpeed?: number;
27
+ tools?: Tool[];
28
+ }
29
+
30
+ let idCounter = 0;
31
+ const genId = () => `ba-${++idCounter}`;
32
+
33
+ export function BuddyAssistant({
34
+ systemPrompt,
35
+ autoStartConversation,
36
+ circleSize = '160px',
37
+ chatPlaceholder,
38
+ bottomAction,
39
+ className,
40
+ voiceSpeed = 1,
41
+ tools,
42
+ }: BuddyAssistantProps): JSX.Element {
43
+ const { ai, event, plugin } = useRimori();
44
+ const { isDark } = useTheme(plugin.theme);
45
+ const buddy = plugin.getUserInfo()?.study_buddy;
46
+
47
+ const [ttsEnabled, setTtsEnabled] = useState(true);
48
+ const [chatInput, setChatInput] = useState('');
49
+ const [messages, setMessages] = useState<ChatMessage[]>([]);
50
+ const [isLoading, setIsLoading] = useState(false);
51
+ const [isSpeaking, setIsSpeaking] = useState(false);
52
+
53
+ const ttsEnabledRef = useRef(ttsEnabled);
54
+ useEffect(() => {
55
+ ttsEnabledRef.current = ttsEnabled;
56
+ }, [ttsEnabled]);
57
+
58
+ const sender = useMemo(
59
+ () => new MessageSender((...args) => ai.getVoice(...args), buddy?.voiceId ?? ''),
60
+ [buddy?.voiceId, ai],
61
+ );
62
+
63
+ // Setup sender callbacks and cleanup
64
+ useEffect(() => {
65
+ sender.setVoiceSpeed(voiceSpeed);
66
+ sender.setOnLoudnessChange((value: number) => event.emit('self.avatar.triggerLoudness', { loudness: value }));
67
+ sender.setOnEndOfSpeech(() => setIsSpeaking(false));
68
+ return () => sender.cleanup();
69
+ }, [sender]);
70
+
71
+ // Build full API message list with system prompt
72
+ const buildApiMessages = (history: ChatMessage[]) => [
73
+ { role: 'system' as const, content: systemPrompt },
74
+ ...history.map((m) => ({ role: m.role, content: m.content })),
75
+ ];
76
+
77
+ const triggerAI = (history: ChatMessage[]) => {
78
+ setIsLoading(true);
79
+ void ai.getSteamedText(
80
+ buildApiMessages(history),
81
+ (id: string, partial: string, finished: boolean) => {
82
+ setIsLoading(!finished);
83
+ const assistantId = `ai-${id}`;
84
+ setMessages((prev) => {
85
+ const last = prev[prev.length - 1];
86
+ if (last?.id === assistantId) {
87
+ return [...prev.slice(0, -1), { ...last, content: partial }];
88
+ }
89
+ return [...prev, { id: assistantId, role: 'assistant', content: partial }];
90
+ });
91
+ if (ttsEnabledRef.current) {
92
+ void sender.handleNewText(partial, !finished);
93
+ if (partial) setIsSpeaking(true);
94
+ }
95
+ },
96
+ tools,
97
+ );
98
+ };
99
+
100
+ // Auto-start conversation on mount
101
+ const autoStartedRef = useRef(false);
102
+ useEffect(() => {
103
+ if (autoStartedRef.current) return;
104
+ autoStartedRef.current = true;
105
+
106
+ if (autoStartConversation?.assistantMessage) {
107
+ const initMsg: ChatMessage = { id: 'init', role: 'assistant', content: autoStartConversation.assistantMessage };
108
+ setMessages([initMsg]);
109
+ if (ttsEnabledRef.current) {
110
+ void sender.handleNewText(autoStartConversation.assistantMessage, false);
111
+ setIsSpeaking(true);
112
+ }
113
+ } else if (autoStartConversation?.userMessage) {
114
+ const userMsg: ChatMessage = { id: 'auto-start', role: 'user', content: autoStartConversation.userMessage };
115
+ setMessages([userMsg]);
116
+ triggerAI([userMsg]);
117
+ }
118
+ // eslint-disable-next-line react-hooks/exhaustive-deps
119
+ }, []);
120
+
121
+ if (!buddy) return <div />;
122
+
123
+ const sendMessage = (text: string) => {
124
+ if (!text.trim() || isLoading) return;
125
+ const userMsg: ChatMessage = { id: genId(), role: 'user', content: text };
126
+ const newMessages = [...messages, userMsg];
127
+ setMessages(newMessages);
128
+ triggerAI(newMessages);
129
+ };
130
+
131
+ const handleToggleTts = () => {
132
+ if (ttsEnabled && isSpeaking) {
133
+ sender.stop();
134
+ setIsSpeaking(false);
135
+ }
136
+ setTtsEnabled((prev) => !prev);
137
+ };
138
+
139
+ const lastAssistantMessage = [...messages].filter((m) => m.role === 'assistant').pop();
140
+
141
+ return (
142
+ <div className={`flex flex-col items-center ${className || ''}`}>
143
+ {/* Animated circle avatar */}
144
+ <CircleAudioAvatar width={circleSize} imageUrl={buddy.avatarUrl} isDarkTheme={isDark} className="mx-auto" />
145
+
146
+ {/* Buddy name + TTS toggle */}
147
+ <div className="flex items-center gap-2 pl-10">
148
+ <span className="text-3xl font-semibold">{buddy.name}</span>
149
+ <button
150
+ type="button"
151
+ onClick={handleToggleTts}
152
+ className="p-1 rounded-md hover:bg-gray-700/50 transition-colors"
153
+ title={ttsEnabled ? 'Disable voice' : 'Enable voice'}
154
+ >
155
+ {ttsEnabled ? (
156
+ <HiMiniSpeakerWave className={`w-5 h-5 mt-0.5 ${isSpeaking ? 'text-blue-400' : 'text-gray-300'}`} />
157
+ ) : (
158
+ <HiMiniSpeakerXMark className="w-5 h-5 mt-0.5 text-gray-500" />
159
+ )}
160
+ </button>
161
+ </div>
162
+
163
+ {/* Last buddy message card — only shown when TTS is disabled */}
164
+ {!ttsEnabled && (
165
+ <div className="w-full max-w-md rounded-xl bg-gray-800/70 px-4 py-3 text-sm text-gray-200 leading-relaxed border border-gray-700/40 mt-4">
166
+ {!lastAssistantMessage?.content && isLoading ? (
167
+ <span className="inline-flex gap-1 py-0.5">
168
+ <span className="w-1.5 h-1.5 rounded-full bg-gray-400 animate-bounce" />
169
+ <span
170
+ className="w-1.5 h-1.5 rounded-full bg-gray-400 animate-bounce"
171
+ style={{ animationDelay: '0.15s' }}
172
+ />
173
+ <span
174
+ className="w-1.5 h-1.5 rounded-full bg-gray-400 animate-bounce"
175
+ style={{ animationDelay: '0.3s' }}
176
+ />
177
+ </span>
178
+ ) : (
179
+ <span className="whitespace-pre-wrap">{lastAssistantMessage?.content}</span>
180
+ )}
181
+ </div>
182
+ )}
183
+
184
+ {/* Chat input */}
185
+ <div className="w-full max-w-md relative mt-4">
186
+ <input
187
+ value={chatInput}
188
+ onChange={(e) => setChatInput(e.target.value)}
189
+ onKeyDown={(e) => {
190
+ if (e.key === 'Enter' && !e.shiftKey) {
191
+ e.preventDefault();
192
+ sendMessage(chatInput);
193
+ setChatInput('');
194
+ }
195
+ }}
196
+ placeholder={chatPlaceholder ?? `Ask ${buddy.name} a question…`}
197
+ disabled={isLoading}
198
+ className="w-full bg-gray-800/50 border border-gray-700 rounded-lg px-3 py-2 pr-16 text-sm text-gray-200 placeholder:text-gray-500 focus:outline-none focus:ring-1 focus:ring-blue-500 disabled:opacity-60"
199
+ />
200
+ <div className="absolute right-2 top-1/2 -translate-y-1/2 flex items-center gap-1">
201
+ <VoiceRecorder
202
+ iconSize="14"
203
+ className="p-1 text-gray-400 hover:text-white transition-colors"
204
+ disabled={isLoading}
205
+ onVoiceRecorded={(text) => sendMessage(text)}
206
+ onRecordingStatusChange={() => {}}
207
+ />
208
+ <div className="w-px h-3.5 bg-gray-600" />
209
+ <button
210
+ type="button"
211
+ onClick={() => {
212
+ sendMessage(chatInput);
213
+ setChatInput('');
214
+ }}
215
+ disabled={isLoading || !chatInput.trim()}
216
+ className="p-1 text-gray-400 hover:text-white disabled:opacity-40 transition-colors"
217
+ >
218
+ <BiSolidRightArrow className="w-4 h-4" />
219
+ </button>
220
+ </div>
221
+ </div>
222
+
223
+ {/* Optional bottom action (e.g. a CTA button) */}
224
+ {bottomAction && <div className="w-full max-w-md border-t border-gray-700/60 pt-3">{bottomAction}</div>}
225
+ </div>
226
+ );
227
+ }
@@ -13,6 +13,7 @@ type AudioPlayerProps = {
13
13
  initialSpeed?: number;
14
14
  enableSpeedAdjustment?: boolean;
15
15
  playListenerEvent?: string;
16
+ size?: string;
16
17
  };
17
18
 
18
19
  export const AudioPlayOptions = [0.8, 0.9, 1.0, 1.1, 1.2, 1.5];
@@ -30,6 +31,7 @@ export const AudioPlayer: React.FC<AudioPlayerProps> = ({
30
31
  playOnMount = false,
31
32
  enableSpeedAdjustment = false,
32
33
  cache = true,
34
+ size = '25px',
33
35
  }) => {
34
36
  const [audioUrl, setAudioUrl] = useState<string | null>(null);
35
37
  const [speed, setSpeed] = useState(initialSpeed);
@@ -161,11 +163,11 @@ export const AudioPlayer: React.FC<AudioPlayerProps> = ({
161
163
  {!hide && (
162
164
  <button className="text-gray-400" onClick={togglePlayback} disabled={isLoading}>
163
165
  {isLoading ? (
164
- <Spinner size="25px" />
166
+ <Spinner size={size} />
165
167
  ) : isPlaying ? (
166
- <FaStopCircle size="25px" />
168
+ <FaStopCircle size={size} />
167
169
  ) : (
168
- <FaPlayCircle size="25px" />
170
+ <FaPlayCircle size={size} />
169
171
  )}
170
172
  </button>
171
173
  )}
package/src/index.ts CHANGED
@@ -6,6 +6,8 @@ export * from './components/ai/Avatar';
6
6
  export { FirstMessages } from './components/ai/utils';
7
7
  export { useTranslation } from './hooks/I18nHooks';
8
8
  export { Avatar } from './components/ai/Avatar';
9
+ export { BuddyAssistant } from './components/ai/BuddyAssistant';
10
+ export type { BuddyAssistantProps, BuddyAssistantAutoStart } from './components/ai/BuddyAssistant';
9
11
  export { VoiceRecorder } from './components/ai/EmbeddedAssistent/VoiceRecorder';
10
12
  export { MarkdownEditor } from './components/editor/MarkdownEditor';
11
13
  export type { MarkdownEditorProps, EditorLabels } from './components/editor/MarkdownEditor';