lyf 1 年之前
父節點
當前提交
6e79b9a7a2
共有 4 個文件被更改,包括 25 次插入0 次删除
  1. 1 0
      app/command.ts
  2. 1 0
      app/components/chat.tsx
  3. 1 0
      app/locales/cn.ts
  4. 22 0
      app/store/chat.ts

+ 1 - 0
app/command.ts

@@ -38,6 +38,7 @@ interface ChatCommands {
   next?: Command;
   prev?: Command;
   clear?: Command;
+  fork?: Command;
   del?: Command;
 }
 

+ 1 - 0
app/components/chat.tsx

@@ -980,6 +980,7 @@ function _Chat() {
       chatStore.updateCurrentSession(
         (session) => (session.clearContextIndex = session.messages.length),
       ),
+    fork: () => chatStore.forkSession(),
     del: () => chatStore.deleteSession(chatStore.currentSessionIndex),
   });
 

+ 1 - 0
app/locales/cn.ts

@@ -51,6 +51,7 @@ const cn = {
       next: "下一个聊天",
       prev: "上一个聊天",
       clear: "清除上下文",
+      fork: "复制聊天",
       del: "删除聊天",
     },
     InputActions: {

+ 22 - 0
app/store/chat.ts

@@ -195,6 +195,28 @@ export const useChatStore = createPersistStore(
     }
 
     const methods = {
+      forkSession() {
+        // 获取当前会话
+        const currentSession = get().currentSession();
+        if (!currentSession) return;
+
+        const newSession = createEmptySession();
+
+        newSession.topic = currentSession.topic;
+        newSession.messages = [...currentSession.messages];
+        newSession.mask = {
+          ...currentSession.mask,
+          modelConfig: {
+            ...currentSession.mask.modelConfig,
+          },
+        };
+
+        set((state) => ({
+          currentSessionIndex: 0,
+          sessions: [newSession, ...state.sessions],
+        }));
+      },
+
       clearSessions() {
         set(() => ({
           sessions: [createEmptySession()],