@rimori/client 1.1.10 → 1.3.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 (171) hide show
  1. package/README.md +189 -63
  2. package/dist/cli/scripts/init/dev-registration.d.ts +35 -0
  3. package/dist/cli/scripts/init/dev-registration.js +174 -0
  4. package/dist/cli/scripts/init/env-setup.d.ts +9 -0
  5. package/dist/cli/scripts/init/env-setup.js +43 -0
  6. package/dist/cli/scripts/init/file-operations.d.ts +4 -0
  7. package/dist/cli/scripts/init/file-operations.js +51 -0
  8. package/dist/cli/scripts/init/html-cleaner.d.ts +4 -0
  9. package/dist/cli/scripts/init/html-cleaner.js +38 -0
  10. package/dist/cli/scripts/init/main.d.ts +2 -0
  11. package/dist/cli/scripts/init/main.js +160 -0
  12. package/dist/cli/scripts/init/package-setup.d.ts +32 -0
  13. package/dist/cli/scripts/init/package-setup.js +75 -0
  14. package/dist/cli/scripts/init/router-transformer.d.ts +6 -0
  15. package/dist/cli/scripts/init/router-transformer.js +254 -0
  16. package/dist/cli/scripts/init/tailwind-config.d.ts +4 -0
  17. package/dist/cli/scripts/init/tailwind-config.js +56 -0
  18. package/dist/cli/scripts/init/vite-config.d.ts +20 -0
  19. package/dist/cli/scripts/init/vite-config.js +54 -0
  20. package/dist/cli/scripts/release/release-config-upload.d.ts +7 -0
  21. package/dist/cli/scripts/release/release-config-upload.js +116 -0
  22. package/dist/cli/scripts/release/release-db-update.d.ts +6 -0
  23. package/dist/cli/scripts/release/release-db-update.js +100 -0
  24. package/dist/cli/scripts/release/release-file-upload.d.ts +6 -0
  25. package/dist/cli/scripts/release/release-file-upload.js +136 -0
  26. package/dist/cli/scripts/release/release.d.ts +23 -0
  27. package/dist/cli/scripts/release/release.js +70 -0
  28. package/dist/cli/types/DatabaseTypes.d.ts +103 -0
  29. package/dist/cli/types/DatabaseTypes.js +2 -0
  30. package/dist/components/LoggerExample.d.ts +6 -0
  31. package/dist/components/LoggerExample.js +79 -0
  32. package/dist/components/ai/Assistant.js +5 -5
  33. package/dist/components/ai/Avatar.d.ts +3 -2
  34. package/dist/components/ai/Avatar.js +11 -6
  35. package/dist/components/ai/EmbeddedAssistent/CircleAudioAvatar.js +1 -1
  36. package/dist/components/ai/EmbeddedAssistent/VoiceRecoder.d.ts +1 -0
  37. package/dist/components/ai/EmbeddedAssistent/VoiceRecoder.js +48 -33
  38. package/dist/components/ai/utils.js +0 -1
  39. package/dist/components/audio/Playbutton.js +4 -4
  40. package/dist/{core → components}/components/ContextMenu.js +50 -11
  41. package/dist/components.d.ts +5 -5
  42. package/dist/components.js +5 -5
  43. package/dist/core/controller/AIController.d.ts +15 -0
  44. package/dist/core/controller/AIController.js +253 -0
  45. package/dist/core/controller/AudioController.d.ts +0 -0
  46. package/dist/core/controller/AudioController.js +1 -0
  47. package/dist/{controller → core/controller}/ObjectController.d.ts +10 -2
  48. package/dist/{controller → core/controller}/ObjectController.js +8 -8
  49. package/dist/{controller → core/controller}/SettingsController.d.ts +28 -4
  50. package/dist/{controller → core/controller}/SettingsController.js +0 -25
  51. package/dist/{controller → core/controller}/SharedContentController.d.ts +31 -3
  52. package/dist/{controller → core/controller}/SharedContentController.js +77 -26
  53. package/dist/core/controller/VoiceController.d.ts +9 -0
  54. package/dist/{controller → core/controller}/VoiceController.js +11 -4
  55. package/dist/core/core.d.ts +14 -0
  56. package/dist/core/core.js +8 -0
  57. package/dist/{plugin/fromRimori → fromRimori}/EventBus.d.ts +3 -3
  58. package/dist/{plugin/fromRimori → fromRimori}/EventBus.js +26 -9
  59. package/dist/fromRimori/PluginTypes.d.ts +174 -0
  60. package/dist/hooks/UseChatHook.d.ts +2 -1
  61. package/dist/hooks/UseChatHook.js +6 -4
  62. package/dist/hooks/UseLogger.d.ts +30 -0
  63. package/dist/hooks/UseLogger.js +122 -0
  64. package/dist/index.d.ts +6 -3
  65. package/dist/index.js +5 -3
  66. package/dist/plugin/AccomplishmentHandler.d.ts +1 -1
  67. package/dist/plugin/AccomplishmentHandler.js +1 -1
  68. package/dist/plugin/AudioController.d.ts +37 -0
  69. package/dist/plugin/AudioController.js +68 -0
  70. package/dist/plugin/Logger.d.ts +68 -0
  71. package/dist/plugin/Logger.js +256 -0
  72. package/dist/plugin/LoggerExample.d.ts +16 -0
  73. package/dist/plugin/LoggerExample.js +140 -0
  74. package/dist/plugin/PluginController.d.ts +30 -5
  75. package/dist/plugin/PluginController.js +182 -53
  76. package/dist/plugin/RimoriClient.d.ts +68 -21
  77. package/dist/plugin/RimoriClient.js +88 -41
  78. package/dist/plugin/StandaloneClient.d.ts +1 -0
  79. package/dist/plugin/StandaloneClient.js +24 -10
  80. package/dist/plugin/ThemeSetter.d.ts +2 -1
  81. package/dist/plugin/ThemeSetter.js +13 -7
  82. package/dist/providers/PluginProvider.d.ts +4 -1
  83. package/dist/providers/PluginProvider.js +39 -13
  84. package/dist/utils/Language.d.ts +2 -1
  85. package/dist/utils/Language.js +4 -2
  86. package/dist/utils/audioFormats.d.ts +26 -0
  87. package/dist/utils/audioFormats.js +67 -0
  88. package/dist/utils/difficultyConverter.js +1 -1
  89. package/dist/utils/endpoint.d.ts +2 -0
  90. package/dist/utils/endpoint.js +2 -0
  91. package/dist/worker/WorkerSetup.d.ts +3 -2
  92. package/dist/worker/WorkerSetup.js +22 -65
  93. package/example/docs/devdocs.md +231 -0
  94. package/example/docs/overview.md +29 -0
  95. package/example/docs/userdocs.md +123 -0
  96. package/example/rimori.config.ts +89 -0
  97. package/example/worker/vite.config.ts +23 -0
  98. package/example/worker/worker.ts +11 -0
  99. package/package.json +16 -9
  100. package/src/cli/scripts/init/dev-registration.ts +192 -0
  101. package/src/cli/scripts/init/env-setup.ts +44 -0
  102. package/src/cli/scripts/init/file-operations.ts +58 -0
  103. package/src/cli/scripts/init/html-cleaner.ts +48 -0
  104. package/src/cli/scripts/init/main.ts +172 -0
  105. package/src/cli/scripts/init/package-setup.ts +117 -0
  106. package/src/cli/scripts/init/router-transformer.ts +329 -0
  107. package/src/cli/scripts/init/tailwind-config.ts +75 -0
  108. package/src/cli/scripts/init/vite-config.ts +73 -0
  109. package/src/cli/scripts/release/release-config-upload.ts +114 -0
  110. package/src/cli/scripts/release/release-db-update.ts +97 -0
  111. package/src/cli/scripts/release/release-file-upload.ts +138 -0
  112. package/src/cli/scripts/release/release.ts +69 -0
  113. package/src/cli/types/DatabaseTypes.ts +117 -0
  114. package/src/components/ai/Assistant.tsx +5 -5
  115. package/src/components/ai/Avatar.tsx +25 -8
  116. package/src/components/ai/EmbeddedAssistent/CircleAudioAvatar.tsx +1 -1
  117. package/src/components/ai/EmbeddedAssistent/VoiceRecoder.tsx +50 -35
  118. package/src/components/ai/utils.ts +0 -2
  119. package/src/components/audio/Playbutton.tsx +4 -4
  120. package/src/{core → components}/components/ContextMenu.tsx +56 -12
  121. package/src/components.ts +6 -6
  122. package/src/core/controller/AIController.ts +283 -0
  123. package/src/core/controller/ObjectController.ts +115 -0
  124. package/src/{controller → core/controller}/SettingsController.ts +29 -29
  125. package/src/{controller → core/controller}/SharedContentController.ts +91 -29
  126. package/src/core/controller/VoiceController.ts +31 -0
  127. package/src/core/core.ts +16 -0
  128. package/src/{plugin/fromRimori → fromRimori}/EventBus.ts +29 -11
  129. package/src/fromRimori/PluginTypes.ts +205 -0
  130. package/src/hooks/UseChatHook.ts +8 -5
  131. package/src/index.ts +6 -3
  132. package/src/plugin/AccomplishmentHandler.ts +1 -1
  133. package/src/plugin/AudioController.ts +58 -0
  134. package/src/plugin/Logger.ts +324 -0
  135. package/src/plugin/PluginController.ts +203 -63
  136. package/src/plugin/RimoriClient.ts +127 -55
  137. package/src/plugin/StandaloneClient.ts +30 -11
  138. package/src/plugin/ThemeSetter.ts +16 -9
  139. package/src/providers/PluginProvider.tsx +46 -13
  140. package/src/utils/Language.ts +4 -2
  141. package/src/utils/difficultyConverter.ts +3 -3
  142. package/src/utils/endpoint.ts +2 -0
  143. package/src/worker/WorkerSetup.ts +13 -60
  144. package/dist/components/PluginController.d.ts +0 -21
  145. package/dist/components/PluginController.js +0 -116
  146. package/dist/controller/AIController.d.ts +0 -23
  147. package/dist/controller/AIController.js +0 -93
  148. package/dist/controller/SidePluginController.d.ts +0 -3
  149. package/dist/controller/SidePluginController.js +0 -31
  150. package/dist/controller/VoiceController.d.ts +0 -10
  151. package/dist/core.d.ts +0 -7
  152. package/dist/core.js +0 -7
  153. package/dist/plugin/ContextMenu.d.ts +0 -17
  154. package/dist/plugin/ContextMenu.js +0 -45
  155. package/dist/plugin/fromRimori/PluginTypes.d.ts +0 -48
  156. package/dist/plugin/fromRimori/SupabaseHandler.d.ts +0 -13
  157. package/dist/plugin/fromRimori/SupabaseHandler.js +0 -55
  158. package/dist/providers/PluginController.d.ts +0 -21
  159. package/dist/providers/PluginController.js +0 -116
  160. package/dist/types/Actions.d.ts +0 -4
  161. package/dist/types/Actions.js +0 -1
  162. package/src/controller/AIController.ts +0 -112
  163. package/src/controller/ObjectController.ts +0 -107
  164. package/src/controller/SidePluginController.ts +0 -25
  165. package/src/controller/VoiceController.ts +0 -26
  166. package/src/core.ts +0 -8
  167. package/src/plugin/fromRimori/PluginTypes.ts +0 -64
  168. package/src/types/Actions.ts +0 -6
  169. /package/dist/{core → components}/components/ContextMenu.d.ts +0 -0
  170. /package/dist/{plugin/fromRimori → fromRimori}/PluginTypes.js +0 -0
  171. /package/src/{plugin/fromRimori → fromRimori}/readme.md +0 -0
@@ -8,41 +8,106 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
8
8
  });
9
9
  };
10
10
  import { createClient } from '@supabase/supabase-js';
11
- import { EventBus } from './fromRimori/EventBus';
11
+ import { EventBus } from '../fromRimori/EventBus';
12
12
  import { RimoriClient } from "./RimoriClient";
13
- import { setTheme } from './ThemeSetter';
14
13
  import { StandaloneClient } from './StandaloneClient';
14
+ import { setTheme } from './ThemeSetter';
15
+ import { Logger } from './Logger';
15
16
  export class PluginController {
16
17
  constructor(pluginId, standalone) {
17
- this.communicationSecret = null;
18
+ this.port = null;
19
+ this.queryParams = {};
18
20
  this.supabase = null;
19
- this.supabaseInfo = null;
21
+ this.rimoriInfo = null;
22
+ this.isMessageChannelReady = false;
23
+ this.pendingRequests = [];
20
24
  this.pluginId = pluginId;
21
25
  this.getClient = this.getClient.bind(this);
22
26
  if (typeof WorkerGlobalScope === 'undefined') {
23
- setTheme();
27
+ // In standalone mode, use URL fallback. In iframe mode, theme will be set after MessageChannel init
28
+ if (standalone) {
29
+ setTheme();
30
+ }
24
31
  }
25
- //no need to forward messages to parent in standalone mode
32
+ //no need to forward messages to parent in standalone mode or worker context
26
33
  if (standalone)
27
34
  return;
28
- window.addEventListener("message", (event) => {
29
- // console.log("client: message received", event);
30
- const { topic, sender, data, eventId } = event.data.event;
31
- // skip forwarding messages from own plugin
32
- if (sender === pluginId)
33
- return;
34
- EventBus.emit(sender, topic, data, eventId);
35
- });
36
- const secret = this.getSecret();
37
- EventBus.on("*", (event) => {
38
- // skip messages which are not from the own plugin
39
- if (event.sender !== this.pluginId)
40
- return;
41
- if (event.topic.startsWith("self."))
35
+ this.initMessageChannel(typeof WorkerGlobalScope !== 'undefined');
36
+ }
37
+ initMessageChannel(worker = false) {
38
+ const listener = (event) => {
39
+ console.log("[PluginController] window message", { origin: event.origin, data: event.data });
40
+ const { type, pluginId, queryParams, rimoriInfo } = event.data || {};
41
+ const [transferredPort] = event.ports || [];
42
+ if (type !== "rimori:init" || !transferredPort || pluginId !== this.pluginId) {
43
+ console.log("[PluginController] message ignored (not init or wrong plugin)", { type, pluginId, hasPort: !!transferredPort });
42
44
  return;
43
- // console.log("sending event to parent", event);
44
- window.parent.postMessage({ event, secret }, "*");
45
- });
45
+ }
46
+ this.queryParams = queryParams || {};
47
+ this.port = transferredPort;
48
+ // Initialize Supabase client immediately with provided info
49
+ if (rimoriInfo) {
50
+ this.rimoriInfo = rimoriInfo;
51
+ this.supabase = createClient(rimoriInfo.url, rimoriInfo.key, {
52
+ accessToken: () => Promise.resolve(rimoriInfo.token)
53
+ });
54
+ }
55
+ // Handle messages from parent
56
+ this.port.onmessage = ({ data }) => {
57
+ const { event, type, eventId, response, error } = data || {};
58
+ // no idea why this is needed but it works for now
59
+ if (type === 'response' && eventId) {
60
+ EventBus.emit(this.pluginId, response.topic, response.data, eventId);
61
+ }
62
+ else if (type === 'error' && eventId) {
63
+ EventBus.emit(this.pluginId, 'error', { error }, eventId);
64
+ }
65
+ else if (event) {
66
+ const { topic, sender, data: eventData, eventId } = event;
67
+ if (sender !== this.pluginId) {
68
+ EventBus.emit(sender, topic, eventData, eventId);
69
+ }
70
+ }
71
+ };
72
+ // Set theme from MessageChannel query params
73
+ if (!worker) {
74
+ const theme = this.queryParams['rm_theme'];
75
+ setTheme(theme);
76
+ }
77
+ // Forward plugin events to parent (only after MessageChannel is ready)
78
+ EventBus.on("*", (ev) => {
79
+ var _a;
80
+ if (ev.sender === this.pluginId && !ev.topic.startsWith("self.")) {
81
+ (_a = this.port) === null || _a === void 0 ? void 0 : _a.postMessage({ event: ev });
82
+ }
83
+ });
84
+ // Mark MessageChannel as ready and process pending requests
85
+ this.isMessageChannelReady = true;
86
+ // Process any pending requests
87
+ this.pendingRequests.forEach(request => request());
88
+ this.pendingRequests = [];
89
+ };
90
+ if (worker) {
91
+ self.onmessage = listener;
92
+ }
93
+ else {
94
+ window.addEventListener("message", listener);
95
+ }
96
+ this.sendHello(worker);
97
+ }
98
+ sendHello(isWorker = false) {
99
+ try {
100
+ const payload = { type: "rimori:hello", pluginId: this.pluginId };
101
+ if (isWorker) {
102
+ self.postMessage(payload);
103
+ }
104
+ else {
105
+ window.parent.postMessage(payload, "*");
106
+ }
107
+ }
108
+ catch (e) {
109
+ console.error("[PluginController] Error sending hello:", e);
110
+ }
46
111
  }
47
112
  static getInstance(pluginId_1) {
48
113
  return __awaiter(this, arguments, void 0, function* (pluginId, standalone = false) {
@@ -52,54 +117,118 @@ export class PluginController {
52
117
  }
53
118
  PluginController.instance = new PluginController(pluginId, standalone);
54
119
  PluginController.client = yield RimoriClient.getInstance(PluginController.instance);
120
+ //only init logger in workers and on main plugin pages
121
+ if (PluginController.instance.getQueryParam("applicationMode") !== "sidebar") {
122
+ Logger.getInstance(PluginController.client);
123
+ }
55
124
  }
56
125
  return PluginController.client;
57
126
  });
58
127
  }
59
- getSecret() {
60
- if (!this.communicationSecret) {
61
- const secret = new URLSearchParams(window.location.search).get("secret");
62
- if (!secret) {
63
- console.info("Communication secret not found in URL as query parameter");
64
- }
65
- this.communicationSecret = secret;
66
- }
67
- return this.communicationSecret;
128
+ getQueryParam(key) {
129
+ return this.queryParams[key] || null;
68
130
  }
69
131
  getClient() {
70
132
  return __awaiter(this, void 0, void 0, function* () {
71
- if (this.supabase &&
72
- this.supabaseInfo &&
73
- this.supabaseInfo.expiration > new Date()) {
74
- return { supabase: this.supabase, tablePrefix: this.supabaseInfo.tablePrefix, pluginId: this.supabaseInfo.pluginId };
133
+ // Return cached client if valid
134
+ if (this.supabase && this.rimoriInfo && this.rimoriInfo.expiration > new Date()) {
135
+ return { supabase: this.supabase, info: this.rimoriInfo };
75
136
  }
76
- const { data } = yield EventBus.request(this.pluginId, "global.supabase.requestAccess");
77
- this.supabaseInfo = data;
78
- this.supabase = createClient(this.supabaseInfo.url, this.supabaseInfo.key, {
79
- accessToken: () => Promise.resolve(this.getToken())
80
- });
81
- return { supabase: this.supabase, tablePrefix: this.supabaseInfo.tablePrefix, pluginId: this.supabaseInfo.pluginId };
137
+ // If MessageChannel is not ready yet, queue the request
138
+ if (!this.isMessageChannelReady) {
139
+ return new Promise((resolve) => {
140
+ this.pendingRequests.push(() => __awaiter(this, void 0, void 0, function* () {
141
+ const result = yield this.getClient();
142
+ resolve(result);
143
+ }));
144
+ });
145
+ }
146
+ // If we have rimoriInfo from MessageChannel init, use it directly
147
+ if (this.rimoriInfo && this.supabase) {
148
+ return { supabase: this.supabase, info: this.rimoriInfo };
149
+ }
150
+ // Fallback: request from parent
151
+ if (!this.rimoriInfo) {
152
+ if (typeof WorkerGlobalScope !== 'undefined') {
153
+ // In worker context, send request via self.postMessage to WorkerHandler
154
+ const eventId = Math.floor(Math.random() * 1000000000);
155
+ const requestEvent = {
156
+ event: {
157
+ timestamp: new Date().toISOString(),
158
+ eventId,
159
+ sender: this.pluginId,
160
+ topic: 'global.supabase.requestAccess',
161
+ data: {},
162
+ debug: false
163
+ }
164
+ };
165
+ return new Promise((resolve) => {
166
+ // Listen for the response
167
+ const originalOnMessage = self.onmessage;
168
+ self.onmessage = (event) => {
169
+ var _a, _b;
170
+ if (((_a = event.data) === null || _a === void 0 ? void 0 : _a.topic) === 'global.supabase.requestAccess' && ((_b = event.data) === null || _b === void 0 ? void 0 : _b.eventId) === eventId) {
171
+ this.rimoriInfo = event.data.data;
172
+ this.supabase = createClient(this.rimoriInfo.url, this.rimoriInfo.key, {
173
+ accessToken: () => Promise.resolve(this.getToken())
174
+ });
175
+ self.onmessage = originalOnMessage; // Restore original handler
176
+ resolve({ supabase: this.supabase, info: this.rimoriInfo });
177
+ }
178
+ else if (originalOnMessage) {
179
+ originalOnMessage.call(self, event);
180
+ }
181
+ };
182
+ // Send the request
183
+ self.postMessage(requestEvent);
184
+ });
185
+ }
186
+ else {
187
+ // In main thread context, use EventBus
188
+ const { data } = yield EventBus.request(this.pluginId, "global.supabase.requestAccess");
189
+ this.rimoriInfo = data;
190
+ this.supabase = createClient(this.rimoriInfo.url, this.rimoriInfo.key, {
191
+ accessToken: () => Promise.resolve(this.getToken())
192
+ });
193
+ }
194
+ }
195
+ return { supabase: this.supabase, info: this.rimoriInfo };
82
196
  });
83
197
  }
84
198
  getToken() {
85
199
  return __awaiter(this, void 0, void 0, function* () {
86
- if (this.supabaseInfo && this.supabaseInfo.expiration && this.supabaseInfo.expiration > new Date()) {
87
- return this.supabaseInfo.token;
200
+ if (this.rimoriInfo && this.rimoriInfo.expiration && this.rimoriInfo.expiration > new Date()) {
201
+ return this.rimoriInfo.token;
88
202
  }
89
- const { data } = yield EventBus.request(this.pluginId, "global.supabase.requestAccess");
90
- if (!this.supabaseInfo) {
91
- throw new Error("Supabase info not found");
203
+ // If we don't have rimoriInfo, request it
204
+ if (!this.rimoriInfo) {
205
+ const { data } = yield EventBus.request(this.pluginId, "global.supabase.requestAccess");
206
+ this.rimoriInfo = data;
207
+ return this.rimoriInfo.token;
92
208
  }
93
- this.supabaseInfo.token = data.token;
94
- this.supabaseInfo.expiration = data.expiration;
95
- return this.supabaseInfo.token;
209
+ // If token is expired, request fresh access
210
+ const { data } = yield EventBus.request(this.pluginId, "global.supabase.requestAccess");
211
+ this.rimoriInfo.token = data.token;
212
+ this.rimoriInfo.expiration = data.expiration;
213
+ return this.rimoriInfo.token;
96
214
  });
97
215
  }
216
+ /**
217
+ * Gets the Supabase URL.
218
+ * @returns The Supabase URL.
219
+ * @deprecated All endpoints should use the backend URL instead.
220
+ */
98
221
  getSupabaseUrl() {
99
- if (!this.supabaseInfo) {
222
+ if (!this.rimoriInfo) {
100
223
  throw new Error("Supabase info not found");
101
224
  }
102
- return this.supabaseInfo.url;
225
+ return this.rimoriInfo.url;
226
+ }
227
+ getBackendUrl() {
228
+ if (!this.rimoriInfo) {
229
+ throw new Error("Rimori info not found");
230
+ }
231
+ return this.rimoriInfo.backendUrl;
103
232
  }
104
233
  getGlobalEventTopic(preliminaryTopic) {
105
234
  var _a, _b;
@@ -119,7 +248,7 @@ export class PluginController {
119
248
  else if (topicParts.length > 3) {
120
249
  throw new Error(`The event topic must consist of 3 parts. <pluginId>.<topic area>.<action>. Received: ${preliminaryTopic}`);
121
250
  }
122
- const topicRoot = (_b = (_a = this.supabaseInfo) === null || _a === void 0 ? void 0 : _a.pluginId) !== null && _b !== void 0 ? _b : "global";
251
+ const topicRoot = (_b = (_a = this.rimoriInfo) === null || _a === void 0 ? void 0 : _a.pluginId) !== null && _b !== void 0 ? _b : "global";
123
252
  return `${topicRoot}.${preliminaryTopic}`;
124
253
  }
125
254
  }
@@ -1,20 +1,18 @@
1
1
  import { PostgrestQueryBuilder } from "@supabase/postgrest-js";
2
- import { SupabaseClient } from "@supabase/supabase-js";
3
2
  import { GenericSchema } from "@supabase/supabase-js/dist/module/lib/types";
4
- import { Message, OnLLMResponse, Tool } from "../controller/AIController";
5
- import { ObjectRequest } from "../controller/ObjectController";
6
- import { UserInfo } from "../controller/SettingsController";
7
- import { SharedContent, SharedContentFilter, SharedContentObjectRequest } from "../controller/SharedContentController";
3
+ import { Message, OnLLMResponse } from "../core/controller/AIController";
4
+ import { ObjectRequest } from "../core/controller/ObjectController";
5
+ import { UserInfo } from "../core/controller/SettingsController";
6
+ import { SharedContent, SharedContentFilter, SharedContentObjectRequest } from "../core/controller/SharedContentController";
7
+ import { EventBusMessage, EventHandler, EventPayload } from "../fromRimori/EventBus";
8
+ import { ActivePlugin, MainPanelAction, Plugin, Tool } from "../fromRimori/PluginTypes";
8
9
  import { AccomplishmentPayload } from "./AccomplishmentHandler";
9
- import { EventBusMessage, EventHandler, EventPayload } from "./fromRimori/EventBus";
10
- import { Plugin } from "./fromRimori/PluginTypes";
11
10
  import { PluginController } from "./PluginController";
12
11
  interface Db {
13
12
  from: {
14
13
  <TableName extends string & keyof GenericSchema['Tables'], Table extends GenericSchema['Tables'][TableName]>(relation: TableName): PostgrestQueryBuilder<GenericSchema, Table, TableName>;
15
14
  <ViewName extends string & keyof GenericSchema['Views'], View extends GenericSchema['Views'][ViewName]>(relation: ViewName): PostgrestQueryBuilder<GenericSchema, View, ViewName>;
16
15
  };
17
- storage: SupabaseClient["storage"];
18
16
  /**
19
17
  * The table prefix for of database tables of the plugin.
20
18
  */
@@ -38,11 +36,26 @@ interface PluginInterface {
38
36
  */
39
37
  getSettings: <T extends object>(defaultSettings: T) => Promise<T>;
40
38
  /**
41
- * Fetches all installed plugins.
42
- * @returns A promise that resolves to an array of plugins
43
- */
44
- getInstalled: () => Promise<Plugin[]>;
45
- getUserInfo: () => Promise<UserInfo>;
39
+ * Retrieves information about plugins, including:
40
+ * - All installed plugins
41
+ * - The currently active plugin in the main panel
42
+ * - The currently active plugin in the side panel
43
+ */
44
+ getPluginInfo: () => {
45
+ /**
46
+ * All installed plugins.
47
+ */
48
+ installedPlugins: Plugin[];
49
+ /**
50
+ * The plugin that is loaded in the main panel.
51
+ */
52
+ mainPanelPlugin?: ActivePlugin;
53
+ /**
54
+ * The plugin that is loaded in the side panel.
55
+ */
56
+ sidePanelPlugin?: ActivePlugin;
57
+ };
58
+ getUserInfo: () => UserInfo;
46
59
  }
47
60
  export declare class RimoriClient {
48
61
  private static instance;
@@ -51,9 +64,9 @@ export declare class RimoriClient {
51
64
  private settingsController;
52
65
  private sharedContentController;
53
66
  private accomplishmentHandler;
54
- private supabaseUrl;
55
- db: Db;
67
+ private rimoriInfo;
56
68
  plugin: PluginInterface;
69
+ db: Db;
57
70
  private constructor();
58
71
  event: {
59
72
  /**
@@ -78,9 +91,9 @@ export declare class RimoriClient {
78
91
  * Subscribe to an event.
79
92
  * @param topic The topic to subscribe to.
80
93
  * @param callback The callback to call when the event is emitted.
81
- * @returns The unsubscribe ids.
94
+ * @returns An EventListener object containing an off() method to unsubscribe the listeners.
82
95
  */
83
- on: <T = EventPayload>(topic: string | string[], callback: EventHandler<T>) => import("./fromRimori/EventBus").EventListener[];
96
+ on: <T = EventPayload>(topic: string | string[], callback: EventHandler<T>) => import("../fromRimori/EventBus").EventListener;
84
97
  /**
85
98
  * Subscribe to an event once.
86
99
  * @param topic The topic to subscribe to.
@@ -92,7 +105,7 @@ export declare class RimoriClient {
92
105
  * @param topic The topic to respond to.
93
106
  * @param data The data to respond with.
94
107
  */
95
- respond: <T = EventPayload>(topic: string, data: EventPayload | ((data: EventBusMessage<T>) => EventPayload | Promise<EventPayload>)) => void;
108
+ respond: <T = EventPayload>(topic: string | string[], data: EventPayload | ((data: EventBusMessage<T>) => EventPayload | Promise<EventPayload>)) => void;
96
109
  /**
97
110
  * Emit an accomplishment.
98
111
  * @param payload The payload to emit.
@@ -111,17 +124,30 @@ export declare class RimoriClient {
111
124
  * @param text Optional text to be used for the action like for example text that the translator would look up.
112
125
  */
113
126
  emitSidebarAction: (pluginId: string, actionKey: string, text?: string) => void;
127
+ onMainPanelAction: (callback: (data: MainPanelAction) => void) => void;
114
128
  };
129
+ navigation: {
130
+ toDashboard: () => void;
131
+ };
132
+ /**
133
+ * Get a query parameter value that was passed via MessageChannel
134
+ * @param key The query parameter key
135
+ * @returns The query parameter value or null if not found
136
+ */
137
+ getQueryParam(key: string): string | null;
115
138
  static getInstance(pluginController: PluginController): Promise<RimoriClient>;
116
139
  private from;
117
140
  private getTableName;
118
- llm: {
141
+ ai: {
119
142
  getText: (messages: Message[], tools?: Tool[]) => Promise<string>;
120
143
  getSteamedText: (messages: Message[], onMessage: OnLLMResponse, tools?: Tool[]) => Promise<void>;
121
144
  getVoice: (text: string, voice?: string, speed?: number, language?: string) => Promise<Blob>;
122
145
  getTextFromVoice: (file: Blob) => Promise<string>;
123
146
  getObject: (request: ObjectRequest) => Promise<any>;
124
147
  };
148
+ runtime: {
149
+ fetchBackend: (url: string, options: RequestInit) => Promise<Response>;
150
+ };
125
151
  community: {
126
152
  /**
127
153
  * Shared content is a way to share completable content with other users using this plugin.
@@ -149,10 +175,19 @@ export declare class RimoriClient {
149
175
  * @param contentType The type of shared content to fetch. E.g. assignments, exercises, etc.
150
176
  * @param generatorInstructions The instructions for the creation of new shared content. The object will automatically be extended with a tool property with a topic and keywords property to let a new unique topic be generated.
151
177
  * @param filter The optional additional filter for checking new shared content based on a column and value. This is useful if the aditional information stored on the shared content is used to further narrow down the kind of shared content wanted to be received. E.g. only adjective grammar exercises.
152
- * @param privateTopic An optional flag to indicate if the topic should be private and only be visible to the user. This is useful if the topic is not meant to be shared with other users. Like for personal topics or if the content is based on the personal study goal.
178
+ * @param options An optional object with options for the new shared content.
179
+ * @param options.privateTopic An optional flag to indicate if the topic should be private and only be visible to the user. This is useful if the topic is not meant to be shared with other users. Like for personal topics or if the content is based on the personal study goal.
180
+ * @param options.skipDbSave An optional flag to indicate if the new shared content should not be saved to the database. This is useful if the new shared content is not meant to be saved to the database.
181
+ * @param options.alwaysGenerateNew An optional flag to indicate if the new shared content should always be generated even if there is already a content with the same filter. This is useful if the new shared content is not meant to be saved to the database.
182
+ * @param options.excludeIds An optional list of ids to exclude from the selection. This is useful if the new shared content is not meant to be saved to the database.
153
183
  * @returns The new shared content.
154
184
  */
155
- getNew: <T = any>(contentType: string, generatorInstructions: SharedContentObjectRequest, filter?: SharedContentFilter, privateTopic?: boolean) => Promise<SharedContent<T>>;
185
+ getNew: <T = any>(contentType: string, generatorInstructions: SharedContentObjectRequest, filter?: SharedContentFilter, options?: {
186
+ privateTopic?: boolean;
187
+ skipDbSave?: boolean;
188
+ alwaysGenerateNew?: boolean;
189
+ excludeIds?: string[];
190
+ }) => Promise<SharedContent<T>>;
156
191
  /**
157
192
  * Create a new shared content item.
158
193
  * @param content The content to create.
@@ -172,6 +207,18 @@ export declare class RimoriClient {
172
207
  * @param assignmentId The id of the shared content item to complete.
173
208
  */
174
209
  complete: (contentType: string, assignmentId: string) => Promise<void>;
210
+ /**
211
+ /**
212
+ * Update the state of a shared content item for a specific user.
213
+ * Useful for marking content as completed, ongoing, hidden, liked, disliked, or bookmarked.
214
+ */
215
+ updateState: (params: {
216
+ contentType: string;
217
+ id: string;
218
+ state?: "completed" | "ongoing" | "hidden";
219
+ reaction?: "liked" | "disliked" | null;
220
+ bookmarked?: boolean;
221
+ }) => Promise<void>;
175
222
  /**
176
223
  * Remove a shared content item.
177
224
  * @param id The id of the shared content item to remove.