diff --git a/src/lang/en.ts b/src/lang/en.ts index a9218126..a0a1abbc 100644 --- a/src/lang/en.ts +++ b/src/lang/en.ts @@ -842,4 +842,5 @@ export const languageEnglish = { checkCorruption: "Check Corruption", showPromptComparison: "Show Prompt Comparison", hypaV3Desc: "HypaMemory V3 is a long-term memory system that use both summarized data and vector search.", + inlayErrorResponse: "Inlay Error Response", } \ No newline at end of file diff --git a/src/lib/Setting/Pages/AccessibilitySettings.svelte b/src/lib/Setting/Pages/AccessibilitySettings.svelte index 46a36ece..90695cb0 100644 --- a/src/lib/Setting/Pages/AccessibilitySettings.svelte +++ b/src/lib/Setting/Pages/AccessibilitySettings.svelte @@ -50,4 +50,8 @@
+
+ +
+
\ No newline at end of file diff --git a/src/styles.css b/src/styles.css index 2be1c75b..bad19e46 100644 --- a/src/styles.css +++ b/src/styles.css @@ -260,6 +260,14 @@ html, body{ @apply rounded-lg focus:outline-none max-w-80 w-full } +.x-risu-risu-error { + @apply border-2 border-red-700 bg-red-500 text-white rounded-md shadow-sm focus:outline-none transition-colors duration-200 px-4 py-2 min-w-0 break-words +} + +.x-risu-risu-error h1 { + @apply text-xl mb-2 +} + .z-100{ z-index: 100; } diff --git a/src/ts/parser.svelte.ts b/src/ts/parser.svelte.ts index 56305eca..c6912d5e 100644 --- a/src/ts/parser.svelte.ts +++ b/src/ts/parser.svelte.ts @@ -255,6 +255,11 @@ async function renderHighlightableMarkdown(data:string) { } break } + case 'risuerror':{ + lang = 'error' + shotLang = 'error' + break + } default:{ lang = 'none' shotLang = 'none' @@ -266,6 +271,9 @@ async function renderHighlightableMarkdown(data:string) { if(lang === 'none'){ rendered = rendered.replace(placeholder, `
${md.utils.escapeHtml(code)}
`) } + else if(lang === 'error'){ + rendered = rendered.replace(placeholder, `

${language.error}

${md.utils.escapeHtml(code)}
`) + } else{ const highlighted = hljs.highlight(code, { language: lang, @@ -285,7 +293,7 @@ async function renderHighlightableMarkdown(data:string) { } -export const assetRegex = /{{(raw|path|img|image|video|audio|bg|emotion|asset|video-img|source)::(.+?)}}/g +export const assetRegex = /{{(raw|path|img|image|video|audio|bg|emotion|asset|video-img|source)::(.+?)}}/gms async function parseAdditionalAssets(data:string, char:simpleCharacterArgument|character, mode:'normal'|'back', mode2:'unset'|'pre'|'post' = 'unset'){ const assetWidthString = (DBState.db.assetWidth && DBState.db.assetWidth !== -1 || DBState.db.assetWidth === 0) ? `max-width:${DBState.db.assetWidth}rem;` : '' diff --git a/src/ts/process/index.svelte.ts b/src/ts/process/index.svelte.ts index 9cca8808..1a52fc72 100644 --- a/src/ts/process/index.svelte.ts +++ b/src/ts/process/index.svelte.ts @@ -102,6 +102,24 @@ export async function sendChat(chatProcessIndex = -1,arg:{ return data.trim() } + function throwError(error:string){ + + if(DBState.db.inlayErrorResponse){ + DBState.db.characters[selectedChar].chats[selectedChat].message.push({ + role: 'char', + data: `\`\`\`risuerror\n${error}\n\`\`\``, + saying: currentChar.chaId, + time: Date.now(), + generationInfo, + }) + + return + } + + alertError(error) + return + } + let isDoing = get(doingChat) if(isDoing){ @@ -134,7 +152,7 @@ export async function sendChat(chatProcessIndex = -1,arg:{ if(!peerSafe){ peerRevertChat() doingChat.set(false) - alertError(language.otherUserRequesting) + throwError(language.otherUserRequesting) return false } await peerSync() @@ -198,7 +216,7 @@ export async function sendChat(chatProcessIndex = -1,arg:{ else{ currentChar = findCharacterbyIdwithCache(nowChatroom.characters[chatProcessIndex]) if(!currentChar){ - alertError(`cannot find character: ${nowChatroom.characters[chatProcessIndex]}`) + throwError(`cannot find character: ${nowChatroom.characters[chatProcessIndex]}`) return false } } @@ -815,7 +833,7 @@ export async function sendChat(chatProcessIndex = -1,arg:{ const sp = await hypaMemoryV2(chats, currentTokens, maxContextTokens, currentChat, nowChatroom, tokenizer) if(sp.error){ console.log(sp) - alertError(sp.error) + throwError(sp.error) return false } chats = sp.chats @@ -836,7 +854,7 @@ export async function sendChat(chatProcessIndex = -1,arg:{ DBState.db.characters[selectedChar].chats[selectedChat].hypaV3Data = currentChat.hypaV3Data } console.log(sp) - alertError(sp.error) + throwError(sp.error) return false } chats = sp.chats @@ -852,7 +870,7 @@ export async function sendChat(chatProcessIndex = -1,arg:{ asHyper: DBState.db.hypaMemory }) if(sp.error){ - alertError(sp.error) + throwError(sp.error) return false } chats = sp.chats @@ -867,7 +885,7 @@ export async function sendChat(chatProcessIndex = -1,arg:{ else{ while(currentTokens > maxContextTokens){ if(chats.length <= 1){ - alertError(language.errors.toomuchtoken + "\n\nRequired Tokens: " + currentTokens) + throwError(language.errors.toomuchtoken + "\n\nRequired Tokens: " + currentTokens) return false } @@ -1158,7 +1176,7 @@ export async function sendChat(chatProcessIndex = -1,arg:{ let pointer = 0 while(inputTokens > maxContextTokens){ if(pointer >= formated.length){ - alertError(language.errors.toomuchtoken + "\n\nAt token rechecking. Required Tokens: " + inputTokens) + throwError(language.errors.toomuchtoken + "\n\nAt token rechecking. Required Tokens: " + inputTokens) return false } if(formated[pointer].removable){ @@ -1212,7 +1230,7 @@ export async function sendChat(chatProcessIndex = -1,arg:{ return false } if(req.type === 'fail'){ - alertError(req.result) + throwError(req.result) return false } else if(req.type === 'streaming'){ @@ -1553,7 +1571,7 @@ export async function sendChat(chatProcessIndex = -1,arg:{ if(abortSignal.aborted){ return true } - alertError(`${rq.result}`) + throwError(`${rq.result}`) return true } else{ @@ -1594,7 +1612,7 @@ export async function sendChat(chatProcessIndex = -1,arg:{ emotionSelected = true } } catch (error) { - alertError(language.errors.httpError + `${error}`) + throwError(language.errors.httpError + `${error}`) return true } } @@ -1605,7 +1623,7 @@ export async function sendChat(chatProcessIndex = -1,arg:{ } else if(currentChar.viewScreen === 'imggen'){ if(chatProcessIndex !== -1){ - alertError("Stable diffusion in group chat is not supported") + throwError("Stable diffusion in group chat is not supported") } const msgs = DBState.db.characters[selectedChar].chats[selectedChat].message diff --git a/src/ts/storage/database.svelte.ts b/src/ts/storage/database.svelte.ts index 317d8a51..397fa67e 100644 --- a/src/ts/storage/database.svelte.ts +++ b/src/ts/storage/database.svelte.ts @@ -895,6 +895,7 @@ export interface Database{ processRegexScript: boolean }, OaiCompAPIKeys: {[key:string]:string} + inlayErrorResponse:boolean } interface SeparateParameters{