Questa pagina non è ancora tradotta in italiano: qui la trovi in inglese.
IMentorPageContext interface
The IMentorPageContext interface of Novior.MentorAgent.Abstractions.Interfaces: Scoped service that Blazor pages use to communicate with MentorAgent. Two…
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:
@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");Definition
Section titled “Definition”Namespace: Novior.MentorAgent.Abstractions.Interfaces. Package: Novior.MentorAgent.Abstractions.
public interface IMentorPageContext
dotnet add package Novior.MentorAgent.AbstractionsProperties
Section titled “Properties”ContextData
Section titled “ContextData”IReadOnlyDictionary<string, object?> ContextData { get; }
Snapshot of the current context entries.
PageName
Section titled “PageName”string? PageName { get; }
The current page name.
UIActions
Section titled “UIActions”IReadOnlyDictionary<string, UIActionRegistration> UIActions { get; }
UI actions registered by the current page.
Methods
Section titled “Methods”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.
RegisterUIAction
Section titled “RegisterUIAction”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.
RegisterUIActionAsync
Section titled “RegisterUIActionAsync”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.
Remove
Section titled “Remove”IMentorPageContext Remove(string key)
Removes a context entry.
IMentorPageContext Set(string key, object? value)
Adds or updates a context entry.
SetPageName
Section titled “SetPageName”IMentorPageContext SetPageName(string pageName)
Sets the current page name (e.g. "Orders", "Products").
SignalReady
Section titled “SignalReady”IMentorPageContext SignalReady()
Signals that the page has finished rendering and its UI actions are ready.
UnregisterUIAction
Section titled “UnregisterUIAction”IMentorPageContext UnregisterUIAction(string actionName)
Removes a registered UI action.
WaitForPageReadyAsync
Section titled “WaitForPageReadyAsync”Task<bool> WaitForPageReadyAsync(int timeoutMs = 2000, CancellationToken ct = default)
Waits until the page calls SignalReady or the timeout expires.
