From b43eec49d11d650544ad19091bd2cec60518b4a0 Mon Sep 17 00:00:00 2001 From: Bo26fhmC5M <88071760+Bo26fhmC5M@users.noreply.github.com> Date: Fri, 17 Jan 2025 09:03:23 +0900 Subject: [PATCH] fix: handle empty message edge cases in getNextMessageToSummarize --- src/lib/Others/HypaV3Modal.svelte | 28 +++++++++++++++++----------- 1 file changed, 17 insertions(+), 11 deletions(-) diff --git a/src/lib/Others/HypaV3Modal.svelte b/src/lib/Others/HypaV3Modal.svelte index 717f6fd5..3ac09afd 100644 --- a/src/lib/Others/HypaV3Modal.svelte +++ b/src/lib/Others/HypaV3Modal.svelte @@ -232,7 +232,7 @@ }; } - function getNextMessageToSummarize(): Message { + function getNextMessageToSummarize(): Message | null { const char = DBState.db.characters[$selectedCharID]; const chat = char.chats[DBState.db.characters[$selectedCharID].chatPage]; const firstMessage = @@ -256,7 +256,11 @@ } if (firstMessage?.trim() === "") { - return chat.message[0]; + if (chat.message.length > 0) { + return chat.message[0]; + } + + return null; } return { role: "char", chatId: "first message", data: firstMessage }; @@ -601,16 +605,18 @@ {#if true} {@const nextMessage = getNextMessageToSummarize()} -
- - HypaV3 will summarize {nextMessage.chatId} - -
- {nextMessage.data} + {#if nextMessage} +
+ + HypaV3 will summarize [{nextMessage.chatId}] + +
+ {nextMessage.data} +
-
+ {/if} {/if}