WorkspaceMessageTimeline.vue 38 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562
  1. <script setup lang="ts">
  2. import { computed, nextTick, onBeforeUnmount, onMounted, ref, watch } from 'vue'
  3. import AppIcon from '@/components/common/AppIcon.vue'
  4. import AgentAvatar from '@/components/common/AgentAvatar.vue'
  5. import TeamAvatar from '@/components/common/TeamAvatar.vue'
  6. import EmptyState from '@/components/common/EmptyState.vue'
  7. import TypingIndicator from '@/components/common/TypingIndicator.vue'
  8. import InteractionCard from '../messages/InteractionCard.vue'
  9. import WorkspaceApprovalCard from './WorkspaceApprovalCard.vue'
  10. import TaskResultNotice from './TaskResultNotice.vue'
  11. import MarkdownContent from '../messages/MarkdownContent.vue'
  12. import ToolTrace from '../messages/ToolTrace.vue'
  13. import TurnTrace from '../messages/TurnTrace.vue'
  14. import type { UiInteraction, UiLocalFileLink, UiMessage } from '../messages/types'
  15. import { buildMessageTimelineRows } from '@/utils/turnTrace'
  16. import { copyTextToClipboard } from '@/utils/clipboard'
  17. import { displayContentForMessage } from '@/utils/messageDisplay'
  18. import { formatMessageTime } from '@/utils/messageTime'
  19. type AvatarState = 'idle' | 'working' | 'waiting' | 'loading' | 'success' | 'failure' | 'notifying'
  20. type HeaderAvatarMember = { name: string; avatar?: string; state?: AvatarState; activityKey?: number }
  21. const props = withDefaults(defineProps<{
  22. messages: UiMessage[]
  23. identity: string
  24. title?: string
  25. subtitle?: string
  26. headerAvatarName?: string
  27. headerAvatar?: string
  28. headerAvatarKind?: 'agent' | 'team'
  29. headerAvatarMembers?: HeaderAvatarMember[]
  30. headerAvatarState?: AvatarState
  31. headerAvatarActivityKey?: string | number
  32. emptyTitle?: string
  33. emptyDescription?: string
  34. emptyLogo?: boolean
  35. transparentHeader?: boolean
  36. forkSourceTitle?: string
  37. loading?: boolean
  38. loadingOlder?: boolean
  39. hasOlder?: boolean
  40. showTools?: boolean
  41. showAssistantIdentity?: boolean
  42. interaction?: UiInteraction | null
  43. interactionBusy?: boolean
  44. interactionError?: string
  45. approvalAgentName?: string
  46. mentionNames?: string[]
  47. agentAvatars?: Record<string, string>
  48. agentStates?: Record<string, AvatarState>
  49. thinking?: boolean
  50. allowBranch?: boolean
  51. readOnly?: boolean
  52. }>(), {
  53. title: '',
  54. subtitle: '',
  55. headerAvatarName: '',
  56. headerAvatar: '',
  57. headerAvatarKind: 'agent',
  58. headerAvatarMembers: () => [],
  59. headerAvatarState: 'idle',
  60. emptyTitle: '开始一段新对话',
  61. emptyDescription: '从下方输入框发送消息,或选择左侧的历史会话。',
  62. emptyLogo: false,
  63. transparentHeader: false,
  64. forkSourceTitle: '',
  65. loading: false,
  66. loadingOlder: false,
  67. hasOlder: false,
  68. showTools: true,
  69. showAssistantIdentity: true,
  70. interaction: null,
  71. mentionNames: () => [],
  72. agentAvatars: () => ({}),
  73. agentStates: () => ({}),
  74. thinking: false,
  75. allowBranch: true,
  76. readOnly: false,
  77. })
  78. const emit = defineEmits<{
  79. loadOlder: []
  80. quote: [message: UiMessage]
  81. branch: [message: UiMessage]
  82. preview: [attachment: NonNullable<UiMessage['attachments']>[number]]
  83. previewFile: [file: UiLocalFileLink]
  84. approvalChoice: [choice: 'once' | 'deny' | 'auto']
  85. clarify: [text: string]
  86. }>()
  87. const scroller = ref<HTMLElement | null>(null)
  88. const pinnedToBottom = ref(true)
  89. const showJump = ref(false)
  90. const copiedMessageId = ref('')
  91. const copyFailedMessageId = ref('')
  92. // Like OpenMausBot, mount the tail first and explicitly expand older content.
  93. const windowStart = ref(0)
  94. const windowSize = 120
  95. const windowedMessages = computed(() => props.messages.slice(windowStart.value))
  96. const messageBodies = new WeakMap<UiMessage, UiMessage>()
  97. const timelineRows = computed(() => buildMessageTimelineRows(windowedMessages.value, messageBodies))
  98. const mentionSignature = computed(() => props.mentionNames.join("\u0000"))
  99. let transcriptObserver: ResizeObserver | undefined
  100. let followFrame: number | undefined
  101. let previousTop = 0
  102. let touchY = 0
  103. let historyAnchor: { id: string; top: number } | undefined
  104. function stopFollowing() { pinnedToBottom.value = false }
  105. function captureHistoryAnchor() {
  106. const el = scroller.value
  107. const row = el && [...el.querySelectorAll<HTMLElement>('[data-message-id]')].find(row => row.getBoundingClientRect().bottom > el.getBoundingClientRect().top)
  108. if (row) historyAnchor = { id: row.dataset.messageId!, top: row.getBoundingClientRect().top }
  109. stopFollowing()
  110. }
  111. async function restoreHistoryAnchor() {
  112. await nextTick()
  113. const el = scroller.value, anchor = historyAnchor
  114. if (!el || !anchor) return
  115. const row = el.querySelector<HTMLElement>(`[data-message-id="${CSS.escape(anchor.id)}"]`)
  116. if (row) el.scrollTop += row.getBoundingClientRect().top - anchor.top
  117. previousTop = el.scrollTop; historyAnchor = undefined
  118. }
  119. async function showEarlier() {
  120. captureHistoryAnchor()
  121. if (windowStart.value > 0) { windowStart.value = Math.max(0, windowStart.value - windowSize); await restoreHistoryAnchor() }
  122. else emit('loadOlder')
  123. }
  124. watch(() => props.identity, () => {
  125. windowStart.value = Math.max(0, props.messages.length - windowSize)
  126. pinnedToBottom.value = true; showJump.value = false; historyAnchor = undefined
  127. void nextTick(() => scheduleFollow())
  128. }, { immediate: true })
  129. watch(() => props.messages[0]?.id, (id, oldId) => {
  130. if (!oldId || id === oldId) return
  131. const offset = props.messages.findIndex(message => message.id === oldId)
  132. if (offset > 0 && windowStart.value > 0) windowStart.value += offset
  133. if (historyAnchor) void restoreHistoryAnchor()
  134. })
  135. function scheduleFollow() {
  136. if (!pinnedToBottom.value || followFrame !== undefined) return
  137. followFrame = requestAnimationFrame(() => {
  138. followFrame = undefined
  139. if (pinnedToBottom.value) scrollToBottom('auto')
  140. })
  141. }
  142. const showThinkingIndicator = computed(() => {
  143. return props.thinking
  144. })
  145. const thinkingAgent = computed(() =>
  146. [...props.messages].reverse().find(message => message.role === 'assistant' && message.status === 'streaming')
  147. ?? [...props.messages].reverse().find(message => message.role === 'assistant'),
  148. )
  149. const thinkingAvatarName = computed(() => thinkingAgent.value?.author || thinkingAgent.value?.profile || '夭')
  150. const thinkingAvatar = computed(() => {
  151. const profile = thinkingAgent.value?.profile
  152. return profile ? props.agentAvatars[profile] || '' : ''
  153. })
  154. let copyResetTimer: number | undefined
  155. const formatTime = formatMessageTime
  156. function avatarState(message: UiMessage): 'idle' | 'working' | 'waiting' | 'loading' | 'success' | 'failure' | 'notifying' {
  157. if (message.status === 'streaming') return (message.profile && props.agentStates[message.profile]) || 'working'
  158. if (message.status === 'pending' || message.status === 'unknown-receipt') return 'waiting'
  159. if (message.status === 'failed') return 'failure'
  160. const outcome = message.profile ? props.agentStates[message.profile] : undefined
  161. if ((outcome === 'success' || outcome === 'failure') && [...props.messages].reverse().find(m => m.profile === message.profile && m.role === 'assistant')?.id === message.id) return outcome
  162. return 'idle'
  163. }
  164. function delegationSummary(metadata?: Record<string, unknown>): string {
  165. const total = Number(metadata?.task_count ?? 0)
  166. const completed = Number(metadata?.completed_count ?? 0)
  167. const failed = Number(metadata?.failed_count ?? 0)
  168. const seconds = Number(metadata?.duration_seconds ?? 0)
  169. const duration = seconds > 0 ? ` · ${seconds < 60 ? `${Math.round(seconds)} 秒` : `${Math.floor(seconds / 60)} 分 ${Math.round(seconds % 60)} 秒`}` : ''
  170. return `${total || completed + failed || 1} 个子任务 · ${completed} 已完成${failed ? ` · ${failed} 失败` : ''}${duration}`
  171. }
  172. function systemSummary(content: string): string {
  173. const model = content.match(/(?:changed to|切换为)\s*([^\s,。\]]+?)(?=\s+via\b|\s*$|\])/i)?.[1]
  174. if (model) return `模型已切换:${model}`
  175. return '系统信息'
  176. }
  177. function backgroundProcessSummary(metadata?: Record<string, unknown>): string {
  178. const exitCode = Number(metadata?.exit_code)
  179. const signal = typeof metadata?.signal === 'string' ? metadata.signal : ''
  180. if (exitCode === 0) return '后台子任务已完成'
  181. if (signal) return `后台子任务已终止 · ${signal}`
  182. return Number.isFinite(exitCode) ? `后台子任务失败 · 退出码 ${exitCode}` : '后台子任务已结束'
  183. }
  184. function isCompactionEvent(message: UiMessage): boolean {
  185. return message.timelineMetadata?.eventKind === 'compaction'
  186. || message.content.trim().toLocaleLowerCase().startsWith('[context compaction')
  187. }
  188. function onScroll() {
  189. const el = scroller.value
  190. if (!el) return
  191. const distance = el.scrollHeight - el.scrollTop - el.clientHeight
  192. // Content growth is not a user gesture. Only a downward return to the end re-arms follow.
  193. if (el.scrollTop > previousTop && distance < 80) pinnedToBottom.value = true
  194. previousTop = el.scrollTop
  195. showJump.value = !pinnedToBottom.value && distance > 100
  196. }
  197. function scrollToBottom(behavior: ScrollBehavior = 'smooth') {
  198. const el = scroller.value
  199. if (!el) return
  200. pinnedToBottom.value = true
  201. el.scrollTo({ top: el.scrollHeight, behavior })
  202. previousTop = el.scrollTop
  203. }
  204. function onMarkdownRendered() { scheduleFollow() }
  205. function scrollToMessage(id: string): boolean {
  206. const root = scroller.value
  207. if (!root) return false
  208. const message = root.querySelector<HTMLElement>(`[data-message-id="${CSS.escape(id)}"]`)
  209. if (!message) {
  210. const index = props.messages.findIndex(message => message.id === id)
  211. if (index < 0) return false
  212. stopFollowing(); windowStart.value = Math.max(0, index - Math.floor(windowSize / 2))
  213. void nextTick(() => scrollToMessage(id)); return true
  214. }
  215. stopFollowing()
  216. message.scrollIntoView({ block: 'center', behavior: 'smooth' })
  217. message.classList.remove('message--revealed')
  218. requestAnimationFrame(() => message.classList.add('message--revealed'))
  219. window.setTimeout(() => message.classList.remove('message--revealed'), 1800)
  220. return true
  221. }
  222. function scrollToAnchor(messageId: string, anchorId: string): boolean {
  223. const root = scroller.value
  224. if (!root) return false
  225. const message = root.querySelector<HTMLElement>(`[data-message-id="${CSS.escape(messageId)}"]`)
  226. if (!message) { const index = props.messages.findIndex(m => m.id === messageId); if (index < 0) return false; stopFollowing(); windowStart.value = Math.max(0, index - 60); void nextTick(() => scrollToAnchor(messageId, anchorId)); return true }
  227. stopFollowing()
  228. const target = anchorId ? message.querySelector<HTMLElement>(`#${CSS.escape(anchorId)}`) : null
  229. ;(target || message).scrollIntoView({ block: target ? 'start' : 'center', behavior: 'smooth' })
  230. message.classList.remove('message--revealed')
  231. requestAnimationFrame(() => message.classList.add('message--revealed'))
  232. window.setTimeout(() => message.classList.remove('message--revealed'), 1800)
  233. return true
  234. }
  235. async function copyMessage(message: UiMessage) {
  236. const text = displayContentForMessage(message.role, message.content)
  237. const copied = await copyTextToClipboard(text)
  238. copiedMessageId.value = copied ? message.id : ''
  239. copyFailedMessageId.value = copied ? '' : message.id
  240. if (copyResetTimer !== undefined) window.clearTimeout(copyResetTimer)
  241. copyResetTimer = window.setTimeout(() => {
  242. copiedMessageId.value = ''
  243. copyFailedMessageId.value = ''
  244. copyResetTimer = undefined
  245. }, 1400)
  246. }
  247. function hasConversationActions(message: UiMessage): boolean {
  248. return message.role === 'user' || (message.role === 'assistant' && Boolean(message.content.trim()))
  249. }
  250. function deliveryLabel(status?: UiMessage['status']): string {
  251. return ({
  252. preparing: '正在准备附件',
  253. attached: '附件已就绪',
  254. pending: '正在发送',
  255. accepted: '已发送',
  256. failed: '发送失败',
  257. 'unknown-receipt': '回执未知,请检查后重试',
  258. } as Partial<Record<NonNullable<UiMessage['status']>, string>>)[status || 'settled'] || ''
  259. }
  260. watch(() => props.messages.length, async () => {
  261. if (!pinnedToBottom.value) return
  262. await nextTick()
  263. scheduleFollow()
  264. })
  265. watch(() => props.messages.at(-1)?.content, async () => {
  266. if (!pinnedToBottom.value) return
  267. await nextTick()
  268. scheduleFollow()
  269. })
  270. onMounted(() => nextTick(() => {
  271. scheduleFollow()
  272. transcriptObserver = new ResizeObserver(scheduleFollow)
  273. const stack = scroller.value?.querySelector('.message-stack')
  274. if (stack) transcriptObserver.observe(stack)
  275. }))
  276. watch(() => props.messages.length, () => nextTick(() => {
  277. const stack = scroller.value?.querySelector('.message-stack')
  278. if (stack) transcriptObserver?.observe(stack)
  279. }))
  280. onBeforeUnmount(() => {
  281. transcriptObserver?.disconnect()
  282. if (followFrame !== undefined) cancelAnimationFrame(followFrame)
  283. if (copyResetTimer !== undefined) window.clearTimeout(copyResetTimer)
  284. })
  285. defineExpose({ scrollToMessage, scrollToAnchor, scrollToBottom, isFollowingBottom: () => pinnedToBottom.value })
  286. </script>
  287. <template>
  288. <section class="timeline-frame" :class="{ 'timeline-frame--transparent': transparentHeader }">
  289. <header v-if="title || transparentHeader" class="timeline-header" :class="{ 'timeline-header--transparent': transparentHeader }">
  290. <slot name="header-leading" />
  291. <div v-if="!transparentHeader" class="timeline-identity">
  292. <TeamAvatar v-if="headerAvatarName && headerAvatarKind === 'team'" :name="headerAvatarName" :avatar="headerAvatar" :members="headerAvatarMembers" :size="34" />
  293. <AgentAvatar v-else-if="headerAvatarName" class="timeline-header__avatar" :name="headerAvatarName" :avatar="headerAvatar" :state="headerAvatarState" :activity-key="headerAvatarActivityKey" :size="34" />
  294. <div class="timeline-heading"><h2>{{ title }}</h2><p v-if="subtitle">{{ subtitle }}</p></div>
  295. </div>
  296. <slot name="header-actions" />
  297. </header>
  298. <div ref="scroller" class="timeline" @scroll.passive="onScroll"
  299. @wheel.passive="event => { if (event.deltaY < 0) stopFollowing() }"
  300. @touchstart.passive="event => { touchY = event.touches[0]?.clientY ?? 0 }"
  301. @touchmove.passive="event => { const y = event.touches[0]?.clientY ?? touchY; if (y > touchY) stopFollowing(); touchY = y }"
  302. @pointerdown="event => { const el = scroller; if (el && event.clientX >= el.getBoundingClientRect().right - 18) stopFollowing() }"
  303. @keydown="event => { if (['PageUp', 'Home', 'ArrowUp'].includes(event.key)) stopFollowing() }">
  304. <div v-if="loading && !messages.length" class="message-skeletons" aria-label="正在加载消息">
  305. <div v-for="n in 4" :key="n" :class="{ user: n % 2 === 0 }"><i /><span /></div>
  306. </div>
  307. <div v-else-if="!messages.length && emptyLogo" class="new-chat-empty">
  308. <img class="new-chat-empty__logo" src="/brand/AppIcon-1024.png" width="1024" height="1024" alt="" aria-hidden="true" />
  309. <p>聊点什么</p>
  310. </div>
  311. <EmptyState v-else-if="!messages.length" icon="chat" :title="emptyTitle" :description="emptyDescription" />
  312. <div v-else class="message-stack" :class="{ 'message-stack--interaction': interaction }">
  313. <div v-if="forkSourceTitle" class="fork-divider" role="separator">
  314. <span><AppIcon name="branch" :size="13" />FORK 来源 <strong>{{ forkSourceTitle }}</strong></span>
  315. </div>
  316. <button v-if="hasOlder || windowStart > 0" class="load-older" type="button" :disabled="loadingOlder" @click="showEarlier">
  317. {{ loadingOlder ? '正在加载…' : '加载更早消息' }}
  318. </button>
  319. <template v-for="row in timelineRows" :key="row.id">
  320. <TurnTrace v-if="row.kind === 'trace' && showTools" :group="row" :stream-interval-ms="0" />
  321. <template v-else-if="row.kind === 'message'">
  322. <article
  323. v-for="message in [row.message]"
  324. :key="message.id"
  325. v-memo="[message, showTools, showAssistantIdentity, mentionSignature, agentAvatars[message.profile || ''], avatarState(message), copiedMessageId === message.id, copyFailedMessageId === message.id, readOnly, allowBranch]"
  326. :data-message-id="message.id"
  327. class="message"
  328. :class="[`message--${message.role}`, {
  329. 'message--failed': message.status === 'failed',
  330. 'message--communication': !!message.communication,
  331. 'message--tool-only': message.role === 'assistant' && !message.content && !message.reasoning && Boolean(message.tools?.length),
  332. 'message--assistant-internal': message.role === 'assistant' && !message.content.trim(),
  333. 'message--assistant-anonymous': message.role === 'assistant' && !showAssistantIdentity,
  334. }]"
  335. >
  336. <AgentAvatar v-if="!message.communication && message.role !== 'user' && (message.role !== 'assistant' || showAssistantIdentity)" class="message__avatar" :name="message.author || message.profile || (message.role === 'assistant' ? '夭' : '系')" :avatar="message.profile ? agentAvatars[message.profile] || '' : ''" :size="27" :state="avatarState(message)" />
  337. <div v-if="message.communication" class="communication-caption" role="note">
  338. <span>{{ message.communication.direction === 'outgoing' ? '发送给' : '消息来自' }}</span>
  339. <AgentAvatar :name="message.communication.peerName" :avatar="message.communication.peerAvatar" :size="16" :animated="false" aria-hidden="true" />
  340. <span class="communication-caption__name">{{ message.communication.peerName }}</span>
  341. </div>
  342. <div class="message__body">
  343. <TaskResultNotice v-if="message.role === 'system' && message.taskReference" :content="message.content" :task-reference="message.taskReference" />
  344. <template v-else-if="message.timelineKind === 'delegation-complete'">
  345. <details class="delegation-event">
  346. <summary><AppIcon name="groups" :size="14" /><span><strong>子任务已完成</strong><small>{{ delegationSummary(message.timelineMetadata) }}</small></span></summary>
  347. <MarkdownContent process-content v-if="message.content" :content="message.content" />
  348. </details>
  349. </template>
  350. <template v-else-if="message.timelineKind === 'background-process'">
  351. <details class="system-event background-process-event">
  352. <summary><AppIcon name="tools" :size="13" /><span>{{ backgroundProcessSummary(message.timelineMetadata) }}</span></summary>
  353. <MarkdownContent process-content v-if="message.content" :content="message.content" />
  354. </details>
  355. </template>
  356. <template v-else-if="message.timelineKind === 'system' && isCompactionEvent(message)">
  357. <details class="delegation-event compaction-event">
  358. <summary><AppIcon name="archive" :size="14" /><span><strong>上下文已压缩</strong><small>压缩摘要已归档 · 点击查看</small></span></summary>
  359. <MarkdownContent process-content v-if="message.content" :content="message.content" />
  360. </details>
  361. </template>
  362. <template v-else-if="message.timelineKind === 'system'">
  363. <details class="system-event">
  364. <summary><AppIcon name="settings" :size="13" /><span>{{ systemSummary(message.content) }}</span></summary>
  365. <MarkdownContent process-content v-if="message.content" :content="message.content" />
  366. </details>
  367. </template>
  368. <template v-else>
  369. <div v-if="!message.communication && (message.role !== 'assistant' || showAssistantIdentity)" class="message__meta">
  370. <strong><AppIcon v-if="message.isRemoteAgent" class="message__remote-agent" name="globe" :size="12" />{{ message.role === 'user' ? '你' : message.author || message.profile || (message.role === 'assistant' ? '机器人' : '系统') }}</strong>
  371. <span v-if="message.metadata" class="message__execution">{{ message.metadata }}</span>
  372. <time>{{ formatTime(message.createdAt) }}</time>
  373. <span v-if="message.status && !['settled', 'streaming'].includes(message.status)">{{ { preparing: '准备中', attached: '附件已就绪', pending: '等待回执', accepted: '已接收', streaming: '生成中', settled: '已完成', failed: '发送失败', 'unknown-receipt': '回执未知' }[message.status] }}</span>
  374. </div>
  375. <details v-if="message.reasoning" class="message__reasoning">
  376. <summary><AppIcon name="brain" :size="13" />思考过程 · {{ message.reasoning.length }} 字</summary>
  377. <MarkdownContent process-content :content="message.reasoning" :streaming="message.status === 'streaming'" :stream-interval-ms="0" @rendered="onMarkdownRendered" />
  378. </details>
  379. <div v-if="message.role === 'user' && message.attachments?.length" class="message__attachments">
  380. <button v-for="attachment in message.attachments" :key="attachment.id" type="button" :class="{ 'message__attachment--image': attachment.kind === 'image' && attachment.url }" @click="emit('preview', attachment)">
  381. <img v-if="attachment.kind === 'image' && attachment.url" :src="attachment.url" :alt="attachment.name" />
  382. <span v-else><AppIcon :name="attachment.kind || 'file'" :size="17" /></span>
  383. <strong v-if="attachment.kind !== 'image' || !attachment.url">{{ attachment.name }}</strong>
  384. </button>
  385. </div>
  386. <div class="message__content">
  387. <MarkdownContent
  388. :stream-interval-ms="0"
  389. :file-profile="message.profile"
  390. :content="displayContentForMessage(message.role, message.content)"
  391. :streaming="message.status === 'streaming'"
  392. :legacy-media="message.role === 'assistant'"
  393. :plain="message.role === 'user'"
  394. :mention-names="mentionNames"
  395. :outline-prefix="message.role === 'assistant' ? `outline-${message.id}` : ''"
  396. :file-cards="message.role === 'user' || message.role === 'assistant' || !!message.communication"
  397. :process-content="!message.communication && message.role !== 'user' && message.role !== 'assistant'"
  398. @rendered="onMarkdownRendered"
  399. @file-link="(name, url) => emit('previewFile', { name, url })"
  400. />
  401. </div>
  402. <div
  403. v-if="message.role === 'user' && deliveryLabel(message.status)"
  404. class="message__delivery"
  405. :class="`message__delivery--${message.status}`"
  406. role="status"
  407. aria-live="polite"
  408. >
  409. <AppIcon :name="message.status === 'accepted' ? 'check' : message.status === 'failed' || message.status === 'unknown-receipt' ? 'alert' : 'dots'" :size="11" />
  410. {{ deliveryLabel(message.status) }}
  411. </div>
  412. <div v-if="(message.role === 'assistant' || message.communication) && message.attachments?.length" class="message__attachments">
  413. <button v-for="attachment in message.attachments" :key="attachment.id" type="button" @click="emit('preview', attachment)">
  414. <img v-if="attachment.kind === 'image' && attachment.url" :src="attachment.url" :alt="attachment.name" />
  415. <span v-else><AppIcon :name="attachment.kind || 'file'" :size="17" /></span>
  416. <strong>{{ attachment.name }}</strong>
  417. </button>
  418. </div>
  419. <div v-if="showTools && message.tools?.length" class="message__tools">
  420. <ToolTrace v-for="tool in message.tools" :key="tool.id" :tool="tool" />
  421. </div>
  422. <p v-if="message.error" class="message__error"><AppIcon name="alert" :size="13" />{{ message.error }}</p>
  423. <div v-if="hasConversationActions(message)" class="message__actions">
  424. <time v-if="message.role === 'assistant' && !showAssistantIdentity && message.createdAt" class="message__action-time">{{ formatTime(message.createdAt) }}</time>
  425. <button
  426. type="button"
  427. :class="{
  428. 'message-action--copied': copiedMessageId === message.id,
  429. 'message-action--copy-failed': copyFailedMessageId === message.id,
  430. }"
  431. :title="copiedMessageId === message.id ? '已复制' : copyFailedMessageId === message.id ? '复制失败' : '复制'"
  432. :aria-label="copiedMessageId === message.id ? '已复制' : copyFailedMessageId === message.id ? '复制失败' : '复制消息'"
  433. @click="copyMessage(message)"
  434. ><AppIcon :name="copiedMessageId === message.id ? 'check' : copyFailedMessageId === message.id ? 'alert' : 'copy'" :size="13" /></button>
  435. <button v-if="!readOnly" type="button" title="引用" aria-label="引用消息" @click="emit('quote', message)"><AppIcon name="quote" :size="13" /></button>
  436. <button v-if="!readOnly && allowBranch && message.role === 'assistant'" type="button" title="从这里分支" aria-label="从这里分支" @click="emit('branch', message)"><AppIcon name="branch" :size="13" /></button>
  437. </div>
  438. </template>
  439. </div>
  440. </article>
  441. </template>
  442. </template>
  443. <TypingIndicator
  444. v-if="showThinkingIndicator"
  445. :avatar-name="thinkingAvatarName"
  446. :avatar="thinkingAvatar"
  447. />
  448. <WorkspaceApprovalCard v-if="interaction?.kind === 'approval'" :prompt="interaction.prompt" :agent-name="approvalAgentName" :busy="interactionBusy" :error="interactionError" @choose="emit('approvalChoice', $event)" />
  449. <InteractionCard
  450. v-else-if="interaction"
  451. :interaction="interaction"
  452. :busy="interactionBusy"
  453. @clarify="emit('clarify', $event)"
  454. />
  455. <p v-if="interaction && interaction.kind !== 'approval' && interactionError" role="alert" style="color:var(--danger);font-size:14px">{{ interactionError }}</p>
  456. </div>
  457. </div>
  458. <Transition name="view-fade">
  459. <button v-if="showJump" class="jump-bottom" type="button" @click="scrollToBottom()">
  460. <AppIcon name="chevron-down" :size="15" />回到底部
  461. </button>
  462. </Transition>
  463. </section>
  464. </template>
  465. <style scoped>
  466. .message.message--communication { flex-direction: column; align-items: flex-start; gap: 12px; margin-top: 24px; }
  467. .communication-caption { display: flex; width: 100%; min-width: 0; justify-content: center; align-items: center; gap: 6px; color: var(--text-secondary); font-size: 12px; font-weight: 400; line-height: 16px; }
  468. .communication-caption > span:first-child { flex-shrink: 0; white-space: nowrap; }
  469. .communication-caption__name { min-width: 0; max-width: 60%; overflow-wrap: anywhere; }
  470. .message.message--communication .message__body { width: fit-content; max-width: min(680px, 86%); margin: 0; padding: 12px 16px; border: 0; border-radius: 20px; background: var(--surface-soft); text-align: left; }
  471. .timeline-frame { position: relative; display: flex; min-width: 0; min-height: 0; flex: 1; flex-direction: column; }
  472. .timeline-header { display: flex; z-index: 6; min-height: 62px; align-items: center; gap: 13px; padding: 10px 18px; border-bottom: 1px solid var(--line); background: color-mix(in srgb, var(--canvas) 92%, transparent); backdrop-filter: blur(16px); }
  473. .timeline-header--transparent { position: absolute; top: 0; right: 0; left: 0; min-height: 0; justify-content: flex-end; padding: 11px 14px; border: 0; background: transparent; backdrop-filter: none; pointer-events: none; }
  474. .timeline-header--transparent > * { pointer-events: auto; }
  475. .timeline-identity { display: flex; min-width: 0; flex: 1; align-items: center; gap: 10px; }.timeline-heading { min-width: 0; }.timeline-header h2 { overflow: hidden; margin: 0; font-size: 14px; font-weight: 630; letter-spacing: -.02em; text-overflow: ellipsis; white-space: nowrap; }.timeline-header p { overflow: hidden; margin: 3px 0 0; color: var(--text-muted); font-size: 9px; text-overflow: ellipsis; white-space: nowrap; }
  476. .timeline { min-height: 0; flex: 1; overflow-y: auto; overflow-anchor: none; overscroll-behavior: contain; background: var(--conversation-canvas); }
  477. .message-stack { width: min(780px, 100%); min-height: 100%; margin: 0 auto; padding: 24px 24px 36px; }
  478. .message-stack--interaction { padding-bottom: 10px; }
  479. .timeline-frame--transparent .message-stack { padding-top: 58px; }
  480. .load-older { display: block; margin: 0 auto 18px; padding: 5px 9px; border: 1px solid var(--line); border-radius: 8px; background: transparent; color: var(--text-muted); cursor: pointer; font-size: 10px; }.load-older:hover { background: var(--surface-soft); color: var(--text-secondary); }
  481. .message { position: relative; display: flex; max-width: 100%; gap: 10px; margin: 0 0 21px; }
  482. .message__avatar { display: grid; place-items: center; width: 27px; height: 27px; flex: 0 0 27px; background: transparent; color: var(--text-secondary); font-size: 11px; font-weight: 700; }
  483. .message__body { position: relative; min-width: 0; max-width: min(680px, calc(100% - 37px)); }
  484. .message__meta { display: flex; min-height: 20px; align-items: center; gap: 7px; color: var(--text-muted); font-size: 10px; }.message__meta strong { display: inline-flex; align-items: center; color: var(--text-primary); font-size: 12px; font-weight: 600; }.message__remote-agent { margin-right: 4px; color: var(--accent); }.message__meta span { color: var(--warning); }.message__meta .message__execution { overflow: hidden; max-width: 230px; color: var(--text-secondary); font-variant-numeric: tabular-nums; text-overflow: ellipsis; white-space: nowrap; }
  485. .message__content { color: var(--text-primary); }
  486. .message__content :deep(.plain-text), .message__content :deep(.markdown) { font-size: 15px; }
  487. .message__content :deep(.code-lang), .message__content :deep(.code-copy) { font-size: 10px; }
  488. .message__content :deep(.code-block code) { font-size: 12px; }
  489. .message__content :deep(.file-link-card)::after { font-size: 10px; }
  490. .message--user { justify-content: flex-end; margin-top: 27px; }
  491. .message--user .message__body { max-width: min(610px, 76%); padding: 11px 15px; border-radius: 20px 20px 6px 20px; background: #eceff3; }
  492. .dark .message--user .message__body { background: #2d323a; }
  493. .message--user .message__meta { display: none; }
  494. .message__delivery { display: flex; min-height: 18px; align-items: center; justify-content: flex-end; gap: 4px; margin: 5px 1px -4px; color: var(--text-muted); font-size: 10px; }.message__delivery--accepted { color: var(--success); }.message__delivery--failed, .message__delivery--unknown-receipt { color: var(--danger); }
  495. .message--system { justify-content: center; }.message--system .message__avatar, .message--system .message__meta { display: none; }.message--system .message__body { width: min(640px, 100%); max-width: 92%; padding: 0; color: var(--text-muted); text-align: center; }
  496. .message--system .message__body:has(> :not(.task-result-notice)) { width: auto; max-width: 82%; padding: 6px 10px; border: 1px solid var(--line); border-radius: 9px; }
  497. .delegation-event { min-width: 230px; max-width: 460px; text-align: left; }.delegation-event summary { display: flex; align-items: center; gap: 8px; cursor: pointer; list-style: none; }.delegation-event summary::-webkit-details-marker { display: none; }.delegation-event summary > span { display: flex; min-width: 0; flex-direction: column; gap: 2px; }.delegation-event strong { color: var(--text-secondary); font-size: 12px; font-weight: 650; }.delegation-event small { color: var(--text-muted); font-size: 10px; }.delegation-event :deep(.markdown) { max-height: 260px; margin-top: 9px; overflow: auto; color: var(--text-secondary); font-size: 11px; }
  498. .system-event { max-width: 460px; text-align: left; }.system-event summary { display: inline-flex; align-items: center; gap: 6px; cursor: pointer; list-style: none; color: var(--text-muted); font-size: 11px; }.system-event summary::-webkit-details-marker { display: none; }.system-event :deep(.markdown) { max-height: 220px; margin-top: 8px; overflow: auto; color: var(--text-secondary); font-size: 11px; }
  499. .message--tool-only { margin-block: 4px; }.message--tool-only .message__avatar, .message--tool-only .message__meta, .message--tool-only .message__actions { display: none; }.message--tool-only .message__body { max-width: 100%; }
  500. .message--assistant-internal { margin-bottom: 6px; }.message--assistant-internal .message__reasoning { margin-bottom: 4px; padding-bottom: 4px; }.message--assistant-internal .message__tools { margin-top: 4px; }
  501. .message--assistant-anonymous .message__body { max-width: min(680px, 100%); }
  502. .message__reasoning { max-width: 420px; margin: 3px 0 10px; padding: 0 0 8px; border: 0; border-bottom: 1px dashed var(--line-strong); color: var(--text-secondary); font-size: 12px; }.message__reasoning summary { display: flex; align-items: center; gap: 5px; list-style: none; color: var(--text-muted); cursor: pointer; font-size: 10px; }.message__reasoning summary::-webkit-details-marker { display: none; }.message__reasoning summary::before { content: '›'; color: var(--text-muted); font-size: 14px; line-height: 1; transition: transform 120ms ease; }.message__reasoning[open] summary::before { transform: rotate(90deg); }.message__reasoning :deep(.markdown) { margin-top: 8px; }
  503. .fork-divider { display: flex; align-items: center; gap: 12px; margin: 8px 0 28px; color: var(--text-muted); font-size: 11px; }.fork-divider::before, .fork-divider::after { height: 1px; flex: 1; background: var(--line); content: ''; }.fork-divider > span { display: inline-flex; align-items: center; gap: 6px; padding: 5px 10px; border: 1px solid var(--line); border-radius: 999px; background: var(--surface-raised); white-space: nowrap; }.fork-divider strong { max-width: 180px; overflow: hidden; color: var(--text-secondary); text-overflow: ellipsis; }
  504. .message__attachments { display: flex; margin-top: 8px; flex-wrap: wrap; gap: 7px; }.message__attachments button { display: flex; min-width: 90px; max-width: 210px; min-height: 42px; align-items: center; gap: 7px; padding: 5px 8px; overflow: hidden; border: 1px solid var(--line); border-radius: 9px; background: var(--surface); color: var(--text-secondary); cursor: pointer; }.message__attachments button:hover { border-color: var(--line-strong); }.message__attachments img { width: 48px; height: 48px; margin: -5px 0 -5px -8px; object-fit: cover; }.message__attachments button > span { display: grid; place-items: center; width: 25px; height: 25px; border-radius: 7px; background: var(--surface-soft); }.message__attachments strong { min-width: 0; overflow: hidden; font-size: 11px; font-weight: 520; text-overflow: ellipsis; white-space: nowrap; }
  505. .message--user .message__attachments { margin: 0 0 9px; }.message--user .message__attachments button { width: 100%; max-width: none; min-height: 50px; padding: 7px 9px; border: 0; border-radius: 11px; background: rgba(255,255,255,.48); color: var(--text-primary); }.message--user .message__attachments button > span { width: 28px; height: 28px; background: rgba(255,255,255,.65); }.message--user .message__attachments strong { font-size: 12px; font-weight: 560; }.dark .message--user .message__attachments button { background: rgba(255,255,255,.08); }.message--user .message__attachments button.message__attachment--image { display: block; width: auto; min-width: 0; max-width: min(360px, 100%); min-height: 0; padding: 0; border: 0; border-radius: 8px; background: transparent; }.message--user .message__attachments button.message__attachment--image img { display: block; width: auto; height: auto; max-width: min(360px, 100%); max-height: 420px; margin: 0; border-radius: inherit; object-fit: contain; }
  506. .message__tools { margin-top: 9px; }.message__error { display: flex; align-items: center; gap: 5px; margin: 7px 0 0; color: var(--danger); font-size: 10px; }
  507. .message__actions { display: flex; position: absolute; left: -3px; top: 100%; gap: 2px; padding-top: 2px; opacity: 0; transition: opacity 120ms ease; }.message:hover .message__actions, .message:focus-within .message__actions { opacity: 1; }.message--user .message__actions { right: 0; left: auto; }.message__actions button { display: grid; place-items: center; width: 24px; height: 24px; padding: 0; border: 0; border-radius: 7px; background: transparent; color: var(--text-muted); cursor: pointer; }.message__actions button:hover { background: var(--surface-soft); color: var(--text-primary); }.message__actions .message-action--copied { color: var(--success); }.message__actions .message-action--copy-failed { color: var(--danger); }
  508. .message--assistant-anonymous .message__actions { align-items: center; }.message__action-time { min-width: 36px; padding: 0 4px 0 3px; color: var(--text-muted); font-size: 10px; font-variant-numeric: tabular-nums; }
  509. .message--failed .message__body { border-color: color-mix(in srgb, var(--danger) 35%, var(--line)); }
  510. .message--revealed .message__body { animation: reveal-message 1.8s ease; }
  511. @keyframes reveal-message { 0%, 28% { box-shadow: 0 0 0 5px var(--focus-ring); } 100% { box-shadow: 0 0 0 0 transparent; } }
  512. .jump-bottom { display: flex; position: absolute; z-index: 8; bottom: 8px; left: 50%; align-items: center; gap: 5px; padding: 6px 10px; border: 1px solid var(--line); border-radius: 999px; background: var(--surface-raised); color: var(--text-secondary); cursor: pointer; font-size: 10px; box-shadow: 0 6px 18px rgba(0,0,0,.1); transform: translateX(-50%); }
  513. .new-chat-empty { display: flex; min-height: 100%; align-items: center; justify-content: center; gap: 18px; padding: 12vh 24px; box-sizing: border-box; flex-direction: column; color: var(--text-muted); text-align: center; }
  514. .new-chat-empty__logo { display: block; width: min(180px, 34vw); height: auto; aspect-ratio: 1; opacity: .18; filter: grayscale(1); }
  515. .new-chat-empty p { margin: 0; color: var(--text-secondary); font-size: 17px; font-weight: 520; letter-spacing: .02em; }
  516. .message-skeletons { width: min(760px, 100%); margin: 0 auto; padding: 35px 24px; }.message-skeletons div { display: flex; gap: 10px; margin: 0 0 25px; }.message-skeletons div.user { justify-content: flex-end; }.message-skeletons i { width: 27px; height: 27px; border-radius: 9px; background: var(--surface-hover); }.message-skeletons span { width: min(480px, 70%); height: 64px; border-radius: 12px; background: linear-gradient(90deg, var(--surface-soft), var(--surface-hover), var(--surface-soft)); background-size: 200% 100%; animation: shimmer 1.5s linear infinite; }.message-skeletons .user i { display: none; }.message-skeletons .user span { width: 44%; height: 46px; }
  517. @keyframes shimmer { to { background-position: -200% 0; } }
  518. @media (max-width: 768px) {
  519. .timeline-header { min-height: 54px; padding: 8px 12px; }
  520. .new-chat-empty { gap: 15px; padding-block: 9vh; }.new-chat-empty__logo { width: min(150px, 42vw); }.new-chat-empty p { font-size: 16px; }
  521. .message-stack { padding: 18px 14px 30px; }.message-stack--interaction { padding-bottom: 8px; }.message { margin-bottom: 18px; }.message__body { max-width: calc(100% - 37px); }.message--user .message__body { max-width: 88%; }
  522. .message--system .message__body { max-width: 100%; }
  523. .message__actions { opacity: .65; }.message__meta time { display: none; }
  524. }
  525. </style>