# Orchestrator
Source: https://docs.maelstrom-ai.co/dev/reference/client/classes/orchestrator/
Documentation revision: 89a8f5e9d10cedcf0b30376d7846113f06f26120
SDK manifests in this build: @maelstrom-co/react@0.2.1, @maelstrom-co/client@0.2.1, @maelstrom-co/connectors@0.2.1, @maelstrom-co/protocol@0.2.1, @maelstrom-co/engine@0.2.1
These docs follow this source revision. Manifest versions do not prove release compatibility; verify the installed package exports before using an API.

Defined in: [packages/client/src/lib/orchestrator/orchestrator.ts:147](https://github.com/maelstrom-co/maelstrom/blob/89a8f5e9d10cedcf0b30376d7846113f06f26120/packages/client/src/lib/orchestrator/orchestrator.ts#L147)

Composition root that creates, wires, and coordinates all microkernels.

The Orchestrator owns **zero private state** and emits no events of its own beyond the agent conversation events exposed through `agent`. All other events stay on the microkernel emitters. It sequences calls across microkernels in the right order. Consumers interact with microkernels directly for domain operations.

## Example

```ts
const connector = new WebSocketConnector({ url: 'wss://api.example.com/ws' });
const orchestrator = new Orchestrator(connector, { debug: true });

await orchestrator.connect();
const response = await orchestrator.processIntent('show me sales data');

// Listen for events via microkernels directly:
orchestrator.requestCoordinator.events.on('processing_completed', (e) => { ... });
orchestrator.chartManager.setDimensions({ columns: 10, rows: 6 });
```

## Throws

If `options.initialLayout` is not a tiling layout (a grid layout only repositions instances that already exist, and none do at construction).

## Throws

If `options.initialLayout` is present and `options.layoutMode` is `'grid'` — the seed’s type and the mode must agree.

## Throws

If `options.initialLayout` declares the same `instanceId` twice.

## Throws

If an `options.initialLayout` tree contains a split token whose weight suffix is malformed — anything an engine response would have repaired, such as `"V:1,5000"` or `"V:01,1"`. A seed is rejected rather than repaired: the lenient-LLM / strict-developer asymmetry means the author is told, instead of being handed geometry they did not write.

## Throws

If an `options.initialLayout` tree names the same instance in two leaves. An instance renders as exactly one tile; weight the split token instead of repeating the leaf.

## Throws

If an `options.initialLayout` tree leaf is not declared in its `instances`, or a declared instance is referenced by no tree leaf.

## Throws

If an `options.initialLayout` instance names a vessel that is not registered via `options.vessels`, or a variant that vessel does not declare.

## Constructors

### Constructor

> **new Orchestrator**(`connector`, `options?`): `Orchestrator`

Defined in: [packages/client/src/lib/orchestrator/orchestrator.ts:189](https://github.com/maelstrom-co/maelstrom/blob/89a8f5e9d10cedcf0b30376d7846113f06f26120/packages/client/src/lib/orchestrator/orchestrator.ts#L189)

#### Parameters

##### connector

[`EngineConnector`](https://docs.maelstrom-ai.co/dev/reference/client/interfaces/engineconnector/)

##### options?

[`OrchestratorOptions`](https://docs.maelstrom-ai.co/dev/reference/client/type-aliases/orchestratoroptions/) = `{}`

#### Returns

`Orchestrator`

## Properties

### diagnostics

> `readonly` **diagnostics**: [`DiagnosticChannel`](https://docs.maelstrom-ai.co/dev/reference/client/classes/diagnosticchannel/)

Defined in: [packages/client/src/lib/orchestrator/orchestrator.ts:149](https://github.com/maelstrom-co/maelstrom/blob/89a8f5e9d10cedcf0b30376d7846113f06f26120/packages/client/src/lib/orchestrator/orchestrator.ts#L149)

Optional diagnostic observation, isolated from application operations.

## Accessors

### agent

#### Get Signature

> **get** **agent**(): [`OrchestratorAgent`](https://docs.maelstrom-ai.co/dev/reference/client/type-aliases/orchestratoragent/)

Defined in: [packages/client/src/lib/orchestrator/orchestrator.ts:445](https://github.com/maelstrom-co/maelstrom/blob/89a8f5e9d10cedcf0b30376d7846113f06f26120/packages/client/src/lib/orchestrator/orchestrator.ts#L445)

The Agent Session conversation carried by the current connector.

`store` holds the Agent Run state of every input sent through [sendMessage](https://docs.maelstrom-ai.co/dev/reference/client/classes/orchestrator/#sendmessage), capped at the 20 latest inputs. It is folded from the same events, so it never misses one that arrived before a component subscribed. Events for inputs not sent through [sendMessage](https://docs.maelstrom-ai.co/dev/reference/client/classes/orchestrator/#sendmessage) are ignored by the store. An error thrown by a store subscriber is logged and affects neither the send nor the settlement of any `result`.

`events` delivers the raw events. Every payload is the protocol object the agent sent, unchanged, except `accepted`, `ui_change` and `conversation_lost`, which the Orchestrator builds itself.

-   `accepted`: the agent accepts an input. It carries the `inputId` that [sendMessage](https://docs.maelstrom-ai.co/dev/reference/client/classes/orchestrator/#sendmessage) returned, the `runId` of the Agent Run that handles it, which is `null` for the `noise` disposition, and the agent’s `ack`.
-   `ui_change`: the Orchestrator finished applying a UI change the agent sent. It carries the `runId`, the `changeId` and the outcome of each Action, the same outcomes the `ui_applied` acknowledgement carries.
-   `placeholder`: the agent sends text to show while it works on an input.
-   `message`: the agent streams part of a conversational reply.
-   `finished`: an Agent Run ends, whatever the reason.
-   `error`: the agent reports a failure that is not an Agent Run’s own ending, such as an admission rejection. It carries the `inputId` when the failure relates to an input. It also reports a failed loop-driven UI change of an Agent Run, named by `runId` and `changeId`, which can arrive mid-run or after that run’s `finished`.
-   `conversation_lost`: the conversation can no longer continue. Fires once when the transport closes, cleanly or not, or when [setConnector](https://docs.maelstrom-ai.co/dev/reference/client/classes/orchestrator/#setconnector) replaces the connector, and only while a conversation exists, meaning at least one input was sent or one agent event arrived since the last loss. Also fires with reason `stale_run` when an input or Agent Run stays silent for the `agentRunStaleTimeoutMs` window, naming the `runId`, or the `inputId` when no run was accepted yet. Time the client spends applying a UI change does not count as silence. Events that arrive for that run afterwards are still delivered here, but the stale loss starts a new session, so a `ui_applied` for a change still being applied is dropped. After the other reasons no further events arrive.

UI changes the agent sends are applied and acknowledged internally, and a `ui_change` event reports each one after it was applied, whether or not its acknowledgement could be sent. A change still applying when the conversation is lost to `disconnected` or `connector_replaced` is applied but reports no `ui_change`. Listeners cannot alter the apply or the acknowledgement. Subscribing to `events` after [dispose](https://docs.maelstrom-ai.co/dev/reference/client/classes/orchestrator/#dispose) throws. [dispose](https://docs.maelstrom-ai.co/dev/reference/client/classes/orchestrator/#dispose) reports `conversation_lost` with reason `disconnected` first, so pending results settle.

The agent loop is experimental in 0.3 and may change in any minor release.

> [!WARNING]
> Experimental
> 
> This API should not be used in production and may be trimmed from a public release.

##### Returns

[`OrchestratorAgent`](https://docs.maelstrom-ai.co/dev/reference/client/type-aliases/orchestratoragent/)

* * *

### chartManager

#### Get Signature

> **get** **chartManager**(): [`ChartManager`](https://docs.maelstrom-ai.co/dev/reference/client/classes/chartmanager/)

Defined in: [packages/client/src/lib/orchestrator/orchestrator.ts:385](https://github.com/maelstrom-co/maelstrom/blob/89a8f5e9d10cedcf0b30376d7846113f06f26120/packages/client/src/lib/orchestrator/orchestrator.ts#L385)

##### Returns

[`ChartManager`](https://docs.maelstrom-ai.co/dev/reference/client/classes/chartmanager/)

* * *

### commandProcessor

#### Get Signature

> **get** **commandProcessor**(): [`CommandProcessor`](https://docs.maelstrom-ai.co/dev/reference/client/classes/commandprocessor/)

Defined in: [packages/client/src/lib/orchestrator/orchestrator.ts:377](https://github.com/maelstrom-co/maelstrom/blob/89a8f5e9d10cedcf0b30376d7846113f06f26120/packages/client/src/lib/orchestrator/orchestrator.ts#L377)

##### Returns

[`CommandProcessor`](https://docs.maelstrom-ai.co/dev/reference/client/classes/commandprocessor/)

* * *

### connectionManager

#### Get Signature

> **get** **connectionManager**(): [`ConnectionManager`](https://docs.maelstrom-ai.co/dev/reference/client/classes/connectionmanager/)

Defined in: [packages/client/src/lib/orchestrator/orchestrator.ts:373](https://github.com/maelstrom-co/maelstrom/blob/89a8f5e9d10cedcf0b30376d7846113f06f26120/packages/client/src/lib/orchestrator/orchestrator.ts#L373)

##### Returns

[`ConnectionManager`](https://docs.maelstrom-ai.co/dev/reference/client/classes/connectionmanager/)

* * *

### intentScheduler

#### Get Signature

> **get** **intentScheduler**(): [`IntentSchedulerView`](https://docs.maelstrom-ai.co/dev/reference/client/interfaces/intentschedulerview/)

Defined in: [packages/client/src/lib/orchestrator/orchestrator.ts:729](https://github.com/maelstrom-co/maelstrom/blob/89a8f5e9d10cedcf0b30376d7846113f06f26120/packages/client/src/lib/orchestrator/orchestrator.ts#L729)

Shared admission state; network telemetry alone does not imply readiness.

##### Returns

[`IntentSchedulerView`](https://docs.maelstrom-ai.co/dev/reference/client/interfaces/intentschedulerview/)

* * *

### requestCoordinator

#### Get Signature

> **get** **requestCoordinator**(): [`RequestCoordinator`](https://docs.maelstrom-ai.co/dev/reference/client/classes/requestcoordinator/)

Defined in: [packages/client/src/lib/orchestrator/orchestrator.ts:389](https://github.com/maelstrom-co/maelstrom/blob/89a8f5e9d10cedcf0b30376d7846113f06f26120/packages/client/src/lib/orchestrator/orchestrator.ts#L389)

##### Returns

[`RequestCoordinator`](https://docs.maelstrom-ai.co/dev/reference/client/classes/requestcoordinator/)

* * *

### vesselManager

#### Get Signature

> **get** **vesselManager**(): [`VesselManager`](https://docs.maelstrom-ai.co/dev/reference/client/classes/vesselmanager/)

Defined in: [packages/client/src/lib/orchestrator/orchestrator.ts:381](https://github.com/maelstrom-co/maelstrom/blob/89a8f5e9d10cedcf0b30376d7846113f06f26120/packages/client/src/lib/orchestrator/orchestrator.ts#L381)

##### Returns

[`VesselManager`](https://docs.maelstrom-ai.co/dev/reference/client/classes/vesselmanager/)

## Methods

### addAssistantMessage()

> **addAssistantMessage**(`message`): `Promise`<`void`\>

Defined in: [packages/client/src/lib/orchestrator/orchestrator.ts:1069](https://github.com/maelstrom-co/maelstrom/blob/89a8f5e9d10cedcf0b30376d7846113f06f26120/packages/client/src/lib/orchestrator/orchestrator.ts#L1069)

#### Parameters

##### message

`string`

#### Returns

`Promise`<`void`\>

* * *

### addAssistantMessageAcknowledged()

> **addAssistantMessageAcknowledged**(`args`): `Promise`<[`AssistantMessageOutcome`](https://docs.maelstrom-ai.co/dev/reference/client/type-aliases/assistantmessageoutcome/)\>

Defined in: [packages/client/src/lib/orchestrator/orchestrator.ts:1095](https://github.com/maelstrom-co/maelstrom/blob/89a8f5e9d10cedcf0b30376d7846113f06f26120/packages/client/src/lib/orchestrator/orchestrator.ts#L1095)

Insert an assistant message into engine history and report whether the engine stored it or recognized it as a duplicate.

Used by greeting flows that must prove persistence before speech and must not speak twice for one session: `'inserted'` means this call created the record; `'deduped'` means an equal `id` already existed.

Requires an active connector that implements [AcknowledgedAssistantConnector](https://docs.maelstrom-ai.co/dev/reference/client/interfaces/acknowledgedassistantconnector/).

#### Parameters

##### args

###### id

[`MessageId`](https://docs.maelstrom-ai.co/dev/reference/client/type-aliases/messageid/)

Stable message id; identity for engine-side dedupe.

###### message

`string`

Exact assistant text to persist.

#### Returns

`Promise`<[`AssistantMessageOutcome`](https://docs.maelstrom-ai.co/dev/reference/client/type-aliases/assistantmessageoutcome/)\>

#### Throws

If called after [dispose](https://docs.maelstrom-ai.co/dev/reference/client/classes/orchestrator/#dispose).

#### Throws

If the active connector lacks acknowledged-assistant support.

#### Throws

Propagates connector transport, engine, close, and timeout failures.

* * *

### connect()

> **connect**(): `Promise`<`void`\>

Defined in: [packages/client/src/lib/orchestrator/orchestrator.ts:1030](https://github.com/maelstrom-co/maelstrom/blob/89a8f5e9d10cedcf0b30376d7846113f06f26120/packages/client/src/lib/orchestrator/orchestrator.ts#L1030)

#### Returns

`Promise`<`void`\>

* * *

### createIntentScope()

> **createIntentScope**(): [`IntentScope`](https://docs.maelstrom-ai.co/dev/reference/client/interfaces/intentscope/)

Defined in: [packages/client/src/lib/orchestrator/orchestrator.ts:747](https://github.com/maelstrom-co/maelstrom/blob/89a8f5e9d10cedcf0b30376d7846113f06f26120/packages/client/src/lib/orchestrator/orchestrator.ts#L747)

Create a lifetime that retires only its pending intents, never active work.

#### Returns

[`IntentScope`](https://docs.maelstrom-ai.co/dev/reference/client/interfaces/intentscope/)

* * *

### disconnect()

> **disconnect**(): `Promise`<`void`\>

Defined in: [packages/client/src/lib/orchestrator/orchestrator.ts:1034](https://github.com/maelstrom-co/maelstrom/blob/89a8f5e9d10cedcf0b30376d7846113f06f26120/packages/client/src/lib/orchestrator/orchestrator.ts#L1034)

#### Returns

`Promise`<`void`\>

* * *

### dispose()

> **dispose**(): `Promise`<`void`\>

Defined in: [packages/client/src/lib/orchestrator/orchestrator.ts:1191](https://github.com/maelstrom-co/maelstrom/blob/89a8f5e9d10cedcf0b30376d7846113f06f26120/packages/client/src/lib/orchestrator/orchestrator.ts#L1191)

Retire scheduled updates and request error reporting before transport shutdown. Coalesced flushes resolve to `null` because their response cannot be applied. In-flight intents still settle with their transport outcome.

#### Returns

`Promise`<`void`\>

* * *

### enqueueIntent()

> **enqueueIntent**(`intent`, `options?`): [`IntentSubmission`](https://docs.maelstrom-ai.co/dev/reference/client/interfaces/intentsubmission/)

Defined in: [packages/client/src/lib/orchestrator/orchestrator.ts:739](https://github.com/maelstrom-co/maelstrom/blob/89a8f5e9d10cedcf0b30376d7846113f06f26120/packages/client/src/lib/orchestrator/orchestrator.ts#L739)

Accept into the bounded FIFO synchronously. Request snapshots are built at dispatch, after earlier response application settles. Operational failures resolve the ticket result; unknown outcomes must not be automatically retried. Throws only for a scope belonging to another Orchestrator.

#### Parameters

##### intent

`string`

##### options?

[`EnqueueIntentOptions`](https://docs.maelstrom-ai.co/dev/reference/client/interfaces/enqueueintentoptions/)

#### Returns

[`IntentSubmission`](https://docs.maelstrom-ai.co/dev/reference/client/interfaces/intentsubmission/)

* * *

### flushUpdates()

> **flushUpdates**(): `Promise`<`MaelstromResponse` | `null`\>

Defined in: [packages/client/src/lib/orchestrator/orchestrator.ts:839](https://github.com/maelstrom-co/maelstrom/blob/89a8f5e9d10cedcf0b30376d7846113f06f26120/packages/client/src/lib/orchestrator/orchestrator.ts#L839)

Send whatever the UpdateCoordinator has buffered now, instead of waiting for its debounce to fire, and apply the response the same way [processIntent](https://docs.maelstrom-ai.co/dev/reference/client/classes/orchestrator/#processintent) does.

Use it when something must reach the engine at a known moment — a test, a teardown, a UI gesture that should not sit out the debounce window. If a request is already in flight this coalesces with it rather than sending a second one: the buffered updates are put back and the returned promise settles with that request’s outcome. After an immediate intent has delivered its response, new flushes wait for the next engine turn even if that intent’s actions are still settling.

RESOLVES `null` — deliberately the same value for every “nothing landed” case, because none of them is a failure the caller can act on:

-   the Orchestrator is disposed;
-   nothing was buffered;
-   disconnect removed buffered work waiting for a future engine turn;
-   a concurrent [setConnector](https://docs.maelstrom-ai.co/dev/reference/client/classes/orchestrator/#setconnector) superseded the response, which was therefore never applied (the updates are requeued for the next flush);
-   the send itself failed _because_ of that swap — the transport error is swallowed rather than thrown, and logged at warn with the epoch that fenced it, which is the only thing distinguishing it from a request that was never sent.

REJECTS with the transport’s error when a send fails under the current connector — an ordinary failure, not a fenced one, is never swallowed.

#### Returns

`Promise`<`MaelstromResponse` | `null`\>

* * *

### getCapabilitySnapshot()

> **getCapabilitySnapshot**(): [`CapabilitySnapshot`](https://docs.maelstrom-ai.co/dev/reference/client/interfaces/capabilitysnapshot/)

Defined in: [packages/client/src/lib/orchestrator/orchestrator.ts:505](https://github.com/maelstrom-co/maelstrom/blob/89a8f5e9d10cedcf0b30376d7846113f06f26120/packages/client/src/lib/orchestrator/orchestrator.ts#L505)

Capability catalog (vessels, variants, actions) for `get_capabilities` pulls.

#### Returns

[`CapabilitySnapshot`](https://docs.maelstrom-ai.co/dev/reference/client/interfaces/capabilitysnapshot/)

* * *

### getConfig()

> **getConfig**(): [`ResolvedOrchestratorOptions`](https://docs.maelstrom-ai.co/dev/reference/client/interfaces/resolvedorchestratoroptions/)

Defined in: [packages/client/src/lib/orchestrator/orchestrator.ts:453](https://github.com/maelstrom-co/maelstrom/blob/89a8f5e9d10cedcf0b30376d7846113f06f26120/packages/client/src/lib/orchestrator/orchestrator.ts#L453)

#### Returns

[`ResolvedOrchestratorOptions`](https://docs.maelstrom-ai.co/dev/reference/client/interfaces/resolvedorchestratoroptions/)

* * *

### getHistory()

> **getHistory**(`sessionId`): `Promise`<readonly `SessionHistoryEntry`\[\]>

Defined in: [packages/client/src/lib/orchestrator/orchestrator.ts:1124](https://github.com/maelstrom-co/maelstrom/blob/89a8f5e9d10cedcf0b30376d7846113f06f26120/packages/client/src/lib/orchestrator/orchestrator.ts#L1124)

Fetch the engine-recorded history for the given session.

Use this to rehydrate a conversation after a refresh, on a new device, or in a parallel tab — anywhere a developer has persisted a session id and wants to seed UI state from the server. The session id is passed explicitly (rather than read from the orchestrator’s own `config.sessionId`) so callers can fetch any session they have an id for, including a session that predates this orchestrator instance.

Errors from the connector (transport failure, engine error) propagate as thrown `Error`s — same shape as `addAssistantMessage` and `processIntent`.

#### Parameters

##### sessionId

[`SessionId`](https://docs.maelstrom-ai.co/dev/reference/client/type-aliases/sessionid/)

#### Returns

`Promise`<readonly `SessionHistoryEntry`\[\]>

* * *

### getStructuralSnapshot()

> **getStructuralSnapshot**(): [`UIStructuralSnapshot`](https://docs.maelstrom-ai.co/dev/reference/client/interfaces/uistructuralsnapshot/)

Defined in: [packages/client/src/lib/orchestrator/orchestrator.ts:468](https://github.com/maelstrom-co/maelstrom/blob/89a8f5e9d10cedcf0b30376d7846113f06f26120/packages/client/src/lib/orchestrator/orchestrator.ts#L468)

Structural-only UI snapshot for grounding + `get_ui_state` pulls.

#### Returns

[`UIStructuralSnapshot`](https://docs.maelstrom-ai.co/dev/reference/client/interfaces/uistructuralsnapshot/)

* * *

### getViewState()

> **getViewState**(): [`OrchestratorViewState`](https://docs.maelstrom-ai.co/dev/reference/client/interfaces/orchestratorviewstate/)

Defined in: [packages/client/src/lib/orchestrator/orchestrator.ts:457](https://github.com/maelstrom-co/maelstrom/blob/89a8f5e9d10cedcf0b30376d7846113f06f26120/packages/client/src/lib/orchestrator/orchestrator.ts#L457)

#### Returns

[`OrchestratorViewState`](https://docs.maelstrom-ai.co/dev/reference/client/interfaces/orchestratorviewstate/)

* * *

### invokeAction()

> **invokeAction**(`instanceId`, `action`, `params?`): `void`

Defined in: [packages/client/src/lib/orchestrator/orchestrator.ts:934](https://github.com/maelstrom-co/maelstrom/blob/89a8f5e9d10cedcf0b30376d7846113f06f26120/packages/client/src/lib/orchestrator/orchestrator.ts#L934)

Invoke a vessel action locally — the client-authoritative path for actions a user triggers directly in the UI (e.g. a button click), as opposed to actions the engine returns in an execution plan.

WHAT it does, in order:

1.  Validates that `instanceId` exists and that `action` is declared on the instance’s **current** variant. If either check fails it logs a warning and no-ops — it never throws, so it is safe to call straight from a render callback.
2.  If the action declares a `transitionsTo` variant that exists on the vessel, it updates the store’s variant **synchronously, before the runner runs** — the store is authoritative and the UI reflects the new variant immediately (no optimistic-override-then-rollback dance).
3.  Runs the action’s registered runner through the same CommandProcessor / ActionManager machinery as engine-plan actions (runner-readiness wait, execution timeout, `action_error` emission).
4.  If the runner fails (error result, throw, or timeout), reverts the variant — but only if the store variant is still the one this call set, so a newer transition or an engine layout that landed in between wins. An action that does not run at all, because no runner registered or the runner has no handler for it, reverts the same way unless it is declared effect `'none'`, which needs no handler.
5.  When (and only when) a transition actually happened in step 2, schedules a `vessel_mutation` update so the engine can re-plan layout. Bursts are coalesced by the UpdateCoordinator’s debounce.

WHY: vessels declare their own state machines, so a locally-invoked action with a `transitionsTo` is a fact the client already knows — applying it locally makes the client the authority instead of waiting on an engine round-trip.

INVARIANTS:

-   Never throws; invalid input warns and no-ops.
-   The variant transition is applied before the runner is awaited.
-   A revert never clobbers a variant a later write already changed.
-   Only an action declared effect `'none'` keeps its transition without a handler.
-   No `transitionsTo`, or no effective variant change → no engine update.

#### Parameters

##### instanceId

`InstanceId`

The instance to act on; must exist in the store.

##### action

`ActionName`

The action name; must be declared on the current variant.

##### params?

`Record`<`string`, `unknown`\>

Optional parameter object passed to the runner verbatim.

#### Returns

`void`

#### Example

```ts
// In a vessel's render callback:
<button onClick={() => orchestrator.invokeAction(instanceId, 'expand')}>
  Expand
</button>
```

* * *

### onSettled()

> **onSettled**(`cb`): [`Unsubscribe`](https://docs.maelstrom-ai.co/dev/reference/client/type-aliases/unsubscribe/)

Defined in: [packages/client/src/lib/orchestrator/orchestrator.ts:535](https://github.com/maelstrom-co/maelstrom/blob/89a8f5e9d10cedcf0b30376d7846113f06f26120/packages/client/src/lib/orchestrator/orchestrator.ts#L535)

Subscribe to the render-settled signal.

Fires whenever the CommandProcessor’s command queue drains back to idle — the moment a batch of layout + action commands has fully applied. Both settle sources required by grounding reach this transition: an engine response dispatched via `processIntent` / `flushUpdates` (`set_layout` + `execute_actions` as one atomic batch), and direct manipulation (a user click / variant change, which reaches the processor through `commandProcessor.executeActions()` the same way a React `executeAction` call does). Neither path bypasses the queue, so a single subscription to the queue-idle transition grounds both.

This is the grounding-push trigger only — it is NOT how speak-after-render is sequenced. That flow awaits a specific intent’s own `commandProcessor.waitForIdle()` after `processIntent` resolves, so it correlates to that intent’s response rather than racing this global signal.

May fire more than once per logical settle (each queue-drain-to-idle transition invokes it); downstream consumers that only want the latest state should debounce.

#### Parameters

##### cb

() => `void`

#### Returns

[`Unsubscribe`](https://docs.maelstrom-ai.co/dev/reference/client/type-aliases/unsubscribe/)

* * *

### processIntent()

> **processIntent**(`intent`): `Promise`<`MaelstromResponse`\>

Defined in: [packages/client/src/lib/orchestrator/orchestrator.ts:592](https://github.com/maelstrom-co/maelstrom/blob/89a8f5e9d10cedcf0b30376d7846113f06f26120/packages/client/src/lib/orchestrator/orchestrator.ts#L592)

Send a user intent to the engine and apply the response it plans.

Any updates buffered by the UpdateCoordinator ride along in the same request, so an intent typed right after a resize or a vessel mutation asks the engine to plan against what the board actually looks like. The response is dispatched as one atomic batch — layout first, then actions — before the legacy response/flush promises resolve. These promises do not certify action success. Use [enqueueIntent](https://docs.maelstrom-ai.co/dev/reference/client/classes/orchestrator/#enqueueintent) for exact-batch outcomes.

Single-flight includes response application and active local commands, not just network time. Older accepted users also take priority. This rejects with [RequestInFlightError](https://docs.maelstrom-ai.co/dev/reference/client/classes/requestinflighterror/) rather than queueing, and its admission lock remains held through command settlement after this promise resolves.

REJECTS WITH:

-   `RequestInFlightError` — a request is already in flight; retry when the shared scheduler and command processor become idle.
-   `ConnectorSupersededError` — a concurrent [setConnector](https://docs.maelstrom-ai.co/dev/reference/client/classes/orchestrator/#setconnector) replaced the connector while this request was in flight. The response was deliberately never applied locally. Server-side effects may be uncertain; do not automatically retry.
-   the transport’s own error — either an ordinary send failure, or the failure a swap itself caused when the outgoing connector was disconnected out from under this request. Both shapes mean the intent may have effects; do not automatically retry uncertain work.
-   `Error('Orchestrator is disposed')` — called after [dispose](https://docs.maelstrom-ai.co/dev/reference/client/classes/orchestrator/#dispose).

INVARIANTS:

-   Whenever a fenced outcome discards the response, the updates that rode along are requeued for the next flush — but the intent itself is not. Re-issuing it is the caller’s call to make.
-   A response that arrives after [dispose](https://docs.maelstrom-ai.co/dev/reference/client/classes/orchestrator/#dispose) still resolves here: the request was legitimately issued, it simply is never dispatched into a torn-down CommandProcessor.

#### Parameters

##### intent

`string`

#### Returns

`Promise`<`MaelstromResponse`\>

* * *

### scheduleUpdate()

> **scheduleUpdate**(`reason`): `void`

Defined in: [packages/client/src/lib/orchestrator/orchestrator.ts:807](https://github.com/maelstrom-co/maelstrom/blob/89a8f5e9d10cedcf0b30376d7846113f06f26120/packages/client/src/lib/orchestrator/orchestrator.ts#L807)

#### Parameters

##### reason

`ChartResizeReason` | `VesselMutationReason`

#### Returns

`void`

* * *

### sendMessage()

> **sendMessage**(`text`, `options?`): [`AgentMessageSubmission`](https://docs.maelstrom-ai.co/dev/reference/client/type-aliases/agentmessagesubmission/)

Defined in: [packages/client/src/lib/orchestrator/orchestrator.ts:696](https://github.com/maelstrom-co/maelstrom/blob/89a8f5e9d10cedcf0b30376d7846113f06f26120/packages/client/src/lib/orchestrator/orchestrator.ts#L696)

Send a message the user typed or said to the agent, with a Chart snapshot of the board as it stands now.

Returns at once with the message’s `inputId` and a `result` promise. The input appears in `agent.store` as `pending` right before the frame is handed to the connector. The agent answers through [agent](https://docs.maelstrom-ai.co/dev/reference/client/classes/orchestrator/#agent), and UI changes it plans are applied as they arrive, Layout first, then Actions.

`result` settles exactly once and never rejects. It carries the input’s Agent Run state at the moment it settled, which later events may still change in `agent.store`:

-   `finished`, `ignored` or `failed`: the agent handled the input.
-   `lost`: the outcome is unknown and the agent may have acted, so do not automatically resend it. Any `conversation_lost` settles every open input, and `send_failed` reports that the transport refused the frame.
-   `not_submitted`: the message never left the client, because the Orchestrator is disposed or not connected, or the connector cannot carry agent inputs, as with `HttpConnector`.

INVARIANTS:

-   Never throws and never reports busy. It does not wait for an intent, a flush, or command application.
-   Does not touch updates buffered for the next engine request. They stay queued for [processIntent](https://docs.maelstrom-ai.co/dev/reference/client/classes/orchestrator/#processintent) or [flushUpdates](https://docs.maelstrom-ai.co/dev/reference/client/classes/orchestrator/#flushupdates).
-   The returned `inputId` is the one the agent’s `placeholder`, `accepted` and `error` events for this message carry.
-   Tracks `result` independently of the store’s cap, so it settles even after newer inputs evicted the run from `agent.store`.
-   Starts the `agentRunStaleTimeoutMs` silence window for the message. If the agent neither accepts nor answers it in time, or the accepted Agent Run goes silent before `finished`, [agent](https://docs.maelstrom-ai.co/dev/reference/client/classes/orchestrator/#agent) emits `conversation_lost` with reason `stale_run`. Pass `Infinity` for the option to disable this.

The agent loop is experimental in 0.3 and may change in any minor release.

> [!WARNING]
> Experimental
> 
> This API should not be used in production and may be trimmed from a public release.

#### Parameters

##### text

`string`

##### options?

[`SendMessageOptions`](https://docs.maelstrom-ai.co/dev/reference/client/type-aliases/sendmessageoptions/)

#### Returns

[`AgentMessageSubmission`](https://docs.maelstrom-ai.co/dev/reference/client/type-aliases/agentmessagesubmission/)

* * *

### setConnector()

> **setConnector**(`next`): `void`

Defined in: [packages/client/src/lib/orchestrator/orchestrator.ts:1157](https://github.com/maelstrom-co/maelstrom/blob/89a8f5e9d10cedcf0b30376d7846113f06f26120/packages/client/src/lib/orchestrator/orchestrator.ts#L1157)

Replace the connector on a live Orchestrator, preserving the session.

Use this when the transport changes but the session does not — re-auth is the motivating case. The arranged board, vessel registry, and chart dimensions all survive; only the transport is swapped.

Any request already in flight is _fenced_, not cancelled: `EngineConnector` exposes no abort, so the old request runs to completion and its response is discarded rather than applied. The guarantee is scoped to dispatch: a response computed under superseded credentials is never handed to the CommandProcessor, so it cannot reach the UI — but it has already been committed to `requestCoordinator.lastResponse` and emitted as `processing_completed` by the time the fence runs, so anything subscribed to those two surfaces still observes it.

A caller’s pending [processIntent](https://docs.maelstrom-ai.co/dev/reference/client/classes/orchestrator/#processintent) always _rejects_ under a swap, in one of two shapes: [ConnectorSupersededError](https://docs.maelstrom-ai.co/dev/reference/client/classes/connectorsupersedederror/) when the response arrived after the swap, or the transport’s own error when the swap made the send itself fail (the outgoing connector was disconnected out from under it). Either way the intent took no effect and must be re-issued. A pending [flushUpdates](https://docs.maelstrom-ai.co/dev/reference/client/classes/orchestrator/#flushupdates) resolves `null` for both shapes instead — its updates are requeued, so there is nothing for the caller to redo.

#### Parameters

##### next

[`EngineConnector`](https://docs.maelstrom-ai.co/dev/reference/client/interfaces/engineconnector/)

#### Returns

`void`

* * *

### setLayoutMode()

> **setLayoutMode**(`mode`): `void`

Defined in: [packages/client/src/lib/orchestrator/orchestrator.ts:490](https://github.com/maelstrom-co/maelstrom/blob/89a8f5e9d10cedcf0b30376d7846113f06f26120/packages/client/src/lib/orchestrator/orchestrator.ts#L490)

Change the layout mode for subsequent engine requests.

The mode is read fresh on every request and view-state read — it is never captured at construction — so this takes effect on the next request with no rebuild and no session teardown. The client does not lay anything out itself; the mode is forwarded to the engine, which decides.

This does not touch the stored layout. If the stored layout’s own `type` no longer agrees with `mode`, `buildChartRequest` resynthesizes a fresh, empty layout of the requested type at request-build time instead of forwarding the stale one — see the comment there for why that has to happen at build time rather than here. That resynthesis costs the arranged board, so this warns when it commits to it: the same combination the constructor rejects outright is merely lossy here, and the loss is otherwise invisible.

#### Parameters

##### mode

`LayoutMode`

#### Returns

`void`
