@rimori/react-client 0.1.0 → 0.2.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.
Files changed (115) hide show
  1. package/README.md +142 -1
  2. package/dist/{react-client/src/components → components}/ContextMenu.js +1 -2
  3. package/dist/components/Spinner.d.ts +0 -7
  4. package/dist/components/Spinner.js +1 -4
  5. package/dist/components/ai/Assistant.js +1 -1
  6. package/dist/components/ai/Avatar.d.ts +2 -3
  7. package/dist/components/ai/Avatar.js +6 -4
  8. package/dist/components/ai/EmbeddedAssistent/AudioInputField.js +1 -1
  9. package/dist/components/ai/EmbeddedAssistent/CircleAudioAvatar.js +1 -1
  10. package/dist/components/ai/EmbeddedAssistent/VoiceRecoder.js +2 -2
  11. package/dist/components/audio/Playbutton.js +13 -9
  12. package/dist/hooks/I18nHooks.d.ts +1 -1
  13. package/dist/{react-client/src/plugin → hooks}/ThemeSetter.d.ts +1 -1
  14. package/dist/hooks/ThemeSetter.js +31 -0
  15. package/dist/hooks/UseChatHook.d.ts +2 -2
  16. package/dist/index.d.ts +9 -0
  17. package/dist/index.js +9 -0
  18. package/dist/{react-client/plugin → plugin}/ThemeSetter.d.ts +1 -1
  19. package/dist/plugin/ThemeSetter.js +31 -0
  20. package/dist/providers/PluginProvider.d.ts +2 -1
  21. package/dist/providers/PluginProvider.js +10 -7
  22. package/dist/{react-client/src/utils → utils}/FullscreenUtils.js +2 -2
  23. package/package.json +4 -7
  24. package/src/components/ContextMenu.tsx +2 -2
  25. package/src/components/ai/Avatar.tsx +9 -4
  26. package/src/components/ai/EmbeddedAssistent/AudioInputField.tsx +1 -1
  27. package/src/components/audio/Playbutton.tsx +28 -1
  28. package/src/hooks/ThemeSetter.ts +40 -0
  29. package/src/index.ts +10 -0
  30. package/src/providers/PluginProvider.tsx +12 -8
  31. package/tsconfig.json +6 -12
  32. package/dist/components/components/ContextMenu.d.ts +0 -10
  33. package/dist/components/components/ContextMenu.js +0 -135
  34. package/dist/react-client/plugin/ThemeSetter.js +0 -19
  35. package/dist/react-client/src/components/MarkdownEditor.d.ts +0 -8
  36. package/dist/react-client/src/components/MarkdownEditor.js +0 -48
  37. package/dist/react-client/src/components/Spinner.d.ts +0 -8
  38. package/dist/react-client/src/components/Spinner.js +0 -4
  39. package/dist/react-client/src/components/ai/Assistant.d.ts +0 -9
  40. package/dist/react-client/src/components/ai/Assistant.js +0 -58
  41. package/dist/react-client/src/components/ai/Avatar.d.ts +0 -14
  42. package/dist/react-client/src/components/ai/Avatar.js +0 -59
  43. package/dist/react-client/src/components/ai/EmbeddedAssistent/AudioInputField.d.ts +0 -7
  44. package/dist/react-client/src/components/ai/EmbeddedAssistent/AudioInputField.js +0 -37
  45. package/dist/react-client/src/components/ai/EmbeddedAssistent/CircleAudioAvatar.d.ts +0 -8
  46. package/dist/react-client/src/components/ai/EmbeddedAssistent/CircleAudioAvatar.js +0 -79
  47. package/dist/react-client/src/components/ai/EmbeddedAssistent/TTS/MessageSender.d.ts +0 -19
  48. package/dist/react-client/src/components/ai/EmbeddedAssistent/TTS/MessageSender.js +0 -91
  49. package/dist/react-client/src/components/ai/EmbeddedAssistent/TTS/Player.d.ts +0 -27
  50. package/dist/react-client/src/components/ai/EmbeddedAssistent/TTS/Player.js +0 -185
  51. package/dist/react-client/src/components/ai/utils.d.ts +0 -6
  52. package/dist/react-client/src/components/ai/utils.js +0 -13
  53. package/dist/react-client/src/components/audio/Playbutton.d.ts +0 -15
  54. package/dist/react-client/src/components/audio/Playbutton.js +0 -82
  55. package/dist/react-client/src/components/components/ContextMenu.d.ts +0 -10
  56. package/dist/react-client/src/components/components/ContextMenu.js +0 -135
  57. package/dist/react-client/src/hooks/I18nHooks.d.ts +0 -11
  58. package/dist/react-client/src/hooks/I18nHooks.js +0 -25
  59. package/dist/react-client/src/hooks/UseChatHook.d.ts +0 -10
  60. package/dist/react-client/src/hooks/UseChatHook.js +0 -29
  61. package/dist/react-client/src/plugin/ThemeSetter.js +0 -19
  62. package/dist/react-client/src/providers/PluginProvider.d.ts +0 -12
  63. package/dist/react-client/src/providers/PluginProvider.js +0 -142
  64. package/dist/react-client/src/utils/PluginUtils.d.ts +0 -2
  65. package/dist/react-client/src/utils/PluginUtils.js +0 -23
  66. package/dist/rimori-client/src/cli/types/DatabaseTypes.d.ts +0 -103
  67. package/dist/rimori-client/src/cli/types/DatabaseTypes.js +0 -2
  68. package/dist/rimori-client/src/controller/AIController.d.ts +0 -15
  69. package/dist/rimori-client/src/controller/AIController.js +0 -255
  70. package/dist/rimori-client/src/controller/AccomplishmentController.d.ts +0 -38
  71. package/dist/rimori-client/src/controller/AccomplishmentController.js +0 -112
  72. package/dist/rimori-client/src/controller/AudioController.d.ts +0 -37
  73. package/dist/rimori-client/src/controller/AudioController.js +0 -68
  74. package/dist/rimori-client/src/controller/ExerciseController.d.ts +0 -54
  75. package/dist/rimori-client/src/controller/ExerciseController.js +0 -74
  76. package/dist/rimori-client/src/controller/ObjectController.d.ts +0 -42
  77. package/dist/rimori-client/src/controller/ObjectController.js +0 -76
  78. package/dist/rimori-client/src/controller/SettingsController.d.ts +0 -79
  79. package/dist/rimori-client/src/controller/SettingsController.js +0 -118
  80. package/dist/rimori-client/src/controller/SharedContentController.d.ts +0 -106
  81. package/dist/rimori-client/src/controller/SharedContentController.js +0 -285
  82. package/dist/rimori-client/src/controller/TranslationController.d.ts +0 -38
  83. package/dist/rimori-client/src/controller/TranslationController.js +0 -106
  84. package/dist/rimori-client/src/controller/VoiceController.d.ts +0 -9
  85. package/dist/rimori-client/src/controller/VoiceController.js +0 -37
  86. package/dist/rimori-client/src/fromRimori/EventBus.d.ts +0 -101
  87. package/dist/rimori-client/src/fromRimori/EventBus.js +0 -263
  88. package/dist/rimori-client/src/fromRimori/PluginTypes.d.ts +0 -174
  89. package/dist/rimori-client/src/fromRimori/PluginTypes.js +0 -1
  90. package/dist/rimori-client/src/index.d.ts +0 -11
  91. package/dist/rimori-client/src/index.js +0 -10
  92. package/dist/rimori-client/src/plugin/CommunicationHandler.d.ts +0 -48
  93. package/dist/rimori-client/src/plugin/CommunicationHandler.js +0 -234
  94. package/dist/rimori-client/src/plugin/Logger.d.ts +0 -73
  95. package/dist/rimori-client/src/plugin/Logger.js +0 -308
  96. package/dist/rimori-client/src/plugin/RimoriClient.d.ts +0 -258
  97. package/dist/rimori-client/src/plugin/RimoriClient.js +0 -375
  98. package/dist/rimori-client/src/plugin/StandaloneClient.d.ts +0 -17
  99. package/dist/rimori-client/src/plugin/StandaloneClient.js +0 -115
  100. package/dist/rimori-client/src/utils/difficultyConverter.d.ts +0 -4
  101. package/dist/rimori-client/src/utils/difficultyConverter.js +0 -10
  102. package/dist/rimori-client/src/utils/endpoint.d.ts +0 -2
  103. package/dist/rimori-client/src/utils/endpoint.js +0 -2
  104. package/dist/utils/PluginUtils.d.ts +0 -2
  105. package/dist/utils/PluginUtils.js +0 -23
  106. package/index.ts +0 -6
  107. package/src/components/MarkdownEditor.tsx +0 -144
  108. package/src/components/Spinner.tsx +0 -29
  109. package/src/plugin/ThemeSetter.ts +0 -23
  110. package/src/utils/FullscreenUtils.ts +0 -22
  111. /package/dist/{react-client/src/components → components}/ContextMenu.d.ts +0 -0
  112. /package/dist/{react-client/src/components/ai/EmbeddedAssistent/VoiceRecoder.d.ts → components/ai/EmbeddedAssistent/VoiceRecorder.d.ts} +0 -0
  113. /package/dist/{react-client/src/components/ai/EmbeddedAssistent/VoiceRecoder.js → components/ai/EmbeddedAssistent/VoiceRecorder.js} +0 -0
  114. /package/dist/{react-client/src/utils → utils}/FullscreenUtils.d.ts +0 -0
  115. /package/src/components/ai/EmbeddedAssistent/{VoiceRecoder.tsx → VoiceRecorder.tsx} +0 -0
@@ -1,7 +1,6 @@
1
1
  import React, { useState, useEffect } from 'react';
2
2
  import { FaPlayCircle, FaStopCircle } from 'react-icons/fa';
3
3
  import { useRimori } from '../../providers/PluginProvider';
4
- import { Spinner } from '../Spinner';
5
4
  import { EventBus } from '@rimori/client';
6
5
 
7
6
  type AudioPlayerProps = {
@@ -124,3 +123,31 @@ export const AudioPlayer: React.FC<AudioPlayerProps> = ({
124
123
  </div>
125
124
  );
126
125
  };
126
+
127
+ interface SpinnerProps {
128
+ text?: string;
129
+ size?: string;
130
+ className?: string;
131
+ }
132
+
133
+ const Spinner = ({ text, className, size = '30px' }: SpinnerProps) => {
134
+ return (
135
+ <div className={'flex items-center space-x-2 ' + className}>
136
+ <svg
137
+ style={{ width: size, height: size }}
138
+ className="animate-spin -ml-1 mr-3 h-5 w-5 text-white"
139
+ xmlns="http://www.w3.org/2000/svg"
140
+ fill="none"
141
+ viewBox="0 0 24 24"
142
+ >
143
+ <circle className="opacity-25" cx="12" cy="12" r="10" stroke="currentColor" strokeWidth="4"></circle>
144
+ <path
145
+ className="opacity-75"
146
+ fill="currentColor"
147
+ 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"
148
+ ></path>
149
+ </svg>
150
+ {text && <span className="">{text}</span>}
151
+ </div>
152
+ );
153
+ };
@@ -0,0 +1,40 @@
1
+ import { useEffect, useState } from 'react';
2
+
3
+ export function useTheme(theme?: string | null): boolean {
4
+ const [isDark, setIsDark] = useState(false);
5
+
6
+ useEffect(() => {
7
+ const root = document.documentElement;
8
+ const nextIsDark = isDarkTheme(theme);
9
+
10
+ setIsDark(nextIsDark);
11
+ root.classList.add('dark:text-gray-200');
12
+
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
+ }
19
+
20
+ root.removeAttribute('data-theme');
21
+ root.classList.remove('dark', 'dark:bg-gray-950');
22
+ root.style.background = '';
23
+ }, [theme]);
24
+
25
+ return isDark;
26
+ }
27
+
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';
40
+ }
package/src/index.ts ADDED
@@ -0,0 +1,10 @@
1
+ // Re-export everything
2
+ export * from './hooks/UseChatHook';
3
+ export * from './providers/PluginProvider';
4
+ export * from './components/audio/Playbutton';
5
+ export * from './components/ai/EmbeddedAssistent/TTS/Player';
6
+ export * from './components/ai/Avatar';
7
+ export { FirstMessages } from './components/ai/utils';
8
+ export { useTranslation } from './hooks/I18nHooks';
9
+ export { Avatar } from './components/ai/Avatar';
10
+ export { VoiceRecorder } from './components/ai/EmbeddedAssistent/VoiceRecorder';
@@ -1,6 +1,7 @@
1
1
  import React, { createContext, useContext, ReactNode, useEffect, useState } from 'react';
2
2
  import { EventBusHandler, RimoriClient, StandaloneClient } from '@rimori/client';
3
3
  import ContextMenu from '../components/ContextMenu';
4
+ import { useTheme } from '../hooks/ThemeSetter';
4
5
 
5
6
  interface PluginProviderProps {
6
7
  children: ReactNode;
@@ -18,6 +19,8 @@ export const PluginProvider: React.FC<PluginProviderProps> = ({ children, plugin
18
19
  const [applicationMode, setApplicationMode] = useState<string | null>(null);
19
20
  const [theme, setTheme] = useState<string | null>(null);
20
21
 
22
+ useTheme(theme);
23
+
21
24
  const isSidebar = applicationMode === 'sidebar';
22
25
  const isSettings = applicationMode === 'settings';
23
26
 
@@ -28,13 +31,13 @@ export const PluginProvider: React.FC<PluginProviderProps> = ({ children, plugin
28
31
  const standaloneDetected = window === window.parent;
29
32
 
30
33
  if (standaloneDetected && !standaloneClient) {
31
- StandaloneClient.getInstance().then((client) => {
32
- client.needsLogin().then((needLogin) => setStandaloneClient(needLogin ? client : true));
34
+ void StandaloneClient.getInstance().then((client) => {
35
+ void client.needsLogin().then((needLogin) => setStandaloneClient(needLogin ? client : true));
33
36
  });
34
37
  }
35
38
 
36
39
  if ((!standaloneDetected && !plugin) || (standaloneDetected && standaloneClient === true)) {
37
- RimoriClient.getInstance(pluginId).then((client) => {
40
+ void RimoriClient.getInstance(pluginId).then((client) => {
38
41
  setPlugin(client);
39
42
  // Get applicationMode and theme from MessageChannel query params
40
43
  if (!standaloneDetected) {
@@ -42,10 +45,11 @@ export const PluginProvider: React.FC<PluginProviderProps> = ({ children, plugin
42
45
  const themeParam = client.getQueryParam('rm_theme');
43
46
  setApplicationMode(mode);
44
47
  setTheme(themeParam);
48
+ client.event.emit('self.rimori.triggerInitFinished');
45
49
  }
46
50
  });
47
51
  }
48
- }, [pluginId, standaloneClient]);
52
+ }, [pluginId, standaloneClient, plugin]);
49
53
 
50
54
  //route change
51
55
  useEffect(() => {
@@ -66,7 +70,7 @@ export const PluginProvider: React.FC<PluginProviderProps> = ({ children, plugin
66
70
 
67
71
  emitUrlChange(lastHash);
68
72
  return () => clearInterval(interval);
69
- }, [plugin]);
73
+ }, [plugin, isSidebar]);
70
74
 
71
75
  if (standaloneClient instanceof StandaloneClient) {
72
76
  return (
@@ -98,7 +102,7 @@ export const useRimori = () => {
98
102
  return context;
99
103
  };
100
104
 
101
- function getUrlParam(name: string) {
105
+ function getUrlParam(name: string): string | null {
102
106
  // First try to get from URL hash query params (for compatibility)
103
107
  const hashParts = window.location.hash.split('?');
104
108
  if (hashParts.length > 1) {
@@ -112,13 +116,13 @@ function getUrlParam(name: string) {
112
116
  return url.searchParams.get(name);
113
117
  }
114
118
 
115
- function initEventBus(pluginId: string) {
119
+ function initEventBus(pluginId: string): void {
116
120
  // For now, use URL fallback for EventBus naming - this will be updated once MessageChannel is ready
117
121
  const isSidebar = getUrlParam('applicationMode') === 'sidebar';
118
122
  EventBusHandler.getInstance('Plugin EventBus ' + pluginId + ' ' + (isSidebar ? 'sidebar' : 'main'));
119
123
  }
120
124
 
121
- function StandaloneAuth({ onLogin }: { onLogin: (user: string, password: string) => void }) {
125
+ function StandaloneAuth({ onLogin }: { onLogin: (user: string, password: string) => void }): JSX.Element {
122
126
  const [user, setUser] = useState('');
123
127
  const [password, setPassword] = useState('');
124
128
  return (
package/tsconfig.json CHANGED
@@ -1,6 +1,7 @@
1
1
  {
2
2
  "compilerOptions": {
3
3
  "outDir": "dist",
4
+ "rootDir": "src",
4
5
  "module": "ESNext",
5
6
  "target": "ES6",
6
7
  "declaration": true,
@@ -8,16 +9,9 @@
8
9
  "moduleResolution": "node",
9
10
  "esModuleInterop": true,
10
11
  "skipLibCheck": true,
11
- "strict": true,
12
- "baseUrl": ".",
13
- "paths": {
14
- "@rimori/client": [
15
- "../rimori-client/src/index.ts"
16
- ],
17
- "@rimori/client/*": [
18
- "../rimori-client/src/*"
19
- ]
20
- }
12
+ "strict": true
21
13
  },
22
- "include": ["src/**/*"]
23
- }
14
+ "include": [
15
+ "src/**/*"
16
+ ]
17
+ }
@@ -1,10 +0,0 @@
1
- import { RimoriClient } from '../../plugin/RimoriClient';
2
- export interface Position {
3
- x: number;
4
- y: number;
5
- text?: string;
6
- }
7
- declare const ContextMenu: ({ client }: {
8
- client: RimoriClient;
9
- }) => import("react/jsx-runtime").JSX.Element | null;
10
- export default ContextMenu;
@@ -1,135 +0,0 @@
1
- import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
- import { useState, useEffect, useRef } from 'react';
3
- import { EventBus } from '../../fromRimori/EventBus';
4
- const ContextMenu = ({ client }) => {
5
- const [isOpen, setIsOpen] = useState(false);
6
- const [actions, setActions] = useState([]);
7
- const [position, setPosition] = useState({ x: 0, y: 0 });
8
- const [openOnTextSelect, setOpenOnTextSelect] = useState(false);
9
- const [menuWidth, setMenuWidth] = useState(0);
10
- const menuRef = useRef(null);
11
- const isMobile = window.innerWidth < 768;
12
- /**
13
- * Calculates position for mobile context menu based on selected text bounds.
14
- * Centers the menu horizontally over the selected text and positions it 30px below the text's end.
15
- * @param selectedText - The currently selected text
16
- * @param menuWidth - The width of the menu to center properly
17
- * @returns Position object with x and y coordinates
18
- */
19
- const calculateMobilePosition = (selectedText, menuWidth = 0) => {
20
- const selection = window.getSelection();
21
- if (!selection || !selectedText) {
22
- return { x: 0, y: 0, text: selectedText };
23
- }
24
- const range = selection.getRangeAt(0);
25
- const rect = range.getBoundingClientRect();
26
- // Center horizontally over the selected text, accounting for menu width
27
- const centerX = rect.left + rect.width / 2 - menuWidth / 2;
28
- // Position 12px below where the text ends vertically
29
- const textEndY = rect.bottom + 12;
30
- return { x: centerX, y: textEndY, text: selectedText };
31
- };
32
- useEffect(() => {
33
- const actions = client.plugin
34
- .getPluginInfo()
35
- .installedPlugins.flatMap((p) => p.context_menu_actions)
36
- .filter(Boolean);
37
- setActions(actions);
38
- setOpenOnTextSelect(client.plugin.getUserInfo().context_menu_on_select);
39
- EventBus.on('global.contextMenu.createActions', ({ data }) => {
40
- setActions([...data.actions, ...actions]);
41
- });
42
- }, []);
43
- // Update menu width when menu is rendered
44
- useEffect(() => {
45
- if (isOpen && menuRef.current) {
46
- setMenuWidth(menuRef.current.offsetWidth);
47
- }
48
- }, [isOpen, actions]);
49
- useEffect(() => {
50
- // Track mouse position globally
51
- const handleMouseMove = (e) => {
52
- var _a;
53
- const selectedText = (_a = window.getSelection()) === null || _a === void 0 ? void 0 : _a.toString().trim();
54
- if (isOpen && selectedText === position.text)
55
- return;
56
- if (isMobile && selectedText) {
57
- setPosition(calculateMobilePosition(selectedText, menuWidth));
58
- }
59
- else {
60
- setPosition({ x: e.clientX, y: e.clientY, text: selectedText });
61
- }
62
- };
63
- const handleMouseUp = (e) => {
64
- var _a, _b;
65
- const selectedText = (_a = window.getSelection()) === null || _a === void 0 ? void 0 : _a.toString().trim();
66
- // Check if click is inside the context menu
67
- if (menuRef.current && menuRef.current.contains(e.target)) {
68
- // Don't close the menu if clicking inside
69
- return;
70
- }
71
- // Prevent context menu on textarea or text input selection
72
- const target = e.target;
73
- const isTextInput = target &&
74
- (target.tagName === 'TEXTAREA' || (target.tagName === 'INPUT' && target.type === 'text'));
75
- if (isTextInput) {
76
- setIsOpen(false);
77
- return;
78
- }
79
- if (e.button === 0 && isOpen) {
80
- setIsOpen(false);
81
- (_b = window.getSelection()) === null || _b === void 0 ? void 0 : _b.removeAllRanges();
82
- }
83
- else if (selectedText && (openOnTextSelect || e.button === 2)) {
84
- if (e.button === 2) {
85
- e.preventDefault();
86
- }
87
- if (isMobile) {
88
- setPosition(calculateMobilePosition(selectedText, menuWidth));
89
- }
90
- else {
91
- setPosition({ x: e.clientX, y: e.clientY, text: selectedText });
92
- }
93
- setIsOpen(true);
94
- }
95
- else {
96
- setIsOpen(false);
97
- }
98
- };
99
- // Add selectionchange listener to close menu if selection is cleared and update position for mobile
100
- const handleSelectionChange = () => {
101
- var _a;
102
- const selectedText = (_a = window.getSelection()) === null || _a === void 0 ? void 0 : _a.toString().trim();
103
- if (!selectedText && isOpen) {
104
- setIsOpen(false);
105
- }
106
- else if (selectedText && isOpen && isMobile) {
107
- // Update position in real-time as text selection changes on mobile
108
- setPosition(calculateMobilePosition(selectedText, menuWidth));
109
- }
110
- };
111
- document.addEventListener('mouseup', handleMouseUp);
112
- window.addEventListener('mousemove', handleMouseMove);
113
- document.addEventListener('contextmenu', handleMouseUp);
114
- document.addEventListener('selectionchange', handleSelectionChange);
115
- return () => {
116
- document.removeEventListener('mouseup', handleMouseUp);
117
- window.removeEventListener('mousemove', handleMouseMove);
118
- document.removeEventListener('contextmenu', handleMouseUp);
119
- document.removeEventListener('selectionchange', handleSelectionChange);
120
- };
121
- }, [openOnTextSelect, isOpen, position.text]);
122
- if (!isOpen) {
123
- return null;
124
- }
125
- return (_jsx("div", { ref: menuRef, className: "fixed bg-gray-400 dark:bg-gray-700 shadow-lg border border-gray-400 rounded-md overflow-hidden dark:text-white z-50", style: { top: position.y, left: position.x }, children: actions.map((action, index) => (_jsx(MenuEntryItem, { icon: action.icon, text: action.text, onClick: () => {
126
- var _a;
127
- setIsOpen(false);
128
- (_a = window.getSelection()) === null || _a === void 0 ? void 0 : _a.removeAllRanges();
129
- client.event.emitSidebarAction(action.plugin_id, action.action_key, position.text);
130
- } }, index))) }));
131
- };
132
- function MenuEntryItem(props) {
133
- return (_jsxs("button", { onClick: props.onClick, className: "px-4 py-2 text-left hover:bg-gray-500 dark:hover:bg-gray-600 w-full flex flex-row", children: [_jsx("span", { className: "flex-grow", children: props.icon }), _jsx("span", { className: "flex-grow", children: props.text })] }));
134
- }
135
- export default ContextMenu;
@@ -1,19 +0,0 @@
1
- export function setTheme(theme) {
2
- document.documentElement.classList.add('dark:text-gray-200');
3
- if (isDarkTheme(theme)) {
4
- document.documentElement.setAttribute('data-theme', 'dark');
5
- document.documentElement.classList.add('dark', 'dark:bg-gray-950');
6
- document.documentElement.style.background = 'hsl(var(--background))';
7
- }
8
- }
9
- export function isDarkTheme(theme) {
10
- // If no theme provided, try to get from URL as fallback (for standalone mode)
11
- if (!theme) {
12
- const urlParams = new URLSearchParams(window.location.search);
13
- theme = urlParams.get('theme');
14
- }
15
- if (!theme || theme === 'system') {
16
- return window.matchMedia && window.matchMedia('(prefers-color-scheme: dark)').matches;
17
- }
18
- return theme === 'dark';
19
- }
@@ -1,8 +0,0 @@
1
- interface Props {
2
- content?: string;
3
- editable: boolean;
4
- className?: string;
5
- onUpdate?: (content: string) => void;
6
- }
7
- export declare const MarkdownEditor: (props: Props) => import("react/jsx-runtime").JSX.Element;
8
- export {};
@@ -1,48 +0,0 @@
1
- import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
- import { Markdown } from 'tiptap-markdown';
3
- import StarterKit from '@tiptap/starter-kit';
4
- import { PiCodeBlock } from 'react-icons/pi';
5
- import { TbBlockquote } from 'react-icons/tb';
6
- import { GoListOrdered } from 'react-icons/go';
7
- import { AiOutlineUnorderedList } from 'react-icons/ai';
8
- import { EditorProvider, useCurrentEditor } from '@tiptap/react';
9
- import { LuHeading1, LuHeading2, LuHeading3 } from 'react-icons/lu';
10
- import { FaBold, FaCode, FaItalic, FaParagraph, FaStrikethrough } from 'react-icons/fa';
11
- const EditorButton = ({ action, isActive, label, disabled }) => {
12
- const { editor } = useCurrentEditor();
13
- if (!editor) {
14
- return null;
15
- }
16
- if (action.includes('heading')) {
17
- const level = parseInt(action[action.length - 1]);
18
- return (_jsx("button", { onClick: () => editor.chain().focus().toggleHeading({ level: level }).run(), className: `pl-2 ${isActive ? 'is-active' : ''}`, children: label }));
19
- }
20
- return (_jsx("button", { onClick: () => editor.chain().focus()[action]().run(), disabled: disabled ? !editor.can().chain().focus()[action]().run() : false, className: `pl-2 ${isActive ? 'is-active' : ''}`, children: label }));
21
- };
22
- const MenuBar = () => {
23
- const { editor } = useCurrentEditor();
24
- if (!editor) {
25
- return null;
26
- }
27
- return (_jsxs("div", { className: "bg-gray-400 dark:bg-gray-800 dark:text-white text-lg flex flex-row flex-wrap items-center p-1", children: [_jsx(EditorButton, { action: "toggleBold", isActive: editor.isActive('bold'), label: _jsx(FaBold, {}), disabled: true }), _jsx(EditorButton, { action: "toggleItalic", isActive: editor.isActive('italic'), label: _jsx(FaItalic, {}), disabled: true }), _jsx(EditorButton, { action: "toggleStrike", isActive: editor.isActive('strike'), label: _jsx(FaStrikethrough, {}), disabled: true }), _jsx(EditorButton, { action: "toggleCode", isActive: editor.isActive('code'), label: _jsx(FaCode, {}), disabled: true }), _jsx(EditorButton, { action: "setParagraph", isActive: editor.isActive('paragraph'), label: _jsx(FaParagraph, {}) }), _jsx(EditorButton, { action: "setHeading1", isActive: editor.isActive('heading', { level: 1 }), label: _jsx(LuHeading1, { size: '24px' }) }), _jsx(EditorButton, { action: "setHeading2", isActive: editor.isActive('heading', { level: 2 }), label: _jsx(LuHeading2, { size: '24px' }) }), _jsx(EditorButton, { action: "setHeading3", isActive: editor.isActive('heading', { level: 3 }), label: _jsx(LuHeading3, { size: '24px' }) }), _jsx(EditorButton, { action: "toggleBulletList", isActive: editor.isActive('bulletList'), label: _jsx(AiOutlineUnorderedList, { size: '24px' }) }), _jsx(EditorButton, { action: "toggleOrderedList", isActive: editor.isActive('orderedList'), label: _jsx(GoListOrdered, { size: '24px' }) }), _jsx(EditorButton, { action: "toggleCodeBlock", isActive: editor.isActive('codeBlock'), label: _jsx(PiCodeBlock, { size: '24px' }) }), _jsx(EditorButton, { action: "toggleBlockquote", isActive: editor.isActive('blockquote'), label: _jsx(TbBlockquote, { size: '24px' }) })] }));
28
- };
29
- const extensions = [
30
- StarterKit.configure({
31
- bulletList: {
32
- HTMLAttributes: {
33
- class: 'list-disc list-inside dark:text-white p-1 mt-1 [&_li]:mb-1 [&_p]:inline m-0',
34
- },
35
- },
36
- orderedList: {
37
- HTMLAttributes: {
38
- className: 'list-decimal list-inside dark:text-white p-1 mt-1 [&_li]:mb-1 [&_p]:inline m-0',
39
- },
40
- },
41
- }),
42
- Markdown,
43
- ];
44
- export const MarkdownEditor = (props) => {
45
- return (_jsx("div", { className: 'text-md border border-gray-800 overflow-hidden ' + props.className, style: { borderWidth: props.editable ? 1 : 0 }, children: _jsx(EditorProvider, { slotBefore: props.editable ? _jsx(MenuBar, {}) : null, extensions: extensions, content: props.content, editable: props.editable, onUpdate: (e) => {
46
- props.onUpdate && props.onUpdate(e.editor.storage.markdown.getMarkdown());
47
- } }, (props.editable ? 'editable' : 'readonly') + props.content) }));
48
- };
@@ -1,8 +0,0 @@
1
- import React from 'react';
2
- interface SpinnerProps {
3
- text?: string;
4
- size?: string;
5
- className?: string;
6
- }
7
- export declare const Spinner: React.FC<SpinnerProps>;
8
- export {};
@@ -1,4 +0,0 @@
1
- import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
- export const Spinner = ({ text, className, size = '30px' }) => {
3
- 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 })] }));
4
- };
@@ -1,9 +0,0 @@
1
- import { FirstMessages } from './utils';
2
- interface Props {
3
- voiceId: any;
4
- avatarImageUrl: string;
5
- onComplete: (result: any) => void;
6
- autoStartConversation?: FirstMessages;
7
- }
8
- export declare function AssistantChat({ avatarImageUrl, voiceId, onComplete, autoStartConversation }: Props): import("react/jsx-runtime").JSX.Element;
9
- export {};
@@ -1,58 +0,0 @@
1
- import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
- import React, { useEffect, useMemo } from 'react';
3
- import { CircleAudioAvatar } from './EmbeddedAssistent/CircleAudioAvatar';
4
- import { AudioInputField } from './EmbeddedAssistent/AudioInputField';
5
- import { MessageSender } from './EmbeddedAssistent/TTS/MessageSender';
6
- import Markdown from 'react-markdown';
7
- import { useChat } from '../../hooks/UseChatHook';
8
- import { useRimori } from '../../providers/PluginProvider';
9
- import { getFirstMessages } from './utils';
10
- export function AssistantChat({ avatarImageUrl, voiceId, onComplete, autoStartConversation }) {
11
- var _a;
12
- const [oralCommunication, setOralCommunication] = React.useState(true);
13
- const { ai: llm, event } = useRimori();
14
- const sender = useMemo(() => new MessageSender(llm.getVoice, voiceId), []);
15
- const { messages, append, isLoading, setMessages } = useChat();
16
- const lastAssistantMessage = (_a = [...messages].filter((m) => m.role === 'assistant').pop()) === null || _a === void 0 ? void 0 : _a.content;
17
- useEffect(() => {
18
- sender.setOnLoudnessChange((value) => event.emit('self.avatar.triggerLoudness', { loudness: value }));
19
- if (!autoStartConversation) {
20
- return;
21
- }
22
- setMessages(getFirstMessages(autoStartConversation));
23
- // append([{ role: 'user', content: autoStartConversation.userMessage }]);
24
- if (autoStartConversation.assistantMessage) {
25
- // console.log("autostartmessages", { autoStartConversation, isLoading });
26
- sender.handleNewText(autoStartConversation.assistantMessage, isLoading);
27
- }
28
- }, []);
29
- useEffect(() => {
30
- var _a;
31
- let message = lastAssistantMessage;
32
- if (message !== ((_a = messages[messages.length - 1]) === null || _a === void 0 ? void 0 : _a.content)) {
33
- message = undefined;
34
- }
35
- sender.handleNewText(message, isLoading);
36
- }, [messages, isLoading]);
37
- const lastMessage = messages[messages.length - 1];
38
- useEffect(() => {
39
- console.log('lastMessage', lastMessage);
40
- const toolInvocations = lastMessage === null || lastMessage === void 0 ? void 0 : lastMessage.toolCalls;
41
- if (toolInvocations && toolInvocations.length > 0) {
42
- console.log('toolInvocations', toolInvocations);
43
- onComplete(toolInvocations[0].args);
44
- }
45
- }, [lastMessage]);
46
- if ((lastMessage === null || lastMessage === void 0 ? void 0 : lastMessage.toolCalls) && lastMessage.toolCalls.length > 0) {
47
- console.log('lastMessage test2', lastMessage);
48
- const args = lastMessage.toolCalls[0].args;
49
- const success = args.explanationUnderstood === 'TRUE' || args.studentKnowsTopic === 'TRUE';
50
- return (_jsxs("div", { className: "px-5 pt-5 overflow-y-auto text-center", style: { height: '478px' }, children: [_jsx("h1", { className: "text-center mt-5 mb-5", children: success ? 'Great job!' : 'You failed' }), _jsx("p", { children: args.improvementHints })] }));
51
- }
52
- return (_jsxs("div", { children: [oralCommunication && _jsx(CircleAudioAvatar, { imageUrl: avatarImageUrl, className: "mx-auto my-10" }), _jsx("div", { className: "w-full", children: lastAssistantMessage && (_jsx("div", { className: "px-5 pt-5 overflow-y-auto remirror-theme", style: { height: '4k78px' }, children: _jsx(Markdown, { children: lastAssistantMessage }) })) }), _jsx(AudioInputField, { blockSubmission: isLoading, onSubmit: (message) => {
53
- append([{ role: 'user', content: message, id: messages.length.toString() }]);
54
- }, onAudioControl: (voice) => {
55
- setOralCommunication(voice);
56
- sender.setVolume(voice ? 1 : 0);
57
- } })] }));
58
- }
@@ -1,14 +0,0 @@
1
- import { Tool } from '@rimori/client';
2
- import { FirstMessages } from './utils';
3
- interface Props {
4
- voiceId: string;
5
- agentTools: Tool[];
6
- avatarImageUrl: string;
7
- circleSize?: string;
8
- isDarkTheme?: boolean;
9
- children?: React.ReactNode;
10
- autoStartConversation?: FirstMessages;
11
- className?: string;
12
- }
13
- export declare function Avatar({ avatarImageUrl, voiceId, agentTools, autoStartConversation, children, isDarkTheme, circleSize, className, }: Props): import("react/jsx-runtime").JSX.Element;
14
- export {};
@@ -1,59 +0,0 @@
1
- import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
- import { useEffect, useMemo, useState } from 'react';
3
- import { VoiceRecorder } from './EmbeddedAssistent/VoiceRecoder';
4
- import { MessageSender } from './EmbeddedAssistent/TTS/MessageSender';
5
- import { CircleAudioAvatar } from './EmbeddedAssistent/CircleAudioAvatar';
6
- import { useChat } from '../../hooks/UseChatHook';
7
- import { useRimori } from '../../providers/PluginProvider';
8
- import { getFirstMessages } from './utils';
9
- export function Avatar({ avatarImageUrl, voiceId, agentTools, autoStartConversation, children, isDarkTheme = false, circleSize = '300px', className, }) {
10
- const { ai, event } = useRimori();
11
- const [agentReplying, setAgentReplying] = useState(false);
12
- const [isProcessingMessage, setIsProcessingMessage] = useState(false);
13
- const sender = useMemo(() => new MessageSender(ai.getVoice, voiceId), [voiceId]);
14
- const { messages, append, isLoading, lastMessage, setMessages } = useChat(agentTools);
15
- useEffect(() => {
16
- console.log('messages', messages);
17
- }, [messages]);
18
- useEffect(() => {
19
- if (!isLoading)
20
- setIsProcessingMessage(false);
21
- }, [isLoading]);
22
- useEffect(() => {
23
- if (!voiceId)
24
- return; //at the beginning when being mounted the voiceId is undefined
25
- sender.setOnLoudnessChange((value) => event.emit('self.avatar.triggerLoudness', { loudness: value }));
26
- sender.setOnEndOfSpeech(() => setAgentReplying(false));
27
- if (!autoStartConversation)
28
- return;
29
- setMessages(getFirstMessages(autoStartConversation));
30
- // append([{ role: 'user', content: autoStartConversation.userMessage }]);
31
- if (autoStartConversation.assistantMessage) {
32
- // console.log("autostartmessages", { autoStartConversation, isLoading });
33
- sender.handleNewText(autoStartConversation.assistantMessage, isLoading);
34
- }
35
- else if (autoStartConversation.userMessage) {
36
- append([{ role: 'user', content: autoStartConversation.userMessage, id: messages.length.toString() }]);
37
- }
38
- }, [autoStartConversation, voiceId]);
39
- useEffect(() => {
40
- if ((lastMessage === null || lastMessage === void 0 ? void 0 : lastMessage.role) === 'assistant') {
41
- sender.handleNewText(lastMessage.content, isLoading);
42
- if (lastMessage.toolCalls) {
43
- // console.log("unlocking mic", lastMessage)
44
- setAgentReplying(false);
45
- setIsProcessingMessage(false);
46
- }
47
- }
48
- }, [lastMessage, isLoading]);
49
- return (_jsxs("div", { className: `md:pb-8 ${className || ''}`, children: [_jsx(CircleAudioAvatar, { width: circleSize, className: "mx-auto", imageUrl: avatarImageUrl, isDarkTheme: isDarkTheme }), children, _jsx(VoiceRecorder, { iconSize: "30", className: "w-16 h-16 shadow-lg rounded-full bg-gray-400 dark:bg-gray-800", disabled: agentReplying, loading: isProcessingMessage, enablePushToTalk: true, onVoiceRecorded: (message) => {
50
- setAgentReplying(true);
51
- append([
52
- {
53
- role: 'user',
54
- content: 'Message(' + Math.floor((messages.length + 1) / 2) + '): ' + message,
55
- id: messages.length.toString(),
56
- },
57
- ]);
58
- }, onRecordingStatusChange: (running) => !running && setIsProcessingMessage(true) })] }));
59
- }
@@ -1,7 +0,0 @@
1
- interface AudioInputFieldProps {
2
- onSubmit: (text: string) => void;
3
- onAudioControl?: (voice: boolean) => void;
4
- blockSubmission?: boolean;
5
- }
6
- export declare function AudioInputField({ onSubmit, onAudioControl, blockSubmission }: AudioInputFieldProps): import("react/jsx-runtime").JSX.Element;
7
- export {};
@@ -1,37 +0,0 @@
1
- import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
- import { useState } from 'react';
3
- import { VoiceRecorder } from './VoiceRecoder';
4
- import { BiSolidRightArrow } from 'react-icons/bi';
5
- import { HiMiniSpeakerXMark, HiMiniSpeakerWave } from 'react-icons/hi2';
6
- export function AudioInputField({ onSubmit, onAudioControl, blockSubmission = false }) {
7
- const [text, setText] = useState('');
8
- const [audioEnabled, setAudioEnabled] = useState(true);
9
- const handleSubmit = (manualText) => {
10
- if (blockSubmission)
11
- return;
12
- const sendableText = manualText || text;
13
- if (sendableText.trim()) {
14
- onSubmit(sendableText);
15
- setTimeout(() => {
16
- setText('');
17
- }, 100);
18
- }
19
- };
20
- const handleKeyDown = (e) => {
21
- if (blockSubmission)
22
- return;
23
- if (e.key === 'Enter' && e.ctrlKey) {
24
- setText(text + '\n');
25
- }
26
- else if (e.key === 'Enter') {
27
- handleSubmit();
28
- }
29
- };
30
- return (_jsxs("div", { className: "flex items-center bg-gray-600 pt-2 pb-2 p-2", children: [onAudioControl && (_jsx("button", { onClick: () => {
31
- onAudioControl(!audioEnabled);
32
- setAudioEnabled(!audioEnabled);
33
- }, className: "cursor-default", children: audioEnabled ? (_jsx(HiMiniSpeakerWave, { className: "w-9 h-9 cursor-pointer" })) : (_jsx(HiMiniSpeakerXMark, { className: "w-9 h-9 cursor-pointer" })) })), _jsx(VoiceRecorder, { onRecordingStatusChange: () => { }, onVoiceRecorded: (m) => {
34
- console.log('onVoiceRecorded', m);
35
- handleSubmit(m);
36
- } }), _jsx("textarea", { value: text, onChange: (e) => setText(e.target.value), onKeyDown: handleKeyDown, className: "flex-1 border-none rounded-lg p-2 text-gray-800 focus::outline-none", placeholder: "Type a message...", disabled: blockSubmission }), _jsx("button", { onClick: () => handleSubmit(), className: "cursor-default", disabled: blockSubmission, children: _jsx(BiSolidRightArrow, { className: "w-9 h-10 cursor-pointer" }) })] }));
37
- }
@@ -1,8 +0,0 @@
1
- interface CircleAudioAvatarProps {
2
- width?: string;
3
- imageUrl: string;
4
- className?: string;
5
- isDarkTheme?: boolean;
6
- }
7
- export declare function CircleAudioAvatar({ imageUrl, className, isDarkTheme, width, }: CircleAudioAvatarProps): import("react/jsx-runtime").JSX.Element;
8
- export {};