# RealtimeInstance
Source: https://docs.maelstrom-ai.co/dev/reference/realtime/interfaces/realtimeinstance/
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/realtime/src/lib/realtime-session/realtime-session.types.ts:54](https://github.com/maelstrom-co/maelstrom/blob/89a8f5e9d10cedcf0b30376d7846113f06f26120/packages/realtime/src/lib/realtime-session/realtime-session.types.ts#L54)

The minimal bridge `RealtimeSession` needs from a Maelstrom instance. `Orchestrator` maps onto this via a small wrapper (`submitIntent` -> `processIntent`, `createIntentScope` -> the shared scheduler scope, and idle waits -> `commandProcessor.waitForIdle`) — this interface exists so the realtime package depends on a narrow seam rather than the whole `Orchestrator` surface. `getStructuralSnapshot` backs the `get_ui_state` pull (what’s on screen); `getCapabilitySnapshot` backs the `get_capabilities` pull (what CAN be shown).

`submitIntent` resolves with a [SubmitIntentResult](https://docs.maelstrom-ai.co/dev/reference/realtime/interfaces/submitintentresult/) carrying the engine’s conversational `userMessage`, so the session can speak the engine’s own reply instead of a structural summary once the change settles. It still rejects with `RequestInFlightError` while a prior intent is applying. Legacy instances are attempted once and report busy as not-submitted, without retry. Supply `createIntentScope` for bounded cross-source FIFO and exact outcomes.

## Properties

### applicationWork?

> `readonly` `optional` **applicationWork?**: `VoiceApplicationWorkSource`

Defined in: [packages/realtime/src/lib/realtime-session/realtime-session.types.ts:56](https://github.com/maelstrom-co/maelstrom/blob/89a8f5e9d10cedcf0b30376d7846113f06f26120/packages/realtime/src/lib/realtime-session/realtime-session.types.ts#L56)

Optional application-wide current work observations, including non-voice input.

## Methods

### addAssistantMessageAcknowledged()

> **addAssistantMessageAcknowledged**(`args`): `Promise`<`AssistantMessageOutcome`\>

Defined in: [packages/realtime/src/lib/realtime-session/realtime-session.types.ts:108](https://github.com/maelstrom-co/maelstrom/blob/89a8f5e9d10cedcf0b30376d7846113f06f26120/packages/realtime/src/lib/realtime-session/realtime-session.types.ts#L108)

Persist an assistant message with the engine’s existing MessageId dedup. `'inserted'` is positive evidence this runtime owns first insertion; `'deduped'` means an earlier attempt already landed.

#### Parameters

##### args

###### id

`MessageId`

###### message

`string`

#### Returns

`Promise`<`AssistantMessageOutcome`\>

* * *

### createIntentScope()?

> `optional` **createIntentScope**(): `IntentScope`

Defined in: [packages/realtime/src/lib/realtime-session/realtime-session.types.ts:64](https://github.com/maelstrom-co/maelstrom/blob/89a8f5e9d10cedcf0b30376d7846113f06f26120/packages/realtime/src/lib/realtime-session/realtime-session.types.ts#L64)

Creates one connection-owned lifetime backed by the application’s shared scheduler. Preferred over submitIntent when present. Retirement settles only pending work; active results remain observable after voice ends. Ticket results include response application settlement and must never reject. Queue capacity, wait and connection-loss bounds belong to the client policy.

#### Returns

`IntentScope`

* * *

### getCapabilitySnapshot()

> **getCapabilitySnapshot**(): `CapabilitySnapshot`

Defined in: [packages/realtime/src/lib/realtime-session/realtime-session.types.ts:101](https://github.com/maelstrom-co/maelstrom/blob/89a8f5e9d10cedcf0b30376d7846113f06f26120/packages/realtime/src/lib/realtime-session/realtime-session.types.ts#L101)

#### Returns

`CapabilitySnapshot`

* * *

### getStructuralSnapshot()

> **getStructuralSnapshot**(): `UIStructuralSnapshot`

Defined in: [packages/realtime/src/lib/realtime-session/realtime-session.types.ts:100](https://github.com/maelstrom-co/maelstrom/blob/89a8f5e9d10cedcf0b30376d7846113f06f26120/packages/realtime/src/lib/realtime-session/realtime-session.types.ts#L100)

#### Returns

`UIStructuralSnapshot`

* * *

### observeEngineConnection()

> **observeEngineConnection**(`cb`): `Unsubscribe`

Defined in: [packages/realtime/src/lib/realtime-session/realtime-session.types.ts:118](https://github.com/maelstrom-co/maelstrom/blob/89a8f5e9d10cedcf0b30376d7846113f06f26120/packages/realtime/src/lib/realtime-session/realtime-session.types.ts#L118)

Observe engine connection readiness. Subscribe first, then the current status is delivered synchronously (subscribe-then-snapshot), so an already-connected engine resolves immediately and a not-connected engine delivers `false` now and `true` on the next transition.

#### Parameters

##### cb

(`connected`) => `void`

#### Returns

`Unsubscribe`

* * *

### onSettled()

> **onSettled**(`cb`): `Unsubscribe`

Defined in: [packages/realtime/src/lib/realtime-session/realtime-session.types.ts:102](https://github.com/maelstrom-co/maelstrom/blob/89a8f5e9d10cedcf0b30376d7846113f06f26120/packages/realtime/src/lib/realtime-session/realtime-session.types.ts#L102)

#### Parameters

##### cb

() => `void`

#### Returns

`Unsubscribe`

* * *

### sendAgentMessage()?

> `optional` **sendAgentMessage**(`text`): `Promise`<`SettledAgentRun`\>

Defined in: [packages/realtime/src/lib/realtime-session/realtime-session.types.ts:75](https://github.com/maelstrom-co/maelstrom/blob/89a8f5e9d10cedcf0b30376d7846113f06f26120/packages/realtime/src/lib/realtime-session/realtime-session.types.ts#L75)

Sends one `submit_intent` intent as an agent message and resolves with the input’s Agent Run state once it settled, the `result` that `Orchestrator.sendMessage` returns. A run can finish before its UI changes are applied. Preferred over `createIntentScope` and `submitIntent` when present. Must never reject. A `lost` state is an unknown outcome and is never replayed.

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`

#### Returns

`Promise`<`SettledAgentRun`\>

* * *

### submitIntent()

> **submitIntent**(`intent`): `Promise`<[`SubmitIntentResult`](https://docs.maelstrom-ai.co/dev/reference/realtime/interfaces/submitintentresult/)\>

Defined in: [packages/realtime/src/lib/realtime-session/realtime-session.types.ts:77](https://github.com/maelstrom-co/maelstrom/blob/89a8f5e9d10cedcf0b30376d7846113f06f26120/packages/realtime/src/lib/realtime-session/realtime-session.types.ts#L77)

Legacy immediate admission; called once, with no busy retry or FIFO guarantee.

#### Parameters

##### intent

`string`

#### Returns

`Promise`<[`SubmitIntentResult`](https://docs.maelstrom-ai.co/dev/reference/realtime/interfaces/submitintentresult/)\>

* * *

### waitForIdle()

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

Defined in: [packages/realtime/src/lib/realtime-session/realtime-session.types.ts:79](https://github.com/maelstrom-co/maelstrom/blob/89a8f5e9d10cedcf0b30376d7846113f06f26120/packages/realtime/src/lib/realtime-session/realtime-session.types.ts#L79)

Legacy global settle wait, unused for scoped ticket results.

#### Returns

`Promise`<`void`\>

* * *

### waitForIdleResult()?

> `optional` **waitForIdleResult**(): `Promise`<`Result`<`void`, `Error`\>>

Defined in: [packages/realtime/src/lib/realtime-session/realtime-session.types.ts:99](https://github.com/maelstrom-co/maelstrom/blob/89a8f5e9d10cedcf0b30376d7846113f06f26120/packages/realtime/src/lib/realtime-session/realtime-session.types.ts#L99)

Result-bearing settle wait, preferred over [RealtimeInstance.waitForIdle](https://docs.maelstrom-ai.co/dev/reference/realtime/interfaces/realtimeinstance/#waitforidle) wherever the session needs to know whether the settled work succeeded.

It is optional so that an instance written against the void-only [RealtimeInstance.waitForIdle](https://docs.maelstrom-ai.co/dev/reference/realtime/interfaces/realtimeinstance/#waitforidle) still satisfies this interface; a session that finds it absent falls back to that wait and can only treat every settle as successful. An `Orchestrator`\-backed instance supplies it directly, because `commandProcessor.waitForIdle()` already resolves with this Result.

A `!ok` result means the settled work failed — a refused `set_layout` (duplicate tiling leaf, malformed weight token) being the ordinary case. Such a refusal neither throws nor rejects and leaves the previous screen in place, so this is the only signal that the intent changed nothing, and `RealtimeSession` answers the `submit_intent` tool call as a failure rather than describing a snapshot the intent never produced. A rejection leaves the application outcome unconfirmed and must not trigger automatic replay.

#### Returns

`Promise`<`Result`<`void`, `Error`\>>
