Bläddra i källkod

修复浏览旧会话改变日期分组

LSamien 2 månader sedan
förälder
incheckning
6febc4328e
2 ändrade filer med 23 tillägg och 2 borttagningar
  1. 5 2
      src/client/stores/chat.ts
  2. 18 0
      tests/client/chatModelSync.test.ts

+ 5 - 2
src/client/stores/chat.ts

@@ -935,8 +935,11 @@ export const useChatStore = defineStore('chat', () => {
   }
 
   async function refreshContextUsage(initialState = activeRouteState.value): Promise<void> {
-    if (!initialState || initialState.route.sessionId.startsWith('draft-')) return
-    const current = await ensureRuntime(initialState)
+    // Opening history is read-only. Resuming an old session merely to fetch
+    // usage updates Hermes' last_active timestamp and incorrectly moves it
+    // into today's sidebar group.
+    if (!initialState || initialState.route.sessionId.startsWith('draft-') || !initialState.runtimeSessionId) return
+    const current = initialState
     const usage = resultRecord(await socket.request('session.usage', { session_id: current.runtimeSessionId! }))
     current.usage = {
       inputTokens: number(usage.input_tokens ?? usage.input) || undefined,

+ 18 - 0
tests/client/chatModelSync.test.ts

@@ -134,4 +134,22 @@ describe('chat model realtime synchronization', () => {
     })
     expect(chat.selectedModel).toEqual(newModel)
   })
+
+  it('does not resume an old session merely to show its context usage', async () => {
+    const chat = useChatStore()
+    chat.sessions = [{
+      id: 'session-1', profile: 'alpha', source: 'web', title: '旧会话',
+      messageCount: 1, toolCallCount: 0, startedAt: 1, updatedAt: 1,
+    }]
+    chat.routes[routeKey('alpha', 'session-1')] = {
+      route: { profile: 'alpha', sessionId: 'session-1' }, messages: [], historySynced: true,
+      hasMoreBefore: false, loadedMessageCount: 0, messageTotal: 0,
+      isLoadingHistory: false, isStreaming: false, isQueued: false, generation: 1,
+    }
+
+    await chat.selectSession('session-1', 'alpha')
+    await Promise.resolve()
+
+    expect(realtime.request).not.toHaveBeenCalled()
+  })
 })