@prismshadow/penguin-server · packages/server/src/mechanisms/workbenches.ts:150

Workbenches

interface

Every route that serves a workbench refuses one that does not run — its own switch or the Agent-wide one is off — with 409 workbench_disabled: its pages, the page runtime, its API, a reload. Listing, history, rollback (source only), export and removal still work.

API

@Interface()
export abstract class Workbenches {
  abstract list(projectId: string, agentId: string): Promise<WorkbenchInfo[]>;
  abstract one(
      projectId: string,
      agentId: string,
      workbenchId: string,
    ): Promise<WorkbenchInfo | null>;
  abstract agentEnabled(projectId: string, agentId: string): Promise<boolean>;
  abstract describe(
      projectId: string,
      agentId: string,
      workbenchId: string,
    ): Promise<WorkbenchInfo>;
  abstract reload(
      projectId: string,
      agentId: string,
      workbenchId: string,
      by?: VersionAuthor,
    ): Promise<WorkbenchInfo>;
  abstract reloadIfEnabled(
      projectId: string,
      agentId: string,
      workbenchId: string,
      by?: VersionAuthor,
    ): Promise<WorkbenchInfo>;
  abstract setEnabled(
      projectId: string,
      agentId: string,
      workbenchId: string,
      enabled: boolean,
      by?: VersionAuthor,
    ): Promise<WorkbenchInfo>;
  abstract setAgentEnabled(
      projectId: string,
      agentId: string,
      enabled: boolean,
    ): Promise<{ workbenches: WorkbenchInfo[]; enabled: boolean }>;
  abstract dispatch(
      projectId: string,
      agentId: string,
      workbenchId: string,
      request: WorkbenchRequest,
    ): Promise<WorkbenchResponse>;
  abstract uiFile(
      projectId: string,
      agentId: string,
      workbenchId: string,
      rel: string,
    ): Promise<WorkbenchUiFile | null>;
  abstract uiRuntimeFile(
      projectId: string,
      agentId: string,
      workbenchId: string,
      rel: string,
    ): Promise<WorkbenchUiRuntimeFile | null>;
  abstract exists(projectId: string, agentId: string, workbenchId: string): Promise<boolean>;
  abstract iconSvg(
      projectId: string,
      agentId: string,
      workbenchId: string,
    ): Promise<WorkbenchTabIcon | null>;
  abstract history(
      projectId: string,
      agentId: string,
      workbenchId: string,
    ): Promise<WorkbenchVersion[]>;
  abstract rollback(
      projectId: string,
      agentId: string,
      workbenchId: string,
      revision: string,
      by?: VersionAuthor,
    ): Promise<WorkbenchInfo>;
  abstract remove(
      projectId: string,
      agentId: string,
      workbenchId: string,
      by?: VersionAuthor,
    ): Promise<void>;
  abstract appCenter(
      projectId: string,
      hidden?: boolean,
      unavailable?: AppCenterUnavailable,
    ): Promise<AppCenterShortcut[]>;
  abstract appCenterIcon(
      projectId: string,
      agentId: string,
      workbenchId: string,
    ): Promise<IconImage | null>;
  abstract sidebar(projectId: string, agentId: string): Promise<AppCenterShortcut[]>;
  abstract setSidebar(
      projectId: string,
      agentId: string,
      workbenchId: string,
      show: boolean,
    ): Promise<WorkbenchInfo>;
  abstract setAppCenter(
      projectId: string,
      agentId: string,
      workbenchId: string,
      show: boolean,
      by?: VersionAuthor,
    ): Promise<WorkbenchInfo>;
  abstract releaseAgent(projectId: string, agentId: string): Promise<void>;
  abstract whileReleased<T>(projectId: string, agentId: string, work: () => Promise<T>): Promise<T>;
}

Contract Topology

Static AST wiring across @Module / @Provide / @Use

Members (23)

list

list(projectId: string, agentId: string): Promise<WorkbenchInfo[]>

Every workbench of the Agent, disabled ones included; the ones that run are loaded when stale.

@paramprojectIdstring
@paramagentIdstring
@returnsPromise<WorkbenchInfo[]>

one

one(projectId: string, agentId: string, workbenchId: string): Promise<WorkbenchInfo | null>

One workbench as list gives it, loaded when it runs and is stale; null when the Agent has no such workbench. The Agent's other workbenches are neither read nor loaded, so a page opened on its own waits for its own compile alone.

@paramprojectIdstring
@paramagentIdstring
@paramworkbenchIdstring
@returnsPromise<WorkbenchInfo | null>

agentEnabled

agentEnabled(projectId: string, agentId: string): Promise<boolean>

The Agent-wide switch: false while .disabled sits beside the workbench folders.

@paramprojectIdstring
@paramagentIdstring
@returnsPromise<boolean>

describe

describe(projectId: string, agentId: string, workbenchId: string): Promise<WorkbenchInfo>

One workbench's registration, read from its folder alone — no migrate, no watcher, no load (a 404 WorkbenchNotFound for an unknown id). The auth-less install-manifest gate answers from this: an anonymous request must not be able to run the folder's compile/boot lifecycle, only look at its package.json.

@paramprojectIdstring
@paramagentIdstring
@paramworkbenchIdstring
@returnsPromise<WorkbenchInfo>

reload

reload(projectId: string, agentId: string, workbenchId: string, by?: VersionAuthor): Promise<WorkbenchInfo>
@paramprojectIdstring
@paramagentIdstring
@paramworkbenchIdstring
@paramby?VersionAuthor
@returnsPromise<WorkbenchInfo>

reloadIfEnabled

reloadIfEnabled(projectId: string, agentId: string, workbenchId: string, by?: VersionAuthor): Promise<WorkbenchInfo>

After its source was written (an archive import): loads it as reload does when it runs, and otherwise answers it as it stands, not loaded.

@paramprojectIdstring
@paramagentIdstring
@paramworkbenchIdstring
@paramby?VersionAuthor
@returnsPromise<WorkbenchInfo>

setEnabled

setEnabled(projectId: string, agentId: string, workbenchId: string, enabled: boolean, by?: VersionAuthor): Promise<WorkbenchInfo>

Sets one workbench's own switch. Off unloads it at once (its subscriptions end with its tree); on loads it, unless the Agent-wide switch is off. The Project's users hear workbench_updated.

@paramprojectIdstring
@paramagentIdstring
@paramworkbenchIdstring
@paramenabledboolean
@paramby?VersionAuthor
@returnsPromise<WorkbenchInfo>

setAgentEnabled

setAgentEnabled(projectId: string, agentId: string, enabled: boolean): Promise<{ workbenches: WorkbenchInfo[]; enabled: boolean }>

Sets the Agent-wide switch, leaving each workbench's own as it is: off unloads every workbench of the Agent at once, on loads the ones whose own switch is on. Answers the listing after the change; each workbench is announced as workbench_updated.

@paramprojectIdstring
@paramagentIdstring
@paramenabledboolean
@returnsPromise<{ workbenches: WorkbenchInfo[]; enabled: boolean }>

dispatch

dispatch(projectId: string, agentId: string, workbenchId: string, request: WorkbenchRequest): Promise<WorkbenchResponse>
@paramprojectIdstring
@paramagentIdstring
@paramworkbenchIdstring
@paramrequestWorkbenchRequest
@returnsPromise<WorkbenchResponse>

uiFile

uiFile(projectId: string, agentId: string, workbenchId: string, rel: string): Promise<WorkbenchUiFile | null>

A file of the workbench's ui/: the one on disk, else — for a .js a TSX page compiles to — what the serving instance emitted. Null when absent or unsafe.

@paramprojectIdstring
@paramagentIdstring
@paramworkbenchIdstring
@paramrelstring
@returnsPromise<WorkbenchUiFile | null>

uiRuntimeFile

uiRuntimeFile(projectId: string, agentId: string, workbenchId: string, rel: string): Promise<WorkbenchUiRuntimeFile | null>

A file of the page runtime this server serves compiled pages with (React and the shared components), under a workbench that exists; null otherwise.

@paramprojectIdstring
@paramagentIdstring
@paramworkbenchIdstring
@paramrelstring
@returnsPromise<WorkbenchUiRuntimeFile | null>

exists

exists(projectId: string, agentId: string, workbenchId: string): Promise<boolean>

Whether the Agent has this workbench, read from its folder after any import has ended: false when it has none, a 409 WorkbenchDisabled when it does not run. Loads nothing, so a route that serves the same files under every workbench never compiles the Agent's others.

@paramprojectIdstring
@paramagentIdstring
@paramworkbenchIdstring
@returnsPromise<boolean>

iconSvg

iconSvg(projectId: string, agentId: string, workbenchId: string): Promise<WorkbenchTabIcon | null>

The workbench's plugin icon (.svg markup or .png bytes base64-encoded), from its package.json#penguin.icon; null when it ships none or the read refuses it. The PWA manifest inlines it; the session tabs default to it. A pure read of the current layout — no migration, like describe; the auth-less manifest gate calls this.

@paramprojectIdstring
@paramagentIdstring
@paramworkbenchIdstring
@returnsPromise<WorkbenchTabIcon | null>

history

history(projectId: string, agentId: string, workbenchId: string): Promise<WorkbenchVersion[]>
@paramprojectIdstring
@paramagentIdstring
@paramworkbenchIdstring
@returnsPromise<WorkbenchVersion[]>

rollback

rollback(projectId: string, agentId: string, workbenchId: string, revision: string, by?: VersionAuthor): Promise<WorkbenchInfo>

Restores a version's source; it is loaded (and recorded as the newest version) only when it runs.

@paramprojectIdstring
@paramagentIdstring
@paramworkbenchIdstring
@paramrevisionstring
@paramby?VersionAuthor
@returnsPromise<WorkbenchInfo>

remove

remove(projectId: string, agentId: string, workbenchId: string, by?: VersionAuthor): Promise<void>

Deletes the folder, state and switch included, and records the removal; its earlier versions are no longer listed. The instance goes with it.

@paramprojectIdstring
@paramagentIdstring
@paramworkbenchIdstring
@paramby?VersionAuthor
@returnsPromise<void>

appCenter

appCenter(projectId: string, hidden?: boolean, unavailable?: AppCenterUnavailable): Promise<AppCenterShortcut[]>

The App Center of a Project: a shortcut for every workbench of its Agents on this server whose manifest asks to be shown (or explicitly hidden when requested), in Agent list order and by title within an Agent. Read from the manifests, each one's last load status and the loads under way — nothing is loaded or compiled. From then on the Agents' folders are watched, so an edit loads and is announced.

@paramprojectIdstring
@paramhidden?boolean
@paramunavailable?AppCenterUnavailable
@returnsPromise<AppCenterShortcut[]>

appCenterIcon

appCenterIcon(projectId: string, agentId: string, workbenchId: string): Promise<IconImage | null>

The icon a workbench's App Center declaration names, read and checked again; null when the workbench is unknown, its declaration does not hold up, or it names no icon.

@paramprojectIdstring
@paramagentIdstring
@paramworkbenchIdstring
@returnsPromise<IconImage | null>

setSidebar

setSidebar(projectId: string, agentId: string, workbenchId: string, show: boolean): Promise<WorkbenchInfo>

Writes (show: false) or removes the installation's .hidden-from-sidebar marker. It is no part of the source, so writing it records no version and does not reload the workbench; the workbench as it then stands is answered and announced.

@paramprojectIdstring
@paramagentIdstring
@paramworkbenchIdstring
@paramshowboolean
@returnsPromise<WorkbenchInfo>

setAppCenter

setAppCenter(projectId: string, agentId: string, workbenchId: string, show: boolean, by?: VersionAuthor): Promise<WorkbenchInfo>

Rewrites penguin.appCenter.show in the workbench's package.json, and nothing else of it, then reloads the workbench — which records the edit as a version like any other.

@paramprojectIdstring
@paramagentIdstring
@paramworkbenchIdstring
@paramshowboolean
@paramby?VersionAuthor
@returnsPromise<WorkbenchInfo>

releaseAgent

releaseAgent(projectId: string, agentId: string): Promise<void>

Lets go of everything held for one Agent before its folder is deleted or its State is replaced: the folder watcher, pending reloads, loads in flight and the loaded instances. A later listing takes them up again, so an Agent whose deletion is then refused loses nothing.

@paramprojectIdstring
@paramagentIdstring
@returnsPromise<void>

whileReleased

whileReleased<T>(projectId: string, agentId: string, work: () => Promise<T>): Promise<T>

Runs work (an Agent State import) with the Agent's workbenches released as by releaseAgent and kept so until it settles: a request for them meanwhile waits for the end instead of watching or loading the directory being replaced.

@paramprojectIdstring
@paramagentIdstring
@paramwork() => Promise<T>
@returnsPromise<T>