@rimori/client 1.0.0
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/dist/CRUDModal.d.ts +16 -0
- package/dist/CRUDModal.js +31 -0
- package/dist/MarkdownEditor.d.ts +8 -0
- package/dist/MarkdownEditor.js +46 -0
- package/dist/audio/Playbutton.d.ts +14 -0
- package/dist/audio/Playbutton.js +73 -0
- package/dist/components/CRUDModal.d.ts +17 -0
- package/dist/components/CRUDModal.js +25 -0
- package/dist/components/MarkdownEditor.d.ts +8 -0
- package/dist/components/MarkdownEditor.js +46 -0
- package/dist/components/Spinner.d.ts +8 -0
- package/dist/components/Spinner.js +5 -0
- package/dist/components/audio/Playbutton.d.ts +15 -0
- package/dist/components/audio/Playbutton.js +78 -0
- package/dist/components/hooks/UseChatHook.d.ts +15 -0
- package/dist/components/hooks/UseChatHook.js +21 -0
- package/dist/controller/AIController.d.ts +22 -0
- package/dist/controller/AIController.js +68 -0
- package/dist/controller/ObjectController.d.ts +34 -0
- package/dist/controller/ObjectController.js +77 -0
- package/dist/controller/SettingsController.d.ts +24 -0
- package/dist/controller/SettingsController.js +72 -0
- package/dist/controller/SharedContentController.d.ts +22 -0
- package/dist/controller/SharedContentController.js +56 -0
- package/dist/controller/VoiceController.d.ts +10 -0
- package/dist/controller/VoiceController.js +28 -0
- package/dist/hooks/UseChatHook.d.ts +9 -0
- package/dist/hooks/UseChatHook.js +21 -0
- package/dist/index.d.ts +14 -0
- package/dist/index.js +14 -0
- package/dist/plugin/AIController copy.d.ts +22 -0
- package/dist/plugin/AIController copy.js +68 -0
- package/dist/plugin/AIController.d.ts +22 -0
- package/dist/plugin/AIController.js +68 -0
- package/dist/plugin/ObjectController.d.ts +34 -0
- package/dist/plugin/ObjectController.js +77 -0
- package/dist/plugin/PluginController.d.ts +29 -0
- package/dist/plugin/PluginController.js +138 -0
- package/dist/plugin/RimoriClient.d.ts +91 -0
- package/dist/plugin/RimoriClient.js +163 -0
- package/dist/plugin/SettingController.d.ts +13 -0
- package/dist/plugin/SettingController.js +55 -0
- package/dist/plugin/ThemeSetter.d.ts +1 -0
- package/dist/plugin/ThemeSetter.js +13 -0
- package/dist/plugin/VoiceController.d.ts +2 -0
- package/dist/plugin/VoiceController.js +27 -0
- package/dist/providers/EventEmitter.d.ts +11 -0
- package/dist/providers/EventEmitter.js +41 -0
- package/dist/providers/EventEmitterContext.d.ts +6 -0
- package/dist/providers/EventEmitterContext.js +19 -0
- package/dist/providers/PluginProvider.d.ts +8 -0
- package/dist/providers/PluginProvider.js +52 -0
- package/dist/style.css +110 -0
- package/dist/style.css.map +1 -0
- package/dist/utils/DifficultyConverter.d.ts +3 -0
- package/dist/utils/DifficultyConverter.js +7 -0
- package/dist/utils/PluginUtils.d.ts +2 -0
- package/dist/utils/PluginUtils.js +23 -0
- package/dist/utils/constants.d.ts +4 -0
- package/dist/utils/constants.js +12 -0
- package/dist/utils/difficultyConverter.d.ts +3 -0
- package/dist/utils/difficultyConverter.js +7 -0
- package/dist/utils/plugin/Client.d.ts +72 -0
- package/dist/utils/plugin/Client.js +118 -0
- package/dist/utils/plugin/PluginController.d.ts +36 -0
- package/dist/utils/plugin/PluginController.js +119 -0
- package/dist/utils/plugin/PluginUtils.d.ts +2 -0
- package/dist/utils/plugin/PluginUtils.js +23 -0
- package/dist/utils/plugin/RimoriClient.d.ts +72 -0
- package/dist/utils/plugin/RimoriClient.js +118 -0
- package/dist/utils/plugin/ThemeSetter.d.ts +1 -0
- package/dist/utils/plugin/ThemeSetter.js +13 -0
- package/dist/utils/plugin/WhereClauseBuilder.d.ts +24 -0
- package/dist/utils/plugin/WhereClauseBuilder.js +79 -0
- package/dist/utils/plugin/providers/EventEmitter.d.ts +11 -0
- package/dist/utils/plugin/providers/EventEmitter.js +41 -0
- package/dist/utils/plugin/providers/EventEmitterContext.d.ts +6 -0
- package/dist/utils/plugin/providers/EventEmitterContext.js +19 -0
- package/dist/utils/plugin/providers/PluginProvider.d.ts +8 -0
- package/dist/utils/plugin/providers/PluginProvider.js +49 -0
- package/package.json +30 -0
- package/src/components/CRUDModal.tsx +61 -0
- package/src/components/MarkdownEditor.tsx +111 -0
- package/src/components/Spinner.tsx +24 -0
- package/src/components/audio/Playbutton.tsx +119 -0
- package/src/controller/AIController.ts +87 -0
- package/src/controller/ObjectController.ts +109 -0
- package/src/controller/SettingsController.ts +87 -0
- package/src/controller/SharedContentController.ts +71 -0
- package/src/controller/VoiceController.ts +26 -0
- package/src/hooks/UseChatHook.ts +25 -0
- package/src/index.ts +14 -0
- package/src/plugin/PluginController.ts +158 -0
- package/src/plugin/RimoriClient.ts +207 -0
- package/src/plugin/ThemeSetter.ts +17 -0
- package/src/providers/EventEmitter.ts +48 -0
- package/src/providers/EventEmitterContext.tsx +27 -0
- package/src/providers/PluginProvider.tsx +68 -0
- package/src/style.scss +136 -0
- package/src/utils/PluginUtils.ts +26 -0
- package/src/utils/constants.ts +18 -0
- package/src/utils/difficultyConverter.ts +11 -0
- package/tsconfig.json +16 -0
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
interface Props {
|
|
2
|
+
title: string;
|
|
3
|
+
show?: boolean;
|
|
4
|
+
className?: string;
|
|
5
|
+
closeAble?: boolean;
|
|
6
|
+
children: React.ReactNode;
|
|
7
|
+
actionbuttons: ActionButton[];
|
|
8
|
+
buttonText?: string | React.ReactNode;
|
|
9
|
+
}
|
|
10
|
+
interface ActionButton {
|
|
11
|
+
text: string;
|
|
12
|
+
onClick: () => void;
|
|
13
|
+
closeModal?: boolean;
|
|
14
|
+
}
|
|
15
|
+
export declare function CRUDModal({ actionbuttons, children, title, buttonText, className, closeAble, show }: Props): import("react/jsx-runtime").JSX.Element;
|
|
16
|
+
export {};
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
|
|
3
|
+
import { useEffect, useState, useRef } from "react";
|
|
4
|
+
export function CRUDModal({ actionbuttons, children, title, buttonText, className, closeAble = true, show = false }) {
|
|
5
|
+
const [openModal, setOpenModal] = useState(show);
|
|
6
|
+
const dialogRef = useRef(null);
|
|
7
|
+
useEffect(() => {
|
|
8
|
+
var _a, _b;
|
|
9
|
+
if (show) {
|
|
10
|
+
(_a = dialogRef.current) === null || _a === void 0 ? void 0 : _a.showModal();
|
|
11
|
+
}
|
|
12
|
+
else {
|
|
13
|
+
(_b = dialogRef.current) === null || _b === void 0 ? void 0 : _b.close();
|
|
14
|
+
}
|
|
15
|
+
setOpenModal(show);
|
|
16
|
+
}, [show]);
|
|
17
|
+
const handleClose = () => {
|
|
18
|
+
var _a;
|
|
19
|
+
setOpenModal(false);
|
|
20
|
+
(_a = dialogRef.current) === null || _a === void 0 ? void 0 : _a.close();
|
|
21
|
+
};
|
|
22
|
+
return (_jsxs(_Fragment, { children: [!!buttonText && _jsx("button", { className: className, onClick: () => {
|
|
23
|
+
var _a;
|
|
24
|
+
setOpenModal(true);
|
|
25
|
+
(_a = dialogRef.current) === null || _a === void 0 ? void 0 : _a.showModal();
|
|
26
|
+
}, children: buttonText }), _jsxs("dialog", { ref: dialogRef, className: "bg-gray-400 rounded-lg font-normal", onClose: handleClose, children: [_jsxs("div", { className: "bg-gray-500 text-xl flex flex-row justify-between p-3 items-start font-bold", children: [_jsx("h2", { children: title }), closeAble && _jsx("button", { onClick: handleClose, children: "\u00D7" })] }), _jsx("div", { className: "modal-body p-2", children: children }), _jsx("div", { className: "modal-footer px-2 py-2 flex flex-row gap-2 border-t-2", children: actionbuttons.map(({ onClick, text, closeModal = true }, index) => (_jsx("button", { className: " bg-blue-500 hover:bg-blue-600 dark:border-gray-900 rounded-md py-2 px-4 dark:text-white font-bold", onClick: () => {
|
|
27
|
+
if (closeModal)
|
|
28
|
+
handleClose();
|
|
29
|
+
onClick();
|
|
30
|
+
}, children: text }, index))) })] })] }));
|
|
31
|
+
}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { Markdown } from 'tiptap-markdown';
|
|
3
|
+
import StarterKit from "@tiptap/starter-kit";
|
|
4
|
+
import { PiCodeBlock } from "react-icons/pi";
|
|
5
|
+
import { TbBlockquote } from "react-icons/tb";
|
|
6
|
+
import { GoListOrdered } from "react-icons/go";
|
|
7
|
+
import { AiOutlineUnorderedList } from "react-icons/ai";
|
|
8
|
+
import { EditorProvider, useCurrentEditor } from "@tiptap/react";
|
|
9
|
+
import { LuHeading1, LuHeading2, LuHeading3 } from "react-icons/lu";
|
|
10
|
+
import { FaBold, FaCode, FaItalic, FaParagraph, FaStrikethrough } from "react-icons/fa";
|
|
11
|
+
const EditorButton = ({ action, isActive, label, disabled }) => {
|
|
12
|
+
const { editor } = useCurrentEditor();
|
|
13
|
+
if (!editor) {
|
|
14
|
+
return null;
|
|
15
|
+
}
|
|
16
|
+
if (action.includes("heading")) {
|
|
17
|
+
const level = parseInt(action[action.length - 1]);
|
|
18
|
+
return (_jsx("button", { onClick: () => editor.chain().focus().toggleHeading({ level: level }).run(), className: `pl-2 ${isActive ? "is-active" : ""}`, children: label }));
|
|
19
|
+
}
|
|
20
|
+
return (_jsx("button", { onClick: () => editor.chain().focus()[action]().run(), disabled: disabled ? !editor.can().chain().focus()[action]().run() : false, className: `pl-2 ${isActive ? "is-active" : ""}`, children: label }));
|
|
21
|
+
};
|
|
22
|
+
const MenuBar = () => {
|
|
23
|
+
const { editor } = useCurrentEditor();
|
|
24
|
+
if (!editor) {
|
|
25
|
+
return null;
|
|
26
|
+
}
|
|
27
|
+
return (_jsxs("div", { className: "bg-gray-400 dark:bg-gray-800 dark:text-white text-lg flex flex-row flex-wrap items-center p-1", children: [_jsx(EditorButton, { action: "toggleBold", isActive: editor.isActive("bold"), label: _jsx(FaBold, {}), disabled: true }), _jsx(EditorButton, { action: "toggleItalic", isActive: editor.isActive("italic"), label: _jsx(FaItalic, {}), disabled: true }), _jsx(EditorButton, { action: "toggleStrike", isActive: editor.isActive("strike"), label: _jsx(FaStrikethrough, {}), disabled: true }), _jsx(EditorButton, { action: "toggleCode", isActive: editor.isActive("code"), label: _jsx(FaCode, {}), disabled: true }), _jsx(EditorButton, { action: "setParagraph", isActive: editor.isActive("paragraph"), label: _jsx(FaParagraph, {}) }), _jsx(EditorButton, { action: 'setHeading1', isActive: editor.isActive("heading", { level: 1 }), label: _jsx(LuHeading1, { size: "24px" }) }), _jsx(EditorButton, { action: 'setHeading2', isActive: editor.isActive("heading", { level: 2 }), label: _jsx(LuHeading2, { size: "24px" }) }), _jsx(EditorButton, { action: 'setHeading3', isActive: editor.isActive("heading", { level: 3 }), label: _jsx(LuHeading3, { size: "24px" }) }), _jsx(EditorButton, { action: "toggleBulletList", isActive: editor.isActive("bulletList"), label: _jsx(AiOutlineUnorderedList, { size: "24px" }) }), _jsx(EditorButton, { action: "toggleOrderedList", isActive: editor.isActive("orderedList"), label: _jsx(GoListOrdered, { size: "24px" }) }), _jsx(EditorButton, { action: "toggleCodeBlock", isActive: editor.isActive("codeBlock"), label: _jsx(PiCodeBlock, { size: "24px" }) }), _jsx(EditorButton, { action: "toggleBlockquote", isActive: editor.isActive("blockquote"), label: _jsx(TbBlockquote, { size: "24px" }) })] }));
|
|
28
|
+
};
|
|
29
|
+
const extensions = [
|
|
30
|
+
StarterKit.configure({
|
|
31
|
+
bulletList: {
|
|
32
|
+
keepMarks: true,
|
|
33
|
+
keepAttributes: false,
|
|
34
|
+
},
|
|
35
|
+
orderedList: {
|
|
36
|
+
keepMarks: true,
|
|
37
|
+
keepAttributes: false,
|
|
38
|
+
},
|
|
39
|
+
}),
|
|
40
|
+
Markdown,
|
|
41
|
+
];
|
|
42
|
+
export const MarkdownEditor = (props) => {
|
|
43
|
+
return (_jsx("div", { className: "text-md border border-gray-800 overflow-hidden " + props.className, style: { borderWidth: props.editable ? 1 : 0 }, children: _jsx(EditorProvider, { slotBefore: props.editable ? _jsx(MenuBar, {}) : null, extensions: extensions, content: props.content, editable: props.editable, onUpdate: (e) => {
|
|
44
|
+
props.onUpdate && props.onUpdate(e.editor.storage.markdown.getMarkdown());
|
|
45
|
+
} }, (props.editable ? "editable" : "readonly") + props.content) }));
|
|
46
|
+
};
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
type AudioPlayerProps = {
|
|
3
|
+
text: string;
|
|
4
|
+
voice?: string;
|
|
5
|
+
language?: string;
|
|
6
|
+
playOnMount?: boolean;
|
|
7
|
+
initialSpeed?: number;
|
|
8
|
+
enableSpeedAdjustment?: boolean;
|
|
9
|
+
playListenerEvent?: string;
|
|
10
|
+
};
|
|
11
|
+
export declare const AudioPlayOptions: number[];
|
|
12
|
+
export type AudioPlayOptionType = 0.8 | 0.9 | 1.0 | 1.1 | 1.2 | 1.5;
|
|
13
|
+
export declare const AudioPlayer: React.FC<AudioPlayerProps>;
|
|
14
|
+
export {};
|
|
@@ -0,0 +1,73 @@
|
|
|
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
|
+
};
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
interface Props {
|
|
2
|
+
title: string;
|
|
3
|
+
show?: boolean;
|
|
4
|
+
className?: string;
|
|
5
|
+
closeAble?: boolean;
|
|
6
|
+
children: React.ReactNode;
|
|
7
|
+
actionbuttons: ActionButton[];
|
|
8
|
+
buttonText?: string | React.ReactNode;
|
|
9
|
+
onClose?: () => void;
|
|
10
|
+
}
|
|
11
|
+
interface ActionButton {
|
|
12
|
+
text: string;
|
|
13
|
+
onClick: () => void;
|
|
14
|
+
closeModal?: boolean;
|
|
15
|
+
}
|
|
16
|
+
export declare function CRUDModal({ actionbuttons, children, title, buttonText, className, closeAble, show, onClose }: Props): import("react/jsx-runtime").JSX.Element;
|
|
17
|
+
export {};
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
|
|
3
|
+
import { useEffect, useRef } from "react";
|
|
4
|
+
export function CRUDModal({ actionbuttons, children, title, buttonText, className, closeAble = true, show = false, onClose }) {
|
|
5
|
+
const dialogRef = useRef(null);
|
|
6
|
+
useEffect(() => {
|
|
7
|
+
var _a, _b;
|
|
8
|
+
if (show) {
|
|
9
|
+
(_a = dialogRef.current) === null || _a === void 0 ? void 0 : _a.showModal();
|
|
10
|
+
}
|
|
11
|
+
else {
|
|
12
|
+
(_b = dialogRef.current) === null || _b === void 0 ? void 0 : _b.close();
|
|
13
|
+
}
|
|
14
|
+
}, [show]);
|
|
15
|
+
const handleClose = () => {
|
|
16
|
+
var _a;
|
|
17
|
+
(_a = dialogRef.current) === null || _a === void 0 ? void 0 : _a.close();
|
|
18
|
+
onClose === null || onClose === void 0 ? void 0 : onClose();
|
|
19
|
+
};
|
|
20
|
+
return (_jsxs(_Fragment, { children: [!!buttonText && _jsx("button", { className: className, onClick: () => { var _a; return (_a = dialogRef.current) === null || _a === void 0 ? void 0 : _a.showModal(); }, children: buttonText }), _jsxs("dialog", { ref: dialogRef, className: "bg-gray-400 rounded-lg font-normal", onClose: handleClose, children: [_jsxs("div", { className: "bg-gray-500 text-xl flex flex-row justify-between p-3 items-start font-bold", children: [_jsx("h2", { children: title }), closeAble && _jsx("button", { onClick: handleClose, children: "\u00D7" })] }), _jsx("div", { className: "modal-body p-2", children: children }), _jsx("div", { className: "modal-footer px-2 py-2 flex flex-row gap-2 border-t-2", children: actionbuttons.map(({ onClick, text, closeModal = true }, index) => (_jsx("button", { className: "bg-blue-500 hover:bg-blue-600 dark:border-gray-900 rounded-md py-2 px-4 dark:text-white font-bold", onClick: () => {
|
|
21
|
+
if (closeModal)
|
|
22
|
+
handleClose();
|
|
23
|
+
onClick();
|
|
24
|
+
}, children: text }, index))) })] })] }));
|
|
25
|
+
}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { Markdown } from 'tiptap-markdown';
|
|
3
|
+
import StarterKit from "@tiptap/starter-kit";
|
|
4
|
+
import { PiCodeBlock } from "react-icons/pi";
|
|
5
|
+
import { TbBlockquote } from "react-icons/tb";
|
|
6
|
+
import { GoListOrdered } from "react-icons/go";
|
|
7
|
+
import { AiOutlineUnorderedList } from "react-icons/ai";
|
|
8
|
+
import { EditorProvider, useCurrentEditor } from "@tiptap/react";
|
|
9
|
+
import { LuHeading1, LuHeading2, LuHeading3 } from "react-icons/lu";
|
|
10
|
+
import { FaBold, FaCode, FaItalic, FaParagraph, FaStrikethrough } from "react-icons/fa";
|
|
11
|
+
const EditorButton = ({ action, isActive, label, disabled }) => {
|
|
12
|
+
const { editor } = useCurrentEditor();
|
|
13
|
+
if (!editor) {
|
|
14
|
+
return null;
|
|
15
|
+
}
|
|
16
|
+
if (action.includes("heading")) {
|
|
17
|
+
const level = parseInt(action[action.length - 1]);
|
|
18
|
+
return (_jsx("button", { onClick: () => editor.chain().focus().toggleHeading({ level: level }).run(), className: `pl-2 ${isActive ? "is-active" : ""}`, children: label }));
|
|
19
|
+
}
|
|
20
|
+
return (_jsx("button", { onClick: () => editor.chain().focus()[action]().run(), disabled: disabled ? !editor.can().chain().focus()[action]().run() : false, className: `pl-2 ${isActive ? "is-active" : ""}`, children: label }));
|
|
21
|
+
};
|
|
22
|
+
const MenuBar = () => {
|
|
23
|
+
const { editor } = useCurrentEditor();
|
|
24
|
+
if (!editor) {
|
|
25
|
+
return null;
|
|
26
|
+
}
|
|
27
|
+
return (_jsxs("div", { className: "bg-gray-400 dark:bg-gray-800 dark:text-white text-lg flex flex-row flex-wrap items-center p-1", children: [_jsx(EditorButton, { action: "toggleBold", isActive: editor.isActive("bold"), label: _jsx(FaBold, {}), disabled: true }), _jsx(EditorButton, { action: "toggleItalic", isActive: editor.isActive("italic"), label: _jsx(FaItalic, {}), disabled: true }), _jsx(EditorButton, { action: "toggleStrike", isActive: editor.isActive("strike"), label: _jsx(FaStrikethrough, {}), disabled: true }), _jsx(EditorButton, { action: "toggleCode", isActive: editor.isActive("code"), label: _jsx(FaCode, {}), disabled: true }), _jsx(EditorButton, { action: "setParagraph", isActive: editor.isActive("paragraph"), label: _jsx(FaParagraph, {}) }), _jsx(EditorButton, { action: 'setHeading1', isActive: editor.isActive("heading", { level: 1 }), label: _jsx(LuHeading1, { size: "24px" }) }), _jsx(EditorButton, { action: 'setHeading2', isActive: editor.isActive("heading", { level: 2 }), label: _jsx(LuHeading2, { size: "24px" }) }), _jsx(EditorButton, { action: 'setHeading3', isActive: editor.isActive("heading", { level: 3 }), label: _jsx(LuHeading3, { size: "24px" }) }), _jsx(EditorButton, { action: "toggleBulletList", isActive: editor.isActive("bulletList"), label: _jsx(AiOutlineUnorderedList, { size: "24px" }) }), _jsx(EditorButton, { action: "toggleOrderedList", isActive: editor.isActive("orderedList"), label: _jsx(GoListOrdered, { size: "24px" }) }), _jsx(EditorButton, { action: "toggleCodeBlock", isActive: editor.isActive("codeBlock"), label: _jsx(PiCodeBlock, { size: "24px" }) }), _jsx(EditorButton, { action: "toggleBlockquote", isActive: editor.isActive("blockquote"), label: _jsx(TbBlockquote, { size: "24px" }) })] }));
|
|
28
|
+
};
|
|
29
|
+
const extensions = [
|
|
30
|
+
StarterKit.configure({
|
|
31
|
+
bulletList: {
|
|
32
|
+
keepMarks: true,
|
|
33
|
+
keepAttributes: false,
|
|
34
|
+
},
|
|
35
|
+
orderedList: {
|
|
36
|
+
keepMarks: true,
|
|
37
|
+
keepAttributes: false,
|
|
38
|
+
},
|
|
39
|
+
}),
|
|
40
|
+
Markdown,
|
|
41
|
+
];
|
|
42
|
+
export const MarkdownEditor = (props) => {
|
|
43
|
+
return (_jsx("div", { className: "text-md border border-gray-800 overflow-hidden " + props.className, style: { borderWidth: props.editable ? 1 : 0 }, children: _jsx(EditorProvider, { slotBefore: props.editable ? _jsx(MenuBar, {}) : null, extensions: extensions, content: props.content, editable: props.editable, onUpdate: (e) => {
|
|
44
|
+
props.onUpdate && props.onUpdate(e.editor.storage.markdown.getMarkdown());
|
|
45
|
+
} }, (props.editable ? "editable" : "readonly") + props.content) }));
|
|
46
|
+
};
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
const Spinner = ({ text, className, size = "30px" }) => {
|
|
3
|
+
return (_jsxs("div", { className: "flex items-center space-x-2 " + className, children: [_jsxs("svg", { style: { width: size, height: size }, className: "animate-spin -ml-1 mr-3 h-5 w-5 text-white", xmlns: "http://www.w3.org/2000/svg", fill: "none", viewBox: "0 0 24 24", children: [_jsx("circle", { className: "opacity-25", cx: "12", cy: "12", r: "10", stroke: "currentColor", strokeWidth: "4" }), _jsx("path", { className: "opacity-75", fill: "currentColor", d: "M4 12a8 8 0 018-8V0C5.373 0 0 5.373 0 12h4zm2 5.291A7.962 7.962 0 014 12H0c0 3.042 1.135 5.824 3 7.938l3-2.647z" })] }), text && _jsx("span", { className: "", children: text })] }));
|
|
4
|
+
};
|
|
5
|
+
export default Spinner;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
type AudioPlayerProps = {
|
|
3
|
+
text: string;
|
|
4
|
+
voice?: string;
|
|
5
|
+
language?: string;
|
|
6
|
+
hide?: boolean;
|
|
7
|
+
playOnMount?: boolean;
|
|
8
|
+
initialSpeed?: number;
|
|
9
|
+
enableSpeedAdjustment?: boolean;
|
|
10
|
+
playListenerEvent?: string;
|
|
11
|
+
};
|
|
12
|
+
export declare const AudioPlayOptions: number[];
|
|
13
|
+
export type AudioPlayOptionType = 0.8 | 0.9 | 1.0 | 1.1 | 1.2 | 1.5;
|
|
14
|
+
export declare const AudioPlayer: React.FC<AudioPlayerProps>;
|
|
15
|
+
export {};
|
|
@@ -0,0 +1,78 @@
|
|
|
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 "../../providers/PluginProvider";
|
|
14
|
+
import Spinner from '../Spinner';
|
|
15
|
+
import { EmitterSingleton } from '../../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, hide, 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
|
+
useEffect(() => {
|
|
31
|
+
audioUrl && setAudioUrl(null);
|
|
32
|
+
return () => {
|
|
33
|
+
audioUrl && URL.revokeObjectURL(audioUrl);
|
|
34
|
+
};
|
|
35
|
+
}, [text]);
|
|
36
|
+
// Function to generate audio from text using API
|
|
37
|
+
const generateAudio = () => __awaiter(void 0, void 0, void 0, function* () {
|
|
38
|
+
setIsLoading(true);
|
|
39
|
+
const blob = yield getVoiceResponse(text, voice || (language ? "aws_default" : "openai_alloy"), 1, language);
|
|
40
|
+
setAudioUrl(URL.createObjectURL(blob));
|
|
41
|
+
setIsLoading(false);
|
|
42
|
+
});
|
|
43
|
+
// Effect to play audio when audioUrl changes and play state is true
|
|
44
|
+
useEffect(() => {
|
|
45
|
+
if (!audioUrl || !isPlaying)
|
|
46
|
+
return;
|
|
47
|
+
const audio = new Audio(audioUrl);
|
|
48
|
+
audio.playbackRate = speed;
|
|
49
|
+
audio.play().then(() => {
|
|
50
|
+
audio.onended = () => {
|
|
51
|
+
setIsPlaying(false);
|
|
52
|
+
isFetchingAudio = false;
|
|
53
|
+
};
|
|
54
|
+
}).catch(e => {
|
|
55
|
+
console.warn("Error playing audio:", e);
|
|
56
|
+
setIsPlaying(false);
|
|
57
|
+
});
|
|
58
|
+
return () => {
|
|
59
|
+
audio.pause();
|
|
60
|
+
};
|
|
61
|
+
}, [audioUrl, isPlaying, speed]);
|
|
62
|
+
const togglePlayback = () => {
|
|
63
|
+
if (!isPlaying && !audioUrl) {
|
|
64
|
+
generateAudio().then(() => setIsPlaying(true));
|
|
65
|
+
}
|
|
66
|
+
else {
|
|
67
|
+
setIsPlaying((prev) => !prev);
|
|
68
|
+
}
|
|
69
|
+
};
|
|
70
|
+
useEffect(() => {
|
|
71
|
+
if (!playOnMount || isFetchingAudio)
|
|
72
|
+
return;
|
|
73
|
+
isFetchingAudio = true;
|
|
74
|
+
// console.log("playOnMount", playOnMount);
|
|
75
|
+
togglePlayback();
|
|
76
|
+
}, [playOnMount]);
|
|
77
|
+
return (_jsx("div", { className: "group relative", children: _jsxs("div", { className: 'flex flex-row items-end', children: [!hide && _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))) })] }))] }) }));
|
|
78
|
+
};
|
|
@@ -0,0 +1,15 @@
|
|
|
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
|
+
};
|
|
@@ -0,0 +1,21 @@
|
|
|
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
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
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>;
|
|
@@ -0,0 +1,68 @@
|
|
|
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
|
+
}
|
|
@@ -0,0 +1,34 @@
|
|
|
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 {};
|