@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.
Files changed (95) hide show
  1. package/README.md +13 -0
  2. package/dist/components/MarkdownEditor.js +6 -4
  3. package/dist/components/PluginController.d.ts +21 -0
  4. package/dist/components/PluginController.js +116 -0
  5. package/dist/components/ai/Assistant.js +1 -1
  6. package/dist/components/ai/Avatar.d.ts +5 -3
  7. package/dist/components/ai/Avatar.js +14 -6
  8. package/dist/components/ai/EmbeddedAssistent/CircleAudioAvatar.d.ts +2 -1
  9. package/dist/components/ai/EmbeddedAssistent/CircleAudioAvatar.js +35 -14
  10. package/dist/components/ai/EmbeddedAssistent/TTS/MessageSender.d.ts +1 -0
  11. package/dist/components/ai/EmbeddedAssistent/TTS/MessageSender.js +3 -0
  12. package/dist/components/ai/EmbeddedAssistent/TTS/Player.d.ts +2 -0
  13. package/dist/components/ai/EmbeddedAssistent/TTS/Player.js +5 -0
  14. package/dist/components/ai/EmbeddedAssistent/VoiceRecoder.d.ts +3 -0
  15. package/dist/components/ai/EmbeddedAssistent/VoiceRecoder.js +41 -5
  16. package/dist/components/ai/utils.d.ts +1 -1
  17. package/dist/components.d.ts +1 -0
  18. package/dist/components.js +1 -0
  19. package/dist/controller/AIController.js +2 -1
  20. package/dist/controller/SettingsController.d.ts +18 -10
  21. package/dist/controller/SettingsController.js +28 -31
  22. package/dist/controller/SharedContentController.d.ts +58 -11
  23. package/dist/controller/SharedContentController.js +161 -26
  24. package/dist/controller/SidePluginController.d.ts +1 -12
  25. package/dist/core/components/ContextMenu.d.ts +10 -0
  26. package/dist/core/components/ContextMenu.js +93 -0
  27. package/dist/core.d.ts +2 -0
  28. package/dist/core.js +2 -0
  29. package/dist/hooks/UseChatHook.d.ts +1 -1
  30. package/dist/plugin/AccomplishmentHandler.d.ts +38 -0
  31. package/dist/plugin/AccomplishmentHandler.js +108 -0
  32. package/dist/plugin/ContextMenu.d.ts +17 -0
  33. package/dist/plugin/ContextMenu.js +45 -0
  34. package/dist/plugin/PluginController.js +9 -4
  35. package/dist/plugin/RimoriClient.d.ts +92 -65
  36. package/dist/plugin/RimoriClient.js +105 -75
  37. package/dist/plugin/ThemeSetter.js +4 -4
  38. package/dist/plugin/fromRimori/EventBus.d.ts +6 -3
  39. package/dist/plugin/fromRimori/EventBus.js +15 -9
  40. package/dist/plugin/fromRimori/PluginTypes.d.ts +51 -0
  41. package/dist/plugin/fromRimori/PluginTypes.js +1 -0
  42. package/dist/providers/PluginController.d.ts +21 -0
  43. package/dist/providers/PluginController.js +116 -0
  44. package/dist/providers/PluginProvider.js +26 -73
  45. package/dist/types/Actions.d.ts +4 -0
  46. package/dist/types/Actions.js +1 -0
  47. package/dist/utils/Language.d.ts +66 -0
  48. package/dist/utils/Language.js +67 -0
  49. package/dist/utils/difficultyConverter.d.ts +1 -0
  50. package/dist/utils/difficultyConverter.js +3 -0
  51. package/dist/worker/WorkerSetup.js +5 -4
  52. package/package.json +3 -3
  53. package/src/components/MarkdownEditor.tsx +78 -76
  54. package/src/components/ai/Assistant.tsx +1 -1
  55. package/src/components/ai/Avatar.tsx +65 -48
  56. package/src/components/ai/EmbeddedAssistent/CircleAudioAvatar.tsx +81 -58
  57. package/src/components/ai/EmbeddedAssistent/TTS/MessageSender.ts +4 -0
  58. package/src/components/ai/EmbeddedAssistent/TTS/Player.ts +6 -0
  59. package/src/components/ai/EmbeddedAssistent/VoiceRecoder.tsx +51 -8
  60. package/src/components/ai/utils.ts +1 -1
  61. package/src/components.ts +2 -1
  62. package/src/controller/AIController.ts +2 -1
  63. package/src/controller/SettingsController.ts +80 -75
  64. package/src/controller/SharedContentController.ts +214 -53
  65. package/src/controller/SidePluginController.ts +1 -13
  66. package/src/core/components/ContextMenu.tsx +123 -0
  67. package/src/core.ts +3 -1
  68. package/src/hooks/UseChatHook.ts +17 -17
  69. package/src/plugin/AccomplishmentHandler.ts +165 -0
  70. package/src/plugin/PluginController.ts +107 -100
  71. package/src/plugin/RimoriClient.ts +267 -250
  72. package/src/plugin/ThemeSetter.ts +4 -5
  73. package/src/plugin/fromRimori/EventBus.ts +23 -12
  74. package/src/plugin/fromRimori/PluginTypes.ts +67 -0
  75. package/src/providers/PluginProvider.tsx +63 -110
  76. package/src/types/Actions.ts +6 -0
  77. package/src/utils/Language.ts +70 -0
  78. package/src/utils/difficultyConverter.ts +4 -0
  79. package/src/worker/WorkerSetup.ts +5 -4
  80. package/dist/components/avatar/Assistant.d.ts +0 -9
  81. package/dist/components/avatar/Assistant.js +0 -59
  82. package/dist/components/avatar/Avatar.d.ts +0 -12
  83. package/dist/components/avatar/Avatar.js +0 -42
  84. package/dist/components/avatar/EmbeddedAssistent/AudioInputField.d.ts +0 -7
  85. package/dist/components/avatar/EmbeddedAssistent/AudioInputField.js +0 -38
  86. package/dist/components/avatar/EmbeddedAssistent/CircleAudioAvatar.d.ts +0 -7
  87. package/dist/components/avatar/EmbeddedAssistent/CircleAudioAvatar.js +0 -59
  88. package/dist/components/avatar/EmbeddedAssistent/TTS/MessageSender.d.ts +0 -19
  89. package/dist/components/avatar/EmbeddedAssistent/TTS/MessageSender.js +0 -84
  90. package/dist/components/avatar/EmbeddedAssistent/TTS/Player.d.ts +0 -25
  91. package/dist/components/avatar/EmbeddedAssistent/TTS/Player.js +0 -180
  92. package/dist/components/avatar/EmbeddedAssistent/VoiceRecoder.d.ts +0 -7
  93. package/dist/components/avatar/EmbeddedAssistent/VoiceRecoder.js +0 -45
  94. package/dist/components/avatar/utils.d.ts +0 -6
  95. 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
- setTheme();
6
+ // Add declaration for WorkerGlobalScope
7
+ declare const WorkerGlobalScope: any;
7
8
 
8
9
  interface SupabaseInfo {
9
- url: string,
10
- key: string,
11
- token: string,
12
- expiration: Date,
13
- tablePrefix: string,
14
- pluginId: string
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
- private static client: RimoriClient;
19
- private static instance: PluginController;
20
- private communicationSecret: string | null = null;
21
- private supabase: SupabaseClient | null = null;
22
- private supabaseInfo: SupabaseInfo | null = null;
23
- private pluginId: string;
24
-
25
- private constructor(pluginId: string) {
26
- this.pluginId = pluginId;
27
- this.getClient = this.getClient.bind(this);
28
-
29
- window.addEventListener("message", (event) => {
30
- // console.log("client: message received", event);
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
- public static async getInstance(sender: string): Promise<RimoriClient> {
48
- if (!PluginController.instance) {
49
- PluginController.instance = new PluginController(sender);
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
- private getSecret() {
56
- if (!this.communicationSecret) {
57
- const secret = new URLSearchParams(window.location.search).get("secret");
58
- if (!secret) {
59
- throw new Error("Communication secret not found in URL as query parameter");
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
- public async getClient(): Promise<{ supabase: SupabaseClient, tablePrefix: string, pluginId: string }> {
67
- if (
68
- this.supabase &&
69
- this.supabaseInfo &&
70
- this.supabaseInfo.expiration > new Date()
71
- ) {
72
- return { supabase: this.supabase, tablePrefix: this.supabaseInfo.tablePrefix, pluginId: this.supabaseInfo.pluginId };
73
- }
74
-
75
- const {data} = await EventBus.request<SupabaseInfo>(this.pluginId, "global.supabase.requestAccess");
76
- this.supabaseInfo = data;
77
- this.supabase = createClient(this.supabaseInfo.url, this.supabaseInfo.key, {
78
- accessToken: () => Promise.resolve(this.getToken())
79
- });
80
-
81
- return { supabase: this.supabase, tablePrefix: this.supabaseInfo.tablePrefix, pluginId: this.supabaseInfo.pluginId };
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
- public async getToken() {
85
- if (this.supabaseInfo && this.supabaseInfo.expiration && this.supabaseInfo.expiration > new Date()) {
86
- return this.supabaseInfo.token;
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
- const {data} = await EventBus.request<{ token: string, expiration: Date }>(this.pluginId, "global.supabase.requestAccess");
86
+ return { supabase: this.supabase, tablePrefix: this.supabaseInfo.tablePrefix, pluginId: this.supabaseInfo.pluginId };
87
+ }
90
88
 
91
- if (!this.supabaseInfo) {
92
- throw new Error("Supabase info not found");
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
- this.supabaseInfo.token = data.token;
96
- this.supabaseInfo.expiration = data.expiration;
94
+ const { data } = await EventBus.request<{ token: string, expiration: Date }>(this.pluginId, "global.supabase.requestAccess");
97
95
 
98
- return this.supabaseInfo.token;
96
+ if (!this.supabaseInfo) {
97
+ throw new Error("Supabase info not found");
99
98
  }
100
99
 
101
- public getSupabaseUrl() {
102
- if (!this.supabaseInfo) {
103
- throw new Error("Supabase info not found");
104
- }
100
+ this.supabaseInfo.token = data.token;
101
+ this.supabaseInfo.expiration = data.expiration;
102
+
103
+ return this.supabaseInfo.token;
104
+ }
105
105
 
106
- return this.supabaseInfo.url;
106
+ public getSupabaseUrl() {
107
+ if (!this.supabaseInfo) {
108
+ throw new Error("Supabase info not found");
107
109
  }
108
110
 
109
- public getGlobalEventTopic(preliminaryTopic: string) {
110
- if (preliminaryTopic.startsWith("global.")) {
111
- return preliminaryTopic;
112
- }
113
- if (preliminaryTopic.startsWith("self.")) {
114
- return preliminaryTopic;
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
  }