@rimori/client 1.2.0 → 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 (75) hide show
  1. package/README.md +61 -18
  2. package/dist/cli/scripts/init/dev-registration.js +0 -1
  3. package/dist/cli/scripts/init/main.d.ts +1 -1
  4. package/dist/cli/scripts/init/main.js +1 -0
  5. package/dist/components/LoggerExample.d.ts +6 -0
  6. package/dist/components/LoggerExample.js +79 -0
  7. package/dist/components/ai/Assistant.js +2 -2
  8. package/dist/components/ai/Avatar.js +2 -2
  9. package/dist/components/ai/EmbeddedAssistent/VoiceRecoder.js +41 -32
  10. package/dist/components/audio/Playbutton.js +2 -2
  11. package/dist/components/components/ContextMenu.js +48 -9
  12. package/dist/core/controller/AIController.js +202 -69
  13. package/dist/core/controller/AudioController.d.ts +0 -0
  14. package/dist/core/controller/AudioController.js +1 -0
  15. package/dist/core/controller/ObjectController.d.ts +2 -2
  16. package/dist/core/controller/ObjectController.js +8 -8
  17. package/dist/core/controller/SettingsController.d.ts +16 -0
  18. package/dist/core/controller/SharedContentController.d.ts +30 -2
  19. package/dist/core/controller/SharedContentController.js +74 -23
  20. package/dist/core/controller/VoiceController.d.ts +2 -3
  21. package/dist/core/controller/VoiceController.js +11 -4
  22. package/dist/core/core.d.ts +1 -0
  23. package/dist/fromRimori/EventBus.js +1 -1
  24. package/dist/fromRimori/PluginTypes.d.ts +7 -4
  25. package/dist/hooks/UseChatHook.js +6 -4
  26. package/dist/hooks/UseLogger.d.ts +30 -0
  27. package/dist/hooks/UseLogger.js +122 -0
  28. package/dist/index.d.ts +1 -0
  29. package/dist/index.js +1 -0
  30. package/dist/plugin/AudioController.d.ts +37 -0
  31. package/dist/plugin/AudioController.js +68 -0
  32. package/dist/plugin/Logger.d.ts +68 -0
  33. package/dist/plugin/Logger.js +256 -0
  34. package/dist/plugin/LoggerExample.d.ts +16 -0
  35. package/dist/plugin/LoggerExample.js +140 -0
  36. package/dist/plugin/PluginController.d.ts +15 -3
  37. package/dist/plugin/PluginController.js +162 -39
  38. package/dist/plugin/RimoriClient.d.ts +55 -13
  39. package/dist/plugin/RimoriClient.js +60 -23
  40. package/dist/plugin/StandaloneClient.d.ts +1 -0
  41. package/dist/plugin/StandaloneClient.js +16 -5
  42. package/dist/plugin/ThemeSetter.d.ts +2 -2
  43. package/dist/plugin/ThemeSetter.js +8 -5
  44. package/dist/providers/PluginProvider.d.ts +1 -1
  45. package/dist/providers/PluginProvider.js +36 -10
  46. package/dist/utils/audioFormats.d.ts +26 -0
  47. package/dist/utils/audioFormats.js +67 -0
  48. package/dist/worker/WorkerSetup.d.ts +3 -2
  49. package/dist/worker/WorkerSetup.js +22 -67
  50. package/package.json +2 -1
  51. package/src/cli/scripts/init/dev-registration.ts +0 -1
  52. package/src/cli/scripts/init/main.ts +1 -0
  53. package/src/components/ai/Assistant.tsx +2 -2
  54. package/src/components/ai/Avatar.tsx +2 -2
  55. package/src/components/ai/EmbeddedAssistent/VoiceRecoder.tsx +39 -32
  56. package/src/components/audio/Playbutton.tsx +2 -2
  57. package/src/components/components/ContextMenu.tsx +53 -9
  58. package/src/core/controller/AIController.ts +236 -75
  59. package/src/core/controller/ObjectController.ts +8 -8
  60. package/src/core/controller/SettingsController.ts +16 -0
  61. package/src/core/controller/SharedContentController.ts +87 -25
  62. package/src/core/controller/VoiceController.ts +24 -19
  63. package/src/core/core.ts +1 -0
  64. package/src/fromRimori/EventBus.ts +1 -1
  65. package/src/fromRimori/PluginTypes.ts +6 -4
  66. package/src/hooks/UseChatHook.ts +6 -4
  67. package/src/index.ts +1 -0
  68. package/src/plugin/AudioController.ts +58 -0
  69. package/src/plugin/Logger.ts +324 -0
  70. package/src/plugin/PluginController.ts +171 -43
  71. package/src/plugin/RimoriClient.ts +95 -30
  72. package/src/plugin/StandaloneClient.ts +22 -6
  73. package/src/plugin/ThemeSetter.ts +8 -5
  74. package/src/providers/PluginProvider.tsx +40 -10
  75. package/src/worker/WorkerSetup.ts +14 -63
@@ -18,10 +18,18 @@ const PluginContext = createContext<RimoriClient | null>(null);
18
18
  export const PluginProvider: React.FC<PluginProviderProps> = ({ children, pluginId, settings }) => {
19
19
  const [plugin, setPlugin] = useState<RimoriClient | null>(null);
20
20
  const [standaloneClient, setStandaloneClient] = useState<StandaloneClient | boolean>(false);
21
+ const [applicationMode, setApplicationMode] = useState<string | null>(null);
22
+ const [theme, setTheme] = useState<string | null>(null);
23
+
24
+ const isSidebar = applicationMode === "sidebar";
25
+ const isSettings = applicationMode === "settings";
21
26
 
22
27
  useEffect(() => {
23
28
  initEventBus(pluginId);
24
- const standaloneDetected = new URLSearchParams(window.location.search).get("secret") === null;
29
+
30
+ // Check if we're in an iframe context - if not, we're standalone
31
+ const standaloneDetected = window === window.parent;
32
+
25
33
  if (standaloneDetected && !standaloneClient) {
26
34
  StandaloneClient.getInstance().then(client => {
27
35
  client.needsLogin().then((needLogin) => setStandaloneClient(needLogin ? client : true));
@@ -29,7 +37,16 @@ export const PluginProvider: React.FC<PluginProviderProps> = ({ children, plugin
29
37
  }
30
38
 
31
39
  if ((!standaloneDetected && !plugin) || (standaloneDetected && standaloneClient === true)) {
32
- PluginController.getInstance(pluginId, standaloneDetected).then(setPlugin);
40
+ PluginController.getInstance(pluginId, standaloneDetected).then(client => {
41
+ setPlugin(client);
42
+ // Get applicationMode and theme from MessageChannel query params
43
+ if (!standaloneDetected) {
44
+ const mode = client.getQueryParam("applicationMode");
45
+ const themeParam = client.getQueryParam("rm_theme");
46
+ setApplicationMode(mode);
47
+ setTheme(themeParam);
48
+ }
49
+ });
33
50
  }
34
51
  }, [pluginId, standaloneClient]);
35
52
 
@@ -37,11 +54,10 @@ export const PluginProvider: React.FC<PluginProviderProps> = ({ children, plugin
37
54
  useEffect(() => {
38
55
  if (!plugin) return;
39
56
 
40
- const url = new URL(window.location.href);
41
57
  //sidebar pages should not report url changes
42
- if (url.searchParams.get("applicationMode") === "sidebar") return;
58
+ if (isSidebar) return;
43
59
 
44
- let lastHash = url.hash;
60
+ let lastHash = window.location.hash;
45
61
  const emitUrlChange = (url: string) => plugin.event.emit('session.triggerUrlChange', { url });
46
62
 
47
63
  const interval = setInterval(() => {
@@ -76,23 +92,37 @@ export const PluginProvider: React.FC<PluginProviderProps> = ({ children, plugin
76
92
 
77
93
  return (
78
94
  <PluginContext.Provider value={plugin}>
79
- {!settings?.disableContextMenu && <ContextMenu client={plugin} />}
95
+ {!settings?.disableContextMenu && !isSidebar && !isSettings && <ContextMenu client={plugin} />}
80
96
  {children}
81
97
  </PluginContext.Provider>
82
98
  );
83
99
  };
84
100
 
85
- export const usePlugin = () => {
101
+ export const useRimori = () => {
86
102
  const context = useContext(PluginContext);
87
103
  if (context === null) {
88
- throw new Error('usePlugin must be used within an PluginProvider');
104
+ throw new Error('useRimori must be used within an PluginProvider');
89
105
  }
90
106
  return context;
91
107
  };
92
108
 
93
- function initEventBus(pluginId: string) {
109
+ function getUrlParam(name: string) {
110
+ // First try to get from URL hash query params (for compatibility)
111
+ const hashParts = window.location.hash.split('?');
112
+ if (hashParts.length > 1) {
113
+ const hashParams = new URLSearchParams(hashParts[1]);
114
+ const hashValue = hashParams.get(name);
115
+ if (hashValue) return hashValue;
116
+ }
117
+
118
+ // Fallback to regular URL search params
94
119
  const url = new URL(window.location.href);
95
- const isSidebar = url.searchParams.get("applicationMode") === "sidebar";
120
+ return url.searchParams.get(name);
121
+ }
122
+
123
+ function initEventBus(pluginId: string) {
124
+ // For now, use URL fallback for EventBus naming - this will be updated once MessageChannel is ready
125
+ const isSidebar = getUrlParam("applicationMode") === "sidebar";
96
126
  EventBusHandler.getInstance("Plugin EventBus " + pluginId + " " + (isSidebar ? "sidebar" : "main"));
97
127
  }
98
128
 
@@ -1,36 +1,22 @@
1
- import { EventBus, EventBusHandler, EventBusMessage } from "../fromRimori/EventBus";
2
- import { PluginController } from "../plugin/PluginController";
3
1
  import { RimoriClient } from "../plugin/RimoriClient";
4
-
5
- let controller: RimoriClient | null = null;
6
- const listeners: ((event: { data: { event: EventBusMessage, secret: string } }) => void)[] = [];
7
- let debugEnabled = false;
2
+ import { EventBusHandler } from "../fromRimori/EventBus";
3
+ import { PluginController } from "../plugin/PluginController";
8
4
 
9
5
  /**
10
6
  * Sets up the web worker for the plugin to be able receive and send messages to Rimori.
11
- * @param init - The function containing the subscription logic.
7
+ * @param pluginId - The id of the plugin to setup the worker for.
8
+ * @param init - The function containing the initialization logic.
12
9
  */
13
- export function setupWorker(init: (controller: RimoriClient) => void | Promise<void>) {
10
+ export async function setupWorker(pluginId: string, init: (client: RimoriClient) => void | Promise<void>) {
11
+
14
12
  // Mock of the window object for the worker context to be able to use the PluginController.
15
13
  const mockWindow = {
16
14
  isWorker: true,
17
- location: { search: '?secret=123' },
15
+ location: {},
18
16
  parent: {
19
- postMessage: (message: { event: EventBusMessage }) => {
20
- message.event.sender = "worker." + message.event.sender;
21
- checkDebugMode(message.event);
22
- logIfDebug('sending event to Rimori', message.event);
23
- self.postMessage(message)
24
- }
25
- },
26
- addEventListener: (_: string, listener: any) => {
27
- listeners.push(listener);
28
- },
29
- APP_CONFIG: {
30
- SUPABASE_URL: 'NOT_SET',
31
- SUPABASE_ANON_KEY: 'NOT_SET',
32
- BACKEND_URL: 'NOT_SET',
17
+ postMessage: () => { }
33
18
  },
19
+ addEventListener: () => { }
34
20
  };
35
21
 
36
22
  // Assign the mock to globalThis.
@@ -38,46 +24,11 @@ export function setupWorker(init: (controller: RimoriClient) => void | Promise<v
38
24
 
39
25
  EventBusHandler.getInstance("Worker EventBus");
40
26
 
41
- // Handle init message from Rimori.
42
- self.onmessage = async (response: MessageEvent) => {
43
- checkDebugMode(response.data);
44
- logIfDebug('Message received', response.data);
45
-
46
- const event = response.data as EventBusMessage;
47
-
48
- if (event.topic === 'global.worker.requestInit') {
49
- if (!controller) {
50
- mockWindow.APP_CONFIG.SUPABASE_URL = event.data.supabaseUrl;
51
- mockWindow.APP_CONFIG.SUPABASE_ANON_KEY = event.data.supabaseAnonKey;
52
- mockWindow.APP_CONFIG.BACKEND_URL = event.data.backendUrl;
53
- controller = await PluginController.getInstance(event.data.pluginId);
54
- logIfDebug('Worker initialized.');
55
- await init(controller);
56
- logIfDebug('Plugin listeners initialized.');
57
- }
58
- const initEvent: EventBusMessage = {
59
- timestamp: new Date().toISOString(),
60
- eventId: event.eventId,
61
- sender: "worker." + event.sender,
62
- topic: 'global.worker.requestInit',
63
- data: { success: true },
64
- debug: debugEnabled
65
- };
66
- return self.postMessage({ secret: "123", event: initEvent });
67
- }
68
- listeners.forEach(listener => listener({ data: { event: response.data, secret: "123" } }));
69
- };
70
- }
27
+ const rimoriClient = await PluginController.getInstance(pluginId);
28
+ console.debug('[Worker] RimoriClient initialized.');
71
29
 
72
- function checkDebugMode(event: EventBusMessage) {
73
- if (event.topic === 'global.system.requestDebug' || event.debug) {
74
- debugEnabled = true;
75
- EventBus.emit("worker", "global.system.requestDebug");
76
- }
77
- }
30
+ await init(rimoriClient);
31
+ console.debug('[Worker] Worker initialized.');
78
32
 
79
- function logIfDebug(...args: any[]) {
80
- if (debugEnabled) {
81
- console.debug('[Worker] ' + args[0], ...args.slice(1));
82
- }
33
+ self.postMessage({ type: "rimori:acknowledged", pluginId: pluginId });
83
34
  }