diff --git a/apps/desktop/src/main/services/remote/web/views.ts b/apps/desktop/src/main/services/remote/web/views.ts index b43b15b9..b4b69d0f 100644 --- a/apps/desktop/src/main/services/remote/web/views.ts +++ b/apps/desktop/src/main/services/remote/web/views.ts @@ -59,15 +59,39 @@ export function toWebMessages(m: DisplayMessage, index: number, running = false) } let parts: WebPart[] = [] let texts: string[] = [] + /** 最后一个执行步骤(工具调用等)之后的 parts 长度:此前的正文都属于「工作过程」。 */ + let processAt = -1 const endText = (): void => { const text = texts.join('\n\n').trim() texts = [] if (text) parts.push({ k: 'text', text }) } + /** 固定展示的块:无论位置都留在折叠条外面(用户需要立刻看到)。 */ + const isPinnedPart = (p: WebPart): boolean => p.k === 'note' || p.k === 'receipt' + const endReply = (last: boolean): void => { endText() - if (parts.length) out.push({ id: id(), role: 'assistant', parts, durationMs: last ? m.durationMs : undefined }) + if (parts.length) { + // 把「最后一个工具调用之前」的说明文字收进一段 process,默认收起(见 WebPart.process 的注释)。 + // 判据同电脑端 splitProcess 的 hasVisible:后面还有正文,或本轮有交付文件,才值得折叠; + // 否则(比如中断在工具调用上、一句话都没写)全部照常显示,不要把仅有的内容也藏起来。 + const tail = processAt >= 0 ? parts.slice(processAt) : [] + const hasTail = tail.some((p) => p.k !== 'receipt') || tail.some((p) => p.k === 'file') + const deliveryInHead = processAt >= 0 && parts.slice(0, processAt).some((p) => p.k === 'file') + if (processAt >= 0 && (hasTail || deliveryInHead)) { + const head = parts.slice(0, processAt) + const pinned = head.filter(isPinnedPart) + const rest = head.filter((p) => !isPinnedPart(p)) + const next: WebPart[] = [...pinned] + if (rest.length) next.push({ k: 'process', parts: rest }) + next.push(...parts.slice(processAt)) + out.push({ id: id(), role: 'assistant', parts: next, durationMs: last ? m.durationMs : undefined }) + } else { + out.push({ id: id(), role: 'assistant', parts, durationMs: last ? m.durationMs : undefined }) + } + } parts = [] + processAt = -1 } const note = (text: string): void => { endText() @@ -85,6 +109,8 @@ export function toWebMessages(m: DisplayMessage, index: number, running = false) if (b.text.trim()) out.push({ id: id(), role: 'user', text: b.text }) } else if (b.kind === 'tool') { endText() + // 最后一个执行步骤之前的所有内容都算「工作过程」(同电脑端 splitProcess)。 + processAt = parts.length if (b.name === 'present_files' && b.status === 'ok') { const paths = (b.args as { paths?: unknown } | null)?.paths if (Array.isArray(paths)) diff --git a/apps/desktop/src/mobile/chat.tsx b/apps/desktop/src/mobile/chat.tsx index 5327207b..27d7f30f 100644 --- a/apps/desktop/src/mobile/chat.tsx +++ b/apps/desktop/src/mobile/chat.tsx @@ -1,5 +1,5 @@ import { memo, useCallback, useEffect, useLayoutEffect, useMemo, useRef, useState } from 'react' -import { AlarmClock, ChevronLeft, MoreHorizontal } from 'lucide-react' +import { AlarmClock, ChevronDown, ChevronLeft, MoreHorizontal } from 'lucide-react' import type { WebDelivered, WebMessage, WebPart, WebPersona } from '../shared/remote-web' import type { Store } from './App' import { Avatar, MemberFace, SessionFace } from './avatar' @@ -376,6 +376,7 @@ const Reply = memo(function Reply({ function Part({ p, enter, onOpen }: { p: WebPart; enter: boolean; onOpen: (file: WebDelivered) => void }): React.JSX.Element { const [fresh] = useState(enter) if (p.k === 'receipt') return + if (p.k === 'process') return const cls = fresh ? ' is-new' : '' if (p.k === 'text') return ( @@ -386,3 +387,41 @@ function Part({ p, enter, onOpen }: { p: WebPart; enter: boolean; onOpen: (file: if (p.k === 'file') return onOpen(p.file)} className={fresh ? 'is-new' : undefined} /> return
{p.text}
} + +/** + * 工作过程:本轮最后一次工具调用之前那些说明文字,压成一条可展开的折叠行,默认收起。 + * + * 电脑端是「工作过程」折叠条;手机上原本每次工具调用就断一个气泡,一轮能冒出七八条旁白。 + * 收起时只留一行灰字提示,点一下展开原文(沿用成员卡的 .mfold 折叠动画,见 mobile.css)。 + */ +function Process({ + parts, + enter, + onOpen +}: { + parts: WebPart[] + enter: boolean + onOpen: (file: WebDelivered) => void +}): React.JSX.Element { + const [open, setOpen] = useState(false) + const paragraphs = parts.filter((p) => p.k === 'text' && p.text.trim()).length + return ( +
+ +
+
+
+ {parts.map((p, i) => ( + + ))} +
+
+
+
+ ) +} diff --git a/apps/desktop/src/mobile/mobile.css b/apps/desktop/src/mobile/mobile.css index 1362c5a0..0a27ec3a 100644 --- a/apps/desktop/src/mobile/mobile.css +++ b/apps/desktop/src/mobile/mobile.css @@ -406,6 +406,31 @@ button.info__r:active:not(:disabled) { background: var(--bg-hover); } @keyframes dot { 0%, 60%, 100% { opacity: .3; transform: none; } 30% { opacity: 1; transform: translateY(-3px); } } .note--center { text-align: center; padding: 12px 20px 24px; } +/* + * 工作过程折叠条:一轮里最后一次工具调用之前的说明文字(电脑端的「工作过程」)。 + * 收起时只有一行灰字,点开才展开原文——用户要的是结果,不是过程。 + */ +.proc { display: flex; flex-direction: column; } +.proc__pill { + align-self: flex-start; + display: inline-flex; + align-items: center; + gap: 5px; + max-width: 100%; + padding: 4px 10px 4px 6px; + border-radius: 999px; + background: var(--bg-inset); + color: var(--fg-subtle); + font-size: 12.5px; + line-height: 18px; +} +.proc__chev { flex: none; transition: transform .15s; } +.proc__pill.is-open .proc__chev { transform: rotate(180deg); } +.proc__text { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; } +.proc__body { display: flex; flex-direction: column; gap: 8px; padding: 8px 0 2px; } +/* 展开后里面的气泡同样不淡入:它们是已经显示过又重新展开的内容 */ +.proc__body .bb { opacity: .82; } + /* Markdown */ .md > :first-child { margin-top: 0; } .md > :last-child { margin-bottom: 0; } diff --git a/apps/desktop/src/mobile/strings.ts b/apps/desktop/src/mobile/strings.ts index 04452915..7a471f15 100644 --- a/apps/desktop/src/mobile/strings.ts +++ b/apps/desktop/src/mobile/strings.ts @@ -17,6 +17,9 @@ const STR = { later: ['以后再说', 'Later'], yesterday: ['昨天', 'Yesterday'], justNow: ['刚刚', 'Just now'], + // 工作过程折叠条:收起时只留一行提示,点开看原文 + processShow: ['工作过程({n} 段)', 'How it worked ({n})'], + processHide: ['收起工作过程', 'Hide how it worked'], // 连接 connectingTitle: ['正在连接', 'Connecting'], stepTicket: ['验证二维码', 'Verify the QR code'], diff --git a/apps/desktop/src/shared/remote-web.ts b/apps/desktop/src/shared/remote-web.ts index 18e99864..25d280c0 100644 --- a/apps/desktop/src/shared/remote-web.ts +++ b/apps/desktop/src/shared/remote-web.ts @@ -139,7 +139,19 @@ export interface WebReceipt { } /** 一条助手回复里的内容:一段正文、一个交付的文件、一行提示(已停止、出错等)、一行回执,按出现的先后排列。 */ -export type WebPart = { k: 'text'; text: string } | { k: 'file'; file: WebDelivered } | { k: 'note'; text: string } | WebReceipt +export type WebPart = + | { k: 'text'; text: string } + | { k: 'file'; file: WebDelivered } + | { k: 'note'; text: string } + | WebReceipt + /** + * 工作过程:本轮最后一次工具调用之前的所有说明文字(含夹在工具调用之间的旁白),合成一段、默认收起。 + * + * 电脑端把这批文字收进「工作过程」折叠条,只把最后那段正文当回复显示(见 blocks.tsx 的 splitProcess)。 + * 手机上原本是每次工具调用就断一个气泡,于是一轮里冒出七八条「我先确认一下…」「已确认…」—— + * 用户要的是结果,不是过程。这里沿用同一套切法:最后一个过程块之前的内容全收进这一段。 + */ + | { k: 'process'; parts: WebPart[] } /** * 对话里的一条消息(由电脑端的展示投影归约而来:只有正文,工具调用与过程不下发)。