feat(web): workspaces, connect and status pages plus the full chat experience
- workspaces list + new-workspace flow (add -> ensure -> navigate), server context bar - connect: manual/pair-code redeem, QR scan with paste fallback, paired summary, disconnect - status: info/health/resources/models/devices/connection cards with 3s visible-only polling - chat: 3/2/1-column layout, session tree, virtualized stream, tool/thinking/todo/batch blocks, composer with queue chips and abort, subagents/todo/tasks panel, attention + diff review modals, history pagination merged with live entries - canonical reducer reused via @protocol alias (no duplicated types) - 63 vitest tests, typecheck + build green, zh/en parity at 411 keys
This commit is contained in:
1 parent
2e5d6d5006
commit
721661177c
61 files changed
+10931
-355
No files matched your search
@@ -0,0 +1,162 @@
|
||||
import type { InfoResponse } from "@/lib/api";
|
||||
import type { WsConnectionState } from "@/lib/ws";
|
||||
|
||||
/**
|
||||
* Optional identity fields the daemon may expose beyond the minimal /info
|
||||
* contract. The status page degrades to `—` when they are missing: the wire
|
||||
* contract only guarantees `{v,daemonId,machineId,platform,capabilities,limits}`.
|
||||
*/
|
||||
export interface InfoExtras extends InfoResponse {
|
||||
os?: string;
|
||||
kernel?: string;
|
||||
uptimeSec?: number;
|
||||
lastHeartbeat?: number;
|
||||
mdns?: string;
|
||||
cpu?: number;
|
||||
mem?: number;
|
||||
disk?: number;
|
||||
addresses?: { local?: string; network?: string };
|
||||
pairing?: { code?: string; expiresIn?: number };
|
||||
pairingCode?: string;
|
||||
}
|
||||
|
||||
export interface ServerIdentity {
|
||||
name: string;
|
||||
hostname: string;
|
||||
port: number | null;
|
||||
endpoint: string;
|
||||
bindAddress: string;
|
||||
os: string;
|
||||
piVersion: string;
|
||||
pluginVersion: string;
|
||||
kernel: string;
|
||||
uptimeSec: number | null;
|
||||
status: "online" | "degraded" | "offline";
|
||||
wsConnected: boolean;
|
||||
wsProto: string;
|
||||
lastHeartbeatAt: number | null;
|
||||
localAddress: string;
|
||||
networkAddress: string;
|
||||
mdns: string;
|
||||
pairingCode: string;
|
||||
cpu: number | null;
|
||||
mem: number | null;
|
||||
disk: number | null;
|
||||
}
|
||||
|
||||
function parseUrl(value: string | null | undefined): URL | null {
|
||||
if (!value) return null;
|
||||
try {
|
||||
return new URL(value);
|
||||
} catch {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
function browserLocation(): { hostname: string; port: string; protocol: string; origin: string } {
|
||||
if (typeof window === "undefined") {
|
||||
return { hostname: "localhost", port: "", protocol: "http:", origin: "http://localhost" };
|
||||
}
|
||||
return {
|
||||
hostname: window.location.hostname || "localhost",
|
||||
port: window.location.port,
|
||||
protocol: window.location.protocol,
|
||||
origin: window.location.origin,
|
||||
};
|
||||
}
|
||||
|
||||
export interface DeriveServerInput {
|
||||
info?: InfoExtras | null;
|
||||
endpoint?: string | null;
|
||||
wsState?: WsConnectionState;
|
||||
fetchedAt?: number | null;
|
||||
nameFallback?: string | null;
|
||||
status?: "online" | "degraded" | "offline" | null;
|
||||
}
|
||||
|
||||
/** Resolve the single server's identity from /info + the locally stored endpoint. */
|
||||
export function deriveServerIdentity({
|
||||
info,
|
||||
endpoint,
|
||||
wsState,
|
||||
fetchedAt,
|
||||
nameFallback,
|
||||
status,
|
||||
}: DeriveServerInput): ServerIdentity {
|
||||
const extras: InfoExtras = info ?? {};
|
||||
const browser = browserLocation();
|
||||
const url = parseUrl(endpoint) ?? parseUrl(browser.origin);
|
||||
const protocol = url?.protocol ?? browser.protocol;
|
||||
const portText = extras.port != null ? String(extras.port) : url?.port || browser.port;
|
||||
const port = portText ? Number(portText) : protocol === "https:" ? 443 : 80;
|
||||
const hostname = extras.hostname?.trim() || url?.hostname || browser.hostname;
|
||||
const name = extras.name?.trim() || nameFallback?.trim() || hostname;
|
||||
const endpointOrigin = extras.host
|
||||
? `${protocol}//${extras.host}:${port}`
|
||||
: url?.origin ?? browser.origin;
|
||||
const localAddress = extras.addresses?.local || `http://127.0.0.1:${port}`;
|
||||
const networkAddress = extras.addresses?.network || endpointOrigin;
|
||||
const resolvedStatus = status ?? extras.status ?? (info ? "online" : "offline");
|
||||
|
||||
return {
|
||||
name,
|
||||
hostname,
|
||||
port,
|
||||
endpoint: endpointOrigin,
|
||||
bindAddress: extras.host?.trim() || hostname,
|
||||
os: extras.os || extras.platform || "—",
|
||||
piVersion: extras.version || "—",
|
||||
pluginVersion: extras.pluginVersion || "—",
|
||||
kernel: extras.kernel || "—",
|
||||
uptimeSec: typeof extras.uptimeSec === "number" ? extras.uptimeSec : null,
|
||||
status: resolvedStatus,
|
||||
wsConnected: wsState === "open",
|
||||
wsProto: info?.v ? `v${info.v}` : "v1",
|
||||
lastHeartbeatAt: extras.lastHeartbeat ?? fetchedAt ?? null,
|
||||
localAddress,
|
||||
networkAddress,
|
||||
mdns: extras.mdns || `${hostname}.local`,
|
||||
pairingCode: extras.pairingCode || extras.pairing?.code || "—",
|
||||
cpu: typeof extras.cpu === "number" ? extras.cpu : null,
|
||||
mem: typeof extras.mem === "number" ? extras.mem : null,
|
||||
disk: typeof extras.disk === "number" ? extras.disk : null,
|
||||
};
|
||||
}
|
||||
|
||||
export function formatUptime(seconds: number | null | undefined): string {
|
||||
if (seconds == null || !Number.isFinite(seconds) || seconds < 0) return "—";
|
||||
const days = Math.floor(seconds / 86_400);
|
||||
const hours = Math.floor((seconds % 86_400) / 3_600);
|
||||
const minutes = Math.floor((seconds % 3_600) / 60);
|
||||
if (days > 0) return `${days}d ${hours}h ${minutes}m`;
|
||||
return `${hours}h ${minutes}m`;
|
||||
}
|
||||
|
||||
export function formatBytes(bytes: number | null | undefined): string {
|
||||
if (bytes == null || !Number.isFinite(bytes) || bytes < 0) return "—";
|
||||
const units = ["B", "KiB", "MiB", "GiB", "TiB"];
|
||||
let value = bytes;
|
||||
let unit = 0;
|
||||
while (value >= 1024 && unit < units.length - 1) {
|
||||
value /= 1024;
|
||||
unit += 1;
|
||||
}
|
||||
const digits = value >= 100 || unit === 0 ? 0 : value >= 10 ? 1 : 2;
|
||||
return `${value.toFixed(digits)} ${units[unit]}`;
|
||||
}
|
||||
|
||||
export function formatContextWindow(tokens: number): string {
|
||||
if (!Number.isFinite(tokens) || tokens <= 0) return "—";
|
||||
if (tokens >= 1_000_000) return `${Math.round(tokens / 100_000) / 10}M`;
|
||||
return `${Math.round(tokens / 1000)}k`;
|
||||
}
|
||||
|
||||
export function formatDuration(ms: number | null | undefined): string {
|
||||
if (ms == null || !Number.isFinite(ms) || ms < 0) return "—";
|
||||
if (ms < 1000) return `${Math.round(ms)}ms`;
|
||||
const seconds = ms / 1000;
|
||||
if (seconds < 60) return `${seconds.toFixed(seconds >= 10 ? 0 : 1)}s`;
|
||||
const minutes = Math.floor(seconds / 60);
|
||||
const rest = Math.round(seconds % 60);
|
||||
return `${minutes}m ${rest}s`;
|
||||
}
|
||||
Reference in new issue
Block a user