From fea4f561b4c175c6f5c1fcc842e31a475132591b Mon Sep 17 00:00:00 2001
From: Cesaryuan <35998162+cesaryuan@users.noreply.github.com>
Date: Sun, 2 Apr 2023 19:43:11 +0800
Subject: [PATCH 1/2] fix: fix history message count

Bug: The length of `new Array(20).slice(20 - 24) ` is 4 which should be 24.
---
 app/store/app.ts | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/app/store/app.ts b/app/store/app.ts
index ec0c8c50..d6fd140f 100644
--- a/app/store/app.ts
+++ b/app/store/app.ts
@@ -384,7 +384,7 @@ export const useChatStore = create<ChatStore>()(
         const config = get().config;
         const n = session.messages.length;
         const recentMessages = session.messages.slice(
-          n - config.historyMessageCount,
+          - config.historyMessageCount,
         );
 
         const memoryPrompt = get().getMemoryPrompt();

From 12f342f01589a1a458d16601c47d617ebe124659 Mon Sep 17 00:00:00 2001
From: Cesaryuan <Cesaryuan@qq.com>
Date: Sun, 2 Apr 2023 20:23:56 +0800
Subject: [PATCH 2/2] fix: historyMessageCount

---
 app/store/app.ts | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/app/store/app.ts b/app/store/app.ts
index d6fd140f..b0fcbe91 100644
--- a/app/store/app.ts
+++ b/app/store/app.ts
@@ -384,7 +384,7 @@ export const useChatStore = create<ChatStore>()(
         const config = get().config;
         const n = session.messages.length;
         const recentMessages = session.messages.slice(
-          - config.historyMessageCount,
+          Math.max(0, n - config.historyMessageCount),
         );
 
         const memoryPrompt = get().getMemoryPrompt();