testdriverai 4.0.33 → 4.0.34
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/index.js +6 -7
- package/lib/commands.js +9 -12
- package/lib/sdk.js +2 -2
- package/lib/system.js +12 -35
- package/package.json +1 -1
package/index.js
CHANGED
|
@@ -170,7 +170,7 @@ const haveAIResolveError = async (error, markdown, depth = 0, undo = false) => {
|
|
|
170
170
|
|
|
171
171
|
let image;
|
|
172
172
|
if (error.attachScreenshot) {
|
|
173
|
-
image = await system.captureScreenBase64();
|
|
173
|
+
image = await system.captureScreenBase64(.5);
|
|
174
174
|
} else {
|
|
175
175
|
image = null;
|
|
176
176
|
}
|
|
@@ -196,7 +196,7 @@ const check = async () => {
|
|
|
196
196
|
|
|
197
197
|
console.log('')
|
|
198
198
|
log.log('info', chalk.dim('checking...'), 'testdriver')
|
|
199
|
-
let image = await system.captureScreenBase64();
|
|
199
|
+
let image = await system.captureScreenBase64(.5);
|
|
200
200
|
let mousePosition = await system.getMousePosition();
|
|
201
201
|
let activeWindow = await system.activeWin();
|
|
202
202
|
return await sdk.req('check', {tasks, image, mousePosition, activeWindow});
|
|
@@ -382,7 +382,7 @@ const humanInput = async (currentTask, validateAndLoop = false) => {
|
|
|
382
382
|
|
|
383
383
|
log.log('info', '');
|
|
384
384
|
|
|
385
|
-
let image = await system.captureScreenBase64();
|
|
385
|
+
let image = await system.captureScreenBase64(.5);
|
|
386
386
|
let message = await sdk.req('input', {
|
|
387
387
|
input: currentTask,
|
|
388
388
|
mousePosition: await system.getMousePosition(),
|
|
@@ -409,7 +409,7 @@ const generate = async (type) => {
|
|
|
409
409
|
|
|
410
410
|
log.log('info', '');
|
|
411
411
|
|
|
412
|
-
let image = await system.captureScreenBase64();
|
|
412
|
+
let image = await system.captureScreenBase64(.5);
|
|
413
413
|
let message = await sdk.req('generate', {
|
|
414
414
|
type,
|
|
415
415
|
image});
|
|
@@ -420,9 +420,8 @@ const generate = async (type) => {
|
|
|
420
420
|
|
|
421
421
|
// for each testPrompt
|
|
422
422
|
for (const testPrompt of testPrompts) {
|
|
423
|
-
// write a file called testprompt.headings[0].replace(' ', '-').toLowerCase().md
|
|
424
423
|
// with the contents of the testPrompt
|
|
425
|
-
let fileName = testPrompt.headings[0].trim().replace(/ /g, '-').toLowerCase() + '.md';
|
|
424
|
+
let fileName = sanitizeFilename(testPrompt.headings[0]).trim().replace(/ /g, '-').toLowerCase() + '.md';
|
|
426
425
|
let path1 = path.join(process.cwd(), 'testdriver', '.generate', fileName);
|
|
427
426
|
let contents = testPrompt.listsOrdered[0].map((item, index) => `${index + 1}. /explore ${item}`).join('\n');
|
|
428
427
|
fs.writeFileSync(path1, contents);
|
|
@@ -634,7 +633,7 @@ let summarize = async (error = null) => {
|
|
|
634
633
|
log.log('info', chalk.dim('reviewing test...'), true);
|
|
635
634
|
|
|
636
635
|
// let text = prompts.summarize(tasks, error);
|
|
637
|
-
let image = await system.captureScreenBase64();
|
|
636
|
+
let image = await system.captureScreenBase64(.5);
|
|
638
637
|
|
|
639
638
|
log.log('info', chalk.dim('summarizing...'), true);
|
|
640
639
|
|
package/lib/commands.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
// the actual commands to interact with the system
|
|
2
2
|
const sdk = require('./sdk');
|
|
3
3
|
const chalk = require('chalk');
|
|
4
|
-
const {captureScreenBase64, captureScreenPNG, platform,
|
|
4
|
+
const {captureScreenBase64, captureScreenPNG, platform, activeWin} = require('./system');
|
|
5
5
|
const {log} = require('./logger');
|
|
6
6
|
const keymap = require('./keymap');
|
|
7
7
|
const { focusApplication } = require('./focus-application');
|
|
@@ -31,7 +31,6 @@ class AiError extends Error {
|
|
|
31
31
|
const commandOrControl = process.platform === 'darwin' ? 'command' : 'control';
|
|
32
32
|
|
|
33
33
|
const findImageOnScreen = async (relativePath, haystack, restrictToWindow) => {
|
|
34
|
-
let displayMultiple = await getDisplayMultiple();
|
|
35
34
|
|
|
36
35
|
// move the file from filePath to `testdriver/screenshots`
|
|
37
36
|
let rootpath = path.join(cwd(), `testdriver`, `screenshots`, platform());
|
|
@@ -94,10 +93,10 @@ const findImageOnScreen = async (relativePath, haystack, restrictToWindow) => {
|
|
|
94
93
|
|
|
95
94
|
results = results.filter((el) => {
|
|
96
95
|
|
|
97
|
-
return el.centerX
|
|
98
|
-
&& el.centerX
|
|
99
|
-
&& el.centerY
|
|
100
|
-
&& el.centerY
|
|
96
|
+
return el.centerX > activeWindow.bounds.x
|
|
97
|
+
&& el.centerX < activeWindow.bounds.x + activeWindow.bounds.width
|
|
98
|
+
&& el.centerY > activeWindow.bounds.y
|
|
99
|
+
&& el.centerY < activeWindow.bounds.y + activeWindow.bounds.height;
|
|
101
100
|
|
|
102
101
|
});
|
|
103
102
|
}
|
|
@@ -250,7 +249,7 @@ let commands = {
|
|
|
250
249
|
button,
|
|
251
250
|
clickType,
|
|
252
251
|
description,
|
|
253
|
-
displayMultiple:
|
|
252
|
+
displayMultiple: 1
|
|
254
253
|
});
|
|
255
254
|
|
|
256
255
|
if (!response.data) {
|
|
@@ -275,7 +274,7 @@ let commands = {
|
|
|
275
274
|
intent: action,
|
|
276
275
|
button,
|
|
277
276
|
clickType,
|
|
278
|
-
displayMultiple:
|
|
277
|
+
displayMultiple: 1
|
|
279
278
|
});
|
|
280
279
|
|
|
281
280
|
if (!response?.data) {
|
|
@@ -293,16 +292,14 @@ let commands = {
|
|
|
293
292
|
|
|
294
293
|
let result = await findImageOnScreen(relativePath, image)
|
|
295
294
|
|
|
296
|
-
let displayMultiple = await getDisplayMultiple();
|
|
297
|
-
|
|
298
295
|
if (!result) {
|
|
299
296
|
throw new AiError(`Image not found: ${relativePath}`)
|
|
300
297
|
} else {
|
|
301
298
|
|
|
302
299
|
if (action === 'click') {
|
|
303
|
-
await click(result.centerX
|
|
300
|
+
await click(result.centerX, result.centerY, button, clickType);
|
|
304
301
|
} else if (action === 'hover') {
|
|
305
|
-
await hover(result.centerX
|
|
302
|
+
await hover(result.centerX, result.centerY);
|
|
306
303
|
}
|
|
307
304
|
}
|
|
308
305
|
|
package/lib/sdk.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
|
|
2
2
|
// custom "sdk" for calling our API
|
|
3
|
-
|
|
4
|
-
const root = "https://replayable-api-production.herokuapp.com";
|
|
3
|
+
const root = "https://replayable-dev-ian-mac-m1-16.ngrok.io";
|
|
4
|
+
// const root = "https://replayable-api-production.herokuapp.com";
|
|
5
5
|
const chalk = require('chalk');
|
|
6
6
|
const axios = require('axios');
|
|
7
7
|
const session = require('./session')
|
package/lib/system.js
CHANGED
|
@@ -8,7 +8,6 @@ const activeWindow = require('active-win');
|
|
|
8
8
|
const robot = require('robotjs');
|
|
9
9
|
const sharp = require('sharp')
|
|
10
10
|
|
|
11
|
-
let displayMultiple = 0;
|
|
12
11
|
let primaryDisplay = null;
|
|
13
12
|
|
|
14
13
|
// get the primary display
|
|
@@ -27,54 +26,34 @@ const getSystemInformationOsInfo = async() => {
|
|
|
27
26
|
return await si.osInfo();
|
|
28
27
|
}
|
|
29
28
|
|
|
30
|
-
// this hepls us understand how to scale things for retina screens
|
|
31
|
-
const calculateDisplayMultiple = async () => {
|
|
32
|
-
let primaryDisplay = await getPrimaryDisplay();
|
|
33
|
-
displayMultiple = primaryDisplay.currentResX / primaryDisplay.resolutionX;
|
|
34
|
-
};
|
|
35
|
-
|
|
36
|
-
const getDisplayMultiple = async () => {
|
|
37
|
-
|
|
38
|
-
if (!displayMultiple) {
|
|
39
|
-
await calculateDisplayMultiple();
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
return displayMultiple;
|
|
43
|
-
};
|
|
44
|
-
|
|
45
29
|
const tmpFilename = () => {
|
|
46
30
|
return path.join(os.tmpdir(), `${new Date().getTime() + Math.random()}.png`);
|
|
47
31
|
}
|
|
48
32
|
|
|
49
|
-
|
|
50
|
-
const captureScreenBase64 = async () => {
|
|
51
|
-
|
|
33
|
+
const captureAndResize = async(scale = 1) => {
|
|
52
34
|
let primaryDisplay = await getPrimaryDisplay();
|
|
53
35
|
|
|
54
36
|
let step1 = tmpFilename();
|
|
55
37
|
let step2 = tmpFilename();
|
|
56
38
|
|
|
57
|
-
await screenshot({ filename: step1, format: 'png' });
|
|
39
|
+
let step1Screenshot = await screenshot({ filename: step1, format: 'png' });
|
|
58
40
|
|
|
59
|
-
|
|
41
|
+
// resize to 1:1 px ratio
|
|
60
42
|
await sharp(step1)
|
|
61
|
-
.resize(primaryDisplay.currentResX, primaryDisplay.currentResY)
|
|
43
|
+
.resize(Math.floor(primaryDisplay.currentResX * scale), Math.floor(primaryDisplay.currentResY * scale))
|
|
62
44
|
.toFile(step2);
|
|
63
45
|
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
return image;
|
|
46
|
+
return step2;
|
|
47
|
+
}
|
|
68
48
|
|
|
49
|
+
// our handy screenshot function
|
|
50
|
+
const captureScreenBase64 = async (scale = 1) => {
|
|
51
|
+
let step2 = await captureAndResize(scale);
|
|
52
|
+
return fs.readFileSync(step2, "base64");
|
|
69
53
|
};
|
|
70
54
|
|
|
71
|
-
const captureScreenPNG = async () => {
|
|
72
|
-
|
|
73
|
-
let step1 = tmpFilename();
|
|
74
|
-
await screenshot({ filename: step1, format: 'png' });
|
|
75
|
-
|
|
76
|
-
return step1;
|
|
77
|
-
|
|
55
|
+
const captureScreenPNG = async (scale = 1) => {
|
|
56
|
+
return await captureAndResize(scale);
|
|
78
57
|
}
|
|
79
58
|
|
|
80
59
|
const platform = () => {
|
|
@@ -103,8 +82,6 @@ const getMousePosition = async () => {
|
|
|
103
82
|
module.exports = {
|
|
104
83
|
captureScreenBase64,
|
|
105
84
|
captureScreenPNG,
|
|
106
|
-
getDisplayMultiple,
|
|
107
|
-
calculateDisplayMultiple,
|
|
108
85
|
getMousePosition,
|
|
109
86
|
primaryDisplay,
|
|
110
87
|
activeWin,
|