@rimori/client 1.0.4 → 1.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 +13 -0
- package/dist/components/MarkdownEditor.js +6 -4
- package/dist/components/PluginController.d.ts +21 -0
- package/dist/components/PluginController.js +116 -0
- package/dist/components/ai/Assistant.js +1 -1
- package/dist/components/ai/Avatar.d.ts +5 -3
- package/dist/components/ai/Avatar.js +14 -6
- package/dist/components/ai/EmbeddedAssistent/CircleAudioAvatar.d.ts +2 -1
- package/dist/components/ai/EmbeddedAssistent/CircleAudioAvatar.js +35 -14
- package/dist/components/ai/EmbeddedAssistent/TTS/MessageSender.d.ts +1 -0
- package/dist/components/ai/EmbeddedAssistent/TTS/MessageSender.js +3 -0
- package/dist/components/ai/EmbeddedAssistent/TTS/Player.d.ts +2 -0
- package/dist/components/ai/EmbeddedAssistent/TTS/Player.js +5 -0
- package/dist/components/ai/EmbeddedAssistent/VoiceRecoder.d.ts +3 -0
- package/dist/components/ai/EmbeddedAssistent/VoiceRecoder.js +41 -5
- package/dist/components/ai/utils.d.ts +1 -1
- package/dist/components.d.ts +1 -0
- package/dist/components.js +1 -0
- package/dist/controller/AIController.js +2 -1
- package/dist/controller/SettingsController.d.ts +18 -10
- package/dist/controller/SettingsController.js +28 -31
- package/dist/controller/SharedContentController.d.ts +58 -11
- package/dist/controller/SharedContentController.js +161 -26
- package/dist/controller/SidePluginController.d.ts +1 -12
- package/dist/core/components/ContextMenu.d.ts +10 -0
- package/dist/core/components/ContextMenu.js +93 -0
- package/dist/core.d.ts +2 -0
- package/dist/core.js +2 -0
- package/dist/hooks/UseChatHook.d.ts +1 -1
- package/dist/plugin/AccomplishmentHandler.d.ts +38 -0
- package/dist/plugin/AccomplishmentHandler.js +108 -0
- package/dist/plugin/ContextMenu.d.ts +17 -0
- package/dist/plugin/ContextMenu.js +45 -0
- package/dist/plugin/PluginController.js +9 -4
- package/dist/plugin/RimoriClient.d.ts +92 -65
- package/dist/plugin/RimoriClient.js +105 -75
- package/dist/plugin/ThemeSetter.js +4 -4
- package/dist/plugin/fromRimori/EventBus.d.ts +6 -3
- package/dist/plugin/fromRimori/EventBus.js +15 -9
- package/dist/plugin/fromRimori/PluginTypes.d.ts +51 -0
- package/dist/plugin/fromRimori/PluginTypes.js +1 -0
- package/dist/providers/PluginController.d.ts +21 -0
- package/dist/providers/PluginController.js +116 -0
- package/dist/providers/PluginProvider.js +26 -73
- package/dist/types/Actions.d.ts +4 -0
- package/dist/types/Actions.js +1 -0
- package/dist/utils/Language.d.ts +66 -0
- package/dist/utils/Language.js +67 -0
- package/dist/utils/difficultyConverter.d.ts +1 -0
- package/dist/utils/difficultyConverter.js +3 -0
- package/dist/worker/WorkerSetup.js +5 -4
- package/package.json +3 -3
- package/src/components/MarkdownEditor.tsx +78 -76
- package/src/components/ai/Assistant.tsx +1 -1
- package/src/components/ai/Avatar.tsx +65 -48
- package/src/components/ai/EmbeddedAssistent/CircleAudioAvatar.tsx +81 -58
- package/src/components/ai/EmbeddedAssistent/TTS/MessageSender.ts +4 -0
- package/src/components/ai/EmbeddedAssistent/TTS/Player.ts +6 -0
- package/src/components/ai/EmbeddedAssistent/VoiceRecoder.tsx +51 -8
- package/src/components/ai/utils.ts +1 -1
- package/src/components.ts +2 -1
- package/src/controller/AIController.ts +2 -1
- package/src/controller/SettingsController.ts +80 -75
- package/src/controller/SharedContentController.ts +214 -53
- package/src/controller/SidePluginController.ts +1 -13
- package/src/core/components/ContextMenu.tsx +123 -0
- package/src/core.ts +3 -1
- package/src/hooks/UseChatHook.ts +17 -17
- package/src/plugin/AccomplishmentHandler.ts +165 -0
- package/src/plugin/PluginController.ts +107 -100
- package/src/plugin/RimoriClient.ts +267 -250
- package/src/plugin/ThemeSetter.ts +4 -5
- package/src/plugin/fromRimori/EventBus.ts +23 -12
- package/src/plugin/fromRimori/PluginTypes.ts +67 -0
- package/src/providers/PluginProvider.tsx +63 -110
- package/src/types/Actions.ts +6 -0
- package/src/utils/Language.ts +70 -0
- package/src/utils/difficultyConverter.ts +4 -0
- package/src/worker/WorkerSetup.ts +5 -4
- package/dist/components/avatar/Assistant.d.ts +0 -9
- package/dist/components/avatar/Assistant.js +0 -59
- package/dist/components/avatar/Avatar.d.ts +0 -12
- package/dist/components/avatar/Avatar.js +0 -42
- package/dist/components/avatar/EmbeddedAssistent/AudioInputField.d.ts +0 -7
- package/dist/components/avatar/EmbeddedAssistent/AudioInputField.js +0 -38
- package/dist/components/avatar/EmbeddedAssistent/CircleAudioAvatar.d.ts +0 -7
- package/dist/components/avatar/EmbeddedAssistent/CircleAudioAvatar.js +0 -59
- package/dist/components/avatar/EmbeddedAssistent/TTS/MessageSender.d.ts +0 -19
- package/dist/components/avatar/EmbeddedAssistent/TTS/MessageSender.js +0 -84
- package/dist/components/avatar/EmbeddedAssistent/TTS/Player.d.ts +0 -25
- package/dist/components/avatar/EmbeddedAssistent/TTS/Player.js +0 -180
- package/dist/components/avatar/EmbeddedAssistent/VoiceRecoder.d.ts +0 -7
- package/dist/components/avatar/EmbeddedAssistent/VoiceRecoder.js +0 -45
- package/dist/components/avatar/utils.d.ts +0 -6
- package/dist/components/avatar/utils.js +0 -14
|
@@ -1,282 +1,299 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { PostgrestQueryBuilder } from "@supabase/postgrest-js";
|
|
2
2
|
import { SupabaseClient } from "@supabase/supabase-js";
|
|
3
|
-
import { EventBusMessage, EventPayload } from "./fromRimori/EventBus";
|
|
4
|
-
import { SettingsController } from "../controller/SettingsController";
|
|
5
3
|
import { GenericSchema } from "@supabase/supabase-js/dist/module/lib/types";
|
|
6
|
-
import {
|
|
7
|
-
import { PostgrestQueryBuilder, PostgrestFilterBuilder } from "@supabase/postgrest-js";
|
|
8
|
-
import { SharedContentController, BasicAssignment } from "../controller/SharedContentController";
|
|
9
|
-
import { streamChatGPT, Message, Tool, OnLLMResponse, generateText } from "../controller/AIController";
|
|
4
|
+
import { generateText, Message, OnLLMResponse, streamChatGPT, Tool } from "../controller/AIController";
|
|
10
5
|
import { generateObject as generateObjectFunction, ObjectRequest } from "../controller/ObjectController";
|
|
11
|
-
import {
|
|
12
|
-
import {
|
|
13
|
-
import {
|
|
6
|
+
import { SettingsController, UserInfo } from "../controller/SettingsController";
|
|
7
|
+
import { BasicAssignment, SharedContent, SharedContentController, SharedContentFilter, SharedContentObjectRequest } from "../controller/SharedContentController";
|
|
8
|
+
import { getPlugins } from "../controller/SidePluginController";
|
|
9
|
+
import { getSTTResponse, getTTSResponse } from "../controller/VoiceController";
|
|
10
|
+
import { AccomplishmentHandler, AccomplishmentPayload } from "./AccomplishmentHandler";
|
|
11
|
+
import { EventBus, EventBusMessage, EventHandler, EventPayload } from "./fromRimori/EventBus";
|
|
12
|
+
import { Plugin } from "./fromRimori/PluginTypes";
|
|
13
|
+
import { PluginController } from "./PluginController";
|
|
14
14
|
|
|
15
15
|
interface RimoriClientOptions {
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
16
|
+
pluginController: PluginController;
|
|
17
|
+
supabase: SupabaseClient;
|
|
18
|
+
tablePrefix: string;
|
|
19
|
+
pluginId: string;
|
|
20
20
|
}
|
|
21
21
|
|
|
22
22
|
interface Db {
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
23
|
+
from: {
|
|
24
|
+
<TableName extends string & keyof GenericSchema['Tables'], Table extends GenericSchema['Tables'][TableName]>(relation: TableName): PostgrestQueryBuilder<GenericSchema, Table, TableName>;
|
|
25
|
+
<ViewName extends string & keyof GenericSchema['Views'], View extends GenericSchema['Views'][ViewName]>(relation: ViewName): PostgrestQueryBuilder<GenericSchema, View, ViewName>;
|
|
26
|
+
};
|
|
27
|
+
storage: SupabaseClient["storage"];
|
|
28
|
+
|
|
29
|
+
// functions: SupabaseClient["functions"];
|
|
30
|
+
/**
|
|
31
|
+
* The table prefix for of database tables of the plugin.
|
|
32
|
+
*/
|
|
33
|
+
tablePrefix: string;
|
|
34
|
+
/**
|
|
35
|
+
* Get the table name for a given plugin table.
|
|
36
|
+
* Internally all tables are prefixed with the plugin id. This function is used to get the correct table name for a given public table.
|
|
37
|
+
* @param table The plugin table name to get the full table name for.
|
|
38
|
+
* @returns The full table name.
|
|
39
|
+
*/
|
|
40
|
+
getTableName: (table: string) => string;
|
|
34
41
|
}
|
|
35
42
|
|
|
36
43
|
interface PluginInterface {
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
getUserInfo: () => Promise<UserInfo>;
|
|
44
|
+
pluginId: string;
|
|
45
|
+
setSettings: (settings: any) => Promise<void>;
|
|
46
|
+
/**
|
|
47
|
+
* Get the settings for the plugin. T can be any type of settings, UserSettings or SystemSettings.
|
|
48
|
+
* @param defaultSettings The default settings to use if no settings are found.
|
|
49
|
+
* @param genericSettings The type of settings to get.
|
|
50
|
+
* @returns The settings for the plugin.
|
|
51
|
+
*/
|
|
52
|
+
getSettings: <T extends object>(defaultSettings: T) => Promise<T>;
|
|
53
|
+
/**
|
|
54
|
+
* Fetches all installed plugins.
|
|
55
|
+
* @returns A promise that resolves to an array of plugins
|
|
56
|
+
*/
|
|
57
|
+
getInstalled: () => Promise<Plugin[]>;
|
|
58
|
+
getUserInfo: () => Promise<UserInfo>;
|
|
53
59
|
}
|
|
54
60
|
|
|
55
61
|
export class RimoriClient {
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
private constructor(options: RimoriClientOptions) {
|
|
66
|
-
this.superbase = options.supabase;
|
|
67
|
-
this.pluginController = options.pluginController;
|
|
68
|
-
this.settingsController = new SettingsController(options.supabase, options.pluginId);
|
|
69
|
-
this.sharedContentController = new SharedContentController(this);
|
|
70
|
-
this.supabaseUrl = this.pluginController.getSupabaseUrl();
|
|
71
|
-
|
|
72
|
-
this.rpc = this.rpc.bind(this);
|
|
73
|
-
this.from = this.from.bind(this);
|
|
62
|
+
private static instance: RimoriClient;
|
|
63
|
+
private superbase: SupabaseClient;
|
|
64
|
+
private pluginController: PluginController;
|
|
65
|
+
private settingsController: SettingsController;
|
|
66
|
+
private sharedContentController: SharedContentController;
|
|
67
|
+
private accomplishmentHandler: AccomplishmentHandler;
|
|
68
|
+
private supabaseUrl: string;
|
|
69
|
+
public db: Db;
|
|
70
|
+
public plugin: PluginInterface;
|
|
74
71
|
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
pluginId: options.pluginId,
|
|
83
|
-
tablePrefix: options.tablePrefix,
|
|
84
|
-
setSettings: async (settings: any) => {
|
|
85
|
-
await this.settingsController.setSettings(settings);
|
|
86
|
-
},
|
|
87
|
-
getSettings: async <T extends object>(defaultSettings: T): Promise<T> => {
|
|
88
|
-
return await this.settingsController.getSettings<T>(defaultSettings);
|
|
89
|
-
},
|
|
90
|
-
getInstalled: async (): Promise<Plugin[]> => {
|
|
91
|
-
return getPlugins(this.superbase);
|
|
92
|
-
},
|
|
93
|
-
getUserInfo: async (): Promise<UserInfo> => {
|
|
94
|
-
return this.settingsController.getUserInfo();
|
|
95
|
-
}
|
|
96
|
-
}
|
|
97
|
-
}
|
|
72
|
+
private constructor(options: RimoriClientOptions) {
|
|
73
|
+
this.superbase = options.supabase;
|
|
74
|
+
this.pluginController = options.pluginController;
|
|
75
|
+
this.settingsController = new SettingsController(options.supabase, options.pluginId);
|
|
76
|
+
this.sharedContentController = new SharedContentController(this.superbase, this);
|
|
77
|
+
this.supabaseUrl = this.pluginController.getSupabaseUrl();
|
|
78
|
+
this.accomplishmentHandler = new AccomplishmentHandler(options.pluginId);
|
|
98
79
|
|
|
99
|
-
|
|
100
|
-
/**
|
|
101
|
-
* Emit an event to Rimori or a plugin.
|
|
102
|
-
* The topic schema is:
|
|
103
|
-
* {pluginId}.{eventId}
|
|
104
|
-
* Check out the event bus documentation for more information.
|
|
105
|
-
* For triggering events from Rimori like context menu actions use the "global" keyword.
|
|
106
|
-
* @param topic The topic to emit the event on.
|
|
107
|
-
* @param data The data to emit.
|
|
108
|
-
* @param eventId The event id.
|
|
109
|
-
*/
|
|
110
|
-
emit: (topic: string, data: any, eventId?: number) => {
|
|
111
|
-
const globalTopic = this.pluginController.getGlobalEventTopic(topic);
|
|
112
|
-
EventBus.emit(this.plugin.pluginId, globalTopic, data, eventId);
|
|
113
|
-
},
|
|
114
|
-
/**
|
|
115
|
-
* Request an event.
|
|
116
|
-
* @param topic The topic to request the event on.
|
|
117
|
-
* @param data The data to request.
|
|
118
|
-
* @returns The response from the event.
|
|
119
|
-
*/
|
|
120
|
-
request: <T>(topic: string, data?: any): Promise<EventBusMessage<T>> => {
|
|
121
|
-
const globalTopic = this.pluginController.getGlobalEventTopic(topic);
|
|
122
|
-
return EventBus.request<T>(this.plugin.pluginId, globalTopic, data);
|
|
123
|
-
},
|
|
124
|
-
/**
|
|
125
|
-
* Subscribe to an event.
|
|
126
|
-
* @param topic The topic to subscribe to.
|
|
127
|
-
* @param callback The callback to call when the event is emitted.
|
|
128
|
-
*/
|
|
129
|
-
on: <T = EventPayload>(topic: string, callback: EventHandler<T>) => {
|
|
130
|
-
EventBus.on<T>(this.pluginController.getGlobalEventTopic(topic), callback);
|
|
131
|
-
},
|
|
132
|
-
/**
|
|
133
|
-
* Subscribe to an event once.
|
|
134
|
-
* @param topic The topic to subscribe to.
|
|
135
|
-
* @param callback The callback to call when the event is emitted.
|
|
136
|
-
*/
|
|
137
|
-
once: <T = EventPayload>(topic: string, callback: EventHandler<T>) => {
|
|
138
|
-
EventBus.once<T>(this.pluginController.getGlobalEventTopic(topic), callback);
|
|
139
|
-
},
|
|
140
|
-
/**
|
|
141
|
-
* Respond to an event.
|
|
142
|
-
* @param topic The topic to respond to.
|
|
143
|
-
* @param data The data to respond with.
|
|
144
|
-
*/
|
|
145
|
-
respond: <T = EventPayload>(topic: string, data: EventPayload | ((data: EventBusMessage<T>) => EventPayload | Promise<EventPayload>)) => {
|
|
146
|
-
EventBus.respond(this.plugin.pluginId, this.pluginController.getGlobalEventTopic(topic), data);
|
|
147
|
-
}
|
|
148
|
-
}
|
|
80
|
+
this.from = this.from.bind(this);
|
|
149
81
|
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
82
|
+
this.db = {
|
|
83
|
+
from: this.from,
|
|
84
|
+
storage: this.superbase.storage,
|
|
85
|
+
// functions: this.superbase.functions,
|
|
86
|
+
tablePrefix: options.tablePrefix,
|
|
87
|
+
getTableName: this.getTableName.bind(this),
|
|
156
88
|
}
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
89
|
+
this.plugin = {
|
|
90
|
+
pluginId: options.pluginId,
|
|
91
|
+
setSettings: async (settings: any) => {
|
|
92
|
+
await this.settingsController.setSettings(settings);
|
|
93
|
+
},
|
|
94
|
+
getSettings: async <T extends object>(defaultSettings: T): Promise<T> => {
|
|
95
|
+
return await this.settingsController.getSettings<T>(defaultSettings);
|
|
96
|
+
},
|
|
97
|
+
getInstalled: async (): Promise<Plugin[]> => {
|
|
98
|
+
return getPlugins(this.superbase);
|
|
99
|
+
},
|
|
100
|
+
getUserInfo: async (): Promise<UserInfo> => {
|
|
101
|
+
return this.settingsController.getUserInfo();
|
|
102
|
+
}
|
|
168
103
|
}
|
|
104
|
+
}
|
|
169
105
|
|
|
106
|
+
public event = {
|
|
107
|
+
/**
|
|
108
|
+
* Emit an event to Rimori or a plugin.
|
|
109
|
+
* The topic schema is:
|
|
110
|
+
* {pluginId}.{eventId}
|
|
111
|
+
* Check out the event bus documentation for more information.
|
|
112
|
+
* For triggering events from Rimori like context menu actions use the "global" keyword.
|
|
113
|
+
* @param topic The topic to emit the event on.
|
|
114
|
+
* @param data The data to emit.
|
|
115
|
+
* @param eventId The event id.
|
|
116
|
+
*/
|
|
117
|
+
emit: (topic: string, data?: any, eventId?: number) => {
|
|
118
|
+
const globalTopic = this.pluginController.getGlobalEventTopic(topic);
|
|
119
|
+
EventBus.emit(this.plugin.pluginId, globalTopic, data, eventId);
|
|
120
|
+
},
|
|
121
|
+
/**
|
|
122
|
+
* Request an event.
|
|
123
|
+
* @param topic The topic to request the event on.
|
|
124
|
+
* @param data The data to request.
|
|
125
|
+
* @returns The response from the event.
|
|
126
|
+
*/
|
|
127
|
+
request: <T>(topic: string, data?: any): Promise<EventBusMessage<T>> => {
|
|
128
|
+
const globalTopic = this.pluginController.getGlobalEventTopic(topic);
|
|
129
|
+
return EventBus.request<T>(this.plugin.pluginId, globalTopic, data);
|
|
130
|
+
},
|
|
131
|
+
/**
|
|
132
|
+
* Subscribe to an event.
|
|
133
|
+
* @param topic The topic to subscribe to.
|
|
134
|
+
* @param callback The callback to call when the event is emitted.
|
|
135
|
+
* @returns The unsubscribe ids.
|
|
136
|
+
*/
|
|
137
|
+
on: <T = EventPayload>(topic: string | string[], callback: EventHandler<T>) => {
|
|
138
|
+
const topics = Array.isArray(topic) ? topic : [topic];
|
|
139
|
+
return topics.map(topic => EventBus.on<T>(this.pluginController.getGlobalEventTopic(topic), callback));
|
|
140
|
+
},
|
|
170
141
|
/**
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
string,
|
|
210
|
-
null
|
|
211
|
-
> {
|
|
212
|
-
return this.superbase.rpc(this.getTableName(functionName), args, options)
|
|
142
|
+
* Subscribe to an event once.
|
|
143
|
+
* @param topic The topic to subscribe to.
|
|
144
|
+
* @param callback The callback to call when the event is emitted.
|
|
145
|
+
*/
|
|
146
|
+
once: <T = EventPayload>(topic: string, callback: EventHandler<T>) => {
|
|
147
|
+
EventBus.once<T>(this.pluginController.getGlobalEventTopic(topic), callback);
|
|
148
|
+
},
|
|
149
|
+
/**
|
|
150
|
+
* Respond to an event.
|
|
151
|
+
* @param topic The topic to respond to.
|
|
152
|
+
* @param data The data to respond with.
|
|
153
|
+
*/
|
|
154
|
+
respond: <T = EventPayload>(topic: string, data: EventPayload | ((data: EventBusMessage<T>) => EventPayload | Promise<EventPayload>)) => {
|
|
155
|
+
EventBus.respond(this.plugin.pluginId, this.pluginController.getGlobalEventTopic(topic), data);
|
|
156
|
+
},
|
|
157
|
+
/**
|
|
158
|
+
* Emit an accomplishment.
|
|
159
|
+
* @param payload The payload to emit.
|
|
160
|
+
*/
|
|
161
|
+
emitAccomplishment: (payload: AccomplishmentPayload) => {
|
|
162
|
+
this.accomplishmentHandler.emitAccomplishment(payload);
|
|
163
|
+
},
|
|
164
|
+
/**
|
|
165
|
+
* Subscribe to an accomplishment.
|
|
166
|
+
* @param accomplishmentTopic The topic to subscribe to.
|
|
167
|
+
* @param callback The callback to call when the accomplishment is emitted.
|
|
168
|
+
*/
|
|
169
|
+
onAccomplishment: (accomplishmentTopic: string, callback: (payload: EventBusMessage<AccomplishmentPayload>) => void) => {
|
|
170
|
+
this.accomplishmentHandler.subscribe(accomplishmentTopic, callback);
|
|
171
|
+
},
|
|
172
|
+
/**
|
|
173
|
+
* Trigger an action that opens the sidebar and triggers an action in the designated plugin.
|
|
174
|
+
* @param pluginId The id of the plugin to trigger the action for.
|
|
175
|
+
* @param actionKey The key of the action to trigger.
|
|
176
|
+
* @param text Optional text to be used for the action like for example text that the translator would look up.
|
|
177
|
+
*/
|
|
178
|
+
emitSidebarAction: (pluginId: string, actionKey: string, text?: string) => {
|
|
179
|
+
this.event.emit("global.sidebar.triggerAction", { pluginId, actionKey, text });
|
|
213
180
|
}
|
|
181
|
+
}
|
|
214
182
|
|
|
215
|
-
|
|
216
|
-
|
|
183
|
+
public static async getInstance(pluginController: PluginController): Promise<RimoriClient> {
|
|
184
|
+
if (!RimoriClient.instance) {
|
|
185
|
+
const { supabase, tablePrefix, pluginId } = await pluginController.getClient();
|
|
186
|
+
RimoriClient.instance = new RimoriClient({ pluginController, supabase, tablePrefix, pluginId });
|
|
217
187
|
}
|
|
188
|
+
return RimoriClient.instance;
|
|
189
|
+
}
|
|
218
190
|
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
this.pluginController.getSupabaseUrl(),
|
|
231
|
-
{ input: text, voice, speed, language },
|
|
232
|
-
await this.pluginController.getToken()
|
|
233
|
-
);
|
|
234
|
-
},
|
|
235
|
-
getTextFromVoice: (file: Blob): Promise<string> => {
|
|
236
|
-
return getSTTResponse(this.superbase, file);
|
|
237
|
-
},
|
|
238
|
-
getObject: async (request: ObjectRequest): Promise<any> => {
|
|
239
|
-
const token = await this.pluginController.getToken();
|
|
240
|
-
return generateObjectFunction(this.pluginController.getSupabaseUrl(), request, token);
|
|
241
|
-
},
|
|
242
|
-
// getSteamedObject: this.generateObjectStream,
|
|
243
|
-
}
|
|
191
|
+
private from<
|
|
192
|
+
TableName extends string & keyof GenericSchema['Tables'],
|
|
193
|
+
Table extends GenericSchema['Tables'][TableName]
|
|
194
|
+
>(relation: TableName): PostgrestQueryBuilder<GenericSchema, Table, TableName>
|
|
195
|
+
private from<
|
|
196
|
+
ViewName extends string & keyof GenericSchema['Views'],
|
|
197
|
+
View extends GenericSchema['Views'][ViewName]
|
|
198
|
+
>(relation: ViewName): PostgrestQueryBuilder<GenericSchema, View, ViewName>
|
|
199
|
+
private from(relation: string): PostgrestQueryBuilder<GenericSchema, any, any> {
|
|
200
|
+
return this.superbase.from(this.getTableName(relation));
|
|
201
|
+
}
|
|
244
202
|
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
* @param generatorInstructions The instructions for the generator.
|
|
249
|
-
* @param filter The filter for the shared content.
|
|
250
|
-
* @returns The new shared content.
|
|
251
|
-
*/
|
|
252
|
-
public async fetchNewSharedContent<T, R = T & BasicAssignment>(
|
|
253
|
-
type: string,
|
|
254
|
-
generatorInstructions: (reservedTopics: string[]) => Promise<ObjectRequest> | ObjectRequest,
|
|
255
|
-
filter?: { column: string, value: string | number | boolean },
|
|
256
|
-
): Promise<R[]> {
|
|
257
|
-
return this.sharedContentController.fetchNewSharedContent(type, generatorInstructions, filter);
|
|
258
|
-
}
|
|
203
|
+
private getTableName(type: string) {
|
|
204
|
+
return this.db.tablePrefix + "_" + type;
|
|
205
|
+
}
|
|
259
206
|
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
}
|
|
207
|
+
public llm = {
|
|
208
|
+
getText: async (messages: Message[], tools?: Tool[]): Promise<string> => {
|
|
209
|
+
const token = await this.pluginController.getToken();
|
|
210
|
+
return generateText(this.supabaseUrl, messages, tools || [], token).then(({ messages }) => messages[0].content[0].text);
|
|
211
|
+
},
|
|
212
|
+
getSteamedText: async (messages: Message[], onMessage: OnLLMResponse, tools?: Tool[]) => {
|
|
213
|
+
const token = await this.pluginController.getToken();
|
|
214
|
+
streamChatGPT(this.supabaseUrl, messages, tools || [], onMessage, token);
|
|
215
|
+
},
|
|
216
|
+
getVoice: async (text: string, voice = "alloy", speed = 1, language?: string): Promise<Blob> => {
|
|
217
|
+
const token = await this.pluginController.getToken();
|
|
218
|
+
return getTTSResponse(this.supabaseUrl, { input: text, voice, speed, language }, token);
|
|
219
|
+
},
|
|
220
|
+
getTextFromVoice: (file: Blob): Promise<string> => {
|
|
221
|
+
return getSTTResponse(this.superbase, file);
|
|
222
|
+
},
|
|
223
|
+
getObject: async (request: ObjectRequest): Promise<any> => {
|
|
224
|
+
const token = await this.pluginController.getToken();
|
|
225
|
+
return generateObjectFunction(this.supabaseUrl, request, token);
|
|
226
|
+
},
|
|
227
|
+
// getSteamedObject: this.generateObjectStream,
|
|
228
|
+
}
|
|
269
229
|
|
|
230
|
+
public community = {
|
|
270
231
|
/**
|
|
271
|
-
*
|
|
272
|
-
*
|
|
273
|
-
*
|
|
232
|
+
* Shared content is a way to share completable content with other users using this plugin.
|
|
233
|
+
* Typical examples are assignments, exercises, stories, etc.
|
|
234
|
+
* Users generate new shared content items and others can complete the content too.
|
|
274
235
|
*/
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
236
|
+
sharedContent: {
|
|
237
|
+
/**
|
|
238
|
+
* Get one dedicated shared content item by id. It does not matter if it is completed or not.
|
|
239
|
+
* @param contentType The type of shared content to get. E.g. assignments, exercises, etc.
|
|
240
|
+
* @param id The id of the shared content item.
|
|
241
|
+
* @returns The shared content item.
|
|
242
|
+
*/
|
|
243
|
+
get: async <T = any>(contentType: string, id: string): Promise<BasicAssignment<T>> => {
|
|
244
|
+
return await this.sharedContentController.getSharedContent(contentType, id);
|
|
245
|
+
},
|
|
246
|
+
/**
|
|
247
|
+
* Get a list of shared content items.
|
|
248
|
+
* @param contentType The type of shared content to get. E.g. assignments, exercises, etc.
|
|
249
|
+
* @param filter The optional additional filter for checking new shared content based on a column and value. This is useful if the aditional information stored on the shared content is used to further narrow down the kind of shared content wanted to be received. E.g. only adjective grammar exercises.
|
|
250
|
+
* @param limit The optional limit for the number of results.
|
|
251
|
+
* @returns The list of shared content items.
|
|
252
|
+
*/
|
|
253
|
+
getList: async <T = any>(contentType: string, filter?: SharedContentFilter, limit?: number): Promise<BasicAssignment<T>[]> => {
|
|
254
|
+
return await this.sharedContentController.getSharedContentList(contentType, filter, limit);
|
|
255
|
+
},
|
|
256
|
+
/**
|
|
257
|
+
* Get new shared content.
|
|
258
|
+
* @param contentType The type of shared content to fetch. E.g. assignments, exercises, etc.
|
|
259
|
+
* @param generatorInstructions The instructions for the creation of new shared content. The object will automatically be extended with a tool property with a topic and keywords property to let a new unique topic be generated.
|
|
260
|
+
* @param filter The optional additional filter for checking new shared content based on a column and value. This is useful if the aditional information stored on the shared content is used to further narrow down the kind of shared content wanted to be received. E.g. only adjective grammar exercises.
|
|
261
|
+
* @param privateTopic An optional flag to indicate if the topic should be private and only be visible to the user. This is useful if the topic is not meant to be shared with other users. Like for personal topics or if the content is based on the personal study goal.
|
|
262
|
+
* @returns The new shared content.
|
|
263
|
+
*/
|
|
264
|
+
getNew: async <T = any>(
|
|
265
|
+
contentType: string,
|
|
266
|
+
generatorInstructions: SharedContentObjectRequest,
|
|
267
|
+
filter?: SharedContentFilter,
|
|
268
|
+
privateTopic?: boolean,
|
|
269
|
+
): Promise<BasicAssignment<T>> => {
|
|
270
|
+
return await this.sharedContentController.getNewSharedContent(contentType, generatorInstructions, filter, privateTopic);
|
|
271
|
+
},
|
|
272
|
+
/**
|
|
273
|
+
* Create a new shared content item.
|
|
274
|
+
* @param content The content to create.
|
|
275
|
+
* @returns The new shared content item.
|
|
276
|
+
*/
|
|
277
|
+
create: async <T = any>(content: SharedContent<T>): Promise<BasicAssignment<T>> => {
|
|
278
|
+
return await this.sharedContentController.createSharedContent(content);
|
|
279
|
+
},
|
|
280
|
+
/**
|
|
281
|
+
* Update a shared content item.
|
|
282
|
+
* @param id The id of the shared content item to update.
|
|
283
|
+
* @param content The content to update.
|
|
284
|
+
* @returns The updated shared content item.
|
|
285
|
+
*/
|
|
286
|
+
update: async <T = any>(id: string, content: Partial<SharedContent<T>>): Promise<BasicAssignment<T>> => {
|
|
287
|
+
return await this.sharedContentController.updateSharedContent(id, content);
|
|
288
|
+
},
|
|
289
|
+
/**
|
|
290
|
+
* Complete a shared content item.
|
|
291
|
+
* @param contentType The type of shared content to complete. E.g. assignments, exercises, etc.
|
|
292
|
+
* @param assignmentId The id of the shared content item to complete.
|
|
293
|
+
*/
|
|
294
|
+
complete: async (contentType: string, assignmentId: string) => {
|
|
295
|
+
return await this.sharedContentController.completeSharedContent(contentType, assignmentId);
|
|
296
|
+
}
|
|
281
297
|
}
|
|
298
|
+
}
|
|
282
299
|
}
|
|
@@ -2,16 +2,15 @@ export function setTheme() {
|
|
|
2
2
|
const urlParams = new URLSearchParams(window.location.search);
|
|
3
3
|
|
|
4
4
|
let theme = urlParams.get('theme');
|
|
5
|
-
const isSidebar = urlParams.get('applicationMode') === "sidebar";
|
|
6
|
-
|
|
7
5
|
if (!theme || theme === 'system') {
|
|
8
6
|
theme = window.matchMedia && window.matchMedia('(prefers-color-scheme: dark)').matches ? 'dark' : 'light';
|
|
9
7
|
}
|
|
10
8
|
|
|
11
|
-
document.documentElement.classList.add("dark:text-gray-200"
|
|
9
|
+
document.documentElement.classList.add("dark:text-gray-200");
|
|
12
10
|
|
|
13
11
|
if (theme === 'dark') {
|
|
14
|
-
document.documentElement.
|
|
15
|
-
document.documentElement.
|
|
12
|
+
document.documentElement.setAttribute("data-theme", "dark");
|
|
13
|
+
document.documentElement.classList.add('dark', "dark:bg-gray-950");
|
|
14
|
+
document.documentElement.style.background = "hsl(var(--background))";
|
|
16
15
|
}
|
|
17
16
|
}
|