---
url: 'https://adk.nht.io/api/@nhtio/adk/batteries/classes/HostEndpoint.md'
description: >-
  Host-side correlation engine over a [`PortLike`](https://adk.nht.io/api/@nhtio/adk/batteries/interfaces/PortLike). Queues
  calls/stream-starts made before `ready` and flushes them in order once it
  arrives; tracks in-flight calls (one-shot, resolved/rejected by a `result`
  envelope) and open streams (persistent, fed by
  `stream:delta`/`stream:end`/`stream:error` until closed). `terminate()`
  rejects every in-flight call and errors every open stream with a
  caller-supplied reason (the message text `host.ts` uses is
  `E_ISOLATED_TERMINATED`'s message).
---

# Class: HostEndpoint

Defined in: [src/batteries/isolation/protocol.ts:143](https://github.com/NHTIO/ADK/blob/v1.20261103.0/src/src/batteries/isolation/protocol.ts#L143)

Host-side correlation engine over a [PortLike](../interfaces/PortLike.md). Queues calls/stream-starts made before `ready`
and flushes them in order once it arrives; tracks in-flight calls (one-shot, resolved/rejected by a
`result` envelope) and open streams (persistent, fed by `stream:delta`/`stream:end`/`stream:error`
until closed). `terminate()` rejects every in-flight call and errors every open stream with a
caller-supplied reason (the message text `host.ts` uses is `E_ISOLATED_TERMINATED`'s message).

## Constructors

### Constructor

```ts
new HostEndpoint(
   port: PortLike,
   hooks?: HostEndpointHooks,
   hostcalls?: {
  handlers?: ReadonlyMap<string, HostcallHandler>;
  maxHostcallBytes?: number;
  quotas?: HostcallQuotas;
}): HostEndpoint;
```

Defined in: [src/batteries/isolation/protocol.ts:158](https://github.com/NHTIO/ADK/blob/v1.20261103.0/src/src/batteries/isolation/protocol.ts#L158)

#### Parameters

| Parameter                     | Type                                                                                                                         |
| ----------------------------- | ---------------------------------------------------------------------------------------------------------------------------- |
| `port`                        | [`PortLike`](../interfaces/PortLike.md)                                                                                      |
| `hooks`                       | [`HostEndpointHooks`](../interfaces/HostEndpointHooks.md)                                                                    |
| `hostcalls`                   | { `handlers?`: `ReadonlyMap`<`string`, `HostcallHandler`>; `maxHostcallBytes?`: `number`; `quotas?`: `HostcallQuotas`; } |
| `hostcalls.handlers?`         | `ReadonlyMap`<`string`, `HostcallHandler`>                                                                                 |
| `hostcalls.maxHostcallBytes?` | `number`                                                                                                                     |
| `hostcalls.quotas?`           | `HostcallQuotas`                                                                                                             |

#### Returns

`HostEndpoint`

## Accessors

### isReady

#### Get Signature

```ts
get isReady(): boolean;
```

Defined in: [src/batteries/isolation/protocol.ts:176](https://github.com/NHTIO/ADK/blob/v1.20261103.0/src/src/batteries/isolation/protocol.ts#L176)

Whether the guest has signaled `ready` yet.

##### Returns

`boolean`

***

### openStreamCount

#### Get Signature

```ts
get openStreamCount(): number;
```

Defined in: [src/batteries/isolation/protocol.ts:188](https://github.com/NHTIO/ADK/blob/v1.20261103.0/src/src/batteries/isolation/protocol.ts#L188)

Number of streams currently open (started, not yet ended/errored). Used by `host.ts` alongside
[pendingCallCount](#pendingcallcount) to report an accurate `inFlight` count on a crash.

##### Returns

`number`

***

### pendingCallCount

#### Get Signature

```ts
get pendingCallCount(): number;
```

Defined in: [src/batteries/isolation/protocol.ts:182](https://github.com/NHTIO/ADK/blob/v1.20261103.0/src/src/batteries/isolation/protocol.ts#L182)

Number of calls currently awaiting a `result` envelope. Used by `host.ts` to report an accurate
`inFlight` count on a crash before `terminate()` clears the pending map.

##### Returns

`number`

## Methods

### abort()

```ts
abort(id: string): void;
```

Defined in: [src/batteries/isolation/protocol.ts:351](https://github.com/NHTIO/ADK/blob/v1.20261103.0/src/src/batteries/isolation/protocol.ts#L351)

Send an `abort` envelope for an in-flight call's id. Does not itself reject the call — the guest
is expected to respond with a `result` (ok:false) once it observes the abort.

#### Parameters

| Parameter | Type     |
| --------- | -------- |
| `id`      | `string` |

#### Returns

`void`

***

### call()

```ts
call(method: string, args: WireValue[]): {
  id: string;
  promise: Promise<WireValue>;
};
```

Defined in: [src/batteries/isolation/protocol.ts:261](https://github.com/NHTIO/ADK/blob/v1.20261103.0/src/src/batteries/isolation/protocol.ts#L261)

Issue a request/response call. Resolves with the guest's returned [WireValue](../type-aliases/WireValue.md), rejects with a
reconstructed `Error` (see [wireErrorToError](../functions/wireErrorToError.md)) on failure or on `terminate()`.

#### Parameters

| Parameter | Type                                          |
| --------- | --------------------------------------------- |
| `method`  | `string`                                      |
| `args`    | [`WireValue`](../type-aliases/WireValue.md)\[] |

#### Returns

```ts
{
  id: string;
  promise: Promise<WireValue>;
}
```

| Name      | Type                                                     | Defined in                                                                                                                              |
| --------- | -------------------------------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------- |
| `id`      | `string`                                                 | [src/batteries/isolation/protocol.ts:261](https://github.com/NHTIO/ADK/blob/v1.20261103.0/src/src/batteries/isolation/protocol.ts#L261) |
| `promise` | `Promise`<[`WireValue`](../type-aliases/WireValue.md)> | [src/batteries/isolation/protocol.ts:261](https://github.com/NHTIO/ADK/blob/v1.20261103.0/src/src/batteries/isolation/protocol.ts#L261) |

***

### cancelStream()

```ts
cancelStream(id: string, reason?: WireValue): void;
```

Defined in: [src/batteries/isolation/protocol.ts:368](https://github.com/NHTIO/ADK/blob/v1.20261103.0/src/src/batteries/isolation/protocol.ts#L368)

Send a `stream:cancel` envelope and stop tracking the stream locally.

#### Parameters

| Parameter | Type                                        |
| --------- | ------------------------------------------- |
| `id`      | `string`                                    |
| `reason?` | [`WireValue`](../type-aliases/WireValue.md) |

#### Returns

`void`

***

### hostresult()

```ts
hostresult(id: string, result:
  | {
  ok: true;
  value: string | WireValue;
}
  | {
  error?: WireError;
  ok: false;
  value?: string;
}): void;
```

Defined in: [src/batteries/isolation/protocol.ts:339](https://github.com/NHTIO/ADK/blob/v1.20261103.0/src/src/batteries/isolation/protocol.ts#L339)

Post a guest capability result. Unknown/late ids are harmlessly ignored by the guest.

#### Parameters

| Parameter | Type                                                                                                                                                                                      |
| --------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `id`      | `string`                                                                                                                                                                                  |
| `result`  | | { `ok`: `true`; `value`: `string` | [`WireValue`](../type-aliases/WireValue.md); } | { `error?`: [`WireError`](../interfaces/WireError.md); `ok`: `false`; `value?`: `string`; } |

#### Returns

`void`

***

### shutdown()

```ts
shutdown(): void;
```

Defined in: [src/batteries/isolation/protocol.ts:374](https://github.com/NHTIO/ADK/blob/v1.20261103.0/src/src/batteries/isolation/protocol.ts#L374)

Send a `shutdown` envelope (graceful-exit request; does not itself tear down the port).

#### Returns

`void`

***

### startStream()

```ts
startStream(
   stream: string,
   args: WireValue[],
   sink: StreamSink): string;
```

Defined in: [src/batteries/isolation/protocol.ts:360](https://github.com/NHTIO/ADK/blob/v1.20261103.0/src/src/batteries/isolation/protocol.ts#L360)

Start a fire-and-forward stream. Returns the correlation id immediately (before the guest
necessarily even exists, if not yet `ready`) and a `sink` the caller wires to a `ReadableStream`
controller.

#### Parameters

| Parameter | Type                                          |
| --------- | --------------------------------------------- |
| `stream`  | `string`                                      |
| `args`    | [`WireValue`](../type-aliases/WireValue.md)\[] |
| `sink`    | `StreamSink`                                  |

#### Returns

`string`

***

### terminate()

```ts
terminate(reason: string): void;
```

Defined in: [src/batteries/isolation/protocol.ts:382](https://github.com/NHTIO/ADK/blob/v1.20261103.0/src/src/batteries/isolation/protocol.ts#L382)

Reject every in-flight call and error every open stream with `reason`, clear all queued-but-unsent
envelopes, and unsubscribe from the port. Idempotent.

#### Parameters

| Parameter | Type     |
| --------- | -------- |
| `reason`  | `string` |

#### Returns

`void`
