# PushConnector
Source: https://docs.maelstrom-ai.co/dev/reference/client/interfaces/pushconnector/
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/connection-manager/connector.types.ts:555](https://github.com/maelstrom-co/maelstrom/blob/89a8f5e9d10cedcf0b30376d7846113f06f26120/packages/client/src/lib/connection-manager/connector.types.ts#L555)

Extension for connectors that support server-initiated (push) messages.

Push messages are unsolicited responses from the engine, typically triggered by voice interactions where the engine responds without a client request.

## Example

```typescript
if ('onPushMessage' in connector) {
  (connector as PushConnector).onPushMessage((response) => {
    commandProcessor.setLayout(response.layout);
    commandProcessor.executeActions(response.executionPlan);
  });
}
```

## Extends

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

## Properties

### capabilities

> `readonly` **capabilities**: [`ConnectorCapabilities`](https://docs.maelstrom-ai.co/dev/reference/client/interfaces/connectorcapabilities/)

Defined in: [packages/client/src/lib/connection-manager/connector.types.ts:322](https://github.com/maelstrom-co/maelstrom/blob/89a8f5e9d10cedcf0b30376d7846113f06f26120/packages/client/src/lib/connection-manager/connector.types.ts#L322)

Connector capabilities. Metadata for consumers — the ConnectionManager does not use these for flow control.

#### Inherited from

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

## Methods

### addAssistantMessage()

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

Defined in: [packages/client/src/lib/connection-manager/connector.types.ts:447](https://github.com/maelstrom-co/maelstrom/blob/89a8f5e9d10cedcf0b30376d7846113f06f26120/packages/client/src/lib/connection-manager/connector.types.ts#L447)

Add an assistant message to conversation history without LLM processing. Used for programmatic messages (greetings, notifications).

This legacy capability is fire-and-forget: it resolves after the transport accepts the send and does not confirm insertion. Use [AcknowledgedAssistantConnector.addAssistantMessageAcknowledged](https://docs.maelstrom-ai.co/dev/reference/client/interfaces/acknowledgedassistantconnector/#addassistantmessageacknowledged) when dependent side effects require a correlated engine outcome.

#### Parameters

##### message

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

#### Returns

`Promise`<`void`\>

#### Inherited from

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

* * *

### connect()

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

Defined in: [packages/client/src/lib/connection-manager/connector.types.ts:335](https://github.com/maelstrom-co/maelstrom/blob/89a8f5e9d10cedcf0b30376d7846113f06f26120/packages/client/src/lib/connection-manager/connector.types.ts#L335)

Establish the transport connection. Resolves when the connection is ready to use. Throws if the connection cannot be established (ConnectionManager retries).

For stateless transports (HTTP), this may be a no-op or a health check.

#### Parameters

##### sessionId

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

The canonical session ID generated by the Provider/Orchestrator. Transports may use it to namespace server-side state (e.g. conversation history) so every channel of a session shares a single namespace with engine requests.

#### Returns

`Promise`<`void`\>

#### Inherited from

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

* * *

### disconnect()

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

Defined in: [packages/client/src/lib/connection-manager/connector.types.ts:341](https://github.com/maelstrom-co/maelstrom/blob/89a8f5e9d10cedcf0b30376d7846113f06f26120/packages/client/src/lib/connection-manager/connector.types.ts#L341)

Close the transport connection. For stateless transports (HTTP), this is a no-op.

#### Returns

`Promise`<`void`\>

#### Inherited from

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

* * *

### getHistory()

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

Defined in: [packages/client/src/lib/connection-manager/connector.types.ts:464](https://github.com/maelstrom-co/maelstrom/blob/89a8f5e9d10cedcf0b30376d7846113f06f26120/packages/client/src/lib/connection-manager/connector.types.ts#L464)

Fetch the engine-recorded history for the given session.

Used by clients that persist a session id and need to rehydrate the conversation after a refresh, on a different device, or in a parallel tab. The session id is supplied explicitly (not taken from the connector’s current connection) so callers can fetch any session they have an id for — including a session that predates the current orchestrator instance.

Implementations translate transport / engine errors into thrown `Error`s, matching the existing `process` and `addAssistantMessage` shape. Whether an unknown or empty session resolves to `[]` or rejects is the engine’s call (the reference engine resolves to `[]`); connectors do not synthesize that behavior themselves.

#### Parameters

##### sessionId

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

#### Returns

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

#### Inherited from

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

* * *

### onEvent()

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

Defined in: [packages/client/src/lib/connection-manager/connector.types.ts:491](https://github.com/maelstrom-co/maelstrom/blob/89a8f5e9d10cedcf0b30376d7846113f06f26120/packages/client/src/lib/connection-manager/connector.types.ts#L491)

Subscribe to decoded AgentEvents the engine sends over the Agent Session wire.

Transports that never carry agent events return a no-op unsubscribe and never invoke the handler. Connection status changes arrive through [EngineConnector.subscribe](https://docs.maelstrom-ai.co/dev/reference/client/interfaces/engineconnector/#subscribe) instead.

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

#### Parameters

##### handler

(`event`) => `void`

Callback invoked for each decoded agent event

#### Returns

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

Unsubscribe function to remove the handler

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

#### Inherited from

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

* * *

### onPushMessage()

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

Defined in: [packages/client/src/lib/connection-manager/connector.types.ts:559](https://github.com/maelstrom-co/maelstrom/blob/89a8f5e9d10cedcf0b30376d7846113f06f26120/packages/client/src/lib/connection-manager/connector.types.ts#L559)

Subscribe to unsolicited responses from the engine.

#### Parameters

##### callback

(`response`) => `void`

#### Returns

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

* * *

### process()

> **process**(`message`): `Promise`<`MaelstromResponse`\>

Defined in: [packages/client/src/lib/connection-manager/connector.types.ts:354](https://github.com/maelstrom-co/maelstrom/blob/89a8f5e9d10cedcf0b30376d7846113f06f26120/packages/client/src/lib/connection-manager/connector.types.ts#L354)

Send a chart\_request envelope to the engine and return the response.

The envelope (ChartRequestMessage) carries `sessionId`, `id`, and `timestamp` — used by the engine for response correlation and session routing. Implementations should use `message.id` for any request/response correlation logic.

Round-trip guarantee: the returned `MaelstromResponse.requestId` always equals `message.id`, regardless of the underlying transport.

#### Parameters

##### message

`ChartRequestMessage`

#### Returns

`Promise`<`MaelstromResponse`\>

#### Inherited from

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

* * *

### sendInput()

> **sendInput**(`input`): `Promise`<`void`\>

Defined in: [packages/client/src/lib/connection-manager/connector.types.ts:476](https://github.com/maelstrom-co/maelstrom/blob/89a8f5e9d10cedcf0b30376d7846113f06f26120/packages/client/src/lib/connection-manager/connector.types.ts#L476)

Send one AgentInput to the engine over the Agent Session wire.

Resolves when the transport accepted the frame and does not wait for any AgentEvent. Rejects when the transport is not connected, no session is established, or the transport cannot carry agent inputs, in which case it rejects with [AgentWireUnsupportedError](https://docs.maelstrom-ai.co/dev/reference/client/classes/agentwireunsupportederror/).

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

##### input

`AgentInput`

#### Returns

`Promise`<`void`\>

#### Inherited from

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

* * *

### subscribe()

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

Defined in: [packages/client/src/lib/connection-manager/connector.types.ts:436](https://github.com/maelstrom-co/maelstrom/blob/89a8f5e9d10cedcf0b30376d7846113f06f26120/packages/client/src/lib/connection-manager/connector.types.ts#L436)

Subscribe to transport-level events.

**THIS IS THE CRITICAL METHOD FOR CONNECTIONMANAGER**

The ConnectionManager uses these events to:

-   Detect unexpected disconnections and trigger auto-reconnect
-   Update connection state (disconnected, error)
-   Log transport errors for monitoring

## Events to Emit:

### `disconnected` (REQUIRED for stateful connectors)

Emit when the transport closes (cleanly or unexpectedly).

```typescript
// Clean disconnect (user clicked disconnect button)
handler({ type: 'disconnected', clean: true, message: 'User disconnected' });

// Unexpected disconnect (network failure, server crash)
handler({ type: 'disconnected', clean: false, message: 'Network error' });

// Server rejected this client outright (e.g. WebSocket close code 1008) —
// retrying would just be rejected again, so flag it non-retryable.
handler({ type: 'disconnected', clean: false, message: 'Policy violation', retryable: false });
```

ConnectionManager behavior:

-   `clean: true` → No auto-reconnect (intentional disconnect)
-   `clean: false` → Auto-reconnect with exponential backoff
-   `retryable: false` → Opens the circuit breaker immediately instead of auto-reconnecting, regardless of `clean`. Omit for the default `clean`\-based behavior.

### `error` (Optional but recommended)

Emit when transport-level errors occur (distinct from disconnects).

```typescript
handler({ type: 'error', error: new Error('WebSocket error') });
```

## Implementation Pattern:

```typescript
subscribe(handler: (event: ConnectorEvent) => void): Unsubscribe {
  // Store the handler
  this.handlers.add(handler);

  // Set up transport event listeners
  this.ws.onclose = (event) => {
    handler({
      type: 'disconnected',
      clean: event.code === 1000,
      message: event.reason || `Closed with code ${event.code}`,
    });
  };

  this.ws.onerror = () => {
    handler({ type: 'error', error: new Error('WebSocket error') });
  };

  // Return unsubscribe function
  return () => this.handlers.delete(handler);
}
```

## HTTP (Stateless) Implementation:

```typescript
subscribe(_handler: (event: ConnectorEvent) => void): Unsubscribe {
  // HTTP never emits transport events
  return () => {};
}
```

#### Parameters

##### handler

(`event`) => `void`

Callback invoked when transport events occur

#### Returns

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

Unsubscribe function to remove the handler

#### See

CONNECTOR\_GUIDE.md for detailed examples

#### Inherited from

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