@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
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
import React from "react";
|
|
2
|
-
import { usePlugin } from "../../utils/plugin/providers/PluginProvider";
|
|
3
|
-
export function useChat(tools) {
|
|
4
|
-
const [messages, setMessages] = React.useState([]);
|
|
5
|
-
const [isLoading, setIsLoading] = React.useState(false);
|
|
6
|
-
const { getAIResponseStream } = usePlugin();
|
|
7
|
-
const append = (appendMessages) => {
|
|
8
|
-
getAIResponseStream([...messages, ...appendMessages], (id, message, finished, toolInvocations) => {
|
|
9
|
-
const lastMessage = messages[messages.length - 1];
|
|
10
|
-
setIsLoading(!finished);
|
|
11
|
-
if ((lastMessage === null || lastMessage === void 0 ? void 0 : lastMessage.id) === id) {
|
|
12
|
-
lastMessage.content = message;
|
|
13
|
-
setMessages([...messages, lastMessage]);
|
|
14
|
-
}
|
|
15
|
-
else {
|
|
16
|
-
setMessages([...messages, ...appendMessages, { id, role: 'assistant', content: message, toolInvocations }]);
|
|
17
|
-
}
|
|
18
|
-
}, tools);
|
|
19
|
-
};
|
|
20
|
-
return { messages, append, isLoading, setMessages, lastMessage: messages[messages.length - 1] };
|
|
21
|
-
}
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
import { SupabaseClient } from '@supabase/supabase-js';
|
|
2
|
-
export interface Plugin {
|
|
3
|
-
id: string;
|
|
4
|
-
title: string;
|
|
5
|
-
icon_url: string;
|
|
6
|
-
website: string;
|
|
7
|
-
context_menu_actions: string;
|
|
8
|
-
plugin_pages: string;
|
|
9
|
-
sidebar_pages: string;
|
|
10
|
-
settings_page: string;
|
|
11
|
-
version: string;
|
|
12
|
-
external_hosted_url: string;
|
|
13
|
-
}
|
|
14
|
-
export declare function getPlugins(supabase: SupabaseClient): Promise<Plugin[]>;
|
|
@@ -1,30 +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 getPlugins(supabase) {
|
|
11
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
12
|
-
let { data, error } = yield supabase.from('plugins').select('*');
|
|
13
|
-
if (error) {
|
|
14
|
-
console.error(error);
|
|
15
|
-
return [];
|
|
16
|
-
}
|
|
17
|
-
return (data || []).map((plugin) => ({
|
|
18
|
-
id: plugin.id,
|
|
19
|
-
title: plugin.title,
|
|
20
|
-
icon_url: plugin.icon_url,
|
|
21
|
-
website: plugin.website,
|
|
22
|
-
context_menu_actions: plugin.context_menu_actions,
|
|
23
|
-
plugin_pages: plugin.plugin_pages,
|
|
24
|
-
sidebar_pages: plugin.sidebar_pages,
|
|
25
|
-
settings_page: plugin.settings_page,
|
|
26
|
-
version: plugin.version,
|
|
27
|
-
external_hosted_url: plugin.external_hosted_url,
|
|
28
|
-
}));
|
|
29
|
-
});
|
|
30
|
-
}
|
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
export interface ToolInvocation {
|
|
2
|
-
toolName: string;
|
|
3
|
-
args: Record<string, string>;
|
|
4
|
-
}
|
|
5
|
-
export interface Tool {
|
|
6
|
-
name: string;
|
|
7
|
-
description: string;
|
|
8
|
-
parameters: {
|
|
9
|
-
name: string;
|
|
10
|
-
type: "string" | "number" | "boolean";
|
|
11
|
-
description: string;
|
|
12
|
-
}[];
|
|
13
|
-
}
|
|
14
|
-
export interface Message {
|
|
15
|
-
id: string;
|
|
16
|
-
role: string;
|
|
17
|
-
content: string;
|
|
18
|
-
toolInvocations?: ToolInvocation[];
|
|
19
|
-
}
|
|
20
|
-
export declare function generateText(messages: Message[], tools: Tool[], token: string): Promise<any>;
|
|
21
|
-
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>;
|
|
@@ -1,68 +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 generateText(messages, tools, token) {
|
|
12
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
13
|
-
const response = yield fetch(`${env.SUPABASE_URL}/functions/v1/llm`, {
|
|
14
|
-
method: 'POST',
|
|
15
|
-
body: JSON.stringify({ messages, tools }),
|
|
16
|
-
headers: { 'Authorization': `Bearer ${token}` }
|
|
17
|
-
});
|
|
18
|
-
return yield response.json();
|
|
19
|
-
});
|
|
20
|
-
}
|
|
21
|
-
export function streamChatGPT(messages, tools, onResponse, token) {
|
|
22
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
23
|
-
const messageId = Math.random().toString(36).substring(3);
|
|
24
|
-
const response = yield fetch(`${env.SUPABASE_URL}/functions/v1/llm`, {
|
|
25
|
-
method: 'POST',
|
|
26
|
-
body: JSON.stringify({ messages, tools, stream: true }),
|
|
27
|
-
headers: { 'Authorization': `Bearer ${token}` }
|
|
28
|
-
});
|
|
29
|
-
if (!response.body) {
|
|
30
|
-
console.error('No response body.');
|
|
31
|
-
return;
|
|
32
|
-
}
|
|
33
|
-
const reader = response.body.getReader();
|
|
34
|
-
const decoder = new TextDecoder('utf-8');
|
|
35
|
-
let content = "";
|
|
36
|
-
let done = false;
|
|
37
|
-
let toolInvocations = [];
|
|
38
|
-
while (!done) {
|
|
39
|
-
const { value } = yield reader.read();
|
|
40
|
-
if (value) {
|
|
41
|
-
const chunk = decoder.decode(value, { stream: true });
|
|
42
|
-
const lines = chunk.split('\n').filter(line => line.trim() !== '');
|
|
43
|
-
for (const line of lines) {
|
|
44
|
-
const data = line.substring(3, line.length - 1);
|
|
45
|
-
const command = line.substring(0, 1);
|
|
46
|
-
// console.log("data: ", { line, data, command });
|
|
47
|
-
if (command === '0') {
|
|
48
|
-
content += data;
|
|
49
|
-
// console.log("AI response:", content);
|
|
50
|
-
//content \n\n should be real line break when message is displayed
|
|
51
|
-
onResponse(messageId, content.replace(/\\n/g, '\n'), false);
|
|
52
|
-
}
|
|
53
|
-
else if (command === 'd') {
|
|
54
|
-
// console.log("AI usage:", JSON.parse(line.substring(2)));
|
|
55
|
-
done = true;
|
|
56
|
-
break;
|
|
57
|
-
}
|
|
58
|
-
else if (command === '9') {
|
|
59
|
-
// console.log("tool call:", JSON.parse(line.substring(2)));
|
|
60
|
-
// console.log("tools", tools);
|
|
61
|
-
toolInvocations.push(JSON.parse(line.substring(2)));
|
|
62
|
-
}
|
|
63
|
-
}
|
|
64
|
-
}
|
|
65
|
-
}
|
|
66
|
-
onResponse(messageId, content.replace(/\\n/g, '\n'), true, toolInvocations);
|
|
67
|
-
});
|
|
68
|
-
}
|
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
export interface ToolInvocation {
|
|
2
|
-
toolName: string;
|
|
3
|
-
args: Record<string, string>;
|
|
4
|
-
}
|
|
5
|
-
export interface Tool {
|
|
6
|
-
name: string;
|
|
7
|
-
description: string;
|
|
8
|
-
parameters: {
|
|
9
|
-
name: string;
|
|
10
|
-
type: "string" | "number" | "boolean";
|
|
11
|
-
description: string;
|
|
12
|
-
}[];
|
|
13
|
-
}
|
|
14
|
-
export interface Message {
|
|
15
|
-
id: string;
|
|
16
|
-
role: string;
|
|
17
|
-
content: string;
|
|
18
|
-
toolInvocations?: ToolInvocation[];
|
|
19
|
-
}
|
|
20
|
-
export declare function generateText(messages: Message[], tools: Tool[], token: string): Promise<any>;
|
|
21
|
-
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>;
|
|
@@ -1,68 +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 generateText(messages, tools, token) {
|
|
12
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
13
|
-
const response = yield fetch(`${env.SUPABASE_URL}/functions/v1/llm`, {
|
|
14
|
-
method: 'POST',
|
|
15
|
-
body: JSON.stringify({ messages, tools }),
|
|
16
|
-
headers: { 'Authorization': `Bearer ${token}` }
|
|
17
|
-
});
|
|
18
|
-
return yield response.json();
|
|
19
|
-
});
|
|
20
|
-
}
|
|
21
|
-
export function streamChatGPT(messages, tools, onResponse, token) {
|
|
22
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
23
|
-
const messageId = Math.random().toString(36).substring(3);
|
|
24
|
-
const response = yield fetch(`${env.SUPABASE_URL}/functions/v1/llm`, {
|
|
25
|
-
method: 'POST',
|
|
26
|
-
body: JSON.stringify({ messages, tools, stream: true }),
|
|
27
|
-
headers: { 'Authorization': `Bearer ${token}` }
|
|
28
|
-
});
|
|
29
|
-
if (!response.body) {
|
|
30
|
-
console.error('No response body.');
|
|
31
|
-
return;
|
|
32
|
-
}
|
|
33
|
-
const reader = response.body.getReader();
|
|
34
|
-
const decoder = new TextDecoder('utf-8');
|
|
35
|
-
let content = "";
|
|
36
|
-
let done = false;
|
|
37
|
-
let toolInvocations = [];
|
|
38
|
-
while (!done) {
|
|
39
|
-
const { value } = yield reader.read();
|
|
40
|
-
if (value) {
|
|
41
|
-
const chunk = decoder.decode(value, { stream: true });
|
|
42
|
-
const lines = chunk.split('\n').filter(line => line.trim() !== '');
|
|
43
|
-
for (const line of lines) {
|
|
44
|
-
const data = line.substring(3, line.length - 1);
|
|
45
|
-
const command = line.substring(0, 1);
|
|
46
|
-
// console.log("data: ", { line, data, command });
|
|
47
|
-
if (command === '0') {
|
|
48
|
-
content += data;
|
|
49
|
-
// console.log("AI response:", content);
|
|
50
|
-
//content \n\n should be real line break when message is displayed
|
|
51
|
-
onResponse(messageId, content.replace(/\\n/g, '\n'), false);
|
|
52
|
-
}
|
|
53
|
-
else if (command === 'd') {
|
|
54
|
-
// console.log("AI usage:", JSON.parse(line.substring(2)));
|
|
55
|
-
done = true;
|
|
56
|
-
break;
|
|
57
|
-
}
|
|
58
|
-
else if (command === '9') {
|
|
59
|
-
// console.log("tool call:", JSON.parse(line.substring(2)));
|
|
60
|
-
// console.log("tools", tools);
|
|
61
|
-
toolInvocations.push(JSON.parse(line.substring(2)));
|
|
62
|
-
}
|
|
63
|
-
}
|
|
64
|
-
}
|
|
65
|
-
}
|
|
66
|
-
onResponse(messageId, content.replace(/\\n/g, '\n'), true, toolInvocations);
|
|
67
|
-
});
|
|
68
|
-
}
|
|
@@ -1,34 +0,0 @@
|
|
|
1
|
-
type PrimitiveType = 'string' | 'number' | 'boolean';
|
|
2
|
-
type ObjectToolParameterType = PrimitiveType | {
|
|
3
|
-
[key: string]: ObjectToolParameter;
|
|
4
|
-
} | [{
|
|
5
|
-
[key: string]: ObjectToolParameter;
|
|
6
|
-
}];
|
|
7
|
-
interface ObjectToolParameter {
|
|
8
|
-
type: ObjectToolParameterType;
|
|
9
|
-
description?: string;
|
|
10
|
-
enum?: string[];
|
|
11
|
-
}
|
|
12
|
-
export type ObjectTool = {
|
|
13
|
-
[key: string]: ObjectToolParameter;
|
|
14
|
-
};
|
|
15
|
-
export interface ObjectRequest {
|
|
16
|
-
/**
|
|
17
|
-
* The tools that the AI can use.
|
|
18
|
-
*/
|
|
19
|
-
tool: ObjectTool;
|
|
20
|
-
/**
|
|
21
|
-
* High level instructions for the AI to follow. Behaviour, tone, restrictions, etc.
|
|
22
|
-
* Example: "Act like a recipe writer."
|
|
23
|
-
*/
|
|
24
|
-
behaviour?: string;
|
|
25
|
-
/**
|
|
26
|
-
* The specific instruction for the AI to follow.
|
|
27
|
-
* Example: "Generate a recipe using chicken, rice and vegetables."
|
|
28
|
-
*/
|
|
29
|
-
instructions: string;
|
|
30
|
-
}
|
|
31
|
-
export declare function generateObject(request: ObjectRequest, token: string): Promise<any>;
|
|
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>;
|
|
34
|
-
export {};
|
|
@@ -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
|
-
}
|