mirror of
https://github.com/ThearchyHelios/AgentLab.git
synced 2026-11-25 20:22:52 +00:00
587bf7e27c
起因是一次探索运行:Copilot 改节点时把工具绑定整份抹掉,agent 没有工具只能写「假设调用」, 校验节点的自动修复编出 total_count=0 让 schema 通过,协作成员把工具调用标记当文字输出了四轮, 轮数用完后节点把原话当成功结果交出去——运行标成已完成,数据库一次都没查。 平台可信度(先写失败测试) - Copilot 修改节点改为合并:没写的字段保留,null 才删除;协作成员按名字合并。前后端同一套规则, 工具集合变小时自查报警、改图回执列出变化 - 新校验规则:提示词点名了某个工具而节点没有绑定它,判错误,Copilot 自查会交回去修 - 校验修复只许改格式:冒出原文没有的值就判修复无效;修复这次模型调用计入用量 - 识别模型把工具调用写成文字的情况(DSML、<tool_call> 等标记):纠正一次,仍然如此就判失败并说明原因 - 协作团队用完轮数不再按成功交付:默认失败,可选降档,点出一次都没派到的成员 - 审批恢复后,同一节点里已经执行过的工具调用复用结果,不再重复执行 后端 - 查询时限交给数据库执行(Oracle call_timeout、PG statement_timeout、MySQL max_execution_time、 SQLite progress handler),可按数据源配置;超时报错与实际耗时一致 - 等审批的运行可以真正取消;会话列表带最后一轮状态;测连接结果持久化;探查结构可只看不存; 自定义工具可草稿试跑、写坏的参数定义保存时拒绝;MCP 服务改动后作废旧工具缓存; 检索命中带贡献分解;重建索引在后台跑并报进度;报错统一收进 core/errors 前端 - 公共层:管理页共用件、失败说明(lib/explain)、健康状态进公共库;目录按表各自加载并有超时, 一张表卡住不再拖垮整站;上传显示真实字节进度;离线横幅只播报不变的句子 - 画布:卡片只说游标所在的那一次执行;等审批时可放弃运行;团队收尾判定与未完成说清楚; 回放用量取那一刻的值 - 编排页:Copilot 合并语义与工具变化回执;「用完轮数时」选项;正式运行期间锁住所有改图入口 - 回答流 / 问数据:新失败类型说人话并给下一步;画布与右栏互相定位;数据源范围、回收站、重新核对 - 记录页:「航迹」页签复用画布时间轴,可拖动回放、列出关键时刻;列表行带执行 / 等人 / 失败缩略条 - 外壳:统一的离开前确认(data router),导航、⌘K、快捷键、后退都会先问 验证(沙箱):tsc 干净,pytest 838 passed(两遍),14 个检查脚本中 13 个全绿; check-ui 余 1 项旧断言(按旧日期格式找运行行),3c 更新。
196 lines
8.8 KiB
TypeScript
196 lines
8.8 KiB
TypeScript
import { useState } from 'react'
|
||
import { createPortal } from 'react-dom'
|
||
import { Lock, PanelLeftClose, PanelLeftOpen } from 'lucide-react'
|
||
import clsx from 'clsx'
|
||
import { NODE_CATEGORIES, NODE_DEFS, type NodeDef } from './nodeDefs'
|
||
import { hintOf } from './shortcuts'
|
||
import { EDIT_LOCK_TEXT, useEditLock, useStudio } from '../store/studio'
|
||
import { IconButton } from '../components/ui'
|
||
import type { NodeType } from '../types'
|
||
|
||
/** 节点库搜索框的 id:「/」要把焦点送过来 */
|
||
export const PALETTE_SEARCH_ID = 'studio-palette-search'
|
||
|
||
const startDrag = (e: React.DragEvent, def: NodeDef) => {
|
||
e.dataTransfer.setData('application/agentlab-node', def.type)
|
||
e.dataTransfer.effectAllowed = 'move'
|
||
}
|
||
|
||
/**
|
||
* 左侧节点库。拖到画布,或点一下放在视野中间的空地上(新节点自动选中)。
|
||
*
|
||
* 可以收成 48px 的图标轨:画布才是主角。1024 宽时三栏固定占掉 624px,画布只剩约
|
||
* 400px,一张八个节点的图被缩成一条线。收起后悬停图标浮出名字和说明,拖拽照常。
|
||
*/
|
||
export function Palette({ collapsed, onToggle }: { collapsed: boolean; onToggle: () => void }) {
|
||
const [query, setQuery] = useState('')
|
||
const addNode = useStudio((s) => s.addNode)
|
||
// 助手在改、正式运行在跑:点了、拖了都落不下来,整块置灰并说清为什么
|
||
const lock = useEditLock()
|
||
const locked = lock != null
|
||
|
||
if (collapsed) return <Rail onToggle={onToggle} onAdd={(t) => addNode(t)} lock={lock} />
|
||
|
||
const q = query.trim().toLowerCase()
|
||
const defs = Object.values(NODE_DEFS).filter(
|
||
(d) => !q || d.label.toLowerCase().includes(q) || d.description.includes(q) || d.type.includes(q),
|
||
)
|
||
|
||
return (
|
||
<div className="flex h-full flex-col" aria-label="节点库">
|
||
<div className="flex items-center gap-1 border-b p-2">
|
||
<input
|
||
id={PALETTE_SEARCH_ID}
|
||
className="field"
|
||
placeholder="搜索节点…(/)"
|
||
value={query}
|
||
onChange={(e) => setQuery(e.target.value)}
|
||
onKeyDown={(e) => {
|
||
// 回车直接加第一个:搜索 → 添加一气呵成,不用再去点
|
||
if (e.key === 'Enter' && defs[0] && !locked && !e.nativeEvent.isComposing) {
|
||
e.preventDefault()
|
||
addNode(defs[0].type as NodeType)
|
||
} else if (e.key === 'Escape') {
|
||
setQuery('')
|
||
;(e.target as HTMLInputElement).blur()
|
||
}
|
||
}}
|
||
/>
|
||
<IconButton label="收起节点库" title={hintOf('收起节点库', 'palette')} onClick={onToggle}
|
||
icon={<PanelLeftClose size={13} />} />
|
||
</div>
|
||
<div className={clsx('flex-1 overflow-y-auto p-2', locked && 'pointer-events-none opacity-50')}
|
||
aria-disabled={locked || undefined}>
|
||
{NODE_CATEGORIES.map((category) => {
|
||
const items = defs.filter((d) => d.category === category)
|
||
if (!items.length) return null
|
||
return (
|
||
<div key={category} className="mb-3">
|
||
<div className="mb-1.5 px-1 text-2xs font-semibold tracking-wider text-faint">
|
||
{category}
|
||
</div>
|
||
<div className="space-y-1">
|
||
{items.map((def, i) => (
|
||
<button
|
||
type="button"
|
||
key={def.type}
|
||
draggable={!locked}
|
||
onDragStart={(e) => startDrag(e, def)}
|
||
onClick={() => addNode(def.type as NodeType)}
|
||
className={clsx(
|
||
`nt-${def.type} group flex w-full cursor-grab items-start gap-2 rounded-md border border-transparent px-2 py-1.5 text-left hover:border-[var(--border)] hover:bg-hover active:cursor-grabbing`,
|
||
q && category === defs[0]?.category && i === 0 && 'border-[var(--border)] bg-hover',
|
||
)}
|
||
title={`${def.description}\n点一下放在视野中间,或拖到画布上`}
|
||
>
|
||
<TypeIcon def={def} />
|
||
<div className="min-w-0">
|
||
<div className="text-xs font-medium leading-tight">{def.label}</div>
|
||
<div className="truncate text-2xs leading-tight text-faint">
|
||
{def.description}
|
||
</div>
|
||
</div>
|
||
</button>
|
||
))}
|
||
</div>
|
||
</div>
|
||
)
|
||
})}
|
||
{!defs.length && (
|
||
<div className="px-2 py-6 text-center text-2xs text-faint">没有匹配的节点</div>
|
||
)}
|
||
</div>
|
||
{lock ? (
|
||
<div className="flex items-start gap-1.5 border-t px-3 py-2 text-2xs leading-relaxed text-dim" role="note">
|
||
<Lock size={11} className="mt-0.5 shrink-0" aria-hidden />
|
||
<span>{EDIT_LOCK_TEXT[lock]}</span>
|
||
</div>
|
||
) : (
|
||
<div className="border-t px-3 py-2 text-2xs leading-relaxed text-faint">
|
||
拖到画布,或点击放在视野中间。<br />
|
||
从节点右侧圆点拖到另一个节点左侧即可连线。
|
||
</div>
|
||
)}
|
||
</div>
|
||
)
|
||
}
|
||
|
||
function TypeIcon({ def, size = 20 }: { def: NodeDef; size?: number }) {
|
||
return (
|
||
<div
|
||
className="mt-0.5 flex shrink-0 items-center justify-center rounded"
|
||
style={{
|
||
width: size, height: size,
|
||
background: 'color-mix(in srgb, var(--nt) 18%, transparent)',
|
||
color: 'var(--nt)',
|
||
}}
|
||
>
|
||
<def.icon size={Math.round(size * 0.6)} />
|
||
</div>
|
||
)
|
||
}
|
||
|
||
/**
|
||
* 收起后的图标轨。说明不用原生 title:原生提示要停一秒多才出来,而且只能一行灰字;
|
||
* 这里悬停即浮出名字和一句话说明。浮层挂到 body 上,不被这一栏的滚动裁掉
|
||
*/
|
||
function Rail({ onToggle, onAdd, lock }: {
|
||
onToggle: () => void; onAdd: (t: NodeType) => void; lock: ReturnType<typeof useEditLock>
|
||
}) {
|
||
const locked = lock != null
|
||
const [tip, setTip] = useState<{ def: NodeDef; top: number; left: number } | null>(null)
|
||
const show = (def: NodeDef, el: HTMLElement) => {
|
||
const r = el.getBoundingClientRect()
|
||
setTip({ def, top: r.top + r.height / 2, left: r.right + 8 })
|
||
}
|
||
return (
|
||
<div className="flex h-full flex-col items-center" aria-label="节点库(已收起)"
|
||
title={lock ? EDIT_LOCK_TEXT[lock] : undefined}>
|
||
<div className="flex w-full justify-center border-b py-2">
|
||
<IconButton label="展开节点库" title={hintOf('展开节点库', 'palette')} onClick={onToggle}
|
||
icon={<PanelLeftOpen size={13} />} />
|
||
</div>
|
||
{/* 置灰的图标轨接不到悬停,也就没有说明可看:原因挂在外面那一层的 title 上 */}
|
||
<div className={clsx('flex w-full flex-1 flex-col items-center gap-0.5 overflow-y-auto py-1.5',
|
||
locked && 'pointer-events-none opacity-50')}
|
||
aria-disabled={locked || undefined}
|
||
onMouseLeave={() => setTip(null)}>
|
||
{NODE_CATEGORIES.map((category, ci) => (
|
||
<div key={category} className="flex w-full flex-col items-center gap-0.5">
|
||
{ci > 0 && <span className="my-1 h-px w-5" style={{ background: 'var(--border)' }} aria-hidden />}
|
||
{Object.values(NODE_DEFS).filter((d) => d.category === category).map((def) => (
|
||
<button
|
||
type="button"
|
||
key={def.type}
|
||
aria-label={`添加${def.label}`}
|
||
draggable={!locked}
|
||
onDragStart={(e) => { setTip(null); startDrag(e, def) }}
|
||
onClick={() => onAdd(def.type as NodeType)}
|
||
onMouseEnter={(e) => show(def, e.currentTarget)}
|
||
onFocus={(e) => show(def, e.currentTarget)}
|
||
onBlur={() => setTip(null)}
|
||
className={`nt-${def.type} flex h-8 w-8 cursor-grab items-center justify-center rounded-md hover:bg-hover active:cursor-grabbing`}
|
||
>
|
||
<TypeIcon def={def} size={22} />
|
||
</button>
|
||
))}
|
||
</div>
|
||
))}
|
||
</div>
|
||
{tip && createPortal(
|
||
// 居中和入场分两层:fade-up 的关键帧也写 transform,放在同一层上会在动画期间
|
||
// 顶掉 translateY(-50%),浮层先落低半个身位、动画一完再跳上去
|
||
<div role="tooltip" className="pointer-events-none fixed z-50 w-52"
|
||
style={{ top: tip.top, left: tip.left, transform: 'translateY(-50%)' }}>
|
||
<div className="fade-up rounded-md border bg-panel px-2.5 py-2 shadow-elev-2">
|
||
<div className="text-xs font-medium">{tip.def.label}</div>
|
||
<div className="mt-0.5 text-2xs leading-snug text-faint">{tip.def.description}</div>
|
||
<div className="mt-1 text-2xs text-faint">点一下放在视野中间 · 或拖到画布上</div>
|
||
</div>
|
||
</div>,
|
||
document.body,
|
||
)}
|
||
</div>
|
||
)
|
||
}
|