"use client"; // Start a team run: objective + the few playbook knobs the hub actually honours. import { useRouter } from "next/navigation"; import { useState } from "react"; import { ErrorNote, Field, Input, Modal, PixelButton, Select, Textarea } from "./ui"; import { api } from "@/lib/api"; import { useAsync } from "@/lib/useAsync"; export function RunModal({ team, defaultPlaybook = "", onClose, }: { team: string; defaultPlaybook?: string; onClose: () => void; }) { const router = useRouter(); const playbooks = useAsync(() => api.playbooks(), []); const [objective, setObjective] = useState(""); const [playbook, setPlaybook] = useState(""); const [rounds, setRounds] = useState("2"); const [hops, setHops] = useState("6"); const [busy, setBusy] = useState(false); const [error, setError] = useState(""); const chosen = playbook || defaultPlaybook; const submit = async () => { if (!objective.trim()) return; setBusy(true); setError(""); try { const spec: Record = {}; if (playbook) spec.playbook = playbook; if (chosen === "round_robin") spec.rounds = Number(rounds) || 1; if (chosen === "handoff") spec.max_hops = Number(hops) || 1; const run = await api.runTeam(team, objective.trim(), spec); router.push("/runs/" + run.id); onClose(); } catch (exc) { setError(exc instanceof Error ? exc.message : String(exc)); setBusy(false); } }; return ( 取消 {busy ? "启动中" : "开始 Run"} } >