@rimori/react-client 0.4.17 → 0.4.18-next.0
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 +5 -4
- package/dist/components/ai/Avatar.js +8 -3
- package/dist/components/ai/BuddyAssistant.d.ts +7 -4
- package/dist/components/ai/BuddyAssistant.js +35 -38
- 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 +13 -8
- package/src/components/ai/BuddyAssistant.tsx +37 -52
- 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
|
@@ -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 (
|