diff --git a/src/composables/useSearchSession.ts b/src/composables/useSearchSession.ts index 21049fe..2f39f76 100644 --- a/src/composables/useSearchSession.ts +++ b/src/composables/useSearchSession.ts @@ -80,8 +80,8 @@ export function useSearchSession() { if (!resp.ok) throw new Error(`HTTP ${resp.status}`) const data = await resp.json() // Enrich sessions with last query from messages - const sessions = data.sessions || [] - for (const s of sessions) { + const sessionList = data.sessions || [] + for (const s of sessionList) { try { const msgResp = await fetch(`${base}/api/v2/search-sessions/${s.id}/messages?limit=1`, { headers: getAuthHeaders() @@ -95,7 +95,7 @@ export function useSearchSession() { } } catch {} } - sessions.value = sessions + sessions.value = sessionList } catch (e: any) { error.value = e.message || 'Failed to load sessions' } finally { @@ -117,7 +117,9 @@ export function useSearchSession() { if (!resp.ok) throw new Error(`HTTP ${resp.status}`) const data = await resp.json() await loadSessions() - return data.session + // Return the newly created session from the sessions list + const newSession = sessions.value.find(s => s.id === data.session?.id) + return newSession || data.session } catch (e: any) { error.value = e.message || 'Failed to create session' return null diff --git a/src/views/SearchView.vue b/src/views/SearchView.vue index 8612745..0792e98 100644 --- a/src/views/SearchView.vue +++ b/src/views/SearchView.vue @@ -765,7 +765,9 @@ async function saveCurrentSession() { // Show rename dialog for session name if (currentSession.value) { - renamingSession.value = currentSession.value + // Ensure we're working with the session from the list + const sessionFromList = sessionList.value.find(s => s.id === currentSession.value!.id) + renamingSession.value = sessionFromList || currentSession.value renameValue.value = currentSession.value.title === '未命名' ? '' : currentSession.value.title nextTick(() => renameInputEl.value?.focus()) }