import type { Letta } from "@letta-ai/letta-client"; import { Box, Text } from "ink"; import Link from "ink-link"; import { getVersion } from "../../version"; import { useTerminalWidth } from "../hooks/useTerminalWidth"; import { asciiLogo } from "./AsciiArt"; import { colors } from "./colors"; type LoadingState = | "assembling" | "upserting" | "linking" | "unlinking" | "initializing" | "checking" | "ready"; export function WelcomeScreen({ loadingState, continueSession, agentState, terminalWidth: frozenWidth, }: { loadingState: LoadingState; continueSession?: boolean; agentState?: Letta.AgentState | null; terminalWidth?: number; }) { const currentWidth = useTerminalWidth(); const terminalWidth = frozenWidth ?? currentWidth; const cwd = process.cwd(); const version = getVersion(); const agentId = agentState?.id; // Split logo into lines for side-by-side rendering const logoLines = asciiLogo.trim().split("\n"); // Determine verbosity level based on terminal width const isWide = terminalWidth >= 120; const isMedium = terminalWidth >= 80; const getMemoryBlocksText = () => { if (!agentState?.memory?.blocks) { return null; } const blocks = agentState.memory.blocks; const count = blocks.length; const labels = blocks .map((b) => b.label) .filter(Boolean) .join(", "); if (isWide && labels) { return `attached ${count} memory block${count !== 1 ? "s" : ""} (${labels})`; } if (isMedium) { return `attached ${count} memory block${count !== 1 ? "s" : ""}`; } return null; }; const getAgentMessage = () => { if (loadingState === "ready") { const memoryText = getMemoryBlocksText(); const baseText = continueSession && agentId ? "Resumed agent" : agentId ? "Created a new agent" : "Ready to go!"; if (memoryText) { return `${baseText}, ${memoryText}`; } return baseText; } if (loadingState === "initializing") { return continueSession ? "Resuming agent..." : "Creating agent..."; } if (loadingState === "assembling") { return "Assembling tools..."; } if (loadingState === "upserting") { return "Upserting tools..."; } if (loadingState === "linking") { return "Attaching Letta Code tools..."; } if (loadingState === "unlinking") { return "Removing Letta Code tools..."; } if (loadingState === "checking") { return "Checking for pending approvals..."; } return ""; }; const getPathLine = () => { if (isMedium) { return `Running in ${cwd}`; } return cwd; }; const getAgentLink = () => { if (loadingState === "ready" && agentId) { const url = `https://app.letta.com/agents/${agentId}`; if (isWide) { return { text: url, url }; } if (isMedium) { return { text: agentId, url }; } return { text: "Click to view in ADE", url }; } return null; }; const agentMessage = getAgentMessage(); const pathLine = getPathLine(); const agentLink = getAgentLink(); return ( {/* Left column: Logo */} {logoLines.map((line, idx) => ( // biome-ignore lint/suspicious/noArrayIndexKey: Logo lines are static and never reorder {idx === 0 ? ` ${line}` : line} ))} {/* Right column: Text info */} Letta Code v{version} {pathLine} {agentMessage && {agentMessage}} {agentLink && ( {agentLink.text} )} ); }