@mgamadeus/ddd-agents 0.6.4 → 0.6.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +6 -1
- package/dist/chunks/realtime-arrival-BfsAPwqQ.js.map +1 -1
- package/dist/types/ui/AgentUIClient.d.ts +5 -0
- package/dist/types/ui/ClientToolRequestRunner.d.ts +6 -2
- package/dist/types/ui/DomScreenReader.d.ts +46 -2
- package/dist/types/ui/agent-ui-state.d.ts +5 -0
- package/dist/types/ui/client-tools.d.ts +2 -0
- package/dist/types/ui/screen-markdown.d.ts +15 -3
- package/dist/types/ui/screen-picture.d.ts +42 -5
- package/dist/ui.js +278 -39
- package/dist/ui.js.map +1 -1
- package/package.json +1 -1
- package/public-api.json +7 -0
package/README.md
CHANGED
|
@@ -121,7 +121,12 @@ const uiClient = useAgentUIClient({
|
|
|
121
121
|
`data-agent-tabs`, `data-agent-views`, `data-agent-anchor-group` (with `groupKey`).
|
|
122
122
|
- In a picture, passwords show as dots, `data-agent-secret` content is blanked and `data-agent-skip` elements are left
|
|
123
123
|
out (mark the agent window `data-agent-skip`); what a picture cannot show is `PICTURE_LIMITATIONS`.
|
|
124
|
-
- The agent window steps aside before a screen is opened, marked or pictured, and comes back after a picture.
|
|
124
|
+
- The agent window steps aside before a screen is opened, marked or pictured, and comes back after a picture. Its
|
|
125
|
+
mode (`getMode`) and the browser size ride with the UI state into the `[SIGNAL:ui]` note.
|
|
126
|
+
- `new DomScreenReader({ findRoot, currentLocation, describeUnsavedChanges, registry, findNavigation,
|
|
127
|
+
describeAgentWindow })`: `findNavigation` returns the main menu (entries `data-nav-key`, groups `data-nav-group`,
|
|
128
|
+
read as `nav.<key>`), `describeAgentWindow` says where the agent window is (`full screen: it covers the page`).
|
|
129
|
+
- A picture shows the browser window only: elements out of view are not copied.
|
|
125
130
|
- A host push transport hands each message to `acceptArrivedRealtimeMessage(conversationId, message, uiClient, sendAnswer)`;
|
|
126
131
|
without one the run-state read delivers. A transport that only pings calls
|
|
127
132
|
`readRunStateAfterClientToolRequestPing(conversationId, client.getConversationRunState, uiClient)`: a read that
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"realtime-arrival-BfsAPwqQ.js","sources":["../../src/ui/agent-ui-state.ts","../../src/ui/realtime-arrival.ts"],"sourcesContent":["/**\n * What the client reports about its UI with every message and every run-state read (`Agent.UI`): the server keeps\n * only tokens of one pattern (route path, tab, view, references, dialog key) and writes the `[SIGNAL:ui]` note from\n * them and its own screen catalog. Never field values or labels: those reach the model only through `getCurrentScreen`.\n * The wire shape of `AgentUIState` of ddd-agents.\n */\nexport interface AgentUIState {\n /** The path of the route, e.g. `/orders/42` */\n routePath: string | null;\n /** The route's parameters, in order */\n routeParameters?: { name: string; value: string }[] | null;\n tab?: string | null;\n view?: string | null;\n /** The references of the fields with unsaved changes */\n unsavedFieldReferences?: string[];\n /** The references of the fields with a validation message */\n invalidFieldReferences?: string[];\n /** The key of a dialog or drawer open on the screen */\n openDialogKey?: string | null;\n visible?: boolean | null;\n /** ISO time of the capture */\n capturedAt?: string | null;\n}\n\n/** Reads the UI state now; the application's adapter (ddd-admin-ui ships one for screens built from its blocks). */\nexport interface AgentUIStateSource {\n readUIState(): AgentUIState | null;\n}\n\n/** A client id: 8 to 64 letters, digits and `-`, random per mount of the agent window (the server's pattern). */\nexport const createAgentUIClientId = (): string => {\n const randomPart =\n typeof crypto !== \"undefined\" && typeof crypto.randomUUID === \"function\"\n ? crypto.randomUUID()\n : `${Date.now().toString(36)}-${Math.random().toString(36).slice(2, 12)}`;\n return `ui-${randomPart}`.slice(0, 64);\n};\n","import type { ClientToolAnswerSender } from \"./ClientToolRequestRunner\";\nimport type { ClientToolAnswer, ClientToolRequestDelivery, ClientToolRequestType } from \"./client-tools\";\n\n/** The message type of a client tool request on the realtime port (`AgentUIRealtimeMessageTypeProviderService`). */\nexport const CLIENT_TOOL_REQUEST_MESSAGE_TYPE = 'agent.ui.clientToolRequest';\n\n/** A message of the realtime port as the run-state read or the host's transport delivers it (`AgentRealtimeMessageDelivery`). */\nexport interface AgentRealtimeMessageDelivery {\n messageType: string;\n messageKey: string;\n /** One JSON object */\n payloadJson: string;\n secondsLeft: number;\n}\n\n/** What a client needs to listen on the host's transport (`AgentRealtimeListenerCredential`). */\nexport interface AgentRealtimeListenerCredential {\n transportName: string;\n credential: string;\n listenPath?: string | null;\n expiresAt?: string | null;\n}\n\n/** The client tool request a realtime message carries, or null for another type or a payload that does not parse. */\nexport const readClientToolRequestOfRealtimeMessage = (message: AgentRealtimeMessageDelivery): ClientToolRequestDelivery | null => {\n if (message.messageType !== CLIENT_TOOL_REQUEST_MESSAGE_TYPE) return null;\n try {\n const payload: unknown = JSON.parse(message.payloadJson);\n if (typeof payload !== 'object' || payload === null) return null;\n const { id, requestType, argumentsJson, secondsLeft } = payload as Record<string, unknown>;\n if (typeof id !== 'number' || !Number.isSafeInteger(id) || typeof requestType !== 'string') return null;\n return {\n id,\n requestType,\n argumentsJson: typeof argumentsJson === 'string' ? argumentsJson : '{}',\n // the transport's own clock: the message's seconds left win when the payload's are older\n secondsLeft: Math.min(typeof secondsLeft === 'number' ? secondsLeft : message.secondsLeft, message.secondsLeft),\n };\n } catch {\n return null;\n }\n};\n\n/** What takes an arrived client tool request (an `AgentUIClient`). */\nexport interface ClientToolRequestAcceptor {\n acceptClientToolRequest(conversationId: number, delivery: ClientToolRequestDelivery, sendAnswer: ClientToolAnswerSender): void;\n}\n\n/**\n * The arrival adapter for a host transport: hand it every message the transport receives for a conversation; a\n * client tool request goes to the UI client (which runs a request id once, so the run-state read delivering the same\n * request is harmless), any other type to `onOtherMessage`. Returns whether the message was a client tool request.\n */\nexport const acceptArrivedRealtimeMessage = (\n conversationId: number,\n message: AgentRealtimeMessageDelivery,\n acceptor: ClientToolRequestAcceptor,\n sendAnswer: ClientToolAnswerSender,\n onOtherMessage?: (conversationId: number, message: AgentRealtimeMessageDelivery) => void,\n): boolean => {\n const delivery = readClientToolRequestOfRealtimeMessage(message);\n if (delivery) {\n acceptor.acceptClientToolRequest(conversationId, delivery, sendAnswer);\n return true;\n }\n onOtherMessage?.(conversationId, message);\n return false;\n};\n\n/** The pause before the one re-read of `readRunStateAfterClientToolRequestPing` when the first read found nothing. */\nexport const CLIENT_TOOL_REQUEST_PING_REREAD_DELAY_MS = 400;\n\n/** What counts the client tool requests delivered to the UI client (`AgentUIClient`). */\nexport interface ClientToolRequestDeliveryCounter {\n countAcceptedClientToolRequests(): number;\n}\n\n/**\n * The arrival adapter for a host transport that only pings (it carries no message, e.g. the per-conversation ping of\n * a client tool request): reads the run state, which hands a waiting request to the UI client; when that read\n * delivered none — the ping overtook the server's write — it reads once more after `rereadDelayMs`, so the request is\n * not left to the next regular read. Resolves with whether a request was delivered.\n */\nexport const readRunStateAfterClientToolRequestPing = async (\n conversationId: number,\n readRunState: (conversationId: number) => Promise<unknown>,\n deliveryCounter: ClientToolRequestDeliveryCounter,\n rereadDelayMs: number = CLIENT_TOOL_REQUEST_PING_REREAD_DELAY_MS,\n): Promise<boolean> => {\n const acceptedBefore = deliveryCounter.countAcceptedClientToolRequests();\n await readRunState(conversationId);\n if (deliveryCounter.countAcceptedClientToolRequests() > acceptedBefore) return true;\n await new Promise<void>(resolve => setTimeout(resolve, rereadDelayMs));\n await readRunState(conversationId);\n return deliveryCounter.countAcceptedClientToolRequests() > acceptedBefore;\n};\n\nlet developmentRequestId = 9_000_000_000_000;\n\n/**\n * The dev helper: runs a request through the UI client as if the server had sent it and resolves with the answer, so\n * an application tries its adapters without a model (e.g. from the browser console in development).\n */\nexport const runClientToolRequestForDevelopment = (\n acceptor: ClientToolRequestAcceptor,\n requestType: ClientToolRequestType | string,\n parameters: Record<string, unknown> = {},\n secondsLeft: number = 30,\n): Promise<ClientToolAnswer> =>\n new Promise(resolve => {\n developmentRequestId += 1;\n acceptor.acceptClientToolRequest(\n 0,\n { id: developmentRequestId, requestType, argumentsJson: JSON.stringify(parameters), secondsLeft },\n async (_requestId, answer) => resolve(answer),\n );\n });\n"],"names":[],"mappings":";
|
|
1
|
+
{"version":3,"file":"realtime-arrival-BfsAPwqQ.js","sources":["../../src/ui/agent-ui-state.ts","../../src/ui/realtime-arrival.ts"],"sourcesContent":["/**\n * What the client reports about its UI with every message and every run-state read (`Agent.UI`): the server keeps\n * only tokens of one pattern (route path, tab, view, references, dialog key) and writes the `[SIGNAL:ui]` note from\n * them and its own screen catalog. Never field values or labels: those reach the model only through `getCurrentScreen`.\n * The wire shape of `AgentUIState` of ddd-agents.\n */\nexport interface AgentUIState {\n /** The path of the route, e.g. `/orders/42` */\n routePath: string | null;\n /** The route's parameters, in order */\n routeParameters?: { name: string; value: string }[] | null;\n tab?: string | null;\n view?: string | null;\n /** The references of the fields with unsaved changes */\n unsavedFieldReferences?: string[];\n /** The references of the fields with a validation message */\n invalidFieldReferences?: string[];\n /** The key of a dialog or drawer open on the screen */\n openDialogKey?: string | null;\n /** The mode the agent window shows (`full`, `compact`, `closed`, … the application's modes); `AgentUIClient` fills it from the window adapter */\n agentWindow?: string | null;\n /** The size of the browser window in CSS pixels; `AgentUIClient` fills it */\n viewportWidth?: number | null;\n viewportHeight?: number | null;\n visible?: boolean | null;\n /** ISO time of the capture */\n capturedAt?: string | null;\n}\n\n/** Reads the UI state now; the application's adapter (ddd-admin-ui ships one for screens built from its blocks). */\nexport interface AgentUIStateSource {\n readUIState(): AgentUIState | null;\n}\n\n/** A client id: 8 to 64 letters, digits and `-`, random per mount of the agent window (the server's pattern). */\nexport const createAgentUIClientId = (): string => {\n const randomPart =\n typeof crypto !== \"undefined\" && typeof crypto.randomUUID === \"function\"\n ? crypto.randomUUID()\n : `${Date.now().toString(36)}-${Math.random().toString(36).slice(2, 12)}`;\n return `ui-${randomPart}`.slice(0, 64);\n};\n","import type { ClientToolAnswerSender } from \"./ClientToolRequestRunner\";\nimport type { ClientToolAnswer, ClientToolRequestDelivery, ClientToolRequestType } from \"./client-tools\";\n\n/** The message type of a client tool request on the realtime port (`AgentUIRealtimeMessageTypeProviderService`). */\nexport const CLIENT_TOOL_REQUEST_MESSAGE_TYPE = 'agent.ui.clientToolRequest';\n\n/** A message of the realtime port as the run-state read or the host's transport delivers it (`AgentRealtimeMessageDelivery`). */\nexport interface AgentRealtimeMessageDelivery {\n messageType: string;\n messageKey: string;\n /** One JSON object */\n payloadJson: string;\n secondsLeft: number;\n}\n\n/** What a client needs to listen on the host's transport (`AgentRealtimeListenerCredential`). */\nexport interface AgentRealtimeListenerCredential {\n transportName: string;\n credential: string;\n listenPath?: string | null;\n expiresAt?: string | null;\n}\n\n/** The client tool request a realtime message carries, or null for another type or a payload that does not parse. */\nexport const readClientToolRequestOfRealtimeMessage = (message: AgentRealtimeMessageDelivery): ClientToolRequestDelivery | null => {\n if (message.messageType !== CLIENT_TOOL_REQUEST_MESSAGE_TYPE) return null;\n try {\n const payload: unknown = JSON.parse(message.payloadJson);\n if (typeof payload !== 'object' || payload === null) return null;\n const { id, requestType, argumentsJson, secondsLeft } = payload as Record<string, unknown>;\n if (typeof id !== 'number' || !Number.isSafeInteger(id) || typeof requestType !== 'string') return null;\n return {\n id,\n requestType,\n argumentsJson: typeof argumentsJson === 'string' ? argumentsJson : '{}',\n // the transport's own clock: the message's seconds left win when the payload's are older\n secondsLeft: Math.min(typeof secondsLeft === 'number' ? secondsLeft : message.secondsLeft, message.secondsLeft),\n };\n } catch {\n return null;\n }\n};\n\n/** What takes an arrived client tool request (an `AgentUIClient`). */\nexport interface ClientToolRequestAcceptor {\n acceptClientToolRequest(conversationId: number, delivery: ClientToolRequestDelivery, sendAnswer: ClientToolAnswerSender): void;\n}\n\n/**\n * The arrival adapter for a host transport: hand it every message the transport receives for a conversation; a\n * client tool request goes to the UI client (which runs a request id once, so the run-state read delivering the same\n * request is harmless), any other type to `onOtherMessage`. Returns whether the message was a client tool request.\n */\nexport const acceptArrivedRealtimeMessage = (\n conversationId: number,\n message: AgentRealtimeMessageDelivery,\n acceptor: ClientToolRequestAcceptor,\n sendAnswer: ClientToolAnswerSender,\n onOtherMessage?: (conversationId: number, message: AgentRealtimeMessageDelivery) => void,\n): boolean => {\n const delivery = readClientToolRequestOfRealtimeMessage(message);\n if (delivery) {\n acceptor.acceptClientToolRequest(conversationId, delivery, sendAnswer);\n return true;\n }\n onOtherMessage?.(conversationId, message);\n return false;\n};\n\n/** The pause before the one re-read of `readRunStateAfterClientToolRequestPing` when the first read found nothing. */\nexport const CLIENT_TOOL_REQUEST_PING_REREAD_DELAY_MS = 400;\n\n/** What counts the client tool requests delivered to the UI client (`AgentUIClient`). */\nexport interface ClientToolRequestDeliveryCounter {\n countAcceptedClientToolRequests(): number;\n}\n\n/**\n * The arrival adapter for a host transport that only pings (it carries no message, e.g. the per-conversation ping of\n * a client tool request): reads the run state, which hands a waiting request to the UI client; when that read\n * delivered none — the ping overtook the server's write — it reads once more after `rereadDelayMs`, so the request is\n * not left to the next regular read. Resolves with whether a request was delivered.\n */\nexport const readRunStateAfterClientToolRequestPing = async (\n conversationId: number,\n readRunState: (conversationId: number) => Promise<unknown>,\n deliveryCounter: ClientToolRequestDeliveryCounter,\n rereadDelayMs: number = CLIENT_TOOL_REQUEST_PING_REREAD_DELAY_MS,\n): Promise<boolean> => {\n const acceptedBefore = deliveryCounter.countAcceptedClientToolRequests();\n await readRunState(conversationId);\n if (deliveryCounter.countAcceptedClientToolRequests() > acceptedBefore) return true;\n await new Promise<void>(resolve => setTimeout(resolve, rereadDelayMs));\n await readRunState(conversationId);\n return deliveryCounter.countAcceptedClientToolRequests() > acceptedBefore;\n};\n\nlet developmentRequestId = 9_000_000_000_000;\n\n/**\n * The dev helper: runs a request through the UI client as if the server had sent it and resolves with the answer, so\n * an application tries its adapters without a model (e.g. from the browser console in development).\n */\nexport const runClientToolRequestForDevelopment = (\n acceptor: ClientToolRequestAcceptor,\n requestType: ClientToolRequestType | string,\n parameters: Record<string, unknown> = {},\n secondsLeft: number = 30,\n): Promise<ClientToolAnswer> =>\n new Promise(resolve => {\n developmentRequestId += 1;\n acceptor.acceptClientToolRequest(\n 0,\n { id: developmentRequestId, requestType, argumentsJson: JSON.stringify(parameters), secondsLeft },\n async (_requestId, answer) => resolve(answer),\n );\n });\n"],"names":[],"mappings":";AAmCO,MAAM,wBAAwB,MAAc;AACjD,QAAM,aACJ,OAAO,WAAW,eAAe,OAAO,OAAO,eAAe,aAC1D,OAAO,eACP,GAAG,KAAK,MAAM,SAAS,EAAE,CAAC,IAAI,KAAK,OAAA,EAAS,SAAS,EAAE,EAAE,MAAM,GAAG,EAAE,CAAC;AAC3E,SAAO,MAAM,UAAU,GAAG,MAAM,GAAG,EAAE;AACvC;ACrCO,MAAM,mCAAmC;AAoBzC,MAAM,yCAAyC,CAAC,YAA4E;AACjI,MAAI,QAAQ,gBAAgB,iCAAkC,QAAO;AACrE,MAAI;AACF,UAAM,UAAmB,KAAK,MAAM,QAAQ,WAAW;AACvD,QAAI,OAAO,YAAY,YAAY,YAAY,KAAM,QAAO;AAC5D,UAAM,EAAE,IAAI,aAAa,eAAe,gBAAgB;AACxD,QAAI,OAAO,OAAO,YAAY,CAAC,OAAO,cAAc,EAAE,KAAK,OAAO,gBAAgB,SAAU,QAAO;AACnG,WAAO;AAAA,MACL;AAAA,MACA;AAAA,MACA,eAAe,OAAO,kBAAkB,WAAW,gBAAgB;AAAA;AAAA,MAEnE,aAAa,KAAK,IAAI,OAAO,gBAAgB,WAAW,cAAc,QAAQ,aAAa,QAAQ,WAAW;AAAA,IAAA;AAAA,EAElH,QAAQ;AACN,WAAO;AAAA,EACT;AACF;AAYO,MAAM,+BAA+B,CAC1C,gBACA,SACA,UACA,YACA,mBACY;AACZ,QAAM,WAAW,uCAAuC,OAAO;AAC/D,MAAI,UAAU;AACZ,aAAS,wBAAwB,gBAAgB,UAAU,UAAU;AACrE,WAAO;AAAA,EACT;AACA,mBAAiB,gBAAgB,OAAO;AACxC,SAAO;AACT;AAGO,MAAM,2CAA2C;AAajD,MAAM,yCAAyC,OACpD,gBACA,cACA,iBACA,gBAAwB,6CACH;AACrB,QAAM,iBAAiB,gBAAgB,gCAAA;AACvC,QAAM,aAAa,cAAc;AACjC,MAAI,gBAAgB,oCAAoC,eAAgB,QAAO;AAC/E,QAAM,IAAI,QAAc,CAAA,YAAW,WAAW,SAAS,aAAa,CAAC;AACrE,QAAM,aAAa,cAAc;AACjC,SAAO,gBAAgB,oCAAoC;AAC7D;AAEA,IAAI,uBAAuB;AAMpB,MAAM,qCAAqC,CAChD,UACA,aACA,aAAsC,CAAA,GACtC,cAAsB,OAEtB,IAAI,QAAQ,CAAA,YAAW;AACrB,0BAAwB;AACxB,WAAS;AAAA,IACP;AAAA,IACA,EAAE,IAAI,sBAAsB,aAAa,eAAe,KAAK,UAAU,UAAU,GAAG,YAAA;AAAA,IACpF,OAAO,YAAY,WAAW,QAAQ,MAAM;AAAA,EAAA;AAEhD,CAAC;"}
|
|
@@ -20,8 +20,13 @@ export declare class AgentUIClient implements AgentUIClientBinding {
|
|
|
20
20
|
readonly clientId: string;
|
|
21
21
|
protected readonly runner: ClientToolRequestRunner;
|
|
22
22
|
protected readonly uiStateSource: AgentUIStateSource | null;
|
|
23
|
+
protected readonly adapters: ScreenAdapters;
|
|
23
24
|
protected acceptedClientToolRequestCount: number;
|
|
24
25
|
constructor(adapters: ScreenAdapters, uiStateSource?: AgentUIStateSource | null, clientId?: string);
|
|
26
|
+
/**
|
|
27
|
+
* The source's UI state with the agent window's mode (the window adapter) and the browser window's size, unless the
|
|
28
|
+
* source reports them itself: the agent learns whether its window covers the page and whether a panel fits beside it.
|
|
29
|
+
*/
|
|
25
30
|
readUIState(): AgentUIState | null;
|
|
26
31
|
acceptClientToolRequest(_conversationId: number, delivery: ClientToolRequestDelivery, sendAnswer: ClientToolAnswerSender): void;
|
|
27
32
|
/** How many client tool requests were delivered to this client so far (a repeat delivery counts again). */
|
|
@@ -1,6 +1,10 @@
|
|
|
1
1
|
import { type ClientToolAnswer, type ClientToolRequestDelivery, type ClientToolRequestType, type ScreenAdapters, type ScreenTarget } from "./client-tools";
|
|
2
|
-
/**
|
|
3
|
-
|
|
2
|
+
/**
|
|
3
|
+
* The most characters of screen content in one answer: half the answer's cap ({@link MAX_ANSWER_TEXT_CHARS}), the
|
|
4
|
+
* same number as the server's cut (`AgentUIToolResponseDto::MAX_CONTENT_CHARS`, a contract test compares them). With
|
|
5
|
+
* 6,000 a list page was cut before its table; the reader's own caps (rows, cells, section text) keep a read short.
|
|
6
|
+
*/
|
|
7
|
+
export declare const MAX_SCREEN_CHARS: number;
|
|
4
8
|
/** Posts an answer; the transport is the application's. */
|
|
5
9
|
export type ClientToolAnswerSender = (requestId: number, answer: ClientToolAnswer) => Promise<void>;
|
|
6
10
|
/**
|
|
@@ -10,7 +10,13 @@ export declare const AGENT_ATTRIBUTES: {
|
|
|
10
10
|
readonly skip: 'data-agent-skip';
|
|
11
11
|
/** The key of a table row (@mgamadeus/ddd-admin-ui) */
|
|
12
12
|
readonly rowKey: 'data-row-key';
|
|
13
|
+
/** The key of a main menu entry (@mgamadeus/ddd-admin-ui): `nav.<value>` */
|
|
14
|
+
readonly navKey: 'data-nav-key';
|
|
15
|
+
/** The key of a main menu group (@mgamadeus/ddd-admin-ui): `nav.<value>`; its entries sit inside it */
|
|
16
|
+
readonly navGroup: 'data-nav-group';
|
|
13
17
|
};
|
|
18
|
+
/** The heading of the main menu part of a read. */
|
|
19
|
+
export declare const MAIN_MENU_HEADING = "## Main menu (highlightOnScreen marks an entry by its nav. reference)";
|
|
14
20
|
/** The references of the newest read: reference → element. The highlighter marks by them. */
|
|
15
21
|
export declare class ScreenReferenceRegistry {
|
|
16
22
|
protected elements: Map<string, Element>;
|
|
@@ -38,21 +44,59 @@ export interface DomScreenReaderOptions {
|
|
|
38
44
|
/** Whether the open screen has unsaved changes: `no`, or `yes (<form> (<fields>))` */
|
|
39
45
|
describeUnsavedChanges: () => string;
|
|
40
46
|
registry: ScreenReferenceRegistry;
|
|
47
|
+
/**
|
|
48
|
+
* Optional: the application's main menu (outside the content root). Its entries (`data-nav-key`) and groups
|
|
49
|
+
* (`data-nav-group`) on the screen are read as `nav.<key>` references, so the agent can name and mark them.
|
|
50
|
+
*/
|
|
51
|
+
findNavigation?: () => Element | null;
|
|
52
|
+
/**
|
|
53
|
+
* Optional: where the agent window is, e.g. `full screen: it covers the whole page`. The read writes it with the
|
|
54
|
+
* browser window's size (`Agent window: … · browser 1440×900 px`), so the agent knows what the user sees beside it.
|
|
55
|
+
*/
|
|
56
|
+
describeAgentWindow?: () => string | null;
|
|
41
57
|
}
|
|
42
58
|
/**
|
|
43
|
-
* Reads the open screen from the DOM: title and route,
|
|
44
|
-
*
|
|
59
|
+
* Reads the open screen from the DOM: title and route, the agent window and the browser size, tabs, open dialogs,
|
|
60
|
+
* messages, then per section its plain text (`Text: …`), tables, cards, fields and buttons, and the main menu. Never
|
|
61
|
+
* the agent window (`data-agent-skip`), never a secret's value.
|
|
45
62
|
*/
|
|
46
63
|
export declare class DomScreenReader implements ScreenReader {
|
|
47
64
|
protected readonly options: DomScreenReaderOptions;
|
|
65
|
+
/** The containers whose text this read wrote already (a section before the page around it). */
|
|
66
|
+
protected textReadContainers: Set<Element>;
|
|
48
67
|
constructor(options: DomScreenReaderOptions);
|
|
49
68
|
read({ focus, maxChars }: {
|
|
50
69
|
focus?: string;
|
|
51
70
|
maxChars: number;
|
|
52
71
|
}): ScreenSnapshot;
|
|
72
|
+
/** `Agent window: … · browser 1440×900 px`, or `Browser window: 1440×900 px` without a description of the window. */
|
|
73
|
+
protected describeWindow(): string;
|
|
74
|
+
/**
|
|
75
|
+
* The main menu: its entries (`data-nav-key`) and groups (`data-nav-group`) on the screen, as `nav.<key>`
|
|
76
|
+
* references (the menu of a compact layout shows icons only: an entry's name is its aria-label). A closed group
|
|
77
|
+
* shows only itself.
|
|
78
|
+
*/
|
|
79
|
+
protected readNavigation(register: (reference: string, element: Element) => string): string[];
|
|
53
80
|
protected readWhole(element: Element): string;
|
|
54
81
|
/** The sections of a container (by headings), each with its fields, tables and buttons. */
|
|
55
82
|
protected readContainer(container: Element, register: (reference: string, element: Element) => string): string[];
|
|
83
|
+
/**
|
|
84
|
+
* The plain text, tables, cards, fields and buttons of a container. Tables and cards go before the fields: a page's
|
|
85
|
+
* filters and forms never push its list out of the read.
|
|
86
|
+
*/
|
|
56
87
|
protected readElements(container: Element, register: (reference: string, element: Element) => string, seen: Set<Element>): string[];
|
|
88
|
+
/** The tables of a container and the cards of a card grid (`EntityListGrid` sets `data-row-key` on each). */
|
|
89
|
+
protected readTablesAndCards(container: Element, register: (reference: string, element: Element) => string, seen: Set<Element>): string[];
|
|
90
|
+
/**
|
|
91
|
+
* The visible text of a container that no field, table, card or button line carries, its pieces joined with " · "
|
|
92
|
+
* (pieces of one block with a space), without the text of a section read before: a message, a record's facts or a
|
|
93
|
+
* dashboard figure the user reads.
|
|
94
|
+
*/
|
|
95
|
+
protected readPlainText(container: Element): string;
|
|
96
|
+
/** The nearest ancestor that is not laid out inline (the container at the latest). */
|
|
97
|
+
protected blockOf(element: Element, container: Element): Element;
|
|
98
|
+
protected isInsideReadSection(element: Element, container: Element): boolean;
|
|
57
99
|
protected readTable(table: Element, register: (reference: string, element: Element) => string): TableFacts;
|
|
100
|
+
/** Whether the row's selection checkbox is checked. */
|
|
101
|
+
protected isRowChecked(row: Element): boolean;
|
|
58
102
|
}
|
|
@@ -20,6 +20,11 @@ export interface AgentUIState {
|
|
|
20
20
|
invalidFieldReferences?: string[];
|
|
21
21
|
/** The key of a dialog or drawer open on the screen */
|
|
22
22
|
openDialogKey?: string | null;
|
|
23
|
+
/** The mode the agent window shows (`full`, `compact`, `closed`, … the application's modes); `AgentUIClient` fills it from the window adapter */
|
|
24
|
+
agentWindow?: string | null;
|
|
25
|
+
/** The size of the browser window in CSS pixels; `AgentUIClient` fills it */
|
|
26
|
+
viewportWidth?: number | null;
|
|
27
|
+
viewportHeight?: number | null;
|
|
23
28
|
visible?: boolean | null;
|
|
24
29
|
/** ISO time of the capture */
|
|
25
30
|
capturedAt?: string | null;
|
|
@@ -156,6 +156,8 @@ export interface AgentWindowAdapter {
|
|
|
156
156
|
setMode(mode: string): boolean | Promise<boolean>;
|
|
157
157
|
/** Whether the window steps aside before a request of the type; default true for the three screen requests */
|
|
158
158
|
shouldStepAsideBefore?(requestType: ClientToolRequestType): boolean;
|
|
159
|
+
/** The mode the window shows now: the UI state reports it, so the agent knows whether the user sees the page */
|
|
160
|
+
getMode?(): string;
|
|
159
161
|
}
|
|
160
162
|
/** Shows the user the way to a target before it opens (`createDomScreenPathGuide()` is the DOM default). */
|
|
161
163
|
export interface ScreenPathGuide {
|
|
@@ -10,9 +10,17 @@
|
|
|
10
10
|
* - `s.<slug>` a section (its heading)
|
|
11
11
|
* - `t.<slug>` a tab
|
|
12
12
|
* - `a.<anchor>` an anchor the application set (`data-agent-anchor`)
|
|
13
|
+
* - `nav.<key>` an entry or group of the application's main menu (`data-nav-key`, `data-nav-group`)
|
|
13
14
|
*/
|
|
14
|
-
/**
|
|
15
|
-
|
|
15
|
+
/**
|
|
16
|
+
* The most rows of one table (and cards of one grid) in a read. A list of 200 loaded rows filled the whole read with
|
|
17
|
+
* rows before; the rest of the page never reached the model. `focus` on a row reads it whole.
|
|
18
|
+
*/
|
|
19
|
+
export declare const MAX_TABLE_ROWS = 15;
|
|
20
|
+
/** The most characters of one table cell in a read (a cell says how long it was; `focus` on the row reads it whole). */
|
|
21
|
+
export declare const MAX_CELL_CHARS = 60;
|
|
22
|
+
/** The most characters of the plain text of one section (`Text: …`). */
|
|
23
|
+
export declare const MAX_SECTION_TEXT_CHARS = 1200;
|
|
16
24
|
/** The most characters of one value in a read (a long text says how long it is; `focus` reads it whole). */
|
|
17
25
|
export declare const MAX_VALUE_CHARS = 200;
|
|
18
26
|
/** The most buttons in a read. */
|
|
@@ -55,7 +63,11 @@ export interface TableFacts {
|
|
|
55
63
|
/** All rows of the table in the DOM (more than shown) */
|
|
56
64
|
totalRows: number;
|
|
57
65
|
}
|
|
58
|
-
/**
|
|
66
|
+
/**
|
|
67
|
+
* A table as `| … |` lines with the row reference first, at most {@link MAX_TABLE_ROWS} rows, cells cut to
|
|
68
|
+
* {@link MAX_CELL_CHARS}. A column without text in every shown row (a selection box, an actions menu) is left out: the
|
|
69
|
+
* selection shows as `(selected)` on the row.
|
|
70
|
+
*/
|
|
59
71
|
export declare const formatTable: (table: TableFacts, maxRows?: number) => string[];
|
|
60
72
|
export interface ButtonFacts {
|
|
61
73
|
reference: string;
|
|
@@ -45,12 +45,48 @@ export declare const computePictureDimensions: (sourceWidth: number, sourceHeigh
|
|
|
45
45
|
export declare const computeRetryScale: (previousRetryScale: number, encodedBytes: number, byteBudget: number) => number;
|
|
46
46
|
/** Turns RGBA pixels grey in place; with `greyLevels` the grey is quantized to that many levels. */
|
|
47
47
|
export declare const convertPixelsToGrey: (pixels: Uint8ClampedArray, greyLevels?: number | null) => void;
|
|
48
|
+
/** A box in window coordinates. */
|
|
49
|
+
export interface PictureBox {
|
|
50
|
+
top: number;
|
|
51
|
+
left: number;
|
|
52
|
+
bottom: number;
|
|
53
|
+
right: number;
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* The style an element has without any style of the page: the browser's default for its tag. A clone's inline style
|
|
57
|
+
* carries only what differs from it, so the copy holds tens of declarations per element instead of all ~350 computed
|
|
58
|
+
* ones (measured: about 20 KB per element, 10 MB for 516 elements of a list page).
|
|
59
|
+
*/
|
|
60
|
+
export interface DefaultStyleSource {
|
|
61
|
+
/** The default value of `property` for an element of `tagName` (`namespaceUri` for SVG) */
|
|
62
|
+
valueOf(tagName: string, namespaceUri: string | null, property: string): string;
|
|
63
|
+
/** Frees what the source holds (a frame) */
|
|
64
|
+
dispose(): void;
|
|
65
|
+
}
|
|
66
|
+
/**
|
|
67
|
+
* The browser defaults read from an empty frame (no style sheet of the page reaches it), cached per tag. Without a
|
|
68
|
+
* frame (no document, a sandbox refusing it) every value is unknown and every declaration is copied, as before.
|
|
69
|
+
*/
|
|
70
|
+
export declare const createFrameDefaultStyleSource: (documentOfRoot: Document) => DefaultStyleSource;
|
|
71
|
+
export interface ScreenCloneOptions {
|
|
72
|
+
/** Whether computed styles are inlined; false in tests (default true) */
|
|
73
|
+
copyStyles?: boolean;
|
|
74
|
+
/**
|
|
75
|
+
* Only elements with a part inside this box are copied (window coordinates; default the browser window); `null`
|
|
76
|
+
* copies the whole page with its scroll containers expanded. A long list's rows below the window are left out:
|
|
77
|
+
* the picture shows what the user sees, and the copy stays small.
|
|
78
|
+
*/
|
|
79
|
+
visibleBox?: PictureBox | null;
|
|
80
|
+
/** The defaults a declaration is compared with (default: an empty frame, {@link createFrameDefaultStyleSource}) */
|
|
81
|
+
defaultStyles?: DefaultStyleSource | null;
|
|
82
|
+
}
|
|
48
83
|
/**
|
|
49
|
-
* A copy of `root` ready to be drawn:
|
|
50
|
-
*
|
|
51
|
-
*
|
|
84
|
+
* A copy of `root` ready to be drawn: the elements in the browser window only (`visibleBox`), computed styles inlined
|
|
85
|
+
* where they differ from the tag's default, form values written (passwords as dots), elements with `data-agent-skip`
|
|
86
|
+
* left out, the content of elements with `data-agent-secret` blanked (the box stays). With `visibleBox: null` the whole
|
|
87
|
+
* page is copied and scroll containers are expanded. `false` instead of options skips the styles (tests).
|
|
52
88
|
*/
|
|
53
|
-
export declare const prepareScreenCloneForPicture: (root: Element,
|
|
89
|
+
export declare const prepareScreenCloneForPicture: (root: Element, cloneOptions?: boolean | ScreenCloneOptions) => Element;
|
|
54
90
|
export interface DomScreenPictureCapturerOptions {
|
|
55
91
|
/** The element pictured; default the document element */
|
|
56
92
|
root?: () => Element | null;
|
|
@@ -58,7 +94,8 @@ export interface DomScreenPictureCapturerOptions {
|
|
|
58
94
|
quality?: number;
|
|
59
95
|
}
|
|
60
96
|
/**
|
|
61
|
-
* The DOM default of `ScreenPictureCapturer`: draws a styled copy of the
|
|
97
|
+
* The DOM default of `ScreenPictureCapturer`: draws a styled copy of what the browser window shows (SVG foreignObject
|
|
98
|
+
* onto a canvas; elements out of view are not copied, styles only where they differ from the browser's default) at the
|
|
62
99
|
* size of the preset, grey in `greyscale` and `machine` (64 levels), and encodes it as WebP (JPEG where the browser
|
|
63
100
|
* has no WebP encoder) within the byte budget; a miss retries from the source size, at most
|
|
64
101
|
* `MAX_PICTURE_ENCODE_ATTEMPTS` times. No dependency; what it cannot show is `PICTURE_LIMITATIONS`. Returns null when
|