@ingcreators/annot-mcp 0.1.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.
@@ -0,0 +1,43 @@
1
+ import { BBox, BboxAnnotation, LocatorAnnotation } from '../dsl/types.js';
2
+ export interface PageLike {
3
+ locator(selector: string): LocatorLike;
4
+ }
5
+ export interface LocatorLike {
6
+ boundingBox(): Promise<BBox | null>;
7
+ }
8
+ export declare class LocatorResolutionError extends Error {
9
+ readonly locator: string;
10
+ constructor(locator: string, message: string);
11
+ }
12
+ /**
13
+ * Resolve a single locator string to its bounding box. Throws
14
+ * `LocatorResolutionError` when the locator matches nothing or
15
+ * lies outside the visible viewport (Playwright returns `null` for
16
+ * both cases — we can't disambiguate without an extra `.count()`
17
+ * call, and the error message keeps both possibilities in scope).
18
+ */
19
+ export declare function resolveLocator(page: PageLike, locator: string): Promise<BBox>;
20
+ /**
21
+ * Convert a `LocatorAnnotation` to its `BboxAnnotation` equivalent
22
+ * by resolving any embedded locator strings. Annotation type
23
+ * dictates the adaptation rule for non-rect shapes:
24
+ *
25
+ * - `rect` — bbox stands in directly.
26
+ * - `circle` — center = bbox centroid; radius = `min(w,h) / 2`.
27
+ * - `arrow` — each endpoint resolves independently; locator
28
+ * endpoints land at the bbox centroid.
29
+ * - `text` — `at` = bbox top-left, raised one font line so
30
+ * the caption sits above the element.
31
+ * - `callout` — `at` / `atLocator` controls the caption anchor;
32
+ * `targetBbox` / `targetLocator` the rect.
33
+ * - `raw` — passes through unchanged.
34
+ */
35
+ export declare function resolveLocatorAnnotation(page: PageLike, annotation: LocatorAnnotation): Promise<BboxAnnotation>;
36
+ /**
37
+ * Resolve every entry in a `LocatorAnnotation[]` against the page,
38
+ * returning the corresponding `BboxAnnotation[]`. Failures throw
39
+ * the first `LocatorResolutionError` — callers surface this as a
40
+ * structured tool error so agents can retry with a corrected
41
+ * selector.
42
+ */
43
+ export declare function resolveLocatorAnnotations(page: PageLike, annotations: readonly LocatorAnnotation[]): Promise<BboxAnnotation[]>;
@@ -0,0 +1,6 @@
1
+ import { BBox } from '../dsl/types.js';
2
+ /**
3
+ * Walk a pixelmatch diff mask and return one bbox per contiguous
4
+ * changed region. 4-connected adjacency.
5
+ */
6
+ export declare function aggregateDiffRegions(diffRgba: Uint8Array, width: number, height: number): BBox[];
@@ -0,0 +1,30 @@
1
+ import { BBox } from '../dsl/types.js';
2
+ export interface DiffResult {
3
+ /** Number of mismatched pixels. */
4
+ mismatchedPixels: number;
5
+ /** Bounding boxes of contiguous changed regions. */
6
+ regions: BBox[];
7
+ /** Dimensions of the input pair. */
8
+ width: number;
9
+ height: number;
10
+ }
11
+ export interface DiffOptions {
12
+ /** Matching threshold (0 to 1); smaller is more sensitive. */
13
+ threshold?: number;
14
+ }
15
+ export declare class DimensionMismatchError extends Error {
16
+ constructor(a: {
17
+ width: number;
18
+ height: number;
19
+ }, b: {
20
+ width: number;
21
+ height: number;
22
+ });
23
+ }
24
+ /**
25
+ * Compare two PNGs pixel-by-pixel and return the changed-region
26
+ * bboxes. Throws `DimensionMismatchError` when the inputs have
27
+ * different sizes — the agent has to capture both with the same
28
+ * viewport for the comparison to make sense.
29
+ */
30
+ export declare function diffScreenshots(before: Uint8Array, after: Uint8Array, options?: DiffOptions): Promise<DiffResult>;
@@ -0,0 +1,466 @@
1
+ /** Common shared subschemas — referenced from `$defs` in each tool's
2
+ * inputSchema. Spread these into the tool's `$defs` object at
3
+ * registration time. */
4
+ export declare const SHARED_DEFS: {
5
+ BBox: {
6
+ type: string;
7
+ required: string[];
8
+ additionalProperties: boolean;
9
+ properties: {
10
+ x: {
11
+ type: string;
12
+ };
13
+ y: {
14
+ type: string;
15
+ };
16
+ width: {
17
+ type: string;
18
+ minimum: number;
19
+ };
20
+ height: {
21
+ type: string;
22
+ minimum: number;
23
+ };
24
+ };
25
+ };
26
+ Point: {
27
+ type: string;
28
+ required: string[];
29
+ additionalProperties: boolean;
30
+ properties: {
31
+ x: {
32
+ type: string;
33
+ };
34
+ y: {
35
+ type: string;
36
+ };
37
+ };
38
+ };
39
+ Intent: {
40
+ type: string;
41
+ enum: string[];
42
+ };
43
+ AnnotationStyle: {
44
+ type: string;
45
+ additionalProperties: boolean;
46
+ properties: {
47
+ intent: {
48
+ $ref: string;
49
+ };
50
+ stroke: {
51
+ type: string;
52
+ };
53
+ strokeWidth: {
54
+ type: string;
55
+ minimum: number;
56
+ };
57
+ fill: {
58
+ type: string;
59
+ };
60
+ color: {
61
+ type: string;
62
+ };
63
+ };
64
+ };
65
+ Locator: {
66
+ type: string;
67
+ minLength: number;
68
+ };
69
+ };
70
+ export declare const BBOX_ANNOTATION_SCHEMA: {
71
+ oneOf: ({
72
+ type: string;
73
+ required: string[];
74
+ additionalProperties: boolean;
75
+ properties: {
76
+ type: {
77
+ const: string;
78
+ };
79
+ bbox: {
80
+ $ref: string;
81
+ };
82
+ intent: {
83
+ $ref: string;
84
+ };
85
+ stroke: {
86
+ type: string;
87
+ };
88
+ strokeWidth: {
89
+ type: string;
90
+ minimum: number;
91
+ };
92
+ fill: {
93
+ type: string;
94
+ };
95
+ color: {
96
+ type: string;
97
+ };
98
+ };
99
+ } | {
100
+ type: string;
101
+ required: string[];
102
+ additionalProperties: boolean;
103
+ properties: {
104
+ type: {
105
+ const: string;
106
+ };
107
+ center: {
108
+ $ref: string;
109
+ };
110
+ radius: {
111
+ type: string;
112
+ minimum: number;
113
+ };
114
+ intent: {
115
+ $ref: string;
116
+ };
117
+ stroke: {
118
+ type: string;
119
+ };
120
+ strokeWidth: {
121
+ type: string;
122
+ minimum: number;
123
+ };
124
+ fill: {
125
+ type: string;
126
+ };
127
+ color: {
128
+ type: string;
129
+ };
130
+ };
131
+ } | {
132
+ type: string;
133
+ required: string[];
134
+ additionalProperties: boolean;
135
+ properties: {
136
+ type: {
137
+ const: string;
138
+ };
139
+ from: {
140
+ $ref: string;
141
+ };
142
+ to: {
143
+ $ref: string;
144
+ };
145
+ intent: {
146
+ $ref: string;
147
+ };
148
+ stroke: {
149
+ type: string;
150
+ };
151
+ strokeWidth: {
152
+ type: string;
153
+ minimum: number;
154
+ };
155
+ color: {
156
+ type: string;
157
+ };
158
+ };
159
+ } | {
160
+ type: string;
161
+ required: string[];
162
+ additionalProperties: boolean;
163
+ properties: {
164
+ type: {
165
+ const: string;
166
+ };
167
+ at: {
168
+ $ref: string;
169
+ };
170
+ content: {
171
+ type: string;
172
+ };
173
+ fontSize: {
174
+ type: string;
175
+ minimum: number;
176
+ };
177
+ anchor: {
178
+ type: string;
179
+ enum: string[];
180
+ };
181
+ intent: {
182
+ $ref: string;
183
+ };
184
+ color: {
185
+ type: string;
186
+ };
187
+ };
188
+ } | {
189
+ type: string;
190
+ required: string[];
191
+ additionalProperties: boolean;
192
+ properties: {
193
+ type: {
194
+ const: string;
195
+ };
196
+ at: {
197
+ $ref: string;
198
+ };
199
+ targetBbox: {
200
+ $ref: string;
201
+ };
202
+ content: {
203
+ type: string;
204
+ };
205
+ intent: {
206
+ $ref: string;
207
+ };
208
+ stroke: {
209
+ type: string;
210
+ };
211
+ color: {
212
+ type: string;
213
+ };
214
+ };
215
+ } | {
216
+ type: string;
217
+ required: string[];
218
+ additionalProperties: boolean;
219
+ properties: {
220
+ type: {
221
+ const: string;
222
+ };
223
+ svgFragment: {
224
+ type: string;
225
+ };
226
+ };
227
+ })[];
228
+ };
229
+ export declare const LOCATOR_ANNOTATION_SCHEMA: {
230
+ oneOf: ({
231
+ type: string;
232
+ required: string[];
233
+ additionalProperties: boolean;
234
+ properties: {
235
+ type: {
236
+ const: string;
237
+ };
238
+ svgFragment: {
239
+ type: string;
240
+ };
241
+ };
242
+ } | {
243
+ type: string;
244
+ required: string[];
245
+ additionalProperties: boolean;
246
+ properties: {
247
+ type: {
248
+ const: string;
249
+ };
250
+ bbox: {
251
+ $ref: string;
252
+ };
253
+ locator: {
254
+ $ref: string;
255
+ };
256
+ intent: {
257
+ $ref: string;
258
+ };
259
+ stroke: {
260
+ type: string;
261
+ };
262
+ strokeWidth: {
263
+ type: string;
264
+ minimum: number;
265
+ };
266
+ fill: {
267
+ type: string;
268
+ };
269
+ color: {
270
+ type: string;
271
+ };
272
+ };
273
+ anyOf: {
274
+ required: string[];
275
+ }[];
276
+ } | {
277
+ type: string;
278
+ required: string[];
279
+ additionalProperties: boolean;
280
+ properties: {
281
+ type: {
282
+ const: string;
283
+ };
284
+ center: {
285
+ $ref: string;
286
+ };
287
+ radius: {
288
+ type: string;
289
+ minimum: number;
290
+ };
291
+ locator: {
292
+ $ref: string;
293
+ };
294
+ intent: {
295
+ $ref: string;
296
+ };
297
+ stroke: {
298
+ type: string;
299
+ };
300
+ strokeWidth: {
301
+ type: string;
302
+ minimum: number;
303
+ };
304
+ fill: {
305
+ type: string;
306
+ };
307
+ color: {
308
+ type: string;
309
+ };
310
+ };
311
+ anyOf: {
312
+ required: string[];
313
+ }[];
314
+ } | {
315
+ type: string;
316
+ required: string[];
317
+ additionalProperties: boolean;
318
+ properties: {
319
+ type: {
320
+ const: string;
321
+ };
322
+ from: {
323
+ $ref: string;
324
+ };
325
+ fromLocator: {
326
+ $ref: string;
327
+ };
328
+ to: {
329
+ $ref: string;
330
+ };
331
+ toLocator: {
332
+ $ref: string;
333
+ };
334
+ intent: {
335
+ $ref: string;
336
+ };
337
+ stroke: {
338
+ type: string;
339
+ };
340
+ strokeWidth: {
341
+ type: string;
342
+ minimum: number;
343
+ };
344
+ color: {
345
+ type: string;
346
+ };
347
+ };
348
+ allOf: {
349
+ anyOf: {
350
+ required: string[];
351
+ }[];
352
+ }[];
353
+ } | {
354
+ type: string;
355
+ required: string[];
356
+ additionalProperties: boolean;
357
+ properties: {
358
+ type: {
359
+ const: string;
360
+ };
361
+ at: {
362
+ $ref: string;
363
+ };
364
+ locator: {
365
+ $ref: string;
366
+ };
367
+ content: {
368
+ type: string;
369
+ };
370
+ fontSize: {
371
+ type: string;
372
+ minimum: number;
373
+ };
374
+ anchor: {
375
+ type: string;
376
+ enum: string[];
377
+ };
378
+ intent: {
379
+ $ref: string;
380
+ };
381
+ color: {
382
+ type: string;
383
+ };
384
+ };
385
+ anyOf: {
386
+ required: string[];
387
+ }[];
388
+ } | {
389
+ type: string;
390
+ required: string[];
391
+ additionalProperties: boolean;
392
+ properties: {
393
+ type: {
394
+ const: string;
395
+ };
396
+ at: {
397
+ $ref: string;
398
+ };
399
+ atLocator: {
400
+ $ref: string;
401
+ };
402
+ targetBbox: {
403
+ $ref: string;
404
+ };
405
+ targetLocator: {
406
+ $ref: string;
407
+ };
408
+ content: {
409
+ type: string;
410
+ };
411
+ intent: {
412
+ $ref: string;
413
+ };
414
+ stroke: {
415
+ type: string;
416
+ };
417
+ color: {
418
+ type: string;
419
+ };
420
+ };
421
+ allOf: {
422
+ anyOf: {
423
+ required: string[];
424
+ }[];
425
+ }[];
426
+ })[];
427
+ };
428
+ export declare const BBOX_REDACT_REGION_SCHEMA: {
429
+ type: string;
430
+ required: string[];
431
+ additionalProperties: boolean;
432
+ properties: {
433
+ bbox: {
434
+ $ref: string;
435
+ };
436
+ style: {
437
+ type: string;
438
+ enum: string[];
439
+ };
440
+ color: {
441
+ type: string;
442
+ };
443
+ };
444
+ };
445
+ export declare const LOCATOR_REDACT_REGION_SCHEMA: {
446
+ type: string;
447
+ additionalProperties: boolean;
448
+ properties: {
449
+ bbox: {
450
+ $ref: string;
451
+ };
452
+ locator: {
453
+ $ref: string;
454
+ };
455
+ style: {
456
+ type: string;
457
+ enum: string[];
458
+ };
459
+ color: {
460
+ type: string;
461
+ };
462
+ };
463
+ anyOf: {
464
+ required: string[];
465
+ }[];
466
+ };
@@ -0,0 +1,34 @@
1
+ export interface BoundingBox {
2
+ x: number;
3
+ y: number;
4
+ width: number;
5
+ height: number;
6
+ }
7
+ export interface Point {
8
+ x: number;
9
+ y: number;
10
+ }
11
+ export interface RectOptions {
12
+ stroke?: string;
13
+ strokeWidth?: number;
14
+ fill?: string;
15
+ }
16
+ export interface ArrowOptions {
17
+ color?: string;
18
+ strokeWidth?: number;
19
+ }
20
+ export interface TextOptions {
21
+ color?: string;
22
+ fontSize?: number;
23
+ anchor?: "start" | "middle" | "end";
24
+ }
25
+ /** Outline a bounding box with an SVG `<rect>`. */
26
+ export declare function rectForBoundingBox(bbox: BoundingBox, opts?: RectOptions): string;
27
+ /**
28
+ * Draw an arrow from `from` to `to`. Inlines a unique-id `<marker>`
29
+ * definition so the helper is self-contained — call it twice and
30
+ * each call produces a distinct arrowhead marker.
31
+ */
32
+ export declare function arrowBetween(from: Point, to: Point, opts?: ArrowOptions): string;
33
+ /** Drop a text label at a position. */
34
+ export declare function textAt(at: Point, content: string, opts?: TextOptions): string;
@@ -0,0 +1,10 @@
1
+ import { BboxAnnotation } from './types.js';
2
+ /**
3
+ * Convert a list of bbox-flavour annotations into a single SVG
4
+ * fragment string. The fragment is suitable as the
5
+ * `annotationsSvg` payload for `@ingcreators/annot-annotator`.
6
+ *
7
+ * Phase 1 emits the bare fragments only (no `<svg>` wrapper); the
8
+ * annotator's sanitiser handles wrapping at rasterise time.
9
+ */
10
+ export declare function bboxAnnotationsToSvg(annotations: readonly BboxAnnotation[]): string;
@@ -0,0 +1,126 @@
1
+ /** Axis-aligned bounding box. Coordinates are page pixels. */
2
+ export interface BBox {
3
+ x: number;
4
+ y: number;
5
+ width: number;
6
+ height: number;
7
+ }
8
+ /** Point in page pixels. */
9
+ export interface Point {
10
+ x: number;
11
+ y: number;
12
+ }
13
+ /**
14
+ * Semantic colour shorthand. Resolves to the Annot design system's
15
+ * matching token (e.g. `intent: "error"` → `--annot-color-error`).
16
+ * Explicit `stroke` / `color` / `fill` on an annotation override
17
+ * the intent-derived defaults.
18
+ */
19
+ export type Intent = "info" | "warning" | "error" | "success" | "neutral";
20
+ /** Style overrides shared across most annotation shapes. */
21
+ export interface AnnotationStyle {
22
+ intent?: Intent;
23
+ stroke?: string;
24
+ strokeWidth?: number;
25
+ fill?: string;
26
+ color?: string;
27
+ }
28
+ export type BboxRectAnnotation = AnnotationStyle & {
29
+ type: "rect";
30
+ bbox: BBox;
31
+ };
32
+ export type BboxCircleAnnotation = AnnotationStyle & {
33
+ type: "circle";
34
+ center: Point;
35
+ radius: number;
36
+ };
37
+ export type BboxArrowAnnotation = AnnotationStyle & {
38
+ type: "arrow";
39
+ from: Point;
40
+ to: Point;
41
+ };
42
+ export type BboxTextAnnotation = AnnotationStyle & {
43
+ type: "text";
44
+ at: Point;
45
+ content: string;
46
+ fontSize?: number;
47
+ anchor?: "start" | "middle" | "end";
48
+ };
49
+ export type BboxCalloutAnnotation = AnnotationStyle & {
50
+ type: "callout";
51
+ at: Point;
52
+ targetBbox: BBox;
53
+ content: string;
54
+ };
55
+ export interface RawAnnotation {
56
+ type: "raw";
57
+ svgFragment: string;
58
+ }
59
+ export type BboxAnnotation = BboxRectAnnotation | BboxCircleAnnotation | BboxArrowAnnotation | BboxTextAnnotation | BboxCalloutAnnotation | RawAnnotation;
60
+ /**
61
+ * Playwright locator string. Follows the standard locator grammar:
62
+ * CSS selectors (`button.primary`), text engines (`text=Submit`,
63
+ * `button:has-text("Submit")`), ARIA roles (`role=button[name="Sign in"]`),
64
+ * test ids (`[data-testid="email"]`), and chained `>>` operators.
65
+ */
66
+ export type Locator = string;
67
+ export type LocatorRectAnnotation = AnnotationStyle & {
68
+ type: "rect";
69
+ /** Exactly one of `bbox` / `locator` is required. */
70
+ bbox?: BBox;
71
+ locator?: Locator;
72
+ };
73
+ export type LocatorCircleAnnotation = AnnotationStyle & {
74
+ type: "circle";
75
+ /** Coordinate path. */
76
+ center?: Point;
77
+ radius?: number;
78
+ /** Locator path. Radius derives from `min(width, height) / 2`. */
79
+ locator?: Locator;
80
+ };
81
+ export type LocatorArrowAnnotation = AnnotationStyle & {
82
+ type: "arrow";
83
+ /** Exactly one of `from` / `fromLocator` is required. */
84
+ from?: Point;
85
+ fromLocator?: Locator;
86
+ /** Exactly one of `to` / `toLocator` is required. */
87
+ to?: Point;
88
+ toLocator?: Locator;
89
+ };
90
+ export type LocatorTextAnnotation = AnnotationStyle & {
91
+ type: "text";
92
+ /** Coordinate path. */
93
+ at?: Point;
94
+ /**
95
+ * Locator path. `at` becomes the bbox top-left, with the text
96
+ * placed directly above the bbox.
97
+ */
98
+ locator?: Locator;
99
+ content: string;
100
+ fontSize?: number;
101
+ anchor?: "start" | "middle" | "end";
102
+ };
103
+ export type LocatorCalloutAnnotation = AnnotationStyle & {
104
+ type: "callout";
105
+ /** Coordinate path for the caption anchor. */
106
+ at?: Point;
107
+ atLocator?: Locator;
108
+ /** Coordinate path for the targeted region. */
109
+ targetBbox?: BBox;
110
+ targetLocator?: Locator;
111
+ content: string;
112
+ };
113
+ export type LocatorAnnotation = LocatorRectAnnotation | LocatorCircleAnnotation | LocatorArrowAnnotation | LocatorTextAnnotation | LocatorCalloutAnnotation | RawAnnotation;
114
+ export type RedactStyle = "solid" | "mosaic" | "blur";
115
+ export interface BboxRedactRegion {
116
+ bbox: BBox;
117
+ style?: RedactStyle;
118
+ /** CSS colour, applied only when `style` is `"solid"`. */
119
+ color?: string;
120
+ }
121
+ export type LocatorRedactRegion = {
122
+ bbox?: BBox;
123
+ locator?: Locator;
124
+ style?: RedactStyle;
125
+ color?: string;
126
+ };