MentorAgent Docs
Menu

ConceptPackages: Novior.MentorAgent, Novior.MentorAgent.Blazor

Pages the agent knows

With the AutoMentor on, MentorAgent knows the pages of your Blazor app from their routes, and what a scan or your users saw of each one.

View as Markdown
On this page

Since 1.5.0, MentorAgent can know the pages of your Blazor application with no attribute on each one. Turn on the AutoMentor, the option that also finds candidate actions in your services, and MentorAgent reads the routes of your components. A scan of your pages, at development time, adds what each page offers. In production, the widget can add what your users open. IMentorActionCatalog.GetPages() gives the result: one entry for each route, with its coverage, which says where its elements come from.

In this version the list is for your code, and for the tools that read the catalog of your application. The model does not receive it. To let the agent open a page with navigate_to, describe the page with [MentorPage], as before.

With AutoMentor.Enabled, MentorAgent reads the components that carry @page, as the Blazor router reads them. A page needs nothing from MentorAgent:

Invoices.razor
@page "/invoices"
@page "/invoices/{id:int}"

<h1>Invoices</h1>

@code {
    [Parameter] public int? Id { get; set; }
}

This component is two pages, /invoices and /invoices/{id:int}. A route with parameters is listed as it is written. Routes that differ only in letter case are one page, as in the Blazor router.

MentorAgent reads the pages once, the first time that something asks for them, and keeps them. It reads them from:

  • the entry assembly of the application;
  • the assemblies that it references and that use the components, such as the client project of an Auto application, or a Razor class library given to AddAdditionalAssemblies;
  • the assemblies of AutoMentor.PageAssemblies, for pages that the entry assembly does not reference.
Program.cs
options.AutoMentor.Enabled = true;
// Only for an assembly with pages that the app does not reference,
// such as one it loads as a plugin
options.AutoMentor.PageAssemblies = [typeof(Invoices).Assembly];

Put these lines in AddMentorAgent, with the options that you already set. AutoMentor.Enabled also turns on the candidates of your services. With no namespace in AutoMentor.Namespaces there is no candidate, and a warning in the log says so.

The pages of other clients reach the server in other ways:

  • A WebAssembly client. The server cannot read the code of a WebAssembly client. The client of Novior.MentorAgent.Blazor reads its own pages in the same way. It sends them to the hub every time it connects, with the hub method ReportPages. To add an assembly, use MentorAgentBlazorOptions.PageAssemblies. A server with the AutoMentor off ignores the pages that the client sends.
  • React and Angular. A front end that loads /mentor/agent.js sends its routes when it calls attach. They come from options.routes, or from the configuration of its router: Angular's Routes, or React Router's route objects. A route such as /orders/:id is listed as /orders/{id}. Without either, it sends the path of the current page and the links on it.

A page that a client sends is listed after the pages of the host. It comes from the browser, so MentorAgent lists it only if:

  • its route starts with /;
  • its route and its component name have 1 to 256 characters each, with no white space.

Another page is not listed, and a warning in the log says so once, without what the client sent. The application lists 1,000 pages at most, its own and its clients' together.

Reading the pages never stops the application. An assembly that does not load, or a type that throws while it is read, is skipped and named in a warning. The other pages are listed.

Each page has a coverage, a MentorPageCoverage, which says where its elements come from. The manifest in the table is the file that a scan of your pages writes, explained after the table:

CoverageWhere it comes fromElements
ToScanOnly the route: no scan read the page, because the manifest does not have it or there is no manifestNone
ScannedThe manifest of a scan has the page, and says when the scan read itThe elements that the scan read, then those that the widget observed and the scan did not read
ObservedThe manifest does not have the page, but the widget observed it in the users' browsersThose that two different users saw the same way, or one user in a .NET MAUI Blazor Hybrid app

The manifest. A scan of the pages writes mentor-ui-manifest.json in the project, at development time or in a pipeline. The build embeds the manifest in the application, also when the project references only Novior.MentorAgent.Server. The build does not publish it as a separate file. The host reads it once, together with the pages. A page that only the manifest has is listed last, with no component. A WebAssembly client does not send a manifest, so put it in the project of the server. Scan your pages explains how to write it.

MentorAgent does not trust the manifest. Whoever wrote it, MentorAgent never takes these elements from it: a password field, card data (autocomplete="cc-…"), and a hidden, disabled or data-mentor-exclude element. The format has no place for a value. A manifest of another version, or a file that is not a manifest, leaves every page to scan, and the log says so.

Observation. With the AutoMentor on, AutoMentor.ObservePages is on by default. The widget then reads the structure of the pages that your users open. Pages observed in production says what leaves the browser.

GetPages() gives the pages in the order first seen: those of the host, those that clients sent, then those that only the manifest has. It gives none when the AutoMentor is off. The list is built again at every call, so a page that a client sends appears at the next call. The list is a copy: changing it changes nothing in MentorAgent.

For example, the routes of the pages that no scan has read yet:

PageCoverage.cs
// The routes of the pages that no scan has read yet
public static IEnumerable<string> NotScanned(IMentorActionCatalog catalog) =>
    catalog.GetPages()
        .Where(page => page.Coverage != MentorPageCoverage.Scanned)
        .Select(page => page.Route);
PropertyWhat it holds
RouteThe route template, as @page writes it, for example /invoices/{id:int}. It is the key of the page
ComponentThe full name of the component that serves the page. null for a page that only the manifest has
CoverageToScan, Scanned or Observed. The list of values may grow: treat a value that you do not know as not scanned, like ToScan
ScannedAtWhen the scan read the page, as the manifest says. null when no scan read it
ElementsThe elements of the page, each a MentorPageElement. Empty for a page to scan
PropertyWhat it holds
ElementThe tag, for example input, select, button or a
RoleThe ARIA role, for example textbox, combobox or button
TypeThe type of an input, for example text or date
LabelThe visible or accessible label, up to 256 characters. null for an observed element
FormThe form, or group of fields, that it belongs to. null for an observed element
OptionsThe labels of the options of a select or a radio group, up to 64, never their values
SelectorA stable selector for the element
RolesThe roles of your application that the scan saw it with. None for an observed element
CoverageScanned or Observed: whether a scan read it or the widget observed it

A label is text from your pages. Treat it as data, never as an instruction. The labels of what users saw stay in the memory of your application, so GetPages() never gives them.

The list describes what a page offers, not the data that it holds:

  • No value. Neither the manifest nor the widget has a place for what a field holds.
  • Fields left out. A password field, card data, a hidden or disabled element, and MentorAgent's own chat widget are never in the list.
  • Zones left out. Mark a part of a page with data-mentor-exclude. Nothing inside it is scanned, and nothing inside it is sent by the observation.
  • Labels are text of the page. The label of a button or a link is often its visible text. On a scanned page, the scan reads your development data. In production, the observation reads what your users see: Pages observed in production says what leaves the browser.

Read this section before you publish your application with the AutoMentor on. It says what leaves your users' browsers, so that you can tell your users and the person who looks after privacy. The AutoMentor is off by default.

An application in production often has no manifest, because nobody scanned it. With the AutoMentor on, AutoMentor.ObservePages is on by default. The widget then observes the pages that your users open, with their dialogs, tabs and panels. GetPages() adds what at least two users saw, with the coverage Observed. To turn the observation off, see Turn it off.

When a page has not changed for one second, the widget reads it with the same reader as the scan. While the page is open, the widget sends the elements that it has not sent yet. For each interactive element it sends:

  • its tag, its role, its type and its selector;
  • its form: the form's aria-label, name or id, or its number;
  • its label.

The label can be text of the page. For a button, a link, a tab or a menu item, the label is the first of these that exists: its aria-label, the text that labels it, its visible text, its placeholder or its title. A label has at most 256 characters. When that text does not repeat, it may be a person's name or data of a record, such as a link Order 1002, and it leaves the browser. Mark with data-mentor-exclude the parts of a page where such text is shown.

What is never sent:

  • No value. Never what a field holds, the options of a select or the one chosen. A label that wraps a field is read without the field.
  • Fields left out. A password field, a field of card data (autocomplete="cc-…"), a hidden or disabled element, and MentorAgent's own widget.
  • Zones left out. Nothing inside data-mentor-exclude is sent.
  • Text that repeats. The rows of a table are read once per column, with the column's header as label. A list of links, cards of records or a feed are read once, with no label.

There is one exception to Text that repeats: an input, select or textarea with an id of its own and a label tied to it (<label for>, aria-labelledby) keeps its label, also in a list. A list of check boxes labelled with the names of records sends each name.

The browser sends the path of the page without its query string and its fragment, so a path such as /invoices/1002 leaves the browser with the id that it holds. Your application uses it to find the page, as the router would, and does not keep it.

On Blazor Server the elements reach your application in the circuit, and in .NET MAUI Blazor Hybrid in the app's own process. A WebAssembly client sends them to the hub, as explained below.

An observed element's selector is made of a data-mentor-id, tags and positions. It starts from the element's data-mentor-id when that is unique on the page, or from the nearest ancestor with a unique data-mentor-id, or from the body. Then it goes down by tags and positions. In the rows of a table, or in another structure that repeats, the selector is the same for every row. It never holds an id, a class, a name, a data-testid or a label, because those may hold data of a record. An element more than 16 steps below its starting point is not sent. Your application keeps only a selector of that shape, whoever sent it.

For stable selectors on the observed pages, give the elements, or a container of theirs, a data-mentor-id. Put a name in it, such as invoice.status, never a value from a record: MentorAgent checks the shape of the selector, not what you write in a data-mentor-id.

An element reaches GetPages() only once two different users saw it exactly the same way: the same tag, role, type, label, form and selector. A menu that shows one user's name therefore never reaches GetPages(). Until a second user sees it, the element waits in the memory of your application, with its label and its form but with no connection and no user name. A restart of the application clears this memory.

  • A signed-in user is one user in every tab.
  • Without sign-in, each circuit or connection is a user. Two tabs of one anonymous person, a reload of the page, or a new connection to the hub count as two users. Without sign-in, the rule cannot tell one person from two.
  • In a .NET MAUI Blazor Hybrid app, which runs on its user's own device, one user is enough.

GetPages() gives an observed element without its label and its form: its tag, role, type and selector only. The labels and the forms stay in the memory of your application, for the rule of two users. Everything observed is kept in memory: a restart forgets it, and two instances of your application do not share it.

The log never has a path or a text of the page. A line at the Debug level gives the route and how many elements were observed.

The WebAssembly client of Novior.MentorAgent.Blazor sends what it observed to the hub, with the hub method ReportObservedPage. There, a connection's user is its signed-in user, or the connection itself. The client opens no connection for it. What it observed waits in the browser until the widget's hub is connected and has sent the client's pages. Since 1.5.0 the widget opens that connection when it is created. At most 200 messages wait, and the oldest are dropped.

The client cannot read the server's options, so it observes even when the AutoMentor is off. Its first message reaches the server once the hub is connected. A server with the observation off keeps nothing of it, and its answer stops the observation in the client. A server older than 1.5.0, without the method, stops the observation, never the connection.

React and Angular front ends do not observe their pages in this version: only the Blazor widget does.

  • In the browser: at most 500 elements a page, one message every 2 seconds, 24 KB a message and 200 messages while the page is open. Past one of these limits, the browser stops observing every page, and says so once in its console.
  • In your application: 200 messages a connection or circuit, 500 observed elements a page, and 10,000 elements waiting for a second user. Past these limits, your application keeps nothing more. Each kind of limit is written once in the log, as a warning.
Program.cs
options.AutoMentor.Enabled = true;
options.AutoMentor.ObservePages = false;   // routes and manifest only

With ObservePages = false, or the AutoMentor off, the widget on Blazor Server and in .NET MAUI Blazor Hybrid does not load the observation, and nothing is sent. A WebAssembly client still sends its first message once the hub is connected: the server keeps nothing of it and stops it. To keep only a part of a page out, mark it with data-mentor-exclude.

What the observation adds is little. What repeats on a page is kept once, with no label, and an element counts only once two users saw it, so a page without a manifest stays mostly unknown. Scanning your pages in development remains the main way to give the AutoMentor its pages; the observation adds what the scan did not open.

The rules of the pages are the page area of ACTION-RULES.md in the MentorAgent repository (external site). Each rule has a name that never changes, and a test in the library. These are the rules of this page:

RuleWhat it says
page.from-routesWith the AutoMentor on, the pages are the routes of the Blazor components, read once from the entry assembly, the assemblies that it references and PageAssemblies
page.client-routesA WebAssembly client reads its own pages and sends them at every connection. A server with the AutoMentor off ignores them
page.front-end-routesA React or Angular front end sends its routes with attach, at every reconnection, and again with report()
page.route-shapeA route starts with /. A route and a component name have 1 to 256 characters each, with no white space
page.route-limitThe application lists 1,000 pages at most
page.readAn assembly or a type that cannot be read is skipped and named in the log. The application does not stop
page.manifestThe manifest of a scan is embedded in the application and read once. A page that it has is scanned
page.catalogGetPages() gives one page per route, decided again at every call, as a copy. None with the AutoMentor off
page.observeThe widget observes the pages that the users open, with ObservePages on
page.observe-privateWhat a user saw never leaves the process of your application
page.observe-valuesNo value leaves the browser: not what a field holds, nor the options of a select
page.observe-sharedAn observed element counts once two different users saw it the same way, or one in a MAUI Blazor Hybrid app
page.observe-offWith ObservePages or the AutoMentor off, nothing is kept, and the server's answer stops a WebAssembly client

The other rules of the area, for the scan and the observation, are in ACTION-RULES.md. The rules of the actions that your classes declare are in How methods become actions.

  • How methods become actions — The rules by which MentorAgent turns your methods into actions, names them, turns them on or off, adds up roles and confirmations, and publishes them.
  • Attributes — The parameters of MentorAction, MentorAgent, MentorTeam, TeamMember, MentorPage, MentorSkill and MentorExclude, with their defaults and rules.
  • Configuration options — Every MentorOptions property with its type, default and effect, grouped by area, plus the options of the WebAssembly client and the YAML loader.
  • MentorAgent 1.5.0 release notes — What's new in MentorAgent 1.5.0: pages known from your routes, a scan of the pages, recipes, forms and grids as UI actions, and the cost per agent and user.