---
url: >-
  https://adk.nht.io/api/@nhtio/adk/batteries/llm/webllm_chat_completions/adapter/classes/WebLLMChatCompletionsAdapter.md
description: >-
  Opinionated cross-environment LLM adapter for the WebLLM Chat Completions wire
  shape.
---

# Class: WebLLMChatCompletionsAdapter

Defined in: [batteries/llm/webllm\_chat\_completions/adapter.ts:241](https://github.com/NHTIO/ADK/blob/v1.20260605.0/src/batteries/llm/webllm_chat_completions/adapter.ts#L241)

Opinionated cross-environment LLM adapter for the WebLLM Chat Completions wire shape.

## Remarks

Construction validates options eagerly via [@nhtio/adk/batteries!validateOptions](../../../openai_chat_completions/validation/functions/validateOptions.md) and throws
[@nhtio/adk/batteries!E\_INVALID\_WEBLLM\_CHAT\_COMPLETIONS\_OPTIONS](../../exceptions/variables/E_INVALID_WEBLLM_CHAT_COMPLETIONS_OPTIONS.md) on failure — config bugs fail loud, not at
dispatch time. The returned instance is reusable: call [WebLLMChatCompletionsAdapter.executor](#executor)
once per `DispatchRunner` configuration to obtain an [@nhtio/adk!DispatchExecutorFn](../../../../../dispatch_runner/type-aliases/DispatchExecutorFn.md) bound to the
baseline plus optional executor-scope overrides.

Per-iteration overrides live on the active [@nhtio/adk!DispatchContext](../../../../../types/interfaces/DispatchContext.md)'s
`stash.webLLMChatCompletions` slot and take highest precedence — they merge into the
executor-scope shape on every iteration. `helpers` merge key-by-key across all three layers;
every other field is replaced wholesale at the highest layer that
sets it.

## Constructors

### Constructor

```ts
new WebLLMChatCompletionsAdapter(options: unknown): WebLLMChatCompletionsAdapter;
```

Defined in: [batteries/llm/webllm\_chat\_completions/adapter.ts:267](https://github.com/NHTIO/ADK/blob/v1.20260605.0/src/batteries/llm/webllm_chat_completions/adapter.ts#L267)

#### Parameters

| Parameter | Type      | Description                                                                                                                  |
| --------- | --------- | ---------------------------------------------------------------------------------------------------------------------------- |
| `options` | `unknown` | Constructor-baseline options. Re-validated on every iteration after per-dispatch and per-iteration overrides are layered in. |

#### Returns

`WebLLMChatCompletionsAdapter`

#### Throws

[@nhtio/adk/batteries!E\_INVALID\_WEBLLM\_CHAT\_COMPLETIONS\_OPTIONS](../../exceptions/variables/E_INVALID_WEBLLM_CHAT_COMPLETIONS_OPTIONS.md) when `options` does not satisfy
[@nhtio/adk/batteries!webLLMChatCompletionsOptionsSchema](../../validation/variables/webLLMChatCompletionsOptionsSchema.md).

## Properties

| Property                                    | Modifier   | Type                      | Description                                                                                                                                                                                                                   | Defined in                                                                                                                                                        |
| ------------------------------------------- | ---------- | ------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|  `STASH_KEY` | `readonly` | `"webLLMChatCompletions"` | Customary key for per-iteration overrides on `ctx.stash`. The adapter reads `ctx.stash.get(WebLLMChatCompletionsAdapter.STASH_KEY, {})` at the start of every iteration and merges the value into the resolved options shape. | [batteries/llm/webllm\_chat\_completions/adapter.ts:247](https://github.com/NHTIO/ADK/blob/v1.20260605.0/src/batteries/llm/webllm_chat_completions/adapter.ts#L247) |

## Methods

### executor()

```ts
executor(overrides?: Partial<WebLLMChatCompletionsAdapterOptions>): DispatchExecutorFn;
```

Defined in: [batteries/llm/webllm\_chat\_completions/adapter.ts:330](https://github.com/NHTIO/ADK/blob/v1.20260605.0/src/batteries/llm/webllm_chat_completions/adapter.ts#L330)

Returns an [@nhtio/adk!DispatchExecutorFn](../../../../../dispatch_runner/type-aliases/DispatchExecutorFn.md) bound to this adapter's baseline plus optional
executor-scope overrides. The returned function is reusable across iterations — every
iteration re-merges with `ctx.stash[STASH_KEY]` and re-validates the result.

#### Parameters

| Parameter    | Type                                                                                                                                                                                               | Description                                                                                                           |
| ------------ | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | --------------------------------------------------------------------------------------------------------------------- |
| `overrides?` | [`Partial`](https://www.typescriptlang.org/docs/handbook/utility-types.html#partialtype)<[`WebLLMChatCompletionsAdapterOptions`](../../../../interfaces/WebLLMChatCompletionsAdapterOptions.md)> | Optional executor-scope overrides. Higher precedence than the baseline, lower precedence than `ctx.stash[STASH_KEY]`. |

#### Returns

[`DispatchExecutorFn`](../../../../../dispatch_runner/type-aliases/DispatchExecutorFn.md)

An [@nhtio/adk!DispatchExecutorFn](../../../../../dispatch_runner/type-aliases/DispatchExecutorFn.md) suitable for `DispatchRunner`.

***

### isAvailable()

```ts
isAvailable(): boolean;
```

Defined in: [batteries/llm/webllm\_chat\_completions/adapter.ts:282](https://github.com/NHTIO/ADK/blob/v1.20260605.0/src/batteries/llm/webllm_chat_completions/adapter.ts#L282)

#### Returns

`boolean`

***

### preload()

```ts
preload(overrides?: Partial<WebLLMChatCompletionsAdapterOptions>): Promise<MLCEngineInterface>;
```

Defined in: [batteries/llm/webllm\_chat\_completions/adapter.ts:272](https://github.com/NHTIO/ADK/blob/v1.20260605.0/src/batteries/llm/webllm_chat_completions/adapter.ts#L272)

#### Parameters

| Parameter    | Type                                                                                                                                                                                               |
| ------------ | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `overrides?` | [`Partial`](https://www.typescriptlang.org/docs/handbook/utility-types.html#partialtype)<[`WebLLMChatCompletionsAdapterOptions`](../../../../interfaces/WebLLMChatCompletionsAdapterOptions.md)> |

#### Returns

`Promise`<`MLCEngineInterface`>

***

### reset()

```ts
reset(): void;
```

Defined in: [batteries/llm/webllm\_chat\_completions/adapter.ts:277](https://github.com/NHTIO/ADK/blob/v1.20260605.0/src/batteries/llm/webllm_chat_completions/adapter.ts#L277)

#### Returns

`void`

***

### isAvailable()

```ts
static isAvailable(): boolean;
```

Defined in: [batteries/llm/webllm\_chat\_completions/adapter.ts:253](https://github.com/NHTIO/ADK/blob/v1.20260605.0/src/batteries/llm/webllm_chat_completions/adapter.ts#L253)

#### Returns

`boolean`

***

### isWebLLMChatCompletionsAdapter()

```ts
static isWebLLMChatCompletionsAdapter(value: unknown): value is WebLLMChatCompletionsAdapter;
```

Defined in: [batteries/llm/webllm\_chat\_completions/adapter.ts:995](https://github.com/NHTIO/ADK/blob/v1.20260605.0/src/batteries/llm/webllm_chat_completions/adapter.ts#L995)

Returns `true` when `value` is an WebLLMChatCompletionsAdapter instance.

#### Parameters

| Parameter | Type      | Description        |
| --------- | --------- | ------------------ |
| `value`   | `unknown` | The value to test. |

#### Returns

`value is WebLLMChatCompletionsAdapter`

`true` when `value` is an `WebLLMChatCompletionsAdapter` instance.
