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,182 @@
|
||||
import { useEffect, useRef, useState } from "react";
|
||||
import { useTranslation } from "react-i18next";
|
||||
|
||||
import { Icon } from "@/components/icons";
|
||||
import { ConfirmDialog } from "@/components/shared/confirm-dialog";
|
||||
import { RelativeTime } from "@/components/shared/relative-time";
|
||||
import { Badge } from "@/components/ui/badge";
|
||||
import { Button } from "@/components/ui/button";
|
||||
import { KV, KVList } from "@/components/ui/kv";
|
||||
import { toast } from "@/components/ui/toast";
|
||||
import { drawQr } from "@/features/status/qr";
|
||||
import type { ServerIdentity } from "@/features/status/server";
|
||||
|
||||
import { ErrorBlock, LoadingBlock, StatusCard } from "./card-parts";
|
||||
|
||||
function scopeTone(scope: string): "default" | "info" | "ok" {
|
||||
if (scope === "read") return "default";
|
||||
if (scope === "steer") return "info";
|
||||
if (scope === "apply") return "ok";
|
||||
return "default";
|
||||
}
|
||||
|
||||
function CopyButton({ value, label }: { value: string; label: string }) {
|
||||
const { t } = useTranslation();
|
||||
|
||||
async function copy() {
|
||||
try {
|
||||
if (!navigator.clipboard?.writeText) throw new Error("clipboard unavailable");
|
||||
await navigator.clipboard.writeText(value);
|
||||
toast.success(t("common.copied", { label }));
|
||||
} catch {
|
||||
toast.error(t("common.copyFailed"));
|
||||
}
|
||||
}
|
||||
|
||||
return (
|
||||
<Button
|
||||
variant="ghost"
|
||||
size="icon"
|
||||
className="status-copy"
|
||||
title={t("common.copy", { label })}
|
||||
aria-label={t("common.copy", { label })}
|
||||
onClick={() => void copy()}
|
||||
>
|
||||
<Icon name="copy" />
|
||||
</Button>
|
||||
);
|
||||
}
|
||||
|
||||
function AddressBlock({ label, value }: { label: string; value: string }) {
|
||||
return (
|
||||
<div className="addr-block">
|
||||
<div className="addr-label muted">{label}</div>
|
||||
<div className="addr-row">
|
||||
<code className="mono truncate grow">{value}</code>
|
||||
<CopyButton value={value} label={label} />
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
function QrCanvas({ seed, label }: { seed: string; label: string }) {
|
||||
const ref = useRef<HTMLCanvasElement | null>(null);
|
||||
|
||||
useEffect(() => {
|
||||
const canvas = ref.current;
|
||||
if (!canvas) return;
|
||||
const draw = () => drawQr(canvas, seed);
|
||||
draw();
|
||||
|
||||
if (typeof MutationObserver === "undefined") return;
|
||||
const observer = new MutationObserver(draw);
|
||||
observer.observe(document.documentElement, { attributes: true, attributeFilter: ["data-theme"] });
|
||||
return () => observer.disconnect();
|
||||
}, [seed]);
|
||||
|
||||
return <canvas ref={ref} className="qr-canvas" role="img" aria-label={label} />;
|
||||
}
|
||||
|
||||
export interface ConnectionCardProps {
|
||||
server: ServerIdentity;
|
||||
deviceName: string;
|
||||
scopes: string[];
|
||||
connectedAt: number | null;
|
||||
loading: boolean;
|
||||
error: string | null;
|
||||
onRetry: () => void;
|
||||
onDisconnect: () => void;
|
||||
}
|
||||
|
||||
/** Card 7 — addresses, mDNS, pairing code/QR, scopes, last connection, actions. */
|
||||
export function ConnectionCard({
|
||||
server,
|
||||
deviceName,
|
||||
scopes,
|
||||
connectedAt,
|
||||
loading,
|
||||
error,
|
||||
onRetry,
|
||||
onDisconnect,
|
||||
}: ConnectionCardProps) {
|
||||
const { t } = useTranslation();
|
||||
const [confirmOpen, setConfirmOpen] = useState(false);
|
||||
const qrSeed = `${server.networkAddress}/#pair=${server.pairingCode}`;
|
||||
|
||||
return (
|
||||
<StatusCard title={t("status.connection")} icon="qr">
|
||||
{error ? (
|
||||
<ErrorBlock message={error} onRetry={onRetry} />
|
||||
) : loading ? (
|
||||
<LoadingBlock rows={6} />
|
||||
) : (
|
||||
<>
|
||||
<div className="connect-grid">
|
||||
<div className="connect-addr">
|
||||
<AddressBlock label={t("status.local")} value={server.localAddress} />
|
||||
<AddressBlock label={t("status.network")} value={server.networkAddress} />
|
||||
<KV label={t("status.mdns")} mono>
|
||||
{server.mdns}
|
||||
</KV>
|
||||
<KV label={t("connect.endpoint")} valueClassName="status-endpoint">
|
||||
<span className="mono truncate">{server.endpoint}</span>
|
||||
<CopyButton value={server.endpoint} label={t("connect.endpoint")} />
|
||||
</KV>
|
||||
<KV label={t("connect.device")}>{deviceName || "—"}</KV>
|
||||
<KV label={t("status.tokenScopes")} valueClassName="status-kv-val">
|
||||
{scopes.length ? (
|
||||
<span className="status-scopes">
|
||||
{scopes.map((scope) => (
|
||||
<Badge key={scope} tone={scopeTone(scope)}>
|
||||
{scope}
|
||||
</Badge>
|
||||
))}
|
||||
</span>
|
||||
) : (
|
||||
<span className="muted">—</span>
|
||||
)}
|
||||
</KV>
|
||||
<KV label={t("status.lastConnected")}>
|
||||
<RelativeTime ts={connectedAt} />
|
||||
</KV>
|
||||
</div>
|
||||
|
||||
<div className="qr-wrap">
|
||||
<QrCanvas seed={qrSeed} label={t("status.qrAria")} />
|
||||
<div className="pair-code">{server.pairingCode}</div>
|
||||
<div className="pair-hint muted">
|
||||
<Icon name="phone" />
|
||||
<span>{t("status.pairHint")}</span>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<KVList className="security-note">
|
||||
<div className="security-item">{t("status.securityLocal")}</div>
|
||||
<div className="security-item">{t("status.securityToken")}</div>
|
||||
</KVList>
|
||||
|
||||
<div className="status-conn-actions">
|
||||
<a className="btn btn--sm" href="/connect?next=%2Fstatus">
|
||||
<Icon name="refresh" />
|
||||
{t("connect.reconnect")}
|
||||
</a>
|
||||
<Button variant="danger" size="sm" onClick={() => setConfirmOpen(true)}>
|
||||
<Icon name="plug" />
|
||||
{t("connect.disconnect")}
|
||||
</Button>
|
||||
</div>
|
||||
</>
|
||||
)}
|
||||
|
||||
<ConfirmDialog
|
||||
open={confirmOpen}
|
||||
onOpenChange={setConfirmOpen}
|
||||
title={t("connect.disconnectTitle")}
|
||||
description={t("connect.disconnectText")}
|
||||
confirmLabel={t("connect.disconnect")}
|
||||
onConfirm={onDisconnect}
|
||||
/>
|
||||
</StatusCard>
|
||||
);
|
||||
}
|
||||
Reference in new issue
Block a user