ChatView.vue 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486
  1. <script setup lang="ts">
  2. import { computed, nextTick, onBeforeUnmount, onMounted, ref, watch } from 'vue'
  3. import { useRoute, useRouter } from 'vue-router'
  4. import AppIcon from '@/components/common/AppIcon.vue'
  5. import YaoYaoSidebarIcon from '@/components/common/YaoYaoSidebarIcon.vue'
  6. import ChoiceDialog from '@/components/common/ChoiceDialog.vue'
  7. import type { ChoiceOption } from '@/components/common/types'
  8. import ComposerShell from '@/components/composer/ComposerShell.vue'
  9. import type { ComposerOption, ComposerReference, ComposerSubmit } from '@/components/composer/types'
  10. import PreviewInspector from '@/components/library/PreviewInspector.vue'
  11. import PreviewModal from '@/components/library/PreviewModal.vue'
  12. import ImagePreviewLightbox from '@/components/library/ImagePreviewLightbox.vue'
  13. import type { PreviewMedia } from '@/components/library/ImagePreviewLightbox.vue'
  14. import type { UiLibraryItem } from '@/components/library/types'
  15. import { mediaItemsFromMessages, mediaUrlIdentity, previewItemFromUrl } from '@/components/library/mediaSequence'
  16. import MessageTimeline from '@/components/messages/MessageTimeline.vue'
  17. import SessionOutline from '@/components/messages/SessionOutline.vue'
  18. import type { UiMessage } from '@/components/messages/types'
  19. import ResourceSidebar from '@/components/app/ResourceSidebar.vue'
  20. import WorkspaceView from '@/components/workspace/WorkspaceView.vue'
  21. import { chatInteraction, chatMessagesToUi, sessionSidebarItem } from '@/components/workspace/viewModels'
  22. import { consumeLibraryItemForComposer, loadComposerFile } from '@/components/workspace/pendingComposer'
  23. import { readAgentShowThinking, writeAgentShowThinking } from '@/utils/sessionPreferences'
  24. import { useAuthStore } from '@/stores/auth'
  25. import { useChatStore } from '@/stores/chat'
  26. import { getSession } from '@/api/sessions'
  27. const auth = useAuthStore()
  28. const chat = useChatStore()
  29. const route = useRoute()
  30. const router = useRouter()
  31. const search = ref('')
  32. const quoted = ref<UiMessage | null>(null)
  33. const preview = ref<UiLibraryItem | null>(null)
  34. const filePreview = ref<UiLibraryItem | null>(null)
  35. const mediaPreviewIndex = ref<number | null>(null)
  36. const outlineOpen = ref(false)
  37. const modelDialog = ref(false)
  38. const showThinking = ref(true)
  39. const queueMode = ref(false)
  40. const actionSessionId = ref('')
  41. const renaming = ref(false)
  42. const renameValue = ref('')
  43. const actionMenuPosition = ref({ x: 8, y: 8 })
  44. const composer = ref<InstanceType<typeof ComposerShell> | null>(null)
  45. const timeline = ref<InstanceType<typeof MessageTimeline> | null>(null)
  46. const headerSessionMenuButton = ref<HTMLButtonElement | null>(null)
  47. const restoringRouteProfile = ref('')
  48. const sessions = computed(() => [...chat.sessions]
  49. .filter(session => !['cron', 'ios_group'].includes(session.source))
  50. .filter(session => !search.value.trim() || `${session.title} ${session.preview || ''}`.toLocaleLowerCase().includes(search.value.trim().toLocaleLowerCase())))
  51. const agentNames = computed(() => new Map(auth.profiles.map(profile => [
  52. profile.name,
  53. profile.agentName || profile.displayName || profile.name,
  54. ])))
  55. const sidebarItems = computed(() => sessions.value.map(session => sessionSidebarItem(
  56. session,
  57. chat.unreadCounts[session.id] ?? 0,
  58. agentNames.value.get(session.profile || auth.activeProfile?.name || ''),
  59. )))
  60. const messages = computed(() => chatMessagesToUi(chat.messages, profile => profile ? agentNames.value.get(profile) : undefined))
  61. const conversationMediaItems = computed(() => mediaItemsFromMessages(messages.value))
  62. const lightboxMedia = computed(() => conversationMediaItems.value.map(item => ({ url: item.previewUrl || item.downloadUrl || '', name: item.name, type: item.kind as 'image' | 'video' })).filter(item => item.url))
  63. const activeSession = computed(() => chat.activeSession)
  64. const actionSession = computed(() => chat.sessions.find(session => session.id === actionSessionId.value))
  65. const connected = computed(() => ['connected', 'ready'].includes(chat.connectionState))
  66. const interaction = computed(() => chatInteraction(chat.pendingApproval, chat.pendingClarification))
  67. const reference = computed<ComposerReference | null>(() => quoted.value ? { id: quoted.value.id, content: quoted.value.content, author: quoted.value.author } : null)
  68. const forkSourceTitle = computed(() => {
  69. const parentId = activeSession.value?.parentSessionId
  70. if (!parentId) return ''
  71. return chat.sessions.find(session => session.id === parentId && session.profile === activeSession.value?.profile)?.title || parentId
  72. })
  73. const modelOptions = computed<ChoiceOption[]>(() => chat.models.map(model => ({ id: `${model.provider}:${model.id}`, label: model.name || model.id, description: model.provider })))
  74. const selectedModelId = computed(() => chat.selectedModel ? `${chat.selectedModel.provider}:${chat.selectedModel.id}` : '')
  75. const reasoningOptions: ChoiceOption[] = [
  76. { id: '', label: '默认', description: '使用模型或 Profile 的默认强度' },
  77. { id: 'none', label: '关闭', description: '不使用额外推理' },
  78. { id: 'low', label: '低', description: '更快的轻量推理' },
  79. { id: 'medium', label: '中', description: '速度与深度平衡' },
  80. { id: 'high', label: '高', description: '更深入地分析复杂问题' },
  81. { id: 'xhigh', label: '极高', description: '适用于最复杂的任务' },
  82. ]
  83. const reasoningComposerOptions = computed<ComposerOption[]>(() => reasoningOptions.map(option => ({
  84. id: option.id,
  85. label: option.label,
  86. detail: option.description,
  87. })))
  88. const reasoningLabel = computed(() => reasoningOptions.find(option => option.id === (chat.reasoningEffort || ''))?.label || '默认')
  89. const actionMenuStyle = computed(() => ({ left: `${actionMenuPosition.value.x}px`, top: `${actionMenuPosition.value.y}px` }))
  90. function routeProfile(): string {
  91. const value = typeof route.query.profile === 'string' ? route.query.profile : ''
  92. return auth.profiles.some(profile => profile.name === value) ? value : ''
  93. }
  94. function sessionLocation(id: string, profile: string) {
  95. return { path: `/chat/${encodeURIComponent(id)}`, query: { profile } }
  96. }
  97. async function findLegacySessionProfile(sessionId: string): Promise<string> {
  98. for (const profile of auth.profiles) {
  99. try {
  100. const session = await getSession(sessionId, profile.name)
  101. if (session.id === sessionId) return profile.name
  102. } catch { /* Try the next profile: 9119 returns 404 for a foreign session. */ }
  103. }
  104. return auth.activeProfile?.name || ''
  105. }
  106. async function ensureRouteProfile(profile: string): Promise<void> {
  107. if (!profile || auth.activeProfile?.name === profile) return
  108. chat.switchProfile(profile)
  109. restoringRouteProfile.value = profile
  110. auth.selectProfile(profile)
  111. await nextTick()
  112. }
  113. async function refreshSessions() {
  114. const requestedId = typeof route.params.sessionId === 'string' ? route.params.sessionId : ''
  115. const profile = routeProfile() || (requestedId ? await findLegacySessionProfile(requestedId) : auth.activeProfile?.name || '')
  116. if (profile && auth.activeProfile?.name !== profile) {
  117. if (requestedId) await router.replace(sessionLocation(requestedId, profile))
  118. await ensureRouteProfile(profile)
  119. }
  120. // The session route is the authoritative navigation target. A secondary
  121. // unread-count request must never prevent its history from being restored.
  122. await chat.loadSessions(profile)
  123. if (requestedId && chat.activeSessionId !== requestedId) await chat.selectSession(requestedId, profile)
  124. if (requestedId && profile && routeProfile() !== profile) await router.replace(sessionLocation(requestedId, profile))
  125. void chat.loadUnread(profile).catch(() => undefined)
  126. }
  127. async function chooseSession(id: string) {
  128. outlineOpen.value = false
  129. preview.value = null
  130. const session = chat.sessions.find(item => item.id === id)
  131. const profile = session?.profile || auth.activeProfile?.name || 'default'
  132. await router.push(sessionLocation(id, profile))
  133. await ensureRouteProfile(profile)
  134. if (chat.activeProfileName !== profile) await chat.loadSessions(profile)
  135. await chat.selectSession(id, profile)
  136. await chat.markRead(id, profile).catch(() => undefined)
  137. quoted.value = null
  138. }
  139. async function createSession() {
  140. outlineOpen.value = false
  141. preview.value = null
  142. const id = chat.createSession(auth.activeProfile?.name)
  143. await router.push(sessionLocation(id, auth.activeProfile?.name || 'default'))
  144. }
  145. async function send(payload: ComposerSubmit) {
  146. try {
  147. await chat.send(payload.text, payload.files, queueMode.value ? 'queue' : chat.isStreaming ? 'steer' : 'submit')
  148. composer.value?.clearAfterSend()
  149. } catch { /* store exposes the error and the composer keeps its draft */ }
  150. }
  151. function openAttachment(attachment: NonNullable<UiMessage['attachments']>[number]) {
  152. const item = previewItemFromUrl(attachment.name, attachment.url || '', attachment.id, attachment.kind)
  153. item.size = attachment.size
  154. if (item.kind === 'image' || item.kind === 'video') openMedia(item)
  155. else { outlineOpen.value = false; preview.value = item }
  156. }
  157. function openMedia(item: UiLibraryItem) {
  158. const target = mediaUrlIdentity(item.previewUrl || item.downloadUrl || '')
  159. const index = lightboxMedia.value.findIndex(media => mediaUrlIdentity(media.url) === target)
  160. mediaPreviewIndex.value = index >= 0 ? index : null
  161. }
  162. function openLocalFile({ name, url }: { name: string; url: string }) {
  163. const item = previewItemFromUrl(name, url)
  164. if (item.kind === 'image' || item.kind === 'video') openMedia(item)
  165. else { outlineOpen.value = false; filePreview.value = item }
  166. }
  167. async function addPreviewToComposer(item: UiLibraryItem) {
  168. const file = await loadComposerFile(item)
  169. if (!file || !composer.value) return
  170. composer.value.attachFiles([file])
  171. preview.value = null
  172. filePreview.value = null
  173. mediaPreviewIndex.value = null
  174. await nextTick()
  175. composer.value?.focus()
  176. }
  177. async function addMediaToComposer(media: PreviewMedia) {
  178. await addPreviewToComposer(previewItemFromUrl(media.name, media.url, `preview:${media.url}`, media.type))
  179. }
  180. async function selectModel(id: string) {
  181. const [provider, ...rest] = id.split(':')
  182. const model = chat.models.find(item => item.provider === provider && item.id === rest.join(':'))
  183. if (model) await chat.setModel(model)
  184. modelDialog.value = false
  185. }
  186. function selectReasoning(id: string) {
  187. chat.reasoningEffort = id || undefined
  188. }
  189. async function toggleFastMode(enabled: boolean) {
  190. try { await chat.setFastMode(enabled) } catch { /* store restores the acknowledged state */ }
  191. }
  192. function restoreShowThinking(profile = auth.activeProfile?.name || 'default') {
  193. showThinking.value = readAgentShowThinking(auth.user?.id ?? 'local', profile)
  194. }
  195. function toggleShowThinking() {
  196. showThinking.value = !showThinking.value
  197. writeAgentShowThinking(auth.user?.id ?? 'local', auth.activeProfile?.name || 'default', showThinking.value)
  198. }
  199. function openSessionActions(id: string, event?: MouseEvent) {
  200. actionSessionId.value = id
  201. const session = chat.sessions.find(item => item.id === id)
  202. renameValue.value = session?.title || ''
  203. renaming.value = false
  204. const menuWidth = 208
  205. const menuHeight = 176
  206. const inset = 8
  207. const anchor = event?.currentTarget instanceof HTMLElement ? event.currentTarget.getBoundingClientRect() : null
  208. const requestedX = event?.type === 'contextmenu' ? event.clientX : anchor ? anchor.right - menuWidth : window.innerWidth - menuWidth - 14
  209. const requestedY = event?.type === 'contextmenu' ? event.clientY : anchor ? anchor.bottom + 5 : 46
  210. actionMenuPosition.value = {
  211. x: Math.max(inset, Math.min(requestedX, window.innerWidth - menuWidth - inset)),
  212. y: Math.max(inset, Math.min(requestedY, window.innerHeight - menuHeight - inset)),
  213. }
  214. }
  215. function closeSessionActions() {
  216. actionSessionId.value = ''
  217. renaming.value = false
  218. }
  219. function handleSessionActionPointer(event: PointerEvent) {
  220. if (!actionSessionId.value || (event.target as HTMLElement).closest('.session-actions')) return
  221. closeSessionActions()
  222. }
  223. function handleSessionActionKey(event: KeyboardEvent) {
  224. if (event.key === 'Escape' && actionSessionId.value) closeSessionActions()
  225. }
  226. async function saveRename() {
  227. const session = chat.sessions.find(item => item.id === actionSessionId.value)
  228. if (!session || !renameValue.value.trim()) return
  229. await chat.renameSession(session.id, renameValue.value.trim(), session.profile)
  230. closeSessionActions()
  231. }
  232. async function toggleSessionPinned() {
  233. const session = actionSession.value
  234. if (!session) return
  235. await chat.setSessionPinned(session.id, !session.pinned, session.profile)
  236. closeSessionActions()
  237. }
  238. async function openSessionOutline() {
  239. const session = actionSession.value
  240. if (!session) return
  241. closeSessionActions()
  242. if (session.id !== chat.activeSessionId || session.profile !== chat.activeProfileName) await chooseSession(session.id)
  243. preview.value = null
  244. outlineOpen.value = true
  245. }
  246. function closeInspector() {
  247. const restoreMenuFocus = outlineOpen.value
  248. preview.value = null
  249. outlineOpen.value = false
  250. if (restoreMenuFocus) void nextTick(() => headerSessionMenuButton.value?.focus())
  251. }
  252. function navigateOutline(target: { messageId: string; anchorId: string }) {
  253. timeline.value?.scrollToAnchor(target.messageId, target.anchorId)
  254. if (window.matchMedia('(max-width: 900px)').matches) closeInspector()
  255. }
  256. async function deleteSession() {
  257. const session = chat.sessions.find(item => item.id === actionSessionId.value)
  258. if (!session) return
  259. await chat.removeSession(session.id, session.profile)
  260. closeSessionActions()
  261. if (route.params.sessionId === session.id) await router.replace('/chat')
  262. }
  263. async function branch() {
  264. const id = await chat.branchSession()
  265. if (id) await router.push(sessionLocation(id, chat.activeProfileName || auth.activeProfile?.name || 'default'))
  266. }
  267. async function revealSourceMessage() {
  268. const messageId = typeof route.query.message === 'string' ? route.query.message : ''
  269. if (!messageId) return
  270. await nextTick()
  271. for (let attempt = 0; attempt < 10; attempt += 1) {
  272. if (timeline.value?.scrollToMessage(messageId)) return
  273. if (!chat.hasMoreBefore) return
  274. await chat.loadOlder()
  275. await nextTick()
  276. }
  277. }
  278. onMounted(async () => {
  279. restoreShowThinking()
  280. document.addEventListener('pointerdown', handleSessionActionPointer)
  281. document.addEventListener('keydown', handleSessionActionKey)
  282. await refreshSessions()
  283. await Promise.allSettled([chat.loadModels(auth.activeProfile?.name), chat.connect()])
  284. await revealSourceMessage()
  285. const pendingFile = await consumeLibraryItemForComposer()
  286. if (pendingFile) composer.value?.attachFiles([pendingFile])
  287. })
  288. onBeforeUnmount(() => {
  289. document.removeEventListener('pointerdown', handleSessionActionPointer)
  290. document.removeEventListener('keydown', handleSessionActionKey)
  291. chat.disconnect()
  292. })
  293. watch(() => auth.activeProfile?.name, async (profile, previous) => {
  294. if (!profile || profile === previous) return
  295. restoreShowThinking(profile)
  296. outlineOpen.value = false
  297. preview.value = null
  298. if (restoringRouteProfile.value === profile) {
  299. restoringRouteProfile.value = ''
  300. return
  301. }
  302. chat.switchProfile(profile)
  303. const requestedId = typeof route.params.sessionId === 'string' ? route.params.sessionId : ''
  304. if (requestedId && routeProfile() === profile) {
  305. await Promise.allSettled([chat.loadSessions(profile), chat.loadModels(profile), chat.loadUnread(profile), chat.connect()])
  306. await chat.selectSession(requestedId, profile)
  307. return
  308. }
  309. await router.replace({ path: '/chat', query: { profile } })
  310. await Promise.allSettled([chat.loadSessions(profile), chat.loadModels(profile), chat.loadUnread(profile), chat.connect()])
  311. })
  312. watch(() => chat.activeSessionId, async id => {
  313. const profile = chat.activeProfileName || auth.activeProfile?.name || ''
  314. if (!id || (route.params.sessionId === id && routeProfile() === profile)) return
  315. await router.replace(sessionLocation(id, profile))
  316. })
  317. </script>
  318. <template>
  319. <WorkspaceView sidebar-title="对话" :sidebar-subtitle="`${sessions.length} 个会话`" :inspector-open="!!preview || outlineOpen" :inspector-close-label="outlineOpen ? '关闭会话大纲' : '关闭预览'" @close-inspector="closeInspector">
  320. <template #sidebar-action>
  321. <button class="sidebar-primary-action" type="button" title="新建聊天" aria-label="新建聊天" @click="createSession">
  322. <YaoYaoSidebarIcon name="add" />
  323. <span>新建聊天</span>
  324. </button>
  325. </template>
  326. <template #sidebar>
  327. <ResourceSidebar
  328. :items="sidebarItems"
  329. :active-id="chat.activeSessionId"
  330. :loading="chat.isLoading"
  331. :search="search"
  332. single-line
  333. :has-more="chat.hasMoreSessions"
  334. :loading-more="chat.isLoadingMoreSessions"
  335. search-placeholder="搜索会话"
  336. empty-title="还没有会话"
  337. empty-description="新建会话后,从输入框开始聊天。"
  338. @search="search = $event"
  339. @load-more="chat.loadMoreSessions(auth.activeProfile?.name)"
  340. @select="chooseSession"
  341. @more="openSessionActions"
  342. @context-menu="openSessionActions"
  343. />
  344. </template>
  345. <div class="chat-workspace">
  346. <MessageTimeline
  347. ref="timeline"
  348. :messages="messages"
  349. :title="activeSession?.title || '新会话'"
  350. :subtitle="activeSession ? `${activeSession.profile || auth.activeProfile?.name || ''} · ${activeSession.model || chat.selectedModel?.name || '默认模型'}` : '选择会话或直接开始输入'"
  351. :loading="chat.activeRouteState?.isLoadingHistory || chat.isLoading"
  352. :loading-older="chat.activeRouteState?.isLoadingHistory"
  353. :has-older="chat.hasMoreBefore"
  354. :connected="connected"
  355. :synced="chat.historySynced"
  356. :show-tools="showThinking"
  357. :show-assistant-identity="false"
  358. :interaction="interaction"
  359. empty-logo
  360. transparent-header
  361. :fork-source-title="forkSourceTitle"
  362. @load-older="chat.loadOlder"
  363. @quote="quoted = $event"
  364. @branch="branch"
  365. @preview="openAttachment"
  366. @preview-file="openLocalFile"
  367. @approve="interaction && chat.respondToApproval(interaction.id, $event)"
  368. @clarify="interaction && chat.respondToClarification(interaction.id, $event)"
  369. >
  370. <template #header-actions>
  371. <button v-if="activeSession" ref="headerSessionMenuButton" class="icon-button header-session-menu" type="button" title="会话操作" aria-label="会话操作" @click="openSessionActions(activeSession.id, $event)"><AppIcon name="dots" :size="18" /></button>
  372. </template>
  373. </MessageTimeline>
  374. <p v-if="chat.error" class="chat-error" role="alert"><AppIcon name="alert" :size="13" />{{ chat.error }}</p>
  375. <ComposerShell
  376. ref="composer"
  377. mode="chat"
  378. :draft-key="`${auth.user?.id || 'local'}:${auth.activeProfile?.name || 'default'}:${chat.activeSessionId || 'new'}`"
  379. :disabled="chat.connectionState === 'failed'"
  380. :streaming="chat.isStreaming"
  381. :sending="chat.isSending"
  382. :model-label="chat.selectedModel?.name || '选择模型'"
  383. :fast-mode="chat.fastMode"
  384. :fast-mode-disabled="!chat.activeSessionId"
  385. :reasoning-effort="reasoningLabel"
  386. :reasoning-value="chat.reasoningEffort || ''"
  387. :reasoning-options="reasoningComposerOptions"
  388. :context-used="chat.contextUsage?.contextTokens || chat.contextUsage?.totalTokens || 0"
  389. :context-limit="chat.contextUsage?.contextLimit || 262144"
  390. :queue-mode="queueMode || chat.isQueued"
  391. :tool-trace-visible="showThinking"
  392. :reference="reference"
  393. :slash-commands="[
  394. { id: 'fork', label: 'fork', detail: '从当前会话创建分支' },
  395. { id: 'compact', label: 'compact', detail: '压缩当前会话上下文' },
  396. { id: 'model', label: 'model', detail: '切换模型' },
  397. ]"
  398. @send="send"
  399. @stop="chat.interrupt"
  400. @model-click="modelDialog = true"
  401. @fast-mode-toggle="toggleFastMode"
  402. @reasoning-change="selectReasoning"
  403. @settings-click="toggleShowThinking"
  404. @queue-toggle="queueMode = !queueMode"
  405. @clear-reference="quoted = null"
  406. />
  407. </div>
  408. <template #inspector>
  409. <SessionOutline v-if="outlineOpen" :messages="messages" :has-older="chat.hasMoreBefore" @navigate="navigateOutline" />
  410. <PreviewInspector v-else-if="preview" :item="preview" @close="preview = null" @add-to-composer="addPreviewToComposer" />
  411. </template>
  412. </WorkspaceView>
  413. <PreviewModal v-if="filePreview" :item="filePreview" :items="conversationMediaItems" @close="filePreview = null" @add-to-composer="addPreviewToComposer" @source="filePreview = null" />
  414. <ImagePreviewLightbox v-model="mediaPreviewIndex" :images="lightboxMedia" @add="addMediaToComposer" />
  415. <ChoiceDialog :open="modelDialog" title="选择模型" :options="modelOptions" :selected-id="selectedModelId" @close="modelDialog = false" @select="selectModel" />
  416. <Teleport to="body">
  417. <Transition name="session-menu">
  418. <section v-if="actionSessionId" class="session-actions" :style="actionMenuStyle" role="menu" aria-label="会话操作" @contextmenu.prevent>
  419. <template v-if="renaming">
  420. <label>会话名称<input v-model="renameValue" maxlength="120" autofocus @keydown.enter="saveRename" /></label>
  421. <div><button class="quiet-button" type="button" @click="renaming = false">取消</button><button class="solid-button" type="button" @click="saveRename">保存</button></div>
  422. </template>
  423. <template v-else>
  424. <button class="action-row" role="menuitem" type="button" @click="openSessionOutline"><AppIcon name="menu" :size="14" />会话大纲</button>
  425. <button class="action-row" role="menuitem" type="button" @click="toggleSessionPinned"><AppIcon :name="actionSession?.pinned ? 'pin-off' : 'pin'" :size="14" />{{ actionSession?.pinned ? '取消置顶' : '置顶会话' }}</button>
  426. <button class="action-row" role="menuitem" type="button" @click="renaming = true"><AppIcon name="edit" :size="14" />重命名</button>
  427. <button class="action-row danger" role="menuitem" type="button" @click="deleteSession"><AppIcon name="trash" :size="14" />删除会话</button>
  428. </template>
  429. </section>
  430. </Transition>
  431. </Teleport>
  432. </template>
  433. <style scoped>
  434. .chat-workspace { display: flex; min-width: 0; min-height: 0; flex: 1; flex-direction: column; }
  435. .sidebar-primary-action { display: flex; width: 100%; min-height: 40px; align-items: center; gap: 10px; padding: 0 11px; border: 0; border-radius: 9px; background: transparent; color: var(--text-primary); cursor: pointer; font-size: 12px; font-weight: 610; text-align: left; transition: background-color 120ms ease; }
  436. .sidebar-primary-action:hover, .sidebar-primary-action:focus-visible { background: var(--surface-hover); outline: 0; }
  437. .sidebar-primary-action:focus-visible { box-shadow: inset 0 0 0 1px var(--line-strong); }
  438. .header-session-menu { color: var(--text-muted); background: transparent; }.header-session-menu:hover { color: var(--text-primary); background: var(--surface-soft); }
  439. .chat-error { display: flex; width: min(760px, calc(100% - 32px)); margin: 0 auto 4px; align-items: center; gap: 6px; color: var(--danger); font-size: 9px; }
  440. .session-actions { position: fixed; z-index: 205; width: 208px; box-sizing: border-box; padding: 6px; border: 1px solid var(--line); border-radius: 11px; background: var(--surface-raised); box-shadow: 0 12px 34px rgba(0,0,0,.16); }.action-row { display: flex; width: 100%; min-height: 34px; align-items: center; gap: 8px; padding: 0 9px; border: 0; border-radius: 7px; background: transparent; color: var(--text-secondary); cursor: pointer; font-size: 11px; text-align: left; }.action-row:hover, .action-row:focus-visible { outline: 0; background: var(--surface-soft); color: var(--text-primary); }.action-row.danger { color: var(--danger); }.session-actions label { display: flex; flex-direction: column; gap: 6px; padding: 4px; color: var(--text-muted); font-size: 9px; }.session-actions input { width: 100%; height: 32px; box-sizing: border-box; padding: 0 8px; border: 1px solid var(--line); border-radius: 7px; outline: 0; background: var(--surface-soft); color: var(--text-primary); font-size: 11px; }.session-actions input:focus { border-color: var(--line-strong); box-shadow: 0 0 0 3px var(--focus-ring); }.session-actions > div { display: flex; justify-content: flex-end; gap: 5px; margin-top: 7px; padding: 0 4px 3px; }.session-actions :deep(.quiet-button), .session-actions :deep(.solid-button) { min-height: 29px; padding-inline: 10px; font-size: 10px; }
  441. .session-menu-enter-active, .session-menu-leave-active { transition: opacity 100ms ease, transform 120ms var(--ease-out); transform-origin: top right; }.session-menu-enter-from, .session-menu-leave-to { opacity: 0; transform: translateY(-3px) scale(.98); }
  442. @media (prefers-reduced-motion: reduce) { .sidebar-primary-action, .session-menu-enter-active, .session-menu-leave-active { transition: none; } }
  443. </style>