@mgamadeus/ddd-agents 0.4.1 → 0.5.0

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.
@@ -7,7 +7,7 @@
7
7
  * Pure (no React, no app imports), so the logic tests cover it.
8
8
  */
9
9
  /** What the server asks a tab to do (`AgentClientToolRequest::TYPE_*`). */
10
- export type ClientToolRequestType = 'READ_SCREEN' | 'LIST_TARGETS' | 'OPEN_TARGET' | 'HIGHLIGHT';
10
+ export type ClientToolRequestType = 'READ_SCREEN' | 'LIST_TARGETS' | 'OPEN_TARGET' | 'HIGHLIGHT' | 'SET_WINDOW_MODE';
11
11
  /** A request as the run-state read delivers it. */
12
12
  export interface ClientToolRequestDelivery {
13
13
  id: number;
@@ -20,6 +20,8 @@ export interface ClientToolAnswer {
20
20
  outcome: string;
21
21
  text: string;
22
22
  details: Record<string, string | number | boolean | null>;
23
+ /** A picture of the screen (base64 of WebP, JPEG or PNG), only for a `READ_SCREEN` request with `format: picture` */
24
+ pictureBase64?: string;
23
25
  }
24
26
  /** A tab never starts a request with fewer seconds left: it would finish after the tool gave up. */
25
27
  export declare const MIN_SECONDS_LEFT_TO_START = 3;
@@ -39,6 +41,8 @@ export declare const CLIENT_TOOL_OUTCOMES: {
39
41
  readonly expiredBeforeStart: 'EXPIRED_BEFORE_START';
40
42
  readonly readFailed: 'READ_FAILED';
41
43
  readonly unknownRequest: 'UNKNOWN_REQUEST';
44
+ readonly unknownMode: 'UNKNOWN_MODE';
45
+ readonly pictureUnavailable: 'PICTURE_UNAVAILABLE';
42
46
  };
43
47
  export interface ScreenTargetFilter {
44
48
  /** The query parameter, e.g. `customerId` */
@@ -121,6 +125,50 @@ export interface ScreenHighlighter {
121
125
  mark(references: string[], note: string | null): ScreenMarkResult;
122
126
  clear(): void;
123
127
  }
128
+ /** The size presets of a screen picture (`pictureSize` of `getCurrentScreen`). */
129
+ export type ScreenPictureSize = 'small' | 'medium' | 'large';
130
+ /** How a screen picture is rendered (`renderMode` of `getCurrentScreen`). */
131
+ export type ScreenPictureRenderMode = 'colour' | 'greyscale' | 'machine';
132
+ export interface ScreenPictureRequest {
133
+ pictureSize: ScreenPictureSize;
134
+ renderMode: ScreenPictureRenderMode;
135
+ }
136
+ /** A captured picture of the screen. */
137
+ export interface ScreenPicture {
138
+ /** base64 of the encoded bytes, without a `data:` prefix */
139
+ base64: string;
140
+ mimeType: 'image/webp' | 'image/jpeg' | 'image/png';
141
+ width: number;
142
+ height: number;
143
+ byteSize: number;
144
+ }
145
+ /** Captures the open screen as a picture (`createDomScreenPictureCapturer()` is the DOM default). */
146
+ export interface ScreenPictureCapturer {
147
+ capture(request: ScreenPictureRequest): Promise<ScreenPicture | null>;
148
+ }
149
+ /** The agent window of the application: steps aside before the agent works on the screen, takes a requested mode. */
150
+ export interface AgentWindowAdapter {
151
+ /** Makes room for the screen (the default before `OPEN_TARGET`, `HIGHLIGHT` and a picture) */
152
+ stepAside(requestType: ClientToolRequestType): void | Promise<void>;
153
+ /** Back to the mode before `stepAside()` */
154
+ restore(): void | Promise<void>;
155
+ /** A mode the application knows (`SET_WINDOW_MODE`); false = unknown mode */
156
+ setMode(mode: string): boolean | Promise<boolean>;
157
+ /** Whether the window steps aside before a request of the type; default true for the three screen requests */
158
+ shouldStepAsideBefore?(requestType: ClientToolRequestType): boolean;
159
+ }
160
+ /** Shows the user the way to a target before it opens (`createDomScreenPathGuide()` is the DOM default). */
161
+ export interface ScreenPathGuide {
162
+ /**
163
+ * Shows the path to the target; never awaited by the runner, so it never delays the answer. Returns false when it
164
+ * shows nothing (reduced motion, already on the target, no element of the path on the screen).
165
+ */
166
+ guide(target: ScreenTarget, request: ScreenOpenRequest): boolean;
167
+ /** Stops a guide still running */
168
+ cancel(): void;
169
+ }
170
+ /** A request type the application handles itself (a type a host or package registered on the server). */
171
+ export type ClientToolRequestHandler = (parameters: Record<string, unknown>, delivery: ClientToolRequestDelivery) => ClientToolAnswer | Promise<ClientToolAnswer>;
124
172
  export interface ScreenAdapters {
125
173
  targets: ScreenTargetSource;
126
174
  navigator: ScreenNavigator;
@@ -128,6 +176,14 @@ export interface ScreenAdapters {
128
176
  highlighter: ScreenHighlighter;
129
177
  /** Whether the client is visible now */
130
178
  isVisible: () => boolean;
179
+ /** Optional: captures the screen as a picture; without it a picture request is answered `PICTURE_UNAVAILABLE` */
180
+ picture?: ScreenPictureCapturer;
181
+ /** Optional: the agent window; without it `SET_WINDOW_MODE` is answered `UNKNOWN_MODE` */
182
+ agentWindow?: AgentWindowAdapter;
183
+ /** Optional: the path guide shown before `OPEN_TARGET` */
184
+ pathGuide?: ScreenPathGuide;
185
+ /** Optional: handlers of further request types, by type; a type of the package is never replaced */
186
+ requestHandlers?: Record<string, ClientToolRequestHandler>;
131
187
  }
132
188
  /** The arguments of a delivery as an object; anything else is empty. */
133
189
  export declare const parseClientToolArguments: (argumentsJson: string) => Record<string, unknown>;
@@ -0,0 +1,36 @@
1
+ import type { ClientToolAnswerSender } from "./ClientToolRequestRunner";
2
+ import type { ClientToolAnswer, ClientToolRequestDelivery, ClientToolRequestType } from "./client-tools";
3
+ /** The message type of a client tool request on the realtime port (`AgentUIRealtimeMessageTypeProviderService`). */
4
+ export declare const CLIENT_TOOL_REQUEST_MESSAGE_TYPE = "agent.ui.clientToolRequest";
5
+ /** A message of the realtime port as the run-state read or the host's transport delivers it (`AgentRealtimeMessageDelivery`). */
6
+ export interface AgentRealtimeMessageDelivery {
7
+ messageType: string;
8
+ messageKey: string;
9
+ /** One JSON object */
10
+ payloadJson: string;
11
+ secondsLeft: number;
12
+ }
13
+ /** What a client needs to listen on the host's transport (`AgentRealtimeListenerCredential`). */
14
+ export interface AgentRealtimeListenerCredential {
15
+ transportName: string;
16
+ credential: string;
17
+ listenPath?: string | null;
18
+ expiresAt?: string | null;
19
+ }
20
+ /** The client tool request a realtime message carries, or null for another type or a payload that does not parse. */
21
+ export declare const readClientToolRequestOfRealtimeMessage: (message: AgentRealtimeMessageDelivery) => ClientToolRequestDelivery | null;
22
+ /** What takes an arrived client tool request (an `AgentUIClient`). */
23
+ export interface ClientToolRequestAcceptor {
24
+ acceptClientToolRequest(conversationId: number, delivery: ClientToolRequestDelivery, sendAnswer: ClientToolAnswerSender): void;
25
+ }
26
+ /**
27
+ * The arrival adapter for a host transport: hand it every message the transport receives for a conversation; a
28
+ * client tool request goes to the UI client (which runs a request id once, so the run-state read delivering the same
29
+ * request is harmless), any other type to `onOtherMessage`. Returns whether the message was a client tool request.
30
+ */
31
+ export declare const acceptArrivedRealtimeMessage: (conversationId: number, message: AgentRealtimeMessageDelivery, acceptor: ClientToolRequestAcceptor, sendAnswer: ClientToolAnswerSender, onOtherMessage?: (conversationId: number, message: AgentRealtimeMessageDelivery) => void) => boolean;
32
+ /**
33
+ * The dev helper: runs a request through the UI client as if the server had sent it and resolves with the answer, so
34
+ * an application tries its adapters without a model (e.g. from the browser console in development).
35
+ */
36
+ export declare const runClientToolRequestForDevelopment: (acceptor: ClientToolRequestAcceptor, requestType: ClientToolRequestType | string, parameters?: Record<string, unknown>, secondsLeft?: number) => Promise<ClientToolAnswer>;
@@ -0,0 +1,67 @@
1
+ import type { ScreenPictureCapturer, ScreenPictureRenderMode, ScreenPictureRequest, ScreenPictureSize } from "./client-tools";
2
+ /**
3
+ * What a picture of the screen cannot show. The same sentences as `AgentUIMCPPackage::PICTURE_LIMITATIONS` of the
4
+ * server (a contract test compares them): the model reads them beside every picture.
5
+ */
6
+ export declare const PICTURE_LIMITATIONS: readonly string[];
7
+ /** The budgets of one size preset: the long edge, the pixels and the encoded bytes. */
8
+ export interface ScreenPicturePreset {
9
+ maxLongEdge: number;
10
+ maxPixels: number;
11
+ maxBytes: number;
12
+ }
13
+ /** The three size presets; `large` stays below the server's caps (4,000,000 pixels, 614,400 bytes). */
14
+ export declare const SCREEN_PICTURE_PRESETS: Record<ScreenPictureSize, ScreenPicturePreset>;
15
+ /** The machine mode: 64 grey levels, 75 % of the size, half the byte budget (a picture for the model, not a person). */
16
+ export declare const MACHINE_MODE_GREY_LEVELS = 64;
17
+ export declare const MACHINE_MODE_SIZE_FACTOR = 0.75;
18
+ export declare const MACHINE_MODE_BYTE_FACTOR = 0.5;
19
+ /** The most encodings of one capture; each retry scales down from the source. */
20
+ export declare const MAX_PICTURE_ENCODE_ATTEMPTS = 4;
21
+ /** The most elements a capture copies (a larger page keeps its first elements). */
22
+ export declare const MAX_PICTURE_ELEMENTS = 8000;
23
+ /** The attribute that leaves an element out of a picture. */
24
+ export declare const AGENT_SKIP_ATTRIBUTE = "data-agent-skip";
25
+ /** The attribute that blanks an element's content in a picture (its box stays). */
26
+ export declare const AGENT_SECRET_ATTRIBUTE = "data-agent-secret";
27
+ export interface ScreenPictureDimensions {
28
+ width: number;
29
+ height: number;
30
+ /** The factor from the source size */
31
+ scale: number;
32
+ }
33
+ /** The byte budget of a preset in a render mode. */
34
+ export declare const computePictureByteBudget: (pictureSize: ScreenPictureSize, renderMode: ScreenPictureRenderMode) => number;
35
+ /**
36
+ * The size of the picture of a source: within the long edge and the pixels of the preset (never larger than the
37
+ * source), 75 % of it in the machine mode, times `retryScale` (a retry's factor, always taken from the source size).
38
+ */
39
+ export declare const computePictureDimensions: (sourceWidth: number, sourceHeight: number, request: ScreenPictureRequest, retryScale?: number) => ScreenPictureDimensions;
40
+ /**
41
+ * The factor of the next attempt after an encoding of `encodedBytes` missed the budget: the bytes shrink about with the
42
+ * pixels, so the side shrinks with the square root, with a margin. Applied to the source size, never to the last
43
+ * picture (no blur piling up over retries).
44
+ */
45
+ export declare const computeRetryScale: (previousRetryScale: number, encodedBytes: number, byteBudget: number) => number;
46
+ /** Turns RGBA pixels grey in place; with `greyLevels` the grey is quantized to that many levels. */
47
+ export declare const convertPixelsToGrey: (pixels: Uint8ClampedArray, greyLevels?: number | null) => void;
48
+ /**
49
+ * A copy of `root` ready to be drawn: computed styles inlined, form values written (passwords as dots), elements with
50
+ * `data-agent-skip` left out, the content of elements with `data-agent-secret` blanked (the box stays), scroll
51
+ * containers expanded. `copyStyles` false skips the styles (tests).
52
+ */
53
+ export declare const prepareScreenCloneForPicture: (root: Element, copyStyles?: boolean) => Element;
54
+ export interface DomScreenPictureCapturerOptions {
55
+ /** The element pictured; default the document element */
56
+ root?: () => Element | null;
57
+ /** The quality of the first encoding (default 0.8); a retry lowers it once to 0.65 */
58
+ quality?: number;
59
+ }
60
+ /**
61
+ * The DOM default of `ScreenPictureCapturer`: draws a styled copy of the page (SVG foreignObject onto a canvas) at the
62
+ * size of the preset, grey in `greyscale` and `machine` (64 levels), and encodes it as WebP (JPEG where the browser
63
+ * has no WebP encoder) within the byte budget; a miss retries from the source size, at most
64
+ * `MAX_PICTURE_ENCODE_ATTEMPTS` times. No dependency; what it cannot show is `PICTURE_LIMITATIONS`. Returns null when
65
+ * the browser refuses (a tainted canvas, no canvas), and the runner answers `PICTURE_UNAVAILABLE`.
66
+ */
67
+ export declare const createDomScreenPictureCapturer: (options?: DomScreenPictureCapturerOptions) => ScreenPictureCapturer;