mirror of
https://github.com/ThearchyHelios/AgentLab.git
synced 2026-11-26 10:33:17 +00:00
复核套件骨架(前端):节点库加双盲复算、反方审稿(把关类,图标、配色、空配置,说明和卡片写明尚未生效,检查器照常打开)。路由加 /runs/compare(排在 /runs/:runId 前,标签页标题写「运行对比」)和 /schedules、/schedules/:id,都是页头加「功能开发中」的占位页;导航和命令面板在设置前加「定时任务」,快捷键 ⌥8,设置仍是 ⌥7;八个导航项在 480px 高的窗口里放不下,矮窗口的导航项从 40px 收到 36px。请求层从 api/client.ts 拆到 api/http.ts,client.ts 原样转出原有导出并加转请求函数;schedules、compare、bundle、inquiry、whatif 各一个空的命名空间文件,从 http.ts 取请求函数、挂到 api 上,不和 client.ts 互相导入。terms.ts 给各包占好文案块(RUN_COMPARE_TEXT 和配方对照的 COMPARE_TEXT 分开)。审批卡留两个插槽:payload.kind 为 dual_check 时的 DualCheckApproval,报告核对概况后面的 ChallengeSummary,都先返回 null。预览页自动收 dev/fixtures/*.tsx 导出的 cases,?syn= 先查这里再走原有用例。check-shell 跟着改导航项和快捷键的断言,check-copy 的 for_model 检查把 http.ts 和 client.ts 合起来看
This commit is contained in:
+13
-5
@@ -12,11 +12,13 @@ import { useConversations } from './store/conversations'
|
||||
import { ChatPage } from './pages/ChatPage'
|
||||
import { StudioPage } from './pages/StudioPage'
|
||||
import { RunsPage } from './pages/RunsPage'
|
||||
import { ComparePage } from './pages/runs/ComparePage'
|
||||
import { DataPage } from './pages/DataPage'
|
||||
import { CatalogPage } from './pages/catalog/CatalogPage'
|
||||
import { ToolsPage } from './pages/ToolsPage'
|
||||
import { KnowledgePage } from './pages/KnowledgePage'
|
||||
import { SettingsPage } from './pages/SettingsPage'
|
||||
import { SchedulesPage } from './pages/schedules/SchedulesPage'
|
||||
import { NotFound } from './pages/NotFound'
|
||||
import { Logo } from './components/Logo'
|
||||
import {
|
||||
@@ -35,7 +37,7 @@ import {
|
||||
import type { Attention, FaviconDot } from './lib/notify'
|
||||
import { useLeaveBlocker } from './lib/leave'
|
||||
import { useLocalActor } from './lib/actor'
|
||||
import { runName } from './lib/terms'
|
||||
import { RUN_COMPARE_TEXT, runName } from './lib/terms'
|
||||
|
||||
export default function App() {
|
||||
const loaded = useCatalog((s) => s.loaded)
|
||||
@@ -103,6 +105,8 @@ export default function App() {
|
||||
<Route path="/studio" element={<StudioPage />} />
|
||||
<Route path="/studio/:workflowId" element={<StudioPage />} />
|
||||
<Route path="/runs" element={<RunsPage />} />
|
||||
{/* 固定路径写在 /runs/:runId 前面:读的人一眼看出 compare 不是运行 id */}
|
||||
<Route path="/runs/compare" element={<ComparePage />} />
|
||||
<Route path="/runs/:runId" element={<RunsPage />} />
|
||||
<Route path="/data" element={<DataPage />} />
|
||||
<Route path="/data/:tab" element={<DataPage />} />
|
||||
@@ -115,6 +119,8 @@ export default function App() {
|
||||
<Route path="/knowledge" element={<KnowledgePage />} />
|
||||
<Route path="/knowledge/:tab" element={<KnowledgePage />} />
|
||||
<Route path="/knowledge/:tab/:id" element={<KnowledgePage />} />
|
||||
<Route path="/schedules" element={<SchedulesPage />} />
|
||||
<Route path="/schedules/:id" element={<SchedulesPage />} />
|
||||
{/* 数据源搬到了顶级「数据」页;旧书签和各处「去设置 → 数据源」的链接还在 */}
|
||||
<Route path="/settings/datasources" element={<Navigate to="/data" replace />} />
|
||||
<Route path="/settings" element={<SettingsPage />} />
|
||||
@@ -241,9 +247,10 @@ function Nav({ stalled }: { stalled: CatalogCheck[] }) {
|
||||
const chat = useChatActivity()
|
||||
const live = studio.startsWith('run') || chat === 'run'
|
||||
|
||||
// 整条导航约 520px 高,窗口再矮,最底下的遥测点和署名就被切掉、够不着。矮窗口
|
||||
// (≤600px)按高度收紧到 450px 左右,而不是让导航滚动:导航一旦 overflow,
|
||||
// 挂在右侧的悬停提示和遥测浮层也会被一起裁掉
|
||||
// 整条导航约 580px 高(八个导航项),窗口再矮,最底下的遥测点和署名就被切掉、够不着。
|
||||
// 矮窗口(≤600px)按高度收紧到 455px 左右(导航项 36px),而不是让导航滚动:导航一旦
|
||||
// overflow,挂在右侧的悬停提示和遥测浮层也会被一起裁掉。加导航项时在 480px 高的窗口里
|
||||
// 量一遍(check-shell 的「窗口高 480px」)
|
||||
return (
|
||||
<nav aria-label="主导航" className="relative z-30 flex w-16 shrink-0 flex-col border-r bg-panel">
|
||||
<Link
|
||||
@@ -267,7 +274,7 @@ function Nav({ stalled }: { stalled: CatalogCheck[] }) {
|
||||
aria-keyshortcuts={ariaShortcut(p.shortcut)}
|
||||
className={({ isActive }) => clsx(
|
||||
'group relative flex h-12 w-full flex-col items-center justify-center gap-1 rounded-md text-2xs leading-none outline-none',
|
||||
'[@media(max-height:600px)]:h-10',
|
||||
'[@media(max-height:600px)]:h-9',
|
||||
'transition-colors focus-visible:ring-2 focus-visible:ring-[var(--accent)]',
|
||||
isActive ? 'bg-hover font-medium text-fg' : 'text-dim hover:bg-hover hover:text-fg',
|
||||
)}
|
||||
@@ -868,6 +875,7 @@ function describePath(
|
||||
if (seg === 'studio' && id) return [page, ctx.workflowName]
|
||||
if (seg === 'chat' && id) return [page, ctx.conversationTitle || null]
|
||||
if (seg === 'runs') {
|
||||
if (id === 'compare') return [page, RUN_COMPARE_TEXT.title]
|
||||
if (id) return [page, `运行 ${shortId(id)}`]
|
||||
return [page, new URLSearchParams(search).get('tab') === 'approvals' ? '待审批' : null]
|
||||
}
|
||||
|
||||
@@ -0,0 +1,7 @@
|
||||
/**
|
||||
* 可验证报告的接口(/api/runs/{run_id}/…)。现在是空的,可验证报告的工作包往里加,挂在 api.bundle 上。
|
||||
*
|
||||
* 请求函数(get / post / del……)和 ApiError 从 ./http 导入,不要从 ./client 导入:client.ts 要导入
|
||||
* 这个文件把它挂到 api 上,反过来导入就成了循环(见 http.ts 开头的说明)。
|
||||
*/
|
||||
export const bundle = {}
|
||||
+22
-313
@@ -11,189 +11,22 @@ import type {
|
||||
RunEvent, RunStatus, Skill, ToolChange, ToolInfo, ToolTrust, UpgradeResult, UploadDecision, UploadMixedColumn, UploadResult,
|
||||
UploadShapeReason, ValidationIssue, VarIssue, Variable, Workflow, WorkflowVersion,
|
||||
} from '../types'
|
||||
import { localActor } from '../lib/actor'
|
||||
import { VALIDATION_TITLE, describeValidation } from '../lib/validation'
|
||||
import {
|
||||
ApiError, BASE, NETWORK_MESSAGE, actorHeader, codeOf, del, describeDetail, failure, get, isGatewayFailure, parseBody,
|
||||
patch, post, put, qs, report, request, upload, type RequestOptions, type UploadOptions,
|
||||
} from './http'
|
||||
import { bundle } from './bundle'
|
||||
import { compare } from './compare'
|
||||
import { inquiry } from './inquiry'
|
||||
import { schedules } from './schedules'
|
||||
import { whatif } from './whatif'
|
||||
|
||||
const BASE = '/api'
|
||||
|
||||
/**
|
||||
* network:请求根本没到后端(没起、在重启、代理断了、超时没回)。
|
||||
* http:后端回了错误状态码,message 是后端的 detail。
|
||||
*/
|
||||
export type ApiErrorKind = 'network' | 'http'
|
||||
|
||||
export const NETWORK_MESSAGE = '无法连接服务(服务端可能未启动或正在重启),请稍后重试'
|
||||
|
||||
export class ApiError extends Error {
|
||||
kind: ApiErrorKind
|
||||
/** 后端 detail 的原样(字符串、校验错误数组都可能) */
|
||||
detail?: unknown
|
||||
/** 原始报错文本,给「技术细节」和复制用 */
|
||||
raw?: string
|
||||
/** 超时断开时等了多久 */
|
||||
timeoutMs?: number
|
||||
/**
|
||||
* 后端的机读码(app/api/coded.py 的 {detail, code},比如 datasource_scope_empty)。
|
||||
* detail 是给人看的话,随时可能改写;要按错误种类分支的认这个
|
||||
*/
|
||||
code?: string
|
||||
/** 带机读码的错误里出错的是哪一项(app/api/coded.py 的 field,比如剖析设置的 max_queries);没有就是 undefined */
|
||||
field?: string
|
||||
/**
|
||||
* 后端要用户先拍板时随错误一起给的 {kind, details}(比如上传表格的 422:数字列混入非数字、
|
||||
* 交叉表)。原样保留,按接口各自校验后再用(上传表格见 uploadDecision)
|
||||
*/
|
||||
decision?: unknown
|
||||
|
||||
constructor(
|
||||
public status: number,
|
||||
message: string,
|
||||
opts?: { kind?: ApiErrorKind; detail?: unknown; raw?: string; timeoutMs?: number; code?: string; field?: string; decision?: unknown },
|
||||
) {
|
||||
super(message)
|
||||
this.name = 'ApiError'
|
||||
this.kind = opts?.kind ?? (status === 0 ? 'network' : 'http')
|
||||
this.detail = opts?.detail
|
||||
this.raw = opts?.raw
|
||||
this.timeoutMs = opts?.timeoutMs
|
||||
this.code = opts?.code
|
||||
this.field = opts?.field
|
||||
this.decision = opts?.decision
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 连接状态的旁听者:任何一次请求够着了后端(不管状态码)就报 true,网络层失败
|
||||
* 报 false。catalog 靠它维护全站的「后端连没连上」,不用另起一路轮询去猜。
|
||||
*/
|
||||
type ConnectivityListener = (reachable: boolean, error?: ApiError) => void
|
||||
const connectivity = new Set<ConnectivityListener>()
|
||||
|
||||
export function onConnectivity(listener: ConnectivityListener): () => void {
|
||||
connectivity.add(listener)
|
||||
return () => { connectivity.delete(listener) }
|
||||
}
|
||||
|
||||
function report(reachable: boolean, error?: ApiError) {
|
||||
for (const l of connectivity) {
|
||||
try { l(reachable, error) } catch { /* 旁听者出错不能拖垮请求本身 */ }
|
||||
}
|
||||
}
|
||||
|
||||
function actorHeader(): Record<string, string> {
|
||||
const actor = localActor()
|
||||
// 请求头只能是 Latin-1:中文署名原样放进去,fetch 直接抛错、整个请求发不出去。
|
||||
// 后端 runs.actor_of 解码,纯 ASCII 的老署名编码前后一样
|
||||
return actor ? { 'X-Actor': encodeURIComponent(actor) } : {}
|
||||
}
|
||||
|
||||
/**
|
||||
* FastAPI 的 422 是 [{loc, msg, type}] 数组:直接 String() 是 [object Object],照拼 msg
|
||||
* 又是 pydantic 的英文原文。按 type 翻成中文(lib/validation),path 用来查表单上的叫法
|
||||
*/
|
||||
function describeDetail(detail: unknown, path?: string): string {
|
||||
if (typeof detail === 'string') return detail
|
||||
if (Array.isArray(detail)) return `${VALIDATION_TITLE}:${describeValidation(detail, path).join(';')}`
|
||||
// 对象形态的 detail 原样 JSON 化只会把一串花括号摆到提示里:界面只说无法识别,原文在调用方的 raw 里
|
||||
return '请求失败,服务端返回了无法识别的错误信息'
|
||||
}
|
||||
|
||||
/**
|
||||
* 网关类失败(代理够不着后端)也算网络失败:vite 代理连不上后端时回 500 且响应体
|
||||
* 为空,nginx 回 502/503/504 的 HTML。后端自己抛的 HTTPException 一定带 JSON detail。
|
||||
*/
|
||||
function isGatewayFailure(status: number, bodyText: string, isJson: boolean): boolean {
|
||||
if (isJson) return false
|
||||
if (status === 502 || status === 503 || status === 504) return true
|
||||
return status === 500 && !bodyText.trim()
|
||||
}
|
||||
|
||||
/**
|
||||
* 后端交回模型用的改写指令:报告核对的 violations、助手自查的问题条目里带着 for_model。那是写给模型的
|
||||
* 原话(「单元格要写成 Q<编号>.r<行>.<列>」这类),界面只显示给人看的 message。前端没有任何地方读它,
|
||||
* 就在数据进来的地方去掉——原始事件、工件原文、展开详情这些直接显示 JSON 的地方也就不会露出来。
|
||||
*/
|
||||
const MODEL_NOTE = 'for_model'
|
||||
|
||||
function dropModelNotes(v: unknown): void {
|
||||
if (Array.isArray(v)) {
|
||||
for (const x of v) dropModelNotes(x)
|
||||
} else if (v && typeof v === 'object') {
|
||||
delete (v as Record<string, unknown>)[MODEL_NOTE]
|
||||
for (const x of Object.values(v)) dropModelNotes(x)
|
||||
}
|
||||
}
|
||||
|
||||
/** 解析响应体;带 for_model 的(先按原文粗筛,不带的不走一遍)去掉它 */
|
||||
export function parseBody(text: string): any {
|
||||
const body = JSON.parse(text)
|
||||
if (text.includes(`"${MODEL_NOTE}"`)) dropModelNotes(body)
|
||||
return body
|
||||
}
|
||||
|
||||
async function request<T>(path: string, init?: RequestInit & { timeoutMs?: number }): Promise<T> {
|
||||
const { timeoutMs, ...rest } = init ?? {}
|
||||
// 自己的超时和调用方的取消要分开:调用方取消照旧抛 AbortError(没人想看到
|
||||
// 「连不上后端」),只有我们自己掐断的才算网络失败
|
||||
let timer: ReturnType<typeof setTimeout> | undefined
|
||||
let timedOut = false
|
||||
let signal = rest.signal
|
||||
if (timeoutMs) {
|
||||
const ctrl = new AbortController()
|
||||
timer = setTimeout(() => { timedOut = true; ctrl.abort() }, timeoutMs)
|
||||
rest.signal?.addEventListener('abort', () => ctrl.abort())
|
||||
signal = ctrl.signal
|
||||
}
|
||||
let res: Response
|
||||
try {
|
||||
res = await fetch(BASE + path, {
|
||||
...rest,
|
||||
signal,
|
||||
headers: {
|
||||
...(rest.body instanceof FormData ? {} : { 'Content-Type': 'application/json' }),
|
||||
...actorHeader(),
|
||||
...rest.headers,
|
||||
},
|
||||
})
|
||||
} catch (e: any) {
|
||||
if (timedOut) {
|
||||
const err = new ApiError(0, `服务端 ${Math.round(timeoutMs! / 1000)} 秒未响应,请稍后重试`,
|
||||
{ kind: 'network', raw: `timeout after ${timeoutMs}ms: ${path}`, timeoutMs })
|
||||
report(false, err)
|
||||
throw err
|
||||
}
|
||||
if (e?.name === 'AbortError') throw e
|
||||
// fetch 的网络失败是 TypeError(Chrome「Failed to fetch」、Safari「Load failed」),
|
||||
// 原文对用户毫无意义,收进 raw
|
||||
const err = new ApiError(0, NETWORK_MESSAGE, { kind: 'network', raw: `${e?.name ?? 'Error'}: ${e?.message ?? e}` })
|
||||
report(false, err)
|
||||
throw err
|
||||
} finally {
|
||||
if (timer) clearTimeout(timer)
|
||||
}
|
||||
if (!res.ok) throw failure(res.status, res.statusText, await res.text().catch(() => ''), path)
|
||||
report(true)
|
||||
if (res.status === 204) return undefined as T
|
||||
return parseBody(await res.text())
|
||||
}
|
||||
|
||||
/** 后端 {detail, code} 里的机读码;没有就是 undefined */
|
||||
const codeOf = (body: unknown): string | undefined => {
|
||||
const code = body && typeof body === 'object' ? (body as { code?: unknown }).code : undefined
|
||||
return typeof code === 'string' && code ? code : undefined
|
||||
}
|
||||
|
||||
/** 后端 {detail, code, field} 里出错的那一项;没有就是 undefined */
|
||||
const fieldOf = (body: unknown): string | undefined => {
|
||||
const field = body && typeof body === 'object' ? (body as { field?: unknown }).field : undefined
|
||||
return typeof field === 'string' && field ? field : undefined
|
||||
}
|
||||
|
||||
/** 后端 {detail, decision} 里要用户拍板的内容:是个对象就原样带上,没有就是 undefined */
|
||||
const decisionOf = (body: unknown): unknown => {
|
||||
const decision = body && typeof body === 'object' ? (body as { decision?: unknown }).decision : undefined
|
||||
return decision && typeof decision === 'object' ? decision : undefined
|
||||
}
|
||||
// 请求层搬到了 http.ts(见那边的说明)。原先从这里导出的照旧从这里导出,调用方不用改;
|
||||
// 请求函数也一并转出,给不在 api/ 下、又想直接发请求的地方用。api/ 下的命名空间文件请直接从 http.ts 导入
|
||||
export {
|
||||
ApiError, NETWORK_MESSAGE, del, get, onConnectivity, parseBody, patch, post, put, qs, request, upload,
|
||||
} from './http'
|
||||
export type { ApiErrorKind, RequestOptions, UploadOptions, UploadProgress } from './http'
|
||||
|
||||
const isObj = (v: unknown): v is Record<string, unknown> => !!v && typeof v === 'object' && !Array.isArray(v)
|
||||
|
||||
@@ -231,102 +64,6 @@ export function uploadDecision(e: unknown): UploadDecision | null {
|
||||
const mixedColumns = (v: unknown): boolean => Array.isArray(v) && v.length > 0
|
||||
&& v.every((c) => isObj(c) && typeof c.column === 'string' && Array.isArray(c.values))
|
||||
|
||||
/** 非 2xx 的响应 → ApiError,顺带报告连接状态。fetch 和 XHR 两条路共用 */
|
||||
function failure(status: number, statusText: string, text: string, path?: string): ApiError {
|
||||
let body: any
|
||||
let isJson = false
|
||||
try { body = JSON.parse(text); isJson = true } catch { /* 响应体不是 JSON */ }
|
||||
if (isGatewayFailure(status, text, isJson)) {
|
||||
const err = new ApiError(status, NETWORK_MESSAGE, {
|
||||
kind: 'network', raw: `${status} ${statusText}${text ? `\n${text.slice(0, 500)}` : ''}`,
|
||||
})
|
||||
report(false, err)
|
||||
return err
|
||||
}
|
||||
report(true)
|
||||
if (isJson) {
|
||||
const detail = body?.detail ?? body
|
||||
return new ApiError(status, describeDetail(detail, path), {
|
||||
detail, raw: typeof body?.raw === 'string' ? body.raw : `${status} ${text.slice(0, 2000)}`,
|
||||
code: codeOf(body), field: fieldOf(body), decision: decisionOf(body),
|
||||
})
|
||||
}
|
||||
const message = status >= 500
|
||||
? `服务端错误(${status}),详情请查看服务日志`
|
||||
: `请求失败(HTTP ${status})`
|
||||
return new ApiError(status, message, { raw: `${status} ${statusText}\n${text.slice(0, 2000)}` })
|
||||
}
|
||||
|
||||
/** 上传进度。字节发完(sent)之后还要等后端解析、切块,那段没有进度可报 */
|
||||
export interface UploadProgress {
|
||||
/** 已经发出去的字节 */
|
||||
loaded: number
|
||||
/** 总字节;浏览器算不出来时为 null,这时只能画已发多少,不画百分比 */
|
||||
total: number | null
|
||||
/** 字节已经全部发完,在等后端处理 */
|
||||
sent: boolean
|
||||
}
|
||||
|
||||
export interface UploadOptions {
|
||||
onProgress?: (p: UploadProgress) => void
|
||||
signal?: AbortSignal
|
||||
}
|
||||
|
||||
/**
|
||||
* 带字节进度的上传。fetch 拿不到上传进度,只能用 XHR;报错、连接状态、署名头和
|
||||
* request 走同一套,调用方看到的 ApiError 没有区别。取消照旧抛 AbortError。
|
||||
*/
|
||||
function upload<T>(path: string, form: FormData, opts?: UploadOptions): Promise<T> {
|
||||
return new Promise<T>((resolve, reject) => {
|
||||
const xhr = new XMLHttpRequest()
|
||||
xhr.open('POST', BASE + path)
|
||||
for (const [k, v] of Object.entries(actorHeader())) xhr.setRequestHeader(k, v)
|
||||
const onProgress = opts?.onProgress
|
||||
if (onProgress) {
|
||||
// 进度事件里的字节数含 multipart 的边界和表头,比文件本身略大;发完那一下
|
||||
// 沿用它的总数,前后两个数才对得上
|
||||
let total: number | null = null
|
||||
xhr.upload.onprogress = (e) => {
|
||||
if (e.lengthComputable) total = e.total
|
||||
onProgress({ loaded: e.loaded, total, sent: false })
|
||||
}
|
||||
xhr.upload.onload = () => {
|
||||
const bytes = total ?? [...form.values()].reduce((n, v) => n + (v instanceof Blob ? v.size : 0), 0)
|
||||
onProgress({ loaded: bytes, total: bytes || null, sent: true })
|
||||
}
|
||||
}
|
||||
const abort = () => xhr.abort()
|
||||
opts?.signal?.addEventListener('abort', abort)
|
||||
const cleanup = () => opts?.signal?.removeEventListener('abort', abort)
|
||||
xhr.onload = () => {
|
||||
cleanup()
|
||||
if (xhr.status < 200 || xhr.status >= 300) {
|
||||
reject(failure(xhr.status, xhr.statusText, xhr.responseText ?? '', path))
|
||||
return
|
||||
}
|
||||
report(true)
|
||||
if (xhr.status === 204 || !xhr.responseText) { resolve(undefined as T); return }
|
||||
try {
|
||||
resolve(parseBody(xhr.responseText))
|
||||
} catch {
|
||||
reject(new ApiError(xhr.status, '无法解析服务端返回的内容', { raw: xhr.responseText.slice(0, 2000) }))
|
||||
}
|
||||
}
|
||||
xhr.onerror = () => {
|
||||
cleanup()
|
||||
const err = new ApiError(0, NETWORK_MESSAGE, { kind: 'network', raw: `XMLHttpRequest error: POST ${path}` })
|
||||
report(false, err)
|
||||
reject(err)
|
||||
}
|
||||
xhr.onabort = () => {
|
||||
cleanup()
|
||||
reject(new DOMException('上传已取消', 'AbortError'))
|
||||
}
|
||||
if (opts?.signal?.aborted) { xhr.abort(); return }
|
||||
xhr.send(form)
|
||||
})
|
||||
}
|
||||
|
||||
/**
|
||||
* 数据源测连接的结果。ok=false 时 error 是一句人话、hint 是怎么办、detail 是
|
||||
* 驱动的原始报错(放进「技术细节」)。
|
||||
@@ -450,41 +187,6 @@ export interface ReindexJob {
|
||||
/** runs.list 的 workflow_id 传它:只看没保存成工作流的那些运行(问数据页、画布上的临时图) */
|
||||
export const UNSAVED_WORKFLOW_ID = '__none__'
|
||||
|
||||
/** 拼查询串:null / undefined / 空串跳过,数组用逗号连起来 */
|
||||
function qs(params?: Record<string, unknown>): string {
|
||||
if (!params) return ''
|
||||
const q = new URLSearchParams()
|
||||
for (const [k, v] of Object.entries(params)) {
|
||||
if (v == null || v === '') continue
|
||||
if (Array.isArray(v)) {
|
||||
if (v.length) q.set(k, v.join(','))
|
||||
} else {
|
||||
q.set(k, String(v))
|
||||
}
|
||||
}
|
||||
const s = q.toString()
|
||||
return s ? `?${s}` : ''
|
||||
}
|
||||
|
||||
/**
|
||||
* 单次请求的选项。timeoutMs 到点就掐断并按网络失败抛出(带 timeoutMs):连得上但
|
||||
* 卡着不回的接口(MCP 服务不应答时的 /tools)不能让调用方永远等下去,也不该一直
|
||||
* 占着浏览器对同一主机的那几条连接
|
||||
*/
|
||||
export interface RequestOptions {
|
||||
timeoutMs?: number
|
||||
signal?: AbortSignal
|
||||
}
|
||||
|
||||
const get = <T>(p: string, opts?: RequestOptions) => request<T>(p, opts)
|
||||
const post = <T>(p: string, body?: unknown) =>
|
||||
request<T>(p, { method: 'POST', body: JSON.stringify(body ?? {}) })
|
||||
const patch = <T>(p: string, body: unknown) =>
|
||||
request<T>(p, { method: 'PATCH', body: JSON.stringify(body) })
|
||||
const put = <T>(p: string, body: unknown) =>
|
||||
request<T>(p, { method: 'PUT', body: JSON.stringify(body) })
|
||||
const del = (p: string) => request<void>(p, { method: 'DELETE' })
|
||||
|
||||
export const api = {
|
||||
/** 心跳。带超时:后端卡死(连得上但不回)时也要能判成断开,而不是永远等下去 */
|
||||
health: (timeoutMs = 5000) => request<{ status: string; service?: string }>('/health', { timeoutMs }),
|
||||
@@ -1033,6 +735,13 @@ export const api = {
|
||||
upgradeEvidence: (body: { graph: GraphSpec; assist?: boolean; level?: PublishLevel }, opts?: RequestOptions) =>
|
||||
request<UpgradeResult>('/copilot/upgrade-evidence', { method: 'POST', body: JSON.stringify(body), ...opts }),
|
||||
},
|
||||
|
||||
// ---- 复核套件:各功能的接口在自己的文件里(api/<名字>.ts),这里只挂上去 ----
|
||||
schedules,
|
||||
compare,
|
||||
bundle,
|
||||
inquiry,
|
||||
whatif,
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -0,0 +1,7 @@
|
||||
/**
|
||||
* 运行对比的接口(/api/runs/{run_id}/…)。现在是空的,运行对比的工作包往里加,挂在 api.compare 上。
|
||||
*
|
||||
* 请求函数(get / post / del……)和 ApiError 从 ./http 导入,不要从 ./client 导入:client.ts 要导入
|
||||
* 这个文件把它挂到 api 上,反过来导入就成了循环(见 http.ts 开头的说明)。
|
||||
*/
|
||||
export const compare = {}
|
||||
@@ -0,0 +1,322 @@
|
||||
/**
|
||||
* 请求层:fetch / XHR、报错翻译、连接状态旁听、署名头、去掉写给模型的 for_model。
|
||||
*
|
||||
* 从 client.ts 拆出来,是为了让 api/ 下各功能的命名空间文件(schedules.ts、compare.ts……)能复用
|
||||
* get / post / del 这些,又不和 client.ts 互相导入:client.ts 要把它们挂到 api 上,它们要是反过来从
|
||||
* client.ts 取请求函数,谁先被加载谁就会读到另一边还没初始化的绑定。所以命名空间文件只从这里导入;
|
||||
* 页面和组件照旧从 client.ts 导入(ApiError、onConnectivity 这些在那边原样转出)。
|
||||
*/
|
||||
import { localActor } from '../lib/actor'
|
||||
import { VALIDATION_TITLE, describeValidation } from '../lib/validation'
|
||||
|
||||
export const BASE = '/api'
|
||||
|
||||
/**
|
||||
* network:请求根本没到后端(没起、在重启、代理断了、超时没回)。
|
||||
* http:后端回了错误状态码,message 是后端的 detail。
|
||||
*/
|
||||
export type ApiErrorKind = 'network' | 'http'
|
||||
|
||||
export const NETWORK_MESSAGE = '无法连接服务(服务端可能未启动或正在重启),请稍后重试'
|
||||
|
||||
export class ApiError extends Error {
|
||||
kind: ApiErrorKind
|
||||
/** 后端 detail 的原样(字符串、校验错误数组都可能) */
|
||||
detail?: unknown
|
||||
/** 原始报错文本,给「技术细节」和复制用 */
|
||||
raw?: string
|
||||
/** 超时断开时等了多久 */
|
||||
timeoutMs?: number
|
||||
/**
|
||||
* 后端的机读码(app/api/coded.py 的 {detail, code},比如 datasource_scope_empty)。
|
||||
* detail 是给人看的话,随时可能改写;要按错误种类分支的认这个
|
||||
*/
|
||||
code?: string
|
||||
/** 带机读码的错误里出错的是哪一项(app/api/coded.py 的 field,比如剖析设置的 max_queries);没有就是 undefined */
|
||||
field?: string
|
||||
/**
|
||||
* 后端要用户先拍板时随错误一起给的 {kind, details}(比如上传表格的 422:数字列混入非数字、
|
||||
* 交叉表)。原样保留,按接口各自校验后再用(上传表格见 uploadDecision)
|
||||
*/
|
||||
decision?: unknown
|
||||
|
||||
constructor(
|
||||
public status: number,
|
||||
message: string,
|
||||
opts?: { kind?: ApiErrorKind; detail?: unknown; raw?: string; timeoutMs?: number; code?: string; field?: string; decision?: unknown },
|
||||
) {
|
||||
super(message)
|
||||
this.name = 'ApiError'
|
||||
this.kind = opts?.kind ?? (status === 0 ? 'network' : 'http')
|
||||
this.detail = opts?.detail
|
||||
this.raw = opts?.raw
|
||||
this.timeoutMs = opts?.timeoutMs
|
||||
this.code = opts?.code
|
||||
this.field = opts?.field
|
||||
this.decision = opts?.decision
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 连接状态的旁听者:任何一次请求够着了后端(不管状态码)就报 true,网络层失败
|
||||
* 报 false。catalog 靠它维护全站的「后端连没连上」,不用另起一路轮询去猜。
|
||||
*/
|
||||
type ConnectivityListener = (reachable: boolean, error?: ApiError) => void
|
||||
const connectivity = new Set<ConnectivityListener>()
|
||||
|
||||
export function onConnectivity(listener: ConnectivityListener): () => void {
|
||||
connectivity.add(listener)
|
||||
return () => { connectivity.delete(listener) }
|
||||
}
|
||||
|
||||
export function report(reachable: boolean, error?: ApiError) {
|
||||
for (const l of connectivity) {
|
||||
try { l(reachable, error) } catch { /* 旁听者出错不能拖垮请求本身 */ }
|
||||
}
|
||||
}
|
||||
|
||||
export function actorHeader(): Record<string, string> {
|
||||
const actor = localActor()
|
||||
// 请求头只能是 Latin-1:中文署名原样放进去,fetch 直接抛错、整个请求发不出去。
|
||||
// 后端 runs.actor_of 解码,纯 ASCII 的老署名编码前后一样
|
||||
return actor ? { 'X-Actor': encodeURIComponent(actor) } : {}
|
||||
}
|
||||
|
||||
/**
|
||||
* FastAPI 的 422 是 [{loc, msg, type}] 数组:直接 String() 是 [object Object],照拼 msg
|
||||
* 又是 pydantic 的英文原文。按 type 翻成中文(lib/validation),path 用来查表单上的叫法
|
||||
*/
|
||||
export function describeDetail(detail: unknown, path?: string): string {
|
||||
if (typeof detail === 'string') return detail
|
||||
if (Array.isArray(detail)) return `${VALIDATION_TITLE}:${describeValidation(detail, path).join(';')}`
|
||||
// 对象形态的 detail 原样 JSON 化只会把一串花括号摆到提示里:界面只说无法识别,原文在调用方的 raw 里
|
||||
return '请求失败,服务端返回了无法识别的错误信息'
|
||||
}
|
||||
|
||||
/**
|
||||
* 网关类失败(代理够不着后端)也算网络失败:vite 代理连不上后端时回 500 且响应体
|
||||
* 为空,nginx 回 502/503/504 的 HTML。后端自己抛的 HTTPException 一定带 JSON detail。
|
||||
*/
|
||||
export function isGatewayFailure(status: number, bodyText: string, isJson: boolean): boolean {
|
||||
if (isJson) return false
|
||||
if (status === 502 || status === 503 || status === 504) return true
|
||||
return status === 500 && !bodyText.trim()
|
||||
}
|
||||
|
||||
/**
|
||||
* 后端交回模型用的改写指令:报告核对的 violations、助手自查的问题条目里带着 for_model。那是写给模型的
|
||||
* 原话(「单元格要写成 Q<编号>.r<行>.<列>」这类),界面只显示给人看的 message。前端没有任何地方读它,
|
||||
* 就在数据进来的地方去掉——原始事件、工件原文、展开详情这些直接显示 JSON 的地方也就不会露出来。
|
||||
*/
|
||||
const MODEL_NOTE = 'for_model'
|
||||
|
||||
function dropModelNotes(v: unknown): void {
|
||||
if (Array.isArray(v)) {
|
||||
for (const x of v) dropModelNotes(x)
|
||||
} else if (v && typeof v === 'object') {
|
||||
delete (v as Record<string, unknown>)[MODEL_NOTE]
|
||||
for (const x of Object.values(v)) dropModelNotes(x)
|
||||
}
|
||||
}
|
||||
|
||||
/** 解析响应体;带 for_model 的(先按原文粗筛,不带的不走一遍)去掉它 */
|
||||
export function parseBody(text: string): any {
|
||||
const body = JSON.parse(text)
|
||||
if (text.includes(`"${MODEL_NOTE}"`)) dropModelNotes(body)
|
||||
return body
|
||||
}
|
||||
|
||||
export async function request<T>(path: string, init?: RequestInit & { timeoutMs?: number }): Promise<T> {
|
||||
const { timeoutMs, ...rest } = init ?? {}
|
||||
// 自己的超时和调用方的取消要分开:调用方取消照旧抛 AbortError(没人想看到
|
||||
// 「连不上后端」),只有我们自己掐断的才算网络失败
|
||||
let timer: ReturnType<typeof setTimeout> | undefined
|
||||
let timedOut = false
|
||||
let signal = rest.signal
|
||||
if (timeoutMs) {
|
||||
const ctrl = new AbortController()
|
||||
timer = setTimeout(() => { timedOut = true; ctrl.abort() }, timeoutMs)
|
||||
rest.signal?.addEventListener('abort', () => ctrl.abort())
|
||||
signal = ctrl.signal
|
||||
}
|
||||
let res: Response
|
||||
try {
|
||||
res = await fetch(BASE + path, {
|
||||
...rest,
|
||||
signal,
|
||||
headers: {
|
||||
...(rest.body instanceof FormData ? {} : { 'Content-Type': 'application/json' }),
|
||||
...actorHeader(),
|
||||
...rest.headers,
|
||||
},
|
||||
})
|
||||
} catch (e: any) {
|
||||
if (timedOut) {
|
||||
const err = new ApiError(0, `服务端 ${Math.round(timeoutMs! / 1000)} 秒未响应,请稍后重试`,
|
||||
{ kind: 'network', raw: `timeout after ${timeoutMs}ms: ${path}`, timeoutMs })
|
||||
report(false, err)
|
||||
throw err
|
||||
}
|
||||
if (e?.name === 'AbortError') throw e
|
||||
// fetch 的网络失败是 TypeError(Chrome「Failed to fetch」、Safari「Load failed」),
|
||||
// 原文对用户毫无意义,收进 raw
|
||||
const err = new ApiError(0, NETWORK_MESSAGE, { kind: 'network', raw: `${e?.name ?? 'Error'}: ${e?.message ?? e}` })
|
||||
report(false, err)
|
||||
throw err
|
||||
} finally {
|
||||
if (timer) clearTimeout(timer)
|
||||
}
|
||||
if (!res.ok) throw failure(res.status, res.statusText, await res.text().catch(() => ''), path)
|
||||
report(true)
|
||||
if (res.status === 204) return undefined as T
|
||||
return parseBody(await res.text())
|
||||
}
|
||||
|
||||
/** 后端 {detail, code} 里的机读码;没有就是 undefined */
|
||||
export const codeOf = (body: unknown): string | undefined => {
|
||||
const code = body && typeof body === 'object' ? (body as { code?: unknown }).code : undefined
|
||||
return typeof code === 'string' && code ? code : undefined
|
||||
}
|
||||
|
||||
/** 后端 {detail, code, field} 里出错的那一项;没有就是 undefined */
|
||||
const fieldOf = (body: unknown): string | undefined => {
|
||||
const field = body && typeof body === 'object' ? (body as { field?: unknown }).field : undefined
|
||||
return typeof field === 'string' && field ? field : undefined
|
||||
}
|
||||
|
||||
/** 后端 {detail, decision} 里要用户拍板的内容:是个对象就原样带上,没有就是 undefined */
|
||||
const decisionOf = (body: unknown): unknown => {
|
||||
const decision = body && typeof body === 'object' ? (body as { decision?: unknown }).decision : undefined
|
||||
return decision && typeof decision === 'object' ? decision : undefined
|
||||
}
|
||||
|
||||
/** 非 2xx 的响应 → ApiError,顺带报告连接状态。fetch 和 XHR 两条路共用 */
|
||||
export function failure(status: number, statusText: string, text: string, path?: string): ApiError {
|
||||
let body: any
|
||||
let isJson = false
|
||||
try { body = JSON.parse(text); isJson = true } catch { /* 响应体不是 JSON */ }
|
||||
if (isGatewayFailure(status, text, isJson)) {
|
||||
const err = new ApiError(status, NETWORK_MESSAGE, {
|
||||
kind: 'network', raw: `${status} ${statusText}${text ? `\n${text.slice(0, 500)}` : ''}`,
|
||||
})
|
||||
report(false, err)
|
||||
return err
|
||||
}
|
||||
report(true)
|
||||
if (isJson) {
|
||||
const detail = body?.detail ?? body
|
||||
return new ApiError(status, describeDetail(detail, path), {
|
||||
detail, raw: typeof body?.raw === 'string' ? body.raw : `${status} ${text.slice(0, 2000)}`,
|
||||
code: codeOf(body), field: fieldOf(body), decision: decisionOf(body),
|
||||
})
|
||||
}
|
||||
const message = status >= 500
|
||||
? `服务端错误(${status}),详情请查看服务日志`
|
||||
: `请求失败(HTTP ${status})`
|
||||
return new ApiError(status, message, { raw: `${status} ${statusText}\n${text.slice(0, 2000)}` })
|
||||
}
|
||||
|
||||
/** 上传进度。字节发完(sent)之后还要等后端解析、切块,那段没有进度可报 */
|
||||
export interface UploadProgress {
|
||||
/** 已经发出去的字节 */
|
||||
loaded: number
|
||||
/** 总字节;浏览器算不出来时为 null,这时只能画已发多少,不画百分比 */
|
||||
total: number | null
|
||||
/** 字节已经全部发完,在等后端处理 */
|
||||
sent: boolean
|
||||
}
|
||||
|
||||
export interface UploadOptions {
|
||||
onProgress?: (p: UploadProgress) => void
|
||||
signal?: AbortSignal
|
||||
}
|
||||
|
||||
/**
|
||||
* 带字节进度的上传。fetch 拿不到上传进度,只能用 XHR;报错、连接状态、署名头和
|
||||
* request 走同一套,调用方看到的 ApiError 没有区别。取消照旧抛 AbortError。
|
||||
*/
|
||||
export function upload<T>(path: string, form: FormData, opts?: UploadOptions): Promise<T> {
|
||||
return new Promise<T>((resolve, reject) => {
|
||||
const xhr = new XMLHttpRequest()
|
||||
xhr.open('POST', BASE + path)
|
||||
for (const [k, v] of Object.entries(actorHeader())) xhr.setRequestHeader(k, v)
|
||||
const onProgress = opts?.onProgress
|
||||
if (onProgress) {
|
||||
// 进度事件里的字节数含 multipart 的边界和表头,比文件本身略大;发完那一下
|
||||
// 沿用它的总数,前后两个数才对得上
|
||||
let total: number | null = null
|
||||
xhr.upload.onprogress = (e) => {
|
||||
if (e.lengthComputable) total = e.total
|
||||
onProgress({ loaded: e.loaded, total, sent: false })
|
||||
}
|
||||
xhr.upload.onload = () => {
|
||||
const bytes = total ?? [...form.values()].reduce((n, v) => n + (v instanceof Blob ? v.size : 0), 0)
|
||||
onProgress({ loaded: bytes, total: bytes || null, sent: true })
|
||||
}
|
||||
}
|
||||
const abort = () => xhr.abort()
|
||||
opts?.signal?.addEventListener('abort', abort)
|
||||
const cleanup = () => opts?.signal?.removeEventListener('abort', abort)
|
||||
xhr.onload = () => {
|
||||
cleanup()
|
||||
if (xhr.status < 200 || xhr.status >= 300) {
|
||||
reject(failure(xhr.status, xhr.statusText, xhr.responseText ?? '', path))
|
||||
return
|
||||
}
|
||||
report(true)
|
||||
if (xhr.status === 204 || !xhr.responseText) { resolve(undefined as T); return }
|
||||
try {
|
||||
resolve(parseBody(xhr.responseText))
|
||||
} catch {
|
||||
reject(new ApiError(xhr.status, '无法解析服务端返回的内容', { raw: xhr.responseText.slice(0, 2000) }))
|
||||
}
|
||||
}
|
||||
xhr.onerror = () => {
|
||||
cleanup()
|
||||
const err = new ApiError(0, NETWORK_MESSAGE, { kind: 'network', raw: `XMLHttpRequest error: POST ${path}` })
|
||||
report(false, err)
|
||||
reject(err)
|
||||
}
|
||||
xhr.onabort = () => {
|
||||
cleanup()
|
||||
reject(new DOMException('上传已取消', 'AbortError'))
|
||||
}
|
||||
if (opts?.signal?.aborted) { xhr.abort(); return }
|
||||
xhr.send(form)
|
||||
})
|
||||
}
|
||||
|
||||
/** 拼查询串:null / undefined / 空串跳过,数组用逗号连起来 */
|
||||
export function qs(params?: Record<string, unknown>): string {
|
||||
if (!params) return ''
|
||||
const q = new URLSearchParams()
|
||||
for (const [k, v] of Object.entries(params)) {
|
||||
if (v == null || v === '') continue
|
||||
if (Array.isArray(v)) {
|
||||
if (v.length) q.set(k, v.join(','))
|
||||
} else {
|
||||
q.set(k, String(v))
|
||||
}
|
||||
}
|
||||
const s = q.toString()
|
||||
return s ? `?${s}` : ''
|
||||
}
|
||||
|
||||
/**
|
||||
* 单次请求的选项。timeoutMs 到点就掐断并按网络失败抛出(带 timeoutMs):连得上但
|
||||
* 卡着不回的接口(MCP 服务不应答时的 /tools)不能让调用方永远等下去,也不该一直
|
||||
* 占着浏览器对同一主机的那几条连接
|
||||
*/
|
||||
export interface RequestOptions {
|
||||
timeoutMs?: number
|
||||
signal?: AbortSignal
|
||||
}
|
||||
|
||||
export const get = <T>(p: string, opts?: RequestOptions) => request<T>(p, opts)
|
||||
export const post = <T>(p: string, body?: unknown) =>
|
||||
request<T>(p, { method: 'POST', body: JSON.stringify(body ?? {}) })
|
||||
export const patch = <T>(p: string, body: unknown) =>
|
||||
request<T>(p, { method: 'PATCH', body: JSON.stringify(body) })
|
||||
export const put = <T>(p: string, body: unknown) =>
|
||||
request<T>(p, { method: 'PUT', body: JSON.stringify(body) })
|
||||
export const del = (p: string) => request<void>(p, { method: 'DELETE' })
|
||||
@@ -0,0 +1,7 @@
|
||||
/**
|
||||
* 审批质询的接口(/api/runs/{run_id}/…)。现在是空的,审批质询的工作包往里加,挂在 api.inquiry 上。
|
||||
*
|
||||
* 请求函数(get / post / del……)和 ApiError 从 ./http 导入,不要从 ./client 导入:client.ts 要导入
|
||||
* 这个文件把它挂到 api 上,反过来导入就成了循环(见 http.ts 开头的说明)。
|
||||
*/
|
||||
export const inquiry = {}
|
||||
@@ -0,0 +1,7 @@
|
||||
/**
|
||||
* 定时任务的接口(/api/schedules)。现在是空的,定时任务的工作包往里加,挂在 api.schedules 上。
|
||||
*
|
||||
* 请求函数(get / post / del……)和 ApiError 从 ./http 导入,不要从 ./client 导入:client.ts 要导入
|
||||
* 这个文件把它挂到 api 上,反过来导入就成了循环(见 http.ts 开头的说明)。
|
||||
*/
|
||||
export const schedules = {}
|
||||
@@ -0,0 +1,7 @@
|
||||
/**
|
||||
* 数字推演的接口(/api/runs/{run_id}/…)。现在是空的,数字推演的工作包往里加,挂在 api.whatif 上。
|
||||
*
|
||||
* 请求函数(get / post / del……)和 ApiError 从 ./http 导入,不要从 ./client 导入:client.ts 要导入
|
||||
* 这个文件把它挂到 api 上,反过来导入就成了循环(见 http.ts 开头的说明)。
|
||||
*/
|
||||
export const whatif = {}
|
||||
@@ -17,7 +17,9 @@ import { claimCountsOf, matchedSource } from '../lib/evidence'
|
||||
import { explainRunError } from '../lib/explain'
|
||||
import { formatDuration, formatLapse, formatNumber, formatTokens, NONE, shortId } from '../lib/format'
|
||||
import { statusMeta } from '../lib/status'
|
||||
import { claimTally, issuanceLabel, reportStampText, RUN_CLASS_LABEL, UPGRADE_POLICY_LABEL } from '../lib/terms'
|
||||
import {
|
||||
CHALLENGE_TEXT, claimTally, DUAL_CHECK_TEXT, issuanceLabel, reportStampText, RUN_CLASS_LABEL, UPGRADE_POLICY_LABEL,
|
||||
} from '../lib/terms'
|
||||
import { useReportStamp, type ReportStamp } from './reportStamp'
|
||||
import { ApprovalCard } from '../run/RunPanel'
|
||||
import type { NodeState, NodeTrace } from '../run/trace'
|
||||
@@ -92,6 +94,11 @@ function summarize(type: NodeType, config: Record<string, any>): string {
|
||||
return first(config.expression, config.template) || '未配置'
|
||||
case 'subgraph':
|
||||
return config.workflow_id ? '嵌套工作流' : '未选择工作流'
|
||||
// 还是占位的两种:卡片上直接说尚未生效,免得以为放上去就会执行
|
||||
case 'dual_check':
|
||||
return DUAL_CHECK_TEXT.pending
|
||||
case 'challenge':
|
||||
return CHALLENGE_TEXT.pending
|
||||
default:
|
||||
return ''
|
||||
}
|
||||
|
||||
@@ -1,8 +1,10 @@
|
||||
import {
|
||||
Bot, Braces, Brain, CheckCircle2, Code2, Combine, Database, FileInput, FileOutput, FileText,
|
||||
Gauge, GitBranch, Hand, Repeat, Search, Shuffle, Users, Wrench,
|
||||
Gauge, GitBranch, GitCompareArrows, Hand, Repeat, Search, ShieldAlert, Shuffle, Users, Wrench,
|
||||
} from 'lucide-react'
|
||||
import { APPROVAL_POLICY_LABEL, MERGE_TEXT, NODE_TYPE_LABEL, UPGRADE_POLICY_LABEL } from '../lib/terms'
|
||||
import {
|
||||
APPROVAL_POLICY_LABEL, CHALLENGE_TEXT, DUAL_CHECK_TEXT, MERGE_TEXT, NODE_TYPE_LABEL, UPGRADE_POLICY_LABEL,
|
||||
} from '../lib/terms'
|
||||
import type { NodeType } from '../types'
|
||||
|
||||
export type FieldType =
|
||||
@@ -656,6 +658,22 @@ export const NODE_DEFS: Record<NodeType, NodeDef> = {
|
||||
metrics: [{ id: 'total', name: '', unit: '', expression: '' }],
|
||||
},
|
||||
},
|
||||
// 下面两种还是占位:服务端的执行器原样跳过(engine/nodes/dual_check.py、challenge.py),没有可配的字段。
|
||||
// 说明里写明尚未生效,检查器顶上就是这一句;各自的工作包补上字段时把这句去掉
|
||||
dual_check: {
|
||||
type: 'dual_check', label: NODE_TYPE_LABEL.dual_check, category: '把关', icon: GitCompareArrows,
|
||||
description: `${DUAL_CHECK_TEXT.description}。${DUAL_CHECK_TEXT.pending}`,
|
||||
hasTarget: true, sources: [{ id: 'out', label: '' }],
|
||||
fields: [],
|
||||
defaults: {},
|
||||
},
|
||||
challenge: {
|
||||
type: 'challenge', label: NODE_TYPE_LABEL.challenge, category: '把关', icon: ShieldAlert,
|
||||
description: `${CHALLENGE_TEXT.description}。${CHALLENGE_TEXT.pending}`,
|
||||
hasTarget: true, sources: [{ id: 'out', label: '' }],
|
||||
fields: [],
|
||||
defaults: {},
|
||||
},
|
||||
}
|
||||
|
||||
export const NODE_CATEGORIES = ['起止', '模型', '执行', '控制', '上下文', '把关']
|
||||
|
||||
@@ -5,7 +5,7 @@ import type { NavigateFunction } from 'react-router-dom'
|
||||
import { create } from 'zustand'
|
||||
import clsx from 'clsx'
|
||||
import {
|
||||
Bell, BellOff, BookOpen, Database, FlaskConical, History, Hourglass, Keyboard, MessageSquare,
|
||||
Bell, BellOff, BookOpen, CalendarClock, Database, FlaskConical, History, Hourglass, Keyboard, MessageSquare,
|
||||
MessageSquarePlus, Monitor, Plus, Search, Settings, SunMoon, Workflow as WorkflowIcon, Wrench,
|
||||
} from 'lucide-react'
|
||||
import { ApiError, api } from '../api/client'
|
||||
@@ -19,7 +19,7 @@ import type { ThemePref } from '../lib/theme'
|
||||
import { isMac } from '../lib/keys'
|
||||
import { formatDateTime, formatTime, parseServerTime, shortId } from '../lib/format'
|
||||
import { statusLabel } from '../lib/status'
|
||||
import { WORKFLOW_STATUS_LABEL, runClassLabel, runName } from '../lib/terms'
|
||||
import { SCHEDULE_TEXT, WORKFLOW_STATUS_LABEL, runClassLabel, runName } from '../lib/terms'
|
||||
import { errorMessage } from '../lib/errors'
|
||||
import { disableNotify, enableNotify, notifySupported, useSignals } from '../lib/notify'
|
||||
import { canLeave, leavePass } from '../lib/leave'
|
||||
@@ -57,6 +57,8 @@ export const PAGES: PageDef[] = [
|
||||
{ to: '/data', label: '数据', hint: '接入数据库和表格,供问数据和工作流查询', icon: Database, shortcut: 'Alt+4', keywords: 'data datasource 数据源 数据库 表格 excel csv' },
|
||||
{ to: '/tools', label: '工具', hint: '工具库、沙箱试验台、自定义工具、MCP', icon: Wrench, shortcut: 'Alt+5', keywords: 'tools mcp sandbox 沙箱 函数' },
|
||||
{ to: '/knowledge', label: '知识', hint: '知识库、长期记忆、方法论 Skill', icon: BookOpen, shortcut: 'Alt+6', keywords: 'knowledge kb memory skill 知识库 记忆 文档' },
|
||||
// 后加的页排在设置前面,设置留在最底下、快捷键也不动:⌥7 按了好几个版本,改了等于让人重新记
|
||||
{ to: '/schedules', label: SCHEDULE_TEXT.title, hint: SCHEDULE_TEXT.hint, icon: CalendarClock, shortcut: 'Alt+8', keywords: 'schedules schedule cron 定时 计划 周期 自动运行' },
|
||||
{ to: '/settings', label: '设置', hint: '模型接入、偏好、运行环境', icon: Settings, shortcut: 'Alt+7', keywords: 'settings provider 模型 署名 主题 偏好' },
|
||||
]
|
||||
|
||||
|
||||
@@ -0,0 +1,14 @@
|
||||
import type { JSX } from 'react'
|
||||
|
||||
/**
|
||||
* 预览用例的写法示例:打开 /preview.html?syn=scaffold-example 看到的就是下面这个。
|
||||
*
|
||||
* dev/fixtures 下每个 .tsx 导出 cases(用例名 → 组件),preview.tsx 自动收进来,?syn=<用例名> 先在这里找,
|
||||
* 找不到再走 preview.tsx 里原有的用例。用例名全站唯一,带上功能前缀(schedules-list、compare-basic),
|
||||
* 重名时后加载的会盖掉先加载的,控制台会提示。和 preview.tsx 一样只在开发服务器里加载,不进生产包。
|
||||
*/
|
||||
export const cases: Record<string, () => JSX.Element> = {
|
||||
'scaffold-example': () => (
|
||||
<div className="p-4 text-sm" data-fixture="scaffold-example">预览用例示例</div>
|
||||
),
|
||||
}
|
||||
@@ -1,4 +1,5 @@
|
||||
import { useEffect, useState } from 'react'
|
||||
import type { JSX } from 'react'
|
||||
import { createRoot } from 'react-dom/client'
|
||||
import { BrowserRouter } from 'react-router-dom'
|
||||
import { Database, MessageSquare, RotateCw } from 'lucide-react'
|
||||
@@ -34,6 +35,20 @@ import '../index.css'
|
||||
|
||||
type Bucket = keyof typeof fixtures
|
||||
|
||||
/**
|
||||
* 各功能自带的预览用例:dev/fixtures/*.tsx 各自导出 cases(用例名 → 组件),?syn=<用例名> 先在这里找,
|
||||
* 找不到再走下面 synthetic() 里的用例。新功能加预览只加自己的文件,不用改这里——几个工作包同时加用例,
|
||||
* 不会在这一个文件上互相冲突。写法见 dev/fixtures/_example.tsx
|
||||
*/
|
||||
type FixtureCases = Record<string, () => JSX.Element>
|
||||
const FIXTURE_CASES: FixtureCases = {}
|
||||
for (const [file, mod] of Object.entries(import.meta.glob<{ cases?: FixtureCases }>('./fixtures/*.tsx', { eager: true }))) {
|
||||
for (const [name, render] of Object.entries(mod.cases ?? {})) {
|
||||
if (name in FIXTURE_CASES) console.warn(`预览用例重名:${name}(${file} 盖掉了先加载的那个)`)
|
||||
FIXTURE_CASES[name] = render
|
||||
}
|
||||
}
|
||||
|
||||
const CASES: { key: Bucket; question: string; phase: StreamTurn['phase']; status: string }[] = [
|
||||
{ key: 'db', question: '这个库里有多少数据?挑最大的表说说', phase: 'done', status: '已完成' },
|
||||
{ key: 'think', question: '分析上季度华东区销量下滑的原因', phase: 'running', status: '运行中' },
|
||||
@@ -561,6 +576,9 @@ function Preview() {
|
||||
)
|
||||
}
|
||||
if (syn) {
|
||||
// 当组件渲染,不直接调用:用例里可以用 hook
|
||||
const Fixture = FIXTURE_CASES[syn]
|
||||
if (Fixture) return <Fixture />
|
||||
const linked: string[] = ((window as any).__linked ??= [])
|
||||
const stream = (
|
||||
<AssistantStream
|
||||
|
||||
@@ -83,6 +83,8 @@
|
||||
--nt-validate: #ebb1fd;
|
||||
--nt-metrics: #cbaddb;
|
||||
--nt-report: #a9b0ec;
|
||||
--nt-dual_check: #a98ee0;
|
||||
--nt-challenge: #dcb7ef;
|
||||
|
||||
/* 检索通路的分类色:只说「这一分是哪一路检索贡献的」,不表示状态,所以
|
||||
不借 accent / ok / warn。两色按 dataviz 校验过:色觉异常下也分得开,
|
||||
@@ -142,6 +144,8 @@
|
||||
--nt-validate: #885398;
|
||||
--nt-metrics: #6e557b;
|
||||
--nt-report: #4f5694;
|
||||
--nt-dual_check: #5a4a91;
|
||||
--nt-challenge: #7d4c8f;
|
||||
--via-semantic: #0a7ea4;
|
||||
--via-keyword: #c2447a;
|
||||
}
|
||||
@@ -199,6 +203,8 @@
|
||||
--nt-validate: #885398;
|
||||
--nt-metrics: #6e557b;
|
||||
--nt-report: #4f5694;
|
||||
--nt-dual_check: #5a4a91;
|
||||
--nt-challenge: #7d4c8f;
|
||||
--via-semantic: #0a7ea4;
|
||||
--via-keyword: #c2447a;
|
||||
}
|
||||
@@ -407,6 +413,8 @@
|
||||
.nt-subgraph { --nt: var(--nt-subgraph); }
|
||||
.nt-metrics { --nt: var(--nt-metrics); }
|
||||
.nt-report { --nt: var(--nt-report); }
|
||||
.nt-dual_check { --nt: var(--nt-dual_check); }
|
||||
.nt-challenge { --nt: var(--nt-challenge); }
|
||||
|
||||
/* --------------------------------------------------------------------------
|
||||
React Flow 覆盖
|
||||
|
||||
@@ -167,6 +167,8 @@ export const NODE_TYPE_LABEL: Record<NodeType, string> = {
|
||||
validate: '结构校验',
|
||||
metrics: '口径卡',
|
||||
report: '报告撰写',
|
||||
dual_check: '双盲复算',
|
||||
challenge: '反方审稿',
|
||||
}
|
||||
|
||||
/** 与 decode.ts 里旧名字同名的出口,第二波改成从这里导入时不用改调用处 */
|
||||
@@ -2721,3 +2723,57 @@ export const COPILOT_CONTEXT_TEXT = {
|
||||
noCatalog: (who: string | null) => `${who ?? '这个数据源'}还没有数据目录,起草后挑表和 SQL 检查会更准`,
|
||||
toCatalog: '去数据目录起草',
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// 下面几块是复核套件各工作包的文案位:名字先占好,各包只往自己那块里加,不去改同一处。
|
||||
// 还没做出来的功能,界面上统一写 PENDING_TEXT 那一句
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
/** 尚未完成的功能在界面上的统一说法 */
|
||||
const PENDING_TEXT = '功能开发中'
|
||||
|
||||
/** 定时任务:导航、命令面板和定时任务页 */
|
||||
export const SCHEDULE_TEXT = {
|
||||
title: '定时任务',
|
||||
hint: '按设定的周期自动发起工作流运行',
|
||||
pending: PENDING_TEXT,
|
||||
pendingHint: '定时任务尚未开放,完成后可在此处管理',
|
||||
}
|
||||
|
||||
/** 运行对比:记录页里两次运行的对照。配方前后对照另有 COMPARE_TEXT,别混用 */
|
||||
export const RUN_COMPARE_TEXT = {
|
||||
title: '运行对比',
|
||||
hint: '对照两次运行的结论与数据',
|
||||
pending: PENDING_TEXT,
|
||||
pendingHint: '运行对比尚未开放,完成后可从记录页选择两次运行进行对照',
|
||||
}
|
||||
|
||||
/** 可验证报告:导出可独立核对的报告 */
|
||||
export const BUNDLE_TEXT = {
|
||||
title: '可验证报告',
|
||||
}
|
||||
|
||||
/** 审批质询:审批人在批准前就待审的报告提出质询 */
|
||||
export const INQUIRY_TEXT = {
|
||||
title: '审批质询',
|
||||
}
|
||||
|
||||
/** 数字推演:在一次运行的基础上改动输入,推演指标的变化 */
|
||||
export const WHATIF_TEXT = {
|
||||
title: '数字推演',
|
||||
}
|
||||
|
||||
/** 双盲复算节点:节点库说明、检查器和运行结果 */
|
||||
export const DUAL_CHECK_TEXT = {
|
||||
description: '另起一路独立计算,与原结果逐项比对',
|
||||
pending: `${PENDING_TEXT}:本节点暂未生效,运行时将跳过`,
|
||||
}
|
||||
|
||||
/** 反方审稿节点:节点库说明、检查器和运行结果 */
|
||||
export const CHALLENGE_TEXT = {
|
||||
description: '从反方立场审阅上游报告,逐条提出质疑',
|
||||
pending: `${PENDING_TEXT}:本节点暂未生效,运行时将跳过`,
|
||||
}
|
||||
|
||||
/** 设置页里复核套件(双盲复算、反方审稿等)的默认值一栏 */
|
||||
export const VERIFY_SETTING_TEXT = {}
|
||||
|
||||
@@ -0,0 +1,21 @@
|
||||
import { GitCompareArrows } from 'lucide-react'
|
||||
import { EmptyState, PageHeader } from '../../components/ui'
|
||||
import { RUN_COMPARE_TEXT } from '../../lib/terms'
|
||||
|
||||
/**
|
||||
* 运行对比(/runs/compare)。现在是占位页,运行对比的工作包补上内容。
|
||||
*
|
||||
* 挂在 /runs 下面,导航照旧点亮「记录」;路由表里排在 /runs/:runId 之前,「compare」不会被当成运行 id。
|
||||
*/
|
||||
export function ComparePage() {
|
||||
return (
|
||||
<div className="flex h-full flex-col">
|
||||
<PageHeader icon={<GitCompareArrows size={13} />} title={RUN_COMPARE_TEXT.title} subtitle={RUN_COMPARE_TEXT.hint} />
|
||||
<div className="min-h-0 flex-1 overflow-y-auto">
|
||||
{/* 功能没做出来,和连没连上服务端无关:不走空态的离线说法 */}
|
||||
<EmptyState icon={<GitCompareArrows size={22} />} title={RUN_COMPARE_TEXT.pending}
|
||||
body={RUN_COMPARE_TEXT.pendingHint} offline={false} />
|
||||
</div>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
import { CalendarClock } from 'lucide-react'
|
||||
import { EmptyState, PageHeader } from '../../components/ui'
|
||||
import { SCHEDULE_TEXT } from '../../lib/terms'
|
||||
|
||||
/**
|
||||
* 定时任务(/schedules、/schedules/:id)。现在是占位页,定时任务的工作包补上列表和详情。
|
||||
*/
|
||||
export function SchedulesPage() {
|
||||
return (
|
||||
<div className="flex h-full flex-col">
|
||||
<PageHeader icon={<CalendarClock size={13} />} title={SCHEDULE_TEXT.title} subtitle={SCHEDULE_TEXT.hint} />
|
||||
<div className="min-h-0 flex-1 overflow-y-auto">
|
||||
{/* 功能没做出来,和连没连上服务端无关:不走空态的离线说法 */}
|
||||
<EmptyState icon={<CalendarClock size={22} />} title={SCHEDULE_TEXT.pending}
|
||||
body={SCHEDULE_TEXT.pendingHint} offline={false} />
|
||||
</div>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
import type { ApprovalReport } from '../types'
|
||||
|
||||
export interface ChallengeSummaryProps {
|
||||
/** 这张审批卡审的报告(payload.reports,和 ApprovalReports 拿到的是同一份) */
|
||||
reports: ApprovalReport[]
|
||||
runId: string
|
||||
}
|
||||
|
||||
/**
|
||||
* 审批卡里反方审稿的摘要,紧跟在报告核对概况(ApprovalReports)后面。
|
||||
*
|
||||
* 现在是占位,什么都不画;反方审稿的工作包在这里补上反驳意见的摘要。审的不是报告、或者报告没经过
|
||||
* 反方审稿时也应该什么都不画,卡片和以前一样。
|
||||
*/
|
||||
export function ChallengeSummary(_props: ChallengeSummaryProps) {
|
||||
return null
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
import type { Approval } from '../types'
|
||||
|
||||
export interface DualCheckApprovalProps {
|
||||
/** payload.kind 为 'dual_check' 的审批:双盲复算两路对不上、交给人裁决 */
|
||||
approval: Approval
|
||||
}
|
||||
|
||||
/**
|
||||
* 审批卡里双盲复算那一块(RunPanel 的 ApprovalCard 在 payload.kind === 'dual_check' 时渲染它)。
|
||||
*
|
||||
* 现在是占位,什么都不画;双盲复算的工作包在这里补上两路结果的对照,payload 的形状由那边定。
|
||||
*/
|
||||
export function DualCheckApproval(_props: DualCheckApprovalProps) {
|
||||
return null
|
||||
}
|
||||
@@ -12,6 +12,8 @@ import { runClassLabel, runName, TOOL_TRUST_TEXT } from '../lib/terms'
|
||||
import { useRunClock } from './useRunClock'
|
||||
import { Markdown } from './Markdown'
|
||||
import { ApprovalReports, ApprovalRunClass } from './ApprovalReport'
|
||||
import { ChallengeSummary } from './ChallengeSummary'
|
||||
import { DualCheckApproval } from './DualCheckApproval'
|
||||
import type { Approval, ApprovalReport } from '../types'
|
||||
|
||||
// 发起运行的表单搬去了 run/RunControl.tsx 的工具栏控件里。它原先常驻在
|
||||
@@ -144,7 +146,11 @@ export function ApprovalCard({ approval, onResolved, showWorkflow = true }: {
|
||||
</div>
|
||||
)}
|
||||
|
||||
{/* 双盲复算对不上、交给人裁决的审批,卡上画两路结果的对照 */}
|
||||
{payload.kind === 'dual_check' && <DualCheckApproval approval={approval} />}
|
||||
|
||||
<ApprovalReports reports={reports} runId={approval.run_id} runClass={approval.run_class} />
|
||||
<ChallengeSummary reports={reports} runId={approval.run_id} />
|
||||
|
||||
{payload.tool && (
|
||||
<div className="mb-2 rounded border bg-bg p-2">
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
export type NodeType =
|
||||
| 'input' | 'output' | 'llm' | 'agent' | 'supervisor' | 'tool' | 'code' | 'merge'
|
||||
| 'branch' | 'loop' | 'subgraph' | 'memory' | 'retrieve' | 'transform'
|
||||
| 'human' | 'validate' | 'metrics' | 'report'
|
||||
| 'human' | 'validate' | 'metrics' | 'report' | 'dual_check' | 'challenge'
|
||||
|
||||
export interface GraphNode {
|
||||
id: string
|
||||
|
||||
Reference in New Issue
Block a user