Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 27 additions & 1 deletion apps/desktop/src/main/services/remote/web/views.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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))
Expand Down
41 changes: 40 additions & 1 deletion apps/desktop/src/mobile/chat.tsx
Original file line number Diff line number Diff line change
@@ -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'
Expand Down Expand Up @@ -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 <Receipt r={p} />
if (p.k === 'process') return <Process parts={p.parts} enter={fresh} onOpen={onOpen} />
const cls = fresh ? ' is-new' : ''
if (p.k === 'text')
return (
Expand All @@ -386,3 +387,41 @@ function Part({ p, enter, onOpen }: { p: WebPart; enter: boolean; onOpen: (file:
if (p.k === 'file') return <FileCard file={p.file} onOpen={() => onOpen(p.file)} className={fresh ? 'is-new' : undefined} />
return <div className={`note${cls}`}>{p.text}</div>
}

/**
* 工作过程:本轮最后一次工具调用之前那些说明文字,压成一条可展开的折叠行,默认收起。
*
* 电脑端是「工作过程」折叠条;手机上原本每次工具调用就断一个气泡,一轮能冒出七八条旁白。
* 收起时只留一行灰字提示,点一下展开原文(沿用成员卡的 .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 (
<div className={`proc${enter ? ' is-new' : ''}`}>
<button className={`proc__pill${open ? ' is-open' : ''}`} onClick={() => setOpen((v) => !v)}>
<ChevronDown className="proc__chev" size={14} />
<span className="proc__text">
{open ? t('processHide') : t('processShow', { n: String(paragraphs) })}
</span>
</button>
<div className={`mfold${open ? '' : ' is-shut'}`}>
<div className="mfold__in">
<div className="proc__body">
{parts.map((p, i) => (
<Part key={i} p={p} enter={false} onOpen={onOpen} />
))}
</div>
</div>
</div>
</div>
)
}
25 changes: 25 additions & 0 deletions apps/desktop/src/mobile/mobile.css
Original file line number Diff line number Diff line change
Expand Up @@ -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; }
Expand Down
3 changes: 3 additions & 0 deletions apps/desktop/src/mobile/strings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'],
Expand Down
14 changes: 13 additions & 1 deletion apps/desktop/src/shared/remote-web.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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[] }

/**
* 对话里的一条消息(由电脑端的展示投影归约而来:只有正文,工具调用与过程不下发)。
Expand Down