@xpert-ai/chatkit-host-automation 0.3.3 → 0.3.5

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 +550 -0
  2. package/dist/index.js +850 -304
  3. package/package.json +2 -2
package/dist/index.js CHANGED
@@ -1,4 +1,4 @@
1
- const z = [
1
+ const it = [
2
2
  "host_page_snapshot",
3
3
  "host_page_click",
4
4
  "host_page_fill",
@@ -11,9 +11,9 @@ const z = [
11
11
  "host_page_pointer",
12
12
  "host_page_screenshot",
13
13
  "host_page_wait_for"
14
- ], G = new Set(
15
- z
16
- ), K = [
14
+ ], rt = new Set(
15
+ it
16
+ ), st = [
17
17
  "a[href]",
18
18
  "button",
19
19
  "input",
@@ -28,116 +28,257 @@ const z = [
28
28
  "[data-testid]",
29
29
  "[data-test-id]",
30
30
  "[data-qa]"
31
- ].join(","), D = 100, J = 1e4, Q = 6e4;
32
- function Z(t) {
33
- return G.has(t);
31
+ ].join(","), X = 100, at = 1e4, ct = 6e4;
32
+ function lt(t) {
33
+ return rt.has(t);
34
34
  }
35
- function g(t) {
35
+ function T(t) {
36
36
  return t instanceof Document ? t : t.ownerDocument;
37
37
  }
38
38
  function N(t) {
39
- return g(t).defaultView ?? window;
39
+ return T(t).defaultView ?? window;
40
40
  }
41
- function h(t) {
41
+ function m(t) {
42
42
  return typeof t == "object" && t !== null && !Array.isArray(t) ? t : {};
43
43
  }
44
- function R(t, e) {
44
+ function O(t, e) {
45
45
  if (typeof t != "string" || t.trim() === "")
46
46
  throw new Error(`${e} must be a non-empty string.`);
47
47
  return t;
48
48
  }
49
- function p(t) {
49
+ function x(t) {
50
50
  return typeof t == "string" && t.trim() ? t : void 0;
51
51
  }
52
- function tt(t) {
52
+ function ut(t) {
53
+ return t === "viewport_normalized" ? "viewport_normalized" : "viewport-css-px";
54
+ }
55
+ function U(t, e) {
56
+ const n = z(e.x, "x"), o = z(e.y, "y");
57
+ if (ut(e.coordinateSpace) === "viewport_normalized") {
58
+ const i = N(t);
59
+ return {
60
+ x: Number((n * i.innerWidth).toFixed(3)),
61
+ y: Number((o * i.innerHeight).toFixed(3))
62
+ };
63
+ }
64
+ return { x: n, y: o };
65
+ }
66
+ function dt(t) {
53
67
  return typeof t == "number" && Number.isInteger(t) ? t : void 0;
54
68
  }
55
- function M(t, e) {
69
+ function z(t, e) {
56
70
  if (typeof t != "number" || !Number.isFinite(t))
57
71
  throw new Error(`${e} must be a finite number.`);
58
72
  return t;
59
73
  }
60
- function T(t) {
74
+ function k(t) {
61
75
  return typeof t == "number" && Number.isFinite(t) ? t : void 0;
62
76
  }
63
- function F(t, e) {
77
+ function Y(t, e) {
64
78
  return typeof t == "string" && e.includes(t) ? t : void 0;
65
79
  }
66
- function et(t) {
80
+ function ft(t) {
67
81
  if (typeof t == "string")
68
82
  return [t];
69
83
  if (Array.isArray(t) && t.every((e) => typeof e == "string"))
70
84
  return t;
71
85
  throw new Error("value or values must be a string or an array of strings.");
72
86
  }
73
- function v(t) {
87
+ function b(t) {
74
88
  const e = (t.textContent ?? "").replace(/\s+/g, " ").trim();
75
89
  return e ? e.slice(0, 160) : void 0;
76
90
  }
77
- function V(t) {
91
+ function P(t) {
78
92
  const e = Array.from(t.childNodes).filter((n) => n.nodeType === Node.TEXT_NODE).map((n) => n.textContent ?? "").join(" ").replace(/\s+/g, " ").trim();
79
93
  return e ? e.slice(0, 160) : void 0;
80
94
  }
81
- function nt(t) {
95
+ function F(t) {
82
96
  if (t instanceof HTMLInputElement || t instanceof HTMLTextAreaElement || t instanceof HTMLSelectElement)
83
97
  return t.value;
84
98
  }
85
- function E(t) {
86
- const e = t.getAttribute("aria-label");
87
- if (e != null && e.trim())
88
- return e.trim();
89
- const n = t.getAttribute("title");
90
- if (n != null && n.trim())
91
- return n.trim();
92
- if (t instanceof HTMLInputElement) {
93
- const r = Array.from(t.labels ?? []).map((c) => v(c)).filter(Boolean);
94
- if (r.length > 0)
95
- return r.join(" ").slice(0, 160);
99
+ function Q(t) {
100
+ return t instanceof HTMLInputElement && (t.type === "checkbox" || t.type === "radio");
101
+ }
102
+ function pt(t) {
103
+ return t instanceof HTMLInputElement || t instanceof HTMLSelectElement || t instanceof HTMLTextAreaElement ? Array.from(t.labels ?? []) : [];
104
+ }
105
+ function ht(t, e) {
106
+ var o;
107
+ return (((o = t.getAttribute(e)) == null ? void 0 : o.trim().split(/\s+/)) ?? []).map((i) => t.ownerDocument.getElementById(i)).filter((i) => !!i).map((i) => b(i)).filter((i) => !!i);
108
+ }
109
+ function gt(t) {
110
+ const e = ht(t, "aria-labelledby");
111
+ if (e.length > 0)
112
+ return e.join(" ").slice(0, 160);
113
+ const n = pt(t).map((o) => b(o)).filter((o) => !!o);
114
+ if (n.length > 0)
115
+ return n.join(" ").slice(0, 160);
116
+ }
117
+ function bt(t) {
118
+ const e = [];
119
+ let n = t.nextSibling;
120
+ for (; n; ) {
121
+ if (n.nodeType === Node.TEXT_NODE) {
122
+ const i = (n.textContent ?? "").replace(/\s+/g, " ").trim();
123
+ i && e.push(i);
124
+ } else {
125
+ if (n.nodeType === Node.ELEMENT_NODE && n.tagName.toLowerCase() === "br")
126
+ break;
127
+ if (n.nodeType === Node.ELEMENT_NODE) {
128
+ const i = n;
129
+ if (i.matches(
130
+ 'input,textarea,select,button,a[href],[role="button"],[role="link"]'
131
+ ))
132
+ break;
133
+ const s = b(i);
134
+ s && e.push(s);
135
+ break;
136
+ }
137
+ }
138
+ if (e.join(" ").length >= 120)
139
+ break;
140
+ n = n.nextSibling;
141
+ }
142
+ const o = e.join(" ").replace(/\s+/g, " ").trim();
143
+ return o ? o.slice(0, 160) : void 0;
144
+ }
145
+ function G(t, e) {
146
+ var d;
147
+ const n = t.ownerDocument, o = n.body;
148
+ if (!o)
149
+ return;
150
+ const i = t.getBoundingClientRect();
151
+ if (i.width <= 0 || i.height <= 0)
152
+ return;
153
+ const s = i.top + i.height / 2, r = [], a = n.createTreeWalker(o, NodeFilter.SHOW_ELEMENT);
154
+ let c = a.nextNode();
155
+ for (; c; ) {
156
+ const u = c;
157
+ if (u !== t && !u.contains(t) && j(u)) {
158
+ const l = u.getBoundingClientRect(), f = P(u) ?? b(u);
159
+ if (f) {
160
+ const p = l.top + l.height / 2, y = Math.abs(p - s) <= Math.max(28, i.height * 1.25), h = e === "left" ? i.left - l.right : l.left - i.right;
161
+ y && h >= -8 && h <= 240 && r.push({
162
+ text: f,
163
+ score: Math.abs(h) + Math.abs(p - s)
164
+ });
165
+ }
166
+ }
167
+ c = a.nextNode();
96
168
  }
97
- const o = X(t)[0];
98
- return o || v(t);
169
+ return (d = r.sort((u, l) => u.score - l.score)[0]) == null ? void 0 : d.text;
99
170
  }
100
- function ot(t) {
101
- if (!(t instanceof HTMLElement || t instanceof SVGElement) || !m(t) || t.matches(
171
+ function H(t) {
172
+ if (!(t instanceof HTMLInputElement || t instanceof HTMLSelectElement || t instanceof HTMLTextAreaElement))
173
+ return;
174
+ const e = gt(t);
175
+ return e || (Q(t) ? G(t, "right") ?? bt(t) ?? C(t)[0] : G(t, "left") ?? C(t)[0]);
176
+ }
177
+ function K(t, e) {
178
+ const n = e.trim().toLowerCase();
179
+ 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;
180
+ }
181
+ function v(t) {
182
+ const e = H(t), n = t.getAttribute("aria-label");
183
+ if (n != null && n.trim() && !K(t, n))
184
+ return n.trim();
185
+ const o = t.getAttribute("title");
186
+ if (o != null && o.trim() && !K(t, o))
187
+ return o.trim();
188
+ if (e)
189
+ return e;
190
+ const i = C(t)[0];
191
+ return i || b(t);
192
+ }
193
+ function j(t) {
194
+ if (!(t instanceof HTMLElement || t instanceof SVGElement) || !_(t) || t.matches(
102
195
  'input,textarea,select,button,a[href],[role="button"],[role="link"]'
103
196
  ))
104
197
  return !1;
105
- const e = V(t) ?? v(t);
198
+ const e = P(t) ?? b(t);
106
199
  return !!(e && e.length <= 120);
107
200
  }
108
- function X(t) {
201
+ function Z(t) {
202
+ var l;
203
+ if (!Q(t))
204
+ return;
205
+ const e = t.closest("fieldset"), n = e == null ? void 0 : e.querySelector("legend"), o = n ? b(n) : void 0;
206
+ if (o)
207
+ return o;
208
+ const i = t.ownerDocument, s = i.body;
209
+ if (!s)
210
+ return;
211
+ const r = t.getBoundingClientRect();
212
+ if (r.width <= 0 || r.height <= 0)
213
+ return;
214
+ const a = r.left + r.width / 2, c = [], d = i.createTreeWalker(s, NodeFilter.SHOW_ELEMENT);
215
+ let u = d.nextNode();
216
+ for (; u; ) {
217
+ const f = u;
218
+ if (f !== t && !f.contains(t) && f.matches('legend,strong,b,[role="heading"],h1,h2,h3,h4,h5,h6') && j(f)) {
219
+ const p = f.getBoundingClientRect(), y = P(f) ?? b(f);
220
+ if (y && p.bottom <= r.top + 8) {
221
+ const h = r.top - p.bottom, E = p.left + p.width / 2;
222
+ h <= 160 && E >= r.left - 120 && E <= r.right + 320 && c.push({
223
+ text: y,
224
+ score: h + Math.abs(E - a) * 0.25
225
+ });
226
+ }
227
+ }
228
+ u = d.nextNode();
229
+ }
230
+ return (l = c.sort((f, p) => f.score - p.score)[0]) == null ? void 0 : l.text;
231
+ }
232
+ function yt(t) {
233
+ if (!(t instanceof HTMLSelectElement))
234
+ return;
235
+ const e = Array.from(t.options).map((n) => ({
236
+ label: ((n.label || n.textContent || n.value).replace(/\s+/g, " ").trim() || n.value).slice(0, 160),
237
+ value: n.value,
238
+ selected: n.selected || void 0,
239
+ disabled: n.disabled || void 0
240
+ }));
241
+ return e.length ? e : void 0;
242
+ }
243
+ function Et(t) {
244
+ if (!(t instanceof HTMLSelectElement))
245
+ return;
246
+ const e = t.selectedOptions[0], n = e ? (e.label || e.textContent || e.value).replace(/\s+/g, " ").trim() : void 0;
247
+ return n ? n.slice(0, 160) : void 0;
248
+ }
249
+ function C(t) {
109
250
  const e = t.ownerDocument, n = e.body;
110
251
  if (!n)
111
252
  return [];
112
253
  const o = t.getBoundingClientRect();
113
254
  if (o.width <= 0 || o.height <= 0)
114
255
  return [];
115
- const r = o.top + o.height / 2, c = o.left + o.width / 2, s = [], i = e.createTreeWalker(n, NodeFilter.SHOW_ELEMENT);
116
- let a = i.nextNode();
117
- for (; a; ) {
118
- const l = a;
119
- if (l !== t && ot(l)) {
120
- const u = l.getBoundingClientRect(), f = V(l) ?? v(l);
256
+ const i = o.top + o.height / 2, s = o.left + o.width / 2, r = [], a = e.createTreeWalker(n, NodeFilter.SHOW_ELEMENT);
257
+ let c = a.nextNode();
258
+ for (; c; ) {
259
+ const u = c;
260
+ if (u !== t && !u.contains(t) && j(u)) {
261
+ const l = u.getBoundingClientRect(), f = P(u) ?? b(u);
121
262
  if (f) {
122
- const b = u.top + u.height / 2, w = u.left + u.width / 2, y = u.right <= o.left + 12 && Math.abs(b - r) <= Math.max(28, o.height * 1.25), S = u.bottom <= o.top + 8 && o.top - u.bottom <= 80 && w >= o.left - 80 && w <= o.right + 80;
123
- if (y || S) {
124
- const j = y ? o.left - u.right + Math.abs(b - r) : o.top - u.bottom + Math.abs(w - c);
125
- s.push({
263
+ const p = l.top + l.height / 2, y = l.left + l.width / 2, h = l.right <= o.left + 12 && Math.abs(p - i) <= Math.max(28, o.height * 1.25), E = l.left >= o.right - 8 && l.left - o.right <= 240 && Math.abs(p - i) <= Math.max(28, o.height * 1.25), W = l.bottom <= o.top + 8 && o.top - l.bottom <= 80 && y >= o.left - 80 && y <= o.right + 80;
264
+ if (h || E || W) {
265
+ const ot = h ? o.left - l.right + Math.abs(p - i) : E ? l.left - o.right + Math.abs(p - i) : o.top - l.bottom + Math.abs(y - s);
266
+ r.push({
126
267
  text: f,
127
- score: j + (y ? 0 : 100)
268
+ score: ot + (h ? 0 : E ? 5 : 100)
128
269
  });
129
270
  }
130
271
  }
131
272
  }
132
- a = i.nextNode();
273
+ c = a.nextNode();
133
274
  }
134
275
  const d = /* @__PURE__ */ new Set();
135
- return s.sort((l, u) => l.score - u.score).map((l) => l.text).filter((l) => d.has(l) ? !1 : (d.add(l), !0)).slice(0, 4);
276
+ return r.sort((u, l) => u.score - l.score).map((u) => u.text).filter((u) => d.has(u) ? !1 : (d.add(u), !0)).slice(0, 4);
136
277
  }
137
- function rt(t) {
278
+ function mt(t) {
138
279
  return t.getAttribute("data-testid") ?? t.getAttribute("data-test-id") ?? t.getAttribute("data-qa") ?? void 0;
139
280
  }
140
- function x(t) {
281
+ function S(t) {
141
282
  const e = t.getAttribute("role");
142
283
  if (e != null && e.trim())
143
284
  return e.trim();
@@ -161,65 +302,65 @@ function x(t) {
161
302
  return "textbox";
162
303
  }
163
304
  }
164
- function q(t) {
305
+ function tt(t) {
165
306
  return t instanceof HTMLButtonElement || t instanceof HTMLInputElement || t instanceof HTMLSelectElement || t instanceof HTMLTextAreaElement ? t.disabled || void 0 : t.getAttribute("aria-disabled") === "true" || void 0;
166
307
  }
167
- function it(t) {
308
+ function wt(t) {
168
309
  return t instanceof HTMLInputElement && (t.type === "checkbox" || t.type === "radio") ? t.checked : void 0;
169
310
  }
170
- function st(t) {
171
- const e = k(t);
311
+ function vt(t) {
312
+ const e = A(t);
172
313
  if (!(e.width <= 0 || e.height <= 0))
173
314
  return {
174
315
  x: e.x + e.width / 2,
175
316
  y: e.y + e.height / 2
176
317
  };
177
318
  }
178
- function $(t) {
319
+ function V(t) {
179
320
  return {
180
321
  tag: t.tagName.toLowerCase(),
181
- role: x(t),
182
- name: E(t),
183
- selector: P(t)
322
+ role: S(t),
323
+ name: v(t),
324
+ selector: q(t)
184
325
  };
185
326
  }
186
- function m(t) {
327
+ function _(t) {
187
328
  if (!(t instanceof HTMLElement || t instanceof SVGElement) || t instanceof HTMLElement && t.hidden)
188
329
  return !1;
189
330
  const e = t.ownerDocument.defaultView, n = e == null ? void 0 : e.getComputedStyle(t);
190
331
  return !(n && (n.display === "none" || n.visibility === "hidden" || n.opacity === "0"));
191
332
  }
192
- function U(t) {
193
- return t.matches(K) && m(t);
333
+ function et(t) {
334
+ return t.matches(st) && _(t);
194
335
  }
195
- function ct(t) {
196
- return q(t) !== !0;
336
+ function xt(t) {
337
+ return tt(t) !== !0;
197
338
  }
198
- function at(t) {
339
+ function Tt(t) {
199
340
  var n;
200
- if (U(t))
341
+ if (et(t))
201
342
  return !0;
202
343
  if (!(t instanceof HTMLElement))
203
344
  return !1;
204
345
  const e = (n = t.ownerDocument.defaultView) == null ? void 0 : n.getComputedStyle(t);
205
- return ((e == null ? void 0 : e.cursor) === "pointer" || !!t.onclick) && m(t);
346
+ return ((e == null ? void 0 : e.cursor) === "pointer" || !!t.onclick) && _(t);
206
347
  }
207
- function k(t) {
208
- var c, s;
348
+ function A(t) {
349
+ var s, r;
209
350
  const e = t.getBoundingClientRect();
210
- let n = e.left, o = e.top, r = null;
351
+ let n = e.left, o = e.top, i = null;
211
352
  try {
212
- r = ((c = t.ownerDocument.defaultView) == null ? void 0 : c.frameElement) ?? null;
353
+ i = ((s = t.ownerDocument.defaultView) == null ? void 0 : s.frameElement) ?? null;
213
354
  } catch {
214
- r = null;
355
+ i = null;
215
356
  }
216
- for (; r; ) {
217
- const i = r.getBoundingClientRect();
218
- n += i.left, o += i.top;
357
+ for (; i; ) {
358
+ const a = i.getBoundingClientRect();
359
+ n += a.left, o += a.top;
219
360
  try {
220
- r = ((s = r.ownerDocument.defaultView) == null ? void 0 : s.frameElement) ?? null;
361
+ i = ((r = i.ownerDocument.defaultView) == null ? void 0 : r.frameElement) ?? null;
221
362
  } catch {
222
- r = null;
363
+ i = null;
223
364
  }
224
365
  }
225
366
  return {
@@ -229,21 +370,21 @@ function k(t) {
229
370
  height: e.height
230
371
  };
231
372
  }
232
- function P(t) {
373
+ function q(t) {
233
374
  const e = (o) => typeof CSS < "u" && typeof CSS.escape == "function" ? CSS.escape(o) : o.replaceAll("\\", "\\\\").replaceAll('"', '\\"');
234
375
  if (t.id)
235
376
  return `#${e(t.id)}`;
236
377
  for (const o of ["data-testid", "data-test-id", "data-qa"]) {
237
- const r = t.getAttribute(o);
238
- if (r)
239
- return `[${o}="${e(r)}"]`;
378
+ const i = t.getAttribute(o);
379
+ if (i)
380
+ return `[${o}="${e(i)}"]`;
240
381
  }
241
382
  const n = t.getAttribute("name");
242
383
  return n ? `${t.tagName.toLowerCase()}[name="${e(
243
384
  n
244
385
  )}"]` : t.tagName.toLowerCase();
245
386
  }
246
- function lt(t) {
387
+ function _t(t) {
247
388
  const e = t.getBoundingClientRect();
248
389
  if (!(e.width <= 0 || e.height <= 0))
249
390
  return {
@@ -251,7 +392,7 @@ function lt(t) {
251
392
  y: e.top + e.height / 2
252
393
  };
253
394
  }
254
- function W(t, e) {
395
+ function nt(t, e) {
255
396
  if (typeof t.elementsFromPoint == "function")
256
397
  return t.elementsFromPoint(e.x, e.y);
257
398
  if (typeof t.elementFromPoint != "function")
@@ -259,25 +400,25 @@ function W(t, e) {
259
400
  const n = t.elementFromPoint(e.x, e.y);
260
401
  return n ? [n] : [];
261
402
  }
262
- function ut(t) {
403
+ function St(t) {
263
404
  return typeof t.elementsFromPoint == "function" || typeof t.elementFromPoint == "function";
264
405
  }
265
- function C(t, e) {
406
+ function R(t, e) {
266
407
  return t === e || t.contains(e);
267
408
  }
268
- function ft(t) {
409
+ function kt(t) {
269
410
  let e = t;
270
411
  for (; e; ) {
271
- if (at(e))
412
+ if (Tt(e))
272
413
  return e;
273
414
  e = e.parentElement;
274
415
  }
275
416
  return t;
276
417
  }
277
- function B(t) {
418
+ function J(t) {
278
419
  return (t ?? "").replace(/\([^)]*\)/g, "").replace(/\s+/g, "").trim().toLowerCase();
279
420
  }
280
- function Y(t) {
421
+ function B(t) {
281
422
  const e = t.getBoundingClientRect();
282
423
  if (e.width <= 0 || e.height <= 0)
283
424
  return;
@@ -289,93 +430,158 @@ function Y(t) {
289
430
  { x: e.left + e.width / 2, y: e.top + Math.min(8, e.height / 2) },
290
431
  { x: e.left + e.width / 2, y: e.bottom - Math.min(8, e.height / 2) }
291
432
  ].find(
292
- (r) => W(n, r).some(
293
- (c) => C(t, c) || C(c, t)
433
+ (i) => nt(n, i).some(
434
+ (s) => R(t, s) || R(s, t)
294
435
  )
295
436
  );
296
437
  }
297
- function dt(t, e) {
298
- var c;
299
- const n = x(e), o = B(E(e));
300
- return o ? ((c = I(t).filter((s) => s !== e).filter((s) => {
301
- const i = x(s), a = B(E(s));
302
- return n && i && n !== i ? !1 : a.includes(o) || o.includes(a);
303
- }).map((s) => ({
304
- candidate: s,
305
- point: Y(s),
306
- rect: k(s)
438
+ function Mt(t, e) {
439
+ const n = t.getBoundingClientRect(), o = A(t);
440
+ return {
441
+ x: e.x + o.x - n.left,
442
+ y: e.y + o.y - n.top
443
+ };
444
+ }
445
+ function Lt(t, e) {
446
+ var s;
447
+ const n = S(e), o = J(v(e));
448
+ return o ? ((s = $(t).filter((r) => r !== e).filter((r) => {
449
+ const a = S(r), c = J(v(r));
450
+ return n && a && n !== a ? !1 : c.includes(o) || o.includes(c);
451
+ }).map((r) => ({
452
+ candidate: r,
453
+ point: B(r),
454
+ rect: A(r)
307
455
  })).filter(
308
- (s) => !!s.point
309
- ).sort((s, i) => i.rect.y - s.rect.y)[0]) == null ? void 0 : c.candidate) ?? null : null;
456
+ (r) => !!r.point
457
+ ).sort((r, a) => a.rect.y - r.rect.y)[0]) == null ? void 0 : s.candidate) ?? null : null;
310
458
  }
311
- function L(t) {
312
- const e = t.ownerDocument, n = lt(t), o = m(t) && !!n, r = ct(t), c = n ? W(e, n) : [], s = c[0], i = !!(s && (C(t, s) || C(s, t)));
459
+ function g(t) {
460
+ const e = t.ownerDocument, n = _t(t), o = _(t) && !!n, i = xt(t), s = n ? nt(e, n) : [], r = s[0], a = !!(r && (R(t, r) || R(r, t)));
313
461
  return {
314
462
  visible: o,
315
- enabled: r,
316
- receivesEvents: i,
317
- actionable: o && r && i,
318
- center: st(t),
319
- hitTarget: s,
320
- hitStack: c
463
+ enabled: i,
464
+ receivesEvents: a,
465
+ actionable: o && i && a,
466
+ center: vt(t),
467
+ hitTarget: r,
468
+ hitStack: s
321
469
  };
322
470
  }
323
- function ht(t, e) {
324
- var i, a, d;
325
- const n = p(e.testId);
471
+ function Ct(t, e) {
472
+ var a, c, d;
473
+ const n = x(e.testId);
326
474
  if (n) {
327
- const l = typeof CSS < "u" && typeof CSS.escape == "function" ? CSS.escape(n) : n.replaceAll("\\", "\\\\").replaceAll('"', '\\"'), u = t.querySelector(
328
- `[data-testid="${l}"],[data-test-id="${l}"],[data-qa="${l}"]`
475
+ const u = typeof CSS < "u" && typeof CSS.escape == "function" ? CSS.escape(n) : n.replaceAll("\\", "\\\\").replaceAll('"', '\\"'), l = t.querySelector(
476
+ `[data-testid="${u}"],[data-test-id="${u}"],[data-qa="${u}"]`
329
477
  );
330
- if (u)
331
- return u;
332
- }
333
- const o = (i = p(e.role)) == null ? void 0 : i.toLowerCase(), r = (a = p(e.name)) == null ? void 0 : a.toLowerCase(), c = (d = p(e.text)) == null ? void 0 : d.toLowerCase();
334
- return !o && !r && !c ? null : I(t).find((l) => {
335
- var w, y, S;
336
- const u = (w = x(l)) == null ? void 0 : w.toLowerCase(), f = (y = E(l)) == null ? void 0 : y.toLowerCase(), b = (S = v(l)) == null ? void 0 : S.toLowerCase();
337
- return !(o && u !== o || r && !(f != null && f.includes(r)) || c && !(b != null && b.includes(c)));
478
+ if (l)
479
+ return l;
480
+ }
481
+ const o = (a = x(e.role)) == null ? void 0 : a.toLowerCase(), i = (c = x(e.name)) == null ? void 0 : c.toLowerCase(), s = (d = x(e.text)) == null ? void 0 : d.toLowerCase();
482
+ return !o && !i && !s ? null : $(t).find((u) => {
483
+ var y, h, E;
484
+ const l = (y = S(u)) == null ? void 0 : y.toLowerCase(), f = (h = v(u)) == null ? void 0 : h.toLowerCase(), p = (E = b(u)) == null ? void 0 : E.toLowerCase();
485
+ return !(o && l !== o || i && !(f != null && f.includes(i)) || s && !(p != null && p.includes(s)));
338
486
  }) ?? null;
339
487
  }
340
- function I(t) {
341
- const e = g(t), n = t instanceof Document ? t.body ?? t.documentElement : t;
488
+ function At(t) {
489
+ return [
490
+ v(t),
491
+ H(t),
492
+ Z(t),
493
+ b(t),
494
+ F(t)
495
+ ].filter((e) => !!e).join(" ").toLowerCase();
496
+ }
497
+ function Nt(t, e) {
498
+ const n = e.trim().toLowerCase();
499
+ let o = t, i = 0;
500
+ for (; o && i < 5; ) {
501
+ const s = o.tagName.toLowerCase();
502
+ if (s === "body" || s === "html")
503
+ return !1;
504
+ if (At(o).includes(n))
505
+ return !0;
506
+ o = o.parentElement, i += 1;
507
+ }
508
+ return !1;
509
+ }
510
+ function Rt(t) {
511
+ if (!t || typeof t != "object" || Array.isArray(t))
512
+ return;
513
+ const e = t;
514
+ if (e.type === "field_contains" && typeof e.field == "string" && e.field.trim() && typeof e.value == "string")
515
+ return {
516
+ type: "field_contains",
517
+ field: e.field,
518
+ value: e.value
519
+ };
520
+ }
521
+ function Pt(t, e) {
522
+ const n = e.trim().toLowerCase();
523
+ return Array.from(t.querySelectorAll("input,textarea,select")).find(
524
+ (o) => [
525
+ H(o),
526
+ v(o),
527
+ o.getAttribute("name") ?? void 0,
528
+ o.getAttribute("placeholder") ?? void 0,
529
+ ...C(o)
530
+ ].some(
531
+ (s) => s == null ? void 0 : s.trim().toLowerCase().includes(n)
532
+ )
533
+ );
534
+ }
535
+ function Ht(t, e) {
536
+ if (!e)
537
+ return;
538
+ const n = Pt(t, e.field), o = n ? F(n) ?? "" : void 0;
539
+ return {
540
+ ...e,
541
+ ok: typeof o == "string" && o.toLowerCase().includes(e.value.toLowerCase()),
542
+ actual: o,
543
+ matchedField: n ? V(n) : void 0
544
+ };
545
+ }
546
+ function $(t) {
547
+ const e = t instanceof Element ? t.ownerDocument : T(t), n = t instanceof Document ? t.body ?? t.documentElement : t;
342
548
  if (!n)
343
549
  return [];
344
- const o = [], r = (c) => {
345
- const s = e.createTreeWalker(c, NodeFilter.SHOW_ELEMENT);
346
- let i = s.nextNode();
347
- for (; i; ) {
348
- const a = i;
349
- U(a) && o.push(a);
350
- const d = a.shadowRoot;
351
- if (d && r(d), a instanceof HTMLIFrameElement)
550
+ const o = [], i = (s) => {
551
+ const r = e.createTreeWalker(s, NodeFilter.SHOW_ELEMENT);
552
+ let a = r.nextNode();
553
+ for (; a; ) {
554
+ const c = a;
555
+ et(c) && o.push(c);
556
+ const d = c.shadowRoot;
557
+ if (d && i(d), c instanceof HTMLIFrameElement)
352
558
  try {
353
- a.contentDocument && r(a.contentDocument);
559
+ c.contentDocument && i(c.contentDocument);
354
560
  } catch {
355
561
  }
356
- if (o.length >= D)
562
+ if (o.length >= X)
357
563
  return;
358
- i = s.nextNode();
564
+ a = r.nextNode();
359
565
  }
360
566
  };
361
- return r(n), o.slice(0, D);
567
+ return i(n), o.slice(0, X);
362
568
  }
363
- function gt(t, e) {
364
- var r;
569
+ function Ot(t, e) {
570
+ var i;
365
571
  const n = Object.getPrototypeOf(t), o = Object.getOwnPropertyDescriptor(n, "value");
366
- (r = o == null ? void 0 : o.set) == null || r.call(t, e);
572
+ (i = o == null ? void 0 : o.set) == null || i.call(t, e);
367
573
  }
368
- function H(t) {
574
+ function I(t) {
369
575
  t.dispatchEvent(new Event("input", { bubbles: !0 })), t.dispatchEvent(new Event("change", { bubbles: !0 }));
370
576
  }
371
- function A(t) {
577
+ function M(t) {
372
578
  var e, n;
373
579
  (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));
374
580
  }
375
- function _(t, e) {
581
+ function L(t, e) {
376
582
  return typeof PointerEvent == "function" ? new PointerEvent(t, e) : new MouseEvent(t.replace("pointer", "mouse"), e);
377
583
  }
378
- class pt {
584
+ class It {
379
585
  constructor(e = {}) {
380
586
  this.options = e, this.refs = /* @__PURE__ */ new Map(), this.nextRef = 1;
381
587
  }
@@ -410,10 +616,10 @@ class pt {
410
616
  }
411
617
  }
412
618
  snapshot() {
413
- var c, s;
619
+ var s, r;
414
620
  this.refs.clear(), this.nextRef = 1;
415
- const e = this.getRoot(), n = g(e), o = N(e), r = I(e).map(
416
- (i) => this.snapshotElement(i)
621
+ const e = this.getRoot(), n = T(e), o = N(e), i = $(e).map(
622
+ (a) => this.snapshotElement(a)
417
623
  );
418
624
  return {
419
625
  url: o.location.href,
@@ -438,28 +644,28 @@ class pt {
438
644
  readyState: n.readyState,
439
645
  visibilityState: n.visibilityState,
440
646
  focusedElement: n.activeElement && n.activeElement !== n.body ? this.snapshotElementWithoutRef(n.activeElement) : void 0,
441
- selection: ((s = (c = n.getSelection) == null ? void 0 : c.call(n)) == null ? void 0 : s.toString()) || void 0
647
+ selection: ((r = (s = n.getSelection) == null ? void 0 : s.call(n)) == null ? void 0 : r.toString()) || void 0
442
648
  },
443
649
  navigation: this.getNavigationState(o),
444
650
  frames: this.getFrameState(n),
445
- accessibility: r.map((i) => ({
446
- ref: i.ref,
447
- role: i.role,
448
- name: i.name,
449
- value: i.value,
450
- disabled: i.disabled,
451
- checked: i.checked,
452
- focused: n.activeElement === this.refs.get(i.ref)
651
+ accessibility: i.map((a) => ({
652
+ ref: a.ref,
653
+ role: a.role,
654
+ name: a.name,
655
+ value: a.value,
656
+ disabled: a.disabled,
657
+ checked: a.checked,
658
+ focused: n.activeElement === this.refs.get(a.ref)
453
659
  })),
454
- elements: r
660
+ elements: i
455
661
  };
456
662
  }
457
663
  getRoot() {
458
664
  return this.options.root ?? document;
459
665
  }
460
666
  getNavigationState(e) {
461
- var o, r, c;
462
- const n = (c = (r = (o = e.performance) == null ? void 0 : o.getEntriesByType) == null ? void 0 : r.call(o, "navigation")) == null ? void 0 : c[0];
667
+ var o, i, s;
668
+ const n = (s = (i = (o = e.performance) == null ? void 0 : o.getEntriesByType) == null ? void 0 : i.call(o, "navigation")) == null ? void 0 : s[0];
463
669
  if (!(typeof PerformanceNavigationTiming != "function" || !(n instanceof PerformanceNavigationTiming)))
464
670
  return {
465
671
  type: n.type,
@@ -470,12 +676,12 @@ class pt {
470
676
  }
471
677
  getFrameState(e) {
472
678
  return Array.from(e.querySelectorAll("iframe")).map((n) => {
473
- var r, c;
474
- const o = k(n);
679
+ var i, s;
680
+ const o = A(n);
475
681
  try {
476
682
  return {
477
- url: (r = n.contentWindow) == null ? void 0 : r.location.href,
478
- title: (c = n.contentDocument) == null ? void 0 : c.title,
683
+ url: (i = n.contentWindow) == null ? void 0 : i.location.href,
684
+ title: (s = n.contentDocument) == null ? void 0 : s.title,
479
685
  sameOrigin: !0,
480
686
  rect: o
481
687
  };
@@ -496,179 +702,282 @@ class pt {
496
702
  return this.createElementSnapshot(e, "");
497
703
  }
498
704
  createElementSnapshot(e, n) {
499
- const o = (e instanceof HTMLInputElement || e instanceof HTMLTextAreaElement) && e.placeholder || void 0, r = L(e);
705
+ const o = (e instanceof HTMLInputElement || e instanceof HTMLTextAreaElement) && e.placeholder || void 0, i = g(e);
500
706
  return {
501
707
  ref: n,
502
708
  tag: e.tagName.toLowerCase(),
503
- role: x(e),
504
- name: E(e),
505
- text: v(e),
506
- nearbyText: X(e),
507
- testId: rt(e),
508
- value: nt(e),
709
+ role: S(e),
710
+ name: v(e),
711
+ label: H(e),
712
+ groupLabel: Z(e),
713
+ text: b(e),
714
+ nearbyText: C(e),
715
+ testId: mt(e),
716
+ value: F(e),
717
+ selectedLabel: Et(e),
718
+ options: yt(e),
509
719
  placeholder: o,
510
- selector: P(e),
511
- disabled: q(e),
512
- enabled: r.enabled,
513
- checked: it(e),
514
- visible: r.visible,
515
- actionable: r.actionable,
516
- rect: k(e),
517
- center: r.center,
518
- hitTarget: r.hitTarget ? $(r.hitTarget) : void 0,
519
- hitStack: r.hitStack.slice(0, 5).map($)
720
+ selector: q(e),
721
+ disabled: tt(e),
722
+ enabled: i.enabled,
723
+ checked: wt(e),
724
+ visible: i.visible,
725
+ actionable: i.actionable,
726
+ rect: A(e),
727
+ center: i.center,
728
+ hitTarget: i.hitTarget ? V(i.hitTarget) : void 0,
729
+ hitStack: i.hitStack.slice(0, 5).map(V)
520
730
  };
521
731
  }
522
732
  resolveElement(e) {
523
- const n = p(e.ref) ?? p(e.axRef);
733
+ const n = x(e.ref) ?? x(e.axRef);
524
734
  if (n) {
525
- const c = this.refs.get(n);
526
- if (!c)
735
+ const s = this.refs.get(n);
736
+ if (!s)
527
737
  throw new Error(`Unknown element ref: ${n}. Take a new snapshot.`);
528
- return c;
738
+ return s;
529
739
  }
530
- const o = p(e.selector);
740
+ const o = x(e.selector);
531
741
  if (o) {
532
- const c = this.getRoot().querySelector(o);
533
- if (!c)
742
+ const s = this.getRoot().querySelector(o);
743
+ if (!s)
534
744
  throw new Error(`No element matches selector: ${o}.`);
535
- return c;
745
+ return s;
536
746
  }
537
- const r = ht(this.getRoot(), e);
538
- if (r)
539
- return r;
747
+ const i = Ct(this.getRoot(), e);
748
+ if (i)
749
+ return i;
540
750
  if (typeof e.x < "u" || typeof e.y < "u") {
541
- const c = {
542
- x: M(e.x, "x"),
543
- y: M(e.y, "y")
544
- }, s = g(this.getRoot()).elementFromPoint(
545
- c.x,
546
- c.y
751
+ const s = U(this.getRoot(), e), r = T(this.getRoot()).elementFromPoint(
752
+ s.x,
753
+ s.y
547
754
  );
548
- if (!s)
549
- throw new Error(`No element found at (${c.x}, ${c.y}).`);
550
- return s;
755
+ if (!r)
756
+ throw new Error(`No element found at (${s.x}, ${s.y}).`);
757
+ return r;
551
758
  }
552
759
  throw new Error(
553
760
  "Expected one of ref, selector, role/name/text/testId, or x/y."
554
761
  );
555
762
  }
556
- click(e) {
557
- const n = h(e), o = this.resolveElement(n), r = L(o), s = (r.actionable ? null : dt(this.getRoot(), o)) ?? ft(o), i = Y(s);
558
- if (!i && !r.actionable && ut(o.ownerDocument))
763
+ async click(e) {
764
+ const n = m(e), o = this.resolveElement(n), i = g(o), r = (i.actionable ? null : Lt(this.getRoot(), o)) ?? kt(o);
765
+ if (!B(r) && !i.actionable && St(o.ownerDocument))
559
766
  throw new Error(
560
- `Target "${E(o) ?? o.tagName.toLowerCase()}" is not receiving pointer events. Take a screenshot or use host_page_pointer coordinates.`
767
+ `Target "${v(o) ?? o.tagName.toLowerCase()}" is not receiving pointer events. Take a screenshot or use host_page_pointer coordinates.`
561
768
  );
562
- return A(s), s instanceof HTMLElement ? s.click() : s.dispatchEvent(new MouseEvent("click", { bubbles: !0 })), {
563
- clicked: this.describeElement(s),
769
+ M(r);
770
+ const c = B(r), d = g(r), u = g(o), l = c ? Mt(r, c) : d.center ?? i.center;
771
+ return l && await this.showVisualEffect({
772
+ type: "click",
773
+ point: l,
774
+ anchor: "target",
775
+ target: r,
776
+ requested: o
777
+ }), r instanceof HTMLElement ? r.click() : r.dispatchEvent(new MouseEvent("click", { bubbles: !0 })), {
778
+ clicked: this.describeElement(r),
564
779
  requested: this.describeElement(o),
565
- strategy: s === o ? "dom" : "semantic_visible_fallback",
566
- point: i ?? r.center,
780
+ strategy: r === o ? "dom" : "semantic_visible_fallback",
781
+ point: l,
567
782
  actionability: {
568
- visible: r.visible,
569
- enabled: r.enabled,
570
- receivesEvents: r.receivesEvents
783
+ visible: u.visible,
784
+ enabled: u.enabled,
785
+ receivesEvents: u.receivesEvents
571
786
  }
572
787
  };
573
788
  }
574
- fill(e) {
575
- const n = h(e), o = R(n.value, "value"), r = this.resolveElement(n);
576
- if (A(r), r instanceof HTMLInputElement || r instanceof HTMLTextAreaElement)
577
- return gt(r, o), H(r), { filled: this.describeElement(r), value: o };
578
- if (r instanceof HTMLElement && r.isContentEditable)
579
- return r.textContent = o, H(r), { filled: this.describeElement(r), value: o };
789
+ async fill(e) {
790
+ const n = m(e), o = O(n.value, "value"), i = this.resolveElement(n);
791
+ if (M(i), i instanceof HTMLInputElement || i instanceof HTMLTextAreaElement)
792
+ return await this.showVisualEffect({
793
+ type: "fill",
794
+ target: i,
795
+ requested: i,
796
+ value: o,
797
+ anchor: "target",
798
+ point: g(i).center
799
+ }), Ot(i, o), I(i), { filled: this.describeElement(i), value: o };
800
+ if (i instanceof HTMLElement && i.isContentEditable)
801
+ return await this.showVisualEffect({
802
+ type: "fill",
803
+ target: i,
804
+ requested: i,
805
+ value: o,
806
+ anchor: "target",
807
+ point: g(i).center
808
+ }), i.textContent = o, I(i), { filled: this.describeElement(i), value: o };
580
809
  throw new Error("Target element cannot be filled.");
581
810
  }
582
- press(e) {
583
- const n = h(e), o = R(n.key, "key"), r = n.ref || n.selector || n.x !== void 0 && n.y !== void 0 ? this.resolveElement(n) : g(this.getRoot()).activeElement ?? g(this.getRoot()).body;
584
- if (!r)
811
+ async press(e) {
812
+ const n = m(e), o = O(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;
813
+ if (!i)
585
814
  throw new Error("No target element is available for key press.");
586
- A(r);
587
- const c = { key: o, bubbles: !0, cancelable: !0 };
588
- 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) };
815
+ M(i), await this.showVisualEffect({
816
+ type: "press",
817
+ target: i,
818
+ requested: i,
819
+ key: o,
820
+ anchor: "target",
821
+ point: g(i).center
822
+ });
823
+ const s = { key: o, bubbles: !0, cancelable: !0 };
824
+ return i.dispatchEvent(new KeyboardEvent("keydown", s)), o.length === 1 && i.dispatchEvent(new KeyboardEvent("keypress", s)), i.dispatchEvent(new KeyboardEvent("keyup", s)), { pressed: o, target: this.describeElement(i) };
589
825
  }
590
- select(e) {
591
- const n = h(e), o = et(n.values ?? n.value), r = this.resolveElement(n);
592
- if (!(r instanceof HTMLSelectElement))
826
+ async select(e) {
827
+ const n = m(e), o = ft(n.values ?? n.value), i = this.resolveElement(n);
828
+ if (!(i instanceof HTMLSelectElement))
593
829
  throw new Error("Target element is not a select.");
594
- const c = new Set(o);
595
- for (const s of Array.from(r.options))
596
- s.selected = c.has(s.value);
597
- return H(r), {
598
- selected: Array.from(r.selectedOptions).map(
599
- (s) => s.value
830
+ M(i);
831
+ const s = new Set(o);
832
+ await this.showVisualEffect({
833
+ type: "select",
834
+ target: i,
835
+ requested: i,
836
+ values: o,
837
+ anchor: "target",
838
+ point: g(i).center
839
+ });
840
+ for (const r of Array.from(i.options))
841
+ r.selected = s.has(r.value);
842
+ return I(i), {
843
+ selected: Array.from(i.selectedOptions).map(
844
+ (r) => r.value
600
845
  ),
601
- target: this.describeElement(r)
846
+ target: this.describeElement(i)
602
847
  };
603
848
  }
604
- scroll(e) {
605
- var a, d, l, u;
606
- const n = h(e), o = n.x !== void 0 || n.y !== void 0 ? {
607
- x: T(n.x) ?? 0,
608
- y: T(n.y) ?? 0
609
- } : null, r = T(n.deltaX) ?? 0, c = T(n.deltaY) ?? 0, s = this.getRoot(), i = N(s);
849
+ async scroll(e) {
850
+ var c, d, u, l;
851
+ const n = m(e), o = n.x !== void 0 || n.y !== void 0 ? {
852
+ x: k(n.x) ?? 0,
853
+ y: k(n.y) ?? 0
854
+ } : null, i = k(n.deltaX) ?? 0, s = k(n.deltaY) ?? 0, r = this.getRoot(), a = N(r);
610
855
  if (n.ref || n.selector || n.role || n.name || n.text || n.testId) {
611
856
  const f = this.resolveElement(n);
612
857
  if (!(f instanceof HTMLElement))
613
858
  throw new Error("Target element cannot be scrolled.");
614
- return o ? (a = f.scrollTo) == null || a.call(f, o.x, o.y) : (d = f.scrollBy) == null || d.call(f, r, c), {
859
+ return await this.showVisualEffect({
860
+ type: "scroll",
861
+ target: f,
862
+ requested: f,
863
+ deltaX: i,
864
+ deltaY: s,
865
+ anchor: "target",
866
+ point: g(f).center
867
+ }), o ? (c = f.scrollTo) == null || c.call(f, o.x, o.y) : (d = f.scrollBy) == null || d.call(f, i, s), {
615
868
  scrolled: this.describeElement(f),
616
869
  scroll: { x: f.scrollLeft, y: f.scrollTop }
617
870
  };
618
871
  }
619
- return o ? (l = i.scrollTo) == null || l.call(i, o.x, o.y) : (u = i.scrollBy) == null || u.call(i, r, c), { scroll: { x: i.scrollX, y: i.scrollY } };
872
+ return await this.showVisualEffect({
873
+ type: "scroll",
874
+ deltaX: i,
875
+ deltaY: s,
876
+ point: {
877
+ x: a.innerWidth / 2,
878
+ y: a.innerHeight / 2
879
+ }
880
+ }), o ? (u = a.scrollTo) == null || u.call(a, o.x, o.y) : (l = a.scrollBy) == null || l.call(a, i, s), { scroll: { x: a.scrollX, y: a.scrollY } };
620
881
  }
621
882
  navigate(e) {
622
883
  if (this.options.allowNavigation === !1)
623
884
  throw new Error("Navigation is disabled for host page automation.");
624
- const n = h(e), o = this.getRoot(), r = N(o), c = R(n.url, "url"), s = new URL(c, r.location.href);
625
- if (s.protocol !== "http:" && s.protocol !== "https:")
885
+ const n = m(e), o = this.getRoot(), i = N(o), s = O(n.url, "url"), r = new URL(s, i.location.href);
886
+ if (r.protocol !== "http:" && r.protocol !== "https:")
626
887
  throw new Error("Navigation only supports HTTP(S) URLs.");
627
- return this.refs.clear(), r.location.assign(s.toString()), { navigated: s.toString() };
888
+ return this.refs.clear(), i.location.assign(r.toString()), { navigated: r.toString() };
628
889
  }
629
- hover(e) {
630
- const n = h(e), o = this.resolveElement(n), r = L(o).center;
631
- return o.dispatchEvent(
890
+ async hover(e) {
891
+ const n = m(e), o = this.resolveElement(n), i = g(o).center;
892
+ return await this.showVisualEffect({
893
+ type: "hover",
894
+ target: o,
895
+ requested: o,
896
+ anchor: "target",
897
+ point: i
898
+ }), o.dispatchEvent(
632
899
  new MouseEvent("mouseover", {
633
900
  bubbles: !0,
634
901
  cancelable: !0,
635
- clientX: r == null ? void 0 : r.x,
636
- clientY: r == null ? void 0 : r.y
902
+ clientX: i == null ? void 0 : i.x,
903
+ clientY: i == null ? void 0 : i.y
637
904
  })
638
905
  ), o.dispatchEvent(
639
906
  new MouseEvent("mousemove", {
640
907
  bubbles: !0,
641
908
  cancelable: !0,
642
- clientX: r == null ? void 0 : r.x,
643
- clientY: r == null ? void 0 : r.y
909
+ clientX: i == null ? void 0 : i.x,
910
+ clientY: i == null ? void 0 : i.y
644
911
  })
645
- ), { hovered: this.describeElement(o), point: r };
912
+ ), { hovered: this.describeElement(o), point: i };
646
913
  }
647
- focus(e) {
648
- const n = h(e), o = this.resolveElement(n);
649
- return A(o), { focused: this.describeElement(o) };
914
+ async focus(e) {
915
+ const n = m(e), o = this.resolveElement(n);
916
+ return M(o), await this.showVisualEffect({
917
+ type: "focus",
918
+ target: o,
919
+ requested: o,
920
+ anchor: "target",
921
+ point: g(o).center
922
+ }), { focused: this.describeElement(o) };
650
923
  }
651
- pointer(e) {
652
- const n = h(e), o = F(n.action, ["move", "down", "up", "click"]) ?? "click", r = tt(n.button) ?? 0, c = n.ref || n.selector || n.role || n.name || n.text || n.testId ? this.resolveElement(n) : null, s = c ? L(c).center : {
653
- x: M(n.x, "x"),
654
- y: M(n.y, "y")
655
- };
656
- if (!s)
924
+ async pointer(e) {
925
+ const n = m(e), o = Y(n.action, ["move", "down", "up", "click"]) ?? "click", i = dt(n.button) ?? 0, s = typeof n.x < "u" || typeof n.y < "u", r = x(n.targetText);
926
+ if (o === "click" && s && !r)
927
+ throw new Error(
928
+ "Pointer coordinate clicks require targetText to avoid unintended navigation."
929
+ );
930
+ const a = n.ref || n.selector || n.role || n.name || n.text || n.testId ? this.resolveElement(n) : null, c = a ? g(a).center : U(this.getRoot(), n);
931
+ if (!c)
657
932
  throw new Error("Target element has no clickable point.");
658
- const i = c ?? g(this.getRoot()).elementFromPoint(s.x, s.y);
659
- if (!i)
660
- throw new Error(`No element found at (${s.x}, ${s.y}).`);
661
- const a = {
933
+ const d = a ?? T(this.getRoot()).elementFromPoint(c.x, c.y);
934
+ if (!d)
935
+ throw new Error(`No element found at (${c.x}, ${c.y}).`);
936
+ const u = r ? Nt(d, r) : void 0;
937
+ if (r && !u)
938
+ throw new Error(
939
+ `Pointer target text mismatch: expected hit target to contain "${r}".`
940
+ );
941
+ const l = {
662
942
  bubbles: !0,
663
943
  cancelable: !0,
664
- clientX: s.x,
665
- clientY: s.y,
666
- button: r
944
+ clientX: c.x,
945
+ clientY: c.y,
946
+ button: i
667
947
  };
668
- return o === "move" ? (i.dispatchEvent(_("pointermove", a)), i.dispatchEvent(new MouseEvent("mousemove", a))) : o === "down" ? (i.dispatchEvent(_("pointerdown", a)), i.dispatchEvent(new MouseEvent("mousedown", a))) : o === "up" ? (i.dispatchEvent(_("pointerup", a)), i.dispatchEvent(new MouseEvent("mouseup", a))) : (i.dispatchEvent(_("pointerdown", a)), i.dispatchEvent(new MouseEvent("mousedown", a)), i.dispatchEvent(_("pointerup", a)), i.dispatchEvent(new MouseEvent("mouseup", a)), i instanceof HTMLElement ? i.click() : i.dispatchEvent(new MouseEvent("click", a))), {
948
+ return o === "move" ? (await this.showVisualEffect({
949
+ type: "pointer",
950
+ action: o,
951
+ anchor: "point",
952
+ point: c,
953
+ target: d
954
+ }), d.dispatchEvent(L("pointermove", l)), d.dispatchEvent(new MouseEvent("mousemove", l))) : o === "down" ? (await this.showVisualEffect({
955
+ type: "pointer",
956
+ action: o,
957
+ anchor: "point",
958
+ point: c,
959
+ target: d
960
+ }), d.dispatchEvent(L("pointerdown", l)), d.dispatchEvent(new MouseEvent("mousedown", l))) : o === "up" ? (await this.showVisualEffect({
961
+ type: "pointer",
962
+ action: o,
963
+ anchor: "point",
964
+ point: c,
965
+ target: d
966
+ }), d.dispatchEvent(L("pointerup", l)), d.dispatchEvent(new MouseEvent("mouseup", l))) : (await this.showVisualEffect({
967
+ type: "click",
968
+ anchor: "point",
969
+ point: c,
970
+ target: d
971
+ }), d.dispatchEvent(L("pointerdown", l)), d.dispatchEvent(new MouseEvent("mousedown", l)), d.dispatchEvent(L("pointerup", l)), d.dispatchEvent(new MouseEvent("mouseup", l)), d instanceof HTMLElement ? d.click() : d.dispatchEvent(new MouseEvent("click", l))), {
669
972
  pointer: o,
670
- point: s,
671
- target: this.describeElement(i)
973
+ point: c,
974
+ coordinateSpace: "viewport-css-px",
975
+ target: this.describeElement(d),
976
+ targetTextMatched: u,
977
+ expectedAfterClick: o === "click" ? Ht(
978
+ this.getRoot(),
979
+ Rt(n.expectedAfterClick)
980
+ ) : void 0
672
981
  };
673
982
  }
674
983
  screenshot() {
@@ -676,25 +985,48 @@ class pt {
676
985
  "host_page_screenshot requires the browser extension CDP adapter."
677
986
  );
678
987
  }
988
+ async showVisualEffect(e) {
989
+ var n, o, i, s;
990
+ try {
991
+ await ((o = (n = this.options).showVisualEffect) == null ? void 0 : o.call(n, e));
992
+ } catch {
993
+ }
994
+ if (!(e.type !== "click" || !e.point || !e.target || this.options.showVisualEffect))
995
+ try {
996
+ await ((s = (i = this.options).showClickEffect) == null ? void 0 : s.call(i, {
997
+ point: e.point,
998
+ target: e.target,
999
+ requested: e.requested
1000
+ }));
1001
+ } catch {
1002
+ }
1003
+ }
679
1004
  async waitFor(e) {
680
- const n = h(e), o = F(n.state, [
1005
+ const n = m(e), o = Y(n.state, [
681
1006
  "attached",
682
1007
  "visible",
683
1008
  "hidden",
684
1009
  "detached"
685
- ]) ?? "visible", r = T(n.timeoutSeconds), c = Math.min(
686
- Q,
687
- Math.max(0, (r ?? J / 1e3) * 1e3)
688
- ), s = Date.now();
689
- for (; Date.now() - s <= c; ) {
690
- const i = this.tryResolveElement(n);
691
- if (o === "attached" ? !!i : o === "detached" ? !i : o === "hidden" ? !i || !m(i) : !!(i && m(i)))
1010
+ ]) ?? "visible", i = k(n.timeoutSeconds), s = Math.min(
1011
+ ct,
1012
+ Math.max(0, (i ?? at / 1e3) * 1e3)
1013
+ ), r = Date.now(), a = this.tryResolveElement(n);
1014
+ for (await this.showVisualEffect({
1015
+ type: "wait_for",
1016
+ state: o,
1017
+ target: a ?? void 0,
1018
+ requested: a ?? void 0,
1019
+ ...a ? { anchor: "target" } : {},
1020
+ point: a ? g(a).center : void 0
1021
+ }); Date.now() - r <= s; ) {
1022
+ const c = this.tryResolveElement(n);
1023
+ if (o === "attached" ? !!c : o === "detached" ? !c : o === "hidden" ? !c || !_(c) : !!(c && _(c)))
692
1024
  return {
693
1025
  waitedFor: o,
694
- elapsedMs: Date.now() - s,
695
- target: i ? this.describeElement(i) : void 0
1026
+ elapsedMs: Date.now() - r,
1027
+ target: c ? this.describeElement(c) : void 0
696
1028
  };
697
- await new Promise((d) => setTimeout(d, 100));
1029
+ await new Promise((u) => setTimeout(u, 100));
698
1030
  }
699
1031
  throw new Error(`Timed out waiting for target to become ${o}.`);
700
1032
  }
@@ -708,54 +1040,268 @@ class pt {
708
1040
  describeElement(e) {
709
1041
  return {
710
1042
  tag: e.tagName.toLowerCase(),
711
- role: x(e),
712
- name: E(e),
713
- selector: P(e)
1043
+ role: S(e),
1044
+ name: v(e),
1045
+ selector: q(e)
714
1046
  };
715
1047
  }
716
1048
  }
717
- function Et(t) {
1049
+ function Dt(t) {
718
1050
  return typeof t == "object" && t !== null && !Array.isArray(t) ? t : {};
719
1051
  }
720
- function mt(t) {
1052
+ function Vt(t) {
721
1053
  return JSON.stringify(t);
722
1054
  }
723
- function O(t, e, n) {
1055
+ function D(t, e, n) {
724
1056
  return {
725
1057
  tool_call_id: t.tool_call_id ?? t.id,
726
1058
  name: t.name,
727
1059
  status: e,
728
- content: mt(n)
1060
+ content: Vt(n)
729
1061
  };
730
1062
  }
731
- function bt(t) {
1063
+ function qt(t) {
732
1064
  return t instanceof Error ? t.message : String(t);
733
1065
  }
734
- function wt(t = {}) {
735
- const e = new pt(t);
1066
+ function jt(t = {}) {
1067
+ const e = new It(t);
736
1068
  return async (n) => {
737
- if (!Z(n.name))
738
- return O(n, "error", {
1069
+ if (!lt(n.name))
1070
+ return D(n, "error", {
739
1071
  ok: !1,
740
1072
  error: `Unknown host page automation tool: ${n.name}`
741
1073
  });
742
1074
  try {
743
1075
  const o = await e.execute(
744
1076
  n.name,
745
- Et(n.params)
1077
+ Dt(n.params)
746
1078
  );
747
- return O(n, "success", { ok: !0, result: o });
1079
+ return D(n, "success", { ok: !0, result: o });
748
1080
  } catch (o) {
749
- return O(n, "error", {
1081
+ return D(n, "error", {
750
1082
  ok: !1,
751
- error: bt(o)
1083
+ error: qt(o)
752
1084
  });
753
1085
  }
754
1086
  };
755
1087
  }
1088
+ const w = {
1089
+ ref: {
1090
+ type: ["string", "number"],
1091
+ description: "Element ref from host_page_snapshot."
1092
+ },
1093
+ axRef: {
1094
+ type: ["string", "number"],
1095
+ description: "Accessibility ref from host_page_snapshot."
1096
+ },
1097
+ selector: {
1098
+ type: "string",
1099
+ description: "CSS selector for the target element."
1100
+ },
1101
+ testId: {
1102
+ type: "string",
1103
+ description: "data-testid, data-test-id, or data-qa value."
1104
+ },
1105
+ role: {
1106
+ type: "string",
1107
+ description: "Accessible role to match."
1108
+ },
1109
+ name: {
1110
+ type: "string",
1111
+ description: "Accessible name to match."
1112
+ },
1113
+ text: {
1114
+ type: "string",
1115
+ description: "Visible text to match."
1116
+ },
1117
+ x: {
1118
+ type: "number",
1119
+ description: "Viewport x coordinate."
1120
+ },
1121
+ y: {
1122
+ type: "number",
1123
+ description: "Viewport y coordinate."
1124
+ }
1125
+ }, Bt = {
1126
+ coordinateSpace: {
1127
+ type: "string",
1128
+ enum: ["viewport-css-px", "viewport_normalized"],
1129
+ description: "Coordinate space for x/y. Use viewport_normalized for screenshot-derived points."
1130
+ }
1131
+ }, Ft = {
1132
+ type: "object",
1133
+ properties: {
1134
+ type: {
1135
+ const: "field_contains",
1136
+ description: "Currently supported post-click expectation type."
1137
+ },
1138
+ field: {
1139
+ type: "string",
1140
+ description: "Field label/name expected to change after clicking."
1141
+ },
1142
+ value: {
1143
+ type: "string",
1144
+ description: "Expected substring in the field value after clicking."
1145
+ }
1146
+ },
1147
+ required: ["type", "field", "value"],
1148
+ additionalProperties: !1
1149
+ }, $t = {
1150
+ host_page_snapshot: {
1151
+ type: "object",
1152
+ properties: {},
1153
+ additionalProperties: !1
1154
+ },
1155
+ host_page_click: {
1156
+ type: "object",
1157
+ properties: {
1158
+ ...w
1159
+ },
1160
+ additionalProperties: !1
1161
+ },
1162
+ host_page_fill: {
1163
+ type: "object",
1164
+ properties: {
1165
+ ...w,
1166
+ value: {
1167
+ type: "string",
1168
+ description: "Text value to set on the target field."
1169
+ }
1170
+ },
1171
+ required: ["value"],
1172
+ additionalProperties: !1
1173
+ },
1174
+ host_page_press: {
1175
+ type: "object",
1176
+ properties: {
1177
+ ...w,
1178
+ key: {
1179
+ type: "string",
1180
+ description: "Keyboard key to press."
1181
+ }
1182
+ },
1183
+ required: ["key"],
1184
+ additionalProperties: !1
1185
+ },
1186
+ host_page_select: {
1187
+ type: "object",
1188
+ properties: {
1189
+ ...w,
1190
+ value: {
1191
+ type: ["string", "array"],
1192
+ description: "Select option value or values.",
1193
+ items: { type: "string" }
1194
+ },
1195
+ values: {
1196
+ type: ["string", "array"],
1197
+ description: "Select option values.",
1198
+ items: { type: "string" }
1199
+ }
1200
+ },
1201
+ additionalProperties: !1
1202
+ },
1203
+ host_page_scroll: {
1204
+ type: "object",
1205
+ properties: {
1206
+ ...w,
1207
+ deltaX: {
1208
+ type: "number",
1209
+ description: "Horizontal scroll delta."
1210
+ },
1211
+ deltaY: {
1212
+ type: "number",
1213
+ description: "Vertical scroll delta."
1214
+ }
1215
+ },
1216
+ additionalProperties: !1
1217
+ },
1218
+ host_page_navigate: {
1219
+ type: "object",
1220
+ properties: {
1221
+ url: {
1222
+ type: "string",
1223
+ description: "HTTP(S) URL to navigate to."
1224
+ }
1225
+ },
1226
+ required: ["url"],
1227
+ additionalProperties: !1
1228
+ },
1229
+ host_page_hover: {
1230
+ type: "object",
1231
+ properties: {
1232
+ ...w
1233
+ },
1234
+ additionalProperties: !1
1235
+ },
1236
+ host_page_focus: {
1237
+ type: "object",
1238
+ properties: {
1239
+ ...w
1240
+ },
1241
+ additionalProperties: !1
1242
+ },
1243
+ host_page_pointer: {
1244
+ type: "object",
1245
+ properties: {
1246
+ ...w,
1247
+ ...Bt,
1248
+ action: {
1249
+ type: "string",
1250
+ enum: ["move", "down", "up", "click"],
1251
+ description: "Pointer action. Defaults to click."
1252
+ },
1253
+ button: {
1254
+ type: ["string", "number"],
1255
+ description: "Mouse button."
1256
+ },
1257
+ clickCount: {
1258
+ type: "number",
1259
+ description: "Number of clicks for CDP mouse click."
1260
+ },
1261
+ targetText: {
1262
+ type: "string",
1263
+ description: "Required for explicit coordinate clicks. The actual hit target or near ancestor must contain this text."
1264
+ },
1265
+ expectedAfterClick: Ft
1266
+ },
1267
+ additionalProperties: !1
1268
+ },
1269
+ host_page_screenshot: {
1270
+ type: "object",
1271
+ properties: {
1272
+ format: {
1273
+ type: "string",
1274
+ enum: ["jpeg", "png"],
1275
+ description: "Screenshot image format."
1276
+ },
1277
+ quality: {
1278
+ type: "number",
1279
+ description: "JPEG quality from 1 to 100."
1280
+ }
1281
+ },
1282
+ additionalProperties: !1
1283
+ },
1284
+ host_page_wait_for: {
1285
+ type: "object",
1286
+ properties: {
1287
+ ...w,
1288
+ state: {
1289
+ type: "string",
1290
+ enum: ["attached", "visible", "hidden", "detached"],
1291
+ description: "Target state to wait for. Defaults to visible."
1292
+ },
1293
+ timeoutSeconds: {
1294
+ type: "number",
1295
+ description: "Maximum wait time in seconds."
1296
+ }
1297
+ },
1298
+ additionalProperties: !1
1299
+ }
1300
+ };
756
1301
  export {
757
- z as HOST_PAGE_AUTOMATION_TOOL_NAMES,
758
- pt as HostPageAutomationExecutor,
759
- wt as createHostPageAutomationClientToolHandler,
760
- Z as isHostPageAutomationToolName
1302
+ it as HOST_PAGE_AUTOMATION_TOOL_NAMES,
1303
+ $t as HOST_PAGE_AUTOMATION_TOOL_SCHEMAS,
1304
+ It as HostPageAutomationExecutor,
1305
+ jt as createHostPageAutomationClientToolHandler,
1306
+ lt as isHostPageAutomationToolName
761
1307
  };