[feat] added character api to plugin
This commit is contained in:
@@ -24,6 +24,24 @@
|
|||||||
frequency_penalty?: number
|
frequency_penalty?: number
|
||||||
bias?: {[key:string]:string}
|
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}}){
|
async function risuFetch(url:string, arg:{body:any,headers?:{[key:string]:string}}){
|
||||||
const id = `${Date.now()}_${Math.random()}`
|
const id = `${Date.now()}_${Math.random()}`
|
||||||
@@ -89,6 +107,18 @@
|
|||||||
body: data
|
body: data
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
function getChar(){
|
||||||
|
return transferDataAsync('getChar', '')
|
||||||
|
}
|
||||||
|
|
||||||
|
function setChar(char:any){
|
||||||
|
postMessage({
|
||||||
|
type: 'setChar',
|
||||||
|
body: char
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
async function handleOnmessage(data:{type:string,body:any}) {
|
async function handleOnmessage(data:{type:string,body:any}) {
|
||||||
if(!data.type){
|
if(!data.type){
|
||||||
@@ -143,5 +173,9 @@
|
|||||||
const data:{type:string,body:any} = ev.data
|
const data:{type:string,body:any} = ev.data
|
||||||
}
|
}
|
||||||
|
|
||||||
//{{placeholder}}
|
{
|
||||||
|
const __risuPlugin__ = null
|
||||||
|
const transferDataAsync = null
|
||||||
|
//{{placeholder}}
|
||||||
|
}
|
||||||
})()
|
})()
|
||||||
@@ -5,6 +5,7 @@ import { DataBase } from "../database";
|
|||||||
import { checkNullish, selectSingleFile, sleep } from "../util";
|
import { checkNullish, selectSingleFile, sleep } from "../util";
|
||||||
import type { OpenAIChat } from ".";
|
import type { OpenAIChat } from ".";
|
||||||
import { globalFetch } from "../globalApi";
|
import { globalFetch } from "../globalApi";
|
||||||
|
import { selectedCharID } from "../stores";
|
||||||
|
|
||||||
export const customProviderStore = writable([] as string[])
|
export const customProviderStore = writable([] as string[])
|
||||||
|
|
||||||
@@ -229,6 +230,20 @@ export async function loadPlugins() {
|
|||||||
}
|
}
|
||||||
break
|
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":{
|
case "log":{
|
||||||
console.log(data.body)
|
console.log(data.body)
|
||||||
break
|
break
|
||||||
|
|||||||
Reference in New Issue
Block a user