@rimori/client 1.0.5 → 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 +15 -15
  21. package/dist/controller/SettingsController.js +15 -16
  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 +6 -3
  35. package/dist/plugin/RimoriClient.d.ts +92 -65
  36. package/dist/plugin/RimoriClient.js +105 -75
  37. package/dist/plugin/ThemeSetter.js +2 -2
  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 +4 -4
  52. package/package.json +2 -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 +83 -84
  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 +105 -103
  71. package/src/plugin/RimoriClient.ts +267 -250
  72. package/src/plugin/ThemeSetter.ts +2 -2
  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 +4 -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
@@ -7,127 +7,129 @@ import { setTheme } from './ThemeSetter';
7
7
  declare const WorkerGlobalScope: any;
8
8
 
9
9
  interface SupabaseInfo {
10
- url: string,
11
- key: string,
12
- token: string,
13
- expiration: Date,
14
- tablePrefix: string,
15
- pluginId: string
10
+ url: string,
11
+ key: string,
12
+ token: string,
13
+ expiration: Date,
14
+ tablePrefix: string,
15
+ pluginId: string
16
16
  }
17
17
 
18
18
  export class PluginController {
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();
32
- }
33
-
34
- window.addEventListener("message", (event) => {
35
- // console.log("client: message received", event);
36
- const { topic, sender, data, eventId } = event.data.event as EventBusMessage;
37
-
38
- // skip forwarding messages from own plugin
39
- if (sender === pluginId) return;
40
-
41
- EventBus.emit(sender, topic, data, eventId);
42
- });
43
-
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
- });
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();
50
32
  }
51
33
 
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
- }
34
+ window.addEventListener("message", (event) => {
35
+ // console.log("client: message received", event);
36
+ const { topic, sender, data, eventId } = event.data.event as EventBusMessage;
59
37
 
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
- }
38
+ // skip forwarding messages from own plugin
39
+ if (sender === pluginId) return;
40
+
41
+ EventBus.emit(sender, topic, data, eventId);
42
+ });
70
43
 
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 };
78
- }
79
-
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
- });
85
-
86
- 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 };
87
78
  }
88
79
 
89
- public async getToken() {
90
- if (this.supabaseInfo && this.supabaseInfo.expiration && this.supabaseInfo.expiration > new Date()) {
91
- return this.supabaseInfo.token;
92
- }
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
+ });
93
85
 
94
- 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
+ }
95
88
 
96
- if (!this.supabaseInfo) {
97
- throw new Error("Supabase info not found");
98
- }
89
+ public async getToken() {
90
+ if (this.supabaseInfo && this.supabaseInfo.expiration && this.supabaseInfo.expiration > new Date()) {
91
+ return this.supabaseInfo.token;
92
+ }
99
93
 
100
- this.supabaseInfo.token = data.token;
101
- this.supabaseInfo.expiration = data.expiration;
94
+ const { data } = await EventBus.request<{ token: string, expiration: Date }>(this.pluginId, "global.supabase.requestAccess");
102
95
 
103
- return this.supabaseInfo.token;
96
+ if (!this.supabaseInfo) {
97
+ throw new Error("Supabase info not found");
104
98
  }
105
99
 
106
- public getSupabaseUrl() {
107
- if (!this.supabaseInfo) {
108
- throw new Error("Supabase info not found");
109
- }
100
+ this.supabaseInfo.token = data.token;
101
+ this.supabaseInfo.expiration = data.expiration;
102
+
103
+ return this.supabaseInfo.token;
104
+ }
110
105
 
111
- return this.supabaseInfo.url;
106
+ public getSupabaseUrl() {
107
+ if (!this.supabaseInfo) {
108
+ throw new Error("Supabase info not found");
112
109
  }
113
110
 
114
- public getGlobalEventTopic(preliminaryTopic: string) {
115
- if (preliminaryTopic.startsWith("global.")) {
116
- return preliminaryTopic;
117
- }
118
- if (preliminaryTopic.startsWith("self.")) {
119
- return preliminaryTopic;
120
- }
121
- const topicParts = preliminaryTopic.split(".");
122
- if (topicParts.length === 3) {
123
- if (![this.supabaseInfo?.pluginId, "global"].includes(topicParts[0])) {
124
- throw new Error("The event topic must start with the plugin id or 'global'.");
125
- }
126
- return preliminaryTopic;
127
- }
128
-
129
- const topicRoot = this.supabaseInfo?.pluginId ?? "global";
130
- return `${topicRoot}.${preliminaryTopic}`;
111
+ return this.supabaseInfo.url;
112
+ }
113
+
114
+ public getGlobalEventTopic(preliminaryTopic: string) {
115
+ if (preliminaryTopic.startsWith("global.")) {
116
+ return preliminaryTopic;
131
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
+ }
132
134
 
133
135
  }