@rimori/client 1.1.10 → 1.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (171) hide show
  1. package/README.md +189 -63
  2. package/dist/cli/scripts/init/dev-registration.d.ts +35 -0
  3. package/dist/cli/scripts/init/dev-registration.js +174 -0
  4. package/dist/cli/scripts/init/env-setup.d.ts +9 -0
  5. package/dist/cli/scripts/init/env-setup.js +43 -0
  6. package/dist/cli/scripts/init/file-operations.d.ts +4 -0
  7. package/dist/cli/scripts/init/file-operations.js +51 -0
  8. package/dist/cli/scripts/init/html-cleaner.d.ts +4 -0
  9. package/dist/cli/scripts/init/html-cleaner.js +38 -0
  10. package/dist/cli/scripts/init/main.d.ts +2 -0
  11. package/dist/cli/scripts/init/main.js +160 -0
  12. package/dist/cli/scripts/init/package-setup.d.ts +32 -0
  13. package/dist/cli/scripts/init/package-setup.js +75 -0
  14. package/dist/cli/scripts/init/router-transformer.d.ts +6 -0
  15. package/dist/cli/scripts/init/router-transformer.js +254 -0
  16. package/dist/cli/scripts/init/tailwind-config.d.ts +4 -0
  17. package/dist/cli/scripts/init/tailwind-config.js +56 -0
  18. package/dist/cli/scripts/init/vite-config.d.ts +20 -0
  19. package/dist/cli/scripts/init/vite-config.js +54 -0
  20. package/dist/cli/scripts/release/release-config-upload.d.ts +7 -0
  21. package/dist/cli/scripts/release/release-config-upload.js +116 -0
  22. package/dist/cli/scripts/release/release-db-update.d.ts +6 -0
  23. package/dist/cli/scripts/release/release-db-update.js +100 -0
  24. package/dist/cli/scripts/release/release-file-upload.d.ts +6 -0
  25. package/dist/cli/scripts/release/release-file-upload.js +136 -0
  26. package/dist/cli/scripts/release/release.d.ts +23 -0
  27. package/dist/cli/scripts/release/release.js +70 -0
  28. package/dist/cli/types/DatabaseTypes.d.ts +103 -0
  29. package/dist/cli/types/DatabaseTypes.js +2 -0
  30. package/dist/components/LoggerExample.d.ts +6 -0
  31. package/dist/components/LoggerExample.js +79 -0
  32. package/dist/components/ai/Assistant.js +5 -5
  33. package/dist/components/ai/Avatar.d.ts +3 -2
  34. package/dist/components/ai/Avatar.js +11 -6
  35. package/dist/components/ai/EmbeddedAssistent/CircleAudioAvatar.js +1 -1
  36. package/dist/components/ai/EmbeddedAssistent/VoiceRecoder.d.ts +1 -0
  37. package/dist/components/ai/EmbeddedAssistent/VoiceRecoder.js +48 -33
  38. package/dist/components/ai/utils.js +0 -1
  39. package/dist/components/audio/Playbutton.js +4 -4
  40. package/dist/{core → components}/components/ContextMenu.js +50 -11
  41. package/dist/components.d.ts +5 -5
  42. package/dist/components.js +5 -5
  43. package/dist/core/controller/AIController.d.ts +15 -0
  44. package/dist/core/controller/AIController.js +253 -0
  45. package/dist/core/controller/AudioController.d.ts +0 -0
  46. package/dist/core/controller/AudioController.js +1 -0
  47. package/dist/{controller → core/controller}/ObjectController.d.ts +10 -2
  48. package/dist/{controller → core/controller}/ObjectController.js +8 -8
  49. package/dist/{controller → core/controller}/SettingsController.d.ts +28 -4
  50. package/dist/{controller → core/controller}/SettingsController.js +0 -25
  51. package/dist/{controller → core/controller}/SharedContentController.d.ts +31 -3
  52. package/dist/{controller → core/controller}/SharedContentController.js +77 -26
  53. package/dist/core/controller/VoiceController.d.ts +9 -0
  54. package/dist/{controller → core/controller}/VoiceController.js +11 -4
  55. package/dist/core/core.d.ts +14 -0
  56. package/dist/core/core.js +8 -0
  57. package/dist/{plugin/fromRimori → fromRimori}/EventBus.d.ts +3 -3
  58. package/dist/{plugin/fromRimori → fromRimori}/EventBus.js +26 -9
  59. package/dist/fromRimori/PluginTypes.d.ts +174 -0
  60. package/dist/hooks/UseChatHook.d.ts +2 -1
  61. package/dist/hooks/UseChatHook.js +6 -4
  62. package/dist/hooks/UseLogger.d.ts +30 -0
  63. package/dist/hooks/UseLogger.js +122 -0
  64. package/dist/index.d.ts +6 -3
  65. package/dist/index.js +5 -3
  66. package/dist/plugin/AccomplishmentHandler.d.ts +1 -1
  67. package/dist/plugin/AccomplishmentHandler.js +1 -1
  68. package/dist/plugin/AudioController.d.ts +37 -0
  69. package/dist/plugin/AudioController.js +68 -0
  70. package/dist/plugin/Logger.d.ts +68 -0
  71. package/dist/plugin/Logger.js +256 -0
  72. package/dist/plugin/LoggerExample.d.ts +16 -0
  73. package/dist/plugin/LoggerExample.js +140 -0
  74. package/dist/plugin/PluginController.d.ts +30 -5
  75. package/dist/plugin/PluginController.js +182 -53
  76. package/dist/plugin/RimoriClient.d.ts +68 -21
  77. package/dist/plugin/RimoriClient.js +88 -41
  78. package/dist/plugin/StandaloneClient.d.ts +1 -0
  79. package/dist/plugin/StandaloneClient.js +24 -10
  80. package/dist/plugin/ThemeSetter.d.ts +2 -1
  81. package/dist/plugin/ThemeSetter.js +13 -7
  82. package/dist/providers/PluginProvider.d.ts +4 -1
  83. package/dist/providers/PluginProvider.js +39 -13
  84. package/dist/utils/Language.d.ts +2 -1
  85. package/dist/utils/Language.js +4 -2
  86. package/dist/utils/audioFormats.d.ts +26 -0
  87. package/dist/utils/audioFormats.js +67 -0
  88. package/dist/utils/difficultyConverter.js +1 -1
  89. package/dist/utils/endpoint.d.ts +2 -0
  90. package/dist/utils/endpoint.js +2 -0
  91. package/dist/worker/WorkerSetup.d.ts +3 -2
  92. package/dist/worker/WorkerSetup.js +22 -65
  93. package/example/docs/devdocs.md +231 -0
  94. package/example/docs/overview.md +29 -0
  95. package/example/docs/userdocs.md +123 -0
  96. package/example/rimori.config.ts +89 -0
  97. package/example/worker/vite.config.ts +23 -0
  98. package/example/worker/worker.ts +11 -0
  99. package/package.json +16 -9
  100. package/src/cli/scripts/init/dev-registration.ts +192 -0
  101. package/src/cli/scripts/init/env-setup.ts +44 -0
  102. package/src/cli/scripts/init/file-operations.ts +58 -0
  103. package/src/cli/scripts/init/html-cleaner.ts +48 -0
  104. package/src/cli/scripts/init/main.ts +172 -0
  105. package/src/cli/scripts/init/package-setup.ts +117 -0
  106. package/src/cli/scripts/init/router-transformer.ts +329 -0
  107. package/src/cli/scripts/init/tailwind-config.ts +75 -0
  108. package/src/cli/scripts/init/vite-config.ts +73 -0
  109. package/src/cli/scripts/release/release-config-upload.ts +114 -0
  110. package/src/cli/scripts/release/release-db-update.ts +97 -0
  111. package/src/cli/scripts/release/release-file-upload.ts +138 -0
  112. package/src/cli/scripts/release/release.ts +69 -0
  113. package/src/cli/types/DatabaseTypes.ts +117 -0
  114. package/src/components/ai/Assistant.tsx +5 -5
  115. package/src/components/ai/Avatar.tsx +25 -8
  116. package/src/components/ai/EmbeddedAssistent/CircleAudioAvatar.tsx +1 -1
  117. package/src/components/ai/EmbeddedAssistent/VoiceRecoder.tsx +50 -35
  118. package/src/components/ai/utils.ts +0 -2
  119. package/src/components/audio/Playbutton.tsx +4 -4
  120. package/src/{core → components}/components/ContextMenu.tsx +56 -12
  121. package/src/components.ts +6 -6
  122. package/src/core/controller/AIController.ts +283 -0
  123. package/src/core/controller/ObjectController.ts +115 -0
  124. package/src/{controller → core/controller}/SettingsController.ts +29 -29
  125. package/src/{controller → core/controller}/SharedContentController.ts +91 -29
  126. package/src/core/controller/VoiceController.ts +31 -0
  127. package/src/core/core.ts +16 -0
  128. package/src/{plugin/fromRimori → fromRimori}/EventBus.ts +29 -11
  129. package/src/fromRimori/PluginTypes.ts +205 -0
  130. package/src/hooks/UseChatHook.ts +8 -5
  131. package/src/index.ts +6 -3
  132. package/src/plugin/AccomplishmentHandler.ts +1 -1
  133. package/src/plugin/AudioController.ts +58 -0
  134. package/src/plugin/Logger.ts +324 -0
  135. package/src/plugin/PluginController.ts +203 -63
  136. package/src/plugin/RimoriClient.ts +127 -55
  137. package/src/plugin/StandaloneClient.ts +30 -11
  138. package/src/plugin/ThemeSetter.ts +16 -9
  139. package/src/providers/PluginProvider.tsx +46 -13
  140. package/src/utils/Language.ts +4 -2
  141. package/src/utils/difficultyConverter.ts +3 -3
  142. package/src/utils/endpoint.ts +2 -0
  143. package/src/worker/WorkerSetup.ts +13 -60
  144. package/dist/components/PluginController.d.ts +0 -21
  145. package/dist/components/PluginController.js +0 -116
  146. package/dist/controller/AIController.d.ts +0 -23
  147. package/dist/controller/AIController.js +0 -93
  148. package/dist/controller/SidePluginController.d.ts +0 -3
  149. package/dist/controller/SidePluginController.js +0 -31
  150. package/dist/controller/VoiceController.d.ts +0 -10
  151. package/dist/core.d.ts +0 -7
  152. package/dist/core.js +0 -7
  153. package/dist/plugin/ContextMenu.d.ts +0 -17
  154. package/dist/plugin/ContextMenu.js +0 -45
  155. package/dist/plugin/fromRimori/PluginTypes.d.ts +0 -48
  156. package/dist/plugin/fromRimori/SupabaseHandler.d.ts +0 -13
  157. package/dist/plugin/fromRimori/SupabaseHandler.js +0 -55
  158. package/dist/providers/PluginController.d.ts +0 -21
  159. package/dist/providers/PluginController.js +0 -116
  160. package/dist/types/Actions.d.ts +0 -4
  161. package/dist/types/Actions.js +0 -1
  162. package/src/controller/AIController.ts +0 -112
  163. package/src/controller/ObjectController.ts +0 -107
  164. package/src/controller/SidePluginController.ts +0 -25
  165. package/src/controller/VoiceController.ts +0 -26
  166. package/src/core.ts +0 -8
  167. package/src/plugin/fromRimori/PluginTypes.ts +0 -64
  168. package/src/types/Actions.ts +0 -6
  169. /package/dist/{core → components}/components/ContextMenu.d.ts +0 -0
  170. /package/dist/{plugin/fromRimori → fromRimori}/PluginTypes.js +0 -0
  171. /package/src/{plugin/fromRimori → fromRimori}/readme.md +0 -0
@@ -7,16 +7,23 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
7
7
  step((generator = generator.apply(thisArg, _arguments || [])).next());
8
8
  });
9
9
  };
10
- export function getSTTResponse(supabase, audio) {
10
+ export function getSTTResponse(backendUrl, audio, token) {
11
11
  return __awaiter(this, void 0, void 0, function* () {
12
12
  const formData = new FormData();
13
13
  formData.append('file', audio);
14
- return yield supabase.functions.invoke('speech', { method: 'POST', body: formData }).then(({ data }) => data.text);
14
+ return yield fetch(`${backendUrl}/voice/stt`, {
15
+ method: 'POST',
16
+ headers: { 'Authorization': `Bearer ${token}` },
17
+ body: formData,
18
+ }).then(r => r.json()).then(r => {
19
+ // console.log("STT response: ", r);
20
+ return r.text;
21
+ });
15
22
  });
16
23
  }
17
- export function getTTSResponse(supabaseUrl, request, token) {
24
+ export function getTTSResponse(backendUrl, request, token) {
18
25
  return __awaiter(this, void 0, void 0, function* () {
19
- return yield fetch(`${supabaseUrl}/functions/v1/speech`, {
26
+ return yield fetch(`${backendUrl}/voice/tts`, {
20
27
  method: 'POST',
21
28
  headers: {
22
29
  'Content-Type': 'application/json',
@@ -0,0 +1,14 @@
1
+ export * from "../fromRimori/PluginTypes";
2
+ export * from "../plugin/PluginController";
3
+ export * from "../plugin/RimoriClient";
4
+ export * from "../utils/difficultyConverter";
5
+ export * from "../utils/Language";
6
+ export * from "../utils/PluginUtils";
7
+ export * from "../worker/WorkerSetup";
8
+ export { EventBusMessage } from "../fromRimori/EventBus";
9
+ export { Buddy, UserInfo } from "./controller/SettingsController";
10
+ export { SharedContent } from "./controller/SharedContentController";
11
+ export { Message, OnLLMResponse, ToolInvocation } from "./controller/AIController";
12
+ export { MacroAccomplishmentPayload, MicroAccomplishmentPayload } from "../plugin/AccomplishmentHandler";
13
+ export { Tool } from "../fromRimori/PluginTypes";
14
+ export { SharedContentObjectRequest } from "./controller/SharedContentController";
@@ -0,0 +1,8 @@
1
+ // Core functionality exports
2
+ export * from "../fromRimori/PluginTypes";
3
+ export * from "../plugin/PluginController";
4
+ export * from "../plugin/RimoriClient";
5
+ export * from "../utils/difficultyConverter";
6
+ export * from "../utils/Language";
7
+ export * from "../utils/PluginUtils";
8
+ export * from "../worker/WorkerSetup";
@@ -52,7 +52,7 @@ export declare class EventBusHandler {
52
52
  * @param topics - The topic of the event.
53
53
  * @param handler - The handler to be called when the event is emitted.
54
54
  * @param ignoreSender - The senders to ignore.
55
- * @returns The ids of the listeners.
55
+ * @returns An EventListener object containing an off() method to unsubscribe the listeners.
56
56
  */
57
57
  on<T = EventPayload>(topics: string | string[], handler: EventHandler<T>, ignoreSender?: string[]): EventListener;
58
58
  /**
@@ -60,9 +60,9 @@ export declare class EventBusHandler {
60
60
  * @param sender - The sender of the event.
61
61
  * @param topic - The topic of the event.
62
62
  * @param handler - The handler to be called when the event is received. The handler returns the data to be emitted. Can be a static object or a function.
63
- * @returns The ids of the listeners.
63
+ * @returns An EventListener object containing an off() method to unsubscribe the listeners.
64
64
  */
65
- respond(sender: string, topic: string, handler: EventPayload | ((data: EventBusMessage) => EventPayload | Promise<EventPayload>)): EventListener;
65
+ respond(sender: string, topic: string | string[], handler: EventPayload | ((data: EventBusMessage) => EventPayload | Promise<EventPayload>)): EventListener;
66
66
  /**
67
67
  * Subscribes to an event on the event bus. The handler will be called once and then removed.
68
68
  * @param topic - The topic of the event.
@@ -11,7 +11,7 @@ export class EventBusHandler {
11
11
  constructor() {
12
12
  this.listeners = new Map();
13
13
  this.responseResolvers = new Map();
14
- this.debugEnabled = true;
14
+ this.debugEnabled = false;
15
15
  this.evName = "";
16
16
  //private constructor
17
17
  }
@@ -90,7 +90,7 @@ export class EventBusHandler {
90
90
  * @param topics - The topic of the event.
91
91
  * @param handler - The handler to be called when the event is emitted.
92
92
  * @param ignoreSender - The senders to ignore.
93
- * @returns The ids of the listeners.
93
+ * @returns An EventListener object containing an off() method to unsubscribe the listeners.
94
94
  */
95
95
  on(topics, handler, ignoreSender = []) {
96
96
  const ids = this.toArray(topics).map(topic => {
@@ -117,16 +117,33 @@ export class EventBusHandler {
117
117
  * @param sender - The sender of the event.
118
118
  * @param topic - The topic of the event.
119
119
  * @param handler - The handler to be called when the event is received. The handler returns the data to be emitted. Can be a static object or a function.
120
- * @returns The ids of the listeners.
120
+ * @returns An EventListener object containing an off() method to unsubscribe the listeners.
121
121
  */
122
122
  respond(sender, topic, handler) {
123
- const listener = this.on(topic, (data) => __awaiter(this, void 0, void 0, function* () {
124
- const response = typeof handler === "function" ? yield handler(data) : handler;
125
- this.emit(sender, topic, response, data.eventId);
126
- }), [sender]);
127
- this.logIfDebug(`Added respond listener ` + sender + " to topic " + topic, { listener, sender });
123
+ const topics = Array.isArray(topic) ? topic : [topic];
124
+ const listeners = topics.map(topic => {
125
+ const blackListedEventIds = [];
126
+ //To allow event communication inside the same plugin the sender needs to be ignored but the events still need to be checked for the same event just reaching the subscriber to prevent infinite loops
127
+ const finalIgnoreSender = !topic.startsWith("self.") ? [sender] : [];
128
+ const listener = this.on(topic, (data) => __awaiter(this, void 0, void 0, function* () {
129
+ if (blackListedEventIds.includes(data.eventId)) {
130
+ // console.log("BLACKLISTED EVENT ID", data.eventId);
131
+ return;
132
+ }
133
+ blackListedEventIds.push(data.eventId);
134
+ if (blackListedEventIds.length > 20) {
135
+ blackListedEventIds.shift();
136
+ }
137
+ const response = typeof handler === "function" ? yield handler(data) : handler;
138
+ this.emit(sender, topic, response, data.eventId);
139
+ }), finalIgnoreSender);
140
+ this.logIfDebug(`Added respond listener ` + sender + " to topic " + topic, { listener, sender });
141
+ return {
142
+ off: () => listener.off()
143
+ };
144
+ });
128
145
  return {
129
- off: () => listener.off()
146
+ off: () => listeners.forEach(listener => listener.off())
130
147
  };
131
148
  }
132
149
  /**
@@ -0,0 +1,174 @@
1
+ export type Plugin<T extends {} = {}> = Omit<RimoriPluginConfig<T>, 'context_menu_actions'> & {
2
+ version: string;
3
+ endpoint: string;
4
+ assetEndpoint: string;
5
+ context_menu_actions: MenuEntry[];
6
+ release_channel: "alpha" | "beta" | "stable";
7
+ };
8
+ export type ActivePlugin = Plugin<{
9
+ active?: boolean;
10
+ }>;
11
+ export interface PluginPage {
12
+ id: string;
13
+ name: string;
14
+ url: string;
15
+ show: boolean;
16
+ description: string;
17
+ root: "vocabulary" | "grammar" | "reading" | "listening" | "watching" | "writing" | "speaking" | "other" | "community";
18
+ action?: {
19
+ key: string;
20
+ parameters: ObjectTool;
21
+ };
22
+ }
23
+ export interface SidebarPage {
24
+ id: string;
25
+ name: string;
26
+ description: string;
27
+ url: string;
28
+ icon: string;
29
+ }
30
+ export interface MenuEntry {
31
+ plugin_id: string;
32
+ action_key: string;
33
+ text: string;
34
+ icon?: React.ReactNode;
35
+ }
36
+ export type MainPanelAction = {
37
+ plugin_id: string;
38
+ action_key: string;
39
+ } & Record<string, string>;
40
+ export interface ContextMenuAction {
41
+ text: string;
42
+ plugin_id: string;
43
+ action_key: string;
44
+ }
45
+ /**
46
+ * Rimori plugin structure representing the complete configuration
47
+ * of a Rimori plugin with all metadata and configuration options.
48
+ */
49
+ export interface RimoriPluginConfig<T extends {} = {}> {
50
+ id: string;
51
+ /**
52
+ * Basic information about the plugin including branding and core details.
53
+ */
54
+ info: {
55
+ /** The display name of the plugin shown to users */
56
+ title: string;
57
+ /** Detailed description introducing the plugin */
58
+ description: string;
59
+ /** relative or absolute URL or path to the plugin's logo/icon image */
60
+ logo: string;
61
+ /** Optional website URL for the plugin's homepage or link to plugins owner for contributions */
62
+ website?: string;
63
+ };
64
+ /**
65
+ * Configuration for different types of pages.
66
+ */
67
+ pages: {
68
+ /** Optional external URL where the plugin is hosted instead of the default CDN */
69
+ external_hosted_url?: string;
70
+ /** Array of main plugin pages that appear in the application's main navigation (can be disabled using the 'show' flag) */
71
+ main: (PluginPage & T)[];
72
+ /** Array of sidebar pages that appear in the sidebar for quick access (can be disabled using the 'show' flag) */
73
+ sidebar: (SidebarPage & T)[];
74
+ /** Optional path to the plugin's settings/configuration page */
75
+ settings?: string;
76
+ /** Optional array of event topics the plugin pages can listen to for cross-plugin communication */
77
+ topics?: string[];
78
+ };
79
+ /**
80
+ * Context menu actions that the plugin registers to appear in right-click menus throughout the application.
81
+ */
82
+ context_menu_actions: Omit<MenuEntry, "plugin_id">[];
83
+ /**
84
+ * Documentation paths for different types of plugin documentation.
85
+ */
86
+ documentation: {
87
+ /** Path to the general overview documentation. It's shown upon installation of the plugin. */
88
+ overview_path: string;
89
+ /** Path to user-facing documentation and guides */
90
+ user_path: string;
91
+ /** Path to developer documentation for plugin development */
92
+ developer_path: string;
93
+ };
94
+ /**
95
+ * Configuration for the plugin's web worker if it uses background processing or exposes actions to other plugins.
96
+ */
97
+ worker?: {
98
+ /** Relative path to the web worker JavaScript file. Mostly it's 'web-worker.js' which is located in the public folder. */
99
+ url: string;
100
+ /** Optional array of event topics the worker should listen to in addition to events having the pluginId in the topic. Can be a wildcard. Example: 'global.topic.*' or 'pluginId.*' */
101
+ topics?: string[];
102
+ };
103
+ }
104
+ export interface Tool {
105
+ name: string;
106
+ description: string;
107
+ parameters: {
108
+ name: string;
109
+ description: string;
110
+ type: "string" | "number" | "boolean";
111
+ }[];
112
+ execute?: (args: Record<string, any>) => Promise<unknown> | unknown | void;
113
+ }
114
+ /**
115
+ * The tool definition structure is used for LLM function calling and plugin action parameters.
116
+ * It defines the schema for tools that can be used by Language Learning Models (LLMs)
117
+ * and plugin actions.
118
+ *
119
+ * @example
120
+ * ```typescript
121
+ * const flashcardTool: Tool = {
122
+ * total_amount: {
123
+ * type: 'string',
124
+ * enum: ['default', '10', '20', '50'],
125
+ * description: 'Number of flashcards to practice'
126
+ * },
127
+ * deck: {
128
+ * type: 'string',
129
+ * enum: ['latest', 'random', 'oldest', 'mix', 'best_known'],
130
+ * description: 'Type of deck to practice'
131
+ * }
132
+ * };
133
+ * ```
134
+ *
135
+ */
136
+ export type ObjectTool = {
137
+ [key: string]: ToolParameter;
138
+ };
139
+ /**
140
+ * Parameter definition for LLM tools and plugin actions.
141
+ * Defines the structure, validation rules, and metadata for individual tool parameters.
142
+ * Used to create type-safe interfaces between LLMs, plugins, and the Rimori platform.
143
+ */
144
+ interface ToolParameter {
145
+ /** The data type of the parameter - can be primitive, nested object, or array */
146
+ type: ToolParameterType;
147
+ /** Human-readable description of the parameter's purpose and usage */
148
+ description: string;
149
+ /** Optional array of allowed values for enumerated parameters */
150
+ enum?: string[];
151
+ /** Whether the parameter is optional */
152
+ optional?: boolean;
153
+ }
154
+ /**
155
+ * Union type defining all possible parameter types for LLM tools.
156
+ * Supports primitive types, nested objects for complex data structures,
157
+ * and arrays of objects for collections. The tuple notation [{}] indicates
158
+ * arrays of objects with a specific structure.
159
+ *
160
+ * @example Primitive: 'string' | 'number' | 'boolean'
161
+ * @example Nested object: { name: { type: 'string' }, age: { type: 'number' } }
162
+ * @example Array of objects: [{ id: { type: 'string' }, value: { type: 'number' } }]
163
+ */
164
+ type ToolParameterType = PrimitiveType | {
165
+ [key: string]: ToolParameter;
166
+ } | [{
167
+ [key: string]: ToolParameter;
168
+ }];
169
+ /**
170
+ * Primitive data types supported by the LLM tool system.
171
+ * These align with JSON schema primitive types and TypeScript basic types.
172
+ */
173
+ type PrimitiveType = 'string' | 'number' | 'boolean';
174
+ export {};
@@ -1,5 +1,6 @@
1
1
  import React from "react";
2
- import { Message, Tool } from "../controller/AIController";
2
+ import { Tool } from "../fromRimori/PluginTypes";
3
+ import { Message } from "../core/controller/AIController";
3
4
  export declare function useChat(tools?: Tool[]): {
4
5
  messages: Message[];
5
6
  append: (appendMessages: Message[]) => void;
@@ -1,11 +1,13 @@
1
1
  import React from "react";
2
- import { usePlugin } from "../providers/PluginProvider";
2
+ import { useRimori } from "../providers/PluginProvider";
3
3
  export function useChat(tools) {
4
4
  const [messages, setMessages] = React.useState([]);
5
5
  const [isLoading, setIsLoading] = React.useState(false);
6
- const { llm } = usePlugin();
6
+ const { ai } = useRimori();
7
7
  const append = (appendMessages) => {
8
- llm.getSteamedText([...messages, ...appendMessages], (id, message, finished, toolInvocations) => {
8
+ const allMessages = [...messages, ...appendMessages];
9
+ setMessages(allMessages);
10
+ ai.getSteamedText(allMessages, (id, message, finished, toolInvocations) => {
9
11
  const lastMessage = messages[messages.length - 1];
10
12
  setIsLoading(!finished);
11
13
  if ((lastMessage === null || lastMessage === void 0 ? void 0 : lastMessage.id) === id) {
@@ -13,7 +15,7 @@ export function useChat(tools) {
13
15
  setMessages([...messages, lastMessage]);
14
16
  }
15
17
  else {
16
- setMessages([...messages, ...appendMessages, { id, role: 'assistant', content: message, toolInvocations }]);
18
+ setMessages([...allMessages, { id, role: 'assistant', content: message, toolCalls: toolInvocations }]);
17
19
  }
18
20
  }, tools);
19
21
  };
@@ -0,0 +1,30 @@
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
+ };
@@ -0,0 +1,122 @@
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
+ }
package/dist/index.d.ts CHANGED
@@ -1,8 +1,11 @@
1
- export * from './core';
2
1
  export * from './components';
3
2
  export * from "./hooks/UseChatHook";
4
- export * from "./plugin/RimoriClient";
3
+ export * from "./plugin/PluginController";
5
4
  export * from "./providers/PluginProvider";
5
+ export * from "./cli/types/DatabaseTypes";
6
6
  export * from "./utils/difficultyConverter";
7
7
  export * from "./utils/PluginUtils";
8
- export * from "./plugin/PluginController";
8
+ export * from "./utils/Language";
9
+ export * from "./fromRimori/PluginTypes";
10
+ export { FirstMessages } from "./components/ai/utils";
11
+ export { AudioController } from "./plugin/AudioController";
package/dist/index.js CHANGED
@@ -1,9 +1,11 @@
1
1
  // Re-export everything
2
- export * from './core';
3
2
  export * from './components';
4
3
  export * from "./hooks/UseChatHook";
5
- export * from "./plugin/RimoriClient";
4
+ export * from "./plugin/PluginController";
6
5
  export * from "./providers/PluginProvider";
6
+ export * from "./cli/types/DatabaseTypes";
7
7
  export * from "./utils/difficultyConverter";
8
8
  export * from "./utils/PluginUtils";
9
- export * from "./plugin/PluginController";
9
+ export * from "./utils/Language";
10
+ export * from "./fromRimori/PluginTypes";
11
+ export { AudioController } from "./plugin/AudioController";
@@ -1,4 +1,4 @@
1
- import { EventBusMessage } from "./fromRimori/EventBus";
1
+ import { EventBusMessage } from "../fromRimori/EventBus";
2
2
  export type AccomplishmentMessage = EventBusMessage<MicroAccomplishmentPayload>;
3
3
  export declare const skillCategories: readonly ["reading", "listening", "speaking", "writing", "learning", "community"];
4
4
  interface BaseAccomplishmentPayload {
@@ -1,4 +1,4 @@
1
- import { EventBus } from "./fromRimori/EventBus";
1
+ import { EventBus } from "../fromRimori/EventBus";
2
2
  export const skillCategories = ["reading", "listening", "speaking", "writing", "learning", "community"];
3
3
  export class AccomplishmentHandler {
4
4
  constructor(pluginId) {
@@ -0,0 +1,37 @@
1
+ /**
2
+ * AudioController is a class that provides methods to record audio. It is a wrapper around the Capacitor Voice Recorder plugin. For more information, see https://github.com/tchvu3/capacitor-voice-recorder.
3
+ *
4
+ * @example
5
+ * const audioController = new AudioController();
6
+ * await audioController.startRecording();
7
+ */
8
+ export declare class AudioController {
9
+ private pluginId;
10
+ constructor(pluginId: string);
11
+ /**
12
+ * Start the recording.
13
+ *
14
+ * @example
15
+ * const audioController = new AudioController();
16
+ * await audioController.startRecording();
17
+ * @returns void
18
+ */
19
+ startRecording(): Promise<void>;
20
+ /**
21
+ * Stop the recording and return the audio data.
22
+ * @returns The audio data.
23
+ *
24
+ * @example
25
+ * const audioRef = new Audio(`data:${mimeType};base64,${base64Sound}`)
26
+ * audioRef.oncanplaythrough = () => audioRef.play()
27
+ * audioRef.load()
28
+ */
29
+ stopRecording(): Promise<{
30
+ recording: Blob;
31
+ msDuration: number;
32
+ mimeType: string;
33
+ }>;
34
+ pauseRecording(): Promise<boolean>;
35
+ resumeRecording(): Promise<boolean>;
36
+ getCurrentStatus(): Promise<"RECORDING" | "PAUSED" | "NONE">;
37
+ }
@@ -0,0 +1,68 @@
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 { EventBus } from "../fromRimori/EventBus";
11
+ /**
12
+ * AudioController is a class that provides methods to record audio. It is a wrapper around the Capacitor Voice Recorder plugin. For more information, see https://github.com/tchvu3/capacitor-voice-recorder.
13
+ *
14
+ * @example
15
+ * const audioController = new AudioController();
16
+ * await audioController.startRecording();
17
+ */
18
+ export class AudioController {
19
+ constructor(pluginId) {
20
+ this.pluginId = pluginId;
21
+ }
22
+ /**
23
+ * Start the recording.
24
+ *
25
+ * @example
26
+ * const audioController = new AudioController();
27
+ * await audioController.startRecording();
28
+ * @returns void
29
+ */
30
+ startRecording() {
31
+ return __awaiter(this, void 0, void 0, function* () {
32
+ EventBus.emit(this.pluginId, "global.microphone.triggerStartRecording");
33
+ });
34
+ }
35
+ /**
36
+ * Stop the recording and return the audio data.
37
+ * @returns The audio data.
38
+ *
39
+ * @example
40
+ * const audioRef = new Audio(`data:${mimeType};base64,${base64Sound}`)
41
+ * audioRef.oncanplaythrough = () => audioRef.play()
42
+ * audioRef.load()
43
+ */
44
+ stopRecording() {
45
+ return __awaiter(this, void 0, void 0, function* () {
46
+ const result = yield EventBus.request(this.pluginId, "global.microphone.triggerStopRecording");
47
+ return result.data;
48
+ });
49
+ }
50
+ pauseRecording() {
51
+ return __awaiter(this, void 0, void 0, function* () {
52
+ const result = yield EventBus.request(this.pluginId, "global.microphone.triggerPauseRecording");
53
+ return result.data;
54
+ });
55
+ }
56
+ resumeRecording() {
57
+ return __awaiter(this, void 0, void 0, function* () {
58
+ const result = yield EventBus.request(this.pluginId, "global.microphone.triggerResumeRecording");
59
+ return result.data;
60
+ });
61
+ }
62
+ getCurrentStatus() {
63
+ return __awaiter(this, void 0, void 0, function* () {
64
+ const result = yield EventBus.request(this.pluginId, "global.microphone.triggerGetCurrentStatus");
65
+ return result.data;
66
+ });
67
+ }
68
+ }