Skip to content
Draft
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
5 changes: 5 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,11 @@ jobs:
timeout-minutes: 5
run: node scripts/workbench/e2e-sessions.mjs

- name: Verify delivery cards, browser downloads and scoped file reveal
if: ${{ !cancelled() && steps.host_tests.outcome == 'success' }}
timeout-minutes: 5
run: node scripts/workbench/e2e-deliveries.mjs

- name: Select the same installed Chrome for UI and worker
run: bash scripts/workbench/ci-select-chromium.sh

Expand Down
2 changes: 1 addition & 1 deletion README.en.md
Original file line number Diff line number Diff line change
Expand Up @@ -341,7 +341,7 @@ When memory is full, the next write by the model first consolidates the existing

## Headless server workbench (fork development)

The [amd64 Docker Compose workbench](apps/headless/README.md) supports browser enrollment, the original desktop model settings, and general text conversations with shared desktop UI, streaming, cancellation and reconnect. It also includes profile and role editing, avatar management, and notes scoped to the owner, a role, or a registered project. Manual workspaces and explicit chat attachments are separate: browsing a project does not send its files to a model. The workbench accepts supported UTF-8 text, static images and PDFs for compatible adapters. An [optional human-operated browser](apps/browser-worker/README.md) uses a separate sandboxed worker and an explicit list of sites. The base app requires neither that worker nor a running desktop. This is separate from the mobile relay; see the [parity inventory](docs/development/web-workbench/README.md) for the remaining desktop workflows.
The [amd64 Docker Compose workbench](apps/headless/README.md) supports browser enrollment, the original desktop model settings, and general text conversations with shared desktop UI, streaming, cancellation and reconnect. It also includes profile and role editing, avatar management, and notes scoped to the owner, a role, or a registered project. Manual workspaces and explicit chat attachments are separate: browsing a project does not send its files to a model. The workbench accepts supported UTF-8 text, static images and PDFs for compatible adapters. Confirmed replies can be exported as Markdown or plain text. Desktop delivery cards are reused for scoped downloads and project file reveal. An [optional human-operated browser](apps/browser-worker/README.md) uses a separate sandboxed worker and an explicit list of sites. The base app requires neither that worker nor a running desktop. This is separate from the mobile relay; see the [parity inventory](docs/development/web-workbench/README.md) for the remaining desktop workflows.

## Build from Source

Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -332,7 +332,7 @@ IM 机器人支持 `/new [角色名]`、`/list`、`/stop`、`/status`、`/help`

## 无 GUI 服务器工作台(本分支开发中)

[amd64 Docker Compose 与 Web 工作台说明](apps/headless/README.md):当前可在浏览器认领服务器、配置模型,并使用桌面同源的会话列表、编辑器及消息区进行通用文本对话;支持停止与刷新续接。网页还可以编辑个人资料、普通角色及其头像,并分别管理全局、角色和已授权项目的记忆。可手动浏览获准项目的文件,也可显式把所选文本、静态图片或兼容协议的 PDF 作为会话附件发送;浏览项目不会自动上传。还可配置[独立人工浏览器面板](apps/browser-worker/README.md),由当前登录者接管已登记站点;实际工作器须通过 Chromium 沙箱就绪检查。它和手机版中转是两个不同部署目标;完整业务进度见[对等清单](docs/development/web-workbench/README.md)。
[amd64 Docker Compose 与 Web 工作台说明](apps/headless/README.md):当前可在浏览器认领服务器、配置模型,并使用桌面同源的会话列表、编辑器及消息区进行通用文本对话;支持停止与刷新续接。网页还可以编辑个人资料、普通角色及其头像,并分别管理全局、角色和已授权项目的记忆。可手动浏览获准项目的文件,也可显式把所选文本、静态图片或兼容协议的 PDF 作为会话附件发送;浏览项目不会自动上传。已确认的回复可导出为 Markdown 或纯文本;桌面交付卡复用于 Web,支持按授权项目下载文件和定位。还可配置[独立人工浏览器面板](apps/browser-worker/README.md),由当前登录者接管已登记站点;实际工作器须通过 Chromium 沙箱就绪检查。它和手机版中转是两个不同部署目标;完整业务进度见[对等清单](docs/development/web-workbench/README.md)。

## 从源码构建

Expand Down
174 changes: 36 additions & 138 deletions apps/desktop/src/renderer/src/features/chat/DeliverablesCard.tsx
Original file line number Diff line number Diff line change
@@ -1,15 +1,5 @@
import { useEffect, useState } from 'react'
import {
Check,
ChevronDown,
ChevronRight,
ChevronUp,
Copy,
ExternalLink,
File,
FolderOpen,
Package
} from 'lucide-react'
import { DeliverablesView, formatDeliverableSize, type DeliverableViewRow } from './DeliverablesView'
import { useI18n } from '../../i18n/i18n'
import { type ChatBlock, useChatState } from '../../store/chat'
import { useToast } from '../../components/ToastProvider'
Expand All @@ -24,16 +14,6 @@ import type { DeliverableInfo } from '../../../../shared/deliverables'
// 缩略图按「对话:调用:序号」缓存:滚动 / 重渲染时不反复向系统要图。
const thumbCache = new Map<string, string | null>()

/** 文件多于 FOLD_PREVIEW + 1 个时折叠,只显示前 FOLD_PREVIEW 个(免得出现「展开其余 1 个」)。 */
const FOLD_PREVIEW = 5

function formatSize(n: number): string {
if (n < 1024) return `${n} B`
if (n < 1024 * 1024) return `${Math.round(n / 1024)} KB`
if (n < 1024 * 1024 * 1024) return `${(n / 1024 / 1024).toFixed(1)} MB`
return `${(n / 1024 / 1024 / 1024).toFixed(1)} GB`
}

/**
* 主进程信息到达前,先按调用参数画出文件名,避免卡片高度跳动。参数是模型原样发出的(可能是相对路径、
* 可能重复),只取文件名占位;真实路径以 inspect 返回的为准。
Expand All @@ -60,9 +40,6 @@ export function DeliverablesCard({
const [loaded, setLoaded] = useState(false)
const [thumbs, setThumbs] = useState<Record<number, string | null>>({})
const [copied, setCopied] = useState<number | null>(null)
const [expanded, setExpanded] = useState(false)
// 整张卡收起(点标题):默认展开——交付物就是这一轮的结果;收起状态不保存,重开对话恢复展开。
const [cardOpen, setCardOpen] = useState(true)

useEffect(() => {
let alive = true
Expand Down Expand Up @@ -145,121 +122,42 @@ export function DeliverablesCard({
? 'chat.deliver.revealMac'
: 'chat.deliver.revealOther'
)
const count = t(files.length === 1 ? 'chat.deliver.countOne' : 'chat.deliver.count').replace(
'{n}',
String(files.length)
)
const foldable = files.length > FOLD_PREVIEW + 1
// 从头截取,行序号即文件在交付清单里的序号(IPC 按它取路径)。
const shown = foldable && !expanded ? files.slice(0, FOLD_PREVIEW) : files
// 收起时标题带上首个文件名与总数,不展开也知道交付了什么。
const summary =
files.length === 0
? ''
: files.length === 1
? files[0].name
: t('chat.deliver.collapsedMany')
.replace('{name}', files[0].name)
.replace('{n}', String(files.length))
.replace('{rest}', String(files.length - 1))
// 保留原始序号:打开、定位和复制仍由 Electron 的上下文与 IPC 完成。
const rows = files.map((f, i): DeliverableViewRow => {
const missing = loaded && f.size === null
const available = loaded && !missing
const canOpen = available && f.openable
const actions: DeliverableViewRow['actions'][number][] = []
if (canOpen) actions.push({ id: 'open', label: t('chat.deliver.open'), onClick: () => open(i) })
actions.push(
{ id: 'locate', label: revealLabel, onClick: () => reveal(i), disabled: !available },
{ id: 'copy', label: t('chat.deliver.copyPath'), onClick: () => copyPath(i, f.path), copied: copied === i }
)
return {
key: f.path,
index: i,
name: f.name,
title: f.path,
thumb: thumbs[i],
missing,
detail: missing ? t('chat.deliver.missing') : loaded ? `${formatDeliverableSize(f.size ?? 0)} · ${dirLabel(f)}` : dirLabel(f),
// 点整行:能打开就打开,否则在文件夹中显示(可执行 / 脚本类文件不直接打开)。
primary: available ? () => canOpen ? open(i) : reveal(i) : undefined,
actions
}
})

return (
<div className={`card deliv${cardOpen ? ' is-open' : ''}`}>
<button
type="button"
className="card__head deliv__head"
onClick={() => setCardOpen((v) => !v)}
aria-expanded={cardOpen}
>
<ChevronRight size={13} className="deliv__caret" />
<span className="card__head-icon">
<Package size={14} />
</span>
<span className="card__title">
{t('chat.deliver.title')}
{!cardOpen && summary && <span className="deliv__summary"> · {summary}</span>}
</span>
{cardOpen && <span className="deliv__count">{count}</span>}
</button>
<div className="deliv__list" hidden={!cardOpen}>
{shown.map((f, i) => {
const missing = loaded && f.size === null
const canOpen = loaded && !missing && f.openable
const thumb = thumbs[i]
// 点整行:能打开就打开,否则在文件夹中显示(可执行 / 脚本类文件不直接打开)。
const primary = (): void => (canOpen ? open(i) : reveal(i))
return (
<div key={f.path} className={`deliv__item${missing ? ' is-missing' : ''}`}>
<button
type="button"
className="deliv__main"
onClick={primary}
disabled={!loaded || missing}
title={f.path}
>
<span className="deliv__thumb">
{thumb ? <img src={thumb} alt="" draggable={false} /> : <File size={20} />}
</span>
<span className="deliv__meta">
<span className="deliv__name">{f.name}</span>
<span className="deliv__sub">
{missing
? t('chat.deliver.missing')
: loaded
? `${formatSize(f.size ?? 0)} · ${dirLabel(f)}`
: dirLabel(f)}
</span>
</span>
</button>
<span className="deliv__actions">
{canOpen && (
<button
type="button"
className="deliv__act"
onClick={() => open(i)}
title={t('chat.deliver.open')}
aria-label={t('chat.deliver.open')}
>
<ExternalLink size={14} />
</button>
)}
<button
type="button"
className="deliv__act"
onClick={() => reveal(i)}
disabled={!loaded || missing}
title={revealLabel}
aria-label={revealLabel}
>
<FolderOpen size={14} />
</button>
<button
type="button"
className="deliv__act"
onClick={() => copyPath(i, f.path)}
title={t('chat.deliver.copyPath')}
aria-label={t('chat.deliver.copyPath')}
>
{copied === i ? <Check size={14} /> : <Copy size={14} />}
</button>
</span>
</div>
)
})}
</div>
{cardOpen && foldable && (
<button
type="button"
className="deliv__more"
onClick={() => setExpanded((v) => !v)}
aria-expanded={expanded}
>
{expanded ? <ChevronUp size={13} /> : <ChevronDown size={13} />}
{expanded
? t('chat.deliver.collapse')
: t('chat.deliver.expand').replace('{n}', String(files.length - FOLD_PREVIEW))}
</button>
)}
</div>
<DeliverablesView
title={t('chat.deliver.title')}
labels={{
count: (n) => t(n === 1 ? 'chat.deliver.countOne' : 'chat.deliver.count').replace('{n}', String(n)),
collapsed: (name, n) => t('chat.deliver.collapsedMany')
.replace('{name}', name).replace('{n}', String(n)).replace('{rest}', String(n - 1)),
expand: (remaining) => t('chat.deliver.expand').replace('{n}', String(remaining)),
collapse: t('chat.deliver.collapse')
}}
rows={rows}
/>
)
}
131 changes: 131 additions & 0 deletions apps/desktop/src/renderer/src/features/chat/DeliverablesView.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,131 @@
import { useState, type ReactNode } from 'react'
import {
Check,
ChevronDown,
ChevronRight,
ChevronUp,
Copy,
Download,
ExternalLink,
Eye,
File,
FolderOpen,
Package
} from 'lucide-react'

// Leave six-file cards unfolded rather than creating a control for one remaining row.
const FOLD_PREVIEW = 5
const ACTION_ICONS = {
open: ExternalLink,
preview: Eye,
download: Download,
locate: FolderOpen,
copy: Copy
}

export interface DeliverableViewAction {
id: keyof typeof ACTION_ICONS
label: string
onClick: () => void
disabled?: boolean
copied?: boolean
}

export interface DeliverableViewRow {
key: string
index?: number
name: string
detail: string
title?: string
thumb?: string | null
missing?: boolean
primary?: () => void
actions: readonly DeliverableViewAction[]
}

interface DeliverablesViewProps {
title: string
labels: {
count: (n: number) => string
collapsed: (name: string, n: number) => string
expand: (remaining: number) => string
collapse: string
}
rows: readonly DeliverableViewRow[]
groupId?: string
origin?: 'reply' | 'desktop'
onCollapse?: () => void
children?: ReactNode
}

export function formatDeliverableSize(n: number): string {
if (n < 1024) return `${n} B`
if (n < 1024 * 1024) return `${Math.round(n / 1024)} KB`
if (n < 1024 * 1024 * 1024) return `${(n / 1024 / 1024).toFixed(1)} MB`
return `${(n / 1024 / 1024 / 1024).toFixed(1)} GB`
}

function DeliverableFileRow({ row }: { row: DeliverableViewRow }): React.JSX.Element {
return (
<div className={`deliv__item${row.missing ? ' is-missing' : ''}`}
data-testid="deliverables-file-row" data-delivery-item-index={row.index}>
<button type="button" className="deliv__main" onClick={row.primary}
disabled={!row.primary} title={row.title}>
<span className="deliv__thumb">
{row.thumb ? <img src={row.thumb} alt="" draggable={false} /> : <File size={20} />}
</span>
<span className="deliv__meta">
<span className="deliv__name">{row.name}</span>
<span className="deliv__sub">{row.detail}</span>
</span>
</button>
<span className="deliv__actions">
{row.actions.map(({ id, label, onClick, disabled, copied }) => {
const Icon = copied ? Check : ACTION_ICONS[id]
return (
<button key={id} type="button" className="deliv__act" data-testid={`deliverables-${id}`}
onClick={onClick} disabled={disabled} title={label} aria-label={label}>
<Icon size={14} />
</button>
)
})}
</span>
</div>
)
}

/** Shared file card; the host supplies display metadata and owns every action. */
export function DeliverablesView({ title, labels, rows, groupId, origin, onCollapse, children }: DeliverablesViewProps): React.JSX.Element {
const [expanded, setExpanded] = useState(false)
const [cardOpen, setCardOpen] = useState(true)
const foldable = rows.length > FOLD_PREVIEW + 1
const shown = foldable && !expanded ? rows.slice(0, FOLD_PREVIEW) : rows
const summary = rows.length > 1 ? labels.collapsed(rows[0].name, rows.length) : rows[0]?.name

return (
<div className={`card deliv${cardOpen ? ' is-open' : ''}`} data-testid="deliverables-card"
data-delivery-group-id={groupId} data-delivery-origin={origin} tabIndex={groupId ? -1 : undefined}>
<button type="button" className="card__head deliv__head" data-testid="deliverables-card-toggle"
onClick={() => { if (cardOpen) onCollapse?.(); setCardOpen(!cardOpen) }} aria-expanded={cardOpen}>
<ChevronRight size={13} className="deliv__caret" />
<span className="card__head-icon"><Package size={14} /></span>
<span className="card__title">
{title}
{!cardOpen && summary && <span className="deliv__summary"> · {summary}</span>}
</span>
{cardOpen && <span className="deliv__count">{labels.count(rows.length)}</span>}
</button>
<div className="deliv__list" hidden={!cardOpen}>
{shown.map((row) => <DeliverableFileRow key={row.key} row={row} />)}
{children}
</div>
{cardOpen && foldable && (
<button type="button" className="deliv__more" data-testid="deliverables-show-more"
onClick={() => setExpanded((v) => !v)} aria-expanded={expanded}>
{expanded ? <ChevronUp size={13} /> : <ChevronDown size={13} />}
{expanded ? labels.collapse : labels.expand(rows.length - FOLD_PREVIEW)}
</button>
)}
</div>
)
}
Loading
Loading