import { useEffect, useState } from "react"; import { whichAgents } from "./socketBridge"; import { KNOWN_AGENTS, SHELL, CUSTOM, agentLabel, specForChoice } from "./agents"; type SlotSpec = { command?: string; args?: string[] }; /** * Asks what to open in each new panel before a preset spawns it: Terminal * (shell), one of the installed CLIs (claude/codex/gemini/deepseek), or a * custom command. `count` is the number of new panels the preset will add. */ export function SurfacePicker({ count, onConfirm, onCancel }: { count: number; onConfirm: (specs: SlotSpec[]) => void; onCancel: () => void }) { const [installed, setInstalled] = useState([]); const [choices, setChoices] = useState([]); const [customCmds, setCustomCmds] = useState([]); const choiceList = [SHELL, ...installed, CUSTOM]; useEffect(() => { void whichAgents(KNOWN_AGENTS).then(setInstalled).catch(() => {}); }, []); function confirm() { const specs = Array.from({ length: count }, (_, i) => specForChoice(choices[i] ?? SHELL, customCmds[i] ?? "")); onConfirm(specs); } function onKeyDown(e: React.KeyboardEvent) { e.stopPropagation(); if (e.key === "Escape") { e.preventDefault(); onCancel(); } else if (e.key === "Enter" && (e.target as HTMLElement).tagName !== "SELECT") { e.preventDefault(); confirm(); } } return (
e.stopPropagation()} onKeyDown={onKeyDown} style={{ width: 420, background: "#0E1116", border: "1px solid #323C49", borderRadius: 14, padding: 24, color: "#E6EDF3" }} >
{count > 1 ? `Open ${count} new panels` : "Open new panel"}
Choose what to run in each new panel.
1 ? "1fr 1fr" : "1fr", gap: 8, marginBottom: 20 }}> {Array.from({ length: count }, (_, i) => { const val = choices[i] ?? SHELL; return (
{val === CUSTOM && ( setCustomCmds((c) => { const n = [...c]; n[i] = e.target.value; return n; })} style={{ padding: 8, background: "#0A0D12", color: "#E6EDF3", border: "1px solid #4C8DFF", borderRadius: 6, fontFamily: "monospace", fontSize: 12 }} /> )}
); })}
); }