@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.
- package/README.md +142 -1
- package/dist/{react-client/src/components → components}/ContextMenu.js +1 -2
- package/dist/components/Spinner.d.ts +0 -7
- package/dist/components/Spinner.js +1 -4
- package/dist/components/ai/Assistant.js +1 -1
- package/dist/components/ai/Avatar.d.ts +2 -3
- package/dist/components/ai/Avatar.js +6 -4
- package/dist/components/ai/EmbeddedAssistent/AudioInputField.js +1 -1
- package/dist/components/ai/EmbeddedAssistent/CircleAudioAvatar.js +1 -1
- package/dist/components/ai/EmbeddedAssistent/VoiceRecoder.js +2 -2
- package/dist/components/audio/Playbutton.js +13 -9
- package/dist/hooks/I18nHooks.d.ts +1 -1
- package/dist/{react-client/src/plugin → hooks}/ThemeSetter.d.ts +1 -1
- package/dist/hooks/ThemeSetter.js +31 -0
- package/dist/hooks/UseChatHook.d.ts +2 -2
- package/dist/index.d.ts +9 -0
- package/dist/index.js +9 -0
- package/dist/{react-client/plugin → plugin}/ThemeSetter.d.ts +1 -1
- package/dist/plugin/ThemeSetter.js +31 -0
- package/dist/providers/PluginProvider.d.ts +2 -1
- package/dist/providers/PluginProvider.js +10 -7
- package/dist/{react-client/src/utils → utils}/FullscreenUtils.js +2 -2
- package/package.json +4 -7
- package/src/components/ContextMenu.tsx +2 -2
- package/src/components/ai/Avatar.tsx +9 -4
- package/src/components/ai/EmbeddedAssistent/AudioInputField.tsx +1 -1
- package/src/components/audio/Playbutton.tsx +28 -1
- package/src/hooks/ThemeSetter.ts +40 -0
- package/src/index.ts +10 -0
- package/src/providers/PluginProvider.tsx +12 -8
- package/tsconfig.json +6 -12
- package/dist/components/components/ContextMenu.d.ts +0 -10
- package/dist/components/components/ContextMenu.js +0 -135
- package/dist/react-client/plugin/ThemeSetter.js +0 -19
- package/dist/react-client/src/components/MarkdownEditor.d.ts +0 -8
- package/dist/react-client/src/components/MarkdownEditor.js +0 -48
- package/dist/react-client/src/components/Spinner.d.ts +0 -8
- package/dist/react-client/src/components/Spinner.js +0 -4
- package/dist/react-client/src/components/ai/Assistant.d.ts +0 -9
- package/dist/react-client/src/components/ai/Assistant.js +0 -58
- package/dist/react-client/src/components/ai/Avatar.d.ts +0 -14
- package/dist/react-client/src/components/ai/Avatar.js +0 -59
- package/dist/react-client/src/components/ai/EmbeddedAssistent/AudioInputField.d.ts +0 -7
- package/dist/react-client/src/components/ai/EmbeddedAssistent/AudioInputField.js +0 -37
- package/dist/react-client/src/components/ai/EmbeddedAssistent/CircleAudioAvatar.d.ts +0 -8
- package/dist/react-client/src/components/ai/EmbeddedAssistent/CircleAudioAvatar.js +0 -79
- package/dist/react-client/src/components/ai/EmbeddedAssistent/TTS/MessageSender.d.ts +0 -19
- package/dist/react-client/src/components/ai/EmbeddedAssistent/TTS/MessageSender.js +0 -91
- package/dist/react-client/src/components/ai/EmbeddedAssistent/TTS/Player.d.ts +0 -27
- package/dist/react-client/src/components/ai/EmbeddedAssistent/TTS/Player.js +0 -185
- package/dist/react-client/src/components/ai/utils.d.ts +0 -6
- package/dist/react-client/src/components/ai/utils.js +0 -13
- package/dist/react-client/src/components/audio/Playbutton.d.ts +0 -15
- package/dist/react-client/src/components/audio/Playbutton.js +0 -82
- package/dist/react-client/src/components/components/ContextMenu.d.ts +0 -10
- package/dist/react-client/src/components/components/ContextMenu.js +0 -135
- package/dist/react-client/src/hooks/I18nHooks.d.ts +0 -11
- package/dist/react-client/src/hooks/I18nHooks.js +0 -25
- package/dist/react-client/src/hooks/UseChatHook.d.ts +0 -10
- package/dist/react-client/src/hooks/UseChatHook.js +0 -29
- package/dist/react-client/src/plugin/ThemeSetter.js +0 -19
- package/dist/react-client/src/providers/PluginProvider.d.ts +0 -12
- package/dist/react-client/src/providers/PluginProvider.js +0 -142
- package/dist/react-client/src/utils/PluginUtils.d.ts +0 -2
- package/dist/react-client/src/utils/PluginUtils.js +0 -23
- package/dist/rimori-client/src/cli/types/DatabaseTypes.d.ts +0 -103
- package/dist/rimori-client/src/cli/types/DatabaseTypes.js +0 -2
- package/dist/rimori-client/src/controller/AIController.d.ts +0 -15
- package/dist/rimori-client/src/controller/AIController.js +0 -255
- package/dist/rimori-client/src/controller/AccomplishmentController.d.ts +0 -38
- package/dist/rimori-client/src/controller/AccomplishmentController.js +0 -112
- package/dist/rimori-client/src/controller/AudioController.d.ts +0 -37
- package/dist/rimori-client/src/controller/AudioController.js +0 -68
- package/dist/rimori-client/src/controller/ExerciseController.d.ts +0 -54
- package/dist/rimori-client/src/controller/ExerciseController.js +0 -74
- package/dist/rimori-client/src/controller/ObjectController.d.ts +0 -42
- package/dist/rimori-client/src/controller/ObjectController.js +0 -76
- package/dist/rimori-client/src/controller/SettingsController.d.ts +0 -79
- package/dist/rimori-client/src/controller/SettingsController.js +0 -118
- package/dist/rimori-client/src/controller/SharedContentController.d.ts +0 -106
- package/dist/rimori-client/src/controller/SharedContentController.js +0 -285
- package/dist/rimori-client/src/controller/TranslationController.d.ts +0 -38
- package/dist/rimori-client/src/controller/TranslationController.js +0 -106
- package/dist/rimori-client/src/controller/VoiceController.d.ts +0 -9
- package/dist/rimori-client/src/controller/VoiceController.js +0 -37
- package/dist/rimori-client/src/fromRimori/EventBus.d.ts +0 -101
- package/dist/rimori-client/src/fromRimori/EventBus.js +0 -263
- package/dist/rimori-client/src/fromRimori/PluginTypes.d.ts +0 -174
- package/dist/rimori-client/src/fromRimori/PluginTypes.js +0 -1
- package/dist/rimori-client/src/index.d.ts +0 -11
- package/dist/rimori-client/src/index.js +0 -10
- package/dist/rimori-client/src/plugin/CommunicationHandler.d.ts +0 -48
- package/dist/rimori-client/src/plugin/CommunicationHandler.js +0 -234
- package/dist/rimori-client/src/plugin/Logger.d.ts +0 -73
- package/dist/rimori-client/src/plugin/Logger.js +0 -308
- package/dist/rimori-client/src/plugin/RimoriClient.d.ts +0 -258
- package/dist/rimori-client/src/plugin/RimoriClient.js +0 -375
- package/dist/rimori-client/src/plugin/StandaloneClient.d.ts +0 -17
- package/dist/rimori-client/src/plugin/StandaloneClient.js +0 -115
- package/dist/rimori-client/src/utils/difficultyConverter.d.ts +0 -4
- package/dist/rimori-client/src/utils/difficultyConverter.js +0 -10
- package/dist/rimori-client/src/utils/endpoint.d.ts +0 -2
- package/dist/rimori-client/src/utils/endpoint.js +0 -2
- package/dist/utils/PluginUtils.d.ts +0 -2
- package/dist/utils/PluginUtils.js +0 -23
- package/index.ts +0 -6
- package/src/components/MarkdownEditor.tsx +0 -144
- package/src/components/Spinner.tsx +0 -29
- package/src/plugin/ThemeSetter.ts +0 -23
- package/src/utils/FullscreenUtils.ts +0 -22
- /package/dist/{react-client/src/components → components}/ContextMenu.d.ts +0 -0
- /package/dist/{react-client/src/components/ai/EmbeddedAssistent/VoiceRecoder.d.ts → components/ai/EmbeddedAssistent/VoiceRecorder.d.ts} +0 -0
- /package/dist/{react-client/src/components/ai/EmbeddedAssistent/VoiceRecoder.js → components/ai/EmbeddedAssistent/VoiceRecorder.js} +0 -0
- /package/dist/{react-client/src/utils → utils}/FullscreenUtils.d.ts +0 -0
- /package/src/components/ai/EmbeddedAssistent/{VoiceRecoder.tsx → VoiceRecorder.tsx} +0 -0
|
@@ -1,38 +0,0 @@
|
|
|
1
|
-
import { EventBusMessage } from '../fromRimori/EventBus';
|
|
2
|
-
export type AccomplishmentMessage = EventBusMessage<MicroAccomplishmentPayload>;
|
|
3
|
-
export declare const skillCategories: readonly ["reading", "listening", "speaking", "writing", "learning", "community"];
|
|
4
|
-
interface BaseAccomplishmentPayload {
|
|
5
|
-
type: 'micro' | 'macro';
|
|
6
|
-
skillCategory: (typeof skillCategories)[number];
|
|
7
|
-
accomplishmentKeyword: string;
|
|
8
|
-
description: string;
|
|
9
|
-
meta?: {
|
|
10
|
-
key: string;
|
|
11
|
-
value: string | number | boolean;
|
|
12
|
-
description: string;
|
|
13
|
-
}[];
|
|
14
|
-
}
|
|
15
|
-
export interface MicroAccomplishmentPayload extends BaseAccomplishmentPayload {
|
|
16
|
-
type: 'micro';
|
|
17
|
-
}
|
|
18
|
-
export interface MacroAccomplishmentPayload extends BaseAccomplishmentPayload {
|
|
19
|
-
type: 'macro';
|
|
20
|
-
errorRatio: number;
|
|
21
|
-
durationMinutes: number;
|
|
22
|
-
}
|
|
23
|
-
export type AccomplishmentPayload = MicroAccomplishmentPayload | MacroAccomplishmentPayload;
|
|
24
|
-
export declare class AccomplishmentController {
|
|
25
|
-
private pluginId;
|
|
26
|
-
constructor(pluginId: string);
|
|
27
|
-
emitAccomplishment(payload: Omit<AccomplishmentPayload, 'type'>): void;
|
|
28
|
-
private validateAccomplishment;
|
|
29
|
-
private sanitizeAccomplishment;
|
|
30
|
-
private getDecoupledTopic;
|
|
31
|
-
/**
|
|
32
|
-
* Subscribe to accomplishment events
|
|
33
|
-
* @param accomplishmentTopic - The topic of the accomplishment event. The pattern can be any pattern of plugin.skillCategory.accomplishmentKeyword or an * as wildcard for any plugin, skill category or accomplishment keyword
|
|
34
|
-
* @param callback - The callback function to be called when the accomplishment event is triggered
|
|
35
|
-
*/
|
|
36
|
-
subscribe(accomplishmentTopics: string | string[] | undefined, callback: (payload: EventBusMessage<AccomplishmentPayload>) => void): void;
|
|
37
|
-
}
|
|
38
|
-
export {};
|
|
@@ -1,112 +0,0 @@
|
|
|
1
|
-
import { EventBus } from '../fromRimori/EventBus';
|
|
2
|
-
export const skillCategories = ['reading', 'listening', 'speaking', 'writing', 'learning', 'community'];
|
|
3
|
-
export class AccomplishmentController {
|
|
4
|
-
constructor(pluginId) {
|
|
5
|
-
this.pluginId = pluginId;
|
|
6
|
-
}
|
|
7
|
-
emitAccomplishment(payload) {
|
|
8
|
-
const accomplishmentPayload = Object.assign(Object.assign({}, payload), { type: 'durationMinutes' in payload ? 'macro' : 'micro' });
|
|
9
|
-
this.validateAccomplishment(accomplishmentPayload);
|
|
10
|
-
const sanitizedPayload = this.sanitizeAccomplishment(accomplishmentPayload);
|
|
11
|
-
const topic = 'global.accomplishment.trigger' + (accomplishmentPayload.type === 'macro' ? 'Macro' : 'Micro');
|
|
12
|
-
EventBus.emit(this.pluginId, topic, sanitizedPayload);
|
|
13
|
-
}
|
|
14
|
-
validateAccomplishment(payload) {
|
|
15
|
-
if (!skillCategories.includes(payload.skillCategory)) {
|
|
16
|
-
throw new Error(`Invalid skill category: ${payload.skillCategory}`);
|
|
17
|
-
}
|
|
18
|
-
//regex validate accomplishmentKeyword
|
|
19
|
-
if (!/^[a-z_-]+$/.test(payload.accomplishmentKeyword)) {
|
|
20
|
-
throw new Error(`The accomplishment keyword: ${payload.accomplishmentKeyword} is invalid. Only lowercase letters, minuses and underscores are allowed`);
|
|
21
|
-
}
|
|
22
|
-
//description is required
|
|
23
|
-
if (payload.description.length < 10) {
|
|
24
|
-
throw new Error('Description is too short');
|
|
25
|
-
}
|
|
26
|
-
//check that the type is valid
|
|
27
|
-
if (!['micro', 'macro'].includes(payload.type)) {
|
|
28
|
-
throw new Error('Invalid accomplishment type ' + payload.type);
|
|
29
|
-
}
|
|
30
|
-
//durationMinutes is required
|
|
31
|
-
if (payload.type === 'macro' && payload.durationMinutes < 4) {
|
|
32
|
-
throw new Error('The duration must be at least 4 minutes');
|
|
33
|
-
}
|
|
34
|
-
//errorRatio is required
|
|
35
|
-
if (payload.type === 'macro' && (payload.errorRatio < 0 || payload.errorRatio > 1)) {
|
|
36
|
-
throw new Error('The error ratio must be between 0 and 1');
|
|
37
|
-
}
|
|
38
|
-
//regex check meta data key
|
|
39
|
-
if (payload.meta) {
|
|
40
|
-
payload.meta.forEach((meta) => {
|
|
41
|
-
if (!/^[a-z_]+$/.test(meta.key)) {
|
|
42
|
-
throw new Error('Invalid meta data key ' + meta.key + ', only lowercase letters and underscores are allowed');
|
|
43
|
-
}
|
|
44
|
-
});
|
|
45
|
-
}
|
|
46
|
-
}
|
|
47
|
-
sanitizeAccomplishment(payload) {
|
|
48
|
-
var _a;
|
|
49
|
-
payload.description = payload.description.replace(/[^\x20-\x7E]/g, '');
|
|
50
|
-
(_a = payload.meta) === null || _a === void 0 ? void 0 : _a.forEach((meta) => {
|
|
51
|
-
meta.description = meta.description.replace(/[^\x20-\x7E]/g, '');
|
|
52
|
-
});
|
|
53
|
-
return payload;
|
|
54
|
-
}
|
|
55
|
-
getDecoupledTopic(topic) {
|
|
56
|
-
const [plugin, skillCategory, accomplishmentKeyword] = topic.split('.');
|
|
57
|
-
return {
|
|
58
|
-
plugin: plugin || '*',
|
|
59
|
-
skillCategory: skillCategory || '*',
|
|
60
|
-
accomplishmentKeyword: accomplishmentKeyword || '*',
|
|
61
|
-
};
|
|
62
|
-
}
|
|
63
|
-
/**
|
|
64
|
-
* Subscribe to accomplishment events
|
|
65
|
-
* @param accomplishmentTopic - The topic of the accomplishment event. The pattern can be any pattern of plugin.skillCategory.accomplishmentKeyword or an * as wildcard for any plugin, skill category or accomplishment keyword
|
|
66
|
-
* @param callback - The callback function to be called when the accomplishment event is triggered
|
|
67
|
-
*/
|
|
68
|
-
subscribe(accomplishmentTopics = '*', callback) {
|
|
69
|
-
if (typeof accomplishmentTopics === 'string') {
|
|
70
|
-
accomplishmentTopics = [accomplishmentTopics];
|
|
71
|
-
}
|
|
72
|
-
accomplishmentTopics.forEach((accomplishmentTopic) => {
|
|
73
|
-
const topicLength = accomplishmentTopic.split('.').length;
|
|
74
|
-
if (topicLength === 1) {
|
|
75
|
-
accomplishmentTopic += '.*.*';
|
|
76
|
-
}
|
|
77
|
-
else if (topicLength === 2) {
|
|
78
|
-
accomplishmentTopic += '.*';
|
|
79
|
-
}
|
|
80
|
-
else if (topicLength !== 3) {
|
|
81
|
-
throw new Error('Invalid accomplishment topic pattern. The pattern must be plugin.skillCategory.accomplishmentKeyword or an * as wildcard for any plugin, skill category or accomplishment keyword');
|
|
82
|
-
}
|
|
83
|
-
EventBus.on(['global.accomplishment.triggerMicro', 'global.accomplishment.triggerMacro'], (event) => {
|
|
84
|
-
const { plugin, skillCategory, accomplishmentKeyword } = this.getDecoupledTopic(accomplishmentTopic);
|
|
85
|
-
if (plugin !== '*' && event.sender !== plugin)
|
|
86
|
-
return;
|
|
87
|
-
if (skillCategory !== '*' && event.data.skillCategory !== skillCategory)
|
|
88
|
-
return;
|
|
89
|
-
if (accomplishmentKeyword !== '*' && event.data.accomplishmentKeyword !== accomplishmentKeyword)
|
|
90
|
-
return;
|
|
91
|
-
callback(event);
|
|
92
|
-
}, [this.pluginId]);
|
|
93
|
-
});
|
|
94
|
-
}
|
|
95
|
-
}
|
|
96
|
-
// const accomplishmentHandler = AccomplishmentHandler.getInstance("my-plugin");
|
|
97
|
-
// accomplishmentHandler.subscribe("*", (payload) => {
|
|
98
|
-
// console.log(payload);
|
|
99
|
-
// });
|
|
100
|
-
// accomplishmentHandler.emitAccomplishment({
|
|
101
|
-
// skillCategory: "reading",
|
|
102
|
-
// accomplishmentKeyword: "chapter",
|
|
103
|
-
// description: "Read chapter 1 of the book",
|
|
104
|
-
// durationMinutes: 10,
|
|
105
|
-
// meta: [
|
|
106
|
-
// {
|
|
107
|
-
// key: "book",
|
|
108
|
-
// value: "The Great Gatsby",
|
|
109
|
-
// description: "The book I read",
|
|
110
|
-
// },
|
|
111
|
-
// ],
|
|
112
|
-
// });
|
|
@@ -1,37 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* AudioController is a class that provides methods to record audio. It is a wrapper around the Capacitor Voice Recorder plugin. For more information, see https://github.com/tchvu3/capacitor-voice-recorder.
|
|
3
|
-
*
|
|
4
|
-
* @example
|
|
5
|
-
* const audioController = new AudioController();
|
|
6
|
-
* await audioController.startRecording();
|
|
7
|
-
*/
|
|
8
|
-
export declare class AudioController {
|
|
9
|
-
private pluginId;
|
|
10
|
-
constructor(pluginId: string);
|
|
11
|
-
/**
|
|
12
|
-
* Start the recording.
|
|
13
|
-
*
|
|
14
|
-
* @example
|
|
15
|
-
* const audioController = new AudioController();
|
|
16
|
-
* await audioController.startRecording();
|
|
17
|
-
* @returns void
|
|
18
|
-
*/
|
|
19
|
-
startRecording(): Promise<void>;
|
|
20
|
-
/**
|
|
21
|
-
* Stop the recording and return the audio data.
|
|
22
|
-
* @returns The audio data.
|
|
23
|
-
*
|
|
24
|
-
* @example
|
|
25
|
-
* const audioRef = new Audio(`data:${mimeType};base64,${base64Sound}`)
|
|
26
|
-
* audioRef.oncanplaythrough = () => audioRef.play()
|
|
27
|
-
* audioRef.load()
|
|
28
|
-
*/
|
|
29
|
-
stopRecording(): Promise<{
|
|
30
|
-
recording: Blob;
|
|
31
|
-
msDuration: number;
|
|
32
|
-
mimeType: string;
|
|
33
|
-
}>;
|
|
34
|
-
pauseRecording(): Promise<boolean>;
|
|
35
|
-
resumeRecording(): Promise<boolean>;
|
|
36
|
-
getCurrentStatus(): Promise<'RECORDING' | 'PAUSED' | 'NONE'>;
|
|
37
|
-
}
|
|
@@ -1,68 +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 { EventBus } from '../fromRimori/EventBus';
|
|
11
|
-
/**
|
|
12
|
-
* AudioController is a class that provides methods to record audio. It is a wrapper around the Capacitor Voice Recorder plugin. For more information, see https://github.com/tchvu3/capacitor-voice-recorder.
|
|
13
|
-
*
|
|
14
|
-
* @example
|
|
15
|
-
* const audioController = new AudioController();
|
|
16
|
-
* await audioController.startRecording();
|
|
17
|
-
*/
|
|
18
|
-
export class AudioController {
|
|
19
|
-
constructor(pluginId) {
|
|
20
|
-
this.pluginId = pluginId;
|
|
21
|
-
}
|
|
22
|
-
/**
|
|
23
|
-
* Start the recording.
|
|
24
|
-
*
|
|
25
|
-
* @example
|
|
26
|
-
* const audioController = new AudioController();
|
|
27
|
-
* await audioController.startRecording();
|
|
28
|
-
* @returns void
|
|
29
|
-
*/
|
|
30
|
-
startRecording() {
|
|
31
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
32
|
-
EventBus.emit(this.pluginId, 'global.microphone.triggerStartRecording');
|
|
33
|
-
});
|
|
34
|
-
}
|
|
35
|
-
/**
|
|
36
|
-
* Stop the recording and return the audio data.
|
|
37
|
-
* @returns The audio data.
|
|
38
|
-
*
|
|
39
|
-
* @example
|
|
40
|
-
* const audioRef = new Audio(`data:${mimeType};base64,${base64Sound}`)
|
|
41
|
-
* audioRef.oncanplaythrough = () => audioRef.play()
|
|
42
|
-
* audioRef.load()
|
|
43
|
-
*/
|
|
44
|
-
stopRecording() {
|
|
45
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
46
|
-
const result = yield EventBus.request(this.pluginId, 'global.microphone.triggerStopRecording');
|
|
47
|
-
return result.data;
|
|
48
|
-
});
|
|
49
|
-
}
|
|
50
|
-
pauseRecording() {
|
|
51
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
52
|
-
const result = yield EventBus.request(this.pluginId, 'global.microphone.triggerPauseRecording');
|
|
53
|
-
return result.data;
|
|
54
|
-
});
|
|
55
|
-
}
|
|
56
|
-
resumeRecording() {
|
|
57
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
58
|
-
const result = yield EventBus.request(this.pluginId, 'global.microphone.triggerResumeRecording');
|
|
59
|
-
return result.data;
|
|
60
|
-
});
|
|
61
|
-
}
|
|
62
|
-
getCurrentStatus() {
|
|
63
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
64
|
-
const result = yield EventBus.request(this.pluginId, 'global.microphone.triggerGetCurrentStatus');
|
|
65
|
-
return result.data;
|
|
66
|
-
});
|
|
67
|
-
}
|
|
68
|
-
}
|
|
@@ -1,54 +0,0 @@
|
|
|
1
|
-
import { SupabaseClient } from '@supabase/supabase-js';
|
|
2
|
-
export type TriggerAction = {
|
|
3
|
-
action_key: string;
|
|
4
|
-
} & Record<string, string | number | boolean>;
|
|
5
|
-
export interface CreateExerciseParams {
|
|
6
|
-
plugin_id: string;
|
|
7
|
-
start_date: string;
|
|
8
|
-
end_date: string;
|
|
9
|
-
trigger_action: TriggerAction;
|
|
10
|
-
name: string;
|
|
11
|
-
description: string;
|
|
12
|
-
estimated_duration: number;
|
|
13
|
-
}
|
|
14
|
-
export interface Exercise {
|
|
15
|
-
id: string;
|
|
16
|
-
plugin_id: string;
|
|
17
|
-
start_date: string;
|
|
18
|
-
end_date: string;
|
|
19
|
-
trigger_action: TriggerAction;
|
|
20
|
-
name: string;
|
|
21
|
-
description: string;
|
|
22
|
-
estimated_duration: number;
|
|
23
|
-
created_at?: string;
|
|
24
|
-
updated_at?: string;
|
|
25
|
-
}
|
|
26
|
-
export declare class ExerciseController {
|
|
27
|
-
private supabase;
|
|
28
|
-
constructor(supabase: SupabaseClient);
|
|
29
|
-
/**
|
|
30
|
-
* Fetches weekly exercises from the weekly_exercises view.
|
|
31
|
-
* Shows exercises for the current week that haven't expired.
|
|
32
|
-
* @returns Array of exercise objects.
|
|
33
|
-
*/
|
|
34
|
-
viewWeeklyExercises(): Promise<Exercise[]>;
|
|
35
|
-
/**
|
|
36
|
-
* Creates a new exercise via the backend API.
|
|
37
|
-
* @param token The token to use for authentication.
|
|
38
|
-
* @param backendUrl The URL of the backend API.
|
|
39
|
-
* @param params Exercise creation parameters.
|
|
40
|
-
* @returns Created exercise object.
|
|
41
|
-
*/
|
|
42
|
-
addExercise(token: string, backendUrl: string, params: CreateExerciseParams): Promise<Exercise>;
|
|
43
|
-
/**
|
|
44
|
-
* Deletes an exercise via the backend API.
|
|
45
|
-
* @param token The token to use for authentication.
|
|
46
|
-
* @param backendUrl The URL of the backend API.
|
|
47
|
-
* @param exerciseId The exercise ID to delete.
|
|
48
|
-
* @returns Success status.
|
|
49
|
-
*/
|
|
50
|
-
deleteExercise(token: string, backendUrl: string, id: string): Promise<{
|
|
51
|
-
success: boolean;
|
|
52
|
-
message: string;
|
|
53
|
-
}>;
|
|
54
|
-
}
|
|
@@ -1,74 +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
|
-
export class ExerciseController {
|
|
11
|
-
constructor(supabase) {
|
|
12
|
-
this.supabase = supabase;
|
|
13
|
-
}
|
|
14
|
-
/**
|
|
15
|
-
* Fetches weekly exercises from the weekly_exercises view.
|
|
16
|
-
* Shows exercises for the current week that haven't expired.
|
|
17
|
-
* @returns Array of exercise objects.
|
|
18
|
-
*/
|
|
19
|
-
viewWeeklyExercises() {
|
|
20
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
21
|
-
const { data, error } = yield this.supabase.from('weekly_exercises').select('*');
|
|
22
|
-
if (error) {
|
|
23
|
-
throw new Error(`Failed to fetch weekly exercises: ${error.message}`);
|
|
24
|
-
}
|
|
25
|
-
return data || [];
|
|
26
|
-
});
|
|
27
|
-
}
|
|
28
|
-
/**
|
|
29
|
-
* Creates a new exercise via the backend API.
|
|
30
|
-
* @param token The token to use for authentication.
|
|
31
|
-
* @param backendUrl The URL of the backend API.
|
|
32
|
-
* @param params Exercise creation parameters.
|
|
33
|
-
* @returns Created exercise object.
|
|
34
|
-
*/
|
|
35
|
-
addExercise(token, backendUrl, params) {
|
|
36
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
37
|
-
const response = yield fetch(`${backendUrl}/exercises`, {
|
|
38
|
-
method: 'POST',
|
|
39
|
-
headers: {
|
|
40
|
-
'Content-Type': 'application/json',
|
|
41
|
-
Authorization: `Bearer ${token}`,
|
|
42
|
-
},
|
|
43
|
-
body: JSON.stringify(params),
|
|
44
|
-
});
|
|
45
|
-
if (!response.ok) {
|
|
46
|
-
const errorText = yield response.text();
|
|
47
|
-
throw new Error(`Failed to create exercise: ${errorText}`);
|
|
48
|
-
}
|
|
49
|
-
return yield response.json();
|
|
50
|
-
});
|
|
51
|
-
}
|
|
52
|
-
/**
|
|
53
|
-
* Deletes an exercise via the backend API.
|
|
54
|
-
* @param token The token to use for authentication.
|
|
55
|
-
* @param backendUrl The URL of the backend API.
|
|
56
|
-
* @param exerciseId The exercise ID to delete.
|
|
57
|
-
* @returns Success status.
|
|
58
|
-
*/
|
|
59
|
-
deleteExercise(token, backendUrl, id) {
|
|
60
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
61
|
-
const response = yield fetch(`${backendUrl}/exercises/${id}`, {
|
|
62
|
-
method: 'DELETE',
|
|
63
|
-
headers: {
|
|
64
|
-
Authorization: `Bearer ${token}`,
|
|
65
|
-
},
|
|
66
|
-
});
|
|
67
|
-
if (!response.ok) {
|
|
68
|
-
const errorText = yield response.text();
|
|
69
|
-
throw new Error(`Failed to delete exercise: ${errorText}`);
|
|
70
|
-
}
|
|
71
|
-
return yield response.json();
|
|
72
|
-
});
|
|
73
|
-
}
|
|
74
|
-
}
|
|
@@ -1,42 +0,0 @@
|
|
|
1
|
-
type PrimitiveType = 'string' | 'number' | 'boolean';
|
|
2
|
-
type ObjectToolParameterType = PrimitiveType | {
|
|
3
|
-
[key: string]: ObjectToolParameter;
|
|
4
|
-
} | [{
|
|
5
|
-
[key: string]: ObjectToolParameter;
|
|
6
|
-
}];
|
|
7
|
-
interface ObjectToolParameter {
|
|
8
|
-
type: ObjectToolParameterType;
|
|
9
|
-
description?: string;
|
|
10
|
-
enum?: string[];
|
|
11
|
-
optional?: boolean;
|
|
12
|
-
}
|
|
13
|
-
/**
|
|
14
|
-
* The tools that the AI can use.
|
|
15
|
-
*
|
|
16
|
-
* The key is the name of the tool.
|
|
17
|
-
* The value is the parameter of the tool.
|
|
18
|
-
*
|
|
19
|
-
*/
|
|
20
|
-
export type ObjectTool = {
|
|
21
|
-
[key: string]: ObjectToolParameter;
|
|
22
|
-
};
|
|
23
|
-
export interface ObjectRequest {
|
|
24
|
-
/**
|
|
25
|
-
* The tools that the AI can use.
|
|
26
|
-
*/
|
|
27
|
-
tool: ObjectTool;
|
|
28
|
-
/**
|
|
29
|
-
* High level instructions for the AI to follow. Behaviour, tone, restrictions, etc.
|
|
30
|
-
* Example: "Act like a recipe writer."
|
|
31
|
-
*/
|
|
32
|
-
behaviour?: string;
|
|
33
|
-
/**
|
|
34
|
-
* The specific instruction for the AI to follow.
|
|
35
|
-
* Example: "Generate a recipe using chicken, rice and vegetables."
|
|
36
|
-
*/
|
|
37
|
-
instructions: string;
|
|
38
|
-
}
|
|
39
|
-
export declare function generateObject<T = any>(backendUrl: string, request: ObjectRequest, token: string): Promise<T>;
|
|
40
|
-
export type OnLLMResponse = (id: string, response: string, finished: boolean, toolInvocations?: any[]) => void;
|
|
41
|
-
export declare function streamObject(backendUrl: string, request: ObjectRequest, onResponse: OnLLMResponse, token: string): Promise<void>;
|
|
42
|
-
export {};
|
|
@@ -1,76 +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
|
-
export function generateObject(backendUrl, request, token) {
|
|
11
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
12
|
-
return yield fetch(`${backendUrl}/ai/llm-object`, {
|
|
13
|
-
method: 'POST',
|
|
14
|
-
body: JSON.stringify({
|
|
15
|
-
stream: false,
|
|
16
|
-
tool: request.tool,
|
|
17
|
-
behaviour: request.behaviour,
|
|
18
|
-
instructions: request.instructions,
|
|
19
|
-
}),
|
|
20
|
-
headers: { Authorization: `Bearer ${token}`, 'Content-Type': 'application/json' },
|
|
21
|
-
}).then((response) => response.json());
|
|
22
|
-
});
|
|
23
|
-
}
|
|
24
|
-
export function streamObject(backendUrl, request, onResponse, token) {
|
|
25
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
26
|
-
const messageId = Math.random().toString(36).substring(3);
|
|
27
|
-
const response = yield fetch(`${backendUrl}/ai/llm-object`, {
|
|
28
|
-
method: 'POST',
|
|
29
|
-
body: JSON.stringify({
|
|
30
|
-
stream: true,
|
|
31
|
-
tools: request.tool,
|
|
32
|
-
systemInstructions: request.behaviour,
|
|
33
|
-
secondaryInstructions: request.instructions,
|
|
34
|
-
}),
|
|
35
|
-
headers: { Authorization: `Bearer ${token}`, 'Content-Type': 'application/json' },
|
|
36
|
-
});
|
|
37
|
-
if (!response.body) {
|
|
38
|
-
console.error('No response body.');
|
|
39
|
-
return;
|
|
40
|
-
}
|
|
41
|
-
const reader = response.body.getReader();
|
|
42
|
-
const decoder = new TextDecoder('utf-8');
|
|
43
|
-
let content = '';
|
|
44
|
-
let done = false;
|
|
45
|
-
const toolInvocations = [];
|
|
46
|
-
while (!done) {
|
|
47
|
-
const { value } = yield reader.read();
|
|
48
|
-
if (value) {
|
|
49
|
-
const chunk = decoder.decode(value, { stream: true });
|
|
50
|
-
const lines = chunk.split('\n').filter((line) => line.trim() !== '');
|
|
51
|
-
for (const line of lines) {
|
|
52
|
-
const data = line.substring(3, line.length - 1);
|
|
53
|
-
const command = line.substring(0, 1);
|
|
54
|
-
// console.log("data: ", { line, data, command });
|
|
55
|
-
if (command === '0') {
|
|
56
|
-
content += data;
|
|
57
|
-
// console.log("AI response:", content);
|
|
58
|
-
//content \n\n should be real line break when message is displayed
|
|
59
|
-
onResponse(messageId, content.replace(/\\n/g, '\n').replace(/\\+"/g, '"'), false);
|
|
60
|
-
}
|
|
61
|
-
else if (command === 'd') {
|
|
62
|
-
// console.log("AI usage:", JSON.parse(line.substring(2)));
|
|
63
|
-
done = true;
|
|
64
|
-
break;
|
|
65
|
-
}
|
|
66
|
-
else if (command === '9') {
|
|
67
|
-
// console.log("tool call:", JSON.parse(line.substring(2)));
|
|
68
|
-
// console.log("tools", tools);
|
|
69
|
-
toolInvocations.push(JSON.parse(line.substring(2)));
|
|
70
|
-
}
|
|
71
|
-
}
|
|
72
|
-
}
|
|
73
|
-
}
|
|
74
|
-
onResponse(messageId, content.replace(/\\n/g, '\n').replace(/\\+"/g, '"'), true, toolInvocations);
|
|
75
|
-
});
|
|
76
|
-
}
|
|
@@ -1,79 +0,0 @@
|
|
|
1
|
-
import { SupabaseClient } from '@supabase/supabase-js';
|
|
2
|
-
import { LanguageLevel } from '../utils/difficultyConverter';
|
|
3
|
-
import { Guild } from '../plugin/CommunicationHandler';
|
|
4
|
-
export interface Buddy {
|
|
5
|
-
id: string;
|
|
6
|
-
name: string;
|
|
7
|
-
description: string;
|
|
8
|
-
avatarUrl: string;
|
|
9
|
-
voiceId: string;
|
|
10
|
-
aiPersonality: string;
|
|
11
|
-
}
|
|
12
|
-
export interface Language {
|
|
13
|
-
code: string;
|
|
14
|
-
name: string;
|
|
15
|
-
native: string;
|
|
16
|
-
capitalized: string;
|
|
17
|
-
uppercase: string;
|
|
18
|
-
}
|
|
19
|
-
export interface UserInfo {
|
|
20
|
-
skill_level_reading: LanguageLevel;
|
|
21
|
-
skill_level_writing: LanguageLevel;
|
|
22
|
-
skill_level_grammar: LanguageLevel;
|
|
23
|
-
skill_level_speaking: LanguageLevel;
|
|
24
|
-
skill_level_listening: LanguageLevel;
|
|
25
|
-
skill_level_understanding: LanguageLevel;
|
|
26
|
-
goal_longterm: string;
|
|
27
|
-
goal_weekly: string;
|
|
28
|
-
study_buddy: Buddy;
|
|
29
|
-
story_genre: string;
|
|
30
|
-
study_duration: number;
|
|
31
|
-
/**
|
|
32
|
-
* The 2 letter language code of the language the user speaks natively.
|
|
33
|
-
* With the function getLanguageName, the language name can be retrieved.
|
|
34
|
-
*/
|
|
35
|
-
mother_tongue: Language;
|
|
36
|
-
/**
|
|
37
|
-
* The language the user targets to learn.
|
|
38
|
-
*/
|
|
39
|
-
target_language: Language;
|
|
40
|
-
motivation_type: string;
|
|
41
|
-
onboarding_completed: boolean;
|
|
42
|
-
context_menu_on_select: boolean;
|
|
43
|
-
user_name?: string;
|
|
44
|
-
/**
|
|
45
|
-
* ISO 3166-1 alpha-2 country code of user's target location (exposed to plugins)
|
|
46
|
-
*/
|
|
47
|
-
target_country: string;
|
|
48
|
-
/**
|
|
49
|
-
* Optional: nearest big city (>100,000) near user's location
|
|
50
|
-
*/
|
|
51
|
-
target_city?: string;
|
|
52
|
-
}
|
|
53
|
-
export declare class SettingsController {
|
|
54
|
-
private pluginId;
|
|
55
|
-
private supabase;
|
|
56
|
-
private guild;
|
|
57
|
-
constructor(supabase: SupabaseClient, pluginId: string, guild: Guild);
|
|
58
|
-
/**
|
|
59
|
-
* Fetches settings based on guild configuration.
|
|
60
|
-
* If guild doesn't allow user settings, fetches guild-level settings.
|
|
61
|
-
* Otherwise, fetches user-specific settings.
|
|
62
|
-
* @returns The settings object or null if not found.
|
|
63
|
-
*/
|
|
64
|
-
private fetchSettings;
|
|
65
|
-
/**
|
|
66
|
-
* Sets settings for the plugin.
|
|
67
|
-
* Automatically saves as guild settings if guild doesn't allow user settings,
|
|
68
|
-
* otherwise saves as user-specific settings.
|
|
69
|
-
* @param settings - The settings object to save.
|
|
70
|
-
* @throws {Error} if RLS blocks the operation.
|
|
71
|
-
*/
|
|
72
|
-
setSettings(settings: any): Promise<void>;
|
|
73
|
-
/**
|
|
74
|
-
* Get the settings for the plugin. T can be any type of settings, UserSettings or SystemSettings.
|
|
75
|
-
* @param defaultSettings The default settings to use if no settings are found.
|
|
76
|
-
* @returns The settings for the plugin.
|
|
77
|
-
*/
|
|
78
|
-
getSettings<T extends object>(defaultSettings: T): Promise<T>;
|
|
79
|
-
}
|