ctx.workspaces
Read and drive workspace state through WorkspaceService — create/rename/close workspaces, manage their folders, and subscribe to a frozen snapshot. (Opening editor tabs lives on ctx.editors, not here.)
ts
ctx.workspaces: WorkspaceServiceExample
tsx
import { useServiceState } from "@silo-code/sdk";
// read workspace state reactively in a component
function OpenCount() {
const state = useServiceState(ctx.workspaces);
return <span>{state.open.length} open</span>;
}
// or observe changes imperatively
const sub = ctx.workspaces.subscribe((state) => {
console.log(state.open.length, "open workspaces");
});Methods
On ctx.workspaces. Method names link to the full signature.
| Method | What it does |
|---|---|
getState() | Current frozen WorkspaceState. |
subscribe(listener) | Observe changes; returns a Disposable. |
get(id) | One-shot lookup of a workspace by id (for reactive reads, prefer the state). |
create(input) | Create a workspace from a folder + name. |
createFromFolderPicker() | Show a folder picker, then create. |
rename(id, name) | Rename a workspace. |
reorder(from, to, position) | Reorder workspaces. |
activate(id) | Activate (and reopen if closed). |
close(id) | Soft close — hidden but still saved. |
reopen(id) | Reverse of close. |
delete(id) | Hard delete — permanent removal. |
addFolder(id, folder) | Add an extra folder to a workspace. |
removeFolder(id, folder) | Remove an extra folder. |
State
The readable state — a frozen WorkspaceState from getState(), subscribe, or useServiceState:
| Property | Type | What it is |
|---|---|---|
all | readonly Workspace[] | every workspace, in user order |
open | readonly Workspace[] | open workspaces (not closed) |
closed | readonly Workspace[] | closed workspaces, most-recent first |
activeId | string | null | id of the active workspace |
hydrated | boolean | true once persisted state has loaded |
Types
Pass WorkspaceService.
Related: WorkspaceState · CreateWorkspaceInput · OpenFileOptions.
See also
Other State members on ctx.