// The claude login dialog's steps, kept out of the component so `npm test` // runs them. The routes are swarm-controller's `claude_login` module. import type { ProblemDetails } from "@hive/shared/api-error.js"; export type LoginStep = | { step: "starting" } | { step: "code"; url: string } | { step: "submitting"; url: string } | { step: "stored" } | { step: "failed"; problem: ProblemDetails }; export function claudeLoginPath(agent: string, code = false): string { return `/api/agents/${encodeURIComponent(agent)}/claude-login${code ? "/code" : ""}`; } // The step after the start answered: its URL, or why there is none. export function afterStart( answer: { url: string } | { problem: ProblemDetails }, ): LoginStep { return "url" in answer ? { step: "code", url: answer.url } : { step: "failed", problem: answer.problem }; } // The step after the code was posted. The minter ends the login on a // refused code, so the next attempt is a fresh start. export function afterCode(problem: ProblemDetails | null): LoginStep { return problem === null ? { step: "stored" } : { step: "failed", problem }; } // Whether closing the dialog leaves a login running that should be // stopped. export function leavesLoginRunning(s: LoginStep): boolean { return s.step === "code"; } // What the code form may submit: the pasted code without surrounding // whitespace, or nothing. export function pastedCode(raw: string): string | null { const code = raw.trim(); return code === "" ? null : code; }