mirror of
https://github.com/ThearchyHelios/AgentLab.git
synced 2026-11-23 03:41:59 +00:00
右栏重构:助手常驻,属性改为盖上去的一层
两个问题都源于同一件事——一栏 360px 被要求同时干两件活。 **没地方引导写问题。** Copilot 输入框是个 38px 高的框,挤在一条长长的流 底下,比它上面任何一块都不起眼;例句被截断成 16 个字的 chip,示范"该说到 什么颗粒度"这个作用就没了,只剩装饰。改成一个组件两种体量:没说过话时它 就是这一栏的主体(竖直居中、三行高、自动聚焦、完整句子的例句),并且告诉 用户它能够到什么(N 个数据源 / M 个工具)——不然"查销售库"这种话有没有意义 只能靠猜。有了对话之后它退到底部两行。不做成两个组件:那就是两个实例, 切换时会卸载其中一个,草稿、光标、输入法候选词全没。 **Copilot 和属性挤在一起。** 它们原是 [助手|属性] 两个 tab,而 tab 是互斥的 ——跑图跑到一半点开节点看配置,整条执行过程就从眼前消失,切回来滚动位置和 输入草稿也没了(切 tab 会卸载组件)。改成属性滑出来盖在助手上:助手一直在 下面活着,属性是临时造访者。头部给一个明确的"‹ 助手",Esc 关得掉;盖住 期间底部留一条执行进度,点一下回去——不能因为换了实现就把原来最难受的 那个场景原样留着。 运行控件搬去工具栏。它原先和 Copilot 输入框一起常驻助手栏,两个都是"主要 动作"互相压着;而它们是两种意图(跑这张图 / 改这张图)。运行是对整张图的 动作,和保存、发布同类。有输入字段就弹表单,没有就一键直接跑。 顺带修了两处状态说反的地方: - 停在人工介入时,承载的节点还在转蓝圈。转圈说的是"它在忙,你等着",而 实际正相反——它在等你。改成待办色 + 手势图标。 - "继续执行"的去重原先靠"界面上还有没有 waiting 步骤",上一条改动多了一处 产生 waiting 的地方就失效了。改用事件相邻性判断——那是这两条事件的固有 性质,不会因为别处改了展示而变。 动效:面板滑入、例句依次入场、正在出字的那一步有一道光扫过(比转圈多说 一件事:它在产出,不只是在等)、空态标记轻微呼吸。全部 240ms 以内,缓动 统一 cubic-bezier(.32,.72,0,1)。另外补上了此前完全没有的 prefers-reduced-motion——这套界面里动的东西不少(边在流动、节点在脉冲、 面板在滑),系统里关了还照播,对前庭敏感的人是实打实的难受。 验证:check-ui 重写了助手栏那一节,核心断言是"选中节点再回来,输入的字 还在"——那正是 tab 方案做不到的。新增一条用 emulateMedia 验证关掉动效后 动画确实停了。真跑了一次带人工审批的图,期间打开属性面板确认进度条还在。 四套检查 + 82 个后端测试全过,生产构建通过。
This commit is contained in:
@@ -1,27 +1,24 @@
|
||||
import { useEffect, useMemo, useRef, useState } from 'react'
|
||||
import { Code2, Send, Settings2, Sparkles, Square, Trash2 } from 'lucide-react'
|
||||
import { useMemo, useRef, useState, useEffect } from 'react'
|
||||
import { Code2, Eraser } from 'lucide-react'
|
||||
import clsx from 'clsx'
|
||||
import { api } from '../api/client'
|
||||
import { useCatalog, modelOptions } from '../store/catalog'
|
||||
import { useCatalog } from '../store/catalog'
|
||||
import { useStudio } from '../store/studio'
|
||||
import { Spinner, useToast } from '../components/ui'
|
||||
import { AssistantStream, StreamEmpty, type StreamTurn } from './AssistantStream'
|
||||
import { Spinner } from '../components/ui'
|
||||
import { AssistantStream, type StreamTurn } from './AssistantStream'
|
||||
import { Composer } from './Composer'
|
||||
import { decodeCopilot, decodeRun, formatDuration } from './decode'
|
||||
import { ApprovalCard, RunLauncher } from './RunPanel'
|
||||
import { ApprovalCard } from './RunPanel'
|
||||
|
||||
/**
|
||||
* 画布右栏的助手。
|
||||
* 画布右栏:助手。
|
||||
*
|
||||
* 取代原来的「运行 / 属性 → 时间线 / 成果 / 事件」两层嵌套(5 个视图,
|
||||
* 每个只装一小块,找什么都得先猜在哪一层)。现在一栏一条流:你让它做什么、
|
||||
* 它做了什么、结果是什么,按时间从上往下。
|
||||
* 这一栏现在只有一件事——和 Copilot 说话,以及看它和运行做了什么。属性不再
|
||||
* 和它平级挤在两个 tab 里:选中一个节点会滑出属性面板盖在上面,关掉就回到
|
||||
* 原处。之前是切 tab,而 tab 是互斥的——跑图跑到一半点开一个节点看配置,
|
||||
* 整条执行过程就从眼前消失了,回来还得重新找位置。
|
||||
*
|
||||
* 两件事在这里合流——Copilot 建图和跑图。它们在协议上完全无关(SSE 操作流
|
||||
* vs 事件 WebSocket,不共享 seq 和 node_id),但对用户是同一件事的两半:
|
||||
* "帮我搭一个能算月度毛利的流程" → "跑一下"。decode.ts 把两种流翻译成同一种
|
||||
* Step,这里才能把它们排进同一条时间轴。
|
||||
*
|
||||
* 右栏不能删:它是发起运行和处理审批的唯一入口,RunLauncher 必须留着。
|
||||
* 两种体量:没说过话时输入框是主体(竖直居中、带例句),有对话之后它退到
|
||||
* 底部,上面让给过程。
|
||||
*/
|
||||
export function AssistantPanel() {
|
||||
const run = useStudio((s) => s.run)
|
||||
@@ -40,30 +37,28 @@ export function AssistantPanel() {
|
||||
id: t.id,
|
||||
question: t.instruction,
|
||||
phase: t.phase === 'running' ? 'running' : t.phase === 'error' ? 'error' : 'done',
|
||||
// 生成期间不能只给一个孤零零的转圈图标。具体阶段从 copilot 实时状态
|
||||
// 里取——它只对当前这一轮有效,历史轮次用固定文案
|
||||
status: t.phase === 'running'
|
||||
? (copilot.lastOp || PHASE_TEXT[copilot.phase] || '正在生成流程…')
|
||||
// 生成期间不能只给一个孤零零的转圈图标。具体阶段从 copilot 实时状态里取
|
||||
status: t.phase === 'running' ? (copilot.lastOp || '正在生成流程…')
|
||||
: t.phase === 'done' ? '流程已更新到画布' : '',
|
||||
steps: decodeCopilot(t.ops),
|
||||
output: t.explanation ? { 说明: t.explanation } : null,
|
||||
error: t.error,
|
||||
}))
|
||||
if (run) {
|
||||
const steps = decodeRun(events)
|
||||
// run 对象是启动时的快照,成果在 run.finished 事件里
|
||||
const finished = [...events].reverse().find((e) => e.type === 'run.finished')
|
||||
const failedEvent = [...events].reverse().find((e) => e.type === 'run.failed')
|
||||
const waiting = pending.length > 0
|
||||
list.push({
|
||||
id: run.id,
|
||||
question: undefined, // 运行的"问题"是输入表单,已经在上面填过了
|
||||
// 运行的"问题"是输入表单,已经在工具栏那边填过了
|
||||
question: undefined,
|
||||
phase: failedEvent ? 'error'
|
||||
: waiting ? 'waiting'
|
||||
: streaming ? 'running'
|
||||
: finished ? 'done' : 'running',
|
||||
status: streaming ? '正在执行…' : waiting ? '等待你的确认' : finished ? '完成' : '',
|
||||
steps,
|
||||
steps: decodeRun(events),
|
||||
// run 对象是启动时的快照,成果在 run.finished 事件里
|
||||
output: finished?.data?.output ?? run.output ?? null,
|
||||
error: failedEvent ? String(failedEvent.data?.error ?? '运行失败') : run.error || undefined,
|
||||
runId: run.id,
|
||||
@@ -71,250 +66,97 @@ export function AssistantPanel() {
|
||||
})
|
||||
}
|
||||
return list
|
||||
}, [copilotTurns, run, events, streaming, pending.length, copilot.lastOp, copilot.phase])
|
||||
}, [copilotTurns, run, events, streaming, pending.length, copilot.lastOp])
|
||||
|
||||
const empty = !turns.length
|
||||
|
||||
return (
|
||||
<div className="flex h-full flex-col">
|
||||
<RunLauncher />
|
||||
|
||||
{pending.map((approval) => (
|
||||
<ApprovalCard key={approval.id} approval={approval}
|
||||
onResolved={(runId) => attachRun(runId)} />
|
||||
))}
|
||||
|
||||
<div className="min-h-0 flex-1">
|
||||
{raw ? <RawEvents /> : (
|
||||
<AssistantStream
|
||||
turns={turns}
|
||||
dense
|
||||
empty={<PanelEmpty />}
|
||||
/>
|
||||
)}
|
||||
</div>
|
||||
|
||||
<Composer />
|
||||
|
||||
<div className="flex items-center gap-2 border-t px-2.5 py-1 text-[10px] text-faint">
|
||||
{run ? (
|
||||
<>
|
||||
<span className="mono truncate" title={run.id}>#{run.id.slice(0, 8)}</span>
|
||||
{run.run_class === 'formal'
|
||||
? <span className="chip" style={{ color: 'var(--ok)', borderColor: 'var(--ok)' }}>正式 v{run.version}</span>
|
||||
: <span className="chip">探索</span>}
|
||||
{streaming && <span className="text-[var(--accent)]">● 实时</span>}
|
||||
<span className="flex-1" />
|
||||
{!!run.usage?.total_tokens && <span>{run.usage.total_tokens} tok</span>}
|
||||
{run.usage?.cost_usd ? <span>${Number(run.usage.cost_usd).toFixed(4)}</span> : null}
|
||||
{run.usage?.duration_ms ? <span>{formatDuration(run.usage.duration_ms)}</span> : null}
|
||||
</>
|
||||
) : <span className="flex-1" />}
|
||||
{!!copilotTurns.length && !raw && (
|
||||
<button className="hover:text-dim" title="清空助手记录(不影响画布)"
|
||||
onClick={clearCopilot}>
|
||||
<Trash2 size={11} />
|
||||
</button>
|
||||
)}
|
||||
{/* 原始事件是排查用的开发者视图,不该占一个常驻 tab——但也不能删,
|
||||
翻译层出问题时它是唯一能对照的东西 */}
|
||||
<button
|
||||
className={clsx('flex items-center gap-1 hover:text-dim', raw && 'text-[var(--accent)]')}
|
||||
title={raw ? '回到助手视图' : `看原始事件(${events.length} 条)`}
|
||||
onClick={() => setRaw((v) => !v)}
|
||||
>
|
||||
<Code2 size={11} />
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
function PanelEmpty() {
|
||||
const nodes = useStudio((s) => s.nodes)
|
||||
return (
|
||||
<StreamEmpty
|
||||
icon={<Sparkles size={20} />}
|
||||
title={nodes.length ? '还没有动静' : '从一句话开始'}
|
||||
hint={nodes.length
|
||||
? '上面填好输入点「试运行」,或者在下面告诉它要改什么'
|
||||
: '在下面描述你要的流程,它会直接画到左边的画布上'}
|
||||
/>
|
||||
)
|
||||
}
|
||||
|
||||
// -------------------------------------------------------------------------
|
||||
|
||||
const EXAMPLES = [
|
||||
'读取用户上传的问题,先查知识库,查到就基于资料回答并标注出处,查不到就联网搜索',
|
||||
'把一段长文本拆成要点,逐条用模型打分,低分的让模型重写一次,最后汇总成表格',
|
||||
'写代码分析数据,在沙箱里跑,出错就把报错喂回去让模型修,最多修三次',
|
||||
]
|
||||
|
||||
/**
|
||||
* Copilot 输入框。
|
||||
*
|
||||
* 原来是个 Modal:点按钮 → 弹窗 → 输入 → 关闭弹窗 → 盯着画布上的浮条看。
|
||||
* 每改一次图都要重走一遍,而且弹窗关掉之后需求文本就没了,想微调只能重打。
|
||||
* 放进侧栏之后它就是个普通输入框,说完一句接着说下一句。
|
||||
*/
|
||||
function Composer() {
|
||||
const nodes = useStudio((s) => s.nodes)
|
||||
const copilot = useStudio((s) => s.copilot)
|
||||
const { runCopilot, stopCopilot, retryCopilot } = useStudio()
|
||||
const providers = useCatalog((s) => s.providers)
|
||||
const [text, setText] = useState('')
|
||||
const [opts, setOpts] = useState(false)
|
||||
const [model, setModel] = useState('')
|
||||
const [effective, setEffective] = useState('')
|
||||
const [useBase, setUseBase] = useState(true)
|
||||
const ref = useRef<HTMLTextAreaElement>(null)
|
||||
|
||||
// Copilot 的模型是独立设置:它写的是编排本身,值得和工作流节点分开选
|
||||
useEffect(() => {
|
||||
void api.copilot.getModel().then((m) => {
|
||||
setModel(m.model ?? '')
|
||||
setEffective(m.effective_model ?? '')
|
||||
}).catch(() => undefined)
|
||||
}, [])
|
||||
|
||||
// 工具栏的 Copilot 按钮把焦点甩过来
|
||||
useEffect(() => {
|
||||
const focus = () => ref.current?.focus()
|
||||
window.addEventListener('agentlab:focus-copilot', focus)
|
||||
return () => window.removeEventListener('agentlab:focus-copilot', focus)
|
||||
}, [])
|
||||
|
||||
const pickModel = (value: string) => {
|
||||
setModel(value)
|
||||
void api.copilot.setModel({ model: value || null })
|
||||
.then((m) => setEffective(m.effective_model ?? ''))
|
||||
.catch(() => undefined)
|
||||
}
|
||||
|
||||
const send = () => {
|
||||
const q = text.trim()
|
||||
if (!q || copilot.active) return
|
||||
runCopilot(q, useBase && nodes.length > 0, model || undefined)
|
||||
setText('')
|
||||
}
|
||||
|
||||
const options = modelOptions(providers)
|
||||
const groups = [...new Set(options.map((o) => o.group))]
|
||||
|
||||
return (
|
||||
<div className="shrink-0 border-t">
|
||||
{copilot.error && (
|
||||
<div className="flex items-center gap-2 border-b px-2.5 py-1.5 text-[10.5px]"
|
||||
style={{ color: 'var(--err)' }}>
|
||||
<span className="min-w-0 flex-1">{copilot.error}</span>
|
||||
{/* 失败多半跟需求本身无关(模型抽风、协议跑偏、网断了),
|
||||
不该逼用户把需求再敲一遍 */}
|
||||
{copilot.lastInstruction && (
|
||||
<button className="btn btn-sm shrink-0" onClick={retryCopilot}>重试</button>
|
||||
{!empty && (
|
||||
<div className="flex shrink-0 items-center gap-2 border-b px-2.5 py-1.5">
|
||||
<span className="text-[11px] font-semibold">助手</span>
|
||||
{streaming && (
|
||||
<span className="flex items-center gap-1 text-[10px]" style={{ color: 'var(--accent)' }}>
|
||||
<Spinner size={9} /> 执行中
|
||||
</span>
|
||||
)}
|
||||
</div>
|
||||
)}
|
||||
|
||||
{!nodes.length && !copilot.active && (
|
||||
<div className="flex flex-wrap gap-1 border-b px-2.5 py-1.5">
|
||||
{EXAMPLES.map((ex) => (
|
||||
<button key={ex} className="chip text-left hover:border-[var(--accent)]"
|
||||
title={ex} onClick={() => { setText(ex); ref.current?.focus() }}>
|
||||
{ex.slice(0, 16)}…
|
||||
<span className="flex-1" />
|
||||
{run && (
|
||||
<span className="mono text-[9.5px] text-faint" title={run.id}>
|
||||
#{run.id.slice(0, 6)}
|
||||
</span>
|
||||
)}
|
||||
{/* 原始事件是排查用的开发者视图,不该占一个常驻 tab——但也不能删,
|
||||
翻译层出问题时它是唯一能对照的东西 */}
|
||||
<button
|
||||
className={clsx('rounded p-1 transition-colors hover:bg-hover',
|
||||
raw ? 'text-[var(--accent)]' : 'text-faint')}
|
||||
title={raw ? '回到助手视图' : `看原始事件(${events.length} 条)`}
|
||||
onClick={() => setRaw((v) => !v)}
|
||||
>
|
||||
<Code2 size={12} />
|
||||
</button>
|
||||
{!!copilotTurns.length && (
|
||||
<button className="rounded p-1 text-faint transition-colors hover:bg-hover"
|
||||
title="清空助手记录(不影响画布)" onClick={clearCopilot}>
|
||||
<Eraser size={12} />
|
||||
</button>
|
||||
))}
|
||||
)}
|
||||
</div>
|
||||
)}
|
||||
|
||||
{opts && (
|
||||
<div className="space-y-2 border-b px-2.5 py-2">
|
||||
<div>
|
||||
<label className="label">Copilot 用哪个模型</label>
|
||||
<select className="field" value={model} onChange={(e) => pickModel(e.target.value)}>
|
||||
<option value="">跟随默认{effective ? `(当前:${effective})` : ''}</option>
|
||||
{groups.map((g) => (
|
||||
<optgroup key={g} label={g}>
|
||||
{options.filter((o) => o.group === g).map((o) => (
|
||||
<option key={g + o.value} value={o.value}>{o.label}</option>
|
||||
))}
|
||||
</optgroup>
|
||||
))}
|
||||
</select>
|
||||
<div className="mt-1 text-[10px] leading-snug text-faint">
|
||||
只影响 Copilot 自己,不改节点上的模型。它要按协议逐行输出操作,
|
||||
指令遵循弱的模型生成不出东西。
|
||||
</div>
|
||||
{empty ? (
|
||||
// 没说过话时输入框就是这一栏的主体,竖直居中。之前它是个 38px 高的
|
||||
// 框挤在最底下,比上面任何一块都不起眼——"没地方引导写问题"说的就是它
|
||||
<div className="flex min-h-0 flex-1 flex-col justify-center overflow-y-auto py-6">
|
||||
<Composer hero />
|
||||
</div>
|
||||
) : (
|
||||
<>
|
||||
<div className="min-h-0 flex-1">
|
||||
{raw ? <RawEvents /> : (
|
||||
<AssistantStream
|
||||
turns={turns}
|
||||
dense
|
||||
// 审批卡插在它所属的那一轮里,而不是浮在整栏顶上:
|
||||
// "等你确认"和确认的按钮之间隔着整条执行过程,是两件事
|
||||
approvalsFor={(t) => (
|
||||
t.runId && pending.length ? (
|
||||
<div className="fade-up mt-2 overflow-hidden rounded-lg border"
|
||||
style={{ borderColor: 'var(--warn)' }}>
|
||||
{pending.map((a) => (
|
||||
<ApprovalCard key={a.id} approval={a}
|
||||
onResolved={(runId) => attachRun(runId)} />
|
||||
))}
|
||||
</div>
|
||||
) : null
|
||||
)}
|
||||
/>
|
||||
)}
|
||||
</div>
|
||||
{!!nodes.length && (
|
||||
<label className="flex items-center gap-2 text-[11px]">
|
||||
<input type="checkbox" checked={useBase} className="accent-[var(--accent)]"
|
||||
onChange={(e) => setUseBase(e.target.checked)} />
|
||||
在当前这张图上改(不勾就重新生成)
|
||||
</label>
|
||||
)}
|
||||
</div>
|
||||
)}
|
||||
|
||||
<div className="flex items-end gap-1.5 p-2">
|
||||
<button className={clsx('btn btn-sm btn-ghost shrink-0', opts && 'text-[var(--accent)]')}
|
||||
title="模型和生成方式" onClick={() => setOpts((v) => !v)}>
|
||||
<Settings2 size={12} />
|
||||
</button>
|
||||
<textarea
|
||||
ref={ref}
|
||||
className="field min-h-[38px] flex-1 resize-none py-1.5 text-[11.5px]"
|
||||
rows={2}
|
||||
value={text}
|
||||
placeholder={nodes.length ? '告诉它要改什么…' : '描述你要的流程…'}
|
||||
onChange={(e) => setText(e.target.value)}
|
||||
onKeyDown={(e) => {
|
||||
if (e.key === 'Enter' && !e.shiftKey) { e.preventDefault(); send() }
|
||||
}}
|
||||
/>
|
||||
{copilot.active ? (
|
||||
<button className="btn btn-sm btn-danger shrink-0" onClick={stopCopilot} title="取消生成">
|
||||
<Square size={11} />
|
||||
</button>
|
||||
) : (
|
||||
<button className="btn btn-sm btn-primary shrink-0" onClick={send}
|
||||
disabled={!text.trim()} title="生成到画布(Enter)">
|
||||
<Send size={11} />
|
||||
</button>
|
||||
)}
|
||||
</div>
|
||||
|
||||
{copilot.active && (
|
||||
<div className="flex items-center gap-1.5 border-t px-2.5 py-1 text-[10px] text-faint">
|
||||
<Spinner size={10} />
|
||||
<span className="min-w-0 flex-1 truncate">
|
||||
{copilot.lastOp || PHASE_TEXT[copilot.phase] || '正在起草…'}
|
||||
</span>
|
||||
{copilot.model && <span className="truncate">{copilot.model}</span>}
|
||||
{copilot.elapsedMs > 0 && (
|
||||
<span className="mono">{Math.round(copilot.elapsedMs / 1000)}s</span>
|
||||
)}
|
||||
</div>
|
||||
)}
|
||||
{!copilot.active && !!copilot.explanation && (
|
||||
<div className="border-t px-2.5 py-1 text-[10px] text-faint">
|
||||
结果不会自动保存,检查无误记得 ⌘S
|
||||
</div>
|
||||
<Composer hero={false} />
|
||||
{run && <RunFooter />}
|
||||
</>
|
||||
)}
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
// 从提交到第一个节点落地中间有 5~30 秒。阶段会变本身就是"它还活着"的信号,
|
||||
// 恒定的"正在起草…"让人分不清是在想还是已经卡死
|
||||
const PHASE_TEXT: Record<string, string> = {
|
||||
connecting: '正在连接模型…',
|
||||
planning: '正在理解需求、规划结构…',
|
||||
building: '正在放置节点…',
|
||||
wiring: '正在连接数据流…',
|
||||
finalizing: '正在排版和校验…',
|
||||
function RunFooter() {
|
||||
const run = useStudio((s) => s.run)!
|
||||
return (
|
||||
<div className="flex shrink-0 items-center gap-2 border-t px-2.5 py-1 text-[9.5px] text-faint">
|
||||
{run.run_class === 'formal'
|
||||
? <span className="chip" style={{ color: 'var(--ok)', borderColor: 'var(--ok)' }}>正式 v{run.version}</span>
|
||||
: <span className="chip">探索</span>}
|
||||
<span className="flex-1" />
|
||||
{!!run.usage?.total_tokens && <span>{run.usage.total_tokens} tok</span>}
|
||||
{run.usage?.cost_usd ? <span>${Number(run.usage.cost_usd).toFixed(4)}</span> : null}
|
||||
{run.usage?.duration_ms ? <span>{formatDuration(run.usage.duration_ms)}</span> : null}
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
// -------------------------------------------------------------------------
|
||||
|
||||
/** 原始事件。翻译层出问题时用来对照,平时收着。 */
|
||||
function RawEvents() {
|
||||
const events = useStudio((s) => s.events)
|
||||
|
||||
Reference in New Issue
Block a user