@rimori/client 2.4.0 → 2.5.0-next.2
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/dist/cli/scripts/init/dev-registration.js +4 -2
- package/dist/cli/scripts/init/main.js +1 -0
- package/dist/cli/scripts/release/release.js +0 -0
- package/dist/controller/SettingsController.d.ts +1 -1
- package/dist/controller/SharedContentController.d.ts +1 -1
- package/dist/fromRimori/EventBus.js +1 -1
- package/dist/index.d.ts +2 -2
- package/dist/plugin/CommunicationHandler.d.ts +13 -8
- package/dist/plugin/CommunicationHandler.js +44 -59
- package/dist/plugin/RimoriClient.d.ts +11 -195
- package/dist/plugin/RimoriClient.js +17 -298
- package/dist/plugin/StandaloneClient.d.ts +1 -1
- package/dist/plugin/StandaloneClient.js +3 -2
- package/dist/plugin/module/AIModule.d.ts +49 -0
- package/dist/plugin/module/AIModule.js +81 -0
- package/dist/plugin/module/DbModule.d.ts +30 -0
- package/dist/plugin/module/DbModule.js +51 -0
- package/dist/plugin/module/EventModule.d.ts +99 -0
- package/dist/plugin/module/EventModule.js +162 -0
- package/dist/{controller/ExerciseController.d.ts → plugin/module/ExerciseModule.d.ts} +20 -16
- package/dist/{controller/ExerciseController.js → plugin/module/ExerciseModule.js} +27 -20
- package/dist/plugin/module/PluginModule.d.ts +76 -0
- package/dist/plugin/module/PluginModule.js +88 -0
- package/package.json +8 -3
- package/.github/workflows/pre-release.yml +0 -126
- package/.prettierignore +0 -35
- package/eslint.config.js +0 -53
- package/example/docs/devdocs.md +0 -241
- package/example/docs/overview.md +0 -29
- package/example/docs/userdocs.md +0 -126
- package/example/rimori.config.ts +0 -91
- package/example/worker/vite.config.ts +0 -26
- package/example/worker/worker.ts +0 -11
- package/prettier.config.js +0 -8
- package/src/cli/scripts/init/dev-registration.ts +0 -189
- package/src/cli/scripts/init/env-setup.ts +0 -44
- package/src/cli/scripts/init/file-operations.ts +0 -58
- package/src/cli/scripts/init/html-cleaner.ts +0 -45
- package/src/cli/scripts/init/main.ts +0 -175
- package/src/cli/scripts/init/package-setup.ts +0 -113
- package/src/cli/scripts/init/router-transformer.ts +0 -332
- package/src/cli/scripts/init/tailwind-config.ts +0 -66
- package/src/cli/scripts/init/vite-config.ts +0 -73
- package/src/cli/scripts/release/detect-translation-languages.ts +0 -37
- package/src/cli/scripts/release/release-config-upload.ts +0 -119
- package/src/cli/scripts/release/release-db-update.ts +0 -97
- package/src/cli/scripts/release/release-file-upload.ts +0 -138
- package/src/cli/scripts/release/release.ts +0 -85
- package/src/cli/types/DatabaseTypes.ts +0 -125
- package/src/controller/AIController.ts +0 -295
- package/src/controller/AccomplishmentController.ts +0 -188
- package/src/controller/AudioController.ts +0 -64
- package/src/controller/ExerciseController.ts +0 -117
- package/src/controller/ObjectController.ts +0 -120
- package/src/controller/SettingsController.ts +0 -186
- package/src/controller/SharedContentController.ts +0 -365
- package/src/controller/TranslationController.ts +0 -136
- package/src/controller/VoiceController.ts +0 -33
- package/src/fromRimori/EventBus.ts +0 -382
- package/src/fromRimori/PluginTypes.ts +0 -214
- package/src/fromRimori/readme.md +0 -2
- package/src/index.ts +0 -19
- package/src/plugin/CommunicationHandler.ts +0 -310
- package/src/plugin/Logger.ts +0 -394
- package/src/plugin/RimoriClient.ts +0 -530
- package/src/plugin/StandaloneClient.ts +0 -125
- package/src/utils/difficultyConverter.ts +0 -15
- package/src/utils/endpoint.ts +0 -3
- package/src/worker/WorkerSetup.ts +0 -35
- package/tsconfig.json +0 -17
|
@@ -7,176 +7,24 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
7
7
|
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
8
|
});
|
|
9
9
|
};
|
|
10
|
-
import { generateText, streamChatGPT } from '../controller/AIController';
|
|
11
|
-
import { generateObject } from '../controller/ObjectController';
|
|
12
|
-
import { SettingsController } from '../controller/SettingsController';
|
|
13
10
|
import { SharedContentController, } from '../controller/SharedContentController';
|
|
14
|
-
import { getSTTResponse, getTTSResponse } from '../controller/VoiceController';
|
|
15
|
-
import { ExerciseController } from '../controller/ExerciseController';
|
|
16
|
-
import { EventBus } from '../fromRimori/EventBus';
|
|
17
|
-
import { AccomplishmentController } from '../controller/AccomplishmentController';
|
|
18
11
|
import { RimoriCommunicationHandler } from './CommunicationHandler';
|
|
19
|
-
import { Translator } from '../controller/TranslationController';
|
|
20
12
|
import { Logger } from './Logger';
|
|
13
|
+
import { PluginModule } from './module/PluginModule';
|
|
14
|
+
import { DbModule } from './module/DbModule';
|
|
15
|
+
import { EventModule } from './module/EventModule';
|
|
16
|
+
import { AIModule } from './module/AIModule';
|
|
17
|
+
import { ExerciseModule } from './module/ExerciseModule';
|
|
21
18
|
export class RimoriClient {
|
|
22
19
|
constructor(controller, supabase, info) {
|
|
23
|
-
this.event = {
|
|
24
|
-
/**
|
|
25
|
-
* Emit an event to Rimori or a plugin.
|
|
26
|
-
* The topic schema is:
|
|
27
|
-
* {pluginId}.{eventId}
|
|
28
|
-
* Check out the event bus documentation for more information.
|
|
29
|
-
* For triggering events from Rimori like context menu actions use the "global" keyword.
|
|
30
|
-
* @param topic The topic to emit the event on.
|
|
31
|
-
* @param data The data to emit.
|
|
32
|
-
* @param eventId The event id.
|
|
33
|
-
*/
|
|
34
|
-
emit: (topic, data, eventId) => {
|
|
35
|
-
const globalTopic = this.pluginController.getGlobalEventTopic(topic);
|
|
36
|
-
EventBus.emit(this.plugin.pluginId, globalTopic, data, eventId);
|
|
37
|
-
},
|
|
38
|
-
/**
|
|
39
|
-
* Request an event.
|
|
40
|
-
* @param topic The topic to request the event on.
|
|
41
|
-
* @param data The data to request.
|
|
42
|
-
* @returns The response from the event.
|
|
43
|
-
*/
|
|
44
|
-
request: (topic, data) => {
|
|
45
|
-
const globalTopic = this.pluginController.getGlobalEventTopic(topic);
|
|
46
|
-
return EventBus.request(this.plugin.pluginId, globalTopic, data);
|
|
47
|
-
},
|
|
48
|
-
/**
|
|
49
|
-
* Subscribe to an event.
|
|
50
|
-
* @param topic The topic to subscribe to.
|
|
51
|
-
* @param callback The callback to call when the event is emitted.
|
|
52
|
-
* @returns An EventListener object containing an off() method to unsubscribe the listeners.
|
|
53
|
-
*/
|
|
54
|
-
on: (topic, callback) => {
|
|
55
|
-
const topics = Array.isArray(topic) ? topic : [topic];
|
|
56
|
-
return EventBus.on(topics.map((t) => this.pluginController.getGlobalEventTopic(t)), callback);
|
|
57
|
-
},
|
|
58
|
-
/**
|
|
59
|
-
* Subscribe to an event once.
|
|
60
|
-
* @param topic The topic to subscribe to.
|
|
61
|
-
* @param callback The callback to call when the event is emitted.
|
|
62
|
-
*/
|
|
63
|
-
once: (topic, callback) => {
|
|
64
|
-
EventBus.once(this.pluginController.getGlobalEventTopic(topic), callback);
|
|
65
|
-
},
|
|
66
|
-
/**
|
|
67
|
-
* Respond to an event.
|
|
68
|
-
* @param topic The topic to respond to.
|
|
69
|
-
* @param data The data to respond with.
|
|
70
|
-
*/
|
|
71
|
-
respond: (topic, data) => {
|
|
72
|
-
const topics = Array.isArray(topic) ? topic : [topic];
|
|
73
|
-
EventBus.respond(this.plugin.pluginId, topics.map((t) => this.pluginController.getGlobalEventTopic(t)), data);
|
|
74
|
-
},
|
|
75
|
-
/**
|
|
76
|
-
* Emit an accomplishment.
|
|
77
|
-
* @param payload The payload to emit.
|
|
78
|
-
*/
|
|
79
|
-
emitAccomplishment: (payload) => {
|
|
80
|
-
this.accomplishmentHandler.emitAccomplishment(payload);
|
|
81
|
-
},
|
|
82
|
-
/**
|
|
83
|
-
* Subscribe to an accomplishment.
|
|
84
|
-
* @param accomplishmentTopic The topic to subscribe to.
|
|
85
|
-
* @param callback The callback to call when the accomplishment is emitted.
|
|
86
|
-
*/
|
|
87
|
-
onAccomplishment: (accomplishmentTopic, callback) => {
|
|
88
|
-
this.accomplishmentHandler.subscribe(accomplishmentTopic, callback);
|
|
89
|
-
},
|
|
90
|
-
/**
|
|
91
|
-
* Trigger an action that opens the sidebar and triggers an action in the designated plugin.
|
|
92
|
-
* @param pluginId The id of the plugin to trigger the action for.
|
|
93
|
-
* @param actionKey The key of the action to trigger.
|
|
94
|
-
* @param text Optional text to be used for the action like for example text that the translator would look up.
|
|
95
|
-
*/
|
|
96
|
-
emitSidebarAction: (pluginId, actionKey, text) => {
|
|
97
|
-
this.event.emit('global.sidebar.triggerAction', { plugin_id: pluginId, action_key: actionKey, text });
|
|
98
|
-
},
|
|
99
|
-
/**
|
|
100
|
-
* Subscribe to main panel actions triggered by the user from the dashboard.
|
|
101
|
-
* @param callback Handler function that receives the action data when a matching action is triggered.
|
|
102
|
-
* @param actionsToListen Optional filter to listen only to specific action keys. If empty or not provided, all actions will trigger the callback.
|
|
103
|
-
* @returns An EventListener object with an `off()` method for cleanup.
|
|
104
|
-
*
|
|
105
|
-
* @example
|
|
106
|
-
* ```ts
|
|
107
|
-
* const listener = client.event.onMainPanelAction((data) => {
|
|
108
|
-
* console.log('Action received:', data.action_key);
|
|
109
|
-
* }, ['startSession', 'pauseSession']);
|
|
110
|
-
*
|
|
111
|
-
* // Clean up when component unmounts to prevent events from firing
|
|
112
|
-
* // when navigating away or returning to the page
|
|
113
|
-
* useEffect(() => {
|
|
114
|
-
* return () => listener.off();
|
|
115
|
-
* }, []);
|
|
116
|
-
* ```
|
|
117
|
-
*
|
|
118
|
-
* **Important:** Always call `listener.off()` when your component unmounts or when you no longer need to listen.
|
|
119
|
-
* This prevents the event handler from firing when navigating away from or returning to the page, which could
|
|
120
|
-
* cause unexpected behavior or duplicate event handling.
|
|
121
|
-
*/
|
|
122
|
-
onMainPanelAction: (callback, actionsToListen = []) => {
|
|
123
|
-
const listeningActions = Array.isArray(actionsToListen) ? actionsToListen : [actionsToListen];
|
|
124
|
-
// this needs to be a emit and on because the main panel action is triggered by the user and not by the plugin
|
|
125
|
-
this.event.emit('action.requestMain');
|
|
126
|
-
return this.event.on('action.requestMain', ({ data }) => {
|
|
127
|
-
// console.log('Received action for main panel ' + data.action_key);
|
|
128
|
-
// console.log('Listening to actions', listeningActions);
|
|
129
|
-
if (listeningActions.length === 0 || listeningActions.includes(data.action_key)) {
|
|
130
|
-
callback(data);
|
|
131
|
-
}
|
|
132
|
-
});
|
|
133
|
-
},
|
|
134
|
-
onSidePanelAction: (callback, actionsToListen = []) => {
|
|
135
|
-
const listeningActions = Array.isArray(actionsToListen) ? actionsToListen : [actionsToListen];
|
|
136
|
-
// this needs to be a emit and on because the main panel action is triggered by the user and not by the plugin
|
|
137
|
-
this.event.emit('action.requestSidebar');
|
|
138
|
-
return this.event.on('action.requestSidebar', ({ data }) => {
|
|
139
|
-
// console.log("eventHandler .onSidePanelAction", data);
|
|
140
|
-
// console.log('Received action for sidebar ' + data.action);
|
|
141
|
-
// console.log('Listening to actions', listeningActions);
|
|
142
|
-
if (listeningActions.length === 0 || listeningActions.includes(data.action)) {
|
|
143
|
-
callback(data);
|
|
144
|
-
}
|
|
145
|
-
});
|
|
146
|
-
},
|
|
147
|
-
};
|
|
148
20
|
this.navigation = {
|
|
149
21
|
toDashboard: () => {
|
|
150
22
|
this.event.emit('global.navigation.triggerToDashboard');
|
|
151
23
|
},
|
|
152
24
|
};
|
|
153
|
-
this.ai = {
|
|
154
|
-
getText: (messages, tools) => __awaiter(this, void 0, void 0, function* () {
|
|
155
|
-
const token = yield this.pluginController.getToken();
|
|
156
|
-
return generateText(this.pluginController.getBackendUrl(), messages, tools || [], token).then(({ messages }) => messages[0].content[0].text);
|
|
157
|
-
}),
|
|
158
|
-
getSteamedText: (messages, onMessage, tools) => __awaiter(this, void 0, void 0, function* () {
|
|
159
|
-
const token = yield this.pluginController.getToken();
|
|
160
|
-
streamChatGPT(this.pluginController.getBackendUrl(), messages, tools || [], onMessage, token);
|
|
161
|
-
}),
|
|
162
|
-
getVoice: (text_1, ...args_1) => __awaiter(this, [text_1, ...args_1], void 0, function* (text, voice = 'alloy', speed = 1, language) {
|
|
163
|
-
const token = yield this.pluginController.getToken();
|
|
164
|
-
return getTTSResponse(this.pluginController.getBackendUrl(), { input: text, voice, speed, language }, token);
|
|
165
|
-
}),
|
|
166
|
-
getTextFromVoice: (file) => __awaiter(this, void 0, void 0, function* () {
|
|
167
|
-
const token = yield this.pluginController.getToken();
|
|
168
|
-
return getSTTResponse(this.pluginController.getBackendUrl(), file, token);
|
|
169
|
-
}),
|
|
170
|
-
getObject: (request) => __awaiter(this, void 0, void 0, function* () {
|
|
171
|
-
const token = yield this.pluginController.getToken();
|
|
172
|
-
return generateObject(this.pluginController.getBackendUrl(), request, token);
|
|
173
|
-
}),
|
|
174
|
-
// getSteamedObject: this.generateObjectStream,
|
|
175
|
-
};
|
|
176
25
|
this.runtime = {
|
|
177
26
|
fetchBackend: (url, options) => __awaiter(this, void 0, void 0, function* () {
|
|
178
|
-
|
|
179
|
-
return fetch(this.pluginController.getBackendUrl() + url, Object.assign(Object.assign({}, options), { headers: Object.assign(Object.assign({}, options.headers), { Authorization: `Bearer ${token}` }) }));
|
|
27
|
+
return fetch(this.rimoriInfo.backendUrl + url, Object.assign(Object.assign({}, options), { headers: Object.assign(Object.assign({}, options.headers), { Authorization: `Bearer ${this.rimoriInfo.token}` }) }));
|
|
180
28
|
}),
|
|
181
29
|
};
|
|
182
30
|
this.community = {
|
|
@@ -263,156 +111,26 @@ export class RimoriClient {
|
|
|
263
111
|
}),
|
|
264
112
|
},
|
|
265
113
|
};
|
|
266
|
-
this.exercise = {
|
|
267
|
-
/**
|
|
268
|
-
* Fetches weekly exercises from the weekly_exercises view.
|
|
269
|
-
* Shows exercises for the current week that haven't expired.
|
|
270
|
-
* @returns Array of exercise objects.
|
|
271
|
-
*/
|
|
272
|
-
view: () => __awaiter(this, void 0, void 0, function* () {
|
|
273
|
-
return this.exerciseController.viewWeeklyExercises();
|
|
274
|
-
}),
|
|
275
|
-
/**
|
|
276
|
-
* Creates a new exercise or multiple exercises via the backend API.
|
|
277
|
-
* When creating multiple exercises, all requests are made in parallel but only one event is emitted.
|
|
278
|
-
* @param params Exercise creation parameters (single or array).
|
|
279
|
-
* @returns Created exercise objects.
|
|
280
|
-
*/
|
|
281
|
-
add: (params) => __awaiter(this, void 0, void 0, function* () {
|
|
282
|
-
const token = yield this.pluginController.getToken();
|
|
283
|
-
const backendUrl = this.pluginController.getBackendUrl();
|
|
284
|
-
const exercises = Array.isArray(params) ? params : [params];
|
|
285
|
-
return this.exerciseController.addExercise(token, backendUrl, exercises);
|
|
286
|
-
}),
|
|
287
|
-
/**
|
|
288
|
-
* Deletes an exercise via the backend API.
|
|
289
|
-
* @param id The exercise ID to delete.
|
|
290
|
-
* @returns Success status.
|
|
291
|
-
*/
|
|
292
|
-
delete: (id) => __awaiter(this, void 0, void 0, function* () {
|
|
293
|
-
const token = yield this.pluginController.getToken();
|
|
294
|
-
const backendUrl = this.pluginController.getBackendUrl();
|
|
295
|
-
return this.exerciseController.deleteExercise(token, backendUrl, id);
|
|
296
|
-
}),
|
|
297
|
-
};
|
|
298
114
|
this.rimoriInfo = info;
|
|
299
|
-
this.superbase = supabase;
|
|
300
115
|
this.pluginController = controller;
|
|
301
|
-
this.exerciseController = new ExerciseController(supabase, this);
|
|
302
|
-
this.accomplishmentHandler = new AccomplishmentController(info.pluginId);
|
|
303
|
-
this.settingsController = new SettingsController(supabase, info.pluginId, info.guild);
|
|
304
116
|
this.sharedContentController = new SharedContentController(supabase, this);
|
|
305
|
-
|
|
306
|
-
this.
|
|
117
|
+
this.ai = new AIModule(controller, info);
|
|
118
|
+
this.event = new EventModule(info.pluginId);
|
|
119
|
+
this.db = new DbModule(supabase, controller, info);
|
|
120
|
+
this.plugin = new PluginModule(supabase, controller, info);
|
|
121
|
+
this.exercise = new ExerciseModule(supabase, controller, info, this.event);
|
|
122
|
+
controller.onUpdate((updatedInfo) => {
|
|
123
|
+
this.rimoriInfo = updatedInfo;
|
|
124
|
+
});
|
|
307
125
|
//only init logger in workers and on main plugin pages
|
|
308
|
-
if (this.
|
|
126
|
+
if (this.plugin.applicationMode !== 'sidebar') {
|
|
309
127
|
Logger.getInstance(this);
|
|
310
128
|
}
|
|
311
129
|
}
|
|
312
|
-
get plugin() {
|
|
313
|
-
return {
|
|
314
|
-
pluginId: this.rimoriInfo.pluginId,
|
|
315
|
-
/**
|
|
316
|
-
* The release channel of this plugin installation.
|
|
317
|
-
* Determines which database schema is used for plugin tables.
|
|
318
|
-
*/
|
|
319
|
-
releaseChannel: this.rimoriInfo.releaseChannel,
|
|
320
|
-
/**
|
|
321
|
-
* Set the settings for the plugin.
|
|
322
|
-
* @param settings The settings to set.
|
|
323
|
-
*/
|
|
324
|
-
setSettings: (settings) => __awaiter(this, void 0, void 0, function* () {
|
|
325
|
-
yield this.settingsController.setSettings(settings);
|
|
326
|
-
}),
|
|
327
|
-
/**
|
|
328
|
-
* Get the settings for the plugin. T can be any type of settings, UserSettings or SystemSettings.
|
|
329
|
-
* @param defaultSettings The default settings to use if no settings are found.
|
|
330
|
-
* @param genericSettings The type of settings to get.
|
|
331
|
-
* @returns The settings for the plugin.
|
|
332
|
-
*/
|
|
333
|
-
getSettings: (defaultSettings) => __awaiter(this, void 0, void 0, function* () {
|
|
334
|
-
return yield this.settingsController.getSettings(defaultSettings);
|
|
335
|
-
}),
|
|
336
|
-
getUserInfo: () => {
|
|
337
|
-
return this.rimoriInfo.profile;
|
|
338
|
-
},
|
|
339
|
-
/**
|
|
340
|
-
* Retrieves information about plugins, including:
|
|
341
|
-
* - All installed plugins
|
|
342
|
-
* - The currently active plugin in the main panel
|
|
343
|
-
* - The currently active plugin in the side panel
|
|
344
|
-
*/
|
|
345
|
-
getPluginInfo: () => {
|
|
346
|
-
return {
|
|
347
|
-
installedPlugins: this.rimoriInfo.installedPlugins,
|
|
348
|
-
mainPanelPlugin: this.rimoriInfo.mainPanelPlugin,
|
|
349
|
-
sidePanelPlugin: this.rimoriInfo.sidePanelPlugin,
|
|
350
|
-
};
|
|
351
|
-
},
|
|
352
|
-
/**
|
|
353
|
-
* Get the translator for the plugin.
|
|
354
|
-
* @returns The translator for the plugin.
|
|
355
|
-
*/
|
|
356
|
-
getTranslator: () => __awaiter(this, void 0, void 0, function* () {
|
|
357
|
-
yield this.translator.initialize();
|
|
358
|
-
return this.translator;
|
|
359
|
-
}),
|
|
360
|
-
};
|
|
361
|
-
}
|
|
362
|
-
get db() {
|
|
363
|
-
return {
|
|
364
|
-
// private from<
|
|
365
|
-
// TableName extends string & keyof GenericSchema['Tables'],
|
|
366
|
-
// Table extends GenericSchema['Tables'][TableName],
|
|
367
|
-
// >(relation: TableName): PostgrestQueryBuilder<GenericSchema, Table, TableName>;
|
|
368
|
-
// private from<ViewName extends string & keyof GenericSchema['Views'], View extends GenericSchema['Views'][ViewName]>(
|
|
369
|
-
// relation: ViewName,
|
|
370
|
-
// ): PostgrestQueryBuilder<GenericSchema, View, ViewName>;
|
|
371
|
-
from: (relation) => {
|
|
372
|
-
const tableName = this.db.getTableName(relation);
|
|
373
|
-
// Use the schema determined by rimori-main based on release channel
|
|
374
|
-
// Global tables (starting with 'global_') remain in public schema
|
|
375
|
-
// Plugin tables use the schema provided by rimori-main (plugins or plugins_alpha)
|
|
376
|
-
if (relation.startsWith('global_')) {
|
|
377
|
-
// Global tables stay in public schema
|
|
378
|
-
return this.superbase.from(tableName);
|
|
379
|
-
}
|
|
380
|
-
// Plugin tables go to the schema provided by rimori-main
|
|
381
|
-
return this.superbase.schema(this.rimoriInfo.dbSchema).from(tableName);
|
|
382
|
-
},
|
|
383
|
-
// storage: this.superbase.storage,
|
|
384
|
-
// functions: this.superbase.functions,
|
|
385
|
-
/**
|
|
386
|
-
* The table prefix for of database tables of the plugin.
|
|
387
|
-
*/
|
|
388
|
-
tablePrefix: this.rimoriInfo.tablePrefix,
|
|
389
|
-
/**
|
|
390
|
-
* The database schema used for plugin tables.
|
|
391
|
-
* Determined by rimori-main based on release channel:
|
|
392
|
-
* - 'plugins_alpha' for alpha release channel
|
|
393
|
-
* - 'plugins' for beta and stable release channels
|
|
394
|
-
*/
|
|
395
|
-
schema: this.rimoriInfo.dbSchema,
|
|
396
|
-
/**
|
|
397
|
-
* Get the table name for a given plugin table.
|
|
398
|
-
* Internally all tables are prefixed with the plugin id. This function is used to get the correct table name for a given public table.
|
|
399
|
-
* @param table The plugin table name to get the full table name for.
|
|
400
|
-
* @returns The full table name.
|
|
401
|
-
*/
|
|
402
|
-
getTableName: (table) => {
|
|
403
|
-
if (/[A-Z]/.test(table)) {
|
|
404
|
-
throw new Error('Table name cannot include uppercase letters. Please use snake_case for table names.');
|
|
405
|
-
}
|
|
406
|
-
if (table.startsWith('global_')) {
|
|
407
|
-
return table.replace('global_', '');
|
|
408
|
-
}
|
|
409
|
-
return this.db.tablePrefix + '_' + table;
|
|
410
|
-
},
|
|
411
|
-
};
|
|
412
|
-
}
|
|
413
130
|
/**
|
|
414
131
|
* Get a query parameter value that was passed via MessageChannel
|
|
415
132
|
* @param key The query parameter key
|
|
133
|
+
* @deprecated Use the plugin.applicationMode and plugin.theme properties instead
|
|
416
134
|
* @returns The query parameter value or null if not found
|
|
417
135
|
*/
|
|
418
136
|
getQueryParam(key) {
|
|
@@ -436,3 +154,4 @@ export class RimoriClient {
|
|
|
436
154
|
});
|
|
437
155
|
}
|
|
438
156
|
}
|
|
157
|
+
// test
|
|
@@ -7,12 +7,13 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
7
7
|
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
8
|
});
|
|
9
9
|
};
|
|
10
|
-
import { createClient } from '@supabase/supabase-js';
|
|
11
10
|
import { EventBus } from '../fromRimori/EventBus';
|
|
12
11
|
import { DEFAULT_ANON_KEY, DEFAULT_ENDPOINT } from '../utils/endpoint';
|
|
13
12
|
export class StandaloneClient {
|
|
14
13
|
constructor(config) {
|
|
15
|
-
|
|
14
|
+
throw new Error('Authentication is disabled until new developer platform is released.');
|
|
15
|
+
// this.supabase = createClient(config.url, config.key);
|
|
16
|
+
this.supabase = {};
|
|
16
17
|
this.config = config;
|
|
17
18
|
}
|
|
18
19
|
static getInstance() {
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { RimoriCommunicationHandler, RimoriInfo } from '../CommunicationHandler';
|
|
2
|
+
import { Message, OnLLMResponse } from '../../controller/AIController';
|
|
3
|
+
import { ObjectRequest } from '../../controller/ObjectController';
|
|
4
|
+
import { Tool } from '../../fromRimori/PluginTypes';
|
|
5
|
+
/**
|
|
6
|
+
* Controller for AI-related operations.
|
|
7
|
+
* Provides access to text generation, voice synthesis, and object generation.
|
|
8
|
+
*/
|
|
9
|
+
export declare class AIModule {
|
|
10
|
+
private communicationHandler;
|
|
11
|
+
private backendUrl;
|
|
12
|
+
private token;
|
|
13
|
+
constructor(communicationHandler: RimoriCommunicationHandler, info: RimoriInfo);
|
|
14
|
+
/**
|
|
15
|
+
* Generate text from messages using AI.
|
|
16
|
+
* @param messages The messages to generate text from.
|
|
17
|
+
* @param tools Optional tools to use for generation.
|
|
18
|
+
* @returns The generated text.
|
|
19
|
+
*/
|
|
20
|
+
getText(messages: Message[], tools?: Tool[]): Promise<string>;
|
|
21
|
+
/**
|
|
22
|
+
* Stream text generation from messages using AI.
|
|
23
|
+
* @param messages The messages to generate text from.
|
|
24
|
+
* @param onMessage Callback for each message chunk.
|
|
25
|
+
* @param tools Optional tools to use for generation.
|
|
26
|
+
*/
|
|
27
|
+
getSteamedText(messages: Message[], onMessage: OnLLMResponse, tools?: Tool[]): Promise<void>;
|
|
28
|
+
/**
|
|
29
|
+
* Generate voice audio from text using AI.
|
|
30
|
+
* @param text The text to convert to voice.
|
|
31
|
+
* @param voice The voice to use (default: 'alloy').
|
|
32
|
+
* @param speed The speed of the voice (default: 1).
|
|
33
|
+
* @param language Optional language for the voice.
|
|
34
|
+
* @returns The generated audio as a Blob.
|
|
35
|
+
*/
|
|
36
|
+
getVoice(text: string, voice?: string, speed?: number, language?: string): Promise<Blob>;
|
|
37
|
+
/**
|
|
38
|
+
* Convert voice audio to text using AI.
|
|
39
|
+
* @param file The audio file to convert.
|
|
40
|
+
* @returns The transcribed text.
|
|
41
|
+
*/
|
|
42
|
+
getTextFromVoice(file: Blob): Promise<string>;
|
|
43
|
+
/**
|
|
44
|
+
* Generate a structured object from a request using AI.
|
|
45
|
+
* @param request The object generation request.
|
|
46
|
+
* @returns The generated object.
|
|
47
|
+
*/
|
|
48
|
+
getObject<T = any>(request: ObjectRequest): Promise<T>;
|
|
49
|
+
}
|
|
@@ -0,0 +1,81 @@
|
|
|
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 { generateText, streamChatGPT } from '../../controller/AIController';
|
|
11
|
+
import { generateObject } from '../../controller/ObjectController';
|
|
12
|
+
import { getSTTResponse, getTTSResponse } from '../../controller/VoiceController';
|
|
13
|
+
/**
|
|
14
|
+
* Controller for AI-related operations.
|
|
15
|
+
* Provides access to text generation, voice synthesis, and object generation.
|
|
16
|
+
*/
|
|
17
|
+
export class AIModule {
|
|
18
|
+
constructor(communicationHandler, info) {
|
|
19
|
+
this.token = info.token;
|
|
20
|
+
this.backendUrl = info.backendUrl;
|
|
21
|
+
this.communicationHandler = communicationHandler;
|
|
22
|
+
this.communicationHandler.onUpdate((updatedInfo) => {
|
|
23
|
+
this.token = updatedInfo.token;
|
|
24
|
+
});
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Generate text from messages using AI.
|
|
28
|
+
* @param messages The messages to generate text from.
|
|
29
|
+
* @param tools Optional tools to use for generation.
|
|
30
|
+
* @returns The generated text.
|
|
31
|
+
*/
|
|
32
|
+
getText(messages, tools) {
|
|
33
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
34
|
+
return generateText(this.backendUrl, messages, tools || [], this.token).then(({ messages }) => messages[0].content[0].text);
|
|
35
|
+
});
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* Stream text generation from messages using AI.
|
|
39
|
+
* @param messages The messages to generate text from.
|
|
40
|
+
* @param onMessage Callback for each message chunk.
|
|
41
|
+
* @param tools Optional tools to use for generation.
|
|
42
|
+
*/
|
|
43
|
+
getSteamedText(messages, onMessage, tools) {
|
|
44
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
45
|
+
streamChatGPT(this.backendUrl, messages, tools || [], onMessage, this.token);
|
|
46
|
+
});
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* Generate voice audio from text using AI.
|
|
50
|
+
* @param text The text to convert to voice.
|
|
51
|
+
* @param voice The voice to use (default: 'alloy').
|
|
52
|
+
* @param speed The speed of the voice (default: 1).
|
|
53
|
+
* @param language Optional language for the voice.
|
|
54
|
+
* @returns The generated audio as a Blob.
|
|
55
|
+
*/
|
|
56
|
+
getVoice(text_1) {
|
|
57
|
+
return __awaiter(this, arguments, void 0, function* (text, voice = 'alloy', speed = 1, language) {
|
|
58
|
+
return getTTSResponse(this.backendUrl, { input: text, voice, speed, language }, this.token);
|
|
59
|
+
});
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* Convert voice audio to text using AI.
|
|
63
|
+
* @param file The audio file to convert.
|
|
64
|
+
* @returns The transcribed text.
|
|
65
|
+
*/
|
|
66
|
+
getTextFromVoice(file) {
|
|
67
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
68
|
+
return getSTTResponse(this.backendUrl, file, this.token);
|
|
69
|
+
});
|
|
70
|
+
}
|
|
71
|
+
/**
|
|
72
|
+
* Generate a structured object from a request using AI.
|
|
73
|
+
* @param request The object generation request.
|
|
74
|
+
* @returns The generated object.
|
|
75
|
+
*/
|
|
76
|
+
getObject(request) {
|
|
77
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
78
|
+
return generateObject(this.backendUrl, request, this.token);
|
|
79
|
+
});
|
|
80
|
+
}
|
|
81
|
+
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { PostgrestClientOptions, PostgrestQueryBuilder } from '@supabase/postgrest-js';
|
|
2
|
+
import { SupabaseClient } from '../CommunicationHandler';
|
|
3
|
+
import { RimoriCommunicationHandler, RimoriInfo } from '../CommunicationHandler';
|
|
4
|
+
import { GenericSchema, GenericTable } from '@supabase/postgrest-js/dist/cjs/types/common/common';
|
|
5
|
+
/**
|
|
6
|
+
* Database module for plugin database operations.
|
|
7
|
+
* Provides access to plugin tables with automatic prefixing and schema management.
|
|
8
|
+
*/
|
|
9
|
+
export declare class DbModule {
|
|
10
|
+
private supabase;
|
|
11
|
+
private rimoriInfo;
|
|
12
|
+
tablePrefix: string;
|
|
13
|
+
schema: string;
|
|
14
|
+
constructor(supabase: SupabaseClient, communicationHandler: RimoriCommunicationHandler, info: RimoriInfo);
|
|
15
|
+
/**
|
|
16
|
+
* Query a database table.
|
|
17
|
+
* Global tables (starting with 'global_') remain in public schema.
|
|
18
|
+
* Plugin tables use the schema provided by rimori-main (plugins or plugins_alpha).
|
|
19
|
+
* @param relation The table name (without prefix for plugin tables, with 'global_' for global tables).
|
|
20
|
+
* @returns A Postgrest query builder for the table.
|
|
21
|
+
*/
|
|
22
|
+
from<ViewName extends string & keyof GenericSchema['Views'], View extends GenericSchema['Views'][ViewName]>(relation: string): PostgrestQueryBuilder<PostgrestClientOptions, GenericSchema, GenericTable, ViewName, View>;
|
|
23
|
+
/**
|
|
24
|
+
* Get the table name for a given plugin table.
|
|
25
|
+
* Internally all tables are prefixed with the plugin id. This function is used to get the correct table name for a given public table.
|
|
26
|
+
* @param table The plugin table name to get the full table name for.
|
|
27
|
+
* @returns The full table name.
|
|
28
|
+
*/
|
|
29
|
+
getTableName(table: string): string;
|
|
30
|
+
}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Database module for plugin database operations.
|
|
3
|
+
* Provides access to plugin tables with automatic prefixing and schema management.
|
|
4
|
+
*/
|
|
5
|
+
export class DbModule {
|
|
6
|
+
constructor(supabase, communicationHandler, info) {
|
|
7
|
+
this.supabase = supabase;
|
|
8
|
+
this.rimoriInfo = info;
|
|
9
|
+
this.tablePrefix = info.tablePrefix;
|
|
10
|
+
this.schema = info.dbSchema;
|
|
11
|
+
communicationHandler.onUpdate((updatedInfo) => {
|
|
12
|
+
this.rimoriInfo = updatedInfo;
|
|
13
|
+
this.tablePrefix = updatedInfo.tablePrefix;
|
|
14
|
+
this.schema = updatedInfo.dbSchema;
|
|
15
|
+
});
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* Query a database table.
|
|
19
|
+
* Global tables (starting with 'global_') remain in public schema.
|
|
20
|
+
* Plugin tables use the schema provided by rimori-main (plugins or plugins_alpha).
|
|
21
|
+
* @param relation The table name (without prefix for plugin tables, with 'global_' for global tables).
|
|
22
|
+
* @returns A Postgrest query builder for the table.
|
|
23
|
+
*/
|
|
24
|
+
from(relation) {
|
|
25
|
+
const tableName = this.getTableName(relation);
|
|
26
|
+
// Use the schema determined by rimori-main based on release channel
|
|
27
|
+
// Global tables (starting with 'global_') remain in public schema
|
|
28
|
+
// Plugin tables use the schema provided by rimori-main (plugins or plugins_alpha)
|
|
29
|
+
if (relation.startsWith('global_')) {
|
|
30
|
+
// Global tables stay in public schema
|
|
31
|
+
return this.supabase.from(tableName);
|
|
32
|
+
}
|
|
33
|
+
// Plugin tables go to the schema provided by rimori-main
|
|
34
|
+
return this.supabase.schema(this.rimoriInfo.dbSchema).from(tableName);
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Get the table name for a given plugin table.
|
|
38
|
+
* Internally all tables are prefixed with the plugin id. This function is used to get the correct table name for a given public table.
|
|
39
|
+
* @param table The plugin table name to get the full table name for.
|
|
40
|
+
* @returns The full table name.
|
|
41
|
+
*/
|
|
42
|
+
getTableName(table) {
|
|
43
|
+
if (/[A-Z]/.test(table)) {
|
|
44
|
+
throw new Error('Table name cannot include uppercase letters. Please use snake_case for table names.');
|
|
45
|
+
}
|
|
46
|
+
if (table.startsWith('global_')) {
|
|
47
|
+
return table.replace('global_', '');
|
|
48
|
+
}
|
|
49
|
+
return this.tablePrefix + '_' + table;
|
|
50
|
+
}
|
|
51
|
+
}
|