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,66 @@
|
||||
import { api } from "@/lib/api";
|
||||
import type { WorkspaceInfo } from "@/lib/protocol";
|
||||
|
||||
interface CommandResult {
|
||||
accepted?: boolean;
|
||||
disposition?: string;
|
||||
workspaceId?: string;
|
||||
workspace?: { workspaceId?: string };
|
||||
result?: { workspaceId?: string; workspace?: { workspaceId?: string } };
|
||||
instance?: { workspaceId?: string };
|
||||
[key: string]: unknown;
|
||||
}
|
||||
|
||||
function extractWorkspaceId(result: CommandResult): string | undefined {
|
||||
return (
|
||||
result.workspaceId ||
|
||||
result.workspace?.workspaceId ||
|
||||
result.result?.workspaceId ||
|
||||
result.result?.workspace?.workspaceId ||
|
||||
result.instance?.workspaceId
|
||||
);
|
||||
}
|
||||
|
||||
function findCreated(list: WorkspaceInfo[], cwd: string, name: string): WorkspaceInfo | undefined {
|
||||
const exact = list.find((item) => item.cwd === cwd && (name ? item.name === name : true));
|
||||
if (exact) return exact;
|
||||
return list.find((item) => item.cwd === cwd);
|
||||
}
|
||||
|
||||
/**
|
||||
* `workspace.add` → resolve the new workspace id (the command response is not
|
||||
* required to carry it, so fall back to a fresh GET) → `instance.ensure`.
|
||||
*/
|
||||
export async function openWorkspace(input: { cwd: string; name?: string }): Promise<string> {
|
||||
const cwd = input.cwd.trim();
|
||||
const name = input.name?.trim() ?? "";
|
||||
const added = (await api.command({
|
||||
method: "workspace.add",
|
||||
params: { cwd, ...(name ? { name } : {}) },
|
||||
})) as unknown as CommandResult;
|
||||
|
||||
let workspaceId = extractWorkspaceId(added);
|
||||
if (!workspaceId) {
|
||||
const list = await api.workspaces();
|
||||
workspaceId = findCreated(list, cwd, name)?.workspaceId;
|
||||
}
|
||||
if (!workspaceId) {
|
||||
throw new Error("workspace.add returned no workspace id");
|
||||
}
|
||||
|
||||
await api.command({ method: "instance.ensure", params: { workspaceId } });
|
||||
return workspaceId;
|
||||
}
|
||||
|
||||
/** Display name: explicit name → alias → last cwd segment → untitled. */
|
||||
export function workspaceName(workspace: WorkspaceInfo, unnamed = "Untitled"): string {
|
||||
const explicit = workspace.name?.trim() || workspace.alias?.trim();
|
||||
if (explicit) return explicit;
|
||||
const cwd = String(workspace.cwd || "").replace(/\/+$/, "");
|
||||
const segments = cwd.split("/");
|
||||
return segments[segments.length - 1] || cwd || unnamed;
|
||||
}
|
||||
|
||||
export function workspaceSessionCount(workspace: WorkspaceInfo): number {
|
||||
return Math.max(workspace.liveCount || 0, workspace.sessionCount || 0);
|
||||
}
|
||||
Reference in new issue
Block a user