@rimori/client 1.0.3 → 1.0.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +51 -0
- package/dist/components/CRUDModal.js +0 -1
- package/dist/components/ai/Assistant.d.ts +9 -0
- package/dist/components/ai/Assistant.js +59 -0
- package/dist/components/ai/Avatar.d.ts +11 -0
- package/dist/components/ai/Avatar.js +39 -0
- package/dist/components/ai/EmbeddedAssistent/AudioInputField.d.ts +7 -0
- package/dist/components/ai/EmbeddedAssistent/AudioInputField.js +38 -0
- package/dist/components/ai/EmbeddedAssistent/CircleAudioAvatar.d.ts +7 -0
- package/dist/components/ai/EmbeddedAssistent/CircleAudioAvatar.js +59 -0
- package/dist/components/ai/EmbeddedAssistent/TTS/MessageSender.d.ts +19 -0
- package/dist/components/ai/EmbeddedAssistent/TTS/MessageSender.js +86 -0
- package/dist/components/ai/EmbeddedAssistent/TTS/Player.d.ts +25 -0
- package/dist/components/ai/EmbeddedAssistent/TTS/Player.js +180 -0
- package/dist/components/ai/EmbeddedAssistent/VoiceRecoder.d.ts +7 -0
- package/dist/components/ai/EmbeddedAssistent/VoiceRecoder.js +45 -0
- package/dist/components/ai/utils.d.ts +6 -0
- package/dist/components/ai/utils.js +14 -0
- package/dist/components/audio/Playbutton.js +4 -5
- package/dist/components/avatar/Assistant.d.ts +9 -0
- package/dist/components/avatar/Assistant.js +59 -0
- package/dist/components/avatar/Avatar.d.ts +12 -0
- package/dist/components/avatar/Avatar.js +42 -0
- package/dist/components/avatar/EmbeddedAssistent/AudioInputField.d.ts +7 -0
- package/dist/components/avatar/EmbeddedAssistent/AudioInputField.js +38 -0
- package/dist/components/avatar/EmbeddedAssistent/CircleAudioAvatar.d.ts +7 -0
- package/dist/components/avatar/EmbeddedAssistent/CircleAudioAvatar.js +59 -0
- package/dist/components/avatar/EmbeddedAssistent/TTS/MessageSender.d.ts +19 -0
- package/dist/components/avatar/EmbeddedAssistent/TTS/MessageSender.js +84 -0
- package/dist/components/avatar/EmbeddedAssistent/TTS/Player.d.ts +25 -0
- package/dist/components/avatar/EmbeddedAssistent/TTS/Player.js +180 -0
- package/dist/components/avatar/EmbeddedAssistent/VoiceRecoder.d.ts +7 -0
- package/dist/components/avatar/EmbeddedAssistent/VoiceRecoder.js +45 -0
- package/dist/components/avatar/utils.d.ts +6 -0
- package/dist/components/avatar/utils.js +14 -0
- package/dist/components.d.ts +9 -0
- package/dist/components.js +10 -0
- package/dist/controller/AIController.d.ts +4 -3
- package/dist/controller/AIController.js +32 -8
- package/dist/controller/ObjectController.d.ts +2 -2
- package/dist/controller/ObjectController.js +4 -5
- package/dist/controller/SettingsController.d.ts +2 -1
- package/dist/controller/SettingsController.js +9 -0
- package/dist/controller/SharedContentController.js +6 -6
- package/dist/core.d.ts +9 -0
- package/dist/core.js +10 -0
- package/dist/hooks/UseChatHook.js +2 -2
- package/dist/index.d.ts +3 -2
- package/dist/index.js +4 -2
- package/dist/plugin/PluginController.d.ts +4 -12
- package/dist/plugin/PluginController.js +43 -70
- package/dist/plugin/RimoriClient.d.ts +85 -32
- package/dist/plugin/RimoriClient.js +98 -77
- package/dist/plugin/fromRimori/EventBus.d.ts +98 -0
- package/dist/plugin/fromRimori/EventBus.js +240 -0
- package/dist/providers/PluginProvider.d.ts +1 -0
- package/dist/providers/PluginProvider.js +10 -12
- package/dist/worker/WorkerSetup.d.ts +6 -0
- package/dist/worker/WorkerSetup.js +79 -0
- package/package.json +16 -3
- package/src/components/CRUDModal.tsx +1 -3
- package/src/components/ai/Assistant.tsx +96 -0
- package/src/components/ai/Avatar.tsx +61 -0
- package/src/components/ai/EmbeddedAssistent/AudioInputField.tsx +64 -0
- package/src/components/ai/EmbeddedAssistent/CircleAudioAvatar.tsx +75 -0
- package/src/components/ai/EmbeddedAssistent/TTS/MessageSender.ts +91 -0
- package/src/components/ai/EmbeddedAssistent/TTS/Player.ts +192 -0
- package/src/components/ai/EmbeddedAssistent/VoiceRecoder.tsx +56 -0
- package/src/components/ai/utils.ts +23 -0
- package/src/components/audio/Playbutton.tsx +4 -5
- package/src/components.ts +10 -0
- package/src/controller/AIController.ts +84 -60
- package/src/controller/ObjectController.ts +4 -6
- package/src/controller/SettingsController.ts +9 -1
- package/src/controller/SharedContentController.ts +6 -6
- package/src/core.ts +10 -0
- package/src/hooks/UseChatHook.ts +2 -2
- package/src/index.ts +4 -2
- package/src/plugin/PluginController.ts +46 -76
- package/src/plugin/RimoriClient.ts +147 -85
- package/src/plugin/fromRimori/EventBus.ts +301 -0
- package/src/plugin/fromRimori/readme.md +2 -0
- package/src/providers/PluginProvider.tsx +12 -14
- package/src/worker/WorkerSetup.ts +80 -0
- package/dist/CRUDModal.d.ts +0 -16
- package/dist/CRUDModal.js +0 -31
- package/dist/MarkdownEditor.d.ts +0 -8
- package/dist/MarkdownEditor.js +0 -46
- package/dist/audio/Playbutton.d.ts +0 -14
- package/dist/audio/Playbutton.js +0 -73
- package/dist/components/hooks/UseChatHook.d.ts +0 -15
- package/dist/components/hooks/UseChatHook.js +0 -21
- package/dist/controller/PluginController.d.ts +0 -14
- package/dist/controller/PluginController.js +0 -30
- package/dist/plugin/AIController copy.d.ts +0 -22
- package/dist/plugin/AIController copy.js +0 -68
- package/dist/plugin/AIController.d.ts +0 -22
- package/dist/plugin/AIController.js +0 -68
- package/dist/plugin/ObjectController.d.ts +0 -34
- package/dist/plugin/ObjectController.js +0 -77
- package/dist/plugin/SettingController.d.ts +0 -13
- package/dist/plugin/SettingController.js +0 -55
- package/dist/plugin/VoiceController.d.ts +0 -2
- package/dist/plugin/VoiceController.js +0 -27
- package/dist/providers/EventEmitter.d.ts +0 -11
- package/dist/providers/EventEmitter.js +0 -41
- package/dist/providers/EventEmitterContext.d.ts +0 -6
- package/dist/providers/EventEmitterContext.js +0 -19
- package/dist/utils/DifficultyConverter.d.ts +0 -3
- package/dist/utils/DifficultyConverter.js +0 -7
- package/dist/utils/constants.d.ts +0 -4
- package/dist/utils/constants.js +0 -12
- package/dist/utils/plugin/Client.d.ts +0 -72
- package/dist/utils/plugin/Client.js +0 -118
- package/dist/utils/plugin/PluginController.d.ts +0 -36
- package/dist/utils/plugin/PluginController.js +0 -119
- package/dist/utils/plugin/PluginUtils.d.ts +0 -2
- package/dist/utils/plugin/PluginUtils.js +0 -23
- package/dist/utils/plugin/RimoriClient.d.ts +0 -72
- package/dist/utils/plugin/RimoriClient.js +0 -118
- package/dist/utils/plugin/ThemeSetter.d.ts +0 -1
- package/dist/utils/plugin/ThemeSetter.js +0 -13
- package/dist/utils/plugin/WhereClauseBuilder.d.ts +0 -24
- package/dist/utils/plugin/WhereClauseBuilder.js +0 -79
- package/dist/utils/plugin/providers/EventEmitter.d.ts +0 -11
- package/dist/utils/plugin/providers/EventEmitter.js +0 -41
- package/dist/utils/plugin/providers/EventEmitterContext.d.ts +0 -6
- package/dist/utils/plugin/providers/EventEmitterContext.js +0 -19
- package/dist/utils/plugin/providers/PluginProvider.d.ts +0 -8
- package/dist/utils/plugin/providers/PluginProvider.js +0 -49
- package/src/providers/EventEmitter.ts +0 -48
- package/src/providers/EventEmitterContext.tsx +0 -27
- 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,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
|
-
|
|
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(`${
|
|
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(`${
|
|
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
|
-
|
|
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
|
-
|
|
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(`${
|
|
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(`${
|
|
27
|
+
const response = yield fetch(`${supabaseUrl}/functions/v1/llm-object`, {
|
|
29
28
|
method: 'POST',
|
|
30
29
|
body: JSON.stringify({
|
|
31
30
|
stream: true,
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { SupabaseClient } from "@supabase/supabase-js";
|
|
2
2
|
import { LanguageLevel } from "../utils/difficultyConverter";
|
|
3
|
-
export interface
|
|
3
|
+
export interface UserInfo {
|
|
4
4
|
motherTongue: string;
|
|
5
5
|
languageLevel: LanguageLevel;
|
|
6
6
|
contextMenuOnSelect: boolean;
|
|
@@ -14,6 +14,7 @@ export declare class SettingsController {
|
|
|
14
14
|
private getSettingsType;
|
|
15
15
|
private fetchSettings;
|
|
16
16
|
private saveSettings;
|
|
17
|
+
getUserInfo(): Promise<UserInfo>;
|
|
17
18
|
/**
|
|
18
19
|
* Get the settings for the plugin. T can be any type of settings, UserSettings or SystemSettings.
|
|
19
20
|
* @param defaultSettings The default settings to use if no settings are found.
|
|
@@ -33,6 +33,15 @@ export class SettingsController {
|
|
|
33
33
|
yield this.supabase.from("plugin_settings").upsert({ plugin_id: this.pluginId, settings });
|
|
34
34
|
});
|
|
35
35
|
}
|
|
36
|
+
getUserInfo() {
|
|
37
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
38
|
+
return this.getSettings({
|
|
39
|
+
motherTongue: "sv",
|
|
40
|
+
languageLevel: "A1",
|
|
41
|
+
contextMenuOnSelect: true,
|
|
42
|
+
}, "user");
|
|
43
|
+
});
|
|
44
|
+
}
|
|
36
45
|
/**
|
|
37
46
|
* Get the settings for the plugin. T can be any type of settings, UserSettings or SystemSettings.
|
|
38
47
|
* @param defaultSettings The default settings to use if no settings are found.
|
|
@@ -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.
|
|
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 {
|
|
6
|
+
const { llm } = usePlugin();
|
|
7
7
|
const append = (appendMessages) => {
|
|
8
|
-
|
|
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
|
|
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
|
-
|
|
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
|
}
|
|
@@ -7,54 +7,44 @@ 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 { Child } from "ibridge-flex";
|
|
11
10
|
import { createClient } from '@supabase/supabase-js';
|
|
12
11
|
import { RimoriClient } from "./RimoriClient";
|
|
12
|
+
import { EventBus } from './fromRimori/EventBus';
|
|
13
|
+
import { setTheme } from './ThemeSetter';
|
|
14
|
+
setTheme();
|
|
13
15
|
export class PluginController {
|
|
14
|
-
constructor() {
|
|
15
|
-
this.onceListeners = new Map();
|
|
16
|
-
this.listeners = new Map();
|
|
16
|
+
constructor(pluginId) {
|
|
17
17
|
this.communicationSecret = null;
|
|
18
|
-
this.initialized = false;
|
|
19
18
|
this.supabase = null;
|
|
20
19
|
this.supabaseInfo = null;
|
|
21
|
-
|
|
22
|
-
this.plugin = new Child({
|
|
23
|
-
triggerChild: ({ topic, data, _id }) => {
|
|
24
|
-
var _a, _b;
|
|
25
|
-
// console.log("trigger child with topic:" + topic + " and data: ", data);
|
|
26
|
-
(_a = this.onceListeners.get(topic)) === null || _a === void 0 ? void 0 : _a.forEach((callback) => callback(_id, data));
|
|
27
|
-
this.onceListeners.set(topic, []);
|
|
28
|
-
(_b = this.listeners.get(topic)) === null || _b === void 0 ? void 0 : _b.forEach((callback) => callback(_id, data));
|
|
29
|
-
}
|
|
30
|
-
});
|
|
31
|
-
this.emit = this.emit.bind(this);
|
|
32
|
-
this.onOnce = this.onOnce.bind(this);
|
|
20
|
+
this.pluginId = pluginId;
|
|
33
21
|
this.getClient = this.getClient.bind(this);
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
22
|
+
window.addEventListener("message", (event) => {
|
|
23
|
+
// console.log("client: message received", event);
|
|
24
|
+
const { topic, sender, data, eventId } = event.data.event;
|
|
25
|
+
// skip forwarding messages from own plugin
|
|
26
|
+
if (sender === pluginId)
|
|
27
|
+
return;
|
|
28
|
+
EventBus.emit(sender, topic, data, eventId);
|
|
29
|
+
});
|
|
30
|
+
EventBus.on("*", (event) => {
|
|
31
|
+
// skip messages which are not from the own plugin
|
|
32
|
+
if (event.sender !== this.pluginId)
|
|
33
|
+
return;
|
|
34
|
+
if (event.topic.startsWith("self."))
|
|
35
|
+
return;
|
|
36
|
+
window.parent.postMessage({ event, secret: this.getSecret() }, "*");
|
|
37
|
+
});
|
|
37
38
|
}
|
|
38
|
-
static getInstance() {
|
|
39
|
+
static getInstance(sender) {
|
|
39
40
|
return __awaiter(this, void 0, void 0, function* () {
|
|
40
41
|
if (!PluginController.instance) {
|
|
41
|
-
PluginController.instance = new PluginController();
|
|
42
|
-
yield PluginController.instance.init();
|
|
42
|
+
PluginController.instance = new PluginController(sender);
|
|
43
43
|
PluginController.client = yield RimoriClient.getInstance(PluginController.instance);
|
|
44
44
|
}
|
|
45
45
|
return PluginController.client;
|
|
46
46
|
});
|
|
47
47
|
}
|
|
48
|
-
init() {
|
|
49
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
50
|
-
if (this.initialized)
|
|
51
|
-
return;
|
|
52
|
-
// Wait for the plugin to be ready
|
|
53
|
-
yield this.plugin.handshake().then(() => this.initialized = true).catch((error) => {
|
|
54
|
-
console.error("Failed to initialize the plugin communication:", error);
|
|
55
|
-
});
|
|
56
|
-
});
|
|
57
|
-
}
|
|
58
48
|
getSecret() {
|
|
59
49
|
if (!this.communicationSecret) {
|
|
60
50
|
const secret = new URLSearchParams(window.location.search).get("secret");
|
|
@@ -72,7 +62,8 @@ export class PluginController {
|
|
|
72
62
|
this.supabaseInfo.expiration > new Date()) {
|
|
73
63
|
return { supabase: this.supabase, tablePrefix: this.supabaseInfo.tablePrefix, pluginId: this.supabaseInfo.pluginId };
|
|
74
64
|
}
|
|
75
|
-
|
|
65
|
+
const { data } = yield EventBus.request(this.pluginId, "global.supabase.requestAccess");
|
|
66
|
+
this.supabaseInfo = data;
|
|
76
67
|
this.supabase = createClient(this.supabaseInfo.url, this.supabaseInfo.key, {
|
|
77
68
|
accessToken: () => Promise.resolve(this.getToken())
|
|
78
69
|
});
|
|
@@ -84,12 +75,12 @@ export class PluginController {
|
|
|
84
75
|
if (this.supabaseInfo && this.supabaseInfo.expiration && this.supabaseInfo.expiration > new Date()) {
|
|
85
76
|
return this.supabaseInfo.token;
|
|
86
77
|
}
|
|
87
|
-
const
|
|
78
|
+
const { data } = yield EventBus.request(this.pluginId, "global.supabase.requestAccess");
|
|
88
79
|
if (!this.supabaseInfo) {
|
|
89
80
|
throw new Error("Supabase info not found");
|
|
90
81
|
}
|
|
91
|
-
this.supabaseInfo.token =
|
|
92
|
-
this.supabaseInfo.expiration =
|
|
82
|
+
this.supabaseInfo.token = data.token;
|
|
83
|
+
this.supabaseInfo.expiration = data.expiration;
|
|
93
84
|
return this.supabaseInfo.token;
|
|
94
85
|
});
|
|
95
86
|
}
|
|
@@ -99,40 +90,22 @@ export class PluginController {
|
|
|
99
90
|
}
|
|
100
91
|
return this.supabaseInfo.url;
|
|
101
92
|
}
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
internalEmit(eventName, id, data) {
|
|
107
|
-
this.init().then(() => this.plugin.emitToParent(eventName, { data, _id: id, secret: this.getSecret() }));
|
|
108
|
-
}
|
|
109
|
-
subscribe(eventName, callback) {
|
|
110
|
-
var _a;
|
|
111
|
-
if (!this.listeners.has(eventName)) {
|
|
112
|
-
this.listeners.set(eventName, []);
|
|
93
|
+
getGlobalEventTopic(preliminaryTopic) {
|
|
94
|
+
var _a, _b, _c;
|
|
95
|
+
if (preliminaryTopic.startsWith("global.")) {
|
|
96
|
+
return preliminaryTopic;
|
|
113
97
|
}
|
|
114
|
-
(
|
|
115
|
-
|
|
116
|
-
onOnce(eventName, callback) {
|
|
117
|
-
var _a;
|
|
118
|
-
if (!this.onceListeners.has(eventName)) {
|
|
119
|
-
this.onceListeners.set(eventName, []);
|
|
98
|
+
if (preliminaryTopic.startsWith("self.")) {
|
|
99
|
+
return preliminaryTopic;
|
|
120
100
|
}
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
if (triggered || (_id !== id && _id !== 0))
|
|
131
|
-
return;
|
|
132
|
-
triggered = true;
|
|
133
|
-
resolve(data);
|
|
134
|
-
});
|
|
135
|
-
});
|
|
136
|
-
});
|
|
101
|
+
const topicParts = preliminaryTopic.split(".");
|
|
102
|
+
if (topicParts.length === 3) {
|
|
103
|
+
if (![(_a = this.supabaseInfo) === null || _a === void 0 ? void 0 : _a.pluginId, "global"].includes(topicParts[0])) {
|
|
104
|
+
throw new Error("The event topic must start with the plugin id or 'global'.");
|
|
105
|
+
}
|
|
106
|
+
return preliminaryTopic;
|
|
107
|
+
}
|
|
108
|
+
const topicRoot = (_c = (_b = this.supabaseInfo) === null || _b === void 0 ? void 0 : _b.pluginId) !== null && _c !== void 0 ? _c : "global";
|
|
109
|
+
return `${topicRoot}.${preliminaryTopic}`;
|
|
137
110
|
}
|
|
138
111
|
}
|