Merge branch 'main' of https://github.com/kwaroran/RisuAI
This commit is contained in:
@@ -50,6 +50,9 @@
|
||||
},
|
||||
{
|
||||
"url": "http://*/**/*"
|
||||
},
|
||||
{
|
||||
"url": "http://*:**"
|
||||
}
|
||||
]
|
||||
},
|
||||
|
||||
@@ -1 +1 @@
|
||||
{"desktop-capability":{"identifier":"desktop-capability","description":"","local":true,"permissions":["updater:default","process:default","shell:default","http:default","deep-link:default"],"platforms":["macOS","windows","linux"]},"migrated":{"identifier":"migrated","description":"permissions that were migrated from v1","local":true,"windows":["main"],"permissions":["core:default","fs:allow-read-file","fs:allow-write-file","fs:allow-read-dir","fs:allow-copy-file","fs:allow-mkdir","fs:allow-remove","fs:allow-remove","fs:allow-rename","fs:allow-exists",{"identifier":"fs:scope","allow":["$APPDATA","$APPDATA/*","$APPDATA/**/*","$DOWNLOAD/*","/data/**/*","$RESOURCE/*"]},"core:window:allow-maximize","core:window:allow-set-fullscreen","shell:allow-open","dialog:allow-open","dialog:allow-save","dialog:allow-message","dialog:allow-ask","dialog:allow-confirm","updater:default",{"identifier":"http:default","allow":[{"url":"https://*/*"},{"url":"https://*/**/*"},{"url":"http://*/*"},{"url":"http://*/**/*"}]},"os:allow-platform","os:allow-version","os:allow-os-type","os:allow-family","os:allow-arch","os:allow-exe-extension","os:allow-locale","os:allow-hostname","process:allow-restart","core:app:allow-app-show","core:app:allow-app-hide","fs:default","os:default","dialog:default","process:default","shell:default","http:default","deep-link:default"]}}
|
||||
{"desktop-capability":{"identifier":"desktop-capability","description":"","local":true,"permissions":["updater:default","process:default","shell:default","http:default","deep-link:default"],"platforms":["macOS","windows","linux"]},"migrated":{"identifier":"migrated","description":"permissions that were migrated from v1","local":true,"windows":["main"],"permissions":["core:default","fs:allow-read-file","fs:allow-write-file","fs:allow-read-dir","fs:allow-copy-file","fs:allow-mkdir","fs:allow-remove","fs:allow-remove","fs:allow-rename","fs:allow-exists",{"identifier":"fs:scope","allow":["$APPDATA","$APPDATA/*","$APPDATA/**/*","$DOWNLOAD/*","/data/**/*","$RESOURCE/*"]},"core:window:allow-maximize","core:window:allow-set-fullscreen","shell:allow-open","dialog:allow-open","dialog:allow-save","dialog:allow-message","dialog:allow-ask","dialog:allow-confirm","updater:default",{"identifier":"http:default","allow":[{"url":"https://*/*"},{"url":"https://*/**/*"},{"url":"http://*/*"},{"url":"http://*/**/*"},{"url":"http://*:**"}]},"os:allow-platform","os:allow-version","os:allow-os-type","os:allow-family","os:allow-arch","os:allow-exe-extension","os:allow-locale","os:allow-hostname","process:allow-restart","core:app:allow-app-show","core:app:allow-app-hide","fs:default","os:default","dialog:default","process:default","shell:default","http:default","deep-link:default"]}}
|
||||
@@ -805,7 +805,7 @@
|
||||
{/if}
|
||||
|
||||
{#if DBState.db.showMenuHypaMemoryModal}
|
||||
{#if DBState.db.supaModelType !== 'none' && (DBState.db.hypav2 || DBState.db.hypaV3)}
|
||||
{#if (DBState.db.supaModelType !== 'none' && DBState.db.hypav2) || DBState.db.hypaV3}
|
||||
<div class="flex items-center cursor-pointer hover:text-green-500 transition-colors" onclick={() => {
|
||||
if (DBState.db.hypav2) {
|
||||
DBState.db.characters[$selectedCharID].chats[DBState.db.characters[$selectedCharID].chatPage].hypaV2Data ??= {
|
||||
|
||||
@@ -96,11 +96,13 @@
|
||||
<h2 class="text-green-700 mt-0 mb-2 w-40 max-w-full">Input</h2>
|
||||
{/if}
|
||||
{#if $alertStore.type === 'markdown'}
|
||||
<span class="text-gray-300 chattext prose chattext2" class:prose-invert={$ColorSchemeTypeStore}>
|
||||
{#await ParseMarkdown($alertStore.msg) then msg}
|
||||
{@html msg}
|
||||
{/await}
|
||||
</span>
|
||||
<div class="overflow-y-auto">
|
||||
<span class="text-gray-300 chattext prose chattext2" class:prose-invert={$ColorSchemeTypeStore}>
|
||||
{#await ParseMarkdown($alertStore.msg) then msg}
|
||||
{@html msg}
|
||||
{/await}
|
||||
</span>
|
||||
</div>
|
||||
{:else if $alertStore.type === 'tos'}
|
||||
<!-- svelte-ignore a11y_missing_attribute -->
|
||||
<!-- svelte-ignore a11y_click_events_have_key_events -->
|
||||
|
||||
@@ -26,14 +26,18 @@ export const alertStore = {
|
||||
}
|
||||
}
|
||||
|
||||
export function alertError(msg:string){
|
||||
export function alertError(msg: string | Error) {
|
||||
console.error(msg)
|
||||
const db = getDatabase()
|
||||
|
||||
if(typeof(msg) !== 'string'){
|
||||
if (typeof(msg) !== 'string') {
|
||||
try{
|
||||
msg = JSON.stringify(msg)
|
||||
}catch(e){
|
||||
if (msg instanceof Error) {
|
||||
msg = msg.message
|
||||
} else {
|
||||
msg = JSON.stringify(msg)
|
||||
}
|
||||
} catch {
|
||||
msg = `${msg}`
|
||||
}
|
||||
}
|
||||
|
||||
@@ -400,15 +400,13 @@ export async function sendChat(chatProcessIndex = -1,arg:{
|
||||
if(currentChat.note){
|
||||
unformated.authorNote.push({
|
||||
role: 'system',
|
||||
content: risuChatParser(currentChat.note, {chara: currentChar}),
|
||||
memo: 'authornote'
|
||||
content: risuChatParser(currentChat.note, {chara: currentChar})
|
||||
})
|
||||
}
|
||||
else if(getAuthorNoteDefaultText() !== ''){
|
||||
unformated.authorNote.push({
|
||||
role: 'system',
|
||||
content: risuChatParser(getAuthorNoteDefaultText(), {chara: currentChar}),
|
||||
memo: 'authornote'
|
||||
content: risuChatParser(getAuthorNoteDefaultText(), {chara: currentChar})
|
||||
})
|
||||
}
|
||||
|
||||
@@ -438,8 +436,7 @@ export async function sendChat(chatProcessIndex = -1,arg:{
|
||||
|
||||
unformated.description.push({
|
||||
role: 'system',
|
||||
content: description,
|
||||
memo: 'description',
|
||||
content: description
|
||||
})
|
||||
|
||||
if(nowChatroom.type === 'group'){
|
||||
@@ -460,8 +457,7 @@ export async function sendChat(chatProcessIndex = -1,arg:{
|
||||
for(const lorebook of normalActives){
|
||||
unformated.lorebook.push({
|
||||
role: lorebook.role,
|
||||
content: risuChatParser(lorebook.prompt, {chara: currentChar}),
|
||||
memo: 'lore',
|
||||
content: risuChatParser(lorebook.prompt, {chara: currentChar})
|
||||
})
|
||||
}
|
||||
|
||||
@@ -485,8 +481,7 @@ export async function sendChat(chatProcessIndex = -1,arg:{
|
||||
if(DBState.db.personaPrompt){
|
||||
unformated.personaPrompt.push({
|
||||
role: 'system',
|
||||
content: risuChatParser(getPersonaPrompt(), {chara: currentChar}),
|
||||
memo: 'persona',
|
||||
content: risuChatParser(getPersonaPrompt(), {chara: currentChar})
|
||||
})
|
||||
}
|
||||
|
||||
@@ -511,8 +506,7 @@ export async function sendChat(chatProcessIndex = -1,arg:{
|
||||
for(const lorebook of postEverythingLorebooks){
|
||||
unformated.postEverything.push({
|
||||
role: lorebook.role,
|
||||
content: risuChatParser(lorebook.prompt, {chara: currentChar}),
|
||||
memo: 'postEverything',
|
||||
content: risuChatParser(lorebook.prompt, {chara: currentChar})
|
||||
})
|
||||
}
|
||||
|
||||
@@ -1100,10 +1094,15 @@ export async function sendChat(chatProcessIndex = -1,arg:{
|
||||
}
|
||||
}
|
||||
|
||||
type MemoType = 'persona' | 'description' | 'authornote' | 'supaMemory';
|
||||
const promptBodyMap: Record<MemoType, string[]> = { persona: [], description: [], authornote: [], supaMemory: [] };
|
||||
function pushPromptInfoBody(memo: MemoType, fmt: string) {
|
||||
promptBodyMap[memo].push(risuChatParser(fmt));
|
||||
let promptBodyformatedForChatStore: OpenAIChat[] = []
|
||||
function pushPromptInfoBody(role: "function" | "system" | "user" | "assistant", fmt: string, promptBody: OpenAIChat[]) {
|
||||
if(!fmt.trim()){
|
||||
return
|
||||
}
|
||||
promptBody.push({
|
||||
role: role,
|
||||
content: risuChatParser(fmt),
|
||||
})
|
||||
}
|
||||
|
||||
if(promptTemplate){
|
||||
@@ -1118,7 +1117,7 @@ export async function sendChat(chatProcessIndex = -1,arg:{
|
||||
pmt[i].content = risuChatParser(positionParser(card.innerFormat), {chara: currentChar}).replace('{{slot}}', pmt[i].content)
|
||||
|
||||
if(DBState.db.promptInfoInsideChat && DBState.db.promptTextInfoInsideChat){
|
||||
pushPromptInfoBody(card.type, card.innerFormat)
|
||||
pushPromptInfoBody(pmt[i].role, card.innerFormat, promptBodyformatedForChatStore)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1133,7 +1132,7 @@ export async function sendChat(chatProcessIndex = -1,arg:{
|
||||
pmt[i].content = risuChatParser(positionParser(card.innerFormat), {chara: currentChar}).replace('{{slot}}', pmt[i].content)
|
||||
|
||||
if(DBState.db.promptInfoInsideChat && DBState.db.promptTextInfoInsideChat){
|
||||
pushPromptInfoBody(card.type, card.innerFormat)
|
||||
pushPromptInfoBody(pmt[i].role, card.innerFormat, promptBodyformatedForChatStore)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1148,7 +1147,7 @@ export async function sendChat(chatProcessIndex = -1,arg:{
|
||||
pmt[i].content = risuChatParser(positionParser(card.innerFormat), {chara: currentChar}).replace('{{slot}}', pmt[i].content || card.defaultText || '')
|
||||
|
||||
if(DBState.db.promptInfoInsideChat && DBState.db.promptTextInfoInsideChat){
|
||||
pushPromptInfoBody(card.type, card.innerFormat)
|
||||
pushPromptInfoBody(pmt[i].role, card.innerFormat, promptBodyformatedForChatStore)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1206,6 +1205,10 @@ export async function sendChat(chatProcessIndex = -1,arg:{
|
||||
content: content
|
||||
}
|
||||
|
||||
if(DBState.db.promptInfoInsideChat && DBState.db.promptTextInfoInsideChat && card.type2 !== 'globalNote'){
|
||||
pushPromptInfoBody(prompt.role, prompt.content, promptBodyformatedForChatStore)
|
||||
}
|
||||
|
||||
pushPrompts([prompt])
|
||||
break
|
||||
}
|
||||
@@ -1267,7 +1270,7 @@ export async function sendChat(chatProcessIndex = -1,arg:{
|
||||
pmt[i].content = risuChatParser(card.innerFormat, {chara: currentChar}).replace('{{slot}}', pmt[i].content)
|
||||
|
||||
if(DBState.db.promptInfoInsideChat && DBState.db.promptTextInfoInsideChat){
|
||||
pushPromptInfoBody('supaMemory', card.innerFormat)
|
||||
pushPromptInfoBody(pmt[i].role, card.innerFormat, promptBodyformatedForChatStore)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1306,6 +1309,13 @@ export async function sendChat(chatProcessIndex = -1,arg:{
|
||||
return v
|
||||
})
|
||||
|
||||
if(DBState.db.promptInfoInsideChat && DBState.db.promptTextInfoInsideChat){
|
||||
promptBodyformatedForChatStore = promptBodyformatedForChatStore.map((v) => {
|
||||
v.content = v.content.trim()
|
||||
return v
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
if(currentChar.depth_prompt && currentChar.depth_prompt.prompt && currentChar.depth_prompt.prompt.length > 0){
|
||||
//depth_prompt
|
||||
@@ -1318,6 +1328,11 @@ export async function sendChat(chatProcessIndex = -1,arg:{
|
||||
|
||||
formated = await runLuaEditTrigger(currentChar, 'editRequest', formated)
|
||||
|
||||
if(DBState.db.promptInfoInsideChat && DBState.db.promptTextInfoInsideChat){
|
||||
promptBodyformatedForChatStore = await runLuaEditTrigger(currentChar, 'editRequest', promptBodyformatedForChatStore)
|
||||
promptInfo.promptText = promptBodyformatedForChatStore
|
||||
}
|
||||
|
||||
//token rechecking
|
||||
let inputTokens = 0
|
||||
|
||||
@@ -1389,29 +1404,6 @@ export async function sendChat(chatProcessIndex = -1,arg:{
|
||||
return true
|
||||
}
|
||||
|
||||
|
||||
function isPromptMemo(m: string): m is MemoType {
|
||||
return ['persona', 'description', 'authornote', 'supaMemory'].includes(m);
|
||||
}
|
||||
if(DBState.db.promptInfoInsideChat && DBState.db.promptTextInfoInsideChat){
|
||||
const promptBodyInfo: OpenAIChat[] = formated.flatMap(format => {
|
||||
if (isPromptMemo(format.memo)) {
|
||||
return promptBodyMap[format.memo].map(content => ({
|
||||
role: format.role,
|
||||
content,
|
||||
}))
|
||||
}
|
||||
|
||||
if (format.memo == null) {
|
||||
return [format]
|
||||
}
|
||||
|
||||
return []
|
||||
})
|
||||
|
||||
promptInfo.promptText = promptBodyInfo
|
||||
}
|
||||
|
||||
let result = ''
|
||||
let emoChanged = false
|
||||
let resendChat = false
|
||||
|
||||
@@ -67,22 +67,16 @@ export async function runLua(code:string, arg:{
|
||||
luaEngineState.code = code
|
||||
luaEngineState.engine = await luaFactory.createEngine({injectObjects: true})
|
||||
const luaEngine = luaEngineState.engine
|
||||
luaEngine.global.set('getChatVar', (id:string,key:string) => {
|
||||
return luaEngineState.getVar(key)
|
||||
})
|
||||
luaEngine.global.set('setChatVar', (id:string,key:string, value:string) => {
|
||||
if(!LuaSafeIds.has(id) && !LuaEditDisplayIds.has(id)){
|
||||
return
|
||||
}
|
||||
luaEngineState.setVar(key, value)
|
||||
})
|
||||
luaEngine.global.set('getChatVar', (id:string,key:string) => {
|
||||
if(!LuaSafeIds.has(id) && !LuaEditDisplayIds.has(id)){
|
||||
return
|
||||
}
|
||||
return luaEngineState.getVar(key)
|
||||
})
|
||||
luaEngine.global.set('getGlobalVar', (id:string, key:string) => {
|
||||
if(!LuaSafeIds.has(id) && !LuaEditDisplayIds.has(id)){
|
||||
return
|
||||
}
|
||||
return getGlobalChatVar(key)
|
||||
})
|
||||
luaEngine.global.set('stopChat', (id:string) => {
|
||||
@@ -166,11 +160,9 @@ export async function runLua(code:string, arg:{
|
||||
return await tokenize(value)
|
||||
})
|
||||
luaEngine.global.set('getChatLength', (id:string) => {
|
||||
if(!LuaSafeIds.has(id)){
|
||||
return
|
||||
}
|
||||
return luaEngineState.chat.message.length
|
||||
})
|
||||
|
||||
luaEngine.global.set('getFullChatMain', (id:string) => {
|
||||
const data = JSON.stringify(luaEngineState.chat.message.map((v) => {
|
||||
return {
|
||||
@@ -183,10 +175,11 @@ export async function runLua(code:string, arg:{
|
||||
})
|
||||
|
||||
luaEngine.global.set('setFullChatMain', (id:string, value:string) => {
|
||||
const realValue = JSON.parse(value)
|
||||
if(!LuaSafeIds.has(id)){
|
||||
return
|
||||
}
|
||||
const realValue = JSON.parse(value)
|
||||
|
||||
luaEngineState.chat.message = realValue.map((v) => {
|
||||
return {
|
||||
role: v.role,
|
||||
@@ -396,9 +389,6 @@ export async function runLua(code:string, arg:{
|
||||
})
|
||||
|
||||
luaEngine.global.set('getName', async (id:string) => {
|
||||
if(!LuaSafeIds.has(id)){
|
||||
return
|
||||
}
|
||||
const db = getDatabase()
|
||||
const selectedChar = get(selectedCharID)
|
||||
const char = db.characters[selectedChar]
|
||||
@@ -418,6 +408,19 @@ export async function runLua(code:string, arg:{
|
||||
setDatabase(db)
|
||||
})
|
||||
|
||||
luaEngine.global.set('getDescription', async (id:string) => {
|
||||
if(!LuaSafeIds.has(id)){
|
||||
return
|
||||
}
|
||||
const db = getDatabase()
|
||||
const selectedChar = get(selectedCharID)
|
||||
const char = db.characters[selectedChar]
|
||||
if(char.type === 'group'){
|
||||
throw('Character is a group')
|
||||
}
|
||||
return char.desc
|
||||
})
|
||||
|
||||
luaEngine.global.set('setDescription', async (id:string, desc:string) => {
|
||||
if(!LuaSafeIds.has(id)){
|
||||
return
|
||||
@@ -436,6 +439,13 @@ export async function runLua(code:string, arg:{
|
||||
setDatabase(db)
|
||||
})
|
||||
|
||||
luaEngine.global.set('getCharacterFirstMessage', async (id:string) => {
|
||||
const db = getDatabase()
|
||||
const selectedChar = get(selectedCharID)
|
||||
const char = db.characters[selectedChar]
|
||||
return char.firstMessage
|
||||
})
|
||||
|
||||
luaEngine.global.set('setCharacterFirstMessage', async (id:string, data:string) => {
|
||||
if(!LuaSafeIds.has(id)){
|
||||
return
|
||||
@@ -452,29 +462,11 @@ export async function runLua(code:string, arg:{
|
||||
return true
|
||||
})
|
||||
|
||||
luaEngine.global.set('getCharacterFirstMessage', async (id:string) => {
|
||||
if(!LuaSafeIds.has(id)){
|
||||
return
|
||||
}
|
||||
const db = getDatabase()
|
||||
const selectedChar = get(selectedCharID)
|
||||
const char = db.characters[selectedChar]
|
||||
return char.firstMessage
|
||||
})
|
||||
|
||||
luaEngine.global.set('getPersonaName', (id:string) => {
|
||||
if(!LuaSafeIds.has(id)){
|
||||
return
|
||||
}
|
||||
|
||||
return getUserName()
|
||||
})
|
||||
|
||||
luaEngine.global.set('getPersonaDescription', (id:string) => {
|
||||
if(!LuaSafeIds.has(id)){
|
||||
return
|
||||
}
|
||||
|
||||
const db = getDatabase()
|
||||
const selectedChar = get(selectedCharID)
|
||||
const char = db.characters[selectedChar]
|
||||
@@ -482,6 +474,10 @@ export async function runLua(code:string, arg:{
|
||||
return risuChatParser(getPersonaPrompt(), { chara: char })
|
||||
})
|
||||
|
||||
luaEngine.global.set('getAuthorsNote', (id:string) => {
|
||||
return luaEngineState.chat?.note ?? ''
|
||||
})
|
||||
|
||||
luaEngine.global.set('getBackgroundEmbedding', async (id:string) => {
|
||||
if(!LuaSafeIds.has(id)){
|
||||
return
|
||||
@@ -508,10 +504,6 @@ export async function runLua(code:string, arg:{
|
||||
|
||||
// Lore books
|
||||
luaEngine.global.set('getLoreBooksMain', (id:string, search: string) => {
|
||||
if(!LuaSafeIds.has(id)){
|
||||
return
|
||||
}
|
||||
|
||||
const db = getDatabase()
|
||||
const selectedChar = db.characters[get(selectedCharID)]
|
||||
if (selectedChar.type !== 'character') {
|
||||
@@ -524,7 +516,7 @@ export async function runLua(code:string, arg:{
|
||||
return JSON.stringify(found.map((b) => ({ ...b, content: risuChatParser(b.content, { chara: selectedChar }) })))
|
||||
})
|
||||
|
||||
luaEngine.global.set('loadLoreBooksMain', async (id:string, usedContext:number) => {
|
||||
luaEngine.global.set('loadLoreBooksMain', async (id:string, reserve:number) => {
|
||||
if(!LuaLowLevelIds.has(id)){
|
||||
return
|
||||
}
|
||||
@@ -538,9 +530,9 @@ export async function runLua(code:string, arg:{
|
||||
}
|
||||
|
||||
const fullLoreBooks = (await loadLoreBookV3Prompt()).actives
|
||||
const maxContext = db.maxContext - usedContext
|
||||
const maxContext = db.maxContext - reserve
|
||||
if (maxContext < 0) {
|
||||
return
|
||||
return JSON.stringify([])
|
||||
}
|
||||
|
||||
let totalTokens = 0
|
||||
@@ -972,4 +964,4 @@ export async function runLuaButtonTrigger(char:character|groupChat|simpleCharact
|
||||
throw(error)
|
||||
}
|
||||
return runResult
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user