mirror of
https://github.com/ThearchyHelios/AgentLab.git
synced 2026-11-17 05:21:57 +00:00
e10c4f23fc
来自 2026-09 的 UI/UX 审查(142 条)。本提交是前两波,第三波(记录页接入时间轴、跨页互链、check-ui 更新、全站扫尾)另行提交。 地基 - 设计令牌:全局规则和 .btn/.field/.chip 放进 CSS 层,Tailwind 工具类重新生效,选中态、开启态不再被吞掉;字号阶梯; 辅助文字在所有底色上 >= 4.5:1;状态色专用,节点类型色与之拉开色相;「跟随系统」真的跟随,首帧不闪深色;新字标与 favicon - 基础组件:confirmDialog / promptDialog 取代原生对话框;toast 出错不自动消失、可复制、读屏可播报;离线横幅与断线恢复; 九种剪影的状态徽标;唯一一份状态文案(lib/status)、格式化(lib/format)、术语(lib/terms)、报错人话(lib/errors) - 运行态内核:事件折成航迹(run/trace.ts),可投影到任意时刻;取消 / 失败 / 服务重启后统一收尾,不再永远转圈; run.status 随事件回写;token 事件不再堆进 events - 后端:协作成员逐个完成即发事件,调度者决策有事件;时长分执行 / 墙钟 / 等人;API 时间带时区; 中断的运行也发 stream.end;运行列表可筛选翻页;删除运行 / 工作流有保护;运行默认值接通;可测未保存的配置; 报错说清发生了什么、为什么、怎么办 功能 - 画布:状态四重编码、固定高度遥测槽、按缩放三档、运行胶囊与 HUD、航迹时间轴与回放、执行轨迹边、 等待闸门、跟随执行、正式运行只读、一次性时刻(开场点亮、回扫、阻断级联、出具印章) - 编辑:撤销重做、版本历史、问题面板可定位、三栏可收起、模板与表达式字段区分、变量血缘、快捷键、带搜索的选择器 - 回答流 / 问数据:贴底才跟随滚动、工件下钻、出具横幅列出缺口、答案可复制导出、按会话的忙闲、 答案不再在 2000 字处截断、重启后这一轮会收尾 - 记录页:待审批 / 运行中 / 失败页签、筛选翻页、实时接流、排错路径指到节点、封存凭证常驻 - 管理页:新的「数据」页、写操作失败都有反馈、弹窗里先测连接、统一持久的连接状态 - 外壳:导航改版、⌘K 命令面板、? 快捷键帮助、404、页面标题与 favicon 状态点、后台提醒 验证(沙箱):tsc 干净,pytest 579 passed,14 个检查脚本中 13 个全绿;check-ui 剩 1 项旧断言(按旧日期格式找运行行),第三波更新。
99 lines
4.7 KiB
TypeScript
99 lines
4.7 KiB
TypeScript
import { useMemo } from 'react'
|
|
import type { Edge } from '@xyflow/react'
|
|
import { useStudio } from '../store/studio'
|
|
|
|
/**
|
|
* 变量血缘画在画布上。悬停变量(停靠栏里的一行、模板里的一枚胶囊)时:产出它的节点
|
|
* 实线描边、引用它的虚线描边,两者之间的走线提亮,其余节点和线退到 45%。
|
|
*
|
|
* 排查「为什么这里取到的是空值」,以前得在抽屉、检查器、画布三处之间来回对照;
|
|
* 这个产品的卖点就是看得见的数据流,偏偏缺了「数据从哪流到哪」这一眼。
|
|
*
|
|
* 画法是一段按 data-id 生成的样式,不给卡片和边加 props:lineage 一变只换这一段文字,
|
|
* 大图上也不用让每张卡片各自订阅、各自重渲染。压暗走卡片自己的 --nc-dim、线色走
|
|
* --sf-edge,和卡片、走线原有的过渡和 reduced-motion 规则一起生效,不另起动画。
|
|
* 画布要自己画血缘的话,在 .react-flow 上写 data-lineage-native,这一层就让开。
|
|
*/
|
|
export function LineageLayer() {
|
|
const lineage = useStudio((s) => s.lineage)
|
|
const edges = useStudio((s) => s.edges)
|
|
const css = useMemo(() => (lineage ? lineageCss(lineage, edges) : ''), [lineage, edges])
|
|
return css ? <style data-lineage={lineage!.var}>{css}</style> : null
|
|
}
|
|
|
|
type Lineage = { var: string; producers: string[]; consumers: string[] }
|
|
|
|
const ROOT = '.react-flow:not([data-lineage-native])'
|
|
const q = (s: string) => `"${s.replace(/["\\]/g, '\\$&')}"`
|
|
const ids = (list: Iterable<string>) => [...list].map((id) => `[data-id=${q(id)}]`).join(',')
|
|
|
|
/**
|
|
* 产出者和引用者之间往往隔着好几跳,只取直连边会断成几截。一条边 u→v 在某条
|
|
* 「产出 → … → 引用」的路上,当且仅当 u 能从产出者走到、v 能走到引用者
|
|
*/
|
|
export function lineagePath(lineage: Lineage, edges: Pick<Edge, 'id' | 'source' | 'target'>[]) {
|
|
const out = new Map<string, string[]>()
|
|
const inc = new Map<string, string[]>()
|
|
for (const e of edges) {
|
|
out.set(e.source, [...(out.get(e.source) ?? []), e.target])
|
|
inc.set(e.target, [...(inc.get(e.target) ?? []), e.source])
|
|
}
|
|
const walk = (seeds: string[], next: Map<string, string[]>) => {
|
|
const seen = new Set(seeds)
|
|
const stack = [...seeds]
|
|
while (stack.length) {
|
|
for (const n of next.get(stack.pop()!) ?? []) {
|
|
if (!seen.has(n)) { seen.add(n); stack.push(n) }
|
|
}
|
|
}
|
|
return seen
|
|
}
|
|
const down = walk(lineage.producers, out)
|
|
const up = walk(lineage.consumers, inc)
|
|
const path = lineage.producers.length && lineage.consumers.length
|
|
? edges.filter((e) => down.has(e.source) && up.has(e.target))
|
|
: []
|
|
const through = new Set<string>([...lineage.producers, ...lineage.consumers])
|
|
for (const e of path) { through.add(e.source); through.add(e.target) }
|
|
return { path, through }
|
|
}
|
|
|
|
function lineageCss(lineage: Lineage, edges: Edge[]): string {
|
|
const { path, through } = lineagePath(lineage, edges)
|
|
if (!through.size) return ''
|
|
// 标签按缩放反向补回来:缩到 0.4 时卡片上的 10px 只剩 4px,看不出写的是什么
|
|
const tag = `position: absolute; bottom: 100%; left: 0; margin-bottom: calc(4px / var(--zoom, 1));
|
|
padding: 0 calc(5px / var(--zoom, 1)); border-radius: calc(3px / var(--zoom, 1));
|
|
font: 600 min(calc(10px / var(--zoom, 1)), 26px) / 1.45 var(--font-sans); white-space: nowrap; pointer-events: none;`
|
|
const rules = [
|
|
`${ROOT} .react-flow__node > .nc { --nc-dim: 0.45; }`,
|
|
`${ROOT} .react-flow__node:is(${ids(through)}) > .nc { --nc-dim: 1; }`,
|
|
`${ROOT} .react-flow__edge { opacity: 0.45; }`,
|
|
]
|
|
if (lineage.producers.length) {
|
|
rules.push(
|
|
`${ROOT} .react-flow__node:is(${ids(lineage.producers)}) > .nc {
|
|
box-shadow: 0 0 0 2px var(--bg), 0 0 0 3.5px var(--accent), var(--elev-2); }`,
|
|
`${ROOT} .react-flow__node:is(${ids(lineage.producers)}) > .nc::after {
|
|
content: ${q(`产出 ${lineage.var}`)}; ${tag} background: var(--accent-solid); color: var(--on-accent); }`,
|
|
)
|
|
}
|
|
if (lineage.consumers.length) {
|
|
rules.push(
|
|
`${ROOT} .react-flow__node:is(${ids(lineage.consumers)}) > .nc {
|
|
outline: 1.5px dashed var(--accent); outline-offset: 3px; }`,
|
|
`${ROOT} .react-flow__node:is(${ids(lineage.consumers)}) > .nc::after {
|
|
content: "引用"; ${tag} background: var(--bg-elev); color: var(--accent);
|
|
box-shadow: inset 0 0 0 1px var(--accent); }`,
|
|
)
|
|
}
|
|
if (path.length) {
|
|
const on = ids(path.map((e) => e.id))
|
|
rules.push(
|
|
`${ROOT} .react-flow__edge:is(${on}) { opacity: 1; --sf-edge: var(--accent); }`,
|
|
`${ROOT} .react-flow__edge:is(${on}) .react-flow__edge-path { stroke: var(--accent); }`,
|
|
)
|
|
}
|
|
return rules.join('\n')
|
|
}
|