@rimori/client 1.1.10 → 1.3.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 +189 -63
- package/dist/cli/scripts/init/dev-registration.d.ts +35 -0
- package/dist/cli/scripts/init/dev-registration.js +174 -0
- package/dist/cli/scripts/init/env-setup.d.ts +9 -0
- package/dist/cli/scripts/init/env-setup.js +43 -0
- package/dist/cli/scripts/init/file-operations.d.ts +4 -0
- package/dist/cli/scripts/init/file-operations.js +51 -0
- package/dist/cli/scripts/init/html-cleaner.d.ts +4 -0
- package/dist/cli/scripts/init/html-cleaner.js +38 -0
- package/dist/cli/scripts/init/main.d.ts +2 -0
- package/dist/cli/scripts/init/main.js +160 -0
- package/dist/cli/scripts/init/package-setup.d.ts +32 -0
- package/dist/cli/scripts/init/package-setup.js +75 -0
- package/dist/cli/scripts/init/router-transformer.d.ts +6 -0
- package/dist/cli/scripts/init/router-transformer.js +254 -0
- package/dist/cli/scripts/init/tailwind-config.d.ts +4 -0
- package/dist/cli/scripts/init/tailwind-config.js +56 -0
- package/dist/cli/scripts/init/vite-config.d.ts +20 -0
- package/dist/cli/scripts/init/vite-config.js +54 -0
- package/dist/cli/scripts/release/release-config-upload.d.ts +7 -0
- package/dist/cli/scripts/release/release-config-upload.js +116 -0
- package/dist/cli/scripts/release/release-db-update.d.ts +6 -0
- package/dist/cli/scripts/release/release-db-update.js +100 -0
- package/dist/cli/scripts/release/release-file-upload.d.ts +6 -0
- package/dist/cli/scripts/release/release-file-upload.js +136 -0
- package/dist/cli/scripts/release/release.d.ts +23 -0
- package/dist/cli/scripts/release/release.js +70 -0
- package/dist/cli/types/DatabaseTypes.d.ts +103 -0
- package/dist/cli/types/DatabaseTypes.js +2 -0
- package/dist/components/LoggerExample.d.ts +6 -0
- package/dist/components/LoggerExample.js +79 -0
- package/dist/components/ai/Assistant.js +5 -5
- package/dist/components/ai/Avatar.d.ts +3 -2
- package/dist/components/ai/Avatar.js +11 -6
- package/dist/components/ai/EmbeddedAssistent/CircleAudioAvatar.js +1 -1
- package/dist/components/ai/EmbeddedAssistent/VoiceRecoder.d.ts +1 -0
- package/dist/components/ai/EmbeddedAssistent/VoiceRecoder.js +48 -33
- package/dist/components/ai/utils.js +0 -1
- package/dist/components/audio/Playbutton.js +4 -4
- package/dist/{core → components}/components/ContextMenu.js +50 -11
- package/dist/components.d.ts +5 -5
- package/dist/components.js +5 -5
- package/dist/core/controller/AIController.d.ts +15 -0
- package/dist/core/controller/AIController.js +253 -0
- package/dist/core/controller/AudioController.d.ts +0 -0
- package/dist/core/controller/AudioController.js +1 -0
- package/dist/{controller → core/controller}/ObjectController.d.ts +10 -2
- package/dist/{controller → core/controller}/ObjectController.js +8 -8
- package/dist/{controller → core/controller}/SettingsController.d.ts +28 -4
- package/dist/{controller → core/controller}/SettingsController.js +0 -25
- package/dist/{controller → core/controller}/SharedContentController.d.ts +31 -3
- package/dist/{controller → core/controller}/SharedContentController.js +77 -26
- package/dist/core/controller/VoiceController.d.ts +9 -0
- package/dist/{controller → core/controller}/VoiceController.js +11 -4
- package/dist/core/core.d.ts +14 -0
- package/dist/core/core.js +8 -0
- package/dist/{plugin/fromRimori → fromRimori}/EventBus.d.ts +3 -3
- package/dist/{plugin/fromRimori → fromRimori}/EventBus.js +26 -9
- package/dist/fromRimori/PluginTypes.d.ts +174 -0
- package/dist/hooks/UseChatHook.d.ts +2 -1
- package/dist/hooks/UseChatHook.js +6 -4
- package/dist/hooks/UseLogger.d.ts +30 -0
- package/dist/hooks/UseLogger.js +122 -0
- package/dist/index.d.ts +6 -3
- package/dist/index.js +5 -3
- package/dist/plugin/AccomplishmentHandler.d.ts +1 -1
- package/dist/plugin/AccomplishmentHandler.js +1 -1
- package/dist/plugin/AudioController.d.ts +37 -0
- package/dist/plugin/AudioController.js +68 -0
- package/dist/plugin/Logger.d.ts +68 -0
- package/dist/plugin/Logger.js +256 -0
- package/dist/plugin/LoggerExample.d.ts +16 -0
- package/dist/plugin/LoggerExample.js +140 -0
- package/dist/plugin/PluginController.d.ts +30 -5
- package/dist/plugin/PluginController.js +182 -53
- package/dist/plugin/RimoriClient.d.ts +68 -21
- package/dist/plugin/RimoriClient.js +88 -41
- package/dist/plugin/StandaloneClient.d.ts +1 -0
- package/dist/plugin/StandaloneClient.js +24 -10
- package/dist/plugin/ThemeSetter.d.ts +2 -1
- package/dist/plugin/ThemeSetter.js +13 -7
- package/dist/providers/PluginProvider.d.ts +4 -1
- package/dist/providers/PluginProvider.js +39 -13
- package/dist/utils/Language.d.ts +2 -1
- package/dist/utils/Language.js +4 -2
- package/dist/utils/audioFormats.d.ts +26 -0
- package/dist/utils/audioFormats.js +67 -0
- package/dist/utils/difficultyConverter.js +1 -1
- package/dist/utils/endpoint.d.ts +2 -0
- package/dist/utils/endpoint.js +2 -0
- package/dist/worker/WorkerSetup.d.ts +3 -2
- package/dist/worker/WorkerSetup.js +22 -65
- package/example/docs/devdocs.md +231 -0
- package/example/docs/overview.md +29 -0
- package/example/docs/userdocs.md +123 -0
- package/example/rimori.config.ts +89 -0
- package/example/worker/vite.config.ts +23 -0
- package/example/worker/worker.ts +11 -0
- package/package.json +16 -9
- package/src/cli/scripts/init/dev-registration.ts +192 -0
- package/src/cli/scripts/init/env-setup.ts +44 -0
- package/src/cli/scripts/init/file-operations.ts +58 -0
- package/src/cli/scripts/init/html-cleaner.ts +48 -0
- package/src/cli/scripts/init/main.ts +172 -0
- package/src/cli/scripts/init/package-setup.ts +117 -0
- package/src/cli/scripts/init/router-transformer.ts +329 -0
- package/src/cli/scripts/init/tailwind-config.ts +75 -0
- package/src/cli/scripts/init/vite-config.ts +73 -0
- package/src/cli/scripts/release/release-config-upload.ts +114 -0
- package/src/cli/scripts/release/release-db-update.ts +97 -0
- package/src/cli/scripts/release/release-file-upload.ts +138 -0
- package/src/cli/scripts/release/release.ts +69 -0
- package/src/cli/types/DatabaseTypes.ts +117 -0
- package/src/components/ai/Assistant.tsx +5 -5
- package/src/components/ai/Avatar.tsx +25 -8
- package/src/components/ai/EmbeddedAssistent/CircleAudioAvatar.tsx +1 -1
- package/src/components/ai/EmbeddedAssistent/VoiceRecoder.tsx +50 -35
- package/src/components/ai/utils.ts +0 -2
- package/src/components/audio/Playbutton.tsx +4 -4
- package/src/{core → components}/components/ContextMenu.tsx +56 -12
- package/src/components.ts +6 -6
- package/src/core/controller/AIController.ts +283 -0
- package/src/core/controller/ObjectController.ts +115 -0
- package/src/{controller → core/controller}/SettingsController.ts +29 -29
- package/src/{controller → core/controller}/SharedContentController.ts +91 -29
- package/src/core/controller/VoiceController.ts +31 -0
- package/src/core/core.ts +16 -0
- package/src/{plugin/fromRimori → fromRimori}/EventBus.ts +29 -11
- package/src/fromRimori/PluginTypes.ts +205 -0
- package/src/hooks/UseChatHook.ts +8 -5
- package/src/index.ts +6 -3
- package/src/plugin/AccomplishmentHandler.ts +1 -1
- package/src/plugin/AudioController.ts +58 -0
- package/src/plugin/Logger.ts +324 -0
- package/src/plugin/PluginController.ts +203 -63
- package/src/plugin/RimoriClient.ts +127 -55
- package/src/plugin/StandaloneClient.ts +30 -11
- package/src/plugin/ThemeSetter.ts +16 -9
- package/src/providers/PluginProvider.tsx +46 -13
- package/src/utils/Language.ts +4 -2
- package/src/utils/difficultyConverter.ts +3 -3
- package/src/utils/endpoint.ts +2 -0
- package/src/worker/WorkerSetup.ts +13 -60
- package/dist/components/PluginController.d.ts +0 -21
- package/dist/components/PluginController.js +0 -116
- package/dist/controller/AIController.d.ts +0 -23
- package/dist/controller/AIController.js +0 -93
- package/dist/controller/SidePluginController.d.ts +0 -3
- package/dist/controller/SidePluginController.js +0 -31
- package/dist/controller/VoiceController.d.ts +0 -10
- package/dist/core.d.ts +0 -7
- package/dist/core.js +0 -7
- package/dist/plugin/ContextMenu.d.ts +0 -17
- package/dist/plugin/ContextMenu.js +0 -45
- package/dist/plugin/fromRimori/PluginTypes.d.ts +0 -48
- package/dist/plugin/fromRimori/SupabaseHandler.d.ts +0 -13
- package/dist/plugin/fromRimori/SupabaseHandler.js +0 -55
- package/dist/providers/PluginController.d.ts +0 -21
- package/dist/providers/PluginController.js +0 -116
- package/dist/types/Actions.d.ts +0 -4
- package/dist/types/Actions.js +0 -1
- package/src/controller/AIController.ts +0 -112
- package/src/controller/ObjectController.ts +0 -107
- package/src/controller/SidePluginController.ts +0 -25
- package/src/controller/VoiceController.ts +0 -26
- package/src/core.ts +0 -8
- package/src/plugin/fromRimori/PluginTypes.ts +0 -64
- package/src/types/Actions.ts +0 -6
- /package/dist/{core → components}/components/ContextMenu.d.ts +0 -0
- /package/dist/{plugin/fromRimori → fromRimori}/PluginTypes.js +0 -0
- /package/src/{plugin/fromRimori → fromRimori}/readme.md +0 -0
|
@@ -8,41 +8,106 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
8
8
|
});
|
|
9
9
|
};
|
|
10
10
|
import { createClient } from '@supabase/supabase-js';
|
|
11
|
-
import { EventBus } from '
|
|
11
|
+
import { EventBus } from '../fromRimori/EventBus';
|
|
12
12
|
import { RimoriClient } from "./RimoriClient";
|
|
13
|
-
import { setTheme } from './ThemeSetter';
|
|
14
13
|
import { StandaloneClient } from './StandaloneClient';
|
|
14
|
+
import { setTheme } from './ThemeSetter';
|
|
15
|
+
import { Logger } from './Logger';
|
|
15
16
|
export class PluginController {
|
|
16
17
|
constructor(pluginId, standalone) {
|
|
17
|
-
this.
|
|
18
|
+
this.port = null;
|
|
19
|
+
this.queryParams = {};
|
|
18
20
|
this.supabase = null;
|
|
19
|
-
this.
|
|
21
|
+
this.rimoriInfo = null;
|
|
22
|
+
this.isMessageChannelReady = false;
|
|
23
|
+
this.pendingRequests = [];
|
|
20
24
|
this.pluginId = pluginId;
|
|
21
25
|
this.getClient = this.getClient.bind(this);
|
|
22
26
|
if (typeof WorkerGlobalScope === 'undefined') {
|
|
23
|
-
|
|
27
|
+
// In standalone mode, use URL fallback. In iframe mode, theme will be set after MessageChannel init
|
|
28
|
+
if (standalone) {
|
|
29
|
+
setTheme();
|
|
30
|
+
}
|
|
24
31
|
}
|
|
25
|
-
//no need to forward messages to parent in standalone mode
|
|
32
|
+
//no need to forward messages to parent in standalone mode or worker context
|
|
26
33
|
if (standalone)
|
|
27
34
|
return;
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
EventBus.on("*", (event) => {
|
|
38
|
-
// skip messages which are not from the own plugin
|
|
39
|
-
if (event.sender !== this.pluginId)
|
|
40
|
-
return;
|
|
41
|
-
if (event.topic.startsWith("self."))
|
|
35
|
+
this.initMessageChannel(typeof WorkerGlobalScope !== 'undefined');
|
|
36
|
+
}
|
|
37
|
+
initMessageChannel(worker = false) {
|
|
38
|
+
const listener = (event) => {
|
|
39
|
+
console.log("[PluginController] window message", { origin: event.origin, data: event.data });
|
|
40
|
+
const { type, pluginId, queryParams, rimoriInfo } = event.data || {};
|
|
41
|
+
const [transferredPort] = event.ports || [];
|
|
42
|
+
if (type !== "rimori:init" || !transferredPort || pluginId !== this.pluginId) {
|
|
43
|
+
console.log("[PluginController] message ignored (not init or wrong plugin)", { type, pluginId, hasPort: !!transferredPort });
|
|
42
44
|
return;
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
45
|
+
}
|
|
46
|
+
this.queryParams = queryParams || {};
|
|
47
|
+
this.port = transferredPort;
|
|
48
|
+
// Initialize Supabase client immediately with provided info
|
|
49
|
+
if (rimoriInfo) {
|
|
50
|
+
this.rimoriInfo = rimoriInfo;
|
|
51
|
+
this.supabase = createClient(rimoriInfo.url, rimoriInfo.key, {
|
|
52
|
+
accessToken: () => Promise.resolve(rimoriInfo.token)
|
|
53
|
+
});
|
|
54
|
+
}
|
|
55
|
+
// Handle messages from parent
|
|
56
|
+
this.port.onmessage = ({ data }) => {
|
|
57
|
+
const { event, type, eventId, response, error } = data || {};
|
|
58
|
+
// no idea why this is needed but it works for now
|
|
59
|
+
if (type === 'response' && eventId) {
|
|
60
|
+
EventBus.emit(this.pluginId, response.topic, response.data, eventId);
|
|
61
|
+
}
|
|
62
|
+
else if (type === 'error' && eventId) {
|
|
63
|
+
EventBus.emit(this.pluginId, 'error', { error }, eventId);
|
|
64
|
+
}
|
|
65
|
+
else if (event) {
|
|
66
|
+
const { topic, sender, data: eventData, eventId } = event;
|
|
67
|
+
if (sender !== this.pluginId) {
|
|
68
|
+
EventBus.emit(sender, topic, eventData, eventId);
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
};
|
|
72
|
+
// Set theme from MessageChannel query params
|
|
73
|
+
if (!worker) {
|
|
74
|
+
const theme = this.queryParams['rm_theme'];
|
|
75
|
+
setTheme(theme);
|
|
76
|
+
}
|
|
77
|
+
// Forward plugin events to parent (only after MessageChannel is ready)
|
|
78
|
+
EventBus.on("*", (ev) => {
|
|
79
|
+
var _a;
|
|
80
|
+
if (ev.sender === this.pluginId && !ev.topic.startsWith("self.")) {
|
|
81
|
+
(_a = this.port) === null || _a === void 0 ? void 0 : _a.postMessage({ event: ev });
|
|
82
|
+
}
|
|
83
|
+
});
|
|
84
|
+
// Mark MessageChannel as ready and process pending requests
|
|
85
|
+
this.isMessageChannelReady = true;
|
|
86
|
+
// Process any pending requests
|
|
87
|
+
this.pendingRequests.forEach(request => request());
|
|
88
|
+
this.pendingRequests = [];
|
|
89
|
+
};
|
|
90
|
+
if (worker) {
|
|
91
|
+
self.onmessage = listener;
|
|
92
|
+
}
|
|
93
|
+
else {
|
|
94
|
+
window.addEventListener("message", listener);
|
|
95
|
+
}
|
|
96
|
+
this.sendHello(worker);
|
|
97
|
+
}
|
|
98
|
+
sendHello(isWorker = false) {
|
|
99
|
+
try {
|
|
100
|
+
const payload = { type: "rimori:hello", pluginId: this.pluginId };
|
|
101
|
+
if (isWorker) {
|
|
102
|
+
self.postMessage(payload);
|
|
103
|
+
}
|
|
104
|
+
else {
|
|
105
|
+
window.parent.postMessage(payload, "*");
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
catch (e) {
|
|
109
|
+
console.error("[PluginController] Error sending hello:", e);
|
|
110
|
+
}
|
|
46
111
|
}
|
|
47
112
|
static getInstance(pluginId_1) {
|
|
48
113
|
return __awaiter(this, arguments, void 0, function* (pluginId, standalone = false) {
|
|
@@ -52,54 +117,118 @@ export class PluginController {
|
|
|
52
117
|
}
|
|
53
118
|
PluginController.instance = new PluginController(pluginId, standalone);
|
|
54
119
|
PluginController.client = yield RimoriClient.getInstance(PluginController.instance);
|
|
120
|
+
//only init logger in workers and on main plugin pages
|
|
121
|
+
if (PluginController.instance.getQueryParam("applicationMode") !== "sidebar") {
|
|
122
|
+
Logger.getInstance(PluginController.client);
|
|
123
|
+
}
|
|
55
124
|
}
|
|
56
125
|
return PluginController.client;
|
|
57
126
|
});
|
|
58
127
|
}
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
const secret = new URLSearchParams(window.location.search).get("secret");
|
|
62
|
-
if (!secret) {
|
|
63
|
-
console.info("Communication secret not found in URL as query parameter");
|
|
64
|
-
}
|
|
65
|
-
this.communicationSecret = secret;
|
|
66
|
-
}
|
|
67
|
-
return this.communicationSecret;
|
|
128
|
+
getQueryParam(key) {
|
|
129
|
+
return this.queryParams[key] || null;
|
|
68
130
|
}
|
|
69
131
|
getClient() {
|
|
70
132
|
return __awaiter(this, void 0, void 0, function* () {
|
|
71
|
-
if
|
|
72
|
-
|
|
73
|
-
this.
|
|
74
|
-
return { supabase: this.supabase, tablePrefix: this.supabaseInfo.tablePrefix, pluginId: this.supabaseInfo.pluginId };
|
|
133
|
+
// Return cached client if valid
|
|
134
|
+
if (this.supabase && this.rimoriInfo && this.rimoriInfo.expiration > new Date()) {
|
|
135
|
+
return { supabase: this.supabase, info: this.rimoriInfo };
|
|
75
136
|
}
|
|
76
|
-
|
|
77
|
-
this.
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
137
|
+
// If MessageChannel is not ready yet, queue the request
|
|
138
|
+
if (!this.isMessageChannelReady) {
|
|
139
|
+
return new Promise((resolve) => {
|
|
140
|
+
this.pendingRequests.push(() => __awaiter(this, void 0, void 0, function* () {
|
|
141
|
+
const result = yield this.getClient();
|
|
142
|
+
resolve(result);
|
|
143
|
+
}));
|
|
144
|
+
});
|
|
145
|
+
}
|
|
146
|
+
// If we have rimoriInfo from MessageChannel init, use it directly
|
|
147
|
+
if (this.rimoriInfo && this.supabase) {
|
|
148
|
+
return { supabase: this.supabase, info: this.rimoriInfo };
|
|
149
|
+
}
|
|
150
|
+
// Fallback: request from parent
|
|
151
|
+
if (!this.rimoriInfo) {
|
|
152
|
+
if (typeof WorkerGlobalScope !== 'undefined') {
|
|
153
|
+
// In worker context, send request via self.postMessage to WorkerHandler
|
|
154
|
+
const eventId = Math.floor(Math.random() * 1000000000);
|
|
155
|
+
const requestEvent = {
|
|
156
|
+
event: {
|
|
157
|
+
timestamp: new Date().toISOString(),
|
|
158
|
+
eventId,
|
|
159
|
+
sender: this.pluginId,
|
|
160
|
+
topic: 'global.supabase.requestAccess',
|
|
161
|
+
data: {},
|
|
162
|
+
debug: false
|
|
163
|
+
}
|
|
164
|
+
};
|
|
165
|
+
return new Promise((resolve) => {
|
|
166
|
+
// Listen for the response
|
|
167
|
+
const originalOnMessage = self.onmessage;
|
|
168
|
+
self.onmessage = (event) => {
|
|
169
|
+
var _a, _b;
|
|
170
|
+
if (((_a = event.data) === null || _a === void 0 ? void 0 : _a.topic) === 'global.supabase.requestAccess' && ((_b = event.data) === null || _b === void 0 ? void 0 : _b.eventId) === eventId) {
|
|
171
|
+
this.rimoriInfo = event.data.data;
|
|
172
|
+
this.supabase = createClient(this.rimoriInfo.url, this.rimoriInfo.key, {
|
|
173
|
+
accessToken: () => Promise.resolve(this.getToken())
|
|
174
|
+
});
|
|
175
|
+
self.onmessage = originalOnMessage; // Restore original handler
|
|
176
|
+
resolve({ supabase: this.supabase, info: this.rimoriInfo });
|
|
177
|
+
}
|
|
178
|
+
else if (originalOnMessage) {
|
|
179
|
+
originalOnMessage.call(self, event);
|
|
180
|
+
}
|
|
181
|
+
};
|
|
182
|
+
// Send the request
|
|
183
|
+
self.postMessage(requestEvent);
|
|
184
|
+
});
|
|
185
|
+
}
|
|
186
|
+
else {
|
|
187
|
+
// In main thread context, use EventBus
|
|
188
|
+
const { data } = yield EventBus.request(this.pluginId, "global.supabase.requestAccess");
|
|
189
|
+
this.rimoriInfo = data;
|
|
190
|
+
this.supabase = createClient(this.rimoriInfo.url, this.rimoriInfo.key, {
|
|
191
|
+
accessToken: () => Promise.resolve(this.getToken())
|
|
192
|
+
});
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
return { supabase: this.supabase, info: this.rimoriInfo };
|
|
82
196
|
});
|
|
83
197
|
}
|
|
84
198
|
getToken() {
|
|
85
199
|
return __awaiter(this, void 0, void 0, function* () {
|
|
86
|
-
if (this.
|
|
87
|
-
return this.
|
|
200
|
+
if (this.rimoriInfo && this.rimoriInfo.expiration && this.rimoriInfo.expiration > new Date()) {
|
|
201
|
+
return this.rimoriInfo.token;
|
|
88
202
|
}
|
|
89
|
-
|
|
90
|
-
if (!this.
|
|
91
|
-
|
|
203
|
+
// If we don't have rimoriInfo, request it
|
|
204
|
+
if (!this.rimoriInfo) {
|
|
205
|
+
const { data } = yield EventBus.request(this.pluginId, "global.supabase.requestAccess");
|
|
206
|
+
this.rimoriInfo = data;
|
|
207
|
+
return this.rimoriInfo.token;
|
|
92
208
|
}
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
209
|
+
// If token is expired, request fresh access
|
|
210
|
+
const { data } = yield EventBus.request(this.pluginId, "global.supabase.requestAccess");
|
|
211
|
+
this.rimoriInfo.token = data.token;
|
|
212
|
+
this.rimoriInfo.expiration = data.expiration;
|
|
213
|
+
return this.rimoriInfo.token;
|
|
96
214
|
});
|
|
97
215
|
}
|
|
216
|
+
/**
|
|
217
|
+
* Gets the Supabase URL.
|
|
218
|
+
* @returns The Supabase URL.
|
|
219
|
+
* @deprecated All endpoints should use the backend URL instead.
|
|
220
|
+
*/
|
|
98
221
|
getSupabaseUrl() {
|
|
99
|
-
if (!this.
|
|
222
|
+
if (!this.rimoriInfo) {
|
|
100
223
|
throw new Error("Supabase info not found");
|
|
101
224
|
}
|
|
102
|
-
return this.
|
|
225
|
+
return this.rimoriInfo.url;
|
|
226
|
+
}
|
|
227
|
+
getBackendUrl() {
|
|
228
|
+
if (!this.rimoriInfo) {
|
|
229
|
+
throw new Error("Rimori info not found");
|
|
230
|
+
}
|
|
231
|
+
return this.rimoriInfo.backendUrl;
|
|
103
232
|
}
|
|
104
233
|
getGlobalEventTopic(preliminaryTopic) {
|
|
105
234
|
var _a, _b;
|
|
@@ -119,7 +248,7 @@ export class PluginController {
|
|
|
119
248
|
else if (topicParts.length > 3) {
|
|
120
249
|
throw new Error(`The event topic must consist of 3 parts. <pluginId>.<topic area>.<action>. Received: ${preliminaryTopic}`);
|
|
121
250
|
}
|
|
122
|
-
const topicRoot = (_b = (_a = this.
|
|
251
|
+
const topicRoot = (_b = (_a = this.rimoriInfo) === null || _a === void 0 ? void 0 : _a.pluginId) !== null && _b !== void 0 ? _b : "global";
|
|
123
252
|
return `${topicRoot}.${preliminaryTopic}`;
|
|
124
253
|
}
|
|
125
254
|
}
|
|
@@ -1,20 +1,18 @@
|
|
|
1
1
|
import { PostgrestQueryBuilder } from "@supabase/postgrest-js";
|
|
2
|
-
import { SupabaseClient } from "@supabase/supabase-js";
|
|
3
2
|
import { GenericSchema } from "@supabase/supabase-js/dist/module/lib/types";
|
|
4
|
-
import { Message, OnLLMResponse
|
|
5
|
-
import { ObjectRequest } from "../controller/ObjectController";
|
|
6
|
-
import { UserInfo } from "../controller/SettingsController";
|
|
7
|
-
import { SharedContent, SharedContentFilter, SharedContentObjectRequest } from "../controller/SharedContentController";
|
|
3
|
+
import { Message, OnLLMResponse } from "../core/controller/AIController";
|
|
4
|
+
import { ObjectRequest } from "../core/controller/ObjectController";
|
|
5
|
+
import { UserInfo } from "../core/controller/SettingsController";
|
|
6
|
+
import { SharedContent, SharedContentFilter, SharedContentObjectRequest } from "../core/controller/SharedContentController";
|
|
7
|
+
import { EventBusMessage, EventHandler, EventPayload } from "../fromRimori/EventBus";
|
|
8
|
+
import { ActivePlugin, MainPanelAction, Plugin, Tool } from "../fromRimori/PluginTypes";
|
|
8
9
|
import { AccomplishmentPayload } from "./AccomplishmentHandler";
|
|
9
|
-
import { EventBusMessage, EventHandler, EventPayload } from "./fromRimori/EventBus";
|
|
10
|
-
import { Plugin } from "./fromRimori/PluginTypes";
|
|
11
10
|
import { PluginController } from "./PluginController";
|
|
12
11
|
interface Db {
|
|
13
12
|
from: {
|
|
14
13
|
<TableName extends string & keyof GenericSchema['Tables'], Table extends GenericSchema['Tables'][TableName]>(relation: TableName): PostgrestQueryBuilder<GenericSchema, Table, TableName>;
|
|
15
14
|
<ViewName extends string & keyof GenericSchema['Views'], View extends GenericSchema['Views'][ViewName]>(relation: ViewName): PostgrestQueryBuilder<GenericSchema, View, ViewName>;
|
|
16
15
|
};
|
|
17
|
-
storage: SupabaseClient["storage"];
|
|
18
16
|
/**
|
|
19
17
|
* The table prefix for of database tables of the plugin.
|
|
20
18
|
*/
|
|
@@ -38,11 +36,26 @@ interface PluginInterface {
|
|
|
38
36
|
*/
|
|
39
37
|
getSettings: <T extends object>(defaultSettings: T) => Promise<T>;
|
|
40
38
|
/**
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
39
|
+
* Retrieves information about plugins, including:
|
|
40
|
+
* - All installed plugins
|
|
41
|
+
* - The currently active plugin in the main panel
|
|
42
|
+
* - The currently active plugin in the side panel
|
|
43
|
+
*/
|
|
44
|
+
getPluginInfo: () => {
|
|
45
|
+
/**
|
|
46
|
+
* All installed plugins.
|
|
47
|
+
*/
|
|
48
|
+
installedPlugins: Plugin[];
|
|
49
|
+
/**
|
|
50
|
+
* The plugin that is loaded in the main panel.
|
|
51
|
+
*/
|
|
52
|
+
mainPanelPlugin?: ActivePlugin;
|
|
53
|
+
/**
|
|
54
|
+
* The plugin that is loaded in the side panel.
|
|
55
|
+
*/
|
|
56
|
+
sidePanelPlugin?: ActivePlugin;
|
|
57
|
+
};
|
|
58
|
+
getUserInfo: () => UserInfo;
|
|
46
59
|
}
|
|
47
60
|
export declare class RimoriClient {
|
|
48
61
|
private static instance;
|
|
@@ -51,9 +64,9 @@ export declare class RimoriClient {
|
|
|
51
64
|
private settingsController;
|
|
52
65
|
private sharedContentController;
|
|
53
66
|
private accomplishmentHandler;
|
|
54
|
-
private
|
|
55
|
-
db: Db;
|
|
67
|
+
private rimoriInfo;
|
|
56
68
|
plugin: PluginInterface;
|
|
69
|
+
db: Db;
|
|
57
70
|
private constructor();
|
|
58
71
|
event: {
|
|
59
72
|
/**
|
|
@@ -78,9 +91,9 @@ export declare class RimoriClient {
|
|
|
78
91
|
* Subscribe to an event.
|
|
79
92
|
* @param topic The topic to subscribe to.
|
|
80
93
|
* @param callback The callback to call when the event is emitted.
|
|
81
|
-
* @returns
|
|
94
|
+
* @returns An EventListener object containing an off() method to unsubscribe the listeners.
|
|
82
95
|
*/
|
|
83
|
-
on: <T = EventPayload>(topic: string | string[], callback: EventHandler<T>) => import("
|
|
96
|
+
on: <T = EventPayload>(topic: string | string[], callback: EventHandler<T>) => import("../fromRimori/EventBus").EventListener;
|
|
84
97
|
/**
|
|
85
98
|
* Subscribe to an event once.
|
|
86
99
|
* @param topic The topic to subscribe to.
|
|
@@ -92,7 +105,7 @@ export declare class RimoriClient {
|
|
|
92
105
|
* @param topic The topic to respond to.
|
|
93
106
|
* @param data The data to respond with.
|
|
94
107
|
*/
|
|
95
|
-
respond: <T = EventPayload>(topic: string, data: EventPayload | ((data: EventBusMessage<T>) => EventPayload | Promise<EventPayload>)) => void;
|
|
108
|
+
respond: <T = EventPayload>(topic: string | string[], data: EventPayload | ((data: EventBusMessage<T>) => EventPayload | Promise<EventPayload>)) => void;
|
|
96
109
|
/**
|
|
97
110
|
* Emit an accomplishment.
|
|
98
111
|
* @param payload The payload to emit.
|
|
@@ -111,17 +124,30 @@ export declare class RimoriClient {
|
|
|
111
124
|
* @param text Optional text to be used for the action like for example text that the translator would look up.
|
|
112
125
|
*/
|
|
113
126
|
emitSidebarAction: (pluginId: string, actionKey: string, text?: string) => void;
|
|
127
|
+
onMainPanelAction: (callback: (data: MainPanelAction) => void) => void;
|
|
114
128
|
};
|
|
129
|
+
navigation: {
|
|
130
|
+
toDashboard: () => void;
|
|
131
|
+
};
|
|
132
|
+
/**
|
|
133
|
+
* Get a query parameter value that was passed via MessageChannel
|
|
134
|
+
* @param key The query parameter key
|
|
135
|
+
* @returns The query parameter value or null if not found
|
|
136
|
+
*/
|
|
137
|
+
getQueryParam(key: string): string | null;
|
|
115
138
|
static getInstance(pluginController: PluginController): Promise<RimoriClient>;
|
|
116
139
|
private from;
|
|
117
140
|
private getTableName;
|
|
118
|
-
|
|
141
|
+
ai: {
|
|
119
142
|
getText: (messages: Message[], tools?: Tool[]) => Promise<string>;
|
|
120
143
|
getSteamedText: (messages: Message[], onMessage: OnLLMResponse, tools?: Tool[]) => Promise<void>;
|
|
121
144
|
getVoice: (text: string, voice?: string, speed?: number, language?: string) => Promise<Blob>;
|
|
122
145
|
getTextFromVoice: (file: Blob) => Promise<string>;
|
|
123
146
|
getObject: (request: ObjectRequest) => Promise<any>;
|
|
124
147
|
};
|
|
148
|
+
runtime: {
|
|
149
|
+
fetchBackend: (url: string, options: RequestInit) => Promise<Response>;
|
|
150
|
+
};
|
|
125
151
|
community: {
|
|
126
152
|
/**
|
|
127
153
|
* Shared content is a way to share completable content with other users using this plugin.
|
|
@@ -149,10 +175,19 @@ export declare class RimoriClient {
|
|
|
149
175
|
* @param contentType The type of shared content to fetch. E.g. assignments, exercises, etc.
|
|
150
176
|
* @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.
|
|
151
177
|
* @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.
|
|
152
|
-
* @param
|
|
178
|
+
* @param options An optional object with options for the new shared content.
|
|
179
|
+
* @param options.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.
|
|
180
|
+
* @param options.skipDbSave An optional flag to indicate if the new shared content should not be saved to the database. This is useful if the new shared content is not meant to be saved to the database.
|
|
181
|
+
* @param options.alwaysGenerateNew An optional flag to indicate if the new shared content should always be generated even if there is already a content with the same filter. This is useful if the new shared content is not meant to be saved to the database.
|
|
182
|
+
* @param options.excludeIds An optional list of ids to exclude from the selection. This is useful if the new shared content is not meant to be saved to the database.
|
|
153
183
|
* @returns The new shared content.
|
|
154
184
|
*/
|
|
155
|
-
getNew: <T = any>(contentType: string, generatorInstructions: SharedContentObjectRequest, filter?: SharedContentFilter,
|
|
185
|
+
getNew: <T = any>(contentType: string, generatorInstructions: SharedContentObjectRequest, filter?: SharedContentFilter, options?: {
|
|
186
|
+
privateTopic?: boolean;
|
|
187
|
+
skipDbSave?: boolean;
|
|
188
|
+
alwaysGenerateNew?: boolean;
|
|
189
|
+
excludeIds?: string[];
|
|
190
|
+
}) => Promise<SharedContent<T>>;
|
|
156
191
|
/**
|
|
157
192
|
* Create a new shared content item.
|
|
158
193
|
* @param content The content to create.
|
|
@@ -172,6 +207,18 @@ export declare class RimoriClient {
|
|
|
172
207
|
* @param assignmentId The id of the shared content item to complete.
|
|
173
208
|
*/
|
|
174
209
|
complete: (contentType: string, assignmentId: string) => Promise<void>;
|
|
210
|
+
/**
|
|
211
|
+
/**
|
|
212
|
+
* Update the state of a shared content item for a specific user.
|
|
213
|
+
* Useful for marking content as completed, ongoing, hidden, liked, disliked, or bookmarked.
|
|
214
|
+
*/
|
|
215
|
+
updateState: (params: {
|
|
216
|
+
contentType: string;
|
|
217
|
+
id: string;
|
|
218
|
+
state?: "completed" | "ongoing" | "hidden";
|
|
219
|
+
reaction?: "liked" | "disliked" | null;
|
|
220
|
+
bookmarked?: boolean;
|
|
221
|
+
}) => Promise<void>;
|
|
175
222
|
/**
|
|
176
223
|
* Remove a shared content item.
|
|
177
224
|
* @param id The id of the shared content item to remove.
|