WorkspaceShell.vue 59 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075
  1. <script setup lang="ts">
  2. import UnreadPanel from './UnreadPanel.vue'
  3. import { useUnreadStore } from '@/stores/unread'
  4. import { computed, defineAsyncComponent, nextTick, onBeforeUnmount, onMounted, ref, watch } from 'vue'
  5. import { useRoute, useRouter } from 'vue-router'
  6. import type { Profile } from '@shared/types'
  7. import AgentAvatar from '@/components/common/AgentAvatar.vue'
  8. import AccountInitialAvatar from '@/components/common/AccountInitialAvatar.vue'
  9. import type { ProfileIdentityInput } from '@/api/profiles'
  10. import AppIcon from '@/components/common/AppIcon.vue'
  11. import BrandMark from '@/components/common/BrandMark.vue'
  12. import SettingsCenterDialog from '@/components/app/SettingsCenterDialog.vue'
  13. import { rememberInterfacePath } from '@/utils/interfaceMode'
  14. import YaoYaoSidebarIcon from '@/components/common/YaoYaoSidebarIcon.vue'
  15. import DesktopUpdateEntry from './DesktopUpdateEntry.vue'
  16. import { useDesktopUpdate } from '@/composables/useDesktopUpdate'
  17. const AboutDialog = defineAsyncComponent(() => import('./AboutDialog.vue'))
  18. const UpdateCheckDialog = defineAsyncComponent(() => import('./UpdateCheckDialog.vue'))
  19. const BotPluginsDialog = defineAsyncComponent(() => import('@/components/workspace/BotPluginsDialog.vue'))
  20. const BotSettingsDialog = defineAsyncComponent(() => import('@/components/workspace/BotSettingsDialog.vue'))
  21. type NavItem = {
  22. key: 'chat' | 'history' | 'groups' | 'kanban' | 'files'
  23. label: string
  24. path: string
  25. icon: 'chat' | 'history' | 'groups' | 'board' | 'files'
  26. }
  27. type SettingsPage =
  28. | 'agent-identity'
  29. | 'agent-models'
  30. | 'account-profile'
  31. | 'account-security'
  32. | 'credential-vault'
  33. | 'account-mobile'
  34. | 'appearance'
  35. | 'system-overview'
  36. | 'system-users'
  37. | 'system-connection'
  38. | 'system-push'
  39. | 'system-voice'
  40. | 'system-update'
  41. const SIDEBAR_COLLAPSED_KEY = 'hermes-yaoyao:sidebar-collapsed'
  42. const SIDEBAR_SEARCH_EVENT = 'hermes-yaoyao:sidebar-search'
  43. const SIDEBAR_SEARCH_CLOSE_EVENT = 'hermes-yaoyao:sidebar-search-close'
  44. const props = withDefaults(defineProps<{
  45. serverName?: string
  46. userName?: string
  47. userAvatar?: string
  48. pairingUserName?: string
  49. activeProfile?: Profile
  50. profiles?: Profile[]
  51. theme?: 'light' | 'dark'
  52. themePreference?: 'light' | 'dark' | 'system'
  53. insecureTransport?: boolean
  54. sidebarTitle?: string
  55. sidebarSubtitle?: string
  56. sidebarContextTitle?: string
  57. sidebarFocusMode?: boolean
  58. inspectorOpen?: boolean
  59. inspectorCloseLabel?: string
  60. isAdmin?: boolean
  61. upstreamReady?: boolean
  62. upstreamError?: string
  63. identityBusy?: boolean
  64. identityError?: string
  65. identityResetVersion?: number
  66. }>(), {
  67. serverName: '',
  68. userName: '',
  69. userAvatar: '',
  70. pairingUserName: '',
  71. activeProfile: undefined,
  72. profiles: () => [],
  73. theme: 'light',
  74. themePreference: 'system',
  75. insecureTransport: false,
  76. sidebarTitle: '',
  77. sidebarSubtitle: '',
  78. sidebarContextTitle: '',
  79. sidebarFocusMode: false,
  80. inspectorOpen: false,
  81. inspectorCloseLabel: '关闭预览',
  82. isAdmin: false,
  83. upstreamReady: false,
  84. upstreamError: '',
  85. identityBusy: false,
  86. identityError: '',
  87. identityResetVersion: 0,
  88. })
  89. const emit = defineEmits<{
  90. logout: []
  91. toggleTheme: []
  92. setTheme: [theme: 'light' | 'dark' | 'system']
  93. selectProfile: [profile: string]
  94. saveIdentity: [input: ProfileIdentityInput]
  95. closeInspector: []
  96. createAgent: []
  97. createGroup: []
  98. botSettingsChanged: []
  99. }>()
  100. const unread = useUnreadStore(), unreadOpen = ref(false)
  101. const unreadAnchor = ref({ left: 0, top: 0 })
  102. let unreadTrigger: HTMLButtonElement | undefined
  103. function openUnread(event: MouseEvent) {
  104. unreadTrigger = event.currentTarget as HTMLButtonElement
  105. const entry = unreadTrigger.getBoundingClientRect()
  106. const sidebar = unreadTrigger.closest('aside')!.getBoundingClientRect()
  107. unreadAnchor.value = { left: sidebar.right + 12, top: entry.top }
  108. profileMenuOpen.value = false
  109. createMenuOpen.value = false
  110. settingsMenuOpen.value = false
  111. toolsMenuOpen.value = false
  112. unreadOpen.value = true
  113. }
  114. function closeUnread() {
  115. unreadOpen.value = false
  116. void nextTick(() => { if (unreadTrigger?.isConnected) unreadTrigger.focus() })
  117. }
  118. const route = useRoute()
  119. const router = useRouter()
  120. const mobileDrawerOpen = ref(false)
  121. const profileMenuOpen = ref(false)
  122. const settingsOpen = ref(false)
  123. const standalone = ref<'plugins' | 'about' | 'update' | 'bot-settings' | null>(null)
  124. const botSettingsPage = ref<'projects' | 'vm'>('projects')
  125. const standaloneReturnFocus = ref<HTMLElement>()
  126. const settingsPage = ref<SettingsPage>('agent-identity')
  127. const settingsReturnFocus = ref<HTMLButtonElement>()
  128. const mobileNavigationTrigger = ref<HTMLButtonElement>()
  129. const mobileDrawerClose = ref<HTMLButtonElement>()
  130. const profileMenuTrigger = ref<HTMLButtonElement>()
  131. const sidebarCollapsed = ref(false)
  132. const sidebarSearchOpen = ref(false)
  133. const createMenuOpen = ref(false)
  134. const createMenu = ref<HTMLElement | null>(null)
  135. let createTrigger: HTMLElement | null = null
  136. const createPosition = ref({ left: '8px', top: '58px' })
  137. const settingsMenuOpen = ref(false)
  138. const desktopUpdate = useDesktopUpdate()
  139. const { state: desktopUpdateState, error: desktopUpdateError, pending: desktopUpdatePending, visible: desktopUpdateVisible } = desktopUpdate
  140. const canCheckUpdates = computed(() => desktopUpdate.supported || Boolean(window.yaoyaoDesktop?.openUpdates) || props.isAdmin)
  141. const desktopUpdateBusy = computed(() => desktopUpdatePending.value || ['checking', 'downloading', 'verifying', 'preparing', 'installing'].includes(desktopUpdateState.value?.phase ?? ''))
  142. const desktopUpdateCheckLabel = computed(() => desktopUpdateState.value?.phase === 'checking' ? '正在检测…'
  143. : desktopUpdateState.value?.phase === 'checked' && !desktopUpdateState.value.available ? '已是最新版本' : '检测更新')
  144. const openingUpdate = ref(false)
  145. const updateError = ref('')
  146. const settingsMenu = ref<HTMLElement | null>(null)
  147. let settingsTrigger: HTMLButtonElement | null = null
  148. const settingsMenuPosition = ref({ left: '8px', top: '8px' })
  149. const toolsMenuOpen = ref(false), toolsMenu = ref<HTMLElement | null>(null)
  150. const toolsPosition = ref({ left: '8px', top: '8px' })
  151. let toolsTrigger: HTMLButtonElement | null = null
  152. const desktopSidebarContext = ref<HTMLElement | null>(null)
  153. const mobileSidebarContext = ref<HTMLElement | null>(null)
  154. function profileTitle(profile?: Profile): string {
  155. return profile?.agentName || profile?.displayName || profile?.name || '未选择机器人'
  156. }
  157. const navItems: NavItem[] = [
  158. { key: 'chat', label: '聊天', path: '/chat', icon: 'chat' },
  159. { key: 'history', label: '历史记录', path: '/history', icon: 'history' },
  160. { key: 'groups', label: '聊天', path: '/conversations', icon: 'groups' },
  161. { key: 'kanban', label: '看板', path: '/kanban', icon: 'board' },
  162. { key: 'files', label: '文件库', path: '/files', icon: 'files' },
  163. ]
  164. // The active workspace is already represented by its main canvas and sidebar
  165. // context. Keep this strip focused on destinations the user can switch to.
  166. const featureNavItems = computed(() => !props.isAdmin ? [] : navItems.filter(item => item.key !== 'groups' && item.key !== activeNav.value.key
  167. ))
  168. const applicationWorkspace = computed(() => route.path.startsWith('/conversations'))
  169. const activeNav = computed(() => {
  170. const item = navItems.find(entry => route.path.startsWith(entry.path))
  171. return item ?? navItems[0]
  172. })
  173. const contextHeading = computed(() => ({
  174. chat: '聊天',
  175. history: '历史记录',
  176. groups: '聊天列表',
  177. kanban: '看板列表',
  178. files: '历史记录',
  179. })[activeNav.value.key])
  180. const hasPrimaryAction = computed(() => ['chat', 'groups', 'kanban', 'files'].includes(activeNav.value.key))
  181. async function navigate(path: string) {
  182. mobileDrawerOpen.value = false
  183. rememberInterfacePath(path)
  184. await router.push(path)
  185. }
  186. function openMobileDrawer() {
  187. mobileDrawerOpen.value = true
  188. void nextTick(() => mobileDrawerClose.value?.focus())
  189. }
  190. function closeMobileDrawer() {
  191. mobileDrawerOpen.value = false
  192. void nextTick(() => mobileNavigationTrigger.value?.focus())
  193. }
  194. function closeMenus(event: MouseEvent) {
  195. const target = event.target as HTMLElement
  196. if (!target.closest('.sidebar-account-switcher')) profileMenuOpen.value = false
  197. if (!target.closest('.workspace-create-menu, .sidebar-create-trigger')) createMenuOpen.value = false
  198. if (!target.closest('.workspace-settings-menu, .sidebar-settings-trigger')) settingsMenuOpen.value = false
  199. if (!target.closest('.workspace-tools-menu, .sidebar-tools-trigger')) toolsMenuOpen.value = false
  200. }
  201. function closeCreateMenu() {
  202. createMenuOpen.value = false
  203. void nextTick(() => { if (createTrigger?.isConnected) createTrigger.focus() })
  204. }
  205. async function openCreateMenu(event: Event) {
  206. if (createMenuOpen.value) { closeCreateMenu(); return }
  207. createTrigger = event.currentTarget as HTMLElement
  208. const rect = createTrigger.getBoundingClientRect()
  209. createPosition.value = { left: `${Math.max(8, Math.min(rect.left, window.innerWidth - 192))}px`, top: `${Math.max(8, Math.min(rect.bottom + 6, window.innerHeight - 96))}px` }
  210. profileMenuOpen.value = false
  211. createMenuOpen.value = true
  212. await nextTick()
  213. createMenu.value?.querySelector<HTMLButtonElement>('[role="menuitem"]')?.focus()
  214. }
  215. function chooseCreate(kind: 'agent' | 'group') {
  216. closeCreateMenu()
  217. mobileDrawerOpen.value = false
  218. if (kind === 'agent') emit('createAgent')
  219. else emit('createGroup')
  220. }
  221. function actionMenuKeydown(event: KeyboardEvent) {
  222. if (!['ArrowUp', 'ArrowDown', 'Home', 'End'].includes(event.key)) return
  223. event.preventDefault()
  224. const buttons = [...(event.currentTarget as HTMLElement).querySelectorAll<HTMLElement>('[role="menuitem"]:not(:disabled)')]
  225. const index = buttons.indexOf(document.activeElement as HTMLElement)
  226. buttons[event.key === 'Home' ? 0 : event.key === 'End' ? buttons.length - 1 : (index + (event.key === 'ArrowUp' ? -1 : 1) + buttons.length) % buttons.length]?.focus()
  227. }
  228. function closeSettingsMenu() {
  229. settingsMenuOpen.value = false
  230. void nextTick(() => { if (settingsTrigger?.isConnected) settingsTrigger.focus() })
  231. }
  232. async function openSettingsMenu(event: MouseEvent) {
  233. if (settingsMenuOpen.value) { closeSettingsMenu(); return }
  234. settingsTrigger = event.currentTarget as HTMLButtonElement
  235. const rect = settingsTrigger.getBoundingClientRect()
  236. const height = ((props.isAdmin ? 4 : 3) + Number(canCheckUpdates.value)) * (window.innerWidth < 768 ? 44 : 36) + 18
  237. settingsMenuPosition.value = { left: `${Math.max(8, Math.min(rect.right - 180, window.innerWidth - 188))}px`, top: `${Math.max(8, rect.top - height)}px` }
  238. profileMenuOpen.value = false
  239. createMenuOpen.value = false
  240. toolsMenuOpen.value = false
  241. updateError.value = ''
  242. void desktopUpdate.refresh()
  243. settingsMenuOpen.value = true
  244. await nextTick()
  245. settingsMenu.value?.querySelector<HTMLButtonElement>('[role="menuitem"]')?.focus()
  246. }
  247. async function checkForUpdates() {
  248. if (openingUpdate.value || !canCheckUpdates.value) return
  249. updateError.value = ''
  250. if (desktopUpdate.supported) { await desktopUpdate.run('check'); return }
  251. if (window.yaoyaoDesktop?.openUpdates) {
  252. openingUpdate.value = true
  253. try {
  254. await window.yaoyaoDesktop.openUpdates()
  255. closeSettingsMenu()
  256. } catch (cause) {
  257. updateError.value = cause instanceof Error ? cause.message : '无法打开更新窗口,请重试'
  258. } finally { openingUpdate.value = false }
  259. return
  260. }
  261. standaloneReturnFocus.value = settingsTrigger?.closest('.mobile-drawer')
  262. ? mobileNavigationTrigger.value : settingsTrigger ?? undefined
  263. settingsMenuOpen.value = false
  264. mobileDrawerOpen.value = false
  265. standalone.value = 'update'
  266. }
  267. function openUpdateSettings() {
  268. settingsReturnFocus.value = standaloneReturnFocus.value as HTMLButtonElement | undefined
  269. standalone.value = null
  270. openSettings('system-update')
  271. }
  272. function chooseSettingsAction(action: 'settings' | 'bots' | 'about') {
  273. settingsMenuOpen.value = false
  274. if (action === 'bots') { switchInterfaceMode(); return }
  275. settingsReturnFocus.value = settingsTrigger?.closest('.mobile-drawer')
  276. ? mobileNavigationTrigger.value : settingsTrigger ?? undefined
  277. if (action === 'about') {
  278. standaloneReturnFocus.value = settingsReturnFocus.value
  279. mobileDrawerOpen.value = false
  280. standalone.value = 'about'
  281. return
  282. }
  283. openSettings(applicationWorkspace.value ? 'account-profile' : 'agent-identity')
  284. }
  285. function closeStandalone() { standalone.value = null; void nextTick(() => standaloneReturnFocus.value?.isConnected && standaloneReturnFocus.value.focus()) }
  286. function closeToolsMenu() { toolsMenuOpen.value = false; void nextTick(() => toolsTrigger?.isConnected && toolsTrigger.focus()) }
  287. async function openToolsMenu(event: MouseEvent) {
  288. if (!applicationWorkspace.value) return
  289. if (toolsMenuOpen.value) { closeToolsMenu(); return }
  290. toolsTrigger = event.currentTarget as HTMLButtonElement
  291. const rect = toolsTrigger.getBoundingClientRect()
  292. const height = 3 * (window.innerWidth < 768 ? 44 : 36) + 18
  293. toolsPosition.value = { left: `${Math.max(8, Math.min(rect.left, window.innerWidth - 208))}px`, top: `${Math.max(8, rect.top - height)}px` }
  294. settingsMenuOpen.value = false; createMenuOpen.value = false; toolsMenuOpen.value = true
  295. await nextTick(); toolsMenu.value?.querySelector<HTMLElement>('[role="menuitem"]')?.focus()
  296. }
  297. function chooseTool(page: 'apps' | 'automations' | 'bot-settings') {
  298. toolsMenuOpen.value = false
  299. if (page === 'automations') { void navigate('/conversations/automations?from=' + encodeURIComponent(route.fullPath)); return }
  300. standaloneReturnFocus.value = toolsTrigger?.closest('.mobile-drawer') ? mobileNavigationTrigger.value : toolsTrigger ?? undefined
  301. mobileDrawerOpen.value = false
  302. botSettingsPage.value = 'projects'
  303. standalone.value = page === 'bot-settings' ? 'bot-settings' : 'plugins'
  304. }
  305. function switchInterfaceMode() {
  306. if (!props.isAdmin) return
  307. settingsOpen.value = false
  308. void navigate(applicationWorkspace.value ? '/chat' : '/conversations')
  309. }
  310. function workspaceKeydown(event: KeyboardEvent) {
  311. if (!applicationWorkspace.value || !(event.metaKey || event.ctrlKey) || event.key.toLowerCase() !== 'k' || settingsOpen.value || document.querySelector('dialog[open]')) return
  312. event.preventDefault()
  313. if (sidebarSearchOpen.value) document.dispatchEvent(new CustomEvent(SIDEBAR_SEARCH_CLOSE_EVENT))
  314. else void openSidebarSearch(null)
  315. }
  316. function toggleProfileMenu(event: MouseEvent) {
  317. const trigger = event.currentTarget
  318. if (trigger instanceof HTMLButtonElement) profileMenuTrigger.value = trigger
  319. profileMenuOpen.value = !profileMenuOpen.value
  320. if (!profileMenuOpen.value) return
  321. void nextTick(() => {
  322. trigger instanceof HTMLElement
  323. && trigger.closest('.sidebar-account-switcher')?.querySelector<HTMLButtonElement>('.profile-menu [role="option"][aria-selected="true"]')?.focus()
  324. })
  325. }
  326. function chooseProfile(name: string) {
  327. emit('selectProfile', name)
  328. profileMenuOpen.value = false
  329. void nextTick(() => profileMenuTrigger.value?.focus())
  330. }
  331. function handleProfileMenuKeydown(event: KeyboardEvent) {
  332. const options = [...(event.currentTarget as HTMLElement).querySelectorAll<HTMLButtonElement>('[role="option"]')]
  333. if (!options.length) return
  334. const current = Math.max(0, options.indexOf(document.activeElement as HTMLButtonElement))
  335. let next: number | undefined
  336. if (event.key === 'ArrowDown') next = (current + 1) % options.length
  337. else if (event.key === 'ArrowUp') next = (current - 1 + options.length) % options.length
  338. else if (event.key === 'Home') next = 0
  339. else if (event.key === 'End') next = options.length - 1
  340. else if (event.key === 'Escape') {
  341. event.preventDefault()
  342. profileMenuOpen.value = false
  343. void nextTick(() => profileMenuTrigger.value?.focus())
  344. return
  345. }
  346. if (next === undefined) return
  347. event.preventDefault()
  348. options[next]?.focus()
  349. }
  350. function openSettings(page: SettingsPage = 'agent-identity', event?: MouseEvent) {
  351. const trigger = event?.currentTarget
  352. if (trigger instanceof HTMLButtonElement) {
  353. settingsReturnFocus.value = trigger.closest('.mobile-drawer')
  354. ? mobileNavigationTrigger.value
  355. : trigger
  356. }
  357. profileMenuOpen.value = false
  358. toolsMenuOpen.value = false
  359. settingsMenuOpen.value = false
  360. mobileDrawerOpen.value = false
  361. settingsPage.value = page
  362. settingsOpen.value = true
  363. }
  364. function closeSettings() {
  365. settingsOpen.value = false
  366. void nextTick(() => settingsReturnFocus.value?.focus())
  367. }
  368. function toggleSidebar() {
  369. createMenuOpen.value = false
  370. settingsMenuOpen.value = false
  371. sidebarCollapsed.value = !sidebarCollapsed.value
  372. try { localStorage.setItem(SIDEBAR_COLLAPSED_KEY, sidebarCollapsed.value ? '1' : '0') } catch { /* optional persistence */ }
  373. }
  374. function navIcon(key: NavItem['key']): 'chat' | 'history' | 'folder' | 'people' | 'board' {
  375. return key === 'groups' ? 'people' : key === 'kanban' ? 'board' : key === 'files' ? 'folder' : key === 'history' ? 'history' : 'chat'
  376. }
  377. async function openSidebarSearch(host: HTMLElement | null) {
  378. if (applicationWorkspace.value) {
  379. createMenuOpen.value = false
  380. sidebarSearchOpen.value = true
  381. document.dispatchEvent(new CustomEvent(SIDEBAR_SEARCH_EVENT, { detail: { section: 'groups' } }))
  382. return
  383. }
  384. if (sidebarCollapsed.value) {
  385. sidebarCollapsed.value = false
  386. try { localStorage.setItem(SIDEBAR_COLLAPSED_KEY, '0') } catch { /* optional persistence */ }
  387. await nextTick()
  388. }
  389. sidebarSearchOpen.value = true
  390. document.dispatchEvent(new CustomEvent(SIDEBAR_SEARCH_EVENT, { detail: { section: activeNav.value.key } }))
  391. await nextTick()
  392. host?.querySelector<HTMLInputElement>('input[type="search"]')?.focus()
  393. }
  394. async function closeSidebarSearch(host: HTMLElement | null, clear = false, restoreFocus = false) {
  395. const input = host?.querySelector<HTMLInputElement>('input[type="search"]')
  396. if (clear && input?.value) {
  397. input.value = ''
  398. input.dispatchEvent(new Event('input', { bubbles: true }))
  399. }
  400. sidebarSearchOpen.value = false
  401. document.dispatchEvent(new CustomEvent(SIDEBAR_SEARCH_CLOSE_EVENT))
  402. input?.blur()
  403. if (restoreFocus) {
  404. await nextTick()
  405. host?.closest('aside')?.querySelector<HTMLButtonElement>('.sidebar-search-trigger')?.focus()
  406. }
  407. }
  408. function handleSidebarInput(event: Event) {
  409. const input = event.target as HTMLInputElement
  410. if (input.matches('input[type="search"]') && !input.value) void closeSidebarSearch(input.closest('.sidebar-context'))
  411. }
  412. function handleSidebarFocusout(event: FocusEvent) {
  413. const input = event.target as HTMLInputElement
  414. if (input.matches('input[type="search"]') && !input.value) void closeSidebarSearch(input.closest('.sidebar-context'))
  415. }
  416. function handleSidebarSearchClosed() { sidebarSearchOpen.value = false }
  417. watch(() => route.fullPath, () => { mobileDrawerOpen.value = false; createMenuOpen.value = false; settingsMenuOpen.value = false; toolsMenuOpen.value = false; standalone.value = null })
  418. watch(() => activeNav.value.key, () => {
  419. sidebarSearchOpen.value = false
  420. profileMenuOpen.value = false
  421. })
  422. function showLocalVmSettings(){
  423. if(!props.isAdmin)return
  424. standaloneReturnFocus.value = document.activeElement instanceof HTMLElement ? document.activeElement : undefined
  425. settingsOpen.value = false; settingsMenuOpen.value = false; toolsMenuOpen.value = false; mobileDrawerOpen.value = false
  426. botSettingsPage.value = 'vm'; standalone.value = 'bot-settings'
  427. }
  428. onMounted(() => {
  429. window.addEventListener('yaoyao:local-vm-settings',showLocalVmSettings)
  430. try { sidebarCollapsed.value = localStorage.getItem(SIDEBAR_COLLAPSED_KEY) === '1' } catch { /* optional persistence */ }
  431. document.addEventListener('mousedown', closeMenus)
  432. document.addEventListener(SIDEBAR_SEARCH_CLOSE_EVENT, handleSidebarSearchClosed)
  433. document.addEventListener('keydown', workspaceKeydown)
  434. })
  435. onBeforeUnmount(() => {
  436. window.removeEventListener('yaoyao:local-vm-settings',showLocalVmSettings)
  437. document.removeEventListener('mousedown', closeMenus)
  438. document.removeEventListener(SIDEBAR_SEARCH_CLOSE_EVENT, handleSidebarSearchClosed)
  439. document.removeEventListener('keydown', workspaceKeydown)
  440. })
  441. defineExpose({openLocalVm:showLocalVmSettings})
  442. </script>
  443. <template>
  444. <div class="workspace-shell" :data-desktop-update-inline="desktopUpdate.supported ? '' : undefined" :class="{ 'workspace-shell--collapsed': sidebarCollapsed && !applicationWorkspace, 'workspace-shell--sidebar-focused': sidebarFocusMode, 'workspace-shell--conversations': applicationWorkspace, 'workspace-shell--conversation-open': applicationWorkspace && !!route.params.id }" :inert="(unreadOpen || settingsOpen || !!standalone || (applicationWorkspace && sidebarSearchOpen)) ? true : undefined">
  445. <header class="mobile-header" :inert="mobileDrawerOpen">
  446. <button ref="mobileNavigationTrigger" class="icon-button" type="button" aria-label="打开导航" @click="openMobileDrawer">
  447. <AppIcon name="menu" :size="20" />
  448. </button>
  449. <button class="mobile-brand" type="button" aria-label="返回聊天" @click="navigate(applicationWorkspace ? '/conversations' : '/chat')">
  450. <BrandMark :size="28" compact />
  451. </button>
  452. <button class="icon-button" type="button" :aria-label="theme === 'dark' ? '切换浅色主题' : '切换深色主题'" @click="emit('toggleTheme')">
  453. <AppIcon :name="theme === 'dark' ? 'sun' : 'moon'" />
  454. </button>
  455. </header>
  456. <aside
  457. class="desktop-sidebar rail"
  458. :class="{ 'desktop-sidebar--collapsed': sidebarCollapsed && !applicationWorkspace }"
  459. aria-label="主导航"
  460. :inert="mobileDrawerOpen"
  461. >
  462. <div v-if="applicationWorkspace" class="bot-list-header">
  463. <button class="bot-logo-trigger sidebar-brand" type="button" aria-label="返回 Bot 列表" title="夭夭 AI" @click="navigate('/conversations')"><BrandMark :size="32" :label="false" compact bare /></button>
  464. <span class="bot-list-header__spacer" />
  465. <button class="bot-list-toolbar-button unread-entry" type="button" :aria-label="`未读消息,${unread.total} 条`" aria-haspopup="dialog" aria-controls="unread-center" :aria-expanded="unreadOpen" title="未读消息" @click="openUnread">
  466. <AppIcon name="bell" :size="20" />
  467. <b v-if="unread.total" class="unread-entry__count" aria-hidden="true">{{ unread.total > 99 ? '99+' : unread.total }}</b>
  468. </button>
  469. <DesktopUpdateEntry v-if="desktopUpdate.supported && desktopUpdateVisible" :state="desktopUpdateState" :pending="desktopUpdatePending" :error="desktopUpdateError" @activate="desktopUpdate.run()" />
  470. <button class="bot-list-toolbar-button sidebar-search-trigger" type="button" aria-label="搜索" :aria-expanded="sidebarSearchOpen" @click="openSidebarSearch(desktopSidebarContext)"><AppIcon name="search" :size="21" /></button>
  471. <button class="bot-list-toolbar-button sidebar-create-trigger" type="button" aria-label="新建" aria-haspopup="menu" :aria-expanded="createMenuOpen" @click="openCreateMenu"><AppIcon name="plus" :size="23" /></button>
  472. </div>
  473. <div v-else class="sidebar-brand-row">
  474. <button class="rail__brand sidebar-brand" type="button" aria-label="返回聊天" title="夭夭 AI" @click="navigate(applicationWorkspace ? '/conversations' : '/chat')">
  475. <BrandMark :size="sidebarCollapsed ? 26 : 32" :label="false" compact bare />
  476. </button>
  477. <div class="sidebar-status-actions">
  478. <button class="unread-entry" type="button" :aria-label="`未读消息,${unread.total} 条`" aria-haspopup="dialog" aria-controls="unread-center" :aria-expanded="unreadOpen" title="未读消息" @click="openUnread">
  479. <AppIcon name="bell" :size="20" />
  480. <b v-if="unread.total" class="unread-entry__count" aria-hidden="true">{{ unread.total > 99 ? '99+' : unread.total }}</b>
  481. </button>
  482. <DesktopUpdateEntry v-if="desktopUpdate.supported && desktopUpdateVisible" :state="desktopUpdateState" :pending="desktopUpdatePending" :error="desktopUpdateError" @activate="desktopUpdate.run()" />
  483. </div>
  484. </div>
  485. <button
  486. v-if="!applicationWorkspace"
  487. class="sidebar-collapse"
  488. :class="{ 'sidebar-collapse--collapsed': sidebarCollapsed }"
  489. type="button"
  490. :aria-label="sidebarCollapsed ? '展开侧边栏' : '折叠侧边栏'"
  491. :title="sidebarCollapsed ? '展开侧边栏' : '折叠侧边栏'"
  492. @click="toggleSidebar"
  493. >
  494. <AppIcon name="chevron-left" :size="18" />
  495. </button>
  496. <button
  497. v-if="!applicationWorkspace && !['files', 'kanban'].includes(activeNav.key)"
  498. class="sidebar-search-trigger"
  499. :class="{ 'sidebar-search-trigger--searching': sidebarSearchOpen && !applicationWorkspace }"
  500. type="button"
  501. aria-label="搜索"
  502. title="搜索"
  503. :aria-expanded="sidebarSearchOpen"
  504. :aria-hidden="sidebarSearchOpen && !applicationWorkspace ? 'true' : undefined"
  505. :tabindex="sidebarSearchOpen && !applicationWorkspace ? -1 : 0"
  506. @click="openSidebarSearch(desktopSidebarContext)"
  507. >
  508. <YaoYaoSidebarIcon name="search" />
  509. <span>搜索</span>
  510. </button>
  511. <div v-if="hasPrimaryAction && !applicationWorkspace" class="sidebar-primary-action">
  512. <slot name="sidebar-action" />
  513. </div>
  514. <nav v-if="!applicationWorkspace" class="sidebar-feature-nav" aria-label="功能入口">
  515. <button
  516. v-for="item in featureNavItems"
  517. :key="item.key"
  518. type="button"
  519. :class="{ active: activeNav.key === item.key }"
  520. :aria-current="activeNav.key === item.key ? 'page' : undefined"
  521. :title="item.label"
  522. @click="navigate(item.path)"
  523. >
  524. <YaoYaoSidebarIcon :name="navIcon(item.key)" />
  525. <span>{{ item.label }}</span>
  526. </button>
  527. </nav>
  528. <section
  529. ref="desktopSidebarContext"
  530. class="sidebar-context"
  531. :class="{ 'sidebar-context--searching': sidebarSearchOpen }"
  532. @keydown.esc.capture="closeSidebarSearch(desktopSidebarContext, true, true)"
  533. @input.capture="handleSidebarInput"
  534. @focusout.capture="handleSidebarFocusout"
  535. >
  536. <slot name="sidebar-before-heading" />
  537. <header v-if="!applicationWorkspace" class="sidebar-context__heading">
  538. <strong>{{ sidebarContextTitle || contextHeading }}</strong>
  539. <span v-if="sidebarSubtitle">{{ sidebarSubtitle }}</span>
  540. </header>
  541. <div class="sidebar-context__body">
  542. <slot name="sidebar" />
  543. </div>
  544. </section>
  545. <div class="sidebar-footer">
  546. <button v-if="applicationWorkspace" class="sidebar-tools-trigger" type="button" aria-haspopup="menu" :aria-expanded="toolsMenuOpen" @click="openToolsMenu"><YaoYaoSidebarIcon name="tools" :size="18" /><span>工具</span><AppIcon name="chevron-down" :size="15" /></button>
  547. <div class="sidebar-account-switcher">
  548. <button class="sidebar-account-switcher__main" type="button" :title="applicationWorkspace ? '当前账号' : `切换机器人:${profileTitle(activeProfile)}`" :aria-haspopup="applicationWorkspace ? 'menu' : 'listbox'" :aria-expanded="applicationWorkspace ? settingsMenuOpen : profileMenuOpen" @click="applicationWorkspace ? openSettingsMenu($event) : toggleProfileMenu($event)">
  549. <AccountInitialAvatar v-if="applicationWorkspace" :name="userName" :image-url="userAvatar" :size="30" />
  550. <AgentAvatar v-else :name="profileTitle(activeProfile)" :avatar="activeProfile?.agentAvatar || ''" :size="30" />
  551. <span class="account-copy">
  552. <strong>{{ applicationWorkspace ? userName : profileTitle(activeProfile) }}</strong>
  553. <span>{{ serverName || (applicationWorkspace ? '当前账号' : activeProfile?.name || userName || '未选择机器人') }}</span>
  554. </span>
  555. <AppIcon v-if="!applicationWorkspace" class="sidebar-account-switcher__chevron" name="chevron-down" :size="14" />
  556. </button>
  557. <button v-if="!applicationWorkspace" class="sidebar-settings-trigger" type="button" title="设置与模式" aria-label="设置与模式" aria-haspopup="menu" :aria-expanded="settingsMenuOpen" @click="openSettingsMenu">
  558. <AppIcon name="settings" :size="17" />
  559. </button>
  560. <Transition name="menu-fade">
  561. <div v-if="profileMenuOpen" class="profile-menu" role="listbox" aria-label="切换机器人" @keydown="handleProfileMenuKeydown">
  562. <strong class="profile-menu__heading">切换机器人</strong>
  563. <button
  564. v-for="profile in profiles"
  565. :key="profile.name"
  566. type="button"
  567. role="option"
  568. :class="{ active: profile.name === activeProfile?.name }"
  569. :aria-selected="profile.name === activeProfile?.name"
  570. @click="chooseProfile(profile.name)"
  571. >
  572. <AgentAvatar :name="profileTitle(profile)" :avatar="profile.agentAvatar || ''" :size="24" />
  573. <strong>{{ profileTitle(profile) }}</strong>
  574. <AppIcon v-if="profile.name === activeProfile?.name" name="check" :size="15" />
  575. </button>
  576. </div>
  577. </Transition>
  578. </div>
  579. </div>
  580. </aside>
  581. <Transition name="drawer-fade">
  582. <button v-if="mobileDrawerOpen" class="drawer-scrim" type="button" aria-label="关闭导航" @click="closeMobileDrawer" />
  583. </Transition>
  584. <aside
  585. class="mobile-drawer"
  586. :class="{ 'mobile-drawer--open': mobileDrawerOpen, 'mobile-drawer--focused': sidebarFocusMode }"
  587. aria-label="移动导航"
  588. :aria-hidden="!mobileDrawerOpen"
  589. :inert="!mobileDrawerOpen"
  590. >
  591. <div class="mobile-drawer__header">
  592. <button class="sidebar-brand" type="button" aria-label="返回聊天" @click="navigate(applicationWorkspace ? '/conversations' : '/chat')">
  593. <BrandMark :size="32" compact />
  594. </button>
  595. <div class="mobile-drawer__actions"><DesktopUpdateEntry v-if="desktopUpdate.supported && desktopUpdateVisible" :state="desktopUpdateState" :pending="desktopUpdatePending" :error="desktopUpdateError" @activate="desktopUpdate.run()" /><button ref="mobileDrawerClose" class="icon-button" type="button" aria-label="关闭导航" @click="closeMobileDrawer">
  596. <AppIcon name="close" />
  597. </button><button v-if="applicationWorkspace" class="sidebar-create-trigger" type="button" aria-label="新建" title="新建" aria-haspopup="menu" :aria-expanded="createMenuOpen" @click="openCreateMenu"><AppIcon name="plus" :size="19" /></button></div>
  598. </div>
  599. <button
  600. v-if="!applicationWorkspace && !['files', 'kanban'].includes(activeNav.key)"
  601. class="sidebar-search-trigger"
  602. :class="{ 'sidebar-search-trigger--searching': sidebarSearchOpen && !applicationWorkspace }"
  603. type="button"
  604. aria-label="搜索"
  605. title="搜索"
  606. :aria-expanded="sidebarSearchOpen"
  607. :aria-hidden="sidebarSearchOpen && !applicationWorkspace ? 'true' : undefined"
  608. :tabindex="sidebarSearchOpen && !applicationWorkspace ? -1 : 0"
  609. @click="openSidebarSearch(mobileSidebarContext)"
  610. >
  611. <AppIcon name="search" :size="18" />
  612. <span>搜索</span>
  613. </button>
  614. <div v-if="hasPrimaryAction && !applicationWorkspace" class="sidebar-primary-action">
  615. <slot name="sidebar-action" />
  616. </div>
  617. <nav v-if="!applicationWorkspace" class="sidebar-feature-nav" aria-label="功能入口">
  618. <button
  619. v-for="item in featureNavItems"
  620. :key="item.key"
  621. type="button"
  622. :class="{ active: activeNav.key === item.key }"
  623. :aria-current="activeNav.key === item.key ? 'page' : undefined"
  624. @click="navigate(item.path)"
  625. >
  626. <AppIcon :name="item.icon" :size="18" />
  627. <span>{{ item.label }}</span>
  628. </button>
  629. </nav>
  630. <section
  631. ref="mobileSidebarContext"
  632. class="sidebar-context mobile-drawer__context"
  633. :class="{ 'sidebar-context--searching': sidebarSearchOpen }"
  634. @keydown.esc.capture="closeSidebarSearch(mobileSidebarContext, true, true)"
  635. @input.capture="handleSidebarInput"
  636. @focusout.capture="handleSidebarFocusout"
  637. >
  638. <slot name="sidebar-before-heading" />
  639. <header v-if="!applicationWorkspace" class="sidebar-context__heading">
  640. <strong>{{ sidebarContextTitle || contextHeading }}</strong>
  641. <span v-if="sidebarSubtitle">{{ sidebarSubtitle }}</span>
  642. </header>
  643. <div class="sidebar-context__body">
  644. <slot name="mobile-sidebar" />
  645. </div>
  646. </section>
  647. <div class="sidebar-footer mobile-drawer__footer">
  648. <button v-if="applicationWorkspace" class="sidebar-tools-trigger" type="button" aria-haspopup="menu" :aria-expanded="toolsMenuOpen" @click="openToolsMenu"><YaoYaoSidebarIcon name="tools" :size="18" /><span>工具</span><AppIcon name="chevron-down" :size="15" /></button>
  649. <div class="sidebar-account-switcher">
  650. <button class="sidebar-account-switcher__main" type="button" :title="applicationWorkspace ? '当前账号' : `切换机器人:${profileTitle(activeProfile)}`" :aria-haspopup="applicationWorkspace ? 'menu' : 'listbox'" :aria-expanded="applicationWorkspace ? settingsMenuOpen : profileMenuOpen" @click="applicationWorkspace ? openSettingsMenu($event) : toggleProfileMenu($event)">
  651. <AccountInitialAvatar v-if="applicationWorkspace" :name="userName" :image-url="userAvatar" :size="30" />
  652. <AgentAvatar v-else :name="profileTitle(activeProfile)" :avatar="activeProfile?.agentAvatar || ''" :size="30" />
  653. <span class="account-copy">
  654. <strong>{{ applicationWorkspace ? userName : profileTitle(activeProfile) }}</strong>
  655. <span>{{ serverName || (applicationWorkspace ? '当前账号' : activeProfile?.name || userName || '未选择机器人') }}</span>
  656. </span>
  657. <AppIcon v-if="!applicationWorkspace" class="sidebar-account-switcher__chevron" name="chevron-down" :size="14" />
  658. </button>
  659. <button v-if="!applicationWorkspace" class="sidebar-settings-trigger" type="button" title="设置与模式" aria-label="设置与模式" aria-haspopup="menu" :aria-expanded="settingsMenuOpen" @click="openSettingsMenu">
  660. <AppIcon name="settings" :size="17" />
  661. </button>
  662. <Transition name="menu-fade">
  663. <div v-if="profileMenuOpen" class="profile-menu" role="listbox" aria-label="切换机器人" @keydown="handleProfileMenuKeydown">
  664. <strong class="profile-menu__heading">切换机器人</strong>
  665. <button
  666. v-for="profile in profiles"
  667. :key="profile.name"
  668. type="button"
  669. role="option"
  670. :class="{ active: profile.name === activeProfile?.name }"
  671. :aria-selected="profile.name === activeProfile?.name"
  672. @click="chooseProfile(profile.name)"
  673. >
  674. <AgentAvatar :name="profileTitle(profile)" :avatar="profile.agentAvatar || ''" :size="24" />
  675. <strong>{{ profileTitle(profile) }}</strong>
  676. <AppIcon v-if="profile.name === activeProfile?.name" name="check" :size="15" />
  677. </button>
  678. </div>
  679. </Transition>
  680. </div>
  681. </div>
  682. </aside>
  683. <main class="workspace-main" :inert="mobileDrawerOpen">
  684. <slot />
  685. </main>
  686. <Transition name="inspector-slide">
  687. <aside v-if="inspectorOpen" class="workspace-inspector">
  688. <div class="workspace-inspector__close">
  689. <button class="icon-button" type="button" :aria-label="inspectorCloseLabel" :title="inspectorCloseLabel" @click="emit('closeInspector')">
  690. <AppIcon name="close" />
  691. </button>
  692. </div>
  693. <slot name="inspector" />
  694. </aside>
  695. </Transition>
  696. <AboutDialog v-if="standalone === 'about'" @close="closeStandalone" />
  697. <UpdateCheckDialog v-if="standalone === 'update' && isAdmin" @close="closeStandalone" @manage="openUpdateSettings" />
  698. <BotPluginsDialog v-if="standalone === 'plugins' && applicationWorkspace" @close="closeStandalone" />
  699. <BotSettingsDialog v-if="standalone === 'bot-settings'" :is-admin="isAdmin" :initial-page="botSettingsPage" @close="closeStandalone" @changed="emit('botSettingsChanged')" />
  700. <SettingsCenterDialog
  701. :open="settingsOpen"
  702. :bot-mode="applicationWorkspace"
  703. @switch-mode="switchInterfaceMode"
  704. :initial-page="settingsPage"
  705. :user-name="userName"
  706. :user-avatar="userAvatar"
  707. :pairing-user-name="pairingUserName"
  708. :active-profile="activeProfile"
  709. :profiles="profiles"
  710. :theme="theme"
  711. :theme-preference="themePreference"
  712. :insecure-transport="insecureTransport"
  713. :is-admin="isAdmin"
  714. :upstream-ready="upstreamReady"
  715. :upstream-error="upstreamError"
  716. :identity-busy="identityBusy"
  717. :identity-error="identityError"
  718. :identity-reset-version="identityResetVersion"
  719. @close="closeSettings"
  720. @logout="emit('logout')"
  721. @select-profile="emit('selectProfile', $event)"
  722. @save-identity="emit('saveIdentity', $event)"
  723. @set-theme="emit('setTheme', $event)"
  724. />
  725. <Teleport to="body">
  726. <div v-if="settingsMenuOpen" class="workspace-create-dismiss" @pointerdown.self="closeSettingsMenu" @keydown.esc.prevent.stop="closeSettingsMenu">
  727. <div ref="settingsMenu" class="workspace-create-menu workspace-settings-menu" :style="settingsMenuPosition" role="menu" aria-label="账号菜单" @keydown="actionMenuKeydown">
  728. <button type="button" role="menuitem" @click="chooseSettingsAction('settings')"><AppIcon name="settings" :size="17" />我的设置</button>
  729. <button type="button" role="menuitem" @click="chooseSettingsAction('about')"><AppIcon name="info" :size="17" />关于</button>
  730. <button v-if="desktopUpdate.supported" class="desktop-update-check" type="button" role="menuitem" :disabled="desktopUpdateBusy || desktopUpdateState?.phase === 'ready'" :aria-busy="desktopUpdateBusy" @click="checkForUpdates"><AppIcon name="refresh" :size="17" />{{ desktopUpdateCheckLabel }}</button>
  731. <button v-else-if="canCheckUpdates" type="button" role="menuitem" :disabled="openingUpdate" :aria-busy="openingUpdate" @click="checkForUpdates"><AppIcon name="refresh" :size="17" />{{ openingUpdate ? '正在打开…' : '检测更新' }}</button>
  732. <p v-if="updateError" class="update-menu-error" role="alert">{{ updateError }}</p>
  733. <p v-if="desktopUpdate.supported && (desktopUpdateError || desktopUpdateState?.error)" class="update-menu-error" role="alert">{{ desktopUpdateError || desktopUpdateState?.error }}</p>
  734. <a role="menuitem" href="https://yaoyao.samien.cn" target="_blank" rel="noopener noreferrer" @click="closeSettingsMenu"><AppIcon name="external" :size="17" />帮助</a>
  735. <button v-if="isAdmin" type="button" role="menuitem" @click="chooseSettingsAction('bots')"><AppIcon :name="applicationWorkspace ? 'chat' : 'users'" :size="17" />{{ applicationWorkspace ? '进入聊天模式' : '进入 Bot 模式' }}</button>
  736. </div>
  737. </div>
  738. <div v-if="toolsMenuOpen && applicationWorkspace" class="workspace-create-dismiss" @pointerdown.self="closeToolsMenu" @keydown.esc.prevent.stop="closeToolsMenu"><div ref="toolsMenu" class="workspace-create-menu workspace-tools-menu" :style="toolsPosition" role="menu" aria-label="工具" @keydown="actionMenuKeydown"><button type="button" role="menuitem" @click="chooseTool('bot-settings')"><AppIcon name="settings" :size="17" />Bot 设置</button><button type="button" role="menuitem" @click="chooseTool('automations')"><AppIcon name="clock" :size="17" />自动化</button><button type="button" role="menuitem" @click="chooseTool('apps')"><AppIcon name="link" :size="17" />已连接应用</button></div></div>
  739. <div v-if="createMenuOpen" class="workspace-create-dismiss" @pointerdown.self="closeCreateMenu" @keydown.esc.prevent.stop="closeCreateMenu">
  740. <div ref="createMenu" class="workspace-create-menu" :style="createPosition" role="menu" aria-label="新建聊天" @keydown="actionMenuKeydown">
  741. <button type="button" role="menuitem" @click="chooseCreate('agent')"><AppIcon name="users" :size="17" />新建 Bot</button>
  742. <button type="button" role="menuitem" @click="chooseCreate('group')"><AppIcon name="groups" :size="17" />新建群聊</button>
  743. </div>
  744. </div>
  745. </Teleport>
  746. <UnreadPanel v-if="unreadOpen" :anchor="unreadAnchor" @close="closeUnread" />
  747. </div>
  748. </template>
  749. <style scoped>
  750. .update-menu-error{margin:4px 10px;color:var(--danger);font-size:12px;line-height:1.5;overflow-wrap:anywhere}.workspace-settings-menu button:disabled{opacity:.6;cursor:wait}
  751. .sidebar-tools-trigger{display:flex;width:100%;min-height:44px;align-items:center;gap:10px;padding:8px 12px;margin:0 0 8px;border:0;border-radius:9px;background:transparent;color:var(--text-primary);font:500 13px var(--font-ui);cursor:pointer}.sidebar-tools-trigger span{flex:1;text-align:left}.sidebar-tools-trigger:hover,.sidebar-tools-trigger[aria-expanded=true]{background:var(--surface-hover)}.sidebar-tools-trigger:focus-visible{outline:2px solid var(--accent);outline-offset:2px}.workspace-settings-menu a{display:flex;align-items:center;gap:8px;min-height:36px;padding:8px 10px;box-sizing:border-box;border-radius:7px;color:var(--text-primary);text-decoration:none;font-size:13px}.workspace-settings-menu a:hover{background:var(--surface-hover)}.workspace-settings-menu a:focus-visible{outline:2px solid var(--accent);outline-offset:-2px}
  752. .workspace-shell {
  753. display: grid;
  754. grid-template-columns: 264px minmax(0, 1fr) auto;
  755. width: 100%;
  756. height: 100%;
  757. min-width: 0;
  758. overflow: hidden;
  759. background: var(--canvas);
  760. transition: grid-template-columns 180ms var(--ease-out);
  761. }
  762. .workspace-shell--conversations { grid-template-columns: 360px minmax(0, 1fr) auto; }
  763. .workspace-shell--collapsed { grid-template-columns: 68px minmax(0, 1fr) auto; }
  764. .mobile-header, .mobile-drawer, .drawer-scrim { display: none; }
  765. .desktop-sidebar {
  766. --sidebar-search-top: 58px;
  767. position: relative;
  768. z-index: 20;
  769. display: flex;
  770. min-width: 0;
  771. min-height: 0;
  772. flex-direction: column;
  773. overflow: hidden;
  774. border-right: 1px solid var(--line);
  775. background: var(--surface);
  776. color: var(--text-primary);
  777. }
  778. .sidebar-brand-row { display: flex; min-height: 58px; align-items: center; padding: 9px 20px 7px; }
  779. .sidebar-brand { display: flex; min-width: 0; align-items: center; padding: 0; border: 0; border-radius: 10px; background: transparent; cursor: pointer; }
  780. .sidebar-brand:hover { background: transparent; }
  781. .sidebar-collapse {
  782. display: grid;
  783. width: 34px;
  784. height: 34px;
  785. flex: 0 0 34px;
  786. place-items: center;
  787. padding: 0;
  788. border: 0;
  789. border-radius: 9px;
  790. background: transparent;
  791. color: var(--text-muted);
  792. cursor: pointer;
  793. }
  794. .sidebar-collapse:hover { background: var(--surface-hover); color: var(--text-primary); }
  795. .sidebar-collapse { position: absolute; top: 12px; right: 11px; transition: transform 180ms var(--ease-out), color 140ms ease, background-color 140ms ease; }
  796. .sidebar-collapse--collapsed { transform: rotate(180deg); }
  797. .sidebar-search-trigger,
  798. .sidebar-feature-nav button {
  799. display: flex;
  800. width: calc(100% - 20px);
  801. min-height: 36px;
  802. align-items: center;
  803. gap: 11px;
  804. margin-inline: 10px;
  805. padding: 0 11px;
  806. border: 0;
  807. border-radius: 10px;
  808. background: transparent;
  809. color: var(--text-primary);
  810. cursor: pointer;
  811. text-align: left;
  812. font-size: 14px;
  813. font-weight: 650;
  814. }
  815. .sidebar-search-trigger:hover,
  816. .sidebar-search-trigger[aria-expanded="true"],
  817. .sidebar-feature-nav button:hover,
  818. .sidebar-feature-nav button.active { background: var(--surface-soft); }
  819. .sidebar-search-trigger[aria-expanded="true"] { box-shadow: 0 0 0 3px var(--focus-ring); }
  820. .sidebar-search-trigger--searching { visibility: hidden; pointer-events: none; }
  821. .desktop-sidebar .sidebar-context--searching :deep(.sidebar-search),
  822. .desktop-sidebar .sidebar-context--searching :deep(.library-search),
  823. .mobile-drawer .sidebar-context--searching :deep(.sidebar-search),
  824. .mobile-drawer .sidebar-context--searching :deep(.library-search) {
  825. position: absolute;
  826. z-index: 40;
  827. top: var(--sidebar-search-top);
  828. left: 10px;
  829. width: calc(100% - 20px);
  830. min-height: 36px;
  831. margin: 0;
  832. background: var(--surface);
  833. }
  834. .sidebar-primary-action { margin: 3px 10px; }
  835. .sidebar-primary-action :deep(button) {
  836. display: flex;
  837. width: 100%;
  838. min-height: 36px;
  839. align-items: center;
  840. justify-content: flex-start;
  841. gap: 11px;
  842. padding: 0 11px;
  843. border: 0;
  844. border-radius: 10px;
  845. background: transparent;
  846. color: var(--text-primary);
  847. cursor: pointer;
  848. font-size: 14px;
  849. font-weight: 650;
  850. }
  851. .sidebar-primary-action :deep(button:hover),
  852. .sidebar-primary-action :deep(button:focus-visible) { background: var(--surface-soft); }
  853. .sidebar-primary-action :deep(button:focus-visible) { outline: 0; box-shadow: inset 0 0 0 1px var(--line-strong); }
  854. .sidebar-primary-action :deep(button:active) { background: var(--surface-hover); }
  855. .sidebar-primary-action :deep(button > span) { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  856. .sidebar-feature-nav { display: flex; flex-direction: column; gap: 1px; padding: 0 0 9px; }
  857. .sidebar-feature-nav button { margin-block: 0; font-weight: 680; }
  858. .sidebar-feature-nav button.active { font-weight: 740; }
  859. .sidebar-context { display: flex; min-height: 0; flex: 1; flex-direction: column; overflow: hidden; }
  860. .sidebar-context__heading { display: flex; min-height: 35px; align-items: center; justify-content: space-between; gap: 8px; padding: 6px 20px 5px 21px; }
  861. .sidebar-context__heading strong { font-size: 13px; font-weight: 680; }
  862. .sidebar-context__heading span { overflow: hidden; color: var(--text-muted); font-size: 10px; text-overflow: ellipsis; white-space: nowrap; }
  863. .sidebar-context__body { min-height: 0; flex: 1; overflow: hidden; }
  864. .sidebar-context:not(.sidebar-context--searching) :deep(.library-search) { display: none; }
  865. .sidebar-context__body :deep(.library-search) { margin-bottom: 10px; }
  866. .sidebar-context__body :deep(.sidebar-list) { padding-inline: 10px; }
  867. .sidebar-context__body :deep(.sidebar-item) { min-height: 42px; padding: 5px 9px; }
  868. .sidebar-context__body :deep(.sidebar-item.sidebar-item--single-line) { min-height: 31px; padding: 1px 7px; }
  869. .sidebar-context__body :deep(.sidebar-item--single-line .sidebar-item__row strong) { font-size: 14px; font-weight: 400; }
  870. .sidebar-context__body :deep(.sidebar-item__icon) { width: 25px; height: 25px; flex-basis: 25px; border: 0; border-radius: 7px; background: transparent; }
  871. .sidebar-context__body :deep(.sidebar-item__icon--avatar) { background: transparent; color: var(--text-secondary); }
  872. .sidebar-context__body :deep(.sidebar-item__row strong) { font-size: 13px; }
  873. .sidebar-context__body :deep(.sidebar-item.sidebar-item--topic .sidebar-item__row strong) { font-size: 14px; font-weight: 450; }
  874. .sidebar-context__body :deep(.library-sidebar) { padding-top: 1px; }
  875. .sidebar-context__body :deep(.library-sidebar section) { margin-top: 2px; }
  876. .workspace-shell--sidebar-focused .desktop-sidebar .sidebar-search-trigger,
  877. .workspace-shell--sidebar-focused .desktop-sidebar > .sidebar-primary-action,
  878. .workspace-shell--sidebar-focused .desktop-sidebar .sidebar-feature-nav,
  879. .workspace-shell--sidebar-focused .desktop-sidebar .sidebar-footer { display: none; }
  880. .workspace-shell--sidebar-focused { grid-template-columns: 264px minmax(0, 1fr) auto; }
  881. .workspace-shell--sidebar-focused .desktop-sidebar .sidebar-context,
  882. .workspace-shell--sidebar-focused .desktop-sidebar--collapsed .sidebar-context { display: flex; flex: 1; }
  883. .sidebar-footer { flex: 0 0 auto; padding: 7px 10px 10px; background: var(--surface); }
  884. .sidebar-account-switcher { position: relative; z-index: 30; display: flex; min-height: 46px; align-items: center; gap: 6px; padding: 4px 2px; border-top: 1px solid var(--line); }
  885. .sidebar-account-switcher__main { display: flex; min-width: 0; min-height: 38px; flex: 1; align-items: center; gap: 9px; padding: 4px 1px; border: 0; border-radius: 8px; background: transparent; color: var(--text-primary); cursor: pointer; text-align: left; }
  886. .sidebar-account-switcher__main:hover { background: var(--surface-soft); }
  887. .sidebar-settings-trigger { display: grid; width: 38px; min-width: 38px; height: 38px; flex: 0 0 38px; place-items: center; padding: 0; border: 0; border-radius: 8px; background: transparent; color: var(--text-muted); cursor: pointer; }
  888. .sidebar-settings-trigger:hover { background: var(--surface-soft); color: var(--text-primary); }
  889. .sidebar-settings-trigger:focus-visible { outline: 0; box-shadow: inset 0 0 0 1px var(--line-strong), 0 0 0 3px var(--focus-ring); }
  890. .sidebar-account__avatar { display: grid; width: 30px; height: 30px; flex: 0 0 30px; place-items: center; border-radius: 50%; background: transparent; color: var(--text-secondary); font-size: 13px; font-weight: 700; }
  891. .sidebar-account-switcher__chevron { flex: 0 0 auto; color: var(--text-muted); }
  892. .profile-menu { position: absolute; right: 0; bottom: calc(100% + 6px); left: 0; padding: 5px; border: 1px solid var(--line); border-radius: 12px; background: var(--surface-raised); box-shadow: var(--shadow-float); }
  893. .profile-menu__heading { display: block; padding: 8px 8px 5px; color: var(--text-muted); font-size: 11px; font-weight: 650; }
  894. .profile-menu button { display: flex; width: 100%; min-height: 38px; align-items: center; gap: 9px; padding: 5px 8px; border: 0; border-radius: 8px; background: transparent; cursor: pointer; text-align: left; }
  895. .profile-menu button:hover, .profile-menu button.active { background: var(--surface-hover); }
  896. .profile-menu button > span:not(.agent-avatar) { display: grid; width: 25px; height: 25px; place-items: center; border-radius: 8px; background: var(--surface-soft); color: var(--text-secondary); font-size: 11px; }
  897. .profile-menu button strong { flex: 1; overflow: hidden; font-size: 13px; text-overflow: ellipsis; }
  898. .account-copy { display: flex; min-width: 0; flex: 1; flex-direction: column; }
  899. .account-copy strong, .account-copy span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  900. .account-copy strong { font-size: 13px; font-weight: 650; }
  901. .account-copy span { color: var(--text-muted); font-size: 11px; }
  902. .desktop-sidebar--collapsed .sidebar-brand-row { padding-inline: 21px; }
  903. .desktop-sidebar--collapsed .sidebar-brand { width: 26px; flex: 0 0 26px; overflow: hidden; }
  904. .desktop-sidebar--collapsed .sidebar-collapse { position: static; width: 28px; height: 28px; flex: 0 0 28px; order: 1; align-self: center; margin-top: auto; margin-bottom: 5px; }
  905. .desktop-sidebar--collapsed .sidebar-context { display: none; }
  906. .desktop-sidebar--collapsed .sidebar-search-trigger { width: 42px; justify-content: center; margin-inline: auto; padding: 0; }
  907. .desktop-sidebar--collapsed .sidebar-search-trigger span { display: none; }
  908. .desktop-sidebar--collapsed .sidebar-primary-action { width: 42px; margin-inline: auto; }
  909. .desktop-sidebar--collapsed .sidebar-primary-action :deep(button) { width: 42px; justify-content: center; padding: 0; }
  910. .desktop-sidebar--collapsed .sidebar-primary-action :deep(button > span) { display: none; }
  911. .desktop-sidebar--collapsed .sidebar-feature-nav { align-items: center; padding: 8px 0; }
  912. .desktop-sidebar--collapsed .sidebar-feature-nav button { width: 42px; justify-content: center; margin-inline: 0; padding: 0; }
  913. .desktop-sidebar--collapsed .sidebar-feature-nav button span,
  914. .desktop-sidebar--collapsed .sidebar-account-switcher__chevron,
  915. .desktop-sidebar--collapsed .account-copy { display: none; }
  916. .desktop-sidebar--collapsed .sidebar-footer { display: flex; order: 2; margin-top: 0; flex-direction: column; align-items: center; padding: 0 8px 8px; }
  917. .desktop-sidebar--collapsed .sidebar-account-switcher { width: 42px; flex-direction: column; gap: 3px; padding: 0; border-top: 0; }
  918. .desktop-sidebar--collapsed .sidebar-account-switcher__main { width: 42px; min-height: 42px; flex: 0 0 42px; justify-content: center; padding: 0; }
  919. .desktop-sidebar--collapsed .sidebar-settings-trigger { width: 42px; min-width: 42px; height: 42px; padding: 0; }
  920. .desktop-sidebar--collapsed .profile-menu { right: auto; bottom: 0; left: calc(100% + 8px); width: 220px; }
  921. .workspace-main { position: relative; display: flex; min-width: 0; min-height: 0; flex-direction: column; overflow: hidden; background: var(--canvas); }
  922. .workspace-inspector { position: relative; width: min(390px, 34vw); min-width: 310px; min-height: 0; overflow: hidden; border-left: 1px solid var(--line); background: var(--surface); }
  923. .workspace-inspector__close { position: absolute; z-index: 5; top: 10px; right: 10px; }
  924. .menu-fade-enter-active, .menu-fade-leave-active { transition: opacity 120ms ease, transform 120ms var(--ease-out); }
  925. .menu-fade-enter-from, .menu-fade-leave-to { opacity: 0; transform: translateY(4px); }
  926. .inspector-slide-enter-active, .inspector-slide-leave-active { overflow: hidden; transition: width 180ms var(--ease-out), opacity 150ms ease; }
  927. .inspector-slide-enter-from, .inspector-slide-leave-to { width: 0; min-width: 0; opacity: 0; }
  928. @media (max-width: 900px) {
  929. .workspace-shell, .workspace-shell--collapsed { grid-template-columns: minmax(0, 1fr); grid-template-rows: 52px minmax(0, 1fr); }
  930. .mobile-header { display: flex; z-index: 24; grid-row: 1; align-items: center; justify-content: space-between; padding: max(5px, env(safe-area-inset-top)) 10px 5px; border-bottom: 1px solid var(--line); background: color-mix(in srgb, var(--surface) 94%, transparent); backdrop-filter: blur(18px); }
  931. .mobile-brand { padding: 0; border: 0; background: transparent; cursor: pointer; }
  932. .desktop-sidebar { display: none; }
  933. .workspace-main { grid-row: 2; }
  934. .drawer-scrim { display: block; position: fixed; z-index: 50; inset: 0; padding: 0; border: 0; background: var(--scrim); backdrop-filter: blur(2px); }
  935. .mobile-drawer { --sidebar-search-top: calc(max(9px, env(safe-area-inset-top)) + 49px); display: flex; position: fixed; z-index: 51; inset: 0 auto 0 0; width: min(304px, 88vw); min-height: 0; flex-direction: column; overflow: hidden; padding: max(9px, env(safe-area-inset-top)) 0 max(9px, env(safe-area-inset-bottom)); background: var(--surface); box-shadow: var(--shadow-float); transform: translateX(-102%); transition: transform 190ms var(--ease-out); }
  936. .mobile-drawer--open { transform: translateX(0); }
  937. .mobile-drawer__header { display: flex; min-height: 49px; align-items: center; justify-content: space-between; padding: 0 14px 5px 12px; }
  938. .mobile-drawer__context { margin-top: 2px; }
  939. .mobile-drawer--focused { padding-block: max(9px, env(safe-area-inset-top)) max(9px, env(safe-area-inset-bottom)); }
  940. .mobile-drawer--focused > .sidebar-search-trigger,
  941. .mobile-drawer--focused > .sidebar-primary-action,
  942. .mobile-drawer--focused > .sidebar-feature-nav,
  943. .mobile-drawer--focused > .sidebar-footer { display: none; }
  944. .mobile-drawer--focused .mobile-drawer__context { margin-top: 0; flex: 1; }
  945. .mobile-drawer__context .sidebar-context__body :deep(.resource-sidebar) { min-height: 0; flex: 1; }
  946. .mobile-drawer__footer { padding-inline: 10px; }
  947. .workspace-inspector { position: fixed; z-index: 45; inset: 52px 0 0 auto; width: min(440px, 100vw); min-width: 0; box-shadow: var(--shadow-float); }
  948. .inspector-slide-enter-from, .inspector-slide-leave-to { width: min(440px, 100vw); transform: translateX(100%); }
  949. }
  950. .drawer-fade-enter-active, .drawer-fade-leave-active { transition: opacity 160ms ease; }
  951. .drawer-fade-enter-from, .drawer-fade-leave-to { opacity: 0; }
  952. .sidebar-create-trigger{display:grid;width:34px;height:34px;flex:0 0 34px;place-items:center;padding:0;border:0;border-radius:9px;background:transparent;color:var(--text-muted);cursor:pointer}
  953. .sidebar-create-trigger:hover,.sidebar-create-trigger[aria-expanded="true"]{background:var(--surface-hover);color:var(--text-primary)}
  954. .workspace-shell--conversations .desktop-sidebar:not(.desktop-sidebar--collapsed) .sidebar-collapse{right:49px}
  955. .desktop-sidebar > .sidebar-create-trigger{position:absolute;top:12px;right:11px}
  956. .desktop-sidebar--collapsed > .sidebar-create-trigger{position:static;width:42px;height:36px;flex-basis:36px;align-self:center;margin:0 auto 4px}
  957. .mobile-drawer__actions{display:flex;align-items:center;gap:4px}
  958. .workspace-create-dismiss{position:fixed;inset:0;z-index:80}
  959. .workspace-create-menu{position:absolute;width:180px;padding:5px;border:1px solid var(--line);border-radius:11px;background:var(--surface-raised);box-shadow:var(--shadow-float)}
  960. .workspace-create-menu button{display:flex;width:100%;min-height:36px;align-items:center;gap:9px;padding:7px 10px;border:0;border-radius:7px;background:transparent;color:var(--text-primary);font:13px var(--font-ui);text-align:left;cursor:pointer}
  961. .workspace-create-menu button:hover,.workspace-create-menu button:focus-visible{outline:0;background:var(--surface-hover)}
  962. @media(max-width:767px){.workspace-tools-menu button,.workspace-settings-menu button,.workspace-settings-menu a{min-height:44px}}
  963. .bot-list-header{display:flex;align-items:center;gap:10px;padding:20px 20px 12px;min-height:74px}
  964. .bot-list-header__spacer{flex:1}
  965. .bot-logo-trigger{display:grid;place-items:center;padding:0;border:0;background:transparent;cursor:pointer;border-radius:50%}
  966. .bot-list-header .bot-list-toolbar-button{position:static;display:grid;place-items:center;width:42px;height:42px;min-height:42px;flex:0 0 42px;margin:0;padding:0;border:1px solid var(--line);border-radius:50%;background:var(--surface);color:var(--text-primary)}
  967. .workspace-shell--conversations .sidebar-context{margin-top:0}
  968. @media(max-width:900px){
  969. .workspace-shell--conversations{grid-template-rows:minmax(0,1fr);grid-template-columns:minmax(0,1fr)}
  970. .workspace-shell--conversations>.mobile-header,.workspace-shell--conversations>.mobile-drawer{display:none}
  971. .workspace-shell--conversations>.desktop-sidebar{display:flex;grid-row:1;border:0;padding-top:env(safe-area-inset-top)}
  972. .workspace-shell--conversations>.workspace-main{display:none;grid-row:1}
  973. .workspace-shell--conversation-open>.desktop-sidebar{display:none}
  974. .workspace-shell--conversation-open>.workspace-main{display:flex}
  975. }
  976. </style>
  977. <style scoped>
  978. .unread-entry {
  979. position: relative;
  980. display: grid;
  981. width: 36px;
  982. height: 36px;
  983. flex: 0 0 auto;
  984. place-items: center;
  985. padding: 0;
  986. border: 1px solid transparent;
  987. border-radius: 50%;
  988. background: transparent;
  989. color: var(--text-secondary);
  990. text-align: left;
  991. cursor: pointer;
  992. transition: background-color 140ms ease, border-color 140ms ease;
  993. }
  994. .sidebar-status-actions { position: absolute; top: 9px; right: 49px; display: flex; align-items: center; gap: 4px; }
  995. .bot-list-header .desktop-update-entry { width: 42px; height: 42px; }
  996. .bot-list-header .desktop-update-entry :deep(button) { border-color: var(--line); background: var(--surface); }
  997. .bot-list-header .desktop-update-entry--ready :deep(button) { background: rgba(var(--accent-rgb), .10); }
  998. .bot-list-header .unread-entry { position: relative; color: var(--text-secondary); }
  999. .unread-entry:hover, .unread-entry[aria-expanded="true"], .bot-list-header .unread-entry:hover, .bot-list-header .unread-entry[aria-expanded="true"] { background: var(--surface-hover); color: var(--text-primary); }
  1000. .unread-entry:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
  1001. .unread-entry__count { position: absolute; top: -3px; right: -3px; display: grid; min-width: 18px; height: 18px; place-items: center; padding: 0 4px; border: 2px solid var(--surface); border-radius: 20px; background: var(--accent); color: var(--text-on-solid); font-size: 10px; font-weight: 600; line-height: 14px; white-space: nowrap; font-variant-numeric: tabular-nums; }
  1002. .desktop-sidebar--collapsed .sidebar-brand-row { flex-direction: column; gap: 8px; padding: 9px 13px; }
  1003. .desktop-sidebar--collapsed .sidebar-status-actions { position: static; flex-direction: column; }
  1004. .desktop-sidebar--collapsed .unread-entry { position: relative; top: auto; right: auto; }
  1005. @media (max-width: 767px) { .sidebar-status-actions, .unread-entry, .bot-list-header .unread-entry { display: none; } }
  1006. </style>