@rimori/client 1.0.3 → 1.0.5
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 +51 -0
- package/dist/components/CRUDModal.js +0 -1
- package/dist/components/ai/Assistant.d.ts +9 -0
- package/dist/components/ai/Assistant.js +59 -0
- package/dist/components/ai/Avatar.d.ts +11 -0
- package/dist/components/ai/Avatar.js +39 -0
- package/dist/components/ai/EmbeddedAssistent/AudioInputField.d.ts +7 -0
- package/dist/components/ai/EmbeddedAssistent/AudioInputField.js +38 -0
- package/dist/components/ai/EmbeddedAssistent/CircleAudioAvatar.d.ts +7 -0
- package/dist/components/ai/EmbeddedAssistent/CircleAudioAvatar.js +59 -0
- package/dist/components/ai/EmbeddedAssistent/TTS/MessageSender.d.ts +19 -0
- package/dist/components/ai/EmbeddedAssistent/TTS/MessageSender.js +86 -0
- package/dist/components/ai/EmbeddedAssistent/TTS/Player.d.ts +25 -0
- package/dist/components/ai/EmbeddedAssistent/TTS/Player.js +180 -0
- package/dist/components/ai/EmbeddedAssistent/VoiceRecoder.d.ts +7 -0
- package/dist/components/ai/EmbeddedAssistent/VoiceRecoder.js +45 -0
- package/dist/components/ai/utils.d.ts +6 -0
- package/dist/components/ai/utils.js +14 -0
- package/dist/components/audio/Playbutton.js +4 -5
- package/dist/components/avatar/Assistant.d.ts +9 -0
- package/dist/components/avatar/Assistant.js +59 -0
- package/dist/components/avatar/Avatar.d.ts +12 -0
- package/dist/components/avatar/Avatar.js +42 -0
- package/dist/components/avatar/EmbeddedAssistent/AudioInputField.d.ts +7 -0
- package/dist/components/avatar/EmbeddedAssistent/AudioInputField.js +38 -0
- package/dist/components/avatar/EmbeddedAssistent/CircleAudioAvatar.d.ts +7 -0
- package/dist/components/avatar/EmbeddedAssistent/CircleAudioAvatar.js +59 -0
- package/dist/components/avatar/EmbeddedAssistent/TTS/MessageSender.d.ts +19 -0
- package/dist/components/avatar/EmbeddedAssistent/TTS/MessageSender.js +84 -0
- package/dist/components/avatar/EmbeddedAssistent/TTS/Player.d.ts +25 -0
- package/dist/components/avatar/EmbeddedAssistent/TTS/Player.js +180 -0
- package/dist/components/avatar/EmbeddedAssistent/VoiceRecoder.d.ts +7 -0
- package/dist/components/avatar/EmbeddedAssistent/VoiceRecoder.js +45 -0
- package/dist/components/avatar/utils.d.ts +6 -0
- package/dist/components/avatar/utils.js +14 -0
- package/dist/components.d.ts +9 -0
- package/dist/components.js +10 -0
- package/dist/controller/AIController.d.ts +4 -3
- package/dist/controller/AIController.js +32 -8
- package/dist/controller/ObjectController.d.ts +2 -2
- package/dist/controller/ObjectController.js +4 -5
- package/dist/controller/SettingsController.d.ts +19 -10
- package/dist/controller/SettingsController.js +33 -26
- package/dist/controller/SharedContentController.js +6 -6
- package/dist/core.d.ts +9 -0
- package/dist/core.js +10 -0
- package/dist/hooks/UseChatHook.js +2 -2
- package/dist/index.d.ts +3 -2
- package/dist/index.js +4 -2
- package/dist/plugin/PluginController.d.ts +4 -12
- package/dist/plugin/PluginController.js +45 -70
- package/dist/plugin/RimoriClient.d.ts +85 -32
- package/dist/plugin/RimoriClient.js +98 -77
- package/dist/plugin/ThemeSetter.js +3 -3
- package/dist/plugin/fromRimori/EventBus.d.ts +98 -0
- package/dist/plugin/fromRimori/EventBus.js +240 -0
- package/dist/providers/PluginProvider.d.ts +1 -0
- package/dist/providers/PluginProvider.js +10 -12
- package/dist/worker/WorkerSetup.d.ts +6 -0
- package/dist/worker/WorkerSetup.js +80 -0
- package/package.json +17 -3
- package/src/components/CRUDModal.tsx +1 -3
- package/src/components/ai/Assistant.tsx +96 -0
- package/src/components/ai/Avatar.tsx +61 -0
- package/src/components/ai/EmbeddedAssistent/AudioInputField.tsx +64 -0
- package/src/components/ai/EmbeddedAssistent/CircleAudioAvatar.tsx +75 -0
- package/src/components/ai/EmbeddedAssistent/TTS/MessageSender.ts +91 -0
- package/src/components/ai/EmbeddedAssistent/TTS/Player.ts +192 -0
- package/src/components/ai/EmbeddedAssistent/VoiceRecoder.tsx +56 -0
- package/src/components/ai/utils.ts +23 -0
- package/src/components/audio/Playbutton.tsx +4 -5
- package/src/components.ts +10 -0
- package/src/controller/AIController.ts +84 -60
- package/src/controller/ObjectController.ts +4 -6
- package/src/controller/SettingsController.ts +49 -35
- package/src/controller/SharedContentController.ts +6 -6
- package/src/core.ts +10 -0
- package/src/hooks/UseChatHook.ts +2 -2
- package/src/index.ts +4 -2
- package/src/plugin/PluginController.ts +51 -76
- package/src/plugin/RimoriClient.ts +147 -85
- package/src/plugin/ThemeSetter.ts +3 -4
- package/src/plugin/fromRimori/EventBus.ts +301 -0
- package/src/plugin/fromRimori/readme.md +2 -0
- package/src/providers/PluginProvider.tsx +12 -14
- package/src/worker/WorkerSetup.ts +81 -0
- package/dist/CRUDModal.d.ts +0 -16
- package/dist/CRUDModal.js +0 -31
- package/dist/MarkdownEditor.d.ts +0 -8
- package/dist/MarkdownEditor.js +0 -46
- package/dist/audio/Playbutton.d.ts +0 -14
- package/dist/audio/Playbutton.js +0 -73
- package/dist/components/hooks/UseChatHook.d.ts +0 -15
- package/dist/components/hooks/UseChatHook.js +0 -21
- package/dist/controller/PluginController.d.ts +0 -14
- package/dist/controller/PluginController.js +0 -30
- package/dist/plugin/AIController copy.d.ts +0 -22
- package/dist/plugin/AIController copy.js +0 -68
- package/dist/plugin/AIController.d.ts +0 -22
- package/dist/plugin/AIController.js +0 -68
- package/dist/plugin/ObjectController.d.ts +0 -34
- package/dist/plugin/ObjectController.js +0 -77
- package/dist/plugin/SettingController.d.ts +0 -13
- package/dist/plugin/SettingController.js +0 -55
- package/dist/plugin/VoiceController.d.ts +0 -2
- package/dist/plugin/VoiceController.js +0 -27
- package/dist/providers/EventEmitter.d.ts +0 -11
- package/dist/providers/EventEmitter.js +0 -41
- package/dist/providers/EventEmitterContext.d.ts +0 -6
- package/dist/providers/EventEmitterContext.js +0 -19
- package/dist/utils/DifficultyConverter.d.ts +0 -3
- package/dist/utils/DifficultyConverter.js +0 -7
- package/dist/utils/constants.d.ts +0 -4
- package/dist/utils/constants.js +0 -12
- package/dist/utils/plugin/Client.d.ts +0 -72
- package/dist/utils/plugin/Client.js +0 -118
- package/dist/utils/plugin/PluginController.d.ts +0 -36
- package/dist/utils/plugin/PluginController.js +0 -119
- package/dist/utils/plugin/PluginUtils.d.ts +0 -2
- package/dist/utils/plugin/PluginUtils.js +0 -23
- package/dist/utils/plugin/RimoriClient.d.ts +0 -72
- package/dist/utils/plugin/RimoriClient.js +0 -118
- package/dist/utils/plugin/ThemeSetter.d.ts +0 -1
- package/dist/utils/plugin/ThemeSetter.js +0 -13
- package/dist/utils/plugin/WhereClauseBuilder.d.ts +0 -24
- package/dist/utils/plugin/WhereClauseBuilder.js +0 -79
- package/dist/utils/plugin/providers/EventEmitter.d.ts +0 -11
- package/dist/utils/plugin/providers/EventEmitter.js +0 -41
- package/dist/utils/plugin/providers/EventEmitterContext.d.ts +0 -6
- package/dist/utils/plugin/providers/EventEmitterContext.js +0 -19
- package/dist/utils/plugin/providers/PluginProvider.d.ts +0 -8
- package/dist/utils/plugin/providers/PluginProvider.js +0 -49
- package/src/providers/EventEmitter.ts +0 -48
- package/src/providers/EventEmitterContext.tsx +0 -27
- package/src/utils/constants.ts +0 -18
|
@@ -7,54 +7,46 @@ 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 { Child } from "ibridge-flex";
|
|
11
10
|
import { createClient } from '@supabase/supabase-js';
|
|
12
11
|
import { RimoriClient } from "./RimoriClient";
|
|
12
|
+
import { EventBus } from './fromRimori/EventBus';
|
|
13
|
+
import { setTheme } from './ThemeSetter';
|
|
13
14
|
export class PluginController {
|
|
14
|
-
constructor() {
|
|
15
|
-
this.onceListeners = new Map();
|
|
16
|
-
this.listeners = new Map();
|
|
15
|
+
constructor(pluginId) {
|
|
17
16
|
this.communicationSecret = null;
|
|
18
|
-
this.initialized = false;
|
|
19
17
|
this.supabase = null;
|
|
20
18
|
this.supabaseInfo = null;
|
|
21
|
-
|
|
22
|
-
this.plugin = new Child({
|
|
23
|
-
triggerChild: ({ topic, data, _id }) => {
|
|
24
|
-
var _a, _b;
|
|
25
|
-
// console.log("trigger child with topic:" + topic + " and data: ", data);
|
|
26
|
-
(_a = this.onceListeners.get(topic)) === null || _a === void 0 ? void 0 : _a.forEach((callback) => callback(_id, data));
|
|
27
|
-
this.onceListeners.set(topic, []);
|
|
28
|
-
(_b = this.listeners.get(topic)) === null || _b === void 0 ? void 0 : _b.forEach((callback) => callback(_id, data));
|
|
29
|
-
}
|
|
30
|
-
});
|
|
31
|
-
this.emit = this.emit.bind(this);
|
|
32
|
-
this.onOnce = this.onOnce.bind(this);
|
|
19
|
+
this.pluginId = pluginId;
|
|
33
20
|
this.getClient = this.getClient.bind(this);
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
21
|
+
if (typeof WorkerGlobalScope === 'undefined') {
|
|
22
|
+
setTheme();
|
|
23
|
+
}
|
|
24
|
+
window.addEventListener("message", (event) => {
|
|
25
|
+
// console.log("client: message received", event);
|
|
26
|
+
const { topic, sender, data, eventId } = event.data.event;
|
|
27
|
+
// skip forwarding messages from own plugin
|
|
28
|
+
if (sender === pluginId)
|
|
29
|
+
return;
|
|
30
|
+
EventBus.emit(sender, topic, data, eventId);
|
|
31
|
+
});
|
|
32
|
+
EventBus.on("*", (event) => {
|
|
33
|
+
// skip messages which are not from the own plugin
|
|
34
|
+
if (event.sender !== this.pluginId)
|
|
35
|
+
return;
|
|
36
|
+
if (event.topic.startsWith("self."))
|
|
37
|
+
return;
|
|
38
|
+
window.parent.postMessage({ event, secret: this.getSecret() }, "*");
|
|
39
|
+
});
|
|
37
40
|
}
|
|
38
|
-
static getInstance() {
|
|
41
|
+
static getInstance(sender) {
|
|
39
42
|
return __awaiter(this, void 0, void 0, function* () {
|
|
40
43
|
if (!PluginController.instance) {
|
|
41
|
-
PluginController.instance = new PluginController();
|
|
42
|
-
yield PluginController.instance.init();
|
|
44
|
+
PluginController.instance = new PluginController(sender);
|
|
43
45
|
PluginController.client = yield RimoriClient.getInstance(PluginController.instance);
|
|
44
46
|
}
|
|
45
47
|
return PluginController.client;
|
|
46
48
|
});
|
|
47
49
|
}
|
|
48
|
-
init() {
|
|
49
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
50
|
-
if (this.initialized)
|
|
51
|
-
return;
|
|
52
|
-
// Wait for the plugin to be ready
|
|
53
|
-
yield this.plugin.handshake().then(() => this.initialized = true).catch((error) => {
|
|
54
|
-
console.error("Failed to initialize the plugin communication:", error);
|
|
55
|
-
});
|
|
56
|
-
});
|
|
57
|
-
}
|
|
58
50
|
getSecret() {
|
|
59
51
|
if (!this.communicationSecret) {
|
|
60
52
|
const secret = new URLSearchParams(window.location.search).get("secret");
|
|
@@ -72,7 +64,8 @@ export class PluginController {
|
|
|
72
64
|
this.supabaseInfo.expiration > new Date()) {
|
|
73
65
|
return { supabase: this.supabase, tablePrefix: this.supabaseInfo.tablePrefix, pluginId: this.supabaseInfo.pluginId };
|
|
74
66
|
}
|
|
75
|
-
|
|
67
|
+
const { data } = yield EventBus.request(this.pluginId, "global.supabase.requestAccess");
|
|
68
|
+
this.supabaseInfo = data;
|
|
76
69
|
this.supabase = createClient(this.supabaseInfo.url, this.supabaseInfo.key, {
|
|
77
70
|
accessToken: () => Promise.resolve(this.getToken())
|
|
78
71
|
});
|
|
@@ -84,12 +77,12 @@ export class PluginController {
|
|
|
84
77
|
if (this.supabaseInfo && this.supabaseInfo.expiration && this.supabaseInfo.expiration > new Date()) {
|
|
85
78
|
return this.supabaseInfo.token;
|
|
86
79
|
}
|
|
87
|
-
const
|
|
80
|
+
const { data } = yield EventBus.request(this.pluginId, "global.supabase.requestAccess");
|
|
88
81
|
if (!this.supabaseInfo) {
|
|
89
82
|
throw new Error("Supabase info not found");
|
|
90
83
|
}
|
|
91
|
-
this.supabaseInfo.token =
|
|
92
|
-
this.supabaseInfo.expiration =
|
|
84
|
+
this.supabaseInfo.token = data.token;
|
|
85
|
+
this.supabaseInfo.expiration = data.expiration;
|
|
93
86
|
return this.supabaseInfo.token;
|
|
94
87
|
});
|
|
95
88
|
}
|
|
@@ -99,40 +92,22 @@ export class PluginController {
|
|
|
99
92
|
}
|
|
100
93
|
return this.supabaseInfo.url;
|
|
101
94
|
}
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
internalEmit(eventName, id, data) {
|
|
107
|
-
this.init().then(() => this.plugin.emitToParent(eventName, { data, _id: id, secret: this.getSecret() }));
|
|
108
|
-
}
|
|
109
|
-
subscribe(eventName, callback) {
|
|
110
|
-
var _a;
|
|
111
|
-
if (!this.listeners.has(eventName)) {
|
|
112
|
-
this.listeners.set(eventName, []);
|
|
95
|
+
getGlobalEventTopic(preliminaryTopic) {
|
|
96
|
+
var _a, _b, _c;
|
|
97
|
+
if (preliminaryTopic.startsWith("global.")) {
|
|
98
|
+
return preliminaryTopic;
|
|
113
99
|
}
|
|
114
|
-
(
|
|
115
|
-
|
|
116
|
-
onOnce(eventName, callback) {
|
|
117
|
-
var _a;
|
|
118
|
-
if (!this.onceListeners.has(eventName)) {
|
|
119
|
-
this.onceListeners.set(eventName, []);
|
|
100
|
+
if (preliminaryTopic.startsWith("self.")) {
|
|
101
|
+
return preliminaryTopic;
|
|
120
102
|
}
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
if (triggered || (_id !== id && _id !== 0))
|
|
131
|
-
return;
|
|
132
|
-
triggered = true;
|
|
133
|
-
resolve(data);
|
|
134
|
-
});
|
|
135
|
-
});
|
|
136
|
-
});
|
|
103
|
+
const topicParts = preliminaryTopic.split(".");
|
|
104
|
+
if (topicParts.length === 3) {
|
|
105
|
+
if (![(_a = this.supabaseInfo) === null || _a === void 0 ? void 0 : _a.pluginId, "global"].includes(topicParts[0])) {
|
|
106
|
+
throw new Error("The event topic must start with the plugin id or 'global'.");
|
|
107
|
+
}
|
|
108
|
+
return preliminaryTopic;
|
|
109
|
+
}
|
|
110
|
+
const topicRoot = (_c = (_b = this.supabaseInfo) === null || _b === void 0 ? void 0 : _b.pluginId) !== null && _c !== void 0 ? _c : "global";
|
|
111
|
+
return `${topicRoot}.${preliminaryTopic}`;
|
|
137
112
|
}
|
|
138
113
|
}
|
|
@@ -1,25 +1,95 @@
|
|
|
1
1
|
import { PluginController } from "./PluginController";
|
|
2
2
|
import { SupabaseClient } from "@supabase/supabase-js";
|
|
3
|
+
import { EventBusMessage, EventPayload } from "./fromRimori/EventBus";
|
|
3
4
|
import { GenericSchema } from "@supabase/supabase-js/dist/module/lib/types";
|
|
4
5
|
import { PostgrestQueryBuilder, PostgrestFilterBuilder } from "@supabase/postgrest-js";
|
|
5
6
|
import { BasicAssignment } from "../controller/SharedContentController";
|
|
6
7
|
import { Message, Tool, OnLLMResponse } from "../controller/AIController";
|
|
7
8
|
import { ObjectRequest } from "../controller/ObjectController";
|
|
8
9
|
import { Plugin } from "../controller/SidePluginController";
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
10
|
+
import { UserInfo } from "../controller/SettingsController";
|
|
11
|
+
import { EventHandler } from "./fromRimori/EventBus";
|
|
12
|
+
interface Db {
|
|
13
|
+
from: {
|
|
14
|
+
<TableName extends string & keyof GenericSchema['Tables'], Table extends GenericSchema['Tables'][TableName]>(relation: TableName): PostgrestQueryBuilder<GenericSchema, Table, TableName>;
|
|
15
|
+
<ViewName extends string & keyof GenericSchema['Views'], View extends GenericSchema['Views'][ViewName]>(relation: ViewName): PostgrestQueryBuilder<GenericSchema, View, ViewName>;
|
|
16
|
+
};
|
|
17
|
+
rpc: <Fn extends GenericSchema['Functions'][string], FnName extends string & keyof GenericSchema['Functions']>(functionName: FnName, args?: Fn["Args"], options?: {
|
|
18
|
+
head?: boolean;
|
|
19
|
+
get?: boolean;
|
|
20
|
+
count?: "exact" | "planned" | "estimated";
|
|
21
|
+
}) => PostgrestFilterBuilder<GenericSchema, Fn["Returns"] extends any[] ? Fn["Returns"][number] extends Record<string, unknown> ? Fn["Returns"][number] : never : never, Fn["Returns"], string, null>;
|
|
13
22
|
functions: SupabaseClient["functions"];
|
|
14
23
|
storage: SupabaseClient["storage"];
|
|
24
|
+
}
|
|
25
|
+
interface PluginInterface {
|
|
15
26
|
pluginId: string;
|
|
16
27
|
tablePrefix: string;
|
|
28
|
+
setSettings: (settings: any) => Promise<void>;
|
|
29
|
+
/**
|
|
30
|
+
* Get the settings for the plugin. T can be any type of settings, UserSettings or SystemSettings.
|
|
31
|
+
* @param defaultSettings The default settings to use if no settings are found.
|
|
32
|
+
* @param genericSettings The type of settings to get.
|
|
33
|
+
* @returns The settings for the plugin.
|
|
34
|
+
*/
|
|
35
|
+
getSettings: <T extends object>(defaultSettings: T) => Promise<T>;
|
|
36
|
+
/**
|
|
37
|
+
* Fetches all installed plugins.
|
|
38
|
+
* @returns A promise that resolves to an array of plugins
|
|
39
|
+
*/
|
|
40
|
+
getInstalled: () => Promise<Plugin[]>;
|
|
41
|
+
getUserInfo: () => Promise<UserInfo>;
|
|
42
|
+
}
|
|
43
|
+
export declare class RimoriClient {
|
|
44
|
+
private static instance;
|
|
45
|
+
private superbase;
|
|
46
|
+
private pluginController;
|
|
17
47
|
private settingsController;
|
|
18
48
|
private sharedContentController;
|
|
49
|
+
private supabaseUrl;
|
|
50
|
+
db: Db;
|
|
51
|
+
plugin: PluginInterface;
|
|
19
52
|
private constructor();
|
|
53
|
+
event: {
|
|
54
|
+
/**
|
|
55
|
+
* Emit an event to Rimori or a plugin.
|
|
56
|
+
* The topic schema is:
|
|
57
|
+
* {pluginId}.{eventId}
|
|
58
|
+
* Check out the event bus documentation for more information.
|
|
59
|
+
* For triggering events from Rimori like context menu actions use the "global" keyword.
|
|
60
|
+
* @param topic The topic to emit the event on.
|
|
61
|
+
* @param data The data to emit.
|
|
62
|
+
* @param eventId The event id.
|
|
63
|
+
*/
|
|
64
|
+
emit: (topic: string, data: any, eventId?: number) => void;
|
|
65
|
+
/**
|
|
66
|
+
* Request an event.
|
|
67
|
+
* @param topic The topic to request the event on.
|
|
68
|
+
* @param data The data to request.
|
|
69
|
+
* @returns The response from the event.
|
|
70
|
+
*/
|
|
71
|
+
request: <T>(topic: string, data?: any) => Promise<EventBusMessage<T>>;
|
|
72
|
+
/**
|
|
73
|
+
* Subscribe to an event.
|
|
74
|
+
* @param topic The topic to subscribe to.
|
|
75
|
+
* @param callback The callback to call when the event is emitted.
|
|
76
|
+
*/
|
|
77
|
+
on: <T = EventPayload>(topic: string, callback: EventHandler<T>) => void;
|
|
78
|
+
/**
|
|
79
|
+
* Subscribe to an event once.
|
|
80
|
+
* @param topic The topic to subscribe to.
|
|
81
|
+
* @param callback The callback to call when the event is emitted.
|
|
82
|
+
*/
|
|
83
|
+
once: <T = EventPayload>(topic: string, callback: EventHandler<T>) => void;
|
|
84
|
+
/**
|
|
85
|
+
* Respond to an event.
|
|
86
|
+
* @param topic The topic to respond to.
|
|
87
|
+
* @param data The data to respond with.
|
|
88
|
+
*/
|
|
89
|
+
respond: <T = EventPayload>(topic: string, data: EventPayload | ((data: EventBusMessage<T>) => EventPayload | Promise<EventPayload>)) => void;
|
|
90
|
+
};
|
|
20
91
|
static getInstance(pluginController: PluginController): Promise<RimoriClient>;
|
|
21
|
-
from
|
|
22
|
-
from<ViewName extends string & keyof GenericSchema['Views'], View extends GenericSchema['Views'][ViewName]>(relation: ViewName): PostgrestQueryBuilder<GenericSchema, View, ViewName>;
|
|
92
|
+
private from;
|
|
23
93
|
/**
|
|
24
94
|
* Perform a function call.
|
|
25
95
|
*
|
|
@@ -43,33 +113,15 @@ export declare class RimoriClient {
|
|
|
43
113
|
* `"estimated"`: Uses exact count for low numbers and planned count for high
|
|
44
114
|
* numbers.
|
|
45
115
|
*/
|
|
46
|
-
rpc
|
|
47
|
-
head?: boolean;
|
|
48
|
-
get?: boolean;
|
|
49
|
-
count?: 'exact' | 'planned' | 'estimated';
|
|
50
|
-
}): PostgrestFilterBuilder<GenericSchema, Fn['Returns'] extends any[] ? Fn['Returns'][number] extends Record<string, unknown> ? Fn['Returns'][number] : never : never, Fn['Returns'], string, null>;
|
|
116
|
+
private rpc;
|
|
51
117
|
private getTableName;
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
* @returns The settings for the plugin.
|
|
60
|
-
*/
|
|
61
|
-
getSettings<T extends object>(defaultSettings: T, genericSettings?: "user" | "system"): Promise<T>;
|
|
62
|
-
setSettings(settings: any, genericSettings?: "user" | "system"): Promise<void>;
|
|
63
|
-
getAIResponse(messages: Message[], tools?: Tool[]): Promise<string>;
|
|
64
|
-
getAIResponseStream(messages: Message[], onMessage: OnLLMResponse, tools?: Tool[]): Promise<void>;
|
|
65
|
-
getVoiceResponse(text: string, voice?: string, speed?: number, language?: string): Promise<Blob>;
|
|
66
|
-
getVoiceToTextResponse(file: Blob): Promise<string>;
|
|
67
|
-
/**
|
|
68
|
-
* Fetches all installed plugins.
|
|
69
|
-
* @returns A promise that resolves to an array of plugins
|
|
70
|
-
*/
|
|
71
|
-
getPlugins(): Promise<Plugin[]>;
|
|
72
|
-
generateObject(request: ObjectRequest): Promise<any>;
|
|
118
|
+
llm: {
|
|
119
|
+
getText: (messages: Message[], tools?: Tool[]) => Promise<string>;
|
|
120
|
+
getSteamedText: (messages: Message[], onMessage: OnLLMResponse, tools?: Tool[]) => Promise<void>;
|
|
121
|
+
getVoice: (text: string, voice?: string, speed?: number, language?: string) => Promise<Blob>;
|
|
122
|
+
getTextFromVoice: (file: Blob) => Promise<string>;
|
|
123
|
+
getObject: (request: ObjectRequest) => Promise<any>;
|
|
124
|
+
};
|
|
73
125
|
/**
|
|
74
126
|
* Fetch new shared content.
|
|
75
127
|
* @param type The type of shared content to fetch. E.g. assignments, exercises, etc.
|
|
@@ -96,3 +148,4 @@ export declare class RimoriClient {
|
|
|
96
148
|
completeSharedContent(type: string, assignmentId: string): Promise<void>;
|
|
97
149
|
triggerSidebarAction(pluginId: string, actionKey: string, text?: string): void;
|
|
98
150
|
}
|
|
151
|
+
export {};
|
|
@@ -13,28 +13,109 @@ import { SharedContentController } from "../controller/SharedContentController";
|
|
|
13
13
|
import { streamChatGPT, generateText } from "../controller/AIController";
|
|
14
14
|
import { generateObject as generateObjectFunction } from "../controller/ObjectController";
|
|
15
15
|
import { getPlugins } from "../controller/SidePluginController";
|
|
16
|
+
import { EventBus } from "./fromRimori/EventBus";
|
|
16
17
|
export class RimoriClient {
|
|
17
18
|
constructor(options) {
|
|
19
|
+
this.event = {
|
|
20
|
+
/**
|
|
21
|
+
* Emit an event to Rimori or a plugin.
|
|
22
|
+
* The topic schema is:
|
|
23
|
+
* {pluginId}.{eventId}
|
|
24
|
+
* Check out the event bus documentation for more information.
|
|
25
|
+
* For triggering events from Rimori like context menu actions use the "global" keyword.
|
|
26
|
+
* @param topic The topic to emit the event on.
|
|
27
|
+
* @param data The data to emit.
|
|
28
|
+
* @param eventId The event id.
|
|
29
|
+
*/
|
|
30
|
+
emit: (topic, data, eventId) => {
|
|
31
|
+
const globalTopic = this.pluginController.getGlobalEventTopic(topic);
|
|
32
|
+
EventBus.emit(this.plugin.pluginId, globalTopic, data, eventId);
|
|
33
|
+
},
|
|
34
|
+
/**
|
|
35
|
+
* Request an event.
|
|
36
|
+
* @param topic The topic to request the event on.
|
|
37
|
+
* @param data The data to request.
|
|
38
|
+
* @returns The response from the event.
|
|
39
|
+
*/
|
|
40
|
+
request: (topic, data) => {
|
|
41
|
+
const globalTopic = this.pluginController.getGlobalEventTopic(topic);
|
|
42
|
+
return EventBus.request(this.plugin.pluginId, globalTopic, data);
|
|
43
|
+
},
|
|
44
|
+
/**
|
|
45
|
+
* Subscribe to an event.
|
|
46
|
+
* @param topic The topic to subscribe to.
|
|
47
|
+
* @param callback The callback to call when the event is emitted.
|
|
48
|
+
*/
|
|
49
|
+
on: (topic, callback) => {
|
|
50
|
+
EventBus.on(this.pluginController.getGlobalEventTopic(topic), callback);
|
|
51
|
+
},
|
|
52
|
+
/**
|
|
53
|
+
* Subscribe to an event once.
|
|
54
|
+
* @param topic The topic to subscribe to.
|
|
55
|
+
* @param callback The callback to call when the event is emitted.
|
|
56
|
+
*/
|
|
57
|
+
once: (topic, callback) => {
|
|
58
|
+
EventBus.once(this.pluginController.getGlobalEventTopic(topic), callback);
|
|
59
|
+
},
|
|
60
|
+
/**
|
|
61
|
+
* Respond to an event.
|
|
62
|
+
* @param topic The topic to respond to.
|
|
63
|
+
* @param data The data to respond with.
|
|
64
|
+
*/
|
|
65
|
+
respond: (topic, data) => {
|
|
66
|
+
EventBus.respond(this.plugin.pluginId, this.pluginController.getGlobalEventTopic(topic), data);
|
|
67
|
+
}
|
|
68
|
+
};
|
|
69
|
+
this.llm = {
|
|
70
|
+
getText: (messages, tools) => __awaiter(this, void 0, void 0, function* () {
|
|
71
|
+
const token = yield this.pluginController.getToken();
|
|
72
|
+
return generateText(this.supabaseUrl, messages, tools || [], token).then(response => response.messages[0].content[0].text);
|
|
73
|
+
}),
|
|
74
|
+
getSteamedText: (messages, onMessage, tools) => __awaiter(this, void 0, void 0, function* () {
|
|
75
|
+
const token = yield this.pluginController.getToken();
|
|
76
|
+
streamChatGPT(this.supabaseUrl, messages, tools || [], onMessage, token);
|
|
77
|
+
}),
|
|
78
|
+
getVoice: (text_1, ...args_1) => __awaiter(this, [text_1, ...args_1], void 0, function* (text, voice = "alloy", speed = 1, language) {
|
|
79
|
+
return getTTSResponse(this.pluginController.getSupabaseUrl(), { input: text, voice, speed, language }, yield this.pluginController.getToken());
|
|
80
|
+
}),
|
|
81
|
+
getTextFromVoice: (file) => {
|
|
82
|
+
return getSTTResponse(this.superbase, file);
|
|
83
|
+
},
|
|
84
|
+
getObject: (request) => __awaiter(this, void 0, void 0, function* () {
|
|
85
|
+
const token = yield this.pluginController.getToken();
|
|
86
|
+
return generateObjectFunction(this.pluginController.getSupabaseUrl(), request, token);
|
|
87
|
+
}),
|
|
88
|
+
// getSteamedObject: this.generateObjectStream,
|
|
89
|
+
};
|
|
18
90
|
this.superbase = options.supabase;
|
|
19
|
-
this.
|
|
20
|
-
this.plugin = options.pluginController;
|
|
21
|
-
this.tablePrefix = options.tablePrefix;
|
|
22
|
-
this.storage = this.superbase.storage;
|
|
23
|
-
this.functions = this.superbase.functions;
|
|
91
|
+
this.pluginController = options.pluginController;
|
|
24
92
|
this.settingsController = new SettingsController(options.supabase, options.pluginId);
|
|
25
93
|
this.sharedContentController = new SharedContentController(this);
|
|
94
|
+
this.supabaseUrl = this.pluginController.getSupabaseUrl();
|
|
26
95
|
this.rpc = this.rpc.bind(this);
|
|
27
96
|
this.from = this.from.bind(this);
|
|
28
|
-
this.
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
this.
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
97
|
+
this.db = {
|
|
98
|
+
rpc: this.rpc,
|
|
99
|
+
from: this.from,
|
|
100
|
+
storage: this.superbase.storage,
|
|
101
|
+
functions: this.superbase.functions,
|
|
102
|
+
};
|
|
103
|
+
this.plugin = {
|
|
104
|
+
pluginId: options.pluginId,
|
|
105
|
+
tablePrefix: options.tablePrefix,
|
|
106
|
+
setSettings: (settings) => __awaiter(this, void 0, void 0, function* () {
|
|
107
|
+
yield this.settingsController.setSettings(settings);
|
|
108
|
+
}),
|
|
109
|
+
getSettings: (defaultSettings) => __awaiter(this, void 0, void 0, function* () {
|
|
110
|
+
return yield this.settingsController.getSettings(defaultSettings);
|
|
111
|
+
}),
|
|
112
|
+
getInstalled: () => __awaiter(this, void 0, void 0, function* () {
|
|
113
|
+
return getPlugins(this.superbase);
|
|
114
|
+
}),
|
|
115
|
+
getUserInfo: () => __awaiter(this, void 0, void 0, function* () {
|
|
116
|
+
return this.settingsController.getUserInfo();
|
|
117
|
+
})
|
|
118
|
+
};
|
|
38
119
|
}
|
|
39
120
|
static getInstance(pluginController) {
|
|
40
121
|
return __awaiter(this, void 0, void 0, function* () {
|
|
@@ -75,67 +156,7 @@ export class RimoriClient {
|
|
|
75
156
|
return this.superbase.rpc(this.getTableName(functionName), args, options);
|
|
76
157
|
}
|
|
77
158
|
getTableName(type) {
|
|
78
|
-
return this.tablePrefix + "_" + type;
|
|
79
|
-
}
|
|
80
|
-
subscribe(eventName, callback) {
|
|
81
|
-
this.plugin.subscribe(eventName, callback);
|
|
82
|
-
}
|
|
83
|
-
request(eventName, data) {
|
|
84
|
-
return this.plugin.request(eventName, data);
|
|
85
|
-
}
|
|
86
|
-
emit(eventName, data) {
|
|
87
|
-
this.plugin.emit(eventName, data);
|
|
88
|
-
}
|
|
89
|
-
/**
|
|
90
|
-
* Get the settings for the plugin. T can be any type of settings, UserSettings or SystemSettings.
|
|
91
|
-
* @param defaultSettings The default settings to use if no settings are found.
|
|
92
|
-
* @param genericSettings The type of settings to get.
|
|
93
|
-
* @returns The settings for the plugin.
|
|
94
|
-
*/
|
|
95
|
-
getSettings(defaultSettings, genericSettings) {
|
|
96
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
97
|
-
return this.settingsController.getSettings(defaultSettings, genericSettings);
|
|
98
|
-
});
|
|
99
|
-
}
|
|
100
|
-
setSettings(settings, genericSettings) {
|
|
101
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
102
|
-
yield this.settingsController.setSettings(settings, genericSettings);
|
|
103
|
-
});
|
|
104
|
-
}
|
|
105
|
-
getAIResponse(messages, tools) {
|
|
106
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
107
|
-
const token = yield this.plugin.getToken();
|
|
108
|
-
return generateText(messages, tools || [], token).then(response => response.messages[0].content[0].text);
|
|
109
|
-
});
|
|
110
|
-
}
|
|
111
|
-
getAIResponseStream(messages, onMessage, tools) {
|
|
112
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
113
|
-
const token = yield this.plugin.getToken();
|
|
114
|
-
streamChatGPT(messages, tools || [], onMessage, token);
|
|
115
|
-
});
|
|
116
|
-
}
|
|
117
|
-
getVoiceResponse(text_1) {
|
|
118
|
-
return __awaiter(this, arguments, void 0, function* (text, voice = "alloy", speed = 1, language) {
|
|
119
|
-
return getTTSResponse(this.plugin.getSupabaseUrl(), { input: text, voice, speed, language }, yield this.plugin.getToken());
|
|
120
|
-
});
|
|
121
|
-
}
|
|
122
|
-
getVoiceToTextResponse(file) {
|
|
123
|
-
return getSTTResponse(this.superbase, file);
|
|
124
|
-
}
|
|
125
|
-
/**
|
|
126
|
-
* Fetches all installed plugins.
|
|
127
|
-
* @returns A promise that resolves to an array of plugins
|
|
128
|
-
*/
|
|
129
|
-
getPlugins() {
|
|
130
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
131
|
-
return getPlugins(this.superbase);
|
|
132
|
-
});
|
|
133
|
-
}
|
|
134
|
-
generateObject(request) {
|
|
135
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
136
|
-
const token = yield this.plugin.getToken();
|
|
137
|
-
return generateObjectFunction(request, token);
|
|
138
|
-
});
|
|
159
|
+
return this.plugin.tablePrefix + "_" + type;
|
|
139
160
|
}
|
|
140
161
|
/**
|
|
141
162
|
* Fetch new shared content.
|
|
@@ -171,6 +192,6 @@ export class RimoriClient {
|
|
|
171
192
|
});
|
|
172
193
|
}
|
|
173
194
|
triggerSidebarAction(pluginId, actionKey, text) {
|
|
174
|
-
this.emit("
|
|
195
|
+
this.event.emit("global.sidebar.triggerAction", { pluginId, actionKey, text });
|
|
175
196
|
}
|
|
176
197
|
}
|
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
export function setTheme() {
|
|
2
2
|
const urlParams = new URLSearchParams(window.location.search);
|
|
3
3
|
let theme = urlParams.get('theme');
|
|
4
|
-
const isSidebar = urlParams.get('applicationMode') === "sidebar";
|
|
5
4
|
if (!theme || theme === 'system') {
|
|
6
5
|
theme = window.matchMedia && window.matchMedia('(prefers-color-scheme: dark)').matches ? 'dark' : 'light';
|
|
7
6
|
}
|
|
8
7
|
document.documentElement.classList.add("dark:text-gray-200", "bg-white");
|
|
9
8
|
if (theme === 'dark') {
|
|
10
|
-
document.documentElement.
|
|
11
|
-
document.documentElement.
|
|
9
|
+
document.documentElement.setAttribute("data-theme", "dark");
|
|
10
|
+
document.documentElement.classList.add('dark', "bg-gray-950");
|
|
11
|
+
document.documentElement.style.background = "hsl(var(--background))";
|
|
12
12
|
}
|
|
13
13
|
}
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
export type EventPayload = Record<string, any>;
|
|
2
|
+
/**
|
|
3
|
+
* Interface representing a message sent through the EventBus
|
|
4
|
+
*
|
|
5
|
+
* Debug capabilities:
|
|
6
|
+
* - System-wide debugging: Send an event to "global.system.requestDebug"
|
|
7
|
+
* Example: `EventBus.emit("yourPluginId", "global.system.requestDebug");`
|
|
8
|
+
*/
|
|
9
|
+
export interface EventBusMessage<T = EventPayload> {
|
|
10
|
+
timestamp: string;
|
|
11
|
+
eventId: number;
|
|
12
|
+
sender: string;
|
|
13
|
+
topic: string;
|
|
14
|
+
data: T;
|
|
15
|
+
debug: boolean;
|
|
16
|
+
}
|
|
17
|
+
export type EventHandler<T = EventPayload> = (event: EventBusMessage<T>) => void | Promise<void>;
|
|
18
|
+
export declare class EventBusHandler {
|
|
19
|
+
private listeners;
|
|
20
|
+
private responseResolvers;
|
|
21
|
+
private static instance;
|
|
22
|
+
private debugEnabled;
|
|
23
|
+
private evName;
|
|
24
|
+
private constructor();
|
|
25
|
+
static getInstance(name?: string): EventBusHandler;
|
|
26
|
+
private createEvent;
|
|
27
|
+
/**
|
|
28
|
+
* Emits an event to the event bus. Can be a new event or a response to a request.
|
|
29
|
+
* @param sender - The sender of the event.
|
|
30
|
+
* @param topic - The topic of the event.
|
|
31
|
+
* @param data - The data of the event.
|
|
32
|
+
* @param eventId - The event id of the event.
|
|
33
|
+
*
|
|
34
|
+
* The topic format is: **pluginId.area.action**
|
|
35
|
+
*
|
|
36
|
+
* Example topics:
|
|
37
|
+
* - pl1234.card.requestHard
|
|
38
|
+
* - pl1234.card.requestNew
|
|
39
|
+
* - pl1234.card.requestAll
|
|
40
|
+
* - pl1234.card.create
|
|
41
|
+
* - pl1234.card.update
|
|
42
|
+
* - pl1234.card.delete
|
|
43
|
+
* - pl1234.card.triggerBackup
|
|
44
|
+
*/
|
|
45
|
+
emit<T = EventPayload>(sender: string, topic: string, data?: T, eventId?: number): void;
|
|
46
|
+
private emitInternal;
|
|
47
|
+
/**
|
|
48
|
+
* Subscribes to an event on the event bus.
|
|
49
|
+
* @param topics - The topic of the event.
|
|
50
|
+
* @param handler - The handler to be called when the event is emitted.
|
|
51
|
+
* @param ignoreSender - The senders to ignore.
|
|
52
|
+
* @returns The ids of the listeners.
|
|
53
|
+
*/
|
|
54
|
+
on<T = EventPayload>(topics: string | string[], handler: EventHandler<T>, ignoreSender?: string[]): string[];
|
|
55
|
+
/**
|
|
56
|
+
* Subscribes to an event, processes the data and emits a response on the event bus.
|
|
57
|
+
* @param sender - The sender of the event.
|
|
58
|
+
* @param topic - The topic of the event.
|
|
59
|
+
* @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.
|
|
60
|
+
* @returns The ids of the listeners.
|
|
61
|
+
*/
|
|
62
|
+
respond(sender: string, topic: string, handler: EventPayload | ((data: EventBusMessage) => EventPayload | Promise<EventPayload>)): string[];
|
|
63
|
+
/**
|
|
64
|
+
* Subscribes to an event on the event bus. The handler will be called once and then removed.
|
|
65
|
+
* @param topic - The topic of the event.
|
|
66
|
+
* @param handler - The handler to be called when the event is emitted.
|
|
67
|
+
*/
|
|
68
|
+
once<T = EventPayload>(topic: string, handler: EventHandler<T>): void;
|
|
69
|
+
/**
|
|
70
|
+
* Unsubscribes from an event on the event bus.
|
|
71
|
+
* @param listenerIds - The ids of the listeners to unsubscribe from.
|
|
72
|
+
*/
|
|
73
|
+
off(listenerIds: string | string[]): void;
|
|
74
|
+
private toArray;
|
|
75
|
+
/**
|
|
76
|
+
* Requests data from the event bus.
|
|
77
|
+
* @param sender - The sender of the event.
|
|
78
|
+
* @param topic - The topic of the event.
|
|
79
|
+
* @param data - The data of the event.
|
|
80
|
+
* @returns A promise that resolves to the event.
|
|
81
|
+
*/
|
|
82
|
+
request<T = EventPayload>(sender: string, topic: string, data?: EventPayload): Promise<EventBusMessage<T>>;
|
|
83
|
+
/**
|
|
84
|
+
* Gets the matching handlers for an event.
|
|
85
|
+
* @param topic - The topic of the event.
|
|
86
|
+
* @returns A set of handlers that match the event type.
|
|
87
|
+
*/
|
|
88
|
+
private getMatchingHandlers;
|
|
89
|
+
/**
|
|
90
|
+
* Validates the topic of an event.
|
|
91
|
+
* @param topic - The topic of the event.
|
|
92
|
+
* @returns True if the topic is valid, false otherwise.
|
|
93
|
+
*/
|
|
94
|
+
private validateTopic;
|
|
95
|
+
private logIfDebug;
|
|
96
|
+
private logAndThrowError;
|
|
97
|
+
}
|
|
98
|
+
export declare const EventBus: EventBusHandler;
|