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.
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.
Where the pages come from
Section titled “Where the pages come from”With AutoMentor.Enabled, MentorAgent reads the components that carry @page, as the Blazor router reads them. A page needs nothing from MentorAgent:
@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.
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.Blazorreads its own pages in the same way. It sends them to the hub every time it connects, with the hub methodReportPages. To add an assembly, useMentorAgentBlazorOptions.PageAssemblies. A server with the AutoMentor off ignores the pages that the client sends. - React and Angular. A front end that loads
/mentor/agent.jssends its routes when it callsattach. They come fromoptions.routes, or from the configuration of its router: Angular'sRoutes, or React Router's route objects. A route such as/orders/:idis 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.
What the agent knows of each page
Section titled “What the agent knows of each page”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:
| Coverage | Where it comes from | Elements |
|---|---|---|
ToScan | Only the route: no scan read the page, because the manifest does not have it or there is no manifest | None |
Scanned | The manifest of a scan has the page, and says when the scan read it | The elements that the scan read, then those that the widget observed and the scan did not read |
Observed | The manifest does not have the page, but the widget observed it in the users' browsers | Those 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.
Read the list
Section titled “Read the list”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:
// 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);MentorPageInfo: a page
Section titled “MentorPageInfo: a page”| Property | What it holds |
|---|---|
Route | The route template, as @page writes it, for example /invoices/{id:int}. It is the key of the page |
Component | The full name of the component that serves the page. null for a page that only the manifest has |
Coverage | ToScan, Scanned or Observed. The list of values may grow: treat a value that you do not know as not scanned, like ToScan |
ScannedAt | When the scan read the page, as the manifest says. null when no scan read it |
Elements | The elements of the page, each a MentorPageElement. Empty for a page to scan |
MentorPageElement: an element
Section titled “MentorPageElement: an element”| Property | What it holds |
|---|---|
Element | The tag, for example input, select, button or a |
Role | The ARIA role, for example textbox, combobox or button |
Type | The type of an input, for example text or date |
Label | The visible or accessible label, up to 256 characters. null for an observed element |
Form | The form, or group of fields, that it belongs to. null for an observed element |
Options | The labels of the options of a select or a radio group, up to 64, never their values |
Selector | A stable selector for the element |
Roles | The roles of your application that the scan saw it with. None for an observed element |
Coverage | Scanned 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.
Structure only
Section titled “Structure only”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.
Pages observed in production
Section titled “Pages observed in production”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.
What leaves the browser
Section titled “What leaves the browser”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,nameor 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-excludeis 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.
Selectors with nothing of the page
Section titled “Selectors with nothing of the page”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.
Two users before an element counts
Section titled “Two users before an element counts”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.
What your application keeps
Section titled “What your application keeps”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.
A WebAssembly client
Section titled “A WebAssembly client”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.
Limits
Section titled “Limits”- 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.
Turn it off
Section titled “Turn it off”options.AutoMentor.Enabled = true;
options.AutoMentor.ObservePages = false; // routes and manifest onlyWith 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
Section titled “The rules”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:
| Rule | What it says |
|---|---|
page.from-routes | With 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-routes | A WebAssembly client reads its own pages and sends them at every connection. A server with the AutoMentor off ignores them |
page.front-end-routes | A React or Angular front end sends its routes with attach, at every reconnection, and again with report() |
page.route-shape | A route starts with /. A route and a component name have 1 to 256 characters each, with no white space |
page.route-limit | The application lists 1,000 pages at most |
page.read | An assembly or a type that cannot be read is skipped and named in the log. The application does not stop |
page.manifest | The manifest of a scan is embedded in the application and read once. A page that it has is scanned |
page.catalog | GetPages() gives one page per route, decided again at every call, as a copy. None with the AutoMentor off |
page.observe | The widget observes the pages that the users open, with ObservePages on |
page.observe-private | What a user saw never leaves the process of your application |
page.observe-values | No value leaves the browser: not what a field holds, nor the options of a select |
page.observe-shared | An observed element counts once two different users saw it the same way, or one in a MAUI Blazor Hybrid app |
page.observe-off | With 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.
See also
Section titled “See also”- 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.
