This commit is contained in:
Kwaroran
2025-05-24 20:26:54 +09:00
7 changed files with 89 additions and 96 deletions

View File

@@ -50,6 +50,9 @@
}, },
{ {
"url": "http://*/**/*" "url": "http://*/**/*"
},
{
"url": "http://*:**"
} }
] ]
}, },

View File

@@ -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"]}}

View File

@@ -805,7 +805,7 @@
{/if} {/if}
{#if DBState.db.showMenuHypaMemoryModal} {#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={() => { <div class="flex items-center cursor-pointer hover:text-green-500 transition-colors" onclick={() => {
if (DBState.db.hypav2) { if (DBState.db.hypav2) {
DBState.db.characters[$selectedCharID].chats[DBState.db.characters[$selectedCharID].chatPage].hypaV2Data ??= { DBState.db.characters[$selectedCharID].chats[DBState.db.characters[$selectedCharID].chatPage].hypaV2Data ??= {

View File

@@ -96,11 +96,13 @@
<h2 class="text-green-700 mt-0 mb-2 w-40 max-w-full">Input</h2> <h2 class="text-green-700 mt-0 mb-2 w-40 max-w-full">Input</h2>
{/if} {/if}
{#if $alertStore.type === 'markdown'} {#if $alertStore.type === 'markdown'}
<span class="text-gray-300 chattext prose chattext2" class:prose-invert={$ColorSchemeTypeStore}> <div class="overflow-y-auto">
{#await ParseMarkdown($alertStore.msg) then msg} <span class="text-gray-300 chattext prose chattext2" class:prose-invert={$ColorSchemeTypeStore}>
{@html msg} {#await ParseMarkdown($alertStore.msg) then msg}
{/await} {@html msg}
</span> {/await}
</span>
</div>
{:else if $alertStore.type === 'tos'} {:else if $alertStore.type === 'tos'}
<!-- svelte-ignore a11y_missing_attribute --> <!-- svelte-ignore a11y_missing_attribute -->
<!-- svelte-ignore a11y_click_events_have_key_events --> <!-- svelte-ignore a11y_click_events_have_key_events -->

View File

@@ -26,14 +26,18 @@ export const alertStore = {
} }
} }
export function alertError(msg:string){ export function alertError(msg: string | Error) {
console.error(msg) console.error(msg)
const db = getDatabase() const db = getDatabase()
if(typeof(msg) !== 'string'){ if (typeof(msg) !== 'string') {
try{ try{
msg = JSON.stringify(msg) if (msg instanceof Error) {
}catch(e){ msg = msg.message
} else {
msg = JSON.stringify(msg)
}
} catch {
msg = `${msg}` msg = `${msg}`
} }
} }

View File

@@ -400,15 +400,13 @@ export async function sendChat(chatProcessIndex = -1,arg:{
if(currentChat.note){ if(currentChat.note){
unformated.authorNote.push({ unformated.authorNote.push({
role: 'system', role: 'system',
content: risuChatParser(currentChat.note, {chara: currentChar}), content: risuChatParser(currentChat.note, {chara: currentChar})
memo: 'authornote'
}) })
} }
else if(getAuthorNoteDefaultText() !== ''){ else if(getAuthorNoteDefaultText() !== ''){
unformated.authorNote.push({ unformated.authorNote.push({
role: 'system', role: 'system',
content: risuChatParser(getAuthorNoteDefaultText(), {chara: currentChar}), content: risuChatParser(getAuthorNoteDefaultText(), {chara: currentChar})
memo: 'authornote'
}) })
} }
@@ -438,8 +436,7 @@ export async function sendChat(chatProcessIndex = -1,arg:{
unformated.description.push({ unformated.description.push({
role: 'system', role: 'system',
content: description, content: description
memo: 'description',
}) })
if(nowChatroom.type === 'group'){ if(nowChatroom.type === 'group'){
@@ -460,8 +457,7 @@ export async function sendChat(chatProcessIndex = -1,arg:{
for(const lorebook of normalActives){ for(const lorebook of normalActives){
unformated.lorebook.push({ unformated.lorebook.push({
role: lorebook.role, role: lorebook.role,
content: risuChatParser(lorebook.prompt, {chara: currentChar}), content: risuChatParser(lorebook.prompt, {chara: currentChar})
memo: 'lore',
}) })
} }
@@ -485,8 +481,7 @@ export async function sendChat(chatProcessIndex = -1,arg:{
if(DBState.db.personaPrompt){ if(DBState.db.personaPrompt){
unformated.personaPrompt.push({ unformated.personaPrompt.push({
role: 'system', role: 'system',
content: risuChatParser(getPersonaPrompt(), {chara: currentChar}), content: risuChatParser(getPersonaPrompt(), {chara: currentChar})
memo: 'persona',
}) })
} }
@@ -511,8 +506,7 @@ export async function sendChat(chatProcessIndex = -1,arg:{
for(const lorebook of postEverythingLorebooks){ for(const lorebook of postEverythingLorebooks){
unformated.postEverything.push({ unformated.postEverything.push({
role: lorebook.role, role: lorebook.role,
content: risuChatParser(lorebook.prompt, {chara: currentChar}), content: risuChatParser(lorebook.prompt, {chara: currentChar})
memo: 'postEverything',
}) })
} }
@@ -1100,10 +1094,15 @@ export async function sendChat(chatProcessIndex = -1,arg:{
} }
} }
type MemoType = 'persona' | 'description' | 'authornote' | 'supaMemory'; let promptBodyformatedForChatStore: OpenAIChat[] = []
const promptBodyMap: Record<MemoType, string[]> = { persona: [], description: [], authornote: [], supaMemory: [] }; function pushPromptInfoBody(role: "function" | "system" | "user" | "assistant", fmt: string, promptBody: OpenAIChat[]) {
function pushPromptInfoBody(memo: MemoType, fmt: string) { if(!fmt.trim()){
promptBodyMap[memo].push(risuChatParser(fmt)); return
}
promptBody.push({
role: role,
content: risuChatParser(fmt),
})
} }
if(promptTemplate){ 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) pmt[i].content = risuChatParser(positionParser(card.innerFormat), {chara: currentChar}).replace('{{slot}}', pmt[i].content)
if(DBState.db.promptInfoInsideChat && DBState.db.promptTextInfoInsideChat){ 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) pmt[i].content = risuChatParser(positionParser(card.innerFormat), {chara: currentChar}).replace('{{slot}}', pmt[i].content)
if(DBState.db.promptInfoInsideChat && DBState.db.promptTextInfoInsideChat){ 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 || '') pmt[i].content = risuChatParser(positionParser(card.innerFormat), {chara: currentChar}).replace('{{slot}}', pmt[i].content || card.defaultText || '')
if(DBState.db.promptInfoInsideChat && DBState.db.promptTextInfoInsideChat){ 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 content: content
} }
if(DBState.db.promptInfoInsideChat && DBState.db.promptTextInfoInsideChat && card.type2 !== 'globalNote'){
pushPromptInfoBody(prompt.role, prompt.content, promptBodyformatedForChatStore)
}
pushPrompts([prompt]) pushPrompts([prompt])
break 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) pmt[i].content = risuChatParser(card.innerFormat, {chara: currentChar}).replace('{{slot}}', pmt[i].content)
if(DBState.db.promptInfoInsideChat && DBState.db.promptTextInfoInsideChat){ 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 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){ if(currentChar.depth_prompt && currentChar.depth_prompt.prompt && currentChar.depth_prompt.prompt.length > 0){
//depth_prompt //depth_prompt
@@ -1318,6 +1328,11 @@ export async function sendChat(chatProcessIndex = -1,arg:{
formated = await runLuaEditTrigger(currentChar, 'editRequest', formated) formated = await runLuaEditTrigger(currentChar, 'editRequest', formated)
if(DBState.db.promptInfoInsideChat && DBState.db.promptTextInfoInsideChat){
promptBodyformatedForChatStore = await runLuaEditTrigger(currentChar, 'editRequest', promptBodyformatedForChatStore)
promptInfo.promptText = promptBodyformatedForChatStore
}
//token rechecking //token rechecking
let inputTokens = 0 let inputTokens = 0
@@ -1389,29 +1404,6 @@ export async function sendChat(chatProcessIndex = -1,arg:{
return true 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 result = ''
let emoChanged = false let emoChanged = false
let resendChat = false let resendChat = false

View File

@@ -67,22 +67,16 @@ export async function runLua(code:string, arg:{
luaEngineState.code = code luaEngineState.code = code
luaEngineState.engine = await luaFactory.createEngine({injectObjects: true}) luaEngineState.engine = await luaFactory.createEngine({injectObjects: true})
const luaEngine = luaEngineState.engine 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) => { luaEngine.global.set('setChatVar', (id:string,key:string, value:string) => {
if(!LuaSafeIds.has(id) && !LuaEditDisplayIds.has(id)){ if(!LuaSafeIds.has(id) && !LuaEditDisplayIds.has(id)){
return return
} }
luaEngineState.setVar(key, value) 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) => { luaEngine.global.set('getGlobalVar', (id:string, key:string) => {
if(!LuaSafeIds.has(id) && !LuaEditDisplayIds.has(id)){
return
}
return getGlobalChatVar(key) return getGlobalChatVar(key)
}) })
luaEngine.global.set('stopChat', (id:string) => { luaEngine.global.set('stopChat', (id:string) => {
@@ -166,11 +160,9 @@ export async function runLua(code:string, arg:{
return await tokenize(value) return await tokenize(value)
}) })
luaEngine.global.set('getChatLength', (id:string) => { luaEngine.global.set('getChatLength', (id:string) => {
if(!LuaSafeIds.has(id)){
return
}
return luaEngineState.chat.message.length return luaEngineState.chat.message.length
}) })
luaEngine.global.set('getFullChatMain', (id:string) => { luaEngine.global.set('getFullChatMain', (id:string) => {
const data = JSON.stringify(luaEngineState.chat.message.map((v) => { const data = JSON.stringify(luaEngineState.chat.message.map((v) => {
return { return {
@@ -183,10 +175,11 @@ export async function runLua(code:string, arg:{
}) })
luaEngine.global.set('setFullChatMain', (id:string, value:string) => { luaEngine.global.set('setFullChatMain', (id:string, value:string) => {
const realValue = JSON.parse(value)
if(!LuaSafeIds.has(id)){ if(!LuaSafeIds.has(id)){
return return
} }
const realValue = JSON.parse(value)
luaEngineState.chat.message = realValue.map((v) => { luaEngineState.chat.message = realValue.map((v) => {
return { return {
role: v.role, role: v.role,
@@ -396,9 +389,6 @@ export async function runLua(code:string, arg:{
}) })
luaEngine.global.set('getName', async (id:string) => { luaEngine.global.set('getName', async (id:string) => {
if(!LuaSafeIds.has(id)){
return
}
const db = getDatabase() const db = getDatabase()
const selectedChar = get(selectedCharID) const selectedChar = get(selectedCharID)
const char = db.characters[selectedChar] const char = db.characters[selectedChar]
@@ -418,6 +408,19 @@ export async function runLua(code:string, arg:{
setDatabase(db) 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) => { luaEngine.global.set('setDescription', async (id:string, desc:string) => {
if(!LuaSafeIds.has(id)){ if(!LuaSafeIds.has(id)){
return return
@@ -436,6 +439,13 @@ export async function runLua(code:string, arg:{
setDatabase(db) 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) => { luaEngine.global.set('setCharacterFirstMessage', async (id:string, data:string) => {
if(!LuaSafeIds.has(id)){ if(!LuaSafeIds.has(id)){
return return
@@ -452,29 +462,11 @@ export async function runLua(code:string, arg:{
return true 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) => { luaEngine.global.set('getPersonaName', (id:string) => {
if(!LuaSafeIds.has(id)){
return
}
return getUserName() return getUserName()
}) })
luaEngine.global.set('getPersonaDescription', (id:string) => { luaEngine.global.set('getPersonaDescription', (id:string) => {
if(!LuaSafeIds.has(id)){
return
}
const db = getDatabase() const db = getDatabase()
const selectedChar = get(selectedCharID) const selectedChar = get(selectedCharID)
const char = db.characters[selectedChar] const char = db.characters[selectedChar]
@@ -482,6 +474,10 @@ export async function runLua(code:string, arg:{
return risuChatParser(getPersonaPrompt(), { chara: char }) return risuChatParser(getPersonaPrompt(), { chara: char })
}) })
luaEngine.global.set('getAuthorsNote', (id:string) => {
return luaEngineState.chat?.note ?? ''
})
luaEngine.global.set('getBackgroundEmbedding', async (id:string) => { luaEngine.global.set('getBackgroundEmbedding', async (id:string) => {
if(!LuaSafeIds.has(id)){ if(!LuaSafeIds.has(id)){
return return
@@ -508,10 +504,6 @@ export async function runLua(code:string, arg:{
// Lore books // Lore books
luaEngine.global.set('getLoreBooksMain', (id:string, search: string) => { luaEngine.global.set('getLoreBooksMain', (id:string, search: string) => {
if(!LuaSafeIds.has(id)){
return
}
const db = getDatabase() const db = getDatabase()
const selectedChar = db.characters[get(selectedCharID)] const selectedChar = db.characters[get(selectedCharID)]
if (selectedChar.type !== 'character') { 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 }) }))) 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)){ if(!LuaLowLevelIds.has(id)){
return return
} }
@@ -538,9 +530,9 @@ export async function runLua(code:string, arg:{
} }
const fullLoreBooks = (await loadLoreBookV3Prompt()).actives const fullLoreBooks = (await loadLoreBookV3Prompt()).actives
const maxContext = db.maxContext - usedContext const maxContext = db.maxContext - reserve
if (maxContext < 0) { if (maxContext < 0) {
return return JSON.stringify([])
} }
let totalTokens = 0 let totalTokens = 0
@@ -972,4 +964,4 @@ export async function runLuaButtonTrigger(char:character|groupChat|simpleCharact
throw(error) throw(error)
} }
return runResult return runResult
} }