@midscene/core 0.8.16 → 0.8.17-beta-20250103065754.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/README.md +1 -1
- package/dist/lib/ai-model.js +1441 -348
- package/dist/lib/env.js +3 -0
- package/dist/lib/index.js +1443 -350
- package/dist/lib/types/ai-model.d.ts +3 -3
- package/dist/lib/types/{index-43fd19f4.d.ts → automation-1fa20bde.d.ts} +21 -44
- package/dist/lib/types/env.d.ts +2 -1
- package/dist/lib/types/index.d.ts +4 -4
- package/dist/lib/types/{types-55182ae1.d.ts → types-7702c41a.d.ts} +5 -16
- package/dist/lib/types/utils.d.ts +1 -1
- package/dist/lib/utils.js +1 -1
- package/package.json +8 -7
- package/report/index.html +14 -6
package/dist/lib/ai-model.js
CHANGED
|
@@ -33,6 +33,1046 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
|
|
|
33
33
|
));
|
|
34
34
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
35
35
|
|
|
36
|
+
// ../../node_modules/.pnpm/lex@1.7.9/node_modules/lex/lexer.js
|
|
37
|
+
var require_lexer = __commonJS({
|
|
38
|
+
"../../node_modules/.pnpm/lex@1.7.9/node_modules/lex/lexer.js"(exports, module2) {
|
|
39
|
+
"use strict";
|
|
40
|
+
if (typeof module2 === "object" && typeof module2.exports === "object")
|
|
41
|
+
module2.exports = Lexer;
|
|
42
|
+
Lexer.defunct = function(chr) {
|
|
43
|
+
throw new Error("Unexpected character at index " + (this.index - 1) + ": " + chr);
|
|
44
|
+
};
|
|
45
|
+
function Lexer(defunct) {
|
|
46
|
+
if (typeof defunct !== "function")
|
|
47
|
+
defunct = Lexer.defunct;
|
|
48
|
+
var tokens = [];
|
|
49
|
+
var rules = [];
|
|
50
|
+
var remove = 0;
|
|
51
|
+
this.state = 0;
|
|
52
|
+
this.index = 0;
|
|
53
|
+
this.input = "";
|
|
54
|
+
this.addRule = function(pattern, action, start) {
|
|
55
|
+
var global = pattern.global;
|
|
56
|
+
if (!global) {
|
|
57
|
+
var flags = "g";
|
|
58
|
+
if (pattern.multiline)
|
|
59
|
+
flags += "m";
|
|
60
|
+
if (pattern.ignoreCase)
|
|
61
|
+
flags += "i";
|
|
62
|
+
pattern = new RegExp(pattern.source, flags);
|
|
63
|
+
}
|
|
64
|
+
if (Object.prototype.toString.call(start) !== "[object Array]")
|
|
65
|
+
start = [0];
|
|
66
|
+
rules.push({
|
|
67
|
+
pattern,
|
|
68
|
+
global,
|
|
69
|
+
action,
|
|
70
|
+
start
|
|
71
|
+
});
|
|
72
|
+
return this;
|
|
73
|
+
};
|
|
74
|
+
this.setInput = function(input) {
|
|
75
|
+
remove = 0;
|
|
76
|
+
this.state = 0;
|
|
77
|
+
this.index = 0;
|
|
78
|
+
tokens.length = 0;
|
|
79
|
+
this.input = input;
|
|
80
|
+
return this;
|
|
81
|
+
};
|
|
82
|
+
this.lex = function() {
|
|
83
|
+
if (tokens.length)
|
|
84
|
+
return tokens.shift();
|
|
85
|
+
this.reject = true;
|
|
86
|
+
while (this.index <= this.input.length) {
|
|
87
|
+
var matches = scan.call(this).splice(remove);
|
|
88
|
+
var index = this.index;
|
|
89
|
+
while (matches.length) {
|
|
90
|
+
if (this.reject) {
|
|
91
|
+
var match = matches.shift();
|
|
92
|
+
var result = match.result;
|
|
93
|
+
var length = match.length;
|
|
94
|
+
this.index += length;
|
|
95
|
+
this.reject = false;
|
|
96
|
+
remove++;
|
|
97
|
+
var token = match.action.apply(this, result);
|
|
98
|
+
if (this.reject)
|
|
99
|
+
this.index = result.index;
|
|
100
|
+
else if (typeof token !== "undefined") {
|
|
101
|
+
switch (Object.prototype.toString.call(token)) {
|
|
102
|
+
case "[object Array]":
|
|
103
|
+
tokens = token.slice(1);
|
|
104
|
+
token = token[0];
|
|
105
|
+
default:
|
|
106
|
+
if (length)
|
|
107
|
+
remove = 0;
|
|
108
|
+
return token;
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
} else
|
|
112
|
+
break;
|
|
113
|
+
}
|
|
114
|
+
var input = this.input;
|
|
115
|
+
if (index < input.length) {
|
|
116
|
+
if (this.reject) {
|
|
117
|
+
remove = 0;
|
|
118
|
+
var token = defunct.call(this, input.charAt(this.index++));
|
|
119
|
+
if (typeof token !== "undefined") {
|
|
120
|
+
if (Object.prototype.toString.call(token) === "[object Array]") {
|
|
121
|
+
tokens = token.slice(1);
|
|
122
|
+
return token[0];
|
|
123
|
+
} else
|
|
124
|
+
return token;
|
|
125
|
+
}
|
|
126
|
+
} else {
|
|
127
|
+
if (this.index !== index)
|
|
128
|
+
remove = 0;
|
|
129
|
+
this.reject = true;
|
|
130
|
+
}
|
|
131
|
+
} else if (matches.length)
|
|
132
|
+
this.reject = true;
|
|
133
|
+
else
|
|
134
|
+
break;
|
|
135
|
+
}
|
|
136
|
+
};
|
|
137
|
+
function scan() {
|
|
138
|
+
var matches = [];
|
|
139
|
+
var index = 0;
|
|
140
|
+
var state = this.state;
|
|
141
|
+
var lastIndex = this.index;
|
|
142
|
+
var input = this.input;
|
|
143
|
+
for (var i = 0, length = rules.length; i < length; i++) {
|
|
144
|
+
var rule = rules[i];
|
|
145
|
+
var start = rule.start;
|
|
146
|
+
var states = start.length;
|
|
147
|
+
if (!states || start.indexOf(state) >= 0 || state % 2 && states === 1 && !start[0]) {
|
|
148
|
+
var pattern = rule.pattern;
|
|
149
|
+
pattern.lastIndex = lastIndex;
|
|
150
|
+
var result = pattern.exec(input);
|
|
151
|
+
if (result && result.index === lastIndex) {
|
|
152
|
+
var j = matches.push({
|
|
153
|
+
result,
|
|
154
|
+
action: rule.action,
|
|
155
|
+
length: result[0].length
|
|
156
|
+
});
|
|
157
|
+
if (rule.global)
|
|
158
|
+
index = j;
|
|
159
|
+
while (--j > index) {
|
|
160
|
+
var k = j - 1;
|
|
161
|
+
if (matches[j].length > matches[k].length) {
|
|
162
|
+
var temple = matches[j];
|
|
163
|
+
matches[j] = matches[k];
|
|
164
|
+
matches[k] = temple;
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
return matches;
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
});
|
|
175
|
+
|
|
176
|
+
// ../../node_modules/.pnpm/string.fromcodepoint@0.2.1/node_modules/string.fromcodepoint/fromcodepoint.js
|
|
177
|
+
var require_fromcodepoint = __commonJS({
|
|
178
|
+
"../../node_modules/.pnpm/string.fromcodepoint@0.2.1/node_modules/string.fromcodepoint/fromcodepoint.js"() {
|
|
179
|
+
"use strict";
|
|
180
|
+
if (!String.fromCodePoint) {
|
|
181
|
+
(function() {
|
|
182
|
+
var defineProperty = function() {
|
|
183
|
+
try {
|
|
184
|
+
var object = {};
|
|
185
|
+
var $defineProperty = Object.defineProperty;
|
|
186
|
+
var result = $defineProperty(object, object, object) && $defineProperty;
|
|
187
|
+
} catch (error) {
|
|
188
|
+
}
|
|
189
|
+
return result;
|
|
190
|
+
}();
|
|
191
|
+
var stringFromCharCode = String.fromCharCode;
|
|
192
|
+
var floor = Math.floor;
|
|
193
|
+
var fromCodePoint = function(_) {
|
|
194
|
+
var MAX_SIZE = 16384;
|
|
195
|
+
var codeUnits = [];
|
|
196
|
+
var highSurrogate;
|
|
197
|
+
var lowSurrogate;
|
|
198
|
+
var index = -1;
|
|
199
|
+
var length = arguments.length;
|
|
200
|
+
if (!length) {
|
|
201
|
+
return "";
|
|
202
|
+
}
|
|
203
|
+
var result = "";
|
|
204
|
+
while (++index < length) {
|
|
205
|
+
var codePoint = Number(arguments[index]);
|
|
206
|
+
if (!isFinite(codePoint) || // `NaN`, `+Infinity`, or `-Infinity`
|
|
207
|
+
codePoint < 0 || // not a valid Unicode code point
|
|
208
|
+
codePoint > 1114111 || // not a valid Unicode code point
|
|
209
|
+
floor(codePoint) != codePoint) {
|
|
210
|
+
throw RangeError("Invalid code point: " + codePoint);
|
|
211
|
+
}
|
|
212
|
+
if (codePoint <= 65535) {
|
|
213
|
+
codeUnits.push(codePoint);
|
|
214
|
+
} else {
|
|
215
|
+
codePoint -= 65536;
|
|
216
|
+
highSurrogate = (codePoint >> 10) + 55296;
|
|
217
|
+
lowSurrogate = codePoint % 1024 + 56320;
|
|
218
|
+
codeUnits.push(highSurrogate, lowSurrogate);
|
|
219
|
+
}
|
|
220
|
+
if (index + 1 == length || codeUnits.length > MAX_SIZE) {
|
|
221
|
+
result += stringFromCharCode.apply(null, codeUnits);
|
|
222
|
+
codeUnits.length = 0;
|
|
223
|
+
}
|
|
224
|
+
}
|
|
225
|
+
return result;
|
|
226
|
+
};
|
|
227
|
+
if (defineProperty) {
|
|
228
|
+
defineProperty(String, "fromCodePoint", {
|
|
229
|
+
"value": fromCodePoint,
|
|
230
|
+
"configurable": true,
|
|
231
|
+
"writable": true
|
|
232
|
+
});
|
|
233
|
+
} else {
|
|
234
|
+
String.fromCodePoint = fromCodePoint;
|
|
235
|
+
}
|
|
236
|
+
})();
|
|
237
|
+
}
|
|
238
|
+
}
|
|
239
|
+
});
|
|
240
|
+
|
|
241
|
+
// ../../node_modules/.pnpm/unescape-js@1.1.4/node_modules/unescape-js/dist/index.js
|
|
242
|
+
var require_dist = __commonJS({
|
|
243
|
+
"../../node_modules/.pnpm/unescape-js@1.1.4/node_modules/unescape-js/dist/index.js"(exports, module2) {
|
|
244
|
+
"use strict";
|
|
245
|
+
Object.defineProperty(exports, "__esModule", {
|
|
246
|
+
value: true
|
|
247
|
+
});
|
|
248
|
+
exports.default = void 0;
|
|
249
|
+
require_fromcodepoint();
|
|
250
|
+
var jsEscapeRegex = /\\(u\{([0-9A-Fa-f]+)\}|u([0-9A-Fa-f]{4})|x([0-9A-Fa-f]{2})|([1-7][0-7]{0,2}|[0-7]{2,3})|(['"tbrnfv0\\]))|\\U([0-9A-Fa-f]{8})/g;
|
|
251
|
+
var usualEscapeSequences = {
|
|
252
|
+
"0": "\0",
|
|
253
|
+
"b": "\b",
|
|
254
|
+
"f": "\f",
|
|
255
|
+
"n": "\n",
|
|
256
|
+
"r": "\r",
|
|
257
|
+
"t": " ",
|
|
258
|
+
"v": "\v",
|
|
259
|
+
"'": "'",
|
|
260
|
+
'"': '"',
|
|
261
|
+
"\\": "\\"
|
|
262
|
+
};
|
|
263
|
+
var fromHex = function fromHex2(str) {
|
|
264
|
+
return String.fromCodePoint(parseInt(str, 16));
|
|
265
|
+
};
|
|
266
|
+
var fromOct = function fromOct2(str) {
|
|
267
|
+
return String.fromCodePoint(parseInt(str, 8));
|
|
268
|
+
};
|
|
269
|
+
var _default = function _default2(string) {
|
|
270
|
+
return string.replace(jsEscapeRegex, function(_, __, varHex, longHex, shortHex, octal, specialCharacter, python) {
|
|
271
|
+
if (varHex !== void 0) {
|
|
272
|
+
return fromHex(varHex);
|
|
273
|
+
} else if (longHex !== void 0) {
|
|
274
|
+
return fromHex(longHex);
|
|
275
|
+
} else if (shortHex !== void 0) {
|
|
276
|
+
return fromHex(shortHex);
|
|
277
|
+
} else if (octal !== void 0) {
|
|
278
|
+
return fromOct(octal);
|
|
279
|
+
} else if (python !== void 0) {
|
|
280
|
+
return fromHex(python);
|
|
281
|
+
} else {
|
|
282
|
+
return usualEscapeSequences[specialCharacter];
|
|
283
|
+
}
|
|
284
|
+
});
|
|
285
|
+
};
|
|
286
|
+
exports.default = _default;
|
|
287
|
+
module2.exports = exports.default;
|
|
288
|
+
}
|
|
289
|
+
});
|
|
290
|
+
|
|
291
|
+
// ../../node_modules/.pnpm/utf8@3.0.0/node_modules/utf8/utf8.js
|
|
292
|
+
var require_utf8 = __commonJS({
|
|
293
|
+
"../../node_modules/.pnpm/utf8@3.0.0/node_modules/utf8/utf8.js"(exports) {
|
|
294
|
+
"use strict";
|
|
295
|
+
(function(root) {
|
|
296
|
+
var stringFromCharCode = String.fromCharCode;
|
|
297
|
+
function ucs2decode(string) {
|
|
298
|
+
var output = [];
|
|
299
|
+
var counter = 0;
|
|
300
|
+
var length = string.length;
|
|
301
|
+
var value;
|
|
302
|
+
var extra;
|
|
303
|
+
while (counter < length) {
|
|
304
|
+
value = string.charCodeAt(counter++);
|
|
305
|
+
if (value >= 55296 && value <= 56319 && counter < length) {
|
|
306
|
+
extra = string.charCodeAt(counter++);
|
|
307
|
+
if ((extra & 64512) == 56320) {
|
|
308
|
+
output.push(((value & 1023) << 10) + (extra & 1023) + 65536);
|
|
309
|
+
} else {
|
|
310
|
+
output.push(value);
|
|
311
|
+
counter--;
|
|
312
|
+
}
|
|
313
|
+
} else {
|
|
314
|
+
output.push(value);
|
|
315
|
+
}
|
|
316
|
+
}
|
|
317
|
+
return output;
|
|
318
|
+
}
|
|
319
|
+
function ucs2encode(array) {
|
|
320
|
+
var length = array.length;
|
|
321
|
+
var index = -1;
|
|
322
|
+
var value;
|
|
323
|
+
var output = "";
|
|
324
|
+
while (++index < length) {
|
|
325
|
+
value = array[index];
|
|
326
|
+
if (value > 65535) {
|
|
327
|
+
value -= 65536;
|
|
328
|
+
output += stringFromCharCode(value >>> 10 & 1023 | 55296);
|
|
329
|
+
value = 56320 | value & 1023;
|
|
330
|
+
}
|
|
331
|
+
output += stringFromCharCode(value);
|
|
332
|
+
}
|
|
333
|
+
return output;
|
|
334
|
+
}
|
|
335
|
+
function checkScalarValue(codePoint) {
|
|
336
|
+
if (codePoint >= 55296 && codePoint <= 57343) {
|
|
337
|
+
throw Error(
|
|
338
|
+
"Lone surrogate U+" + codePoint.toString(16).toUpperCase() + " is not a scalar value"
|
|
339
|
+
);
|
|
340
|
+
}
|
|
341
|
+
}
|
|
342
|
+
function createByte(codePoint, shift) {
|
|
343
|
+
return stringFromCharCode(codePoint >> shift & 63 | 128);
|
|
344
|
+
}
|
|
345
|
+
function encodeCodePoint(codePoint) {
|
|
346
|
+
if ((codePoint & 4294967168) == 0) {
|
|
347
|
+
return stringFromCharCode(codePoint);
|
|
348
|
+
}
|
|
349
|
+
var symbol = "";
|
|
350
|
+
if ((codePoint & 4294965248) == 0) {
|
|
351
|
+
symbol = stringFromCharCode(codePoint >> 6 & 31 | 192);
|
|
352
|
+
} else if ((codePoint & 4294901760) == 0) {
|
|
353
|
+
checkScalarValue(codePoint);
|
|
354
|
+
symbol = stringFromCharCode(codePoint >> 12 & 15 | 224);
|
|
355
|
+
symbol += createByte(codePoint, 6);
|
|
356
|
+
} else if ((codePoint & 4292870144) == 0) {
|
|
357
|
+
symbol = stringFromCharCode(codePoint >> 18 & 7 | 240);
|
|
358
|
+
symbol += createByte(codePoint, 12);
|
|
359
|
+
symbol += createByte(codePoint, 6);
|
|
360
|
+
}
|
|
361
|
+
symbol += stringFromCharCode(codePoint & 63 | 128);
|
|
362
|
+
return symbol;
|
|
363
|
+
}
|
|
364
|
+
function utf8encode(string) {
|
|
365
|
+
var codePoints = ucs2decode(string);
|
|
366
|
+
var length = codePoints.length;
|
|
367
|
+
var index = -1;
|
|
368
|
+
var codePoint;
|
|
369
|
+
var byteString = "";
|
|
370
|
+
while (++index < length) {
|
|
371
|
+
codePoint = codePoints[index];
|
|
372
|
+
byteString += encodeCodePoint(codePoint);
|
|
373
|
+
}
|
|
374
|
+
return byteString;
|
|
375
|
+
}
|
|
376
|
+
function readContinuationByte() {
|
|
377
|
+
if (byteIndex >= byteCount) {
|
|
378
|
+
throw Error("Invalid byte index");
|
|
379
|
+
}
|
|
380
|
+
var continuationByte = byteArray[byteIndex] & 255;
|
|
381
|
+
byteIndex++;
|
|
382
|
+
if ((continuationByte & 192) == 128) {
|
|
383
|
+
return continuationByte & 63;
|
|
384
|
+
}
|
|
385
|
+
throw Error("Invalid continuation byte");
|
|
386
|
+
}
|
|
387
|
+
function decodeSymbol() {
|
|
388
|
+
var byte1;
|
|
389
|
+
var byte2;
|
|
390
|
+
var byte3;
|
|
391
|
+
var byte4;
|
|
392
|
+
var codePoint;
|
|
393
|
+
if (byteIndex > byteCount) {
|
|
394
|
+
throw Error("Invalid byte index");
|
|
395
|
+
}
|
|
396
|
+
if (byteIndex == byteCount) {
|
|
397
|
+
return false;
|
|
398
|
+
}
|
|
399
|
+
byte1 = byteArray[byteIndex] & 255;
|
|
400
|
+
byteIndex++;
|
|
401
|
+
if ((byte1 & 128) == 0) {
|
|
402
|
+
return byte1;
|
|
403
|
+
}
|
|
404
|
+
if ((byte1 & 224) == 192) {
|
|
405
|
+
byte2 = readContinuationByte();
|
|
406
|
+
codePoint = (byte1 & 31) << 6 | byte2;
|
|
407
|
+
if (codePoint >= 128) {
|
|
408
|
+
return codePoint;
|
|
409
|
+
} else {
|
|
410
|
+
throw Error("Invalid continuation byte");
|
|
411
|
+
}
|
|
412
|
+
}
|
|
413
|
+
if ((byte1 & 240) == 224) {
|
|
414
|
+
byte2 = readContinuationByte();
|
|
415
|
+
byte3 = readContinuationByte();
|
|
416
|
+
codePoint = (byte1 & 15) << 12 | byte2 << 6 | byte3;
|
|
417
|
+
if (codePoint >= 2048) {
|
|
418
|
+
checkScalarValue(codePoint);
|
|
419
|
+
return codePoint;
|
|
420
|
+
} else {
|
|
421
|
+
throw Error("Invalid continuation byte");
|
|
422
|
+
}
|
|
423
|
+
}
|
|
424
|
+
if ((byte1 & 248) == 240) {
|
|
425
|
+
byte2 = readContinuationByte();
|
|
426
|
+
byte3 = readContinuationByte();
|
|
427
|
+
byte4 = readContinuationByte();
|
|
428
|
+
codePoint = (byte1 & 7) << 18 | byte2 << 12 | byte3 << 6 | byte4;
|
|
429
|
+
if (codePoint >= 65536 && codePoint <= 1114111) {
|
|
430
|
+
return codePoint;
|
|
431
|
+
}
|
|
432
|
+
}
|
|
433
|
+
throw Error("Invalid UTF-8 detected");
|
|
434
|
+
}
|
|
435
|
+
var byteArray;
|
|
436
|
+
var byteCount;
|
|
437
|
+
var byteIndex;
|
|
438
|
+
function utf8decode(byteString) {
|
|
439
|
+
byteArray = ucs2decode(byteString);
|
|
440
|
+
byteCount = byteArray.length;
|
|
441
|
+
byteIndex = 0;
|
|
442
|
+
var codePoints = [];
|
|
443
|
+
var tmp;
|
|
444
|
+
while ((tmp = decodeSymbol()) !== false) {
|
|
445
|
+
codePoints.push(tmp);
|
|
446
|
+
}
|
|
447
|
+
return ucs2encode(codePoints);
|
|
448
|
+
}
|
|
449
|
+
root.version = "3.0.0";
|
|
450
|
+
root.encode = utf8encode;
|
|
451
|
+
root.decode = utf8decode;
|
|
452
|
+
})(typeof exports === "undefined" ? exports.utf8 = {} : exports);
|
|
453
|
+
}
|
|
454
|
+
});
|
|
455
|
+
|
|
456
|
+
// ../../node_modules/.pnpm/dirty-json@0.9.2/node_modules/dirty-json/lexer.js
|
|
457
|
+
var require_lexer2 = __commonJS({
|
|
458
|
+
"../../node_modules/.pnpm/dirty-json@0.9.2/node_modules/dirty-json/lexer.js"(exports, module2) {
|
|
459
|
+
"use strict";
|
|
460
|
+
var Lexer = require_lexer();
|
|
461
|
+
var unescapeJs = require_dist();
|
|
462
|
+
var utf8 = require_utf8();
|
|
463
|
+
var LEX_FLOAT = 6;
|
|
464
|
+
var LEX_INT = 7;
|
|
465
|
+
var LEX_QUOTE = 11;
|
|
466
|
+
var LEX_RB = 12;
|
|
467
|
+
var LEX_RCB = 13;
|
|
468
|
+
var LEX_TOKEN = 14;
|
|
469
|
+
var LEX_COLON = -1;
|
|
470
|
+
var LEX_COMMA = -2;
|
|
471
|
+
var LEX_LCB = -3;
|
|
472
|
+
var LEX_LB = -4;
|
|
473
|
+
var LEX_DOT = -5;
|
|
474
|
+
var lexSpc = [
|
|
475
|
+
[/\s*:\s*/, LEX_COLON],
|
|
476
|
+
[/\s*,\s*/, LEX_COMMA],
|
|
477
|
+
[/\s*{\s*/, LEX_LCB],
|
|
478
|
+
[/\s*}\s*/, LEX_RCB],
|
|
479
|
+
[/\s*\[\s*/, LEX_LB],
|
|
480
|
+
[/\s*\]\s*/, LEX_RB],
|
|
481
|
+
[/\s*\.\s*/, LEX_DOT]
|
|
482
|
+
// TODO: remove?
|
|
483
|
+
];
|
|
484
|
+
function parseString(str) {
|
|
485
|
+
str = str.replace(/\\\//, "/");
|
|
486
|
+
return unescapeJs(str);
|
|
487
|
+
}
|
|
488
|
+
function getLexer(string) {
|
|
489
|
+
let lexer = new Lexer();
|
|
490
|
+
let col = 0;
|
|
491
|
+
let row = 0;
|
|
492
|
+
lexer.addRule(/"((?:\\.|[^"])*?)($|")/, (lexeme, txt) => {
|
|
493
|
+
col += lexeme.length;
|
|
494
|
+
return { type: LEX_QUOTE, value: parseString(txt), row, col, single: false };
|
|
495
|
+
});
|
|
496
|
+
lexer.addRule(/'((?:\\.|[^'])*?)($|'|(",?[ \t]*\n))/, (lexeme, txt) => {
|
|
497
|
+
col += lexeme.length;
|
|
498
|
+
return { type: LEX_QUOTE, value: parseString(txt), row, col, single: true };
|
|
499
|
+
});
|
|
500
|
+
lexer.addRule(/[\-0-9]*\.[0-9]*([eE][\+\-]?)?[0-9]*(?:\s*)/, (lexeme) => {
|
|
501
|
+
col += lexeme.length;
|
|
502
|
+
return { type: LEX_FLOAT, value: parseFloat(lexeme), row, col };
|
|
503
|
+
});
|
|
504
|
+
lexer.addRule(/\-?[0-9]+([eE][\+\-]?)[0-9]*(?:\s*)/, (lexeme) => {
|
|
505
|
+
col += lexeme.length;
|
|
506
|
+
return { type: LEX_FLOAT, value: parseFloat(lexeme), row, col };
|
|
507
|
+
});
|
|
508
|
+
lexer.addRule(/\-?[0-9]+(?:\s*)/, (lexeme) => {
|
|
509
|
+
col += lexeme.length;
|
|
510
|
+
return { type: LEX_INT, value: parseInt(lexeme), row, col };
|
|
511
|
+
});
|
|
512
|
+
lexSpc.forEach((item) => {
|
|
513
|
+
lexer.addRule(item[0], (lexeme) => {
|
|
514
|
+
col += lexeme.length;
|
|
515
|
+
return { type: item[1], value: lexeme, row, col };
|
|
516
|
+
});
|
|
517
|
+
});
|
|
518
|
+
lexer.addRule(/\s/, (lexeme) => {
|
|
519
|
+
if (lexeme == "\n") {
|
|
520
|
+
col = 0;
|
|
521
|
+
row++;
|
|
522
|
+
} else {
|
|
523
|
+
col += lexeme.length;
|
|
524
|
+
}
|
|
525
|
+
});
|
|
526
|
+
lexer.addRule(/\S[ \t]*/, (lexeme) => {
|
|
527
|
+
col += lexeme.length;
|
|
528
|
+
let lt = LEX_TOKEN;
|
|
529
|
+
let val = lexeme;
|
|
530
|
+
return { type: lt, value: val, row, col };
|
|
531
|
+
});
|
|
532
|
+
lexer.setInput(string);
|
|
533
|
+
return lexer;
|
|
534
|
+
}
|
|
535
|
+
module2.exports.lexString = lexString;
|
|
536
|
+
function lexString(str, emit) {
|
|
537
|
+
let lex = getLexer(str);
|
|
538
|
+
let token = "";
|
|
539
|
+
while (token = lex.lex()) {
|
|
540
|
+
emit(token);
|
|
541
|
+
}
|
|
542
|
+
}
|
|
543
|
+
module2.exports.getAllTokens = getAllTokens;
|
|
544
|
+
function getAllTokens(str) {
|
|
545
|
+
let arr = [];
|
|
546
|
+
let emit = function(i) {
|
|
547
|
+
arr.push(i);
|
|
548
|
+
};
|
|
549
|
+
lexString(str, emit);
|
|
550
|
+
return arr;
|
|
551
|
+
}
|
|
552
|
+
}
|
|
553
|
+
});
|
|
554
|
+
|
|
555
|
+
// ../../node_modules/.pnpm/dirty-json@0.9.2/node_modules/dirty-json/parser.js
|
|
556
|
+
var require_parser = __commonJS({
|
|
557
|
+
"../../node_modules/.pnpm/dirty-json@0.9.2/node_modules/dirty-json/parser.js"(exports, module2) {
|
|
558
|
+
"use strict";
|
|
559
|
+
var lexer = require_lexer2();
|
|
560
|
+
var LEX_KV = 0;
|
|
561
|
+
var LEX_KVLIST = 1;
|
|
562
|
+
var LEX_VLIST = 2;
|
|
563
|
+
var LEX_BOOLEAN = 3;
|
|
564
|
+
var LEX_COVALUE = 4;
|
|
565
|
+
var LEX_CVALUE = 5;
|
|
566
|
+
var LEX_FLOAT = 6;
|
|
567
|
+
var LEX_INT = 7;
|
|
568
|
+
var LEX_KEY = 8;
|
|
569
|
+
var LEX_LIST = 9;
|
|
570
|
+
var LEX_OBJ = 10;
|
|
571
|
+
var LEX_QUOTE = 11;
|
|
572
|
+
var LEX_RB = 12;
|
|
573
|
+
var LEX_RCB = 13;
|
|
574
|
+
var LEX_TOKEN = 14;
|
|
575
|
+
var LEX_VALUE = 15;
|
|
576
|
+
var LEX_COLON = -1;
|
|
577
|
+
var LEX_COMMA = -2;
|
|
578
|
+
var LEX_LCB = -3;
|
|
579
|
+
var LEX_LB = -4;
|
|
580
|
+
function extendArray(arr) {
|
|
581
|
+
if (arr.peek == null) {
|
|
582
|
+
Object.defineProperty(arr, "peek", {
|
|
583
|
+
enumerable: false,
|
|
584
|
+
value: function() {
|
|
585
|
+
return this[this.length - 1];
|
|
586
|
+
}
|
|
587
|
+
});
|
|
588
|
+
}
|
|
589
|
+
if (arr.last == null) {
|
|
590
|
+
Object.defineProperty(arr, "last", {
|
|
591
|
+
enumerable: false,
|
|
592
|
+
value: function(i) {
|
|
593
|
+
return this[this.length - (1 + i)];
|
|
594
|
+
}
|
|
595
|
+
});
|
|
596
|
+
}
|
|
597
|
+
}
|
|
598
|
+
function is(obj, prop) {
|
|
599
|
+
return obj && obj.hasOwnProperty("type") && obj.type == prop;
|
|
600
|
+
}
|
|
601
|
+
function log(str) {
|
|
602
|
+
}
|
|
603
|
+
module2.exports.parse = parse;
|
|
604
|
+
function parse(text, dupKeys) {
|
|
605
|
+
let stack = [];
|
|
606
|
+
let tokens = [];
|
|
607
|
+
extendArray(stack);
|
|
608
|
+
extendArray(tokens);
|
|
609
|
+
let emit = function(t) {
|
|
610
|
+
tokens.push(t);
|
|
611
|
+
};
|
|
612
|
+
lexer.lexString(text, emit);
|
|
613
|
+
if (tokens[0].type == LEX_LB && tokens.last(0).type != LEX_RB) {
|
|
614
|
+
tokens.push({ type: LEX_RB, value: "]", row: -1, col: -1 });
|
|
615
|
+
}
|
|
616
|
+
if (tokens[0].type == LEX_LCB && tokens.last(0).type != LEX_RCB) {
|
|
617
|
+
tokens.push({ type: LEX_RCB, value: "}", row: -1, col: -1 });
|
|
618
|
+
}
|
|
619
|
+
for (let i = 0; i < tokens.length; i++) {
|
|
620
|
+
log("Shifting " + tokens[i].type);
|
|
621
|
+
stack.push(tokens[i]);
|
|
622
|
+
log(stack);
|
|
623
|
+
log("Reducing...");
|
|
624
|
+
while (reduce(stack)) {
|
|
625
|
+
log(stack);
|
|
626
|
+
log("Reducing...");
|
|
627
|
+
}
|
|
628
|
+
}
|
|
629
|
+
if (stack.length == 1 && stack[0].type == LEX_KVLIST) {
|
|
630
|
+
log("Pre-compile error fix 1");
|
|
631
|
+
stack = [{ type: LEX_OBJ, value: stack[0].value }];
|
|
632
|
+
}
|
|
633
|
+
return compileOST(stack[0], dupKeys);
|
|
634
|
+
}
|
|
635
|
+
function reduce(stack) {
|
|
636
|
+
let next = stack.pop();
|
|
637
|
+
switch (next.type) {
|
|
638
|
+
case LEX_KEY:
|
|
639
|
+
if (next.value.trim() == "true") {
|
|
640
|
+
log("Rule 5");
|
|
641
|
+
stack.push({ "type": LEX_BOOLEAN, "value": "true" });
|
|
642
|
+
return true;
|
|
643
|
+
}
|
|
644
|
+
if (next.value.trim() == "false") {
|
|
645
|
+
log("Rule 6");
|
|
646
|
+
stack.push({ "type": LEX_BOOLEAN, "value": "false" });
|
|
647
|
+
return true;
|
|
648
|
+
}
|
|
649
|
+
if (next.value.trim() == "null") {
|
|
650
|
+
log("Rule 7");
|
|
651
|
+
stack.push({ "type": LEX_VALUE, "value": null });
|
|
652
|
+
return true;
|
|
653
|
+
}
|
|
654
|
+
break;
|
|
655
|
+
case LEX_TOKEN:
|
|
656
|
+
if (is(stack.peek(), LEX_KEY)) {
|
|
657
|
+
log("Rule 11a");
|
|
658
|
+
stack.peek().value += next.value;
|
|
659
|
+
return true;
|
|
660
|
+
}
|
|
661
|
+
log("Rule 11c");
|
|
662
|
+
stack.push({ type: LEX_KEY, value: next.value });
|
|
663
|
+
return true;
|
|
664
|
+
case LEX_INT:
|
|
665
|
+
if (is(next, LEX_INT) && is(stack.peek(), LEX_KEY)) {
|
|
666
|
+
log("Rule 11b");
|
|
667
|
+
stack.peek().value += next.value;
|
|
668
|
+
return true;
|
|
669
|
+
}
|
|
670
|
+
log("Rule 11f");
|
|
671
|
+
next.type = LEX_VALUE;
|
|
672
|
+
stack.push(next);
|
|
673
|
+
return true;
|
|
674
|
+
case LEX_QUOTE:
|
|
675
|
+
log("Rule 11d");
|
|
676
|
+
next.type = LEX_VALUE;
|
|
677
|
+
next.value = next.value;
|
|
678
|
+
stack.push(next);
|
|
679
|
+
return true;
|
|
680
|
+
case LEX_BOOLEAN:
|
|
681
|
+
log("Rule 11e");
|
|
682
|
+
next.type = LEX_VALUE;
|
|
683
|
+
if (next.value == "true") {
|
|
684
|
+
next.value = true;
|
|
685
|
+
} else {
|
|
686
|
+
next.value = false;
|
|
687
|
+
}
|
|
688
|
+
stack.push(next);
|
|
689
|
+
return true;
|
|
690
|
+
case LEX_FLOAT:
|
|
691
|
+
log("Rule 11g");
|
|
692
|
+
next.type = LEX_VALUE;
|
|
693
|
+
stack.push(next);
|
|
694
|
+
return true;
|
|
695
|
+
case LEX_VALUE:
|
|
696
|
+
if (is(stack.peek(), LEX_COMMA)) {
|
|
697
|
+
log("Rule 12");
|
|
698
|
+
next.type = LEX_CVALUE;
|
|
699
|
+
stack.pop();
|
|
700
|
+
stack.push(next);
|
|
701
|
+
return true;
|
|
702
|
+
}
|
|
703
|
+
if (is(stack.peek(), LEX_COLON)) {
|
|
704
|
+
log("Rule 13");
|
|
705
|
+
next.type = LEX_COVALUE;
|
|
706
|
+
stack.pop();
|
|
707
|
+
stack.push(next);
|
|
708
|
+
return true;
|
|
709
|
+
}
|
|
710
|
+
if (is(stack.peek(), LEX_KEY) && is(stack.last(1), LEX_VALUE)) {
|
|
711
|
+
log("Error rule 1");
|
|
712
|
+
let middleVal = stack.pop();
|
|
713
|
+
stack.peek().value += '"' + middleVal.value + '"';
|
|
714
|
+
stack.peek().value += next.value;
|
|
715
|
+
return true;
|
|
716
|
+
}
|
|
717
|
+
if (is(stack.peek(), LEX_KEY) && is(stack.last(1), LEX_VLIST)) {
|
|
718
|
+
log("Error rule 2");
|
|
719
|
+
let middleVal = stack.pop();
|
|
720
|
+
let oldLastVal = stack.peek().value.pop();
|
|
721
|
+
oldLastVal += '"' + middleVal.value + '"';
|
|
722
|
+
oldLastVal += next.value;
|
|
723
|
+
stack.peek().value.push(oldLastVal);
|
|
724
|
+
return true;
|
|
725
|
+
}
|
|
726
|
+
if (is(stack.peek(), LEX_KEY) && is(stack.last(1), LEX_KVLIST)) {
|
|
727
|
+
log("Error rule 3");
|
|
728
|
+
let middleVal = stack.pop();
|
|
729
|
+
let oldLastVal = stack.peek().value.pop();
|
|
730
|
+
const qChar = next.single ? "'" : '"';
|
|
731
|
+
oldLastVal.value += qChar + middleVal.value + qChar;
|
|
732
|
+
oldLastVal.value += next.value;
|
|
733
|
+
stack.peek().value.push(oldLastVal);
|
|
734
|
+
return true;
|
|
735
|
+
}
|
|
736
|
+
if (is(stack.peek(), LEX_KEY)) {
|
|
737
|
+
log("Error rule 4");
|
|
738
|
+
let keyValue = stack.pop().value;
|
|
739
|
+
next.value = keyValue + next.value;
|
|
740
|
+
stack.push(next);
|
|
741
|
+
return true;
|
|
742
|
+
}
|
|
743
|
+
break;
|
|
744
|
+
case LEX_LIST:
|
|
745
|
+
if (is(next, LEX_LIST) && is(stack.peek(), LEX_COMMA)) {
|
|
746
|
+
log("Rule 12a");
|
|
747
|
+
next.type = LEX_CVALUE;
|
|
748
|
+
stack.pop();
|
|
749
|
+
stack.push(next);
|
|
750
|
+
return true;
|
|
751
|
+
}
|
|
752
|
+
if (is(stack.peek(), LEX_COLON)) {
|
|
753
|
+
log("Rule 13a");
|
|
754
|
+
next.type = LEX_COVALUE;
|
|
755
|
+
stack.pop();
|
|
756
|
+
stack.push(next);
|
|
757
|
+
return true;
|
|
758
|
+
}
|
|
759
|
+
break;
|
|
760
|
+
case LEX_OBJ:
|
|
761
|
+
if (is(stack.peek(), LEX_COMMA)) {
|
|
762
|
+
log("Rule 12b");
|
|
763
|
+
let toPush = { "type": LEX_CVALUE, "value": next };
|
|
764
|
+
stack.pop();
|
|
765
|
+
stack.push(toPush);
|
|
766
|
+
return true;
|
|
767
|
+
}
|
|
768
|
+
if (is(stack.peek(), LEX_COLON)) {
|
|
769
|
+
log("Rule 13b");
|
|
770
|
+
let toPush = { "type": LEX_COVALUE, "value": next };
|
|
771
|
+
stack.pop();
|
|
772
|
+
stack.push(toPush);
|
|
773
|
+
return true;
|
|
774
|
+
}
|
|
775
|
+
if (is(stack.peek(), LEX_KEY)) {
|
|
776
|
+
log("Error rule 9");
|
|
777
|
+
let key = stack.pop();
|
|
778
|
+
stack.push({ "type": LEX_KV, "key": key.value.trim(), "value": next });
|
|
779
|
+
return true;
|
|
780
|
+
}
|
|
781
|
+
break;
|
|
782
|
+
case LEX_CVALUE:
|
|
783
|
+
if (is(stack.peek(), LEX_VLIST)) {
|
|
784
|
+
log("Rule 14");
|
|
785
|
+
stack.peek().value.push(next.value);
|
|
786
|
+
return true;
|
|
787
|
+
}
|
|
788
|
+
log("Rule 15");
|
|
789
|
+
stack.push({ "type": LEX_VLIST, "value": [next.value] });
|
|
790
|
+
return true;
|
|
791
|
+
case LEX_VLIST:
|
|
792
|
+
if (is(stack.peek(), LEX_VALUE)) {
|
|
793
|
+
log("Rule 15a");
|
|
794
|
+
next.value.unshift(stack.peek().value);
|
|
795
|
+
stack.pop();
|
|
796
|
+
stack.push(next);
|
|
797
|
+
return true;
|
|
798
|
+
}
|
|
799
|
+
if (is(stack.peek(), LEX_LIST)) {
|
|
800
|
+
log("Rule 15b");
|
|
801
|
+
next.value.unshift(stack.peek().value);
|
|
802
|
+
stack.pop();
|
|
803
|
+
stack.push(next);
|
|
804
|
+
return true;
|
|
805
|
+
}
|
|
806
|
+
if (is(stack.peek(), LEX_OBJ)) {
|
|
807
|
+
log("Rule 15c");
|
|
808
|
+
next.value.unshift(stack.peek());
|
|
809
|
+
stack.pop();
|
|
810
|
+
stack.push(next);
|
|
811
|
+
return true;
|
|
812
|
+
}
|
|
813
|
+
if (is(stack.peek(), LEX_KEY) && (stack.last(1), LEX_COMMA)) {
|
|
814
|
+
log("Error rule 7");
|
|
815
|
+
let l = stack.pop();
|
|
816
|
+
stack.push({ type: LEX_VALUE, "value": l.value });
|
|
817
|
+
log("Start subreduce... (" + l.value + ")");
|
|
818
|
+
while (reduce(stack))
|
|
819
|
+
;
|
|
820
|
+
log("End subreduce");
|
|
821
|
+
stack.push(next);
|
|
822
|
+
return true;
|
|
823
|
+
}
|
|
824
|
+
if (is(stack.peek(), LEX_VLIST)) {
|
|
825
|
+
log("Error rule 8");
|
|
826
|
+
stack.peek().value.push(next.value[0]);
|
|
827
|
+
return true;
|
|
828
|
+
}
|
|
829
|
+
break;
|
|
830
|
+
case LEX_COVALUE:
|
|
831
|
+
if (is(stack.peek(), LEX_KEY) || is(stack.peek(), LEX_VALUE) || is(stack.peek(), LEX_VLIST)) {
|
|
832
|
+
log("Rule 16");
|
|
833
|
+
let key = stack.pop();
|
|
834
|
+
stack.push({ "type": LEX_KV, "key": key.value, "value": next.value });
|
|
835
|
+
return true;
|
|
836
|
+
}
|
|
837
|
+
throw new Error("Got a :value that can't be handled at line " + next.row + ":" + next.col);
|
|
838
|
+
case LEX_KV:
|
|
839
|
+
if (is(stack.last(0), LEX_COMMA) && is(stack.last(1), LEX_KVLIST)) {
|
|
840
|
+
log("Rule 17");
|
|
841
|
+
stack.last(1).value.push(next);
|
|
842
|
+
stack.pop();
|
|
843
|
+
return true;
|
|
844
|
+
}
|
|
845
|
+
log("Rule 18");
|
|
846
|
+
stack.push({ "type": LEX_KVLIST, "value": [next] });
|
|
847
|
+
return true;
|
|
848
|
+
case LEX_KVLIST:
|
|
849
|
+
if (is(stack.peek(), LEX_KVLIST)) {
|
|
850
|
+
log("Rule 17a");
|
|
851
|
+
next.value.forEach(function(i) {
|
|
852
|
+
stack.peek().value.push(i);
|
|
853
|
+
});
|
|
854
|
+
return true;
|
|
855
|
+
}
|
|
856
|
+
break;
|
|
857
|
+
case LEX_RB:
|
|
858
|
+
if (is(stack.peek(), LEX_VLIST) && is(stack.last(1), LEX_LB)) {
|
|
859
|
+
log("Rule 19");
|
|
860
|
+
let l = stack.pop();
|
|
861
|
+
stack.pop();
|
|
862
|
+
stack.push({ "type": LEX_LIST, "value": l.value });
|
|
863
|
+
return true;
|
|
864
|
+
}
|
|
865
|
+
if (is(stack.peek(), LEX_LIST) && is(stack.last(1), LEX_LB)) {
|
|
866
|
+
log("Rule 19b");
|
|
867
|
+
let l = stack.pop();
|
|
868
|
+
stack.pop();
|
|
869
|
+
stack.push({ "type": LEX_LIST, "value": [l.value] });
|
|
870
|
+
return true;
|
|
871
|
+
}
|
|
872
|
+
if (is(stack.peek(), LEX_LB)) {
|
|
873
|
+
log("Rule 22");
|
|
874
|
+
stack.pop();
|
|
875
|
+
stack.push({ type: LEX_LIST, "value": [] });
|
|
876
|
+
return true;
|
|
877
|
+
}
|
|
878
|
+
if (is(stack.peek(), LEX_VALUE) && is(stack.last(1), LEX_LB)) {
|
|
879
|
+
log("Rule 23");
|
|
880
|
+
let val = stack.pop().value;
|
|
881
|
+
stack.pop();
|
|
882
|
+
stack.push({ type: LEX_LIST, "value": [val] });
|
|
883
|
+
return true;
|
|
884
|
+
}
|
|
885
|
+
if (is(stack.peek(), LEX_OBJ) && is(stack.last(1), LEX_LB)) {
|
|
886
|
+
log("Rule 23b");
|
|
887
|
+
let val = stack.pop();
|
|
888
|
+
stack.pop();
|
|
889
|
+
stack.push({ type: LEX_LIST, "value": [val] });
|
|
890
|
+
return true;
|
|
891
|
+
}
|
|
892
|
+
if (is(stack.peek(), LEX_KEY) && is(stack.last(1), LEX_COMMA)) {
|
|
893
|
+
log("Error rule 5");
|
|
894
|
+
let l = stack.pop();
|
|
895
|
+
stack.push({ type: LEX_VALUE, "value": l.value });
|
|
896
|
+
log("Start subreduce... (" + l.value + ")");
|
|
897
|
+
while (reduce(stack))
|
|
898
|
+
;
|
|
899
|
+
log("End subreduce");
|
|
900
|
+
stack.push({ type: LEX_RB });
|
|
901
|
+
return true;
|
|
902
|
+
}
|
|
903
|
+
if (is(stack.peek(), LEX_COMMA) && (is(stack.last(1), LEX_KEY) || is(stack.last(1), LEX_OBJ) || is(stack.last(1), LEX_VALUE))) {
|
|
904
|
+
log("Error rule 5a");
|
|
905
|
+
stack.pop();
|
|
906
|
+
stack.push({ type: LEX_RB, "value": "]" });
|
|
907
|
+
log("Start subreduce...");
|
|
908
|
+
log("Content: " + JSON.stringify(stack));
|
|
909
|
+
while (reduce(stack))
|
|
910
|
+
;
|
|
911
|
+
log("End subreduce");
|
|
912
|
+
return true;
|
|
913
|
+
}
|
|
914
|
+
if (is(stack.peek(), LEX_KEY) && is(stack.last(1), LEX_LB)) {
|
|
915
|
+
log("Error rule 5b");
|
|
916
|
+
let v = stack.pop();
|
|
917
|
+
stack.pop();
|
|
918
|
+
stack.push({ type: LEX_LIST, value: [v.value] });
|
|
919
|
+
return true;
|
|
920
|
+
}
|
|
921
|
+
if (is(stack.peek(), LEX_COMMA) && is(stack.last(1), LEX_VLIST)) {
|
|
922
|
+
log("Error rule 5c");
|
|
923
|
+
stack.pop();
|
|
924
|
+
stack.push({ type: LEX_RB });
|
|
925
|
+
log("Start subreduce...");
|
|
926
|
+
log("Content: " + JSON.stringify(stack));
|
|
927
|
+
while (reduce(stack))
|
|
928
|
+
;
|
|
929
|
+
log("End subreduce");
|
|
930
|
+
return true;
|
|
931
|
+
}
|
|
932
|
+
break;
|
|
933
|
+
case LEX_RCB:
|
|
934
|
+
if (is(stack.peek(), LEX_KVLIST) && is(stack.last(1), LEX_LCB)) {
|
|
935
|
+
log("Rule 20");
|
|
936
|
+
let l = stack.pop();
|
|
937
|
+
stack.pop();
|
|
938
|
+
stack.push({ "type": LEX_OBJ, "value": l.value });
|
|
939
|
+
return true;
|
|
940
|
+
}
|
|
941
|
+
if (is(stack.peek(), LEX_LCB)) {
|
|
942
|
+
log("Rule 21");
|
|
943
|
+
stack.pop();
|
|
944
|
+
stack.push({ type: LEX_OBJ, "value": null });
|
|
945
|
+
return true;
|
|
946
|
+
}
|
|
947
|
+
if (is(stack.peek(), LEX_KEY) && is(stack.last(1), LEX_COLON)) {
|
|
948
|
+
log("Error rule 4a");
|
|
949
|
+
let l = stack.pop();
|
|
950
|
+
stack.push({ type: LEX_VALUE, "value": l.value });
|
|
951
|
+
log("Start subreduce... (" + l.value + ")");
|
|
952
|
+
while (reduce(stack))
|
|
953
|
+
;
|
|
954
|
+
log("End subreduce");
|
|
955
|
+
stack.push({ type: LEX_RCB });
|
|
956
|
+
return true;
|
|
957
|
+
}
|
|
958
|
+
if (is(stack.peek(), LEX_COLON)) {
|
|
959
|
+
log("Error rule 4b");
|
|
960
|
+
stack.push({ type: LEX_VALUE, value: null });
|
|
961
|
+
log("Starting subreduce...");
|
|
962
|
+
while (reduce(stack))
|
|
963
|
+
;
|
|
964
|
+
log("End subreduce.");
|
|
965
|
+
stack.push({ type: LEX_RCB });
|
|
966
|
+
return true;
|
|
967
|
+
}
|
|
968
|
+
if (is(stack.peek(), LEX_COMMA)) {
|
|
969
|
+
log("Error rule 10a");
|
|
970
|
+
stack.pop();
|
|
971
|
+
stack.push({ type: LEX_RCB });
|
|
972
|
+
return true;
|
|
973
|
+
}
|
|
974
|
+
throw new Error("Found } that I can't handle at line " + next.row + ":" + next.col);
|
|
975
|
+
case LEX_COMMA:
|
|
976
|
+
if (is(stack.peek(), LEX_COMMA)) {
|
|
977
|
+
log("Comma error rule 1");
|
|
978
|
+
return true;
|
|
979
|
+
}
|
|
980
|
+
if (is(stack.peek(), LEX_KEY)) {
|
|
981
|
+
log("Comma error rule 2");
|
|
982
|
+
const key = stack.pop();
|
|
983
|
+
stack.push({ type: LEX_VALUE, value: key.value });
|
|
984
|
+
log("Starting subreduce...");
|
|
985
|
+
while (reduce(stack))
|
|
986
|
+
;
|
|
987
|
+
log("End subreduce.");
|
|
988
|
+
stack.push(next);
|
|
989
|
+
return true;
|
|
990
|
+
}
|
|
991
|
+
if (is(stack.peek(), LEX_COLON)) {
|
|
992
|
+
log("Comma error rule 3");
|
|
993
|
+
stack.push({ type: LEX_VALUE, value: null });
|
|
994
|
+
log("Starting subreduce...");
|
|
995
|
+
while (reduce(stack))
|
|
996
|
+
;
|
|
997
|
+
log("End subreduce.");
|
|
998
|
+
stack.push(next);
|
|
999
|
+
return true;
|
|
1000
|
+
}
|
|
1001
|
+
}
|
|
1002
|
+
stack.push(next);
|
|
1003
|
+
return false;
|
|
1004
|
+
}
|
|
1005
|
+
function compileOST(tree, dupKeys) {
|
|
1006
|
+
let rawTypes = ["boolean", "number", "string"];
|
|
1007
|
+
if (rawTypes.indexOf(typeof tree) != -1)
|
|
1008
|
+
return tree;
|
|
1009
|
+
if (tree === null)
|
|
1010
|
+
return null;
|
|
1011
|
+
if (Array.isArray(tree)) {
|
|
1012
|
+
let toR = [];
|
|
1013
|
+
while (tree.length > 0)
|
|
1014
|
+
toR.unshift(compileOST(tree.pop()));
|
|
1015
|
+
return toR;
|
|
1016
|
+
}
|
|
1017
|
+
if (is(tree, LEX_OBJ)) {
|
|
1018
|
+
let toR = {};
|
|
1019
|
+
if (tree.value === null)
|
|
1020
|
+
return {};
|
|
1021
|
+
tree.value.forEach(function(i) {
|
|
1022
|
+
const key = i.key;
|
|
1023
|
+
const val = compileOST(i.value);
|
|
1024
|
+
if (dupKeys && key in toR) {
|
|
1025
|
+
toR[key] = {
|
|
1026
|
+
"value": toR[key],
|
|
1027
|
+
"next": val
|
|
1028
|
+
};
|
|
1029
|
+
} else {
|
|
1030
|
+
toR[key] = val;
|
|
1031
|
+
}
|
|
1032
|
+
});
|
|
1033
|
+
return toR;
|
|
1034
|
+
}
|
|
1035
|
+
if (is(tree, LEX_LIST)) {
|
|
1036
|
+
return compileOST(tree.value);
|
|
1037
|
+
}
|
|
1038
|
+
return tree.value;
|
|
1039
|
+
}
|
|
1040
|
+
}
|
|
1041
|
+
});
|
|
1042
|
+
|
|
1043
|
+
// ../../node_modules/.pnpm/dirty-json@0.9.2/node_modules/dirty-json/dirty-json.js
|
|
1044
|
+
var require_dirty_json = __commonJS({
|
|
1045
|
+
"../../node_modules/.pnpm/dirty-json@0.9.2/node_modules/dirty-json/dirty-json.js"(exports, module2) {
|
|
1046
|
+
"use strict";
|
|
1047
|
+
var parser = require_parser();
|
|
1048
|
+
module2.exports.parse = parse;
|
|
1049
|
+
function parse(text, config) {
|
|
1050
|
+
let fallback = true;
|
|
1051
|
+
let duplicateKeys = false;
|
|
1052
|
+
if (config) {
|
|
1053
|
+
if ("fallback" in config && config[fallback] === false) {
|
|
1054
|
+
fallback = false;
|
|
1055
|
+
}
|
|
1056
|
+
duplicateKeys = "duplicateKeys" in config && config["duplicateKeys"] === true;
|
|
1057
|
+
}
|
|
1058
|
+
try {
|
|
1059
|
+
return parser.parse(text, duplicateKeys);
|
|
1060
|
+
} catch (e) {
|
|
1061
|
+
if (fallback === false) {
|
|
1062
|
+
throw e;
|
|
1063
|
+
}
|
|
1064
|
+
try {
|
|
1065
|
+
let json = JSON.parse(text);
|
|
1066
|
+
console.warn("dirty-json got valid JSON that failed with the custom parser. We're returning the valid JSON, but please file a bug report here: https://github.com/RyanMarcus/dirty-json/issues -- the JSON that caused the failure was: " + text);
|
|
1067
|
+
return json;
|
|
1068
|
+
} catch (json_error) {
|
|
1069
|
+
throw e;
|
|
1070
|
+
}
|
|
1071
|
+
}
|
|
1072
|
+
}
|
|
1073
|
+
}
|
|
1074
|
+
});
|
|
1075
|
+
|
|
36
1076
|
// ../../node_modules/.pnpm/uuid@9.0.1/node_modules/uuid/dist/esm-node/rng.js
|
|
37
1077
|
function rng() {
|
|
38
1078
|
if (poolPtr > rnds8Pool.length - 16) {
|
|
@@ -763,7 +1803,7 @@ var require_priority_queue = __commonJS({
|
|
|
763
1803
|
});
|
|
764
1804
|
|
|
765
1805
|
// ../../node_modules/.pnpm/p-queue@6.6.2/node_modules/p-queue/dist/index.js
|
|
766
|
-
var
|
|
1806
|
+
var require_dist2 = __commonJS({
|
|
767
1807
|
"../../node_modules/.pnpm/p-queue@6.6.2/node_modules/p-queue/dist/index.js"(exports) {
|
|
768
1808
|
"use strict";
|
|
769
1809
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
@@ -1033,13 +2073,13 @@ var require_dist = __commonJS({
|
|
|
1033
2073
|
}
|
|
1034
2074
|
});
|
|
1035
2075
|
|
|
1036
|
-
// ../../node_modules/.pnpm/langsmith@0.1.
|
|
2076
|
+
// ../../node_modules/.pnpm/langsmith@0.1.36_@langchain+core@0.3.26_openai@4.57.1_zod@3.23.8___langchain@0.3.8_@langchain_hhfvzcdxxvt4fjst2j6ox4bwsa/node_modules/langsmith/dist/utils/async_caller.js
|
|
1037
2077
|
var import_p_retry, import_p_queue, STATUS_NO_RETRY, STATUS_IGNORE, AsyncCaller;
|
|
1038
2078
|
var init_async_caller = __esm({
|
|
1039
|
-
"../../node_modules/.pnpm/langsmith@0.1.
|
|
2079
|
+
"../../node_modules/.pnpm/langsmith@0.1.36_@langchain+core@0.3.26_openai@4.57.1_zod@3.23.8___langchain@0.3.8_@langchain_hhfvzcdxxvt4fjst2j6ox4bwsa/node_modules/langsmith/dist/utils/async_caller.js"() {
|
|
1040
2080
|
"use strict";
|
|
1041
2081
|
import_p_retry = __toESM(require_p_retry());
|
|
1042
|
-
import_p_queue = __toESM(
|
|
2082
|
+
import_p_queue = __toESM(require_dist2());
|
|
1043
2083
|
STATUS_NO_RETRY = [
|
|
1044
2084
|
400,
|
|
1045
2085
|
// Bad Request
|
|
@@ -1158,7 +2198,7 @@ var init_async_caller = __esm({
|
|
|
1158
2198
|
}
|
|
1159
2199
|
});
|
|
1160
2200
|
|
|
1161
|
-
// ../../node_modules/.pnpm/langsmith@0.1.
|
|
2201
|
+
// ../../node_modules/.pnpm/langsmith@0.1.36_@langchain+core@0.3.26_openai@4.57.1_zod@3.23.8___langchain@0.3.8_@langchain_hhfvzcdxxvt4fjst2j6ox4bwsa/node_modules/langsmith/dist/utils/messages.js
|
|
1162
2202
|
function isLangChainMessage(message) {
|
|
1163
2203
|
return typeof (message == null ? void 0 : message._getType) === "function";
|
|
1164
2204
|
}
|
|
@@ -1173,25 +2213,25 @@ function convertLangChainMessageToExample(message) {
|
|
|
1173
2213
|
return converted;
|
|
1174
2214
|
}
|
|
1175
2215
|
var init_messages = __esm({
|
|
1176
|
-
"../../node_modules/.pnpm/langsmith@0.1.
|
|
2216
|
+
"../../node_modules/.pnpm/langsmith@0.1.36_@langchain+core@0.3.26_openai@4.57.1_zod@3.23.8___langchain@0.3.8_@langchain_hhfvzcdxxvt4fjst2j6ox4bwsa/node_modules/langsmith/dist/utils/messages.js"() {
|
|
1177
2217
|
"use strict";
|
|
1178
2218
|
}
|
|
1179
2219
|
});
|
|
1180
2220
|
|
|
1181
|
-
// ../../node_modules/.pnpm/langsmith@0.1.
|
|
2221
|
+
// ../../node_modules/.pnpm/langsmith@0.1.36_@langchain+core@0.3.26_openai@4.57.1_zod@3.23.8___langchain@0.3.8_@langchain_hhfvzcdxxvt4fjst2j6ox4bwsa/node_modules/langsmith/dist/utils/_uuid.js
|
|
1182
2222
|
function assertUuid(str) {
|
|
1183
2223
|
if (!validate_default(str)) {
|
|
1184
2224
|
throw new Error(`Invalid UUID: ${str}`);
|
|
1185
2225
|
}
|
|
1186
2226
|
}
|
|
1187
2227
|
var init_uuid = __esm({
|
|
1188
|
-
"../../node_modules/.pnpm/langsmith@0.1.
|
|
2228
|
+
"../../node_modules/.pnpm/langsmith@0.1.36_@langchain+core@0.3.26_openai@4.57.1_zod@3.23.8___langchain@0.3.8_@langchain_hhfvzcdxxvt4fjst2j6ox4bwsa/node_modules/langsmith/dist/utils/_uuid.js"() {
|
|
1189
2229
|
"use strict";
|
|
1190
2230
|
init_esm_node();
|
|
1191
2231
|
}
|
|
1192
2232
|
});
|
|
1193
2233
|
|
|
1194
|
-
// ../../node_modules/.pnpm/langsmith@0.1.
|
|
2234
|
+
// ../../node_modules/.pnpm/langsmith@0.1.36_@langchain+core@0.3.26_openai@4.57.1_zod@3.23.8___langchain@0.3.8_@langchain_hhfvzcdxxvt4fjst2j6ox4bwsa/node_modules/langsmith/dist/utils/warn.js
|
|
1195
2235
|
function warnOnce(message) {
|
|
1196
2236
|
if (!warnedMessages[message]) {
|
|
1197
2237
|
console.warn(message);
|
|
@@ -1200,13 +2240,13 @@ function warnOnce(message) {
|
|
|
1200
2240
|
}
|
|
1201
2241
|
var warnedMessages;
|
|
1202
2242
|
var init_warn = __esm({
|
|
1203
|
-
"../../node_modules/.pnpm/langsmith@0.1.
|
|
2243
|
+
"../../node_modules/.pnpm/langsmith@0.1.36_@langchain+core@0.3.26_openai@4.57.1_zod@3.23.8___langchain@0.3.8_@langchain_hhfvzcdxxvt4fjst2j6ox4bwsa/node_modules/langsmith/dist/utils/warn.js"() {
|
|
1204
2244
|
"use strict";
|
|
1205
2245
|
warnedMessages = {};
|
|
1206
2246
|
}
|
|
1207
2247
|
});
|
|
1208
2248
|
|
|
1209
|
-
// ../../node_modules/.pnpm/langsmith@0.1.
|
|
2249
|
+
// ../../node_modules/.pnpm/langsmith@0.1.36_@langchain+core@0.3.26_openai@4.57.1_zod@3.23.8___langchain@0.3.8_@langchain_hhfvzcdxxvt4fjst2j6ox4bwsa/node_modules/langsmith/dist/client.js
|
|
1210
2250
|
async function mergeRuntimeEnvIntoRunCreates(runs) {
|
|
1211
2251
|
const runtimeEnv = await getRuntimeEnvironment();
|
|
1212
2252
|
const envVars = getLangChainEnvVarsMetadata();
|
|
@@ -1244,7 +2284,7 @@ function trimQuotes(str) {
|
|
|
1244
2284
|
}
|
|
1245
2285
|
var getTracingSamplingRate, isLocalhost, raiseForStatus, handle429, Queue, DEFAULT_BATCH_SIZE_LIMIT_BYTES, Client;
|
|
1246
2286
|
var init_client = __esm({
|
|
1247
|
-
"../../node_modules/.pnpm/langsmith@0.1.
|
|
2287
|
+
"../../node_modules/.pnpm/langsmith@0.1.36_@langchain+core@0.3.26_openai@4.57.1_zod@3.23.8___langchain@0.3.8_@langchain_hhfvzcdxxvt4fjst2j6ox4bwsa/node_modules/langsmith/dist/client.js"() {
|
|
1248
2288
|
"use strict";
|
|
1249
2289
|
init_esm_node();
|
|
1250
2290
|
init_async_caller();
|
|
@@ -3005,10 +4045,10 @@ var init_client = __esm({
|
|
|
3005
4045
|
}
|
|
3006
4046
|
});
|
|
3007
4047
|
|
|
3008
|
-
// ../../node_modules/.pnpm/langsmith@0.1.
|
|
4048
|
+
// ../../node_modules/.pnpm/langsmith@0.1.36_@langchain+core@0.3.26_openai@4.57.1_zod@3.23.8___langchain@0.3.8_@langchain_hhfvzcdxxvt4fjst2j6ox4bwsa/node_modules/langsmith/dist/index.js
|
|
3009
4049
|
var __version__;
|
|
3010
4050
|
var init_dist = __esm({
|
|
3011
|
-
"../../node_modules/.pnpm/langsmith@0.1.
|
|
4051
|
+
"../../node_modules/.pnpm/langsmith@0.1.36_@langchain+core@0.3.26_openai@4.57.1_zod@3.23.8___langchain@0.3.8_@langchain_hhfvzcdxxvt4fjst2j6ox4bwsa/node_modules/langsmith/dist/index.js"() {
|
|
3012
4052
|
"use strict";
|
|
3013
4053
|
init_client();
|
|
3014
4054
|
init_run_trees();
|
|
@@ -3016,7 +4056,7 @@ var init_dist = __esm({
|
|
|
3016
4056
|
}
|
|
3017
4057
|
});
|
|
3018
4058
|
|
|
3019
|
-
// ../../node_modules/.pnpm/langsmith@0.1.
|
|
4059
|
+
// ../../node_modules/.pnpm/langsmith@0.1.36_@langchain+core@0.3.26_openai@4.57.1_zod@3.23.8___langchain@0.3.8_@langchain_hhfvzcdxxvt4fjst2j6ox4bwsa/node_modules/langsmith/dist/utils/env.js
|
|
3020
4060
|
async function getRuntimeEnvironment() {
|
|
3021
4061
|
if (runtimeEnvironment === void 0) {
|
|
3022
4062
|
const env = getEnv();
|
|
@@ -3113,7 +4153,7 @@ function getShas() {
|
|
|
3113
4153
|
}
|
|
3114
4154
|
var globalEnv, isBrowser, isWebWorker, isJsDom, isDeno, isNode, getEnv, runtimeEnvironment, cachedCommitSHAs;
|
|
3115
4155
|
var init_env = __esm({
|
|
3116
|
-
"../../node_modules/.pnpm/langsmith@0.1.
|
|
4156
|
+
"../../node_modules/.pnpm/langsmith@0.1.36_@langchain+core@0.3.26_openai@4.57.1_zod@3.23.8___langchain@0.3.8_@langchain_hhfvzcdxxvt4fjst2j6ox4bwsa/node_modules/langsmith/dist/utils/env.js"() {
|
|
3117
4157
|
"use strict";
|
|
3118
4158
|
init_dist();
|
|
3119
4159
|
isBrowser = () => typeof window !== "undefined" && typeof window.document !== "undefined";
|
|
@@ -3143,10 +4183,10 @@ var init_env = __esm({
|
|
|
3143
4183
|
}
|
|
3144
4184
|
});
|
|
3145
4185
|
|
|
3146
|
-
// ../../node_modules/.pnpm/langsmith@0.1.
|
|
4186
|
+
// ../../node_modules/.pnpm/langsmith@0.1.36_@langchain+core@0.3.26_openai@4.57.1_zod@3.23.8___langchain@0.3.8_@langchain_hhfvzcdxxvt4fjst2j6ox4bwsa/node_modules/langsmith/dist/env.js
|
|
3147
4187
|
var isTracingEnabled;
|
|
3148
4188
|
var init_env2 = __esm({
|
|
3149
|
-
"../../node_modules/.pnpm/langsmith@0.1.
|
|
4189
|
+
"../../node_modules/.pnpm/langsmith@0.1.36_@langchain+core@0.3.26_openai@4.57.1_zod@3.23.8___langchain@0.3.8_@langchain_hhfvzcdxxvt4fjst2j6ox4bwsa/node_modules/langsmith/dist/env.js"() {
|
|
3150
4190
|
"use strict";
|
|
3151
4191
|
init_env();
|
|
3152
4192
|
isTracingEnabled = (tracingEnabled) => {
|
|
@@ -3164,7 +4204,7 @@ var init_env2 = __esm({
|
|
|
3164
4204
|
}
|
|
3165
4205
|
});
|
|
3166
4206
|
|
|
3167
|
-
// ../../node_modules/.pnpm/langsmith@0.1.
|
|
4207
|
+
// ../../node_modules/.pnpm/langsmith@0.1.36_@langchain+core@0.3.26_openai@4.57.1_zod@3.23.8___langchain@0.3.8_@langchain_hhfvzcdxxvt4fjst2j6ox4bwsa/node_modules/langsmith/dist/run_trees.js
|
|
3168
4208
|
function stripNonAlphanumeric(input) {
|
|
3169
4209
|
return input.replace(/[-:.]/g, "");
|
|
3170
4210
|
}
|
|
@@ -3188,7 +4228,7 @@ function isRunnableConfigLike(x) {
|
|
|
3188
4228
|
}
|
|
3189
4229
|
var Baggage, RunTree;
|
|
3190
4230
|
var init_run_trees = __esm({
|
|
3191
|
-
"../../node_modules/.pnpm/langsmith@0.1.
|
|
4231
|
+
"../../node_modules/.pnpm/langsmith@0.1.36_@langchain+core@0.3.26_openai@4.57.1_zod@3.23.8___langchain@0.3.8_@langchain_hhfvzcdxxvt4fjst2j6ox4bwsa/node_modules/langsmith/dist/run_trees.js"() {
|
|
3192
4232
|
"use strict";
|
|
3193
4233
|
init_esm_node();
|
|
3194
4234
|
init_env();
|
|
@@ -3612,13 +4652,13 @@ var init_run_trees = __esm({
|
|
|
3612
4652
|
}
|
|
3613
4653
|
});
|
|
3614
4654
|
|
|
3615
|
-
// ../../node_modules/.pnpm/langsmith@0.1.
|
|
4655
|
+
// ../../node_modules/.pnpm/langsmith@0.1.36_@langchain+core@0.3.26_openai@4.57.1_zod@3.23.8___langchain@0.3.8_@langchain_hhfvzcdxxvt4fjst2j6ox4bwsa/node_modules/langsmith/dist/singletons/traceable.js
|
|
3616
4656
|
function isTraceableFunction(x) {
|
|
3617
4657
|
return typeof x === "function" && "langsmith:traceable" in x;
|
|
3618
4658
|
}
|
|
3619
4659
|
var MockAsyncLocalStorage, AsyncLocalStorageProvider, AsyncLocalStorageProviderSingleton, ROOT;
|
|
3620
4660
|
var init_traceable = __esm({
|
|
3621
|
-
"../../node_modules/.pnpm/langsmith@0.1.
|
|
4661
|
+
"../../node_modules/.pnpm/langsmith@0.1.36_@langchain+core@0.3.26_openai@4.57.1_zod@3.23.8___langchain@0.3.8_@langchain_hhfvzcdxxvt4fjst2j6ox4bwsa/node_modules/langsmith/dist/singletons/traceable.js"() {
|
|
3622
4662
|
"use strict";
|
|
3623
4663
|
MockAsyncLocalStorage = class {
|
|
3624
4664
|
getStore() {
|
|
@@ -3658,7 +4698,7 @@ var init_traceable = __esm({
|
|
|
3658
4698
|
}
|
|
3659
4699
|
});
|
|
3660
4700
|
|
|
3661
|
-
// ../../node_modules/.pnpm/langsmith@0.1.
|
|
4701
|
+
// ../../node_modules/.pnpm/langsmith@0.1.36_@langchain+core@0.3.26_openai@4.57.1_zod@3.23.8___langchain@0.3.8_@langchain_hhfvzcdxxvt4fjst2j6ox4bwsa/node_modules/langsmith/dist/utils/asserts.js
|
|
3662
4702
|
function isPromiseMethod(x) {
|
|
3663
4703
|
if (x === "then" || x === "catch" || x === "finally") {
|
|
3664
4704
|
return true;
|
|
@@ -3674,7 +4714,7 @@ function isKVMap(x) {
|
|
|
3674
4714
|
}
|
|
3675
4715
|
var isAsyncIterable, isIteratorLike, GeneratorFunction, isGenerator, isThenable, isReadableStream;
|
|
3676
4716
|
var init_asserts = __esm({
|
|
3677
|
-
"../../node_modules/.pnpm/langsmith@0.1.
|
|
4717
|
+
"../../node_modules/.pnpm/langsmith@0.1.36_@langchain+core@0.3.26_openai@4.57.1_zod@3.23.8___langchain@0.3.8_@langchain_hhfvzcdxxvt4fjst2j6ox4bwsa/node_modules/langsmith/dist/utils/asserts.js"() {
|
|
3678
4718
|
"use strict";
|
|
3679
4719
|
isAsyncIterable = (x) => x != null && typeof x === "object" && // eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
3680
4720
|
typeof x[Symbol.asyncIterator] === "function";
|
|
@@ -3690,7 +4730,7 @@ var init_asserts = __esm({
|
|
|
3690
4730
|
}
|
|
3691
4731
|
});
|
|
3692
4732
|
|
|
3693
|
-
// ../../node_modules/.pnpm/langsmith@0.1.
|
|
4733
|
+
// ../../node_modules/.pnpm/langsmith@0.1.36_@langchain+core@0.3.26_openai@4.57.1_zod@3.23.8___langchain@0.3.8_@langchain_hhfvzcdxxvt4fjst2j6ox4bwsa/node_modules/langsmith/dist/traceable.js
|
|
3694
4734
|
function traceable(wrappedFunc, config) {
|
|
3695
4735
|
const { aggregator, argsConfigPath, ...runTreeConfig } = config != null ? config : {};
|
|
3696
4736
|
const traceableFunc = (...args) => {
|
|
@@ -3888,7 +4928,7 @@ function traceable(wrappedFunc, config) {
|
|
|
3888
4928
|
}
|
|
3889
4929
|
var import_node_async_hooks, handleRunInputs, handleRunOutputs, getTracingRunTree, getSerializablePromise, convertSerializableArg;
|
|
3890
4930
|
var init_traceable2 = __esm({
|
|
3891
|
-
"../../node_modules/.pnpm/langsmith@0.1.
|
|
4931
|
+
"../../node_modules/.pnpm/langsmith@0.1.36_@langchain+core@0.3.26_openai@4.57.1_zod@3.23.8___langchain@0.3.8_@langchain_hhfvzcdxxvt4fjst2j6ox4bwsa/node_modules/langsmith/dist/traceable.js"() {
|
|
3892
4932
|
"use strict";
|
|
3893
4933
|
import_node_async_hooks = require("async_hooks");
|
|
3894
4934
|
init_run_trees();
|
|
@@ -4068,7 +5108,7 @@ var init_traceable2 = __esm({
|
|
|
4068
5108
|
}
|
|
4069
5109
|
});
|
|
4070
5110
|
|
|
4071
|
-
// ../../node_modules/.pnpm/langsmith@0.1.
|
|
5111
|
+
// ../../node_modules/.pnpm/langsmith@0.1.36_@langchain+core@0.3.26_openai@4.57.1_zod@3.23.8___langchain@0.3.8_@langchain_hhfvzcdxxvt4fjst2j6ox4bwsa/node_modules/langsmith/dist/wrappers/openai.js
|
|
4072
5112
|
function _combineChatCompletionChoices(choices) {
|
|
4073
5113
|
var _a, _b;
|
|
4074
5114
|
const reversedChoices = choices.slice().reverse();
|
|
@@ -4142,7 +5182,7 @@ function _combineChatCompletionChoices(choices) {
|
|
|
4142
5182
|
}
|
|
4143
5183
|
var chatAggregator, textAggregator, wrapOpenAI, _wrapClient, wrapSDK;
|
|
4144
5184
|
var init_openai = __esm({
|
|
4145
|
-
"../../node_modules/.pnpm/langsmith@0.1.
|
|
5185
|
+
"../../node_modules/.pnpm/langsmith@0.1.36_@langchain+core@0.3.26_openai@4.57.1_zod@3.23.8___langchain@0.3.8_@langchain_hhfvzcdxxvt4fjst2j6ox4bwsa/node_modules/langsmith/dist/wrappers/openai.js"() {
|
|
4146
5186
|
"use strict";
|
|
4147
5187
|
init_traceable2();
|
|
4148
5188
|
chatAggregator = (chunks) => {
|
|
@@ -4254,22 +5294,22 @@ var init_openai = __esm({
|
|
|
4254
5294
|
}
|
|
4255
5295
|
});
|
|
4256
5296
|
|
|
4257
|
-
// ../../node_modules/.pnpm/langsmith@0.1.
|
|
5297
|
+
// ../../node_modules/.pnpm/langsmith@0.1.36_@langchain+core@0.3.26_openai@4.57.1_zod@3.23.8___langchain@0.3.8_@langchain_hhfvzcdxxvt4fjst2j6ox4bwsa/node_modules/langsmith/dist/wrappers/index.js
|
|
4258
5298
|
var init_wrappers = __esm({
|
|
4259
|
-
"../../node_modules/.pnpm/langsmith@0.1.
|
|
5299
|
+
"../../node_modules/.pnpm/langsmith@0.1.36_@langchain+core@0.3.26_openai@4.57.1_zod@3.23.8___langchain@0.3.8_@langchain_hhfvzcdxxvt4fjst2j6ox4bwsa/node_modules/langsmith/dist/wrappers/index.js"() {
|
|
4260
5300
|
"use strict";
|
|
4261
5301
|
init_openai();
|
|
4262
5302
|
}
|
|
4263
5303
|
});
|
|
4264
5304
|
|
|
4265
|
-
// ../../node_modules/.pnpm/langsmith@0.1.
|
|
5305
|
+
// ../../node_modules/.pnpm/langsmith@0.1.36_@langchain+core@0.3.26_openai@4.57.1_zod@3.23.8___langchain@0.3.8_@langchain_hhfvzcdxxvt4fjst2j6ox4bwsa/node_modules/langsmith/wrappers.js
|
|
4266
5306
|
var wrappers_exports = {};
|
|
4267
5307
|
__export(wrappers_exports, {
|
|
4268
5308
|
wrapOpenAI: () => wrapOpenAI,
|
|
4269
5309
|
wrapSDK: () => wrapSDK
|
|
4270
5310
|
});
|
|
4271
5311
|
var init_wrappers2 = __esm({
|
|
4272
|
-
"../../node_modules/.pnpm/langsmith@0.1.
|
|
5312
|
+
"../../node_modules/.pnpm/langsmith@0.1.36_@langchain+core@0.3.26_openai@4.57.1_zod@3.23.8___langchain@0.3.8_@langchain_hhfvzcdxxvt4fjst2j6ox4bwsa/node_modules/langsmith/wrappers.js"() {
|
|
4273
5313
|
"use strict";
|
|
4274
5314
|
init_wrappers();
|
|
4275
5315
|
}
|
|
@@ -4295,7 +5335,7 @@ var import_node_assert3 = __toESM(require("assert"));
|
|
|
4295
5335
|
var import_sdk = require("@anthropic-ai/sdk");
|
|
4296
5336
|
var import_identity = require("@azure/identity");
|
|
4297
5337
|
var import_utils = require("@midscene/shared/utils");
|
|
4298
|
-
var import_dirty_json = __toESM(
|
|
5338
|
+
var import_dirty_json = __toESM(require_dirty_json());
|
|
4299
5339
|
var import_openai2 = __toESM(require("openai"));
|
|
4300
5340
|
var import_socks_proxy_agent = require("socks-proxy-agent");
|
|
4301
5341
|
|
|
@@ -4313,6 +5353,7 @@ var OPENAI_MAX_TOKENS = "OPENAI_MAX_TOKENS";
|
|
|
4313
5353
|
var MIDSCENE_MODEL_TEXT_ONLY = "MIDSCENE_MODEL_TEXT_ONLY";
|
|
4314
5354
|
var MIDSCENE_CACHE = "MIDSCENE_CACHE";
|
|
4315
5355
|
var MATCH_BY_POSITION = "MATCH_BY_POSITION";
|
|
5356
|
+
var MIDSCENE_API_TYPE = "MIDSCENE-API-TYPE";
|
|
4316
5357
|
var MIDSCENE_REPORT_TAG_NAME = "MIDSCENE_REPORT_TAG_NAME";
|
|
4317
5358
|
var MIDSCENE_USE_AZURE_OPENAI = "MIDSCENE_USE_AZURE_OPENAI";
|
|
4318
5359
|
var MIDSCENE_AZURE_OPENAI_SCOPE = "MIDSCENE_AZURE_OPENAI_SCOPE";
|
|
@@ -4375,8 +5416,7 @@ var getAIConfigInJson = (configKey) => {
|
|
|
4375
5416
|
|
|
4376
5417
|
// src/ai-model/common.ts
|
|
4377
5418
|
var import_node_assert = __toESM(require("assert"));
|
|
4378
|
-
async function callAiFn(
|
|
4379
|
-
const { msgs, AIActionType: AIActionTypeValue } = options;
|
|
5419
|
+
async function callAiFn(msgs, AIActionTypeValue) {
|
|
4380
5420
|
(0, import_node_assert.default)(
|
|
4381
5421
|
checkAIConfig(),
|
|
4382
5422
|
"Cannot find config for AI model service. You should set it before using. https://midscenejs.com/model-provider.html"
|
|
@@ -4387,19 +5427,9 @@ async function callAiFn(options) {
|
|
|
4387
5427
|
);
|
|
4388
5428
|
return { content, usage };
|
|
4389
5429
|
}
|
|
4390
|
-
function transformUserMessages(msgs) {
|
|
4391
|
-
const textOnly = Boolean(getAIConfig(MIDSCENE_MODEL_TEXT_ONLY));
|
|
4392
|
-
if (!textOnly)
|
|
4393
|
-
return msgs;
|
|
4394
|
-
return msgs.reduce((res, msg) => {
|
|
4395
|
-
if (msg.type === "text") {
|
|
4396
|
-
res += msg.text;
|
|
4397
|
-
}
|
|
4398
|
-
return res;
|
|
4399
|
-
}, "");
|
|
4400
|
-
}
|
|
4401
5430
|
|
|
4402
5431
|
// src/ai-model/prompt/element_inspector.ts
|
|
5432
|
+
var import_prompts = require("@langchain/core/prompts");
|
|
4403
5433
|
function systemPromptToFindElement() {
|
|
4404
5434
|
if (getAIConfig(MATCH_BY_POSITION)) {
|
|
4405
5435
|
return systemPromptToFindElementPosition();
|
|
@@ -4542,36 +5572,31 @@ Output Example:
|
|
|
4542
5572
|
}
|
|
4543
5573
|
function systemPromptToFindElementPosition() {
|
|
4544
5574
|
return `
|
|
4545
|
-
|
|
4546
|
-
You are an expert in software page image (2D) and page element text analysis.
|
|
5575
|
+
You are a GUI agent. You are given a task and your action history, with screenshots. You need to perform the next action to complete the task.
|
|
4547
5576
|
|
|
4548
|
-
|
|
4549
|
-
|
|
5577
|
+
## Output Format
|
|
5578
|
+
\`\`\`
|
|
5579
|
+
Action_Summary: ...
|
|
5580
|
+
Action: ...
|
|
5581
|
+
\`\`\`
|
|
4550
5582
|
|
|
4551
|
-
|
|
5583
|
+
## Action Space
|
|
5584
|
+
click(start_box='[x1, y1, x2, y2]')
|
|
5585
|
+
long_press(start_box='[x1, y1, x2, y2]', time='')
|
|
5586
|
+
type(content='')
|
|
5587
|
+
scroll(direction='down or up or right or left')
|
|
5588
|
+
open_app(app_name='')
|
|
5589
|
+
navigate_back()
|
|
5590
|
+
navigate_home()
|
|
5591
|
+
WAIT()
|
|
5592
|
+
finished() # Submit the task regardless of whether it succeeds or fails.
|
|
4552
5593
|
|
|
4553
|
-
|
|
5594
|
+
## Note
|
|
5595
|
+
- Use Chinese in \`Action_Summary\` part.
|
|
4554
5596
|
|
|
4555
|
-
|
|
4556
|
-
{
|
|
4557
|
-
"elements": [
|
|
4558
|
-
{
|
|
4559
|
-
// Describe the reason for finding this element, replace with actual value in practice
|
|
4560
|
-
"reason": "Reason for finding element 4: It is located in the upper right corner, is an image type, and according to the screenshot, it is a shopping cart icon button",
|
|
4561
|
-
// If the target element includes text information, extract the text information; if it does not, do not extract it
|
|
4562
|
-
"text": "",
|
|
4563
|
-
// position of this element
|
|
4564
|
-
"position": { x: number, y: number }
|
|
4565
|
-
}
|
|
4566
|
-
],
|
|
4567
|
-
"errors": []// Return an error if there is no target element on the picture
|
|
4568
|
-
}
|
|
4569
|
-
\`\`\`
|
|
5597
|
+
## User Instruction
|
|
4570
5598
|
`;
|
|
4571
5599
|
}
|
|
4572
|
-
function multiDescription(multi) {
|
|
4573
|
-
return multi ? "multiple elements matching the description (two or more)" : "The element closest to the description (only one)";
|
|
4574
|
-
}
|
|
4575
5600
|
var findElementSchema = {
|
|
4576
5601
|
type: "json_schema",
|
|
4577
5602
|
json_schema: {
|
|
@@ -4616,6 +5641,23 @@ var findElementSchema = {
|
|
|
4616
5641
|
}
|
|
4617
5642
|
}
|
|
4618
5643
|
};
|
|
5644
|
+
var findElementPrompt = new import_prompts.PromptTemplate({
|
|
5645
|
+
template: `
|
|
5646
|
+
Here is the item user want to find. Just go ahead:
|
|
5647
|
+
=====================================
|
|
5648
|
+
{{
|
|
5649
|
+
"description": "{targetElementDescription}",
|
|
5650
|
+
"multi": {multi}
|
|
5651
|
+
}}
|
|
5652
|
+
=====================================
|
|
5653
|
+
|
|
5654
|
+
pageDescription: {pageDescription}
|
|
5655
|
+
`,
|
|
5656
|
+
inputVariables: ["pageDescription", "targetElementDescription", "multi"]
|
|
5657
|
+
});
|
|
5658
|
+
|
|
5659
|
+
// src/ai-model/prompt/planning.ts
|
|
5660
|
+
var import_prompts3 = require("@langchain/core/prompts");
|
|
4619
5661
|
|
|
4620
5662
|
// src/ai-model/prompt/util.ts
|
|
4621
5663
|
var import_node_assert2 = __toESM(require("assert"));
|
|
@@ -4624,6 +5666,7 @@ var import_node_assert2 = __toESM(require("assert"));
|
|
|
4624
5666
|
var import_img = require("@midscene/shared/img");
|
|
4625
5667
|
|
|
4626
5668
|
// src/ai-model/prompt/util.ts
|
|
5669
|
+
var import_prompts2 = require("@langchain/core/prompts");
|
|
4627
5670
|
var characteristic = "You are a versatile professional in software UI design and testing. Your outstanding contributions will impact the user experience of billions of users.";
|
|
4628
5671
|
var contextFormatIntro = `
|
|
4629
5672
|
The user will give you a screenshot and some of the texts on it. There may be some none-English characters (like Chinese) on it, indicating it's an non-English app. If some text is shown on screenshot but not introduced by the JSON description, use the information you see on screenshot.`;
|
|
@@ -4652,6 +5695,22 @@ Return in the following JSON format:
|
|
|
4652
5695
|
}
|
|
4653
5696
|
`;
|
|
4654
5697
|
}
|
|
5698
|
+
var extractDataPrompt = new import_prompts2.PromptTemplate({
|
|
5699
|
+
template: `
|
|
5700
|
+
pageDescription: {pageDescription}
|
|
5701
|
+
|
|
5702
|
+
Use your extract_data_from_UI skill to find the following data, placing it in the \`data\` field
|
|
5703
|
+
DATA_DEMAND start:
|
|
5704
|
+
=====================================
|
|
5705
|
+
{dataKeys}
|
|
5706
|
+
|
|
5707
|
+
{dataQuery}
|
|
5708
|
+
|
|
5709
|
+
=====================================
|
|
5710
|
+
DATA_DEMAND ends.
|
|
5711
|
+
`,
|
|
5712
|
+
inputVariables: ["pageDescription", "dataKeys", "dataQuery"]
|
|
5713
|
+
});
|
|
4655
5714
|
function systemPromptToAssert() {
|
|
4656
5715
|
return `
|
|
4657
5716
|
${characteristic}
|
|
@@ -4700,7 +5759,7 @@ function truncateText(text, maxLength = 100) {
|
|
|
4700
5759
|
}
|
|
4701
5760
|
return "";
|
|
4702
5761
|
}
|
|
4703
|
-
function
|
|
5762
|
+
function elementByPositionWithElementInfo(elementsInfo, position) {
|
|
4704
5763
|
(0, import_node_assert2.default)(typeof position !== "undefined", "position is required for query");
|
|
4705
5764
|
const item = elementsInfo.find((item2) => {
|
|
4706
5765
|
return item2.rect.left <= position.x && position.x <= item2.rect.left + item2.rect.width && item2.rect.top <= position.y && position.y <= item2.rect.top + item2.rect.height;
|
|
@@ -4754,23 +5813,23 @@ async function describeUserPage(context, opt) {
|
|
|
4754
5813
|
const { id, ...rest } = item;
|
|
4755
5814
|
return `id=${id}: ${JSON.stringify(rest)}`;
|
|
4756
5815
|
}).join("\n\n");
|
|
5816
|
+
const pageJSONDescription = getAIConfig(MATCH_BY_POSITION) ? "" : `Some of the elements are marked with a rectangle in the screenshot, some are not.
|
|
5817
|
+
Json description of all the page elements:
|
|
5818
|
+
${contentList}`;
|
|
5819
|
+
const sizeDescription = describeSize({ width, height });
|
|
4757
5820
|
return {
|
|
4758
|
-
description: `
|
|
4759
|
-
|
|
4760
|
-
Some of the elements are marked with a rectangle in the screenshot, some are not.
|
|
4761
|
-
|
|
4762
|
-
${// if match by id, use the description of the element
|
|
4763
|
-
getAIConfig(MATCH_BY_POSITION) ? "" : `Json description of all the page elements:
|
|
4764
|
-
${contentList}`}
|
|
4765
|
-
`,
|
|
5821
|
+
description: `The size of the page: ${sizeDescription}
|
|
5822
|
+
${pageJSONDescription}`,
|
|
4766
5823
|
elementById(id) {
|
|
4767
5824
|
(0, import_node_assert2.default)(typeof id !== "undefined", "id is required for query");
|
|
4768
5825
|
const item = idElementMap[`${id}`];
|
|
4769
5826
|
return item;
|
|
4770
5827
|
},
|
|
4771
|
-
elementByPosition(position) {
|
|
4772
|
-
|
|
4773
|
-
|
|
5828
|
+
elementByPosition(position, size) {
|
|
5829
|
+
console.log("elementByPosition", { position, size });
|
|
5830
|
+
return elementByPositionWithElementInfo(elementsInfo, position);
|
|
5831
|
+
},
|
|
5832
|
+
size: { width, height }
|
|
4774
5833
|
};
|
|
4775
5834
|
}
|
|
4776
5835
|
function cropFieldInformation(elementsInfo, truncateTextLength, filterNonTextContent = false) {
|
|
@@ -4824,19 +5883,35 @@ function cropFieldInformation(elementsInfo, truncateTextLength, filterNonTextCon
|
|
|
4824
5883
|
// src/ai-model/prompt/planning.ts
|
|
4825
5884
|
var quickAnswerFormat = () => {
|
|
4826
5885
|
const matchByPosition = getAIConfig(MATCH_BY_POSITION);
|
|
4827
|
-
const
|
|
4828
|
-
|
|
4829
|
-
|
|
4830
|
-
|
|
4831
|
-
|
|
5886
|
+
const locationFormat = {
|
|
5887
|
+
position: {
|
|
5888
|
+
description: `"position": { x: number; y: number } // Represents the position of the element; replace with actual values in practice (ensure it reflects the element's position)`,
|
|
5889
|
+
format: '"position": { x: number; y: number }',
|
|
5890
|
+
sample: '{"prompt": "the search bar" // Use language consistent with the information on the page}',
|
|
5891
|
+
locateParam: `{
|
|
5892
|
+
"prompt"?: string // the description of the element to find. It can only be omitted when locate is null.
|
|
5893
|
+
} | null // If it's not on the page, the LocateParam should be null`
|
|
5894
|
+
},
|
|
5895
|
+
id: {
|
|
5896
|
+
description: '"id": string // Represents the ID of the element; replace with actual values in practice',
|
|
5897
|
+
format: '"id": string',
|
|
5898
|
+
sample: `{"id": "c81c4e9a33", "prompt": "the search bar"}`,
|
|
5899
|
+
locateParam: `{
|
|
5900
|
+
"id": string, // the id of the element found. It should either be the id marked with a rectangle in the screenshot or the id described in the description.
|
|
5901
|
+
"prompt"?: string // the description of the element to find. It can only be omitted when locate is null.
|
|
5902
|
+
} | null // If it's not on the page, the LocateParam should be null`
|
|
5903
|
+
}
|
|
5904
|
+
};
|
|
5905
|
+
const type = matchByPosition ? "position" : "id";
|
|
5906
|
+
const format = locationFormat[type];
|
|
4832
5907
|
return {
|
|
4833
|
-
description,
|
|
4834
|
-
format,
|
|
4835
|
-
sample
|
|
5908
|
+
description: format.description,
|
|
5909
|
+
format: format.format,
|
|
5910
|
+
sample: format.sample,
|
|
5911
|
+
locateParam: format.locateParam
|
|
4836
5912
|
};
|
|
4837
5913
|
};
|
|
4838
|
-
|
|
4839
|
-
return `
|
|
5914
|
+
var systemTemplate = `
|
|
4840
5915
|
## Role
|
|
4841
5916
|
|
|
4842
5917
|
You are a versatile professional in software UI automation. Your outstanding contributions will impact the user experience of billions of users.
|
|
@@ -4870,76 +5945,70 @@ You are a versatile professional in software UI automation. Your outstanding con
|
|
|
4870
5945
|
|
|
4871
5946
|
The \`locate\` param is commonly used in the \`param\` field of the action, means to locate the target element to perform the action, it follows the following scheme:
|
|
4872
5947
|
|
|
4873
|
-
type LocateParam = {
|
|
4874
|
-
"id": string, // the id of the element found. It should either be the id marked with a rectangle in the screenshot or the id described in the description.
|
|
4875
|
-
prompt?: string // the description of the element to find. It can only be omitted when locate is null.
|
|
4876
|
-
} | null // If it's not on the page, the LocateParam should be null
|
|
5948
|
+
type LocateParam = {locateParam}
|
|
4877
5949
|
|
|
4878
5950
|
### Supported actions
|
|
4879
5951
|
|
|
4880
5952
|
Each action has a \`type\` and corresponding \`param\`. To be detailed:
|
|
4881
5953
|
- type: 'Tap', tap the located element
|
|
4882
|
-
* { locate:
|
|
5954
|
+
* {{ locate: {sample}, param: null }}
|
|
4883
5955
|
- type: 'Hover', move mouse over to the located element
|
|
4884
|
-
* { locate: LocateParam, param: null }
|
|
5956
|
+
* {{ locate: LocateParam, param: null }}
|
|
4885
5957
|
- type: 'Input', replace the value in the input field
|
|
4886
|
-
* { locate: LocateParam, param: { value: string } }
|
|
5958
|
+
* {{ locate: LocateParam, param: {{ value: string }} }}
|
|
4887
5959
|
* \`value\` is the final required input value based on the existing input. No matter what modifications are required, just provide the final value to replace the existing input value.
|
|
4888
5960
|
- type: 'KeyboardPress', press a key
|
|
4889
|
-
* { param: { value: string } }
|
|
5961
|
+
* {{ param: {{ value: string }} }}
|
|
4890
5962
|
- type: 'Scroll', scroll up or down.
|
|
4891
|
-
* {
|
|
5963
|
+
* {{
|
|
4892
5964
|
locate: LocateParam | null,
|
|
4893
|
-
param: {
|
|
5965
|
+
param: {{
|
|
4894
5966
|
direction: 'down'(default) | 'up' | 'right' | 'left',
|
|
4895
5967
|
scrollType: 'once' (default) | 'untilBottom' | 'untilTop' | 'untilRight' | 'untilLeft',
|
|
4896
5968
|
distance: null | number
|
|
4897
|
-
}
|
|
4898
|
-
}
|
|
5969
|
+
}}
|
|
5970
|
+
}}
|
|
4899
5971
|
* To scroll some specific element, put the element at the center of the region in the \`locate\` field. If it's a page scroll, put \`null\` in the \`locate\` field.
|
|
4900
5972
|
* \`param\` is required in this action. If some fields are not specified, use direction \`down\`, \`once\` scroll type, and \`null\` distance.
|
|
4901
5973
|
- type: 'FalsyConditionStatement'
|
|
4902
|
-
* { param: null }
|
|
5974
|
+
* {{ param: null }}
|
|
4903
5975
|
* use this action when the instruction is an "if" statement and the condition is falsy.
|
|
4904
5976
|
- type: 'Sleep'
|
|
4905
|
-
* { param: { timeMs: number } }
|
|
5977
|
+
* {{ param: {{ timeMs: number }} }}
|
|
4906
5978
|
|
|
4907
5979
|
## How to compose the \`taskWillBeAccomplished\` and \`furtherPlan\` fields ?
|
|
4908
5980
|
|
|
4909
5981
|
\`taskWillBeAccomplished\` is a boolean field, means whether the task will be accomplished after all the actions.
|
|
4910
5982
|
|
|
4911
|
-
\`furtherPlan\` is used when the task cannot be accomplished. It follows the scheme { whatHaveDone: string, whatToDoNext: string }:
|
|
5983
|
+
\`furtherPlan\` is used when the task cannot be accomplished. It follows the scheme {{ whatHaveDone: string, whatToDoNext: string }}:
|
|
4912
5984
|
- \`whatHaveDone\`: a string, describe what have been done after the previous actions.
|
|
4913
5985
|
- \`whatToDoNext\`: a string, describe what should be done next after the previous actions has finished. It should be a concise and clear description of the actions to be performed. Make sure you don't lose any necessary steps user asked.
|
|
4914
|
-
|
|
5986
|
+
`;
|
|
5987
|
+
var outputTemplate = `
|
|
4915
5988
|
## Output JSON Format:
|
|
4916
5989
|
|
|
4917
5990
|
The JSON format is as follows:
|
|
4918
5991
|
|
|
4919
|
-
{
|
|
5992
|
+
{{
|
|
4920
5993
|
"actions": [
|
|
4921
|
-
{
|
|
5994
|
+
{{
|
|
4922
5995
|
"thought": "Reasons for generating this task, and why this task is feasible on this page",
|
|
4923
5996
|
"type": "Tap",
|
|
4924
5997
|
"param": null,
|
|
4925
|
-
"locate": {
|
|
4926
|
-
|
|
4927
|
-
prompt: "the search bar"
|
|
4928
|
-
} | null,
|
|
4929
|
-
},
|
|
5998
|
+
"locate": {sample} | null,
|
|
5999
|
+
}},
|
|
4930
6000
|
// ... more actions
|
|
4931
6001
|
],
|
|
4932
6002
|
"taskWillBeAccomplished": boolean,
|
|
4933
|
-
"furtherPlan": { "whatHaveDone": string, "whatToDoNext": string } | null,
|
|
6003
|
+
"furtherPlan": {{ "whatHaveDone": string, "whatToDoNext": string }} | null,
|
|
4934
6004
|
"error"?: string
|
|
4935
|
-
}
|
|
4936
|
-
|
|
4937
|
-
## Example #1 : How to decompose a task
|
|
6005
|
+
}}
|
|
6006
|
+
Here is an example of how to decompose a task:
|
|
4938
6007
|
|
|
4939
6008
|
When a user says 'Click the language switch button, wait 1s, click "English"', the user will give you the description like this:
|
|
4940
6009
|
|
|
4941
6010
|
====================
|
|
4942
|
-
|
|
6011
|
+
{pageDescription}
|
|
4943
6012
|
====================
|
|
4944
6013
|
|
|
4945
6014
|
By viewing the page screenshot and description, you should consider this and output the JSON:
|
|
@@ -4949,110 +6018,119 @@ By viewing the page screenshot and description, you should consider this and out
|
|
|
4949
6018
|
* The "English" option button is not shown in the screenshot now, it means it may only show after the previous actions are finished. So the last action will have a \`null\` value in the \`locate\` field.
|
|
4950
6019
|
* The task cannot be accomplished (because we cannot see the "English" option now), so a \`furtherPlan\` field is needed.
|
|
4951
6020
|
|
|
4952
|
-
{
|
|
6021
|
+
{{
|
|
4953
6022
|
"actions":[
|
|
4954
|
-
{
|
|
6023
|
+
{{
|
|
6024
|
+
"type": "Tap",
|
|
4955
6025
|
"thought": "Click the language switch button to open the language options.",
|
|
4956
|
-
"type": "Tap",
|
|
4957
6026
|
"param": null,
|
|
4958
|
-
"locate": {
|
|
4959
|
-
|
|
4960
|
-
|
|
4961
|
-
}
|
|
4962
|
-
},
|
|
4963
|
-
{
|
|
4964
|
-
"thought": "Wait for 1 second to ensure the language options are displayed.",
|
|
6027
|
+
"locate": {sample},
|
|
6028
|
+
}},
|
|
6029
|
+
{{
|
|
4965
6030
|
"type": "Sleep",
|
|
4966
|
-
"
|
|
4967
|
-
|
|
4968
|
-
|
|
4969
|
-
|
|
6031
|
+
"thought": "Wait for 1 second to ensure the language options are displayed.",
|
|
6032
|
+
"param": {{ "timeMs": 1000 }},
|
|
6033
|
+
}},
|
|
6034
|
+
{{
|
|
4970
6035
|
"type": "Tap",
|
|
4971
|
-
"
|
|
6036
|
+
"thought": "Locate the 'English' option in the language menu.",
|
|
6037
|
+
"param": null,
|
|
4972
6038
|
"locate": null
|
|
4973
|
-
},
|
|
6039
|
+
}},
|
|
4974
6040
|
],
|
|
4975
6041
|
"error": null,
|
|
4976
6042
|
"taskWillBeAccomplished": false,
|
|
4977
|
-
"furtherPlan": {
|
|
4978
|
-
"whatToDoNext": "find the 'English' option and click on it",
|
|
4979
|
-
"whatHaveDone": "Click the language switch button and wait 1s"
|
|
4980
|
-
}
|
|
4981
|
-
}
|
|
6043
|
+
"furtherPlan": {{
|
|
6044
|
+
"whatToDoNext": "find the 'English' option and click on it",
|
|
6045
|
+
"whatHaveDone": "Click the language switch button and wait 1s"
|
|
6046
|
+
}}
|
|
6047
|
+
}}
|
|
4982
6048
|
|
|
4983
|
-
|
|
6049
|
+
Here is another example of how to tolerate error situations only when the instruction is an "if" statement:
|
|
4984
6050
|
|
|
4985
6051
|
If the user says "If there is a popup, close it", you should consider this and output the JSON:
|
|
4986
6052
|
|
|
4987
6053
|
* By viewing the page screenshot and description, you cannot find the popup, so the condition is falsy.
|
|
4988
6054
|
* The instruction itself is an "if" statement, it means the user can tolerate this situation, so you should leave a \`FalsyConditionStatement\` action.
|
|
4989
6055
|
|
|
4990
|
-
{
|
|
4991
|
-
"actions": [{
|
|
4992
|
-
"thought": "There is no popup on the page",
|
|
6056
|
+
{{
|
|
6057
|
+
"actions": [{{
|
|
4993
6058
|
"type": "FalsyConditionStatement",
|
|
6059
|
+
"thought": "There is no popup on the page",
|
|
4994
6060
|
"param": null
|
|
4995
|
-
}
|
|
6061
|
+
}}
|
|
4996
6062
|
],
|
|
4997
6063
|
"taskWillBeAccomplished": true,
|
|
4998
6064
|
"furtherPlan": null
|
|
4999
|
-
}
|
|
6065
|
+
}}
|
|
5000
6066
|
|
|
5001
6067
|
For contrast, if the user says "Close the popup" in this situation, you should consider this and output the JSON:
|
|
5002
6068
|
|
|
5003
|
-
{
|
|
6069
|
+
{{
|
|
5004
6070
|
"actions": [],
|
|
5005
6071
|
"error": "The instruction and page context are irrelevant, there is no popup on the page",
|
|
5006
6072
|
"taskWillBeAccomplished": true,
|
|
5007
6073
|
"furtherPlan": null
|
|
5008
|
-
}
|
|
6074
|
+
}}
|
|
5009
6075
|
|
|
5010
|
-
|
|
6076
|
+
Here is an example of when task is accomplished, don't plan more actions:
|
|
5011
6077
|
|
|
5012
6078
|
When the user ask to "Wait 4s", you should consider this:
|
|
5013
6079
|
|
|
5014
|
-
{
|
|
6080
|
+
{{
|
|
5015
6081
|
"actions": [
|
|
5016
|
-
{
|
|
5017
|
-
"thought": "Wait for 4 seconds",
|
|
6082
|
+
{{
|
|
5018
6083
|
"type": "Sleep",
|
|
5019
|
-
"
|
|
5020
|
-
|
|
6084
|
+
"thought": "Wait for 4 seconds",
|
|
6085
|
+
"param": {{ "timeMs": 4000 }},
|
|
6086
|
+
}},
|
|
5021
6087
|
],
|
|
5022
6088
|
"taskWillBeAccomplished": true,
|
|
5023
6089
|
"furtherPlan": null // All steps have been included in the actions, so no further plan is needed
|
|
5024
|
-
}
|
|
6090
|
+
}}
|
|
5025
6091
|
|
|
5026
|
-
|
|
6092
|
+
Here is an example of what NOT to do:
|
|
5027
6093
|
|
|
5028
6094
|
Wrong output:
|
|
5029
6095
|
|
|
5030
|
-
{
|
|
6096
|
+
{{
|
|
5031
6097
|
"actions":[
|
|
5032
|
-
{
|
|
5033
|
-
"thought": "Click the language switch button to open the language options.",
|
|
6098
|
+
{{
|
|
5034
6099
|
"type": "Tap",
|
|
6100
|
+
"thought": "Click the language switch button to open the language options.",
|
|
5035
6101
|
"param": null,
|
|
5036
|
-
"locate": {
|
|
5037
|
-
|
|
5038
|
-
}
|
|
5039
|
-
},
|
|
5040
|
-
{
|
|
6102
|
+
"locate": {{
|
|
6103
|
+
{sample}, // WRONG:prompt is missing
|
|
6104
|
+
}}
|
|
6105
|
+
}},
|
|
6106
|
+
{{
|
|
6107
|
+
"type": "Tap",
|
|
5041
6108
|
"thought": "Click the English option",
|
|
5042
|
-
"type": "Tap",
|
|
5043
6109
|
"param": null,
|
|
5044
6110
|
"locate": null, // This means the 'English' option is not shown in the screenshot, the task cannot be accomplished
|
|
5045
|
-
}
|
|
6111
|
+
}}
|
|
5046
6112
|
],
|
|
5047
6113
|
"taskWillBeAccomplished": false,
|
|
5048
6114
|
// WRONG: should not be null
|
|
5049
6115
|
"furtherPlan": null,
|
|
5050
|
-
}
|
|
6116
|
+
}}
|
|
5051
6117
|
|
|
5052
|
-
Reason:
|
|
6118
|
+
Reason:
|
|
5053
6119
|
* The \`prompt\` is missing in the first 'Locate' action
|
|
5054
6120
|
* Since the option button is not shown in the screenshot, the task cannot be accomplished, so a \`furtherPlan\` field is needed.
|
|
5055
6121
|
`;
|
|
6122
|
+
async function systemPromptToTaskPlanning() {
|
|
6123
|
+
const promptTemplate = new import_prompts3.PromptTemplate({
|
|
6124
|
+
template: `${systemTemplate}
|
|
6125
|
+
|
|
6126
|
+
${outputTemplate}`,
|
|
6127
|
+
inputVariables: ["pageDescription", "sample", "locateParam"]
|
|
6128
|
+
});
|
|
6129
|
+
return await promptTemplate.format({
|
|
6130
|
+
pageDescription: samplePageDescription,
|
|
6131
|
+
sample: quickAnswerFormat().sample,
|
|
6132
|
+
locateParam: quickAnswerFormat().locateParam
|
|
6133
|
+
});
|
|
5056
6134
|
}
|
|
5057
6135
|
var planSchema = {
|
|
5058
6136
|
type: "json_schema",
|
|
@@ -5136,6 +6214,35 @@ var planSchema = {
|
|
|
5136
6214
|
}
|
|
5137
6215
|
}
|
|
5138
6216
|
};
|
|
6217
|
+
var generateTaskBackgroundContext = (userPrompt, originalPrompt, whatHaveDone) => {
|
|
6218
|
+
if (originalPrompt && whatHaveDone) {
|
|
6219
|
+
return `
|
|
6220
|
+
For your information, this is a task that some important person handed to you. Here is the original task description and what have been done after the previous actions:
|
|
6221
|
+
=====================================
|
|
6222
|
+
Original task description: ${originalPrompt}
|
|
6223
|
+
=====================================
|
|
6224
|
+
What have been done: ${whatHaveDone}
|
|
6225
|
+
=====================================
|
|
6226
|
+
`;
|
|
6227
|
+
}
|
|
6228
|
+
return `
|
|
6229
|
+
Here is the instruction:
|
|
6230
|
+
=====================================
|
|
6231
|
+
${userPrompt}
|
|
6232
|
+
=====================================
|
|
6233
|
+
`;
|
|
6234
|
+
};
|
|
6235
|
+
var automationUserPrompt = new import_prompts3.PromptTemplate({
|
|
6236
|
+
template: `
|
|
6237
|
+
pageDescription:
|
|
6238
|
+
=====================================
|
|
6239
|
+
{pageDescription}
|
|
6240
|
+
=====================================
|
|
6241
|
+
|
|
6242
|
+
{taskBackgroundContext}
|
|
6243
|
+
`,
|
|
6244
|
+
inputVariables: ["pageDescription", "taskBackgroundContext"]
|
|
6245
|
+
});
|
|
5139
6246
|
|
|
5140
6247
|
// src/ai-model/openai/index.ts
|
|
5141
6248
|
function checkAIConfig(preferVendor) {
|
|
@@ -5158,7 +6265,9 @@ function getModelName() {
|
|
|
5158
6265
|
}
|
|
5159
6266
|
return modelName;
|
|
5160
6267
|
}
|
|
5161
|
-
async function createChatClient(
|
|
6268
|
+
async function createChatClient({
|
|
6269
|
+
AIActionTypeValue
|
|
6270
|
+
}) {
|
|
5162
6271
|
let openai;
|
|
5163
6272
|
const extraConfig = getAIConfigInJson(MIDSCENE_OPENAI_INIT_CONFIG_JSON);
|
|
5164
6273
|
const socksProxy = getAIConfig(MIDSCENE_OPENAI_SOCKS_PROXY);
|
|
@@ -5199,6 +6308,7 @@ async function createChatClient() {
|
|
|
5199
6308
|
endpoint: getAIConfig(AZURE_OPENAI_ENDPOINT),
|
|
5200
6309
|
apiVersion: getAIConfig(AZURE_OPENAI_API_VERSION),
|
|
5201
6310
|
deployment: getAIConfig(AZURE_OPENAI_DEPLOYMENT),
|
|
6311
|
+
dangerouslyAllowBrowser: true,
|
|
5202
6312
|
...extraConfig,
|
|
5203
6313
|
...extraAzureConfig
|
|
5204
6314
|
});
|
|
@@ -5209,6 +6319,10 @@ async function createChatClient() {
|
|
|
5209
6319
|
apiKey: getAIConfig(OPENAI_API_KEY),
|
|
5210
6320
|
httpAgent: socksAgent,
|
|
5211
6321
|
...extraConfig,
|
|
6322
|
+
defaultHeaders: {
|
|
6323
|
+
...(extraConfig == null ? void 0 : extraConfig.defaultHeaders) || {},
|
|
6324
|
+
[MIDSCENE_API_TYPE]: AIActionTypeValue.toString()
|
|
6325
|
+
},
|
|
5212
6326
|
dangerouslyAllowBrowser: true
|
|
5213
6327
|
});
|
|
5214
6328
|
}
|
|
@@ -5241,8 +6355,10 @@ async function createChatClient() {
|
|
|
5241
6355
|
}
|
|
5242
6356
|
throw new Error("Openai SDK or Anthropic SDK is not initialized");
|
|
5243
6357
|
}
|
|
5244
|
-
async function call(messages, responseFormat) {
|
|
5245
|
-
const { completion, style } = await createChatClient(
|
|
6358
|
+
async function call(messages, AIActionTypeValue, responseFormat) {
|
|
6359
|
+
const { completion, style } = await createChatClient({
|
|
6360
|
+
AIActionTypeValue
|
|
6361
|
+
});
|
|
5246
6362
|
const shouldPrintTiming = typeof getAIConfig(MIDSCENE_DEBUG_AI_PROFILE) === "string";
|
|
5247
6363
|
const maxTokens = getAIConfig(OPENAI_MAX_TOKENS);
|
|
5248
6364
|
const startTime = Date.now();
|
|
@@ -5325,47 +6441,47 @@ async function callToGetJSONObject(messages, AIActionTypeValue) {
|
|
|
5325
6441
|
responseFormat = { type: "json_object" /* JSON */ };
|
|
5326
6442
|
}
|
|
5327
6443
|
}
|
|
5328
|
-
const
|
|
5329
|
-
try {
|
|
5330
|
-
return JSON.parse(input);
|
|
5331
|
-
} catch (e) {
|
|
5332
|
-
return null;
|
|
5333
|
-
}
|
|
5334
|
-
};
|
|
5335
|
-
const response = await call(messages, responseFormat);
|
|
6444
|
+
const response = await call(messages, AIActionTypeValue, responseFormat);
|
|
5336
6445
|
(0, import_node_assert3.default)(response, "empty response");
|
|
5337
|
-
|
|
5338
|
-
|
|
5339
|
-
|
|
5340
|
-
|
|
5341
|
-
try {
|
|
5342
|
-
jsonContent = JSON.parse(cleanJsonString);
|
|
5343
|
-
} catch (e) {
|
|
5344
|
-
}
|
|
5345
|
-
if (jsonContent)
|
|
5346
|
-
return { content: jsonContent, usage: response.usage };
|
|
6446
|
+
const jsonContent = safeParseJson(response.content);
|
|
6447
|
+
return { content: jsonContent, usage: response.usage };
|
|
6448
|
+
}
|
|
6449
|
+
function extractJSONFromCodeBlock(response) {
|
|
5347
6450
|
try {
|
|
5348
|
-
|
|
6451
|
+
const jsonMatch = response.match(/^\s*(\{[\s\S]*\})\s*$/);
|
|
6452
|
+
if (jsonMatch) {
|
|
6453
|
+
return jsonMatch[1];
|
|
6454
|
+
}
|
|
6455
|
+
const codeBlockMatch = response.match(
|
|
6456
|
+
/```(?:json)?\s*(\{[\s\S]*?\})\s*```/
|
|
6457
|
+
);
|
|
6458
|
+
if (codeBlockMatch) {
|
|
6459
|
+
return codeBlockMatch[1];
|
|
6460
|
+
}
|
|
6461
|
+
const jsonLikeMatch = response.match(/\{[\s\S]*\}/);
|
|
6462
|
+
if (jsonLikeMatch) {
|
|
6463
|
+
return jsonLikeMatch[0];
|
|
6464
|
+
}
|
|
5349
6465
|
} catch (e) {
|
|
5350
6466
|
}
|
|
5351
|
-
|
|
5352
|
-
return { content: jsonContent, usage: response.usage };
|
|
5353
|
-
throw Error(`failed to parse json response: ${response.content}`);
|
|
6467
|
+
return response;
|
|
5354
6468
|
}
|
|
5355
|
-
function
|
|
5356
|
-
|
|
5357
|
-
|
|
5358
|
-
|
|
6469
|
+
function safeParseJson(input) {
|
|
6470
|
+
var _a;
|
|
6471
|
+
const cleanJsonString = extractJSONFromCodeBlock(input);
|
|
6472
|
+
if (cleanJsonString.match(/\((\d+),(\d+)\)/)) {
|
|
6473
|
+
return (_a = cleanJsonString.match(/\((\d+),(\d+)\)/)) == null ? void 0 : _a.slice(1).map(Number);
|
|
5359
6474
|
}
|
|
5360
|
-
|
|
5361
|
-
|
|
5362
|
-
|
|
6475
|
+
try {
|
|
6476
|
+
return JSON.parse(cleanJsonString);
|
|
6477
|
+
} catch (e) {
|
|
5363
6478
|
}
|
|
5364
|
-
|
|
5365
|
-
|
|
5366
|
-
|
|
6479
|
+
try {
|
|
6480
|
+
return import_dirty_json.default.parse(cleanJsonString);
|
|
6481
|
+
} catch (e) {
|
|
6482
|
+
console.log("e:", e);
|
|
5367
6483
|
}
|
|
5368
|
-
|
|
6484
|
+
throw Error(`failed to parse json response: ${input}`);
|
|
5369
6485
|
}
|
|
5370
6486
|
|
|
5371
6487
|
// src/ai-model/inspect.ts
|
|
@@ -5374,76 +6490,82 @@ var liteContextConfig = {
|
|
|
5374
6490
|
filterNonTextContent: true,
|
|
5375
6491
|
truncateTextLength: 200
|
|
5376
6492
|
};
|
|
5377
|
-
function
|
|
6493
|
+
function transformToAbsoluteCoords(relativePosition, size) {
|
|
6494
|
+
return {
|
|
6495
|
+
x: Number((relativePosition.x / 1e3 * size.width).toFixed(3)),
|
|
6496
|
+
y: Number((relativePosition.y / 1e3 * size.height).toFixed(3))
|
|
6497
|
+
};
|
|
6498
|
+
}
|
|
6499
|
+
async function transformElementPositionToId(aiResult, elementsInfo, size, screenshotBase64) {
|
|
6500
|
+
if (Array.isArray(aiResult)) {
|
|
6501
|
+
const relativePosition = aiResult;
|
|
6502
|
+
const absolutePosition = transformToAbsoluteCoords(
|
|
6503
|
+
{
|
|
6504
|
+
x: relativePosition[0],
|
|
6505
|
+
y: relativePosition[1]
|
|
6506
|
+
},
|
|
6507
|
+
size
|
|
6508
|
+
);
|
|
6509
|
+
const element = elementByPositionWithElementInfo(
|
|
6510
|
+
elementsInfo,
|
|
6511
|
+
absolutePosition
|
|
6512
|
+
);
|
|
6513
|
+
(0, import_node_assert4.default)(
|
|
6514
|
+
element,
|
|
6515
|
+
`inspect: no id found with position: ${JSON.stringify({ absolutePosition })}`
|
|
6516
|
+
);
|
|
6517
|
+
return {
|
|
6518
|
+
errors: [],
|
|
6519
|
+
elements: [
|
|
6520
|
+
{
|
|
6521
|
+
id: element.id
|
|
6522
|
+
}
|
|
6523
|
+
]
|
|
6524
|
+
};
|
|
6525
|
+
}
|
|
5378
6526
|
return {
|
|
5379
6527
|
errors: aiResult.errors,
|
|
5380
|
-
elements: aiResult.elements
|
|
5381
|
-
var _a;
|
|
5382
|
-
if ("id" in item) {
|
|
5383
|
-
return item;
|
|
5384
|
-
}
|
|
5385
|
-
const { position } = item;
|
|
5386
|
-
const id = (_a = elementByPosition(elementsInfo, position)) == null ? void 0 : _a.id;
|
|
5387
|
-
(0, import_node_assert4.default)(
|
|
5388
|
-
id,
|
|
5389
|
-
`inspect: no id found with position: ${JSON.stringify({ position })}`
|
|
5390
|
-
);
|
|
5391
|
-
return {
|
|
5392
|
-
...item,
|
|
5393
|
-
id
|
|
5394
|
-
};
|
|
5395
|
-
})
|
|
6528
|
+
elements: aiResult.elements
|
|
5396
6529
|
};
|
|
5397
6530
|
}
|
|
6531
|
+
function getQuickAnswer(quickAnswer, elementById) {
|
|
6532
|
+
if (!quickAnswer) {
|
|
6533
|
+
return void 0;
|
|
6534
|
+
}
|
|
6535
|
+
if ("id" in quickAnswer && quickAnswer.id && elementById(quickAnswer.id)) {
|
|
6536
|
+
return {
|
|
6537
|
+
parseResult: {
|
|
6538
|
+
elements: [quickAnswer],
|
|
6539
|
+
errors: []
|
|
6540
|
+
},
|
|
6541
|
+
rawResponse: quickAnswer,
|
|
6542
|
+
elementById
|
|
6543
|
+
};
|
|
6544
|
+
}
|
|
6545
|
+
}
|
|
5398
6546
|
async function AiInspectElement(options) {
|
|
5399
6547
|
const { context, multi, targetElementDescription, callAI } = options;
|
|
5400
6548
|
const { screenshotBase64, screenshotBase64WithElementMarker } = context;
|
|
5401
|
-
const { description, elementById, elementByPosition
|
|
5402
|
-
|
|
5403
|
-
|
|
5404
|
-
|
|
5405
|
-
return {
|
|
5406
|
-
parseResult: {
|
|
5407
|
-
elements: [options.quickAnswer],
|
|
5408
|
-
errors: []
|
|
5409
|
-
},
|
|
5410
|
-
elementById
|
|
5411
|
-
};
|
|
5412
|
-
}
|
|
5413
|
-
if (!targetElementDescription) {
|
|
5414
|
-
return {
|
|
5415
|
-
parseResult: {
|
|
5416
|
-
elements: [],
|
|
5417
|
-
errors: [
|
|
5418
|
-
`inspect: cannot find the target by id: ${options.quickAnswer.id}, and no target element description is provided`
|
|
5419
|
-
]
|
|
5420
|
-
},
|
|
5421
|
-
elementById
|
|
5422
|
-
};
|
|
5423
|
-
}
|
|
5424
|
-
}
|
|
5425
|
-
if ("position" in options.quickAnswer && elementByPosition2(options.quickAnswer.position)) {
|
|
5426
|
-
return {
|
|
5427
|
-
parseResult: transformElementPositionToId(
|
|
5428
|
-
{
|
|
5429
|
-
elements: [options.quickAnswer]
|
|
5430
|
-
},
|
|
5431
|
-
context.content
|
|
5432
|
-
),
|
|
5433
|
-
elementById
|
|
5434
|
-
};
|
|
5435
|
-
}
|
|
6549
|
+
const { description, elementById, elementByPosition, size } = await describeUserPage(context);
|
|
6550
|
+
const quickAnswer = getQuickAnswer(options.quickAnswer, elementById);
|
|
6551
|
+
if (quickAnswer) {
|
|
6552
|
+
return quickAnswer;
|
|
5436
6553
|
}
|
|
5437
6554
|
(0, import_node_assert4.default)(
|
|
5438
6555
|
targetElementDescription,
|
|
5439
6556
|
"cannot find the target element description"
|
|
5440
6557
|
);
|
|
6558
|
+
const userInstructionPrompt = await findElementPrompt.format({
|
|
6559
|
+
pageDescription: description,
|
|
6560
|
+
targetElementDescription,
|
|
6561
|
+
multi
|
|
6562
|
+
});
|
|
5441
6563
|
const systemPrompt = systemPromptToFindElement();
|
|
5442
6564
|
const msgs = [
|
|
5443
6565
|
{ role: "system", content: systemPrompt },
|
|
5444
6566
|
{
|
|
5445
6567
|
role: "user",
|
|
5446
|
-
content:
|
|
6568
|
+
content: [
|
|
5447
6569
|
{
|
|
5448
6570
|
type: "image_url",
|
|
5449
6571
|
image_url: {
|
|
@@ -5452,46 +6574,23 @@ async function AiInspectElement(options) {
|
|
|
5452
6574
|
},
|
|
5453
6575
|
{
|
|
5454
6576
|
type: "text",
|
|
5455
|
-
text:
|
|
5456
|
-
pageDescription:
|
|
5457
|
-
|
|
5458
|
-
${description}
|
|
5459
|
-
|
|
5460
|
-
Here is the item user want to find. Just go ahead:
|
|
5461
|
-
=====================================
|
|
5462
|
-
${JSON.stringify({
|
|
5463
|
-
description: targetElementDescription,
|
|
5464
|
-
multi: multiDescription(multi)
|
|
5465
|
-
})}
|
|
5466
|
-
=====================================`
|
|
6577
|
+
text: userInstructionPrompt
|
|
5467
6578
|
}
|
|
5468
|
-
]
|
|
6579
|
+
]
|
|
5469
6580
|
}
|
|
5470
6581
|
];
|
|
5471
|
-
|
|
5472
|
-
|
|
5473
|
-
msgs,
|
|
5474
|
-
AIActionType: 1 /* INSPECT_ELEMENT */
|
|
5475
|
-
});
|
|
5476
|
-
return {
|
|
5477
|
-
parseResult: transformElementPositionToId(res.content, context.content),
|
|
5478
|
-
rawResponse: res,
|
|
5479
|
-
elementById,
|
|
5480
|
-
usage: res.usage
|
|
5481
|
-
};
|
|
5482
|
-
}
|
|
5483
|
-
const inspectElement = await callAiFn({
|
|
5484
|
-
msgs,
|
|
5485
|
-
AIActionType: 1 /* INSPECT_ELEMENT */
|
|
5486
|
-
});
|
|
6582
|
+
const callAIFn = callAI || callToGetJSONObject;
|
|
6583
|
+
const res = await callAIFn(msgs, 1 /* INSPECT_ELEMENT */);
|
|
5487
6584
|
return {
|
|
5488
|
-
parseResult: transformElementPositionToId(
|
|
5489
|
-
|
|
5490
|
-
context.content
|
|
6585
|
+
parseResult: await transformElementPositionToId(
|
|
6586
|
+
res.content,
|
|
6587
|
+
context.content,
|
|
6588
|
+
size,
|
|
6589
|
+
screenshotBase64
|
|
5491
6590
|
),
|
|
5492
|
-
rawResponse:
|
|
6591
|
+
rawResponse: res.content,
|
|
5493
6592
|
elementById,
|
|
5494
|
-
usage:
|
|
6593
|
+
usage: res.usage
|
|
5495
6594
|
};
|
|
5496
6595
|
}
|
|
5497
6596
|
async function AiExtractElementInfo(options) {
|
|
@@ -5502,11 +6601,25 @@ async function AiExtractElementInfo(options) {
|
|
|
5502
6601
|
context,
|
|
5503
6602
|
liteContextConfig
|
|
5504
6603
|
);
|
|
6604
|
+
let dataKeys = "";
|
|
6605
|
+
let dataQueryText = "";
|
|
6606
|
+
if (typeof dataQuery === "string") {
|
|
6607
|
+
dataKeys = "";
|
|
6608
|
+
dataQueryText = dataQuery;
|
|
6609
|
+
} else {
|
|
6610
|
+
dataKeys = `return in key-value style object, keys are ${Object.keys(dataQuery).join(",")}`;
|
|
6611
|
+
dataQueryText = JSON.stringify(dataQuery, null, 2);
|
|
6612
|
+
}
|
|
6613
|
+
const extractDataPromptText = await extractDataPrompt.format({
|
|
6614
|
+
pageDescription: description,
|
|
6615
|
+
dataKeys,
|
|
6616
|
+
dataQuery: dataQueryText
|
|
6617
|
+
});
|
|
5505
6618
|
const msgs = [
|
|
5506
6619
|
{ role: "system", content: systemPrompt },
|
|
5507
6620
|
{
|
|
5508
6621
|
role: "user",
|
|
5509
|
-
content:
|
|
6622
|
+
content: [
|
|
5510
6623
|
{
|
|
5511
6624
|
type: "image_url",
|
|
5512
6625
|
image_url: {
|
|
@@ -5515,25 +6628,15 @@ async function AiExtractElementInfo(options) {
|
|
|
5515
6628
|
},
|
|
5516
6629
|
{
|
|
5517
6630
|
type: "text",
|
|
5518
|
-
text:
|
|
5519
|
-
pageDescription: ${description}
|
|
5520
|
-
|
|
5521
|
-
Use your extract_data_from_UI skill to find the following data, placing it in the \`data\` field
|
|
5522
|
-
DATA_DEMAND start:
|
|
5523
|
-
=====================================
|
|
5524
|
-
${typeof dataQuery === "object" ? `return in key-value style object, keys are ${Object.keys(dataQuery).join(",")}` : ""}
|
|
5525
|
-
${typeof dataQuery === "string" ? dataQuery : JSON.stringify(dataQuery, null, 2)}
|
|
5526
|
-
=====================================
|
|
5527
|
-
DATA_DEMAND ends.
|
|
5528
|
-
`
|
|
6631
|
+
text: extractDataPromptText
|
|
5529
6632
|
}
|
|
5530
|
-
]
|
|
6633
|
+
]
|
|
5531
6634
|
}
|
|
5532
6635
|
];
|
|
5533
|
-
const result = await callAiFn(
|
|
6636
|
+
const result = await callAiFn(
|
|
5534
6637
|
msgs,
|
|
5535
|
-
|
|
5536
|
-
|
|
6638
|
+
2 /* EXTRACT_DATA */
|
|
6639
|
+
);
|
|
5537
6640
|
return {
|
|
5538
6641
|
parseResult: result.content,
|
|
5539
6642
|
elementById,
|
|
@@ -5550,7 +6653,7 @@ async function AiAssert(options) {
|
|
|
5550
6653
|
{ role: "system", content: systemPrompt },
|
|
5551
6654
|
{
|
|
5552
6655
|
role: "user",
|
|
5553
|
-
content:
|
|
6656
|
+
content: [
|
|
5554
6657
|
{
|
|
5555
6658
|
type: "image_url",
|
|
5556
6659
|
image_url: {
|
|
@@ -5569,43 +6672,40 @@ async function AiAssert(options) {
|
|
|
5569
6672
|
=====================================
|
|
5570
6673
|
`
|
|
5571
6674
|
}
|
|
5572
|
-
]
|
|
6675
|
+
]
|
|
5573
6676
|
}
|
|
5574
6677
|
];
|
|
5575
|
-
const { content: assertResult, usage } = await callAiFn(
|
|
6678
|
+
const { content: assertResult, usage } = await callAiFn(
|
|
5576
6679
|
msgs,
|
|
5577
|
-
|
|
5578
|
-
|
|
6680
|
+
0 /* ASSERT */
|
|
6681
|
+
);
|
|
5579
6682
|
return {
|
|
5580
6683
|
content: assertResult,
|
|
5581
6684
|
usage
|
|
5582
6685
|
};
|
|
5583
6686
|
}
|
|
5584
6687
|
|
|
5585
|
-
// src/ai-model/automation
|
|
6688
|
+
// src/ai-model/automation.ts
|
|
5586
6689
|
var import_node_assert5 = __toESM(require("assert"));
|
|
5587
6690
|
async function plan(userPrompt, opts) {
|
|
5588
6691
|
const { callAI, context } = opts || {};
|
|
5589
6692
|
const { screenshotBase64, screenshotBase64WithElementMarker } = context;
|
|
5590
|
-
const { description: pageDescription, elementByPosition
|
|
5591
|
-
const systemPrompt = systemPromptToTaskPlanning();
|
|
5592
|
-
|
|
5593
|
-
|
|
5594
|
-
|
|
5595
|
-
|
|
5596
|
-
|
|
5597
|
-
|
|
5598
|
-
|
|
5599
|
-
|
|
5600
|
-
|
|
5601
|
-
=====================================
|
|
5602
|
-
`;
|
|
5603
|
-
}
|
|
6693
|
+
const { description: pageDescription, elementByPosition } = await describeUserPage(context);
|
|
6694
|
+
const systemPrompt = await systemPromptToTaskPlanning();
|
|
6695
|
+
const taskBackgroundContextText = generateTaskBackgroundContext(
|
|
6696
|
+
userPrompt,
|
|
6697
|
+
opts.originalPrompt,
|
|
6698
|
+
opts.whatHaveDone
|
|
6699
|
+
);
|
|
6700
|
+
const userInstructionPrompt = await automationUserPrompt.format({
|
|
6701
|
+
pageDescription,
|
|
6702
|
+
taskBackgroundContext: taskBackgroundContextText
|
|
6703
|
+
});
|
|
5604
6704
|
const msgs = [
|
|
5605
6705
|
{ role: "system", content: systemPrompt },
|
|
5606
6706
|
{
|
|
5607
6707
|
role: "user",
|
|
5608
|
-
content:
|
|
6708
|
+
content: [
|
|
5609
6709
|
{
|
|
5610
6710
|
type: "image_url",
|
|
5611
6711
|
image_url: {
|
|
@@ -5615,28 +6715,13 @@ ${opts.whatHaveDone}
|
|
|
5615
6715
|
},
|
|
5616
6716
|
{
|
|
5617
6717
|
type: "text",
|
|
5618
|
-
text:
|
|
5619
|
-
pageDescription:
|
|
5620
|
-
|
|
5621
|
-
${pageDescription}
|
|
5622
|
-
|
|
5623
|
-
|
|
5624
|
-
Here is the instruction:
|
|
5625
|
-
=====================================
|
|
5626
|
-
${userPrompt}
|
|
5627
|
-
=====================================
|
|
5628
|
-
|
|
5629
|
-
${taskBackgroundContext}
|
|
5630
|
-
`.trim()
|
|
6718
|
+
text: userInstructionPrompt
|
|
5631
6719
|
}
|
|
5632
|
-
]
|
|
6720
|
+
]
|
|
5633
6721
|
}
|
|
5634
6722
|
];
|
|
5635
|
-
const
|
|
5636
|
-
const { content, usage } = await
|
|
5637
|
-
msgs,
|
|
5638
|
-
AIActionType: 3 /* PLAN */
|
|
5639
|
-
});
|
|
6723
|
+
const call3 = callAI || callAiFn;
|
|
6724
|
+
const { content, usage } = await call3(msgs, 3 /* PLAN */);
|
|
5640
6725
|
const planFromAI = content;
|
|
5641
6726
|
const actions = (planFromAI == null ? void 0 : planFromAI.actions) || [];
|
|
5642
6727
|
(0, import_node_assert5.default)(planFromAI, "can't get plans from AI");
|
|
@@ -5658,3 +6743,11 @@ ${taskBackgroundContext}
|
|
|
5658
6743
|
systemPromptToFindElement,
|
|
5659
6744
|
transformElementPositionToId
|
|
5660
6745
|
});
|
|
6746
|
+
/*! Bundled license information:
|
|
6747
|
+
|
|
6748
|
+
string.fromcodepoint/fromcodepoint.js:
|
|
6749
|
+
(*! http://mths.be/fromcodepoint v0.2.1 by @mathias *)
|
|
6750
|
+
|
|
6751
|
+
utf8/utf8.js:
|
|
6752
|
+
(*! https://mths.be/utf8js v3.0.0 by @mathias *)
|
|
6753
|
+
*/
|