MentorAgent Docs
Menu

ReferencePackage: Novior.MentorAgent.Abstractions

IMentorPageContext interface

The IMentorPageContext interface of Novior.MentorAgent.Abstractions.Interfaces: Scoped service that Blazor pages use to communicate with MentorAgent. Two…

View as Markdown
On this page

Scoped service that Blazor pages use to communicate with MentorAgent. Two responsibilities: 1. CONTEXT — the page registers visible data → injected into the system prompt 2. UI ACTIONS — the page registers executable actions → become AI tools Typical usage in a Razor page:

Example
@inject IMentorPageContext PageContext
@implements IDisposable

protected override void OnInitialized()
{
    PageContext
        .SetPageName("Orders")
        .Set("ActiveFilter", "Pending")
        .RegisterUIAction("highlight_row", "Highlights the row", id => HighlightRow((int)id!));
}

public void Dispose() => PageContext.Clear("Orders");

Namespace: Novior.MentorAgent.Abstractions.Interfaces. Package: Novior.MentorAgent.Abstractions.

public interface IMentorPageContext

Terminal
dotnet add package Novior.MentorAgent.Abstractions

IReadOnlyDictionary<string, object?> ContextData { get; }

Snapshot of the current context entries.

string? PageName { get; }

The current page name.

IReadOnlyDictionary<string, UIActionRegistration> UIActions { get; }

UI actions registered by the current page.

void Clear()

Clears all context data and all UI actions, whichever page registered them. In a page's Dispose() call IMentorPageContext.Clear instead.

void Clear(string pageName)

Clears what the page named pageName registered. Call it in the page's Dispose(), with the name the page gave IMentorPageContext.SetPageName.

Blazor disposes the previous page after it has initialized the next one. If the next page has set its own name, only the entries and actions registered under pageName go, and the next page keeps its own, its name and its IMentorPageContext.SignalReady. If pageName is still the current page, everything is cleared, as with IMentorPageContext.Clear (BUG-192).

Entries and actions belong to the page whose name was set when they were registered, so a page calls IMentorPageContext.SetPageName before anything else. The default body, for an implementation that does not override it, clears everything when pageName is the current page and nothing otherwise.

IMentorPageContext RegisterUIAction(string actionName, string description, Action<object?> handler)

Registers a UI action (untyped parameter).

IMentorPageContext RegisterUIAction<TParam>(string actionName, string description, Action<TParam?> handler, string? parameterHint = null)

Registers a UI action with a strongly-typed parameter.

IMentorPageContext RegisterUIActionAsync(string actionName, string description, Func<object?, Task> handler, string? parameterHint = null)

Registers an async UI action (no typed parameter).

IMentorPageContext RegisterUIActionAsync<TParam>(string actionName, string description, Func<TParam?, Task> handler, string? parameterHint = null)

Registers an async UI action with a strongly-typed parameter.

IMentorPageContext Remove(string key)

Removes a context entry.

IMentorPageContext Set(string key, object? value)

Adds or updates a context entry.

IMentorPageContext SetPageName(string pageName)

Sets the current page name (e.g. "Orders", "Products").

IMentorPageContext SignalReady()

Signals that the page has finished rendering and its UI actions are ready.

IMentorPageContext UnregisterUIAction(string actionName)

Removes a registered UI action.

Task<bool> WaitForPageReadyAsync(int timeoutMs = 2000, CancellationToken ct = default)

Waits until the page calls SignalReady or the timeout expires.