@withgateway/sdk 0.6.0 → 0.9.1

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 (119) hide show
  1. package/dist/agents/index.d.mts +573 -0
  2. package/dist/agents/index.d.ts +573 -0
  3. package/dist/agents/index.js +1443 -0
  4. package/dist/agents/index.js.map +1 -0
  5. package/dist/agents/index.mjs +1394 -0
  6. package/dist/agents/index.mjs.map +1 -0
  7. package/dist/apiError-DHpfbmdx.d.mts +17 -0
  8. package/dist/apiError-DHpfbmdx.d.ts +17 -0
  9. package/dist/cli.js +5019 -1599
  10. package/dist/cli.js.map +1 -1
  11. package/dist/cli.mjs +5003 -1584
  12. package/dist/cli.mjs.map +1 -1
  13. package/dist/files/index.d.mts +3 -1
  14. package/dist/files/index.d.ts +3 -1
  15. package/dist/files/index.js +371 -102
  16. package/dist/files/index.js.map +1 -1
  17. package/dist/files/index.mjs +371 -102
  18. package/dist/files/index.mjs.map +1 -1
  19. package/dist/hooks/index.js +346 -136
  20. package/dist/hooks/index.js.map +1 -1
  21. package/dist/hooks/index.mjs +346 -136
  22. package/dist/hooks/index.mjs.map +1 -1
  23. package/dist/{index-LA-PMRJT.d.ts → index-DIN14Lhg.d.ts} +1 -1
  24. package/dist/{index-Di9nNqOY.d.mts → index-DuB-eQ0Z.d.mts} +1 -1
  25. package/dist/index.d.mts +7 -4
  26. package/dist/index.d.ts +7 -4
  27. package/dist/index.js +2689 -401
  28. package/dist/index.js.map +1 -1
  29. package/dist/index.mjs +2650 -394
  30. package/dist/index.mjs.map +1 -1
  31. package/dist/media-CQUC7TkS.d.mts +39 -0
  32. package/dist/media-DQnBloaX.d.ts +39 -0
  33. package/dist/traces/index.d.mts +3 -1
  34. package/dist/traces/index.d.ts +3 -1
  35. package/dist/traces/index.js +371 -102
  36. package/dist/traces/index.js.map +1 -1
  37. package/dist/traces/index.mjs +371 -102
  38. package/dist/traces/index.mjs.map +1 -1
  39. package/dist/tracing/index.d.mts +3 -2
  40. package/dist/tracing/index.d.ts +3 -2
  41. package/dist/tracing/index.js +257 -16
  42. package/dist/tracing/index.js.map +1 -1
  43. package/dist/tracing/index.mjs +257 -16
  44. package/dist/tracing/index.mjs.map +1 -1
  45. package/dist/transport-CpRe7zgd.d.mts +123 -0
  46. package/dist/transport-CpRe7zgd.d.ts +123 -0
  47. package/dist/worlds/index.d.mts +1983 -1745
  48. package/dist/worlds/index.d.ts +1983 -1745
  49. package/dist/worlds/index.js +1295 -226
  50. package/dist/worlds/index.js.map +1 -1
  51. package/dist/worlds/index.mjs +1290 -222
  52. package/dist/worlds/index.mjs.map +1 -1
  53. package/package.json +6 -1
  54. package/runtime/gatewaysdk/environment/bundle_manifest.py +243 -0
  55. package/runtime/gatewaysdk/environment/schema/__main__.py +2 -2
  56. package/runtime/gatewaysdk/environment/schema/_slack_fidelity.py +8 -23
  57. package/runtime/gatewaysdk/environment/schema/api.py +3 -4
  58. package/runtime/gatewaysdk/environment/schema/assertions.py +7 -1
  59. package/runtime/gatewaysdk/environment/schema/bundle_runtime.py +1 -0
  60. package/runtime/gatewaysdk/environment/schema/call_log.py +20 -0
  61. package/runtime/gatewaysdk/environment/schema/database/base.py +2 -2
  62. package/runtime/gatewaysdk/environment/schema/host.py +74 -11
  63. package/runtime/gatewaysdk/environment/schema/host_browser.py +48 -0
  64. package/runtime/gatewaysdk/environment/schema/host_control.py +33 -2
  65. package/runtime/gatewaysdk/environment/schema/host_handoff.py +4 -1
  66. package/runtime/gatewaysdk/environment/schema/host_requests.py +14 -0
  67. package/runtime/gatewaysdk/environment/schema/host_session.py +13 -2
  68. package/runtime/gatewaysdk/environment/schema/host_surfaces.py +6 -0
  69. package/runtime/gatewaysdk/environment/schema/host_versions.py +96 -19
  70. package/runtime/gatewaysdk/environment/schema/journal.py +7 -2
  71. package/runtime/gatewaysdk/environment/schema/local.py +32 -7
  72. package/runtime/gatewaysdk/environment/schema/page_checks.py +123 -0
  73. package/runtime/gatewaysdk/environment/schema/platform.py +23 -267
  74. package/runtime/gatewaysdk/environment/schema/platform_templates.py +332 -0
  75. package/runtime/gatewaysdk/environment/schema/request_ledger.py +4 -1
  76. package/runtime/gatewaysdk/environment/schema/run_parameters.py +25 -0
  77. package/runtime/gatewaysdk/environment/schema/runtime.py +43 -5
  78. package/runtime/gatewaysdk/environment/schema/scaffold.py +367 -217
  79. package/runtime/gatewaysdk/environment/schema/session_files.py +13 -2
  80. package/runtime/gatewaysdk/environment/schema/skills/benchmarks-getting-started/SKILL.md +1 -1
  81. package/runtime/gatewaysdk/environment/schema/skills/connector-schema-authoring/SKILL.md +1 -2
  82. package/runtime/gatewaysdk/environment/schema/skills/world-data-ingestion/SKILL.md +4 -2
  83. package/runtime/gatewaysdk/environment/schema/skills/worlds-getting-started/SKILL.md +7 -7
  84. package/runtime/gatewaysdk/environment/schema/skills/worlds-getting-started/references/cli-mcp-map.md +32 -2
  85. package/runtime/gatewaysdk/environment/schema/skills/worlds-getting-started/references/gotchas.md +6 -6
  86. package/runtime/gatewaysdk/environment/schema/skills/worlds-getting-started/references/journal-checks.md +17 -2
  87. package/runtime/gatewaysdk/environment/schema/skills/worlds-getting-started/references/new-world-sandbox.md +1 -1
  88. package/runtime/gatewaysdk/environment/schema/skills/worlds-getting-started/references/ui-map.md +3 -2
  89. package/runtime/gatewaysdk/environment/schema/slack.py +55 -10
  90. package/runtime/gatewaysdk/environment/schema/snapshot.py +28 -2
  91. package/runtime/gatewaysdk/environment/schema/tasks.py +25 -2
  92. package/runtime/gatewaysdk/environment/schema/template_record.py +131 -0
  93. package/runtime/gatewaysdk/environment/schema/tools_world.py +7 -5
  94. package/runtime/gatewaysdk/environment/schema/ui.py +54 -33
  95. package/runtime/gatewaysdk/environment/schema/ui_interactions.py +419 -0
  96. package/runtime/gatewaysdk/environment/schema/ui_recorder.js +895 -0
  97. package/runtime/gatewaysdk/environment/schema/ui_replay.py +366 -0
  98. package/runtime/gatewaysdk/environment/schema/ui_replay_record.LICENSE +25 -0
  99. package/runtime/gatewaysdk/environment/schema/ui_replay_record.js +109 -0
  100. package/runtime/gatewaysdk/environment/schema/validation.py +10 -1
  101. package/runtime/gatewaysdk/environment/schema/worker.py +5 -1
  102. package/runtime/gatewaysdk/environment/schema/workers.py +8 -1
  103. package/runtime/gatewaysdk/environment/schema/world_host.py +44 -15
  104. package/runtime/gatewaysdk/environment/secret_values.py +1 -1
  105. package/runtime/gatewaysdk/environment/world.py +34 -43
  106. package/runtime/gatewaysdk/environment/world_session_contract.py +7 -34
  107. package/skills/benchmarks-getting-started/SKILL.md +1 -1
  108. package/skills/connector-schema-authoring/SKILL.md +1 -2
  109. package/skills/connector-schema-authoring/connector-worlds.md +2 -2
  110. package/skills/connector-schema-authoring/world-schema.md +29 -23
  111. package/skills/world-data-ingestion/SKILL.md +4 -2
  112. package/skills/worlds-getting-started/SKILL.md +7 -7
  113. package/skills/worlds-getting-started/references/cli-mcp-map.md +32 -2
  114. package/skills/worlds-getting-started/references/gotchas.md +6 -6
  115. package/skills/worlds-getting-started/references/journal-checks.md +17 -2
  116. package/skills/worlds-getting-started/references/new-world-sandbox.md +1 -1
  117. package/skills/worlds-getting-started/references/ui-map.md +3 -2
  118. package/dist/media-BIApiPzS.d.mts +0 -102
  119. package/dist/media-BIApiPzS.d.ts +0 -102
@@ -0,0 +1,895 @@
1
+ (() => {
2
+ const NAME_CHARS = 120;
3
+ const TEXT_CHARS = 200;
4
+ const VALUE_CHARS = 512;
5
+ const SELECTOR_CHARS = 256;
6
+ const OPTION_CHARS = 60;
7
+ const MAX_OPTIONS = 50;
8
+ const MAX_FILES = 20;
9
+ const MAX_EVENTS = 32;
10
+ const MAX_REPORT_BYTES = 28 * 1024;
11
+ const MAX_REPLAY_EVENTS = 500;
12
+ const MAX_REPLAY_BYTES = 256 * 1024;
13
+ const KEEPALIVE_BYTES = 60 * 1024;
14
+ const NAMING_ATTRIBUTES = ["id", "name", "aria-label", "data-testid"];
15
+ const GONE = 410;
16
+ const CHECKOUT_MS = 120000;
17
+ const INTERACTION_TAG = "gateway.interaction";
18
+ const IDLE_MS = 1000;
19
+ const SCROLL_MS = 500;
20
+ const HOVER_MS = 800;
21
+ const FORWARDED_MS = 100;
22
+ const KEYS = new Set(["Enter", "Tab", "Escape"]);
23
+ const MOVES = new Set([
24
+ "ArrowUp",
25
+ "ArrowDown",
26
+ "ArrowLeft",
27
+ "ArrowRight",
28
+ "Home",
29
+ "End",
30
+ "PageUp",
31
+ "PageDown",
32
+ "Backspace",
33
+ "Delete",
34
+ ]);
35
+ const STABLE = [
36
+ "name",
37
+ "role",
38
+ "aria-label",
39
+ "data-testid",
40
+ "data-qa",
41
+ "data-cy",
42
+ ];
43
+ const STATES = {
44
+ expanded: "aria-expanded",
45
+ pressed: "aria-pressed",
46
+ selected: "aria-selected",
47
+ };
48
+ const BUTTON_TYPES = ["button", "submit", "reset"];
49
+ const SECRET_TYPES = new Set(["password", "hidden"]);
50
+ const SECRET_AUTOCOMPLETE =
51
+ /(^|\s)(current-password|new-password|one-time-code|cc-[a-z-]+)(\s|$)/;
52
+ const SECRET_WORDS = new Set([
53
+ "password",
54
+ "passwd",
55
+ "passcode",
56
+ "pwd",
57
+ "pass",
58
+ "secret",
59
+ "token",
60
+ "otp",
61
+ "totp",
62
+ "pin",
63
+ "cvc",
64
+ "cvv",
65
+ "cvn",
66
+ "ssn",
67
+ "iban",
68
+ "apikey",
69
+ "jwt",
70
+ "2fa",
71
+ "mfa",
72
+ ]);
73
+ const SECRET_PAIRS = new Set([
74
+ "api key",
75
+ "card number",
76
+ "card no",
77
+ "card num",
78
+ "cc number",
79
+ "credit card",
80
+ "security code",
81
+ "verification code",
82
+ "access key",
83
+ "private key",
84
+ "client secret",
85
+ "backup code",
86
+ "recovery code",
87
+ "authenticator code",
88
+ "auth code",
89
+ "account number",
90
+ "routing number",
91
+ "sort code",
92
+ ]);
93
+ const ACTIONABLE =
94
+ "button, a[href], input, select, textarea, summary, label, [role=button], [role=link], [role=menuitem], " +
95
+ "[role=menuitemcheckbox], [role=menuitemradio], [role=tab], [role=option], [role=checkbox], [role=radio], " +
96
+ "[role=switch], [role=row], [role=treeitem], [contenteditable=true]";
97
+ const HOVERABLE = `${ACTIONABLE}, [title], [aria-describedby]`;
98
+ const CONTAINERS =
99
+ "tr, [role=row], li, [role=listitem], [role=option], [role=menuitem], [role=gridcell], [role=treeitem], " +
100
+ "article, [role=article], fieldset, [role=group], dialog, [role=dialog], form, section";
101
+ const REGIONS =
102
+ "dialog, [role=dialog], [role=alertdialog], [role=tabpanel], [role=region], [role=menu], [role=listbox], " +
103
+ "form, section, nav, aside, main, header, footer";
104
+ const GROUPS =
105
+ "[role=radiogroup], [role=listbox], [role=menu], [role=menubar], [role=tablist], [role=group], [role=tree], [role=grid]";
106
+ const MEMBERS =
107
+ "[role=radio], [role=option], [role=menuitem], [role=menuitemradio], [role=menuitemcheckbox], [role=tab], [role=treeitem]";
108
+
109
+ const squeeze = (text, chars) =>
110
+ String(text ?? "")
111
+ .replace(/\s+/g, " ")
112
+ .trim()
113
+ .slice(0, chars);
114
+ const attr = (el, name) =>
115
+ el && el.getAttribute ? el.getAttribute(name) : null;
116
+ const tagOf = (el) => String(el.tagName || "").toLowerCase();
117
+ const typeOf = (el) => String(attr(el, "type") || "").toLowerCase();
118
+ const above = (el, selector) =>
119
+ el && el.parentElement && el.parentElement.closest
120
+ ? el.parentElement.closest(selector)
121
+ : null;
122
+ const checkable = (el) =>
123
+ tagOf(el) === "input" &&
124
+ (typeOf(el) === "checkbox" || typeOf(el) === "radio");
125
+ const editable = (el) =>
126
+ attr(el, "contenteditable") === "true" ||
127
+ tagOf(el) === "textarea" ||
128
+ (tagOf(el) === "input" &&
129
+ !checkable(el) &&
130
+ !BUTTON_TYPES.includes(typeOf(el)));
131
+
132
+ function textOf(el) {
133
+ return el ? (el.innerText ?? el.textContent ?? "") : "";
134
+ }
135
+
136
+ function labelOf(el, doc) {
137
+ const by = attr(el, "aria-labelledby");
138
+ if (doc && by)
139
+ return by
140
+ .split(/\s+/)
141
+ .map((ref) => textOf(doc.getElementById(ref)))
142
+ .join(" ");
143
+ const id = attr(el, "id");
144
+ const forId =
145
+ doc && id
146
+ ? Array.from(doc.querySelectorAll("label[for]")).find(
147
+ (label) => attr(label, "for") === id,
148
+ )
149
+ : null;
150
+ if (forId) return textOf(forId);
151
+ const wrapping =
152
+ el.closest && tagOf(el) !== "label" ? el.closest("label") : null;
153
+ return wrapping ? textOf(wrapping) : "";
154
+ }
155
+
156
+ function roleOf(el) {
157
+ const tag = tagOf(el);
158
+ if (
159
+ tag === "button" ||
160
+ (tag === "input" && BUTTON_TYPES.includes(typeOf(el)))
161
+ )
162
+ return "button";
163
+ if (
164
+ ["input", "select", "textarea"].includes(tag) ||
165
+ attr(el, "contenteditable") === "true"
166
+ )
167
+ return "field";
168
+ if (tag === "form") return "form";
169
+ return "other";
170
+ }
171
+
172
+ const NAMES = {
173
+ button: (el) => [
174
+ textOf(el),
175
+ attr(el, "aria-label"),
176
+ tagOf(el) === "input" ? el.value : "",
177
+ attr(el, "title"),
178
+ ],
179
+ field: (el, doc) => [
180
+ labelOf(el, doc),
181
+ attr(el, "aria-label"),
182
+ attr(el, "placeholder"),
183
+ attr(el, "title"),
184
+ ],
185
+ form: (el, doc) => [
186
+ attr(el, "aria-label"),
187
+ labelOf(el, doc),
188
+ attr(el, "name"),
189
+ attr(el, "title"),
190
+ ],
191
+ other: (el, doc) => [
192
+ attr(el, "aria-label"),
193
+ labelOf(el, doc),
194
+ textOf(el),
195
+ attr(el, "title"),
196
+ attr(el, "alt"),
197
+ ],
198
+ };
199
+
200
+ function nameOf(el, doc) {
201
+ return (
202
+ NAMES[roleOf(el)](el, doc)
203
+ .map((candidate) => squeeze(candidate, NAME_CHARS))
204
+ .find(Boolean) || ""
205
+ );
206
+ }
207
+
208
+ function quoted(value) {
209
+ return `"${String(value).replace(/["\\]/g, "\\$&")}"`;
210
+ }
211
+
212
+ function selectorOf(el) {
213
+ const tag = tagOf(el);
214
+ const id = attr(el, "id");
215
+ const parts = id ? [`[id=${quoted(id)}]`] : [];
216
+ for (const name of STABLE) {
217
+ const value = attr(el, name);
218
+ if (value) parts.push(`[${name}=${quoted(value)}]`);
219
+ }
220
+ if (tag === "input" && typeOf(el))
221
+ parts.push(`[type=${quoted(typeOf(el))}]`);
222
+ return parts.length ? (tag + parts.join("")).slice(0, SELECTOR_CHARS) : "";
223
+ }
224
+
225
+ function xpathOf(el) {
226
+ const steps = [];
227
+ for (
228
+ let node = el;
229
+ node && node.nodeType !== 9;
230
+ node = node.parentElement
231
+ ) {
232
+ const id = attr(node, "id");
233
+ if (id)
234
+ return [`//*[@id=${quoted(id)}]`, ...steps]
235
+ .join("/")
236
+ .slice(0, SELECTOR_CHARS);
237
+ const peers = Array.from(
238
+ (node.parentElement && node.parentElement.children) || [node],
239
+ ).filter((peer) => tagOf(peer) === tagOf(node));
240
+ steps.unshift(`${tagOf(node)}[${peers.indexOf(node) + 1}]`);
241
+ }
242
+ return `/${steps.join("/")}`.slice(0, SELECTOR_CHARS);
243
+ }
244
+
245
+ function hrefOf(href, origin) {
246
+ const base = origin || "http://page.invalid";
247
+ try {
248
+ const url = new URL(href, base);
249
+ if (!/^https?:$/.test(url.protocol)) return url.protocol + url.pathname;
250
+ return url.origin === base
251
+ ? url.pathname + url.search + url.hash
252
+ : url.origin + url.pathname;
253
+ } catch {
254
+ return "";
255
+ }
256
+ }
257
+
258
+ function regionName(region, doc) {
259
+ const heading = region.querySelector
260
+ ? region.querySelector("h1, h2, h3, h4, legend, [role=heading]")
261
+ : null;
262
+ return squeeze(
263
+ attr(region, "aria-label") || labelOf(region, doc) || textOf(heading),
264
+ NAME_CHARS,
265
+ );
266
+ }
267
+
268
+ function withinOf(el, doc) {
269
+ const region = above(el, REGIONS);
270
+ if (!region) return "";
271
+ const kind = attr(region, "role") || tagOf(region);
272
+ const name = regionName(region, doc);
273
+ return name ? `${kind}: ${name}` : kind;
274
+ }
275
+
276
+ function contextOf(el) {
277
+ const container = above(el, CONTAINERS);
278
+ if (container) return squeeze(textOf(container), TEXT_CHARS);
279
+ const around = squeeze(textOf(el.parentElement), TEXT_CHARS + 1);
280
+ return around.length <= TEXT_CHARS ? around : "";
281
+ }
282
+
283
+ function nativeGroup(el, doc) {
284
+ const fieldset = el.closest ? el.closest("fieldset") : null;
285
+ const legend =
286
+ fieldset && fieldset.querySelector
287
+ ? fieldset.querySelector("legend")
288
+ : null;
289
+ const name = attr(el, "name");
290
+ const named =
291
+ typeOf(el) === "radio" && name && doc
292
+ ? Array.from(doc.getElementsByName(name))
293
+ : [];
294
+ const boxes =
295
+ fieldset && fieldset.querySelectorAll
296
+ ? Array.from(fieldset.querySelectorAll(`input[type=${typeOf(el)}]`))
297
+ : [];
298
+ const members = named.length ? named : boxes;
299
+ return {
300
+ group: textOf(legend) || name || "",
301
+ options: members.map((member) => nameOf(member, doc)),
302
+ };
303
+ }
304
+
305
+ function roleGroup(el, doc) {
306
+ const container = above(el, GROUPS);
307
+ if (!container) return { group: "", options: [] };
308
+ const members = container.querySelectorAll
309
+ ? Array.from(container.querySelectorAll(MEMBERS))
310
+ : [];
311
+ return {
312
+ group: attr(container, "aria-label") || labelOf(container, doc),
313
+ options: members.map((member) => nameOf(member, doc)),
314
+ };
315
+ }
316
+
317
+ function groupOf(el, doc) {
318
+ if (tagOf(el) === "select")
319
+ return {
320
+ group: "",
321
+ options: Array.from(el.options || []).map((option) => option.text),
322
+ };
323
+ if (checkable(el)) return nativeGroup(el, doc);
324
+ if (el.matches && el.matches(MEMBERS)) return roleGroup(el, doc);
325
+ return { group: "", options: [] };
326
+ }
327
+
328
+ function describe(el, origin, doc) {
329
+ const target = { tag: tagOf(el) };
330
+ const put = (key, value, chars = NAME_CHARS) => {
331
+ const kept = squeeze(value, chars);
332
+ if (kept) target[key] = kept;
333
+ };
334
+ put("role", attr(el, "role"));
335
+ put("name", nameOf(el, doc));
336
+ const own = ["button", "other"].includes(roleOf(el))
337
+ ? squeeze(textOf(el), TEXT_CHARS)
338
+ : "";
339
+ if (own && own !== target.name) target.text = own;
340
+ put("id", attr(el, "id"));
341
+ put(
342
+ "testid",
343
+ attr(el, "data-testid") || attr(el, "data-qa") || attr(el, "data-cy"),
344
+ );
345
+ if (attr(el, "href")) put("href", hrefOf(attr(el, "href"), origin));
346
+ put("opens", attr(el, "target"));
347
+ put("type", attr(el, "type"));
348
+ put("field", attr(el, "name"));
349
+ put("autocomplete", attr(el, "autocomplete"));
350
+ for (const [key, name] of Object.entries(STATES)) put(key, attr(el, name));
351
+ if (el.disabled === true || attr(el, "aria-disabled") === "true")
352
+ target.disabled = "true";
353
+ if (checkable(el)) target.checked = String(Boolean(el.checked));
354
+ const { group, options } = groupOf(el, doc);
355
+ put("group", group);
356
+ const listed = options
357
+ .map((option) => squeeze(option, OPTION_CHARS))
358
+ .filter(Boolean)
359
+ .slice(0, MAX_OPTIONS);
360
+ if (listed.length) target.options = listed;
361
+ put("within", withinOf(el, doc));
362
+ if (!secret(el, doc)) put("context", contextOf(el), TEXT_CHARS);
363
+ const selector = selectorOf(el);
364
+ if (selector) target.selector = selector;
365
+ target.xpath = xpathOf(el);
366
+ return target;
367
+ }
368
+
369
+ function wordsOf(text) {
370
+ return String(text || "")
371
+ .replace(/([a-z0-9])([A-Z])/g, "$1 $2")
372
+ .toLowerCase()
373
+ .split(/[^a-z0-9]+/)
374
+ .filter(Boolean);
375
+ }
376
+
377
+ function credentialNamed(text) {
378
+ const words = wordsOf(text);
379
+ return words.some(
380
+ (word, i) =>
381
+ SECRET_WORDS.has(word) || SECRET_PAIRS.has(`${word} ${words[i + 1]}`),
382
+ );
383
+ }
384
+
385
+ function secretText(el) {
386
+ for (
387
+ let node = el;
388
+ node && node.nodeType === 1;
389
+ node = node.parentElement
390
+ ) {
391
+ const named = NAMING_ATTRIBUTES.some((name) =>
392
+ credentialNamed(node.getAttribute(name)),
393
+ );
394
+ if (named || node.isContentEditable) return true;
395
+ }
396
+ return false;
397
+ }
398
+
399
+ function maskedText(text, el) {
400
+ return secretText(el) ? text.replace(/\S/g, "*") : text;
401
+ }
402
+
403
+ function secret(el, doc) {
404
+ return (
405
+ SECRET_TYPES.has(typeOf(el)) ||
406
+ SECRET_AUTOCOMPLETE.test(
407
+ String(attr(el, "autocomplete") || "").toLowerCase(),
408
+ ) ||
409
+ [attr(el, "name"), attr(el, "id"), nameOf(el, doc)].some(credentialNamed)
410
+ );
411
+ }
412
+
413
+ function valueOf(el, doc) {
414
+ if (secret(el, doc)) return undefined;
415
+ if (checkable(el)) return String(Boolean(el.checked));
416
+ if (tagOf(el) === "select") {
417
+ const option = el.options ? el.options[el.selectedIndex] : null;
418
+ return squeeze(option ? option.text : el.value, VALUE_CHARS);
419
+ }
420
+ if (attr(el, "contenteditable") === "true" || el.isContentEditable)
421
+ return textOf(el).slice(0, VALUE_CHARS);
422
+ return typeof el.value === "string"
423
+ ? el.value.slice(0, VALUE_CHARS)
424
+ : undefined;
425
+ }
426
+
427
+ function filesOf(el) {
428
+ return Array.from(el.files || [])
429
+ .slice(0, MAX_FILES)
430
+ .map((file) => ({
431
+ name: squeeze(file.name, NAME_CHARS),
432
+ size: file.size,
433
+ type: squeeze(file.type, NAME_CHARS),
434
+ }));
435
+ }
436
+
437
+ function endpoint(src, name = "events") {
438
+ return new URL(name, src).href;
439
+ }
440
+
441
+ function keyOf(event) {
442
+ if (KEYS.has(event.key) || MOVES.has(event.key)) return event.key;
443
+ const shortcut =
444
+ (event.ctrlKey || event.metaKey) && /^[a-z0-9]$/i.test(event.key || "");
445
+ return shortcut ? `CmdOrCtrl+${event.key.toUpperCase()}` : "";
446
+ }
447
+
448
+ function byteLength(text) {
449
+ return new TextEncoder().encode(text).length;
450
+ }
451
+
452
+ function report(queue, limit = MAX_EVENTS, maxBytes = MAX_REPORT_BYTES) {
453
+ const events = [];
454
+ let bytes = 0;
455
+ while (queue.length && events.length < limit) {
456
+ const size = byteLength(JSON.stringify(queue[0])) + 1;
457
+ if (events.length && bytes + size > maxBytes) break;
458
+ events.push(queue.shift());
459
+ bytes += size;
460
+ }
461
+ return events;
462
+ }
463
+
464
+ function loadId(win) {
465
+ const bytes =
466
+ win.crypto && win.crypto.getRandomValues
467
+ ? win.crypto.getRandomValues(new Uint8Array(8))
468
+ : [];
469
+ return (
470
+ Array.from(bytes, (byte) => byte.toString(16).padStart(2, "0")).join(
471
+ "",
472
+ ) || String(Math.random()).slice(2, 18)
473
+ );
474
+ }
475
+
476
+ class Channel {
477
+ constructor(win, url, maxEvents, maxBytes, body, recording = false) {
478
+ this.win = win;
479
+ this.post = win.fetch.bind(win);
480
+ this.url = url;
481
+ this.maxBytes = maxBytes;
482
+ this.body = body;
483
+ this.recording = recording;
484
+ this.queue = [];
485
+ this.limit = maxEvents;
486
+ this.inflight = false;
487
+ this.backoff = 0;
488
+ this.pausedUntil = 0;
489
+ this.closed = false;
490
+ this.onClose = () => {};
491
+ }
492
+
493
+ push(item) {
494
+ if (this.closed) return;
495
+ this.queue.push(item);
496
+ this.pump();
497
+ }
498
+
499
+ close() {
500
+ this.closed = true;
501
+ this.queue = [];
502
+ this.onClose();
503
+ }
504
+
505
+ pump() {
506
+ const idle = !this.inflight && this.queue.length > 0;
507
+ if (!idle || Date.now() < this.pausedUntil) return;
508
+ this.inflight = true;
509
+ const items = report(this.queue, this.limit, this.maxBytes);
510
+ const body = JSON.stringify(this.body(items));
511
+ this.post(this.url, {
512
+ method: "POST",
513
+ body,
514
+ headers: { "content-type": "application/json" },
515
+ keepalive: !this.recording,
516
+ credentials: "same-origin",
517
+ }).then(
518
+ (answer) =>
519
+ this.settle(items, answer.status, answer.headers.get("retry-after")),
520
+ () => this.settle(items, 0, null),
521
+ );
522
+ }
523
+
524
+ settle(items, status, retryAfter) {
525
+ this.inflight = false;
526
+ if (this.recording && status === GONE) return this.close();
527
+ if (status >= 200 && status < 300) {
528
+ this.backoff = 0;
529
+ return this.pump();
530
+ }
531
+ if (status === 413 && items.length > 1) {
532
+ this.limit = Math.max(1, Math.floor(items.length / 2));
533
+ this.queue.unshift(...items);
534
+ return this.pump();
535
+ }
536
+ if (status === 0 || status === 429 || status >= 500)
537
+ return this.later(items, Number(retryAfter) || 0);
538
+ return this.pump();
539
+ }
540
+
541
+ later(items, retryAfter) {
542
+ this.queue.unshift(...items);
543
+ this.backoff = Math.min(Math.max(this.backoff * 2, 1000), 30000);
544
+ const wait = retryAfter > 0 ? retryAfter * 1000 : this.backoff;
545
+ this.pausedUntil = Date.now() + wait;
546
+ this.win.setTimeout(() => {
547
+ this.pausedUntil = 0;
548
+ this.pump();
549
+ }, wait);
550
+ }
551
+
552
+ beacon() {
553
+ const fits = Math.min(this.maxBytes, KEEPALIVE_BYTES);
554
+ while (this.queue.length) {
555
+ const body = JSON.stringify(
556
+ this.body(report(this.queue, this.limit, fits)),
557
+ );
558
+ if (byteLength(body) < KEEPALIVE_BYTES)
559
+ this.win.navigator.sendBeacon(
560
+ this.url,
561
+ new Blob([body], { type: "application/json" }),
562
+ );
563
+ }
564
+ }
565
+ }
566
+
567
+ function startReplay(rrweb, channel) {
568
+ if (!rrweb || typeof rrweb.record !== "function") return null;
569
+ let index = 0;
570
+ const stop = rrweb.record({
571
+ emit: (event) => channel.push({ index: index++, event }),
572
+ maskAllInputs: true,
573
+ maskTextSelector: "*",
574
+ maskTextFn: maskedText,
575
+ blockSelector: 'input[type="hidden"]',
576
+ slimDOMOptions: "all",
577
+ inlineStylesheet: true,
578
+ sampling: { mousemove: 50, scroll: 150, input: "last" },
579
+ checkoutEveryNms: CHECKOUT_MS,
580
+ });
581
+ channel.onClose = () => stop && stop();
582
+ return rrweb.record;
583
+ }
584
+
585
+ function install(doc, win) {
586
+ const mark = Symbol.for("gateway.world-ui.recorder");
587
+ if (win[mark]) return;
588
+ win[mark] = true;
589
+ const src = doc.currentScript
590
+ ? doc.currentScript.src
591
+ : `${win.location.origin}/__world-ui/recorder.js`;
592
+ const origin = win.location.origin;
593
+ const page = () =>
594
+ win.location.pathname + win.location.search + win.location.hash;
595
+ const reported = new WeakMap();
596
+ const load = loadId(win);
597
+ const interactions = new Channel(
598
+ win,
599
+ endpoint(src),
600
+ MAX_EVENTS,
601
+ MAX_REPORT_BYTES,
602
+ (events) => ({ events }),
603
+ );
604
+ const replays = new Channel(
605
+ win,
606
+ endpoint(src, "replay"),
607
+ MAX_REPLAY_EVENTS,
608
+ MAX_REPLAY_BYTES,
609
+ (items) => ({
610
+ load,
611
+ first: items[0].index,
612
+ events: items.map((item) => item.event),
613
+ }),
614
+ true,
615
+ );
616
+ let replaying = null;
617
+ let seq = 0;
618
+ let typing = null;
619
+ let forwarded = null;
620
+ let scrolling = null;
621
+ let hovering = null;
622
+ let dragged = null;
623
+ let last = page();
624
+
625
+ const record = (kind, el, extra) => {
626
+ seq += 1;
627
+ const subject =
628
+ el && el !== doc.body && el !== doc.documentElement ? el : null;
629
+ interactions.push({
630
+ kind,
631
+ page: page(),
632
+ target: subject ? describe(subject, origin, doc) : {},
633
+ ...extra,
634
+ load,
635
+ at: Date.now(),
636
+ seq,
637
+ });
638
+ if (replaying && !replays.closed)
639
+ replaying.addCustomEvent(INTERACTION_TAG, { seq });
640
+ };
641
+ const changed = (el) => {
642
+ const value = valueOf(el, doc);
643
+ if (value !== undefined && reported.get(el) === value) return;
644
+ if (value !== undefined) reported.set(el, value);
645
+ record("change", el, value === undefined ? {} : { value });
646
+ };
647
+ const flush = () => {
648
+ if (!typing) return;
649
+ const { el, timer } = typing;
650
+ typing = null;
651
+ win.clearTimeout(timer);
652
+ changed(el);
653
+ };
654
+ const targetOf = (event) => {
655
+ const path = event.composedPath ? event.composedPath() : [];
656
+ const node = path[0] || event.target;
657
+ if (node && node.nodeType === 1) return node;
658
+ return node && node.parentElement ? node.parentElement : null;
659
+ };
660
+ const actionable = (node) =>
661
+ (node && node.closest && node.closest(ACTIONABLE)) || node;
662
+ const pointOf = (event) => ({
663
+ x: Math.round(event.clientX || 0),
664
+ y: Math.round(event.clientY || 0),
665
+ });
666
+ const selectedText = (el) => {
667
+ if (
668
+ el &&
669
+ typeof el.value === "string" &&
670
+ typeof el.selectionStart === "number"
671
+ )
672
+ return el.value.slice(el.selectionStart, el.selectionEnd);
673
+ return win.getSelection ? String(win.getSelection()) : "";
674
+ };
675
+ const clipped = (el, text) =>
676
+ !text || (el && secret(el, doc))
677
+ ? {}
678
+ : { value: String(text).slice(0, VALUE_CHARS) };
679
+ const on = (type, handle, where = doc, trusted = true) =>
680
+ where.addEventListener(
681
+ type,
682
+ (event) => {
683
+ if (trusted && !event.isTrusted) return;
684
+ try {
685
+ handle(event);
686
+ } catch {}
687
+ },
688
+ true,
689
+ );
690
+ const moved = () => {
691
+ const now = page();
692
+ if (now === last) return;
693
+ last = now;
694
+ flush();
695
+ record("navigate", null, {});
696
+ };
697
+
698
+ on("click", (event) => {
699
+ const node = targetOf(event);
700
+ if (!node) return;
701
+ const el = actionable(node);
702
+ if (
703
+ forwarded &&
704
+ forwarded.control === el &&
705
+ Date.now() - forwarded.at < FORWARDED_MS
706
+ ) {
707
+ forwarded = null;
708
+ return;
709
+ }
710
+ if (tagOf(el) === "label" && el.control)
711
+ forwarded = { control: el.control, at: Date.now() };
712
+ flush();
713
+ record("click", el, { point: pointOf(event) });
714
+ });
715
+ on("dblclick", (event) => {
716
+ const el = actionable(targetOf(event));
717
+ if (el) record("dblclick", el, { point: pointOf(event) });
718
+ });
719
+ on("contextmenu", (event) => {
720
+ const el = actionable(targetOf(event));
721
+ if (el) record("contextmenu", el, { point: pointOf(event) });
722
+ });
723
+ on("pointerover", (event) => {
724
+ const node = targetOf(event);
725
+ const el = node && node.closest ? node.closest(HOVERABLE) : null;
726
+ if (!el || (hovering && hovering.el === el)) return;
727
+ if (hovering) win.clearTimeout(hovering.timer);
728
+ hovering = {
729
+ el,
730
+ timer: win.setTimeout(() => record("hover", el, {}), HOVER_MS),
731
+ };
732
+ });
733
+ on("pointerout", (event) => {
734
+ if (
735
+ !hovering ||
736
+ (event.relatedTarget &&
737
+ hovering.el.contains &&
738
+ hovering.el.contains(event.relatedTarget))
739
+ )
740
+ return;
741
+ win.clearTimeout(hovering.timer);
742
+ hovering = null;
743
+ });
744
+ on("pointerdown", () => {
745
+ if (hovering) win.clearTimeout(hovering.timer);
746
+ });
747
+ on(
748
+ "input",
749
+ (event) => {
750
+ const el = targetOf(event);
751
+ if (
752
+ !el ||
753
+ checkable(el) ||
754
+ tagOf(el) === "select" ||
755
+ typeOf(el) === "file"
756
+ )
757
+ return;
758
+ if (typing && typing.el !== el) flush();
759
+ if (typing) win.clearTimeout(typing.timer);
760
+ typing = { el, timer: win.setTimeout(flush, IDLE_MS) };
761
+ },
762
+ doc,
763
+ false,
764
+ );
765
+ on(
766
+ "change",
767
+ (event) => {
768
+ const el = targetOf(event);
769
+ if (el && typeOf(el) === "file")
770
+ return record("file", el, { files: filesOf(el) });
771
+ if (typing && typing.el === el) return flush();
772
+ if (el) changed(el);
773
+ },
774
+ doc,
775
+ false,
776
+ );
777
+ on("focusout", (event) => {
778
+ if (typing && typing.el === targetOf(event)) flush();
779
+ });
780
+ on(
781
+ "submit",
782
+ (event) => {
783
+ flush();
784
+ record("submit", event.submitter || targetOf(event), {});
785
+ },
786
+ doc,
787
+ false,
788
+ );
789
+ on("keydown", (event) => {
790
+ const key = keyOf(event);
791
+ const el = targetOf(event);
792
+ if (!key || (MOVES.has(key) && el && editable(el))) return;
793
+ if (key === "Enter" || key === "Tab") flush();
794
+ record("key", el, { value: key });
795
+ });
796
+ on("copy", (event) =>
797
+ record(
798
+ "copy",
799
+ targetOf(event),
800
+ clipped(targetOf(event), selectedText(targetOf(event))),
801
+ ),
802
+ );
803
+ on("cut", (event) =>
804
+ record(
805
+ "cut",
806
+ targetOf(event),
807
+ clipped(targetOf(event), selectedText(targetOf(event))),
808
+ ),
809
+ );
810
+ on("paste", (event) => {
811
+ const text = event.clipboardData
812
+ ? event.clipboardData.getData("text")
813
+ : "";
814
+ record("paste", targetOf(event), clipped(targetOf(event), text));
815
+ });
816
+ on("dragstart", (event) => {
817
+ dragged = actionable(targetOf(event));
818
+ if (dragged) record("drag", dragged, {});
819
+ });
820
+ on("drop", (event) => {
821
+ record(
822
+ "drop",
823
+ actionable(targetOf(event)),
824
+ dragged ? { source: describe(dragged, origin, doc) } : {},
825
+ );
826
+ dragged = null;
827
+ });
828
+ on("dragend", () => {
829
+ dragged = null;
830
+ });
831
+ on("scroll", (event) => {
832
+ const el =
833
+ event.target && event.target.nodeType === 1 ? event.target : null;
834
+ win.clearTimeout(scrolling);
835
+ scrolling = win.setTimeout(() => {
836
+ record("scroll", el, {
837
+ value: String(Math.round(el ? el.scrollTop : win.scrollY)),
838
+ });
839
+ }, SCROLL_MS);
840
+ });
841
+ on("visibilitychange", () =>
842
+ record("visibility", null, { value: doc.visibilityState }),
843
+ );
844
+ if (typeof win.open === "function") {
845
+ const opener = win.open;
846
+ win.open = function (address, ...rest) {
847
+ record("open", null, {
848
+ value: address ? hrefOf(String(address), origin) : "",
849
+ });
850
+ return opener.call(this, address, ...rest);
851
+ };
852
+ }
853
+ for (const name of ["pushState", "replaceState"]) {
854
+ const original = win.history[name];
855
+ win.history[name] = function (...args) {
856
+ const result = original.apply(this, args);
857
+ moved();
858
+ return result;
859
+ };
860
+ }
861
+ on("popstate", moved, win);
862
+ on("hashchange", moved, win);
863
+ on(
864
+ "pagehide",
865
+ () => {
866
+ flush();
867
+ interactions.beacon();
868
+ },
869
+ win,
870
+ );
871
+ const script = doc.createElement("script");
872
+ script.src = `${endpoint(src, "replay.js")}${new URL(src).search}`;
873
+ script.onload = () => {
874
+ replaying = startReplay(win.rrwebRecord, replays);
875
+ };
876
+ (doc.head || doc.documentElement).appendChild(script);
877
+ record("navigate", null, {});
878
+ }
879
+
880
+ if (typeof document === "undefined") {
881
+ globalThis.__gatewayUiRecorder = {
882
+ describe,
883
+ valueOf,
884
+ endpoint,
885
+ report,
886
+ filesOf,
887
+ credentialNamed,
888
+ install,
889
+ startReplay,
890
+ maskedText,
891
+ };
892
+ return;
893
+ }
894
+ install(document, window);
895
+ })();