diff --git a/public/pluginApi.js b/public/pluginApi.js
deleted file mode 100644
index 1c62fd59..00000000
--- a/public/pluginApi.js
+++ /dev/null
@@ -1,264 +0,0 @@
-var __assign = (this && this.__assign) || function () {
- __assign = Object.assign || function(t) {
- for (var s, i = 1, n = arguments.length; i < n; i++) {
- s = arguments[i];
- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
- t[p] = s[p];
- }
- return t;
- };
- return __assign.apply(this, arguments);
-};
-var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
- return new (P || (P = Promise))(function (resolve, reject) {
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
- step((generator = generator.apply(thisArg, _arguments || [])).next());
- });
-};
-var __generator = (this && this.__generator) || function (thisArg, body) {
- var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
- return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
- function verb(n) { return function (v) { return step([n, v]); }; }
- function step(op) {
- if (f) throw new TypeError("Generator is already executing.");
- while (g && (g = 0, op[0] && (_ = 0)), _) try {
- if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
- if (y = 0, t) op = [op[0] & 2, t.value];
- switch (op[0]) {
- case 0: case 1: t = op; break;
- case 4: _.label++; return { value: op[1], done: false };
- case 5: _.label++; y = op[1]; op = [0]; continue;
- case 7: op = _.ops.pop(); _.trys.pop(); continue;
- default:
- if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
- if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
- if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
- if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
- if (t[2]) _.ops.pop();
- _.trys.pop(); continue;
- }
- op = body.call(thisArg, _);
- } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
- if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
- }
-};
-(function () {
- var __risuPlugin__ = {
- providers: [],
- fetchResponseQueue: []
- };
- var sleep = function (ms) { return new Promise(function (r) { return setTimeout(r, ms); }); };
- function transferDataAsync(type, body) {
- return __awaiter(this, void 0, void 0, function () {
- var id, i, q;
- return __generator(this, function (_a) {
- switch (_a.label) {
- case 0:
- id = "".concat(Date.now(), "_").concat(Math.random());
- postMessage({
- type: 'fetch',
- body: __assign({ id: id }, body)
- });
- _a.label = 1;
- case 1:
- if (!true) return [3 /*break*/, 3];
- return [4 /*yield*/, sleep(50)];
- case 2:
- _a.sent();
- for (i = 0; i < __risuPlugin__.fetchResponseQueue.length; i++) {
- q = __risuPlugin__.fetchResponseQueue[i];
- if (q.id === id) {
- __risuPlugin__.fetchResponseQueue.splice(i, 1);
- return [2 /*return*/, q.data];
- }
- }
- return [3 /*break*/, 1];
- case 3: return [2 /*return*/];
- }
- });
- });
- }
- function risuFetch(url, arg) {
- return __awaiter(this, void 0, void 0, function () {
- var id, i, q;
- return __generator(this, function (_a) {
- switch (_a.label) {
- case 0:
- id = "".concat(Date.now(), "_").concat(Math.random());
- postMessage({
- type: 'fetch',
- body: {
- id: id,
- url: url,
- arg: arg
- }
- });
- _a.label = 1;
- case 1:
- if (!true) return [3 /*break*/, 3];
- return [4 /*yield*/, sleep(50)];
- case 2:
- _a.sent();
- for (i = 0; i < __risuPlugin__.fetchResponseQueue.length; i++) {
- q = __risuPlugin__.fetchResponseQueue[i];
- if (q.id === id) {
- __risuPlugin__.fetchResponseQueue.splice(i, 1);
- return [2 /*return*/, q.data];
- }
- }
- return [3 /*break*/, 1];
- case 3: return [2 /*return*/];
- }
- });
- });
- }
- function getArg(arg) {
- return __awaiter(this, void 0, void 0, function () {
- var id, i, q;
- return __generator(this, function (_a) {
- switch (_a.label) {
- case 0:
- id = "".concat(Date.now(), "_").concat(Math.random());
- postMessage({
- type: 'getArg',
- body: {
- id: id,
- arg: arg
- }
- });
- _a.label = 1;
- case 1:
- if (!true) return [3 /*break*/, 3];
- return [4 /*yield*/, sleep(50)];
- case 2:
- _a.sent();
- for (i = 0; i < __risuPlugin__.fetchResponseQueue.length; i++) {
- q = __risuPlugin__.fetchResponseQueue[i];
- if (q.id === id) {
- __risuPlugin__.fetchResponseQueue.splice(i, 1);
- return [2 /*return*/, q.data];
- }
- }
- return [3 /*break*/, 1];
- case 3: return [2 /*return*/];
- }
- });
- });
- }
- function addProvider(name, func) {
- postMessage({
- type: 'addProvider',
- body: name
- });
- __risuPlugin__.providers.push({
- name: name,
- func: func
- });
- }
- function printLog(data) {
- postMessage({
- type: 'log',
- body: data
- });
- }
- function getChar() {
- return transferDataAsync('getChar', '');
- }
- function setChar(char) {
- postMessage({
- type: 'setChar',
- body: char
- });
- }
- function addCharaJs(code, position) {
- if (position === void 0) { position = 'back'; }
- var codeString = code.toString().replace(/.+?\{/, '{');
- postMessage({
- type: 'addCharaJs',
- body: {
- code: codeString,
- position: position
- }
- });
- }
- function handleOnmessage(data) {
- return __awaiter(this, void 0, void 0, function () {
- var _a, body, providers, providerfunc, _i, providers_1, provider, _b, error_1;
- var _c;
- return __generator(this, function (_d) {
- switch (_d.label) {
- case 0:
- if (!data.type) {
- return [2 /*return*/];
- }
- _a = data.type;
- switch (_a) {
- case "requestProvider": return [3 /*break*/, 1];
- case "fetchData": return [3 /*break*/, 6];
- }
- return [3 /*break*/, 7];
- case 1:
- body = data.body;
- providers = __risuPlugin__.providers;
- providerfunc = null;
- for (_i = 0, providers_1 = providers; _i < providers_1.length; _i++) {
- provider = providers_1[_i];
- if (provider.name === body.key) {
- providerfunc = provider.func;
- }
- }
- if (!!providerfunc) return [3 /*break*/, 2];
- postMessage({
- type: 'resProvider',
- body: {
- 'success': false,
- 'content': 'unknown provider'
- }
- });
- return [3 /*break*/, 5];
- case 2:
- _d.trys.push([2, 4, , 5]);
- _b = postMessage;
- _c = {
- type: 'resProvider'
- };
- return [4 /*yield*/, providerfunc(body.arg)];
- case 3:
- _b.apply(void 0, [(_c.body = _d.sent(),
- _c)]);
- return [3 /*break*/, 5];
- case 4:
- error_1 = _d.sent();
- postMessage({
- type: 'resProvider',
- body: {
- 'success': false,
- 'content': "providerError: ".concat(error_1)
- }
- });
- return [3 /*break*/, 5];
- case 5: return [3 /*break*/, 7];
- case 6:
- {
- __risuPlugin__.fetchResponseQueue.push(data.body);
- return [3 /*break*/, 7];
- }
- _d.label = 7;
- case 7: return [2 /*return*/];
- }
- });
- });
- }
- onmessage = function (ev) {
- handleOnmessage(ev.data);
- var data = ev.data;
- };
- {
- var __risuPlugin__1 = null;
- var transferDataAsync_1 = null;
- //{{placeholder}}
- }
-})();
diff --git a/public/pluginApi.ts b/public/pluginApi.ts
deleted file mode 100644
index d2cd05c0..00000000
--- a/public/pluginApi.ts
+++ /dev/null
@@ -1,192 +0,0 @@
-(() => {
- interface risuPlugin{
- providers: {name:string, func:(arg:providerArgument) => Promise<{success:boolean,content:string}>}[]
- fetchResponseQueue:{id:string,data:any}[]
- }
-
- let __risuPlugin__:risuPlugin = {
- providers: [],
- fetchResponseQueue: []
- }
-
- const sleep = (ms: number) => new Promise((r) => setTimeout(r, ms));
-
- interface OpenAIChat{
- role: 'system'|'user'|'assistant'
- content: string
- }
-
- interface providerArgument{
- prompt_chat?: OpenAIChat,
- temperature?: number,
- max_tokens?: number,
- presence_penalty?: number
- frequency_penalty?: number
- bias?: {[key:string]:string}
- }
-
- async function transferDataAsync(type:string,body:any) {
- const id = `${Date.now()}_${Math.random()}`
- postMessage({
- type: 'fetch',
- body: {id: id, ...body}
- })
- while(true){
- await sleep(50)
- for(let i=0;i<__risuPlugin__.fetchResponseQueue.length;i++){
- const q = __risuPlugin__.fetchResponseQueue[i]
- if(q.id === id){
- __risuPlugin__.fetchResponseQueue.splice(i, 1)
- return q.data
- }
- }
- }
- }
-
- async function risuFetch(url:string, arg:{body:any,headers?:{[key:string]:string}}){
- const id = `${Date.now()}_${Math.random()}`
- postMessage({
- type: 'fetch',
- body: {
- id: id,
- url: url,
- arg: arg
- }
- })
- while(true){
- await sleep(50)
- for(let i=0;i<__risuPlugin__.fetchResponseQueue.length;i++){
- const q = __risuPlugin__.fetchResponseQueue[i]
- if(q.id === id){
-
- __risuPlugin__.fetchResponseQueue.splice(i, 1)
- return q.data as {
- ok: boolean;
- data: any;
- }
- }
- }
- }
- }
-
- async function getArg(arg:string){
- const id = `${Date.now()}_${Math.random()}`
- postMessage({
- type: 'getArg',
- body: {
- id: id,
- arg: arg
- }
- })
- while(true){
- await sleep(50)
- for(let i=0;i<__risuPlugin__.fetchResponseQueue.length;i++){
- const q = __risuPlugin__.fetchResponseQueue[i]
- if(q.id === id){
- __risuPlugin__.fetchResponseQueue.splice(i, 1)
- return q.data as (string|number|null)
- }
- }
- }
- }
-
- function addProvider(name:string, func:(arg:providerArgument) => Promise<{success:boolean,content:string}>){
- postMessage({
- type: 'addProvider',
- body: name
- })
- __risuPlugin__.providers.push({
- name: name,
- func: func
- })
- }
-
- function printLog(data:any){
- postMessage({
- type: 'log',
- body: data
- })
- }
-
-
- function getChar(){
- return transferDataAsync('getChar', '')
- }
-
- function setChar(char:any){
- postMessage({
- type: 'setChar',
- body: char
- })
- }
-
- function addCharaJs(code:Function, position:'front'|'back' = 'back'){
- const codeString = code.toString().replace(/.+?\{/, '{')
- postMessage({
- type: 'addCharaJs',
- body: {
- code: codeString,
- position: position
- }
- })
- }
-
- async function handleOnmessage(data:{type:string,body:any}) {
- if(!data.type){
- return
- }
- switch(data.type){
- case "requestProvider":{
- const body:{key:string,arg:providerArgument} = data.body
- const providers = __risuPlugin__.providers
- let providerfunc:((arg:providerArgument) => Promise<{success:boolean,content:string}>)|null= null
- for(const provider of providers){
- if(provider.name === body.key){
- providerfunc = provider.func
- }
- }
- if(!providerfunc){
- postMessage({
- type: 'resProvider',
- body: {
- 'success': false,
- 'content': 'unknown provider'
- }
- })
- }
- else{
- try {
- postMessage({
- type: 'resProvider',
- body: await providerfunc(body.arg)
- })
- } catch (error) {
- postMessage({
- type: 'resProvider',
- body: {
- 'success': false,
- 'content': `providerError: ${error}`
- }
- })
- }
- }
- break
- }
- case "fetchData":{
- __risuPlugin__.fetchResponseQueue.push(data.body)
- break
- }
- }
- }
-
- onmessage = (ev) => {
- handleOnmessage(ev.data)
- const data:{type:string,body:any} = ev.data
- }
-
- {
- const __risuPlugin__ = null
- const transferDataAsync = null
- //{{placeholder}}
- }
-})()
\ No newline at end of file
diff --git a/src/etc/example-char.js b/src/etc/example-char.js
deleted file mode 100644
index a73971fb..00000000
--- a/src/etc/example-char.js
+++ /dev/null
@@ -1,115 +0,0 @@
-//The @use comment tells the program what callable functions exist. If you omit this, the function will not be called.
-
-//@use editInput
-//@use editOutput
-//@use editProcess
-//@use editDisplay
-//@use onButtonClick
-//@use modifyRequestChat
-
-
-async function editInput(text){
- //editInput is a callable function that is called when the user inputs text into the input box.
- //the first argument is the text that the user input.
- //the text would replaced to return value, which would change the real value.
- return text;
-}
-
-async function editOutput(text){
- //editOutput is a callable function that is called when bot outputs text.
- //the first argument is the text that the bot outputs.
- //the text would replaced to return value, which would change the real value.
- return text;
-}
-
-async function editProcess(text){
- //editOutput is a callable function that is called when before request.
- //the first argument is the original text.
- //the text would replaced to return value and used in request, but it would not change the real value.
- return text;
-}
-
-async function editDisplay(text){
- //editDisplay is a callable function that is called when before display.
- //the first argument is the original text.
- //the text would replaced to return value and be displayed, but it would not change the real value.
- return text
-}
-
-async function onButtonClick(code){
- //onButtonClick is a callable function that is called when the user clicks the button.
- //a button is a html element that has the attribute "risu-btn".
- //the first argument is the code of the button.
- //example: uses "example-char" as the code.
- //return value is not used.
- return
-}
-
-async function modifyRequestChat(chat){
- //modifyRequestChat is a callable function that is called when before request.
- //the first argument is the chat array. chat array is almost same as OpenAI's chat array.
- //unlike editProcess, its called after other fixes is done, and its only called once, with the whole chat array.
- //the chat array would replaced to return value and used in request.
- return chat
-}
-
-
-async function showcase(){
- //this is a function for just introducing the apis.
-
-
- //getChat() returns the chat object.
- const chat = await getChat()
-
- //setChat(chat) sets the chat object.
- //must be a valid chat object.
- //returns true if success, false if failed.
- await setChat(chat)
-
- //getName() returns the name of the character.
- const name = await getName()
-
- //setName(name) sets the name of the character.
- //must be a valid string.
- //returns true if success, false if failed.
- await setName(name)
-
- //getDescription() returns the description of the character.
- const description = await getDescription()
-
- //setDescription(description) sets the description of the character.
- //must be a valid string.
- //returns true if success, false if failed.
- await setDescription(description)
-
- //getCharacterFirstMessage() returns the first message of the character.
- const firstMessage = await getCharacterFirstMessage()
-
- //setCharacterFirstMessage(firstMessage) sets the first message of the character.
- //must be a valid string.
- //returns true if success, false if failed.
- await setCharacterFirstMessage(firstMessage)
-
-
-
- //setState(stateName, data) sets the states of the character.
- //states are used to store data, because the data would be lost every time when function is called.
- //if data is string, it must be less or equal to 100000 characters.
- //stateName must be a valid string.
- //data must be a valid string, number or boolean.
- //returns true if success, false if failed.
- await setState("somedata", "data")
- await setState("anotherdata", 123)
-
- //getState(stateName) returns the state of the character.
- //stateName must be a valid string.
- //returns the data if success, null if failed.
- const data = await getState("somedata")
- const anotherdata = await getState("anotherdata")
-}
-
-
-// --- additional notes
-// the code are parsed everytime, so complex codes would slow down the program.
-// the function must be return in 400ms, or it would be timeout.
-// for security reasons, you can only access limited apis.
\ No newline at end of file
diff --git a/src/lang/en.ts b/src/lang/en.ts
index 7cb213a7..3dca20d2 100644
--- a/src/lang/en.ts
+++ b/src/lang/en.ts
@@ -834,4 +834,5 @@ export const languageEnglish = {
menuSideBar: "Menu Side Bar",
home: "Home",
showSavingIcon: "Show Saving Icon",
+ pluginVersionWarn: "This is {{plugin_version}} version of the plugin. which is not compatible with this version of RisuAI. please update the plugin to {{required_version}} version.",
}
\ No newline at end of file
diff --git a/src/lib/Setting/Pages/PluginSettings.svelte b/src/lib/Setting/Pages/PluginSettings.svelte
index 24565fc2..b064c0ac 100644
--- a/src/lib/Setting/Pages/PluginSettings.svelte
+++ b/src/lib/Setting/Pages/PluginSettings.svelte
@@ -38,7 +38,11 @@