import { Box, Text, useInput } from "ink"; import { useState } from "react"; import { DEFAULT_AGENT_NAME } from "../../constants"; import { colors } from "./colors"; import { PasteAwareTextInput } from "./PasteAwareTextInput"; import { validateAgentName } from "./PinDialog"; interface NewAgentDialogProps { onSubmit: (name: string) => void; onCancel: () => void; } export function NewAgentDialog({ onSubmit, onCancel }: NewAgentDialogProps) { const [nameInput, setNameInput] = useState(""); const [error, setError] = useState(""); useInput((input, key) => { // CTRL-C: immediately cancel if (key.ctrl && input === "c") { onCancel(); return; } if (key.escape) { onCancel(); } }); const handleNameSubmit = (text: string) => { const trimmed = text.trim(); // Empty input = use default name if (!trimmed) { onSubmit(DEFAULT_AGENT_NAME); return; } const validationError = validateAgentName(trimmed); if (validationError) { setError(validationError); return; } onSubmit(trimmed); }; return ( Create new agent Enter a name for your new agent, or press Enter for default. Agent name: > { setNameInput(val); setError(""); }} onSubmit={handleNameSubmit} placeholder={DEFAULT_AGENT_NAME} /> {error && ( {error} )} Press Enter to create • Esc to cancel ); }