@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.
- 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 +19 -10
- package/dist/controller/SettingsController.js +33 -26
- 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 +45 -70
- package/dist/plugin/RimoriClient.d.ts +85 -32
- package/dist/plugin/RimoriClient.js +98 -77
- package/dist/plugin/ThemeSetter.js +3 -3
- 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 +80 -0
- package/package.json +17 -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 +49 -35
- 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 +51 -76
- package/src/plugin/RimoriClient.ts +147 -85
- package/src/plugin/ThemeSetter.ts +3 -4
- 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 +81 -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
|
@@ -1,77 +0,0 @@
|
|
|
1
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
2
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
3
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
4
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
5
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
6
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
7
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
|
-
});
|
|
9
|
-
};
|
|
10
|
-
import { env } from "../utils/constants";
|
|
11
|
-
export function generateObject(request, token) {
|
|
12
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
13
|
-
return yield fetch(`${env.SUPABASE_URL}/functions/v1/llm-object`, {
|
|
14
|
-
method: 'POST',
|
|
15
|
-
body: JSON.stringify({
|
|
16
|
-
stream: false,
|
|
17
|
-
tool: request.tool,
|
|
18
|
-
behaviour: request.behaviour,
|
|
19
|
-
instructions: request.instructions,
|
|
20
|
-
}),
|
|
21
|
-
headers: { 'Authorization': `Bearer ${token}` }
|
|
22
|
-
}).then(response => response.json());
|
|
23
|
-
});
|
|
24
|
-
}
|
|
25
|
-
export function streamObject(request, onResponse, token) {
|
|
26
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
27
|
-
const messageId = Math.random().toString(36).substring(3);
|
|
28
|
-
const response = yield fetch(`${env.SUPABASE_URL}/functions/v1/llm-object`, {
|
|
29
|
-
method: 'POST',
|
|
30
|
-
body: JSON.stringify({
|
|
31
|
-
stream: true,
|
|
32
|
-
tools: request.tool,
|
|
33
|
-
systemInstructions: request.behaviour,
|
|
34
|
-
secondaryInstructions: request.instructions,
|
|
35
|
-
}),
|
|
36
|
-
headers: { 'Authorization': `Bearer ${token}` }
|
|
37
|
-
});
|
|
38
|
-
if (!response.body) {
|
|
39
|
-
console.error('No response body.');
|
|
40
|
-
return;
|
|
41
|
-
}
|
|
42
|
-
const reader = response.body.getReader();
|
|
43
|
-
const decoder = new TextDecoder('utf-8');
|
|
44
|
-
let content = "";
|
|
45
|
-
let done = false;
|
|
46
|
-
let toolInvocations = [];
|
|
47
|
-
while (!done) {
|
|
48
|
-
const { value } = yield reader.read();
|
|
49
|
-
if (value) {
|
|
50
|
-
const chunk = decoder.decode(value, { stream: true });
|
|
51
|
-
const lines = chunk.split('\n').filter(line => line.trim() !== '');
|
|
52
|
-
for (const line of lines) {
|
|
53
|
-
const data = line.substring(3, line.length - 1);
|
|
54
|
-
const command = line.substring(0, 1);
|
|
55
|
-
// console.log("data: ", { line, data, command });
|
|
56
|
-
if (command === '0') {
|
|
57
|
-
content += data;
|
|
58
|
-
// console.log("AI response:", content);
|
|
59
|
-
//content \n\n should be real line break when message is displayed
|
|
60
|
-
onResponse(messageId, content.replace(/\\n/g, '\n'), false);
|
|
61
|
-
}
|
|
62
|
-
else if (command === 'd') {
|
|
63
|
-
// console.log("AI usage:", JSON.parse(line.substring(2)));
|
|
64
|
-
done = true;
|
|
65
|
-
break;
|
|
66
|
-
}
|
|
67
|
-
else if (command === '9') {
|
|
68
|
-
// console.log("tool call:", JSON.parse(line.substring(2)));
|
|
69
|
-
// console.log("tools", tools);
|
|
70
|
-
toolInvocations.push(JSON.parse(line.substring(2)));
|
|
71
|
-
}
|
|
72
|
-
}
|
|
73
|
-
}
|
|
74
|
-
}
|
|
75
|
-
onResponse(messageId, content.replace(/\\n/g, '\n'), true, toolInvocations);
|
|
76
|
-
});
|
|
77
|
-
}
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
import { SupabaseClient } from "@supabase/supabase-js";
|
|
2
|
-
declare class SettingsController {
|
|
3
|
-
private static instance;
|
|
4
|
-
private supabase;
|
|
5
|
-
private tablePrefix;
|
|
6
|
-
private constructor();
|
|
7
|
-
static getInstance(): SettingsController;
|
|
8
|
-
initialize(supabase: SupabaseClient, tablePrefix: string): void;
|
|
9
|
-
getSettings<T>(defaultSettings: T, genericSettings?: "user" | "system"): Promise<T>;
|
|
10
|
-
setSettings(settings: any, genericSettings?: "user" | "system"): Promise<void>;
|
|
11
|
-
}
|
|
12
|
-
export declare const settingsController: SettingsController;
|
|
13
|
-
export {};
|
|
@@ -1,55 +0,0 @@
|
|
|
1
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
2
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
3
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
4
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
5
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
6
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
7
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
|
-
});
|
|
9
|
-
};
|
|
10
|
-
class SettingsController {
|
|
11
|
-
constructor() {
|
|
12
|
-
this.supabase = null;
|
|
13
|
-
this.tablePrefix = '';
|
|
14
|
-
}
|
|
15
|
-
static getInstance() {
|
|
16
|
-
if (!SettingsController.instance) {
|
|
17
|
-
SettingsController.instance = new SettingsController();
|
|
18
|
-
}
|
|
19
|
-
return SettingsController.instance;
|
|
20
|
-
}
|
|
21
|
-
initialize(supabase, tablePrefix) {
|
|
22
|
-
this.supabase = supabase;
|
|
23
|
-
this.tablePrefix = tablePrefix;
|
|
24
|
-
}
|
|
25
|
-
getSettings(defaultSettings, genericSettings) {
|
|
26
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
27
|
-
// async function getPluginSettings(supabase:SupabaseClient, genericSettings:string) {
|
|
28
|
-
const response = yield this.plugin.request("get_settings", { genericSettings });
|
|
29
|
-
if (response === null) {
|
|
30
|
-
this.setSettings(defaultSettings, genericSettings);
|
|
31
|
-
return defaultSettings;
|
|
32
|
-
//if the settings are not the same, merge the settings
|
|
33
|
-
}
|
|
34
|
-
else if (Object.keys(response).length !== Object.keys(defaultSettings).length) {
|
|
35
|
-
const existingKeys = Object.fromEntries(Object.entries(response).filter(([k]) => k in defaultSettings));
|
|
36
|
-
const mergedSettings = Object.assign(Object.assign({}, defaultSettings), existingKeys);
|
|
37
|
-
console.warn("Settings mismatch", { response, defaultSettings, mergedSettings });
|
|
38
|
-
this.setSettings(mergedSettings, genericSettings);
|
|
39
|
-
return mergedSettings;
|
|
40
|
-
}
|
|
41
|
-
return response;
|
|
42
|
-
});
|
|
43
|
-
}
|
|
44
|
-
setSettings(settings, genericSettings) {
|
|
45
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
46
|
-
if (!this.supabase) {
|
|
47
|
-
throw new Error("SettingsController not initialized");
|
|
48
|
-
}
|
|
49
|
-
yield this.supabase
|
|
50
|
-
.from(this.tablePrefix + '_settings')
|
|
51
|
-
.upsert(settings);
|
|
52
|
-
});
|
|
53
|
-
}
|
|
54
|
-
}
|
|
55
|
-
export const settingsController = SettingsController.getInstance();
|
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
2
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
3
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
4
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
5
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
6
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
7
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
|
-
});
|
|
9
|
-
};
|
|
10
|
-
export function getSTTResponse(audio) {
|
|
11
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
12
|
-
const formData = new FormData();
|
|
13
|
-
formData.append('file', audio);
|
|
14
|
-
return yield fetch('/api/stt', { method: 'POST', body: formData })
|
|
15
|
-
.then(r => r.json())
|
|
16
|
-
.then(r => r.text);
|
|
17
|
-
});
|
|
18
|
-
}
|
|
19
|
-
export function getTTSResponse(text, voice, speed, language) {
|
|
20
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
21
|
-
return yield fetch('/api/speech', {
|
|
22
|
-
method: 'POST',
|
|
23
|
-
headers: { 'Content-Type': 'application/json' },
|
|
24
|
-
body: JSON.stringify({ input: text, voice, speed, language }),
|
|
25
|
-
}).then(r => r.blob());
|
|
26
|
-
});
|
|
27
|
-
}
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
type Listener<T = any> = (event: T) => void;
|
|
2
|
-
export declare class EventEmitter {
|
|
3
|
-
private events;
|
|
4
|
-
constructor();
|
|
5
|
-
on<T = any>(eventName: string, listener: Listener<T>): void;
|
|
6
|
-
once<T = any>(eventName: string, listener: Listener<T>): void;
|
|
7
|
-
removeListener<T = any>(eventName: string, listener: Listener<T>): void;
|
|
8
|
-
emit<T = any>(eventName: string, data?: T): void;
|
|
9
|
-
}
|
|
10
|
-
export declare const EmitterSingleton: EventEmitter;
|
|
11
|
-
export {};
|
|
@@ -1,41 +0,0 @@
|
|
|
1
|
-
export class EventEmitter {
|
|
2
|
-
constructor() {
|
|
3
|
-
this.events = new Map();
|
|
4
|
-
this.on = this.on.bind(this);
|
|
5
|
-
this.once = this.once.bind(this);
|
|
6
|
-
this.emit = this.emit.bind(this);
|
|
7
|
-
this.removeListener = this.removeListener.bind(this);
|
|
8
|
-
}
|
|
9
|
-
// Subscribe to an event
|
|
10
|
-
on(eventName, listener) {
|
|
11
|
-
if (!this.events.has(eventName)) {
|
|
12
|
-
this.events.set(eventName, []);
|
|
13
|
-
}
|
|
14
|
-
this.events.get(eventName).push(listener);
|
|
15
|
-
}
|
|
16
|
-
// Subscribe to an event for a single invocation
|
|
17
|
-
once(eventName, listener) {
|
|
18
|
-
const onceWrapper = (event) => {
|
|
19
|
-
this.removeListener(eventName, onceWrapper);
|
|
20
|
-
listener(event);
|
|
21
|
-
};
|
|
22
|
-
this.on(eventName, onceWrapper);
|
|
23
|
-
}
|
|
24
|
-
// Remove a specific listener
|
|
25
|
-
removeListener(eventName, listener) {
|
|
26
|
-
const listeners = this.events.get(eventName);
|
|
27
|
-
if (!listeners)
|
|
28
|
-
return;
|
|
29
|
-
this.events.set(eventName, listeners.filter((l) => l !== listener));
|
|
30
|
-
}
|
|
31
|
-
// Emit an event
|
|
32
|
-
emit(eventName, data) {
|
|
33
|
-
const listeners = this.events.get(eventName);
|
|
34
|
-
console.log("emit", eventName, data, listeners);
|
|
35
|
-
if (!listeners)
|
|
36
|
-
return;
|
|
37
|
-
listeners.forEach((listener) => listener(data));
|
|
38
|
-
}
|
|
39
|
-
}
|
|
40
|
-
const emitter = new EventEmitter();
|
|
41
|
-
export const EmitterSingleton = emitter;
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
"use client";
|
|
2
|
-
import { jsx as _jsx } from "react/jsx-runtime";
|
|
3
|
-
import { createContext, useContext, useRef } from "react";
|
|
4
|
-
import { EmitterSingleton } from "./EventEmitter";
|
|
5
|
-
// Create the Context
|
|
6
|
-
const EventEmitterContext = createContext(null);
|
|
7
|
-
// Provider Component
|
|
8
|
-
export const EventEmitterProvider = ({ children }) => {
|
|
9
|
-
const eventEmitterRef = useRef(EmitterSingleton);
|
|
10
|
-
return (_jsx(EventEmitterContext.Provider, { value: eventEmitterRef.current, children: children }));
|
|
11
|
-
};
|
|
12
|
-
// Hook to use the EventEmitter
|
|
13
|
-
export const useEventEmitter = () => {
|
|
14
|
-
const context = useContext(EventEmitterContext);
|
|
15
|
-
if (!context) {
|
|
16
|
-
throw new Error("useEventEmitter must be used within an EventEmitterProvider");
|
|
17
|
-
}
|
|
18
|
-
return context;
|
|
19
|
-
};
|
package/dist/utils/constants.js
DELETED
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
// import { unstable_noStore as noStore } from 'next/cache';
|
|
2
|
-
export const env = {
|
|
3
|
-
// SUPABASE_URL: process?.env?.SUPABASE_URL || "https://pheptqdoqsdnadgoihvr.supabase.co",
|
|
4
|
-
SUPABASE_URL: "https://pheptqdoqsdnadgoihvr.supabase.co",
|
|
5
|
-
// SUPABASE_ANON_KEY: process.env.SUPABASE_ANON_KEY,
|
|
6
|
-
};
|
|
7
|
-
// Validate all environment variables are set
|
|
8
|
-
Object.entries(env).forEach(([key, value]) => {
|
|
9
|
-
if (!value) {
|
|
10
|
-
throw new Error(`${key} is not set`);
|
|
11
|
-
}
|
|
12
|
-
});
|
|
@@ -1,72 +0,0 @@
|
|
|
1
|
-
import { SupabaseClient } from "@supabase/supabase-js";
|
|
2
|
-
import { GenericSchema } from "@supabase/supabase-js/dist/module/lib/types";
|
|
3
|
-
import { PostgrestQueryBuilder, PostgrestFilterBuilder } from "@supabase/postgrest-js";
|
|
4
|
-
import { PluginController, Tool, ToolInvocation } from "./PluginController";
|
|
5
|
-
import { LanguageLevel } from "../difficultyConverter";
|
|
6
|
-
export declare class RimoriClient {
|
|
7
|
-
private static instance;
|
|
8
|
-
private superbase;
|
|
9
|
-
private plugin;
|
|
10
|
-
functions: SupabaseClient["functions"];
|
|
11
|
-
storage: SupabaseClient["storage"];
|
|
12
|
-
private constructor();
|
|
13
|
-
static getInstance(pluginController: PluginController): Promise<RimoriClient>;
|
|
14
|
-
from<TableName extends string & keyof GenericSchema['Tables'], Table extends GenericSchema['Tables'][TableName]>(relation: TableName): PostgrestQueryBuilder<GenericSchema, Table, GenericSchema, Table extends {
|
|
15
|
-
Relationships: infer R;
|
|
16
|
-
} ? R : unknown>;
|
|
17
|
-
/**
|
|
18
|
-
* Perform a function call.
|
|
19
|
-
*
|
|
20
|
-
* @param fn - The function name to call
|
|
21
|
-
* @param args - The arguments to pass to the function call
|
|
22
|
-
* @param options - Named parameters
|
|
23
|
-
* @param options.head - When set to `true`, `data` will not be returned.
|
|
24
|
-
* Useful if you only need the count.
|
|
25
|
-
* @param options.get - When set to `true`, the function will be called with
|
|
26
|
-
* read-only access mode.
|
|
27
|
-
* @param options.count - Count algorithm to use to count rows returned by the
|
|
28
|
-
* function. Only applicable for [set-returning
|
|
29
|
-
* functions](https://www.postgresql.org/docs/current/functions-srf.html).
|
|
30
|
-
*
|
|
31
|
-
* `"exact"`: Exact but slow count algorithm. Performs a `COUNT(*)` under the
|
|
32
|
-
* hood.
|
|
33
|
-
*
|
|
34
|
-
* `"planned"`: Approximated but fast count algorithm. Uses the Postgres
|
|
35
|
-
* statistics under the hood.
|
|
36
|
-
*
|
|
37
|
-
* `"estimated"`: Uses exact count for low numbers and planned count for high
|
|
38
|
-
* numbers.
|
|
39
|
-
*/
|
|
40
|
-
rpc<FnName extends string & keyof GenericSchema['Functions'], Fn extends GenericSchema['Functions'][FnName]>(fn: FnName, args?: Fn['Args'], options?: {
|
|
41
|
-
head?: boolean;
|
|
42
|
-
get?: boolean;
|
|
43
|
-
count?: 'exact' | 'planned' | 'estimated';
|
|
44
|
-
}): PostgrestFilterBuilder<GenericSchema, Fn['Returns'] extends any[] ? Fn['Returns'][number] extends Record<string, unknown> ? Fn['Returns'][number] : never : never, Fn['Returns'], FnName, null>;
|
|
45
|
-
subscribe(eventName: string, callback: (_id: number, data: any) => void): void;
|
|
46
|
-
request<T>(eventName: string, data: any): Promise<T>;
|
|
47
|
-
emit(eventName: string, data: any): void;
|
|
48
|
-
/**
|
|
49
|
-
* Get the settings for the plugin. T can be any type of settings, UserSettings or SystemSettings.
|
|
50
|
-
* @param defaultSettings The default settings to use if no settings are found.
|
|
51
|
-
* @param genericSettings The type of settings to get.
|
|
52
|
-
* @returns The settings for the plugin.
|
|
53
|
-
*/
|
|
54
|
-
getSettings<T>(defaultSettings: T, genericSettings?: "user" | "system"): Promise<T>;
|
|
55
|
-
setSettings(settings: any, genericSettings?: "user" | "system"): Promise<void>;
|
|
56
|
-
getAIResponse(messages: {
|
|
57
|
-
role: string;
|
|
58
|
-
content: string;
|
|
59
|
-
}[]): Promise<string>;
|
|
60
|
-
getAIResponseStream(messages: {
|
|
61
|
-
role: string;
|
|
62
|
-
content: string;
|
|
63
|
-
}[], onMessage: (id: string, message: string, finished: boolean, toolInvocations?: ToolInvocation[]) => void, tools?: Tool[]): Promise<void>;
|
|
64
|
-
getVoiceResponse(text: string, voice?: string, speed?: number, language?: string): Promise<Blob>;
|
|
65
|
-
getVoiceToTextResponse(file: Blob): Promise<string>;
|
|
66
|
-
}
|
|
67
|
-
export interface UserSettings {
|
|
68
|
-
motherTongue: string;
|
|
69
|
-
languageLevel: LanguageLevel;
|
|
70
|
-
}
|
|
71
|
-
export interface SystemSettings {
|
|
72
|
-
}
|
|
@@ -1,118 +0,0 @@
|
|
|
1
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
2
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
3
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
4
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
5
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
6
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
7
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
|
-
});
|
|
9
|
-
};
|
|
10
|
-
export class RimoriClient {
|
|
11
|
-
constructor(pluginController, superbase) {
|
|
12
|
-
this.superbase = superbase;
|
|
13
|
-
this.plugin = pluginController;
|
|
14
|
-
this.functions = this.superbase.functions;
|
|
15
|
-
this.storage = this.superbase.storage;
|
|
16
|
-
}
|
|
17
|
-
static getInstance(pluginController) {
|
|
18
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
19
|
-
if (!RimoriClient.instance) {
|
|
20
|
-
const superbase = yield pluginController.getClient();
|
|
21
|
-
RimoriClient.instance = new RimoriClient(pluginController, superbase);
|
|
22
|
-
}
|
|
23
|
-
return RimoriClient.instance;
|
|
24
|
-
});
|
|
25
|
-
}
|
|
26
|
-
from(relation) {
|
|
27
|
-
return this.superbase.from(relation);
|
|
28
|
-
}
|
|
29
|
-
/**
|
|
30
|
-
* Perform a function call.
|
|
31
|
-
*
|
|
32
|
-
* @param fn - The function name to call
|
|
33
|
-
* @param args - The arguments to pass to the function call
|
|
34
|
-
* @param options - Named parameters
|
|
35
|
-
* @param options.head - When set to `true`, `data` will not be returned.
|
|
36
|
-
* Useful if you only need the count.
|
|
37
|
-
* @param options.get - When set to `true`, the function will be called with
|
|
38
|
-
* read-only access mode.
|
|
39
|
-
* @param options.count - Count algorithm to use to count rows returned by the
|
|
40
|
-
* function. Only applicable for [set-returning
|
|
41
|
-
* functions](https://www.postgresql.org/docs/current/functions-srf.html).
|
|
42
|
-
*
|
|
43
|
-
* `"exact"`: Exact but slow count algorithm. Performs a `COUNT(*)` under the
|
|
44
|
-
* hood.
|
|
45
|
-
*
|
|
46
|
-
* `"planned"`: Approximated but fast count algorithm. Uses the Postgres
|
|
47
|
-
* statistics under the hood.
|
|
48
|
-
*
|
|
49
|
-
* `"estimated"`: Uses exact count for low numbers and planned count for high
|
|
50
|
-
* numbers.
|
|
51
|
-
*/
|
|
52
|
-
rpc(fn, args = {}, options = {}) {
|
|
53
|
-
return this.superbase.rpc(fn, args, options);
|
|
54
|
-
}
|
|
55
|
-
subscribe(eventName, callback) {
|
|
56
|
-
this.plugin.subscribe(eventName, callback);
|
|
57
|
-
}
|
|
58
|
-
request(eventName, data) {
|
|
59
|
-
return this.plugin.request(eventName, data);
|
|
60
|
-
}
|
|
61
|
-
emit(eventName, data) {
|
|
62
|
-
this.plugin.emit(eventName, data);
|
|
63
|
-
}
|
|
64
|
-
/**
|
|
65
|
-
* Get the settings for the plugin. T can be any type of settings, UserSettings or SystemSettings.
|
|
66
|
-
* @param defaultSettings The default settings to use if no settings are found.
|
|
67
|
-
* @param genericSettings The type of settings to get.
|
|
68
|
-
* @returns The settings for the plugin.
|
|
69
|
-
*/
|
|
70
|
-
getSettings(defaultSettings, genericSettings) {
|
|
71
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
72
|
-
const response = yield this.plugin.request("get_settings", { genericSettings });
|
|
73
|
-
if (response === null) {
|
|
74
|
-
this.setSettings(defaultSettings, genericSettings);
|
|
75
|
-
return defaultSettings;
|
|
76
|
-
//if the settings are not the same, merge the settings
|
|
77
|
-
}
|
|
78
|
-
else if (Object.keys(response).length !== Object.keys(defaultSettings).length) {
|
|
79
|
-
const existingKeys = Object.fromEntries(Object.entries(response).filter(([k]) => k in defaultSettings));
|
|
80
|
-
const mergedSettings = Object.assign(Object.assign({}, defaultSettings), existingKeys);
|
|
81
|
-
console.warn("Settings mismatch", { response, defaultSettings, mergedSettings });
|
|
82
|
-
this.setSettings(mergedSettings, genericSettings);
|
|
83
|
-
return mergedSettings;
|
|
84
|
-
}
|
|
85
|
-
return response;
|
|
86
|
-
});
|
|
87
|
-
}
|
|
88
|
-
setSettings(settings, genericSettings) {
|
|
89
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
90
|
-
yield this.plugin.request("set_settings", { settings, genericSettings });
|
|
91
|
-
});
|
|
92
|
-
}
|
|
93
|
-
getAIResponse(messages) {
|
|
94
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
95
|
-
return this.plugin.request("getAIResponse", messages);
|
|
96
|
-
});
|
|
97
|
-
}
|
|
98
|
-
getAIResponseStream(messages, onMessage, tools) {
|
|
99
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
100
|
-
throw new Error("Not implemented");
|
|
101
|
-
// let triggered = false;
|
|
102
|
-
// console.log("getAIResponseStream", messages);
|
|
103
|
-
// const id = Math.random();
|
|
104
|
-
// this.internalEmit("getAIResponseStream", id, { messages, tools: tools || [] });
|
|
105
|
-
// this.subscribe("getAIResponseStream", (_id: number, data: { id: string, response: string, finished: boolean, toolInvocations?: ToolInvocation[] }) => {
|
|
106
|
-
// if (triggered || (_id !== id && _id !== 0)) return;
|
|
107
|
-
// triggered = data.finished;
|
|
108
|
-
// onMessage(data.id, data.response, data.finished, data.toolInvocations);
|
|
109
|
-
// })
|
|
110
|
-
});
|
|
111
|
-
}
|
|
112
|
-
getVoiceResponse(text, voice = "alloy", speed = 1, language) {
|
|
113
|
-
return this.plugin.request("getVoiceResponse", { text, voice, speed, language });
|
|
114
|
-
}
|
|
115
|
-
getVoiceToTextResponse(file) {
|
|
116
|
-
return this.plugin.request("getSTTResponse", file);
|
|
117
|
-
}
|
|
118
|
-
}
|
|
@@ -1,36 +0,0 @@
|
|
|
1
|
-
import { SupabaseClient } from '@supabase/supabase-js';
|
|
2
|
-
import { RimoriClient } from "./RimoriClient";
|
|
3
|
-
export interface Tool {
|
|
4
|
-
name: string;
|
|
5
|
-
description: string;
|
|
6
|
-
parameters: {
|
|
7
|
-
name: string;
|
|
8
|
-
type: "string" | "number" | "boolean";
|
|
9
|
-
description: string;
|
|
10
|
-
}[];
|
|
11
|
-
}
|
|
12
|
-
export interface ToolInvocation {
|
|
13
|
-
toolName: string;
|
|
14
|
-
args: Record<string, string>;
|
|
15
|
-
}
|
|
16
|
-
export declare class PluginController {
|
|
17
|
-
private static instance;
|
|
18
|
-
private static client;
|
|
19
|
-
private plugin;
|
|
20
|
-
private onceListeners;
|
|
21
|
-
private listeners;
|
|
22
|
-
private communicationSecret;
|
|
23
|
-
private initialized;
|
|
24
|
-
private supabase;
|
|
25
|
-
private accessTokenExpiration;
|
|
26
|
-
private constructor();
|
|
27
|
-
static getInstance(): Promise<RimoriClient>;
|
|
28
|
-
init(): Promise<void>;
|
|
29
|
-
private getSecret;
|
|
30
|
-
getClient(): Promise<SupabaseClient<any, "public", any>>;
|
|
31
|
-
emit(eventName: string, data?: any): void;
|
|
32
|
-
private internalEmit;
|
|
33
|
-
subscribe(eventName: string, callback: (_id: number, data: any) => void): void;
|
|
34
|
-
onOnce(eventName: string, callback: (data: any) => void): void;
|
|
35
|
-
request<T>(topic: string, data: any): Promise<T>;
|
|
36
|
-
}
|
|
@@ -1,119 +0,0 @@
|
|
|
1
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
2
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
3
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
4
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
5
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
6
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
7
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
|
-
});
|
|
9
|
-
};
|
|
10
|
-
import { Child } from "ibridge-flex";
|
|
11
|
-
import { createClient } from '@supabase/supabase-js';
|
|
12
|
-
import { RimoriClient } from "./RimoriClient";
|
|
13
|
-
export class PluginController {
|
|
14
|
-
constructor() {
|
|
15
|
-
// localStorage.debug = "*";
|
|
16
|
-
this.onceListeners = new Map();
|
|
17
|
-
this.listeners = new Map();
|
|
18
|
-
this.communicationSecret = null;
|
|
19
|
-
this.initialized = false;
|
|
20
|
-
this.supabase = null;
|
|
21
|
-
this.accessTokenExpiration = null;
|
|
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.init();
|
|
32
|
-
this.emit = this.emit.bind(this);
|
|
33
|
-
this.onOnce = this.onOnce.bind(this);
|
|
34
|
-
this.getClient = this.getClient.bind(this);
|
|
35
|
-
this.subscribe = this.subscribe.bind(this);
|
|
36
|
-
this.internalEmit = this.internalEmit.bind(this);
|
|
37
|
-
this.request = this.request.bind(this);
|
|
38
|
-
}
|
|
39
|
-
static getInstance() {
|
|
40
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
41
|
-
if (!PluginController.instance) {
|
|
42
|
-
PluginController.instance = new PluginController();
|
|
43
|
-
yield PluginController.instance.init();
|
|
44
|
-
PluginController.client = yield RimoriClient.getInstance(PluginController.instance);
|
|
45
|
-
}
|
|
46
|
-
return PluginController.client;
|
|
47
|
-
});
|
|
48
|
-
}
|
|
49
|
-
init() {
|
|
50
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
51
|
-
if (this.initialized) {
|
|
52
|
-
return;
|
|
53
|
-
}
|
|
54
|
-
// Wait for the plugin to be ready
|
|
55
|
-
yield this.plugin.handshake().then(() => this.initialized = true).catch((error) => {
|
|
56
|
-
console.error("Failed to initialize the plugin communication:", error);
|
|
57
|
-
});
|
|
58
|
-
});
|
|
59
|
-
}
|
|
60
|
-
getSecret() {
|
|
61
|
-
if (!this.communicationSecret) {
|
|
62
|
-
const secret = new URLSearchParams(window.location.search).get("secret");
|
|
63
|
-
if (!secret) {
|
|
64
|
-
throw new Error("Communication secret not found in URL as query parameter");
|
|
65
|
-
}
|
|
66
|
-
this.communicationSecret = secret;
|
|
67
|
-
}
|
|
68
|
-
return this.communicationSecret;
|
|
69
|
-
}
|
|
70
|
-
getClient() {
|
|
71
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
72
|
-
if (this.supabase && this.accessTokenExpiration && this.accessTokenExpiration > new Date()) {
|
|
73
|
-
return this.supabase;
|
|
74
|
-
}
|
|
75
|
-
const response = yield this.request("getSupabaseAccess", {});
|
|
76
|
-
this.accessTokenExpiration = response.expiration;
|
|
77
|
-
this.supabase = createClient(response.url, response.key, {
|
|
78
|
-
accessToken: () => Promise.resolve(response.token)
|
|
79
|
-
});
|
|
80
|
-
return this.supabase;
|
|
81
|
-
});
|
|
82
|
-
}
|
|
83
|
-
emit(eventName, data) {
|
|
84
|
-
this.internalEmit(eventName, 0, data);
|
|
85
|
-
}
|
|
86
|
-
// the communication needs to have an id to be able to distinguish between different responses
|
|
87
|
-
internalEmit(eventName, id, data) {
|
|
88
|
-
this.init().then(() => this.plugin.emitToParent(eventName, { data, _id: id, secret: this.getSecret() }));
|
|
89
|
-
}
|
|
90
|
-
subscribe(eventName, callback) {
|
|
91
|
-
var _a;
|
|
92
|
-
if (!this.listeners.has(eventName)) {
|
|
93
|
-
this.listeners.set(eventName, []);
|
|
94
|
-
}
|
|
95
|
-
(_a = this.listeners.get(eventName)) === null || _a === void 0 ? void 0 : _a.push(callback);
|
|
96
|
-
}
|
|
97
|
-
onOnce(eventName, callback) {
|
|
98
|
-
var _a;
|
|
99
|
-
if (!this.onceListeners.has(eventName)) {
|
|
100
|
-
this.onceListeners.set(eventName, []);
|
|
101
|
-
}
|
|
102
|
-
(_a = this.onceListeners.get(eventName)) === null || _a === void 0 ? void 0 : _a.push(callback);
|
|
103
|
-
}
|
|
104
|
-
request(topic, data) {
|
|
105
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
106
|
-
return yield new Promise((resolve) => {
|
|
107
|
-
let triggered = false;
|
|
108
|
-
const id = Math.random();
|
|
109
|
-
this.internalEmit(topic, id, data);
|
|
110
|
-
this.subscribe(topic, (_id, data) => {
|
|
111
|
-
if (triggered || (_id !== id && _id !== 0))
|
|
112
|
-
return;
|
|
113
|
-
triggered = true;
|
|
114
|
-
resolve(data);
|
|
115
|
-
});
|
|
116
|
-
});
|
|
117
|
-
});
|
|
118
|
-
}
|
|
119
|
-
}
|