mirror of
https://github.com/ThearchyHelios/AgentLab.git
synced 2026-11-17 22:31:57 +00:00
e4f2693918
「引用即渲染」:写报告的模型只写引用标记([[m:指标id]]、[[i:输入字段]]、[[see:…]]),数值由系统按口径卡
填进去,每个数字都挂着一条能复算的证据链。本期是数字层闭环;实体、结论句的概率性证据放在后续几期。
内核(engine/evidence.py,口径卡、出具契约、表达式等)
- 口径卡记录每个指标的来源:原式、代入式(每个输入写成「值 ← 路径」)、复算结果、口径与版本
- 出具契约的数值匹配改为按位置标注;同一个值有几个出处时记为「出处不唯一」并列出候选,不再随便挑一个
- 证据 id 由内容派生,事后对不上就是被改过;零值、结构性数字(列表序号、代码块标签)单独处理
- 口径卡新增 on_missing:缺输入时默认仍是整个节点失败,可以改成记为空值、交给契约判档
报告撰写节点(report)与引用模式的出具契约
- 流式生成时 token 里就是真实数字,不会漏出原始标记;裸数字、不存在的引用当场判违规,交回去重写
(max_repairs,默认 1 次);仍不过时按 on_violation 失败(正式运行默认)或把违规标在报告里(探索运行默认)
- report.checked 事件记下核对结果,落在封存范围内;fail 模式下仍不过时带 failed,运行记录里画成失败
- 出具契约写了 report_from 就按引用核对:取回文档时复验哈希,独立重算一遍,全部带引用才判完整出具
- 成果字段逐字等于报告正文时标注 _evidence;复核只能加说明,不能改写带证据的答案(前后端各拦一道)
证据接口
- GET /api/runs/{id}/evidence 返回证据图;GET …/evidence/segments/{id} 返回一个片段的证据链
- 只认封存范围内的事件能追到的工件,不读 artifacts 表;封存被改过时不把任何一项标成已封存
- 没有报告的旧运行降级为 none 或 legacy_contract
界面
- EvidenceDoc 按块、句、片段渲染报告,片段是和正文一样的按钮;整份报告只占一个 Tab 位,
←/→ 在片段间移动、↑/↓ 按句、n/N 跳到下一处「无证据」、Enter 打开面板、Esc 关闭并把焦点还回去
- EvidencePanel:宽屏侧边、窄屏底部抽屉、360px 画布右栏里栏内展开;显示指标步骤、代入式、复算结果、
封存状态。正文不是封存的那份报告时明确说出来,不拿别的报告的封存画绿
- 出具横幅多一行「N/N 数字有出处 · 无证据 M」和「定位下一处」;没有 _evidence 的旧回答渲染一字不差
- 画布认得报告撰写节点;Copilot 手册补上口径卡、报告节点、出具契约的写法;新增模板「⑨ 可追溯周报」
验证(沙箱):tsc 干净,生产构建通过,pytest 1601 passed,check-all 16 项检查全绿(新增 check-evidence)。
556 lines
27 KiB
TypeScript
556 lines
27 KiB
TypeScript
import { useEffect, useState } from 'react'
|
||
import type { ReactNode } from 'react'
|
||
import { createRoot } from 'react-dom/client'
|
||
import { BrowserRouter } from 'react-router-dom'
|
||
import { Database, Inbox, Plus, Trash2, RefreshCw } from 'lucide-react'
|
||
import {
|
||
DeleteButton, EmptyState, ErrorState, Field, HealthPill, IconButton, Kbd, Modal, OfflineBanner, PageHeader,
|
||
SectionBar, Skeleton, StatusBadge, StatusPill, Tabs, TabPanel, ToastHost, confirmDialog, deferDelete,
|
||
promptDialog, toast, useRadioGroup, withoutDeferred,
|
||
} from '../components/ui'
|
||
import { ApiError, api, streamCopilot } from '../api/client'
|
||
import { useCatalog, useDatasources, useOnReconnect } from '../store/catalog'
|
||
import { STATUS } from '../lib/status'
|
||
import { formatClock, formatCost, formatDateTime, formatDuration, formatTime, formatTokens } from '../lib/format'
|
||
import * as format from '../lib/format'
|
||
import * as status from '../lib/status'
|
||
import * as keys from '../lib/keys'
|
||
import * as terms from '../lib/terms'
|
||
import * as errors from '../lib/errors'
|
||
import * as explain from '../lib/explain'
|
||
import * as health from '../lib/health'
|
||
import * as actor from '../lib/actor'
|
||
import * as validation from '../lib/validation'
|
||
import * as evidence from '../lib/evidence'
|
||
import { EvidenceDoc, EvidenceField } from '../run/EvidenceDoc'
|
||
import { Markdown } from '../run/Markdown'
|
||
import evidenceFixture from '../run/__tests__/evidence-doc.json'
|
||
import mdPinned from '../run/__tests__/markdown-pinned.json'
|
||
import type { EvidenceDocData } from '../types'
|
||
import '../index.css'
|
||
|
||
/**
|
||
* 基础组件的离线预览(ui.tsx)。
|
||
*
|
||
* 只有 dev server 会加载(vite build 的 input 只有 index.html),不进生产包。
|
||
* 存在的理由:弹窗的焦点管理、Esc 的输入法判断、toast 的寿命这些东西,在真实
|
||
* 页面里要凑齐场景才看得到;这里每样都摆出来,亮暗两套主题一键切换。
|
||
*
|
||
* 打开 http://localhost:5273/ui-harness.html
|
||
*
|
||
* window.__ui 和各个按钮的 id 是检查脚本在用的,改名要一起改。
|
||
*/
|
||
|
||
const ALL_STATUS = Object.keys(STATUS)
|
||
|
||
function Block({ title, children }: { title: string; children: ReactNode }) {
|
||
return (
|
||
<section className="rounded-xl border bg-panel p-4" data-block={title}>
|
||
<h3 className="mb-3 text-[11px] font-semibold uppercase tracking-wide text-faint">{title}</h3>
|
||
{children}
|
||
</section>
|
||
)
|
||
}
|
||
|
||
function DirtyModalDemo() {
|
||
const [open, setOpen] = useState(false)
|
||
const [text, setText] = useState('')
|
||
return (
|
||
<>
|
||
<button className="btn btn-sm" id="open-dirty" onClick={() => setOpen(true)}>打开编辑弹窗</button>
|
||
<Modal
|
||
open={open}
|
||
onClose={() => { setOpen(false); setText('') }}
|
||
title="编辑 Skill"
|
||
dirty={text.trim() !== ''}
|
||
footer={
|
||
<>
|
||
<button className="btn" onClick={() => { setOpen(false); setText('') }}>取消</button>
|
||
<button className="btn btn-primary" onClick={() => { setOpen(false); setText(''); toast.ok('已保存') }}>保存</button>
|
||
</>
|
||
}
|
||
>
|
||
<div className="flex flex-col gap-3">
|
||
<Field label="名称" hint="小写英文、数字和下划线" required>
|
||
{(p) => <input className="field" {...p} placeholder="sales_report" />}
|
||
</Field>
|
||
<Field label="指令" hint="填了内容再按 Esc 或点遮罩,会先问一句">
|
||
{(p) => (
|
||
<textarea className="field" rows={4} {...p} value={text} onChange={(e) => setText(e.target.value)} />
|
||
)}
|
||
</Field>
|
||
</div>
|
||
</Modal>
|
||
</>
|
||
)
|
||
}
|
||
|
||
/**
|
||
* 页面自己拉的列表:断开期间拿到 [],恢复后靠 useOnReconnect 重拉。
|
||
* 运行记录、数据源、会话这些页面都是这个形状。
|
||
*/
|
||
function LocalListDemo() {
|
||
const [runs, setRuns] = useState<{ id: string }[] | null>(null)
|
||
const [loads, setLoads] = useState(0)
|
||
const load = () => {
|
||
setLoads((n) => n + 1)
|
||
void api.runs.list({ limit: 3 }).catch(() => []).then(setRuns)
|
||
}
|
||
useEffect(load, [])
|
||
useOnReconnect(load)
|
||
return (
|
||
<div className="text-xs text-dim">
|
||
<div className="flex items-center gap-2">
|
||
<span>
|
||
页面自己的列表:拉取 <span id="local-list-loads" className="mono">{loads}</span> 次 · 当前{' '}
|
||
<span id="local-list-count" className="mono">{runs?.length ?? '—'}</span> 条
|
||
</span>
|
||
<button className="btn btn-sm ml-auto" id="local-list-reload" onClick={load}>重新拉取</button>
|
||
</div>
|
||
{runs && !runs.length && <EmptyState title="还没有运行记录" className="py-4" />}
|
||
</div>
|
||
)
|
||
}
|
||
|
||
const DEMO_ROWS = [
|
||
{ id: 'orders', name: 'orders' }, { id: 'sales_daily', name: 'sales_daily' }, { id: 'hr_attendance', name: 'hr_attendance' },
|
||
]
|
||
const RADIO = ['service_name', 'sid', 'dsn'] as const
|
||
|
||
/** 管理页共用件:页头、分节、连通胶囊、单选组、删除后可撤销 */
|
||
function ManageKitDemo() {
|
||
const [rows, setRows] = useState(DEMO_ROWS)
|
||
const [mode, setMode] = useState<(typeof RADIO)[number]>('service_name')
|
||
const radio = useRadioGroup(RADIO, mode, setMode)
|
||
const [now] = useState(() => Date.now())
|
||
const reload = () => setRows(withoutDeferred(DEMO_ROWS, '/api/__harness__/rows'))
|
||
return (
|
||
<div className="flex flex-col gap-3">
|
||
<div className="overflow-hidden rounded-lg border" id="page-header-demo">
|
||
<PageHeader icon={<Database size={13} />} title="数据" subtitle="接入的数据库和传上来的表格" actions={<button className="btn btn-sm">刷新</button>} />
|
||
</div>
|
||
<SectionBar title="数据库" hint="接入后助手编排时看得见这些库的结构">
|
||
<button className="btn btn-sm btn-primary"><Plus size={12} /> 接入数据库</button>
|
||
</SectionBar>
|
||
<div className="flex flex-wrap items-center gap-x-4 gap-y-2" id="health-demo">
|
||
<HealthPill />
|
||
<HealthPill checkingSince={now - 1200} />
|
||
<HealthPill record={{ ok: true, ms: 42, at: now - 3 * 60_000 }} />
|
||
<HealthPill record={{ ok: false, at: now - 60 * 60_000, error: '连不上:端口没开' }} />
|
||
<HealthPill record={{ ok: true, ms: 380, at: 0 }} stale />
|
||
<HealthPill record={{ ok: false, at: 0, error: '连不上:认证没通过' }} />
|
||
</div>
|
||
<div role="radiogroup" aria-label="连接方式" className="flex gap-1" id="radio-demo">
|
||
{RADIO.map((v) => (
|
||
<button key={v} type="button" className={v === mode ? 'btn btn-sm btn-primary' : 'btn btn-sm'} {...radio(v)} onClick={() => setMode(v)}>
|
||
{v}
|
||
</button>
|
||
))}
|
||
</div>
|
||
<ul className="flex flex-col gap-1 text-xs" id="defer-demo">
|
||
{rows.map((r) => (
|
||
<li key={r.id} className="flex items-center gap-2" data-row={r.id}>
|
||
<span className="mono flex-1">{r.name}</span>
|
||
<DeleteButton
|
||
label={`删除 ${r.name}`}
|
||
onClick={() => deferDelete({
|
||
what: `「${r.name}」`,
|
||
url: `/api/__harness__/rows/${r.id}`,
|
||
hide: () => setRows((l) => l.filter((x) => x.id !== r.id)),
|
||
restore: reload,
|
||
commit: () => Promise.resolve(),
|
||
})}
|
||
/>
|
||
</li>
|
||
))}
|
||
</ul>
|
||
<button className="btn btn-sm self-start" id="defer-reload" onClick={reload}>重拉列表</button>
|
||
</div>
|
||
)
|
||
}
|
||
|
||
/**
|
||
* useDatasources 的挂载探针:检查脚本用 window.__ui.mountDatasources(n) 同时挂 n 个消费方,
|
||
* 数请求看「过期才拉、多处挂载只拉一次、启动落定后补拉」
|
||
*/
|
||
let setDatasourceConsumers: (n: number) => void = () => {}
|
||
function DatasourceConsumer() {
|
||
const { list, state } = useDatasources()
|
||
return <span data-ds-consumer={state}>{list.length}</span>
|
||
}
|
||
function DatasourceConsumers() {
|
||
const [n, setN] = useState(0)
|
||
useEffect(() => { setDatasourceConsumers = setN }, [])
|
||
return <div hidden data-ds-consumers={n}>{Array.from({ length: n }, (_, i) => <DatasourceConsumer key={i} />)}</div>
|
||
}
|
||
|
||
const EV_DOC = evidenceFixture.doc as unknown as EvidenceDocData
|
||
const EV_LEGACY = evidenceFixture.legacy
|
||
/** 同一份旧契约的出具,去掉位置:老运行就是这样,只能按字符串标 */
|
||
const LEGACY_LOOSE = {
|
||
matched: EV_LEGACY.matched.map(({ start: _s, end: _e, ...m }) => m),
|
||
unmatched_numbers: EV_LEGACY.unmatched.map(({ start: _s, end: _e, ...u }) => u),
|
||
}
|
||
|
||
/**
|
||
* 长报告:把夹具的块重复 n 遍(块、句、片段的 id 各自加后缀),stats 和违规清单去掉,
|
||
* 计数从片段自己数。用来看块级 content-visibility、超长折叠、跳转进折叠区时自动展开
|
||
*/
|
||
function longDoc(doc: EvidenceDocData, times: number): EvidenceDocData {
|
||
const blocks = Array.from({ length: times }, (_, k) => doc.blocks.map((b) => ({
|
||
...b, id: `${b.id}-${k}`,
|
||
units: b.units.map((u) => ({ ...u, id: `${u.id}-${k}`, segments: u.segments.map((s) => ({ ...s, id: `${s.id}-${k}` })) })),
|
||
}))).flat()
|
||
return { ...doc, blocks, stats: undefined, violations: undefined, markdown: undefined }
|
||
}
|
||
const EV_LONG = longDoc(EV_DOC, 16)
|
||
|
||
/**
|
||
* 可点击证据的演示:宽栏(侧边面板 / 窄屏时底部抽屉)、360px 窄栏(栏内展开)、旧契约的
|
||
* 按位置标记。文档是后端 compose_doc 真跑出来的夹具(evidence-doc.json,只用通用名);
|
||
* runId 是假的,片段接口由 check-evidence 用 page.route 伪造,直接打开时面板照实说取不到
|
||
*/
|
||
function EvidenceDemo() {
|
||
return (
|
||
<div className="flex flex-col gap-4" id="evidence-demo">
|
||
<div id="evidence-wide" className="rounded-lg border p-3">
|
||
<EvidenceDoc doc={EV_DOC} artifact={evidenceFixture.doc_artifact} runId={evidenceFixture.run_id} label="周报" tally />
|
||
</div>
|
||
<div id="evidence-narrow" className="rounded-lg border bg-panel p-2.5" style={{ width: 360, maxWidth: '100%' }}>
|
||
<EvidenceDoc doc={EV_DOC} artifact={evidenceFixture.doc_artifact} runId={evidenceFixture.run_id} label="周报" dense tally />
|
||
</div>
|
||
<div className="grid gap-3 md:grid-cols-2">
|
||
<div id="legacy-marks" className="rounded-lg border p-3">
|
||
<div className="mb-1 text-2xs text-faint">旧契约 · 按位置标(日期里的 15 不画)</div>
|
||
<Markdown text={EV_LEGACY.text}
|
||
marks={evidence.issuanceMarks({ matched: EV_LEGACY.matched, unmatched_numbers: EV_LEGACY.unmatched })} />
|
||
</div>
|
||
<div id="legacy-loose" className="rounded-lg border p-3">
|
||
<div className="mb-1 text-2xs text-faint">老运行 · 没有位置,按字符串标</div>
|
||
<Markdown text={EV_LEGACY.text} marks={evidence.issuanceMarks(LEGACY_LOOSE)} />
|
||
</div>
|
||
</div>
|
||
</div>
|
||
)
|
||
}
|
||
|
||
/** ?evidence=1:只摆证据演示,360px 宽度的检查和截图不被别的演示撑宽 */
|
||
function EvidenceOnly() {
|
||
const [theme, setTheme] = useState<'dark' | 'light'>(() => {
|
||
const t = new URLSearchParams(location.search).get('theme') === 'light' ? 'light' : 'dark'
|
||
document.documentElement.setAttribute('data-theme', t)
|
||
return t
|
||
})
|
||
const flip = (t: 'dark' | 'light') => { setTheme(t); document.documentElement.setAttribute('data-theme', t) }
|
||
return (
|
||
<div className="h-full overflow-y-auto">
|
||
<div className="mx-auto flex max-w-5xl flex-col gap-3 p-4">
|
||
<div className="flex items-center gap-2">
|
||
<h1 className="text-base font-semibold">可点击证据</h1>
|
||
<div className="ml-auto flex gap-1">
|
||
<button className="btn btn-sm" id="theme-dark" onClick={() => flip('dark')} aria-pressed={theme === 'dark'}>暗</button>
|
||
<button className="btn btn-sm" id="theme-light" onClick={() => flip('light')} aria-pressed={theme === 'light'}>亮</button>
|
||
</div>
|
||
</div>
|
||
<EvidenceDemo />
|
||
<div id="evidence-long" className="rounded-lg border p-3">
|
||
<div className="mb-1 text-2xs text-faint">长报告:{EV_LONG.blocks.length} 块,块级 content-visibility,超过 3000 字先折叠</div>
|
||
<EvidenceDoc doc={EV_LONG} label="长报告" tally />
|
||
</div>
|
||
{/*
|
||
成果字段按工件 id 取文档。check-evidence 把这几件工件伪造成:正文这份(能画)、
|
||
另一次运行写的(run_id 不同)、没记正文的(缺 markdown)——后两种都得退回普通文本
|
||
*/}
|
||
<div id="evidence-fields" className="grid gap-3 md:grid-cols-3">
|
||
{[['fx-field-ok', '正文这份'], ['fx-field-other-run', '另一次运行写的'], ['fx-field-no-markdown', '没记正文']].map(([id, name]) => (
|
||
<div key={id} id={id} className="rounded-lg border p-3">
|
||
<div className="mb-1 text-2xs text-faint">成果字段 · {name}</div>
|
||
<EvidenceField artifact={id} text={evidenceFixture.output['周报']} runId={evidenceFixture.run_id} dense label="周报" />
|
||
</div>
|
||
))}
|
||
</div>
|
||
{/*
|
||
没有 _evidence 的旧回答:同一批文字用现在的 Markdown 渲染,check-evidence 拿它和
|
||
Markdown.tsx 改动前(HEAD)渲染出来的 outerHTML(markdown-pinned.json)逐字比对
|
||
*/}
|
||
<div id="md-pinned" className="rounded-lg border p-3">
|
||
<div className="mb-1 text-2xs text-faint">旧回答的 Markdown:和改动前逐字比对</div>
|
||
{(mdPinned.samples as { id: string; text: string; dense: boolean; marks?: any[] }[]).map((p) => (
|
||
<div key={p.id} data-pin={p.id} className="border-t py-2 first:border-t-0">
|
||
<Markdown text={p.text} dense={p.dense} marks={p.marks} />
|
||
</div>
|
||
))}
|
||
</div>
|
||
</div>
|
||
</div>
|
||
)
|
||
}
|
||
|
||
function Harness() {
|
||
const [theme, setTheme] = useState<'dark' | 'light'>(() => {
|
||
// 没有显式主题时会跟随系统;预览要确定是哪一套,开场就钉住
|
||
const t = (document.documentElement.getAttribute('data-theme') as 'dark' | 'light') || 'dark'
|
||
document.documentElement.setAttribute('data-theme', t)
|
||
return t
|
||
})
|
||
const [tab, setTab] = useState('a')
|
||
const [last, setLast] = useState('')
|
||
const backend = useCatalog((s) => s.backend)
|
||
|
||
const flip = (t: 'dark' | 'light') => {
|
||
setTheme(t)
|
||
document.documentElement.setAttribute('data-theme', t)
|
||
}
|
||
|
||
return (
|
||
<div className="flex h-full flex-col">
|
||
<OfflineBanner />
|
||
<DatasourceConsumers />
|
||
<div className="flex-1 overflow-y-auto">
|
||
<div className="mx-auto flex max-w-5xl flex-col gap-4 p-6">
|
||
<div className="flex items-center gap-2">
|
||
<h1 className="text-base font-semibold">基础组件</h1>
|
||
<span className="text-xs text-faint">ui.tsx · lib/*</span>
|
||
<div className="ml-auto flex gap-1">
|
||
<button className="btn btn-sm" id="theme-dark" onClick={() => flip('dark')} aria-pressed={theme === 'dark'}>暗</button>
|
||
<button className="btn btn-sm" id="theme-light" onClick={() => flip('light')} aria-pressed={theme === 'light'}>亮</button>
|
||
<button
|
||
className="btn btn-sm"
|
||
id="toggle-offline"
|
||
onClick={() => useCatalog.setState(backend === 'down'
|
||
? { backend: 'ok', backendError: null, retryAt: null }
|
||
: { backend: 'down', backendError: '连不上后端服务(可能没启动或正在重启),稍后重试', retryAt: Date.now() + 8000, lastOkAt: Date.now() - 42_000 })}
|
||
>
|
||
{backend === 'down' ? '恢复在线' : '模拟离线'}
|
||
</button>
|
||
</div>
|
||
</div>
|
||
|
||
<Block title="状态徽标 · 彩色">
|
||
<div className="flex flex-wrap gap-x-5 gap-y-3" id="badges-color">
|
||
{ALL_STATUS.map((s) => (
|
||
<div key={s} className="flex w-24 flex-col items-center gap-1.5">
|
||
<StatusBadge status={s} size={18} />
|
||
<span className="text-[11px] text-dim">{STATUS[s as keyof typeof STATUS].label}</span>
|
||
<span className="mono text-[10px] text-faint">{s}</span>
|
||
</div>
|
||
))}
|
||
</div>
|
||
</Block>
|
||
|
||
<Block title="状态徽标 · 灰度(去掉颜色也要认得出)">
|
||
<div className="flex flex-wrap gap-x-5 gap-y-3" id="badges-gray" style={{ filter: 'grayscale(1)' }}>
|
||
{ALL_STATUS.map((s) => (
|
||
<div key={s} className="flex w-24 flex-col items-center gap-1.5">
|
||
<StatusBadge status={s} size={18} animate={false} />
|
||
<span className="text-[11px] text-dim">{STATUS[s as keyof typeof STATUS].short}</span>
|
||
</div>
|
||
))}
|
||
</div>
|
||
</Block>
|
||
|
||
<Block title="状态标签 StatusPill">
|
||
<div className="flex flex-wrap gap-2">
|
||
{ALL_STATUS.map((s) => <StatusPill key={s} status={s} />)}
|
||
</div>
|
||
<div className="mt-3 flex flex-wrap items-center gap-3 text-xs text-dim">
|
||
<span>后端 interrupted:</span>
|
||
<StatusPill status="interrupted" pendingApproval />
|
||
<StatusPill status="interrupted" pendingApproval={false} />
|
||
<span className="ml-4">plain:</span>
|
||
<StatusPill status="succeeded" plain />
|
||
<StatusPill status="failed" plain />
|
||
</div>
|
||
</Block>
|
||
|
||
<div className="grid grid-cols-2 gap-4">
|
||
<Block title="弹窗 Modal · confirm · prompt">
|
||
<div className="flex flex-wrap gap-2">
|
||
<DirtyModalDemo />
|
||
<button
|
||
className="btn btn-sm"
|
||
id="open-confirm"
|
||
onClick={async () => setLast(String(await confirmDialog({
|
||
title: '发布这个版本?', body: '发布后可以发起正式运行。', confirmLabel: '发布 v4',
|
||
})))}
|
||
>确认框</button>
|
||
<button
|
||
className="btn btn-sm btn-danger"
|
||
id="open-danger"
|
||
onClick={async () => setLast(String(await confirmDialog({
|
||
title: '删除工作流「⑥ 多 Agent 协作」?',
|
||
consequences: ['连同 4 条运行记录一起删除', '不可恢复'],
|
||
confirmLabel: '删除工作流和 4 条记录',
|
||
danger: true,
|
||
})))}
|
||
>危险确认</button>
|
||
<button
|
||
className="btn btn-sm btn-danger"
|
||
id="open-require"
|
||
onClick={async () => setLast(String(await confirmDialog({
|
||
title: '删除封存过的正式运行?',
|
||
body: '这条运行的清单封存过,是审计凭证。',
|
||
consequences: ['事件流、产出物、封存哈希一起删除', '之后无法再核对'],
|
||
confirmLabel: '删除凭证',
|
||
danger: true,
|
||
requireText: 'a3f9c2',
|
||
})))}
|
||
>照抄确认</button>
|
||
<button
|
||
className="btn btn-sm"
|
||
id="open-prompt"
|
||
onClick={async () => setLast(JSON.stringify(await promptDialog({
|
||
title: '新建工作流', label: '名称', initial: '未命名工作流 09-26 10:05', confirmLabel: '新建',
|
||
validate: (v) => (v === '新工作流' ? '已经有一个同名的了' : null),
|
||
})))}
|
||
>输入框</button>
|
||
</div>
|
||
<div className="mt-2 text-[11px] text-faint">结果:<span id="dialog-result" className="mono text-dim">{last || '—'}</span></div>
|
||
</Block>
|
||
|
||
<Block title="提示 toast">
|
||
<div className="flex flex-wrap gap-2">
|
||
<button className="btn btn-sm" onClick={() => toast('已复制到剪贴板')}>普通</button>
|
||
<button className="btn btn-sm" onClick={() => toast.ok('已保存')}>成功</button>
|
||
<button className="btn btn-sm" onClick={() => toast.warn('这张图有 2 条警告')}>警告</button>
|
||
<button className="btn btn-sm" id="toast-error" onClick={() => toast.error('保存失败:工作流名称不能为空')}>出错</button>
|
||
<button
|
||
className="btn btn-sm"
|
||
id="toast-network"
|
||
onClick={() => toast.error(new ApiError(0, '连不上后端服务(可能没启动或正在重启),稍后重试',
|
||
{ kind: 'network', raw: 'TypeError: Failed to fetch' }))}
|
||
>网络断</button>
|
||
<button
|
||
className="btn btn-sm"
|
||
onClick={() => toast.ok('已提取为草稿「⑥ 多 Agent 协作 · 提取模板」', {
|
||
action: { label: '去画布打开', onClick: () => toast('(这里会跳到画布)') },
|
||
})}
|
||
>带动作</button>
|
||
<button
|
||
className="btn btn-sm"
|
||
onClick={() => toast('已删除会话「本周销量」', 'info', {
|
||
action: { label: '撤销', onClick: () => toast.ok('已恢复') }, duration: 5000,
|
||
})}
|
||
>撤销</button>
|
||
<button className="btn btn-sm" onClick={() => { for (let i = 0; i < 6; i++) toast(`第 ${i + 1} 条`) }}>叠 6 条</button>
|
||
<button className="btn btn-sm" onClick={() => toast.dismiss()}>全部关掉</button>
|
||
</div>
|
||
</Block>
|
||
</div>
|
||
|
||
<div className="grid grid-cols-2 gap-4">
|
||
<Block title="空态 EmptyState(模拟离线时会变)">
|
||
<EmptyState
|
||
icon={<Inbox size={22} />}
|
||
title="还没有工作流"
|
||
body="新建一张空白工作流,或者让助手按一句话画出来。"
|
||
action={<button className="btn btn-sm btn-primary"><Plus size={12} /> 新建工作流</button>}
|
||
/>
|
||
<EmptyState title="没有匹配的工具" offline={false} className="py-4" />
|
||
<div id="empty-source-demo" className="border-t">
|
||
<EmptyState
|
||
source="workflows"
|
||
title="还没有工作流"
|
||
className="py-4"
|
||
action={<button className="btn btn-sm btn-primary" id="empty-source-action"><Plus size={12} /> 新建</button>}
|
||
/>
|
||
</div>
|
||
</Block>
|
||
<Block title="出错 ErrorState">
|
||
<ErrorState
|
||
error={new ApiError(0, '连不上后端服务(可能没启动或正在重启),稍后重试', { kind: 'network', raw: 'TypeError: Failed to fetch' })}
|
||
onRetry={() => toast('重试')}
|
||
className="py-4"
|
||
/>
|
||
<ErrorState
|
||
compact
|
||
error={'2 validation errors for GraphSpec\nnodes.1.type\n Input should be \'input\', \'output\' … [type=literal_error]'}
|
||
/>
|
||
<ErrorState
|
||
compact
|
||
className="mt-2"
|
||
error={new ApiError(409, '这条运行还在跑,先停止再删除。', { raw: '409 {"detail":"这条运行还在跑,先停止再删除。"}' })}
|
||
/>
|
||
</Block>
|
||
</div>
|
||
|
||
<div className="grid grid-cols-2 gap-4">
|
||
<Block title="加载 Skeleton">
|
||
<Skeleton rows={4} />
|
||
<Skeleton rows={2} cols={3} height={44} className="mt-4" />
|
||
<div className="mt-4 border-t pt-3"><LocalListDemo /></div>
|
||
</Block>
|
||
<Block title="图标按钮 · 键帽 · 格式">
|
||
<div className="flex items-center gap-2">
|
||
<IconButton label="删除这条记录" icon={<Trash2 size={13} />} variant="danger" />
|
||
<IconButton label="刷新列表" shortcut="Mod+R" icon={<RefreshCw size={13} />} />
|
||
<Kbd combo="Mod+K" />
|
||
<Kbd combo="Mod+Enter" />
|
||
<Kbd combo="Alt+V" />
|
||
<Kbd combo="Shift+?" />
|
||
<Kbd combo="Esc" />
|
||
</div>
|
||
<dl className="mt-3 grid grid-cols-[auto_1fr] gap-x-3 gap-y-1 text-xs tabular-nums">
|
||
<dt className="text-faint">耗时</dt>
|
||
<dd>{[820, 7600, 59_960, 74_000, 119_600, 3_720_000].map(formatDuration).join(' · ')}</dd>
|
||
<dt className="text-faint">计时</dt>
|
||
<dd className="mono">{[7_630, 74_310, 3_723_400].map(formatClock).join(' · ')}</dd>
|
||
<dt className="text-faint">tokens</dt>
|
||
<dd>{formatTokens(56034)} · {formatTokens(56034, { compact: true })} · {formatTokens(null)}</dd>
|
||
<dt className="text-faint">成本</dt>
|
||
<dd>{[0.0312, 0.0004, 0, 1.2345].map(formatCost).join(' · ')}</dd>
|
||
<dt className="text-faint">时间</dt>
|
||
<dd title={formatDateTime('2026-09-26T01:11:19.891698')}>
|
||
{formatTime('2026-09-26T01:11:19.891698')} · {formatTime('2026-09-25T04:52:00Z')} · {formatDateTime('2026-09-26T01:11:19.891698')}
|
||
</dd>
|
||
</dl>
|
||
</Block>
|
||
</div>
|
||
|
||
<Block title="管理页共用件">
|
||
<ManageKitDemo />
|
||
</Block>
|
||
|
||
<Block title="可点击证据 EvidenceDoc(单独看:?evidence=1)">
|
||
<EvidenceDemo />
|
||
</Block>
|
||
|
||
<Block title="标签页 Tabs · 表单字段 Field">
|
||
<Tabs
|
||
label="示例标签"
|
||
idPrefix="demo"
|
||
tabs={[{ key: 'a', label: '模型接入' }, { key: 'b', label: '数据源', badge: 2 }, { key: 'c', label: '偏好' }]}
|
||
active={tab}
|
||
onChange={setTab}
|
||
/>
|
||
<TabPanel idPrefix="demo" tabKey={tab} className="grid grid-cols-2 gap-3 pt-3">
|
||
<Field label="Base URL" htmlFor="demo-url" hint="OpenAI 兼容端点,以 /v1 结尾" required>
|
||
<input id="demo-url" className="field" aria-describedby="demo-url-hint" placeholder="https://…/v1" />
|
||
</Field>
|
||
<Field label="标识" error="只能用小写英文、数字和下划线,并以字母开头">
|
||
{(p) => <input className="field" defaultValue="Sales-DB" {...p} style={{ borderColor: 'var(--err)' }} />}
|
||
</Field>
|
||
</TabPanel>
|
||
</Block>
|
||
</div>
|
||
</div>
|
||
</div>
|
||
)
|
||
}
|
||
|
||
;(window as any).__ui = {
|
||
toast, confirmDialog, promptDialog, useCatalog, ApiError, api, streamCopilot,
|
||
mountDatasources: (n: number) => setDatasourceConsumers(n),
|
||
// 检查脚本直接拿应用同一份模块实例测 lib:instanceof ApiError 才靠得住
|
||
lib: { format, status, keys, terms, errors, explain, health, actor, validation, evidence },
|
||
evidenceFixture,
|
||
}
|
||
|
||
createRoot(document.getElementById('root')!).render(
|
||
<BrowserRouter>
|
||
<ToastHost>
|
||
{new URLSearchParams(location.search).get('evidence') === '1' ? <EvidenceOnly /> : <Harness />}
|
||
</ToastHost>
|
||
</BrowserRouter>,
|
||
)
|