[feat] added character api to plugin

This commit is contained in:
kwaroran
2023-05-07 22:16:16 +09:00
parent 10863cee51
commit 2d1fb23fc8
2 changed files with 50 additions and 1 deletions

View File

@@ -24,6 +24,24 @@
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()}`
@@ -89,6 +107,18 @@
body: data
})
}
function getChar(){
return transferDataAsync('getChar', '')
}
function setChar(char:any){
postMessage({
type: 'setChar',
body: char
})
}
async function handleOnmessage(data:{type:string,body:any}) {
if(!data.type){
@@ -143,5 +173,9 @@
const data:{type:string,body:any} = ev.data
}
//{{placeholder}}
{
const __risuPlugin__ = null
const transferDataAsync = null
//{{placeholder}}
}
})()

View File

@@ -5,6 +5,7 @@ import { DataBase } from "../database";
import { checkNullish, selectSingleFile, sleep } from "../util";
import type { OpenAIChat } from ".";
import { globalFetch } from "../globalApi";
import { selectedCharID } from "../stores";
export const customProviderStore = writable([] as string[])
@@ -229,6 +230,20 @@ export async function loadPlugins() {
}
break
}
case "getChar":{
const db = get(DataBase)
const charid = get(selectedCharID)
const char = db.characters[charid]
postMsgPluginWorker('fetchData',{
id: data.body.id,
data: char
})
}
case "setChar":{
const db = get(DataBase)
const charid = get(selectedCharID)
db.characters[charid] = data.body
}
case "log":{
console.log(data.body)
break