mirror of
https://github.com/ThearchyHelios/AgentLab.git
synced 2026-11-24 01:51:59 +00:00
第三波收尾:跨模块整合、全站扫尾、检查脚本整合;网页工具认得本机代理的 fake-ip
整合(3c-integrate) - 公共层:跨天时长(formatSpan / formatOffset / formatLapse)、本机署名(lib/actor)、检索分类色令牌、 数据源目录(useDatasources)收进公共层;失败说明能一次列出多个写坏的自定义工具,查询超时指到数据源的查询时限 - 管理页收尾:设置页接入统一的离开前确认;检查脚本不再把沙箱里的真实值打进输出 - 画布 ↔ 右栏:点出具印章、点节点能跳到右栏对应位置;「定位」直接聚焦到出问题的字段 - 回答流 / 问数据 / 记录页:失败信息带「去哪修」且不再被翻译两遍;协作团队的结局按执行截取; 等审批时断流重连、而运行已在空档里跑完的,补全事件 扫尾(3c-sweep) - 术语统一:开始运行 / 继续运行、工作流最大步数;未保存的运行统一叫「未保存的工作流」(后端新运行同步) - 沙箱报错不再带 Python 异常类名;新增 check-tokens,未定义的 CSS 变量为 0,两个旧别名迁移后删除 检查脚本(3c-checks) - check-ui 跟上新界面(运行列表按 data 属性找行),加上令牌与选中态的回归断言,输出里的名字打码 - 新增 check-all:按顺序跑全部检查、汇总退出码,--repeat 列出偶发项 - 单节出错只记这一节失败、不再带崩整个脚本;外壳遥测浮层「重新检测」时焦点不再掉到 body 网页工具与 fake-ip - Clash / mihomo 一类代理开 TUN + fake-ip 时,查什么都先拿到 198.18 段的假地址,被当成内网拦截。 新增 AGENTLAB_HTTP_TOOL_FAKE_IP_RANGES(默认空):落在段里的解析结果改向公共 DNS(DoH)核实真实地址, 公网放行、内网照拦、核实不了按拦截处理。DoH 默认先问境外的,境内公共 DNS 会对被封锁的域名返回污染结果 - 列表型环境变量接受逗号分隔(原来注释说逗号分隔、实际只认 JSON 数组);域名解析改为异步,不再阻塞事件循环 验证(沙箱):tsc 干净,pytest 866 passed(两遍),检查脚本全绿。
This commit is contained in:
@@ -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 } from '../lib/terms'
|
||||
import { 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'
|
||||
@@ -51,7 +51,7 @@ export interface PageDef {
|
||||
// ⌥ + 数字切页:不和浏览器的 ⌘1–9(切标签页,页面拦不住)撞,也不和画布上的
|
||||
// Backspace / Delete 以及各处输入框打架——「g c」这类两键序列就是栽在这上面
|
||||
export const PAGES: PageDef[] = [
|
||||
{ to: '/chat', label: '问数据', hint: '说需求,自动接数据源、建流程、跑出结论', icon: MessageSquare, shortcut: 'Alt+1', keywords: 'chat ask 对话 提问 首页' },
|
||||
{ to: '/chat', label: '问数据', hint: '说需求,自动接数据源、搭工作流、跑出结论', icon: MessageSquare, shortcut: 'Alt+1', keywords: 'chat ask 对话 提问 首页' },
|
||||
{ to: '/studio', label: '编排', hint: '在画布上搭工作流、调试、发布', icon: FlaskConical, shortcut: 'Alt+2', keywords: 'studio canvas 画布 工作流 workflow' },
|
||||
{ to: '/runs', label: '记录', hint: '每次运行的过程、成果和待审批', icon: History, shortcut: 'Alt+3', keywords: 'runs history 运行 运行记录 历史 审批' },
|
||||
{ to: '/data', label: '数据', hint: '接入数据库和表格,问数据和工作流从这里取数', icon: Database, shortcut: 'Alt+4', keywords: 'data datasource 数据源 数据库 表格 excel csv' },
|
||||
@@ -247,6 +247,10 @@ function score(c: Command, tokens: string[]): number {
|
||||
return total
|
||||
}
|
||||
|
||||
/** 面板以外的模态框(离开前确认、各页的弹窗) */
|
||||
const OTHER_MODAL = '[aria-modal="true"]:not([data-command-palette])'
|
||||
const otherModal = () => !!document.querySelector(OTHER_MODAL)
|
||||
|
||||
export function CommandPalette() {
|
||||
const open = useShell((s) => s.palette)
|
||||
return open ? <PaletteView /> : null
|
||||
@@ -274,22 +278,34 @@ function PaletteView() {
|
||||
useEffect(() => {
|
||||
inputRef.current?.focus()
|
||||
return () => {
|
||||
// 焦点还给打开前的那个元素;选中的命令已经把焦点带去别处(跳了页、开了弹窗)就不抢
|
||||
// 焦点还给打开前的那个元素;选中的命令已经把焦点带去别处(跳了页、开了弹窗)就不抢。
|
||||
// 别的模态框开着时也不还:焦点该在它里面,还给 opener 就落到了它外面
|
||||
const now = document.activeElement
|
||||
if (otherModal()) return
|
||||
if (opener?.isConnected && (!now || now === document.body)) opener.focus({ preventScroll: true })
|
||||
}
|
||||
}, [opener])
|
||||
|
||||
// 开着时焦点只在面板里:刚跳过去的页面挂载时会自动聚焦(画布助手的输入框),
|
||||
// 焦点一被抢走,接着打的字和 Esc 就都落到了面板底下
|
||||
// 焦点一被抢走,接着打的字和 Esc 就都落到了面板底下。落进别的模态框(离开前确认)
|
||||
// 的不拉回:那是更要紧的问题,拉回来人就答不了它
|
||||
useEffect(() => {
|
||||
const onFocusIn = (e: FocusEvent) => {
|
||||
if (e.target instanceof Node && !panelRef.current?.contains(e.target)) inputRef.current?.focus({ preventScroll: true })
|
||||
if (!(e.target instanceof Element) || panelRef.current?.contains(e.target)) return
|
||||
if (e.target.closest(OTHER_MODAL)) return
|
||||
inputRef.current?.focus({ preventScroll: true })
|
||||
}
|
||||
document.addEventListener('focusin', onFocusIn)
|
||||
return () => document.removeEventListener('focusin', onFocusIn)
|
||||
}, [])
|
||||
|
||||
// 浏览器后退、前进(侧键、触控板手势、⌘[)时先收起面板:离开前确认的框要弹出来,
|
||||
// 面板压在它上面(z 更高)就看不见,焦点也被拉回搜索框,人只能对着面板按键
|
||||
useEffect(() => {
|
||||
window.addEventListener('popstate', closeCommandPalette)
|
||||
return () => window.removeEventListener('popstate', closeCommandPalette)
|
||||
}, [])
|
||||
|
||||
// 最近运行、最近会话是打开面板时才取:常驻轮询它们不值得
|
||||
useEffect(() => {
|
||||
if (backend === 'down') return
|
||||
@@ -314,7 +330,7 @@ function PaletteView() {
|
||||
list.push({
|
||||
id: `approval:${a.id}`, group: 'approvals', label: a.title || '待审批',
|
||||
// 同一个审批节点跑过几次,标题会一模一样:带上运行的短 id 才分得开
|
||||
hint: [a.workflow_name, a.node_label, shortId(a.run_id)].filter(Boolean).join(' · '),
|
||||
hint: [a.workflow_name && runName(a), a.node_label, shortId(a.run_id)].filter(Boolean).join(' · '),
|
||||
keywords: `审批 approval 待办 ${a.run_id}`,
|
||||
icon: <Hourglass size={14} />,
|
||||
meta: waited && <span title={formatDateTime(a.created_at)}>已等 {waited}</span>,
|
||||
@@ -388,7 +404,7 @@ function PaletteView() {
|
||||
for (const r of runs ?? []) {
|
||||
const pendingHere = r.status === 'interrupted' ? hasPendingApproval(approvals, r.id) : undefined
|
||||
list.push({
|
||||
id: `run:${r.id}`, group: 'runs', label: r.workflow_name || '未命名工作流',
|
||||
id: `run:${r.id}`, group: 'runs', label: runName(r) || '未命名工作流',
|
||||
hint: `${statusLabel(r.status, { pendingApproval: pendingHere })} · ${runClassLabel(r.run_class, r.version)} · ${shortId(r.id)}`,
|
||||
keywords: `run 运行 ${r.id}`,
|
||||
icon: <StatusBadge status={r.status} pendingApproval={pendingHere} size={14} animate={false} decorative />,
|
||||
|
||||
@@ -30,17 +30,21 @@ export function isComposing(e: ReactKeyboardEvent | KeyboardEvent): boolean {
|
||||
}
|
||||
|
||||
/**
|
||||
* 页面级错误边界。没有它,任何一个组件渲染时抛错,React 会卸掉整棵树——整站
|
||||
* 白屏,导航栏也没了,用户只能刷新,没保存的编辑跟着丢。
|
||||
* 错误边界。没有它,任何一个组件渲染时抛错,React 会卸掉整棵树——整站白屏,
|
||||
* 导航栏也没了,用户只能刷新,没保存的编辑跟着丢。
|
||||
*
|
||||
* 包在路由外面:导航栏还在,换一页(resetKey 变了)就自动恢复。编辑中的图在
|
||||
* store 里、不在组件树上,点「重试」重新渲染时它还在。
|
||||
* scope 说明兜的是哪一层:
|
||||
* - page(默认):App 里包在路由外面,出错只换掉内容区,导航还在,换一页(resetKey
|
||||
* 变了)就自动恢复;
|
||||
* - shell:main.tsx 里包着整个 App,这时导航也没了,文案不能再说「这一页」。
|
||||
* title 可以再覆盖标题。编辑中的图在 store 里、不在组件树上,点「重试」重新渲染时它还在。
|
||||
*
|
||||
* 技术信息(error.message)收进「技术细节」折叠区并能复制:对用户是噪音,对
|
||||
* 排障是全部线索。
|
||||
* 排障是全部线索。role=alert 只包标题和那句说明:按钮和技术细节也在里面的话,
|
||||
* 读屏会把「重试 刷新页面 技术细节…」连同堆栈摘要一起当成警报念出来。
|
||||
*/
|
||||
export class ErrorBoundary extends Component<
|
||||
{ resetKey?: string; children: ReactNode }, { error: Error | null }
|
||||
{ resetKey?: string; scope?: 'page' | 'shell'; title?: string; children: ReactNode }, { error: Error | null }
|
||||
> {
|
||||
state: { error: Error | null } = { error: null }
|
||||
|
||||
@@ -63,11 +67,17 @@ export class ErrorBoundary extends Component<
|
||||
const raw = error.stack?.includes(error.message)
|
||||
? error.stack
|
||||
: `${error.name}: ${error.message}${error.stack ? `\n\n${error.stack}` : ''}`
|
||||
const shell = this.props.scope === 'shell'
|
||||
return (
|
||||
<div className="flex h-full flex-col items-center justify-center gap-3 p-8 text-center">
|
||||
<div data-error-scope={shell ? 'shell' : 'page'}
|
||||
className={clsx('flex flex-col items-center justify-center gap-3 p-8 text-center', shell ? 'h-screen bg-[var(--bg)]' : 'h-full')}>
|
||||
<AlertCircle size={22} className="text-[var(--err)]" aria-hidden />
|
||||
<div className="text-sm font-medium">这一页出错了</div>
|
||||
<div className="text-[11.5px] text-dim">没保存的编辑还在内存里:先点「重试」,恢复了就尽快保存。</div>
|
||||
<div role="alert" className="flex flex-col items-center gap-3">
|
||||
<div className="text-sm font-medium">{this.props.title ?? (shell ? '界面出错了' : '这一页出错了')}</div>
|
||||
<div className="text-xs text-dim">
|
||||
{shell ? '导航和页面都停了。' : ''}没保存的编辑还在内存里:先点「重试」,恢复了就尽快保存。
|
||||
</div>
|
||||
</div>
|
||||
<div className="flex gap-2">
|
||||
<button className="btn btn-sm" onClick={() => this.setState({ error: null })}>重试</button>
|
||||
<button className="btn btn-sm btn-ghost" onClick={() => location.reload()}>刷新页面</button>
|
||||
@@ -81,12 +91,12 @@ export class ErrorBoundary extends Component<
|
||||
/** 「技术细节」折叠区:原文给运维复制用,默认收起 */
|
||||
export function TechDetails({ raw, summary, className }: { raw: string; summary?: string; className?: string }) {
|
||||
return (
|
||||
<details className={clsx('w-full text-left text-[11px] text-faint', className)}>
|
||||
<details className={clsx('w-full text-left text-2xs text-faint', className)}>
|
||||
<summary className="cursor-pointer select-none hover:text-dim">
|
||||
技术细节{summary ? <span className="ml-1.5 opacity-80">· {summary.length > 60 ? `${summary.slice(0, 60)}…` : summary}</span> : null}
|
||||
</summary>
|
||||
<div className="mt-1.5 flex items-start gap-1.5">
|
||||
<pre className="mono max-h-40 min-w-0 flex-1 overflow-auto whitespace-pre-wrap break-all rounded-md border bg-[var(--bg)] p-2 text-[11px] leading-relaxed text-dim">
|
||||
<pre className="mono max-h-40 min-w-0 flex-1 overflow-auto whitespace-pre-wrap break-all rounded-md border bg-[var(--bg)] p-2 text-2xs leading-relaxed text-dim">
|
||||
{raw}
|
||||
</pre>
|
||||
<CopyButton text={raw} />
|
||||
@@ -242,7 +252,7 @@ export function ToastHost({ children }: { children?: ReactNode }) {
|
||||
<div className="flex w-full max-w-md flex-col gap-2">
|
||||
{hidden > 0 && (
|
||||
<button
|
||||
className="pointer-events-auto self-center rounded-full border bg-panel px-3 py-1 text-[11px] text-dim shadow-md hover:text-fg"
|
||||
className="pointer-events-auto self-center rounded-full border bg-panel px-3 py-1 text-2xs text-dim shadow-md hover:text-fg"
|
||||
onClick={() => setExpanded(true)}
|
||||
>
|
||||
还有 {hidden} 条 · 展开
|
||||
@@ -257,7 +267,7 @@ export function ToastHost({ children }: { children?: ReactNode }) {
|
||||
</div>
|
||||
{expanded && items.length > TOAST_VISIBLE && (
|
||||
<button
|
||||
className="pointer-events-auto self-center text-[11px] text-faint hover:text-dim"
|
||||
className="pointer-events-auto self-center text-2xs text-faint hover:text-dim"
|
||||
onClick={() => { dismissToast(); setExpanded(false) }}
|
||||
>
|
||||
全部关闭
|
||||
@@ -312,9 +322,9 @@ function ToastCard({ item }: { item: ToastItem }) {
|
||||
{item.count > 1 && <span className="ml-1.5 tabular-nums text-faint">×{item.count}</span>}
|
||||
</div>
|
||||
{item.detail && (
|
||||
<details className="mt-1 text-[11px] text-faint">
|
||||
<details className="mt-1 text-2xs text-faint">
|
||||
<summary className="cursor-pointer select-none hover:text-dim">详情</summary>
|
||||
<pre className="mono mt-1 max-h-32 overflow-auto whitespace-pre-wrap break-all text-[11px] leading-relaxed">
|
||||
<pre className="mono mt-1 max-h-32 overflow-auto whitespace-pre-wrap break-all text-2xs leading-relaxed">
|
||||
{item.detail}
|
||||
</pre>
|
||||
</details>
|
||||
@@ -732,7 +742,7 @@ function DialogView({ req }: { req: DialogRequest }) {
|
||||
>
|
||||
<div className="flex flex-col gap-3">
|
||||
{(opts.body || opts.consequences?.length) && (
|
||||
<div id={bodyId} className="flex flex-col gap-2 text-[13px] leading-relaxed text-dim">
|
||||
<div id={bodyId} className="flex flex-col gap-2 text-sm leading-relaxed text-dim">
|
||||
{opts.body && <div>{opts.body}</div>}
|
||||
{!!opts.consequences?.length && (
|
||||
<ul className="flex flex-col gap-1">
|
||||
@@ -978,7 +988,7 @@ export function OfflineBanner({ className }: { className?: string }) {
|
||||
<div
|
||||
ref={ref}
|
||||
data-offline-banner=""
|
||||
className={clsx('flex min-h-7 flex-wrap items-center gap-x-2 gap-y-0.5 border-b px-3 py-1 text-[11.5px]', className)}
|
||||
className={clsx('flex min-h-7 flex-wrap items-center gap-x-2 gap-y-0.5 border-b px-3 py-1 text-xs', className)}
|
||||
style={{
|
||||
color: 'var(--err)',
|
||||
borderColor: 'color-mix(in srgb, var(--err) 30%, var(--border))',
|
||||
@@ -1200,7 +1210,7 @@ export function Section({ title, right, children, defaultOpen = true }: {
|
||||
<button
|
||||
onClick={() => setOpen(!open)}
|
||||
aria-expanded={open}
|
||||
className="flex items-center gap-1.5 text-[11px] font-semibold uppercase tracking-wide text-faint hover:text-dim"
|
||||
className="flex items-center gap-1.5 text-2xs font-semibold uppercase tracking-wide text-faint hover:text-dim"
|
||||
>
|
||||
<span className={clsx('transition-transform', open ? 'rotate-90' : '')} aria-hidden>›</span>
|
||||
{title}
|
||||
@@ -1355,7 +1365,7 @@ export function StatusPill({ status, pendingApproval, short = false, plain = fal
|
||||
return (
|
||||
<span
|
||||
className={clsx(
|
||||
'inline-flex shrink-0 items-center gap-1 whitespace-nowrap text-[11px] leading-4',
|
||||
'inline-flex shrink-0 items-center gap-1 whitespace-nowrap text-2xs leading-4',
|
||||
!plain && 'rounded-full px-1.5 py-px',
|
||||
className,
|
||||
)}
|
||||
@@ -1464,21 +1474,29 @@ export function Field({ label, htmlFor, hint, error, required, children, classNa
|
||||
? children({ id, 'aria-describedby': describedBy, 'aria-invalid': error ? true : undefined })
|
||||
: children}
|
||||
{error
|
||||
? <div id={errorId} className="mt-1 text-[11px] leading-relaxed text-[var(--err)]">{error}</div>
|
||||
? <div id={errorId} className="mt-1 text-2xs leading-relaxed text-[var(--err)]">{error}</div>
|
||||
: hint
|
||||
? <div id={hintId} className="mt-1 text-[11px] leading-relaxed text-faint">{hint}</div>
|
||||
? <div id={hintId} className="mt-1 text-2xs leading-relaxed text-faint">{hint}</div>
|
||||
: null}
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
/** 受控的 JSON 编辑框:输入过程中允许非法 JSON,失焦或合法时才回写。 */
|
||||
export function JsonInput({ value, onChange, rows = 5, placeholder, id }: {
|
||||
/**
|
||||
* 受控的 JSON 编辑框:输入过程中允许非法 JSON,失焦或合法时才回写。
|
||||
*
|
||||
* aria-describedby / aria-invalid 照 Field 的 render-prop 原样传进来:外面(比如后端
|
||||
* 422)说这一项有错时,框要标成出错、描红,读屏聚焦到框上就念出那句原因
|
||||
*/
|
||||
export function JsonInput({ value, onChange, rows = 5, placeholder, id, 'aria-describedby': describedBy, 'aria-invalid': invalid }: {
|
||||
value: any; onChange: (v: any) => void; rows?: number; placeholder?: string; id?: string
|
||||
'aria-describedby'?: string; 'aria-invalid'?: boolean
|
||||
}) {
|
||||
const [text, setText] = useState(() => (value == null ? '' : JSON.stringify(value, null, 2)))
|
||||
const [bad, setBad] = useState(false)
|
||||
const touched = useRef(false)
|
||||
const autoId = useId()
|
||||
const badId = `${id ?? `json${autoId.replace(/[^a-zA-Z0-9_-]/g, '')}`}-json`
|
||||
|
||||
useEffect(() => {
|
||||
if (touched.current) return
|
||||
@@ -1489,12 +1507,13 @@ export function JsonInput({ value, onChange, rows = 5, placeholder, id }: {
|
||||
<div>
|
||||
<textarea
|
||||
id={id}
|
||||
className="field mono text-[11px]"
|
||||
className="field mono text-2xs"
|
||||
rows={rows}
|
||||
value={text}
|
||||
placeholder={placeholder}
|
||||
aria-invalid={bad || undefined}
|
||||
style={bad ? { borderColor: 'var(--err)' } : undefined}
|
||||
aria-invalid={bad || invalid || undefined}
|
||||
aria-describedby={[bad ? badId : null, describedBy].filter(Boolean).join(' ') || undefined}
|
||||
style={bad || invalid ? { borderColor: 'var(--err)' } : undefined}
|
||||
onChange={(e) => {
|
||||
touched.current = true
|
||||
setText(e.target.value)
|
||||
@@ -1508,7 +1527,7 @@ export function JsonInput({ value, onChange, rows = 5, placeholder, id }: {
|
||||
}}
|
||||
onBlur={() => { touched.current = false }}
|
||||
/>
|
||||
{bad && <div className="mt-1 text-[11px] text-[var(--err)]">JSON 格式不对,还没保存</div>}
|
||||
{bad && <div id={badId} className="mt-1 text-2xs text-[var(--err)]">JSON 格式不对,还没保存</div>}
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user