fix: handle empty message edge cases in getNextMessageToSummarize

This commit is contained in:
Bo26fhmC5M
2025-01-17 09:03:23 +09:00
parent 171b267891
commit b43eec49d1

View File

@@ -232,7 +232,7 @@
}; };
} }
function getNextMessageToSummarize(): Message { function getNextMessageToSummarize(): Message | null {
const char = DBState.db.characters[$selectedCharID]; const char = DBState.db.characters[$selectedCharID];
const chat = char.chats[DBState.db.characters[$selectedCharID].chatPage]; const chat = char.chats[DBState.db.characters[$selectedCharID].chatPage];
const firstMessage = const firstMessage =
@@ -256,9 +256,13 @@
} }
if (firstMessage?.trim() === "") { if (firstMessage?.trim() === "") {
if (chat.message.length > 0) {
return chat.message[0]; return chat.message[0];
} }
return null;
}
return { role: "char", chatId: "first message", data: firstMessage }; return { role: "char", chatId: "first message", data: firstMessage };
} }
@@ -601,9 +605,10 @@
{#if true} {#if true}
<!-- Next message to summarize --> <!-- Next message to summarize -->
{@const nextMessage = getNextMessageToSummarize()} {@const nextMessage = getNextMessageToSummarize()}
{#if nextMessage}
<div class="mt-4"> <div class="mt-4">
<span class="text-sm text-textcolor2 mb-2 block"> <span class="text-sm text-textcolor2 mb-2 block">
HypaV3 will summarize {nextMessage.chatId} HypaV3 will summarize [{nextMessage.chatId}]
</span> </span>
<div <div
class="p-2 max-h-48 overflow-y-auto bg-zinc-800 rounded-md whitespace-pre-wrap" class="p-2 max-h-48 overflow-y-auto bg-zinc-800 rounded-md whitespace-pre-wrap"
@@ -612,6 +617,7 @@
</div> </div>
</div> </div>
{/if} {/if}
{/if}
</div> </div>
</div> </div>
</div> </div>