import React, { useState } from "react"; import { render, Box, Text, useInput } from "ink"; import Overview from "./tabs/Overview.jsx"; import Combos from "./tabs/Combos.jsx"; import Providers from "./tabs/Providers.jsx"; import Keys from "./tabs/Keys.jsx"; import Logs from "./tabs/Logs.jsx"; import Health from "./tabs/Health.jsx"; import Cost from "./tabs/Cost.jsx"; const TABS = [ { id: "overview", label: "Overview", Component: Overview }, { id: "combos", label: "Combos", Component: Combos }, { id: "providers", label: "Providers", Component: Providers }, { id: "keys", label: "Keys", Component: Keys }, { id: "logs", label: "Logs", Component: Logs }, { id: "health", label: "Health", Component: Health }, { id: "cost", label: "Cost $", Component: Cost }, ]; function DashboardApp({ port, baseUrl, apiKey, onExit }) { const [active, setActive] = useState(0); useInput((input, key) => { if (input === "q" || (key.ctrl && input === "c")) onExit(); const n = parseInt(input, 10); if (n >= 1 && n <= TABS.length) setActive(n - 1); if (key.tab && !key.shift) setActive((a) => (a + 1) % TABS.length); if (key.tab && key.shift) setActive((a) => (a - 1 + TABS.length) % TABS.length); }); const ActiveComponent = TABS[active]?.Component; return ( OmniRoute | {TABS.map((tab, i) => ( [{i + 1}]{tab.label} ))} {ActiveComponent && } [q]uit [Tab] next [1-7] jump [r]efresh [/]filter ); } export async function startInteractiveTui({ port = 20128, baseUrl, apiKey } = {}) { const resolvedUrl = baseUrl ?? `http://localhost:${port}`; return new Promise((resolve) => { const { unmount, waitUntilExit } = render( unmount()} /> ); waitUntilExit().then(resolve).catch(resolve); }); }