mirror of
https://github.com/ThearchyHelios/AgentLab.git
synced 2026-11-17 22:41:57 +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 更新。
134 lines
5.0 KiB
TypeScript
134 lines
5.0 KiB
TypeScript
import { useSyncExternalStore } from 'react'
|
||
import { toast } from '../components/ui'
|
||
import type { ServerHealth } from '../types'
|
||
import { humanizeError } from './errors'
|
||
import { parseServerTime } from './format'
|
||
|
||
/**
|
||
* 连没连上:统一、持久的状态。
|
||
*
|
||
* 一次「测连接」的结果按 `种类:id` 存:模型接入 provider:<id>、数据源
|
||
* datasource:<id>、MCP mcp:<id>。
|
||
*
|
||
* 以前测完只弹 4 秒 toast,结果存在组件 state 里,切个标签就没了;卡片上的圆点
|
||
* 又各说各的(模型卡的绿点其实是「启用」)。管理页最核心的问题是「现在能不能
|
||
* 用」,答案得留在对象上,并注明是什么时候测的。
|
||
*
|
||
* 模块级而不是组件 state:切标签、换页都还在。再写一份到 localStorage,刷新
|
||
* 也还在——只是这台浏览器的缓存,所以一律带上「几分钟前测的」。后端也记着上次
|
||
* 的结果时(列表接口里的 last_check_*),用 healthFromServer 取出来当初值,
|
||
* useHealth 取两边较新的那份。
|
||
*/
|
||
export interface HealthRecord {
|
||
ok: boolean
|
||
/** 往返毫秒 */
|
||
ms?: number | null
|
||
/** 测的时刻(ms)。0 = 知道结果、不知道是什么时候测的 */
|
||
at: number
|
||
error?: string
|
||
hint?: string
|
||
detail?: string
|
||
/** 成功时的补充:用的哪个模型、回了什么 */
|
||
note?: string
|
||
}
|
||
|
||
const HEALTH_KEY = 'agentlab.health'
|
||
|
||
/**
|
||
* 后端记着的上次结果(列表接口里平铺的 last_check_* 四个字段)→ HealthRecord。
|
||
* 没测过、或者连接配置改过之后后端给的全是 null,这里返回 undefined。
|
||
* 测的时刻解析不出来时 at 为 0:知道结果,不写「几分钟前测」
|
||
*/
|
||
export function healthFromServer(o: ServerHealth | null | undefined): HealthRecord | undefined {
|
||
if (!o || typeof o.last_check_ok !== 'boolean') return undefined
|
||
return {
|
||
ok: o.last_check_ok,
|
||
ms: o.last_latency_ms ?? null,
|
||
at: parseServerTime(o.last_checked_at)?.getTime() ?? 0,
|
||
...(o.last_error ? { error: o.last_error } : {}),
|
||
}
|
||
}
|
||
|
||
function readHealth(): Record<string, HealthRecord> {
|
||
try {
|
||
const raw = JSON.parse(localStorage.getItem(HEALTH_KEY) ?? '{}')
|
||
return raw && typeof raw === 'object' ? raw : {}
|
||
} catch {
|
||
return {}
|
||
}
|
||
}
|
||
|
||
let healthSnap: { records: Record<string, HealthRecord>; checking: Record<string, number> } = {
|
||
records: readHealth(), checking: {},
|
||
}
|
||
const healthListeners = new Set<() => void>()
|
||
const subscribeHealth = (l: () => void) => {
|
||
healthListeners.add(l)
|
||
return () => { healthListeners.delete(l) }
|
||
}
|
||
function emitHealth(next: Partial<typeof healthSnap>, persist = false) {
|
||
healthSnap = { ...healthSnap, ...next }
|
||
if (persist) {
|
||
try { localStorage.setItem(HEALTH_KEY, JSON.stringify(healthSnap.records)) } catch { /* 隐私模式:只是刷新后不记得 */ }
|
||
}
|
||
healthListeners.forEach((l) => l())
|
||
}
|
||
|
||
/**
|
||
* 某个对象最近一次的测连接结果,以及是不是正在测。
|
||
*
|
||
* server 是后端记着的那份(healthFromServer 的结果):换了台浏览器、清了缓存也
|
||
* 还在。两份都有时取测得晚的那份——本机刚测过的比后端上次记的新。
|
||
*/
|
||
export function useHealth(key: string, server?: HealthRecord | null): { record?: HealthRecord; checkingSince?: number } {
|
||
const snap = useSyncExternalStore(subscribeHealth, () => healthSnap, () => healthSnap)
|
||
const local = snap.records[key]
|
||
const record = !server ? local : !local ? server : server.at > local.at ? server : local
|
||
return { record, checkingSince: snap.checking[key] }
|
||
}
|
||
|
||
export function setHealth(key: string, record: HealthRecord) {
|
||
emitHealth({ records: { ...healthSnap.records, [key]: record } }, true)
|
||
}
|
||
|
||
export function forgetHealth(key: string) {
|
||
const { [key]: _gone, ...rest } = healthSnap.records
|
||
emitHealth({ records: rest }, true)
|
||
}
|
||
|
||
/**
|
||
* 测一次并记下结果。run 返回后端的 {ok, error, hint, detail};ms 和 note 由调用方
|
||
* 从各自的字段里取(latency_ms / elapsed_ms)。
|
||
*
|
||
* 后端本身够不着时不记:那说的是「我们连不上后端」,不是这个库或模型坏了,
|
||
* 记成它的失败就是冤枉它。只弹 toast。
|
||
*/
|
||
export async function checkHealth(
|
||
key: string,
|
||
run: () => Promise<Omit<HealthRecord, 'at'>>,
|
||
): Promise<HealthRecord | null> {
|
||
if (healthSnap.checking[key]) return null
|
||
emitHealth({ checking: { ...healthSnap.checking, [key]: Date.now() } })
|
||
let record: HealthRecord | null = null
|
||
try {
|
||
record = { ...(await run()), at: Date.now() }
|
||
} catch (e) {
|
||
const h = humanizeError(e)
|
||
if (h.kind === 'network') {
|
||
toast.error(e)
|
||
} else {
|
||
record = {
|
||
ok: false, at: Date.now(),
|
||
error: h.reason ? `${h.title}:${h.reason}` : h.title, hint: h.action, detail: h.raw,
|
||
}
|
||
}
|
||
} finally {
|
||
const { [key]: _done, ...checking } = healthSnap.checking
|
||
emitHealth({
|
||
checking,
|
||
...(record ? { records: { ...healthSnap.records, [key]: record } } : {}),
|
||
}, !!record)
|
||
}
|
||
return record
|
||
}
|