@rimori/client 1.4.10 → 2.1.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/README.md +140 -1171
- package/dist/{core/controller → controller}/AIController.d.ts +1 -1
- package/dist/{core/controller → controller}/AIController.js +2 -2
- package/dist/{plugin/AccomplishmentHandler.d.ts → controller/AccomplishmentController.d.ts} +1 -1
- package/dist/{plugin/AccomplishmentHandler.js → controller/AccomplishmentController.js} +1 -1
- package/dist/{core/controller → controller}/ExerciseController.d.ts +8 -6
- package/dist/{core/controller → controller}/ExerciseController.js +10 -9
- package/dist/{core/controller → controller}/ObjectController.d.ts +1 -1
- package/dist/{core/controller → controller}/ObjectController.js +1 -1
- package/dist/{core/controller → controller}/SettingsController.d.ts +2 -2
- package/dist/{core/controller → controller}/SharedContentController.d.ts +1 -1
- package/dist/{core/controller → controller}/VoiceController.d.ts +1 -1
- package/dist/index.d.ts +14 -8
- package/dist/index.js +7 -7
- package/dist/plugin/{PluginController.d.ts → CommunicationHandler.d.ts} +4 -7
- package/dist/plugin/{PluginController.js → CommunicationHandler.js} +19 -27
- package/dist/plugin/RimoriClient.d.ts +67 -68
- package/dist/plugin/RimoriClient.js +101 -43
- package/dist/worker/WorkerSetup.js +3 -3
- package/example/docs/devdocs.md +1 -1
- package/package.json +5 -26
- package/src/{core/controller → controller}/AIController.ts +3 -3
- package/src/{plugin/AccomplishmentHandler.ts → controller/AccomplishmentController.ts} +1 -1
- package/src/{core/controller → controller}/ExerciseController.ts +14 -11
- package/src/{core/controller → controller}/ObjectController.ts +2 -2
- package/src/{core/controller → controller}/SettingsController.ts +2 -2
- package/src/{core/controller → controller}/SharedContentController.ts +1 -1
- package/src/{core/controller → controller}/VoiceController.ts +2 -2
- package/src/fromRimori/readme.md +1 -1
- package/src/index.ts +14 -8
- package/src/plugin/{PluginController.ts → CommunicationHandler.ts} +24 -36
- package/src/plugin/RimoriClient.ts +127 -118
- package/src/worker/WorkerSetup.ts +6 -4
- package/tsconfig.json +5 -2
- package/dist/cli/scripts/release/release-translation-upload.d.ts +0 -6
- package/dist/cli/scripts/release/release-translation-upload.js +0 -87
- package/dist/components/CRUDModal.d.ts +0 -17
- package/dist/components/CRUDModal.js +0 -24
- package/dist/components/MarkdownEditor.d.ts +0 -8
- package/dist/components/MarkdownEditor.js +0 -48
- package/dist/components/Spinner.d.ts +0 -8
- package/dist/components/Spinner.js +0 -4
- package/dist/components/ai/Assistant.d.ts +0 -9
- package/dist/components/ai/Assistant.js +0 -58
- package/dist/components/ai/Avatar.d.ts +0 -14
- package/dist/components/ai/Avatar.js +0 -59
- package/dist/components/ai/EmbeddedAssistent/AudioInputField.d.ts +0 -7
- package/dist/components/ai/EmbeddedAssistent/AudioInputField.js +0 -37
- package/dist/components/ai/EmbeddedAssistent/CircleAudioAvatar.d.ts +0 -8
- package/dist/components/ai/EmbeddedAssistent/CircleAudioAvatar.js +0 -79
- package/dist/components/ai/EmbeddedAssistent/TTS/MessageSender.d.ts +0 -19
- package/dist/components/ai/EmbeddedAssistent/TTS/MessageSender.js +0 -91
- package/dist/components/ai/EmbeddedAssistent/TTS/Player.d.ts +0 -27
- package/dist/components/ai/EmbeddedAssistent/TTS/Player.js +0 -185
- package/dist/components/ai/EmbeddedAssistent/VoiceRecoder.d.ts +0 -11
- package/dist/components/ai/EmbeddedAssistent/VoiceRecoder.js +0 -95
- package/dist/components/ai/utils.d.ts +0 -6
- package/dist/components/ai/utils.js +0 -13
- package/dist/components/audio/Playbutton.d.ts +0 -15
- package/dist/components/audio/Playbutton.js +0 -80
- package/dist/components/components/ContextMenu.d.ts +0 -10
- package/dist/components/components/ContextMenu.js +0 -135
- package/dist/components.d.ts +0 -10
- package/dist/components.js +0 -11
- package/dist/core/controller/EnhancedUserInfo.d.ts +0 -0
- package/dist/core/controller/EnhancedUserInfo.js +0 -1
- package/dist/core/core.d.ts +0 -14
- package/dist/core/core.js +0 -7
- package/dist/hooks/I18nHooks.d.ts +0 -11
- package/dist/hooks/I18nHooks.js +0 -25
- package/dist/hooks/UseChatHook.d.ts +0 -10
- package/dist/hooks/UseChatHook.js +0 -29
- package/dist/i18n/I18nHooks.d.ts +0 -11
- package/dist/i18n/I18nHooks.js +0 -25
- package/dist/i18n/Translator.d.ts +0 -43
- package/dist/i18n/Translator.js +0 -118
- package/dist/i18n/config.d.ts +0 -7
- package/dist/i18n/config.js +0 -20
- package/dist/i18n/createI18nInstance.d.ts +0 -7
- package/dist/i18n/createI18nInstance.js +0 -31
- package/dist/i18n/hooks.d.ts +0 -11
- package/dist/i18n/hooks.js +0 -25
- package/dist/i18n/index.d.ts +0 -4
- package/dist/i18n/index.js +0 -4
- package/dist/i18n/types.d.ts +0 -7
- package/dist/i18n/types.js +0 -1
- package/dist/i18n/useRimoriI18n.d.ts +0 -11
- package/dist/i18n/useRimoriI18n.js +0 -41
- package/dist/plugin/ThemeSetter.d.ts +0 -2
- package/dist/plugin/ThemeSetter.js +0 -19
- package/dist/plugin/Translator.d.ts +0 -38
- package/dist/plugin/Translator.js +0 -101
- package/dist/providers/PluginProvider.d.ts +0 -12
- package/dist/providers/PluginProvider.js +0 -152
- package/dist/style.css +0 -110
- package/dist/style.css.map +0 -1
- package/dist/utils/Language.d.ts +0 -67
- package/dist/utils/Language.js +0 -69
- package/dist/utils/LanguageClass.d.ts +0 -36
- package/dist/utils/LanguageClass.example.d.ts +0 -0
- package/dist/utils/LanguageClass.example.js +0 -1
- package/dist/utils/LanguageClass.js +0 -50
- package/dist/utils/LanguageClass.test.d.ts +0 -0
- package/dist/utils/LanguageClass.test.js +0 -1
- package/dist/utils/PluginUtils.d.ts +0 -2
- package/dist/utils/PluginUtils.js +0 -23
- package/src/components/CRUDModal.tsx +0 -75
- package/src/components/MarkdownEditor.tsx +0 -144
- package/src/components/Spinner.tsx +0 -29
- package/src/components/ai/Assistant.tsx +0 -96
- package/src/components/ai/Avatar.tsx +0 -99
- package/src/components/ai/EmbeddedAssistent/AudioInputField.tsx +0 -73
- package/src/components/ai/EmbeddedAssistent/CircleAudioAvatar.tsx +0 -107
- package/src/components/ai/EmbeddedAssistent/TTS/MessageSender.ts +0 -96
- package/src/components/ai/EmbeddedAssistent/TTS/Player.ts +0 -197
- package/src/components/ai/EmbeddedAssistent/VoiceRecoder.tsx +0 -129
- package/src/components/ai/utils.ts +0 -21
- package/src/components/audio/Playbutton.tsx +0 -126
- package/src/components/components/ContextMenu.tsx +0 -179
- package/src/components.ts +0 -11
- package/src/core/core.ts +0 -15
- package/src/hooks/I18nHooks.ts +0 -33
- package/src/hooks/UseChatHook.ts +0 -38
- package/src/plugin/ThemeSetter.ts +0 -23
- package/src/providers/PluginProvider.tsx +0 -209
- package/src/style.scss +0 -136
- package/src/utils/PluginUtils.ts +0 -22
- /package/dist/{plugin → controller}/AudioController.d.ts +0 -0
- /package/dist/{plugin → controller}/AudioController.js +0 -0
- /package/dist/{core/controller → controller}/SettingsController.js +0 -0
- /package/dist/{core/controller → controller}/SharedContentController.js +0 -0
- /package/dist/{plugin → controller}/TranslationController.d.ts +0 -0
- /package/dist/{plugin → controller}/TranslationController.js +0 -0
- /package/dist/{core/controller → controller}/VoiceController.js +0 -0
- /package/src/{plugin → controller}/AudioController.ts +0 -0
- /package/src/{plugin → controller}/TranslationController.ts +0 -0
|
@@ -1,129 +0,0 @@
|
|
|
1
|
-
import { useRimori } from '../../../components';
|
|
2
|
-
import { FaMicrophone, FaSpinner } from 'react-icons/fa6';
|
|
3
|
-
import { AudioController } from '../../../plugin/AudioController';
|
|
4
|
-
import { useState, useRef, forwardRef, useImperativeHandle, useEffect } from 'react';
|
|
5
|
-
|
|
6
|
-
interface Props {
|
|
7
|
-
iconSize?: string;
|
|
8
|
-
className?: string;
|
|
9
|
-
disabled?: boolean;
|
|
10
|
-
loading?: boolean;
|
|
11
|
-
enablePushToTalk?: boolean;
|
|
12
|
-
onRecordingStatusChange: (running: boolean) => void;
|
|
13
|
-
onVoiceRecorded: (message: string) => void;
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
export const VoiceRecorder = forwardRef(
|
|
17
|
-
(
|
|
18
|
-
{
|
|
19
|
-
onVoiceRecorded,
|
|
20
|
-
iconSize,
|
|
21
|
-
className,
|
|
22
|
-
disabled,
|
|
23
|
-
loading,
|
|
24
|
-
onRecordingStatusChange,
|
|
25
|
-
enablePushToTalk = false,
|
|
26
|
-
}: Props,
|
|
27
|
-
ref,
|
|
28
|
-
) => {
|
|
29
|
-
const [isRecording, setIsRecording] = useState(false);
|
|
30
|
-
const [internalIsProcessing, setInternalIsProcessing] = useState(false);
|
|
31
|
-
const audioControllerRef = useRef<AudioController | null>(null);
|
|
32
|
-
const { ai, plugin } = useRimori();
|
|
33
|
-
|
|
34
|
-
// Ref for latest onVoiceRecorded callback
|
|
35
|
-
const onVoiceRecordedRef = useRef(onVoiceRecorded);
|
|
36
|
-
useEffect(() => {
|
|
37
|
-
onVoiceRecordedRef.current = onVoiceRecorded;
|
|
38
|
-
}, [onVoiceRecorded]);
|
|
39
|
-
|
|
40
|
-
const startRecording = async () => {
|
|
41
|
-
try {
|
|
42
|
-
if (!audioControllerRef.current) {
|
|
43
|
-
audioControllerRef.current = new AudioController(plugin.pluginId);
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
await audioControllerRef.current.startRecording();
|
|
47
|
-
setIsRecording(true);
|
|
48
|
-
onRecordingStatusChange(true);
|
|
49
|
-
} catch (error) {
|
|
50
|
-
console.error('Failed to start recording:', error);
|
|
51
|
-
// Handle permission denied or other errors
|
|
52
|
-
}
|
|
53
|
-
};
|
|
54
|
-
|
|
55
|
-
const stopRecording = async () => {
|
|
56
|
-
try {
|
|
57
|
-
if (audioControllerRef.current && isRecording) {
|
|
58
|
-
const audioResult = await audioControllerRef.current.stopRecording();
|
|
59
|
-
// console.log("audioResult: ", audioResult);
|
|
60
|
-
|
|
61
|
-
setInternalIsProcessing(true);
|
|
62
|
-
|
|
63
|
-
// Play the recorded audio from the Blob
|
|
64
|
-
// const blobUrl = URL.createObjectURL(audioResult.recording);
|
|
65
|
-
// const audioRef = new Audio(blobUrl);
|
|
66
|
-
// audioRef.onended = () => URL.revokeObjectURL(blobUrl);
|
|
67
|
-
// audioRef.play().catch((e) => console.error('Playback error:', e));
|
|
68
|
-
|
|
69
|
-
// console.log("audioBlob: ", audioResult.recording);
|
|
70
|
-
const text = await ai.getTextFromVoice(audioResult.recording);
|
|
71
|
-
// console.log("stt result", text);
|
|
72
|
-
// throw new Error("test");
|
|
73
|
-
setInternalIsProcessing(false);
|
|
74
|
-
onVoiceRecordedRef.current(text);
|
|
75
|
-
}
|
|
76
|
-
} catch (error) {
|
|
77
|
-
console.error('Failed to stop recording:', error);
|
|
78
|
-
} finally {
|
|
79
|
-
setIsRecording(false);
|
|
80
|
-
onRecordingStatusChange(false);
|
|
81
|
-
}
|
|
82
|
-
};
|
|
83
|
-
|
|
84
|
-
useImperativeHandle(ref, () => ({
|
|
85
|
-
startRecording,
|
|
86
|
-
stopRecording,
|
|
87
|
-
}));
|
|
88
|
-
|
|
89
|
-
// push to talk feature
|
|
90
|
-
const spacePressedRef = useRef(false);
|
|
91
|
-
|
|
92
|
-
useEffect(() => {
|
|
93
|
-
if (!enablePushToTalk) return;
|
|
94
|
-
|
|
95
|
-
const handleKeyDown = async (event: KeyboardEvent) => {
|
|
96
|
-
if (event.code === 'Space' && !spacePressedRef.current) {
|
|
97
|
-
spacePressedRef.current = true;
|
|
98
|
-
await startRecording();
|
|
99
|
-
}
|
|
100
|
-
};
|
|
101
|
-
const handleKeyUp = (event: KeyboardEvent) => {
|
|
102
|
-
if (event.code === 'Space' && spacePressedRef.current) {
|
|
103
|
-
spacePressedRef.current = false;
|
|
104
|
-
stopRecording();
|
|
105
|
-
}
|
|
106
|
-
};
|
|
107
|
-
window.addEventListener('keydown', handleKeyDown);
|
|
108
|
-
window.addEventListener('keyup', handleKeyUp);
|
|
109
|
-
return () => {
|
|
110
|
-
window.removeEventListener('keydown', handleKeyDown);
|
|
111
|
-
window.removeEventListener('keyup', handleKeyUp);
|
|
112
|
-
};
|
|
113
|
-
}, [enablePushToTalk]);
|
|
114
|
-
|
|
115
|
-
return (
|
|
116
|
-
<button
|
|
117
|
-
className={'flex flex-row justify-center items-center rounded-full mx-auto disabled:opacity-50 ' + className}
|
|
118
|
-
onClick={isRecording ? stopRecording : startRecording}
|
|
119
|
-
disabled={disabled || loading || internalIsProcessing}
|
|
120
|
-
>
|
|
121
|
-
{loading || internalIsProcessing ? (
|
|
122
|
-
<FaSpinner className="animate-spin" />
|
|
123
|
-
) : (
|
|
124
|
-
<FaMicrophone size={iconSize} className={isRecording ? 'text-red-600' : ''} />
|
|
125
|
-
)}
|
|
126
|
-
</button>
|
|
127
|
-
);
|
|
128
|
-
},
|
|
129
|
-
);
|
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
export interface FirstMessages {
|
|
2
|
-
instructions?: string;
|
|
3
|
-
userMessage?: string;
|
|
4
|
-
assistantMessage?: string;
|
|
5
|
-
}
|
|
6
|
-
|
|
7
|
-
export function getFirstMessages(instructions: FirstMessages): any[] {
|
|
8
|
-
const messages = [];
|
|
9
|
-
|
|
10
|
-
if (instructions.instructions) {
|
|
11
|
-
messages.push({ id: '1', role: 'system', content: instructions.instructions });
|
|
12
|
-
}
|
|
13
|
-
if (instructions.userMessage) {
|
|
14
|
-
messages.push({ id: '2', role: 'user', content: instructions.userMessage });
|
|
15
|
-
}
|
|
16
|
-
if (instructions.assistantMessage) {
|
|
17
|
-
messages.push({ id: '3', role: 'assistant', content: instructions.assistantMessage });
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
return messages;
|
|
21
|
-
}
|
|
@@ -1,126 +0,0 @@
|
|
|
1
|
-
import React, { useState, useEffect } from 'react';
|
|
2
|
-
import { FaPlayCircle, FaStopCircle } from 'react-icons/fa';
|
|
3
|
-
import { useRimori } from '../../providers/PluginProvider';
|
|
4
|
-
import { Spinner } from '../Spinner';
|
|
5
|
-
import { EventBus } from '../../fromRimori/EventBus';
|
|
6
|
-
|
|
7
|
-
type AudioPlayerProps = {
|
|
8
|
-
text: string;
|
|
9
|
-
voice?: string;
|
|
10
|
-
language?: string;
|
|
11
|
-
hide?: boolean;
|
|
12
|
-
playOnMount?: boolean;
|
|
13
|
-
initialSpeed?: number;
|
|
14
|
-
enableSpeedAdjustment?: boolean;
|
|
15
|
-
playListenerEvent?: string;
|
|
16
|
-
};
|
|
17
|
-
|
|
18
|
-
export const AudioPlayOptions = [0.8, 0.9, 1.0, 1.1, 1.2, 1.5];
|
|
19
|
-
export type AudioPlayOptionType = 0.8 | 0.9 | 1.0 | 1.1 | 1.2 | 1.5;
|
|
20
|
-
|
|
21
|
-
let isFetchingAudio = false;
|
|
22
|
-
|
|
23
|
-
export const AudioPlayer: React.FC<AudioPlayerProps> = ({
|
|
24
|
-
text,
|
|
25
|
-
voice,
|
|
26
|
-
language,
|
|
27
|
-
hide,
|
|
28
|
-
playListenerEvent,
|
|
29
|
-
initialSpeed = 1.0,
|
|
30
|
-
playOnMount = false,
|
|
31
|
-
enableSpeedAdjustment = false,
|
|
32
|
-
}) => {
|
|
33
|
-
const [audioUrl, setAudioUrl] = useState<string | null>(null);
|
|
34
|
-
const [speed, setSpeed] = useState(initialSpeed);
|
|
35
|
-
const [isPlaying, setIsPlaying] = useState(false);
|
|
36
|
-
const [isLoading, setIsLoading] = useState(false);
|
|
37
|
-
const { ai } = useRimori();
|
|
38
|
-
|
|
39
|
-
useEffect(() => {
|
|
40
|
-
if (!playListenerEvent) return;
|
|
41
|
-
EventBus.on(playListenerEvent, () => togglePlayback());
|
|
42
|
-
}, [playListenerEvent]);
|
|
43
|
-
|
|
44
|
-
useEffect(() => {
|
|
45
|
-
audioUrl && setAudioUrl(null);
|
|
46
|
-
return () => {
|
|
47
|
-
audioUrl && URL.revokeObjectURL(audioUrl);
|
|
48
|
-
};
|
|
49
|
-
}, [text]);
|
|
50
|
-
|
|
51
|
-
// Function to generate audio from text using API
|
|
52
|
-
const generateAudio = async () => {
|
|
53
|
-
setIsLoading(true);
|
|
54
|
-
|
|
55
|
-
const blob = await ai.getVoice(text, voice || (language ? 'aws_default' : 'openai_alloy'), 1, language);
|
|
56
|
-
setAudioUrl(URL.createObjectURL(blob));
|
|
57
|
-
setIsLoading(false);
|
|
58
|
-
};
|
|
59
|
-
|
|
60
|
-
// Effect to play audio when audioUrl changes and play state is true
|
|
61
|
-
useEffect(() => {
|
|
62
|
-
if (!audioUrl || !isPlaying) return;
|
|
63
|
-
const audio = new Audio(audioUrl);
|
|
64
|
-
audio.playbackRate = speed;
|
|
65
|
-
audio
|
|
66
|
-
.play()
|
|
67
|
-
.then(() => {
|
|
68
|
-
audio.onended = () => {
|
|
69
|
-
setIsPlaying(false);
|
|
70
|
-
isFetchingAudio = false;
|
|
71
|
-
};
|
|
72
|
-
})
|
|
73
|
-
.catch((e) => {
|
|
74
|
-
console.warn('Error playing audio:', e);
|
|
75
|
-
setIsPlaying(false);
|
|
76
|
-
});
|
|
77
|
-
|
|
78
|
-
return () => {
|
|
79
|
-
audio.pause();
|
|
80
|
-
};
|
|
81
|
-
}, [audioUrl, isPlaying, speed]);
|
|
82
|
-
|
|
83
|
-
const togglePlayback = () => {
|
|
84
|
-
if (!isPlaying && !audioUrl) {
|
|
85
|
-
generateAudio().then(() => setIsPlaying(true));
|
|
86
|
-
} else {
|
|
87
|
-
setIsPlaying((prev) => !prev);
|
|
88
|
-
}
|
|
89
|
-
};
|
|
90
|
-
|
|
91
|
-
useEffect(() => {
|
|
92
|
-
if (!playOnMount || isFetchingAudio) return;
|
|
93
|
-
isFetchingAudio = true;
|
|
94
|
-
// console.log("playOnMount", playOnMount);
|
|
95
|
-
togglePlayback();
|
|
96
|
-
}, [playOnMount]);
|
|
97
|
-
|
|
98
|
-
return (
|
|
99
|
-
<div className="group relative">
|
|
100
|
-
<div className="flex flex-row items-end">
|
|
101
|
-
{!hide && (
|
|
102
|
-
<button className="text-gray-500" onClick={togglePlayback} disabled={isLoading}>
|
|
103
|
-
{isLoading ? <Spinner /> : isPlaying ? <FaStopCircle size={'25px'} /> : <FaPlayCircle size={'25px'} />}
|
|
104
|
-
</button>
|
|
105
|
-
)}
|
|
106
|
-
{enableSpeedAdjustment && (
|
|
107
|
-
<div className="ml-1 opacity-0 group-hover:opacity-100 transition-opacity duration-300 flex flex-row text-sm text-gray-500">
|
|
108
|
-
<span className="pr-1">Speed: </span>
|
|
109
|
-
<select
|
|
110
|
-
value={speed}
|
|
111
|
-
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"
|
|
112
|
-
onChange={(e) => setSpeed(parseFloat(e.target.value))}
|
|
113
|
-
disabled={isLoading}
|
|
114
|
-
>
|
|
115
|
-
{AudioPlayOptions.map((s) => (
|
|
116
|
-
<option key={s} value={s}>
|
|
117
|
-
{s}
|
|
118
|
-
</option>
|
|
119
|
-
))}
|
|
120
|
-
</select>
|
|
121
|
-
</div>
|
|
122
|
-
)}
|
|
123
|
-
</div>
|
|
124
|
-
</div>
|
|
125
|
-
);
|
|
126
|
-
};
|
|
@@ -1,179 +0,0 @@
|
|
|
1
|
-
import React, { useState, useEffect, useRef } from 'react';
|
|
2
|
-
import { EventBus } from '../../fromRimori/EventBus';
|
|
3
|
-
import { RimoriClient } from '../../plugin/RimoriClient';
|
|
4
|
-
import { MenuEntry } from '../../fromRimori/PluginTypes';
|
|
5
|
-
|
|
6
|
-
export interface Position {
|
|
7
|
-
x: number;
|
|
8
|
-
y: number;
|
|
9
|
-
text?: string;
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
const ContextMenu = ({ client }: { client: RimoriClient }) => {
|
|
13
|
-
const [isOpen, setIsOpen] = useState<boolean>(false);
|
|
14
|
-
const [actions, setActions] = useState<MenuEntry[]>([]);
|
|
15
|
-
const [position, setPosition] = useState<Position>({ x: 0, y: 0 });
|
|
16
|
-
const [openOnTextSelect, setOpenOnTextSelect] = useState(false);
|
|
17
|
-
const [menuWidth, setMenuWidth] = useState<number>(0);
|
|
18
|
-
const menuRef = useRef<HTMLDivElement>(null);
|
|
19
|
-
const isMobile = window.innerWidth < 768;
|
|
20
|
-
|
|
21
|
-
/**
|
|
22
|
-
* Calculates position for mobile context menu based on selected text bounds.
|
|
23
|
-
* Centers the menu horizontally over the selected text and positions it 30px below the text's end.
|
|
24
|
-
* @param selectedText - The currently selected text
|
|
25
|
-
* @param menuWidth - The width of the menu to center properly
|
|
26
|
-
* @returns Position object with x and y coordinates
|
|
27
|
-
*/
|
|
28
|
-
const calculateMobilePosition = (selectedText: string, menuWidth: number = 0): Position => {
|
|
29
|
-
const selection = window.getSelection();
|
|
30
|
-
if (!selection || !selectedText) {
|
|
31
|
-
return { x: 0, y: 0, text: selectedText };
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
const range = selection.getRangeAt(0);
|
|
35
|
-
const rect = range.getBoundingClientRect();
|
|
36
|
-
|
|
37
|
-
// Center horizontally over the selected text, accounting for menu width
|
|
38
|
-
const centerX = rect.left + rect.width / 2 - menuWidth / 2;
|
|
39
|
-
|
|
40
|
-
// Position 12px below where the text ends vertically
|
|
41
|
-
const textEndY = rect.bottom + 12;
|
|
42
|
-
|
|
43
|
-
return { x: centerX, y: textEndY, text: selectedText };
|
|
44
|
-
};
|
|
45
|
-
|
|
46
|
-
useEffect(() => {
|
|
47
|
-
const actions = client.plugin
|
|
48
|
-
.getPluginInfo()
|
|
49
|
-
.installedPlugins.flatMap((p) => p.context_menu_actions)
|
|
50
|
-
.filter(Boolean);
|
|
51
|
-
setActions(actions);
|
|
52
|
-
setOpenOnTextSelect(client.plugin.getUserInfo().context_menu_on_select);
|
|
53
|
-
|
|
54
|
-
EventBus.on<{ actions: MenuEntry[] }>('global.contextMenu.createActions', ({ data }) => {
|
|
55
|
-
setActions([...data.actions, ...actions]);
|
|
56
|
-
});
|
|
57
|
-
}, []);
|
|
58
|
-
|
|
59
|
-
// Update menu width when menu is rendered
|
|
60
|
-
useEffect(() => {
|
|
61
|
-
if (isOpen && menuRef.current) {
|
|
62
|
-
setMenuWidth(menuRef.current.offsetWidth);
|
|
63
|
-
}
|
|
64
|
-
}, [isOpen, actions]);
|
|
65
|
-
|
|
66
|
-
useEffect(() => {
|
|
67
|
-
// Track mouse position globally
|
|
68
|
-
const handleMouseMove = (e: MouseEvent) => {
|
|
69
|
-
const selectedText = window.getSelection()?.toString().trim();
|
|
70
|
-
if (isOpen && selectedText === position.text) return;
|
|
71
|
-
|
|
72
|
-
if (isMobile && selectedText) {
|
|
73
|
-
setPosition(calculateMobilePosition(selectedText, menuWidth));
|
|
74
|
-
} else {
|
|
75
|
-
setPosition({ x: e.clientX, y: e.clientY, text: selectedText });
|
|
76
|
-
}
|
|
77
|
-
};
|
|
78
|
-
|
|
79
|
-
const handleMouseUp = (e: MouseEvent) => {
|
|
80
|
-
const selectedText = window.getSelection()?.toString().trim();
|
|
81
|
-
// Check if click is inside the context menu
|
|
82
|
-
if (menuRef.current && menuRef.current.contains(e.target as Node)) {
|
|
83
|
-
// Don't close the menu if clicking inside
|
|
84
|
-
return;
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
// Prevent context menu on textarea or text input selection
|
|
88
|
-
const target = e.target as HTMLElement;
|
|
89
|
-
const isTextInput =
|
|
90
|
-
target &&
|
|
91
|
-
(target.tagName === 'TEXTAREA' || (target.tagName === 'INPUT' && (target as HTMLInputElement).type === 'text'));
|
|
92
|
-
if (isTextInput) {
|
|
93
|
-
setIsOpen(false);
|
|
94
|
-
return;
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
if (e.button === 0 && isOpen) {
|
|
98
|
-
setIsOpen(false);
|
|
99
|
-
window.getSelection()?.removeAllRanges();
|
|
100
|
-
} else if (selectedText && (openOnTextSelect || e.button === 2)) {
|
|
101
|
-
if (e.button === 2) {
|
|
102
|
-
e.preventDefault();
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
if (isMobile) {
|
|
106
|
-
setPosition(calculateMobilePosition(selectedText, menuWidth));
|
|
107
|
-
} else {
|
|
108
|
-
setPosition({ x: e.clientX, y: e.clientY, text: selectedText });
|
|
109
|
-
}
|
|
110
|
-
setIsOpen(true);
|
|
111
|
-
} else {
|
|
112
|
-
setIsOpen(false);
|
|
113
|
-
}
|
|
114
|
-
};
|
|
115
|
-
|
|
116
|
-
// Add selectionchange listener to close menu if selection is cleared and update position for mobile
|
|
117
|
-
const handleSelectionChange = () => {
|
|
118
|
-
const selectedText = window.getSelection()?.toString().trim();
|
|
119
|
-
if (!selectedText && isOpen) {
|
|
120
|
-
setIsOpen(false);
|
|
121
|
-
} else if (selectedText && isOpen && isMobile) {
|
|
122
|
-
// Update position in real-time as text selection changes on mobile
|
|
123
|
-
setPosition(calculateMobilePosition(selectedText, menuWidth));
|
|
124
|
-
}
|
|
125
|
-
};
|
|
126
|
-
|
|
127
|
-
document.addEventListener('mouseup', handleMouseUp);
|
|
128
|
-
window.addEventListener('mousemove', handleMouseMove);
|
|
129
|
-
document.addEventListener('contextmenu', handleMouseUp);
|
|
130
|
-
document.addEventListener('selectionchange', handleSelectionChange);
|
|
131
|
-
|
|
132
|
-
return () => {
|
|
133
|
-
document.removeEventListener('mouseup', handleMouseUp);
|
|
134
|
-
window.removeEventListener('mousemove', handleMouseMove);
|
|
135
|
-
document.removeEventListener('contextmenu', handleMouseUp);
|
|
136
|
-
document.removeEventListener('selectionchange', handleSelectionChange);
|
|
137
|
-
};
|
|
138
|
-
}, [openOnTextSelect, isOpen, position.text]);
|
|
139
|
-
|
|
140
|
-
if (!isOpen) {
|
|
141
|
-
return null;
|
|
142
|
-
}
|
|
143
|
-
|
|
144
|
-
return (
|
|
145
|
-
<div
|
|
146
|
-
ref={menuRef}
|
|
147
|
-
className="fixed bg-gray-400 dark:bg-gray-700 shadow-lg border border-gray-400 rounded-md overflow-hidden dark:text-white z-50"
|
|
148
|
-
style={{ top: position.y, left: position.x }}
|
|
149
|
-
>
|
|
150
|
-
{actions.map((action, index) => (
|
|
151
|
-
<MenuEntryItem
|
|
152
|
-
key={index}
|
|
153
|
-
icon={action.icon}
|
|
154
|
-
text={action.text}
|
|
155
|
-
onClick={() => {
|
|
156
|
-
setIsOpen(false);
|
|
157
|
-
window.getSelection()?.removeAllRanges();
|
|
158
|
-
client.event.emitSidebarAction(action.plugin_id, action.action_key, position.text);
|
|
159
|
-
}}
|
|
160
|
-
/>
|
|
161
|
-
))}
|
|
162
|
-
</div>
|
|
163
|
-
);
|
|
164
|
-
};
|
|
165
|
-
|
|
166
|
-
function MenuEntryItem(props: { icon: React.ReactNode; text: string; onClick: () => void }) {
|
|
167
|
-
return (
|
|
168
|
-
<button
|
|
169
|
-
onClick={props.onClick}
|
|
170
|
-
className="px-4 py-2 text-left hover:bg-gray-500 dark:hover:bg-gray-600 w-full flex flex-row"
|
|
171
|
-
>
|
|
172
|
-
<span className="flex-grow">{props.icon}</span>
|
|
173
|
-
<span className="flex-grow">{props.text}</span>
|
|
174
|
-
{/* <span className="text-sm">Ctrl+Shift+xxxx</span> */}
|
|
175
|
-
</button>
|
|
176
|
-
);
|
|
177
|
-
}
|
|
178
|
-
|
|
179
|
-
export default ContextMenu;
|
package/src/components.ts
DELETED
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
// React components and hooks exports
|
|
2
|
-
export * from './components/ai/Assistant';
|
|
3
|
-
export * from './components/ai/Avatar';
|
|
4
|
-
export * from './components/ai/EmbeddedAssistent/VoiceRecoder';
|
|
5
|
-
export * from './components/audio/Playbutton';
|
|
6
|
-
export * from './components/CRUDModal';
|
|
7
|
-
export * from './components/MarkdownEditor';
|
|
8
|
-
export * from './components/Spinner';
|
|
9
|
-
export * from './hooks/UseChatHook';
|
|
10
|
-
export * from './plugin/ThemeSetter';
|
|
11
|
-
export * from './providers/PluginProvider';
|
package/src/core/core.ts
DELETED
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
// Core functionality exports
|
|
2
|
-
export * from '../fromRimori/PluginTypes';
|
|
3
|
-
export * from '../plugin/PluginController';
|
|
4
|
-
export * from '../plugin/RimoriClient';
|
|
5
|
-
export * from '../utils/difficultyConverter';
|
|
6
|
-
export * from '../utils/PluginUtils';
|
|
7
|
-
export * from '../worker/WorkerSetup';
|
|
8
|
-
export { EventBusMessage } from '../fromRimori/EventBus';
|
|
9
|
-
export { Buddy, UserInfo, Language } from './controller/SettingsController';
|
|
10
|
-
export { SharedContent } from './controller/SharedContentController';
|
|
11
|
-
export { Exercise, TriggerAction } from './controller/ExerciseController';
|
|
12
|
-
export { Message, OnLLMResponse, ToolInvocation } from './controller/AIController';
|
|
13
|
-
export { MacroAccomplishmentPayload, MicroAccomplishmentPayload } from '../plugin/AccomplishmentHandler';
|
|
14
|
-
export { Tool } from '../fromRimori/PluginTypes';
|
|
15
|
-
export { SharedContentObjectRequest } from './controller/SharedContentController';
|
package/src/hooks/I18nHooks.ts
DELETED
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
import { TOptions } from 'i18next';
|
|
2
|
-
import { useEffect, useState } from 'react';
|
|
3
|
-
import { Translator } from '../plugin/TranslationController';
|
|
4
|
-
import { useRimori } from '../providers/PluginProvider';
|
|
5
|
-
|
|
6
|
-
type TranslatorFn = (key: string, options?: TOptions) => string;
|
|
7
|
-
|
|
8
|
-
/**
|
|
9
|
-
* Custom useTranslation hook that provides a translation function and indicates readiness
|
|
10
|
-
* @returns An object containing the translation function (`t`) and a boolean (`ready`) indicating if the translator is initialized.
|
|
11
|
-
*/
|
|
12
|
-
export function useTranslation(): { t: TranslatorFn; ready: boolean } {
|
|
13
|
-
const { plugin } = useRimori();
|
|
14
|
-
const [translatorInstance, setTranslatorInstance] = useState<Translator | null>(null);
|
|
15
|
-
|
|
16
|
-
useEffect(() => {
|
|
17
|
-
void plugin.getTranslator().then(setTranslatorInstance);
|
|
18
|
-
}, [plugin]);
|
|
19
|
-
|
|
20
|
-
const safeT = (key: string, options?: TOptions): string => {
|
|
21
|
-
// return zero-width space if translator is not initialized to keep text space occupied
|
|
22
|
-
if (!translatorInstance) return '\u200B'; // zero-width space
|
|
23
|
-
|
|
24
|
-
const result = translatorInstance.t(key, options);
|
|
25
|
-
if (!result) {
|
|
26
|
-
console.error(`Translation key not found: ${key}`);
|
|
27
|
-
return '\u200B'; // zero-width space
|
|
28
|
-
}
|
|
29
|
-
return result;
|
|
30
|
-
};
|
|
31
|
-
|
|
32
|
-
return { t: safeT, ready: translatorInstance !== null };
|
|
33
|
-
}
|
package/src/hooks/UseChatHook.ts
DELETED
|
@@ -1,38 +0,0 @@
|
|
|
1
|
-
import React from 'react';
|
|
2
|
-
import { Tool } from '../fromRimori/PluginTypes';
|
|
3
|
-
import { useRimori } from '../providers/PluginProvider';
|
|
4
|
-
import { Message, ToolInvocation } from '../core/controller/AIController';
|
|
5
|
-
|
|
6
|
-
export function useChat(tools?: Tool[]) {
|
|
7
|
-
const [messages, setMessages] = React.useState<Message[]>([]);
|
|
8
|
-
const [isLoading, setIsLoading] = React.useState(false);
|
|
9
|
-
const { ai } = useRimori();
|
|
10
|
-
|
|
11
|
-
const append = (appendMessages: Message[]) => {
|
|
12
|
-
const allMessages = [...messages, ...appendMessages];
|
|
13
|
-
setMessages(allMessages);
|
|
14
|
-
ai.getSteamedText(
|
|
15
|
-
allMessages,
|
|
16
|
-
(id, message, finished: boolean, toolInvocations?: ToolInvocation[]) => {
|
|
17
|
-
const lastMessage = messages[messages.length - 1];
|
|
18
|
-
setIsLoading(!finished);
|
|
19
|
-
|
|
20
|
-
if (lastMessage?.id === id) {
|
|
21
|
-
lastMessage.content = message;
|
|
22
|
-
setMessages([...messages, lastMessage]);
|
|
23
|
-
} else {
|
|
24
|
-
setMessages([...allMessages, { id, role: 'assistant', content: message, toolCalls: toolInvocations }]);
|
|
25
|
-
}
|
|
26
|
-
},
|
|
27
|
-
tools,
|
|
28
|
-
);
|
|
29
|
-
};
|
|
30
|
-
|
|
31
|
-
return {
|
|
32
|
-
messages,
|
|
33
|
-
append,
|
|
34
|
-
isLoading,
|
|
35
|
-
setMessages,
|
|
36
|
-
lastMessage: messages[messages.length - 1] as Message | undefined,
|
|
37
|
-
};
|
|
38
|
-
}
|
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
export function setTheme(theme?: string | null) {
|
|
2
|
-
document.documentElement.classList.add('dark:text-gray-200');
|
|
3
|
-
|
|
4
|
-
if (isDarkTheme(theme)) {
|
|
5
|
-
document.documentElement.setAttribute('data-theme', 'dark');
|
|
6
|
-
document.documentElement.classList.add('dark', 'dark:bg-gray-950');
|
|
7
|
-
document.documentElement.style.background = 'hsl(var(--background))';
|
|
8
|
-
}
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
export function isDarkTheme(theme?: string | null): boolean {
|
|
12
|
-
// If no theme provided, try to get from URL as fallback (for standalone mode)
|
|
13
|
-
if (!theme) {
|
|
14
|
-
const urlParams = new URLSearchParams(window.location.search);
|
|
15
|
-
theme = urlParams.get('theme');
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
if (!theme || theme === 'system') {
|
|
19
|
-
return window.matchMedia && window.matchMedia('(prefers-color-scheme: dark)').matches;
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
return theme === 'dark';
|
|
23
|
-
}
|