@rimori/react-client 0.4.17-next.2 → 0.4.17-next.4
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/dist/components/ai/Avatar.d.ts +1 -4
- package/dist/components/ai/Avatar.js +4 -3
- package/dist/components/ai/BuddyAssistant.d.ts +3 -7
- package/dist/components/ai/BuddyAssistant.js +24 -26
- package/dist/components/ai/utils.d.ts +1 -4
- package/dist/components/ai/utils.js +5 -9
- package/dist/components/editor/MarkdownEditor.js +5 -10
- package/dist/hooks/ThemeSetter.d.ts +2 -1
- package/dist/hooks/ThemeSetter.js +5 -2
- package/dist/hooks/UseChatHook.d.ts +0 -2
- package/dist/hooks/UseChatHook.js +16 -11
- package/dist/providers/PluginProvider.d.ts +6 -0
- package/dist/providers/PluginProvider.js +4 -2
- package/package.json +3 -3
- package/src/components/ai/Avatar.tsx +3 -8
- package/src/components/ai/BuddyAssistant.tsx +9 -26
- package/src/components/ai/utils.ts +5 -11
- package/src/components/editor/MarkdownEditor.tsx +5 -11
- package/src/hooks/ThemeSetter.ts +9 -2
- package/src/hooks/UseChatHook.ts +5 -11
- package/src/providers/PluginProvider.tsx +9 -2
- package/README copy.md +0 -1216
|
@@ -9,13 +9,10 @@ interface Props {
|
|
|
9
9
|
children?: React.ReactNode;
|
|
10
10
|
autoStartConversation?: FirstMessages;
|
|
11
11
|
className?: string;
|
|
12
|
-
knowledgeId?: string;
|
|
13
12
|
/** Server-side prompt name (e.g. 'studyplan.reflection'). When set, the backend resolves the system prompt. */
|
|
14
13
|
prompt?: string;
|
|
15
14
|
/** Variables for the server-side prompt template. */
|
|
16
15
|
promptVariables?: Record<string, any>;
|
|
17
|
-
/** Set to true to disable automatic dialect TTS from userInfo. Default: false (dialect enabled). */
|
|
18
|
-
disableDialect?: boolean;
|
|
19
16
|
}
|
|
20
|
-
export declare function Avatar({ avatarImageUrl, voiceId, agentTools, autoStartConversation, children, circleSize, className, cache,
|
|
17
|
+
export declare function Avatar({ avatarImageUrl, voiceId, agentTools, autoStartConversation, children, circleSize, className, cache, prompt, promptVariables, }: Props): import("react/jsx-runtime").JSX.Element;
|
|
21
18
|
export {};
|
|
@@ -7,18 +7,19 @@ import { useChat } from '../../hooks/UseChatHook';
|
|
|
7
7
|
import { useRimori } from '../../providers/PluginProvider';
|
|
8
8
|
import { getFirstMessages } from './utils';
|
|
9
9
|
import { useTheme } from '../../hooks/ThemeSetter';
|
|
10
|
-
export function Avatar({ avatarImageUrl, voiceId, agentTools, autoStartConversation, children, circleSize = '300px', className, cache = false,
|
|
10
|
+
export function Avatar({ avatarImageUrl, voiceId, agentTools, autoStartConversation, children, circleSize = '300px', className, cache = false, prompt, promptVariables, }) {
|
|
11
11
|
const { ai, event, plugin, userInfo } = useRimori();
|
|
12
12
|
const { isDark: isDarkThemeValue } = useTheme(plugin.theme);
|
|
13
13
|
const [agentReplying, setAgentReplying] = useState(false);
|
|
14
14
|
const [isProcessingMessage, setIsProcessingMessage] = useState(false);
|
|
15
|
-
const dialectTtsInstruction =
|
|
15
|
+
const dialectTtsInstruction = (userInfo === null || userInfo === void 0 ? void 0 : userInfo.dialect)
|
|
16
|
+
? `Speak with a ${userInfo.dialect} accent and pronunciation.`
|
|
17
|
+
: undefined;
|
|
16
18
|
const sender = useMemo(() => new MessageSender((...args) => ai.getVoice(...args), voiceId, cache), [voiceId, ai, cache]);
|
|
17
19
|
useEffect(() => {
|
|
18
20
|
sender.setInstructions(dialectTtsInstruction);
|
|
19
21
|
}, [sender, dialectTtsInstruction]);
|
|
20
22
|
const { messages, append, isLoading, lastMessage, setMessages } = useChat(agentTools, {
|
|
21
|
-
knowledgeId,
|
|
22
23
|
prompt,
|
|
23
24
|
promptVariables,
|
|
24
25
|
});
|
|
@@ -7,10 +7,8 @@ export interface BuddyAssistantAutoStart {
|
|
|
7
7
|
userMessage?: string;
|
|
8
8
|
}
|
|
9
9
|
export interface BuddyAssistantProps {
|
|
10
|
-
/**
|
|
11
|
-
|
|
12
|
-
/** Server-side prompt name (e.g. 'studyplan.goalSummary'). When set, the backend resolves the system prompt. */
|
|
13
|
-
prompt?: string;
|
|
10
|
+
/** Server-side prompt name (e.g. 'studyplan.goalSummary'). The backend resolves the system prompt. */
|
|
11
|
+
prompt: string;
|
|
14
12
|
/** Variables for the server-side prompt template. */
|
|
15
13
|
promptVariables?: Record<string, any>;
|
|
16
14
|
autoStartConversation?: BuddyAssistantAutoStart;
|
|
@@ -20,9 +18,7 @@ export interface BuddyAssistantProps {
|
|
|
20
18
|
className?: string;
|
|
21
19
|
voiceSpeed?: number;
|
|
22
20
|
tools?: Tool[];
|
|
23
|
-
/** Set to true to disable automatic dialect from userInfo. Default: false (dialect enabled). */
|
|
24
|
-
disableDialect?: boolean;
|
|
25
21
|
/** Show the buddy name below the avatar. Default: false. */
|
|
26
22
|
showName?: boolean;
|
|
27
23
|
}
|
|
28
|
-
export declare function BuddyAssistant({
|
|
24
|
+
export declare function BuddyAssistant({ prompt, promptVariables, autoStartConversation, circleSize, chatPlaceholder, bottomAction, className, voiceSpeed, tools, showName, }: BuddyAssistantProps): JSX.Element;
|
|
@@ -8,15 +8,12 @@ import { useTheme } from '../../hooks/ThemeSetter';
|
|
|
8
8
|
import { BiSolidRightArrow } from 'react-icons/bi';
|
|
9
9
|
let idCounter = 0;
|
|
10
10
|
const genId = () => `ba-${++idCounter}`;
|
|
11
|
-
export function BuddyAssistant({
|
|
11
|
+
export function BuddyAssistant({ prompt, promptVariables, autoStartConversation, circleSize = '160px', chatPlaceholder, bottomAction, className, voiceSpeed = 1, tools, showName = false, }) {
|
|
12
12
|
const { ai, event, plugin, userInfo } = useRimori();
|
|
13
13
|
const ttsEnabled = plugin.ttsEnabled;
|
|
14
14
|
const { isDark } = useTheme(plugin.theme);
|
|
15
15
|
const buddy = userInfo.study_buddy;
|
|
16
|
-
const dialect =
|
|
17
|
-
const dialectSystemSuffix = dialect
|
|
18
|
-
? `\n\nThe user is learning the regional ${dialect} dialect. Occasionally use typical regional vocabulary and expressions from this dialect to help them learn local language naturally.`
|
|
19
|
-
: '';
|
|
16
|
+
const dialect = userInfo === null || userInfo === void 0 ? void 0 : userInfo.dialect;
|
|
20
17
|
const dialectTtsInstruction = dialect ? `Speak with a ${dialect} accent and pronunciation.` : undefined;
|
|
21
18
|
const [chatInput, setChatInput] = useState('');
|
|
22
19
|
const [messages, setMessages] = useState([]);
|
|
@@ -42,32 +39,33 @@ export function BuddyAssistant({ systemPrompt, prompt, promptVariables, autoStar
|
|
|
42
39
|
sender.setOnEndOfSpeech(() => setIsSpeaking(false));
|
|
43
40
|
return () => sender.cleanup();
|
|
44
41
|
}, [sender]);
|
|
45
|
-
// Build full API message list — when using server-side prompt, skip the client-side system message
|
|
46
42
|
const buildApiMessages = (history) => {
|
|
47
|
-
|
|
48
|
-
if (!prompt && systemPrompt) {
|
|
49
|
-
return [{ role: 'system', content: systemPrompt + dialectSystemSuffix }, ...msgs];
|
|
50
|
-
}
|
|
51
|
-
return msgs;
|
|
43
|
+
return history.map((m) => ({ role: m.role, content: m.content }));
|
|
52
44
|
};
|
|
53
45
|
const triggerAI = (history) => {
|
|
54
46
|
setIsLoading(true);
|
|
55
|
-
void ai.
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
const
|
|
60
|
-
|
|
61
|
-
|
|
47
|
+
void ai.getStreamedText({
|
|
48
|
+
messages: buildApiMessages(history),
|
|
49
|
+
onMessage: (id, partial, finished) => {
|
|
50
|
+
setIsLoading(!finished);
|
|
51
|
+
const assistantId = `ai-${id}`;
|
|
52
|
+
setMessages((prev) => {
|
|
53
|
+
const last = prev[prev.length - 1];
|
|
54
|
+
if ((last === null || last === void 0 ? void 0 : last.id) === assistantId) {
|
|
55
|
+
return [...prev.slice(0, -1), Object.assign(Object.assign({}, last), { content: partial })];
|
|
56
|
+
}
|
|
57
|
+
return [...prev, { id: assistantId, role: 'assistant', content: partial }];
|
|
58
|
+
});
|
|
59
|
+
if (ttsEnabledRef.current) {
|
|
60
|
+
void sender.handleNewText(partial, !finished);
|
|
61
|
+
if (partial)
|
|
62
|
+
setIsSpeaking(true);
|
|
62
63
|
}
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
setIsSpeaking(true);
|
|
69
|
-
}
|
|
70
|
-
}, tools, false, undefined, undefined, prompt, promptVariables);
|
|
64
|
+
},
|
|
65
|
+
tools,
|
|
66
|
+
prompt,
|
|
67
|
+
variables: promptVariables,
|
|
68
|
+
});
|
|
71
69
|
};
|
|
72
70
|
// Auto-start conversation on mount
|
|
73
71
|
const autoStartedRef = useRef(false);
|
|
@@ -1,8 +1,5 @@
|
|
|
1
|
-
/** @deprecated Use server-side prompt definitions (prompt + variables) instead of building messages client-side. */
|
|
2
1
|
export interface FirstMessages {
|
|
3
|
-
instructions?: string;
|
|
4
2
|
userMessage?: string;
|
|
5
3
|
assistantMessage?: string;
|
|
6
4
|
}
|
|
7
|
-
|
|
8
|
-
export declare function getFirstMessages(instructions: FirstMessages): any[];
|
|
5
|
+
export declare function getFirstMessages(config: FirstMessages): any[];
|
|
@@ -1,14 +1,10 @@
|
|
|
1
|
-
|
|
2
|
-
export function getFirstMessages(instructions) {
|
|
1
|
+
export function getFirstMessages(config) {
|
|
3
2
|
const messages = [];
|
|
4
|
-
if (
|
|
5
|
-
messages.push({ id: '1', role: '
|
|
3
|
+
if (config.userMessage) {
|
|
4
|
+
messages.push({ id: '1', role: 'user', content: config.userMessage });
|
|
6
5
|
}
|
|
7
|
-
if (
|
|
8
|
-
messages.push({ id: '2', role: '
|
|
9
|
-
}
|
|
10
|
-
if (instructions.assistantMessage) {
|
|
11
|
-
messages.push({ id: '3', role: 'assistant', content: instructions.assistantMessage });
|
|
6
|
+
if (config.assistantMessage) {
|
|
7
|
+
messages.push({ id: '2', role: 'assistant', content: config.assistantMessage });
|
|
12
8
|
}
|
|
13
9
|
return messages;
|
|
14
10
|
}
|
|
@@ -250,16 +250,11 @@ export const MarkdownEditor = ({ content, editable, className, onUpdate, labels,
|
|
|
250
250
|
return;
|
|
251
251
|
const selectedText = editor.state.doc.textBetween(from, to, '\n');
|
|
252
252
|
setIsTransforming(true);
|
|
253
|
-
const transformed = yield ai.getText(
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
{
|
|
259
|
-
role: 'user',
|
|
260
|
-
content: `Instruction: ${prompt}\n\nText:\n${selectedText}`,
|
|
261
|
-
},
|
|
262
|
-
]);
|
|
253
|
+
const transformed = yield ai.getText({
|
|
254
|
+
messages: [],
|
|
255
|
+
prompt: 'global.editor.transform-text',
|
|
256
|
+
variables: { instruction: prompt, text: selectedText },
|
|
257
|
+
});
|
|
263
258
|
setIsTransforming(false);
|
|
264
259
|
if (!transformed)
|
|
265
260
|
return;
|
|
@@ -1,12 +1,15 @@
|
|
|
1
|
-
export function useTheme(theme = 'system') {
|
|
1
|
+
export function useTheme(theme = 'system', isDisabled = false) {
|
|
2
2
|
const isDark = theme === 'system' ? systenUsesDarkMode() : theme === 'dark';
|
|
3
|
+
if (isDisabled) {
|
|
4
|
+
return { isDark, theme, isDisabled };
|
|
5
|
+
}
|
|
3
6
|
const dom = document.documentElement;
|
|
4
7
|
dom.dataset.theme = isDark ? 'dark' : 'light';
|
|
5
8
|
dom.style.colorScheme = isDark ? 'dark' : 'light';
|
|
6
9
|
dom.classList[isDark ? 'add' : 'remove']('dark');
|
|
7
10
|
const root = document.querySelector('#root');
|
|
8
11
|
root.classList.add('dark:bg-gradient-to-br', 'dark:from-gray-900', 'dark:to-gray-800', 'dark:text-white', 'min-h-screen', 'bg-fixed');
|
|
9
|
-
return { isDark, theme };
|
|
12
|
+
return { isDark, theme, isDisabled };
|
|
10
13
|
}
|
|
11
14
|
function systenUsesDarkMode() {
|
|
12
15
|
return window.matchMedia('(prefers-color-scheme: dark)').matches;
|
|
@@ -8,8 +8,6 @@ export interface UseChatConfig {
|
|
|
8
8
|
promptVariables?: Record<string, any>;
|
|
9
9
|
}
|
|
10
10
|
export declare function useChat(tools?: Tool[], options?: {
|
|
11
|
-
/** @deprecated Use uuid variable with resolver 'knowledgeEntry' in prompt definitions instead. */
|
|
12
|
-
knowledgeId?: string;
|
|
13
11
|
/** Server-side prompt name (e.g. 'storytelling.story'). When set, the backend resolves the system prompt. */
|
|
14
12
|
prompt?: string;
|
|
15
13
|
/** Variables for the server-side prompt template. */
|
|
@@ -21,19 +21,24 @@ export function useChat(tools, options) {
|
|
|
21
21
|
const allMessages = [...messages, ...appendMessages];
|
|
22
22
|
setMessages(allMessages);
|
|
23
23
|
setIsLoading(true);
|
|
24
|
-
const knowledgeId = options === null || options === void 0 ? void 0 : options.knowledgeId;
|
|
25
24
|
const promptVariables = (_a = configRef.current.promptVariables) !== null && _a !== void 0 ? _a : options === null || options === void 0 ? void 0 : options.promptVariables;
|
|
26
25
|
const prompt = (_b = configRef.current.prompt) !== null && _b !== void 0 ? _b : options === null || options === void 0 ? void 0 : options.prompt;
|
|
27
|
-
void ai.
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
26
|
+
void ai.getStreamedText({
|
|
27
|
+
messages: allMessages,
|
|
28
|
+
onMessage: (id, message, finished, toolInvocations) => {
|
|
29
|
+
setIsLoading(!finished);
|
|
30
|
+
setMessages((prev) => {
|
|
31
|
+
const last = prev[prev.length - 1];
|
|
32
|
+
if ((last === null || last === void 0 ? void 0 : last.id) === id) {
|
|
33
|
+
return [...prev.slice(0, -1), Object.assign(Object.assign({}, last), { content: message, toolCalls: toolInvocations })];
|
|
34
|
+
}
|
|
35
|
+
return [...prev, { id, role: 'assistant', content: message, toolCalls: toolInvocations }];
|
|
36
|
+
});
|
|
37
|
+
},
|
|
38
|
+
tools,
|
|
39
|
+
prompt,
|
|
40
|
+
variables: promptVariables,
|
|
41
|
+
});
|
|
37
42
|
};
|
|
38
43
|
return {
|
|
39
44
|
messages,
|
|
@@ -6,6 +6,12 @@ interface PluginProviderProps {
|
|
|
6
6
|
pluginId: string;
|
|
7
7
|
settings?: {
|
|
8
8
|
disableContextMenu?: boolean;
|
|
9
|
+
disableThemeSetting?: boolean;
|
|
10
|
+
/**
|
|
11
|
+
* Skip the scrollbar detection that emits 'session.triggerScrollbarChange'.
|
|
12
|
+
* In federation mode, the host (FederatedPluginRenderer) handles this instead.
|
|
13
|
+
*/
|
|
14
|
+
disableScrollbarDetection?: boolean;
|
|
9
15
|
};
|
|
10
16
|
}
|
|
11
17
|
export declare const PluginProvider: React.FC<PluginProviderProps>;
|
|
@@ -20,7 +20,7 @@ export const PluginProvider = ({ children, pluginId, settings }) => {
|
|
|
20
20
|
const [applicationMode, setApplicationMode] = useState(null);
|
|
21
21
|
const [theme, setTheme] = useState(undefined);
|
|
22
22
|
const [userInfo, setUserInfo] = useState(null);
|
|
23
|
-
useTheme(theme);
|
|
23
|
+
useTheme(theme, settings === null || settings === void 0 ? void 0 : settings.disableThemeSetting);
|
|
24
24
|
// Init PostHog once per plugin iframe
|
|
25
25
|
useEffect(() => {
|
|
26
26
|
if (!posthog.__loaded) {
|
|
@@ -94,6 +94,8 @@ export const PluginProvider = ({ children, pluginId, settings }) => {
|
|
|
94
94
|
useEffect(() => {
|
|
95
95
|
if (!client)
|
|
96
96
|
return;
|
|
97
|
+
if (settings === null || settings === void 0 ? void 0 : settings.disableScrollbarDetection)
|
|
98
|
+
return;
|
|
97
99
|
const checkScrollbar = () => {
|
|
98
100
|
const hasScrollbar = document.documentElement.scrollHeight > window.innerHeight;
|
|
99
101
|
client.event.emit('session.triggerScrollbarChange', { hasScrollbar });
|
|
@@ -109,7 +111,7 @@ export const PluginProvider = ({ children, pluginId, settings }) => {
|
|
|
109
111
|
window.removeEventListener('resize', checkScrollbar);
|
|
110
112
|
resizeObserver.disconnect();
|
|
111
113
|
};
|
|
112
|
-
}, [client]);
|
|
114
|
+
}, [client, settings === null || settings === void 0 ? void 0 : settings.disableScrollbarDetection]);
|
|
113
115
|
if (standaloneClient instanceof StandaloneClient) {
|
|
114
116
|
return (_jsx(StandaloneAuth, { onLogin: (email, password) => __awaiter(void 0, void 0, void 0, function* () {
|
|
115
117
|
if (yield standaloneClient.login(email, password))
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@rimori/react-client",
|
|
3
|
-
"version": "0.4.17-next.
|
|
3
|
+
"version": "0.4.17-next.4",
|
|
4
4
|
"license": "Apache-2.0",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -25,7 +25,7 @@
|
|
|
25
25
|
"format": "prettier --write ."
|
|
26
26
|
},
|
|
27
27
|
"peerDependencies": {
|
|
28
|
-
"@rimori/client": "2.5.28-next.
|
|
28
|
+
"@rimori/client": "2.5.28-next.7",
|
|
29
29
|
"react": "^18.1.0",
|
|
30
30
|
"react-dom": "^18.1.0"
|
|
31
31
|
},
|
|
@@ -49,7 +49,7 @@
|
|
|
49
49
|
},
|
|
50
50
|
"devDependencies": {
|
|
51
51
|
"@eslint/js": "^9.37.0",
|
|
52
|
-
"@rimori/client": "2.5.28-next.
|
|
52
|
+
"@rimori/client": "2.5.28-next.7",
|
|
53
53
|
"@types/react": "^18.3.21",
|
|
54
54
|
"eslint-config-prettier": "^10.1.8",
|
|
55
55
|
"eslint-plugin-prettier": "^5.5.4",
|
|
@@ -18,13 +18,10 @@ interface Props {
|
|
|
18
18
|
children?: React.ReactNode;
|
|
19
19
|
autoStartConversation?: FirstMessages;
|
|
20
20
|
className?: string;
|
|
21
|
-
knowledgeId?: string;
|
|
22
21
|
/** Server-side prompt name (e.g. 'studyplan.reflection'). When set, the backend resolves the system prompt. */
|
|
23
22
|
prompt?: string;
|
|
24
23
|
/** Variables for the server-side prompt template. */
|
|
25
24
|
promptVariables?: Record<string, any>;
|
|
26
|
-
/** Set to true to disable automatic dialect TTS from userInfo. Default: false (dialect enabled). */
|
|
27
|
-
disableDialect?: boolean;
|
|
28
25
|
}
|
|
29
26
|
|
|
30
27
|
export function Avatar({
|
|
@@ -36,17 +33,16 @@ export function Avatar({
|
|
|
36
33
|
circleSize = '300px',
|
|
37
34
|
className,
|
|
38
35
|
cache = false,
|
|
39
|
-
knowledgeId,
|
|
40
36
|
prompt,
|
|
41
37
|
promptVariables,
|
|
42
|
-
disableDialect = false,
|
|
43
38
|
}: Props) {
|
|
44
39
|
const { ai, event, plugin, userInfo } = useRimori();
|
|
45
40
|
const { isDark: isDarkThemeValue } = useTheme(plugin.theme);
|
|
46
41
|
const [agentReplying, setAgentReplying] = useState(false);
|
|
47
42
|
const [isProcessingMessage, setIsProcessingMessage] = useState(false);
|
|
48
|
-
const dialectTtsInstruction =
|
|
49
|
-
|
|
43
|
+
const dialectTtsInstruction = userInfo?.dialect
|
|
44
|
+
? `Speak with a ${userInfo.dialect} accent and pronunciation.`
|
|
45
|
+
: undefined;
|
|
50
46
|
const sender = useMemo(
|
|
51
47
|
() => new MessageSender((...args) => ai.getVoice(...args), voiceId, cache),
|
|
52
48
|
[voiceId, ai, cache],
|
|
@@ -56,7 +52,6 @@ export function Avatar({
|
|
|
56
52
|
sender.setInstructions(dialectTtsInstruction);
|
|
57
53
|
}, [sender, dialectTtsInstruction]);
|
|
58
54
|
const { messages, append, isLoading, lastMessage, setMessages } = useChat(agentTools, {
|
|
59
|
-
knowledgeId,
|
|
60
55
|
prompt,
|
|
61
56
|
promptVariables,
|
|
62
57
|
});
|
|
@@ -16,10 +16,8 @@ export interface BuddyAssistantAutoStart {
|
|
|
16
16
|
}
|
|
17
17
|
|
|
18
18
|
export interface BuddyAssistantProps {
|
|
19
|
-
/**
|
|
20
|
-
|
|
21
|
-
/** Server-side prompt name (e.g. 'studyplan.goalSummary'). When set, the backend resolves the system prompt. */
|
|
22
|
-
prompt?: string;
|
|
19
|
+
/** Server-side prompt name (e.g. 'studyplan.goalSummary'). The backend resolves the system prompt. */
|
|
20
|
+
prompt: string;
|
|
23
21
|
/** Variables for the server-side prompt template. */
|
|
24
22
|
promptVariables?: Record<string, any>;
|
|
25
23
|
autoStartConversation?: BuddyAssistantAutoStart;
|
|
@@ -29,8 +27,6 @@ export interface BuddyAssistantProps {
|
|
|
29
27
|
className?: string;
|
|
30
28
|
voiceSpeed?: number;
|
|
31
29
|
tools?: Tool[];
|
|
32
|
-
/** Set to true to disable automatic dialect from userInfo. Default: false (dialect enabled). */
|
|
33
|
-
disableDialect?: boolean;
|
|
34
30
|
/** Show the buddy name below the avatar. Default: false. */
|
|
35
31
|
showName?: boolean;
|
|
36
32
|
}
|
|
@@ -39,7 +35,6 @@ let idCounter = 0;
|
|
|
39
35
|
const genId = () => `ba-${++idCounter}`;
|
|
40
36
|
|
|
41
37
|
export function BuddyAssistant({
|
|
42
|
-
systemPrompt,
|
|
43
38
|
prompt,
|
|
44
39
|
promptVariables,
|
|
45
40
|
autoStartConversation,
|
|
@@ -49,17 +44,13 @@ export function BuddyAssistant({
|
|
|
49
44
|
className,
|
|
50
45
|
voiceSpeed = 1,
|
|
51
46
|
tools,
|
|
52
|
-
disableDialect = false,
|
|
53
47
|
showName = false,
|
|
54
48
|
}: BuddyAssistantProps): JSX.Element {
|
|
55
49
|
const { ai, event, plugin, userInfo } = useRimori();
|
|
56
50
|
const ttsEnabled = plugin.ttsEnabled;
|
|
57
51
|
const { isDark } = useTheme(plugin.theme);
|
|
58
52
|
const buddy = userInfo.study_buddy;
|
|
59
|
-
const dialect =
|
|
60
|
-
const dialectSystemSuffix = dialect
|
|
61
|
-
? `\n\nThe user is learning the regional ${dialect} dialect. Occasionally use typical regional vocabulary and expressions from this dialect to help them learn local language naturally.`
|
|
62
|
-
: '';
|
|
53
|
+
const dialect = userInfo?.dialect;
|
|
63
54
|
const dialectTtsInstruction = dialect ? `Speak with a ${dialect} accent and pronunciation.` : undefined;
|
|
64
55
|
const [chatInput, setChatInput] = useState('');
|
|
65
56
|
const [messages, setMessages] = useState<ChatMessage[]>([]);
|
|
@@ -93,20 +84,15 @@ export function BuddyAssistant({
|
|
|
93
84
|
return () => sender.cleanup();
|
|
94
85
|
}, [sender]);
|
|
95
86
|
|
|
96
|
-
// Build full API message list — when using server-side prompt, skip the client-side system message
|
|
97
87
|
const buildApiMessages = (history: ChatMessage[]) => {
|
|
98
|
-
|
|
99
|
-
if (!prompt && systemPrompt) {
|
|
100
|
-
return [{ role: 'system' as const, content: systemPrompt + dialectSystemSuffix }, ...msgs];
|
|
101
|
-
}
|
|
102
|
-
return msgs;
|
|
88
|
+
return history.map((m) => ({ role: m.role, content: m.content }));
|
|
103
89
|
};
|
|
104
90
|
|
|
105
91
|
const triggerAI = (history: ChatMessage[]) => {
|
|
106
92
|
setIsLoading(true);
|
|
107
|
-
void ai.
|
|
108
|
-
buildApiMessages(history),
|
|
109
|
-
(id: string, partial: string, finished: boolean) => {
|
|
93
|
+
void ai.getStreamedText({
|
|
94
|
+
messages: buildApiMessages(history),
|
|
95
|
+
onMessage: (id: string, partial: string, finished: boolean) => {
|
|
110
96
|
setIsLoading(!finished);
|
|
111
97
|
const assistantId = `ai-${id}`;
|
|
112
98
|
setMessages((prev) => {
|
|
@@ -122,12 +108,9 @@ export function BuddyAssistant({
|
|
|
122
108
|
}
|
|
123
109
|
},
|
|
124
110
|
tools,
|
|
125
|
-
false,
|
|
126
|
-
undefined,
|
|
127
|
-
undefined,
|
|
128
111
|
prompt,
|
|
129
|
-
promptVariables,
|
|
130
|
-
);
|
|
112
|
+
variables: promptVariables,
|
|
113
|
+
});
|
|
131
114
|
};
|
|
132
115
|
|
|
133
116
|
// Auto-start conversation on mount
|
|
@@ -1,22 +1,16 @@
|
|
|
1
|
-
/** @deprecated Use server-side prompt definitions (prompt + variables) instead of building messages client-side. */
|
|
2
1
|
export interface FirstMessages {
|
|
3
|
-
instructions?: string;
|
|
4
2
|
userMessage?: string;
|
|
5
3
|
assistantMessage?: string;
|
|
6
4
|
}
|
|
7
5
|
|
|
8
|
-
|
|
9
|
-
export function getFirstMessages(instructions: FirstMessages): any[] {
|
|
6
|
+
export function getFirstMessages(config: FirstMessages): any[] {
|
|
10
7
|
const messages = [];
|
|
11
8
|
|
|
12
|
-
if (
|
|
13
|
-
messages.push({ id: '1', role: '
|
|
9
|
+
if (config.userMessage) {
|
|
10
|
+
messages.push({ id: '1', role: 'user', content: config.userMessage });
|
|
14
11
|
}
|
|
15
|
-
if (
|
|
16
|
-
messages.push({ id: '2', role: '
|
|
17
|
-
}
|
|
18
|
-
if (instructions.assistantMessage) {
|
|
19
|
-
messages.push({ id: '3', role: 'assistant', content: instructions.assistantMessage });
|
|
12
|
+
if (config.assistantMessage) {
|
|
13
|
+
messages.push({ id: '2', role: 'assistant', content: config.assistantMessage });
|
|
20
14
|
}
|
|
21
15
|
|
|
22
16
|
return messages;
|
|
@@ -717,17 +717,11 @@ export const MarkdownEditor = ({
|
|
|
717
717
|
if (from === to) return;
|
|
718
718
|
const selectedText = editor.state.doc.textBetween(from, to, '\n');
|
|
719
719
|
setIsTransforming(true);
|
|
720
|
-
const transformed = await ai.getText(
|
|
721
|
-
|
|
722
|
-
|
|
723
|
-
|
|
724
|
-
|
|
725
|
-
},
|
|
726
|
-
{
|
|
727
|
-
role: 'user',
|
|
728
|
-
content: `Instruction: ${prompt}\n\nText:\n${selectedText}`,
|
|
729
|
-
},
|
|
730
|
-
]);
|
|
720
|
+
const transformed = await ai.getText({
|
|
721
|
+
messages: [],
|
|
722
|
+
prompt: 'global.editor.transform-text',
|
|
723
|
+
variables: { instruction: prompt, text: selectedText },
|
|
724
|
+
});
|
|
731
725
|
setIsTransforming(false);
|
|
732
726
|
if (!transformed) return;
|
|
733
727
|
editor.chain().focus().deleteRange({ from, to }).insertContentAt(from, transformed).run();
|
package/src/hooks/ThemeSetter.ts
CHANGED
|
@@ -1,8 +1,15 @@
|
|
|
1
1
|
import { Theme } from '@rimori/client';
|
|
2
2
|
|
|
3
|
-
export function useTheme(
|
|
3
|
+
export function useTheme(
|
|
4
|
+
theme: Theme = 'system',
|
|
5
|
+
isDisabled = false,
|
|
6
|
+
): { isDark: boolean; theme: Theme; isDisabled: boolean } {
|
|
4
7
|
const isDark = theme === 'system' ? systenUsesDarkMode() : theme === 'dark';
|
|
5
8
|
|
|
9
|
+
if (isDisabled) {
|
|
10
|
+
return { isDark, theme, isDisabled };
|
|
11
|
+
}
|
|
12
|
+
|
|
6
13
|
const dom = document.documentElement;
|
|
7
14
|
dom.dataset.theme = isDark ? 'dark' : 'light';
|
|
8
15
|
dom.style.colorScheme = isDark ? 'dark' : 'light';
|
|
@@ -19,7 +26,7 @@ export function useTheme(theme: Theme = 'system'): { isDark: boolean; theme: The
|
|
|
19
26
|
'bg-fixed',
|
|
20
27
|
);
|
|
21
28
|
|
|
22
|
-
return { isDark, theme };
|
|
29
|
+
return { isDark, theme, isDisabled };
|
|
23
30
|
}
|
|
24
31
|
|
|
25
32
|
function systenUsesDarkMode(): boolean {
|
package/src/hooks/UseChatHook.ts
CHANGED
|
@@ -13,8 +13,6 @@ export interface UseChatConfig {
|
|
|
13
13
|
export function useChat(
|
|
14
14
|
tools?: Tool[],
|
|
15
15
|
options?: {
|
|
16
|
-
/** @deprecated Use uuid variable with resolver 'knowledgeEntry' in prompt definitions instead. */
|
|
17
|
-
knowledgeId?: string;
|
|
18
16
|
/** Server-side prompt name (e.g. 'storytelling.story'). When set, the backend resolves the system prompt. */
|
|
19
17
|
prompt?: string;
|
|
20
18
|
/** Variables for the server-side prompt template. */
|
|
@@ -42,13 +40,12 @@ export function useChat(
|
|
|
42
40
|
const allMessages = [...messages, ...appendMessages];
|
|
43
41
|
setMessages(allMessages);
|
|
44
42
|
setIsLoading(true);
|
|
45
|
-
const knowledgeId = options?.knowledgeId;
|
|
46
43
|
const promptVariables = configRef.current.promptVariables ?? options?.promptVariables;
|
|
47
44
|
const prompt = configRef.current.prompt ?? options?.prompt;
|
|
48
45
|
|
|
49
|
-
void ai.
|
|
50
|
-
allMessages,
|
|
51
|
-
(id, message, finished: boolean, toolInvocations?: ToolInvocation[]) => {
|
|
46
|
+
void ai.getStreamedText({
|
|
47
|
+
messages: allMessages,
|
|
48
|
+
onMessage: (id, message, finished: boolean, toolInvocations?: ToolInvocation[]) => {
|
|
52
49
|
setIsLoading(!finished);
|
|
53
50
|
setMessages((prev) => {
|
|
54
51
|
const last = prev[prev.length - 1];
|
|
@@ -59,12 +56,9 @@ export function useChat(
|
|
|
59
56
|
});
|
|
60
57
|
},
|
|
61
58
|
tools,
|
|
62
|
-
false,
|
|
63
|
-
undefined,
|
|
64
|
-
knowledgeId,
|
|
65
59
|
prompt,
|
|
66
|
-
promptVariables,
|
|
67
|
-
);
|
|
60
|
+
variables: promptVariables,
|
|
61
|
+
});
|
|
68
62
|
};
|
|
69
63
|
|
|
70
64
|
return {
|
|
@@ -11,6 +11,12 @@ interface PluginProviderProps {
|
|
|
11
11
|
pluginId: string;
|
|
12
12
|
settings?: {
|
|
13
13
|
disableContextMenu?: boolean;
|
|
14
|
+
disableThemeSetting?: boolean;
|
|
15
|
+
/**
|
|
16
|
+
* Skip the scrollbar detection that emits 'session.triggerScrollbarChange'.
|
|
17
|
+
* In federation mode, the host (FederatedPluginRenderer) handles this instead.
|
|
18
|
+
*/
|
|
19
|
+
disableScrollbarDetection?: boolean;
|
|
14
20
|
};
|
|
15
21
|
}
|
|
16
22
|
|
|
@@ -28,7 +34,7 @@ export const PluginProvider: React.FC<PluginProviderProps> = ({ children, plugin
|
|
|
28
34
|
const [theme, setTheme] = useState<Theme | undefined>(undefined);
|
|
29
35
|
const [userInfo, setUserInfo] = useState<UserInfo | null>(null);
|
|
30
36
|
|
|
31
|
-
useTheme(theme);
|
|
37
|
+
useTheme(theme, settings?.disableThemeSetting);
|
|
32
38
|
|
|
33
39
|
// Init PostHog once per plugin iframe
|
|
34
40
|
useEffect(() => {
|
|
@@ -112,6 +118,7 @@ export const PluginProvider: React.FC<PluginProviderProps> = ({ children, plugin
|
|
|
112
118
|
|
|
113
119
|
useEffect(() => {
|
|
114
120
|
if (!client) return;
|
|
121
|
+
if (settings?.disableScrollbarDetection) return;
|
|
115
122
|
|
|
116
123
|
const checkScrollbar = (): void => {
|
|
117
124
|
const hasScrollbar = document.documentElement.scrollHeight > window.innerHeight;
|
|
@@ -133,7 +140,7 @@ export const PluginProvider: React.FC<PluginProviderProps> = ({ children, plugin
|
|
|
133
140
|
window.removeEventListener('resize', checkScrollbar);
|
|
134
141
|
resizeObserver.disconnect();
|
|
135
142
|
};
|
|
136
|
-
}, [client]);
|
|
143
|
+
}, [client, settings?.disableScrollbarDetection]);
|
|
137
144
|
|
|
138
145
|
if (standaloneClient instanceof StandaloneClient) {
|
|
139
146
|
return (
|