feat: add local machine registry foundation

This commit is contained in:
Marc Kassubeck
2026-05-26 13:04:00 +02:00
parent 712456f953
commit 0405b384b1
18 changed files with 673 additions and 28 deletions
@@ -0,0 +1,41 @@
import { api, type Machine } from "../api";
import { resetWorkspaceScopedState } from "../appState";
import type { GetState, SetState, UpdateUrl } from "./types";
import type { ProjectController } from "./projectController";
export class MachineController {
constructor(private readonly getState: GetState, private readonly setState: SetState, private readonly updateUrl: UpdateUrl, private readonly projects: ProjectController) {}
async loadMachines(routeMachineId?: string): Promise<void> {
this.setState({ error: "", isLoadingMachines: true });
try {
const machines = await api.machines();
const selectedMachine = machines.find((machine) => machine.id === (routeMachineId ?? "local")) ?? machines.find((machine) => machine.id === "local") ?? machines[0];
this.setState({ machines, selectedMachine });
} catch (error) {
this.setState({ error: String(error) });
} finally {
this.setState({ isLoadingMachines: false });
}
}
async selectMachine(machine: Machine): Promise<void> {
if (this.getState().selectedMachine?.id === machine.id) return;
this.setState({
selectedMachine: machine,
projects: [],
workspaces: [],
selectedProject: undefined,
selectedWorkspace: undefined,
selectedSession: undefined,
messages: [],
messagePageStart: 0,
messagePageTotal: 0,
status: undefined,
activity: undefined,
...resetWorkspaceScopedState(),
});
this.updateUrl();
await this.projects.loadProjects();
}
}