@rimori/client 1.3.1 → 1.4.3

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 (148) hide show
  1. package/.prettierignore +35 -0
  2. package/README.md +77 -71
  3. package/dist/cli/scripts/init/dev-registration.d.ts +1 -1
  4. package/dist/cli/scripts/init/dev-registration.js +4 -4
  5. package/dist/cli/scripts/init/main.js +1 -1
  6. package/dist/cli/scripts/init/package-setup.d.ts +1 -1
  7. package/dist/cli/scripts/init/package-setup.js +3 -3
  8. package/dist/cli/scripts/init/router-transformer.js +19 -12
  9. package/dist/cli/scripts/init/vite-config.d.ts +2 -2
  10. package/dist/cli/scripts/init/vite-config.js +2 -2
  11. package/dist/cli/scripts/release/release-config-upload.js +9 -9
  12. package/dist/cli/scripts/release/release-db-update.d.ts +1 -1
  13. package/dist/cli/scripts/release/release-db-update.js +9 -9
  14. package/dist/cli/scripts/release/release-file-upload.js +2 -2
  15. package/dist/cli/scripts/release/release.js +2 -2
  16. package/dist/cli/types/DatabaseTypes.d.ts +2 -2
  17. package/dist/components/CRUDModal.d.ts +1 -1
  18. package/dist/components/CRUDModal.js +3 -3
  19. package/dist/components/MarkdownEditor.js +16 -16
  20. package/dist/components/Spinner.js +2 -2
  21. package/dist/components/ai/Assistant.js +7 -8
  22. package/dist/components/ai/Avatar.d.ts +2 -2
  23. package/dist/components/ai/Avatar.js +14 -7
  24. package/dist/components/ai/EmbeddedAssistent/AudioInputField.js +5 -6
  25. package/dist/components/ai/EmbeddedAssistent/CircleAudioAvatar.d.ts +1 -1
  26. package/dist/components/ai/EmbeddedAssistent/CircleAudioAvatar.js +1 -2
  27. package/dist/components/ai/EmbeddedAssistent/TTS/MessageSender.d.ts +1 -2
  28. package/dist/components/ai/EmbeddedAssistent/TTS/MessageSender.js +4 -2
  29. package/dist/components/ai/EmbeddedAssistent/TTS/Player.js +1 -1
  30. package/dist/components/ai/EmbeddedAssistent/VoiceRecoder.js +2 -3
  31. package/dist/components/audio/Playbutton.js +10 -7
  32. package/dist/components/components/ContextMenu.d.ts +1 -1
  33. package/dist/components/components/ContextMenu.js +19 -16
  34. package/dist/components.d.ts +10 -10
  35. package/dist/components.js +10 -10
  36. package/dist/core/controller/AIController.d.ts +2 -2
  37. package/dist/core/controller/AIController.js +20 -18
  38. package/dist/core/controller/ExerciseController.d.ts +52 -0
  39. package/dist/core/controller/ExerciseController.js +73 -0
  40. package/dist/core/controller/ObjectController.js +5 -5
  41. package/dist/core/controller/SettingsController.d.ts +22 -7
  42. package/dist/core/controller/SettingsController.js +73 -8
  43. package/dist/core/controller/SharedContentController.d.ts +3 -3
  44. package/dist/core/controller/SharedContentController.js +38 -20
  45. package/dist/core/controller/VoiceController.js +6 -4
  46. package/dist/core/core.d.ts +15 -14
  47. package/dist/core/core.js +7 -7
  48. package/dist/fromRimori/EventBus.js +23 -23
  49. package/dist/fromRimori/PluginTypes.d.ts +4 -4
  50. package/dist/hooks/UseChatHook.d.ts +3 -3
  51. package/dist/hooks/UseChatHook.js +9 -3
  52. package/dist/index.d.ts +10 -10
  53. package/dist/index.js +9 -9
  54. package/dist/plugin/AccomplishmentHandler.d.ts +5 -5
  55. package/dist/plugin/AccomplishmentHandler.js +31 -27
  56. package/dist/plugin/AudioController.d.ts +1 -1
  57. package/dist/plugin/AudioController.js +6 -6
  58. package/dist/plugin/Logger.d.ts +5 -0
  59. package/dist/plugin/Logger.js +65 -13
  60. package/dist/plugin/PluginController.d.ts +7 -1
  61. package/dist/plugin/PluginController.js +32 -27
  62. package/dist/plugin/RimoriClient.d.ts +39 -14
  63. package/dist/plugin/RimoriClient.js +60 -31
  64. package/dist/plugin/StandaloneClient.d.ts +1 -1
  65. package/dist/plugin/StandaloneClient.js +35 -16
  66. package/dist/plugin/ThemeSetter.js +4 -4
  67. package/dist/providers/PluginProvider.js +44 -14
  68. package/dist/utils/Language.js +57 -57
  69. package/dist/utils/PluginUtils.js +3 -3
  70. package/dist/utils/difficultyConverter.d.ts +1 -1
  71. package/dist/utils/difficultyConverter.js +1 -1
  72. package/dist/utils/endpoint.js +2 -2
  73. package/dist/worker/WorkerSetup.d.ts +1 -1
  74. package/dist/worker/WorkerSetup.js +6 -6
  75. package/eslint.config.js +53 -0
  76. package/example/docs/devdocs.md +50 -40
  77. package/example/docs/overview.md +1 -1
  78. package/example/docs/userdocs.md +4 -1
  79. package/example/rimori.config.ts +51 -49
  80. package/example/worker/vite.config.ts +3 -3
  81. package/example/worker/worker.ts +2 -2
  82. package/package.json +17 -4
  83. package/prettier.config.js +8 -0
  84. package/src/cli/scripts/init/dev-registration.ts +5 -8
  85. package/src/cli/scripts/init/env-setup.ts +1 -1
  86. package/src/cli/scripts/init/file-operations.ts +1 -1
  87. package/src/cli/scripts/init/html-cleaner.ts +2 -5
  88. package/src/cli/scripts/init/main.ts +16 -13
  89. package/src/cli/scripts/init/package-setup.ts +11 -15
  90. package/src/cli/scripts/init/router-transformer.ts +40 -37
  91. package/src/cli/scripts/init/tailwind-config.ts +17 -26
  92. package/src/cli/scripts/init/vite-config.ts +3 -3
  93. package/src/cli/scripts/release/release-config-upload.ts +11 -11
  94. package/src/cli/scripts/release/release-db-update.ts +12 -12
  95. package/src/cli/scripts/release/release-file-upload.ts +3 -3
  96. package/src/cli/scripts/release/release.ts +4 -4
  97. package/src/cli/types/DatabaseTypes.ts +7 -8
  98. package/src/components/CRUDModal.tsx +64 -48
  99. package/src/components/MarkdownEditor.tsx +58 -27
  100. package/src/components/Spinner.tsx +24 -17
  101. package/src/components/ai/Assistant.tsx +70 -70
  102. package/src/components/ai/Avatar.tsx +20 -16
  103. package/src/components/ai/EmbeddedAssistent/AudioInputField.tsx +63 -54
  104. package/src/components/ai/EmbeddedAssistent/CircleAudioAvatar.tsx +14 -5
  105. package/src/components/ai/EmbeddedAssistent/TTS/MessageSender.ts +75 -74
  106. package/src/components/ai/EmbeddedAssistent/TTS/Player.ts +177 -178
  107. package/src/components/ai/EmbeddedAssistent/VoiceRecoder.tsx +109 -94
  108. package/src/components/ai/utils.ts +4 -4
  109. package/src/components/audio/Playbutton.tsx +101 -93
  110. package/src/components/components/ContextMenu.tsx +47 -35
  111. package/src/components.ts +10 -10
  112. package/src/core/controller/AIController.ts +62 -50
  113. package/src/core/controller/ExerciseController.ts +98 -0
  114. package/src/core/controller/ObjectController.ts +15 -10
  115. package/src/core/controller/SettingsController.ts +89 -16
  116. package/src/core/controller/SharedContentController.ts +80 -44
  117. package/src/core/controller/VoiceController.ts +10 -8
  118. package/src/core/core.ts +15 -15
  119. package/src/fromRimori/EventBus.ts +76 -47
  120. package/src/fromRimori/PluginTypes.ts +26 -17
  121. package/src/fromRimori/readme.md +2 -2
  122. package/src/hooks/UseChatHook.ts +25 -15
  123. package/src/index.ts +10 -10
  124. package/src/plugin/AccomplishmentHandler.ts +53 -35
  125. package/src/plugin/AudioController.ts +18 -12
  126. package/src/plugin/Logger.ts +77 -19
  127. package/src/plugin/PluginController.ts +60 -44
  128. package/src/plugin/RimoriClient.ts +133 -69
  129. package/src/plugin/StandaloneClient.ts +51 -24
  130. package/src/plugin/ThemeSetter.ts +5 -5
  131. package/src/providers/PluginProvider.tsx +90 -36
  132. package/src/style.scss +3 -3
  133. package/src/utils/Language.ts +58 -58
  134. package/src/utils/PluginUtils.ts +16 -20
  135. package/src/utils/difficultyConverter.ts +2 -2
  136. package/src/utils/endpoint.ts +3 -2
  137. package/src/worker/WorkerSetup.ts +8 -9
  138. package/tsconfig.json +2 -4
  139. package/dist/components/LoggerExample.d.ts +0 -6
  140. package/dist/components/LoggerExample.js +0 -79
  141. package/dist/core/controller/AudioController.d.ts +0 -0
  142. package/dist/core/controller/AudioController.js +0 -1
  143. package/dist/hooks/UseLogger.d.ts +0 -30
  144. package/dist/hooks/UseLogger.js +0 -122
  145. package/dist/plugin/LoggerExample.d.ts +0 -16
  146. package/dist/plugin/LoggerExample.js +0 -140
  147. package/dist/utils/audioFormats.d.ts +0 -26
  148. package/dist/utils/audioFormats.js +0 -67
@@ -1,79 +0,0 @@
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 { useState } from 'react';
12
- import { useLogging, useLogger } from '../hooks/UseLogger';
13
- /**
14
- * Example component demonstrating Logger usage in a React component.
15
- * Shows how console methods are automatically captured by the Logger.
16
- */
17
- export const LoggerExample = () => {
18
- const [logMessage, setLogMessage] = useState('Hello from Logger Example');
19
- const [logData, setLogData] = useState('{"key": "value"}');
20
- // Initialize the logger - this overrides console methods globally
21
- const logger = useLogger(process.env.NODE_ENV === 'production');
22
- // Get logging utilities
23
- const { sendAllLogs, getStats, clearLogs, exportLogs, sendLogsByLevel } = useLogging(process.env.NODE_ENV === 'production');
24
- const handleConsoleLog = () => {
25
- // This will be automatically captured by the Logger
26
- console.log(logMessage, logData ? JSON.parse(logData) : '');
27
- };
28
- const handleConsoleInfo = () => {
29
- // This will be automatically captured by the Logger
30
- console.info(logMessage, logData ? JSON.parse(logData) : '');
31
- };
32
- const handleConsoleWarn = () => {
33
- // This will be automatically captured by the Logger and include screenshot + mouse position
34
- console.warn(logMessage, logData ? JSON.parse(logData) : '');
35
- };
36
- const handleConsoleError = () => {
37
- // This will be automatically captured by the Logger and include screenshot + mouse position
38
- console.error(logMessage, logData ? JSON.parse(logData) : '');
39
- };
40
- const handleConsoleDebug = () => {
41
- // This will be automatically captured by the Logger
42
- console.debug(logMessage, logData ? JSON.parse(logData) : '');
43
- };
44
- const handleSendLogs = () => __awaiter(void 0, void 0, void 0, function* () {
45
- yield sendAllLogs();
46
- alert('Logs sent to Rimori!');
47
- });
48
- const handleGetStats = () => {
49
- const stats = getStats();
50
- alert(`Log Statistics:\nTotal: ${stats.total}\nDebug: ${stats.byLevel.debug}\nInfo: ${stats.byLevel.info}\nWarn: ${stats.byLevel.warn}\nError: ${stats.byLevel.error}`);
51
- };
52
- const handleClearLogs = () => {
53
- clearLogs();
54
- alert('Logs cleared!');
55
- };
56
- const handleExportLogs = () => {
57
- const exportedLogs = exportLogs();
58
- const blob = new Blob([exportedLogs], { type: 'application/json' });
59
- const url = URL.createObjectURL(blob);
60
- const a = document.createElement('a');
61
- a.href = url;
62
- a.download = 'rimori-logs.json';
63
- a.click();
64
- URL.revokeObjectURL(url);
65
- };
66
- const handleSendErrorLogs = () => __awaiter(void 0, void 0, void 0, function* () {
67
- yield sendLogsByLevel('error');
68
- alert('Error logs sent to Rimori!');
69
- });
70
- const handleTriggerError = () => {
71
- // This will trigger an unhandled error that the logger will catch via console.error override
72
- throw new Error('This is a test error for the logger');
73
- };
74
- const handleTriggerPromiseRejection = () => {
75
- // This will trigger an unhandled promise rejection that the logger will catch
76
- Promise.reject(new Error('This is a test promise rejection'));
77
- };
78
- return (_jsxs("div", { style: { padding: '20px', maxWidth: '800px' }, children: [_jsx("h2", { children: "Logger Example - Console Override Demo" }), _jsxs("div", { style: { marginBottom: '20px', padding: '15px', backgroundColor: '#e3f2fd', borderRadius: '5px' }, children: [_jsx("h4", { children: "\uD83C\uDFAF Key Feature: Console Methods Override" }), _jsxs("p", { children: ["The Logger automatically overrides ", _jsx("code", { children: "console.log" }), ", ", _jsx("code", { children: "console.info" }), ",", _jsx("code", { children: "console.warn" }), ", ", _jsx("code", { children: "console.error" }), ", and ", _jsx("code", { children: "console.debug" }), " globally. All console calls are automatically captured and stored with context information."] })] }), _jsx("div", { style: { marginBottom: '20px' }, children: _jsxs("label", { children: ["Log Message:", _jsx("input", { type: "text", value: logMessage, onChange: (e) => setLogMessage(e.target.value), placeholder: "Enter log message", style: { width: '100%', marginTop: '5px' } })] }) }), _jsx("div", { style: { marginBottom: '20px' }, children: _jsxs("label", { children: ["Log Data (JSON):", _jsx("textarea", { value: logData, onChange: (e) => setLogData(e.target.value), placeholder: '{"key": "value"}', style: { width: '100%', height: '60px', marginTop: '5px' } })] }) }), _jsxs("div", { style: { marginBottom: '20px' }, children: [_jsx("h3", { children: "Console Method Calls (Automatically Captured)" }), _jsx("button", { onClick: handleConsoleLog, style: { margin: '5px' }, children: "console.log()" }), _jsx("button", { onClick: handleConsoleInfo, style: { margin: '5px' }, children: "console.info()" }), _jsx("button", { onClick: handleConsoleWarn, style: { margin: '5px', backgroundColor: '#ff9800' }, children: "console.warn() \uD83D\uDCF8" }), _jsx("button", { onClick: handleConsoleError, style: { margin: '5px', backgroundColor: '#f44336' }, children: "console.error() \uD83D\uDCF8" }), _jsx("button", { onClick: handleConsoleDebug, style: { margin: '5px' }, children: "console.debug()" })] }), _jsxs("div", { style: { marginBottom: '20px' }, children: [_jsx("h3", { children: "Log Management" }), _jsx("button", { onClick: handleSendLogs, style: { margin: '5px' }, children: "Send All Logs to Rimori" }), _jsx("button", { onClick: handleSendErrorLogs, style: { margin: '5px', backgroundColor: '#f44336' }, children: "Send Error Logs Only" }), _jsx("button", { onClick: handleGetStats, style: { margin: '5px' }, children: "Get Log Statistics" }), _jsx("button", { onClick: handleClearLogs, style: { margin: '5px' }, children: "Clear Logs" }), _jsx("button", { onClick: handleExportLogs, style: { margin: '5px' }, children: "Export Logs (JSON)" })] }), _jsxs("div", { style: { marginBottom: '20px' }, children: [_jsx("h3", { children: "Test Error Handling" }), _jsx("button", { onClick: handleTriggerError, style: { margin: '5px', backgroundColor: '#ff6b6b' }, children: "Trigger Unhandled Error" }), _jsx("button", { onClick: handleTriggerPromiseRejection, style: { margin: '5px', backgroundColor: '#ff6b6b' }, children: "Trigger Promise Rejection" })] }), _jsxs("div", { style: { marginTop: '30px', padding: '15px', backgroundColor: '#f5f5f5', borderRadius: '5px' }, children: [_jsx("h4", { children: "\uD83D\uDCCB How It Works:" }), _jsxs("ul", { children: [_jsxs("li", { children: [_jsx("strong", { children: "Automatic Capture:" }), " All console calls are automatically captured by the Logger"] }), _jsxs("li", { children: [_jsx("strong", { children: "No Manual Logging:" }), " Just use ", _jsx("code", { children: "console.log()" }), " as usual - no need to call Logger methods"] }), _jsxs("li", { children: [_jsx("strong", { children: "Production Filtering:" }), " In production, only warnings and errors show in console, but all are stored"] }), _jsxs("li", { children: [_jsx("strong", { children: "Screenshot Capture:" }), " Errors and warnings automatically capture screenshots + mouse position"] }), _jsxs("li", { children: [_jsx("strong", { children: "Browser Context:" }), " Each log includes URL, user agent, screen resolution, etc."] }), _jsxs("li", { children: [_jsx("strong", { children: "Rimori Integration:" }), " Logs can be sent to Rimori for centralized logging"] })] }), _jsx("h4", { children: "\uD83C\uDFAF Screenshot & Mouse Position:" }), _jsxs("p", { children: ["When you call ", _jsx("code", { children: "console.warn()" }), " or ", _jsx("code", { children: "console.error()" }), ", the Logger automatically:"] }), _jsxs("ul", { children: [_jsx("li", { children: "Captures a screenshot of the current page (if html2canvas is available)" }), _jsx("li", { children: "Records the current mouse position (x, y coordinates)" }), _jsx("li", { children: "Includes timestamp for both screenshot and mouse position" })] })] }), _jsxs("div", { style: { marginTop: '20px', padding: '15px', backgroundColor: '#fff3e0', borderRadius: '5px' }, children: [_jsx("h4", { children: "\uD83D\uDD27 Setup Required:" }), _jsx("p", { children: "To enable screenshot capture, include html2canvas in your plugin:" }), _jsx("pre", { style: { backgroundColor: '#f5f5f5', padding: '10px', borderRadius: '3px' }, children: `<script src="https://html2canvas.hertzen.com/dist/html2canvas.min.js"></script>` })] })] }));
79
- };
File without changes
@@ -1 +0,0 @@
1
- "use strict";
@@ -1,30 +0,0 @@
1
- import { Logger } from '../plugin/Logger';
2
- /**
3
- * Hook for initializing the Logger singleton with automatic Rimori client integration.
4
- * This hook should be called once at the top level of your plugin.
5
- * @param isProduction - Whether the environment is production
6
- * @returns Logger instance
7
- */
8
- export declare function useLogger(isProduction: boolean): Logger;
9
- /**
10
- * Hook that provides a logger with automatic Rimori client integration.
11
- * This hook should be used after the plugin is fully initialized.
12
- * @param isProduction - Whether the environment is production
13
- * @returns Logger instance with Rimori client set
14
- */
15
- export declare function useLoggerWithRimori(isProduction: boolean): Logger;
16
- /**
17
- * Hook for managing logs with simplified interface.
18
- * Since console methods are overridden globally, this provides utility functions for log management.
19
- * @param isProduction - Whether the environment is production
20
- * @returns Object with log management methods
21
- */
22
- export declare function useLogging(isProduction: boolean): {
23
- sendAllLogs: () => any;
24
- sendRecentLogs: (count: number) => any;
25
- sendLogsByLevel: (level: "debug" | "info" | "warn" | "error") => any;
26
- getStats: () => any;
27
- exportLogs: () => any;
28
- clearLogs: () => any;
29
- restoreConsole: () => any;
30
- };
@@ -1,122 +0,0 @@
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 { useEffect, useRef } from 'react';
11
- import { Logger } from '../plugin/Logger';
12
- import { usePlugin } from './UseChatHook';
13
- /**
14
- * Hook for initializing the Logger singleton with automatic Rimori client integration.
15
- * This hook should be called once at the top level of your plugin.
16
- * @param isProduction - Whether the environment is production
17
- * @returns Logger instance
18
- */
19
- export function useLogger(isProduction) {
20
- const { event } = usePlugin();
21
- const loggerRef = useRef(null);
22
- useEffect(() => {
23
- // Initialize logger if not already done
24
- if (!loggerRef.current) {
25
- loggerRef.current = Logger.getInstance(isProduction);
26
- }
27
- // Set up automatic log transmission on certain events
28
- const handleBeforeUnload = () => {
29
- if (loggerRef.current) {
30
- // Send recent logs before page unload
31
- loggerRef.current.sendRecentLogs(50);
32
- }
33
- };
34
- const handleError = (event) => {
35
- // The logger will automatically capture this via console.error override
36
- console.error('Unhandled error', {
37
- message: event.message,
38
- filename: event.filename,
39
- lineno: event.lineno,
40
- colno: event.colno,
41
- error: event.error
42
- });
43
- };
44
- const handleUnhandledRejection = (event) => {
45
- // The logger will automatically capture this via console.error override
46
- console.error('Unhandled promise rejection', {
47
- reason: event.reason
48
- });
49
- };
50
- // Add event listeners
51
- window.addEventListener('beforeunload', handleBeforeUnload);
52
- window.addEventListener('error', handleError);
53
- window.addEventListener('unhandledrejection', handleUnhandledRejection);
54
- // Cleanup
55
- return () => {
56
- window.removeEventListener('beforeunload', handleBeforeUnload);
57
- window.removeEventListener('error', handleError);
58
- window.removeEventListener('unhandledrejection', handleUnhandledRejection);
59
- };
60
- }, [isProduction]);
61
- // Return a proxy that ensures the logger is available
62
- return new Proxy({}, {
63
- get(target, prop) {
64
- if (!loggerRef.current) {
65
- throw new Error('Logger not initialized');
66
- }
67
- return loggerRef.current[prop];
68
- }
69
- });
70
- }
71
- /**
72
- * Hook that provides a logger with automatic Rimori client integration.
73
- * This hook should be used after the plugin is fully initialized.
74
- * @param isProduction - Whether the environment is production
75
- * @returns Logger instance with Rimori client set
76
- */
77
- export function useLoggerWithRimori(isProduction) {
78
- const logger = useLogger(isProduction);
79
- const { event } = usePlugin();
80
- useEffect(() => {
81
- // Set up Rimori client integration when the hook is used
82
- const setupRimoriIntegration = () => __awaiter(this, void 0, void 0, function* () {
83
- try {
84
- // Get the plugin ID from the event bus context
85
- // This is a simplified approach - in practice, you'd get this from your plugin context
86
- const pluginId = 'your-plugin-id'; // This should come from your plugin configuration
87
- // Set up a listener for log transmission
88
- event.on('global.logger.sendLogs', (data) => __awaiter(this, void 0, void 0, function* () {
89
- if (data.pluginId === pluginId) {
90
- yield logger.sendAllLogs();
91
- }
92
- }));
93
- }
94
- catch (error) {
95
- console.warn('Failed to set up Logger with Rimori integration:', error);
96
- }
97
- });
98
- setupRimoriIntegration();
99
- }, [event, logger]);
100
- return logger;
101
- }
102
- /**
103
- * Hook for managing logs with simplified interface.
104
- * Since console methods are overridden globally, this provides utility functions for log management.
105
- * @param isProduction - Whether the environment is production
106
- * @returns Object with log management methods
107
- */
108
- export function useLogging(isProduction) {
109
- const logger = useLogger(isProduction);
110
- return {
111
- // Log management
112
- sendAllLogs: () => logger.sendAllLogs(),
113
- sendRecentLogs: (count) => logger.sendRecentLogs(count),
114
- sendLogsByLevel: (level) => logger.sendLogsByLevel(level),
115
- // Statistics and export
116
- getStats: () => logger.getStats(),
117
- exportLogs: () => logger.exportLogs(),
118
- clearLogs: () => logger.clearLogs(),
119
- // Console restoration (use with caution)
120
- restoreConsole: () => logger.restoreConsole()
121
- };
122
- }
@@ -1,16 +0,0 @@
1
- /**
2
- * Example of how to integrate the Logger into a plugin's main entry point.
3
- * This shows the complete setup process.
4
- */
5
- export declare function initializePluginWithLogger(): Promise<void>;
6
- export declare function exampleComponentUsage(): {
7
- handleUserAction: () => void;
8
- handleApiError: (error: Error) => void;
9
- handleDeprecatedFeature: () => void;
10
- };
11
- export declare function exampleLogManagement(): {
12
- sendLogsToRimori: () => Promise<void>;
13
- getLogStatistics: () => any;
14
- exportLogsForDebugging: () => void;
15
- clearOldLogs: () => void;
16
- };
@@ -1,140 +0,0 @@
1
- /**
2
- * Example of how to integrate the Logger into a plugin's main entry point.
3
- * This shows the complete setup process.
4
- */
5
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
6
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
7
- return new (P || (P = Promise))(function (resolve, reject) {
8
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
9
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
10
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
11
- step((generator = generator.apply(thisArg, _arguments || [])).next());
12
- });
13
- };
14
- import { Logger } from './Logger';
15
- // Example plugin initialization with Logger integration
16
- export function initializePluginWithLogger() {
17
- return __awaiter(this, void 0, void 0, function* () {
18
- // 1. Initialize the Logger singleton (call this as early as possible)
19
- const logger = Logger.getInstance(process.env.NODE_ENV === 'production');
20
- console.log('Logger initialized, console methods are now overridden globally');
21
- try {
22
- // 2. Initialize your plugin's core functionality
23
- console.info('Starting plugin initialization...');
24
- // 3. Get the Rimori client (this would be your actual client initialization)
25
- const rimoriClient = yield getRimoriClient(); // Your actual client setup
26
- // 4. Set the Rimori client in the Logger
27
- logger.setRimoriClient(rimoriClient);
28
- console.info('Plugin initialized successfully', {
29
- version: '1.0.0',
30
- environment: process.env.NODE_ENV,
31
- timestamp: new Date().toISOString()
32
- });
33
- // 5. Set up periodic log transmission (optional)
34
- setInterval(() => __awaiter(this, void 0, void 0, function* () {
35
- yield logger.sendRecentLogs(10); // Send last 10 logs every 5 minutes
36
- }), 5 * 60 * 1000);
37
- // 6. Set up error boundary for unhandled errors
38
- window.addEventListener('error', (event) => {
39
- console.error('Unhandled error caught by Logger', {
40
- message: event.message,
41
- filename: event.filename,
42
- lineno: event.lineno,
43
- colno: event.colno
44
- });
45
- });
46
- window.addEventListener('unhandledrejection', (event) => {
47
- console.error('Unhandled promise rejection caught by Logger', {
48
- reason: event.reason
49
- });
50
- });
51
- }
52
- catch (error) {
53
- // This console.error will be automatically captured with screenshot + mouse position
54
- console.error('Failed to initialize plugin', {
55
- error: error.message,
56
- stack: error.stack
57
- });
58
- // Send error logs immediately
59
- yield logger.sendLogsByLevel('error');
60
- }
61
- });
62
- }
63
- // Example of how to use console methods in your components
64
- export function exampleComponentUsage() {
65
- const handleUserAction = () => {
66
- // These console calls are automatically captured by the Logger
67
- console.log('User performed action', {
68
- action: 'button_click',
69
- timestamp: Date.now(),
70
- userId: 'user123'
71
- });
72
- };
73
- const handleApiError = (error) => {
74
- // This console.error will include screenshot + mouse position
75
- console.error('API request failed', {
76
- endpoint: '/api/users',
77
- error: error.message,
78
- statusCode: 500
79
- });
80
- };
81
- const handleDeprecatedFeature = () => {
82
- // This console.warn will include screenshot + mouse position
83
- console.warn('Deprecated feature used', {
84
- feature: 'old-api-endpoint',
85
- suggestedAlternative: 'new-api-endpoint'
86
- });
87
- };
88
- return {
89
- handleUserAction,
90
- handleApiError,
91
- handleDeprecatedFeature
92
- };
93
- }
94
- // Example of log management utilities
95
- export function exampleLogManagement() {
96
- const logger = Logger.getInstance(process.env.NODE_ENV === 'production');
97
- const sendLogsToRimori = () => __awaiter(this, void 0, void 0, function* () {
98
- yield logger.sendAllLogs();
99
- console.log('All logs sent to Rimori');
100
- });
101
- const getLogStatistics = () => {
102
- const stats = logger.getStats();
103
- console.log('Log statistics:', stats);
104
- return stats;
105
- };
106
- const exportLogsForDebugging = () => {
107
- const exportedLogs = logger.exportLogs();
108
- const blob = new Blob([exportedLogs], { type: 'application/json' });
109
- const url = URL.createObjectURL(blob);
110
- const a = document.createElement('a');
111
- a.href = url;
112
- a.download = `rimori-logs-${new Date().toISOString()}.json`;
113
- a.click();
114
- URL.revokeObjectURL(url);
115
- };
116
- const clearOldLogs = () => {
117
- logger.clearLogs();
118
- console.log('All logs cleared');
119
- };
120
- return {
121
- sendLogsToRimori,
122
- getLogStatistics,
123
- exportLogsForDebugging,
124
- clearOldLogs
125
- };
126
- }
127
- // Mock function for demonstration
128
- function getRimoriClient() {
129
- return __awaiter(this, void 0, void 0, function* () {
130
- // This would be your actual Rimori client initialization
131
- return {
132
- plugin: { pluginId: 'example-plugin' },
133
- event: {
134
- emit: (topic, data) => __awaiter(this, void 0, void 0, function* () {
135
- console.log('Sending to Rimori:', topic, data);
136
- })
137
- }
138
- };
139
- });
140
- }
@@ -1,26 +0,0 @@
1
- /**
2
- * Maps audio MIME types to their corresponding file extensions
3
- * OpenAI supports: mp3, mp4, mpeg, mpga, m4a, wav, webm
4
- */
5
- export declare const AUDIO_MIME_TO_EXTENSION: Record<string, string>;
6
- /**
7
- * OpenAI supported audio formats for STT API
8
- */
9
- export declare const OPENAI_SUPPORTED_FORMATS: string[];
10
- /**
11
- * Determines the appropriate file extension for an audio MIME type
12
- * @param mimeType - The MIME type of the audio
13
- * @returns The file extension (without dot) or null if unsupported
14
- */
15
- export declare function getAudioFormatFromMimeType(mimeType: string): string | null;
16
- /**
17
- * Checks if an audio MIME type is supported by OpenAI
18
- * @param mimeType - The MIME type to check
19
- * @returns True if supported, false otherwise
20
- */
21
- export declare function isAudioFormatSupported(mimeType: string): boolean;
22
- /**
23
- * Gets a human-readable list of supported audio formats
24
- * @returns Formatted string of supported formats
25
- */
26
- export declare function getSupportedFormatsList(): string;
@@ -1,67 +0,0 @@
1
- /**
2
- * Maps audio MIME types to their corresponding file extensions
3
- * OpenAI supports: mp3, mp4, mpeg, mpga, m4a, wav, webm
4
- */
5
- export const AUDIO_MIME_TO_EXTENSION = {
6
- 'audio/mpeg': 'mp3',
7
- 'audio/mp3': 'mp3',
8
- 'audio/mp4': 'mp4',
9
- 'audio/m4a': 'm4a',
10
- 'audio/wav': 'wav',
11
- 'audio/wave': 'wav',
12
- 'audio/x-wav': 'wav',
13
- 'audio/webm': 'webm',
14
- 'audio/ogg': 'webm', // Convert ogg to webm for OpenAI compatibility
15
- 'audio/aac': 'm4a', // Convert aac to m4a for OpenAI compatibility
16
- 'audio/x-aac': 'm4a',
17
- 'audio/3gpp': 'mp4', // Convert 3gpp to mp4
18
- 'audio/3gpp2': 'mp4',
19
- 'audio/amr': 'mp4', // Convert amr to mp4
20
- 'audio/amr-wb': 'mp4',
21
- 'audio/flac': 'wav', // Convert flac to wav
22
- 'audio/x-flac': 'wav',
23
- 'audio/opus': 'webm', // Convert opus to webm
24
- 'audio/x-opus': 'webm',
25
- };
26
- /**
27
- * OpenAI supported audio formats for STT API
28
- */
29
- export const OPENAI_SUPPORTED_FORMATS = ['mp3', 'mp4', 'mpeg', 'mpga', 'm4a', 'wav', 'webm'];
30
- /**
31
- * Determines the appropriate file extension for an audio MIME type
32
- * @param mimeType - The MIME type of the audio
33
- * @returns The file extension (without dot) or null if unsupported
34
- */
35
- export function getAudioFormatFromMimeType(mimeType) {
36
- const normalizedMimeType = mimeType.toLowerCase();
37
- // Try to get format from MIME type mapping first
38
- let format = AUDIO_MIME_TO_EXTENSION[normalizedMimeType];
39
- // If no mapping found, try to extract from MIME type
40
- if (!format && normalizedMimeType.includes('audio/')) {
41
- format = normalizedMimeType.replace('audio/', '');
42
- }
43
- // Handle special cases
44
- if (format === 'mpeg') {
45
- format = 'mp3'; // OpenAI expects mp3, not mpeg
46
- }
47
- // Validate the format
48
- if (!format || !OPENAI_SUPPORTED_FORMATS.includes(format)) {
49
- return null;
50
- }
51
- return format;
52
- }
53
- /**
54
- * Checks if an audio MIME type is supported by OpenAI
55
- * @param mimeType - The MIME type to check
56
- * @returns True if supported, false otherwise
57
- */
58
- export function isAudioFormatSupported(mimeType) {
59
- return getAudioFormatFromMimeType(mimeType) !== null;
60
- }
61
- /**
62
- * Gets a human-readable list of supported audio formats
63
- * @returns Formatted string of supported formats
64
- */
65
- export function getSupportedFormatsList() {
66
- return OPENAI_SUPPORTED_FORMATS.join(', ');
67
- }