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

WorkbenchHost

interface

What the server publishes into a workbench tree as module Host.

API

@Interface()
export abstract class WorkbenchHost {
  abstract readonly pageId: string;
  abstract listAgents(): { agentId: string }[];
  abstract createSession(opts?: {
      agentId?: string;
      /** Choose a project model for this Session. Omit it to use the Project default. */
      model?: { provider: string; modelId: string };
      /**
       * `allow-all` (the default) runs every tool call, as a scheduled run does. `deny-all`
       * denies every tool call in the Session: the mode for a Session that only talks, so
       * nothing the person types and nothing the workbench inlines can run a command.
       */
      approvalMode?: WorkbenchApprovalMode;
    }): Promise<{ sessionId: string }>;
  abstract run(
      sessionId: string,
      input: WorkbenchInput[],
    ): Promise<{ sessionId: string; queued: boolean }>;
  abstract sessionStatus(sessionId: string): string;
  abstract sessionTitle(sessionId: string): string | null;
  abstract sessionResult(sessionId: string): Promise<WorkbenchResult>;
  abstract subscribe(sessionId: string, listener: (record: WorkbenchRecord) => void): () => void;
  abstract dataPaths(level?: WorkbenchDataLevel): WorkbenchDataPaths;
  abstract socketPath(name: string, level?: WorkbenchDataLevel): string;
  abstract getState(): unknown;
  abstract setState(state: unknown): Promise<void>;
  abstract log(message: string): void;
}

Members (13)

pageId

readonly pageId: string

This workbench's page id (page-YYYY-MM-DD-HH-mm-ss-<8 hex>), which its Sessions record as their source (PageSource).

listAgents

listAgents(): { agentId: string }[]

The Agents of this Project — who createSession can be asked to open a Session of. The system Agent, which runs none, is not one of them.

@returns{ agentId: string }[]

createSession

createSession(opts?: { agentId?: string; model?: { provider: string; modelId: string }; approvalMode?: WorkbenchApprovalMode; }): Promise<{ sessionId: string }>

Opens a Session of an Agent of this Project — the workbench's own Agent when agentId is absent. The SDK's agent.createSession. The Session's approval mode is approvalMode, allow-all when absent; any other value is refused by name.

@paramopts?{ agentId?: string; model?: { provider: string; modelId: string }; approvalMode?: WorkbenchApprovalMode; }
@returnsPromise<{ sessionId: string }>

run

run(sessionId: string, input: WorkbenchInput[]): Promise<{ sessionId: string; queued: boolean }>

Runs one turn in a Session of this Project, new or existing — the SDK's session.run. input is a list of items like the SDK's, each one { text } today; it reaches the Agent as a message from the server, not from a person. A Session that is busy takes it as a queued follow-up (queued: true) instead of refusing it. Resolves once the turn has started; watch it with sessionResult.

@paramsessionIdstring
@paraminputWorkbenchInput[]
@returnsPromise<{ sessionId: string; queued: boolean }>

sessionStatus

sessionStatus(sessionId: string): string

idle / running / … of a Session of this Project.

@paramsessionIdstring
@returnsstring

sessionTitle

sessionTitle(sessionId: string): string | null

The Session's generated or user-edited title; null until one is available.

@paramsessionIdstring
@returnsstring | null

sessionResult

sessionResult(sessionId: string): Promise<WorkbenchResult>

A snapshot, not a wait: running until the latest task ends, then its final answer or failure. No tool or thinking messages.

@paramsessionIdstring
@returnsPromise<WorkbenchResult>

subscribe

subscribe(sessionId: string, listener: (record: WorkbenchRecord) => void): () => void

Follows a Session of this Project live: listener receives each record the Session publishes from now on — exactly the records GET /api/sessions/:id/amsp streams, partial deltas and a subagent's (origin) included. Nothing is replayed, so subscribe before run. Returns the unsubscribe function; calling it again does nothing. A listener runs after the publish, never inside it, records in order; one that throws is logged and the subscription carries on. A main task_end (no origin) arrives before the Session reads idle, and sessionResult answers running until it does. Every subscription ends with the workbench's tree (a reload, a removal), and one whose Session has sat idle with nothing published for the channel hub's idle window ends by itself.

@paramsessionIdstring
@paramlistener(record: WorkbenchRecord) => void
@returns() => void

dataPaths

dataPaths(level?: WorkbenchDataLevel): WorkbenchDataPaths

Where this workbench's data, cache and state folders are at level (agent when left out). All three exist once this returns, and a link where one of them belongs is refused. At the agent level the Agent's commands may write them even in a workspace-write sandbox, so a path in them can be handed to the Agent. The server and machine levels are for an app installed from a plugin, and throw for a workbench made in place.

@paramlevel?WorkbenchDataLevel
@returnsWorkbenchDataPaths

socketPath

socketPath(name: string, level?: WorkbenchDataLevel): string

What to listen on for a local socket called name at level (agent when left out): <stateDir>/<name>, or on Windows a named pipe (\\.\pipe\penguin-…-<name>), which is no path on disk. Throws, naming the limit, when the path would pass the 103 bytes a Unix socket path holds.

@paramnamestring
@paramlevel?WorkbenchDataLevel
@returnsstring

getState

getState(): unknown

The workbench's own document (state.json, kept by the server across reloads and rollbacks).

@returnsunknown

setState

setState(state: unknown): Promise<void>
@paramstateunknown
@returnsPromise<void>

log

log(message: string): void
@parammessagestring
@returnsvoid