@midscene/web 0.7.2 → 0.7.3-beta-20241104100519.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,1715 +1,1417 @@
1
- var __create = Object.create;
2
- var __defProp = Object.defineProperty;
3
- var __defProps = Object.defineProperties;
4
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
- var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
6
- var __getOwnPropNames = Object.getOwnPropertyNames;
7
- var __getOwnPropSymbols = Object.getOwnPropertySymbols;
8
- var __getProtoOf = Object.getPrototypeOf;
9
- var __hasOwnProp = Object.prototype.hasOwnProperty;
10
- var __propIsEnum = Object.prototype.propertyIsEnumerable;
11
- var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
12
- var __spreadValues = (a, b) => {
13
- for (var prop in b || (b = {}))
14
- if (__hasOwnProp.call(b, prop))
15
- __defNormalProp(a, prop, b[prop]);
16
- if (__getOwnPropSymbols)
17
- for (var prop of __getOwnPropSymbols(b)) {
18
- if (__propIsEnum.call(b, prop))
19
- __defNormalProp(a, prop, b[prop]);
20
- }
21
- return a;
22
- };
23
- var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
24
- var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require : typeof Proxy !== "undefined" ? new Proxy(x, {
25
- get: (a, b) => (typeof require !== "undefined" ? require : a)[b]
26
- }) : x)(function(x) {
27
- if (typeof require !== "undefined")
28
- return require.apply(this, arguments);
29
- throw Error('Dynamic require of "' + x + '" is not supported');
30
- });
31
- var __commonJS = (cb, mod) => function __require2() {
32
- return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
33
- };
34
- var __copyProps = (to, from, except, desc) => {
35
- if (from && typeof from === "object" || typeof from === "function") {
36
- for (let key of __getOwnPropNames(from))
37
- if (!__hasOwnProp.call(to, key) && key !== except)
38
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
39
- }
40
- return to;
41
- };
42
- var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
43
- // If the importer is in node compatibility mode or this is not an ESM
44
- // file that has been converted to a CommonJS file using a Babel-
45
- // compatible transform (i.e. "__esModule" has not been set), then set
46
- // "default" to the CommonJS "module.exports" for node compatibility.
47
- isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
48
- mod
49
- ));
50
-
51
- // ../../node_modules/.pnpm/dayjs@1.11.11/node_modules/dayjs/dayjs.min.js
52
- var require_dayjs_min = __commonJS({
53
- "../../node_modules/.pnpm/dayjs@1.11.11/node_modules/dayjs/dayjs.min.js"(exports, module) {
1
+ (function(global, factory) {
2
+ if (typeof module === "object" && typeof module.exports === "object") factory(exports, require("assert"), require("fs"), require("path"), require("@midscene/shared/constants"), require("@midscene/shared/fs"), require("@midscene/shared/img"), require("@midscene/shared/utils"), require("@midscene/core"), require("@midscene/core/utils"));
3
+ else if (typeof define === "function" && define.amd) define([
4
+ "exports",
5
+ "assert",
6
+ "fs",
7
+ "path",
8
+ "@midscene/shared/constants",
9
+ "@midscene/shared/fs",
10
+ "@midscene/shared/img",
11
+ "@midscene/shared/utils",
12
+ "@midscene/core",
13
+ "@midscene/core/utils"
14
+ ], factory);
15
+ else if (global = typeof globalThis !== "undefined" ? globalThis : global || self) factory(global.playground = {}, global.assert, global.fs, global.path, global.constants, global.fs, global.img, global.utils, global.core, global.utils);
16
+ })(this, function(exports, _assert, _fs, _path, _constants, _fs1, _img, _utils, _core, _utils1) {
54
17
  "use strict";
55
- !function(t, e) {
56
- "object" == typeof exports && "undefined" != typeof module ? module.exports = e() : "function" == typeof define && define.amd ? define(e) : (t = "undefined" != typeof globalThis ? globalThis : t || self).dayjs = e();
57
- }(exports, function() {
58
- "use strict";
59
- var t = 1e3, e = 6e4, n = 36e5, r = "millisecond", i = "second", s = "minute", u = "hour", a = "day", o = "week", c = "month", f = "quarter", h = "year", d = "date", l = "Invalid Date", $ = /^(\d{4})[-/]?(\d{1,2})?[-/]?(\d{0,2})[Tt\s]*(\d{1,2})?:?(\d{1,2})?:?(\d{1,2})?[.:]?(\d+)?$/, y = /\[([^\]]+)]|Y{1,4}|M{1,4}|D{1,2}|d{1,4}|H{1,2}|h{1,2}|a|A|m{1,2}|s{1,2}|Z{1,2}|SSS/g, M = { name: "en", weekdays: "Sunday_Monday_Tuesday_Wednesday_Thursday_Friday_Saturday".split("_"), months: "January_February_March_April_May_June_July_August_September_October_November_December".split("_"), ordinal: function(t2) {
60
- var e2 = ["th", "st", "nd", "rd"], n2 = t2 % 100;
61
- return "[" + t2 + (e2[(n2 - 20) % 10] || e2[n2] || e2[0]) + "]";
62
- } }, m = function(t2, e2, n2) {
63
- var r2 = String(t2);
64
- return !r2 || r2.length >= e2 ? t2 : "" + Array(e2 + 1 - r2.length).join(n2) + t2;
65
- }, v = { s: m, z: function(t2) {
66
- var e2 = -t2.utcOffset(), n2 = Math.abs(e2), r2 = Math.floor(n2 / 60), i2 = n2 % 60;
67
- return (e2 <= 0 ? "+" : "-") + m(r2, 2, "0") + ":" + m(i2, 2, "0");
68
- }, m: function t2(e2, n2) {
69
- if (e2.date() < n2.date())
70
- return -t2(n2, e2);
71
- var r2 = 12 * (n2.year() - e2.year()) + (n2.month() - e2.month()), i2 = e2.clone().add(r2, c), s2 = n2 - i2 < 0, u2 = e2.clone().add(r2 + (s2 ? -1 : 1), c);
72
- return +(-(r2 + (n2 - i2) / (s2 ? i2 - u2 : u2 - i2)) || 0);
73
- }, a: function(t2) {
74
- return t2 < 0 ? Math.ceil(t2) || 0 : Math.floor(t2);
75
- }, p: function(t2) {
76
- return { M: c, y: h, w: o, d: a, D: d, h: u, m: s, s: i, ms: r, Q: f }[t2] || String(t2 || "").toLowerCase().replace(/s$/, "");
77
- }, u: function(t2) {
78
- return void 0 === t2;
79
- } }, g = "en", D = {};
80
- D[g] = M;
81
- var p = "$isDayjsObject", S = function(t2) {
82
- return t2 instanceof _ || !(!t2 || !t2[p]);
83
- }, w = function t2(e2, n2, r2) {
84
- var i2;
85
- if (!e2)
86
- return g;
87
- if ("string" == typeof e2) {
88
- var s2 = e2.toLowerCase();
89
- D[s2] && (i2 = s2), n2 && (D[s2] = n2, i2 = s2);
90
- var u2 = e2.split("-");
91
- if (!i2 && u2.length > 1)
92
- return t2(u2[0]);
93
- } else {
94
- var a2 = e2.name;
95
- D[a2] = e2, i2 = a2;
96
- }
97
- return !r2 && i2 && (g = i2), i2 || !r2 && g;
98
- }, O = function(t2, e2) {
99
- if (S(t2))
100
- return t2.clone();
101
- var n2 = "object" == typeof e2 ? e2 : {};
102
- return n2.date = t2, n2.args = arguments, new _(n2);
103
- }, b = v;
104
- b.l = w, b.i = S, b.w = function(t2, e2) {
105
- return O(t2, { locale: e2.$L, utc: e2.$u, x: e2.$x, $offset: e2.$offset });
106
- };
107
- var _ = function() {
108
- function M2(t2) {
109
- this.$L = w(t2.locale, null, true), this.parse(t2), this.$x = this.$x || t2.x || {}, this[p] = true;
110
- }
111
- var m2 = M2.prototype;
112
- return m2.parse = function(t2) {
113
- this.$d = function(t3) {
114
- var e2 = t3.date, n2 = t3.utc;
115
- if (null === e2)
116
- return /* @__PURE__ */ new Date(NaN);
117
- if (b.u(e2))
118
- return /* @__PURE__ */ new Date();
119
- if (e2 instanceof Date)
120
- return new Date(e2);
121
- if ("string" == typeof e2 && !/Z$/i.test(e2)) {
122
- var r2 = e2.match($);
123
- if (r2) {
124
- var i2 = r2[2] - 1 || 0, s2 = (r2[7] || "0").substring(0, 3);
125
- return n2 ? new Date(Date.UTC(r2[1], i2, r2[3] || 1, r2[4] || 0, r2[5] || 0, r2[6] || 0, s2)) : new Date(r2[1], i2, r2[3] || 1, r2[4] || 0, r2[5] || 0, r2[6] || 0, s2);
126
- }
127
- }
128
- return new Date(e2);
129
- }(t2), this.init();
130
- }, m2.init = function() {
131
- var t2 = this.$d;
132
- this.$y = t2.getFullYear(), this.$M = t2.getMonth(), this.$D = t2.getDate(), this.$W = t2.getDay(), this.$H = t2.getHours(), this.$m = t2.getMinutes(), this.$s = t2.getSeconds(), this.$ms = t2.getMilliseconds();
133
- }, m2.$utils = function() {
134
- return b;
135
- }, m2.isValid = function() {
136
- return !(this.$d.toString() === l);
137
- }, m2.isSame = function(t2, e2) {
138
- var n2 = O(t2);
139
- return this.startOf(e2) <= n2 && n2 <= this.endOf(e2);
140
- }, m2.isAfter = function(t2, e2) {
141
- return O(t2) < this.startOf(e2);
142
- }, m2.isBefore = function(t2, e2) {
143
- return this.endOf(e2) < O(t2);
144
- }, m2.$g = function(t2, e2, n2) {
145
- return b.u(t2) ? this[e2] : this.set(n2, t2);
146
- }, m2.unix = function() {
147
- return Math.floor(this.valueOf() / 1e3);
148
- }, m2.valueOf = function() {
149
- return this.$d.getTime();
150
- }, m2.startOf = function(t2, e2) {
151
- var n2 = this, r2 = !!b.u(e2) || e2, f2 = b.p(t2), l2 = function(t3, e3) {
152
- var i2 = b.w(n2.$u ? Date.UTC(n2.$y, e3, t3) : new Date(n2.$y, e3, t3), n2);
153
- return r2 ? i2 : i2.endOf(a);
154
- }, $2 = function(t3, e3) {
155
- return b.w(n2.toDate()[t3].apply(n2.toDate("s"), (r2 ? [0, 0, 0, 0] : [23, 59, 59, 999]).slice(e3)), n2);
156
- }, y2 = this.$W, M3 = this.$M, m3 = this.$D, v2 = "set" + (this.$u ? "UTC" : "");
157
- switch (f2) {
158
- case h:
159
- return r2 ? l2(1, 0) : l2(31, 11);
160
- case c:
161
- return r2 ? l2(1, M3) : l2(0, M3 + 1);
162
- case o:
163
- var g2 = this.$locale().weekStart || 0, D2 = (y2 < g2 ? y2 + 7 : y2) - g2;
164
- return l2(r2 ? m3 - D2 : m3 + (6 - D2), M3);
165
- case a:
166
- case d:
167
- return $2(v2 + "Hours", 0);
168
- case u:
169
- return $2(v2 + "Minutes", 1);
170
- case s:
171
- return $2(v2 + "Seconds", 2);
172
- case i:
173
- return $2(v2 + "Milliseconds", 3);
174
- default:
175
- return this.clone();
176
- }
177
- }, m2.endOf = function(t2) {
178
- return this.startOf(t2, false);
179
- }, m2.$set = function(t2, e2) {
180
- var n2, o2 = b.p(t2), f2 = "set" + (this.$u ? "UTC" : ""), l2 = (n2 = {}, n2[a] = f2 + "Date", n2[d] = f2 + "Date", n2[c] = f2 + "Month", n2[h] = f2 + "FullYear", n2[u] = f2 + "Hours", n2[s] = f2 + "Minutes", n2[i] = f2 + "Seconds", n2[r] = f2 + "Milliseconds", n2)[o2], $2 = o2 === a ? this.$D + (e2 - this.$W) : e2;
181
- if (o2 === c || o2 === h) {
182
- var y2 = this.clone().set(d, 1);
183
- y2.$d[l2]($2), y2.init(), this.$d = y2.set(d, Math.min(this.$D, y2.daysInMonth())).$d;
184
- } else
185
- l2 && this.$d[l2]($2);
186
- return this.init(), this;
187
- }, m2.set = function(t2, e2) {
188
- return this.clone().$set(t2, e2);
189
- }, m2.get = function(t2) {
190
- return this[b.p(t2)]();
191
- }, m2.add = function(r2, f2) {
192
- var d2, l2 = this;
193
- r2 = Number(r2);
194
- var $2 = b.p(f2), y2 = function(t2) {
195
- var e2 = O(l2);
196
- return b.w(e2.date(e2.date() + Math.round(t2 * r2)), l2);
197
- };
198
- if ($2 === c)
199
- return this.set(c, this.$M + r2);
200
- if ($2 === h)
201
- return this.set(h, this.$y + r2);
202
- if ($2 === a)
203
- return y2(1);
204
- if ($2 === o)
205
- return y2(7);
206
- var M3 = (d2 = {}, d2[s] = e, d2[u] = n, d2[i] = t, d2)[$2] || 1, m3 = this.$d.getTime() + r2 * M3;
207
- return b.w(m3, this);
208
- }, m2.subtract = function(t2, e2) {
209
- return this.add(-1 * t2, e2);
210
- }, m2.format = function(t2) {
211
- var e2 = this, n2 = this.$locale();
212
- if (!this.isValid())
213
- return n2.invalidDate || l;
214
- var r2 = t2 || "YYYY-MM-DDTHH:mm:ssZ", i2 = b.z(this), s2 = this.$H, u2 = this.$m, a2 = this.$M, o2 = n2.weekdays, c2 = n2.months, f2 = n2.meridiem, h2 = function(t3, n3, i3, s3) {
215
- return t3 && (t3[n3] || t3(e2, r2)) || i3[n3].slice(0, s3);
216
- }, d2 = function(t3) {
217
- return b.s(s2 % 12 || 12, t3, "0");
218
- }, $2 = f2 || function(t3, e3, n3) {
219
- var r3 = t3 < 12 ? "AM" : "PM";
220
- return n3 ? r3.toLowerCase() : r3;
221
- };
222
- return r2.replace(y, function(t3, r3) {
223
- return r3 || function(t4) {
224
- switch (t4) {
225
- case "YY":
226
- return String(e2.$y).slice(-2);
227
- case "YYYY":
228
- return b.s(e2.$y, 4, "0");
229
- case "M":
230
- return a2 + 1;
231
- case "MM":
232
- return b.s(a2 + 1, 2, "0");
233
- case "MMM":
234
- return h2(n2.monthsShort, a2, c2, 3);
235
- case "MMMM":
236
- return h2(c2, a2);
237
- case "D":
238
- return e2.$D;
239
- case "DD":
240
- return b.s(e2.$D, 2, "0");
241
- case "d":
242
- return String(e2.$W);
243
- case "dd":
244
- return h2(n2.weekdaysMin, e2.$W, o2, 2);
245
- case "ddd":
246
- return h2(n2.weekdaysShort, e2.$W, o2, 3);
247
- case "dddd":
248
- return o2[e2.$W];
249
- case "H":
250
- return String(s2);
251
- case "HH":
252
- return b.s(s2, 2, "0");
253
- case "h":
254
- return d2(1);
255
- case "hh":
256
- return d2(2);
257
- case "a":
258
- return $2(s2, u2, true);
259
- case "A":
260
- return $2(s2, u2, false);
261
- case "m":
262
- return String(u2);
263
- case "mm":
264
- return b.s(u2, 2, "0");
265
- case "s":
266
- return String(e2.$s);
267
- case "ss":
268
- return b.s(e2.$s, 2, "0");
269
- case "SSS":
270
- return b.s(e2.$ms, 3, "0");
271
- case "Z":
272
- return i2;
273
- }
274
- return null;
275
- }(t3) || i2.replace(":", "");
276
- });
277
- }, m2.utcOffset = function() {
278
- return 15 * -Math.round(this.$d.getTimezoneOffset() / 15);
279
- }, m2.diff = function(r2, d2, l2) {
280
- var $2, y2 = this, M3 = b.p(d2), m3 = O(r2), v2 = (m3.utcOffset() - this.utcOffset()) * e, g2 = this - m3, D2 = function() {
281
- return b.m(y2, m3);
282
- };
283
- switch (M3) {
284
- case h:
285
- $2 = D2() / 12;
286
- break;
287
- case c:
288
- $2 = D2();
289
- break;
290
- case f:
291
- $2 = D2() / 3;
292
- break;
293
- case o:
294
- $2 = (g2 - v2) / 6048e5;
295
- break;
296
- case a:
297
- $2 = (g2 - v2) / 864e5;
298
- break;
299
- case u:
300
- $2 = g2 / n;
301
- break;
302
- case s:
303
- $2 = g2 / e;
304
- break;
305
- case i:
306
- $2 = g2 / t;
307
- break;
308
- default:
309
- $2 = g2;
310
- }
311
- return l2 ? $2 : b.a($2);
312
- }, m2.daysInMonth = function() {
313
- return this.endOf(c).$D;
314
- }, m2.$locale = function() {
315
- return D[this.$L];
316
- }, m2.locale = function(t2, e2) {
317
- if (!t2)
318
- return this.$L;
319
- var n2 = this.clone(), r2 = w(t2, e2, true);
320
- return r2 && (n2.$L = r2), n2;
321
- }, m2.clone = function() {
322
- return b.w(this.$d, this);
323
- }, m2.toDate = function() {
324
- return new Date(this.valueOf());
325
- }, m2.toJSON = function() {
326
- return this.isValid() ? this.toISOString() : null;
327
- }, m2.toISOString = function() {
328
- return this.$d.toISOString();
329
- }, m2.toString = function() {
330
- return this.$d.toUTCString();
331
- }, M2;
332
- }(), k = _.prototype;
333
- return O.prototype = k, [["$ms", r], ["$s", i], ["$m", s], ["$H", u], ["$W", a], ["$M", c], ["$y", h], ["$D", d]].forEach(function(t2) {
334
- k[t2[1]] = function(e2) {
335
- return this.$g(e2, t2[0], t2[1]);
336
- };
337
- }), O.extend = function(t2, e2) {
338
- return t2.$i || (t2(e2, _, O), t2.$i = true), O;
339
- }, O.locale = w, O.isDayjs = S, O.unix = function(t2) {
340
- return O(1e3 * t2);
341
- }, O.en = D[g], O.Ls = D, O.p = {}, O;
18
+ Object.defineProperty(exports, "__esModule", {
19
+ value: true
342
20
  });
343
- }
344
- });
345
-
346
- // ../../node_modules/.pnpm/dotenv@16.4.5/node_modules/dotenv/package.json
347
- var require_package = __commonJS({
348
- "../../node_modules/.pnpm/dotenv@16.4.5/node_modules/dotenv/package.json"(exports, module) {
349
- module.exports = {
350
- name: "dotenv",
351
- version: "16.4.5",
352
- description: "Loads environment variables from .env file",
353
- main: "lib/main.js",
354
- types: "lib/main.d.ts",
355
- exports: {
356
- ".": {
357
- types: "./lib/main.d.ts",
358
- require: "./lib/main.js",
359
- default: "./lib/main.js"
360
- },
361
- "./config": "./config.js",
362
- "./config.js": "./config.js",
363
- "./lib/env-options": "./lib/env-options.js",
364
- "./lib/env-options.js": "./lib/env-options.js",
365
- "./lib/cli-options": "./lib/cli-options.js",
366
- "./lib/cli-options.js": "./lib/cli-options.js",
367
- "./package.json": "./package.json"
368
- },
369
- scripts: {
370
- "dts-check": "tsc --project tests/types/tsconfig.json",
371
- lint: "standard",
372
- "lint-readme": "standard-markdown",
373
- pretest: "npm run lint && npm run dts-check",
374
- test: "tap tests/*.js --100 -Rspec",
375
- "test:coverage": "tap --coverage-report=lcov",
376
- prerelease: "npm test",
377
- release: "standard-version"
378
- },
379
- repository: {
380
- type: "git",
381
- url: "git://github.com/motdotla/dotenv.git"
382
- },
383
- funding: "https://dotenvx.com",
384
- keywords: [
385
- "dotenv",
386
- "env",
387
- ".env",
388
- "environment",
389
- "variables",
390
- "config",
391
- "settings"
392
- ],
393
- readmeFilename: "README.md",
394
- license: "BSD-2-Clause",
395
- devDependencies: {
396
- "@definitelytyped/dtslint": "^0.0.133",
397
- "@types/node": "^18.11.3",
398
- decache: "^4.6.1",
399
- sinon: "^14.0.1",
400
- standard: "^17.0.0",
401
- "standard-markdown": "^7.1.0",
402
- "standard-version": "^9.5.0",
403
- tap: "^16.3.0",
404
- tar: "^6.1.11",
405
- typescript: "^4.8.4"
406
- },
407
- engines: {
408
- node: ">=12"
409
- },
410
- browser: {
411
- fs: false
412
- }
413
- };
414
- }
415
- });
416
-
417
- // ../../node_modules/.pnpm/dotenv@16.4.5/node_modules/dotenv/lib/main.js
418
- var require_main = __commonJS({
419
- "../../node_modules/.pnpm/dotenv@16.4.5/node_modules/dotenv/lib/main.js"(exports, module) {
420
- "use strict";
421
- var fs = __require("fs");
422
- var path2 = __require("path");
423
- var os = __require("os");
424
- var crypto = __require("crypto");
425
- var packageJson = require_package();
426
- var version = packageJson.version;
427
- var LINE = /(?:^|^)\s*(?:export\s+)?([\w.-]+)(?:\s*=\s*?|:\s+?)(\s*'(?:\\'|[^'])*'|\s*"(?:\\"|[^"])*"|\s*`(?:\\`|[^`])*`|[^#\r\n]+)?\s*(?:#.*)?(?:$|$)/mg;
428
- function parse(src) {
429
- const obj = {};
430
- let lines = src.toString();
431
- lines = lines.replace(/\r\n?/mg, "\n");
432
- let match;
433
- while ((match = LINE.exec(lines)) != null) {
434
- const key = match[1];
435
- let value = match[2] || "";
436
- value = value.trim();
437
- const maybeQuote = value[0];
438
- value = value.replace(/^(['"`])([\s\S]*)\1$/mg, "$2");
439
- if (maybeQuote === '"') {
440
- value = value.replace(/\\n/g, "\n");
441
- value = value.replace(/\\r/g, "\r");
442
- }
443
- obj[key] = value;
444
- }
445
- return obj;
21
+ function _export(target, all) {
22
+ for(var name in all)Object.defineProperty(target, name, {
23
+ enumerable: true,
24
+ get: all[name]
25
+ });
446
26
  }
447
- function _parseVault(options) {
448
- const vaultPath = _vaultPath(options);
449
- const result = DotenvModule.configDotenv({ path: vaultPath });
450
- if (!result.parsed) {
451
- const err = new Error(`MISSING_DATA: Cannot parse ${vaultPath} for an unknown reason`);
452
- err.code = "MISSING_DATA";
453
- throw err;
454
- }
455
- const keys = _dotenvKey(options).split(",");
456
- const length = keys.length;
457
- let decrypted;
458
- for (let i = 0; i < length; i++) {
459
- try {
460
- const key = keys[i].trim();
461
- const attrs = _instructions(result, key);
462
- decrypted = DotenvModule.decrypt(attrs.ciphertext, attrs.key);
463
- break;
464
- } catch (error) {
465
- if (i + 1 >= length) {
466
- throw error;
467
- }
27
+ _export(exports, {
28
+ ERROR_CODE_NOT_IMPLEMENTED_AS_DESIGNED: function() {
29
+ return ERROR_CODE_NOT_IMPLEMENTED_AS_DESIGNED;
30
+ },
31
+ StaticPage: function() {
32
+ return StaticPage;
33
+ },
34
+ StaticPageAgent: function() {
35
+ return StaticPageAgent;
468
36
  }
469
- }
470
- return DotenvModule.parse(decrypted);
471
- }
472
- function _log(message) {
473
- console.log(`[dotenv@${version}][INFO] ${message}`);
474
- }
475
- function _warn(message) {
476
- console.log(`[dotenv@${version}][WARN] ${message}`);
477
- }
478
- function _debug(message) {
479
- console.log(`[dotenv@${version}][DEBUG] ${message}`);
37
+ });
38
+ _assert = /*#__PURE__*/ _interop_require_default(_assert);
39
+ _path = /*#__PURE__*/ _interop_require_wildcard(_path);
40
+ function _interop_require_default(obj) {
41
+ return obj && obj.__esModule ? obj : {
42
+ default: obj
43
+ };
480
44
  }
481
- function _dotenvKey(options) {
482
- if (options && options.DOTENV_KEY && options.DOTENV_KEY.length > 0) {
483
- return options.DOTENV_KEY;
484
- }
485
- if (process.env.DOTENV_KEY && process.env.DOTENV_KEY.length > 0) {
486
- return process.env.DOTENV_KEY;
487
- }
488
- return "";
45
+ function _getRequireWildcardCache(nodeInterop) {
46
+ if (typeof WeakMap !== "function") return null;
47
+ var cacheBabelInterop = new WeakMap();
48
+ var cacheNodeInterop = new WeakMap();
49
+ return (_getRequireWildcardCache = function(nodeInterop) {
50
+ return nodeInterop ? cacheNodeInterop : cacheBabelInterop;
51
+ })(nodeInterop);
489
52
  }
490
- function _instructions(result, dotenvKey) {
491
- let uri;
492
- try {
493
- uri = new URL(dotenvKey);
494
- } catch (error) {
495
- if (error.code === "ERR_INVALID_URL") {
496
- const err = new Error("INVALID_DOTENV_KEY: Wrong format. Must be in valid uri format like dotenv://:key_1234@dotenvx.com/vault/.env.vault?environment=development");
497
- err.code = "INVALID_DOTENV_KEY";
498
- throw err;
53
+ function _interop_require_wildcard(obj, nodeInterop) {
54
+ if (!nodeInterop && obj && obj.__esModule) {
55
+ return obj;
499
56
  }
500
- throw error;
501
- }
502
- const key = uri.password;
503
- if (!key) {
504
- const err = new Error("INVALID_DOTENV_KEY: Missing key part");
505
- err.code = "INVALID_DOTENV_KEY";
506
- throw err;
507
- }
508
- const environment = uri.searchParams.get("environment");
509
- if (!environment) {
510
- const err = new Error("INVALID_DOTENV_KEY: Missing environment part");
511
- err.code = "INVALID_DOTENV_KEY";
512
- throw err;
513
- }
514
- const environmentKey = `DOTENV_VAULT_${environment.toUpperCase()}`;
515
- const ciphertext = result.parsed[environmentKey];
516
- if (!ciphertext) {
517
- const err = new Error(`NOT_FOUND_DOTENV_ENVIRONMENT: Cannot locate environment ${environmentKey} in your .env.vault file.`);
518
- err.code = "NOT_FOUND_DOTENV_ENVIRONMENT";
519
- throw err;
520
- }
521
- return { ciphertext, key };
522
- }
523
- function _vaultPath(options) {
524
- let possibleVaultPath = null;
525
- if (options && options.path && options.path.length > 0) {
526
- if (Array.isArray(options.path)) {
527
- for (const filepath of options.path) {
528
- if (fs.existsSync(filepath)) {
529
- possibleVaultPath = filepath.endsWith(".vault") ? filepath : `${filepath}.vault`;
57
+ if (obj === null || typeof obj !== "object" && typeof obj !== "function") {
58
+ return {
59
+ default: obj
60
+ };
61
+ }
62
+ var cache = _getRequireWildcardCache(nodeInterop);
63
+ if (cache && cache.has(obj)) {
64
+ return cache.get(obj);
65
+ }
66
+ var newObj = {
67
+ __proto__: null
68
+ };
69
+ var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor;
70
+ for(var key in obj){
71
+ if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) {
72
+ var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null;
73
+ if (desc && (desc.get || desc.set)) {
74
+ Object.defineProperty(newObj, key, desc);
75
+ } else {
76
+ newObj[key] = obj[key];
77
+ }
530
78
  }
531
- }
532
- } else {
533
- possibleVaultPath = options.path.endsWith(".vault") ? options.path : `${options.path}.vault`;
534
79
  }
535
- } else {
536
- possibleVaultPath = path2.resolve(process.cwd(), ".env.vault");
537
- }
538
- if (fs.existsSync(possibleVaultPath)) {
539
- return possibleVaultPath;
540
- }
541
- return null;
542
- }
543
- function _resolveHome(envPath) {
544
- return envPath[0] === "~" ? path2.join(os.homedir(), envPath.slice(1)) : envPath;
545
- }
546
- function _configVault(options) {
547
- _log("Loading env from encrypted .env.vault");
548
- const parsed = DotenvModule._parseVault(options);
549
- let processEnv = process.env;
550
- if (options && options.processEnv != null) {
551
- processEnv = options.processEnv;
552
- }
553
- DotenvModule.populate(processEnv, parsed, options);
554
- return { parsed };
80
+ newObj.default = obj;
81
+ if (cache) {
82
+ cache.set(obj, newObj);
83
+ }
84
+ return newObj;
555
85
  }
556
- function configDotenv(options) {
557
- const dotenvPath = path2.resolve(process.cwd(), ".env");
558
- let encoding = "utf8";
559
- const debug = Boolean(options && options.debug);
560
- if (options && options.encoding) {
561
- encoding = options.encoding;
562
- } else {
563
- if (debug) {
564
- _debug("No encoding is specified. UTF-8 is used by default");
86
+ var __create = Object.create;
87
+ var __defProp = Object.defineProperty;
88
+ var __defProps = Object.defineProperties;
89
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
90
+ var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
91
+ var __getOwnPropNames = Object.getOwnPropertyNames;
92
+ var __getOwnPropSymbols = Object.getOwnPropertySymbols;
93
+ var __getProtoOf = Object.getPrototypeOf;
94
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
95
+ var __propIsEnum = Object.prototype.propertyIsEnumerable;
96
+ var __defNormalProp = (obj, key, value)=>key in obj ? __defProp(obj, key, {
97
+ enumerable: true,
98
+ configurable: true,
99
+ writable: true,
100
+ value
101
+ }) : obj[key] = value;
102
+ var __spreadValues = (a, b)=>{
103
+ for(var prop in b || (b = {}))if (__hasOwnProp.call(b, prop)) __defNormalProp(a, prop, b[prop]);
104
+ if (__getOwnPropSymbols) for (var prop of __getOwnPropSymbols(b)){
105
+ if (__propIsEnum.call(b, prop)) __defNormalProp(a, prop, b[prop]);
565
106
  }
566
- }
567
- let optionPaths = [dotenvPath];
568
- if (options && options.path) {
569
- if (!Array.isArray(options.path)) {
570
- optionPaths = [_resolveHome(options.path)];
571
- } else {
572
- optionPaths = [];
573
- for (const filepath of options.path) {
574
- optionPaths.push(_resolveHome(filepath));
575
- }
107
+ return a;
108
+ };
109
+ var __spreadProps = (a, b)=>__defProps(a, __getOwnPropDescs(b));
110
+ var __commonJS = (cb, mod)=>function __require() {
111
+ return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = {
112
+ exports: {}
113
+ }).exports, mod), mod.exports;
114
+ };
115
+ var __copyProps = (to, from, except, desc)=>{
116
+ if (from && typeof from === "object" || typeof from === "function") {
117
+ for (let key of __getOwnPropNames(from))if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
118
+ get: ()=>from[key],
119
+ enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
120
+ });
576
121
  }
577
- }
578
- let lastError;
579
- const parsedAll = {};
580
- for (const path3 of optionPaths) {
581
- try {
582
- const parsed = DotenvModule.parse(fs.readFileSync(path3, { encoding }));
583
- DotenvModule.populate(parsedAll, parsed, options);
584
- } catch (e) {
585
- if (debug) {
586
- _debug(`Failed to load ${path3} ${e.message}`);
587
- }
588
- lastError = e;
122
+ return to;
123
+ };
124
+ var __toESM = (mod, isNodeMode, target)=>(target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(// If the importer is in node compatibility mode or this is not an ESM
125
+ // file that has been converted to a CommonJS file using a Babel-
126
+ // compatible transform (i.e. "__esModule" has not been set), then set
127
+ // "default" to the CommonJS "module.exports" for node compatibility.
128
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
129
+ value: mod,
130
+ enumerable: true
131
+ }) : target, mod));
132
+ var __async = (__this, __arguments, generator)=>{
133
+ return new Promise((resolve, reject)=>{
134
+ var fulfilled = (value)=>{
135
+ try {
136
+ step(generator.next(value));
137
+ } catch (e) {
138
+ reject(e);
139
+ }
140
+ };
141
+ var rejected = (value)=>{
142
+ try {
143
+ step(generator.throw(value));
144
+ } catch (e) {
145
+ reject(e);
146
+ }
147
+ };
148
+ var step = (x)=>x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
149
+ step((generator = generator.apply(__this, __arguments)).next());
150
+ });
151
+ };
152
+ // ../../node_modules/.pnpm/dayjs@1.11.11/node_modules/dayjs/dayjs.min.js
153
+ var require_dayjs_min = __commonJS({
154
+ "../../node_modules/.pnpm/dayjs@1.11.11/node_modules/dayjs/dayjs.min.js" (exports, module1) {
155
+ "use strict";
156
+ !function(t, e) {
157
+ "object" == typeof exports && "undefined" != typeof module1 ? module1.exports = e() : "function" == typeof define && define.amd ? define(e) : (t = "undefined" != typeof globalThis ? globalThis : t || self).dayjs = e();
158
+ }(exports, function() {
159
+ "use strict";
160
+ var t = 1e3, e = 6e4, n = 36e5, r = "millisecond", i = "second", s = "minute", u = "hour", a = "day", o = "week", c = "month", f = "quarter", h = "year", d = "date", l = "Invalid Date", $ = /^(\d{4})[-/]?(\d{1,2})?[-/]?(\d{0,2})[Tt\s]*(\d{1,2})?:?(\d{1,2})?:?(\d{1,2})?[.:]?(\d+)?$/, y = /\[([^\]]+)]|Y{1,4}|M{1,4}|D{1,2}|d{1,4}|H{1,2}|h{1,2}|a|A|m{1,2}|s{1,2}|Z{1,2}|SSS/g, M = {
161
+ name: "en",
162
+ weekdays: "Sunday_Monday_Tuesday_Wednesday_Thursday_Friday_Saturday".split("_"),
163
+ months: "January_February_March_April_May_June_July_August_September_October_November_December".split("_"),
164
+ ordinal: function(t2) {
165
+ var e2 = [
166
+ "th",
167
+ "st",
168
+ "nd",
169
+ "rd"
170
+ ], n2 = t2 % 100;
171
+ return "[" + t2 + (e2[(n2 - 20) % 10] || e2[n2] || e2[0]) + "]";
172
+ }
173
+ }, m = function(t2, e2, n2) {
174
+ var r2 = String(t2);
175
+ return !r2 || r2.length >= e2 ? t2 : "" + Array(e2 + 1 - r2.length).join(n2) + t2;
176
+ }, v = {
177
+ s: m,
178
+ z: function(t2) {
179
+ var e2 = -t2.utcOffset(), n2 = Math.abs(e2), r2 = Math.floor(n2 / 60), i2 = n2 % 60;
180
+ return (e2 <= 0 ? "+" : "-") + m(r2, 2, "0") + ":" + m(i2, 2, "0");
181
+ },
182
+ m: function t2(e2, n2) {
183
+ if (e2.date() < n2.date()) return -t2(n2, e2);
184
+ var r2 = 12 * (n2.year() - e2.year()) + (n2.month() - e2.month()), i2 = e2.clone().add(r2, c), s2 = n2 - i2 < 0, u2 = e2.clone().add(r2 + (s2 ? -1 : 1), c);
185
+ return +(-(r2 + (n2 - i2) / (s2 ? i2 - u2 : u2 - i2)) || 0);
186
+ },
187
+ a: function(t2) {
188
+ return t2 < 0 ? Math.ceil(t2) || 0 : Math.floor(t2);
189
+ },
190
+ p: function(t2) {
191
+ return ({
192
+ M: c,
193
+ y: h,
194
+ w: o,
195
+ d: a,
196
+ D: d,
197
+ h: u,
198
+ m: s,
199
+ s: i,
200
+ ms: r,
201
+ Q: f
202
+ })[t2] || String(t2 || "").toLowerCase().replace(/s$/, "");
203
+ },
204
+ u: function(t2) {
205
+ return void 0 === t2;
206
+ }
207
+ }, g = "en", D = {};
208
+ D[g] = M;
209
+ var p = "$isDayjsObject", S = function(t2) {
210
+ return t2 instanceof _ || !(!t2 || !t2[p]);
211
+ }, w = function t2(e2, n2, r2) {
212
+ var i2;
213
+ if (!e2) return g;
214
+ if ("string" == typeof e2) {
215
+ var s2 = e2.toLowerCase();
216
+ D[s2] && (i2 = s2), n2 && (D[s2] = n2, i2 = s2);
217
+ var u2 = e2.split("-");
218
+ if (!i2 && u2.length > 1) return t2(u2[0]);
219
+ } else {
220
+ var a2 = e2.name;
221
+ D[a2] = e2, i2 = a2;
222
+ }
223
+ return !r2 && i2 && (g = i2), i2 || !r2 && g;
224
+ }, O = function(t2, e2) {
225
+ if (S(t2)) return t2.clone();
226
+ var n2 = "object" == typeof e2 ? e2 : {};
227
+ return n2.date = t2, n2.args = arguments, new _(n2);
228
+ }, b = v;
229
+ b.l = w, b.i = S, b.w = function(t2, e2) {
230
+ return O(t2, {
231
+ locale: e2.$L,
232
+ utc: e2.$u,
233
+ x: e2.$x,
234
+ $offset: e2.$offset
235
+ });
236
+ };
237
+ var _ = function() {
238
+ function M2(t2) {
239
+ this.$L = w(t2.locale, null, true), this.parse(t2), this.$x = this.$x || t2.x || {}, this[p] = true;
240
+ }
241
+ var m2 = M2.prototype;
242
+ return m2.parse = function(t2) {
243
+ this.$d = function(t3) {
244
+ var e2 = t3.date, n2 = t3.utc;
245
+ if (null === e2) return /* @__PURE__ */ new Date(NaN);
246
+ if (b.u(e2)) return /* @__PURE__ */ new Date();
247
+ if (e2 instanceof Date) return new Date(e2);
248
+ if ("string" == typeof e2 && !/Z$/i.test(e2)) {
249
+ var r2 = e2.match($);
250
+ if (r2) {
251
+ var i2 = r2[2] - 1 || 0, s2 = (r2[7] || "0").substring(0, 3);
252
+ return n2 ? new Date(Date.UTC(r2[1], i2, r2[3] || 1, r2[4] || 0, r2[5] || 0, r2[6] || 0, s2)) : new Date(r2[1], i2, r2[3] || 1, r2[4] || 0, r2[5] || 0, r2[6] || 0, s2);
253
+ }
254
+ }
255
+ return new Date(e2);
256
+ }(t2), this.init();
257
+ }, m2.init = function() {
258
+ var t2 = this.$d;
259
+ this.$y = t2.getFullYear(), this.$M = t2.getMonth(), this.$D = t2.getDate(), this.$W = t2.getDay(), this.$H = t2.getHours(), this.$m = t2.getMinutes(), this.$s = t2.getSeconds(), this.$ms = t2.getMilliseconds();
260
+ }, m2.$utils = function() {
261
+ return b;
262
+ }, m2.isValid = function() {
263
+ return !(this.$d.toString() === l);
264
+ }, m2.isSame = function(t2, e2) {
265
+ var n2 = O(t2);
266
+ return this.startOf(e2) <= n2 && n2 <= this.endOf(e2);
267
+ }, m2.isAfter = function(t2, e2) {
268
+ return O(t2) < this.startOf(e2);
269
+ }, m2.isBefore = function(t2, e2) {
270
+ return this.endOf(e2) < O(t2);
271
+ }, m2.$g = function(t2, e2, n2) {
272
+ return b.u(t2) ? this[e2] : this.set(n2, t2);
273
+ }, m2.unix = function() {
274
+ return Math.floor(this.valueOf() / 1e3);
275
+ }, m2.valueOf = function() {
276
+ return this.$d.getTime();
277
+ }, m2.startOf = function(t2, e2) {
278
+ var n2 = this, r2 = !!b.u(e2) || e2, f2 = b.p(t2), l2 = function(t3, e3) {
279
+ var i2 = b.w(n2.$u ? Date.UTC(n2.$y, e3, t3) : new Date(n2.$y, e3, t3), n2);
280
+ return r2 ? i2 : i2.endOf(a);
281
+ }, $2 = function(t3, e3) {
282
+ return b.w(n2.toDate()[t3].apply(n2.toDate("s"), (r2 ? [
283
+ 0,
284
+ 0,
285
+ 0,
286
+ 0
287
+ ] : [
288
+ 23,
289
+ 59,
290
+ 59,
291
+ 999
292
+ ]).slice(e3)), n2);
293
+ }, y2 = this.$W, M3 = this.$M, m3 = this.$D, v2 = "set" + (this.$u ? "UTC" : "");
294
+ switch(f2){
295
+ case h:
296
+ return r2 ? l2(1, 0) : l2(31, 11);
297
+ case c:
298
+ return r2 ? l2(1, M3) : l2(0, M3 + 1);
299
+ case o:
300
+ var g2 = this.$locale().weekStart || 0, D2 = (y2 < g2 ? y2 + 7 : y2) - g2;
301
+ return l2(r2 ? m3 - D2 : m3 + (6 - D2), M3);
302
+ case a:
303
+ case d:
304
+ return $2(v2 + "Hours", 0);
305
+ case u:
306
+ return $2(v2 + "Minutes", 1);
307
+ case s:
308
+ return $2(v2 + "Seconds", 2);
309
+ case i:
310
+ return $2(v2 + "Milliseconds", 3);
311
+ default:
312
+ return this.clone();
313
+ }
314
+ }, m2.endOf = function(t2) {
315
+ return this.startOf(t2, false);
316
+ }, m2.$set = function(t2, e2) {
317
+ var n2, o2 = b.p(t2), f2 = "set" + (this.$u ? "UTC" : ""), l2 = (n2 = {}, n2[a] = f2 + "Date", n2[d] = f2 + "Date", n2[c] = f2 + "Month", n2[h] = f2 + "FullYear", n2[u] = f2 + "Hours", n2[s] = f2 + "Minutes", n2[i] = f2 + "Seconds", n2[r] = f2 + "Milliseconds", n2)[o2], $2 = o2 === a ? this.$D + (e2 - this.$W) : e2;
318
+ if (o2 === c || o2 === h) {
319
+ var y2 = this.clone().set(d, 1);
320
+ y2.$d[l2]($2), y2.init(), this.$d = y2.set(d, Math.min(this.$D, y2.daysInMonth())).$d;
321
+ } else l2 && this.$d[l2]($2);
322
+ return this.init(), this;
323
+ }, m2.set = function(t2, e2) {
324
+ return this.clone().$set(t2, e2);
325
+ }, m2.get = function(t2) {
326
+ return this[b.p(t2)]();
327
+ }, m2.add = function(r2, f2) {
328
+ var d2, l2 = this;
329
+ r2 = Number(r2);
330
+ var $2 = b.p(f2), y2 = function(t2) {
331
+ var e2 = O(l2);
332
+ return b.w(e2.date(e2.date() + Math.round(t2 * r2)), l2);
333
+ };
334
+ if ($2 === c) return this.set(c, this.$M + r2);
335
+ if ($2 === h) return this.set(h, this.$y + r2);
336
+ if ($2 === a) return y2(1);
337
+ if ($2 === o) return y2(7);
338
+ var M3 = (d2 = {}, d2[s] = e, d2[u] = n, d2[i] = t, d2)[$2] || 1, m3 = this.$d.getTime() + r2 * M3;
339
+ return b.w(m3, this);
340
+ }, m2.subtract = function(t2, e2) {
341
+ return this.add(-1 * t2, e2);
342
+ }, m2.format = function(t2) {
343
+ var e2 = this, n2 = this.$locale();
344
+ if (!this.isValid()) return n2.invalidDate || l;
345
+ var r2 = t2 || "YYYY-MM-DDTHH:mm:ssZ", i2 = b.z(this), s2 = this.$H, u2 = this.$m, a2 = this.$M, o2 = n2.weekdays, c2 = n2.months, f2 = n2.meridiem, h2 = function(t3, n3, i3, s3) {
346
+ return t3 && (t3[n3] || t3(e2, r2)) || i3[n3].slice(0, s3);
347
+ }, d2 = function(t3) {
348
+ return b.s(s2 % 12 || 12, t3, "0");
349
+ }, $2 = f2 || function(t3, e3, n3) {
350
+ var r3 = t3 < 12 ? "AM" : "PM";
351
+ return n3 ? r3.toLowerCase() : r3;
352
+ };
353
+ return r2.replace(y, function(t3, r3) {
354
+ return r3 || function(t4) {
355
+ switch(t4){
356
+ case "YY":
357
+ return String(e2.$y).slice(-2);
358
+ case "YYYY":
359
+ return b.s(e2.$y, 4, "0");
360
+ case "M":
361
+ return a2 + 1;
362
+ case "MM":
363
+ return b.s(a2 + 1, 2, "0");
364
+ case "MMM":
365
+ return h2(n2.monthsShort, a2, c2, 3);
366
+ case "MMMM":
367
+ return h2(c2, a2);
368
+ case "D":
369
+ return e2.$D;
370
+ case "DD":
371
+ return b.s(e2.$D, 2, "0");
372
+ case "d":
373
+ return String(e2.$W);
374
+ case "dd":
375
+ return h2(n2.weekdaysMin, e2.$W, o2, 2);
376
+ case "ddd":
377
+ return h2(n2.weekdaysShort, e2.$W, o2, 3);
378
+ case "dddd":
379
+ return o2[e2.$W];
380
+ case "H":
381
+ return String(s2);
382
+ case "HH":
383
+ return b.s(s2, 2, "0");
384
+ case "h":
385
+ return d2(1);
386
+ case "hh":
387
+ return d2(2);
388
+ case "a":
389
+ return $2(s2, u2, true);
390
+ case "A":
391
+ return $2(s2, u2, false);
392
+ case "m":
393
+ return String(u2);
394
+ case "mm":
395
+ return b.s(u2, 2, "0");
396
+ case "s":
397
+ return String(e2.$s);
398
+ case "ss":
399
+ return b.s(e2.$s, 2, "0");
400
+ case "SSS":
401
+ return b.s(e2.$ms, 3, "0");
402
+ case "Z":
403
+ return i2;
404
+ }
405
+ return null;
406
+ }(t3) || i2.replace(":", "");
407
+ });
408
+ }, m2.utcOffset = function() {
409
+ return 15 * -Math.round(this.$d.getTimezoneOffset() / 15);
410
+ }, m2.diff = function(r2, d2, l2) {
411
+ var $2, y2 = this, M3 = b.p(d2), m3 = O(r2), v2 = (m3.utcOffset() - this.utcOffset()) * e, g2 = this - m3, D2 = function() {
412
+ return b.m(y2, m3);
413
+ };
414
+ switch(M3){
415
+ case h:
416
+ $2 = D2() / 12;
417
+ break;
418
+ case c:
419
+ $2 = D2();
420
+ break;
421
+ case f:
422
+ $2 = D2() / 3;
423
+ break;
424
+ case o:
425
+ $2 = (g2 - v2) / 6048e5;
426
+ break;
427
+ case a:
428
+ $2 = (g2 - v2) / 864e5;
429
+ break;
430
+ case u:
431
+ $2 = g2 / n;
432
+ break;
433
+ case s:
434
+ $2 = g2 / e;
435
+ break;
436
+ case i:
437
+ $2 = g2 / t;
438
+ break;
439
+ default:
440
+ $2 = g2;
441
+ }
442
+ return l2 ? $2 : b.a($2);
443
+ }, m2.daysInMonth = function() {
444
+ return this.endOf(c).$D;
445
+ }, m2.$locale = function() {
446
+ return D[this.$L];
447
+ }, m2.locale = function(t2, e2) {
448
+ if (!t2) return this.$L;
449
+ var n2 = this.clone(), r2 = w(t2, e2, true);
450
+ return r2 && (n2.$L = r2), n2;
451
+ }, m2.clone = function() {
452
+ return b.w(this.$d, this);
453
+ }, m2.toDate = function() {
454
+ return new Date(this.valueOf());
455
+ }, m2.toJSON = function() {
456
+ return this.isValid() ? this.toISOString() : null;
457
+ }, m2.toISOString = function() {
458
+ return this.$d.toISOString();
459
+ }, m2.toString = function() {
460
+ return this.$d.toUTCString();
461
+ }, M2;
462
+ }(), k = _.prototype;
463
+ return O.prototype = k, [
464
+ [
465
+ "$ms",
466
+ r
467
+ ],
468
+ [
469
+ "$s",
470
+ i
471
+ ],
472
+ [
473
+ "$m",
474
+ s
475
+ ],
476
+ [
477
+ "$H",
478
+ u
479
+ ],
480
+ [
481
+ "$W",
482
+ a
483
+ ],
484
+ [
485
+ "$M",
486
+ c
487
+ ],
488
+ [
489
+ "$y",
490
+ h
491
+ ],
492
+ [
493
+ "$D",
494
+ d
495
+ ]
496
+ ].forEach(function(t2) {
497
+ k[t2[1]] = function(e2) {
498
+ return this.$g(e2, t2[0], t2[1]);
499
+ };
500
+ }), O.extend = function(t2, e2) {
501
+ return t2.$i || (t2(e2, _, O), t2.$i = true), O;
502
+ }, O.locale = w, O.isDayjs = S, O.unix = function(t2) {
503
+ return O(1e3 * t2);
504
+ }, O.en = D[g], O.Ls = D, O.p = {}, O;
505
+ });
589
506
  }
590
- }
591
- let processEnv = process.env;
592
- if (options && options.processEnv != null) {
593
- processEnv = options.processEnv;
594
- }
595
- DotenvModule.populate(processEnv, parsedAll, options);
596
- if (lastError) {
597
- return { parsed: parsedAll, error: lastError };
598
- } else {
599
- return { parsed: parsedAll };
600
- }
601
- }
602
- function config(options) {
603
- if (_dotenvKey(options).length === 0) {
604
- return DotenvModule.configDotenv(options);
605
- }
606
- const vaultPath = _vaultPath(options);
607
- if (!vaultPath) {
608
- _warn(`You set DOTENV_KEY but you are missing a .env.vault file at ${vaultPath}. Did you forget to build it?`);
609
- return DotenvModule.configDotenv(options);
610
- }
611
- return DotenvModule._configVault(options);
612
- }
613
- function decrypt(encrypted, keyStr) {
614
- const key = Buffer.from(keyStr.slice(-64), "hex");
615
- let ciphertext = Buffer.from(encrypted, "base64");
616
- const nonce = ciphertext.subarray(0, 12);
617
- const authTag = ciphertext.subarray(-16);
618
- ciphertext = ciphertext.subarray(12, -16);
619
- try {
620
- const aesgcm = crypto.createDecipheriv("aes-256-gcm", key, nonce);
621
- aesgcm.setAuthTag(authTag);
622
- return `${aesgcm.update(ciphertext)}${aesgcm.final()}`;
623
- } catch (error) {
624
- const isRange = error instanceof RangeError;
625
- const invalidKeyLength = error.message === "Invalid key length";
626
- const decryptionFailed = error.message === "Unsupported state or unable to authenticate data";
627
- if (isRange || invalidKeyLength) {
628
- const err = new Error("INVALID_DOTENV_KEY: It must be 64 characters long (or more)");
629
- err.code = "INVALID_DOTENV_KEY";
630
- throw err;
631
- } else if (decryptionFailed) {
632
- const err = new Error("DECRYPTION_FAILED: Please check your DOTENV_KEY");
633
- err.code = "DECRYPTION_FAILED";
634
- throw err;
635
- } else {
636
- throw error;
507
+ });
508
+ // src/common/utils.ts
509
+ var import_dayjs = __toESM(require_dayjs_min());
510
+ // src/web-element.ts
511
+ var WebElementInfo = class {
512
+ constructor({ content, rect, page, locator, id, attributes, indexId }){
513
+ this.content = content;
514
+ this.rect = rect;
515
+ this.center = [
516
+ Math.floor(rect.left + rect.width / 2),
517
+ Math.floor(rect.top + rect.height / 2)
518
+ ];
519
+ this.page = page;
520
+ this.locator = locator;
521
+ this.id = id;
522
+ this.attributes = attributes;
523
+ this.indexId = indexId;
637
524
  }
638
- }
525
+ };
526
+ // src/common/utils.ts
527
+ function parseContextFromWebPage(page, _opt) {
528
+ return __async(this, null, function*() {
529
+ (0, _assert.default)(page, "page is required");
530
+ if (page._forceUsePageContext) {
531
+ return yield page._forceUsePageContext();
532
+ }
533
+ const url = yield page.url();
534
+ let screenshotBase64;
535
+ let elementsInfo;
536
+ yield Promise.all([
537
+ page.screenshotBase64().then((base64)=>{
538
+ screenshotBase64 = base64;
539
+ }),
540
+ page.getElementInfos().then((snapshot)=>__async(this, null, function*() {
541
+ elementsInfo = yield alignElements(snapshot, page);
542
+ }))
543
+ ]);
544
+ (0, _assert.default)(screenshotBase64, "screenshotBase64 is required");
545
+ const elementsPositionInfoWithoutText = elementsInfo.filter((elementInfo)=>{
546
+ if (elementInfo.attributes.nodeType === _constants.NodeType.TEXT) {
547
+ return false;
548
+ }
549
+ return true;
550
+ });
551
+ const size = yield page.size();
552
+ const width = size.width;
553
+ const height = size.height;
554
+ const screenshotBase64WithElementMarker = (_opt == null ? void 0 : _opt.ignoreMarker) ? void 0 : yield (0, _img.compositeElementInfoImg)({
555
+ inputImgBase64: screenshotBase64,
556
+ elementsPositionInfo: elementsPositionInfoWithoutText,
557
+ size: {
558
+ width,
559
+ height
560
+ }
561
+ });
562
+ return {
563
+ content: elementsInfo,
564
+ size: {
565
+ width,
566
+ height
567
+ },
568
+ screenshotBase64,
569
+ screenshotBase64WithElementMarker,
570
+ url
571
+ };
572
+ });
639
573
  }
640
- function populate(processEnv, parsed, options = {}) {
641
- const debug = Boolean(options && options.debug);
642
- const override = Boolean(options && options.override);
643
- if (typeof parsed !== "object") {
644
- const err = new Error("OBJECT_REQUIRED: Please check the processEnv argument being passed to populate");
645
- err.code = "OBJECT_REQUIRED";
646
- throw err;
647
- }
648
- for (const key of Object.keys(parsed)) {
649
- if (Object.prototype.hasOwnProperty.call(processEnv, key)) {
650
- if (override === true) {
651
- processEnv[key] = parsed[key];
652
- }
653
- if (debug) {
654
- if (override === true) {
655
- _debug(`"${key}" is already defined and WAS overwritten`);
656
- } else {
657
- _debug(`"${key}" is already defined and was NOT overwritten`);
574
+ var sizeThreshold = 3;
575
+ function alignElements(elements, page) {
576
+ return __async(this, null, function*() {
577
+ const validElements = elements.filter((item)=>{
578
+ return item.rect.height >= sizeThreshold && item.rect.width >= sizeThreshold;
579
+ });
580
+ const textsAligned = [];
581
+ for (const item of validElements){
582
+ const { rect, id, content, attributes, locator, indexId } = item;
583
+ textsAligned.push(new WebElementInfo({
584
+ rect,
585
+ locator,
586
+ id,
587
+ content,
588
+ attributes,
589
+ page,
590
+ indexId
591
+ }));
658
592
  }
659
- }
660
- } else {
661
- processEnv[key] = parsed[key];
662
- }
663
- }
593
+ return textsAligned;
594
+ });
664
595
  }
665
- var DotenvModule = {
666
- configDotenv,
667
- _configVault,
668
- _parseVault,
669
- config,
670
- decrypt,
671
- parse,
672
- populate
673
- };
674
- module.exports.configDotenv = DotenvModule.configDotenv;
675
- module.exports._configVault = DotenvModule._configVault;
676
- module.exports._parseVault = DotenvModule._parseVault;
677
- module.exports.config = DotenvModule.config;
678
- module.exports.decrypt = DotenvModule.decrypt;
679
- module.exports.parse = DotenvModule.parse;
680
- module.exports.populate = DotenvModule.populate;
681
- module.exports = DotenvModule;
682
- }
683
- });
684
-
685
- // src/common/agent.ts
686
- import {
687
- groupedActionDumpFileExt,
688
- stringifyDumpData as stringifyDumpData2,
689
- writeLogFile as writeLogFile2
690
- } from "@midscene/core/utils";
691
-
692
- // src/common/tasks.ts
693
- import assert2 from "assert";
694
- import {
695
- Executor,
696
- Insight,
697
- plan
698
- } from "@midscene/core";
699
- import { sleep } from "@midscene/core/utils";
700
- import { base64Encoded as base64Encoded2 } from "@midscene/shared/img";
701
-
702
- // src/common/task-cache.ts
703
- import { existsSync, readFileSync as readFileSync2 } from "fs";
704
- import { join } from "path";
705
- import {
706
- getLogDirByType,
707
- stringifyDumpData,
708
- writeLogFile
709
- } from "@midscene/core/utils";
710
- import { getMidscenePkgInfo } from "@midscene/shared/fs";
711
-
712
- // src/common/utils.ts
713
- var import_dayjs = __toESM(require_dayjs_min());
714
- import assert from "assert";
715
- import { randomUUID } from "crypto";
716
- import { readFileSync } from "fs";
717
- import path from "path";
718
- import { NodeType } from "@midscene/shared/constants";
719
- import { findNearestPackageJson } from "@midscene/shared/fs";
720
- import {
721
- base64Encoded,
722
- imageInfoOfBase64
723
- } from "@midscene/shared/img";
724
- import { compositeElementInfoImg } from "@midscene/shared/img";
725
-
726
- // src/web-element.ts
727
- var WebElementInfo = class {
728
- constructor({
729
- content,
730
- rect,
731
- page,
732
- locator,
733
- id,
734
- attributes,
735
- indexId
736
- }) {
737
- this.content = content;
738
- this.rect = rect;
739
- this.center = [
740
- Math.floor(rect.left + rect.width / 2),
741
- Math.floor(rect.top + rect.height / 2)
742
- ];
743
- this.page = page;
744
- this.locator = locator;
745
- this.id = id;
746
- this.attributes = attributes;
747
- this.indexId = indexId;
748
- }
749
- };
750
-
751
- // src/common/utils.ts
752
- async function parseContextFromWebPage(page, _opt) {
753
- assert(page, "page is required");
754
- if (page._forceUsePageContext) {
755
- return await page._forceUsePageContext();
756
- }
757
- const url = page.url();
758
- const file = await page.screenshot();
759
- const screenshotBase64 = base64Encoded(file);
760
- const captureElementSnapshot = await page.getElementInfos();
761
- const elementsInfo = await alignElements(captureElementSnapshot, page);
762
- const elementsPositionInfoWithoutText = elementsInfo.filter((elementInfo) => {
763
- if (elementInfo.attributes.nodeType === NodeType.TEXT) {
764
- return false;
596
+ function reportFileName(tag = "web") {
597
+ const dateTimeInFileName = (0, import_dayjs.default)().format("YYYY-MM-DD_HH-mm-ss-SSS");
598
+ return `${tag}-${dateTimeInFileName}`;
599
+ }
600
+ function printReportMsg(filepath) {
601
+ console.log("Midscene - report file updated:", filepath);
765
602
  }
766
- return true;
767
- });
768
- const size = await imageInfoOfBase64(screenshotBase64);
769
- const screenshotBase64WithElementMarker = await compositeElementInfoImg({
770
- inputImgBase64: screenshotBase64.split(";base64,").pop(),
771
- elementsPositionInfo: elementsPositionInfoWithoutText
772
- });
773
- return {
774
- content: elementsInfo,
775
- size,
776
- screenshotBase64,
777
- screenshotBase64WithElementMarker: `data:image/png;base64,${screenshotBase64WithElementMarker}`,
778
- url
779
- };
780
- }
781
- var sizeThreshold = 3;
782
- async function alignElements(elements, page) {
783
- const validElements = elements.filter((item) => {
784
- return item.rect.height >= sizeThreshold && item.rect.width >= sizeThreshold;
785
- });
786
- const textsAligned = [];
787
- for (const item of validElements) {
788
- const { rect, id, content, attributes, locator, indexId } = item;
789
- textsAligned.push(
790
- new WebElementInfo({
791
- rect,
792
- locator,
793
- id,
794
- content,
795
- attributes,
796
- page,
797
- indexId
798
- })
799
- );
800
- }
801
- return textsAligned;
802
- }
803
- function reportFileName(tag = "web") {
804
- const dateTimeInFileName = (0, import_dayjs.default)().format("YYYY-MM-DD_HH-mm-ss-SSS");
805
- return `${tag}-${dateTimeInFileName}`;
806
- }
807
- function printReportMsg(filepath) {
808
- console.log("Midscene - report file updated:", filepath);
809
- }
810
- function getCurrentExecutionFile(trace) {
811
- const error = new Error();
812
- const stackTrace = trace || error.stack;
813
- const pkgDir = process.cwd() || "";
814
- if (stackTrace) {
815
- const stackLines = stackTrace.split("\n");
816
- for (const line of stackLines) {
817
- if (line.includes(".spec.") || line.includes(".test.") || line.includes(".ts") || line.includes(".js")) {
818
- const match = line.match(/(?:at\s+)?(.*?\.(?:spec|test)\.[jt]s)/);
819
- if (match == null ? void 0 : match[1]) {
820
- const targetFileName = match[1].replace(pkgDir, "").trim().replace("at ", "");
821
- return targetFileName;
603
+ function getCurrentExecutionFile(trace) {
604
+ const error = new Error();
605
+ const stackTrace = trace || error.stack;
606
+ const pkgDir = process.cwd() || "";
607
+ if (stackTrace) {
608
+ const stackLines = stackTrace.split("\n");
609
+ for (const line of stackLines){
610
+ if (line.includes(".spec.") || line.includes(".test.") || line.includes(".ts") || line.includes(".js")) {
611
+ const match = line.match(/(?:at\s+)?(.*?\.(?:spec|test)\.[jt]s)/);
612
+ if (match == null ? void 0 : match[1]) {
613
+ const targetFileName = match[1].replace(pkgDir, "").trim().replace("at ", "");
614
+ return targetFileName;
615
+ }
616
+ }
617
+ }
822
618
  }
823
- }
619
+ return false;
824
620
  }
825
- }
826
- return false;
827
- }
828
- var testFileIndex = /* @__PURE__ */ new Map();
829
- function generateCacheId(fileName) {
830
- let taskFile = fileName || getCurrentExecutionFile();
831
- if (!taskFile) {
832
- taskFile = randomUUID();
833
- console.warn(
834
- "Midscene - using random UUID for cache id. Cache may be invalid."
835
- );
836
- }
837
- if (testFileIndex.has(taskFile)) {
838
- const currentIndex = testFileIndex.get(taskFile);
839
- if (currentIndex !== void 0) {
840
- testFileIndex.set(taskFile, currentIndex + 1);
621
+ var testFileIndex = /* @__PURE__ */ new Map();
622
+ function generateCacheId(fileName) {
623
+ let taskFile = fileName || getCurrentExecutionFile();
624
+ if (!taskFile) {
625
+ taskFile = (0, _utils.uuid)();
626
+ console.warn("Midscene - using random UUID for cache id. Cache may be invalid.");
627
+ }
628
+ if (testFileIndex.has(taskFile)) {
629
+ const currentIndex = testFileIndex.get(taskFile);
630
+ if (currentIndex !== void 0) {
631
+ testFileIndex.set(taskFile, currentIndex + 1);
632
+ }
633
+ } else {
634
+ testFileIndex.set(taskFile, 1);
635
+ }
636
+ return `${taskFile}-${testFileIndex.get(taskFile)}`;
841
637
  }
842
- } else {
843
- testFileIndex.set(taskFile, 1);
844
- }
845
- return `${taskFile}-${testFileIndex.get(taskFile)}`;
846
- }
847
- var ERROR_CODE_NOT_IMPLEMENTED_AS_DESIGNED = "NOT_IMPLEMENTED_AS_DESIGNED";
848
-
849
- // src/common/task-cache.ts
850
- var TaskCache = class {
851
- constructor(opts) {
852
- this.midscenePkgInfo = getMidscenePkgInfo(__dirname);
853
- this.cacheId = generateCacheId(opts == null ? void 0 : opts.fileName);
854
- this.cache = this.readCacheFromFile() || {
855
- aiTasks: []
856
- };
857
- this.newCache = {
858
- aiTasks: []
859
- };
860
- }
861
- getCacheGroupByPrompt(aiActionPrompt) {
862
- const { aiTasks = [] } = this.cache || { aiTasks: [] };
863
- const index = aiTasks.findIndex((item) => item.prompt === aiActionPrompt);
864
- const newCacheGroup = [];
865
- this.newCache.aiTasks.push({
866
- prompt: aiActionPrompt,
867
- tasks: newCacheGroup
868
- });
869
- return {
870
- readCache: (pageContext, type, actionPrompt) => {
871
- if (index === -1) {
872
- return false;
638
+ var ERROR_CODE_NOT_IMPLEMENTED_AS_DESIGNED = "NOT_IMPLEMENTED_AS_DESIGNED";
639
+ var TaskCache = class {
640
+ getCacheGroupByPrompt(aiActionPrompt) {
641
+ const { aiTasks = [] } = this.cache || {
642
+ aiTasks: []
643
+ };
644
+ const index = aiTasks.findIndex((item)=>item.prompt === aiActionPrompt);
645
+ const newCacheGroup = [];
646
+ this.newCache.aiTasks.push({
647
+ prompt: aiActionPrompt,
648
+ tasks: newCacheGroup
649
+ });
650
+ return {
651
+ readCache: (pageContext, type, actionPrompt)=>{
652
+ if (index === -1) {
653
+ return false;
654
+ }
655
+ if (type === "plan") {
656
+ return this.readCache(pageContext, type, actionPrompt, aiTasks[index].tasks);
657
+ }
658
+ return this.readCache(pageContext, type, actionPrompt, aiTasks[index].tasks);
659
+ },
660
+ saveCache: (cache)=>{
661
+ newCacheGroup.push(cache);
662
+ this.writeCacheToFile();
663
+ }
664
+ };
873
665
  }
874
- if (type === "plan") {
875
- return this.readCache(
876
- pageContext,
877
- type,
878
- actionPrompt,
879
- aiTasks[index].tasks
880
- );
666
+ readCache(pageContext, type, userPrompt, cacheGroup) {
667
+ var _a;
668
+ if (cacheGroup.length > 0) {
669
+ const index = cacheGroup.findIndex((item)=>item.prompt === userPrompt);
670
+ if (index === -1) {
671
+ return false;
672
+ }
673
+ const taskRes = cacheGroup.splice(index, 1)[0];
674
+ if ((taskRes == null ? void 0 : taskRes.type) === "locate" && !((_a = taskRes.response) == null ? void 0 : _a.elements.every((element)=>{
675
+ const findIndex = pageContext.content.findIndex((contentElement)=>contentElement.id === element.id);
676
+ if (findIndex === -1) {
677
+ return false;
678
+ }
679
+ return true;
680
+ }))) {
681
+ return false;
682
+ }
683
+ if (taskRes && taskRes.type === type && taskRes.prompt === userPrompt && this.pageContextEqual(taskRes.pageContext, pageContext)) {
684
+ return taskRes.response;
685
+ }
686
+ }
687
+ return false;
881
688
  }
882
- return this.readCache(
883
- pageContext,
884
- type,
885
- actionPrompt,
886
- aiTasks[index].tasks
887
- );
888
- },
889
- saveCache: (cache) => {
890
- newCacheGroup.push(cache);
891
- this.writeCacheToFile();
892
- }
893
- };
894
- }
895
- readCache(pageContext, type, userPrompt, cacheGroup) {
896
- var _a;
897
- if (cacheGroup.length > 0) {
898
- const index = cacheGroup.findIndex((item) => item.prompt === userPrompt);
899
- if (index === -1) {
900
- return false;
901
- }
902
- const taskRes = cacheGroup.splice(index, 1)[0];
903
- if ((taskRes == null ? void 0 : taskRes.type) === "locate" && !((_a = taskRes.response) == null ? void 0 : _a.elements.every((element) => {
904
- const findIndex = pageContext.content.findIndex(
905
- (contentElement) => contentElement.id === element.id
906
- );
907
- if (findIndex === -1) {
908
- return false;
689
+ pageContextEqual(taskPageContext, pageContext) {
690
+ return taskPageContext.size.width === pageContext.size.width && taskPageContext.size.height === pageContext.size.height;
909
691
  }
910
- return true;
911
- }))) {
912
- return false;
913
- }
914
- if (taskRes && taskRes.type === type && taskRes.prompt === userPrompt && this.pageContextEqual(taskRes.pageContext, pageContext)) {
915
- return taskRes.response;
916
- }
917
- }
918
- return false;
919
- }
920
- pageContextEqual(taskPageContext, pageContext) {
921
- return taskPageContext.size.width === pageContext.size.width && taskPageContext.size.height === pageContext.size.height;
922
- }
923
- /**
692
+ /**
924
693
  * Generate task cache data.
925
694
  * This method is mainly used to create or obtain some cached data for tasks, and it returns a new cache object.
926
695
  * In the cache object, it may contain task-related information, states, or other necessary data.
927
696
  * It is assumed that the `newCache` property already exists in the current class or object and is a data structure used to store task cache.
928
697
  * @returns {Object} Returns a new cache object, which may include task cache data.
929
- */
930
- generateTaskCache() {
931
- return this.newCache;
932
- }
933
- readCacheFromFile() {
934
- const cacheFile = join(getLogDirByType("cache"), `${this.cacheId}.json`);
935
- if (process.env.MIDSCENE_CACHE === "true" && existsSync(cacheFile)) {
936
- try {
937
- const data = readFileSync2(cacheFile, "utf8");
938
- const jsonData = JSON.parse(data);
939
- if (jsonData.pkgName !== this.midscenePkgInfo.name || jsonData.pkgVersion !== this.midscenePkgInfo.version) {
940
- return void 0;
698
+ */ generateTaskCache() {
699
+ return this.newCache;
941
700
  }
942
- return jsonData;
943
- } catch (err) {
944
- return void 0;
945
- }
946
- }
947
- return void 0;
948
- }
949
- writeCacheToFile() {
950
- const midscenePkgInfo = getMidscenePkgInfo(__dirname);
951
- writeLogFile({
952
- fileName: `${this.cacheId}`,
953
- fileExt: "json",
954
- fileContent: stringifyDumpData(
955
- __spreadValues({
956
- pkgName: midscenePkgInfo.name,
957
- pkgVersion: midscenePkgInfo.version,
958
- cacheId: this.cacheId
959
- }, this.newCache),
960
- 2
961
- ),
962
- type: "cache"
963
- });
964
- }
965
- };
966
-
967
- // src/common/tasks.ts
968
- var PageTaskExecutor = class {
969
- constructor(page, opts) {
970
- this.page = page;
971
- this.insight = new Insight(async () => {
972
- return await parseContextFromWebPage(page);
973
- });
974
- this.taskCache = new TaskCache({
975
- fileName: opts == null ? void 0 : opts.cacheId
976
- });
977
- }
978
- async recordScreenshot(timing) {
979
- const file = await this.page.screenshot();
980
- const item = {
981
- type: "screenshot",
982
- ts: Date.now(),
983
- screenshot: base64Encoded2(file),
984
- timing
985
- };
986
- return item;
987
- }
988
- wrapExecutorWithScreenshot(taskApply) {
989
- const taskWithScreenshot = __spreadProps(__spreadValues({}, taskApply), {
990
- executor: async (param, context, ...args) => {
991
- const recorder = [];
992
- const { task } = context;
993
- task.recorder = recorder;
994
- const shot = await this.recordScreenshot(`before ${task.type}`);
995
- recorder.push(shot);
996
- const result = await taskApply.executor(param, context, ...args);
997
- if (taskApply.type === "Action") {
998
- await sleep(1e3);
999
- const shot2 = await this.recordScreenshot("after Action");
1000
- recorder.push(shot2);
1001
- }
1002
- return result;
1003
- }
1004
- });
1005
- return taskWithScreenshot;
1006
- }
1007
- async convertPlanToExecutable(plans, cacheGroup) {
1008
- const tasks = plans.map((plan2) => {
1009
- if (plan2.type === "Locate") {
1010
- const taskFind = {
1011
- type: "Insight",
1012
- subType: "Locate",
1013
- param: plan2.param,
1014
- executor: async (param, taskContext) => {
1015
- const { task } = taskContext;
1016
- let insightDump;
1017
- const dumpCollector = (dump) => {
1018
- insightDump = dump;
1019
- };
1020
- this.insight.onceDumpUpdatedFn = dumpCollector;
1021
- const pageContext = await this.insight.contextRetrieverFn();
1022
- const locateCache = cacheGroup == null ? void 0 : cacheGroup.readCache(
1023
- pageContext,
1024
- "locate",
1025
- param.prompt
1026
- );
1027
- let locateResult;
1028
- const callAI = this.insight.aiVendorFn;
1029
- const element = await this.insight.locate(param.prompt, {
1030
- quickAnswer: plan2.quickAnswer,
1031
- callAI: async (...message) => {
1032
- if (locateCache) {
1033
- locateResult = locateCache;
1034
- return Promise.resolve(locateCache);
1035
- }
1036
- locateResult = await callAI(...message);
1037
- assert2(locateResult);
1038
- return locateResult;
1039
- }
1040
- });
1041
- if (locateResult) {
1042
- cacheGroup == null ? void 0 : cacheGroup.saveCache({
1043
- type: "locate",
1044
- pageContext: {
1045
- url: pageContext.url,
1046
- size: pageContext.size
1047
- },
1048
- prompt: param.prompt,
1049
- response: locateResult
1050
- });
701
+ readCacheFromFile() {
702
+ if (_utils.ifInBrowser) {
703
+ return void 0;
1051
704
  }
1052
- if (!element) {
1053
- task.log = {
1054
- dump: insightDump
1055
- };
1056
- throw new Error(`Element not found: ${param.prompt}`);
1057
- }
1058
- return {
1059
- output: {
1060
- element
1061
- },
1062
- log: {
1063
- dump: insightDump
1064
- },
1065
- cache: {
1066
- hit: Boolean(locateCache)
1067
- }
1068
- };
1069
- }
1070
- };
1071
- return taskFind;
1072
- }
1073
- if (plan2.type === "Assert" || plan2.type === "AssertWithoutThrow") {
1074
- const assertPlan = plan2;
1075
- const taskAssert = {
1076
- type: "Insight",
1077
- subType: "Assert",
1078
- param: assertPlan.param,
1079
- executor: async (param, taskContext) => {
1080
- const { task } = taskContext;
1081
- let insightDump;
1082
- const dumpCollector = (dump) => {
1083
- insightDump = dump;
1084
- };
1085
- this.insight.onceDumpUpdatedFn = dumpCollector;
1086
- const assertion = await this.insight.assert(
1087
- assertPlan.param.assertion
1088
- );
1089
- if (!assertion.pass) {
1090
- if (plan2.type === "Assert") {
1091
- task.output = assertion;
1092
- task.log = {
1093
- dump: insightDump
1094
- };
1095
- throw new Error(
1096
- assertion.thought || "Assertion failed without reason"
1097
- );
1098
- }
1099
- task.error = assertion.thought;
705
+ const cacheFile = (0, _path.join)((0, _utils1.getLogDirByType)("cache"), `${this.cacheId}.json`);
706
+ if (process.env.MIDSCENE_CACHE === "true" && (0, _fs.existsSync)(cacheFile)) {
707
+ try {
708
+ const data = (0, _fs.readFileSync)(cacheFile, "utf8");
709
+ const jsonData = JSON.parse(data);
710
+ if (!this.midscenePkgInfo) {
711
+ return void 0;
712
+ }
713
+ if (jsonData.pkgName !== this.midscenePkgInfo.name || jsonData.pkgVersion !== this.midscenePkgInfo.version) {
714
+ return void 0;
715
+ }
716
+ return jsonData;
717
+ } catch (err) {
718
+ return void 0;
719
+ }
1100
720
  }
1101
- return {
1102
- output: assertion,
1103
- log: {
1104
- dump: insightDump
1105
- }
1106
- };
1107
- }
1108
- };
1109
- return taskAssert;
1110
- }
1111
- if (plan2.type === "Input") {
1112
- const taskActionInput = {
1113
- type: "Action",
1114
- subType: "Input",
1115
- param: plan2.param,
1116
- executor: async (taskParam, { element }) => {
1117
- if (element) {
1118
- await this.page.clearInput(element);
1119
- if (taskParam.value === "") {
721
+ return void 0;
722
+ }
723
+ writeCacheToFile() {
724
+ const midscenePkgInfo = (0, _fs1.getRunningPkgInfo)();
725
+ if (!midscenePkgInfo) {
1120
726
  return;
1121
- }
1122
- await this.page.keyboard.type(taskParam.value);
1123
727
  }
1124
- }
1125
- };
1126
- return taskActionInput;
1127
- }
1128
- if (plan2.type === "KeyboardPress") {
1129
- const taskActionKeyboardPress = {
1130
- type: "Action",
1131
- subType: "KeyboardPress",
1132
- param: plan2.param,
1133
- executor: async (taskParam) => {
1134
- assert2(taskParam.value, "No key to press");
1135
- await this.page.keyboard.press(taskParam.value);
1136
- }
1137
- };
1138
- return taskActionKeyboardPress;
1139
- }
1140
- if (plan2.type === "Tap") {
1141
- const taskActionTap = {
1142
- type: "Action",
1143
- subType: "Tap",
1144
- executor: async (param, { element }) => {
1145
- assert2(element, "Element not found, cannot tap");
1146
- await this.page.mouse.click(
1147
- element.center[0],
1148
- element.center[1]
1149
- );
1150
- }
1151
- };
1152
- return taskActionTap;
1153
- }
1154
- if (plan2.type === "Hover") {
1155
- const taskActionHover = {
1156
- type: "Action",
1157
- subType: "Hover",
1158
- executor: async (param, { element }) => {
1159
- assert2(element, "Element not found, cannot hover");
1160
- await this.page.mouse.move(
1161
- element.center[0],
1162
- element.center[1]
1163
- );
1164
- }
1165
- };
1166
- return taskActionHover;
1167
- }
1168
- if (plan2.type === "Scroll") {
1169
- const taskActionScroll = {
1170
- type: "Action",
1171
- subType: "Scroll",
1172
- param: plan2.param,
1173
- executor: async (taskParam) => {
1174
- const scrollToEventName = taskParam.scrollType;
1175
- switch (scrollToEventName) {
1176
- case "scrollUntilTop":
1177
- await this.page.scrollUntilTop();
1178
- break;
1179
- case "scrollUntilBottom":
1180
- await this.page.scrollUntilBottom();
1181
- break;
1182
- case "scrollUpOneScreen":
1183
- await this.page.scrollUpOneScreen();
1184
- break;
1185
- case "scrollDownOneScreen":
1186
- await this.page.scrollDownOneScreen();
1187
- break;
1188
- default:
1189
- console.error(
1190
- "Unknown scroll event type:",
1191
- scrollToEventName
1192
- );
728
+ if (!_utils.ifInBrowser) {
729
+ (0, _utils1.writeLogFile)({
730
+ fileName: `${this.cacheId}`,
731
+ fileExt: "json",
732
+ fileContent: (0, _utils1.stringifyDumpData)(__spreadValues({
733
+ pkgName: midscenePkgInfo.name,
734
+ pkgVersion: midscenePkgInfo.version,
735
+ cacheId: this.cacheId
736
+ }, this.newCache), 2),
737
+ type: "cache"
738
+ });
1193
739
  }
1194
- }
1195
- };
1196
- return taskActionScroll;
1197
- }
1198
- if (plan2.type === "Sleep") {
1199
- const taskActionSleep = {
1200
- type: "Action",
1201
- subType: "Sleep",
1202
- param: plan2.param,
1203
- executor: async (taskParam) => {
1204
- await sleep(taskParam.timeMs || 3e3);
1205
- }
1206
- };
1207
- return taskActionSleep;
1208
- }
1209
- if (plan2.type === "Error") {
1210
- const taskActionError = {
1211
- type: "Action",
1212
- subType: "Error",
1213
- param: plan2.param,
1214
- executor: async (taskParam) => {
1215
- assert2(
1216
- taskParam.thought,
1217
- "An error occurred, but no thought provided"
1218
- );
1219
- throw new Error(taskParam.thought);
1220
- }
1221
- };
1222
- return taskActionError;
1223
- }
1224
- throw new Error(`Unknown or Unsupported task type: ${plan2.type}`);
1225
- }).map((task) => {
1226
- return this.wrapExecutorWithScreenshot(task);
1227
- });
1228
- return tasks;
1229
- }
1230
- async action(userPrompt) {
1231
- const taskExecutor = new Executor(userPrompt);
1232
- const cacheGroup = this.taskCache.getCacheGroupByPrompt(userPrompt);
1233
- let plans = [];
1234
- const planningTask = {
1235
- type: "Planning",
1236
- param: {
1237
- userPrompt
1238
- },
1239
- executor: async (param) => {
1240
- const pageContext = await this.insight.contextRetrieverFn();
1241
- let planResult;
1242
- const planCache = cacheGroup.readCache(pageContext, "plan", userPrompt);
1243
- if (planCache) {
1244
- planResult = planCache;
1245
- } else {
1246
- planResult = await plan(param.userPrompt, {
1247
- context: pageContext
1248
- });
1249
740
  }
1250
- assert2(planResult.plans.length > 0, "No plans found");
1251
- plans = planResult.plans;
1252
- cacheGroup.saveCache({
1253
- type: "plan",
1254
- pageContext: {
1255
- url: pageContext.url,
1256
- size: pageContext.size
1257
- },
1258
- prompt: userPrompt,
1259
- response: planResult
1260
- });
1261
- return {
1262
- output: planResult,
1263
- cache: {
1264
- hit: Boolean(planCache)
1265
- }
1266
- };
1267
- }
1268
- };
1269
- await taskExecutor.append(this.wrapExecutorWithScreenshot(planningTask));
1270
- let output = await taskExecutor.flush();
1271
- if (taskExecutor.isInErrorState()) {
1272
- return {
1273
- output,
1274
- executor: taskExecutor
1275
- };
1276
- }
1277
- const executables = await this.convertPlanToExecutable(plans, cacheGroup);
1278
- await taskExecutor.append(executables);
1279
- output = await taskExecutor.flush();
1280
- return {
1281
- output,
1282
- executor: taskExecutor
1283
- };
1284
- }
1285
- async query(demand) {
1286
- const description = typeof demand === "string" ? demand : JSON.stringify(demand);
1287
- const taskExecutor = new Executor(description);
1288
- const queryTask = {
1289
- type: "Insight",
1290
- subType: "Query",
1291
- param: {
1292
- dataDemand: demand
1293
- },
1294
- executor: async (param) => {
1295
- let insightDump;
1296
- const dumpCollector = (dump) => {
1297
- insightDump = dump;
1298
- };
1299
- this.insight.onceDumpUpdatedFn = dumpCollector;
1300
- const data = await this.insight.extract(param.dataDemand);
1301
- return {
1302
- output: data,
1303
- log: { dump: insightDump }
1304
- };
1305
- }
1306
- };
1307
- await taskExecutor.append(this.wrapExecutorWithScreenshot(queryTask));
1308
- const output = await taskExecutor.flush();
1309
- return {
1310
- output,
1311
- executor: taskExecutor
1312
- };
1313
- }
1314
- async assert(assertion) {
1315
- const description = `assert: ${assertion}`;
1316
- const taskExecutor = new Executor(description);
1317
- const assertionPlan = {
1318
- type: "Assert",
1319
- param: {
1320
- assertion
1321
- }
1322
- };
1323
- const assertTask = await this.convertPlanToExecutable([assertionPlan]);
1324
- await taskExecutor.append(this.wrapExecutorWithScreenshot(assertTask[0]));
1325
- const output = await taskExecutor.flush();
1326
- return {
1327
- output,
1328
- executor: taskExecutor
1329
- };
1330
- }
1331
- async waitFor(assertion, opt) {
1332
- const description = `waitFor: ${assertion}`;
1333
- const taskExecutor = new Executor(description);
1334
- const { timeoutMs, checkIntervalMs } = opt;
1335
- assert2(assertion, "No assertion for waitFor");
1336
- assert2(timeoutMs, "No timeoutMs for waitFor");
1337
- assert2(checkIntervalMs, "No checkIntervalMs for waitFor");
1338
- const overallStartTime = Date.now();
1339
- let startTime = Date.now();
1340
- let errorThought = "";
1341
- while (Date.now() - overallStartTime < timeoutMs) {
1342
- startTime = Date.now();
1343
- const assertPlan = {
1344
- type: "AssertWithoutThrow",
1345
- param: {
1346
- assertion
741
+ constructor(opts){
742
+ this.midscenePkgInfo = (0, _fs1.getRunningPkgInfo)();
743
+ this.cacheId = generateCacheId(opts == null ? void 0 : opts.fileName);
744
+ this.cache = this.readCacheFromFile() || {
745
+ aiTasks: []
746
+ };
747
+ this.newCache = {
748
+ aiTasks: []
749
+ };
1347
750
  }
1348
- };
1349
- const assertTask = await this.convertPlanToExecutable([assertPlan]);
1350
- await taskExecutor.append(this.wrapExecutorWithScreenshot(assertTask[0]));
1351
- const output = await taskExecutor.flush();
1352
- if (output == null ? void 0 : output.pass) {
1353
- return {
1354
- output: void 0,
1355
- executor: taskExecutor
1356
- };
1357
- }
1358
- errorThought = (output == null ? void 0 : output.thought) || "unknown error";
1359
- const now = Date.now();
1360
- if (now - startTime < checkIntervalMs) {
1361
- const timeRemaining = checkIntervalMs - (now - startTime);
1362
- const sleepPlan = {
1363
- type: "Sleep",
1364
- param: {
1365
- timeMs: timeRemaining
1366
- }
1367
- };
1368
- const sleepTask = await this.convertPlanToExecutable([sleepPlan]);
1369
- await taskExecutor.append(
1370
- this.wrapExecutorWithScreenshot(sleepTask[0])
1371
- );
1372
- await taskExecutor.flush();
1373
- }
1374
- }
1375
- const errorPlan = {
1376
- type: "Error",
1377
- param: {
1378
- thought: `waitFor timeout: ${errorThought}`
1379
- }
1380
751
  };
1381
- const errorTask = await this.convertPlanToExecutable([errorPlan]);
1382
- await taskExecutor.append(errorTask[0]);
1383
- await taskExecutor.flush();
1384
- return {
1385
- output: void 0,
1386
- executor: taskExecutor
1387
- };
1388
- }
1389
- };
1390
-
1391
- // src/common/agent.ts
1392
- var PageAgent = class {
1393
- constructor(page, opts) {
1394
- this.page = page;
1395
- this.opts = Object.assign(
1396
- {
1397
- generateReport: true,
1398
- autoPrintReportMsg: true,
1399
- groupName: "Midscene Report",
1400
- groupDescription: ""
1401
- },
1402
- opts || {}
1403
- );
1404
- this.dump = {
1405
- groupName: this.opts.groupName,
1406
- groupDescription: this.opts.groupDescription,
1407
- executions: []
752
+ // src/common/tasks.ts
753
+ var PageTaskExecutor = class {
754
+ recordScreenshot(timing) {
755
+ return __async(this, null, function*() {
756
+ const base64 = yield this.page.screenshotBase64();
757
+ const item = {
758
+ type: "screenshot",
759
+ ts: Date.now(),
760
+ screenshot: base64,
761
+ timing
762
+ };
763
+ return item;
764
+ });
765
+ }
766
+ wrapExecutorWithScreenshot(taskApply) {
767
+ const taskWithScreenshot = __spreadProps(__spreadValues({}, taskApply), {
768
+ executor: (param, context, ...args)=>__async(this, null, function*() {
769
+ const recorder = [];
770
+ const { task } = context;
771
+ task.recorder = recorder;
772
+ const shot = yield this.recordScreenshot(`before ${task.type}`);
773
+ recorder.push(shot);
774
+ const result = yield taskApply.executor(param, context, ...args);
775
+ if (taskApply.type === "Action") {
776
+ yield (0, _utils1.sleep)(1e3);
777
+ const shot2 = yield this.recordScreenshot("after Action");
778
+ recorder.push(shot2);
779
+ }
780
+ return result;
781
+ })
782
+ });
783
+ return taskWithScreenshot;
784
+ }
785
+ convertPlanToExecutable(plans, cacheGroup) {
786
+ return __async(this, null, function*() {
787
+ const tasks = plans.map((plan2)=>{
788
+ if (plan2.type === "Locate") {
789
+ const taskFind = {
790
+ type: "Insight",
791
+ subType: "Locate",
792
+ param: plan2.param,
793
+ quickAnswer: plan2.quickAnswer,
794
+ executor: (param, taskContext)=>__async(this, null, function*() {
795
+ const { task } = taskContext;
796
+ let insightDump;
797
+ const dumpCollector = (dump)=>{
798
+ insightDump = dump;
799
+ };
800
+ this.insight.onceDumpUpdatedFn = dumpCollector;
801
+ const pageContext = yield this.insight.contextRetrieverFn();
802
+ const locateCache = cacheGroup == null ? void 0 : cacheGroup.readCache(pageContext, "locate", param.prompt);
803
+ let locateResult;
804
+ const callAI = this.insight.aiVendorFn;
805
+ const element = yield this.insight.locate(param.prompt, {
806
+ quickAnswer: task.quickAnswer,
807
+ callAI: (...message)=>__async(this, null, function*() {
808
+ if (locateCache) {
809
+ locateResult = locateCache;
810
+ return Promise.resolve(locateCache);
811
+ }
812
+ const aiResult = yield callAI(...message);
813
+ locateResult = (0, _core.transformElementPositionToId)(aiResult, pageContext.content);
814
+ (0, _assert.default)(locateResult);
815
+ return locateResult;
816
+ })
817
+ });
818
+ if (locateResult) {
819
+ cacheGroup == null ? void 0 : cacheGroup.saveCache({
820
+ type: "locate",
821
+ pageContext: {
822
+ url: pageContext.url,
823
+ size: pageContext.size
824
+ },
825
+ prompt: param.prompt,
826
+ response: locateResult
827
+ });
828
+ }
829
+ if (!element) {
830
+ task.log = {
831
+ dump: insightDump
832
+ };
833
+ throw new Error(`Element not found: ${param.prompt}`);
834
+ }
835
+ return {
836
+ output: {
837
+ element
838
+ },
839
+ log: {
840
+ dump: insightDump
841
+ },
842
+ cache: {
843
+ hit: Boolean(locateCache)
844
+ }
845
+ };
846
+ })
847
+ };
848
+ return taskFind;
849
+ }
850
+ if (plan2.type === "Assert" || plan2.type === "AssertWithoutThrow") {
851
+ const assertPlan = plan2;
852
+ const taskAssert = {
853
+ type: "Insight",
854
+ subType: "Assert",
855
+ param: assertPlan.param,
856
+ executor: (param, taskContext)=>__async(this, null, function*() {
857
+ const { task } = taskContext;
858
+ let insightDump;
859
+ const dumpCollector = (dump)=>{
860
+ insightDump = dump;
861
+ };
862
+ this.insight.onceDumpUpdatedFn = dumpCollector;
863
+ const assertion = yield this.insight.assert(assertPlan.param.assertion);
864
+ if (!assertion.pass) {
865
+ if (plan2.type === "Assert") {
866
+ task.output = assertion;
867
+ task.log = {
868
+ dump: insightDump
869
+ };
870
+ throw new Error(assertion.thought || "Assertion failed without reason");
871
+ }
872
+ task.error = assertion.thought;
873
+ }
874
+ return {
875
+ output: assertion,
876
+ log: {
877
+ dump: insightDump
878
+ }
879
+ };
880
+ })
881
+ };
882
+ return taskAssert;
883
+ }
884
+ if (plan2.type === "Input") {
885
+ const taskActionInput = {
886
+ type: "Action",
887
+ subType: "Input",
888
+ param: plan2.param,
889
+ executor: (_0, _1)=>__async(this, [
890
+ _0,
891
+ _1
892
+ ], function*(taskParam, { element }) {
893
+ if (element) {
894
+ yield this.page.clearInput(element);
895
+ if (taskParam.value === "") {
896
+ return;
897
+ }
898
+ yield this.page.keyboard.type(taskParam.value);
899
+ }
900
+ })
901
+ };
902
+ return taskActionInput;
903
+ }
904
+ if (plan2.type === "KeyboardPress") {
905
+ const taskActionKeyboardPress = {
906
+ type: "Action",
907
+ subType: "KeyboardPress",
908
+ param: plan2.param,
909
+ executor: (taskParam)=>__async(this, null, function*() {
910
+ (0, _assert.default)(taskParam.value, "No key to press");
911
+ yield this.page.keyboard.press(taskParam.value);
912
+ })
913
+ };
914
+ return taskActionKeyboardPress;
915
+ }
916
+ if (plan2.type === "Tap") {
917
+ const taskActionTap = {
918
+ type: "Action",
919
+ subType: "Tap",
920
+ executor: (_0, _1)=>__async(this, [
921
+ _0,
922
+ _1
923
+ ], function*(param, { element }) {
924
+ (0, _assert.default)(element, "Element not found, cannot tap");
925
+ yield this.page.mouse.click(element.center[0], element.center[1]);
926
+ })
927
+ };
928
+ return taskActionTap;
929
+ }
930
+ if (plan2.type === "Hover") {
931
+ const taskActionHover = {
932
+ type: "Action",
933
+ subType: "Hover",
934
+ executor: (_0, _1)=>__async(this, [
935
+ _0,
936
+ _1
937
+ ], function*(param, { element }) {
938
+ (0, _assert.default)(element, "Element not found, cannot hover");
939
+ yield this.page.mouse.move(element.center[0], element.center[1]);
940
+ })
941
+ };
942
+ return taskActionHover;
943
+ }
944
+ if (plan2.type === "Scroll") {
945
+ const taskActionScroll = {
946
+ type: "Action",
947
+ subType: "Scroll",
948
+ param: plan2.param,
949
+ executor: (taskParam)=>__async(this, null, function*() {
950
+ const scrollToEventName = taskParam.scrollType;
951
+ switch(scrollToEventName){
952
+ case "scrollUntilTop":
953
+ yield this.page.scrollUntilTop();
954
+ break;
955
+ case "scrollUntilBottom":
956
+ yield this.page.scrollUntilBottom();
957
+ break;
958
+ case "scrollUpOneScreen":
959
+ yield this.page.scrollUpOneScreen();
960
+ break;
961
+ case "scrollDownOneScreen":
962
+ yield this.page.scrollDownOneScreen();
963
+ break;
964
+ default:
965
+ console.error("Unknown scroll event type:", scrollToEventName);
966
+ }
967
+ })
968
+ };
969
+ return taskActionScroll;
970
+ }
971
+ if (plan2.type === "Sleep") {
972
+ const taskActionSleep = {
973
+ type: "Action",
974
+ subType: "Sleep",
975
+ param: plan2.param,
976
+ executor: (taskParam)=>__async(this, null, function*() {
977
+ yield (0, _utils1.sleep)(taskParam.timeMs || 3e3);
978
+ })
979
+ };
980
+ return taskActionSleep;
981
+ }
982
+ if (plan2.type === "Error") {
983
+ const taskActionError = {
984
+ type: "Action",
985
+ subType: "Error",
986
+ param: plan2.param,
987
+ executor: (taskParam)=>__async(this, null, function*() {
988
+ (0, _assert.default)(taskParam.thought, "An error occurred, but no thought provided");
989
+ throw new Error(taskParam.thought);
990
+ })
991
+ };
992
+ return taskActionError;
993
+ }
994
+ throw new Error(`Unknown or Unsupported task type: ${plan2.type}`);
995
+ }).map((task)=>{
996
+ return this.wrapExecutorWithScreenshot(task);
997
+ });
998
+ return tasks;
999
+ });
1000
+ }
1001
+ action(userPrompt) {
1002
+ return __async(this, null, function*() {
1003
+ const taskExecutor = new _core.Executor(userPrompt);
1004
+ const cacheGroup = this.taskCache.getCacheGroupByPrompt(userPrompt);
1005
+ let plans = [];
1006
+ const planningTask = {
1007
+ type: "Planning",
1008
+ param: {
1009
+ userPrompt
1010
+ },
1011
+ executor: (param)=>__async(this, null, function*() {
1012
+ const pageContext = yield this.insight.contextRetrieverFn();
1013
+ let planResult;
1014
+ const planCache = cacheGroup.readCache(pageContext, "plan", userPrompt);
1015
+ if (planCache) {
1016
+ planResult = planCache;
1017
+ } else {
1018
+ planResult = yield (0, _core.plan)(param.userPrompt, {
1019
+ context: pageContext
1020
+ });
1021
+ }
1022
+ (0, _assert.default)(planResult.plans.length > 0, "No plans found");
1023
+ plans = planResult.plans;
1024
+ cacheGroup.saveCache({
1025
+ type: "plan",
1026
+ pageContext: {
1027
+ url: pageContext.url,
1028
+ size: pageContext.size
1029
+ },
1030
+ prompt: userPrompt,
1031
+ response: planResult
1032
+ });
1033
+ return {
1034
+ output: planResult,
1035
+ pageContext,
1036
+ cache: {
1037
+ hit: Boolean(planCache)
1038
+ }
1039
+ };
1040
+ })
1041
+ };
1042
+ yield taskExecutor.append(this.wrapExecutorWithScreenshot(planningTask));
1043
+ let output = yield taskExecutor.flush();
1044
+ if (taskExecutor.isInErrorState()) {
1045
+ return {
1046
+ output,
1047
+ executor: taskExecutor
1048
+ };
1049
+ }
1050
+ const executables = yield this.convertPlanToExecutable(plans, cacheGroup);
1051
+ yield taskExecutor.append(executables);
1052
+ output = yield taskExecutor.flush();
1053
+ return {
1054
+ output,
1055
+ executor: taskExecutor
1056
+ };
1057
+ });
1058
+ }
1059
+ query(demand) {
1060
+ return __async(this, null, function*() {
1061
+ const description = typeof demand === "string" ? demand : JSON.stringify(demand);
1062
+ const taskExecutor = new _core.Executor(description);
1063
+ const queryTask = {
1064
+ type: "Insight",
1065
+ subType: "Query",
1066
+ param: {
1067
+ dataDemand: demand
1068
+ },
1069
+ executor: (param)=>__async(this, null, function*() {
1070
+ let insightDump;
1071
+ const dumpCollector = (dump)=>{
1072
+ insightDump = dump;
1073
+ };
1074
+ this.insight.onceDumpUpdatedFn = dumpCollector;
1075
+ const data = yield this.insight.extract(param.dataDemand);
1076
+ return {
1077
+ output: data,
1078
+ log: {
1079
+ dump: insightDump
1080
+ }
1081
+ };
1082
+ })
1083
+ };
1084
+ yield taskExecutor.append(this.wrapExecutorWithScreenshot(queryTask));
1085
+ const output = yield taskExecutor.flush();
1086
+ return {
1087
+ output,
1088
+ executor: taskExecutor
1089
+ };
1090
+ });
1091
+ }
1092
+ assert(assertion) {
1093
+ return __async(this, null, function*() {
1094
+ const description = `assert: ${assertion}`;
1095
+ const taskExecutor = new _core.Executor(description);
1096
+ const assertionPlan = {
1097
+ type: "Assert",
1098
+ param: {
1099
+ assertion
1100
+ }
1101
+ };
1102
+ const assertTask = yield this.convertPlanToExecutable([
1103
+ assertionPlan
1104
+ ]);
1105
+ yield taskExecutor.append(this.wrapExecutorWithScreenshot(assertTask[0]));
1106
+ const output = yield taskExecutor.flush();
1107
+ return {
1108
+ output,
1109
+ executor: taskExecutor
1110
+ };
1111
+ });
1112
+ }
1113
+ waitFor(assertion, opt) {
1114
+ return __async(this, null, function*() {
1115
+ const description = `waitFor: ${assertion}`;
1116
+ const taskExecutor = new _core.Executor(description);
1117
+ const { timeoutMs, checkIntervalMs } = opt;
1118
+ (0, _assert.default)(assertion, "No assertion for waitFor");
1119
+ (0, _assert.default)(timeoutMs, "No timeoutMs for waitFor");
1120
+ (0, _assert.default)(checkIntervalMs, "No checkIntervalMs for waitFor");
1121
+ const overallStartTime = Date.now();
1122
+ let startTime = Date.now();
1123
+ let errorThought = "";
1124
+ while(Date.now() - overallStartTime < timeoutMs){
1125
+ startTime = Date.now();
1126
+ const assertPlan = {
1127
+ type: "AssertWithoutThrow",
1128
+ param: {
1129
+ assertion
1130
+ }
1131
+ };
1132
+ const assertTask = yield this.convertPlanToExecutable([
1133
+ assertPlan
1134
+ ]);
1135
+ yield taskExecutor.append(this.wrapExecutorWithScreenshot(assertTask[0]));
1136
+ const output = yield taskExecutor.flush();
1137
+ if (output == null ? void 0 : output.pass) {
1138
+ return {
1139
+ output: void 0,
1140
+ executor: taskExecutor
1141
+ };
1142
+ }
1143
+ errorThought = (output == null ? void 0 : output.thought) || "unknown error";
1144
+ const now = Date.now();
1145
+ if (now - startTime < checkIntervalMs) {
1146
+ const timeRemaining = checkIntervalMs - (now - startTime);
1147
+ const sleepPlan = {
1148
+ type: "Sleep",
1149
+ param: {
1150
+ timeMs: timeRemaining
1151
+ }
1152
+ };
1153
+ const sleepTask = yield this.convertPlanToExecutable([
1154
+ sleepPlan
1155
+ ]);
1156
+ yield taskExecutor.append(this.wrapExecutorWithScreenshot(sleepTask[0]));
1157
+ yield taskExecutor.flush();
1158
+ }
1159
+ }
1160
+ const errorPlan = {
1161
+ type: "Error",
1162
+ param: {
1163
+ thought: `waitFor timeout: ${errorThought}`
1164
+ }
1165
+ };
1166
+ const errorTask = yield this.convertPlanToExecutable([
1167
+ errorPlan
1168
+ ]);
1169
+ yield taskExecutor.append(errorTask[0]);
1170
+ yield taskExecutor.flush();
1171
+ return {
1172
+ output: void 0,
1173
+ executor: taskExecutor
1174
+ };
1175
+ });
1176
+ }
1177
+ constructor(page, insight, opts){
1178
+ this.page = page;
1179
+ this.insight = insight;
1180
+ this.taskCache = new TaskCache({
1181
+ fileName: opts == null ? void 0 : opts.cacheId
1182
+ });
1183
+ }
1408
1184
  };
1409
- this.taskExecutor = new PageTaskExecutor(this.page, {
1410
- cacheId: opts == null ? void 0 : opts.cacheId
1411
- });
1412
- this.reportFileName = reportFileName((opts == null ? void 0 : opts.testId) || "web");
1413
- }
1414
- appendExecutionDump(execution) {
1415
- const currentDump = this.dump;
1416
- currentDump.executions.push(execution);
1417
- }
1418
- dumpDataString() {
1419
- this.dump.groupName = this.opts.groupName;
1420
- this.dump.groupDescription = this.opts.groupDescription;
1421
- return stringifyDumpData2(this.dump);
1422
- }
1423
- writeOutActionDumps() {
1424
- const { generateReport, autoPrintReportMsg } = this.opts;
1425
- this.reportFile = writeLogFile2({
1426
- fileName: this.reportFileName,
1427
- fileExt: groupedActionDumpFileExt,
1428
- fileContent: this.dumpDataString(),
1429
- type: "dump",
1430
- generateReport
1431
- });
1432
- if (generateReport && autoPrintReportMsg) {
1433
- printReportMsg(this.reportFile);
1434
- }
1435
- }
1436
- async aiAction(taskPrompt) {
1437
- const { executor } = await this.taskExecutor.action(taskPrompt);
1438
- this.appendExecutionDump(executor.dump());
1439
- this.writeOutActionDumps();
1440
- if (executor.isInErrorState()) {
1441
- const errorTask = executor.latestErrorTask();
1442
- throw new Error(`${errorTask == null ? void 0 : errorTask.error}
1185
+ // src/common/agent.ts
1186
+ var PageAgent = class {
1187
+ getUIContext() {
1188
+ return __async(this, null, function*() {
1189
+ return yield parseContextFromWebPage(this.page);
1190
+ });
1191
+ }
1192
+ resetDump() {
1193
+ this.dump = {
1194
+ groupName: this.opts.groupName,
1195
+ groupDescription: this.opts.groupDescription,
1196
+ executions: []
1197
+ };
1198
+ return this.dump;
1199
+ }
1200
+ appendExecutionDump(execution) {
1201
+ const currentDump = this.dump;
1202
+ currentDump.executions.push(execution);
1203
+ }
1204
+ dumpDataString() {
1205
+ this.dump.groupName = this.opts.groupName;
1206
+ this.dump.groupDescription = this.opts.groupDescription;
1207
+ return (0, _utils1.stringifyDumpData)(this.dump);
1208
+ }
1209
+ reportHTMLString() {
1210
+ return (0, _utils1.reportHTMLContent)(this.dumpDataString());
1211
+ }
1212
+ writeOutActionDumps() {
1213
+ const { generateReport, autoPrintReportMsg } = this.opts;
1214
+ this.reportFile = (0, _utils1.writeLogFile)({
1215
+ fileName: this.reportFileName,
1216
+ fileExt: _utils1.groupedActionDumpFileExt,
1217
+ fileContent: this.dumpDataString(),
1218
+ type: "dump",
1219
+ generateReport
1220
+ });
1221
+ if (generateReport && autoPrintReportMsg && this.reportFile) {
1222
+ printReportMsg(this.reportFile);
1223
+ }
1224
+ }
1225
+ aiAction(taskPrompt) {
1226
+ return __async(this, null, function*() {
1227
+ const { executor } = yield this.taskExecutor.action(taskPrompt);
1228
+ this.appendExecutionDump(executor.dump());
1229
+ this.writeOutActionDumps();
1230
+ if (executor.isInErrorState()) {
1231
+ const errorTask = executor.latestErrorTask();
1232
+ throw new Error(`${errorTask == null ? void 0 : errorTask.error}
1443
1233
  ${errorTask == null ? void 0 : errorTask.errorStack}`);
1444
- }
1445
- }
1446
- async aiQuery(demand) {
1447
- const { output, executor } = await this.taskExecutor.query(demand);
1448
- this.appendExecutionDump(executor.dump());
1449
- this.writeOutActionDumps();
1450
- if (executor.isInErrorState()) {
1451
- const errorTask = executor.latestErrorTask();
1452
- throw new Error(`${errorTask == null ? void 0 : errorTask.error}
1234
+ }
1235
+ });
1236
+ }
1237
+ aiQuery(demand) {
1238
+ return __async(this, null, function*() {
1239
+ const { output, executor } = yield this.taskExecutor.query(demand);
1240
+ this.appendExecutionDump(executor.dump());
1241
+ this.writeOutActionDumps();
1242
+ if (executor.isInErrorState()) {
1243
+ const errorTask = executor.latestErrorTask();
1244
+ throw new Error(`${errorTask == null ? void 0 : errorTask.error}
1453
1245
  ${errorTask == null ? void 0 : errorTask.errorStack}`);
1454
- }
1455
- return output;
1456
- }
1457
- async aiAssert(assertion, msg, opt) {
1458
- const { output, executor } = await this.taskExecutor.assert(assertion);
1459
- this.appendExecutionDump(executor.dump());
1460
- this.writeOutActionDumps();
1461
- if (opt == null ? void 0 : opt.keepRawResponse) {
1462
- return output;
1463
- }
1464
- if (!(output == null ? void 0 : output.pass)) {
1465
- const errMsg = msg || `Assertion failed: ${assertion}`;
1466
- const reasonMsg = `Reason: ${(output == null ? void 0 : output.thought) || "(no_reason)"}`;
1467
- throw new Error(`${errMsg}
1246
+ }
1247
+ return output;
1248
+ });
1249
+ }
1250
+ aiAssert(assertion, msg, opt) {
1251
+ return __async(this, null, function*() {
1252
+ var _a;
1253
+ const { output, executor } = yield this.taskExecutor.assert(assertion);
1254
+ this.appendExecutionDump(executor.dump());
1255
+ this.writeOutActionDumps();
1256
+ if (output && (opt == null ? void 0 : opt.keepRawResponse)) {
1257
+ return output;
1258
+ }
1259
+ if (!(output == null ? void 0 : output.pass)) {
1260
+ const errMsg = msg || `Assertion failed: ${assertion}`;
1261
+ const reasonMsg = `Reason: ${(output == null ? void 0 : output.thought) || ((_a = executor.latestErrorTask()) == null ? void 0 : _a.error) || "(no_reason)"}`;
1262
+ throw new Error(`${errMsg}
1468
1263
  ${reasonMsg}`);
1469
- }
1470
- }
1471
- async aiWaitFor(assertion, opt) {
1472
- const { executor } = await this.taskExecutor.waitFor(assertion, {
1473
- timeoutMs: (opt == null ? void 0 : opt.timeoutMs) || 15 * 1e3,
1474
- checkIntervalMs: (opt == null ? void 0 : opt.checkIntervalMs) || 3 * 1e3,
1475
- assertion
1476
- });
1477
- this.appendExecutionDump(executor.dump());
1478
- this.writeOutActionDumps();
1479
- if (executor.isInErrorState()) {
1480
- const errorTask = executor.latestErrorTask();
1481
- throw new Error(`${errorTask == null ? void 0 : errorTask.error}
1264
+ }
1265
+ });
1266
+ }
1267
+ aiWaitFor(assertion, opt) {
1268
+ return __async(this, null, function*() {
1269
+ const { executor } = yield this.taskExecutor.waitFor(assertion, {
1270
+ timeoutMs: (opt == null ? void 0 : opt.timeoutMs) || 15 * 1e3,
1271
+ checkIntervalMs: (opt == null ? void 0 : opt.checkIntervalMs) || 3 * 1e3,
1272
+ assertion
1273
+ });
1274
+ this.appendExecutionDump(executor.dump());
1275
+ this.writeOutActionDumps();
1276
+ if (executor.isInErrorState()) {
1277
+ const errorTask = executor.latestErrorTask();
1278
+ throw new Error(`${errorTask == null ? void 0 : errorTask.error}
1482
1279
  ${errorTask == null ? void 0 : errorTask.errorStack}`);
1483
- }
1484
- }
1485
- async ai(taskPrompt, type = "action") {
1486
- if (type === "action") {
1487
- return this.aiAction(taskPrompt);
1488
- }
1489
- if (type === "query") {
1490
- return this.aiQuery(taskPrompt);
1491
- }
1492
- if (type === "assert") {
1493
- return this.aiAssert(taskPrompt);
1494
- }
1495
- throw new Error(
1496
- `Unknown type: ${type}, only support 'action', 'query', 'assert'`
1497
- );
1498
- }
1499
- };
1500
-
1501
- // src/playground/agent.ts
1502
- var StaticPageAgent = class extends PageAgent {
1503
- constructor(page) {
1504
- super(page, {});
1505
- }
1506
- };
1507
-
1508
- // src/playground/server.ts
1509
- import assert3 from "assert";
1510
- import { randomUUID as randomUUID2 } from "crypto";
1511
- import { existsSync as existsSync2, readFileSync as readFileSync3, writeFileSync } from "fs";
1512
- import { join as join2 } from "path";
1513
- var import_dotenv = __toESM(require_main());
1514
- import { getTmpDir } from "@midscene/core/utils";
1515
- import cors from "cors";
1516
- import express from "express";
1517
-
1518
- // src/playground/static-page.ts
1519
- import { getTmpFile } from "@midscene/core/utils";
1520
- import { saveBase64Image } from "@midscene/shared/img";
1521
- var ThrowNotImplemented = (methodName) => {
1522
- throw new Error(
1523
- `The method "${methodName}" is not implemented as designed since this is a static UI context. (${ERROR_CODE_NOT_IMPLEMENTED_AS_DESIGNED})`
1524
- );
1525
- };
1526
- var StaticPage = class {
1527
- constructor(uiContext) {
1528
- this.pageType = "static";
1529
- this.mouse = {
1530
- click: ThrowNotImplemented.bind(null, "mouse.click"),
1531
- wheel: ThrowNotImplemented.bind(null, "mouse.wheel"),
1532
- move: ThrowNotImplemented.bind(null, "mouse.move")
1280
+ }
1281
+ });
1282
+ }
1283
+ ai(taskPrompt, type = "action") {
1284
+ return __async(this, null, function*() {
1285
+ if (type === "action") {
1286
+ return this.aiAction(taskPrompt);
1287
+ }
1288
+ if (type === "query") {
1289
+ return this.aiQuery(taskPrompt);
1290
+ }
1291
+ if (type === "assert") {
1292
+ return this.aiAssert(taskPrompt);
1293
+ }
1294
+ throw new Error(`Unknown type: ${type}, only support 'action', 'query', 'assert'`);
1295
+ });
1296
+ }
1297
+ destroy() {
1298
+ return __async(this, null, function*() {
1299
+ yield this.page.destroy();
1300
+ });
1301
+ }
1302
+ constructor(page, opts){
1303
+ /**
1304
+ * If true, the agent will not perform any actions
1305
+ */ this.dryMode = false;
1306
+ this.page = page;
1307
+ this.opts = Object.assign({
1308
+ generateReport: true,
1309
+ autoPrintReportMsg: true,
1310
+ groupName: "Midscene Report",
1311
+ groupDescription: ""
1312
+ }, opts || {});
1313
+ this.insight = new _core.Insight(()=>__async(this, null, function*() {
1314
+ return this.getUIContext();
1315
+ }), {
1316
+ generateElement: ({ content, rect })=>new WebElementInfo({
1317
+ content: content || "",
1318
+ rect,
1319
+ page,
1320
+ id: "",
1321
+ attributes: {
1322
+ nodeType: _constants.NodeType.CONTAINER
1323
+ },
1324
+ indexId: 0
1325
+ })
1326
+ });
1327
+ this.taskExecutor = new PageTaskExecutor(this.page, this.insight, {
1328
+ cacheId: opts == null ? void 0 : opts.cacheId
1329
+ });
1330
+ this.dump = this.resetDump();
1331
+ this.reportFileName = reportFileName((opts == null ? void 0 : opts.testId) || "web");
1332
+ }
1533
1333
  };
1534
- this.keyboard = {
1535
- type: ThrowNotImplemented.bind(null, "keyboard.type"),
1536
- press: ThrowNotImplemented.bind(null, "keyboard.press")
1334
+ // src/playground/agent.ts
1335
+ var StaticPageAgent = class extends PageAgent {
1336
+ constructor(page){
1337
+ super(page, {});
1338
+ this.dryMode = true;
1339
+ }
1537
1340
  };
1538
- this.uiContext = uiContext;
1539
- }
1540
- async getElementInfos() {
1541
- return ThrowNotImplemented("getElementInfos");
1542
- }
1543
- async screenshot() {
1544
- const base64 = this.uiContext.screenshotBase64;
1545
- if (!base64) {
1546
- throw new Error("screenshot base64 is empty");
1547
- }
1548
- const tmpFilePath = getTmpFile("png");
1549
- await saveBase64Image({ base64Data: base64, outputPath: tmpFilePath });
1550
- return tmpFilePath;
1551
- }
1552
- url() {
1553
- return this.uiContext.url;
1554
- }
1555
- async scrollUntilTop() {
1556
- return ThrowNotImplemented("scrollUntilTop");
1557
- }
1558
- async scrollUntilBottom() {
1559
- return ThrowNotImplemented("scrollUntilBottom");
1560
- }
1561
- async scrollUpOneScreen() {
1562
- return ThrowNotImplemented("scrollUpOneScreen");
1563
- }
1564
- async scrollDownOneScreen() {
1565
- return ThrowNotImplemented("scrollDownOneScreen");
1566
- }
1567
- async clearInput() {
1568
- return ThrowNotImplemented("clearInput");
1569
- }
1570
- async _forceUsePageContext() {
1571
- return this.uiContext;
1572
- }
1573
- };
1574
-
1575
- // src/playground/server.ts
1576
- var defaultPort = 5800;
1577
- var staticPath = join2(__dirname, "../../static");
1578
- var agentRequestCount = 1;
1579
- var errorHandler = (err, req, res, next) => {
1580
- console.error(err);
1581
- res.status(500).json({
1582
- error: err.message
1583
- });
1584
- };
1585
- var setup = () => {
1586
- import_dotenv.default.config();
1587
- };
1588
- var PlaygroundServer = class {
1589
- constructor() {
1590
- this.app = express();
1591
- this.tmpDir = getTmpDir();
1592
- setup();
1593
- }
1594
- filePathForUuid(uuid) {
1595
- return join2(this.tmpDir, `${uuid}.json`);
1596
- }
1597
- saveContextFile(uuid, context) {
1598
- const tmpFile = this.filePathForUuid(uuid);
1599
- console.log(`save context file: ${tmpFile}`);
1600
- writeFileSync(tmpFile, context);
1601
- return tmpFile;
1602
- }
1603
- async launch() {
1604
- this.app.use(errorHandler);
1605
- this.app.use(
1606
- cors({
1607
- origin: "*",
1608
- credentials: true
1609
- })
1610
- );
1611
- this.app.get("/status", cors(), async (req, res) => {
1612
- res.send({
1613
- status: "ok"
1614
- });
1615
- });
1616
- this.app.get("/", (req, res) => {
1617
- res.sendFile(join2(staticPath, "index.html"));
1618
- });
1619
- this.app.get("/playground/:uuid", async (req, res) => {
1620
- res.sendFile(join2(staticPath, "index.html"));
1621
- });
1622
- this.app.get("/context/:uuid", async (req, res) => {
1623
- const { uuid } = req.params;
1624
- const contextFile = this.filePathForUuid(uuid);
1625
- assert3(existsSync2(contextFile), "Context not found");
1626
- const context = readFileSync3(contextFile, "utf8");
1627
- res.json({
1628
- context
1629
- });
1630
- });
1631
- this.app.post(
1632
- "/playground-with-context",
1633
- express.json({ limit: "50mb" }),
1634
- async (req, res) => {
1635
- const context = req.body.context;
1636
- assert3(context, "context is required");
1637
- const uuid = randomUUID2();
1638
- this.saveContextFile(uuid, context);
1639
- return res.json({
1640
- location: `/playground/${uuid}`,
1641
- uuid
1642
- });
1643
- }
1644
- );
1645
- this.app.post(
1646
- "/execute",
1647
- express.json({ limit: "30mb" }),
1648
- async (req, res) => {
1649
- const { context, type, prompt } = req.body;
1650
- assert3(context, "context is required");
1651
- assert3(type, "type is required");
1652
- assert3(prompt, "prompt is required");
1653
- const requestId = agentRequestCount++;
1654
- console.log(`handle request: #${requestId}, ${type}, ${prompt}`);
1655
- const page = new StaticPage(context);
1656
- const agent = new StaticPageAgent(page);
1657
- const response = {
1658
- result: null,
1659
- dump: null,
1660
- error: null
1661
- };
1662
- try {
1663
- if (type === "aiQuery") {
1664
- response.result = await agent.aiQuery(prompt);
1665
- } else if (type === "aiAction") {
1666
- response.result = await agent.aiAction(prompt);
1667
- } else if (type === "aiAssert") {
1668
- response.result = await agent.aiAssert(prompt, void 0, {
1669
- keepRawResponse: true
1341
+ // src/playground/static-page.ts
1342
+ var ThrowNotImplemented = (methodName)=>{
1343
+ throw new Error(`The method "${methodName}" is not implemented as designed since this is a static UI context. (${ERROR_CODE_NOT_IMPLEMENTED_AS_DESIGNED})`);
1344
+ };
1345
+ var StaticPage = class {
1346
+ getElementInfos() {
1347
+ return __async(this, null, function*() {
1348
+ return ThrowNotImplemented("getElementInfos");
1670
1349
  });
1671
- } else {
1672
- response.error = `Unknown type: ${type}`;
1673
- }
1674
- } catch (error) {
1675
- if (!error.message.includes(ERROR_CODE_NOT_IMPLEMENTED_AS_DESIGNED)) {
1676
- response.error = error.message;
1677
- }
1678
1350
  }
1679
- try {
1680
- response.dump = JSON.parse(agent.dumpDataString());
1681
- agent.writeOutActionDumps();
1682
- } catch (error) {
1683
- console.error(
1684
- `write out dump failed: #${requestId}, ${error.message}`
1685
- );
1351
+ size() {
1352
+ return __async(this, null, function*() {
1353
+ return this.uiContext.size;
1354
+ });
1686
1355
  }
1687
- res.send(response);
1688
- if (response.error) {
1689
- console.error(
1690
- `handle request failed: #${requestId}, ${response.error}`
1691
- );
1692
- } else {
1693
- console.log(`handle request done: #${requestId}`);
1356
+ screenshotBase64() {
1357
+ return __async(this, null, function*() {
1358
+ const base64 = this.uiContext.screenshotBase64;
1359
+ if (!base64) {
1360
+ throw new Error("screenshot base64 is empty");
1361
+ }
1362
+ return base64;
1363
+ });
1694
1364
  }
1695
- }
1696
- );
1697
- return new Promise((resolve, reject) => {
1698
- const port = this.port || defaultPort;
1699
- this.server = this.app.listen(port, () => {
1700
- this.port = port;
1701
- resolve(this);
1702
- });
1703
- });
1704
- }
1705
- close() {
1706
- if (this.server) {
1707
- return this.server.close();
1708
- }
1709
- }
1710
- };
1711
- export {
1712
- PlaygroundServer,
1713
- StaticPage,
1714
- StaticPageAgent
1715
- };
1365
+ url() {
1366
+ return __async(this, null, function*() {
1367
+ return this.uiContext.url;
1368
+ });
1369
+ }
1370
+ scrollUntilTop() {
1371
+ return __async(this, null, function*() {
1372
+ return ThrowNotImplemented("scrollUntilTop");
1373
+ });
1374
+ }
1375
+ scrollUntilBottom() {
1376
+ return __async(this, null, function*() {
1377
+ return ThrowNotImplemented("scrollUntilBottom");
1378
+ });
1379
+ }
1380
+ scrollUpOneScreen() {
1381
+ return __async(this, null, function*() {
1382
+ return ThrowNotImplemented("scrollUpOneScreen");
1383
+ });
1384
+ }
1385
+ scrollDownOneScreen() {
1386
+ return __async(this, null, function*() {
1387
+ return ThrowNotImplemented("scrollDownOneScreen");
1388
+ });
1389
+ }
1390
+ clearInput() {
1391
+ return __async(this, null, function*() {
1392
+ return ThrowNotImplemented("clearInput");
1393
+ });
1394
+ }
1395
+ _forceUsePageContext() {
1396
+ return __async(this, null, function*() {
1397
+ return this.uiContext;
1398
+ });
1399
+ }
1400
+ destroy() {
1401
+ return __async(this, null, function*() {});
1402
+ }
1403
+ constructor(uiContext){
1404
+ this.pageType = "static";
1405
+ this.mouse = {
1406
+ click: ThrowNotImplemented.bind(null, "mouse.click"),
1407
+ wheel: ThrowNotImplemented.bind(null, "mouse.wheel"),
1408
+ move: ThrowNotImplemented.bind(null, "mouse.move")
1409
+ };
1410
+ this.keyboard = {
1411
+ type: ThrowNotImplemented.bind(null, "keyboard.type"),
1412
+ press: ThrowNotImplemented.bind(null, "keyboard.press")
1413
+ };
1414
+ this.uiContext = uiContext;
1415
+ }
1416
+ };
1417
+ });