@rimori/react-client 0.1.0 → 0.1.1

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 (102) hide show
  1. package/dist/{react-client/src/components → components}/ContextMenu.js +1 -2
  2. package/dist/components/ai/Assistant.js +1 -1
  3. package/dist/components/ai/Avatar.d.ts +1 -1
  4. package/dist/components/ai/Avatar.js +1 -1
  5. package/dist/components/ai/EmbeddedAssistent/CircleAudioAvatar.js +1 -1
  6. package/dist/components/ai/EmbeddedAssistent/VoiceRecoder.js +2 -2
  7. package/dist/components/audio/Playbutton.js +10 -8
  8. package/dist/hooks/I18nHooks.d.ts +1 -1
  9. package/dist/hooks/UseChatHook.d.ts +2 -2
  10. package/dist/index.d.ts +10 -0
  11. package/dist/index.js +10 -0
  12. package/dist/providers/PluginProvider.d.ts +2 -1
  13. package/dist/providers/PluginProvider.js +9 -8
  14. package/dist/{react-client/src/utils → utils}/FullscreenUtils.js +2 -2
  15. package/package.json +1 -1
  16. package/src/components/ContextMenu.tsx +2 -2
  17. package/src/index.ts +11 -0
  18. package/src/plugin/ThemeSetter.ts +1 -1
  19. package/src/providers/PluginProvider.tsx +10 -9
  20. package/src/utils/FullscreenUtils.ts +5 -5
  21. package/tsconfig.json +6 -12
  22. package/dist/components/components/ContextMenu.d.ts +0 -10
  23. package/dist/components/components/ContextMenu.js +0 -135
  24. package/dist/react-client/src/components/MarkdownEditor.d.ts +0 -8
  25. package/dist/react-client/src/components/MarkdownEditor.js +0 -48
  26. package/dist/react-client/src/components/Spinner.d.ts +0 -8
  27. package/dist/react-client/src/components/Spinner.js +0 -4
  28. package/dist/react-client/src/components/ai/Assistant.d.ts +0 -9
  29. package/dist/react-client/src/components/ai/Assistant.js +0 -58
  30. package/dist/react-client/src/components/ai/Avatar.d.ts +0 -14
  31. package/dist/react-client/src/components/ai/Avatar.js +0 -59
  32. package/dist/react-client/src/components/ai/EmbeddedAssistent/AudioInputField.d.ts +0 -7
  33. package/dist/react-client/src/components/ai/EmbeddedAssistent/AudioInputField.js +0 -37
  34. package/dist/react-client/src/components/ai/EmbeddedAssistent/CircleAudioAvatar.d.ts +0 -8
  35. package/dist/react-client/src/components/ai/EmbeddedAssistent/CircleAudioAvatar.js +0 -79
  36. package/dist/react-client/src/components/ai/EmbeddedAssistent/TTS/MessageSender.d.ts +0 -19
  37. package/dist/react-client/src/components/ai/EmbeddedAssistent/TTS/MessageSender.js +0 -91
  38. package/dist/react-client/src/components/ai/EmbeddedAssistent/TTS/Player.d.ts +0 -27
  39. package/dist/react-client/src/components/ai/EmbeddedAssistent/TTS/Player.js +0 -185
  40. package/dist/react-client/src/components/ai/EmbeddedAssistent/VoiceRecoder.d.ts +0 -11
  41. package/dist/react-client/src/components/ai/EmbeddedAssistent/VoiceRecoder.js +0 -95
  42. package/dist/react-client/src/components/ai/utils.d.ts +0 -6
  43. package/dist/react-client/src/components/ai/utils.js +0 -13
  44. package/dist/react-client/src/components/audio/Playbutton.d.ts +0 -15
  45. package/dist/react-client/src/components/audio/Playbutton.js +0 -82
  46. package/dist/react-client/src/components/components/ContextMenu.d.ts +0 -10
  47. package/dist/react-client/src/components/components/ContextMenu.js +0 -135
  48. package/dist/react-client/src/hooks/I18nHooks.d.ts +0 -11
  49. package/dist/react-client/src/hooks/I18nHooks.js +0 -25
  50. package/dist/react-client/src/hooks/UseChatHook.d.ts +0 -10
  51. package/dist/react-client/src/hooks/UseChatHook.js +0 -29
  52. package/dist/react-client/src/plugin/ThemeSetter.d.ts +0 -2
  53. package/dist/react-client/src/plugin/ThemeSetter.js +0 -19
  54. package/dist/react-client/src/providers/PluginProvider.d.ts +0 -12
  55. package/dist/react-client/src/providers/PluginProvider.js +0 -142
  56. package/dist/react-client/src/utils/PluginUtils.d.ts +0 -2
  57. package/dist/react-client/src/utils/PluginUtils.js +0 -23
  58. package/dist/rimori-client/src/cli/types/DatabaseTypes.d.ts +0 -103
  59. package/dist/rimori-client/src/cli/types/DatabaseTypes.js +0 -2
  60. package/dist/rimori-client/src/controller/AIController.d.ts +0 -15
  61. package/dist/rimori-client/src/controller/AIController.js +0 -255
  62. package/dist/rimori-client/src/controller/AccomplishmentController.d.ts +0 -38
  63. package/dist/rimori-client/src/controller/AccomplishmentController.js +0 -112
  64. package/dist/rimori-client/src/controller/AudioController.d.ts +0 -37
  65. package/dist/rimori-client/src/controller/AudioController.js +0 -68
  66. package/dist/rimori-client/src/controller/ExerciseController.d.ts +0 -54
  67. package/dist/rimori-client/src/controller/ExerciseController.js +0 -74
  68. package/dist/rimori-client/src/controller/ObjectController.d.ts +0 -42
  69. package/dist/rimori-client/src/controller/ObjectController.js +0 -76
  70. package/dist/rimori-client/src/controller/SettingsController.d.ts +0 -79
  71. package/dist/rimori-client/src/controller/SettingsController.js +0 -118
  72. package/dist/rimori-client/src/controller/SharedContentController.d.ts +0 -106
  73. package/dist/rimori-client/src/controller/SharedContentController.js +0 -285
  74. package/dist/rimori-client/src/controller/TranslationController.d.ts +0 -38
  75. package/dist/rimori-client/src/controller/TranslationController.js +0 -106
  76. package/dist/rimori-client/src/controller/VoiceController.d.ts +0 -9
  77. package/dist/rimori-client/src/controller/VoiceController.js +0 -37
  78. package/dist/rimori-client/src/fromRimori/EventBus.d.ts +0 -101
  79. package/dist/rimori-client/src/fromRimori/EventBus.js +0 -263
  80. package/dist/rimori-client/src/fromRimori/PluginTypes.d.ts +0 -174
  81. package/dist/rimori-client/src/fromRimori/PluginTypes.js +0 -1
  82. package/dist/rimori-client/src/index.d.ts +0 -11
  83. package/dist/rimori-client/src/index.js +0 -10
  84. package/dist/rimori-client/src/plugin/CommunicationHandler.d.ts +0 -48
  85. package/dist/rimori-client/src/plugin/CommunicationHandler.js +0 -234
  86. package/dist/rimori-client/src/plugin/Logger.d.ts +0 -73
  87. package/dist/rimori-client/src/plugin/Logger.js +0 -308
  88. package/dist/rimori-client/src/plugin/RimoriClient.d.ts +0 -258
  89. package/dist/rimori-client/src/plugin/RimoriClient.js +0 -375
  90. package/dist/rimori-client/src/plugin/StandaloneClient.d.ts +0 -17
  91. package/dist/rimori-client/src/plugin/StandaloneClient.js +0 -115
  92. package/dist/rimori-client/src/utils/difficultyConverter.d.ts +0 -4
  93. package/dist/rimori-client/src/utils/difficultyConverter.js +0 -10
  94. package/dist/rimori-client/src/utils/endpoint.d.ts +0 -2
  95. package/dist/rimori-client/src/utils/endpoint.js +0 -2
  96. package/dist/utils/PluginUtils.d.ts +0 -2
  97. package/dist/utils/PluginUtils.js +0 -23
  98. package/index.ts +0 -6
  99. /package/dist/{react-client/src/components → components}/ContextMenu.d.ts +0 -0
  100. /package/dist/{react-client/plugin → plugin}/ThemeSetter.d.ts +0 -0
  101. /package/dist/{react-client/plugin → plugin}/ThemeSetter.js +0 -0
  102. /package/dist/{react-client/src/utils → utils}/FullscreenUtils.d.ts +0 -0
@@ -1,95 +0,0 @@
1
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3
- return new (P || (P = Promise))(function (resolve, reject) {
4
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
5
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
6
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
7
- step((generator = generator.apply(thisArg, _arguments || [])).next());
8
- });
9
- };
10
- import { jsx as _jsx } from "react/jsx-runtime";
11
- import { useRimori } from '../../../providers/PluginProvider';
12
- import { FaMicrophone, FaSpinner } from 'react-icons/fa6';
13
- import { AudioController } from '@rimori/client';
14
- import { useState, useRef, forwardRef, useImperativeHandle, useEffect } from 'react';
15
- export const VoiceRecorder = forwardRef(({ onVoiceRecorded, iconSize, className, disabled, loading, onRecordingStatusChange, enablePushToTalk = false, }, ref) => {
16
- const [isRecording, setIsRecording] = useState(false);
17
- const [internalIsProcessing, setInternalIsProcessing] = useState(false);
18
- const audioControllerRef = useRef(null);
19
- const { ai, plugin } = useRimori();
20
- // Ref for latest onVoiceRecorded callback
21
- const onVoiceRecordedRef = useRef(onVoiceRecorded);
22
- useEffect(() => {
23
- onVoiceRecordedRef.current = onVoiceRecorded;
24
- }, [onVoiceRecorded]);
25
- const startRecording = () => __awaiter(void 0, void 0, void 0, function* () {
26
- try {
27
- if (!audioControllerRef.current) {
28
- audioControllerRef.current = new AudioController(plugin.pluginId);
29
- }
30
- yield audioControllerRef.current.startRecording();
31
- setIsRecording(true);
32
- onRecordingStatusChange(true);
33
- }
34
- catch (error) {
35
- console.error('Failed to start recording:', error);
36
- // Handle permission denied or other errors
37
- }
38
- });
39
- const stopRecording = () => __awaiter(void 0, void 0, void 0, function* () {
40
- try {
41
- if (audioControllerRef.current && isRecording) {
42
- const audioResult = yield audioControllerRef.current.stopRecording();
43
- // console.log("audioResult: ", audioResult);
44
- setInternalIsProcessing(true);
45
- // Play the recorded audio from the Blob
46
- // const blobUrl = URL.createObjectURL(audioResult.recording);
47
- // const audioRef = new Audio(blobUrl);
48
- // audioRef.onended = () => URL.revokeObjectURL(blobUrl);
49
- // audioRef.play().catch((e) => console.error('Playback error:', e));
50
- // console.log("audioBlob: ", audioResult.recording);
51
- const text = yield ai.getTextFromVoice(audioResult.recording);
52
- // console.log("stt result", text);
53
- // throw new Error("test");
54
- setInternalIsProcessing(false);
55
- onVoiceRecordedRef.current(text);
56
- }
57
- }
58
- catch (error) {
59
- console.error('Failed to stop recording:', error);
60
- }
61
- finally {
62
- setIsRecording(false);
63
- onRecordingStatusChange(false);
64
- }
65
- });
66
- useImperativeHandle(ref, () => ({
67
- startRecording,
68
- stopRecording,
69
- }));
70
- // push to talk feature
71
- const spacePressedRef = useRef(false);
72
- useEffect(() => {
73
- if (!enablePushToTalk)
74
- return;
75
- const handleKeyDown = (event) => __awaiter(void 0, void 0, void 0, function* () {
76
- if (event.code === 'Space' && !spacePressedRef.current) {
77
- spacePressedRef.current = true;
78
- yield startRecording();
79
- }
80
- });
81
- const handleKeyUp = (event) => {
82
- if (event.code === 'Space' && spacePressedRef.current) {
83
- spacePressedRef.current = false;
84
- stopRecording();
85
- }
86
- };
87
- window.addEventListener('keydown', handleKeyDown);
88
- window.addEventListener('keyup', handleKeyUp);
89
- return () => {
90
- window.removeEventListener('keydown', handleKeyDown);
91
- window.removeEventListener('keyup', handleKeyUp);
92
- };
93
- }, [enablePushToTalk]);
94
- return (_jsx("button", { className: 'flex flex-row justify-center items-center rounded-full mx-auto disabled:opacity-50 ' + className, onClick: isRecording ? stopRecording : startRecording, disabled: disabled || loading || internalIsProcessing, children: loading || internalIsProcessing ? (_jsx(FaSpinner, { className: "animate-spin" })) : (_jsx(FaMicrophone, { size: iconSize, className: isRecording ? 'text-red-600' : '' })) }));
95
- });
@@ -1,6 +0,0 @@
1
- export interface FirstMessages {
2
- instructions?: string;
3
- userMessage?: string;
4
- assistantMessage?: string;
5
- }
6
- export declare function getFirstMessages(instructions: FirstMessages): any[];
@@ -1,13 +0,0 @@
1
- export function getFirstMessages(instructions) {
2
- const messages = [];
3
- if (instructions.instructions) {
4
- messages.push({ id: '1', role: 'system', content: instructions.instructions });
5
- }
6
- if (instructions.userMessage) {
7
- messages.push({ id: '2', role: 'user', content: instructions.userMessage });
8
- }
9
- if (instructions.assistantMessage) {
10
- messages.push({ id: '3', role: 'assistant', content: instructions.assistantMessage });
11
- }
12
- return messages;
13
- }
@@ -1,15 +0,0 @@
1
- import React from 'react';
2
- type AudioPlayerProps = {
3
- text: string;
4
- voice?: string;
5
- language?: string;
6
- hide?: boolean;
7
- playOnMount?: boolean;
8
- initialSpeed?: number;
9
- enableSpeedAdjustment?: boolean;
10
- playListenerEvent?: string;
11
- };
12
- export declare const AudioPlayOptions: number[];
13
- export type AudioPlayOptionType = 0.8 | 0.9 | 1.0 | 1.1 | 1.2 | 1.5;
14
- export declare const AudioPlayer: React.FC<AudioPlayerProps>;
15
- export {};
@@ -1,82 +0,0 @@
1
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3
- return new (P || (P = Promise))(function (resolve, reject) {
4
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
5
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
6
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
7
- step((generator = generator.apply(thisArg, _arguments || [])).next());
8
- });
9
- };
10
- import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
11
- import { useState, useEffect } from 'react';
12
- import { FaPlayCircle, FaStopCircle } from 'react-icons/fa';
13
- import { useRimori } from '../../providers/PluginProvider';
14
- import { Spinner } from '../Spinner';
15
- import { EventBus } from '@rimori/client';
16
- export const AudioPlayOptions = [0.8, 0.9, 1.0, 1.1, 1.2, 1.5];
17
- let isFetchingAudio = false;
18
- export const AudioPlayer = ({ text, voice, language, hide, playListenerEvent, initialSpeed = 1.0, playOnMount = false, enableSpeedAdjustment = false, }) => {
19
- const [audioUrl, setAudioUrl] = useState(null);
20
- const [speed, setSpeed] = useState(initialSpeed);
21
- const [isPlaying, setIsPlaying] = useState(false);
22
- const [isLoading, setIsLoading] = useState(false);
23
- const { ai } = useRimori();
24
- useEffect(() => {
25
- if (audioUrl)
26
- setAudioUrl(null);
27
- return () => {
28
- if (audioUrl)
29
- URL.revokeObjectURL(audioUrl);
30
- };
31
- }, [text]);
32
- // Function to generate audio from text using API
33
- const generateAudio = () => __awaiter(void 0, void 0, void 0, function* () {
34
- setIsLoading(true);
35
- const blob = yield ai.getVoice(text, voice || (language ? 'aws_default' : 'openai_alloy'), 1, language);
36
- setAudioUrl(URL.createObjectURL(blob));
37
- setIsLoading(false);
38
- });
39
- // Effect to play audio when audioUrl changes and play state is true
40
- useEffect(() => {
41
- if (!audioUrl || !isPlaying)
42
- return;
43
- const audio = new Audio(audioUrl);
44
- audio.playbackRate = speed;
45
- audio
46
- .play()
47
- .then(() => {
48
- audio.onended = () => {
49
- setIsPlaying(false);
50
- isFetchingAudio = false;
51
- };
52
- })
53
- .catch((e) => {
54
- console.warn('Error playing audio:', e);
55
- setIsPlaying(false);
56
- });
57
- return () => {
58
- audio.pause();
59
- };
60
- }, [audioUrl, isPlaying, speed]);
61
- const togglePlayback = () => {
62
- if (!isPlaying && !audioUrl) {
63
- generateAudio().then(() => setIsPlaying(true));
64
- }
65
- else {
66
- setIsPlaying((prev) => !prev);
67
- }
68
- };
69
- useEffect(() => {
70
- if (!playListenerEvent)
71
- return;
72
- EventBus.on(playListenerEvent, () => togglePlayback());
73
- }, [playListenerEvent]);
74
- useEffect(() => {
75
- if (!playOnMount || isFetchingAudio)
76
- return;
77
- isFetchingAudio = true;
78
- // console.log("playOnMount", playOnMount);
79
- togglePlayback();
80
- }, [playOnMount]);
81
- return (_jsx("div", { className: "group relative", children: _jsxs("div", { className: "flex flex-row items-end", children: [!hide && (_jsx("button", { className: "text-gray-500", onClick: togglePlayback, disabled: isLoading, children: isLoading ? _jsx(Spinner, {}) : 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))) })] }))] }) }));
82
- };
@@ -1,10 +0,0 @@
1
- import { RimoriClient } from '@rimori/client';
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 '@rimori/client';
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,11 +0,0 @@
1
- import { TOptions } from '@rimori/client';
2
- type TranslatorFn = (key: string, options?: TOptions) => string;
3
- /**
4
- * Custom useTranslation hook that provides a translation function and indicates readiness
5
- * @returns An object containing the translation function (`t`) and a boolean (`ready`) indicating if the translator is initialized.
6
- */
7
- export declare function useTranslation(): {
8
- t: TranslatorFn;
9
- ready: boolean;
10
- };
11
- export {};
@@ -1,25 +0,0 @@
1
- import { useEffect, useState } from 'react';
2
- import { useRimori } from '../providers/PluginProvider';
3
- /**
4
- * Custom useTranslation hook that provides a translation function and indicates readiness
5
- * @returns An object containing the translation function (`t`) and a boolean (`ready`) indicating if the translator is initialized.
6
- */
7
- export function useTranslation() {
8
- const { plugin } = useRimori();
9
- const [translatorInstance, setTranslatorInstance] = useState(null);
10
- useEffect(() => {
11
- void plugin.getTranslator().then(setTranslatorInstance);
12
- }, [plugin]);
13
- const safeT = (key, options) => {
14
- // return zero-width space if translator is not initialized to keep text space occupied
15
- if (!translatorInstance)
16
- return '\u200B'; // zero-width space
17
- const result = translatorInstance.t(key, options);
18
- if (!result) {
19
- console.error(`Translation key not found: ${key}`);
20
- return '\u200B'; // zero-width space
21
- }
22
- return result;
23
- };
24
- return { t: safeT, ready: translatorInstance !== null };
25
- }
@@ -1,10 +0,0 @@
1
- import React from 'react';
2
- import { Tool } from '@rimori/client';
3
- import { Message } from '@rimori/client';
4
- export declare function useChat(tools?: Tool[]): {
5
- messages: Message[];
6
- append: (appendMessages: Message[]) => void;
7
- isLoading: boolean;
8
- setMessages: React.Dispatch<React.SetStateAction<Message[]>>;
9
- lastMessage: Message | undefined;
10
- };
@@ -1,29 +0,0 @@
1
- import React from 'react';
2
- import { useRimori } from '../providers/PluginProvider';
3
- export function useChat(tools) {
4
- const [messages, setMessages] = React.useState([]);
5
- const [isLoading, setIsLoading] = React.useState(false);
6
- const { ai } = useRimori();
7
- const append = (appendMessages) => {
8
- const allMessages = [...messages, ...appendMessages];
9
- setMessages(allMessages);
10
- ai.getSteamedText(allMessages, (id, message, finished, toolInvocations) => {
11
- const lastMessage = messages[messages.length - 1];
12
- setIsLoading(!finished);
13
- if ((lastMessage === null || lastMessage === void 0 ? void 0 : lastMessage.id) === id) {
14
- lastMessage.content = message;
15
- setMessages([...messages, lastMessage]);
16
- }
17
- else {
18
- setMessages([...allMessages, { id, role: 'assistant', content: message, toolCalls: toolInvocations }]);
19
- }
20
- }, tools);
21
- };
22
- return {
23
- messages,
24
- append,
25
- isLoading,
26
- setMessages,
27
- lastMessage: messages[messages.length - 1],
28
- };
29
- }
@@ -1,2 +0,0 @@
1
- export declare function setTheme(theme?: string | null): void;
2
- export declare function isDarkTheme(theme?: string | null): boolean;
@@ -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,12 +0,0 @@
1
- import React, { ReactNode } from 'react';
2
- import { RimoriClient } from '@rimori/client';
3
- interface PluginProviderProps {
4
- children: ReactNode;
5
- pluginId: string;
6
- settings?: {
7
- disableContextMenu?: boolean;
8
- };
9
- }
10
- export declare const PluginProvider: React.FC<PluginProviderProps>;
11
- export declare const useRimori: () => RimoriClient;
12
- export {};
@@ -1,142 +0,0 @@
1
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3
- return new (P || (P = Promise))(function (resolve, reject) {
4
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
5
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
6
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
7
- step((generator = generator.apply(thisArg, _arguments || [])).next());
8
- });
9
- };
10
- import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
11
- import { createContext, useContext, useEffect, useState } from 'react';
12
- import { EventBusHandler, RimoriClient, StandaloneClient } from '@rimori/client';
13
- import ContextMenu from '../components/ContextMenu';
14
- const PluginContext = createContext(null);
15
- export const PluginProvider = ({ children, pluginId, settings }) => {
16
- const [plugin, setPlugin] = useState(null);
17
- const [standaloneClient, setStandaloneClient] = useState(false);
18
- const [applicationMode, setApplicationMode] = useState(null);
19
- const [theme, setTheme] = useState(null);
20
- const isSidebar = applicationMode === 'sidebar';
21
- const isSettings = applicationMode === 'settings';
22
- useEffect(() => {
23
- initEventBus(pluginId);
24
- // Check if we're in an iframe context - if not, we're standalone
25
- const standaloneDetected = window === window.parent;
26
- if (standaloneDetected && !standaloneClient) {
27
- StandaloneClient.getInstance().then((client) => {
28
- client.needsLogin().then((needLogin) => setStandaloneClient(needLogin ? client : true));
29
- });
30
- }
31
- if ((!standaloneDetected && !plugin) || (standaloneDetected && standaloneClient === true)) {
32
- RimoriClient.getInstance(pluginId).then((client) => {
33
- setPlugin(client);
34
- // Get applicationMode and theme from MessageChannel query params
35
- if (!standaloneDetected) {
36
- const mode = client.getQueryParam('applicationMode');
37
- const themeParam = client.getQueryParam('rm_theme');
38
- setApplicationMode(mode);
39
- setTheme(themeParam);
40
- }
41
- });
42
- }
43
- }, [pluginId, standaloneClient]);
44
- //route change
45
- useEffect(() => {
46
- if (!plugin)
47
- return;
48
- //sidebar pages should not report url changes
49
- if (isSidebar)
50
- return;
51
- let lastHash = window.location.hash;
52
- const emitUrlChange = (url) => plugin.event.emit('session.triggerUrlChange', { url });
53
- const interval = setInterval(() => {
54
- if (lastHash === window.location.hash)
55
- return;
56
- lastHash = window.location.hash;
57
- // console.log('url changed:', lastHash);
58
- emitUrlChange(lastHash);
59
- }, 1000);
60
- emitUrlChange(lastHash);
61
- return () => clearInterval(interval);
62
- }, [plugin]);
63
- if (standaloneClient instanceof StandaloneClient) {
64
- return (_jsx(StandaloneAuth, { onLogin: (email, password) => __awaiter(void 0, void 0, void 0, function* () {
65
- if (yield standaloneClient.login(email, password))
66
- setStandaloneClient(true);
67
- }) }));
68
- }
69
- if (!plugin) {
70
- return '';
71
- }
72
- return (_jsxs(PluginContext.Provider, { value: plugin, children: [!(settings === null || settings === void 0 ? void 0 : settings.disableContextMenu) && !isSidebar && !isSettings && _jsx(ContextMenu, { client: plugin }), children] }));
73
- };
74
- export const useRimori = () => {
75
- const context = useContext(PluginContext);
76
- if (context === null) {
77
- throw new Error('useRimori must be used within an PluginProvider');
78
- }
79
- return context;
80
- };
81
- function getUrlParam(name) {
82
- // First try to get from URL hash query params (for compatibility)
83
- const hashParts = window.location.hash.split('?');
84
- if (hashParts.length > 1) {
85
- const hashParams = new URLSearchParams(hashParts[1]);
86
- const hashValue = hashParams.get(name);
87
- if (hashValue)
88
- return hashValue;
89
- }
90
- // Fallback to regular URL search params
91
- const url = new URL(window.location.href);
92
- return url.searchParams.get(name);
93
- }
94
- function initEventBus(pluginId) {
95
- // For now, use URL fallback for EventBus naming - this will be updated once MessageChannel is ready
96
- const isSidebar = getUrlParam('applicationMode') === 'sidebar';
97
- EventBusHandler.getInstance('Plugin EventBus ' + pluginId + ' ' + (isSidebar ? 'sidebar' : 'main'));
98
- }
99
- function StandaloneAuth({ onLogin }) {
100
- const [user, setUser] = useState('');
101
- const [password, setPassword] = useState('');
102
- return (_jsx("div", { style: {
103
- position: 'fixed',
104
- inset: 0,
105
- display: 'flex',
106
- alignItems: 'center',
107
- justifyContent: 'center',
108
- backgroundColor: 'rgba(0, 0, 0, 0.5)',
109
- }, children: _jsxs("div", { style: {
110
- backgroundColor: '#343534',
111
- padding: '1rem',
112
- borderRadius: '0.5rem',
113
- width: '500px',
114
- flexDirection: 'column',
115
- display: 'flex',
116
- alignItems: 'center',
117
- justifyContent: 'center',
118
- }, children: [_jsx("p", { style: { fontSize: '2rem', fontWeight: 'bold', marginBottom: '1rem', textAlign: 'center' }, children: "Rimori Login" }), _jsx("p", { style: { marginBottom: '1rem', textAlign: 'center' }, children: "Please login with your Rimori developer account for this plugin to be able to access the Rimori platform the same it will operate in the Rimori platform." }), _jsx("input", { style: {
119
- marginBottom: '1rem',
120
- width: '100%',
121
- padding: '0.5rem',
122
- borderRadius: '0.5rem',
123
- border: 'none',
124
- backgroundColor: '#444444',
125
- }, type: "email", placeholder: "Email", onChange: (e) => setUser(e.target.value) }), _jsx("input", { style: {
126
- marginBottom: '1rem',
127
- width: '100%',
128
- padding: '0.5rem',
129
- borderRadius: '0.5rem',
130
- border: 'none',
131
- backgroundColor: '#444444',
132
- }, type: "password", placeholder: "Password", onChange: (e) => setPassword(e.target.value) }), _jsx("button", { style: {
133
- marginBottom: '1rem',
134
- width: '100%',
135
- padding: '0.5rem',
136
- borderRadius: '0.5rem',
137
- border: 'none',
138
- backgroundColor: '#928358',
139
- }, onClick: () => {
140
- onLogin(user, password);
141
- }, children: "Login" })] }) }));
142
- }
@@ -1,2 +0,0 @@
1
- export declare function isFullscreen(): boolean;
2
- export declare function triggerFullscreen(onStateChange: (isFullscreen: boolean) => void, selector?: string): void;
@@ -1,23 +0,0 @@
1
- export function isFullscreen() {
2
- return !!document.fullscreenElement;
3
- }
4
- export function triggerFullscreen(onStateChange, selector) {
5
- document.addEventListener('fullscreenchange', () => {
6
- onStateChange(isFullscreen());
7
- });
8
- try {
9
- const ref = document.querySelector(selector || '#root');
10
- if (!isFullscreen()) {
11
- // @ts-ignore
12
- ref.requestFullscreen() || ref.webkitRequestFullscreen();
13
- }
14
- else {
15
- // @ts-ignore
16
- document.exitFullscreen() || document.webkitExitFullscreen();
17
- }
18
- }
19
- catch (error) {
20
- console.error('Failed to enter fullscreen', error.message);
21
- }
22
- onStateChange(isFullscreen());
23
- }