import { useEffect, useMemo, useState } from 'react' import { Ban, Check, ChevronRight, Hand, Play, ShieldCheck, Square, Wrench, } from 'lucide-react' import { api } from '../api/client' import { useStudio } from '../store/studio' import { useCatalog } from '../store/catalog' import { NODE_DEFS } from '../canvas/nodeDefs' import { StatusDot, useToast } from '../components/ui' /** * 发起运行。 * * 这是整个界面里**唯一**能发起运行的地方,不能因为改版就顺手删掉——一起没掉的 * 还有审批入口,那会让卡在人工介入上的运行在界面里彻底没有出口。 * * 跑起来之后自动收起:这时候用户要看的是执行到哪了,不是再填一遍输入。 */ export function RunLauncher() { const nodes = useStudio((s) => s.nodes) const run = useStudio((s) => s.run) const streaming = useStudio((s) => s.streaming) const issues = useStudio((s) => s.issues) const workflow = useStudio((s) => s.workflow) const dirty = useStudio((s) => s.dirty) const { startRun, startFormalRun, stopRun } = useStudio() const canFormal = !!workflow && (workflow.status === 'published' || workflow.status === 'governed') && !!workflow.published_version const toast = useToast() const [values, setValues] = useState>({}) const [busy, setBusy] = useState(false) const [open, setOpen] = useState(true) // 入口节点声明了什么字段,这里就渲染什么表单 const inputFields = useMemo(() => { const entry = nodes.find((n) => n.data.nodeType === 'input') return (entry?.data.config?.fields ?? []) as any[] }, [nodes]) // 跑起来就让位给执行过程;停下来再自己展开 useEffect(() => { if (streaming) setOpen(false) }, [streaming]) const errors = issues.filter((i) => i.level === 'error') const launch = async (formal = false) => { setBusy(true) try { const payload: Record = {} for (const field of inputFields) { if (!field.name) continue const raw = values[field.name] ?? field.default ?? '' // 看起来像 JSON 就按 JSON 传,让数组/对象类型的输入能用 if (typeof raw === 'string' && /^\s*[[{]/.test(raw)) { try { payload[field.name] = JSON.parse(raw) } catch { payload[field.name] = raw } } else { payload[field.name] = raw } } if (formal) await startFormalRun(payload) else await startRun(payload) } catch (e: any) { toast(e.message ?? '启动失败', 'error') } finally { setBusy(false) } } const running = streaming || run?.status === 'running' return (
{!!inputFields.length && ( )} {open && inputFields.map((field) => (