@midscene/core 0.0.1 → 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/es/ai-model.js +8 -1
- package/dist/es/image.js +2 -2
- package/dist/es/index.js +44 -16
- package/dist/es/utils.js +20 -11
- package/dist/lib/ai-model.js +8 -1
- package/dist/lib/image.js +2 -2
- package/dist/lib/index.js +44 -16
- package/dist/lib/utils.js +21 -11
- package/dist/types/ai-model.d.ts +1 -1
- package/dist/types/index.d.ts +15 -5
- package/dist/types/utils.d.ts +9 -3
- package/package.json +5 -1
- package/.eslintignore +0 -3
- package/.eslintrc.js +0 -9
- package/CONTRIBUTING.md +0 -5
- package/demo_data/demo.actions.json +0 -160
- package/demo_data/demo.insight.json +0 -3571
- package/demo_data/index.d.ts +0 -1
- package/demo_data/index.js +0 -6
- package/modern.config.ts +0 -18
- package/third-party-licenses.txt +0 -415
- package/tsconfig.json +0 -22
- package/vitest.config.ts +0 -20
package/dist/es/ai-model.js
CHANGED
|
@@ -314,7 +314,14 @@ function truncateText(text) {
|
|
|
314
314
|
}
|
|
315
315
|
async function describeUserPage(context) {
|
|
316
316
|
const { screenshotBase64 } = context;
|
|
317
|
-
|
|
317
|
+
let width;
|
|
318
|
+
let height;
|
|
319
|
+
if (context.size) {
|
|
320
|
+
({ width, height } = context.size);
|
|
321
|
+
} else {
|
|
322
|
+
const imgSize = await imageInfoOfBase64(screenshotBase64);
|
|
323
|
+
({ width, height } = imgSize);
|
|
324
|
+
}
|
|
318
325
|
const elementsInfo = context.content;
|
|
319
326
|
const idElementMap = {};
|
|
320
327
|
elementsInfo.forEach((item) => {
|
package/dist/es/image.js
CHANGED
|
@@ -140,8 +140,8 @@ function getTmpDir() {
|
|
|
140
140
|
mkdirSync(path, { recursive: true });
|
|
141
141
|
return path;
|
|
142
142
|
}
|
|
143
|
-
function getTmpFile(
|
|
144
|
-
const filename = `${randomUUID()}.${
|
|
143
|
+
function getTmpFile(fileExtWithoutDot) {
|
|
144
|
+
const filename = `${randomUUID()}.${fileExtWithoutDot}`;
|
|
145
145
|
return join(getTmpDir(), filename);
|
|
146
146
|
}
|
|
147
147
|
|
package/dist/es/index.js
CHANGED
|
@@ -100,13 +100,18 @@ function getDumpDir() {
|
|
|
100
100
|
function setDumpDir(dir) {
|
|
101
101
|
logDir = dir;
|
|
102
102
|
}
|
|
103
|
-
function
|
|
103
|
+
function getDumpDirPath(type) {
|
|
104
|
+
return join(getDumpDir(), type);
|
|
105
|
+
}
|
|
106
|
+
function writeDumpFile(opts) {
|
|
107
|
+
const { fileName, fileExt, fileContent, type = "dump" } = opts;
|
|
108
|
+
const targetDir = getDumpDirPath(type);
|
|
109
|
+
if (!existsSync(targetDir)) {
|
|
110
|
+
mkdirSync(targetDir, { recursive: true });
|
|
111
|
+
}
|
|
104
112
|
if (!logEnvReady) {
|
|
105
|
-
assert2(
|
|
106
|
-
|
|
107
|
-
mkdirSync(logDir, { recursive: true });
|
|
108
|
-
}
|
|
109
|
-
const gitIgnorePath = join(logDir, "../.gitignore");
|
|
113
|
+
assert2(targetDir, "logDir should be set before writing dump file");
|
|
114
|
+
const gitIgnorePath = join(targetDir, "../../.gitignore");
|
|
110
115
|
let gitIgnoreContent = "";
|
|
111
116
|
if (existsSync(gitIgnorePath)) {
|
|
112
117
|
gitIgnoreContent = readFileSync2(gitIgnorePath, "utf-8");
|
|
@@ -117,16 +122,19 @@ function writeDumpFile(fileName, fileExt, fileContent) {
|
|
|
117
122
|
gitIgnorePath,
|
|
118
123
|
`${gitIgnoreContent}
|
|
119
124
|
# MidScene.js dump files
|
|
120
|
-
${logDirName}/
|
|
125
|
+
${logDirName}/midscene-report
|
|
126
|
+
${logDirName}/dump-logger
|
|
121
127
|
`,
|
|
122
128
|
"utf-8"
|
|
123
129
|
);
|
|
124
130
|
}
|
|
125
131
|
logEnvReady = true;
|
|
126
132
|
}
|
|
127
|
-
const filePath = join(
|
|
133
|
+
const filePath = join(targetDir, `${fileName}.${fileExt}`);
|
|
128
134
|
writeFileSync(filePath, fileContent);
|
|
129
|
-
|
|
135
|
+
if (type === "dump") {
|
|
136
|
+
copyFileSync(filePath, join(targetDir, `latest.${fileExt}`));
|
|
137
|
+
}
|
|
130
138
|
return filePath;
|
|
131
139
|
}
|
|
132
140
|
|
|
@@ -222,7 +230,14 @@ function truncateText(text) {
|
|
|
222
230
|
}
|
|
223
231
|
async function describeUserPage(context) {
|
|
224
232
|
const { screenshotBase64 } = context;
|
|
225
|
-
|
|
233
|
+
let width;
|
|
234
|
+
let height;
|
|
235
|
+
if (context.size) {
|
|
236
|
+
({ width, height } = context.size);
|
|
237
|
+
} else {
|
|
238
|
+
const imgSize = await imageInfoOfBase64(screenshotBase64);
|
|
239
|
+
({ width, height } = imgSize);
|
|
240
|
+
}
|
|
226
241
|
const elementsInfo = context.content;
|
|
227
242
|
const idElementMap = {};
|
|
228
243
|
elementsInfo.forEach((item) => {
|
|
@@ -341,9 +356,13 @@ function writeInsightDump(data, logId, dumpSubscriber) {
|
|
|
341
356
|
const length = logContent.push(dataString);
|
|
342
357
|
logIdIndexMap[id] = length - 1;
|
|
343
358
|
}
|
|
344
|
-
writeDumpFile(
|
|
359
|
+
writeDumpFile({
|
|
360
|
+
fileName: logFileName,
|
|
361
|
+
fileExt: logFileExt,
|
|
362
|
+
fileContent: `[
|
|
345
363
|
${logContent.join(",\n")}
|
|
346
|
-
]`
|
|
364
|
+
]`
|
|
365
|
+
});
|
|
347
366
|
return id;
|
|
348
367
|
}
|
|
349
368
|
function idsIntoElements(ids, elementById) {
|
|
@@ -675,15 +694,16 @@ var Insight = class {
|
|
|
675
694
|
}
|
|
676
695
|
async locate(queryPrompt, opt) {
|
|
677
696
|
var _a;
|
|
697
|
+
const { callAI = this.aiVendorFn, multi = false } = opt || {};
|
|
678
698
|
assert6(queryPrompt, "query is required for located");
|
|
679
699
|
const dumpSubscriber = this.onceDumpUpdatedFn;
|
|
680
700
|
this.onceDumpUpdatedFn = void 0;
|
|
681
701
|
const context = await this.contextRetrieverFn();
|
|
682
702
|
const startTime = Date.now();
|
|
683
703
|
const { parseResult, systemPrompt, elementById } = await AiInspectElement({
|
|
684
|
-
callAI
|
|
704
|
+
callAI,
|
|
685
705
|
context,
|
|
686
|
-
multi: Boolean(
|
|
706
|
+
multi: Boolean(multi),
|
|
687
707
|
findElementDescription: queryPrompt
|
|
688
708
|
});
|
|
689
709
|
const timeCost = Date.now() - startTime;
|
|
@@ -850,6 +870,13 @@ ${parseResult.errors.join("\n")}`;
|
|
|
850
870
|
);
|
|
851
871
|
return mergedData;
|
|
852
872
|
}
|
|
873
|
+
setAiVendorFn(aiVendorFn) {
|
|
874
|
+
const origin = this.aiVendorFn;
|
|
875
|
+
this.aiVendorFn = aiVendorFn;
|
|
876
|
+
return () => {
|
|
877
|
+
this.aiVendorFn = origin;
|
|
878
|
+
};
|
|
879
|
+
}
|
|
853
880
|
};
|
|
854
881
|
|
|
855
882
|
// src/action/executor.ts
|
|
@@ -1032,7 +1059,8 @@ function systemPromptToTaskPlanning(query) {
|
|
|
1032
1059
|
=====================================
|
|
1033
1060
|
`;
|
|
1034
1061
|
}
|
|
1035
|
-
async function plan(
|
|
1062
|
+
async function plan(userPrompt, opts) {
|
|
1063
|
+
const { callAI = callToGetJSONObject, context } = opts || {};
|
|
1036
1064
|
const { screenshotBase64 } = context;
|
|
1037
1065
|
const { description } = await describeUserPage(context);
|
|
1038
1066
|
const systemPrompt = systemPromptToTaskPlanning(userPrompt);
|
|
@@ -1055,7 +1083,7 @@ async function plan(context, userPrompt) {
|
|
|
1055
1083
|
]
|
|
1056
1084
|
}
|
|
1057
1085
|
];
|
|
1058
|
-
const planFromAI = await
|
|
1086
|
+
const planFromAI = await callAI(msgs);
|
|
1059
1087
|
if (planFromAI.error) {
|
|
1060
1088
|
throw new Error(planFromAI.error);
|
|
1061
1089
|
}
|
package/dist/es/utils.js
CHANGED
|
@@ -36,13 +36,18 @@ function getDumpDir() {
|
|
|
36
36
|
function setDumpDir(dir) {
|
|
37
37
|
logDir = dir;
|
|
38
38
|
}
|
|
39
|
-
function
|
|
39
|
+
function getDumpDirPath(type) {
|
|
40
|
+
return join(getDumpDir(), type);
|
|
41
|
+
}
|
|
42
|
+
function writeDumpFile(opts) {
|
|
43
|
+
const { fileName, fileExt, fileContent, type = "dump" } = opts;
|
|
44
|
+
const targetDir = getDumpDirPath(type);
|
|
45
|
+
if (!existsSync(targetDir)) {
|
|
46
|
+
mkdirSync(targetDir, { recursive: true });
|
|
47
|
+
}
|
|
40
48
|
if (!logEnvReady) {
|
|
41
|
-
assert(
|
|
42
|
-
|
|
43
|
-
mkdirSync(logDir, { recursive: true });
|
|
44
|
-
}
|
|
45
|
-
const gitIgnorePath = join(logDir, "../.gitignore");
|
|
49
|
+
assert(targetDir, "logDir should be set before writing dump file");
|
|
50
|
+
const gitIgnorePath = join(targetDir, "../../.gitignore");
|
|
46
51
|
let gitIgnoreContent = "";
|
|
47
52
|
if (existsSync(gitIgnorePath)) {
|
|
48
53
|
gitIgnoreContent = readFileSync(gitIgnorePath, "utf-8");
|
|
@@ -53,16 +58,19 @@ function writeDumpFile(fileName, fileExt, fileContent) {
|
|
|
53
58
|
gitIgnorePath,
|
|
54
59
|
`${gitIgnoreContent}
|
|
55
60
|
# MidScene.js dump files
|
|
56
|
-
${logDirName}/
|
|
61
|
+
${logDirName}/midscene-report
|
|
62
|
+
${logDirName}/dump-logger
|
|
57
63
|
`,
|
|
58
64
|
"utf-8"
|
|
59
65
|
);
|
|
60
66
|
}
|
|
61
67
|
logEnvReady = true;
|
|
62
68
|
}
|
|
63
|
-
const filePath = join(
|
|
69
|
+
const filePath = join(targetDir, `${fileName}.${fileExt}`);
|
|
64
70
|
writeFileSync(filePath, fileContent);
|
|
65
|
-
|
|
71
|
+
if (type === "dump") {
|
|
72
|
+
copyFileSync(filePath, join(targetDir, `latest.${fileExt}`));
|
|
73
|
+
}
|
|
66
74
|
return filePath;
|
|
67
75
|
}
|
|
68
76
|
function getTmpDir() {
|
|
@@ -70,8 +78,8 @@ function getTmpDir() {
|
|
|
70
78
|
mkdirSync(path, { recursive: true });
|
|
71
79
|
return path;
|
|
72
80
|
}
|
|
73
|
-
function getTmpFile(
|
|
74
|
-
const filename = `${randomUUID()}.${
|
|
81
|
+
function getTmpFile(fileExtWithoutDot) {
|
|
82
|
+
const filename = `${randomUUID()}.${fileExtWithoutDot}`;
|
|
75
83
|
return join(getTmpDir(), filename);
|
|
76
84
|
}
|
|
77
85
|
function overlapped(container, target) {
|
|
@@ -84,6 +92,7 @@ var commonScreenshotParam = { type: "jpeg", quality: 75 };
|
|
|
84
92
|
export {
|
|
85
93
|
commonScreenshotParam,
|
|
86
94
|
getDumpDir,
|
|
95
|
+
getDumpDirPath,
|
|
87
96
|
getPkgInfo,
|
|
88
97
|
getTmpDir,
|
|
89
98
|
getTmpFile,
|
package/dist/lib/ai-model.js
CHANGED
|
@@ -351,7 +351,14 @@ function truncateText(text) {
|
|
|
351
351
|
}
|
|
352
352
|
async function describeUserPage(context) {
|
|
353
353
|
const { screenshotBase64 } = context;
|
|
354
|
-
|
|
354
|
+
let width;
|
|
355
|
+
let height;
|
|
356
|
+
if (context.size) {
|
|
357
|
+
({ width, height } = context.size);
|
|
358
|
+
} else {
|
|
359
|
+
const imgSize = await imageInfoOfBase64(screenshotBase64);
|
|
360
|
+
({ width, height } = imgSize);
|
|
361
|
+
}
|
|
355
362
|
const elementsInfo = context.content;
|
|
356
363
|
const idElementMap = {};
|
|
357
364
|
elementsInfo.forEach((item) => {
|
package/dist/lib/image.js
CHANGED
|
@@ -185,8 +185,8 @@ function getTmpDir() {
|
|
|
185
185
|
(0, import_fs.mkdirSync)(path, { recursive: true });
|
|
186
186
|
return path;
|
|
187
187
|
}
|
|
188
|
-
function getTmpFile(
|
|
189
|
-
const filename = `${(0, import_crypto.randomUUID)()}.${
|
|
188
|
+
function getTmpFile(fileExtWithoutDot) {
|
|
189
|
+
const filename = `${(0, import_crypto.randomUUID)()}.${fileExtWithoutDot}`;
|
|
190
190
|
return (0, import_path.join)(getTmpDir(), filename);
|
|
191
191
|
}
|
|
192
192
|
|
package/dist/lib/index.js
CHANGED
|
@@ -141,13 +141,18 @@ function getDumpDir() {
|
|
|
141
141
|
function setDumpDir(dir) {
|
|
142
142
|
logDir = dir;
|
|
143
143
|
}
|
|
144
|
-
function
|
|
144
|
+
function getDumpDirPath(type) {
|
|
145
|
+
return (0, import_path.join)(getDumpDir(), type);
|
|
146
|
+
}
|
|
147
|
+
function writeDumpFile(opts) {
|
|
148
|
+
const { fileName, fileExt, fileContent, type = "dump" } = opts;
|
|
149
|
+
const targetDir = getDumpDirPath(type);
|
|
150
|
+
if (!(0, import_fs.existsSync)(targetDir)) {
|
|
151
|
+
(0, import_fs.mkdirSync)(targetDir, { recursive: true });
|
|
152
|
+
}
|
|
145
153
|
if (!logEnvReady) {
|
|
146
|
-
(0, import_assert.default)(
|
|
147
|
-
|
|
148
|
-
(0, import_fs.mkdirSync)(logDir, { recursive: true });
|
|
149
|
-
}
|
|
150
|
-
const gitIgnorePath = (0, import_path.join)(logDir, "../.gitignore");
|
|
154
|
+
(0, import_assert.default)(targetDir, "logDir should be set before writing dump file");
|
|
155
|
+
const gitIgnorePath = (0, import_path.join)(targetDir, "../../.gitignore");
|
|
151
156
|
let gitIgnoreContent = "";
|
|
152
157
|
if ((0, import_fs.existsSync)(gitIgnorePath)) {
|
|
153
158
|
gitIgnoreContent = (0, import_fs.readFileSync)(gitIgnorePath, "utf-8");
|
|
@@ -158,16 +163,19 @@ function writeDumpFile(fileName, fileExt, fileContent) {
|
|
|
158
163
|
gitIgnorePath,
|
|
159
164
|
`${gitIgnoreContent}
|
|
160
165
|
# MidScene.js dump files
|
|
161
|
-
${logDirName}/
|
|
166
|
+
${logDirName}/midscene-report
|
|
167
|
+
${logDirName}/dump-logger
|
|
162
168
|
`,
|
|
163
169
|
"utf-8"
|
|
164
170
|
);
|
|
165
171
|
}
|
|
166
172
|
logEnvReady = true;
|
|
167
173
|
}
|
|
168
|
-
const filePath = (0, import_path.join)(
|
|
174
|
+
const filePath = (0, import_path.join)(targetDir, `${fileName}.${fileExt}`);
|
|
169
175
|
(0, import_fs.writeFileSync)(filePath, fileContent);
|
|
170
|
-
|
|
176
|
+
if (type === "dump") {
|
|
177
|
+
(0, import_fs.copyFileSync)(filePath, (0, import_path.join)(targetDir, `latest.${fileExt}`));
|
|
178
|
+
}
|
|
171
179
|
return filePath;
|
|
172
180
|
}
|
|
173
181
|
|
|
@@ -263,7 +271,14 @@ function truncateText(text) {
|
|
|
263
271
|
}
|
|
264
272
|
async function describeUserPage(context) {
|
|
265
273
|
const { screenshotBase64 } = context;
|
|
266
|
-
|
|
274
|
+
let width;
|
|
275
|
+
let height;
|
|
276
|
+
if (context.size) {
|
|
277
|
+
({ width, height } = context.size);
|
|
278
|
+
} else {
|
|
279
|
+
const imgSize = await imageInfoOfBase64(screenshotBase64);
|
|
280
|
+
({ width, height } = imgSize);
|
|
281
|
+
}
|
|
267
282
|
const elementsInfo = context.content;
|
|
268
283
|
const idElementMap = {};
|
|
269
284
|
elementsInfo.forEach((item) => {
|
|
@@ -382,9 +397,13 @@ function writeInsightDump(data, logId, dumpSubscriber) {
|
|
|
382
397
|
const length = logContent.push(dataString);
|
|
383
398
|
logIdIndexMap[id] = length - 1;
|
|
384
399
|
}
|
|
385
|
-
writeDumpFile(
|
|
400
|
+
writeDumpFile({
|
|
401
|
+
fileName: logFileName,
|
|
402
|
+
fileExt: logFileExt,
|
|
403
|
+
fileContent: `[
|
|
386
404
|
${logContent.join(",\n")}
|
|
387
|
-
]`
|
|
405
|
+
]`
|
|
406
|
+
});
|
|
388
407
|
return id;
|
|
389
408
|
}
|
|
390
409
|
function idsIntoElements(ids, elementById) {
|
|
@@ -716,15 +735,16 @@ var Insight = class {
|
|
|
716
735
|
}
|
|
717
736
|
async locate(queryPrompt, opt) {
|
|
718
737
|
var _a;
|
|
738
|
+
const { callAI = this.aiVendorFn, multi = false } = opt || {};
|
|
719
739
|
(0, import_assert5.default)(queryPrompt, "query is required for located");
|
|
720
740
|
const dumpSubscriber = this.onceDumpUpdatedFn;
|
|
721
741
|
this.onceDumpUpdatedFn = void 0;
|
|
722
742
|
const context = await this.contextRetrieverFn();
|
|
723
743
|
const startTime = Date.now();
|
|
724
744
|
const { parseResult, systemPrompt, elementById } = await AiInspectElement({
|
|
725
|
-
callAI
|
|
745
|
+
callAI,
|
|
726
746
|
context,
|
|
727
|
-
multi: Boolean(
|
|
747
|
+
multi: Boolean(multi),
|
|
728
748
|
findElementDescription: queryPrompt
|
|
729
749
|
});
|
|
730
750
|
const timeCost = Date.now() - startTime;
|
|
@@ -891,6 +911,13 @@ ${parseResult.errors.join("\n")}`;
|
|
|
891
911
|
);
|
|
892
912
|
return mergedData;
|
|
893
913
|
}
|
|
914
|
+
setAiVendorFn(aiVendorFn) {
|
|
915
|
+
const origin = this.aiVendorFn;
|
|
916
|
+
this.aiVendorFn = aiVendorFn;
|
|
917
|
+
return () => {
|
|
918
|
+
this.aiVendorFn = origin;
|
|
919
|
+
};
|
|
920
|
+
}
|
|
894
921
|
};
|
|
895
922
|
|
|
896
923
|
// src/action/executor.ts
|
|
@@ -1073,7 +1100,8 @@ function systemPromptToTaskPlanning(query) {
|
|
|
1073
1100
|
=====================================
|
|
1074
1101
|
`;
|
|
1075
1102
|
}
|
|
1076
|
-
async function plan(
|
|
1103
|
+
async function plan(userPrompt, opts) {
|
|
1104
|
+
const { callAI = callToGetJSONObject, context } = opts || {};
|
|
1077
1105
|
const { screenshotBase64 } = context;
|
|
1078
1106
|
const { description } = await describeUserPage(context);
|
|
1079
1107
|
const systemPrompt = systemPromptToTaskPlanning(userPrompt);
|
|
@@ -1096,7 +1124,7 @@ async function plan(context, userPrompt) {
|
|
|
1096
1124
|
]
|
|
1097
1125
|
}
|
|
1098
1126
|
];
|
|
1099
|
-
const planFromAI = await
|
|
1127
|
+
const planFromAI = await callAI(msgs);
|
|
1100
1128
|
if (planFromAI.error) {
|
|
1101
1129
|
throw new Error(planFromAI.error);
|
|
1102
1130
|
}
|
package/dist/lib/utils.js
CHANGED
|
@@ -32,6 +32,7 @@ var utils_exports = {};
|
|
|
32
32
|
__export(utils_exports, {
|
|
33
33
|
commonScreenshotParam: () => commonScreenshotParam,
|
|
34
34
|
getDumpDir: () => getDumpDir,
|
|
35
|
+
getDumpDirPath: () => getDumpDirPath,
|
|
35
36
|
getPkgInfo: () => getPkgInfo,
|
|
36
37
|
getTmpDir: () => getTmpDir,
|
|
37
38
|
getTmpFile: () => getTmpFile,
|
|
@@ -80,13 +81,18 @@ function getDumpDir() {
|
|
|
80
81
|
function setDumpDir(dir) {
|
|
81
82
|
logDir = dir;
|
|
82
83
|
}
|
|
83
|
-
function
|
|
84
|
+
function getDumpDirPath(type) {
|
|
85
|
+
return (0, import_path.join)(getDumpDir(), type);
|
|
86
|
+
}
|
|
87
|
+
function writeDumpFile(opts) {
|
|
88
|
+
const { fileName, fileExt, fileContent, type = "dump" } = opts;
|
|
89
|
+
const targetDir = getDumpDirPath(type);
|
|
90
|
+
if (!(0, import_fs.existsSync)(targetDir)) {
|
|
91
|
+
(0, import_fs.mkdirSync)(targetDir, { recursive: true });
|
|
92
|
+
}
|
|
84
93
|
if (!logEnvReady) {
|
|
85
|
-
(0, import_assert.default)(
|
|
86
|
-
|
|
87
|
-
(0, import_fs.mkdirSync)(logDir, { recursive: true });
|
|
88
|
-
}
|
|
89
|
-
const gitIgnorePath = (0, import_path.join)(logDir, "../.gitignore");
|
|
94
|
+
(0, import_assert.default)(targetDir, "logDir should be set before writing dump file");
|
|
95
|
+
const gitIgnorePath = (0, import_path.join)(targetDir, "../../.gitignore");
|
|
90
96
|
let gitIgnoreContent = "";
|
|
91
97
|
if ((0, import_fs.existsSync)(gitIgnorePath)) {
|
|
92
98
|
gitIgnoreContent = (0, import_fs.readFileSync)(gitIgnorePath, "utf-8");
|
|
@@ -97,16 +103,19 @@ function writeDumpFile(fileName, fileExt, fileContent) {
|
|
|
97
103
|
gitIgnorePath,
|
|
98
104
|
`${gitIgnoreContent}
|
|
99
105
|
# MidScene.js dump files
|
|
100
|
-
${logDirName}/
|
|
106
|
+
${logDirName}/midscene-report
|
|
107
|
+
${logDirName}/dump-logger
|
|
101
108
|
`,
|
|
102
109
|
"utf-8"
|
|
103
110
|
);
|
|
104
111
|
}
|
|
105
112
|
logEnvReady = true;
|
|
106
113
|
}
|
|
107
|
-
const filePath = (0, import_path.join)(
|
|
114
|
+
const filePath = (0, import_path.join)(targetDir, `${fileName}.${fileExt}`);
|
|
108
115
|
(0, import_fs.writeFileSync)(filePath, fileContent);
|
|
109
|
-
|
|
116
|
+
if (type === "dump") {
|
|
117
|
+
(0, import_fs.copyFileSync)(filePath, (0, import_path.join)(targetDir, `latest.${fileExt}`));
|
|
118
|
+
}
|
|
110
119
|
return filePath;
|
|
111
120
|
}
|
|
112
121
|
function getTmpDir() {
|
|
@@ -114,8 +123,8 @@ function getTmpDir() {
|
|
|
114
123
|
(0, import_fs.mkdirSync)(path, { recursive: true });
|
|
115
124
|
return path;
|
|
116
125
|
}
|
|
117
|
-
function getTmpFile(
|
|
118
|
-
const filename = `${(0, import_crypto.randomUUID)()}.${
|
|
126
|
+
function getTmpFile(fileExtWithoutDot) {
|
|
127
|
+
const filename = `${(0, import_crypto.randomUUID)()}.${fileExtWithoutDot}`;
|
|
119
128
|
return (0, import_path.join)(getTmpDir(), filename);
|
|
120
129
|
}
|
|
121
130
|
function overlapped(container, target) {
|
|
@@ -129,6 +138,7 @@ var commonScreenshotParam = { type: "jpeg", quality: 75 };
|
|
|
129
138
|
0 && (module.exports = {
|
|
130
139
|
commonScreenshotParam,
|
|
131
140
|
getDumpDir,
|
|
141
|
+
getDumpDirPath,
|
|
132
142
|
getPkgInfo,
|
|
133
143
|
getTmpDir,
|
|
134
144
|
getTmpFile,
|
package/dist/types/ai-model.d.ts
CHANGED
|
@@ -9,7 +9,7 @@ declare function AiInspectElement<ElementType extends BaseElement = BaseElement>
|
|
|
9
9
|
context: UIContext<ElementType>;
|
|
10
10
|
multi: boolean;
|
|
11
11
|
findElementDescription: string;
|
|
12
|
-
callAI?: typeof callToGetJSONObject
|
|
12
|
+
callAI?: typeof callToGetJSONObject<AIElementParseResponse>;
|
|
13
13
|
}): Promise<{
|
|
14
14
|
parseResult: AIElementParseResponse;
|
|
15
15
|
elementById: (id: string) => ElementType;
|
package/dist/types/index.d.ts
CHANGED
|
@@ -4,19 +4,26 @@ export { e as AIElementParseResponse, A as AIResponseFormat, f as AISectionParse
|
|
|
4
4
|
export { setDumpDir } from './utils.js';
|
|
5
5
|
import 'openai/resources';
|
|
6
6
|
|
|
7
|
-
|
|
8
|
-
|
|
7
|
+
interface LocateOpts {
|
|
8
|
+
multi?: boolean;
|
|
9
|
+
callAI?: typeof callToGetJSONObject<AIElementParseResponse>;
|
|
10
|
+
}
|
|
11
|
+
declare class Insight<ElementType extends BaseElement = BaseElement, ContextType extends UIContext<ElementType> = UIContext<ElementType>> {
|
|
12
|
+
contextRetrieverFn: () => Promise<ContextType> | ContextType;
|
|
9
13
|
aiVendorFn: typeof callToGetJSONObject;
|
|
10
14
|
onceDumpUpdatedFn?: DumpSubscriber;
|
|
11
15
|
taskInfo?: Omit<InsightTaskInfo, 'durationMs'>;
|
|
12
|
-
constructor(context:
|
|
13
|
-
locate(queryPrompt: string
|
|
16
|
+
constructor(context: ContextType | (() => Promise<ContextType> | ContextType), opt?: InsightOptions);
|
|
17
|
+
locate(queryPrompt: string, opt?: {
|
|
18
|
+
callAI: LocateOpts['callAI'];
|
|
19
|
+
}): Promise<ElementType | null>;
|
|
14
20
|
locate(queryPrompt: string, opt: {
|
|
15
21
|
multi: true;
|
|
16
22
|
}): Promise<ElementType[]>;
|
|
17
23
|
extract<T = any>(input: string): Promise<T>;
|
|
18
24
|
extract<T extends Record<string, string>>(input: T): Promise<Record<keyof T, any>>;
|
|
19
25
|
extract<T extends object>(input: Record<keyof T, string>): Promise<T>;
|
|
26
|
+
setAiVendorFn<T>(aiVendorFn: typeof callToGetJSONObject<T>): () => void;
|
|
20
27
|
}
|
|
21
28
|
|
|
22
29
|
declare class Executor {
|
|
@@ -36,7 +43,10 @@ declare class Executor {
|
|
|
36
43
|
declare const getElement: typeof retrieveElement;
|
|
37
44
|
declare const getSection: typeof retrieveSection;
|
|
38
45
|
|
|
39
|
-
declare function plan(
|
|
46
|
+
declare function plan(userPrompt: string, opts: {
|
|
47
|
+
context: UIContext;
|
|
48
|
+
callAI?: typeof callToGetJSONObject<PlanningAIResponse>;
|
|
49
|
+
}): Promise<{
|
|
40
50
|
plans: PlanningAction[];
|
|
41
51
|
}>;
|
|
42
52
|
|
package/dist/types/utils.d.ts
CHANGED
|
@@ -10,11 +10,17 @@ declare const insightDumpFileExt = "insight-dump.json";
|
|
|
10
10
|
declare const groupedActionDumpFileExt = "web-dump.json";
|
|
11
11
|
declare function getDumpDir(): string;
|
|
12
12
|
declare function setDumpDir(dir: string): void;
|
|
13
|
-
declare function
|
|
13
|
+
declare function getDumpDirPath(type: 'dump' | 'cache'): string;
|
|
14
|
+
declare function writeDumpFile(opts: {
|
|
15
|
+
fileName: string;
|
|
16
|
+
fileExt: string;
|
|
17
|
+
fileContent: string;
|
|
18
|
+
type?: 'dump' | 'cache';
|
|
19
|
+
}): string;
|
|
14
20
|
declare function getTmpDir(): string;
|
|
15
|
-
declare function getTmpFile(
|
|
21
|
+
declare function getTmpFile(fileExtWithoutDot: string): string;
|
|
16
22
|
declare function overlapped(container: Rect, target: Rect): boolean;
|
|
17
23
|
declare function sleep(ms: number): Promise<unknown>;
|
|
18
24
|
declare const commonScreenshotParam: any;
|
|
19
25
|
|
|
20
|
-
export { commonScreenshotParam, getDumpDir, getPkgInfo, getTmpDir, getTmpFile, groupedActionDumpFileExt, insightDumpFileExt, overlapped, setDumpDir, sleep, writeDumpFile };
|
|
26
|
+
export { commonScreenshotParam, getDumpDir, getDumpDirPath, getPkgInfo, getTmpDir, getTmpFile, groupedActionDumpFileExt, insightDumpFileExt, overlapped, setDumpDir, sleep, writeDumpFile };
|
package/package.json
CHANGED
|
@@ -1,11 +1,15 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@midscene/core",
|
|
3
3
|
"description": "Hello, It's MidScene",
|
|
4
|
-
"version": "0.0
|
|
4
|
+
"version": "0.1.0",
|
|
5
5
|
"jsnext:source": "./src/index.ts",
|
|
6
6
|
"main": "./dist/lib/index.js",
|
|
7
7
|
"module": "./dist/es/index.js",
|
|
8
8
|
"types": "./dist/types/index.d.ts",
|
|
9
|
+
"files": [
|
|
10
|
+
"dist",
|
|
11
|
+
"README.md"
|
|
12
|
+
],
|
|
9
13
|
"exports": {
|
|
10
14
|
".": {
|
|
11
15
|
"types": "./dist/types/index.d.ts",
|
package/.eslintignore
DELETED
package/.eslintrc.js
DELETED