feat: profile-aware cache isolation and UX improvements

- Fix chat store cache keys to include profile name, prevent data leaking between profiles
- Defer cache hydration to after profile load to avoid race condition
- Remove collapsible sidebar feature (not needed)
- Remove confirmation dialog on profile switch (direct reload)
- Auto-start gateway when creating new profile
- Clear profile-specific localStorage cache on profile delete (safe prefix matching)
- Clean up unused imports in SettingsView

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
ekko
2026-04-18 14:32:54 +08:00
parent 17f0cdc1de
commit 27051dcb32
6 changed files with 97 additions and 79 deletions
@@ -3,8 +3,12 @@ import { ref } from 'vue'
import * as profilesApi from '@/api/hermes/profiles'
import type { HermesProfile, HermesProfileDetail } from '@/api/hermes/profiles'
const ACTIVE_PROFILE_STORAGE_KEY = 'hermes_active_profile_name'
export const useProfilesStore = defineStore('profiles', () => {
const profiles = ref<HermesProfile[]>([])
// 初始化时同步读 localStorage,确保其他 store(如 chat)在启动时能拿到 profile name
const activeProfileName = ref<string | null>(localStorage.getItem(ACTIVE_PROFILE_STORAGE_KEY))
const activeProfile = ref<HermesProfile | null>(null)
const detailMap = ref<Record<string, HermesProfileDetail>>({})
const loading = ref(false)
@@ -15,6 +19,11 @@ export const useProfilesStore = defineStore('profiles', () => {
try {
profiles.value = await profilesApi.fetchProfiles()
activeProfile.value = profiles.value.find(p => p.active) ?? null
// 同步缓存 profile name,供其他 store 启动时读取
if (activeProfile.value) {
activeProfileName.value = activeProfile.value.name
localStorage.setItem(ACTIVE_PROFILE_STORAGE_KEY, activeProfile.value.name)
}
} catch (err) {
console.error('Failed to fetch profiles:', err)
} finally {
@@ -43,11 +52,31 @@ export const useProfilesStore = defineStore('profiles', () => {
const ok = await profilesApi.deleteProfile(name)
if (ok) {
delete detailMap.value[name]
// 清理该 profile 的 localStorage 缓存
clearProfileCache(name)
await fetchProfiles()
}
return ok
}
// 清理指定 profile 的所有 localStorage 缓存(精确匹配缓存 key 前缀)
function clearProfileCache(profileName: string) {
const prefixes = [
`hermes_sessions_cache_v1_${profileName}`,
`hermes_session_msgs_v1_${profileName}_`,
`hermes_in_flight_v1_${profileName}_`,
`hermes_active_session_${profileName}`,
]
const keysToRemove: string[] = []
for (let i = 0; i < localStorage.length; i++) {
const key = localStorage.key(i)
if (key && prefixes.some(p => key.startsWith(p))) {
keysToRemove.push(key)
}
}
keysToRemove.forEach(key => localStorage.removeItem(key))
}
async function renameProfile(name: string, newName: string) {
const ok = await profilesApi.renameProfile(name, newName)
if (ok) {
@@ -81,6 +110,7 @@ export const useProfilesStore = defineStore('profiles', () => {
return {
profiles,
activeProfile,
activeProfileName,
detailMap,
loading,
switching,