@rimori/react-client 0.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 (139) hide show
  1. package/.prettierignore +35 -0
  2. package/LICENSE +201 -0
  3. package/README copy.md +1216 -0
  4. package/README.md +1 -0
  5. package/dist/components/MarkdownEditor.d.ts +8 -0
  6. package/dist/components/MarkdownEditor.js +48 -0
  7. package/dist/components/Spinner.d.ts +8 -0
  8. package/dist/components/Spinner.js +4 -0
  9. package/dist/components/ai/Assistant.d.ts +9 -0
  10. package/dist/components/ai/Assistant.js +58 -0
  11. package/dist/components/ai/Avatar.d.ts +14 -0
  12. package/dist/components/ai/Avatar.js +59 -0
  13. package/dist/components/ai/EmbeddedAssistent/AudioInputField.d.ts +7 -0
  14. package/dist/components/ai/EmbeddedAssistent/AudioInputField.js +37 -0
  15. package/dist/components/ai/EmbeddedAssistent/CircleAudioAvatar.d.ts +8 -0
  16. package/dist/components/ai/EmbeddedAssistent/CircleAudioAvatar.js +79 -0
  17. package/dist/components/ai/EmbeddedAssistent/TTS/MessageSender.d.ts +19 -0
  18. package/dist/components/ai/EmbeddedAssistent/TTS/MessageSender.js +91 -0
  19. package/dist/components/ai/EmbeddedAssistent/TTS/Player.d.ts +27 -0
  20. package/dist/components/ai/EmbeddedAssistent/TTS/Player.js +185 -0
  21. package/dist/components/ai/EmbeddedAssistent/VoiceRecoder.d.ts +11 -0
  22. package/dist/components/ai/EmbeddedAssistent/VoiceRecoder.js +95 -0
  23. package/dist/components/ai/utils.d.ts +6 -0
  24. package/dist/components/ai/utils.js +13 -0
  25. package/dist/components/audio/Playbutton.d.ts +15 -0
  26. package/dist/components/audio/Playbutton.js +80 -0
  27. package/dist/components/components/ContextMenu.d.ts +10 -0
  28. package/dist/components/components/ContextMenu.js +135 -0
  29. package/dist/hooks/I18nHooks.d.ts +11 -0
  30. package/dist/hooks/I18nHooks.js +25 -0
  31. package/dist/hooks/UseChatHook.d.ts +10 -0
  32. package/dist/hooks/UseChatHook.js +29 -0
  33. package/dist/providers/PluginProvider.d.ts +11 -0
  34. package/dist/providers/PluginProvider.js +142 -0
  35. package/dist/react-client/plugin/ThemeSetter.d.ts +2 -0
  36. package/dist/react-client/plugin/ThemeSetter.js +19 -0
  37. package/dist/react-client/src/components/ContextMenu.d.ts +10 -0
  38. package/dist/react-client/src/components/ContextMenu.js +135 -0
  39. package/dist/react-client/src/components/MarkdownEditor.d.ts +8 -0
  40. package/dist/react-client/src/components/MarkdownEditor.js +48 -0
  41. package/dist/react-client/src/components/Spinner.d.ts +8 -0
  42. package/dist/react-client/src/components/Spinner.js +4 -0
  43. package/dist/react-client/src/components/ai/Assistant.d.ts +9 -0
  44. package/dist/react-client/src/components/ai/Assistant.js +58 -0
  45. package/dist/react-client/src/components/ai/Avatar.d.ts +14 -0
  46. package/dist/react-client/src/components/ai/Avatar.js +59 -0
  47. package/dist/react-client/src/components/ai/EmbeddedAssistent/AudioInputField.d.ts +7 -0
  48. package/dist/react-client/src/components/ai/EmbeddedAssistent/AudioInputField.js +37 -0
  49. package/dist/react-client/src/components/ai/EmbeddedAssistent/CircleAudioAvatar.d.ts +8 -0
  50. package/dist/react-client/src/components/ai/EmbeddedAssistent/CircleAudioAvatar.js +79 -0
  51. package/dist/react-client/src/components/ai/EmbeddedAssistent/TTS/MessageSender.d.ts +19 -0
  52. package/dist/react-client/src/components/ai/EmbeddedAssistent/TTS/MessageSender.js +91 -0
  53. package/dist/react-client/src/components/ai/EmbeddedAssistent/TTS/Player.d.ts +27 -0
  54. package/dist/react-client/src/components/ai/EmbeddedAssistent/TTS/Player.js +185 -0
  55. package/dist/react-client/src/components/ai/EmbeddedAssistent/VoiceRecoder.d.ts +11 -0
  56. package/dist/react-client/src/components/ai/EmbeddedAssistent/VoiceRecoder.js +95 -0
  57. package/dist/react-client/src/components/ai/utils.d.ts +6 -0
  58. package/dist/react-client/src/components/ai/utils.js +13 -0
  59. package/dist/react-client/src/components/audio/Playbutton.d.ts +15 -0
  60. package/dist/react-client/src/components/audio/Playbutton.js +82 -0
  61. package/dist/react-client/src/components/components/ContextMenu.d.ts +10 -0
  62. package/dist/react-client/src/components/components/ContextMenu.js +135 -0
  63. package/dist/react-client/src/hooks/I18nHooks.d.ts +11 -0
  64. package/dist/react-client/src/hooks/I18nHooks.js +25 -0
  65. package/dist/react-client/src/hooks/UseChatHook.d.ts +10 -0
  66. package/dist/react-client/src/hooks/UseChatHook.js +29 -0
  67. package/dist/react-client/src/plugin/ThemeSetter.d.ts +2 -0
  68. package/dist/react-client/src/plugin/ThemeSetter.js +19 -0
  69. package/dist/react-client/src/providers/PluginProvider.d.ts +12 -0
  70. package/dist/react-client/src/providers/PluginProvider.js +142 -0
  71. package/dist/react-client/src/utils/FullscreenUtils.d.ts +2 -0
  72. package/dist/react-client/src/utils/FullscreenUtils.js +23 -0
  73. package/dist/react-client/src/utils/PluginUtils.d.ts +2 -0
  74. package/dist/react-client/src/utils/PluginUtils.js +23 -0
  75. package/dist/rimori-client/src/cli/types/DatabaseTypes.d.ts +103 -0
  76. package/dist/rimori-client/src/cli/types/DatabaseTypes.js +2 -0
  77. package/dist/rimori-client/src/controller/AIController.d.ts +15 -0
  78. package/dist/rimori-client/src/controller/AIController.js +255 -0
  79. package/dist/rimori-client/src/controller/AccomplishmentController.d.ts +38 -0
  80. package/dist/rimori-client/src/controller/AccomplishmentController.js +112 -0
  81. package/dist/rimori-client/src/controller/AudioController.d.ts +37 -0
  82. package/dist/rimori-client/src/controller/AudioController.js +68 -0
  83. package/dist/rimori-client/src/controller/ExerciseController.d.ts +54 -0
  84. package/dist/rimori-client/src/controller/ExerciseController.js +74 -0
  85. package/dist/rimori-client/src/controller/ObjectController.d.ts +42 -0
  86. package/dist/rimori-client/src/controller/ObjectController.js +76 -0
  87. package/dist/rimori-client/src/controller/SettingsController.d.ts +79 -0
  88. package/dist/rimori-client/src/controller/SettingsController.js +118 -0
  89. package/dist/rimori-client/src/controller/SharedContentController.d.ts +106 -0
  90. package/dist/rimori-client/src/controller/SharedContentController.js +285 -0
  91. package/dist/rimori-client/src/controller/TranslationController.d.ts +38 -0
  92. package/dist/rimori-client/src/controller/TranslationController.js +106 -0
  93. package/dist/rimori-client/src/controller/VoiceController.d.ts +9 -0
  94. package/dist/rimori-client/src/controller/VoiceController.js +37 -0
  95. package/dist/rimori-client/src/fromRimori/EventBus.d.ts +101 -0
  96. package/dist/rimori-client/src/fromRimori/EventBus.js +263 -0
  97. package/dist/rimori-client/src/fromRimori/PluginTypes.d.ts +174 -0
  98. package/dist/rimori-client/src/fromRimori/PluginTypes.js +1 -0
  99. package/dist/rimori-client/src/index.d.ts +11 -0
  100. package/dist/rimori-client/src/index.js +10 -0
  101. package/dist/rimori-client/src/plugin/CommunicationHandler.d.ts +48 -0
  102. package/dist/rimori-client/src/plugin/CommunicationHandler.js +234 -0
  103. package/dist/rimori-client/src/plugin/Logger.d.ts +73 -0
  104. package/dist/rimori-client/src/plugin/Logger.js +308 -0
  105. package/dist/rimori-client/src/plugin/RimoriClient.d.ts +258 -0
  106. package/dist/rimori-client/src/plugin/RimoriClient.js +375 -0
  107. package/dist/rimori-client/src/plugin/StandaloneClient.d.ts +17 -0
  108. package/dist/rimori-client/src/plugin/StandaloneClient.js +115 -0
  109. package/dist/rimori-client/src/utils/difficultyConverter.d.ts +4 -0
  110. package/dist/rimori-client/src/utils/difficultyConverter.js +10 -0
  111. package/dist/rimori-client/src/utils/endpoint.d.ts +2 -0
  112. package/dist/rimori-client/src/utils/endpoint.js +2 -0
  113. package/dist/style.css +110 -0
  114. package/dist/style.css.map +1 -0
  115. package/dist/utils/PluginUtils.d.ts +2 -0
  116. package/dist/utils/PluginUtils.js +23 -0
  117. package/eslint.config.js +53 -0
  118. package/index.ts +6 -0
  119. package/package.json +47 -0
  120. package/prettier.config.js +8 -0
  121. package/src/components/ContextMenu.tsx +177 -0
  122. package/src/components/MarkdownEditor.tsx +144 -0
  123. package/src/components/Spinner.tsx +29 -0
  124. package/src/components/ai/Assistant.tsx +96 -0
  125. package/src/components/ai/Avatar.tsx +99 -0
  126. package/src/components/ai/EmbeddedAssistent/AudioInputField.tsx +73 -0
  127. package/src/components/ai/EmbeddedAssistent/CircleAudioAvatar.tsx +107 -0
  128. package/src/components/ai/EmbeddedAssistent/TTS/MessageSender.ts +96 -0
  129. package/src/components/ai/EmbeddedAssistent/TTS/Player.ts +197 -0
  130. package/src/components/ai/EmbeddedAssistent/VoiceRecoder.tsx +129 -0
  131. package/src/components/ai/utils.ts +21 -0
  132. package/src/components/audio/Playbutton.tsx +126 -0
  133. package/src/hooks/I18nHooks.ts +33 -0
  134. package/src/hooks/UseChatHook.ts +38 -0
  135. package/src/plugin/ThemeSetter.ts +23 -0
  136. package/src/providers/PluginProvider.tsx +197 -0
  137. package/src/style.scss +136 -0
  138. package/src/utils/FullscreenUtils.ts +22 -0
  139. package/tsconfig.json +23 -0
@@ -0,0 +1,135 @@
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import { useState, useEffect, useRef } from 'react';
3
+ import { EventBus } from '@rimori/client';
4
+ const ContextMenu = ({ client }) => {
5
+ const [isOpen, setIsOpen] = useState(false);
6
+ const [actions, setActions] = useState([]);
7
+ const [position, setPosition] = useState({ x: 0, y: 0 });
8
+ const [openOnTextSelect, setOpenOnTextSelect] = useState(false);
9
+ const [menuWidth, setMenuWidth] = useState(0);
10
+ const menuRef = useRef(null);
11
+ const isMobile = window.innerWidth < 768;
12
+ /**
13
+ * Calculates position for mobile context menu based on selected text bounds.
14
+ * Centers the menu horizontally over the selected text and positions it 30px below the text's end.
15
+ * @param selectedText - The currently selected text
16
+ * @param menuWidth - The width of the menu to center properly
17
+ * @returns Position object with x and y coordinates
18
+ */
19
+ const calculateMobilePosition = (selectedText, menuWidth = 0) => {
20
+ const selection = window.getSelection();
21
+ if (!selection || !selectedText) {
22
+ return { x: 0, y: 0, text: selectedText };
23
+ }
24
+ const range = selection.getRangeAt(0);
25
+ const rect = range.getBoundingClientRect();
26
+ // Center horizontally over the selected text, accounting for menu width
27
+ const centerX = rect.left + rect.width / 2 - menuWidth / 2;
28
+ // Position 12px below where the text ends vertically
29
+ const textEndY = rect.bottom + 12;
30
+ return { x: centerX, y: textEndY, text: selectedText };
31
+ };
32
+ useEffect(() => {
33
+ const actions = client.plugin
34
+ .getPluginInfo()
35
+ .installedPlugins.flatMap((p) => p.context_menu_actions)
36
+ .filter(Boolean);
37
+ setActions(actions);
38
+ setOpenOnTextSelect(client.plugin.getUserInfo().context_menu_on_select);
39
+ EventBus.on('global.contextMenu.createActions', ({ data }) => {
40
+ setActions([...data.actions, ...actions]);
41
+ });
42
+ }, []);
43
+ // Update menu width when menu is rendered
44
+ useEffect(() => {
45
+ if (isOpen && menuRef.current) {
46
+ setMenuWidth(menuRef.current.offsetWidth);
47
+ }
48
+ }, [isOpen, actions]);
49
+ useEffect(() => {
50
+ // Track mouse position globally
51
+ const handleMouseMove = (e) => {
52
+ var _a;
53
+ const selectedText = (_a = window.getSelection()) === null || _a === void 0 ? void 0 : _a.toString().trim();
54
+ if (isOpen && selectedText === position.text)
55
+ return;
56
+ if (isMobile && selectedText) {
57
+ setPosition(calculateMobilePosition(selectedText, menuWidth));
58
+ }
59
+ else {
60
+ setPosition({ x: e.clientX, y: e.clientY, text: selectedText });
61
+ }
62
+ };
63
+ const handleMouseUp = (e) => {
64
+ var _a, _b;
65
+ const selectedText = (_a = window.getSelection()) === null || _a === void 0 ? void 0 : _a.toString().trim();
66
+ // Check if click is inside the context menu
67
+ if (menuRef.current && menuRef.current.contains(e.target)) {
68
+ // Don't close the menu if clicking inside
69
+ return;
70
+ }
71
+ // Prevent context menu on textarea or text input selection
72
+ const target = e.target;
73
+ const isTextInput = target &&
74
+ (target.tagName === 'TEXTAREA' || (target.tagName === 'INPUT' && target.type === 'text'));
75
+ if (isTextInput) {
76
+ setIsOpen(false);
77
+ return;
78
+ }
79
+ if (e.button === 0 && isOpen) {
80
+ setIsOpen(false);
81
+ (_b = window.getSelection()) === null || _b === void 0 ? void 0 : _b.removeAllRanges();
82
+ }
83
+ else if (selectedText && (openOnTextSelect || e.button === 2)) {
84
+ if (e.button === 2) {
85
+ e.preventDefault();
86
+ }
87
+ if (isMobile) {
88
+ setPosition(calculateMobilePosition(selectedText, menuWidth));
89
+ }
90
+ else {
91
+ setPosition({ x: e.clientX, y: e.clientY, text: selectedText });
92
+ }
93
+ setIsOpen(true);
94
+ }
95
+ else {
96
+ setIsOpen(false);
97
+ }
98
+ };
99
+ // Add selectionchange listener to close menu if selection is cleared and update position for mobile
100
+ const handleSelectionChange = () => {
101
+ var _a;
102
+ const selectedText = (_a = window.getSelection()) === null || _a === void 0 ? void 0 : _a.toString().trim();
103
+ if (!selectedText && isOpen) {
104
+ setIsOpen(false);
105
+ }
106
+ else if (selectedText && isOpen && isMobile) {
107
+ // Update position in real-time as text selection changes on mobile
108
+ setPosition(calculateMobilePosition(selectedText, menuWidth));
109
+ }
110
+ };
111
+ document.addEventListener('mouseup', handleMouseUp);
112
+ window.addEventListener('mousemove', handleMouseMove);
113
+ document.addEventListener('contextmenu', handleMouseUp);
114
+ document.addEventListener('selectionchange', handleSelectionChange);
115
+ return () => {
116
+ document.removeEventListener('mouseup', handleMouseUp);
117
+ window.removeEventListener('mousemove', handleMouseMove);
118
+ document.removeEventListener('contextmenu', handleMouseUp);
119
+ document.removeEventListener('selectionchange', handleSelectionChange);
120
+ };
121
+ }, [openOnTextSelect, isOpen, position.text]);
122
+ if (!isOpen) {
123
+ return null;
124
+ }
125
+ return (_jsx("div", { ref: menuRef, className: "fixed bg-gray-400 dark:bg-gray-700 shadow-lg border border-gray-400 rounded-md overflow-hidden dark:text-white z-50", style: { top: position.y, left: position.x }, children: actions.map((action, index) => (_jsx(MenuEntryItem, { icon: action.icon, text: action.text, onClick: () => {
126
+ var _a;
127
+ setIsOpen(false);
128
+ (_a = window.getSelection()) === null || _a === void 0 ? void 0 : _a.removeAllRanges();
129
+ client.event.emitSidebarAction(action.plugin_id, action.action_key, position.text);
130
+ } }, index))) }));
131
+ };
132
+ function MenuEntryItem(props) {
133
+ return (_jsxs("button", { onClick: props.onClick, className: "px-4 py-2 text-left hover:bg-gray-500 dark:hover:bg-gray-600 w-full flex flex-row", children: [_jsx("span", { className: "flex-grow", children: props.icon }), _jsx("span", { className: "flex-grow", children: props.text })] }));
134
+ }
135
+ export default ContextMenu;
@@ -0,0 +1,11 @@
1
+ import { TOptions } from '@rimori/client';
2
+ type TranslatorFn = (key: string, options?: TOptions) => string;
3
+ /**
4
+ * Custom useTranslation hook that provides a translation function and indicates readiness
5
+ * @returns An object containing the translation function (`t`) and a boolean (`ready`) indicating if the translator is initialized.
6
+ */
7
+ export declare function useTranslation(): {
8
+ t: TranslatorFn;
9
+ ready: boolean;
10
+ };
11
+ export {};
@@ -0,0 +1,25 @@
1
+ import { useEffect, useState } from 'react';
2
+ import { useRimori } from '../providers/PluginProvider';
3
+ /**
4
+ * Custom useTranslation hook that provides a translation function and indicates readiness
5
+ * @returns An object containing the translation function (`t`) and a boolean (`ready`) indicating if the translator is initialized.
6
+ */
7
+ export function useTranslation() {
8
+ const { plugin } = useRimori();
9
+ const [translatorInstance, setTranslatorInstance] = useState(null);
10
+ useEffect(() => {
11
+ void plugin.getTranslator().then(setTranslatorInstance);
12
+ }, [plugin]);
13
+ const safeT = (key, options) => {
14
+ // return zero-width space if translator is not initialized to keep text space occupied
15
+ if (!translatorInstance)
16
+ return '\u200B'; // zero-width space
17
+ const result = translatorInstance.t(key, options);
18
+ if (!result) {
19
+ console.error(`Translation key not found: ${key}`);
20
+ return '\u200B'; // zero-width space
21
+ }
22
+ return result;
23
+ };
24
+ return { t: safeT, ready: translatorInstance !== null };
25
+ }
@@ -0,0 +1,10 @@
1
+ import React from 'react';
2
+ import { Tool } from '@rimori/client';
3
+ import { Message } from '@rimori/client';
4
+ export declare function useChat(tools?: Tool[]): {
5
+ messages: Message[];
6
+ append: (appendMessages: Message[]) => void;
7
+ isLoading: boolean;
8
+ setMessages: React.Dispatch<React.SetStateAction<Message[]>>;
9
+ lastMessage: Message | undefined;
10
+ };
@@ -0,0 +1,29 @@
1
+ import React from 'react';
2
+ import { useRimori } from '../providers/PluginProvider';
3
+ export function useChat(tools) {
4
+ const [messages, setMessages] = React.useState([]);
5
+ const [isLoading, setIsLoading] = React.useState(false);
6
+ const { ai } = useRimori();
7
+ const append = (appendMessages) => {
8
+ const allMessages = [...messages, ...appendMessages];
9
+ setMessages(allMessages);
10
+ ai.getSteamedText(allMessages, (id, message, finished, toolInvocations) => {
11
+ const lastMessage = messages[messages.length - 1];
12
+ setIsLoading(!finished);
13
+ if ((lastMessage === null || lastMessage === void 0 ? void 0 : lastMessage.id) === id) {
14
+ lastMessage.content = message;
15
+ setMessages([...messages, lastMessage]);
16
+ }
17
+ else {
18
+ setMessages([...allMessages, { id, role: 'assistant', content: message, toolCalls: toolInvocations }]);
19
+ }
20
+ }, tools);
21
+ };
22
+ return {
23
+ messages,
24
+ append,
25
+ isLoading,
26
+ setMessages,
27
+ lastMessage: messages[messages.length - 1],
28
+ };
29
+ }
@@ -0,0 +1,2 @@
1
+ export declare function setTheme(theme?: string | null): void;
2
+ export declare function isDarkTheme(theme?: string | null): boolean;
@@ -0,0 +1,19 @@
1
+ export function setTheme(theme) {
2
+ document.documentElement.classList.add('dark:text-gray-200');
3
+ if (isDarkTheme(theme)) {
4
+ document.documentElement.setAttribute('data-theme', 'dark');
5
+ document.documentElement.classList.add('dark', 'dark:bg-gray-950');
6
+ document.documentElement.style.background = 'hsl(var(--background))';
7
+ }
8
+ }
9
+ export function isDarkTheme(theme) {
10
+ // If no theme provided, try to get from URL as fallback (for standalone mode)
11
+ if (!theme) {
12
+ const urlParams = new URLSearchParams(window.location.search);
13
+ theme = urlParams.get('theme');
14
+ }
15
+ if (!theme || theme === 'system') {
16
+ return window.matchMedia && window.matchMedia('(prefers-color-scheme: dark)').matches;
17
+ }
18
+ return theme === 'dark';
19
+ }
@@ -0,0 +1,12 @@
1
+ import React, { ReactNode } from 'react';
2
+ import { RimoriClient } from '@rimori/client';
3
+ interface PluginProviderProps {
4
+ children: ReactNode;
5
+ pluginId: string;
6
+ settings?: {
7
+ disableContextMenu?: boolean;
8
+ };
9
+ }
10
+ export declare const PluginProvider: React.FC<PluginProviderProps>;
11
+ export declare const useRimori: () => RimoriClient;
12
+ export {};
@@ -0,0 +1,142 @@
1
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3
+ return new (P || (P = Promise))(function (resolve, reject) {
4
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
5
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
6
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
7
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
8
+ });
9
+ };
10
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
11
+ import { createContext, useContext, useEffect, useState } from 'react';
12
+ import { EventBusHandler, RimoriClient, StandaloneClient } from '@rimori/client';
13
+ import ContextMenu from '../components/ContextMenu';
14
+ const PluginContext = createContext(null);
15
+ export const PluginProvider = ({ children, pluginId, settings }) => {
16
+ const [plugin, setPlugin] = useState(null);
17
+ const [standaloneClient, setStandaloneClient] = useState(false);
18
+ const [applicationMode, setApplicationMode] = useState(null);
19
+ const [theme, setTheme] = useState(null);
20
+ const isSidebar = applicationMode === 'sidebar';
21
+ const isSettings = applicationMode === 'settings';
22
+ useEffect(() => {
23
+ initEventBus(pluginId);
24
+ // Check if we're in an iframe context - if not, we're standalone
25
+ const standaloneDetected = window === window.parent;
26
+ if (standaloneDetected && !standaloneClient) {
27
+ StandaloneClient.getInstance().then((client) => {
28
+ client.needsLogin().then((needLogin) => setStandaloneClient(needLogin ? client : true));
29
+ });
30
+ }
31
+ if ((!standaloneDetected && !plugin) || (standaloneDetected && standaloneClient === true)) {
32
+ RimoriClient.getInstance(pluginId).then((client) => {
33
+ setPlugin(client);
34
+ // Get applicationMode and theme from MessageChannel query params
35
+ if (!standaloneDetected) {
36
+ const mode = client.getQueryParam('applicationMode');
37
+ const themeParam = client.getQueryParam('rm_theme');
38
+ setApplicationMode(mode);
39
+ setTheme(themeParam);
40
+ }
41
+ });
42
+ }
43
+ }, [pluginId, standaloneClient]);
44
+ //route change
45
+ useEffect(() => {
46
+ if (!plugin)
47
+ return;
48
+ //sidebar pages should not report url changes
49
+ if (isSidebar)
50
+ return;
51
+ let lastHash = window.location.hash;
52
+ const emitUrlChange = (url) => plugin.event.emit('session.triggerUrlChange', { url });
53
+ const interval = setInterval(() => {
54
+ if (lastHash === window.location.hash)
55
+ return;
56
+ lastHash = window.location.hash;
57
+ // console.log('url changed:', lastHash);
58
+ emitUrlChange(lastHash);
59
+ }, 1000);
60
+ emitUrlChange(lastHash);
61
+ return () => clearInterval(interval);
62
+ }, [plugin]);
63
+ if (standaloneClient instanceof StandaloneClient) {
64
+ return (_jsx(StandaloneAuth, { onLogin: (email, password) => __awaiter(void 0, void 0, void 0, function* () {
65
+ if (yield standaloneClient.login(email, password))
66
+ setStandaloneClient(true);
67
+ }) }));
68
+ }
69
+ if (!plugin) {
70
+ return '';
71
+ }
72
+ return (_jsxs(PluginContext.Provider, { value: plugin, children: [!(settings === null || settings === void 0 ? void 0 : settings.disableContextMenu) && !isSidebar && !isSettings && _jsx(ContextMenu, { client: plugin }), children] }));
73
+ };
74
+ export const useRimori = () => {
75
+ const context = useContext(PluginContext);
76
+ if (context === null) {
77
+ throw new Error('useRimori must be used within an PluginProvider');
78
+ }
79
+ return context;
80
+ };
81
+ function getUrlParam(name) {
82
+ // First try to get from URL hash query params (for compatibility)
83
+ const hashParts = window.location.hash.split('?');
84
+ if (hashParts.length > 1) {
85
+ const hashParams = new URLSearchParams(hashParts[1]);
86
+ const hashValue = hashParams.get(name);
87
+ if (hashValue)
88
+ return hashValue;
89
+ }
90
+ // Fallback to regular URL search params
91
+ const url = new URL(window.location.href);
92
+ return url.searchParams.get(name);
93
+ }
94
+ function initEventBus(pluginId) {
95
+ // For now, use URL fallback for EventBus naming - this will be updated once MessageChannel is ready
96
+ const isSidebar = getUrlParam('applicationMode') === 'sidebar';
97
+ EventBusHandler.getInstance('Plugin EventBus ' + pluginId + ' ' + (isSidebar ? 'sidebar' : 'main'));
98
+ }
99
+ function StandaloneAuth({ onLogin }) {
100
+ const [user, setUser] = useState('');
101
+ const [password, setPassword] = useState('');
102
+ return (_jsx("div", { style: {
103
+ position: 'fixed',
104
+ inset: 0,
105
+ display: 'flex',
106
+ alignItems: 'center',
107
+ justifyContent: 'center',
108
+ backgroundColor: 'rgba(0, 0, 0, 0.5)',
109
+ }, children: _jsxs("div", { style: {
110
+ backgroundColor: '#343534',
111
+ padding: '1rem',
112
+ borderRadius: '0.5rem',
113
+ width: '500px',
114
+ flexDirection: 'column',
115
+ display: 'flex',
116
+ alignItems: 'center',
117
+ justifyContent: 'center',
118
+ }, children: [_jsx("p", { style: { fontSize: '2rem', fontWeight: 'bold', marginBottom: '1rem', textAlign: 'center' }, children: "Rimori Login" }), _jsx("p", { style: { marginBottom: '1rem', textAlign: 'center' }, children: "Please login with your Rimori developer account for this plugin to be able to access the Rimori platform the same it will operate in the Rimori platform." }), _jsx("input", { style: {
119
+ marginBottom: '1rem',
120
+ width: '100%',
121
+ padding: '0.5rem',
122
+ borderRadius: '0.5rem',
123
+ border: 'none',
124
+ backgroundColor: '#444444',
125
+ }, type: "email", placeholder: "Email", onChange: (e) => setUser(e.target.value) }), _jsx("input", { style: {
126
+ marginBottom: '1rem',
127
+ width: '100%',
128
+ padding: '0.5rem',
129
+ borderRadius: '0.5rem',
130
+ border: 'none',
131
+ backgroundColor: '#444444',
132
+ }, type: "password", placeholder: "Password", onChange: (e) => setPassword(e.target.value) }), _jsx("button", { style: {
133
+ marginBottom: '1rem',
134
+ width: '100%',
135
+ padding: '0.5rem',
136
+ borderRadius: '0.5rem',
137
+ border: 'none',
138
+ backgroundColor: '#928358',
139
+ }, onClick: () => {
140
+ onLogin(user, password);
141
+ }, children: "Login" })] }) }));
142
+ }
@@ -0,0 +1,2 @@
1
+ export declare function isFullscreen(): boolean;
2
+ export declare function triggerFullscreen(onStateChange: (isFullscreen: boolean) => void, selector?: string): void;
@@ -0,0 +1,23 @@
1
+ export function isFullscreen() {
2
+ return !!document.fullscreenElement;
3
+ }
4
+ export function triggerFullscreen(onStateChange, selector) {
5
+ document.addEventListener('fullscreenchange', () => {
6
+ onStateChange(isFullscreen());
7
+ });
8
+ try {
9
+ const ref = document.querySelector(selector || '#root');
10
+ if (!isFullscreen()) {
11
+ // @ts-ignore
12
+ ref.requestFullscreen() || ref.webkitRequestFullscreen();
13
+ }
14
+ else {
15
+ // @ts-ignore
16
+ document.exitFullscreen() || document.webkitExitFullscreen();
17
+ }
18
+ }
19
+ catch (error) {
20
+ console.error('Failed to enter fullscreen', error.message);
21
+ }
22
+ onStateChange(isFullscreen());
23
+ }
@@ -0,0 +1,2 @@
1
+ export declare function isFullscreen(): boolean;
2
+ export declare function triggerFullscreen(onStateChange: (isFullscreen: boolean) => void, selector?: string): void;
@@ -0,0 +1,23 @@
1
+ export function isFullscreen() {
2
+ return !!document.fullscreenElement;
3
+ }
4
+ export function triggerFullscreen(onStateChange, selector) {
5
+ document.addEventListener('fullscreenchange', () => {
6
+ onStateChange(isFullscreen());
7
+ });
8
+ try {
9
+ const ref = document.querySelector(selector || '#root');
10
+ if (!isFullscreen()) {
11
+ // @ts-ignore
12
+ ref.requestFullscreen() || ref.webkitRequestFullscreen();
13
+ }
14
+ else {
15
+ // @ts-ignore
16
+ document.exitFullscreen() || document.webkitExitFullscreen();
17
+ }
18
+ }
19
+ catch (error) {
20
+ console.error('Failed to enter fullscreen', error.message);
21
+ }
22
+ onStateChange(isFullscreen());
23
+ }
@@ -0,0 +1,103 @@
1
+ /**
2
+ * Supported database column data types for table schema definitions.
3
+ */
4
+ type DbColumnType = 'decimal' | 'integer' | 'text' | 'boolean' | 'json' | 'timestamp' | 'uuid';
5
+ /**
6
+ * Foreign key relationship configuration with cascade delete support.
7
+ * Defines a relationship where the source record is deleted when the destination record is deleted.
8
+ */
9
+ interface ForeignKeyRelation {
10
+ /** The target table that this column references */
11
+ references_table: string;
12
+ /** The target column in the referenced table (defaults to 'id') */
13
+ references_column?: string;
14
+ /** Whether to cascade delete when the referenced record is deleted */
15
+ on_delete_cascade: boolean;
16
+ }
17
+ /**
18
+ * Database column definition with support for types, constraints, and relationships.
19
+ */
20
+ export interface DbColumnDefinition {
21
+ /** The data type of the column */
22
+ type: DbColumnType;
23
+ /** Human-readable description of the column's purpose */
24
+ description: string;
25
+ /** Whether the column can contain null values */
26
+ nullable?: boolean;
27
+ /** Whether the column has a unique constraint */
28
+ unique?: boolean;
29
+ /** Default value for the column. can also use sql functions like now(), auth.uid() or gen_random_uuid() */
30
+ default_value?: string | number | boolean;
31
+ /** Array of allowed values for enumerated columns */
32
+ /** Foreign key relationship configuration */
33
+ foreign_key?: ForeignKeyRelation;
34
+ /** The name of the column before it was renamed. */
35
+ old_name?: string;
36
+ /** Whether the column is deprecated. The column gets renamed to column_name_old. To fully remove the column, first set deprecated to true and then after a release, remove the column from the table definition. */
37
+ deprecated?: boolean;
38
+ /** Whether the column is a primary key */
39
+ /** Restrictions for the column. If the column is restricted, the permission is further restricted. E.g. if the column is restricted to user, then the user can only read the column if they have the right permission.
40
+ * Example: Denying users to update the column, but allowing the moderator to update the column.
41
+ */
42
+ restrict?: {
43
+ /** Restrictions for the user */
44
+ user: Partial<Omit<DbPermissionDefinition, 'delete'>>;
45
+ /** Restrictions for the moderator */
46
+ moderator?: Partial<Omit<DbPermissionDefinition, 'delete'>>;
47
+ };
48
+ }
49
+ /**
50
+ * Base table structure that all database tables inherit.
51
+ * Includes standard audit fields for tracking creation and ownership.
52
+ */
53
+ interface BaseTableStructure {
54
+ /** Unique identifier for the record */
55
+ id: DbColumnDefinition;
56
+ /** Timestamp when the record was created */
57
+ created_at: DbColumnDefinition;
58
+ /** ID of the user who created the record */
59
+ created_by: DbColumnDefinition;
60
+ }
61
+ /**
62
+ * Complete database table schema definition.
63
+ * Defines the structure, constraints, and relationships for a database table.
64
+ */
65
+ export interface DbTableDefinition {
66
+ /** Name of the database table */
67
+ table_name: string;
68
+ /** Description of the table's purpose and usage */
69
+ description: string;
70
+ /** Permissions for the table */
71
+ permissions: {
72
+ user: DbPermissionDefinition;
73
+ moderator?: DbPermissionDefinition;
74
+ };
75
+ /** Column definitions for the table */
76
+ columns: {
77
+ [column_name: string]: DbColumnDefinition;
78
+ };
79
+ }
80
+ /**
81
+ * Permission definition for a database table.
82
+ * NONE means the action is not allowed.
83
+ * OWN means only do the action on your own records.
84
+ * ALL means do the action on all records.
85
+ *
86
+ * Defines the permissions for a database table.
87
+ */
88
+ export type DbPermission = 'NONE' | 'OWN' | 'ALL';
89
+ /**
90
+ * Permission definition for a database table.
91
+ * Defines the permissions for a database table.
92
+ */
93
+ export interface DbPermissionDefinition {
94
+ read: DbPermission;
95
+ insert: DbPermission;
96
+ update: DbPermission;
97
+ delete: DbPermission;
98
+ }
99
+ /**
100
+ * Full table definition that includes automatically generated fields.
101
+ */
102
+ export type FullTable<T extends Record<string, DbColumnDefinition>> = T & BaseTableStructure;
103
+ export {};
@@ -0,0 +1,2 @@
1
+ // Database table structure definitions
2
+ export {};
@@ -0,0 +1,15 @@
1
+ import { Tool } from '../fromRimori/PluginTypes';
2
+ export interface ToolInvocation {
3
+ toolCallId: string;
4
+ toolName: string;
5
+ args: Record<string, string>;
6
+ }
7
+ export interface Message {
8
+ id?: string;
9
+ role: 'user' | 'assistant' | 'system';
10
+ content: string;
11
+ toolCalls?: ToolInvocation[];
12
+ }
13
+ export declare function generateText(backendUrl: string, messages: Message[], tools: Tool[], token: string): Promise<any>;
14
+ export type OnLLMResponse = (id: string, response: string, finished: boolean, toolInvocations?: ToolInvocation[]) => void;
15
+ export declare function streamChatGPT(backendUrl: string, messages: Message[], tools: Tool[], onResponse: OnLLMResponse, token: string): Promise<void>;