@rimori/react-client 0.4.2-next.1 → 0.4.2
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.js +3 -3
- package/dist/hooks/ThemeSetter.d.ts +2 -5
- package/dist/hooks/ThemeSetter.js +29 -11
- package/dist/providers/PluginProvider.js +5 -3
- package/package.json +3 -3
- package/src/components/ai/Avatar.tsx +3 -3
- package/src/hooks/ThemeSetter.ts +32 -12
- package/src/providers/PluginProvider.tsx +5 -4
|
@@ -6,14 +6,14 @@ import { CircleAudioAvatar } from './EmbeddedAssistent/CircleAudioAvatar';
|
|
|
6
6
|
import { useChat } from '../../hooks/UseChatHook';
|
|
7
7
|
import { useRimori } from '../../providers/PluginProvider';
|
|
8
8
|
import { getFirstMessages } from './utils';
|
|
9
|
-
import {
|
|
9
|
+
import { isDarkTheme } from '../../hooks/ThemeSetter';
|
|
10
10
|
export function Avatar({ avatarImageUrl, voiceId, agentTools, autoStartConversation, children, circleSize = '300px', className, }) {
|
|
11
|
-
const { ai, event
|
|
12
|
-
const { isDark: isDarkThemeValue } = useTheme(plugin.theme);
|
|
11
|
+
const { ai, event } = useRimori();
|
|
13
12
|
const [agentReplying, setAgentReplying] = useState(false);
|
|
14
13
|
const [isProcessingMessage, setIsProcessingMessage] = useState(false);
|
|
15
14
|
const sender = useMemo(() => new MessageSender(ai.getVoice, voiceId), [voiceId]);
|
|
16
15
|
const { messages, append, isLoading, lastMessage, setMessages } = useChat(agentTools);
|
|
16
|
+
const isDarkThemeValue = useMemo(() => isDarkTheme(), []);
|
|
17
17
|
useEffect(() => {
|
|
18
18
|
console.log('messages', messages);
|
|
19
19
|
}, [messages]);
|
|
@@ -1,5 +1,2 @@
|
|
|
1
|
-
|
|
2
|
-
export declare function
|
|
3
|
-
isDark: boolean;
|
|
4
|
-
theme: Theme;
|
|
5
|
-
};
|
|
1
|
+
export declare function useTheme(theme?: string | null): boolean;
|
|
2
|
+
export declare function isDarkTheme(theme?: string | null): boolean;
|
|
@@ -1,13 +1,31 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
const
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
1
|
+
import { useEffect, useState } from 'react';
|
|
2
|
+
export function useTheme(theme) {
|
|
3
|
+
const [isDark, setIsDark] = useState(false);
|
|
4
|
+
useEffect(() => {
|
|
5
|
+
const root = document.documentElement;
|
|
6
|
+
const nextIsDark = isDarkTheme(theme);
|
|
7
|
+
setIsDark(nextIsDark);
|
|
8
|
+
root.classList.add('dark:text-gray-200');
|
|
9
|
+
if (nextIsDark) {
|
|
10
|
+
root.setAttribute('data-theme', 'dark');
|
|
11
|
+
root.classList.add('dark', 'dark:bg-gray-950');
|
|
12
|
+
root.style.background = 'hsl(var(--background))';
|
|
13
|
+
return;
|
|
14
|
+
}
|
|
15
|
+
root.removeAttribute('data-theme');
|
|
16
|
+
root.classList.remove('dark', 'dark:bg-gray-950');
|
|
17
|
+
root.style.background = '';
|
|
18
|
+
}, [theme]);
|
|
19
|
+
return isDark;
|
|
10
20
|
}
|
|
11
|
-
function
|
|
12
|
-
|
|
21
|
+
export function isDarkTheme(theme) {
|
|
22
|
+
// If no theme provided, try to get from URL as fallback (for standalone mode)
|
|
23
|
+
if (!theme) {
|
|
24
|
+
const urlParams = new URLSearchParams(window.location.search);
|
|
25
|
+
theme = urlParams.get('theme');
|
|
26
|
+
}
|
|
27
|
+
if (!theme || theme === 'system') {
|
|
28
|
+
return window.matchMedia && window.matchMedia('(prefers-color-scheme: dark)').matches;
|
|
29
|
+
}
|
|
30
|
+
return theme === 'dark';
|
|
13
31
|
}
|
|
@@ -17,7 +17,7 @@ export const PluginProvider = ({ children, pluginId, settings }) => {
|
|
|
17
17
|
const [client, setClient] = useState(null);
|
|
18
18
|
const [standaloneClient, setStandaloneClient] = useState(false);
|
|
19
19
|
const [applicationMode, setApplicationMode] = useState(null);
|
|
20
|
-
const [theme, setTheme] = useState(
|
|
20
|
+
const [theme, setTheme] = useState(null);
|
|
21
21
|
const [userInfo, setUserInfo] = useState(null);
|
|
22
22
|
useTheme(theme);
|
|
23
23
|
const isSidebar = applicationMode === 'sidebar';
|
|
@@ -38,8 +38,10 @@ export const PluginProvider = ({ children, pluginId, settings }) => {
|
|
|
38
38
|
setUserInfo(client.plugin.getUserInfo());
|
|
39
39
|
// Get applicationMode and theme from MessageChannel query params
|
|
40
40
|
if (!standaloneDetected) {
|
|
41
|
-
|
|
42
|
-
|
|
41
|
+
const mode = client.getQueryParam('applicationMode');
|
|
42
|
+
const themeParam = client.getQueryParam('rm_theme');
|
|
43
|
+
setApplicationMode(mode);
|
|
44
|
+
setTheme(themeParam);
|
|
43
45
|
client.event.emit('self.rimori.triggerInitFinished');
|
|
44
46
|
}
|
|
45
47
|
});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@rimori/react-client",
|
|
3
|
-
"version": "0.4.2
|
|
3
|
+
"version": "0.4.2",
|
|
4
4
|
"license": "Apache-2.0",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -23,7 +23,7 @@
|
|
|
23
23
|
"format": "prettier --write ."
|
|
24
24
|
},
|
|
25
25
|
"peerDependencies": {
|
|
26
|
-
"@rimori/client": "2.5.
|
|
26
|
+
"@rimori/client": "^2.5.3",
|
|
27
27
|
"react": "^18.1.0",
|
|
28
28
|
"react-dom": "^18.1.0"
|
|
29
29
|
},
|
|
@@ -34,7 +34,7 @@
|
|
|
34
34
|
},
|
|
35
35
|
"devDependencies": {
|
|
36
36
|
"@eslint/js": "^9.37.0",
|
|
37
|
-
"@rimori/client": "2.5.
|
|
37
|
+
"@rimori/client": "^2.5.3",
|
|
38
38
|
"@types/react": "^18.3.21",
|
|
39
39
|
"eslint-config-prettier": "^10.1.8",
|
|
40
40
|
"eslint-plugin-prettier": "^5.5.4",
|
|
@@ -7,7 +7,7 @@ import { useChat } from '../../hooks/UseChatHook';
|
|
|
7
7
|
import { useRimori } from '../../providers/PluginProvider';
|
|
8
8
|
import { getFirstMessages } from './utils';
|
|
9
9
|
import { FirstMessages } from './utils';
|
|
10
|
-
import {
|
|
10
|
+
import { isDarkTheme } from '../../hooks/ThemeSetter';
|
|
11
11
|
|
|
12
12
|
interface Props {
|
|
13
13
|
voiceId: string;
|
|
@@ -28,12 +28,12 @@ export function Avatar({
|
|
|
28
28
|
circleSize = '300px',
|
|
29
29
|
className,
|
|
30
30
|
}: Props) {
|
|
31
|
-
const { ai, event
|
|
32
|
-
const { isDark: isDarkThemeValue } = useTheme(plugin.theme);
|
|
31
|
+
const { ai, event } = useRimori();
|
|
33
32
|
const [agentReplying, setAgentReplying] = useState(false);
|
|
34
33
|
const [isProcessingMessage, setIsProcessingMessage] = useState(false);
|
|
35
34
|
const sender = useMemo(() => new MessageSender(ai.getVoice, voiceId), [voiceId]);
|
|
36
35
|
const { messages, append, isLoading, lastMessage, setMessages } = useChat(agentTools);
|
|
36
|
+
const isDarkThemeValue = useMemo(() => isDarkTheme(), []);
|
|
37
37
|
|
|
38
38
|
useEffect(() => {
|
|
39
39
|
console.log('messages', messages);
|
package/src/hooks/ThemeSetter.ts
CHANGED
|
@@ -1,20 +1,40 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { useEffect, useState } from 'react';
|
|
2
2
|
|
|
3
|
-
export function useTheme(theme
|
|
4
|
-
const isDark =
|
|
3
|
+
export function useTheme(theme?: string | null): boolean {
|
|
4
|
+
const [isDark, setIsDark] = useState(false);
|
|
5
5
|
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
6
|
+
useEffect(() => {
|
|
7
|
+
const root = document.documentElement;
|
|
8
|
+
const nextIsDark = isDarkTheme(theme);
|
|
9
9
|
|
|
10
|
-
|
|
11
|
-
|
|
10
|
+
setIsDark(nextIsDark);
|
|
11
|
+
root.classList.add('dark:text-gray-200');
|
|
12
12
|
|
|
13
|
-
|
|
13
|
+
if (nextIsDark) {
|
|
14
|
+
root.setAttribute('data-theme', 'dark');
|
|
15
|
+
root.classList.add('dark', 'dark:bg-gray-950');
|
|
16
|
+
root.style.background = 'hsl(var(--background))';
|
|
17
|
+
return;
|
|
18
|
+
}
|
|
14
19
|
|
|
15
|
-
|
|
20
|
+
root.removeAttribute('data-theme');
|
|
21
|
+
root.classList.remove('dark', 'dark:bg-gray-950');
|
|
22
|
+
root.style.background = '';
|
|
23
|
+
}, [theme]);
|
|
24
|
+
|
|
25
|
+
return isDark;
|
|
16
26
|
}
|
|
17
27
|
|
|
18
|
-
function
|
|
19
|
-
|
|
28
|
+
export function isDarkTheme(theme?: string | null): boolean {
|
|
29
|
+
// If no theme provided, try to get from URL as fallback (for standalone mode)
|
|
30
|
+
if (!theme) {
|
|
31
|
+
const urlParams = new URLSearchParams(window.location.search);
|
|
32
|
+
theme = urlParams.get('theme');
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
if (!theme || theme === 'system') {
|
|
36
|
+
return window.matchMedia && window.matchMedia('(prefers-color-scheme: dark)').matches;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
return theme === 'dark';
|
|
20
40
|
}
|
|
@@ -3,7 +3,6 @@ import { EventBusHandler, RimoriClient, StandaloneClient } from '@rimori/client'
|
|
|
3
3
|
import type { UserInfo } from '@rimori/client';
|
|
4
4
|
import ContextMenu from '../components/ContextMenu';
|
|
5
5
|
import { useTheme } from '../hooks/ThemeSetter';
|
|
6
|
-
import { Theme } from '@rimori/client';
|
|
7
6
|
|
|
8
7
|
interface PluginProviderProps {
|
|
9
8
|
children: ReactNode;
|
|
@@ -24,7 +23,7 @@ export const PluginProvider: React.FC<PluginProviderProps> = ({ children, plugin
|
|
|
24
23
|
const [client, setClient] = useState<RimoriClient | null>(null);
|
|
25
24
|
const [standaloneClient, setStandaloneClient] = useState<StandaloneClient | boolean>(false);
|
|
26
25
|
const [applicationMode, setApplicationMode] = useState<string | null>(null);
|
|
27
|
-
const [theme, setTheme] = useState<
|
|
26
|
+
const [theme, setTheme] = useState<string | null>(null);
|
|
28
27
|
const [userInfo, setUserInfo] = useState<UserInfo | null>(null);
|
|
29
28
|
|
|
30
29
|
useTheme(theme);
|
|
@@ -52,8 +51,10 @@ export const PluginProvider: React.FC<PluginProviderProps> = ({ children, plugin
|
|
|
52
51
|
|
|
53
52
|
// Get applicationMode and theme from MessageChannel query params
|
|
54
53
|
if (!standaloneDetected) {
|
|
55
|
-
|
|
56
|
-
|
|
54
|
+
const mode = client.getQueryParam('applicationMode');
|
|
55
|
+
const themeParam = client.getQueryParam('rm_theme');
|
|
56
|
+
setApplicationMode(mode);
|
|
57
|
+
setTheme(themeParam);
|
|
57
58
|
client.event.emit('self.rimori.triggerInitFinished');
|
|
58
59
|
}
|
|
59
60
|
});
|