@rimori/client 1.0.4 → 1.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +13 -0
- package/dist/components/MarkdownEditor.js +6 -4
- package/dist/components/PluginController.d.ts +21 -0
- package/dist/components/PluginController.js +116 -0
- package/dist/components/ai/Assistant.js +1 -1
- package/dist/components/ai/Avatar.d.ts +5 -3
- package/dist/components/ai/Avatar.js +14 -6
- package/dist/components/ai/EmbeddedAssistent/CircleAudioAvatar.d.ts +2 -1
- package/dist/components/ai/EmbeddedAssistent/CircleAudioAvatar.js +35 -14
- package/dist/components/ai/EmbeddedAssistent/TTS/MessageSender.d.ts +1 -0
- package/dist/components/ai/EmbeddedAssistent/TTS/MessageSender.js +3 -0
- package/dist/components/ai/EmbeddedAssistent/TTS/Player.d.ts +2 -0
- package/dist/components/ai/EmbeddedAssistent/TTS/Player.js +5 -0
- package/dist/components/ai/EmbeddedAssistent/VoiceRecoder.d.ts +3 -0
- package/dist/components/ai/EmbeddedAssistent/VoiceRecoder.js +41 -5
- package/dist/components/ai/utils.d.ts +1 -1
- package/dist/components.d.ts +1 -0
- package/dist/components.js +1 -0
- package/dist/controller/AIController.js +2 -1
- package/dist/controller/SettingsController.d.ts +18 -10
- package/dist/controller/SettingsController.js +28 -31
- package/dist/controller/SharedContentController.d.ts +58 -11
- package/dist/controller/SharedContentController.js +161 -26
- package/dist/controller/SidePluginController.d.ts +1 -12
- package/dist/core/components/ContextMenu.d.ts +10 -0
- package/dist/core/components/ContextMenu.js +93 -0
- package/dist/core.d.ts +2 -0
- package/dist/core.js +2 -0
- package/dist/hooks/UseChatHook.d.ts +1 -1
- package/dist/plugin/AccomplishmentHandler.d.ts +38 -0
- package/dist/plugin/AccomplishmentHandler.js +108 -0
- package/dist/plugin/ContextMenu.d.ts +17 -0
- package/dist/plugin/ContextMenu.js +45 -0
- package/dist/plugin/PluginController.js +9 -4
- package/dist/plugin/RimoriClient.d.ts +92 -65
- package/dist/plugin/RimoriClient.js +105 -75
- package/dist/plugin/ThemeSetter.js +4 -4
- package/dist/plugin/fromRimori/EventBus.d.ts +6 -3
- package/dist/plugin/fromRimori/EventBus.js +15 -9
- package/dist/plugin/fromRimori/PluginTypes.d.ts +51 -0
- package/dist/plugin/fromRimori/PluginTypes.js +1 -0
- package/dist/providers/PluginController.d.ts +21 -0
- package/dist/providers/PluginController.js +116 -0
- package/dist/providers/PluginProvider.js +26 -73
- package/dist/types/Actions.d.ts +4 -0
- package/dist/types/Actions.js +1 -0
- package/dist/utils/Language.d.ts +66 -0
- package/dist/utils/Language.js +67 -0
- package/dist/utils/difficultyConverter.d.ts +1 -0
- package/dist/utils/difficultyConverter.js +3 -0
- package/dist/worker/WorkerSetup.js +5 -4
- package/package.json +3 -3
- package/src/components/MarkdownEditor.tsx +78 -76
- package/src/components/ai/Assistant.tsx +1 -1
- package/src/components/ai/Avatar.tsx +65 -48
- package/src/components/ai/EmbeddedAssistent/CircleAudioAvatar.tsx +81 -58
- package/src/components/ai/EmbeddedAssistent/TTS/MessageSender.ts +4 -0
- package/src/components/ai/EmbeddedAssistent/TTS/Player.ts +6 -0
- package/src/components/ai/EmbeddedAssistent/VoiceRecoder.tsx +51 -8
- package/src/components/ai/utils.ts +1 -1
- package/src/components.ts +2 -1
- package/src/controller/AIController.ts +2 -1
- package/src/controller/SettingsController.ts +80 -75
- package/src/controller/SharedContentController.ts +214 -53
- package/src/controller/SidePluginController.ts +1 -13
- package/src/core/components/ContextMenu.tsx +123 -0
- package/src/core.ts +3 -1
- package/src/hooks/UseChatHook.ts +17 -17
- package/src/plugin/AccomplishmentHandler.ts +165 -0
- package/src/plugin/PluginController.ts +107 -100
- package/src/plugin/RimoriClient.ts +267 -250
- package/src/plugin/ThemeSetter.ts +4 -5
- package/src/plugin/fromRimori/EventBus.ts +23 -12
- package/src/plugin/fromRimori/PluginTypes.ts +67 -0
- package/src/providers/PluginProvider.tsx +63 -110
- package/src/types/Actions.ts +6 -0
- package/src/utils/Language.ts +70 -0
- package/src/utils/difficultyConverter.ts +4 -0
- package/src/worker/WorkerSetup.ts +5 -4
- package/dist/components/avatar/Assistant.d.ts +0 -9
- package/dist/components/avatar/Assistant.js +0 -59
- package/dist/components/avatar/Avatar.d.ts +0 -12
- package/dist/components/avatar/Avatar.js +0 -42
- package/dist/components/avatar/EmbeddedAssistent/AudioInputField.d.ts +0 -7
- package/dist/components/avatar/EmbeddedAssistent/AudioInputField.js +0 -38
- package/dist/components/avatar/EmbeddedAssistent/CircleAudioAvatar.d.ts +0 -7
- package/dist/components/avatar/EmbeddedAssistent/CircleAudioAvatar.js +0 -59
- package/dist/components/avatar/EmbeddedAssistent/TTS/MessageSender.d.ts +0 -19
- package/dist/components/avatar/EmbeddedAssistent/TTS/MessageSender.js +0 -84
- package/dist/components/avatar/EmbeddedAssistent/TTS/Player.d.ts +0 -25
- package/dist/components/avatar/EmbeddedAssistent/TTS/Player.js +0 -180
- package/dist/components/avatar/EmbeddedAssistent/VoiceRecoder.d.ts +0 -7
- package/dist/components/avatar/EmbeddedAssistent/VoiceRecoder.js +0 -45
- package/dist/components/avatar/utils.d.ts +0 -6
- package/dist/components/avatar/utils.js +0 -14
|
@@ -3,126 +3,133 @@ import { RimoriClient } from "./RimoriClient";
|
|
|
3
3
|
import { EventBus, EventBusMessage } from './fromRimori/EventBus';
|
|
4
4
|
import { setTheme } from './ThemeSetter';
|
|
5
5
|
|
|
6
|
-
|
|
6
|
+
// Add declaration for WorkerGlobalScope
|
|
7
|
+
declare const WorkerGlobalScope: any;
|
|
7
8
|
|
|
8
9
|
interface SupabaseInfo {
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
10
|
+
url: string,
|
|
11
|
+
key: string,
|
|
12
|
+
token: string,
|
|
13
|
+
expiration: Date,
|
|
14
|
+
tablePrefix: string,
|
|
15
|
+
pluginId: string
|
|
15
16
|
}
|
|
16
17
|
|
|
17
18
|
export class PluginController {
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
const { topic, sender, data, eventId } = event.data.event as EventBusMessage;
|
|
32
|
-
|
|
33
|
-
// skip forwarding messages from own plugin
|
|
34
|
-
if (sender === pluginId) return;
|
|
35
|
-
|
|
36
|
-
EventBus.emit(sender, topic, data, eventId);
|
|
37
|
-
});
|
|
38
|
-
|
|
39
|
-
EventBus.on("*", (event) => {
|
|
40
|
-
// skip messages which are not from the own plugin
|
|
41
|
-
if (event.sender !== this.pluginId) return;
|
|
42
|
-
if (event.topic.startsWith("self.")) return;
|
|
43
|
-
window.parent.postMessage({ event, secret: this.getSecret() }, "*")
|
|
44
|
-
});
|
|
19
|
+
private static client: RimoriClient;
|
|
20
|
+
private static instance: PluginController;
|
|
21
|
+
private communicationSecret: string | null = null;
|
|
22
|
+
private supabase: SupabaseClient | null = null;
|
|
23
|
+
private supabaseInfo: SupabaseInfo | null = null;
|
|
24
|
+
private pluginId: string;
|
|
25
|
+
|
|
26
|
+
private constructor(pluginId: string) {
|
|
27
|
+
this.pluginId = pluginId;
|
|
28
|
+
this.getClient = this.getClient.bind(this);
|
|
29
|
+
|
|
30
|
+
if (typeof WorkerGlobalScope === 'undefined') {
|
|
31
|
+
setTheme();
|
|
45
32
|
}
|
|
46
33
|
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
PluginController.client = await RimoriClient.getInstance(PluginController.instance);
|
|
51
|
-
}
|
|
52
|
-
return PluginController.client;
|
|
53
|
-
}
|
|
34
|
+
window.addEventListener("message", (event) => {
|
|
35
|
+
// console.log("client: message received", event);
|
|
36
|
+
const { topic, sender, data, eventId } = event.data.event as EventBusMessage;
|
|
54
37
|
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
}
|
|
61
|
-
this.communicationSecret = secret;
|
|
62
|
-
}
|
|
63
|
-
return this.communicationSecret;
|
|
64
|
-
}
|
|
38
|
+
// skip forwarding messages from own plugin
|
|
39
|
+
if (sender === pluginId) return;
|
|
40
|
+
|
|
41
|
+
EventBus.emit(sender, topic, data, eventId);
|
|
42
|
+
});
|
|
65
43
|
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
44
|
+
EventBus.on("*", (event) => {
|
|
45
|
+
// skip messages which are not from the own plugin
|
|
46
|
+
if (event.sender !== this.pluginId) return;
|
|
47
|
+
if (event.topic.startsWith("self.")) return;
|
|
48
|
+
window.parent.postMessage({ event, secret: this.getSecret() }, "*")
|
|
49
|
+
});
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
public static async getInstance(sender: string): Promise<RimoriClient> {
|
|
53
|
+
if (!PluginController.instance) {
|
|
54
|
+
PluginController.instance = new PluginController(sender);
|
|
55
|
+
PluginController.client = await RimoriClient.getInstance(PluginController.instance);
|
|
56
|
+
}
|
|
57
|
+
return PluginController.client;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
private getSecret() {
|
|
61
|
+
if (!this.communicationSecret) {
|
|
62
|
+
const secret = new URLSearchParams(window.location.search).get("secret");
|
|
63
|
+
if (!secret) {
|
|
64
|
+
throw new Error("Communication secret not found in URL as query parameter");
|
|
65
|
+
}
|
|
66
|
+
this.communicationSecret = secret;
|
|
67
|
+
}
|
|
68
|
+
return this.communicationSecret;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
public async getClient(): Promise<{ supabase: SupabaseClient, tablePrefix: string, pluginId: string }> {
|
|
72
|
+
if (
|
|
73
|
+
this.supabase &&
|
|
74
|
+
this.supabaseInfo &&
|
|
75
|
+
this.supabaseInfo.expiration > new Date()
|
|
76
|
+
) {
|
|
77
|
+
return { supabase: this.supabase, tablePrefix: this.supabaseInfo.tablePrefix, pluginId: this.supabaseInfo.pluginId };
|
|
82
78
|
}
|
|
83
79
|
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
80
|
+
const { data } = await EventBus.request<SupabaseInfo>(this.pluginId, "global.supabase.requestAccess");
|
|
81
|
+
this.supabaseInfo = data;
|
|
82
|
+
this.supabase = createClient(this.supabaseInfo.url, this.supabaseInfo.key, {
|
|
83
|
+
accessToken: () => Promise.resolve(this.getToken())
|
|
84
|
+
});
|
|
88
85
|
|
|
89
|
-
|
|
86
|
+
return { supabase: this.supabase, tablePrefix: this.supabaseInfo.tablePrefix, pluginId: this.supabaseInfo.pluginId };
|
|
87
|
+
}
|
|
90
88
|
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
89
|
+
public async getToken() {
|
|
90
|
+
if (this.supabaseInfo && this.supabaseInfo.expiration && this.supabaseInfo.expiration > new Date()) {
|
|
91
|
+
return this.supabaseInfo.token;
|
|
92
|
+
}
|
|
94
93
|
|
|
95
|
-
|
|
96
|
-
this.supabaseInfo.expiration = data.expiration;
|
|
94
|
+
const { data } = await EventBus.request<{ token: string, expiration: Date }>(this.pluginId, "global.supabase.requestAccess");
|
|
97
95
|
|
|
98
|
-
|
|
96
|
+
if (!this.supabaseInfo) {
|
|
97
|
+
throw new Error("Supabase info not found");
|
|
99
98
|
}
|
|
100
99
|
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
100
|
+
this.supabaseInfo.token = data.token;
|
|
101
|
+
this.supabaseInfo.expiration = data.expiration;
|
|
102
|
+
|
|
103
|
+
return this.supabaseInfo.token;
|
|
104
|
+
}
|
|
105
105
|
|
|
106
|
-
|
|
106
|
+
public getSupabaseUrl() {
|
|
107
|
+
if (!this.supabaseInfo) {
|
|
108
|
+
throw new Error("Supabase info not found");
|
|
107
109
|
}
|
|
108
110
|
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
}
|
|
116
|
-
const topicParts = preliminaryTopic.split(".");
|
|
117
|
-
if (topicParts.length === 3) {
|
|
118
|
-
if (![this.supabaseInfo?.pluginId, "global"].includes(topicParts[0])) {
|
|
119
|
-
throw new Error("The event topic must start with the plugin id or 'global'.");
|
|
120
|
-
}
|
|
121
|
-
return preliminaryTopic;
|
|
122
|
-
}
|
|
123
|
-
|
|
124
|
-
const topicRoot = this.supabaseInfo?.pluginId ?? "global";
|
|
125
|
-
return `${topicRoot}.${preliminaryTopic}`;
|
|
111
|
+
return this.supabaseInfo.url;
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
public getGlobalEventTopic(preliminaryTopic: string) {
|
|
115
|
+
if (preliminaryTopic.startsWith("global.")) {
|
|
116
|
+
return preliminaryTopic;
|
|
126
117
|
}
|
|
118
|
+
if (preliminaryTopic.startsWith("self.")) {
|
|
119
|
+
return preliminaryTopic;
|
|
120
|
+
}
|
|
121
|
+
const topicParts = preliminaryTopic.split(".");
|
|
122
|
+
if (topicParts.length === 3) {
|
|
123
|
+
if (!topicParts[0].startsWith("pl") && topicParts[0] !== "global") {
|
|
124
|
+
throw new Error("The event topic must start with the plugin id or 'global'.");
|
|
125
|
+
}
|
|
126
|
+
return preliminaryTopic;
|
|
127
|
+
} else if (topicParts.length > 3) {
|
|
128
|
+
throw new Error(`The event topic must consist of 3 parts. <pluginId>.<topic area>.<action>. Received: ${preliminaryTopic}`);
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
const topicRoot = this.supabaseInfo?.pluginId ?? "global";
|
|
132
|
+
return `${topicRoot}.${preliminaryTopic}`;
|
|
133
|
+
}
|
|
127
134
|
|
|
128
135
|
}
|