# WasmMentorOrchestrator class

> The WasmMentorOrchestrator class of Novior.MentorAgent.Blazor.Services: WASM implementation of IMentorOrchestrator. Delegates all operations to…

- URL: https://docs.mentoragent.net/api/novior-mentoragent-blazor-services/wasmmentororchestrator
- Verified with: MentorAgent 1.2.0
- Last updated: 2026-10-27
- Packages: Novior.MentorAgent.Blazor

WASM implementation of [`IMentorOrchestrator`](https://docs.mentoragent.net/api/novior-mentoragent-abstractions-interfaces/imentororchestrator). Delegates all operations to [`MentorHubClient`](https://docs.mentoragent.net/api/novior-mentoragent-blazor-hub/mentorhubclient) (SignalR). Before each `SendMessageAsync`, sends the current page context snapshot to the server so the AI has the correct page state.

## Definition

Namespace: `Novior.MentorAgent.Blazor.Services`. Package: `Novior.MentorAgent.Blazor`.

`public sealed class WasmMentorOrchestrator : IAsyncDisposable, IMentorOrchestrator`

Implements [`IMentorOrchestrator`](https://docs.mentoragent.net/api/novior-mentoragent-abstractions-interfaces/imentororchestrator).

```shell
dotnet add package Novior.MentorAgent.Blazor
```

## Constructors

`public WasmMentorOrchestrator(MentorHubClient hub, WasmMentorPageContext pageContext, ILogger<WasmMentorOrchestrator> logger, HttpClient http, MentorAgentBlazorOptions? options = null)`

## Methods

### `CancelCurrentRequest`

`public void CancelCurrentRequest()`

Stops the in-flight AI turn. This goes over HTTP, NOT the hub: SignalR dispatches at most one hub invocation at a time per connection, so a `CancelRequest` hub call would queue behind the still-running `SendMessage` and only run after the turn it was meant to abort had finished — i.e. the Stop button would appear to do nothing. Same reasoning as the HITL approval in `WasmMentorStateService`.

### `DisposeAsync`

`public ValueTask DisposeAsync()`

### `InitializeAsync`

`public Task InitializeAsync(CancellationToken ct = default)`

Ensures the SignalR connection is established.

### `ResetSessionAsync`

`public Task ResetSessionAsync(CancellationToken ct = default)`

Starts a new conversation on the server. With no live hub connection there is nothing to reset — the hub connects on the first message, and every connection gets its own server scope, so the next message starts a new conversation anyway (BUG-109: invoking a hub that is not connected threw into the page and raised the Blazor error bar). Connecting only to reset would build a coordinator for an empty conversation.

### `RespondToApprovalAsync`

`public Task RespondToApprovalAsync(ConfirmationRequest req, bool approved, CancellationToken ct = default)`

Answers a pending HITL confirmation. Over HTTP, for the same reason as [`WasmMentorOrchestrator.CancelCurrentRequest`](https://docs.mentoragent.net/api/novior-mentoragent-blazor-services/wasmmentororchestrator#cancelcurrentrequest): the turn that raised the confirmation is parked inside `SendMessage`, and SignalR dispatches one invocation at a time per connection — so a `RespondToApproval` hub call would queue behind the very turn it is meant to release and never run. The server README marks that hub method "do not use" for exactly this.

The built-in widget answers through `IMentorStateService`, which already took the HTTP path; this method exists for hosts that drive approval from their own UI, and it must behave the same on WebAssembly as it does on Blazor Server.

### `RestoreSessionAsync`

`public Task RestoreSessionAsync(JsonElement snapshot, CancellationToken ct = default)`

Not available through this interface on WebAssembly: the `AgentSession` lives in the server's DI scope. The server hands it to a client over HTTP — `GET` and `POST``/mentor/session?connectionId=` with [`MentorHubClient.ConnectionId`](https://docs.mentoragent.net/api/novior-mentoragent-blazor-hub/mentorhubclient#connectionid), described in the Novior.MentorAgent.Blazor README — as an opaque snapshot bound to the signed-in user.

This throws rather than returning `null` on purpose. Null is the documented answer for "no conversation yet", so returning it here would tell a WebAssembly host that it had nothing worth saving — and it would dutifully store nothing, every time, and never find out why the restore did nothing either. That is the shape of defect this suite exists to find; an exception at development time is the honest alternative.

### `SendMessageAsync`

`public Task SendMessageAsync(string userMessage, CancellationToken ct = default)`

`public Task SendMessageAsync(MentorUserMessage message, CancellationToken ct = default)`

Sends a turn. With a language it goes to the hub's `SendUserMessage`; without one to `SendMessage`, as before, so a page with no language of its own still works with a server older than the method.

`public Task SendMessageAsync(string userMessage, IReadOnlyList<MentorAttachment>? attachments, CancellationToken ct = default)`

### `SerializeSessionAsync`

`public Task<JsonElement?> SerializeSessionAsync(CancellationToken ct = default)`

Not available through this interface on WebAssembly: the `AgentSession` lives in the server's DI scope. The server hands it to a client over HTTP — `GET` and `POST``/mentor/session?connectionId=` with [`MentorHubClient.ConnectionId`](https://docs.mentoragent.net/api/novior-mentoragent-blazor-hub/mentorhubclient#connectionid), described in the Novior.MentorAgent.Blazor README — as an opaque snapshot bound to the signed-in user.

This throws rather than returning `null` on purpose. Null is the documented answer for "no conversation yet", so returning it here would tell a WebAssembly host that it had nothing worth saving — and it would dutifully store nothing, every time, and never find out why the restore did nothing either. That is the shape of defect this suite exists to find; an exception at development time is the honest alternative.

---

- Previous: [MentorAgentBlazorOptions class](https://docs.mentoragent.net/api/novior-mentoragent-blazor-models/mentoragentblazoroptions.md)
- Next: [WasmMentorPageContext class](https://docs.mentoragent.net/api/novior-mentoragent-blazor-services/wasmmentorpagecontext.md)
