import { useId, useState } from "react"; import { Button, Dialog, DialogContent, DialogDescription, DialogFooter, DialogHeader, DialogTitle, Empty, EmptyContent, EmptyDescription, EmptyHeader, EmptyTitle, Input, } from "@ace/ui"; import { desktop } from "./desktop"; type Props = { onCreate: (project: string) => Promise; disabled?: boolean; dialog?: boolean; open?: boolean; onOpenChange?: (open: boolean) => void; onSettings?: () => void; }; const DESCRIPTION = "Channels run on this machine. Agents work in lanes: worktrees of the project's Git repository."; /** Starts a channel in a project folder, as the empty state or as a dialog. */ export function NewChannel({ onCreate, disabled, dialog, open, onOpenChange, onSettings }: Props) { const id = useId(); const [path, setPath] = useState(""); const [pending, setPending] = useState<"folder" | "channel">(); const [error, setError] = useState(""); async function choose() { if (!desktop) return; setPending("folder"); setError(""); try { const selected = await desktop.project(); if (selected) setPath(selected); } catch (error) { setError((error as Error).message); } finally { setPending(undefined); } } async function create() { if (!path.trim() || disabled || pending) return; setPending("channel"); setError(""); try { await onCreate(path.trim()); onOpenChange?.(false); } catch (error) { setError((error as Error).message); } finally { setPending(undefined); } } const form = (
{ event.preventDefault(); void create(); }} >
setPath(event.target.value)} /> {desktop && ( )}
{error &&

{error}

} {!dialog && ( )}
); if (!dialog) { return ( Start a channel {DESCRIPTION} {form} {onSettings && } ); } return ( Add a project {DESCRIPTION} {form} {onSettings && } ); }