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