@rimori/client 2.4.0-next.6 → 2.4.0-next.7
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/package.json +5 -1
- package/.github/workflows/create-release-branch.yml +0 -226
- package/.github/workflows/pre-release.yml +0 -126
- package/.github/workflows/release-on-merge.yml +0 -195
- 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 -191
- 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 -176
- 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/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 -291
- package/src/plugin/Logger.ts +0 -394
- package/src/plugin/RimoriClient.ts +0 -199
- package/src/plugin/StandaloneClient.ts +0 -127
- package/src/plugin/module/AIModule.ts +0 -77
- package/src/plugin/module/DbModule.ts +0 -67
- package/src/plugin/module/EventModule.ts +0 -192
- package/src/plugin/module/ExerciseModule.ts +0 -131
- package/src/plugin/module/PluginModule.ts +0 -114
- 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
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
export async function getSTTResponse(backendUrl: string, audio: Blob, token: string): Promise<string> {
|
|
2
|
-
const formData = new FormData();
|
|
3
|
-
formData.append('file', audio);
|
|
4
|
-
|
|
5
|
-
return await fetch(`${backendUrl}/voice/stt`, {
|
|
6
|
-
method: 'POST',
|
|
7
|
-
headers: { Authorization: `Bearer ${token}` },
|
|
8
|
-
body: formData,
|
|
9
|
-
})
|
|
10
|
-
.then((r) => r.json())
|
|
11
|
-
.then((r) => {
|
|
12
|
-
// console.log("STT response: ", r);
|
|
13
|
-
return r.text;
|
|
14
|
-
});
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
export async function getTTSResponse(backendUrl: string, request: TTSRequest, token: string): Promise<Blob> {
|
|
18
|
-
return await fetch(`${backendUrl}/voice/tts`, {
|
|
19
|
-
method: 'POST',
|
|
20
|
-
headers: {
|
|
21
|
-
'Content-Type': 'application/json',
|
|
22
|
-
Authorization: `Bearer ${token}`,
|
|
23
|
-
},
|
|
24
|
-
body: JSON.stringify(request),
|
|
25
|
-
}).then((r) => r.blob());
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
interface TTSRequest {
|
|
29
|
-
input: string;
|
|
30
|
-
voice: string;
|
|
31
|
-
speed: number;
|
|
32
|
-
language?: string;
|
|
33
|
-
}
|
|
@@ -1,382 +0,0 @@
|
|
|
1
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
2
|
-
export type EventPayload = Record<string, any>;
|
|
3
|
-
|
|
4
|
-
/**
|
|
5
|
-
* Interface representing a message sent through the EventBus
|
|
6
|
-
*
|
|
7
|
-
* Debug capabilities:
|
|
8
|
-
* - System-wide debugging: Send an event to "global.system.requestDebug"
|
|
9
|
-
* Example: `EventBus.emit("yourPluginId", "global.system.requestDebug");`
|
|
10
|
-
*/
|
|
11
|
-
export interface EventBusMessage<T = EventPayload> {
|
|
12
|
-
//timestamp of the event
|
|
13
|
-
timestamp: string;
|
|
14
|
-
//unique ID of the event
|
|
15
|
-
eventId: number;
|
|
16
|
-
//plugin id or "global" for global events
|
|
17
|
-
sender: string;
|
|
18
|
-
//the topic of the event consisting of the plugin id, key area and action e.g. "translator.word.triggerTranslation"
|
|
19
|
-
topic: string;
|
|
20
|
-
//any type of data to be transmitted
|
|
21
|
-
data: T;
|
|
22
|
-
//indicated if the debug mode is active
|
|
23
|
-
debug: boolean;
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
export type EventHandler<T = EventPayload> = (event: EventBusMessage<T>) => void | Promise<void>;
|
|
27
|
-
|
|
28
|
-
interface Listeners<T = EventPayload> {
|
|
29
|
-
id: number;
|
|
30
|
-
handler: EventHandler<T>;
|
|
31
|
-
ignoreSender?: string[];
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
export interface EventListener {
|
|
35
|
-
off: () => void;
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
export class EventBusHandler {
|
|
39
|
-
private listeners: Map<string, Set<Listeners<EventPayload>>> = new Map();
|
|
40
|
-
private responseResolvers: Map<number, (value: EventBusMessage<unknown>) => void> = new Map();
|
|
41
|
-
private static instance: EventBusHandler | null = null;
|
|
42
|
-
private debugEnabled = false;
|
|
43
|
-
private evName = '';
|
|
44
|
-
|
|
45
|
-
private constructor() {
|
|
46
|
-
//private constructor
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
static getInstance(name?: string) {
|
|
50
|
-
if (!EventBusHandler.instance) {
|
|
51
|
-
EventBusHandler.instance = new EventBusHandler();
|
|
52
|
-
|
|
53
|
-
EventBusHandler.instance.on('global.system.requestDebug', () => {
|
|
54
|
-
EventBusHandler.instance!.debugEnabled = true;
|
|
55
|
-
console.log(
|
|
56
|
-
`[${
|
|
57
|
-
EventBusHandler.instance!.evName
|
|
58
|
-
}] Debug mode enabled. Make sure debugging messages are enabled in the browser console.`,
|
|
59
|
-
);
|
|
60
|
-
});
|
|
61
|
-
}
|
|
62
|
-
if (name && EventBusHandler.instance.evName === '') {
|
|
63
|
-
EventBusHandler.instance.evName = name;
|
|
64
|
-
}
|
|
65
|
-
return EventBusHandler.instance;
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
private createEvent(sender: string, topic: string, data: EventPayload, eventId?: number): EventBusMessage {
|
|
69
|
-
const generatedEventId = eventId || Math.floor(Math.random() * 10000000000);
|
|
70
|
-
|
|
71
|
-
return {
|
|
72
|
-
eventId: generatedEventId,
|
|
73
|
-
timestamp: new Date().toISOString(),
|
|
74
|
-
sender,
|
|
75
|
-
topic,
|
|
76
|
-
data,
|
|
77
|
-
debug: this.debugEnabled,
|
|
78
|
-
};
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
/**
|
|
82
|
-
* Emits an event to the event bus. Can be a new event or a response to a request.
|
|
83
|
-
* @param sender - The sender of the event.
|
|
84
|
-
* @param topic - The topic of the event.
|
|
85
|
-
* @param data - The data of the event.
|
|
86
|
-
* @param eventId - The event id of the event.
|
|
87
|
-
*
|
|
88
|
-
* The topic format is: **pluginId.area.action**
|
|
89
|
-
*
|
|
90
|
-
* Example topics:
|
|
91
|
-
* - pl1234.card.requestHard
|
|
92
|
-
* - pl1234.card.requestNew
|
|
93
|
-
* - pl1234.card.requestAll
|
|
94
|
-
* - pl1234.card.create
|
|
95
|
-
* - pl1234.card.update
|
|
96
|
-
* - pl1234.card.delete
|
|
97
|
-
* - pl1234.card.triggerBackup
|
|
98
|
-
*/
|
|
99
|
-
public emit<T = EventPayload>(sender: string, topic: string, data?: T, eventId?: number): void {
|
|
100
|
-
this.emitInternal(sender, topic, data || {}, eventId);
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
private emitInternal(
|
|
104
|
-
sender: string,
|
|
105
|
-
topic: string,
|
|
106
|
-
data: EventPayload,
|
|
107
|
-
eventId?: number,
|
|
108
|
-
skipResponseTrigger = false,
|
|
109
|
-
): void {
|
|
110
|
-
if (!this.validateTopic(topic)) {
|
|
111
|
-
this.logAndThrowError(false, `Invalid topic: ` + topic);
|
|
112
|
-
return;
|
|
113
|
-
}
|
|
114
|
-
|
|
115
|
-
const event = this.createEvent(sender, topic, data, eventId);
|
|
116
|
-
|
|
117
|
-
const handlers = this.getMatchingHandlers(event.topic);
|
|
118
|
-
handlers.forEach((handler) => {
|
|
119
|
-
if (handler.ignoreSender && handler.ignoreSender.includes(sender)) {
|
|
120
|
-
// console.log("ignore event as its in the ignoreSender list", { event, ignoreList: handler.ignoreSender });
|
|
121
|
-
return;
|
|
122
|
-
}
|
|
123
|
-
handler.handler(event);
|
|
124
|
-
});
|
|
125
|
-
this.logIfDebug(`Emitting event to ` + topic, event);
|
|
126
|
-
if (handlers.size === 0) {
|
|
127
|
-
this.logAndThrowError(false, `No handlers found for topic: ` + topic);
|
|
128
|
-
}
|
|
129
|
-
|
|
130
|
-
// If it's a response to a request
|
|
131
|
-
if (eventId && this.responseResolvers.has(eventId) && !skipResponseTrigger) {
|
|
132
|
-
// console.log("[Rimori] Resolving response to request: " + eventId, event.data);
|
|
133
|
-
this.responseResolvers.get(eventId)!(event);
|
|
134
|
-
this.responseResolvers.delete(eventId);
|
|
135
|
-
}
|
|
136
|
-
}
|
|
137
|
-
|
|
138
|
-
/**
|
|
139
|
-
* Subscribes to an event on the event bus.
|
|
140
|
-
* @param topics - The topic of the event.
|
|
141
|
-
* @param handler - The handler to be called when the event is emitted.
|
|
142
|
-
* @param ignoreSender - The senders to ignore.
|
|
143
|
-
* @returns An EventListener object containing an off() method to unsubscribe the listeners.
|
|
144
|
-
*/
|
|
145
|
-
public on<T = EventPayload>(
|
|
146
|
-
topics: string | string[],
|
|
147
|
-
handler: EventHandler<T>,
|
|
148
|
-
ignoreSender: string[] = [],
|
|
149
|
-
): EventListener {
|
|
150
|
-
const ids = this.toArray(topics).map((topic) => {
|
|
151
|
-
this.logIfDebug(`Subscribing to ` + topic, { ignoreSender });
|
|
152
|
-
if (!this.validateTopic(topic)) {
|
|
153
|
-
this.logAndThrowError(true, `Invalid topic: ` + topic);
|
|
154
|
-
}
|
|
155
|
-
|
|
156
|
-
if (!this.listeners.has(topic)) {
|
|
157
|
-
this.listeners.set(topic, new Set());
|
|
158
|
-
}
|
|
159
|
-
const id = Math.floor(Math.random() * 10000000000);
|
|
160
|
-
|
|
161
|
-
// To prevent infinite loops and processing the same eventId multiple times
|
|
162
|
-
const blackListedEventIds: { eventId: number; sender: string }[] = [];
|
|
163
|
-
const eventHandler = (data: EventBusMessage) => {
|
|
164
|
-
if (blackListedEventIds.some((item) => item.eventId === data.eventId && item.sender === data.sender)) {
|
|
165
|
-
// console.log('BLACKLISTED EVENT ID', data.eventId, data);
|
|
166
|
-
return;
|
|
167
|
-
}
|
|
168
|
-
blackListedEventIds.push({
|
|
169
|
-
eventId: data.eventId,
|
|
170
|
-
sender: data.sender,
|
|
171
|
-
});
|
|
172
|
-
if (blackListedEventIds.length > 100) {
|
|
173
|
-
blackListedEventIds.shift();
|
|
174
|
-
}
|
|
175
|
-
return (handler as unknown as EventHandler<EventPayload>)(data);
|
|
176
|
-
};
|
|
177
|
-
|
|
178
|
-
this.listeners.get(topic)!.add({ id, handler: eventHandler, ignoreSender });
|
|
179
|
-
|
|
180
|
-
this.logIfDebug(`Subscribed to ` + topic, {
|
|
181
|
-
listenerId: id,
|
|
182
|
-
ignoreSender,
|
|
183
|
-
});
|
|
184
|
-
|
|
185
|
-
return btoa(JSON.stringify({ topic, id }));
|
|
186
|
-
});
|
|
187
|
-
|
|
188
|
-
return {
|
|
189
|
-
off: () => this.off(ids),
|
|
190
|
-
};
|
|
191
|
-
}
|
|
192
|
-
|
|
193
|
-
/**
|
|
194
|
-
* Subscribes to an event, processes the data and emits a response on the event bus.
|
|
195
|
-
* @param sender - The sender of the event.
|
|
196
|
-
* @param topic - The topic of the event.
|
|
197
|
-
* @param handler - The handler to be called when the event is received. The handler returns the data to be emitted. Can be a static object or a function.
|
|
198
|
-
* @returns An EventListener object containing an off() method to unsubscribe the listeners.
|
|
199
|
-
*/
|
|
200
|
-
public respond(
|
|
201
|
-
sender: string,
|
|
202
|
-
topic: string | string[],
|
|
203
|
-
handler: EventPayload | ((data: EventBusMessage) => EventPayload | Promise<EventPayload>),
|
|
204
|
-
): EventListener {
|
|
205
|
-
const topics = Array.isArray(topic) ? topic : [topic];
|
|
206
|
-
const listeners = topics.map((topic) => {
|
|
207
|
-
const blackListedEventIds: number[] = [];
|
|
208
|
-
//To allow event communication inside the same plugin the sender needs to be ignored but the events still need to be checked for the same event just reaching the subscriber to prevent infinite loops
|
|
209
|
-
const finalIgnoreSender = !topic.startsWith('self.') ? [sender] : [];
|
|
210
|
-
|
|
211
|
-
const listener = this.on(
|
|
212
|
-
topic,
|
|
213
|
-
async (data: EventBusMessage) => {
|
|
214
|
-
if (blackListedEventIds.includes(data.eventId)) {
|
|
215
|
-
// console.log("BLACKLISTED EVENT ID", data.eventId);
|
|
216
|
-
return;
|
|
217
|
-
}
|
|
218
|
-
blackListedEventIds.push(data.eventId);
|
|
219
|
-
if (blackListedEventIds.length > 100) {
|
|
220
|
-
blackListedEventIds.shift();
|
|
221
|
-
}
|
|
222
|
-
const response = typeof handler === 'function' ? await handler(data) : handler;
|
|
223
|
-
this.emit(sender, topic, response, data.eventId);
|
|
224
|
-
},
|
|
225
|
-
finalIgnoreSender,
|
|
226
|
-
);
|
|
227
|
-
|
|
228
|
-
this.logIfDebug(`Added respond listener ` + sender + ' to topic ' + topic, { listener, sender });
|
|
229
|
-
return {
|
|
230
|
-
off: () => listener.off(),
|
|
231
|
-
};
|
|
232
|
-
});
|
|
233
|
-
return {
|
|
234
|
-
off: () => listeners.forEach((listener) => listener.off()),
|
|
235
|
-
};
|
|
236
|
-
}
|
|
237
|
-
|
|
238
|
-
/**
|
|
239
|
-
* Subscribes to an event on the event bus. The handler will be called once and then removed.
|
|
240
|
-
* @param topic - The topic of the event.
|
|
241
|
-
* @param handler - The handler to be called when the event is emitted.
|
|
242
|
-
*/
|
|
243
|
-
public once<T = EventPayload>(topic: string, handler: EventHandler<T>): void {
|
|
244
|
-
if (!this.validateTopic(topic)) {
|
|
245
|
-
this.logAndThrowError(false, `Invalid topic: ` + topic);
|
|
246
|
-
return;
|
|
247
|
-
}
|
|
248
|
-
|
|
249
|
-
let listener: EventListener | undefined = undefined;
|
|
250
|
-
const wrapper = (event: EventBusMessage<T>) => {
|
|
251
|
-
handler(event);
|
|
252
|
-
listener?.off();
|
|
253
|
-
};
|
|
254
|
-
listener = this.on(topic, wrapper);
|
|
255
|
-
|
|
256
|
-
this.logIfDebug(`Added once listener ` + topic, { listener, topic });
|
|
257
|
-
}
|
|
258
|
-
|
|
259
|
-
/**
|
|
260
|
-
* Unsubscribes from an event on the event bus.
|
|
261
|
-
* @param listenerIds - The ids of the listeners to unsubscribe from.
|
|
262
|
-
*/
|
|
263
|
-
private off(listenerIds: string | string[]): void {
|
|
264
|
-
this.toArray(listenerIds).forEach((fullId) => {
|
|
265
|
-
const { topic, id } = JSON.parse(atob(fullId));
|
|
266
|
-
|
|
267
|
-
const listeners = this.listeners.get(topic) || new Set();
|
|
268
|
-
|
|
269
|
-
listeners.forEach((listener) => {
|
|
270
|
-
if (listener.id === Number(id)) {
|
|
271
|
-
listeners.delete(listener);
|
|
272
|
-
this.logIfDebug(`Removed listener ` + fullId, {
|
|
273
|
-
topic,
|
|
274
|
-
listenerId: id,
|
|
275
|
-
});
|
|
276
|
-
}
|
|
277
|
-
});
|
|
278
|
-
});
|
|
279
|
-
}
|
|
280
|
-
|
|
281
|
-
private toArray(item: string | string[]): string[] {
|
|
282
|
-
return Array.isArray(item) ? item : [item];
|
|
283
|
-
}
|
|
284
|
-
|
|
285
|
-
/**
|
|
286
|
-
* Requests data from the event bus.
|
|
287
|
-
* @param sender - The sender of the event.
|
|
288
|
-
* @param topic - The topic of the event.
|
|
289
|
-
* @param data - The data of the event.
|
|
290
|
-
* @returns A promise that resolves to the event.
|
|
291
|
-
*/
|
|
292
|
-
public async request<T = EventPayload>(
|
|
293
|
-
sender: string,
|
|
294
|
-
topic: string,
|
|
295
|
-
data?: EventPayload,
|
|
296
|
-
): Promise<EventBusMessage<T>> {
|
|
297
|
-
if (!this.validateTopic(topic)) {
|
|
298
|
-
this.logAndThrowError(true, `Invalid topic: ` + topic);
|
|
299
|
-
}
|
|
300
|
-
|
|
301
|
-
const event = this.createEvent(sender, topic, data || {});
|
|
302
|
-
|
|
303
|
-
this.logIfDebug(`Requesting data from ` + topic, { event });
|
|
304
|
-
|
|
305
|
-
return new Promise<EventBusMessage<T>>((resolve) => {
|
|
306
|
-
this.responseResolvers.set(event.eventId, (value: EventBusMessage<unknown>) =>
|
|
307
|
-
resolve(value as EventBusMessage<T>),
|
|
308
|
-
);
|
|
309
|
-
this.emitInternal(sender, topic, data || {}, event.eventId, true);
|
|
310
|
-
});
|
|
311
|
-
}
|
|
312
|
-
|
|
313
|
-
/**
|
|
314
|
-
* Gets the matching handlers for an event.
|
|
315
|
-
* @param topic - The topic of the event.
|
|
316
|
-
* @returns A set of handlers that match the event type.
|
|
317
|
-
*/
|
|
318
|
-
private getMatchingHandlers(topic: string): Set<Listeners<EventPayload>> {
|
|
319
|
-
const exact = this.listeners.get(topic) || new Set();
|
|
320
|
-
|
|
321
|
-
// Find wildcard matches
|
|
322
|
-
const wildcard = [...this.listeners.entries()]
|
|
323
|
-
.filter(([key]) => key.endsWith('*') && topic.startsWith(key.slice(0, -1)))
|
|
324
|
-
.flatMap(([_, handlers]) => [...handlers]);
|
|
325
|
-
return new Set([...exact, ...wildcard]);
|
|
326
|
-
}
|
|
327
|
-
|
|
328
|
-
/**
|
|
329
|
-
* Validates the topic of an event.
|
|
330
|
-
* @param topic - The topic of the event.
|
|
331
|
-
* @returns True if the topic is valid, false otherwise.
|
|
332
|
-
*/
|
|
333
|
-
private validateTopic(topic: string): boolean {
|
|
334
|
-
// Split event type into parts
|
|
335
|
-
const parts = topic.split('.');
|
|
336
|
-
const [plugin, area, action] = parts;
|
|
337
|
-
|
|
338
|
-
if (parts.length !== 3) {
|
|
339
|
-
if (parts.length === 1 && plugin === '*') {
|
|
340
|
-
return true;
|
|
341
|
-
}
|
|
342
|
-
if (parts.length === 2 && plugin !== '*' && area === '*') {
|
|
343
|
-
return true;
|
|
344
|
-
}
|
|
345
|
-
this.logAndThrowError(false, `Event type must have 3 parts separated by dots. Received: ` + topic);
|
|
346
|
-
return false;
|
|
347
|
-
}
|
|
348
|
-
|
|
349
|
-
if (action === '*') {
|
|
350
|
-
return true;
|
|
351
|
-
}
|
|
352
|
-
|
|
353
|
-
// Validate action part
|
|
354
|
-
const validActions = ['request', 'create', 'update', 'delete', 'trigger'];
|
|
355
|
-
|
|
356
|
-
if (validActions.some((a) => action.startsWith(a))) {
|
|
357
|
-
return true;
|
|
358
|
-
}
|
|
359
|
-
|
|
360
|
-
this.logAndThrowError(
|
|
361
|
-
false,
|
|
362
|
-
`Invalid event topic name. The action: ` + action + '. Must be or start with one of: ' + validActions.join(', '),
|
|
363
|
-
);
|
|
364
|
-
return false;
|
|
365
|
-
}
|
|
366
|
-
|
|
367
|
-
private logIfDebug(...args: (string | EventPayload)[]) {
|
|
368
|
-
if (this.debugEnabled) {
|
|
369
|
-
console.debug(`[${this.evName}] ` + args[0], ...args.slice(1));
|
|
370
|
-
}
|
|
371
|
-
}
|
|
372
|
-
|
|
373
|
-
private logAndThrowError(throwError: boolean, ...args: (string | EventPayload)[]) {
|
|
374
|
-
const message = `[${this.evName}] ` + args[0];
|
|
375
|
-
console.error(message, ...args.slice(1));
|
|
376
|
-
if (throwError) {
|
|
377
|
-
throw new Error(message);
|
|
378
|
-
}
|
|
379
|
-
}
|
|
380
|
-
}
|
|
381
|
-
|
|
382
|
-
export const EventBus = EventBusHandler.getInstance();
|
|
@@ -1,214 +0,0 @@
|
|
|
1
|
-
// whole configuration of a plugin (from the database)
|
|
2
|
-
export type Plugin<T extends object = object> = Omit<RimoriPluginConfig<T>, 'context_menu_actions'> & {
|
|
3
|
-
version: string;
|
|
4
|
-
endpoint: string;
|
|
5
|
-
assetEndpoint: string;
|
|
6
|
-
context_menu_actions: MenuEntry[];
|
|
7
|
-
release_channel: 'alpha' | 'beta' | 'stable';
|
|
8
|
-
};
|
|
9
|
-
|
|
10
|
-
export type ActivePlugin = Plugin<{ active?: boolean }>;
|
|
11
|
-
|
|
12
|
-
// browsable page of a plugin
|
|
13
|
-
export interface PluginPage {
|
|
14
|
-
id: string;
|
|
15
|
-
name: string;
|
|
16
|
-
url: string;
|
|
17
|
-
// Whether the page should be shown in the navbar
|
|
18
|
-
show: boolean;
|
|
19
|
-
description: string;
|
|
20
|
-
root:
|
|
21
|
-
| 'vocabulary'
|
|
22
|
-
| 'grammar'
|
|
23
|
-
| 'reading'
|
|
24
|
-
| 'listening'
|
|
25
|
-
| 'watching'
|
|
26
|
-
| 'writing'
|
|
27
|
-
| 'speaking'
|
|
28
|
-
| 'other'
|
|
29
|
-
| 'community';
|
|
30
|
-
// The actions that can be triggered in the plugin
|
|
31
|
-
// The key is the action key. The other entries are additional properties needed when triggering the action
|
|
32
|
-
action?: {
|
|
33
|
-
key: string;
|
|
34
|
-
parameters: ObjectTool;
|
|
35
|
-
};
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
// a sidebar page of a plugin
|
|
39
|
-
export interface SidebarPage {
|
|
40
|
-
// identifier of the page. Used to know which page to trigger when clicking on the sidebar
|
|
41
|
-
id: string;
|
|
42
|
-
// name of the page. Shown in the settings
|
|
43
|
-
name: string;
|
|
44
|
-
// description of the page. Shown in the settings
|
|
45
|
-
description: string;
|
|
46
|
-
// relative or absolute URL or path to the plugin's page
|
|
47
|
-
url: string;
|
|
48
|
-
// relative or absolute URL or path to the plugin's icon image
|
|
49
|
-
icon: string;
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
// context menu entry being configured in the plugin configuration
|
|
53
|
-
export interface MenuEntry {
|
|
54
|
-
// id of the plugin that the menu entry belongs to
|
|
55
|
-
plugin_id: string;
|
|
56
|
-
// identifier of the menu entry action. Used to know which entry to trigger when clicking on the context menu
|
|
57
|
-
action_key: string;
|
|
58
|
-
// text of the menu entry. Shown in the context menu
|
|
59
|
-
text: string;
|
|
60
|
-
// icon of the menu entry. Shown in the context menu
|
|
61
|
-
iconUrl?: string;
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
// an action from the main panel that can be triggered and performs an action in the main panel
|
|
65
|
-
export type MainPanelAction = {
|
|
66
|
-
plugin_id: string;
|
|
67
|
-
action_key: string;
|
|
68
|
-
} & Record<string, string>;
|
|
69
|
-
|
|
70
|
-
// an action from the context menu that can be triggered and performs an action in the sidebar plugin
|
|
71
|
-
export interface ContextMenuAction {
|
|
72
|
-
// selected text when clicking on the context menu
|
|
73
|
-
text: string;
|
|
74
|
-
// id of the plugin that the action belongs to
|
|
75
|
-
plugin_id: string;
|
|
76
|
-
// key of the action. Used to know which action to trigger when clicking on the context menu
|
|
77
|
-
action_key: string;
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
/**
|
|
81
|
-
* Rimori plugin structure representing the complete configuration
|
|
82
|
-
* of a Rimori plugin with all metadata and configuration options.
|
|
83
|
-
*/
|
|
84
|
-
export interface RimoriPluginConfig<T extends object = object> {
|
|
85
|
-
id: string;
|
|
86
|
-
/**
|
|
87
|
-
* Basic information about the plugin including branding and core details.
|
|
88
|
-
*/
|
|
89
|
-
info: {
|
|
90
|
-
/** The display name of the plugin shown to users */
|
|
91
|
-
title: string;
|
|
92
|
-
/** Detailed description introducing the plugin */
|
|
93
|
-
description: string;
|
|
94
|
-
/** relative or absolute URL or path to the plugin's logo/icon image */
|
|
95
|
-
logo: string;
|
|
96
|
-
/** Optional website URL for the plugin's homepage or link to plugins owner for contributions */
|
|
97
|
-
website?: string;
|
|
98
|
-
};
|
|
99
|
-
/**
|
|
100
|
-
* Configuration for different types of pages.
|
|
101
|
-
*/
|
|
102
|
-
pages: {
|
|
103
|
-
/** Optional external URL where the plugin is hosted instead of the default CDN */
|
|
104
|
-
external_hosted_url?: string;
|
|
105
|
-
/** Array of main plugin pages that appear in the application's main navigation (can be disabled using the 'show' flag) */
|
|
106
|
-
main: (PluginPage & T)[];
|
|
107
|
-
/** Array of sidebar pages that appear in the sidebar for quick access (can be disabled using the 'show' flag) */
|
|
108
|
-
sidebar: (SidebarPage & T)[];
|
|
109
|
-
/** Optional path to the plugin's settings/configuration page */
|
|
110
|
-
settings?: string;
|
|
111
|
-
/** Optional array of event topics the plugin pages can listen to for cross-plugin communication */
|
|
112
|
-
topics?: string[];
|
|
113
|
-
};
|
|
114
|
-
/**
|
|
115
|
-
* Context menu actions that the plugin registers to appear in right-click menus throughout the application.
|
|
116
|
-
*/
|
|
117
|
-
context_menu_actions: Omit<MenuEntry, 'plugin_id'>[];
|
|
118
|
-
/**
|
|
119
|
-
* Documentation paths for different types of plugin documentation.
|
|
120
|
-
*/
|
|
121
|
-
documentation: {
|
|
122
|
-
/** Path to the general overview documentation. It's shown upon installation of the plugin. */
|
|
123
|
-
overview_path: string;
|
|
124
|
-
/** Path to user-facing documentation and guides */
|
|
125
|
-
user_path: string;
|
|
126
|
-
/** Path to developer documentation for plugin development */
|
|
127
|
-
developer_path: string;
|
|
128
|
-
};
|
|
129
|
-
/**
|
|
130
|
-
* Configuration for the plugin's web worker if it uses background processing or exposes actions to other plugins.
|
|
131
|
-
*/
|
|
132
|
-
worker?: {
|
|
133
|
-
/** Relative path to the web worker JavaScript file. Mostly it's 'web-worker.js' which is located in the public folder. */
|
|
134
|
-
url: string;
|
|
135
|
-
/** Optional array of event topics the worker should listen to in addition to events having the pluginId in the topic. Can be a wildcard. Example: 'global.topic.*' or 'pluginId.*' */
|
|
136
|
-
topics?: string[];
|
|
137
|
-
};
|
|
138
|
-
}
|
|
139
|
-
|
|
140
|
-
// copied from llm edge function
|
|
141
|
-
|
|
142
|
-
export interface Tool {
|
|
143
|
-
name: string;
|
|
144
|
-
description: string;
|
|
145
|
-
parameters: {
|
|
146
|
-
name: string;
|
|
147
|
-
description: string;
|
|
148
|
-
type: 'string' | 'number' | 'boolean';
|
|
149
|
-
}[];
|
|
150
|
-
execute?: (args: Record<string, any>) => Promise<unknown> | unknown | void;
|
|
151
|
-
}
|
|
152
|
-
|
|
153
|
-
/**
|
|
154
|
-
* The tool definition structure is used for LLM function calling and plugin action parameters.
|
|
155
|
-
* It defines the schema for tools that can be used by Language Learning Models (LLMs)
|
|
156
|
-
* and plugin actions.
|
|
157
|
-
*
|
|
158
|
-
* @example
|
|
159
|
-
* ```typescript
|
|
160
|
-
* const flashcardTool: Tool = {
|
|
161
|
-
* total_amount: {
|
|
162
|
-
* type: 'string',
|
|
163
|
-
* enum: ['default', '10', '20', '50'],
|
|
164
|
-
* description: 'Number of flashcards to practice'
|
|
165
|
-
* },
|
|
166
|
-
* deck: {
|
|
167
|
-
* type: 'string',
|
|
168
|
-
* enum: ['latest', 'random', 'oldest', 'mix', 'best_known'],
|
|
169
|
-
* description: 'Type of deck to practice'
|
|
170
|
-
* }
|
|
171
|
-
* };
|
|
172
|
-
* ```
|
|
173
|
-
*
|
|
174
|
-
*/
|
|
175
|
-
export type ObjectTool = {
|
|
176
|
-
[key: string]: ToolParameter;
|
|
177
|
-
};
|
|
178
|
-
|
|
179
|
-
/**
|
|
180
|
-
* Parameter definition for LLM tools and plugin actions.
|
|
181
|
-
* Defines the structure, validation rules, and metadata for individual tool parameters.
|
|
182
|
-
* Used to create type-safe interfaces between LLMs, plugins, and the Rimori platform.
|
|
183
|
-
*/
|
|
184
|
-
interface ToolParameter {
|
|
185
|
-
/** The data type of the parameter - can be primitive, nested object, or array */
|
|
186
|
-
type: ToolParameterType;
|
|
187
|
-
/** Human-readable description of the parameter's purpose and usage */
|
|
188
|
-
description: string;
|
|
189
|
-
/** Optional array of allowed values for enumerated parameters */
|
|
190
|
-
enum?: string[];
|
|
191
|
-
/** Whether the parameter is optional */
|
|
192
|
-
optional?: boolean;
|
|
193
|
-
}
|
|
194
|
-
|
|
195
|
-
/**
|
|
196
|
-
* Union type defining all possible parameter types for LLM tools.
|
|
197
|
-
* Supports primitive types, nested objects for complex data structures,
|
|
198
|
-
* and arrays of objects for collections. The tuple notation [{}] indicates
|
|
199
|
-
* arrays of objects with a specific structure.
|
|
200
|
-
*
|
|
201
|
-
* @example Primitive: 'string' | 'number' | 'boolean'
|
|
202
|
-
* @example Nested object: { name: { type: 'string' }, age: { type: 'number' } }
|
|
203
|
-
* @example Array of objects: [{ id: { type: 'string' }, value: { type: 'number' } }]
|
|
204
|
-
*/
|
|
205
|
-
type ToolParameterType =
|
|
206
|
-
| PrimitiveType
|
|
207
|
-
| { [key: string]: ToolParameter } // for nested objects
|
|
208
|
-
| [{ [key: string]: ToolParameter }]; // for arrays of objects (notice the tuple type)
|
|
209
|
-
|
|
210
|
-
/**
|
|
211
|
-
* Primitive data types supported by the LLM tool system.
|
|
212
|
-
* These align with JSON schema primitive types and TypeScript basic types.
|
|
213
|
-
*/
|
|
214
|
-
type PrimitiveType = 'string' | 'number' | 'boolean';
|
package/src/fromRimori/readme.md
DELETED
package/src/index.ts
DELETED
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
// Re-export everything
|
|
2
|
-
export * from './plugin/CommunicationHandler';
|
|
3
|
-
export * from './cli/types/DatabaseTypes';
|
|
4
|
-
export * from './utils/difficultyConverter';
|
|
5
|
-
export * from './fromRimori/PluginTypes';
|
|
6
|
-
export * from './fromRimori/EventBus';
|
|
7
|
-
export * from './plugin/RimoriClient';
|
|
8
|
-
export * from './plugin/StandaloneClient';
|
|
9
|
-
export { setupWorker } from './worker/WorkerSetup';
|
|
10
|
-
export { AudioController } from './controller/AudioController';
|
|
11
|
-
export { Translator } from './controller/TranslationController';
|
|
12
|
-
export type { TOptions } from 'i18next';
|
|
13
|
-
export type { SharedContent, SharedContentObjectRequest } from './controller/SharedContentController';
|
|
14
|
-
export type { Exercise } from './plugin/module/ExerciseModule';
|
|
15
|
-
export type { UserInfo, Language, UserRole } from './controller/SettingsController';
|
|
16
|
-
export type { Message, ToolInvocation } from './controller/AIController';
|
|
17
|
-
export type { TriggerAction } from './plugin/module/ExerciseModule';
|
|
18
|
-
export type { MacroAccomplishmentPayload, MicroAccomplishmentPayload } from './controller/AccomplishmentController';
|
|
19
|
-
export type { EventBusMessage } from './fromRimori/EventBus';
|