@rimori/client 1.2.0 → 1.3.1
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 +61 -18
- package/dist/cli/scripts/init/dev-registration.js +0 -1
- package/dist/cli/scripts/init/main.d.ts +1 -1
- package/dist/cli/scripts/init/main.js +1 -0
- package/dist/components/LoggerExample.d.ts +6 -0
- package/dist/components/LoggerExample.js +79 -0
- package/dist/components/ai/Assistant.js +2 -2
- package/dist/components/ai/Avatar.js +2 -2
- package/dist/components/ai/EmbeddedAssistent/VoiceRecoder.js +41 -32
- package/dist/components/audio/Playbutton.js +2 -2
- package/dist/components/components/ContextMenu.js +48 -9
- package/dist/core/controller/AIController.js +202 -69
- package/dist/core/controller/AudioController.d.ts +0 -0
- package/dist/core/controller/AudioController.js +1 -0
- package/dist/core/controller/ObjectController.d.ts +2 -2
- package/dist/core/controller/ObjectController.js +8 -8
- package/dist/core/controller/SettingsController.d.ts +16 -0
- package/dist/core/controller/SharedContentController.d.ts +30 -2
- package/dist/core/controller/SharedContentController.js +74 -23
- package/dist/core/controller/VoiceController.d.ts +2 -3
- package/dist/core/controller/VoiceController.js +11 -4
- package/dist/core/core.d.ts +1 -0
- package/dist/fromRimori/EventBus.js +1 -1
- package/dist/fromRimori/PluginTypes.d.ts +7 -4
- package/dist/hooks/UseChatHook.js +6 -4
- package/dist/hooks/UseLogger.d.ts +30 -0
- package/dist/hooks/UseLogger.js +122 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +1 -0
- package/dist/plugin/AudioController.d.ts +37 -0
- package/dist/plugin/AudioController.js +68 -0
- package/dist/plugin/Logger.d.ts +68 -0
- package/dist/plugin/Logger.js +256 -0
- package/dist/plugin/LoggerExample.d.ts +16 -0
- package/dist/plugin/LoggerExample.js +140 -0
- package/dist/plugin/PluginController.d.ts +15 -3
- package/dist/plugin/PluginController.js +162 -39
- package/dist/plugin/RimoriClient.d.ts +55 -13
- package/dist/plugin/RimoriClient.js +60 -23
- package/dist/plugin/StandaloneClient.d.ts +1 -0
- package/dist/plugin/StandaloneClient.js +16 -5
- package/dist/plugin/ThemeSetter.d.ts +2 -2
- package/dist/plugin/ThemeSetter.js +8 -5
- package/dist/providers/PluginProvider.d.ts +1 -1
- package/dist/providers/PluginProvider.js +36 -10
- package/dist/utils/audioFormats.d.ts +26 -0
- package/dist/utils/audioFormats.js +67 -0
- package/dist/worker/WorkerSetup.d.ts +3 -2
- package/dist/worker/WorkerSetup.js +22 -67
- package/package.json +7 -6
- package/src/cli/scripts/init/dev-registration.ts +0 -1
- package/src/cli/scripts/init/main.ts +1 -0
- package/src/components/ai/Assistant.tsx +2 -2
- package/src/components/ai/Avatar.tsx +2 -2
- package/src/components/ai/EmbeddedAssistent/VoiceRecoder.tsx +39 -32
- package/src/components/audio/Playbutton.tsx +2 -2
- package/src/components/components/ContextMenu.tsx +53 -9
- package/src/core/controller/AIController.ts +236 -75
- package/src/core/controller/ObjectController.ts +8 -8
- package/src/core/controller/SettingsController.ts +16 -0
- package/src/core/controller/SharedContentController.ts +87 -25
- package/src/core/controller/VoiceController.ts +24 -19
- package/src/core/core.ts +1 -0
- package/src/fromRimori/EventBus.ts +1 -1
- package/src/fromRimori/PluginTypes.ts +6 -4
- package/src/hooks/UseChatHook.ts +6 -4
- package/src/index.ts +1 -0
- package/src/plugin/AudioController.ts +58 -0
- package/src/plugin/Logger.ts +324 -0
- package/src/plugin/PluginController.ts +171 -43
- package/src/plugin/RimoriClient.ts +95 -30
- package/src/plugin/StandaloneClient.ts +22 -6
- package/src/plugin/ThemeSetter.ts +8 -5
- package/src/providers/PluginProvider.tsx +40 -10
- 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
|
-
|
|
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(
|
|
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 (
|
|
58
|
+
if (isSidebar) return;
|
|
43
59
|
|
|
44
|
-
let lastHash =
|
|
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
|
|
101
|
+
export const useRimori = () => {
|
|
86
102
|
const context = useContext(PluginContext);
|
|
87
103
|
if (context === null) {
|
|
88
|
-
throw new Error('
|
|
104
|
+
throw new Error('useRimori must be used within an PluginProvider');
|
|
89
105
|
}
|
|
90
106
|
return context;
|
|
91
107
|
};
|
|
92
108
|
|
|
93
|
-
function
|
|
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
|
-
|
|
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
|
-
|
|
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
|
|
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: (
|
|
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: {
|
|
15
|
+
location: {},
|
|
18
16
|
parent: {
|
|
19
|
-
postMessage: (
|
|
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
|
-
|
|
42
|
-
|
|
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
|
-
|
|
73
|
-
|
|
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
|
-
|
|
80
|
-
if (debugEnabled) {
|
|
81
|
-
console.debug('[Worker] ' + args[0], ...args.slice(1));
|
|
82
|
-
}
|
|
33
|
+
self.postMessage({ type: "rimori:acknowledged", pluginId: pluginId });
|
|
83
34
|
}
|