@xpert-ai/chatkit-host-automation 0.3.4 → 0.3.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.
Files changed (3) hide show
  1. package/dist/index.d.ts +632 -1
  2. package/dist/index.js +1205 -384
  3. package/package.json +2 -2
package/dist/index.js CHANGED
@@ -1,4 +1,4 @@
1
- const tt = [
1
+ const vt = [
2
2
  "host_page_snapshot",
3
3
  "host_page_click",
4
4
  "host_page_fill",
@@ -10,10 +10,441 @@ const tt = [
10
10
  "host_page_focus",
11
11
  "host_page_pointer",
12
12
  "host_page_screenshot",
13
+ "host_page_read",
13
14
  "host_page_wait_for"
14
- ], et = new Set(
15
- tt
16
- ), nt = [
15
+ ];
16
+ function dt(t) {
17
+ return (t ?? "").replace(/\s+/g, " ").trim();
18
+ }
19
+ function J(t, e = 600) {
20
+ return t.length > e ? `${t.slice(0, e)}... [truncated ${t.length - e} chars]` : t;
21
+ }
22
+ function xt(t, e = 600) {
23
+ return t ? J(t, e) : void 0;
24
+ }
25
+ function C(t) {
26
+ const e = dt(t.textContent);
27
+ return e ? J(e) : void 0;
28
+ }
29
+ function ft(t) {
30
+ const e = dt(
31
+ Array.from(t.childNodes).filter((n) => n.nodeType === Node.TEXT_NODE).map((n) => n.textContent ?? "").join(" ")
32
+ );
33
+ return e ? J(e) : void 0;
34
+ }
35
+ function D(t) {
36
+ var o;
37
+ if (!(t instanceof HTMLElement || t instanceof SVGElement) || t instanceof HTMLElement && t.hidden)
38
+ return !1;
39
+ const e = (o = t.ownerDocument.defaultView) == null ? void 0 : o.getComputedStyle(t);
40
+ if (e && (e.display === "none" || e.visibility === "hidden" || e.opacity === "0"))
41
+ return !1;
42
+ const n = t.getBoundingClientRect();
43
+ return n.width > 0 && n.height > 0;
44
+ }
45
+ function k(t) {
46
+ const e = t.getBoundingClientRect();
47
+ return {
48
+ x: e.left,
49
+ y: e.top,
50
+ width: e.width,
51
+ height: e.height
52
+ };
53
+ }
54
+ function _t(t) {
55
+ return t instanceof Document ? t : t.ownerDocument;
56
+ }
57
+ function Q(t) {
58
+ let e = t;
59
+ for (; e; ) {
60
+ let n = e.previousElementSibling;
61
+ for (; n; ) {
62
+ if (n.matches('h1,h2,h3,h4,h5,h6,[role="heading"]'))
63
+ return C(n);
64
+ const o = n.querySelector(
65
+ 'h1,h2,h3,h4,h5,h6,[role="heading"]'
66
+ );
67
+ if (o)
68
+ return C(o);
69
+ n = n.previousElementSibling;
70
+ }
71
+ e = e.parentElement;
72
+ }
73
+ }
74
+ function W(t) {
75
+ const e = Array.from(t.children).map((n) => ft(n) ?? C(n)).filter((n) => !!n);
76
+ return e.length > 1 ? e : t.children.length === 1 ? W(t.children[0]) : e;
77
+ }
78
+ function Tt(t) {
79
+ if (Array.from(t.children).some(
80
+ (i) => W(i).length === 2
81
+ ))
82
+ return;
83
+ const e = W(t);
84
+ if (e.length !== 2)
85
+ return;
86
+ const [n, o] = e;
87
+ if (!(!n || !o || n === o || n.length > 120))
88
+ return { name: n, value: o };
89
+ }
90
+ function St(t) {
91
+ return t.fields ? t.fields.slice(0, 2).map((e) => `${e.name}: ${e.value}`) : t.items ? t.items.slice(0, 2) : t.rows ? t.rows.slice(0, 2).map((e) => e.join(" | ")) : t.text ? [t.text] : [];
92
+ }
93
+ function Ct(t) {
94
+ return t.fields ? t.fields.length : t.items ? t.items.length : t.rows ? t.rows.length : t.text ? 1 : 0;
95
+ }
96
+ function Mt(t) {
97
+ return [
98
+ t.heading,
99
+ t.text,
100
+ ...t.items ?? [],
101
+ ...(t.fields ?? []).flatMap((e) => [e.name, e.value]),
102
+ ...t.headers ?? [],
103
+ ...(t.rows ?? []).flat()
104
+ ].reduce((e, n) => e + ((n == null ? void 0 : n.length) ?? 0), 0);
105
+ }
106
+ function At(t) {
107
+ return t.slice(0, 80).map((e, n) => {
108
+ const o = Mt(e), i = `b${n + 1}`;
109
+ return {
110
+ ...e,
111
+ blockId: i,
112
+ preview: St(e),
113
+ itemCount: Ct(e),
114
+ chars: o,
115
+ truncated: o > 4e3,
116
+ readHint: {
117
+ tool: "host_page_read",
118
+ args: { blockId: i }
119
+ }
120
+ };
121
+ });
122
+ }
123
+ function Lt(t) {
124
+ return t.map((e, n) => ({
125
+ index: n,
126
+ blockId: e.blockId,
127
+ type: e.type,
128
+ heading: e.heading,
129
+ level: e.level,
130
+ itemCount: e.itemCount,
131
+ chars: e.chars,
132
+ truncated: e.truncated
133
+ }));
134
+ }
135
+ function Rt(t) {
136
+ return t.truncated ? "block_truncated" : t.type === "keyValueList" ? "structured_fields" : t.type === "table" ? "structured_table" : t.itemCount > 2 ? "preview_incomplete" : "long_readable_block";
137
+ }
138
+ function kt(t) {
139
+ return (t.type === "keyValueList" ? 100 : t.type === "table" ? 90 : t.type === "list" ? 80 : t.type === "paragraph" ? 50 : 10) + (t.truncated ? 40 : 0) + Math.min(t.itemCount, 20) + Math.min(Math.floor(t.chars / 400), 20);
140
+ }
141
+ function Pt(t) {
142
+ return t.filter(
143
+ (e) => e.type !== "heading" && (e.truncated || e.itemCount > 2 || e.chars > 600)
144
+ ).map((e, n) => ({
145
+ block: e,
146
+ index: n,
147
+ score: kt(e)
148
+ })).sort((e, n) => n.score - e.score || e.index - n.index).slice(0, 12).sort((e, n) => e.index - n.index).map(({ block: e }) => ({
149
+ blockId: e.blockId,
150
+ type: e.type,
151
+ heading: e.heading,
152
+ reason: Rt(e),
153
+ args: {
154
+ blockId: e.blockId,
155
+ pageSize: e.fields || e.items || e.rows ? Math.min(20, Math.max(1, e.itemCount)) : void 0
156
+ }
157
+ }));
158
+ }
159
+ function Nt(t) {
160
+ const e = Lt(t.blocks), n = Pt(t.blocks);
161
+ return {
162
+ ...t,
163
+ outline: e,
164
+ suggestedReads: n,
165
+ blocks: t.blocks.map((o) => ({
166
+ blockId: o.blockId,
167
+ type: o.type,
168
+ heading: o.heading,
169
+ level: o.level,
170
+ preview: o.preview,
171
+ itemCount: o.itemCount,
172
+ chars: o.chars,
173
+ truncated: o.truncated,
174
+ rect: o.rect,
175
+ readHint: o.readHint
176
+ }))
177
+ };
178
+ }
179
+ function It(t, e, n) {
180
+ const o = [], i = _t(t).createTreeWalker(
181
+ t,
182
+ NodeFilter.SHOW_ELEMENT
183
+ );
184
+ let r = i.nextNode();
185
+ for (; r; ) {
186
+ const s = r;
187
+ if (D(s)) {
188
+ const a = Tt(s);
189
+ a && o.push({ ...a, element: s });
190
+ }
191
+ r = i.nextNode();
192
+ }
193
+ if (o.length !== 0) {
194
+ e.push({
195
+ type: "keyValueList",
196
+ heading: Q(o[0].element),
197
+ fields: o.slice(0, 80).map(({ name: s, value: a }) => ({ name: s, value: a })),
198
+ rect: k(o[0].element)
199
+ });
200
+ for (const s of o)
201
+ n.add(s.element);
202
+ }
203
+ }
204
+ function Ht(t, e, n) {
205
+ for (const o of Array.from(t.querySelectorAll('ul,ol,[role="list"]'))) {
206
+ if (!D(o))
207
+ continue;
208
+ const i = Array.from(o.children).map((r) => C(r)).filter((r) => !!r).slice(0, 80);
209
+ if (i.length !== 0) {
210
+ e.push({
211
+ type: "list",
212
+ heading: Q(o),
213
+ items: i,
214
+ rect: k(o)
215
+ }), n.add(o);
216
+ for (const r of Array.from(o.children))
217
+ n.add(r);
218
+ }
219
+ }
220
+ }
221
+ function Ot(t, e, n) {
222
+ var o;
223
+ for (const i of Array.from(t.querySelectorAll('table,[role="table"],[role="grid"]'))) {
224
+ if (!D(i))
225
+ continue;
226
+ const r = Array.from(i.querySelectorAll('tr,[role="row"]')).map(
227
+ (a) => Array.from(a.querySelectorAll('th,td,[role="columnheader"],[role="cell"],[role="gridcell"]')).map((u) => C(u)).filter((u) => !!u).slice(0, 12)
228
+ ).filter((a) => a.length > 0).slice(0, 80);
229
+ if (r.length === 0)
230
+ continue;
231
+ const s = (o = r[0]) != null && o.every((a) => a.length <= 120) ? r[0] : void 0;
232
+ e.push({
233
+ type: "table",
234
+ heading: Q(i),
235
+ headers: s,
236
+ rows: s ? r.slice(1) : r,
237
+ rect: k(i)
238
+ }), n.add(i);
239
+ }
240
+ }
241
+ function Bt(t, e, n) {
242
+ const o = 'h1,h2,h3,h4,h5,h6,[role="heading"],p,article,section';
243
+ for (const i of Array.from(t.querySelectorAll(o))) {
244
+ if (e.length >= 80)
245
+ break;
246
+ if (n.has(i) || !D(i))
247
+ continue;
248
+ const r = i.tagName.toLowerCase(), s = ft(i) ?? C(i);
249
+ if (s) {
250
+ if (r.match(/^h[1-6]$/) || i.getAttribute("role") === "heading") {
251
+ const a = r.match(/^h[1-6]$/) ? Number(r.slice(1)) : Number(i.getAttribute("aria-level") ?? 0) || 2;
252
+ e.push({
253
+ type: "heading",
254
+ level: a,
255
+ text: s,
256
+ rect: k(i)
257
+ });
258
+ continue;
259
+ }
260
+ s.length >= 24 && e.push({
261
+ type: "paragraph",
262
+ text: s,
263
+ rect: k(i)
264
+ });
265
+ }
266
+ }
267
+ }
268
+ function Vt(t) {
269
+ return t.querySelectorAll(
270
+ '[aria-expanded="false"],[data-expanded="false"],details:not([open]),[hidden]'
271
+ ).length;
272
+ }
273
+ function Dt(t) {
274
+ return Array.from(t.querySelectorAll("iframe")).filter((e) => {
275
+ try {
276
+ return !e.contentDocument;
277
+ } catch {
278
+ return !0;
279
+ }
280
+ }).length;
281
+ }
282
+ function ot(t) {
283
+ const e = t instanceof Document ? t.body ?? t.documentElement : t;
284
+ if (!e)
285
+ return {
286
+ blocks: [],
287
+ totalBlocks: 0,
288
+ truncated: !1,
289
+ coverage: {
290
+ status: "complete",
291
+ visibleTextCaptured: !1,
292
+ truncatedBlocks: 0,
293
+ collapsedSections: 0,
294
+ crossOriginFrames: 0,
295
+ virtualizedListsDetected: 0,
296
+ visualOnlyRegions: 0
297
+ }
298
+ };
299
+ const n = [], o = /* @__PURE__ */ new Set();
300
+ It(e, n, o), Ht(e, n, o), Ot(e, n, o), Bt(e, n, o);
301
+ const i = At(n), r = i.filter((l) => l.truncated).length, s = Vt(e), a = Dt(e), u = n.length > i.length || r > 0 || s > 0 || a > 0, d = [];
302
+ return s > 0 && d.push("Some content is inside collapsed sections."), a > 0 && d.push("Some frame content could not be read from DOM."), {
303
+ blocks: i,
304
+ totalBlocks: n.length,
305
+ truncated: n.length > i.length || r > 0,
306
+ coverage: {
307
+ status: u ? "partial" : "complete",
308
+ visibleTextCaptured: i.length > 0,
309
+ truncatedBlocks: r,
310
+ collapsedSections: s,
311
+ crossOriginFrames: a,
312
+ virtualizedListsDetected: 0,
313
+ visualOnlyRegions: 0
314
+ },
315
+ ...d.length > 0 ? { warnings: d } : {}
316
+ };
317
+ }
318
+ function I(t, e, n) {
319
+ const o = Math.max(1, Math.min(100, Math.floor(n))), i = Math.max(1, Math.ceil(t / o)), r = Math.max(1, Math.min(i, Math.floor(e))), s = (r - 1) * o;
320
+ return {
321
+ page: r,
322
+ pageSize: o,
323
+ pageCount: i,
324
+ start: s,
325
+ end: Math.min(t, s + o)
326
+ };
327
+ }
328
+ function U(t) {
329
+ return JSON.stringify(t).length;
330
+ }
331
+ function F(t, e) {
332
+ const n = t[e];
333
+ return typeof n == "number" && Number.isFinite(n) ? n : void 0;
334
+ }
335
+ function H(t, e) {
336
+ const n = t[e];
337
+ return typeof n == "string" && n.trim() ? n : void 0;
338
+ }
339
+ function G(t, e, n = !1) {
340
+ const o = {
341
+ ...t,
342
+ truncated: !!t.truncated || n
343
+ }, i = U(o), r = {
344
+ ...o,
345
+ chars: i
346
+ };
347
+ return U(r) <= e ? r : {
348
+ blockId: H(t, "blockId"),
349
+ type: H(t, "type"),
350
+ heading: xt(H(t, "heading"), 120),
351
+ scope: H(t, "scope"),
352
+ page: F(t, "page"),
353
+ pageSize: 0,
354
+ pageCount: F(t, "pageCount"),
355
+ nextPage: F(t, "nextPage"),
356
+ chars: i,
357
+ truncated: !0,
358
+ budgetExceeded: !0,
359
+ warning: "Read result exceeded maxChars; retry with a smaller pageSize or a narrower blockId/query."
360
+ };
361
+ }
362
+ function O(t, e, n) {
363
+ let o = e;
364
+ for (; o >= 1; ) {
365
+ const i = n(o), r = G(
366
+ i,
367
+ t,
368
+ o < e
369
+ );
370
+ if (U(r) <= t)
371
+ return r;
372
+ o = Math.floor(o / 2);
373
+ }
374
+ return G(n(1), t, !0);
375
+ }
376
+ function qt(t, e = {}) {
377
+ var u;
378
+ const n = typeof e.page == "number" ? e.page : 1, o = typeof e.pageSize == "number" ? e.pageSize : 20, i = typeof e.maxChars == "number" && Number.isFinite(e.maxChars) ? Math.max(500, Math.min(12e3, Math.floor(e.maxChars))) : 4e3, r = (u = e.query) == null ? void 0 : u.trim().toLowerCase(), s = r ? t.blocks.filter(
379
+ (d) => JSON.stringify(d).toLowerCase().includes(r)
380
+ ) : t.blocks, a = e.blockId ? t.blocks.find((d) => d.blockId === e.blockId) : void 0;
381
+ if (a) {
382
+ if (a.fields && a.fields.length > 0) {
383
+ const d = a.fields;
384
+ return O(i, o, (l) => {
385
+ const c = I(d.length, n, l);
386
+ return {
387
+ ...a,
388
+ fields: d.slice(c.start, c.end),
389
+ page: c.page,
390
+ pageSize: c.pageSize,
391
+ pageCount: c.pageCount,
392
+ nextPage: c.page < c.pageCount ? c.page + 1 : void 0
393
+ };
394
+ });
395
+ }
396
+ if (a.items && a.items.length > 0) {
397
+ const d = a.items;
398
+ return O(i, o, (l) => {
399
+ const c = I(d.length, n, l);
400
+ return {
401
+ ...a,
402
+ items: d.slice(c.start, c.end),
403
+ page: c.page,
404
+ pageSize: c.pageSize,
405
+ pageCount: c.pageCount,
406
+ nextPage: c.page < c.pageCount ? c.page + 1 : void 0
407
+ };
408
+ });
409
+ }
410
+ if (a.rows && a.rows.length > 0) {
411
+ const d = a.rows;
412
+ return O(i, o, (l) => {
413
+ const c = I(d.length, n, l);
414
+ return {
415
+ ...a,
416
+ rows: d.slice(c.start, c.end),
417
+ page: c.page,
418
+ pageSize: c.pageSize,
419
+ pageCount: c.pageCount,
420
+ nextPage: c.page < c.pageCount ? c.page + 1 : void 0
421
+ };
422
+ });
423
+ }
424
+ return G(a, i);
425
+ }
426
+ return O(i, o, (d) => {
427
+ const l = I(s.length, n, d);
428
+ return {
429
+ scope: "visible",
430
+ blocks: s.slice(l.start, l.end),
431
+ page: l.page,
432
+ pageSize: l.pageSize,
433
+ pageCount: l.pageCount,
434
+ nextPage: l.page < l.pageCount ? l.page + 1 : void 0,
435
+ coverage: t.coverage,
436
+ warnings: t.warnings
437
+ };
438
+ });
439
+ }
440
+ class Xt extends Error {
441
+ constructor(e, n) {
442
+ super(e), this.details = n;
443
+ }
444
+ }
445
+ const Ft = new Set(
446
+ vt
447
+ ), zt = [
17
448
  "a[href]",
18
449
  "button",
19
450
  "input",
@@ -28,96 +459,110 @@ const tt = [
28
459
  "[data-testid]",
29
460
  "[data-test-id]",
30
461
  "[data-qa]"
31
- ].join(","), $ = 100, ot = 1e4, rt = 6e4;
32
- function it(t) {
33
- return et.has(t);
462
+ ].join(","), it = 100, jt = 1e4, $t = 6e4;
463
+ function Wt(t) {
464
+ return Ft.has(t);
34
465
  }
35
- function m(t) {
466
+ function T(t) {
36
467
  return t instanceof Document ? t : t.ownerDocument;
37
468
  }
38
- function H(t) {
39
- return m(t).defaultView ?? window;
469
+ function V(t) {
470
+ return T(t).defaultView ?? window;
40
471
  }
41
- function y(t) {
472
+ function b(t) {
42
473
  return typeof t == "object" && t !== null && !Array.isArray(t) ? t : {};
43
474
  }
44
- function O(t, e) {
475
+ function z(t, e) {
45
476
  if (typeof t != "string" || t.trim() === "")
46
477
  throw new Error(`${e} must be a non-empty string.`);
47
478
  return t;
48
479
  }
49
- function v(t) {
480
+ function w(t) {
50
481
  return typeof t == "string" && t.trim() ? t : void 0;
51
482
  }
52
- function st(t) {
483
+ function Ut(t) {
484
+ return t === "viewport_normalized" ? "viewport_normalized" : "viewport-css-px";
485
+ }
486
+ function rt(t, e) {
487
+ const n = st(e.x, "x"), o = st(e.y, "y");
488
+ if (Ut(e.coordinateSpace) === "viewport_normalized") {
489
+ const i = V(t);
490
+ return {
491
+ x: Number((n * i.innerWidth).toFixed(3)),
492
+ y: Number((o * i.innerHeight).toFixed(3))
493
+ };
494
+ }
495
+ return { x: n, y: o };
496
+ }
497
+ function B(t) {
53
498
  return typeof t == "number" && Number.isInteger(t) ? t : void 0;
54
499
  }
55
- function C(t, e) {
500
+ function st(t, e) {
56
501
  if (typeof t != "number" || !Number.isFinite(t))
57
502
  throw new Error(`${e} must be a finite number.`);
58
503
  return t;
59
504
  }
60
- function _(t) {
505
+ function A(t) {
61
506
  return typeof t == "number" && Number.isFinite(t) ? t : void 0;
62
507
  }
63
- function W(t, e) {
508
+ function at(t, e) {
64
509
  return typeof t == "string" && e.includes(t) ? t : void 0;
65
510
  }
66
- function ct(t) {
511
+ function Gt(t) {
67
512
  if (typeof t == "string")
68
513
  return [t];
69
514
  if (Array.isArray(t) && t.every((e) => typeof e == "string"))
70
515
  return t;
71
516
  throw new Error("value or values must be a string or an array of strings.");
72
517
  }
73
- function b(t) {
518
+ function m(t) {
74
519
  const e = (t.textContent ?? "").replace(/\s+/g, " ").trim();
75
520
  return e ? e.slice(0, 160) : void 0;
76
521
  }
77
- function R(t) {
522
+ function q(t) {
78
523
  const e = Array.from(t.childNodes).filter((n) => n.nodeType === Node.TEXT_NODE).map((n) => n.textContent ?? "").join(" ").replace(/\s+/g, " ").trim();
79
524
  return e ? e.slice(0, 160) : void 0;
80
525
  }
81
- function at(t) {
526
+ function Z(t) {
82
527
  if (t instanceof HTMLInputElement || t instanceof HTMLTextAreaElement || t instanceof HTMLSelectElement)
83
528
  return t.value;
84
529
  }
85
- function G(t) {
530
+ function ht(t) {
86
531
  return t instanceof HTMLInputElement && (t.type === "checkbox" || t.type === "radio");
87
532
  }
88
- function lt(t) {
533
+ function Yt(t) {
89
534
  return t instanceof HTMLInputElement || t instanceof HTMLSelectElement || t instanceof HTMLTextAreaElement ? Array.from(t.labels ?? []) : [];
90
535
  }
91
- function ut(t, e) {
536
+ function Kt(t, e) {
92
537
  var o;
93
- return (((o = t.getAttribute(e)) == null ? void 0 : o.trim().split(/\s+/)) ?? []).map((r) => t.ownerDocument.getElementById(r)).filter((r) => !!r).map((r) => b(r)).filter((r) => !!r);
538
+ return (((o = t.getAttribute(e)) == null ? void 0 : o.trim().split(/\s+/)) ?? []).map((i) => t.ownerDocument.getElementById(i)).filter((i) => !!i).map((i) => m(i)).filter((i) => !!i);
94
539
  }
95
- function ft(t) {
96
- const e = ut(t, "aria-labelledby");
540
+ function Jt(t) {
541
+ const e = Kt(t, "aria-labelledby");
97
542
  if (e.length > 0)
98
543
  return e.join(" ").slice(0, 160);
99
- const n = lt(t).map((o) => b(o)).filter((o) => !!o);
544
+ const n = Yt(t).map((o) => m(o)).filter((o) => !!o);
100
545
  if (n.length > 0)
101
546
  return n.join(" ").slice(0, 160);
102
547
  }
103
- function dt(t) {
548
+ function Qt(t) {
104
549
  const e = [];
105
550
  let n = t.nextSibling;
106
551
  for (; n; ) {
107
552
  if (n.nodeType === Node.TEXT_NODE) {
108
- const r = (n.textContent ?? "").replace(/\s+/g, " ").trim();
109
- r && e.push(r);
553
+ const i = (n.textContent ?? "").replace(/\s+/g, " ").trim();
554
+ i && e.push(i);
110
555
  } else {
111
556
  if (n.nodeType === Node.ELEMENT_NODE && n.tagName.toLowerCase() === "br")
112
557
  break;
113
558
  if (n.nodeType === Node.ELEMENT_NODE) {
114
- const r = n;
115
- if (r.matches(
559
+ const i = n;
560
+ if (i.matches(
116
561
  'input,textarea,select,button,a[href],[role="button"],[role="link"]'
117
562
  ))
118
563
  break;
119
- const c = b(r);
120
- c && e.push(c);
564
+ const r = m(i);
565
+ r && e.push(r);
121
566
  break;
122
567
  }
123
568
  }
@@ -128,94 +573,94 @@ function dt(t) {
128
573
  const o = e.join(" ").replace(/\s+/g, " ").trim();
129
574
  return o ? o.slice(0, 160) : void 0;
130
575
  }
131
- function X(t, e) {
576
+ function ct(t, e) {
132
577
  var d;
133
578
  const n = t.ownerDocument, o = n.body;
134
579
  if (!o)
135
580
  return;
136
- const r = t.getBoundingClientRect();
137
- if (r.width <= 0 || r.height <= 0)
581
+ const i = t.getBoundingClientRect();
582
+ if (i.width <= 0 || i.height <= 0)
138
583
  return;
139
- const c = r.top + r.height / 2, i = [], s = n.createTreeWalker(o, NodeFilter.SHOW_ELEMENT);
140
- let a = s.nextNode();
141
- for (; a; ) {
142
- const l = a;
143
- if (l !== t && !l.contains(t) && B(l)) {
144
- const u = l.getBoundingClientRect(), f = R(l) ?? b(l);
584
+ const r = i.top + i.height / 2, s = [], a = n.createTreeWalker(o, NodeFilter.SHOW_ELEMENT);
585
+ let u = a.nextNode();
586
+ for (; u; ) {
587
+ const l = u;
588
+ if (l !== t && !l.contains(t) && tt(l)) {
589
+ const c = l.getBoundingClientRect(), f = q(l) ?? m(l);
145
590
  if (f) {
146
- const h = u.top + u.height / 2, E = Math.abs(h - c) <= Math.max(28, r.height * 1.25), g = e === "left" ? r.left - u.right : u.left - r.right;
147
- E && g >= -8 && g <= 240 && i.push({
591
+ const h = c.top + c.height / 2, y = Math.abs(h - r) <= Math.max(28, i.height * 1.25), p = e === "left" ? i.left - c.right : c.left - i.right;
592
+ y && p >= -8 && p <= 240 && s.push({
148
593
  text: f,
149
- score: Math.abs(g) + Math.abs(h - c)
594
+ score: Math.abs(p) + Math.abs(h - r)
150
595
  });
151
596
  }
152
597
  }
153
- a = s.nextNode();
598
+ u = a.nextNode();
154
599
  }
155
- return (d = i.sort((l, u) => l.score - u.score)[0]) == null ? void 0 : d.text;
600
+ return (d = s.sort((l, c) => l.score - c.score)[0]) == null ? void 0 : d.text;
156
601
  }
157
- function z(t) {
602
+ function X(t) {
158
603
  if (!(t instanceof HTMLInputElement || t instanceof HTMLSelectElement || t instanceof HTMLTextAreaElement))
159
604
  return;
160
- const e = ft(t);
161
- return e || (G(t) ? X(t, "right") ?? dt(t) ?? N(t)[0] : X(t, "left") ?? N(t)[0]);
605
+ const e = Jt(t);
606
+ return e || (ht(t) ? ct(t, "right") ?? Qt(t) ?? P(t)[0] : ct(t, "left") ?? P(t)[0]);
162
607
  }
163
- function j(t, e) {
608
+ function lt(t, e) {
164
609
  const n = e.trim().toLowerCase();
165
610
  return t instanceof HTMLInputElement && t.type === "radio" ? n === "radio" || n === "radio button" : t instanceof HTMLInputElement && t.type === "checkbox" ? n === "checkbox" || n === "check box" : t instanceof HTMLSelectElement ? n === "select" || n === "select menu" || n === "combobox" || n === "combo box" : !1;
166
611
  }
167
612
  function x(t) {
168
- const e = z(t), n = t.getAttribute("aria-label");
169
- if (n != null && n.trim() && !j(t, n))
613
+ const e = X(t), n = t.getAttribute("aria-label");
614
+ if (n != null && n.trim() && !lt(t, n))
170
615
  return n.trim();
171
616
  const o = t.getAttribute("title");
172
- if (o != null && o.trim() && !j(t, o))
617
+ if (o != null && o.trim() && !lt(t, o))
173
618
  return o.trim();
174
619
  if (e)
175
620
  return e;
176
- const r = N(t)[0];
177
- return r || b(t);
621
+ const i = P(t)[0];
622
+ return i || m(t);
178
623
  }
179
- function B(t) {
180
- if (!(t instanceof HTMLElement || t instanceof SVGElement) || !T(t) || t.matches(
624
+ function tt(t) {
625
+ if (!(t instanceof HTMLElement || t instanceof SVGElement) || !S(t) || t.matches(
181
626
  'input,textarea,select,button,a[href],[role="button"],[role="link"]'
182
627
  ))
183
628
  return !1;
184
- const e = R(t) ?? b(t);
629
+ const e = q(t) ?? m(t);
185
630
  return !!(e && e.length <= 120);
186
631
  }
187
- function ht(t) {
188
- var u;
189
- if (!G(t))
632
+ function pt(t) {
633
+ var c;
634
+ if (!ht(t))
190
635
  return;
191
- const e = t.closest("fieldset"), n = e == null ? void 0 : e.querySelector("legend"), o = n ? b(n) : void 0;
636
+ const e = t.closest("fieldset"), n = e == null ? void 0 : e.querySelector("legend"), o = n ? m(n) : void 0;
192
637
  if (o)
193
638
  return o;
194
- const r = t.ownerDocument, c = r.body;
195
- if (!c)
639
+ const i = t.ownerDocument, r = i.body;
640
+ if (!r)
196
641
  return;
197
- const i = t.getBoundingClientRect();
198
- if (i.width <= 0 || i.height <= 0)
642
+ const s = t.getBoundingClientRect();
643
+ if (s.width <= 0 || s.height <= 0)
199
644
  return;
200
- const s = i.left + i.width / 2, a = [], d = r.createTreeWalker(c, NodeFilter.SHOW_ELEMENT);
645
+ const a = s.left + s.width / 2, u = [], d = i.createTreeWalker(r, NodeFilter.SHOW_ELEMENT);
201
646
  let l = d.nextNode();
202
647
  for (; l; ) {
203
648
  const f = l;
204
- if (f !== t && !f.contains(t) && f.matches('legend,strong,b,[role="heading"],h1,h2,h3,h4,h5,h6') && B(f)) {
205
- const h = f.getBoundingClientRect(), E = R(f) ?? b(f);
206
- if (E && h.bottom <= i.top + 8) {
207
- const g = i.top - h.bottom, w = h.left + h.width / 2;
208
- g <= 160 && w >= i.left - 120 && w <= i.right + 320 && a.push({
209
- text: E,
210
- score: g + Math.abs(w - s) * 0.25
649
+ if (f !== t && !f.contains(t) && f.matches('legend,strong,b,[role="heading"],h1,h2,h3,h4,h5,h6') && tt(f)) {
650
+ const h = f.getBoundingClientRect(), y = q(f) ?? m(f);
651
+ if (y && h.bottom <= s.top + 8) {
652
+ const p = s.top - h.bottom, E = h.left + h.width / 2;
653
+ p <= 160 && E >= s.left - 120 && E <= s.right + 320 && u.push({
654
+ text: y,
655
+ score: p + Math.abs(E - a) * 0.25
211
656
  });
212
657
  }
213
658
  }
214
659
  l = d.nextNode();
215
660
  }
216
- return (u = a.sort((f, h) => f.score - h.score)[0]) == null ? void 0 : u.text;
661
+ return (c = u.sort((f, h) => f.score - h.score)[0]) == null ? void 0 : c.text;
217
662
  }
218
- function gt(t) {
663
+ function Zt(t) {
219
664
  if (!(t instanceof HTMLSelectElement))
220
665
  return;
221
666
  const e = Array.from(t.options).map((n) => ({
@@ -226,42 +671,42 @@ function gt(t) {
226
671
  }));
227
672
  return e.length ? e : void 0;
228
673
  }
229
- function pt(t) {
674
+ function te(t) {
230
675
  if (!(t instanceof HTMLSelectElement))
231
676
  return;
232
677
  const e = t.selectedOptions[0], n = e ? (e.label || e.textContent || e.value).replace(/\s+/g, " ").trim() : void 0;
233
678
  return n ? n.slice(0, 160) : void 0;
234
679
  }
235
- function N(t) {
680
+ function P(t) {
236
681
  const e = t.ownerDocument, n = e.body;
237
682
  if (!n)
238
683
  return [];
239
684
  const o = t.getBoundingClientRect();
240
685
  if (o.width <= 0 || o.height <= 0)
241
686
  return [];
242
- const r = o.top + o.height / 2, c = o.left + o.width / 2, i = [], s = e.createTreeWalker(n, NodeFilter.SHOW_ELEMENT);
243
- let a = s.nextNode();
244
- for (; a; ) {
245
- const l = a;
246
- if (l !== t && !l.contains(t) && B(l)) {
247
- const u = l.getBoundingClientRect(), f = R(l) ?? b(l);
687
+ const i = o.top + o.height / 2, r = o.left + o.width / 2, s = [], a = e.createTreeWalker(n, NodeFilter.SHOW_ELEMENT);
688
+ let u = a.nextNode();
689
+ for (; u; ) {
690
+ const l = u;
691
+ if (l !== t && !l.contains(t) && tt(l)) {
692
+ const c = l.getBoundingClientRect(), f = q(l) ?? m(l);
248
693
  if (f) {
249
- const h = u.top + u.height / 2, E = u.left + u.width / 2, g = u.right <= o.left + 12 && Math.abs(h - r) <= Math.max(28, o.height * 1.25), w = u.left >= o.right - 8 && u.left - o.right <= 240 && Math.abs(h - r) <= Math.max(28, o.height * 1.25), q = u.bottom <= o.top + 8 && o.top - u.bottom <= 80 && E >= o.left - 80 && E <= o.right + 80;
250
- if (g || w || q) {
251
- const Z = g ? o.left - u.right + Math.abs(h - r) : w ? u.left - o.right + Math.abs(h - r) : o.top - u.bottom + Math.abs(E - c);
252
- i.push({
694
+ const h = c.top + c.height / 2, y = c.left + c.width / 2, p = c.right <= o.left + 12 && Math.abs(h - i) <= Math.max(28, o.height * 1.25), E = c.left >= o.right - 8 && c.left - o.right <= 240 && Math.abs(h - i) <= Math.max(28, o.height * 1.25), nt = c.bottom <= o.top + 8 && o.top - c.bottom <= 80 && y >= o.left - 80 && y <= o.right + 80;
695
+ if (p || E || nt) {
696
+ const wt = p ? o.left - c.right + Math.abs(h - i) : E ? c.left - o.right + Math.abs(h - i) : o.top - c.bottom + Math.abs(y - r);
697
+ s.push({
253
698
  text: f,
254
- score: Z + (g ? 0 : w ? 5 : 100)
699
+ score: wt + (p ? 0 : E ? 5 : 100)
255
700
  });
256
701
  }
257
702
  }
258
703
  }
259
- a = s.nextNode();
704
+ u = a.nextNode();
260
705
  }
261
706
  const d = /* @__PURE__ */ new Set();
262
- return i.sort((l, u) => l.score - u.score).map((l) => l.text).filter((l) => d.has(l) ? !1 : (d.add(l), !0)).slice(0, 4);
707
+ return s.sort((l, c) => l.score - c.score).map((l) => l.text).filter((l) => d.has(l) ? !1 : (d.add(l), !0)).slice(0, 4);
263
708
  }
264
- function Et(t) {
709
+ function ee(t) {
265
710
  return t.getAttribute("data-testid") ?? t.getAttribute("data-test-id") ?? t.getAttribute("data-qa") ?? void 0;
266
711
  }
267
712
  function M(t) {
@@ -288,65 +733,65 @@ function M(t) {
288
733
  return "textbox";
289
734
  }
290
735
  }
291
- function K(t) {
736
+ function gt(t) {
292
737
  return t instanceof HTMLButtonElement || t instanceof HTMLInputElement || t instanceof HTMLSelectElement || t instanceof HTMLTextAreaElement ? t.disabled || void 0 : t.getAttribute("aria-disabled") === "true" || void 0;
293
738
  }
294
- function bt(t) {
739
+ function ne(t) {
295
740
  return t instanceof HTMLInputElement && (t.type === "checkbox" || t.type === "radio") ? t.checked : void 0;
296
741
  }
297
- function wt(t) {
298
- const e = k(t);
742
+ function oe(t) {
743
+ const e = N(t);
299
744
  if (!(e.width <= 0 || e.height <= 0))
300
745
  return {
301
746
  x: e.x + e.width / 2,
302
747
  y: e.y + e.height / 2
303
748
  };
304
749
  }
305
- function U(t) {
750
+ function _(t) {
306
751
  return {
307
752
  tag: t.tagName.toLowerCase(),
308
753
  role: M(t),
309
754
  name: x(t),
310
- selector: D(t)
755
+ selector: Y(t)
311
756
  };
312
757
  }
313
- function T(t) {
758
+ function S(t) {
314
759
  if (!(t instanceof HTMLElement || t instanceof SVGElement) || t instanceof HTMLElement && t.hidden)
315
760
  return !1;
316
761
  const e = t.ownerDocument.defaultView, n = e == null ? void 0 : e.getComputedStyle(t);
317
762
  return !(n && (n.display === "none" || n.visibility === "hidden" || n.opacity === "0"));
318
763
  }
319
- function J(t) {
320
- return t.matches(nt) && T(t);
764
+ function mt(t) {
765
+ return t.matches(zt) && S(t);
321
766
  }
322
- function yt(t) {
323
- return K(t) !== !0;
767
+ function ie(t) {
768
+ return gt(t) !== !0;
324
769
  }
325
- function mt(t) {
770
+ function re(t) {
326
771
  var n;
327
- if (J(t))
772
+ if (mt(t))
328
773
  return !0;
329
774
  if (!(t instanceof HTMLElement))
330
775
  return !1;
331
776
  const e = (n = t.ownerDocument.defaultView) == null ? void 0 : n.getComputedStyle(t);
332
- return ((e == null ? void 0 : e.cursor) === "pointer" || !!t.onclick) && T(t);
777
+ return ((e == null ? void 0 : e.cursor) === "pointer" || !!t.onclick) && S(t);
333
778
  }
334
- function k(t) {
335
- var c, i;
779
+ function N(t) {
780
+ var r, s;
336
781
  const e = t.getBoundingClientRect();
337
- let n = e.left, o = e.top, r = null;
782
+ let n = e.left, o = e.top, i = null;
338
783
  try {
339
- r = ((c = t.ownerDocument.defaultView) == null ? void 0 : c.frameElement) ?? null;
784
+ i = ((r = t.ownerDocument.defaultView) == null ? void 0 : r.frameElement) ?? null;
340
785
  } catch {
341
- r = null;
786
+ i = null;
342
787
  }
343
- for (; r; ) {
344
- const s = r.getBoundingClientRect();
345
- n += s.left, o += s.top;
788
+ for (; i; ) {
789
+ const a = i.getBoundingClientRect();
790
+ n += a.left, o += a.top;
346
791
  try {
347
- r = ((i = r.ownerDocument.defaultView) == null ? void 0 : i.frameElement) ?? null;
792
+ i = ((s = i.ownerDocument.defaultView) == null ? void 0 : s.frameElement) ?? null;
348
793
  } catch {
349
- r = null;
794
+ i = null;
350
795
  }
351
796
  }
352
797
  return {
@@ -356,21 +801,21 @@ function k(t) {
356
801
  height: e.height
357
802
  };
358
803
  }
359
- function D(t) {
804
+ function Y(t) {
360
805
  const e = (o) => typeof CSS < "u" && typeof CSS.escape == "function" ? CSS.escape(o) : o.replaceAll("\\", "\\\\").replaceAll('"', '\\"');
361
806
  if (t.id)
362
807
  return `#${e(t.id)}`;
363
808
  for (const o of ["data-testid", "data-test-id", "data-qa"]) {
364
- const r = t.getAttribute(o);
365
- if (r)
366
- return `[${o}="${e(r)}"]`;
809
+ const i = t.getAttribute(o);
810
+ if (i)
811
+ return `[${o}="${e(i)}"]`;
367
812
  }
368
813
  const n = t.getAttribute("name");
369
814
  return n ? `${t.tagName.toLowerCase()}[name="${e(
370
815
  n
371
816
  )}"]` : t.tagName.toLowerCase();
372
817
  }
373
- function vt(t) {
818
+ function se(t) {
374
819
  const e = t.getBoundingClientRect();
375
820
  if (!(e.width <= 0 || e.height <= 0))
376
821
  return {
@@ -378,7 +823,7 @@ function vt(t) {
378
823
  y: e.top + e.height / 2
379
824
  };
380
825
  }
381
- function Q(t, e) {
826
+ function yt(t, e) {
382
827
  if (typeof t.elementsFromPoint == "function")
383
828
  return t.elementsFromPoint(e.x, e.y);
384
829
  if (typeof t.elementFromPoint != "function")
@@ -386,28 +831,31 @@ function Q(t, e) {
386
831
  const n = t.elementFromPoint(e.x, e.y);
387
832
  return n ? [n] : [];
388
833
  }
389
- function xt(t) {
834
+ function ae(t) {
390
835
  return typeof t.elementsFromPoint == "function" || typeof t.elementFromPoint == "function";
391
836
  }
392
- function A(t, e) {
837
+ function ce(t, e) {
393
838
  return t === e || t.contains(e);
394
839
  }
395
- function Tt(t) {
840
+ function le(t) {
396
841
  let e = t;
397
842
  for (; e; ) {
398
- if (mt(e))
843
+ if (re(e))
399
844
  return e;
400
845
  e = e.parentElement;
401
846
  }
402
847
  return t;
403
848
  }
404
- function Y(t) {
849
+ function ut(t) {
405
850
  return (t ?? "").replace(/\([^)]*\)/g, "").replace(/\s+/g, "").trim().toLowerCase();
406
851
  }
407
- function V(t) {
852
+ function K(t) {
853
+ return bt(t)[0];
854
+ }
855
+ function bt(t) {
408
856
  const e = t.getBoundingClientRect();
409
857
  if (e.width <= 0 || e.height <= 0)
410
- return;
858
+ return [];
411
859
  const n = t.ownerDocument;
412
860
  return [
413
861
  { x: e.left + e.width / 2, y: e.top + e.height / 2 },
@@ -415,101 +863,162 @@ function V(t) {
415
863
  { x: e.right - Math.min(8, e.width / 2), y: e.top + e.height / 2 },
416
864
  { x: e.left + e.width / 2, y: e.top + Math.min(8, e.height / 2) },
417
865
  { x: e.left + e.width / 2, y: e.bottom - Math.min(8, e.height / 2) }
418
- ].find(
419
- (r) => Q(n, r).some(
420
- (c) => A(t, c) || A(c, t)
421
- )
422
- );
866
+ ].filter((i) => {
867
+ const r = yt(n, i)[0];
868
+ return r ? ce(t, r) : !1;
869
+ });
423
870
  }
424
- function Mt(t, e) {
425
- const n = t.getBoundingClientRect(), o = k(t);
871
+ function Et(t, e) {
872
+ const n = t.getBoundingClientRect(), o = N(t);
426
873
  return {
427
874
  x: e.x + o.x - n.left,
428
875
  y: e.y + o.y - n.top
429
876
  };
430
877
  }
431
- function _t(t, e) {
432
- var c;
433
- const n = M(e), o = Y(x(e));
434
- return o ? ((c = F(t).filter((i) => i !== e).filter((i) => {
435
- const s = M(i), a = Y(x(i));
436
- return n && s && n !== s ? !1 : a.includes(o) || o.includes(a);
437
- }).map((i) => ({
438
- candidate: i,
439
- point: V(i),
440
- rect: k(i)
878
+ function ue(t, e) {
879
+ var r;
880
+ const n = M(e), o = ut(x(e));
881
+ return o ? ((r = et(t).filter((s) => s !== e).filter((s) => {
882
+ const a = M(s), u = ut(x(s));
883
+ return n && a && n !== a ? !1 : u.includes(o) || o.includes(u);
884
+ }).map((s) => ({
885
+ candidate: s,
886
+ point: K(s),
887
+ rect: N(s)
441
888
  })).filter(
442
- (i) => !!i.point
443
- ).sort((i, s) => s.rect.y - i.rect.y)[0]) == null ? void 0 : c.candidate) ?? null : null;
889
+ (s) => !!s.point
890
+ ).sort((s, a) => a.rect.y - s.rect.y)[0]) == null ? void 0 : r.candidate) ?? null : null;
444
891
  }
445
- function p(t) {
446
- const e = t.ownerDocument, n = vt(t), o = T(t) && !!n, r = yt(t), c = n ? Q(e, n) : [], i = c[0], s = !!(i && (A(t, i) || A(i, t)));
892
+ function g(t) {
893
+ const e = t.ownerDocument, n = se(t), o = S(t) && !!n, i = ie(t), r = n ? yt(e, n) : [], s = r[0], a = bt(t).map(
894
+ (d) => Et(t, d)
895
+ ), u = a.length > 0;
447
896
  return {
448
897
  visible: o,
449
- enabled: r,
450
- receivesEvents: s,
451
- actionable: o && r && s,
452
- center: wt(t),
453
- hitTarget: i,
454
- hitStack: c
898
+ enabled: i,
899
+ receivesEvents: u,
900
+ actionable: o && i && u,
901
+ center: oe(t),
902
+ hitTarget: s,
903
+ hitStack: r,
904
+ safeClickPoints: a,
905
+ occludedBy: o && i && !u ? s : void 0
455
906
  };
456
907
  }
457
- function St(t, e) {
458
- var s, a, d;
459
- const n = v(e.testId);
908
+ function de(t, e) {
909
+ var a, u, d;
910
+ const n = w(e.testId);
460
911
  if (n) {
461
- const l = typeof CSS < "u" && typeof CSS.escape == "function" ? CSS.escape(n) : n.replaceAll("\\", "\\\\").replaceAll('"', '\\"'), u = t.querySelector(
912
+ const l = typeof CSS < "u" && typeof CSS.escape == "function" ? CSS.escape(n) : n.replaceAll("\\", "\\\\").replaceAll('"', '\\"'), c = t.querySelector(
462
913
  `[data-testid="${l}"],[data-test-id="${l}"],[data-qa="${l}"]`
463
914
  );
464
- if (u)
465
- return u;
466
- }
467
- const o = (s = v(e.role)) == null ? void 0 : s.toLowerCase(), r = (a = v(e.name)) == null ? void 0 : a.toLowerCase(), c = (d = v(e.text)) == null ? void 0 : d.toLowerCase();
468
- return !o && !r && !c ? null : F(t).find((l) => {
469
- var E, g, w;
470
- const u = (E = M(l)) == null ? void 0 : E.toLowerCase(), f = (g = x(l)) == null ? void 0 : g.toLowerCase(), h = (w = b(l)) == null ? void 0 : w.toLowerCase();
471
- return !(o && u !== o || r && !(f != null && f.includes(r)) || c && !(h != null && h.includes(c)));
915
+ if (c)
916
+ return c;
917
+ }
918
+ const o = (a = w(e.role)) == null ? void 0 : a.toLowerCase(), i = (u = w(e.name)) == null ? void 0 : u.toLowerCase(), r = (d = w(e.text)) == null ? void 0 : d.toLowerCase();
919
+ return !o && !i && !r ? null : et(t).find((l) => {
920
+ var y, p, E;
921
+ const c = (y = M(l)) == null ? void 0 : y.toLowerCase(), f = (p = x(l)) == null ? void 0 : p.toLowerCase(), h = (E = m(l)) == null ? void 0 : E.toLowerCase();
922
+ return !(o && c !== o || i && !(f != null && f.includes(i)) || r && !(h != null && h.includes(r)));
472
923
  }) ?? null;
473
924
  }
474
- function F(t) {
475
- const e = m(t), n = t instanceof Document ? t.body ?? t.documentElement : t;
925
+ function fe(t) {
926
+ return [
927
+ x(t),
928
+ X(t),
929
+ pt(t),
930
+ m(t),
931
+ Z(t)
932
+ ].filter((e) => !!e).join(" ").toLowerCase();
933
+ }
934
+ function he(t, e) {
935
+ const n = e.trim().toLowerCase();
936
+ let o = t, i = 0;
937
+ for (; o && i < 5; ) {
938
+ const r = o.tagName.toLowerCase();
939
+ if (r === "body" || r === "html")
940
+ return !1;
941
+ if (fe(o).includes(n))
942
+ return !0;
943
+ o = o.parentElement, i += 1;
944
+ }
945
+ return !1;
946
+ }
947
+ function pe(t) {
948
+ if (!t || typeof t != "object" || Array.isArray(t))
949
+ return;
950
+ const e = t;
951
+ if (e.type === "field_contains" && typeof e.field == "string" && e.field.trim() && typeof e.value == "string")
952
+ return {
953
+ type: "field_contains",
954
+ field: e.field,
955
+ value: e.value
956
+ };
957
+ }
958
+ function ge(t, e) {
959
+ const n = e.trim().toLowerCase();
960
+ return Array.from(t.querySelectorAll("input,textarea,select")).find(
961
+ (o) => [
962
+ X(o),
963
+ x(o),
964
+ o.getAttribute("name") ?? void 0,
965
+ o.getAttribute("placeholder") ?? void 0,
966
+ ...P(o)
967
+ ].some(
968
+ (r) => r == null ? void 0 : r.trim().toLowerCase().includes(n)
969
+ )
970
+ );
971
+ }
972
+ function me(t, e) {
973
+ if (!e)
974
+ return;
975
+ const n = ge(t, e.field), o = n ? Z(n) ?? "" : void 0;
976
+ return {
977
+ ...e,
978
+ ok: typeof o == "string" && o.toLowerCase().includes(e.value.toLowerCase()),
979
+ actual: o,
980
+ matchedField: n ? _(n) : void 0
981
+ };
982
+ }
983
+ function et(t) {
984
+ const e = t instanceof Element ? t.ownerDocument : T(t), n = t instanceof Document ? t.body ?? t.documentElement : t;
476
985
  if (!n)
477
986
  return [];
478
- const o = [], r = (c) => {
479
- const i = e.createTreeWalker(c, NodeFilter.SHOW_ELEMENT);
480
- let s = i.nextNode();
481
- for (; s; ) {
482
- const a = s;
483
- J(a) && o.push(a);
484
- const d = a.shadowRoot;
485
- if (d && r(d), a instanceof HTMLIFrameElement)
987
+ const o = [], i = (r) => {
988
+ const s = e.createTreeWalker(r, NodeFilter.SHOW_ELEMENT);
989
+ let a = s.nextNode();
990
+ for (; a; ) {
991
+ const u = a;
992
+ mt(u) && o.push(u);
993
+ const d = u.shadowRoot;
994
+ if (d && i(d), u instanceof HTMLIFrameElement)
486
995
  try {
487
- a.contentDocument && r(a.contentDocument);
996
+ u.contentDocument && i(u.contentDocument);
488
997
  } catch {
489
998
  }
490
- if (o.length >= $)
999
+ if (o.length >= it)
491
1000
  return;
492
- s = i.nextNode();
1001
+ a = s.nextNode();
493
1002
  }
494
1003
  };
495
- return r(n), o.slice(0, $);
1004
+ return i(n), o.slice(0, it);
496
1005
  }
497
- function Lt(t, e) {
498
- var r;
1006
+ function ye(t, e) {
1007
+ var i;
499
1008
  const n = Object.getPrototypeOf(t), o = Object.getOwnPropertyDescriptor(n, "value");
500
- (r = o == null ? void 0 : o.set) == null || r.call(t, e);
1009
+ (i = o == null ? void 0 : o.set) == null || i.call(t, e);
501
1010
  }
502
- function I(t) {
1011
+ function j(t) {
503
1012
  t.dispatchEvent(new Event("input", { bubbles: !0 })), t.dispatchEvent(new Event("change", { bubbles: !0 }));
504
1013
  }
505
- function S(t) {
1014
+ function L(t) {
506
1015
  var e, n;
507
1016
  (t instanceof HTMLElement || t instanceof SVGElement) && ((e = t.scrollIntoView) == null || e.call(t, { block: "center", inline: "center" })), t instanceof HTMLElement && ((n = t.focus) == null || n.call(t));
508
1017
  }
509
- function L(t, e) {
1018
+ function R(t, e) {
510
1019
  return typeof PointerEvent == "function" ? new PointerEvent(t, e) : new MouseEvent(t.replace("pointer", "mouse"), e);
511
1020
  }
512
- class kt {
1021
+ class be {
513
1022
  constructor(e = {}) {
514
1023
  this.options = e, this.refs = /* @__PURE__ */ new Map(), this.nextRef = 1;
515
1024
  }
@@ -539,17 +1048,19 @@ class kt {
539
1048
  return this.pointer(n);
540
1049
  case "host_page_screenshot":
541
1050
  return this.screenshot();
1051
+ case "host_page_read":
1052
+ return this.read(n);
542
1053
  case "host_page_wait_for":
543
1054
  return this.waitFor(n);
544
1055
  }
545
1056
  }
546
1057
  snapshot() {
547
- var c, i;
1058
+ var r, s;
548
1059
  this.refs.clear(), this.nextRef = 1;
549
- const e = this.getRoot(), n = m(e), o = H(e), r = F(e).map(
550
- (s) => this.snapshotElement(s)
1060
+ const e = this.getRoot(), n = T(e), o = V(e), i = et(e).map(
1061
+ (a) => this.snapshotElement(a)
551
1062
  );
552
- return {
1063
+ return this.readableContent = ot(e), {
553
1064
  url: o.location.href,
554
1065
  title: n.title,
555
1066
  capabilities: {
@@ -572,28 +1083,34 @@ class kt {
572
1083
  readyState: n.readyState,
573
1084
  visibilityState: n.visibilityState,
574
1085
  focusedElement: n.activeElement && n.activeElement !== n.body ? this.snapshotElementWithoutRef(n.activeElement) : void 0,
575
- selection: ((i = (c = n.getSelection) == null ? void 0 : c.call(n)) == null ? void 0 : i.toString()) || void 0
1086
+ selection: ((s = (r = n.getSelection) == null ? void 0 : r.call(n)) == null ? void 0 : s.toString()) || void 0
576
1087
  },
577
1088
  navigation: this.getNavigationState(o),
578
1089
  frames: this.getFrameState(n),
579
- accessibility: r.map((s) => ({
580
- ref: s.ref,
581
- role: s.role,
582
- name: s.name,
583
- value: s.value,
584
- disabled: s.disabled,
585
- checked: s.checked,
586
- focused: n.activeElement === this.refs.get(s.ref)
1090
+ accessibility: i.map((a) => ({
1091
+ ref: a.ref,
1092
+ role: a.role,
1093
+ name: a.name,
1094
+ value: a.value,
1095
+ disabled: a.disabled,
1096
+ checked: a.checked,
1097
+ focused: n.activeElement === this.refs.get(a.ref)
587
1098
  })),
588
- elements: r
1099
+ readableContent: Nt(
1100
+ this.readableContent
1101
+ ),
1102
+ elements: i
589
1103
  };
590
1104
  }
591
1105
  getRoot() {
592
1106
  return this.options.root ?? document;
593
1107
  }
1108
+ invalidateReadableContent() {
1109
+ this.readableContent = void 0;
1110
+ }
594
1111
  getNavigationState(e) {
595
- var o, r, c;
596
- const n = (c = (r = (o = e.performance) == null ? void 0 : o.getEntriesByType) == null ? void 0 : r.call(o, "navigation")) == null ? void 0 : c[0];
1112
+ var o, i, r;
1113
+ const n = (r = (i = (o = e.performance) == null ? void 0 : o.getEntriesByType) == null ? void 0 : i.call(o, "navigation")) == null ? void 0 : r[0];
597
1114
  if (!(typeof PerformanceNavigationTiming != "function" || !(n instanceof PerformanceNavigationTiming)))
598
1115
  return {
599
1116
  type: n.type,
@@ -604,12 +1121,12 @@ class kt {
604
1121
  }
605
1122
  getFrameState(e) {
606
1123
  return Array.from(e.querySelectorAll("iframe")).map((n) => {
607
- var r, c;
608
- const o = k(n);
1124
+ var i, r;
1125
+ const o = N(n);
609
1126
  try {
610
1127
  return {
611
- url: (r = n.contentWindow) == null ? void 0 : r.location.href,
612
- title: (c = n.contentDocument) == null ? void 0 : c.title,
1128
+ url: (i = n.contentWindow) == null ? void 0 : i.location.href,
1129
+ title: (r = n.contentDocument) == null ? void 0 : r.title,
613
1130
  sameOrigin: !0,
614
1131
  rect: o
615
1132
  };
@@ -630,159 +1147,193 @@ class kt {
630
1147
  return this.createElementSnapshot(e, "");
631
1148
  }
632
1149
  createElementSnapshot(e, n) {
633
- const o = (e instanceof HTMLInputElement || e instanceof HTMLTextAreaElement) && e.placeholder || void 0, r = p(e);
1150
+ const o = (e instanceof HTMLInputElement || e instanceof HTMLTextAreaElement) && e.placeholder || void 0, i = g(e);
634
1151
  return {
635
1152
  ref: n,
636
1153
  tag: e.tagName.toLowerCase(),
637
1154
  role: M(e),
638
1155
  name: x(e),
639
- label: z(e),
640
- groupLabel: ht(e),
641
- text: b(e),
642
- nearbyText: N(e),
643
- testId: Et(e),
644
- value: at(e),
645
- selectedLabel: pt(e),
646
- options: gt(e),
1156
+ label: X(e),
1157
+ groupLabel: pt(e),
1158
+ text: m(e),
1159
+ nearbyText: P(e),
1160
+ testId: ee(e),
1161
+ value: Z(e),
1162
+ selectedLabel: te(e),
1163
+ options: Zt(e),
647
1164
  placeholder: o,
648
- selector: D(e),
649
- disabled: K(e),
650
- enabled: r.enabled,
651
- checked: bt(e),
652
- visible: r.visible,
653
- actionable: r.actionable,
654
- rect: k(e),
655
- center: r.center,
656
- hitTarget: r.hitTarget ? U(r.hitTarget) : void 0,
657
- hitStack: r.hitStack.slice(0, 5).map(U)
1165
+ selector: Y(e),
1166
+ disabled: gt(e),
1167
+ enabled: i.enabled,
1168
+ checked: ne(e),
1169
+ visible: i.visible,
1170
+ actionable: i.actionable,
1171
+ receivesEvents: i.receivesEvents,
1172
+ occludedBy: i.occludedBy ? _(i.occludedBy) : void 0,
1173
+ safeClickPoints: i.safeClickPoints,
1174
+ rect: N(e),
1175
+ center: i.center,
1176
+ hitTarget: i.hitTarget ? _(i.hitTarget) : void 0,
1177
+ hitStack: i.hitStack.slice(0, 5).map(_)
658
1178
  };
659
1179
  }
660
1180
  resolveElement(e) {
661
- const n = v(e.ref) ?? v(e.axRef);
1181
+ const n = w(e.ref) ?? w(e.axRef);
662
1182
  if (n) {
663
- const c = this.refs.get(n);
664
- if (!c)
1183
+ const r = this.refs.get(n);
1184
+ if (!r)
665
1185
  throw new Error(`Unknown element ref: ${n}. Take a new snapshot.`);
666
- return c;
1186
+ return r;
667
1187
  }
668
- const o = v(e.selector);
1188
+ const o = w(e.selector);
669
1189
  if (o) {
670
- const c = this.getRoot().querySelector(o);
671
- if (!c)
1190
+ const r = this.getRoot().querySelector(o);
1191
+ if (!r)
672
1192
  throw new Error(`No element matches selector: ${o}.`);
673
- return c;
674
- }
675
- const r = St(this.getRoot(), e);
676
- if (r)
677
1193
  return r;
1194
+ }
1195
+ const i = de(this.getRoot(), e);
1196
+ if (i)
1197
+ return i;
678
1198
  if (typeof e.x < "u" || typeof e.y < "u") {
679
- const c = {
680
- x: C(e.x, "x"),
681
- y: C(e.y, "y")
682
- }, i = m(this.getRoot()).elementFromPoint(
683
- c.x,
684
- c.y
1199
+ const r = rt(this.getRoot(), e), s = T(this.getRoot()).elementFromPoint(
1200
+ r.x,
1201
+ r.y
685
1202
  );
686
- if (!i)
687
- throw new Error(`No element found at (${c.x}, ${c.y}).`);
688
- return i;
1203
+ if (!s)
1204
+ throw new Error(`No element found at (${r.x}, ${r.y}).`);
1205
+ return s;
689
1206
  }
690
1207
  throw new Error(
691
1208
  "Expected one of ref, selector, role/name/text/testId, or x/y."
692
1209
  );
693
1210
  }
694
1211
  async click(e) {
695
- const n = y(e), o = this.resolveElement(n), r = p(o), i = (r.actionable ? null : _t(this.getRoot(), o)) ?? Tt(o);
696
- if (!V(i) && !r.actionable && xt(o.ownerDocument))
697
- throw new Error(
698
- `Target "${x(o) ?? o.tagName.toLowerCase()}" is not receiving pointer events. Take a screenshot or use host_page_pointer coordinates.`
1212
+ const n = b(e), o = this.resolveElement(n), i = g(o), s = (i.actionable ? null : ue(this.getRoot(), o)) ?? le(o);
1213
+ if (!K(s) && !i.actionable && ae(o.ownerDocument))
1214
+ throw new Xt(
1215
+ `Target "${x(o) ?? o.tagName.toLowerCase()}" is not receiving pointer events.`,
1216
+ {
1217
+ reason: "target_occluded",
1218
+ target: this.describeElement(o),
1219
+ occluder: i.occludedBy ? _(i.occludedBy) : void 0,
1220
+ targetVisible: i.visible,
1221
+ targetEnabled: i.enabled,
1222
+ targetReceivesEvents: i.receivesEvents,
1223
+ recoverable: !0,
1224
+ hitStack: i.hitStack.slice(0, 5).map(_),
1225
+ nextActions: [
1226
+ {
1227
+ tool: "host_page_press",
1228
+ args: { key: "Escape" }
1229
+ },
1230
+ {
1231
+ tool: "host_page_screenshot",
1232
+ args: {}
1233
+ }
1234
+ ]
1235
+ }
699
1236
  );
700
- S(i);
701
- const a = V(i), d = p(i), l = p(o), u = a ? Mt(i, a) : d.center ?? r.center;
702
- return u && await this.showVisualEffect({
1237
+ L(s);
1238
+ const u = K(s), d = g(s), l = g(o), c = u ? Et(s, u) : d.center ?? i.center;
1239
+ return c && await this.showVisualEffect({
703
1240
  type: "click",
704
- point: u,
1241
+ point: c,
705
1242
  anchor: "target",
706
- target: i,
1243
+ target: s,
707
1244
  requested: o
708
- }), i instanceof HTMLElement ? i.click() : i.dispatchEvent(new MouseEvent("click", { bubbles: !0 })), {
709
- clicked: this.describeElement(i),
1245
+ }), s instanceof HTMLElement ? s.click() : s.dispatchEvent(new MouseEvent("click", { bubbles: !0 })), this.invalidateReadableContent(), {
1246
+ clicked: this.describeElement(s),
710
1247
  requested: this.describeElement(o),
711
- strategy: i === o ? "dom" : "semantic_visible_fallback",
712
- point: u,
1248
+ strategy: s === o ? "dom" : "semantic_visible_fallback",
1249
+ point: c,
713
1250
  actionability: {
714
1251
  visible: l.visible,
715
1252
  enabled: l.enabled,
716
- receivesEvents: l.receivesEvents
1253
+ receivesEvents: l.receivesEvents,
1254
+ occludedBy: l.occludedBy ? _(l.occludedBy) : void 0,
1255
+ safeClickPoints: l.safeClickPoints
717
1256
  }
718
1257
  };
719
1258
  }
1259
+ read(e) {
1260
+ const n = b(e), o = this.getRoot(), i = this.readableContent ?? ot(o);
1261
+ this.readableContent = i;
1262
+ const r = {
1263
+ blockId: w(n.blockId),
1264
+ query: w(n.query),
1265
+ page: B(n.page),
1266
+ pageSize: B(n.pageSize),
1267
+ maxChars: B(n.maxChars)
1268
+ };
1269
+ return qt(i, r);
1270
+ }
720
1271
  async fill(e) {
721
- const n = y(e), o = O(n.value, "value"), r = this.resolveElement(n);
722
- if (S(r), r instanceof HTMLInputElement || r instanceof HTMLTextAreaElement)
1272
+ const n = b(e), o = z(n.value, "value"), i = this.resolveElement(n);
1273
+ if (L(i), i instanceof HTMLInputElement || i instanceof HTMLTextAreaElement)
723
1274
  return await this.showVisualEffect({
724
1275
  type: "fill",
725
- target: r,
726
- requested: r,
1276
+ target: i,
1277
+ requested: i,
727
1278
  value: o,
728
1279
  anchor: "target",
729
- point: p(r).center
730
- }), Lt(r, o), I(r), { filled: this.describeElement(r), value: o };
731
- if (r instanceof HTMLElement && r.isContentEditable)
1280
+ point: g(i).center
1281
+ }), ye(i, o), j(i), this.invalidateReadableContent(), { filled: this.describeElement(i), value: o };
1282
+ if (i instanceof HTMLElement && i.isContentEditable)
732
1283
  return await this.showVisualEffect({
733
1284
  type: "fill",
734
- target: r,
735
- requested: r,
1285
+ target: i,
1286
+ requested: i,
736
1287
  value: o,
737
1288
  anchor: "target",
738
- point: p(r).center
739
- }), r.textContent = o, I(r), { filled: this.describeElement(r), value: o };
1289
+ point: g(i).center
1290
+ }), i.textContent = o, j(i), this.invalidateReadableContent(), { filled: this.describeElement(i), value: o };
740
1291
  throw new Error("Target element cannot be filled.");
741
1292
  }
742
1293
  async press(e) {
743
- const n = y(e), o = O(n.key, "key"), r = n.ref || n.selector || n.x !== void 0 && n.y !== void 0 ? this.resolveElement(n) : m(this.getRoot()).activeElement ?? m(this.getRoot()).body;
744
- if (!r)
1294
+ const n = b(e), o = z(n.key, "key"), i = n.ref || n.selector || n.x !== void 0 && n.y !== void 0 ? this.resolveElement(n) : T(this.getRoot()).activeElement ?? T(this.getRoot()).body;
1295
+ if (!i)
745
1296
  throw new Error("No target element is available for key press.");
746
- S(r), await this.showVisualEffect({
1297
+ L(i), await this.showVisualEffect({
747
1298
  type: "press",
748
- target: r,
749
- requested: r,
1299
+ target: i,
1300
+ requested: i,
750
1301
  key: o,
751
1302
  anchor: "target",
752
- point: p(r).center
1303
+ point: g(i).center
753
1304
  });
754
- const c = { key: o, bubbles: !0, cancelable: !0 };
755
- return r.dispatchEvent(new KeyboardEvent("keydown", c)), o.length === 1 && r.dispatchEvent(new KeyboardEvent("keypress", c)), r.dispatchEvent(new KeyboardEvent("keyup", c)), { pressed: o, target: this.describeElement(r) };
1305
+ const r = { key: o, bubbles: !0, cancelable: !0 };
1306
+ return i.dispatchEvent(new KeyboardEvent("keydown", r)), o.length === 1 && i.dispatchEvent(new KeyboardEvent("keypress", r)), i.dispatchEvent(new KeyboardEvent("keyup", r)), this.invalidateReadableContent(), { pressed: o, target: this.describeElement(i) };
756
1307
  }
757
1308
  async select(e) {
758
- const n = y(e), o = ct(n.values ?? n.value), r = this.resolveElement(n);
759
- if (!(r instanceof HTMLSelectElement))
1309
+ const n = b(e), o = Gt(n.values ?? n.value), i = this.resolveElement(n);
1310
+ if (!(i instanceof HTMLSelectElement))
760
1311
  throw new Error("Target element is not a select.");
761
- S(r);
762
- const c = new Set(o);
1312
+ L(i);
1313
+ const r = new Set(o);
763
1314
  await this.showVisualEffect({
764
1315
  type: "select",
765
- target: r,
766
- requested: r,
1316
+ target: i,
1317
+ requested: i,
767
1318
  values: o,
768
1319
  anchor: "target",
769
- point: p(r).center
1320
+ point: g(i).center
770
1321
  });
771
- for (const i of Array.from(r.options))
772
- i.selected = c.has(i.value);
773
- return I(r), {
774
- selected: Array.from(r.selectedOptions).map(
775
- (i) => i.value
1322
+ for (const s of Array.from(i.options))
1323
+ s.selected = r.has(s.value);
1324
+ return j(i), this.invalidateReadableContent(), {
1325
+ selected: Array.from(i.selectedOptions).map(
1326
+ (s) => s.value
776
1327
  ),
777
- target: this.describeElement(r)
1328
+ target: this.describeElement(i)
778
1329
  };
779
1330
  }
780
1331
  async scroll(e) {
781
- var a, d, l, u;
782
- const n = y(e), o = n.x !== void 0 || n.y !== void 0 ? {
783
- x: _(n.x) ?? 0,
784
- y: _(n.y) ?? 0
785
- } : null, r = _(n.deltaX) ?? 0, c = _(n.deltaY) ?? 0, i = this.getRoot(), s = H(i);
1332
+ var u, d, l, c;
1333
+ const n = b(e), o = n.x !== void 0 || n.y !== void 0 ? {
1334
+ x: A(n.x) ?? 0,
1335
+ y: A(n.y) ?? 0
1336
+ } : null, i = A(n.deltaX) ?? 0, r = A(n.deltaY) ?? 0, s = this.getRoot(), a = V(s);
786
1337
  if (n.ref || n.selector || n.role || n.name || n.text || n.testId) {
787
1338
  const f = this.resolveElement(n);
788
1339
  if (!(f instanceof HTMLElement))
@@ -791,111 +1342,124 @@ class kt {
791
1342
  type: "scroll",
792
1343
  target: f,
793
1344
  requested: f,
794
- deltaX: r,
795
- deltaY: c,
1345
+ deltaX: i,
1346
+ deltaY: r,
796
1347
  anchor: "target",
797
- point: p(f).center
798
- }), o ? (a = f.scrollTo) == null || a.call(f, o.x, o.y) : (d = f.scrollBy) == null || d.call(f, r, c), {
1348
+ point: g(f).center
1349
+ }), o ? (u = f.scrollTo) == null || u.call(f, o.x, o.y) : (d = f.scrollBy) == null || d.call(f, i, r), this.invalidateReadableContent(), {
799
1350
  scrolled: this.describeElement(f),
800
1351
  scroll: { x: f.scrollLeft, y: f.scrollTop }
801
1352
  };
802
1353
  }
803
1354
  return await this.showVisualEffect({
804
1355
  type: "scroll",
805
- deltaX: r,
806
- deltaY: c,
1356
+ deltaX: i,
1357
+ deltaY: r,
807
1358
  point: {
808
- x: s.innerWidth / 2,
809
- y: s.innerHeight / 2
1359
+ x: a.innerWidth / 2,
1360
+ y: a.innerHeight / 2
810
1361
  }
811
- }), o ? (l = s.scrollTo) == null || l.call(s, o.x, o.y) : (u = s.scrollBy) == null || u.call(s, r, c), { scroll: { x: s.scrollX, y: s.scrollY } };
1362
+ }), o ? (l = a.scrollTo) == null || l.call(a, o.x, o.y) : (c = a.scrollBy) == null || c.call(a, i, r), this.invalidateReadableContent(), { scroll: { x: a.scrollX, y: a.scrollY } };
812
1363
  }
813
1364
  navigate(e) {
814
1365
  if (this.options.allowNavigation === !1)
815
1366
  throw new Error("Navigation is disabled for host page automation.");
816
- const n = y(e), o = this.getRoot(), r = H(o), c = O(n.url, "url"), i = new URL(c, r.location.href);
817
- if (i.protocol !== "http:" && i.protocol !== "https:")
1367
+ const n = b(e), o = this.getRoot(), i = V(o), r = z(n.url, "url"), s = new URL(r, i.location.href);
1368
+ if (s.protocol !== "http:" && s.protocol !== "https:")
818
1369
  throw new Error("Navigation only supports HTTP(S) URLs.");
819
- return this.refs.clear(), r.location.assign(i.toString()), { navigated: i.toString() };
1370
+ return this.refs.clear(), this.invalidateReadableContent(), i.location.assign(s.toString()), { navigated: s.toString() };
820
1371
  }
821
1372
  async hover(e) {
822
- const n = y(e), o = this.resolveElement(n), r = p(o).center;
1373
+ const n = b(e), o = this.resolveElement(n), i = g(o).center;
823
1374
  return await this.showVisualEffect({
824
1375
  type: "hover",
825
1376
  target: o,
826
1377
  requested: o,
827
1378
  anchor: "target",
828
- point: r
1379
+ point: i
829
1380
  }), o.dispatchEvent(
830
1381
  new MouseEvent("mouseover", {
831
1382
  bubbles: !0,
832
1383
  cancelable: !0,
833
- clientX: r == null ? void 0 : r.x,
834
- clientY: r == null ? void 0 : r.y
1384
+ clientX: i == null ? void 0 : i.x,
1385
+ clientY: i == null ? void 0 : i.y
835
1386
  })
836
1387
  ), o.dispatchEvent(
837
1388
  new MouseEvent("mousemove", {
838
1389
  bubbles: !0,
839
1390
  cancelable: !0,
840
- clientX: r == null ? void 0 : r.x,
841
- clientY: r == null ? void 0 : r.y
1391
+ clientX: i == null ? void 0 : i.x,
1392
+ clientY: i == null ? void 0 : i.y
842
1393
  })
843
- ), { hovered: this.describeElement(o), point: r };
1394
+ ), { hovered: this.describeElement(o), point: i };
844
1395
  }
845
1396
  async focus(e) {
846
- const n = y(e), o = this.resolveElement(n);
847
- return S(o), await this.showVisualEffect({
1397
+ const n = b(e), o = this.resolveElement(n);
1398
+ return L(o), await this.showVisualEffect({
848
1399
  type: "focus",
849
1400
  target: o,
850
1401
  requested: o,
851
1402
  anchor: "target",
852
- point: p(o).center
1403
+ point: g(o).center
853
1404
  }), { focused: this.describeElement(o) };
854
1405
  }
855
1406
  async pointer(e) {
856
- const n = y(e), o = W(n.action, ["move", "down", "up", "click"]) ?? "click", r = st(n.button) ?? 0, c = n.ref || n.selector || n.role || n.name || n.text || n.testId ? this.resolveElement(n) : null, i = c ? p(c).center : {
857
- x: C(n.x, "x"),
858
- y: C(n.y, "y")
859
- };
860
- if (!i)
1407
+ const n = b(e), o = at(n.action, ["move", "down", "up", "click"]) ?? "click", i = B(n.button) ?? 0, r = typeof n.x < "u" || typeof n.y < "u", s = w(n.targetText);
1408
+ if (o === "click" && r && !s)
1409
+ throw new Error(
1410
+ "Pointer coordinate clicks require targetText to avoid unintended navigation."
1411
+ );
1412
+ const a = n.ref || n.selector || n.role || n.name || n.text || n.testId ? this.resolveElement(n) : null, u = a ? g(a).center : rt(this.getRoot(), n);
1413
+ if (!u)
861
1414
  throw new Error("Target element has no clickable point.");
862
- const s = c ?? m(this.getRoot()).elementFromPoint(i.x, i.y);
863
- if (!s)
864
- throw new Error(`No element found at (${i.x}, ${i.y}).`);
865
- const a = {
1415
+ const d = a ?? T(this.getRoot()).elementFromPoint(u.x, u.y);
1416
+ if (!d)
1417
+ throw new Error(`No element found at (${u.x}, ${u.y}).`);
1418
+ const l = s ? he(d, s) : void 0;
1419
+ if (s && !l)
1420
+ throw new Error(
1421
+ `Pointer target text mismatch: expected hit target to contain "${s}".`
1422
+ );
1423
+ const c = {
866
1424
  bubbles: !0,
867
1425
  cancelable: !0,
868
- clientX: i.x,
869
- clientY: i.y,
870
- button: r
1426
+ clientX: u.x,
1427
+ clientY: u.y,
1428
+ button: i
871
1429
  };
872
1430
  return o === "move" ? (await this.showVisualEffect({
873
1431
  type: "pointer",
874
1432
  action: o,
875
1433
  anchor: "point",
876
- point: i,
877
- target: s
878
- }), s.dispatchEvent(L("pointermove", a)), s.dispatchEvent(new MouseEvent("mousemove", a))) : o === "down" ? (await this.showVisualEffect({
1434
+ point: u,
1435
+ target: d
1436
+ }), d.dispatchEvent(R("pointermove", c)), d.dispatchEvent(new MouseEvent("mousemove", c))) : o === "down" ? (await this.showVisualEffect({
879
1437
  type: "pointer",
880
1438
  action: o,
881
1439
  anchor: "point",
882
- point: i,
883
- target: s
884
- }), s.dispatchEvent(L("pointerdown", a)), s.dispatchEvent(new MouseEvent("mousedown", a))) : o === "up" ? (await this.showVisualEffect({
1440
+ point: u,
1441
+ target: d
1442
+ }), d.dispatchEvent(R("pointerdown", c)), d.dispatchEvent(new MouseEvent("mousedown", c))) : o === "up" ? (await this.showVisualEffect({
885
1443
  type: "pointer",
886
1444
  action: o,
887
1445
  anchor: "point",
888
- point: i,
889
- target: s
890
- }), s.dispatchEvent(L("pointerup", a)), s.dispatchEvent(new MouseEvent("mouseup", a))) : (await this.showVisualEffect({
1446
+ point: u,
1447
+ target: d
1448
+ }), d.dispatchEvent(R("pointerup", c)), d.dispatchEvent(new MouseEvent("mouseup", c))) : (await this.showVisualEffect({
891
1449
  type: "click",
892
1450
  anchor: "point",
893
- point: i,
894
- target: s
895
- }), s.dispatchEvent(L("pointerdown", a)), s.dispatchEvent(new MouseEvent("mousedown", a)), s.dispatchEvent(L("pointerup", a)), s.dispatchEvent(new MouseEvent("mouseup", a)), s instanceof HTMLElement ? s.click() : s.dispatchEvent(new MouseEvent("click", a))), {
1451
+ point: u,
1452
+ target: d
1453
+ }), d.dispatchEvent(R("pointerdown", c)), d.dispatchEvent(new MouseEvent("mousedown", c)), d.dispatchEvent(R("pointerup", c)), d.dispatchEvent(new MouseEvent("mouseup", c)), d instanceof HTMLElement ? d.click() : d.dispatchEvent(new MouseEvent("click", c)), this.invalidateReadableContent()), {
896
1454
  pointer: o,
897
- point: i,
898
- target: this.describeElement(s)
1455
+ point: u,
1456
+ coordinateSpace: "viewport-css-px",
1457
+ target: this.describeElement(d),
1458
+ targetTextMatched: l,
1459
+ expectedAfterClick: o === "click" ? me(
1460
+ this.getRoot(),
1461
+ pe(n.expectedAfterClick)
1462
+ ) : void 0
899
1463
  };
900
1464
  }
901
1465
  screenshot() {
@@ -904,14 +1468,14 @@ class kt {
904
1468
  );
905
1469
  }
906
1470
  async showVisualEffect(e) {
907
- var n, o, r, c;
1471
+ var n, o, i, r;
908
1472
  try {
909
1473
  await ((o = (n = this.options).showVisualEffect) == null ? void 0 : o.call(n, e));
910
1474
  } catch {
911
1475
  }
912
1476
  if (!(e.type !== "click" || !e.point || !e.target || this.options.showVisualEffect))
913
1477
  try {
914
- await ((c = (r = this.options).showClickEffect) == null ? void 0 : c.call(r, {
1478
+ await ((r = (i = this.options).showClickEffect) == null ? void 0 : r.call(i, {
915
1479
  point: e.point,
916
1480
  target: e.target,
917
1481
  requested: e.requested
@@ -920,29 +1484,29 @@ class kt {
920
1484
  }
921
1485
  }
922
1486
  async waitFor(e) {
923
- const n = y(e), o = W(n.state, [
1487
+ const n = b(e), o = at(n.state, [
924
1488
  "attached",
925
1489
  "visible",
926
1490
  "hidden",
927
1491
  "detached"
928
- ]) ?? "visible", r = _(n.timeoutSeconds), c = Math.min(
929
- rt,
930
- Math.max(0, (r ?? ot / 1e3) * 1e3)
931
- ), i = Date.now(), s = this.tryResolveElement(n);
1492
+ ]) ?? "visible", i = A(n.timeoutSeconds), r = Math.min(
1493
+ $t,
1494
+ Math.max(0, (i ?? jt / 1e3) * 1e3)
1495
+ ), s = Date.now(), a = this.tryResolveElement(n);
932
1496
  for (await this.showVisualEffect({
933
1497
  type: "wait_for",
934
1498
  state: o,
935
- target: s ?? void 0,
936
- requested: s ?? void 0,
937
- ...s ? { anchor: "target" } : {},
938
- point: s ? p(s).center : void 0
939
- }); Date.now() - i <= c; ) {
940
- const a = this.tryResolveElement(n);
941
- if (o === "attached" ? !!a : o === "detached" ? !a : o === "hidden" ? !a || !T(a) : !!(a && T(a)))
1499
+ target: a ?? void 0,
1500
+ requested: a ?? void 0,
1501
+ ...a ? { anchor: "target" } : {},
1502
+ point: a ? g(a).center : void 0
1503
+ }); Date.now() - s <= r; ) {
1504
+ const u = this.tryResolveElement(n);
1505
+ if (o === "attached" ? !!u : o === "detached" ? !u : o === "hidden" ? !u || !S(u) : !!(u && S(u)))
942
1506
  return {
943
1507
  waitedFor: o,
944
- elapsedMs: Date.now() - i,
945
- target: a ? this.describeElement(a) : void 0
1508
+ elapsedMs: Date.now() - s,
1509
+ target: u ? this.describeElement(u) : void 0
946
1510
  };
947
1511
  await new Promise((l) => setTimeout(l, 100));
948
1512
  }
@@ -960,52 +1524,309 @@ class kt {
960
1524
  tag: e.tagName.toLowerCase(),
961
1525
  role: M(e),
962
1526
  name: x(e),
963
- selector: D(e)
1527
+ selector: Y(e)
964
1528
  };
965
1529
  }
966
1530
  }
967
- function Ct(t) {
1531
+ function Ee(t) {
968
1532
  return typeof t == "object" && t !== null && !Array.isArray(t) ? t : {};
969
1533
  }
970
- function Nt(t) {
1534
+ function we(t) {
971
1535
  return JSON.stringify(t);
972
1536
  }
973
- function P(t, e, n) {
1537
+ function $(t, e, n) {
974
1538
  return {
975
1539
  tool_call_id: t.tool_call_id ?? t.id,
976
1540
  name: t.name,
977
1541
  status: e,
978
- content: Nt(n)
1542
+ content: we(n)
979
1543
  };
980
1544
  }
981
- function At(t) {
1545
+ function ve(t) {
982
1546
  return t instanceof Error ? t.message : String(t);
983
1547
  }
984
- function Rt(t = {}) {
985
- const e = new kt(t);
1548
+ function xe(t) {
1549
+ if (!t || typeof t != "object" || Array.isArray(t))
1550
+ return {};
1551
+ const e = Reflect.get(t, "details");
1552
+ return e && typeof e == "object" && !Array.isArray(e) ? e : {};
1553
+ }
1554
+ function Se(t = {}) {
1555
+ const e = new be(t);
986
1556
  return async (n) => {
987
- if (!it(n.name))
988
- return P(n, "error", {
1557
+ if (!Wt(n.name))
1558
+ return $(n, "error", {
989
1559
  ok: !1,
990
1560
  error: `Unknown host page automation tool: ${n.name}`
991
1561
  });
992
1562
  try {
993
1563
  const o = await e.execute(
994
1564
  n.name,
995
- Ct(n.params)
1565
+ Ee(n.params)
996
1566
  );
997
- return P(n, "success", { ok: !0, result: o });
1567
+ return $(n, "success", { ok: !0, result: o });
998
1568
  } catch (o) {
999
- return P(n, "error", {
1569
+ return $(n, "error", {
1000
1570
  ok: !1,
1001
- error: At(o)
1571
+ error: ve(o),
1572
+ ...xe(o)
1002
1573
  });
1003
1574
  }
1004
1575
  };
1005
1576
  }
1577
+ const v = {
1578
+ ref: {
1579
+ type: ["string", "number"],
1580
+ description: "Element ref from host_page_snapshot."
1581
+ },
1582
+ axRef: {
1583
+ type: ["string", "number"],
1584
+ description: "Accessibility ref from host_page_snapshot."
1585
+ },
1586
+ selector: {
1587
+ type: "string",
1588
+ description: "CSS selector for the target element."
1589
+ },
1590
+ testId: {
1591
+ type: "string",
1592
+ description: "data-testid, data-test-id, or data-qa value."
1593
+ },
1594
+ role: {
1595
+ type: "string",
1596
+ description: "Accessible role to match."
1597
+ },
1598
+ name: {
1599
+ type: "string",
1600
+ description: "Accessible name to match."
1601
+ },
1602
+ text: {
1603
+ type: "string",
1604
+ description: "Visible text to match."
1605
+ },
1606
+ x: {
1607
+ type: "number",
1608
+ description: "Viewport x coordinate."
1609
+ },
1610
+ y: {
1611
+ type: "number",
1612
+ description: "Viewport y coordinate."
1613
+ }
1614
+ }, _e = {
1615
+ coordinateSpace: {
1616
+ type: "string",
1617
+ enum: ["viewport-css-px", "viewport_normalized"],
1618
+ description: "Coordinate space for x/y. Use viewport_normalized for screenshot-derived points."
1619
+ }
1620
+ }, Te = {
1621
+ type: "object",
1622
+ properties: {
1623
+ type: {
1624
+ const: "field_contains",
1625
+ description: "Currently supported post-click expectation type."
1626
+ },
1627
+ field: {
1628
+ type: "string",
1629
+ description: "Field label/name expected to change after clicking."
1630
+ },
1631
+ value: {
1632
+ type: "string",
1633
+ description: "Expected substring in the field value after clicking."
1634
+ }
1635
+ },
1636
+ required: ["type", "field", "value"],
1637
+ additionalProperties: !1
1638
+ }, Ce = {
1639
+ host_page_snapshot: {
1640
+ type: "object",
1641
+ properties: {},
1642
+ additionalProperties: !1
1643
+ },
1644
+ host_page_click: {
1645
+ type: "object",
1646
+ properties: {
1647
+ ...v
1648
+ },
1649
+ additionalProperties: !1
1650
+ },
1651
+ host_page_fill: {
1652
+ type: "object",
1653
+ properties: {
1654
+ ...v,
1655
+ value: {
1656
+ type: "string",
1657
+ description: "Text value to set on the target field."
1658
+ }
1659
+ },
1660
+ required: ["value"],
1661
+ additionalProperties: !1
1662
+ },
1663
+ host_page_press: {
1664
+ type: "object",
1665
+ properties: {
1666
+ ...v,
1667
+ key: {
1668
+ type: "string",
1669
+ description: "Keyboard key to press."
1670
+ }
1671
+ },
1672
+ required: ["key"],
1673
+ additionalProperties: !1
1674
+ },
1675
+ host_page_select: {
1676
+ type: "object",
1677
+ properties: {
1678
+ ...v,
1679
+ value: {
1680
+ type: ["string", "array"],
1681
+ description: "Select option value or values.",
1682
+ items: { type: "string" }
1683
+ },
1684
+ values: {
1685
+ type: ["string", "array"],
1686
+ description: "Select option values.",
1687
+ items: { type: "string" }
1688
+ }
1689
+ },
1690
+ additionalProperties: !1
1691
+ },
1692
+ host_page_scroll: {
1693
+ type: "object",
1694
+ properties: {
1695
+ ...v,
1696
+ deltaX: {
1697
+ type: "number",
1698
+ description: "Horizontal scroll delta."
1699
+ },
1700
+ deltaY: {
1701
+ type: "number",
1702
+ description: "Vertical scroll delta."
1703
+ }
1704
+ },
1705
+ additionalProperties: !1
1706
+ },
1707
+ host_page_navigate: {
1708
+ type: "object",
1709
+ properties: {
1710
+ url: {
1711
+ type: "string",
1712
+ description: "HTTP(S) URL to navigate to."
1713
+ }
1714
+ },
1715
+ required: ["url"],
1716
+ additionalProperties: !1
1717
+ },
1718
+ host_page_hover: {
1719
+ type: "object",
1720
+ properties: {
1721
+ ...v
1722
+ },
1723
+ additionalProperties: !1
1724
+ },
1725
+ host_page_focus: {
1726
+ type: "object",
1727
+ properties: {
1728
+ ...v
1729
+ },
1730
+ additionalProperties: !1
1731
+ },
1732
+ host_page_pointer: {
1733
+ type: "object",
1734
+ properties: {
1735
+ ...v,
1736
+ ..._e,
1737
+ action: {
1738
+ type: "string",
1739
+ enum: ["move", "down", "up", "click"],
1740
+ description: "Pointer action. Defaults to click."
1741
+ },
1742
+ button: {
1743
+ type: ["string", "number"],
1744
+ description: "Mouse button."
1745
+ },
1746
+ clickCount: {
1747
+ type: "number",
1748
+ description: "Number of clicks for CDP mouse click."
1749
+ },
1750
+ targetText: {
1751
+ type: "string",
1752
+ description: "Required for explicit coordinate clicks. The actual hit target or near ancestor must contain this text."
1753
+ },
1754
+ expectedAfterClick: Te
1755
+ },
1756
+ additionalProperties: !1
1757
+ },
1758
+ host_page_screenshot: {
1759
+ type: "object",
1760
+ properties: {
1761
+ format: {
1762
+ type: "string",
1763
+ enum: ["jpeg", "png"],
1764
+ description: "Screenshot image format."
1765
+ },
1766
+ quality: {
1767
+ type: "number",
1768
+ description: "JPEG quality from 1 to 100."
1769
+ }
1770
+ },
1771
+ additionalProperties: !1
1772
+ },
1773
+ host_page_read: {
1774
+ type: "object",
1775
+ properties: {
1776
+ blockId: {
1777
+ type: "string",
1778
+ description: "Readable content block id from host_page_snapshot."
1779
+ },
1780
+ scope: {
1781
+ type: "string",
1782
+ enum: ["visible"],
1783
+ description: "Visible content scope. Use blockId when a specific readable block is known."
1784
+ },
1785
+ query: {
1786
+ type: "string",
1787
+ description: "Optional text query for selecting relevant readable blocks."
1788
+ },
1789
+ page: {
1790
+ type: "number",
1791
+ minimum: 1,
1792
+ description: "1-based page for long block content."
1793
+ },
1794
+ pageSize: {
1795
+ type: "number",
1796
+ minimum: 1,
1797
+ maximum: 100,
1798
+ description: "Items, fields, rows, or blocks to return per page."
1799
+ },
1800
+ maxChars: {
1801
+ type: "number",
1802
+ minimum: 500,
1803
+ maximum: 12e3,
1804
+ description: "Maximum characters to return."
1805
+ }
1806
+ },
1807
+ additionalProperties: !1
1808
+ },
1809
+ host_page_wait_for: {
1810
+ type: "object",
1811
+ properties: {
1812
+ ...v,
1813
+ state: {
1814
+ type: "string",
1815
+ enum: ["attached", "visible", "hidden", "detached"],
1816
+ description: "Target state to wait for. Defaults to visible."
1817
+ },
1818
+ timeoutSeconds: {
1819
+ type: "number",
1820
+ description: "Maximum wait time in seconds."
1821
+ }
1822
+ },
1823
+ additionalProperties: !1
1824
+ }
1825
+ };
1006
1826
  export {
1007
- tt as HOST_PAGE_AUTOMATION_TOOL_NAMES,
1008
- kt as HostPageAutomationExecutor,
1009
- Rt as createHostPageAutomationClientToolHandler,
1010
- it as isHostPageAutomationToolName
1827
+ vt as HOST_PAGE_AUTOMATION_TOOL_NAMES,
1828
+ Ce as HOST_PAGE_AUTOMATION_TOOL_SCHEMAS,
1829
+ be as HostPageAutomationExecutor,
1830
+ Se as createHostPageAutomationClientToolHandler,
1831
+ Wt as isHostPageAutomationToolName
1011
1832
  };