@rimori/client 1.0.2 → 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.
Files changed (135) hide show
  1. package/README.md +51 -0
  2. package/dist/components/CRUDModal.js +0 -1
  3. package/dist/components/ai/Assistant.d.ts +9 -0
  4. package/dist/components/ai/Assistant.js +59 -0
  5. package/dist/components/ai/Avatar.d.ts +11 -0
  6. package/dist/components/ai/Avatar.js +39 -0
  7. package/dist/components/ai/EmbeddedAssistent/AudioInputField.d.ts +7 -0
  8. package/dist/components/ai/EmbeddedAssistent/AudioInputField.js +38 -0
  9. package/dist/components/ai/EmbeddedAssistent/CircleAudioAvatar.d.ts +7 -0
  10. package/dist/components/ai/EmbeddedAssistent/CircleAudioAvatar.js +59 -0
  11. package/dist/components/ai/EmbeddedAssistent/TTS/MessageSender.d.ts +19 -0
  12. package/dist/components/ai/EmbeddedAssistent/TTS/MessageSender.js +86 -0
  13. package/dist/components/ai/EmbeddedAssistent/TTS/Player.d.ts +25 -0
  14. package/dist/components/ai/EmbeddedAssistent/TTS/Player.js +180 -0
  15. package/dist/components/ai/EmbeddedAssistent/VoiceRecoder.d.ts +7 -0
  16. package/dist/components/ai/EmbeddedAssistent/VoiceRecoder.js +45 -0
  17. package/dist/components/ai/utils.d.ts +6 -0
  18. package/dist/components/ai/utils.js +14 -0
  19. package/dist/components/audio/Playbutton.js +4 -5
  20. package/dist/components/avatar/Assistant.d.ts +9 -0
  21. package/dist/components/avatar/Assistant.js +59 -0
  22. package/dist/components/avatar/Avatar.d.ts +12 -0
  23. package/dist/components/avatar/Avatar.js +42 -0
  24. package/dist/components/avatar/EmbeddedAssistent/AudioInputField.d.ts +7 -0
  25. package/dist/components/avatar/EmbeddedAssistent/AudioInputField.js +38 -0
  26. package/dist/components/avatar/EmbeddedAssistent/CircleAudioAvatar.d.ts +7 -0
  27. package/dist/components/avatar/EmbeddedAssistent/CircleAudioAvatar.js +59 -0
  28. package/dist/components/avatar/EmbeddedAssistent/TTS/MessageSender.d.ts +19 -0
  29. package/dist/components/avatar/EmbeddedAssistent/TTS/MessageSender.js +84 -0
  30. package/dist/components/avatar/EmbeddedAssistent/TTS/Player.d.ts +25 -0
  31. package/dist/components/avatar/EmbeddedAssistent/TTS/Player.js +180 -0
  32. package/dist/components/avatar/EmbeddedAssistent/VoiceRecoder.d.ts +7 -0
  33. package/dist/components/avatar/EmbeddedAssistent/VoiceRecoder.js +45 -0
  34. package/dist/components/avatar/utils.d.ts +6 -0
  35. package/dist/components/avatar/utils.js +14 -0
  36. package/dist/components.d.ts +9 -0
  37. package/dist/components.js +10 -0
  38. package/dist/controller/AIController.d.ts +4 -3
  39. package/dist/controller/AIController.js +32 -8
  40. package/dist/controller/ObjectController.d.ts +2 -2
  41. package/dist/controller/ObjectController.js +4 -5
  42. package/dist/controller/SettingsController.d.ts +3 -1
  43. package/dist/controller/SettingsController.js +9 -0
  44. package/dist/controller/SharedContentController.js +6 -6
  45. package/dist/controller/SidePluginController.d.ts +14 -0
  46. package/dist/{plugin/VoiceController.js → controller/SidePluginController.js} +18 -15
  47. package/dist/controller/VoiceController.js +1 -1
  48. package/dist/core.d.ts +9 -0
  49. package/dist/core.js +10 -0
  50. package/dist/hooks/UseChatHook.js +2 -2
  51. package/dist/index.d.ts +3 -2
  52. package/dist/index.js +4 -2
  53. package/dist/plugin/PluginController.d.ts +4 -12
  54. package/dist/plugin/PluginController.js +43 -70
  55. package/dist/plugin/RimoriClient.d.ts +87 -27
  56. package/dist/plugin/RimoriClient.js +101 -67
  57. package/dist/plugin/fromRimori/EventBus.d.ts +98 -0
  58. package/dist/plugin/fromRimori/EventBus.js +240 -0
  59. package/dist/providers/PluginProvider.d.ts +1 -0
  60. package/dist/providers/PluginProvider.js +64 -12
  61. package/dist/worker/WorkerSetup.d.ts +6 -0
  62. package/dist/worker/WorkerSetup.js +79 -0
  63. package/package.json +16 -3
  64. package/src/components/CRUDModal.tsx +1 -3
  65. package/src/components/ai/Assistant.tsx +96 -0
  66. package/src/components/ai/Avatar.tsx +61 -0
  67. package/src/components/ai/EmbeddedAssistent/AudioInputField.tsx +64 -0
  68. package/src/components/ai/EmbeddedAssistent/CircleAudioAvatar.tsx +75 -0
  69. package/src/components/ai/EmbeddedAssistent/TTS/MessageSender.ts +91 -0
  70. package/src/components/ai/EmbeddedAssistent/TTS/Player.ts +192 -0
  71. package/src/components/ai/EmbeddedAssistent/VoiceRecoder.tsx +56 -0
  72. package/src/components/ai/utils.ts +23 -0
  73. package/src/components/audio/Playbutton.tsx +4 -5
  74. package/src/components.ts +10 -0
  75. package/src/controller/AIController.ts +84 -60
  76. package/src/controller/ObjectController.ts +4 -6
  77. package/src/controller/SettingsController.ts +10 -1
  78. package/src/controller/SharedContentController.ts +6 -6
  79. package/src/controller/SidePluginController.ts +36 -0
  80. package/src/controller/VoiceController.ts +1 -1
  81. package/src/core.ts +10 -0
  82. package/src/hooks/UseChatHook.ts +2 -2
  83. package/src/index.ts +4 -2
  84. package/src/plugin/PluginController.ts +46 -76
  85. package/src/plugin/RimoriClient.ts +151 -76
  86. package/src/plugin/fromRimori/EventBus.ts +301 -0
  87. package/src/plugin/fromRimori/readme.md +2 -0
  88. package/src/providers/PluginProvider.tsx +70 -14
  89. package/src/worker/WorkerSetup.ts +80 -0
  90. package/dist/CRUDModal.d.ts +0 -16
  91. package/dist/CRUDModal.js +0 -31
  92. package/dist/MarkdownEditor.d.ts +0 -8
  93. package/dist/MarkdownEditor.js +0 -46
  94. package/dist/audio/Playbutton.d.ts +0 -14
  95. package/dist/audio/Playbutton.js +0 -73
  96. package/dist/components/hooks/UseChatHook.d.ts +0 -15
  97. package/dist/components/hooks/UseChatHook.js +0 -21
  98. package/dist/plugin/AIController copy.d.ts +0 -22
  99. package/dist/plugin/AIController copy.js +0 -68
  100. package/dist/plugin/AIController.d.ts +0 -22
  101. package/dist/plugin/AIController.js +0 -68
  102. package/dist/plugin/ObjectController.d.ts +0 -34
  103. package/dist/plugin/ObjectController.js +0 -77
  104. package/dist/plugin/SettingController.d.ts +0 -13
  105. package/dist/plugin/SettingController.js +0 -55
  106. package/dist/plugin/VoiceController.d.ts +0 -2
  107. package/dist/providers/EventEmitter.d.ts +0 -11
  108. package/dist/providers/EventEmitter.js +0 -41
  109. package/dist/providers/EventEmitterContext.d.ts +0 -6
  110. package/dist/providers/EventEmitterContext.js +0 -19
  111. package/dist/utils/DifficultyConverter.d.ts +0 -3
  112. package/dist/utils/DifficultyConverter.js +0 -7
  113. package/dist/utils/constants.d.ts +0 -4
  114. package/dist/utils/constants.js +0 -12
  115. package/dist/utils/plugin/Client.d.ts +0 -72
  116. package/dist/utils/plugin/Client.js +0 -118
  117. package/dist/utils/plugin/PluginController.d.ts +0 -36
  118. package/dist/utils/plugin/PluginController.js +0 -119
  119. package/dist/utils/plugin/PluginUtils.d.ts +0 -2
  120. package/dist/utils/plugin/PluginUtils.js +0 -23
  121. package/dist/utils/plugin/RimoriClient.d.ts +0 -72
  122. package/dist/utils/plugin/RimoriClient.js +0 -118
  123. package/dist/utils/plugin/ThemeSetter.d.ts +0 -1
  124. package/dist/utils/plugin/ThemeSetter.js +0 -13
  125. package/dist/utils/plugin/WhereClauseBuilder.d.ts +0 -24
  126. package/dist/utils/plugin/WhereClauseBuilder.js +0 -79
  127. package/dist/utils/plugin/providers/EventEmitter.d.ts +0 -11
  128. package/dist/utils/plugin/providers/EventEmitter.js +0 -41
  129. package/dist/utils/plugin/providers/EventEmitterContext.d.ts +0 -6
  130. package/dist/utils/plugin/providers/EventEmitterContext.js +0 -19
  131. package/dist/utils/plugin/providers/PluginProvider.d.ts +0 -8
  132. package/dist/utils/plugin/providers/PluginProvider.js +0 -49
  133. package/src/providers/EventEmitter.ts +0 -48
  134. package/src/providers/EventEmitterContext.tsx +0 -27
  135. package/src/utils/constants.ts +0 -18
@@ -1,73 +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 { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
11
- import { useState, useEffect } from 'react';
12
- import { FaPlayCircle, FaStopCircle } from "react-icons/fa";
13
- import { usePlugin } from "../utils/plugin/providers/PluginProvider";
14
- import Spinner from '../components/Spinner';
15
- import { EmitterSingleton } from '../utils/plugin/providers/EventEmitter';
16
- export const AudioPlayOptions = [0.8, 0.9, 1.0, 1.1, 1.2, 1.5];
17
- let isFetchingAudio = false;
18
- export const AudioPlayer = ({ text, voice, language, playListenerEvent, initialSpeed = 1.0, playOnMount = false, enableSpeedAdjustment = false, }) => {
19
- const [audioUrl, setAudioUrl] = useState(null);
20
- const [speed, setSpeed] = useState(initialSpeed);
21
- const [isPlaying, setIsPlaying] = useState(false);
22
- const [isLoading, setIsLoading] = useState(false);
23
- const { getVoiceResponse, } = usePlugin();
24
- const emitter = EmitterSingleton;
25
- useEffect(() => {
26
- if (!playListenerEvent)
27
- return;
28
- emitter.on(playListenerEvent, () => togglePlayback());
29
- }, [playListenerEvent]);
30
- // Function to generate audio from text using API
31
- const generateAudio = () => __awaiter(void 0, void 0, void 0, function* () {
32
- setIsLoading(true);
33
- const blob = yield getVoiceResponse(text, voice || (language ? "aws_default" : "openai_alloy"), 1, language);
34
- setAudioUrl(URL.createObjectURL(blob));
35
- setIsLoading(false);
36
- });
37
- // Effect to play audio when audioUrl changes and play state is true
38
- useEffect(() => {
39
- if (!audioUrl || !isPlaying)
40
- return;
41
- const audio = new Audio(audioUrl);
42
- audio.playbackRate = speed;
43
- audio.play().then(() => {
44
- audio.onended = () => {
45
- setIsPlaying(false);
46
- isFetchingAudio = false;
47
- };
48
- }).catch(e => {
49
- console.warn("Error playing audio:", e);
50
- setIsPlaying(false);
51
- });
52
- return () => {
53
- audio.pause();
54
- URL.revokeObjectURL(audioUrl);
55
- };
56
- }, [audioUrl, isPlaying, speed]);
57
- const togglePlayback = () => {
58
- if (!isPlaying && !audioUrl) {
59
- generateAudio().then(() => setIsPlaying(true));
60
- }
61
- else {
62
- setIsPlaying((prev) => !prev);
63
- }
64
- };
65
- useEffect(() => {
66
- if (!playOnMount || isFetchingAudio)
67
- return;
68
- isFetchingAudio = true;
69
- // console.log("playOnMount", playOnMount);
70
- togglePlayback();
71
- }, [playOnMount]);
72
- return (_jsx("div", { className: "group relative", children: _jsxs("div", { className: 'flex flex-row items-end', children: [_jsx("button", { className: "text-gray-500", onClick: togglePlayback, disabled: isLoading, children: isLoading ? _jsx(Spinner, {}) : isPlaying ? _jsx(FaStopCircle, { size: "25px" }) : _jsx(FaPlayCircle, { size: "25px" }) }), enableSpeedAdjustment && (_jsxs("div", { className: "ml-1 opacity-0 group-hover:opacity-100 transition-opacity duration-300 flex flex-row text-sm text-gray-500", children: [_jsx("span", { className: 'pr-1', children: "Speed: " }), _jsx("select", { value: speed, className: 'appearance-none cursor-pointer pr-0 p-0 rounded shadow leading-tight focus:outline-none focus:bg-gray-800 focus:ring bg-transparent border-0', onChange: (e) => setSpeed(parseFloat(e.target.value)), disabled: isLoading, children: AudioPlayOptions.map((s) => (_jsx("option", { value: s, children: s }, s))) })] }))] }) }));
73
- };
@@ -1,15 +0,0 @@
1
- import React from "react";
2
- import { ToolInvocation, Tool } from "../../utils/plugin/PluginController";
3
- export interface Message {
4
- role: string;
5
- content: string;
6
- id: string | number;
7
- toolInvocations?: ToolInvocation[];
8
- }
9
- export declare function useChat(tools?: Tool[]): {
10
- messages: Message[];
11
- append: (appendMessages: Message[]) => void;
12
- isLoading: boolean;
13
- setMessages: React.Dispatch<React.SetStateAction<Message[]>>;
14
- lastMessage: Message | undefined;
15
- };
@@ -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,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,2 +0,0 @@
1
- export declare function getSTTResponse(audio: Blob): Promise<any>;
2
- export declare function getTTSResponse(text: string, voice: string, speed: number, language?: string): Promise<Blob>;
@@ -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,6 +0,0 @@
1
- import React from "react";
2
- import { EventEmitter } from "./EventEmitter";
3
- export declare const EventEmitterProvider: React.FC<{
4
- children: React.ReactNode;
5
- }>;
6
- export declare const useEventEmitter: () => EventEmitter;
@@ -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
- };
@@ -1,3 +0,0 @@
1
- export type LanguageLevel = "Pre-A1" | "A1" | "A2" | "B1" | "B2" | "C1" | "C2" | "Post-C2";
2
- export declare function getDifficultyLevel(difficulty: LanguageLevel): number;
3
- export declare function getDifficultyLabel(difficulty: number): LanguageLevel;
@@ -1,7 +0,0 @@
1
- const codes = ["Pre-A1", "A1", "A2", "B1", "B2", "C1", "C2", "Post-C2"];
2
- export function getDifficultyLevel(difficulty) {
3
- return codes.indexOf(difficulty) + 1;
4
- }
5
- export function getDifficultyLabel(difficulty) {
6
- return codes[difficulty];
7
- }
@@ -1,4 +0,0 @@
1
- export type Env = typeof env;
2
- export declare const env: {
3
- SUPABASE_URL: string;
4
- };
@@ -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
- });