askui 0.30.0 → 0.32.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/cjs/core/cache/cache-config.d.ts +5 -0
- package/dist/cjs/core/cache/cache-config.js +2 -0
- package/dist/cjs/core/cache/cache-entry-reference.d.ts +7 -0
- package/dist/cjs/core/cache/cache-entry-reference.js +20 -0
- package/dist/cjs/core/cache/cache-entry.d.ts +11 -0
- package/dist/cjs/core/cache/cache-entry.js +47 -0
- package/dist/cjs/core/cache/cache-interface.d.ts +11 -0
- package/dist/cjs/core/cache/cache-interface.js +2 -0
- package/dist/cjs/core/cache/cache-manager.d.ts +24 -0
- package/dist/cjs/core/cache/cache-manager.js +145 -0
- package/dist/cjs/core/cache/cahe-file.d.ts +19 -0
- package/dist/cjs/core/cache/cahe-file.js +128 -0
- package/dist/cjs/core/cache/dummy-cache-manager.d.ts +12 -0
- package/dist/cjs/core/cache/dummy-cache-manager.js +27 -0
- package/dist/cjs/core/cache/image-reference.d.ts +10 -0
- package/dist/cjs/core/cache/image-reference.js +40 -0
- package/dist/cjs/core/cache/index.d.ts +7 -0
- package/dist/cjs/core/cache/index.js +13 -0
- package/dist/cjs/core/model/annotation-result/boundary-box.js +1 -1
- package/dist/cjs/core/model/custom-element.d.ts +1 -0
- package/dist/cjs/core/model/custom-element.js +3 -0
- package/dist/cjs/core/ui-control-commands/action.d.ts +1 -0
- package/dist/cjs/core/ui-control-commands/action.js +10 -2
- package/dist/cjs/core/ui-control-commands/control-command.d.ts +1 -0
- package/dist/cjs/core/ui-control-commands/control-command.js +7 -0
- package/dist/cjs/execution/dsl.d.ts +12 -5
- package/dist/cjs/execution/dsl.js +30 -15
- package/dist/cjs/execution/execution-runtime.d.ts +1 -1
- package/dist/cjs/execution/execution-runtime.js +21 -17
- package/dist/cjs/execution/inference-client.d.ts +5 -3
- package/dist/cjs/execution/inference-client.js +22 -3
- package/dist/cjs/execution/ui-control-client-dependency-builder.js +6 -1
- package/dist/cjs/execution/ui-control-client.d.ts +2 -1
- package/dist/cjs/execution/ui-control-client.js +28 -11
- package/dist/cjs/execution/ui-controller-client-interface.d.ts +2 -0
- package/dist/cjs/utils/base_64_image/base-64-image.d.ts +2 -0
- package/dist/cjs/utils/base_64_image/base-64-image.js +27 -4
- package/dist/cjs/utils/http/http-client-got.d.ts +15 -0
- package/dist/cjs/utils/http/http-client-got.js +59 -11
- package/dist/esm/core/cache/cache-config.d.ts +5 -0
- package/dist/esm/core/cache/cache-config.js +1 -0
- package/dist/esm/core/cache/cache-entry-reference.d.ts +7 -0
- package/dist/esm/core/cache/cache-entry-reference.js +16 -0
- package/dist/esm/core/cache/cache-entry.d.ts +11 -0
- package/dist/esm/core/cache/cache-entry.js +43 -0
- package/dist/esm/core/cache/cache-interface.d.ts +11 -0
- package/dist/esm/core/cache/cache-interface.js +1 -0
- package/dist/esm/core/cache/cache-manager.d.ts +24 -0
- package/dist/esm/core/cache/cache-manager.js +141 -0
- package/dist/esm/core/cache/cahe-file.d.ts +19 -0
- package/dist/esm/core/cache/cahe-file.js +121 -0
- package/dist/esm/core/cache/dummy-cache-manager.d.ts +12 -0
- package/dist/esm/core/cache/dummy-cache-manager.js +23 -0
- package/dist/esm/core/cache/image-reference.d.ts +10 -0
- package/dist/esm/core/cache/image-reference.js +36 -0
- package/dist/esm/core/cache/index.d.ts +7 -0
- package/dist/esm/core/cache/index.js +5 -0
- package/dist/esm/core/model/annotation-result/boundary-box.js +1 -1
- package/dist/esm/core/model/custom-element.d.ts +1 -0
- package/dist/esm/core/model/custom-element.js +3 -0
- package/dist/esm/core/ui-control-commands/action.d.ts +1 -0
- package/dist/esm/core/ui-control-commands/action.js +10 -2
- package/dist/esm/core/ui-control-commands/control-command.d.ts +1 -0
- package/dist/esm/core/ui-control-commands/control-command.js +7 -0
- package/dist/esm/execution/dsl.d.ts +12 -5
- package/dist/esm/execution/dsl.js +30 -15
- package/dist/esm/execution/execution-runtime.d.ts +1 -1
- package/dist/esm/execution/execution-runtime.js +21 -17
- package/dist/esm/execution/inference-client.d.ts +5 -3
- package/dist/esm/execution/inference-client.js +22 -3
- package/dist/esm/execution/ui-control-client-dependency-builder.js +6 -1
- package/dist/esm/execution/ui-control-client.d.ts +2 -1
- package/dist/esm/execution/ui-control-client.js +28 -11
- package/dist/esm/execution/ui-controller-client-interface.d.ts +2 -0
- package/dist/esm/utils/base_64_image/base-64-image.d.ts +2 -0
- package/dist/esm/utils/base_64_image/base-64-image.js +27 -4
- package/dist/esm/utils/http/http-client-got.d.ts +15 -0
- package/dist/esm/utils/http/http-client-got.js +36 -8
- package/package.json +4 -2
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { ImageReference } from './image-reference';
|
|
2
|
+
export declare class CacheEntryReference {
|
|
3
|
+
image?: ImageReference | undefined;
|
|
4
|
+
constructor(image?: ImageReference | undefined);
|
|
5
|
+
static fromJson(json: CacheEntryReference): CacheEntryReference;
|
|
6
|
+
toJson(): Record<string, unknown>;
|
|
7
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.CacheEntryReference = void 0;
|
|
4
|
+
const image_reference_1 = require("./image-reference");
|
|
5
|
+
class CacheEntryReference {
|
|
6
|
+
constructor(image) {
|
|
7
|
+
this.image = image;
|
|
8
|
+
}
|
|
9
|
+
static fromJson(json) {
|
|
10
|
+
return new CacheEntryReference(json.image ? image_reference_1.ImageReference.fromJson(json.image) : undefined);
|
|
11
|
+
}
|
|
12
|
+
toJson() {
|
|
13
|
+
const jsonObject = {};
|
|
14
|
+
if (this.image !== undefined) {
|
|
15
|
+
jsonObject['image'] = this.image.toJson();
|
|
16
|
+
}
|
|
17
|
+
return jsonObject;
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
exports.CacheEntryReference = CacheEntryReference;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { ControlCommand } from '../ui-control-commands';
|
|
2
|
+
import { CacheEntryReference } from './cache-entry-reference';
|
|
3
|
+
export declare class CacheEntry {
|
|
4
|
+
alwaysValid: boolean;
|
|
5
|
+
controlCommand: ControlCommand;
|
|
6
|
+
reference?: CacheEntryReference | undefined;
|
|
7
|
+
createdAt: Date;
|
|
8
|
+
constructor(alwaysValid: boolean, controlCommand: ControlCommand, reference?: CacheEntryReference | undefined, createdAt?: Date);
|
|
9
|
+
static fromJson(json: CacheEntry): CacheEntry | undefined;
|
|
10
|
+
toJson(): Record<string, unknown>;
|
|
11
|
+
}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.CacheEntry = void 0;
|
|
4
|
+
const ui_control_commands_1 = require("../ui-control-commands");
|
|
5
|
+
const cache_entry_reference_1 = require("./cache-entry-reference");
|
|
6
|
+
const lib_1 = require("../../lib");
|
|
7
|
+
class CacheEntry {
|
|
8
|
+
constructor(alwaysValid, controlCommand, reference, createdAt = new Date()) {
|
|
9
|
+
this.alwaysValid = alwaysValid;
|
|
10
|
+
this.controlCommand = controlCommand;
|
|
11
|
+
this.reference = reference;
|
|
12
|
+
this.createdAt = createdAt;
|
|
13
|
+
}
|
|
14
|
+
static fromJson(json) {
|
|
15
|
+
try {
|
|
16
|
+
if (json === undefined) {
|
|
17
|
+
throw new Error('Cache entry is undefined');
|
|
18
|
+
}
|
|
19
|
+
if (json.controlCommand === undefined) {
|
|
20
|
+
throw new Error('the key "controlCommand" is required');
|
|
21
|
+
}
|
|
22
|
+
if (json.createdAt === undefined) {
|
|
23
|
+
throw new Error('the key "createdAt" is required');
|
|
24
|
+
}
|
|
25
|
+
if (json.alwaysValid === undefined) {
|
|
26
|
+
throw new Error('the key "alwaysValid" is required');
|
|
27
|
+
}
|
|
28
|
+
return new CacheEntry(json.alwaysValid, ui_control_commands_1.ControlCommand.fromJson(json.controlCommand), json.reference ? cache_entry_reference_1.CacheEntryReference.fromJson(json.reference) : undefined, new Date(json.createdAt));
|
|
29
|
+
}
|
|
30
|
+
catch (error) {
|
|
31
|
+
lib_1.logger.error(`Error deserializing cache entry: ${error}`);
|
|
32
|
+
return undefined;
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
toJson() {
|
|
36
|
+
const jsonObject = {
|
|
37
|
+
alwaysValid: this.alwaysValid,
|
|
38
|
+
controlCommand: this.controlCommand.toJson(),
|
|
39
|
+
createdAt: this.createdAt,
|
|
40
|
+
};
|
|
41
|
+
if (this.reference !== undefined) {
|
|
42
|
+
jsonObject['reference'] = this.reference.toJson();
|
|
43
|
+
}
|
|
44
|
+
return jsonObject;
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
exports.CacheEntry = CacheEntry;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { CustomElement } from '../model/custom-element';
|
|
2
|
+
import { ControlCommand } from '../ui-control-commands';
|
|
3
|
+
import { CacheEntry } from './cache-entry';
|
|
4
|
+
export interface CacheInterface {
|
|
5
|
+
loadFromFile(): void;
|
|
6
|
+
saveToFile(): void;
|
|
7
|
+
add(key: string, value: CacheEntry): void;
|
|
8
|
+
addCacheEntryFromControlCommand(instruction: string, controlCommand: ControlCommand, customElements: CustomElement[], image?: string): Promise<void>;
|
|
9
|
+
isImageRequired(instruction: string, customElements: CustomElement[]): boolean | undefined;
|
|
10
|
+
getCachedControlCommand(instruction: string, customElements: CustomElement[], image?: string): Promise<ControlCommand | undefined>;
|
|
11
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { ControlCommand } from '../ui-control-commands';
|
|
2
|
+
import { CacheInterface } from './cache-interface';
|
|
3
|
+
import { CacheEntry } from './cache-entry';
|
|
4
|
+
import { CacheConfig, ValidationType } from './cache-config';
|
|
5
|
+
import { CustomElement } from '../model/custom-element';
|
|
6
|
+
export declare class CacheManager implements CacheInterface {
|
|
7
|
+
private relevantData;
|
|
8
|
+
validationType: ValidationType;
|
|
9
|
+
private cacheFile;
|
|
10
|
+
private readonly referenceWidth;
|
|
11
|
+
private readonly referenceHeight;
|
|
12
|
+
private readonly defaultValidationType;
|
|
13
|
+
constructor(config: CacheConfig);
|
|
14
|
+
loadFromFile(): void;
|
|
15
|
+
saveToFile(): void;
|
|
16
|
+
add(key: string, value: CacheEntry): void;
|
|
17
|
+
addCacheEntryFromControlCommand(instruction: string, controlCommand: ControlCommand, customElements: CustomElement[], image?: string): Promise<void>;
|
|
18
|
+
isImageRequired(instruction: string, customElements: CustomElement[]): boolean | undefined;
|
|
19
|
+
getCachedControlCommand(instruction: string, customElements: CustomElement[], image?: string): Promise<ControlCommand | undefined>;
|
|
20
|
+
private encodeKey;
|
|
21
|
+
private getCacheEntriesByKey;
|
|
22
|
+
private getValidCacheEntry;
|
|
23
|
+
private validateAccordingToPixelPerfect;
|
|
24
|
+
}
|
|
@@ -0,0 +1,145 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.CacheManager = void 0;
|
|
13
|
+
const ui_control_commands_1 = require("../ui-control-commands");
|
|
14
|
+
const input_event_1 = require("../ui-control-commands/input-event");
|
|
15
|
+
const base_64_image_1 = require("../../utils/base_64_image/base-64-image");
|
|
16
|
+
const cache_entry_1 = require("./cache-entry");
|
|
17
|
+
const image_reference_1 = require("./image-reference");
|
|
18
|
+
const cache_entry_reference_1 = require("./cache-entry-reference");
|
|
19
|
+
const cahe_file_1 = require("./cahe-file");
|
|
20
|
+
class CacheManager {
|
|
21
|
+
constructor(config) {
|
|
22
|
+
var _a;
|
|
23
|
+
this.relevantData = {};
|
|
24
|
+
this.referenceWidth = 32;
|
|
25
|
+
this.referenceHeight = 16;
|
|
26
|
+
this.defaultValidationType = 'PixelPerfect';
|
|
27
|
+
this.validationType = (_a = config.validationType) !== null && _a !== void 0 ? _a : this.defaultValidationType;
|
|
28
|
+
this.cacheFile = new cahe_file_1.CacheFile(config.cacheFilePath);
|
|
29
|
+
}
|
|
30
|
+
loadFromFile() {
|
|
31
|
+
this.cacheFile.loadFromFile();
|
|
32
|
+
this.relevantData = this.cacheFile.getDataForValidationType(this.validationType);
|
|
33
|
+
}
|
|
34
|
+
saveToFile() {
|
|
35
|
+
this.cacheFile.saveToFile(this.validationType, this.relevantData);
|
|
36
|
+
}
|
|
37
|
+
add(key, value) {
|
|
38
|
+
if (this.relevantData[key] === undefined) {
|
|
39
|
+
this.relevantData[key] = [];
|
|
40
|
+
}
|
|
41
|
+
this.relevantData[key].push(value);
|
|
42
|
+
}
|
|
43
|
+
addCacheEntryFromControlCommand(instruction, controlCommand, customElements, image) {
|
|
44
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
45
|
+
let imageReference;
|
|
46
|
+
if (image !== undefined) {
|
|
47
|
+
const moveAction = controlCommand.actions.find((action) => action.inputEvent === input_event_1.InputEvent.MOUSE_MOVE);
|
|
48
|
+
const x = moveAction === null || moveAction === void 0 ? void 0 : moveAction.position.x;
|
|
49
|
+
const y = moveAction === null || moveAction === void 0 ? void 0 : moveAction.position.y;
|
|
50
|
+
if (x !== undefined && y !== undefined) {
|
|
51
|
+
const xTopLeft = Math.max(0, (x - this.referenceWidth / 2));
|
|
52
|
+
const yTopLeft = Math.max(0, (y - this.referenceHeight / 2));
|
|
53
|
+
const base64Image = yield base_64_image_1.Base64Image.fromString(image);
|
|
54
|
+
const croppedImage = yield base64Image.cropRegion(xTopLeft, yTopLeft, this.referenceWidth, this.referenceHeight);
|
|
55
|
+
imageReference = new image_reference_1.ImageReference(croppedImage.toString(true), this.referenceWidth, this.referenceHeight, xTopLeft, yTopLeft);
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
const cacheEntry = new cache_entry_1.CacheEntry(image === undefined, controlCommand, new cache_entry_reference_1.CacheEntryReference(imageReference));
|
|
59
|
+
const cacheKey = this.encodeKey(instruction, customElements);
|
|
60
|
+
this.add(cacheKey, cacheEntry);
|
|
61
|
+
});
|
|
62
|
+
}
|
|
63
|
+
isImageRequired(instruction, customElements) {
|
|
64
|
+
const cacheKey = this.encodeKey(instruction, customElements);
|
|
65
|
+
const cacheEntries = this.getCacheEntriesByKey(cacheKey);
|
|
66
|
+
if (cacheEntries.length === 0) {
|
|
67
|
+
return undefined;
|
|
68
|
+
}
|
|
69
|
+
return cacheEntries.find((entry) => entry.alwaysValid === false) !== undefined;
|
|
70
|
+
}
|
|
71
|
+
getCachedControlCommand(instruction, customElements, image) {
|
|
72
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
73
|
+
const cacheKey = this.encodeKey(instruction, customElements);
|
|
74
|
+
const cacheEntry = yield this.getValidCacheEntry(cacheKey, image);
|
|
75
|
+
if (cacheEntry === undefined || cacheEntry.controlCommand.code !== ui_control_commands_1.ControlCommandCode.OK) {
|
|
76
|
+
return undefined;
|
|
77
|
+
}
|
|
78
|
+
return cacheEntry.controlCommand;
|
|
79
|
+
});
|
|
80
|
+
}
|
|
81
|
+
// eslint-disable-next-line class-methods-use-this
|
|
82
|
+
encodeKey(instruction, customElements) {
|
|
83
|
+
let key = instruction;
|
|
84
|
+
if (customElements.length > 0) {
|
|
85
|
+
key += ` with CustomElements:${customElements.map((element, index) => `${index}:${element.asString()}`).join(',')}`;
|
|
86
|
+
}
|
|
87
|
+
return key;
|
|
88
|
+
}
|
|
89
|
+
getCacheEntriesByKey(key) {
|
|
90
|
+
if (this.relevantData[key] === undefined) {
|
|
91
|
+
return [];
|
|
92
|
+
}
|
|
93
|
+
const entries = this.relevantData[key];
|
|
94
|
+
if (entries === undefined) {
|
|
95
|
+
return [];
|
|
96
|
+
}
|
|
97
|
+
return entries;
|
|
98
|
+
}
|
|
99
|
+
getValidCacheEntry(key, screenshot) {
|
|
100
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
101
|
+
const cacheEntries = this.getCacheEntriesByKey(key);
|
|
102
|
+
if (cacheEntries.length === 0) {
|
|
103
|
+
return undefined;
|
|
104
|
+
}
|
|
105
|
+
if (this.validationType === 'PixelPerfect') {
|
|
106
|
+
/* eslint-disable no-restricted-syntax, no-await-in-loop */
|
|
107
|
+
for (const cacheEntry of cacheEntries) {
|
|
108
|
+
if (cacheEntry.alwaysValid) {
|
|
109
|
+
return cacheEntry;
|
|
110
|
+
}
|
|
111
|
+
const isValid = yield this.validateAccordingToPixelPerfect(cacheEntry, screenshot);
|
|
112
|
+
if (isValid) {
|
|
113
|
+
/* eslint-enable no-restricted-syntax, no-await-in-loop */
|
|
114
|
+
return cacheEntry;
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
/* eslint-enable no-restricted-syntax, no-await-in-loop */
|
|
118
|
+
}
|
|
119
|
+
return undefined;
|
|
120
|
+
});
|
|
121
|
+
}
|
|
122
|
+
// eslint-disable-next-line class-methods-use-this
|
|
123
|
+
validateAccordingToPixelPerfect(cacheEntry, screenshot) {
|
|
124
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
125
|
+
var _a;
|
|
126
|
+
if (screenshot === undefined) {
|
|
127
|
+
return false;
|
|
128
|
+
}
|
|
129
|
+
if (((_a = cacheEntry.reference) === null || _a === void 0 ? void 0 : _a.image) === undefined) {
|
|
130
|
+
return false;
|
|
131
|
+
}
|
|
132
|
+
try {
|
|
133
|
+
const referenceImage = yield base_64_image_1.Base64Image.fromString(screenshot);
|
|
134
|
+
const croppedScreenshot = yield referenceImage.cropRegion(cacheEntry.reference.image.xTopLeft, cacheEntry.reference.image.yTopLeft, cacheEntry.reference.image.width, cacheEntry.reference.image.height);
|
|
135
|
+
const croppedReferenceImageString = croppedScreenshot.toString(true);
|
|
136
|
+
const isValid = croppedReferenceImageString === cacheEntry.reference.image.base64Image;
|
|
137
|
+
return isValid;
|
|
138
|
+
}
|
|
139
|
+
catch (error) {
|
|
140
|
+
return false;
|
|
141
|
+
}
|
|
142
|
+
});
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
exports.CacheManager = CacheManager;
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { CacheEntry } from './cache-entry';
|
|
2
|
+
import { ValidationType } from './cache-config';
|
|
3
|
+
export type CacheDataByInstruction = Record<string, CacheEntry[]>;
|
|
4
|
+
export type CacheDataByValidationType = Record<string, CacheDataByInstruction>;
|
|
5
|
+
export declare class CacheFile {
|
|
6
|
+
private createAt;
|
|
7
|
+
private version;
|
|
8
|
+
private type;
|
|
9
|
+
private data;
|
|
10
|
+
private filePath;
|
|
11
|
+
constructor(filePath?: string);
|
|
12
|
+
loadFromFileVersion1(json: CacheFile): void;
|
|
13
|
+
loadFromFile(): void;
|
|
14
|
+
getDataForValidationType(validationType: ValidationType): CacheDataByInstruction;
|
|
15
|
+
getData(): CacheDataByValidationType;
|
|
16
|
+
saveToFile(validationType: ValidationType, relevantData: CacheDataByInstruction): void;
|
|
17
|
+
private setRelevantData;
|
|
18
|
+
private asJsonObject;
|
|
19
|
+
}
|
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.CacheFile = void 0;
|
|
7
|
+
const fs_1 = __importDefault(require("fs"));
|
|
8
|
+
const path_1 = __importDefault(require("path"));
|
|
9
|
+
const lib_1 = require("../../lib");
|
|
10
|
+
const cache_entry_1 = require("./cache-entry");
|
|
11
|
+
class CacheFile {
|
|
12
|
+
constructor(filePath) {
|
|
13
|
+
this.createAt = new Date();
|
|
14
|
+
this.version = 1;
|
|
15
|
+
this.type = 'AskUI-Cache';
|
|
16
|
+
this.data = {};
|
|
17
|
+
this.filePath = filePath;
|
|
18
|
+
}
|
|
19
|
+
loadFromFileVersion1(json) {
|
|
20
|
+
if (json.version !== 1) {
|
|
21
|
+
throw new Error(`Unsupported key 'version' in the cache file: '${json.version}'. Only version 1 is supported.`);
|
|
22
|
+
}
|
|
23
|
+
if (json.data === undefined) {
|
|
24
|
+
throw new Error("Key 'data' is required in the cache file.");
|
|
25
|
+
}
|
|
26
|
+
if (json.createAt === undefined) {
|
|
27
|
+
throw new Error("Key 'createAt' is required in the cache file.");
|
|
28
|
+
}
|
|
29
|
+
if (json.version === undefined) {
|
|
30
|
+
throw new Error("Key 'version' is required in the cache file.");
|
|
31
|
+
}
|
|
32
|
+
if (json.type !== 'AskUI-Cache') {
|
|
33
|
+
throw new Error(`Unsupported key 'type' in the cache file: '${json.type}'. Only 'AskUI-Cache' is supported.`);
|
|
34
|
+
}
|
|
35
|
+
this.createAt = new Date(json.createAt);
|
|
36
|
+
this.version = json.version;
|
|
37
|
+
this.type = json.type;
|
|
38
|
+
this.data = Object.keys(json.data).reduce((acc, validationType) => {
|
|
39
|
+
var _a, _b;
|
|
40
|
+
const nextAcc = Object.assign({}, acc);
|
|
41
|
+
const validationEntries = (_b = (_a = json.data) === null || _a === void 0 ? void 0 : _a[validationType]) !== null && _b !== void 0 ? _b : {};
|
|
42
|
+
nextAcc[validationType] = Object.keys(validationEntries).reduce((innerAcc, instruction) => {
|
|
43
|
+
var _a;
|
|
44
|
+
const nextInnerAcc = Object.assign({}, innerAcc);
|
|
45
|
+
const rawEntries = (_a = validationEntries[instruction]) !== null && _a !== void 0 ? _a : [];
|
|
46
|
+
nextInnerAcc[instruction] = rawEntries
|
|
47
|
+
.map((entry) => cache_entry_1.CacheEntry.fromJson(entry))
|
|
48
|
+
.filter((entry) => entry !== undefined);
|
|
49
|
+
return nextInnerAcc;
|
|
50
|
+
}, {});
|
|
51
|
+
return nextAcc;
|
|
52
|
+
}, {});
|
|
53
|
+
}
|
|
54
|
+
loadFromFile() {
|
|
55
|
+
if (this.filePath === undefined) {
|
|
56
|
+
lib_1.logger.debug('The cache file path is not set. Skipping the cache load.');
|
|
57
|
+
return;
|
|
58
|
+
}
|
|
59
|
+
lib_1.logger.debug(`Loading the cache from file '${this.filePath}'.`);
|
|
60
|
+
if (!fs_1.default.existsSync(this.filePath)) {
|
|
61
|
+
lib_1.logger.warn(`The cache file does not exist: '${this.filePath}'. Skipping the cache load.`);
|
|
62
|
+
return;
|
|
63
|
+
}
|
|
64
|
+
const data = fs_1.default.readFileSync(this.filePath, 'utf8');
|
|
65
|
+
const json = JSON.parse(data);
|
|
66
|
+
if (json.version !== 1) {
|
|
67
|
+
throw new Error(`Unsupported key 'version' in the cache file: '${json.version}'. Only version 1 is supported.`);
|
|
68
|
+
}
|
|
69
|
+
this.loadFromFileVersion1(json);
|
|
70
|
+
}
|
|
71
|
+
getDataForValidationType(validationType) {
|
|
72
|
+
var _a;
|
|
73
|
+
return (_a = this.data[validationType]) !== null && _a !== void 0 ? _a : {};
|
|
74
|
+
}
|
|
75
|
+
getData() {
|
|
76
|
+
return this.data;
|
|
77
|
+
}
|
|
78
|
+
saveToFile(validationType, relevantData) {
|
|
79
|
+
if (this.filePath === undefined) {
|
|
80
|
+
lib_1.logger.debug('The cache file path is not set. Skipping the cache save.');
|
|
81
|
+
return;
|
|
82
|
+
}
|
|
83
|
+
try {
|
|
84
|
+
lib_1.logger.debug(`Saving the cache to file '${this.filePath}'.`);
|
|
85
|
+
this.setRelevantData(validationType, relevantData);
|
|
86
|
+
const jsonObject = this.asJsonObject();
|
|
87
|
+
const jsonString = JSON.stringify(jsonObject, null, 2);
|
|
88
|
+
// create the directory if it doesn't exist
|
|
89
|
+
if (!fs_1.default.existsSync(path_1.default.dirname(this.filePath))) {
|
|
90
|
+
fs_1.default.mkdirSync(path_1.default.dirname(this.filePath), { recursive: true });
|
|
91
|
+
}
|
|
92
|
+
fs_1.default.writeFileSync(this.filePath, jsonString, 'utf8');
|
|
93
|
+
lib_1.logger.info(`The cache was saved successfully to '${this.filePath}'.`);
|
|
94
|
+
}
|
|
95
|
+
catch (error) {
|
|
96
|
+
lib_1.logger.error(`An error occurred while saving the cache to file '${this.filePath}': '${error}'`);
|
|
97
|
+
throw error;
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
setRelevantData(validationType, relevantData) {
|
|
101
|
+
this.data[validationType] = relevantData;
|
|
102
|
+
}
|
|
103
|
+
asJsonObject() {
|
|
104
|
+
return {
|
|
105
|
+
createAt: this.createAt.toISOString(),
|
|
106
|
+
data: Object.keys(this.data).reduce((acc, validationType) => {
|
|
107
|
+
const validationData = this.data[validationType];
|
|
108
|
+
if (validationData === undefined) {
|
|
109
|
+
return acc;
|
|
110
|
+
}
|
|
111
|
+
const nextAcc = Object.assign({}, acc);
|
|
112
|
+
nextAcc[validationType] = Object.keys(validationData).reduce((innerAcc, instruction) => {
|
|
113
|
+
const entries = validationData[instruction];
|
|
114
|
+
if (entries !== undefined) {
|
|
115
|
+
const nextInnerAcc = Object.assign({}, innerAcc);
|
|
116
|
+
nextInnerAcc[instruction] = entries;
|
|
117
|
+
return nextInnerAcc;
|
|
118
|
+
}
|
|
119
|
+
return innerAcc;
|
|
120
|
+
}, {});
|
|
121
|
+
return nextAcc;
|
|
122
|
+
}, {}),
|
|
123
|
+
type: this.type,
|
|
124
|
+
version: this.version,
|
|
125
|
+
};
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
exports.CacheFile = CacheFile;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { CacheInterface } from './cache-interface';
|
|
2
|
+
import { CacheEntry } from './cache-entry';
|
|
3
|
+
import { ControlCommand } from '../ui-control-commands';
|
|
4
|
+
import { CustomElement } from '../model/custom-element';
|
|
5
|
+
export declare class DummyCacheManager implements CacheInterface {
|
|
6
|
+
add(_key: string, _value: CacheEntry): void;
|
|
7
|
+
addCacheEntryFromControlCommand(_instruction: string, _controlCommand: ControlCommand, _customElements: CustomElement[], _image?: string): Promise<void>;
|
|
8
|
+
isImageRequired(_instruction: string, _customElements: CustomElement[]): boolean | undefined;
|
|
9
|
+
getCachedControlCommand(_instruction: string, _customElements: CustomElement[], _image?: string): Promise<ControlCommand | undefined>;
|
|
10
|
+
loadFromFile(): void;
|
|
11
|
+
saveToFile(): void;
|
|
12
|
+
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.DummyCacheManager = void 0;
|
|
4
|
+
class DummyCacheManager {
|
|
5
|
+
// eslint-disable-next-line class-methods-use-this
|
|
6
|
+
add(_key, _value) {
|
|
7
|
+
}
|
|
8
|
+
// eslint-disable-next-line class-methods-use-this
|
|
9
|
+
addCacheEntryFromControlCommand(_instruction, _controlCommand, _customElements, _image) {
|
|
10
|
+
return Promise.resolve();
|
|
11
|
+
}
|
|
12
|
+
// eslint-disable-next-line class-methods-use-this
|
|
13
|
+
isImageRequired(_instruction, _customElements) {
|
|
14
|
+
return undefined;
|
|
15
|
+
}
|
|
16
|
+
// eslint-disable-next-line class-methods-use-this
|
|
17
|
+
getCachedControlCommand(_instruction, _customElements, _image) {
|
|
18
|
+
return Promise.resolve(undefined);
|
|
19
|
+
}
|
|
20
|
+
// eslint-disable-next-line class-methods-use-this
|
|
21
|
+
loadFromFile() {
|
|
22
|
+
}
|
|
23
|
+
// eslint-disable-next-line class-methods-use-this
|
|
24
|
+
saveToFile() {
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
exports.DummyCacheManager = DummyCacheManager;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
export declare class ImageReference {
|
|
2
|
+
base64Image: string;
|
|
3
|
+
width: number;
|
|
4
|
+
height: number;
|
|
5
|
+
xTopLeft: number;
|
|
6
|
+
yTopLeft: number;
|
|
7
|
+
constructor(base64Image: string, width: number, height: number, xTopLeft: number, yTopLeft: number);
|
|
8
|
+
static fromJson(json: ImageReference): ImageReference;
|
|
9
|
+
toJson(): Record<string, unknown>;
|
|
10
|
+
}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ImageReference = void 0;
|
|
4
|
+
class ImageReference {
|
|
5
|
+
constructor(base64Image, width, height, xTopLeft, yTopLeft) {
|
|
6
|
+
this.base64Image = base64Image;
|
|
7
|
+
this.width = width;
|
|
8
|
+
this.height = height;
|
|
9
|
+
this.xTopLeft = xTopLeft;
|
|
10
|
+
this.yTopLeft = yTopLeft;
|
|
11
|
+
}
|
|
12
|
+
static fromJson(json) {
|
|
13
|
+
if (json.base64Image === undefined) {
|
|
14
|
+
throw new Error('the key "base64Image" is required');
|
|
15
|
+
}
|
|
16
|
+
if (json.width === undefined) {
|
|
17
|
+
throw new Error('the key "width" is required');
|
|
18
|
+
}
|
|
19
|
+
if (json.height === undefined) {
|
|
20
|
+
throw new Error('the key "height" is required');
|
|
21
|
+
}
|
|
22
|
+
if (json.xTopLeft === undefined) {
|
|
23
|
+
throw new Error('the key "xTopLeft" is required');
|
|
24
|
+
}
|
|
25
|
+
if (json.yTopLeft === undefined) {
|
|
26
|
+
throw new Error('the key "yTopLeft" is required');
|
|
27
|
+
}
|
|
28
|
+
return new ImageReference(json.base64Image, json.width, json.height, json.xTopLeft, json.yTopLeft);
|
|
29
|
+
}
|
|
30
|
+
toJson() {
|
|
31
|
+
return {
|
|
32
|
+
base64Image: this.base64Image,
|
|
33
|
+
height: this.height,
|
|
34
|
+
width: this.width,
|
|
35
|
+
xTopLeft: this.xTopLeft,
|
|
36
|
+
yTopLeft: this.yTopLeft,
|
|
37
|
+
};
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
exports.ImageReference = ImageReference;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export { ImageReference } from './image-reference';
|
|
2
|
+
export { CacheEntryReference } from './cache-entry-reference';
|
|
3
|
+
export { CacheEntry } from './cache-entry';
|
|
4
|
+
export { CacheConfig, ValidationType } from './cache-config';
|
|
5
|
+
export { CacheInterface } from './cache-interface';
|
|
6
|
+
export { DummyCacheManager } from './dummy-cache-manager';
|
|
7
|
+
export { CacheManager } from './cache-manager';
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.CacheManager = exports.DummyCacheManager = exports.CacheEntry = exports.CacheEntryReference = exports.ImageReference = void 0;
|
|
4
|
+
var image_reference_1 = require("./image-reference");
|
|
5
|
+
Object.defineProperty(exports, "ImageReference", { enumerable: true, get: function () { return image_reference_1.ImageReference; } });
|
|
6
|
+
var cache_entry_reference_1 = require("./cache-entry-reference");
|
|
7
|
+
Object.defineProperty(exports, "CacheEntryReference", { enumerable: true, get: function () { return cache_entry_reference_1.CacheEntryReference; } });
|
|
8
|
+
var cache_entry_1 = require("./cache-entry");
|
|
9
|
+
Object.defineProperty(exports, "CacheEntry", { enumerable: true, get: function () { return cache_entry_1.CacheEntry; } });
|
|
10
|
+
var dummy_cache_manager_1 = require("./dummy-cache-manager");
|
|
11
|
+
Object.defineProperty(exports, "DummyCacheManager", { enumerable: true, get: function () { return dummy_cache_manager_1.DummyCacheManager; } });
|
|
12
|
+
var cache_manager_1 = require("./cache-manager");
|
|
13
|
+
Object.defineProperty(exports, "CacheManager", { enumerable: true, get: function () { return cache_manager_1.CacheManager; } });
|
|
@@ -20,7 +20,7 @@ class BoundingBox {
|
|
|
20
20
|
this.ymax = ymax;
|
|
21
21
|
}
|
|
22
22
|
static fromJson(boundinBox, resizeRatio = 1) {
|
|
23
|
-
return new BoundingBox(boundinBox.xmin * resizeRatio, boundinBox.ymin * resizeRatio, boundinBox.xmax * resizeRatio, boundinBox.ymax * resizeRatio);
|
|
23
|
+
return new BoundingBox(Math.round(boundinBox.xmin * resizeRatio), Math.round(boundinBox.ymin * resizeRatio), Math.round(boundinBox.xmax * resizeRatio), Math.round(boundinBox.ymax * resizeRatio));
|
|
24
24
|
}
|
|
25
25
|
/**
|
|
26
26
|
*
|
|
@@ -46,6 +46,9 @@ class CustomElement {
|
|
|
46
46
|
throw new yup_1.ValidationError(e.errors.join(', '));
|
|
47
47
|
}
|
|
48
48
|
}
|
|
49
|
+
asString() {
|
|
50
|
+
return `name:${this.name}-customImage:${this.customImage}-threshold:${this.threshold}-stopThreshold:${this.stopThreshold}-rotationDegreePerStep:${this.rotationDegreePerStep}-imageCompareFormat:${this.imageCompareFormat}-mask:${this.mask}`;
|
|
51
|
+
}
|
|
49
52
|
}
|
|
50
53
|
exports.CustomElement = CustomElement;
|
|
51
54
|
CustomElement.schema = (0, yup_1.object)({
|
|
@@ -11,9 +11,17 @@ class Action {
|
|
|
11
11
|
}
|
|
12
12
|
static fromJson(action, resizeRatio = 1) {
|
|
13
13
|
return new Action(input_event_1.InputEvent[action.inputEvent], {
|
|
14
|
-
x: action.position.x * resizeRatio,
|
|
15
|
-
y: action.position.y * resizeRatio,
|
|
14
|
+
x: Math.round(action.position.x * resizeRatio),
|
|
15
|
+
y: Math.round(action.position.y * resizeRatio),
|
|
16
16
|
}, action.text, action.parameters ? action.parameters : {});
|
|
17
17
|
}
|
|
18
|
+
toJson() {
|
|
19
|
+
return {
|
|
20
|
+
inputEvent: this.inputEvent,
|
|
21
|
+
parameters: this.parameters,
|
|
22
|
+
position: this.position,
|
|
23
|
+
text: this.text,
|
|
24
|
+
};
|
|
25
|
+
}
|
|
18
26
|
}
|
|
19
27
|
exports.Action = Action;
|
|
@@ -18,5 +18,12 @@ class ControlCommand {
|
|
|
18
18
|
this.actions = this.actions.map((action) => ([input_event_1.InputEvent.TYPE, input_event_1.InputEvent.TYPE_TEXT].includes(action.inputEvent)
|
|
19
19
|
? new action_1.Action(action.inputEvent, action.position, text, action.parameters) : action));
|
|
20
20
|
}
|
|
21
|
+
toJson() {
|
|
22
|
+
return {
|
|
23
|
+
actions: this.actions.map((action) => action.toJson()),
|
|
24
|
+
code: this.code,
|
|
25
|
+
tryToRepeat: this.tryToRepeat,
|
|
26
|
+
};
|
|
27
|
+
}
|
|
21
28
|
}
|
|
22
29
|
exports.ControlCommand = ControlCommand;
|