From 5e330424f406d6214801838d402e21485cfc392a Mon Sep 17 00:00:00 2001 From: Joseph Kang Date: Sun, 18 May 2025 17:16:22 +0900 Subject: [PATCH 01/10] Add getDescription function (was missing) The `getDescription(triggerId)` function, documented at: https://kwaroran.github.io/docs/srp/lua/#getdescriptiontriggerid was missing from the codebase and has now been added. --- src/ts/process/lua.ts | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/src/ts/process/lua.ts b/src/ts/process/lua.ts index 074ba707..4d48850a 100644 --- a/src/ts/process/lua.ts +++ b/src/ts/process/lua.ts @@ -418,6 +418,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 @@ -972,4 +985,4 @@ export async function runLuaButtonTrigger(char:character|groupChat|simpleCharact throw(error) } return runResult -} \ No newline at end of file +} From 2c4c2a0f2b37c9e08bd96b0acaad8d9ad10a0c12 Mon Sep 17 00:00:00 2001 From: Bo26fhmC5M <88071760+Bo26fhmC5M@users.noreply.github.com> Date: Sun, 18 May 2025 22:09:27 +0900 Subject: [PATCH 02/10] fix: improve scrolling in Show Request Logs --- src/lib/Others/AlertComp.svelte | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/src/lib/Others/AlertComp.svelte b/src/lib/Others/AlertComp.svelte index 1dea03e1..2b9e3c6d 100644 --- a/src/lib/Others/AlertComp.svelte +++ b/src/lib/Others/AlertComp.svelte @@ -96,11 +96,13 @@

Input

{/if} {#if $alertStore.type === 'markdown'} - - {#await ParseMarkdown($alertStore.msg) then msg} - {@html msg} - {/await} - +
+ + {#await ParseMarkdown($alertStore.msg) then msg} + {@html msg} + {/await} + +
{:else if $alertStore.type === 'tos'} From 6d113ac1526357e5e1c196a1c970f65655157a75 Mon Sep 17 00:00:00 2001 From: Bo26fhmC5M <88071760+Bo26fhmC5M@users.noreply.github.com> Date: Sun, 18 May 2025 22:17:24 +0900 Subject: [PATCH 03/10] fix: resolve Hypa V3 button disappearing from menu --- src/lib/ChatScreens/DefaultChatScreen.svelte | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/lib/ChatScreens/DefaultChatScreen.svelte b/src/lib/ChatScreens/DefaultChatScreen.svelte index f7696799..fcf3a62c 100644 --- a/src/lib/ChatScreens/DefaultChatScreen.svelte +++ b/src/lib/ChatScreens/DefaultChatScreen.svelte @@ -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}
{ if (DBState.db.hypav2) { DBState.db.characters[$selectedCharID].chats[DBState.db.characters[$selectedCharID].chatPage].hypaV2Data ??= { From bf1ea155a3f3fc2895270f7aea39c7d4e9dfc632 Mon Sep 17 00:00:00 2001 From: poroyo <132068975+poroyo@users.noreply.github.com> Date: Mon, 19 May 2025 19:52:07 +0900 Subject: [PATCH 04/10] revert: remove memo field logic from prompt text processing The memo field was used in prompt text logic, but its usage affects string merging conditions for the `formated` inside pushPrompts(). To avoid unintended merging issues, logic involving the memo field has been rolled back. --- src/ts/process/index.svelte.ts | 55 +++++++--------------------------- 1 file changed, 10 insertions(+), 45 deletions(-) diff --git a/src/ts/process/index.svelte.ts b/src/ts/process/index.svelte.ts index 5b10df9e..acc014a7 100644 --- a/src/ts/process/index.svelte.ts +++ b/src/ts/process/index.svelte.ts @@ -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,12 +1094,6 @@ export async function sendChat(chatProcessIndex = -1,arg:{ } } - type MemoType = 'persona' | 'description' | 'authornote' | 'supaMemory'; - const promptBodyMap: Record = { persona: [], description: [], authornote: [], supaMemory: [] }; - function pushPromptInfoBody(memo: MemoType, fmt: string) { - promptBodyMap[memo].push(risuChatParser(fmt)); - } - if(promptTemplate){ const template = promptTemplate @@ -1118,7 +1106,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) + } } } @@ -1133,7 +1121,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) + } } } @@ -1148,7 +1136,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) + } } } @@ -1267,7 +1255,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) + } } } @@ -1388,29 +1376,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 From ec7ffa03141b7c548a22c52689727ca6f6f56527 Mon Sep 17 00:00:00 2001 From: "Kim, Harim" Date: Mon, 19 May 2025 21:02:20 +0900 Subject: [PATCH 05/10] fix: error alert not showing when parameter is error type --- src/ts/alert.ts | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/src/ts/alert.ts b/src/ts/alert.ts index 746f6797..a2042c37 100644 --- a/src/ts/alert.ts +++ b/src/ts/alert.ts @@ -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}` } } From 640caa12d965d86bfc5c2de1e98d0621d8570ace Mon Sep 17 00:00:00 2001 From: "Kim, Harim" Date: Mon, 19 May 2025 21:41:28 +0900 Subject: [PATCH 06/10] fix: request from localhost:xxx failed --- src-tauri/capabilities/migrated.json | 3 +++ src-tauri/gen/schemas/capabilities.json | 2 +- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/src-tauri/capabilities/migrated.json b/src-tauri/capabilities/migrated.json index e3d6abea..b548609e 100644 --- a/src-tauri/capabilities/migrated.json +++ b/src-tauri/capabilities/migrated.json @@ -50,6 +50,9 @@ }, { "url": "http://*/**/*" + }, + { + "url": "http://*:**" } ] }, diff --git a/src-tauri/gen/schemas/capabilities.json b/src-tauri/gen/schemas/capabilities.json index bcf62660..abf9901c 100644 --- a/src-tauri/gen/schemas/capabilities.json +++ b/src-tauri/gen/schemas/capabilities.json @@ -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"]}} \ No newline at end of file +{"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"]}} \ No newline at end of file From fbd25a3770bc9ec87bc99f8c4ff421e0d3131d01 Mon Sep 17 00:00:00 2001 From: poroyo <132068975+poroyo@users.noreply.github.com> Date: Mon, 19 May 2025 21:04:41 +0900 Subject: [PATCH 07/10] =?UTF-8?q?feat:=20re=E2=80=91implement=20per?= =?UTF-8?q?=E2=80=91message=20prompt=20text=20storage=20with=20new=20logic?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/ts/process/index.svelte.ts | 35 ++++++++++++++++++++++++++++++---- 1 file changed, 31 insertions(+), 4 deletions(-) diff --git a/src/ts/process/index.svelte.ts b/src/ts/process/index.svelte.ts index acc014a7..4aec67ee 100644 --- a/src/ts/process/index.svelte.ts +++ b/src/ts/process/index.svelte.ts @@ -1094,6 +1094,17 @@ export async function sendChat(chatProcessIndex = -1,arg:{ } } + 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){ const template = promptTemplate @@ -1106,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(pmt[i].role, card.innerFormat, promptBodyformatedForChatStore) } } } @@ -1121,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(pmt[i].role, card.innerFormat, promptBodyformatedForChatStore) } } } @@ -1136,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(pmt[i].role, card.innerFormat, promptBodyformatedForChatStore) } } } @@ -1194,6 +1205,10 @@ export async function sendChat(chatProcessIndex = -1,arg:{ content: content } + if(DBState.db.promptInfoInsideChat && DBState.db.promptTextInfoInsideChat){ + pushPromptInfoBody(prompt.role, prompt.content, promptBodyformatedForChatStore) + } + pushPrompts([prompt]) break } @@ -1255,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(pmt[i].role, card.innerFormat, promptBodyformatedForChatStore) } } } @@ -1294,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 @@ -1306,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 From 8dc05ccace4f07e8be150af65a4d3ae9a53b446e Mon Sep 17 00:00:00 2001 From: poroyo <132068975+poroyo@users.noreply.github.com> Date: Tue, 20 May 2025 01:03:35 +0900 Subject: [PATCH 08/10] feat: exclude globalNote type from per-message prompt text storage --- src/ts/process/index.svelte.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/ts/process/index.svelte.ts b/src/ts/process/index.svelte.ts index 4aec67ee..97f1e782 100644 --- a/src/ts/process/index.svelte.ts +++ b/src/ts/process/index.svelte.ts @@ -1205,7 +1205,7 @@ export async function sendChat(chatProcessIndex = -1,arg:{ content: content } - if(DBState.db.promptInfoInsideChat && DBState.db.promptTextInfoInsideChat){ + if(DBState.db.promptInfoInsideChat && DBState.db.promptTextInfoInsideChat && card.type2 !== 'globalNote'){ pushPromptInfoBody(prompt.role, prompt.content, promptBodyformatedForChatStore) } From 8fdd8d3beb6b1bdeb9f420f91c4a1eb54624b0ce Mon Sep 17 00:00:00 2001 From: enzi221 Date: Sun, 18 May 2025 22:03:14 +0900 Subject: [PATCH 09/10] feat: Allow more data to be readable from Lua --- src/ts/process/lua.ts | 55 +++++++++++++------------------------------ 1 file changed, 17 insertions(+), 38 deletions(-) diff --git a/src/ts/process/lua.ts b/src/ts/process/lua.ts index 074ba707..866f95c7 100644 --- a/src/ts/process/lua.ts +++ b/src/ts/process/lua.ts @@ -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] @@ -436,6 +426,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 +449,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 +461,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 +491,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') { From 5e10607cb6dcf08e203c35f2cbb194645a9388d7 Mon Sep 17 00:00:00 2001 From: enzi221 Date: Mon, 19 May 2025 20:24:20 +0900 Subject: [PATCH 10/10] fix: Protect loadLoreBooks() from very short max context length --- src/ts/process/lua.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/ts/process/lua.ts b/src/ts/process/lua.ts index 074ba707..fae4377f 100644 --- a/src/ts/process/lua.ts +++ b/src/ts/process/lua.ts @@ -524,7 +524,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 +538,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