import type { PluginApiClient, ShellLayout } from "@termix/plugin-sdk/frontend"; import type { Workspace } from "./types"; /** * The workspace routes, through the plugin's own client. Paths are relative * to /plugin-api/workspaces/, which the client already points at. */ export function createWorkspacesApi(api: PluginApiClient) { const data = async (request: Promise<{ data: T }>) => (await request).data; return { list: () => data(api.get("/")), create: (body: { name: string; color?: string | null; icon?: string | null; payload: ShellLayout; }) => data(api.post("/", body)), rename: ( id: number, body: { name?: string; color?: string | null; icon?: string | null }, ) => data(api.patch(`/${id}`, body)), updateContent: (id: number, payload: ShellLayout) => data(api.put(`/${id}/content`, { payload })), remove: (id: number) => data(api.delete<{ success: boolean }>(`/${id}`)), duplicate: (id: number, name: string) => data(api.post(`/${id}/duplicate`, { name })), setDefault: (id: number) => data(api.post(`/${id}/set-default`)), unsetDefault: (id: number) => data(api.post(`/${id}/unset-default`)), apply: (id: number) => data(api.post(`/${id}/apply`)), getLastSession: () => data(api.get("/last-session")), saveLastSession: (payload: ShellLayout) => data(api.put("/last-session", { payload })), }; } export type WorkspacesApi = ReturnType;