@rimori/client 1.0.3 → 1.0.5

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 (135) hide show
  1. package/README.md +51 -0
  2. package/dist/components/CRUDModal.js +0 -1
  3. package/dist/components/ai/Assistant.d.ts +9 -0
  4. package/dist/components/ai/Assistant.js +59 -0
  5. package/dist/components/ai/Avatar.d.ts +11 -0
  6. package/dist/components/ai/Avatar.js +39 -0
  7. package/dist/components/ai/EmbeddedAssistent/AudioInputField.d.ts +7 -0
  8. package/dist/components/ai/EmbeddedAssistent/AudioInputField.js +38 -0
  9. package/dist/components/ai/EmbeddedAssistent/CircleAudioAvatar.d.ts +7 -0
  10. package/dist/components/ai/EmbeddedAssistent/CircleAudioAvatar.js +59 -0
  11. package/dist/components/ai/EmbeddedAssistent/TTS/MessageSender.d.ts +19 -0
  12. package/dist/components/ai/EmbeddedAssistent/TTS/MessageSender.js +86 -0
  13. package/dist/components/ai/EmbeddedAssistent/TTS/Player.d.ts +25 -0
  14. package/dist/components/ai/EmbeddedAssistent/TTS/Player.js +180 -0
  15. package/dist/components/ai/EmbeddedAssistent/VoiceRecoder.d.ts +7 -0
  16. package/dist/components/ai/EmbeddedAssistent/VoiceRecoder.js +45 -0
  17. package/dist/components/ai/utils.d.ts +6 -0
  18. package/dist/components/ai/utils.js +14 -0
  19. package/dist/components/audio/Playbutton.js +4 -5
  20. package/dist/components/avatar/Assistant.d.ts +9 -0
  21. package/dist/components/avatar/Assistant.js +59 -0
  22. package/dist/components/avatar/Avatar.d.ts +12 -0
  23. package/dist/components/avatar/Avatar.js +42 -0
  24. package/dist/components/avatar/EmbeddedAssistent/AudioInputField.d.ts +7 -0
  25. package/dist/components/avatar/EmbeddedAssistent/AudioInputField.js +38 -0
  26. package/dist/components/avatar/EmbeddedAssistent/CircleAudioAvatar.d.ts +7 -0
  27. package/dist/components/avatar/EmbeddedAssistent/CircleAudioAvatar.js +59 -0
  28. package/dist/components/avatar/EmbeddedAssistent/TTS/MessageSender.d.ts +19 -0
  29. package/dist/components/avatar/EmbeddedAssistent/TTS/MessageSender.js +84 -0
  30. package/dist/components/avatar/EmbeddedAssistent/TTS/Player.d.ts +25 -0
  31. package/dist/components/avatar/EmbeddedAssistent/TTS/Player.js +180 -0
  32. package/dist/components/avatar/EmbeddedAssistent/VoiceRecoder.d.ts +7 -0
  33. package/dist/components/avatar/EmbeddedAssistent/VoiceRecoder.js +45 -0
  34. package/dist/components/avatar/utils.d.ts +6 -0
  35. package/dist/components/avatar/utils.js +14 -0
  36. package/dist/components.d.ts +9 -0
  37. package/dist/components.js +10 -0
  38. package/dist/controller/AIController.d.ts +4 -3
  39. package/dist/controller/AIController.js +32 -8
  40. package/dist/controller/ObjectController.d.ts +2 -2
  41. package/dist/controller/ObjectController.js +4 -5
  42. package/dist/controller/SettingsController.d.ts +19 -10
  43. package/dist/controller/SettingsController.js +33 -26
  44. package/dist/controller/SharedContentController.js +6 -6
  45. package/dist/core.d.ts +9 -0
  46. package/dist/core.js +10 -0
  47. package/dist/hooks/UseChatHook.js +2 -2
  48. package/dist/index.d.ts +3 -2
  49. package/dist/index.js +4 -2
  50. package/dist/plugin/PluginController.d.ts +4 -12
  51. package/dist/plugin/PluginController.js +45 -70
  52. package/dist/plugin/RimoriClient.d.ts +85 -32
  53. package/dist/plugin/RimoriClient.js +98 -77
  54. package/dist/plugin/ThemeSetter.js +3 -3
  55. package/dist/plugin/fromRimori/EventBus.d.ts +98 -0
  56. package/dist/plugin/fromRimori/EventBus.js +240 -0
  57. package/dist/providers/PluginProvider.d.ts +1 -0
  58. package/dist/providers/PluginProvider.js +10 -12
  59. package/dist/worker/WorkerSetup.d.ts +6 -0
  60. package/dist/worker/WorkerSetup.js +80 -0
  61. package/package.json +17 -3
  62. package/src/components/CRUDModal.tsx +1 -3
  63. package/src/components/ai/Assistant.tsx +96 -0
  64. package/src/components/ai/Avatar.tsx +61 -0
  65. package/src/components/ai/EmbeddedAssistent/AudioInputField.tsx +64 -0
  66. package/src/components/ai/EmbeddedAssistent/CircleAudioAvatar.tsx +75 -0
  67. package/src/components/ai/EmbeddedAssistent/TTS/MessageSender.ts +91 -0
  68. package/src/components/ai/EmbeddedAssistent/TTS/Player.ts +192 -0
  69. package/src/components/ai/EmbeddedAssistent/VoiceRecoder.tsx +56 -0
  70. package/src/components/ai/utils.ts +23 -0
  71. package/src/components/audio/Playbutton.tsx +4 -5
  72. package/src/components.ts +10 -0
  73. package/src/controller/AIController.ts +84 -60
  74. package/src/controller/ObjectController.ts +4 -6
  75. package/src/controller/SettingsController.ts +49 -35
  76. package/src/controller/SharedContentController.ts +6 -6
  77. package/src/core.ts +10 -0
  78. package/src/hooks/UseChatHook.ts +2 -2
  79. package/src/index.ts +4 -2
  80. package/src/plugin/PluginController.ts +51 -76
  81. package/src/plugin/RimoriClient.ts +147 -85
  82. package/src/plugin/ThemeSetter.ts +3 -4
  83. package/src/plugin/fromRimori/EventBus.ts +301 -0
  84. package/src/plugin/fromRimori/readme.md +2 -0
  85. package/src/providers/PluginProvider.tsx +12 -14
  86. package/src/worker/WorkerSetup.ts +81 -0
  87. package/dist/CRUDModal.d.ts +0 -16
  88. package/dist/CRUDModal.js +0 -31
  89. package/dist/MarkdownEditor.d.ts +0 -8
  90. package/dist/MarkdownEditor.js +0 -46
  91. package/dist/audio/Playbutton.d.ts +0 -14
  92. package/dist/audio/Playbutton.js +0 -73
  93. package/dist/components/hooks/UseChatHook.d.ts +0 -15
  94. package/dist/components/hooks/UseChatHook.js +0 -21
  95. package/dist/controller/PluginController.d.ts +0 -14
  96. package/dist/controller/PluginController.js +0 -30
  97. package/dist/plugin/AIController copy.d.ts +0 -22
  98. package/dist/plugin/AIController copy.js +0 -68
  99. package/dist/plugin/AIController.d.ts +0 -22
  100. package/dist/plugin/AIController.js +0 -68
  101. package/dist/plugin/ObjectController.d.ts +0 -34
  102. package/dist/plugin/ObjectController.js +0 -77
  103. package/dist/plugin/SettingController.d.ts +0 -13
  104. package/dist/plugin/SettingController.js +0 -55
  105. package/dist/plugin/VoiceController.d.ts +0 -2
  106. package/dist/plugin/VoiceController.js +0 -27
  107. package/dist/providers/EventEmitter.d.ts +0 -11
  108. package/dist/providers/EventEmitter.js +0 -41
  109. package/dist/providers/EventEmitterContext.d.ts +0 -6
  110. package/dist/providers/EventEmitterContext.js +0 -19
  111. package/dist/utils/DifficultyConverter.d.ts +0 -3
  112. package/dist/utils/DifficultyConverter.js +0 -7
  113. package/dist/utils/constants.d.ts +0 -4
  114. package/dist/utils/constants.js +0 -12
  115. package/dist/utils/plugin/Client.d.ts +0 -72
  116. package/dist/utils/plugin/Client.js +0 -118
  117. package/dist/utils/plugin/PluginController.d.ts +0 -36
  118. package/dist/utils/plugin/PluginController.js +0 -119
  119. package/dist/utils/plugin/PluginUtils.d.ts +0 -2
  120. package/dist/utils/plugin/PluginUtils.js +0 -23
  121. package/dist/utils/plugin/RimoriClient.d.ts +0 -72
  122. package/dist/utils/plugin/RimoriClient.js +0 -118
  123. package/dist/utils/plugin/ThemeSetter.d.ts +0 -1
  124. package/dist/utils/plugin/ThemeSetter.js +0 -13
  125. package/dist/utils/plugin/WhereClauseBuilder.d.ts +0 -24
  126. package/dist/utils/plugin/WhereClauseBuilder.js +0 -79
  127. package/dist/utils/plugin/providers/EventEmitter.d.ts +0 -11
  128. package/dist/utils/plugin/providers/EventEmitter.js +0 -41
  129. package/dist/utils/plugin/providers/EventEmitterContext.d.ts +0 -6
  130. package/dist/utils/plugin/providers/EventEmitterContext.js +0 -19
  131. package/dist/utils/plugin/providers/PluginProvider.d.ts +0 -8
  132. package/dist/utils/plugin/providers/PluginProvider.js +0 -49
  133. package/src/providers/EventEmitter.ts +0 -48
  134. package/src/providers/EventEmitterContext.tsx +0 -27
  135. package/src/utils/constants.ts +0 -18
@@ -0,0 +1,45 @@
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 } from "react/jsx-runtime";
11
+ import { useState, useRef, forwardRef, useImperativeHandle } from 'react';
12
+ import { FaMicrophone } from 'react-icons/fa6';
13
+ import { usePlugin } from '../../../components';
14
+ export const VoiceRecorder = forwardRef(({ onVoiceRecorded, iconSize, className }, ref) => {
15
+ const [isRecording, setIsRecording] = useState(false);
16
+ const mediaRecorderRef = useRef(null);
17
+ const audioChunksRef = useRef([]);
18
+ const { llm } = usePlugin();
19
+ const startRecording = () => __awaiter(void 0, void 0, void 0, function* () {
20
+ const stream = yield navigator.mediaDevices.getUserMedia({ audio: true });
21
+ const mediaRecorder = new MediaRecorder(stream);
22
+ mediaRecorderRef.current = mediaRecorder;
23
+ mediaRecorder.ondataavailable = (event) => {
24
+ audioChunksRef.current.push(event.data);
25
+ };
26
+ mediaRecorder.onstop = () => __awaiter(void 0, void 0, void 0, function* () {
27
+ const audioBlob = new Blob(audioChunksRef.current);
28
+ audioChunksRef.current = [];
29
+ onVoiceRecorded(yield llm.getTextFromVoice(audioBlob));
30
+ });
31
+ mediaRecorder.start();
32
+ setIsRecording(true);
33
+ });
34
+ const stopRecording = () => {
35
+ if (mediaRecorderRef.current) {
36
+ mediaRecorderRef.current.stop();
37
+ setIsRecording(false);
38
+ }
39
+ };
40
+ useImperativeHandle(ref, () => ({
41
+ startRecording,
42
+ stopRecording,
43
+ }));
44
+ return (_jsx("div", { className: className, children: _jsx("button", { onClick: isRecording ? stopRecording : startRecording, children: _jsx(FaMicrophone, { size: iconSize, className: "h-7 w-7 mr-2 " + (isRecording ? "text-red-600" : "") }) }) }));
45
+ });
@@ -0,0 +1,6 @@
1
+ export interface FirstMessages {
2
+ instructions?: string;
3
+ userMessage: string;
4
+ assistantMessage?: string;
5
+ }
6
+ export declare function getFirstMessages(instructions: FirstMessages): any[];
@@ -0,0 +1,14 @@
1
+ export function getFirstMessages(instructions) {
2
+ const messages = [];
3
+ if (instructions.instructions) {
4
+ messages.push({ id: '1', role: 'system', content: instructions.instructions });
5
+ }
6
+ if (instructions.userMessage) {
7
+ messages.push({ id: '2', role: 'user', content: instructions.userMessage });
8
+ }
9
+ if (instructions.assistantMessage) {
10
+ messages.push({ id: '3', role: 'assistant', content: instructions.assistantMessage });
11
+ }
12
+ console.log("getFirstMessages", messages);
13
+ return messages;
14
+ }
@@ -0,0 +1,9 @@
1
+ export * from "./components/MarkdownEditor";
2
+ export * from "./components/CRUDModal";
3
+ export * from "./components/Spinner";
4
+ export * from "./components/audio/Playbutton";
5
+ export * from "./hooks/UseChatHook";
6
+ export * from "./plugin/ThemeSetter";
7
+ export * from "./providers/PluginProvider";
8
+ export * from "./components/ai/Avatar";
9
+ export * from "./components/ai/Assistant";
@@ -0,0 +1,10 @@
1
+ // React components and hooks exports
2
+ export * from "./components/MarkdownEditor";
3
+ export * from "./components/CRUDModal";
4
+ export * from "./components/Spinner";
5
+ export * from "./components/audio/Playbutton";
6
+ export * from "./hooks/UseChatHook";
7
+ export * from "./plugin/ThemeSetter";
8
+ export * from "./providers/PluginProvider";
9
+ export * from "./components/ai/Avatar";
10
+ export * from "./components/ai/Assistant";
@@ -7,9 +7,10 @@ export interface Tool {
7
7
  description: string;
8
8
  parameters: {
9
9
  name: string;
10
- type: "string" | "number" | "boolean";
11
10
  description: string;
11
+ type: "string" | "number" | "boolean";
12
12
  }[];
13
+ execute?: <T = Record<string, string | boolean | number>>(args: T) => Promise<any> | void;
13
14
  }
14
15
  export interface Message {
15
16
  id: string;
@@ -17,6 +18,6 @@ export interface Message {
17
18
  content: string;
18
19
  toolInvocations?: ToolInvocation[];
19
20
  }
20
- export declare function generateText(messages: Message[], tools: Tool[], token: string): Promise<any>;
21
+ export declare function generateText(supabaseUrl: string, messages: Message[], tools: Tool[], token: string): Promise<any>;
21
22
  export type OnLLMResponse = (id: string, response: string, finished: boolean, toolInvocations?: ToolInvocation[]) => void;
22
- export declare function streamChatGPT(messages: Message[], tools: Tool[], onResponse: OnLLMResponse, token: string): Promise<void>;
23
+ export declare function streamChatGPT(supabaseUrl: string, messages: Message[], tools: Tool[], onResponse: OnLLMResponse, token: string): Promise<void>;
@@ -7,24 +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
- import { env } from "../utils/constants";
11
- export function generateText(messages, tools, token) {
10
+ export function generateText(supabaseUrl, messages, tools, token) {
12
11
  return __awaiter(this, void 0, void 0, function* () {
13
- const response = yield fetch(`${env.SUPABASE_URL}/functions/v1/llm`, {
12
+ const response = yield fetch(`${supabaseUrl}/functions/v1/llm`, {
14
13
  method: 'POST',
15
14
  body: JSON.stringify({ messages, tools }),
16
- headers: { 'Authorization': `Bearer ${token}` }
15
+ headers: { 'Authorization': `Bearer ${token}`, 'Content-Type': 'application/json' }
17
16
  });
18
17
  return yield response.json();
19
18
  });
20
19
  }
21
- export function streamChatGPT(messages, tools, onResponse, token) {
20
+ export function streamChatGPT(supabaseUrl, messages, tools, onResponse, token) {
22
21
  return __awaiter(this, void 0, void 0, function* () {
23
22
  const messageId = Math.random().toString(36).substring(3);
24
- const response = yield fetch(`${env.SUPABASE_URL}/functions/v1/llm`, {
23
+ const response = yield fetch(`${supabaseUrl}/functions/v1/llm`, {
25
24
  method: 'POST',
26
25
  body: JSON.stringify({ messages, tools, stream: true }),
27
- headers: { 'Authorization': `Bearer ${token}` }
26
+ headers: { 'Authorization': `Bearer ${token}`, 'Content-Type': 'application/json' }
28
27
  });
29
28
  if (!response.body) {
30
29
  console.error('No response body.');
@@ -58,10 +57,35 @@ export function streamChatGPT(messages, tools, onResponse, token) {
58
57
  else if (command === '9') {
59
58
  // console.log("tool call:", JSON.parse(line.substring(2)));
60
59
  // console.log("tools", tools);
61
- toolInvocations.push(JSON.parse(line.substring(2)));
60
+ const toolInvocation = JSON.parse(line.substring(2));
61
+ toolInvocations.push(toolInvocation);
62
+ // Find the tool and execute it if it has an execute function
63
+ const tool = tools.find(t => t.name === toolInvocation.toolName);
64
+ // console.log("tool", tool);
65
+ if (tool && tool.execute) {
66
+ try {
67
+ const result = yield tool.execute(toolInvocation.args);
68
+ const toolResult = { success: true, result: result };
69
+ // Add the tool result as a message
70
+ messages.push({
71
+ id: Math.random().toString(36).substring(3),
72
+ role: "function",
73
+ content: JSON.stringify(toolResult),
74
+ toolInvocations: [{
75
+ args: toolInvocation.args,
76
+ toolName: toolInvocation.toolName,
77
+ }]
78
+ });
79
+ }
80
+ catch (error) {
81
+ console.error(`Error executing tool ${toolInvocation.toolName}:`, error);
82
+ }
83
+ }
62
84
  }
63
85
  }
64
86
  }
87
+ // Wait for 5ms to avoid blocking the main thread
88
+ yield new Promise(resolve => setTimeout(resolve, 5));
65
89
  }
66
90
  onResponse(messageId, content.replace(/\\n/g, '\n'), true, toolInvocations);
67
91
  });
@@ -28,7 +28,7 @@ export interface ObjectRequest {
28
28
  */
29
29
  instructions: string;
30
30
  }
31
- export declare function generateObject(request: ObjectRequest, token: string): Promise<any>;
31
+ export declare function generateObject(supabaseUrl: string, request: ObjectRequest, token: string): Promise<any>;
32
32
  export type OnLLMResponse = (id: string, response: string, finished: boolean, toolInvocations?: any[]) => void;
33
- export declare function streamObject(request: ObjectRequest, onResponse: OnLLMResponse, token: string): Promise<void>;
33
+ export declare function streamObject(supabaseUrl: string, request: ObjectRequest, onResponse: OnLLMResponse, token: string): Promise<void>;
34
34
  export {};
@@ -7,10 +7,9 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
7
7
  step((generator = generator.apply(thisArg, _arguments || [])).next());
8
8
  });
9
9
  };
10
- import { env } from "../utils/constants";
11
- export function generateObject(request, token) {
10
+ export function generateObject(supabaseUrl, request, token) {
12
11
  return __awaiter(this, void 0, void 0, function* () {
13
- return yield fetch(`${env.SUPABASE_URL}/functions/v1/llm-object`, {
12
+ return yield fetch(`${supabaseUrl}/functions/v1/llm-object`, {
14
13
  method: 'POST',
15
14
  body: JSON.stringify({
16
15
  stream: false,
@@ -22,10 +21,10 @@ export function generateObject(request, token) {
22
21
  }).then(response => response.json());
23
22
  });
24
23
  }
25
- export function streamObject(request, onResponse, token) {
24
+ export function streamObject(supabaseUrl, request, onResponse, token) {
26
25
  return __awaiter(this, void 0, void 0, function* () {
27
26
  const messageId = Math.random().toString(36).substring(3);
28
- const response = yield fetch(`${env.SUPABASE_URL}/functions/v1/llm-object`, {
27
+ const response = yield fetch(`${supabaseUrl}/functions/v1/llm-object`, {
29
28
  method: 'POST',
30
29
  body: JSON.stringify({
31
30
  stream: true,
@@ -1,25 +1,34 @@
1
1
  import { SupabaseClient } from "@supabase/supabase-js";
2
2
  import { LanguageLevel } from "../utils/difficultyConverter";
3
- export interface UserSettings {
3
+ export interface UserInfo {
4
4
  motherTongue: string;
5
- languageLevel: LanguageLevel;
6
- contextMenuOnSelect: boolean;
7
- }
8
- export interface SystemSettings {
5
+ xp: number;
6
+ listening_level: LanguageLevel;
7
+ reading_level: LanguageLevel;
8
+ speaking_level: LanguageLevel;
9
+ writing_level: LanguageLevel;
10
+ understanding_level: LanguageLevel;
11
+ grammar_level: LanguageLevel;
12
+ longterm_goal: string;
13
+ motivation_type: string;
14
+ study_buddy: string;
15
+ preferred_genre: string;
16
+ milestone: string;
17
+ settings: {
18
+ contextMenuOnSelect: boolean;
19
+ };
9
20
  }
10
21
  export declare class SettingsController {
11
22
  private pluginId;
12
23
  private supabase;
13
24
  constructor(supabase: SupabaseClient, pluginId: string);
14
- private getSettingsType;
15
25
  private fetchSettings;
16
- private saveSettings;
26
+ setSettings(settings: any): Promise<void>;
27
+ getUserInfo(): Promise<UserInfo>;
17
28
  /**
18
29
  * Get the settings for the plugin. T can be any type of settings, UserSettings or SystemSettings.
19
30
  * @param defaultSettings The default settings to use if no settings are found.
20
- * @param genericSettings The type of settings to get.
21
31
  * @returns The settings for the plugin.
22
32
  */
23
- getSettings<T extends object>(defaultSettings: T, genericSettings?: "user" | "system"): Promise<T>;
24
- setSettings(settings: any, genericSettings?: "user" | "system"): Promise<void>;
33
+ getSettings<T extends object>(defaultSettings: T): Promise<T>;
25
34
  }
@@ -12,41 +12,56 @@ export class SettingsController {
12
12
  this.supabase = supabase;
13
13
  this.pluginId = pluginId;
14
14
  }
15
- getSettingsType(genericSettings) {
16
- return genericSettings || "plugin";
17
- }
18
- fetchSettings(type) {
15
+ fetchSettings() {
19
16
  return __awaiter(this, void 0, void 0, function* () {
20
- const pluginId = type === "plugin" ? this.pluginId : type;
21
- const { data } = yield this.supabase.from("plugin_settings").select("*").eq("plugin_id", pluginId);
17
+ const { data } = yield this.supabase.from("plugin_settings").select("*").eq("plugin_id", this.pluginId);
22
18
  if (!data || data.length === 0) {
23
19
  return null;
24
20
  }
25
21
  return data[0].settings;
26
22
  });
27
23
  }
28
- saveSettings(settings, type) {
24
+ setSettings(settings) {
29
25
  return __awaiter(this, void 0, void 0, function* () {
30
- if (type !== "plugin") {
31
- throw new Error(`Cannot modify ${type} settings`);
32
- }
33
26
  yield this.supabase.from("plugin_settings").upsert({ plugin_id: this.pluginId, settings });
34
27
  });
35
28
  }
29
+ getUserInfo() {
30
+ return __awaiter(this, void 0, void 0, function* () {
31
+ const { data } = yield this.supabase.from("profiles").select("*");
32
+ if (!data || data.length === 0) {
33
+ return {
34
+ motherTongue: "en",
35
+ xp: 0,
36
+ listening_level: "Pre-A1",
37
+ reading_level: "Pre-A1",
38
+ speaking_level: "Pre-A1",
39
+ writing_level: "Pre-A1",
40
+ understanding_level: "Pre-A1",
41
+ grammar_level: "Pre-A1",
42
+ longterm_goal: "",
43
+ motivation_type: "self-motivated",
44
+ study_buddy: "clarence",
45
+ preferred_genre: "adventure",
46
+ milestone: "",
47
+ settings: {
48
+ contextMenuOnSelect: false,
49
+ }
50
+ };
51
+ }
52
+ return data[0];
53
+ });
54
+ }
36
55
  /**
37
56
  * Get the settings for the plugin. T can be any type of settings, UserSettings or SystemSettings.
38
57
  * @param defaultSettings The default settings to use if no settings are found.
39
- * @param genericSettings The type of settings to get.
40
58
  * @returns The settings for the plugin.
41
59
  */
42
- getSettings(defaultSettings, genericSettings) {
60
+ getSettings(defaultSettings) {
43
61
  return __awaiter(this, void 0, void 0, function* () {
44
- const type = this.getSettingsType(genericSettings);
45
- const storedSettings = yield this.fetchSettings(type);
62
+ const storedSettings = yield this.fetchSettings();
46
63
  if (!storedSettings) {
47
- if (type === "plugin") {
48
- yield this.saveSettings(defaultSettings, type);
49
- }
64
+ yield this.setSettings(defaultSettings);
50
65
  return defaultSettings;
51
66
  }
52
67
  // Handle settings migration
@@ -55,18 +70,10 @@ export class SettingsController {
55
70
  if (storedKeys.length !== defaultKeys.length) {
56
71
  const validStoredSettings = Object.fromEntries(Object.entries(storedSettings).filter(([key]) => defaultKeys.includes(key)));
57
72
  const mergedSettings = Object.assign(Object.assign({}, defaultSettings), validStoredSettings);
58
- if (type === "plugin") {
59
- yield this.saveSettings(mergedSettings, type);
60
- }
73
+ yield this.setSettings(mergedSettings);
61
74
  return mergedSettings;
62
75
  }
63
76
  return storedSettings;
64
77
  });
65
78
  }
66
- setSettings(settings, genericSettings) {
67
- return __awaiter(this, void 0, void 0, function* () {
68
- const type = this.getSettingsType(genericSettings);
69
- yield this.saveSettings(settings, type);
70
- });
71
- }
72
79
  }
@@ -15,23 +15,23 @@ export class SharedContentController {
15
15
  fetchNewSharedContent(type, generatorInstructions, filter) {
16
16
  return __awaiter(this, void 0, void 0, function* () {
17
17
  const queryParameter = { filter_column: (filter === null || filter === void 0 ? void 0 : filter.column) || null, filter_value: (filter === null || filter === void 0 ? void 0 : filter.value) || null, unread: true };
18
- const { data: newAssignments } = yield this.rimoriClient.rpc(type + "_entries", queryParameter);
18
+ const { data: newAssignments } = yield this.rimoriClient.db.rpc(type + "_entries", queryParameter);
19
19
  console.log('newAssignments:', newAssignments);
20
20
  if (newAssignments.length > 0) {
21
21
  return newAssignments;
22
22
  }
23
23
  // generate new assignments
24
- const { data: oldAssignments } = yield this.rimoriClient.rpc(type + "_entries", Object.assign(Object.assign({}, queryParameter), { unread: false }));
24
+ const { data: oldAssignments } = yield this.rimoriClient.db.rpc(type + "_entries", Object.assign(Object.assign({}, queryParameter), { unread: false }));
25
25
  console.log('oldAssignments:', oldAssignments);
26
26
  const reservedTopics = this.getReservedTopics(oldAssignments);
27
27
  const request = yield generatorInstructions(reservedTopics);
28
28
  if (!request.tool.keywords || !request.tool.topic) {
29
29
  throw new Error("topic or keywords not found in the request schema");
30
30
  }
31
- const instructions = yield this.rimoriClient.generateObject(request);
31
+ const instructions = yield this.rimoriClient.llm.getObject(request);
32
32
  console.log('instructions:', instructions);
33
33
  const preparedData = Object.assign(Object.assign({ id: uuidv4() }, instructions), { keywords: this.purifyStringArray(instructions.keywords) });
34
- return yield this.rimoriClient.from(type).insert(preparedData).then(() => [preparedData]);
34
+ return yield this.rimoriClient.db.from(type).insert(preparedData).then(() => [preparedData]);
35
35
  });
36
36
  }
37
37
  getReservedTopics(oldAssignments) {
@@ -45,12 +45,12 @@ export class SharedContentController {
45
45
  }
46
46
  getSharedContent(type, id) {
47
47
  return __awaiter(this, void 0, void 0, function* () {
48
- return yield this.rimoriClient.from(type).select().eq('id', id).single();
48
+ return yield this.rimoriClient.db.from(type).select().eq('id', id).single();
49
49
  });
50
50
  }
51
51
  completeSharedContent(type, assignmentId) {
52
52
  return __awaiter(this, void 0, void 0, function* () {
53
- yield this.rimoriClient.from(type + "_result").insert({ assignment_id: assignmentId });
53
+ yield this.rimoriClient.db.from(type + "_result").insert({ assignment_id: assignmentId });
54
54
  });
55
55
  }
56
56
  }
package/dist/core.d.ts ADDED
@@ -0,0 +1,9 @@
1
+ export * from "./controller/AIController";
2
+ export * from "./controller/SharedContentController";
3
+ export * from "./controller/SettingsController";
4
+ export * from "./plugin/RimoriClient";
5
+ export * from "./plugin/PluginController";
6
+ export * from "./utils/difficultyConverter";
7
+ export * from "./utils/PluginUtils";
8
+ export * from "./worker/WorkerSetup";
9
+ export * from "./plugin/fromRimori/EventBus";
package/dist/core.js ADDED
@@ -0,0 +1,10 @@
1
+ // Core functionality exports
2
+ export * from "./controller/AIController";
3
+ export * from "./controller/SharedContentController";
4
+ export * from "./controller/SettingsController";
5
+ export * from "./plugin/RimoriClient";
6
+ export * from "./plugin/PluginController";
7
+ export * from "./utils/difficultyConverter";
8
+ export * from "./utils/PluginUtils";
9
+ export * from "./worker/WorkerSetup";
10
+ export * from "./plugin/fromRimori/EventBus";
@@ -3,9 +3,9 @@ import { usePlugin } 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 { getAIResponseStream } = usePlugin();
6
+ const { llm } = usePlugin();
7
7
  const append = (appendMessages) => {
8
- getAIResponseStream([...messages, ...appendMessages], (id, message, finished, toolInvocations) => {
8
+ llm.getSteamedText([...messages, ...appendMessages], (id, message, finished, toolInvocations) => {
9
9
  const lastMessage = messages[messages.length - 1];
10
10
  setIsLoading(!finished);
11
11
  if ((lastMessage === null || lastMessage === void 0 ? void 0 : lastMessage.id) === id) {
package/dist/index.d.ts CHANGED
@@ -1,3 +1,5 @@
1
+ export * from './core';
2
+ export * from './components';
1
3
  export * from "./components/MarkdownEditor";
2
4
  export * from "./components/CRUDModal";
3
5
  export * from "./components/Spinner";
@@ -8,8 +10,7 @@ export * from "./controller/SettingsController";
8
10
  export * from "./hooks/UseChatHook";
9
11
  export * from "./plugin/RimoriClient";
10
12
  export * from "./plugin/ThemeSetter";
11
- export * from "./providers/EventEmitter";
12
- export * from "./providers/EventEmitterContext";
13
13
  export * from "./providers/PluginProvider";
14
14
  export * from "./utils/difficultyConverter";
15
15
  export * from "./utils/PluginUtils";
16
+ export * from "./plugin/PluginController";
package/dist/index.js CHANGED
@@ -1,3 +1,6 @@
1
+ // Re-export everything
2
+ export * from './core';
3
+ export * from './components';
1
4
  export * from "./components/MarkdownEditor";
2
5
  export * from "./components/CRUDModal";
3
6
  export * from "./components/Spinner";
@@ -8,8 +11,7 @@ export * from "./controller/SettingsController";
8
11
  export * from "./hooks/UseChatHook";
9
12
  export * from "./plugin/RimoriClient";
10
13
  export * from "./plugin/ThemeSetter";
11
- export * from "./providers/EventEmitter";
12
- export * from "./providers/EventEmitterContext";
13
14
  export * from "./providers/PluginProvider";
14
15
  export * from "./utils/difficultyConverter";
15
16
  export * from "./utils/PluginUtils";
17
+ export * from "./plugin/PluginController";
@@ -1,18 +1,14 @@
1
1
  import { SupabaseClient } from '@supabase/supabase-js';
2
2
  import { RimoriClient } from "./RimoriClient";
3
3
  export declare class PluginController {
4
- private static instance;
5
4
  private static client;
6
- private plugin;
7
- private onceListeners;
8
- private listeners;
5
+ private static instance;
9
6
  private communicationSecret;
10
- private initialized;
11
7
  private supabase;
12
8
  private supabaseInfo;
9
+ private pluginId;
13
10
  private constructor();
14
- static getInstance(): Promise<RimoriClient>;
15
- init(): Promise<void>;
11
+ static getInstance(sender: string): Promise<RimoriClient>;
16
12
  private getSecret;
17
13
  getClient(): Promise<{
18
14
  supabase: SupabaseClient;
@@ -21,9 +17,5 @@ export declare class PluginController {
21
17
  }>;
22
18
  getToken(): Promise<string>;
23
19
  getSupabaseUrl(): string;
24
- emit(eventName: string, data?: any): void;
25
- private internalEmit;
26
- subscribe(eventName: string, callback: (_id: number, data: any) => void): void;
27
- onOnce(eventName: string, callback: (data: any) => void): void;
28
- request<T>(topic: string, data?: any): Promise<T>;
20
+ getGlobalEventTopic(preliminaryTopic: string): string;
29
21
  }