import type { ServerConfig } from "@t3tools/contracts"; import { CONFIG_CHOICES, type T3tuiConfig } from "../config.ts"; import { RUNTIME_MODE_LABELS } from "./details.ts"; export interface SettingRow { readonly key: keyof T3tuiConfig; readonly label: string; readonly value: string; readonly help: string; } const LABELS: { readonly [K in keyof T3tuiConfig]: { readonly label: string; readonly help: string; readonly values?: Partial> } } = { followUpBehavior: { label: "While the agent runs, enter", help: "alt+enter does the other", values: { steer: "steers", queue: "queues" } }, sendShortcut: { label: "Send with", help: "ctrl+enter needs kitty keyboard support; alt+enter also sends", values: { enter: "enter", "ctrl-enter": "ctrl+enter (enter adds a line)" } }, timestampFormat: { label: "Times", help: "automation schedules", values: { locale: "system locale", "12-hour": "12-hour", "24-hour": "24-hour" } }, diffIgnoreWhitespace: { label: "Diffs", help: "whitespace-only changes", values: { true: "ignore whitespace", false: "show whitespace" } }, notificationMode: { label: "Alerts", help: "when a thread needs you or finishes; notifications only while the terminal is unfocused", values: { off: "off", sound: "bell", notifications: "desktop notifications", "notifications-and-sound": "bell and desktop notifications" }, }, inAppNotificationsEnabled: { label: "In-app alerts", help: "a line at the bottom for other threads", values: { true: "on", false: "off" } }, theme: { label: "Colours", help: "from the next start", values: { auto: "dark or light, as the terminal is", dark: "dark", light: "light", terminal: "the terminal's own colours" } }, }; /** t3tui's own settings, in display order, each cycled with enter. */ export function settingRows(config: T3tuiConfig): SettingRow[] { return (Object.keys(CONFIG_CHOICES) as (keyof T3tuiConfig)[]).map((key) => { const meta = LABELS[key]; const raw = String(config[key]); return { key, label: meta.label, value: meta.values?.[raw] ?? raw, help: meta.help }; }); } /** The server settings worth knowing from the terminal, read-only: they're changed in the app. */ export function serverSettingLines(config: ServerConfig | null): { label: string; value: string }[] { if (!config) return []; const settings = config.settings; return [ { label: "Server", value: `${config.environment.label} ยท T3 Code ${config.environment.serverVersion}` }, { label: "New thread model", value: settings.defaultModelSelection ? settings.defaultModelSelection.model : "provider default" }, { label: "New thread mode", value: RUNTIME_MODE_LABELS[settings.defaultRuntimeMode] ?? settings.defaultRuntimeMode }, { label: "New threads run in", value: settings.defaultThreadEnvMode ?? "project default" }, { label: "Auto-settle", value: settings.sidebarAutoSettleAfterDays ? `after ${settings.sidebarAutoSettleAfterDays} days idle` : "off" }, { label: "Rate-limited threads", value: [settings.snoozeLimitedThreads ? "snooze" : "", settings.autoResumeLimitedThreads ? "resume when reset" : ""].filter(Boolean).join(", ") || "left as they are" }, ]; }