askui 0.7.0 → 0.7.2

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.
Files changed (62) hide show
  1. package/dist/cjs/core/annotation/annotation-json.d.ts +5 -0
  2. package/dist/cjs/core/annotation/annotation-json.js +2 -0
  3. package/dist/cjs/core/inference-response/inference-response.d.ts +7 -11
  4. package/dist/cjs/core/inference-response/inference-response.js +8 -13
  5. package/dist/cjs/core/inference-response/invalid-model-type-error.d.ts +4 -0
  6. package/dist/cjs/core/inference-response/invalid-model-type-error.js +9 -0
  7. package/dist/cjs/core/inference-response/model-type.d.ts +1 -0
  8. package/dist/cjs/core/inference-response/model-type.js +2 -0
  9. package/dist/cjs/core/model/test-case-dto/custom-element.spec.d.ts +1 -0
  10. package/dist/cjs/core/model/test-case-dto/custom-element.spec.js +53 -0
  11. package/dist/cjs/execution/dsl.d.ts +48 -0
  12. package/dist/cjs/execution/dsl.js +72 -0
  13. package/dist/cjs/execution/dsl.spec.d.ts +1 -0
  14. package/dist/cjs/execution/dsl.spec.js +75 -0
  15. package/dist/cjs/execution/inference-client.d.ts +1 -0
  16. package/dist/cjs/execution/inference-client.js +17 -8
  17. package/dist/cjs/execution/read-environment-credentials.spec.d.ts +1 -0
  18. package/dist/cjs/execution/read-environment-credentials.spec.js +11 -0
  19. package/dist/cjs/lib/download-binaries.d.ts +1 -1
  20. package/dist/cjs/lib/download-binaries.js +42 -29
  21. package/dist/cjs/lib/ui-controller-args.spec.d.ts +1 -0
  22. package/dist/cjs/lib/ui-controller-args.spec.js +23 -0
  23. package/dist/cjs/lib/ui-controller-darwin.js +3 -3
  24. package/dist/cjs/lib/ui-controller-facade.d.ts +1 -2
  25. package/dist/cjs/lib/ui-controller-facade.js +6 -11
  26. package/dist/cjs/lib/ui-controller-linux.js +1 -1
  27. package/dist/cjs/utils/http/credentials.spec.d.ts +1 -0
  28. package/dist/cjs/utils/http/credentials.spec.js +11 -0
  29. package/dist/cjs/utils/http/http-client-got.d.ts +5 -1
  30. package/dist/cjs/utils/http/http-client-got.js +12 -4
  31. package/dist/esm/core/annotation/annotation-json.d.ts +5 -0
  32. package/dist/esm/core/annotation/annotation-json.js +1 -0
  33. package/dist/esm/core/inference-response/inference-response.d.ts +7 -11
  34. package/dist/esm/core/inference-response/inference-response.js +8 -13
  35. package/dist/esm/core/inference-response/invalid-model-type-error.d.ts +4 -0
  36. package/dist/esm/core/inference-response/invalid-model-type-error.js +5 -0
  37. package/dist/esm/core/inference-response/model-type.d.ts +1 -0
  38. package/dist/esm/core/inference-response/model-type.js +1 -0
  39. package/dist/esm/core/model/test-case-dto/custom-element.spec.d.ts +1 -0
  40. package/dist/esm/core/model/test-case-dto/custom-element.spec.js +51 -0
  41. package/dist/esm/execution/dsl.d.ts +48 -0
  42. package/dist/esm/execution/dsl.js +72 -0
  43. package/dist/esm/execution/dsl.spec.d.ts +1 -0
  44. package/dist/esm/execution/dsl.spec.js +73 -0
  45. package/dist/esm/execution/inference-client.d.ts +1 -0
  46. package/dist/esm/execution/inference-client.js +17 -8
  47. package/dist/esm/execution/read-environment-credentials.spec.d.ts +1 -0
  48. package/dist/esm/execution/read-environment-credentials.spec.js +9 -0
  49. package/dist/esm/lib/download-binaries.d.ts +1 -1
  50. package/dist/esm/lib/download-binaries.js +40 -27
  51. package/dist/esm/lib/ui-controller-args.spec.d.ts +1 -0
  52. package/dist/esm/lib/ui-controller-args.spec.js +21 -0
  53. package/dist/esm/lib/ui-controller-darwin.js +3 -3
  54. package/dist/esm/lib/ui-controller-facade.d.ts +1 -2
  55. package/dist/esm/lib/ui-controller-facade.js +7 -12
  56. package/dist/esm/lib/ui-controller-linux.js +1 -1
  57. package/dist/esm/utils/http/credentials.spec.d.ts +1 -0
  58. package/dist/esm/utils/http/credentials.spec.js +9 -0
  59. package/dist/esm/utils/http/http-client-got.d.ts +5 -1
  60. package/dist/esm/utils/http/http-client-got.js +12 -4
  61. package/dist/example_projects_templates/typescript_jest/test/my-first-askui-test-suite.test.ts +5 -6
  62. package/package.json +1 -1
@@ -0,0 +1,5 @@
1
+ import { DetectedElement } from '../model/annotation-result/detected-element';
2
+ export interface AnnotationJson {
3
+ image: string;
4
+ objects: DetectedElement[];
5
+ }
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -1,15 +1,11 @@
1
1
  import { ControlCommand } from '../ui-control-commands/control-command';
2
2
  import { Annotation } from '../annotation/annotation';
3
- export declare class InferenceResponse {
4
- type: string;
5
- data: ControlCommand | Annotation;
6
- constructor(type: string, data: ControlCommand | Annotation);
7
- static fromJson(json: unknown, resizeRatio?: number, image?: string): ControlCommand | Annotation;
8
- static createModels(type: string, data: ControlCommand | Annotation, resizeRatio: number, image?: string): ControlCommand | Annotation;
9
- static models: Models;
3
+ import { ModelType } from './model-type';
4
+ export interface InferenceResponseBody {
5
+ type: ModelType;
6
+ data: ModelType extends 'COMMANDS' ? ControlCommand : Annotation;
10
7
  }
11
- interface Models {
12
- DETECTED_ELEMENTS: CallableFunction;
13
- COMMANDS: CallableFunction;
8
+ export declare class InferenceResponse {
9
+ static fromJson(json: InferenceResponseBody, resizeRatio?: number, image?: string): ControlCommand | Annotation;
10
+ static createModels(type: ModelType, data: ModelType extends 'COMMANDS' ? ControlCommand : Annotation, resizeRatio: number, image?: string): ControlCommand | Annotation;
14
11
  }
15
- export {};
@@ -3,23 +3,18 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.InferenceResponse = void 0;
4
4
  const control_command_1 = require("../ui-control-commands/control-command");
5
5
  const annotation_1 = require("../annotation/annotation");
6
+ const invalid_model_type_error_1 = require("./invalid-model-type-error");
6
7
  class InferenceResponse {
7
- constructor(type, data) {
8
- this.type = type;
9
- this.data = data;
10
- }
11
8
  static fromJson(json, resizeRatio = 1, image) {
12
- const inferenceResponse = json;
13
- return this.createModels(inferenceResponse.type, inferenceResponse.data, resizeRatio, image);
9
+ return this.createModels(json.type, json.data, resizeRatio, image);
14
10
  }
15
11
  static createModels(type, data, resizeRatio, image) {
16
- return this.models[type](data, resizeRatio, image);
12
+ if (type === 'COMMANDS')
13
+ return control_command_1.ControlCommand.fromJson(data, resizeRatio);
14
+ if (type === 'DETECTED_ELEMENTS') {
15
+ return annotation_1.Annotation.fromJson({ image, detected_elements: data.detected_elements }, resizeRatio);
16
+ }
17
+ throw new invalid_model_type_error_1.InvalidModelTypeError(type);
17
18
  }
18
19
  }
19
20
  exports.InferenceResponse = InferenceResponse;
20
- InferenceResponse.models = {
21
- DETECTED_ELEMENTS: (data, resizeRatio, image) => annotation_1.Annotation
22
- .fromJson({ image, detected_elements: data.detected_elements }, resizeRatio),
23
- COMMANDS: (data, resizeRatio) => control_command_1.ControlCommand
24
- .fromJson(data, resizeRatio),
25
- };
@@ -0,0 +1,4 @@
1
+ import { ModelType } from './model-type';
2
+ export declare class InvalidModelTypeError extends Error {
3
+ constructor(type: ModelType);
4
+ }
@@ -0,0 +1,9 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.InvalidModelTypeError = void 0;
4
+ class InvalidModelTypeError extends Error {
5
+ constructor(type) {
6
+ super(`Invalid model type: ${type}`);
7
+ }
8
+ }
9
+ exports.InvalidModelTypeError = InvalidModelTypeError;
@@ -0,0 +1 @@
1
+ export declare type ModelType = 'DETECTED_ELEMENTS' | 'COMMANDS';
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,53 @@
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
+ const custom_element_1 = require("./custom-element");
13
+ const base64ImageString = 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAEAAAAA8CAYAAADWibxkAAAACXBIWXMAABYlAAAWJQFJUiTwAAAN20lEQVRogXVa3XrbSg7T7XHsfZyNneSJtm2cOH1/7UeCIMCRz4Xa2NYPhwRBkKPtdv7e306P/e3le7+dP+v43t9eHvt7HOfH/nb53q/12/vLdx5vL/f97RT/x/G53y73/e1S19Q5ccS9buc7zrt87+/nL1x/wvW3Sxz3/f3lnr/p/Pgu7HrUb/c8j/fC/XHdR9rJa2F7rieeV3/zmrhv3OP9BWvZciF1QvxwO9339xNPlvF+cX4+h2E/fe3bJf7GZxj2MMfiPrn4s84LJ9wu4bwwBosOJ6dN6Rhcm8+OxedBp69BgG08ImBxwB4G5qccEvbhui2ih+jy4jKAjokHnL73jzO9HOf/qRv/mEfj7wfuEWioB8O4QNGjIljO+k8hxc4nCuHQOF/RC4eEEyayLHCJQDoLqILzfvaP89884AA4vh1wLU9h8X9ycXQGoISFEdpKE0LUUBKQPoX36RQaGAbFgiKVaCzgncYy5c50UhyKWEY9I+8OKBsqRRk0OBUO78iffwp5SNc4cJ9HOEAGZ3RPf0YeEZaZ/5EambcF3YhWQ7VQE7A+uQPKmbHgiHwiipwh1DDKXFin3eW+Xy8RJMv9QiKDQFjLQfMz0MM0/oOUK3u3fFgQUhrCiMXfIsbXl9/pGPEFcwzOohG4jukjx3Ua8EikhBP4LEsBg+fMa6WCf5cQN9LryGcgxCfOY7Lvvm+3jAhvsOYibpDGVlT9YjA4HfAjBr945YCh7dyGvKVHoUWcYc+oRQZaWDGUolU9ysFMNRD0dKAqhx8POIBGzCMgj1xRBMETOIqR0wGAcqYSr3GvR/5npOHYhPMpokQO4EKRo5OHCHM5INO2iVYl0T+vaRVph8/xfdj42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vQ8FB+tmhLE2dtRm4lvTlbmK2xRJQ3Xfp+ONunSGPPgfeXWBtONjm8pspaGTZGH16ndrcF2JTItb/k86oFFA2gqQYrweyJEt9zoCq0UvgUcVPx+XzCU9JVo1rsZ0MRkfeGkzjY4M6w5n5MkV5kaXwuzrfKD5I6FyWn0hlzEdh9amQ96R6nA3wQsozpvLny8jck8HTSpsXUgkrgNOk4MbZj8BtTZZDQmBI7lH1/cZ0/fu7/Pf3aX/9RykjXe/laecml72y/Z/5XeT9V+TUnbMxlqDtWgjgRbAmx4xGG6PDNEfURjIhHfpHEPamZkUA6zBzlOHz+zjLNhbh0Zkl27pj7hdraxznbUGIDxrEQ9gDrBod3bEepTLU1RYpYXjM7J1lqiDlWG+e1TZwHfM8ehVrCbNOz+Q7RIQU+rXxZu2u9/SwxrAaAnIaiaz4ufcDoID/36z/6ngq0ecPIVAGaQxF33NxWW6T82gD16/64bnvW3a2sj0X+6irhg9SuHN5EWat8lK84Mt9NPrv66+bniV2H/ckDaZqSbVu0FpIie57NGRs8MAcSLFVeruQAzQ7YJQ4uaX6Z7xtN5TZl8GEy1LZIq/jmzUDL4ZUaG4baMNcD/H8hlYADpzRH1QAAAABJRU5ErkJggg==';
14
+ describe('CustomElement', () => {
15
+ describe('fromJsonWithImagePathOrImage', () => {
16
+ test('should return CustomElement if CustomElement created from JSON is valid', () => __awaiter(void 0, void 0, void 0, function* () {
17
+ const expected = new custom_element_1.CustomElement(base64ImageString, 'Dummy_element', 0.7, 10, 'RGB', [{ x: 0, y: 1 }, { x: 1, y: 2 }, { x: 3, y: 4 }]);
18
+ const actual = yield custom_element_1.CustomElement.fromJsonWithImagePathOrImage({
19
+ customImage: base64ImageString,
20
+ name: 'Dummy_element',
21
+ threshold: 0.7,
22
+ rotationDegreePerStep: 10,
23
+ imageCompareFormat: 'RGB',
24
+ mask: [{ x: 0, y: 1 }, { x: 1, y: 2 }, { x: 3, y: 4 }],
25
+ });
26
+ expect(actual).toStrictEqual(expected);
27
+ }));
28
+ test('should throw ValidationError if threshold is invalid', () => {
29
+ expect(() => {
30
+ const customElement = new custom_element_1.CustomElement(base64ImageString, 'Dummy_element', 1.1, 10, 'RGB', [{ x: 0, y: 1 }, { x: 1, y: 2 }, { x: 3, y: 4 }]);
31
+ customElement.validate();
32
+ }).toThrow('threshold must be less than or equal to 1');
33
+ });
34
+ test('should throw ValidationError if rotationDegreePerStep is invalid', () => {
35
+ expect(() => {
36
+ const customElement = new custom_element_1.CustomElement(base64ImageString, 'Dummy_element', 0.9, -90, 'RGB', [{ x: 0, y: 1 }, { x: 1, y: 2 }, { x: 3, y: 4 }]);
37
+ customElement.validate();
38
+ }).toThrow('rotationDegreePerStep must be greater than or equal to 0');
39
+ });
40
+ test('should throw ValidationError if mask is invalid', () => {
41
+ expect(() => {
42
+ const customElement = new custom_element_1.CustomElement(base64ImageString, 'Dummy_element', 0.9, 10, 'RGB', [{ x: 0, y: 1 }, { x: 1, y: 2 }]);
43
+ customElement.validate();
44
+ }).toThrow('mask must contain at least 3 points');
45
+ });
46
+ test('should throw ValidationError if mask and threshold are both invalid', () => {
47
+ expect(() => {
48
+ const customElement = new custom_element_1.CustomElement(base64ImageString, 'Dummy_element', 90, 10, 'RGB', [{ x: 0, y: 1 }, { x: 1, y: 2 }]);
49
+ customElement.validate();
50
+ }).toThrow('threshold must be less than or equal to 1, mask must contain at least 3 points');
51
+ });
52
+ });
53
+ });
@@ -1779,6 +1779,54 @@ export declare abstract class FluentCommand extends FluentBase {
1779
1779
  * @return {Exec}
1780
1780
  */
1781
1781
  execOnShell(shell_command: string): Exec;
1782
+ /**
1783
+ * Clicks with left mouse key.
1784
+ *
1785
+ * @return {Exec}
1786
+ */
1787
+ mouseLeftClick(): Exec;
1788
+ /**
1789
+ * Clicks with right mouse key.
1790
+ *
1791
+ * @return {Exec}
1792
+ */
1793
+ mouseRightClick(): Exec;
1794
+ /**
1795
+ * Clicks with middle mouse key.
1796
+ *
1797
+ * @return {Exec}
1798
+ */
1799
+ mouseMiddleClick(): Exec;
1800
+ /**
1801
+ * Double-clicks with left mouse key.
1802
+ *
1803
+ * @return {Exec}
1804
+ */
1805
+ mouseDoubleLeftClick(): Exec;
1806
+ /**
1807
+ * Double-clicks with right mouse key.
1808
+ *
1809
+ * @return {Exec}
1810
+ */
1811
+ mouseDoubleRightClick(): Exec;
1812
+ /**
1813
+ * Double-clicks with middle mouse key.
1814
+ *
1815
+ * @return {Exec}
1816
+ */
1817
+ mouseDoubleMiddleClick(): Exec;
1818
+ /**
1819
+ * Toggles mouse down (Left mouse key).
1820
+ *
1821
+ * @return {Exec}
1822
+ */
1823
+ mouseToggleDown(): Exec;
1824
+ /**
1825
+ * Toggles mouse up (Left mouse key).
1826
+ *
1827
+ * @return {Exec}
1828
+ */
1829
+ mouseToggleUp(): Exec;
1782
1830
  /**
1783
1831
  * Press three keys like `CTRL+ALT+DEL`
1784
1832
  *
@@ -2369,6 +2369,78 @@ class FluentCommand extends FluentBase {
2369
2369
  this._textStr = `Execute shell command ${Separators.STRING}${shell_command}${Separators.STRING}`;
2370
2370
  return new Exec(this);
2371
2371
  }
2372
+ /**
2373
+ * Clicks with left mouse key.
2374
+ *
2375
+ * @return {Exec}
2376
+ */
2377
+ mouseLeftClick() {
2378
+ this._textStr = 'Mouse left click';
2379
+ return new Exec(this);
2380
+ }
2381
+ /**
2382
+ * Clicks with right mouse key.
2383
+ *
2384
+ * @return {Exec}
2385
+ */
2386
+ mouseRightClick() {
2387
+ this._textStr = 'Mouse right click';
2388
+ return new Exec(this);
2389
+ }
2390
+ /**
2391
+ * Clicks with middle mouse key.
2392
+ *
2393
+ * @return {Exec}
2394
+ */
2395
+ mouseMiddleClick() {
2396
+ this._textStr = 'Mouse middle click';
2397
+ return new Exec(this);
2398
+ }
2399
+ /**
2400
+ * Double-clicks with left mouse key.
2401
+ *
2402
+ * @return {Exec}
2403
+ */
2404
+ mouseDoubleLeftClick() {
2405
+ this._textStr = 'Mouse double left click';
2406
+ return new Exec(this);
2407
+ }
2408
+ /**
2409
+ * Double-clicks with right mouse key.
2410
+ *
2411
+ * @return {Exec}
2412
+ */
2413
+ mouseDoubleRightClick() {
2414
+ this._textStr = 'Mouse double right click';
2415
+ return new Exec(this);
2416
+ }
2417
+ /**
2418
+ * Double-clicks with middle mouse key.
2419
+ *
2420
+ * @return {Exec}
2421
+ */
2422
+ mouseDoubleMiddleClick() {
2423
+ this._textStr = 'Mouse double middle click';
2424
+ return new Exec(this);
2425
+ }
2426
+ /**
2427
+ * Toggles mouse down (Left mouse key).
2428
+ *
2429
+ * @return {Exec}
2430
+ */
2431
+ mouseToggleDown() {
2432
+ this._textStr = 'Mouse toggle down';
2433
+ return new Exec(this);
2434
+ }
2435
+ /**
2436
+ * Toggles mouse up (Left mouse key).
2437
+ *
2438
+ * @return {Exec}
2439
+ */
2440
+ mouseToggleUp() {
2441
+ this._textStr = 'Mouse toggle up';
2442
+ return new Exec(this);
2443
+ }
2372
2444
  /**
2373
2445
  * Press three keys like `CTRL+ALT+DEL`
2374
2446
  *
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,75 @@
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
+ const dsl_1 = require("./dsl");
13
+ class TestCommand extends dsl_1.FluentCommand {
14
+ // eslint-disable-next-line class-methods-use-this
15
+ fluentCommandExecutor(instruction, customElements) {
16
+ return __awaiter(this, void 0, void 0, function* () {
17
+ // eslint-disable-next-line no-console
18
+ console.log(`${instruction} ${customElements}`);
19
+ return Promise.resolve();
20
+ });
21
+ }
22
+ }
23
+ describe('DSL', () => {
24
+ describe('custom element', () => {
25
+ test('should call exec function with zero custom element', () => __awaiter(void 0, void 0, void 0, function* () {
26
+ const underTest = new TestCommand();
27
+ const testCommandSpy = jest.spyOn(underTest, 'fluentCommandExecutor');
28
+ yield underTest.click().button()
29
+ .exec();
30
+ expect(testCommandSpy).toHaveBeenCalledWith('Click on button', []);
31
+ }));
32
+ test('should call exec function with one custom element', () => __awaiter(void 0, void 0, void 0, function* () {
33
+ const underTest = new TestCommand();
34
+ const testCommandSpy = jest.spyOn(underTest, 'fluentCommandExecutor');
35
+ yield underTest.click().customElement({
36
+ customImage: 'iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVR42mP8z/C/HgAGgwJ/lK3Q6wAAAABJRU5ErkJggg==',
37
+ imageCompareFormat: 'grayscale',
38
+ name: 'custom element 1',
39
+ }).button()
40
+ .exec();
41
+ expect(testCommandSpy).toHaveBeenCalledWith('Click on custom element button', [{
42
+ customImage: 'iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVR42mP8z/C/HgAGgwJ/lK3Q6wAAAABJRU5ErkJggg==',
43
+ imageCompareFormat: 'grayscale',
44
+ name: 'custom element 1',
45
+ }]);
46
+ }));
47
+ test('should call exec function with two custom element', () => __awaiter(void 0, void 0, void 0, function* () {
48
+ const underTest = new TestCommand();
49
+ const testCommandSpy = jest.spyOn(underTest, 'fluentCommandExecutor');
50
+ yield underTest.click().customElement({
51
+ customImage: 'iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVR42mP8z/C/HgAGgwJ/lK3Q6wAAAABJRU5ErkJggg==',
52
+ imageCompareFormat: 'grayscale',
53
+ name: 'custom element 1',
54
+ })
55
+ .button()
56
+ .customElement({
57
+ customImage: 'iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVR42mP8z/C/HgAGgwJ/lK3Q6wAAAABJRU5ErkJggg==',
58
+ imageCompareFormat: 'grayscale',
59
+ name: 'custom element 2',
60
+ })
61
+ .exec();
62
+ expect(testCommandSpy).toHaveBeenCalledWith('Click on custom element button custom element', [{
63
+ customImage: 'iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVR42mP8z/C/HgAGgwJ/lK3Q6wAAAABJRU5ErkJggg==',
64
+ imageCompareFormat: 'grayscale',
65
+ name: 'custom element 1',
66
+ },
67
+ {
68
+ customImage: 'iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVR42mP8z/C/HgAGgwJ/lK3Q6wAAAABJRU5ErkJggg==',
69
+ imageCompareFormat: 'grayscale',
70
+ name: 'custom element 2',
71
+ },
72
+ ]);
73
+ }));
74
+ });
75
+ });
@@ -14,6 +14,7 @@ export declare class InferenceClient {
14
14
  isImageRequired(instruction: string): Promise<boolean>;
15
15
  private resizeIfNeeded;
16
16
  inference(customElements?: CustomElement[], image?: string, instruction?: string): Promise<ControlCommand | Annotation>;
17
+ private static logMetaInformation;
17
18
  predictControlCommand(instruction: string, customElements?: CustomElement[], image?: string): Promise<ControlCommand>;
18
19
  getDetectedElements(instruction: string, image: string, customElements?: CustomElement[]): Promise<DetectedElement[]>;
19
20
  predictImageAnnotation(image: string, customElements?: CustomElement[]): Promise<Annotation>;
@@ -19,6 +19,7 @@ const annotation_1 = require("../core/annotation/annotation");
19
19
  const transformations_1 = require("../utils/transformations");
20
20
  const inference_response_error_1 = require("./inference-response-error");
21
21
  const config_error_1 = require("./config-error");
22
+ const logger_1 = require("../lib/logger");
22
23
  class InferenceClient {
23
24
  constructor(baseUrl, httpClient, resize, workspaceId, apiVersion = 'v3') {
24
25
  this.baseUrl = baseUrl;
@@ -27,7 +28,9 @@ class InferenceClient {
27
28
  this.workspaceId = workspaceId;
28
29
  this.apiVersion = apiVersion;
29
30
  const versionedBaseUrl = (0, url_join_1.default)(this.baseUrl, 'api', this.apiVersion);
30
- this.url = workspaceId ? (0, url_join_1.default)(versionedBaseUrl, 'workspaces', workspaceId) : versionedBaseUrl;
31
+ this.url = workspaceId
32
+ ? (0, url_join_1.default)(versionedBaseUrl, 'workspaces', workspaceId)
33
+ : versionedBaseUrl;
31
34
  if (this.resize !== undefined && this.resize <= 0) {
32
35
  throw new config_error_1.ConfigurationError(`Resize must be a positive number. The current resize value "${this.resize}" is not valid.`);
33
36
  }
@@ -36,17 +39,17 @@ class InferenceClient {
36
39
  isImageRequired(instruction) {
37
40
  return __awaiter(this, void 0, void 0, function* () {
38
41
  const url = (0, url_join_1.default)(this.url, 'instruction', 'is-image-required');
39
- const httpBody = {
42
+ const requestBody = {
40
43
  instruction,
41
44
  };
42
- const httpResponse = yield this.httpClient.post(url, httpBody);
43
- return httpResponse.isImageRequired;
45
+ const response = yield this.httpClient.post(url, requestBody);
46
+ return response.body.isImageRequired;
44
47
  });
45
48
  }
46
49
  // eslint-disable-next-line class-methods-use-this
47
50
  resizeIfNeeded(customElements, image) {
48
51
  return __awaiter(this, void 0, void 0, function* () {
49
- if (!(image) || customElements.length > 0 || this.resize === undefined) {
52
+ if (!image || customElements.length > 0 || this.resize === undefined) {
50
53
  return { base64Image: image, resizeRatio: 1 };
51
54
  }
52
55
  return (0, transformations_1.resizeBase64ImageWithSameRatio)(image, this.resize);
@@ -55,16 +58,22 @@ class InferenceClient {
55
58
  inference(customElements = [], image, instruction) {
56
59
  return __awaiter(this, void 0, void 0, function* () {
57
60
  const resizedImage = yield this.resizeIfNeeded(customElements, image);
58
- const httpBody = {
61
+ const requestBody = {
59
62
  image: resizedImage.base64Image,
60
63
  instruction,
61
64
  customElements,
62
65
  };
63
66
  const url = (0, url_join_1.default)(this.url, 'inference');
64
- const httpResponse = yield this.httpClient.post(url, httpBody);
65
- return ui_control_commands_1.InferenceResponse.fromJson(httpResponse, resizedImage.resizeRatio, image);
67
+ const response = yield this.httpClient.post(url, requestBody);
68
+ InferenceClient.logMetaInformation(response);
69
+ return ui_control_commands_1.InferenceResponse.fromJson(response.body, resizedImage.resizeRatio, image);
66
70
  });
67
71
  }
72
+ static logMetaInformation(response) {
73
+ if (response.headers['askui-usage-warnings'] !== undefined) {
74
+ logger_1.logger.warn(response.headers['askui-usage-warnings']);
75
+ }
76
+ }
68
77
  predictControlCommand(instruction, customElements = [], image) {
69
78
  return __awaiter(this, void 0, void 0, function* () {
70
79
  const inferenceResponse = yield this.inference(customElements, image, instruction);
@@ -0,0 +1,11 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const read_environment_credentials_1 = require("./read-environment-credentials");
4
+ describe('envCredentials()', () => {
5
+ test('should read the credentials from the environment variables', () => {
6
+ process.env['ASKUI_TOKEN'] = 'token';
7
+ process.env['ASKUI_WORKSPACE_ID'] = 'id123';
8
+ const credentialsFromTheEnv = (0, read_environment_credentials_1.envCredentials)();
9
+ expect(credentialsFromTheEnv).toStrictEqual({ workspaceId: 'id123', token: 'token' });
10
+ });
11
+ });
@@ -7,7 +7,7 @@ declare enum SupportedPlatform {
7
7
  WIN32 = "win32"
8
8
  }
9
9
  export declare function platform(): SupportedPlatform;
10
- export declare function getBinaryPath(version: string): string;
10
+ export declare function getBinaryFilePath(version: string): string;
11
11
  export declare function downloadServerBinaries(binaryVersion: string, proxyAgent?: {
12
12
  http: http.Agent;
13
13
  https: https.Agent;
@@ -1,13 +1,24 @@
1
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
+ };
2
11
  var __importDefault = (this && this.__importDefault) || function (mod) {
3
12
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
13
  };
5
14
  Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.downloadServerBinaries = exports.getBinaryPath = exports.platform = void 0;
15
+ exports.downloadServerBinaries = exports.getBinaryFilePath = exports.platform = void 0;
7
16
  const fs_1 = __importDefault(require("fs"));
8
17
  const got_1 = __importDefault(require("got"));
9
18
  const os_1 = __importDefault(require("os"));
10
19
  const path_1 = __importDefault(require("path"));
20
+ const util_1 = require("util");
21
+ const stream_1 = __importDefault(require("stream"));
11
22
  const path_2 = require("../utils/path");
12
23
  const logger_1 = require("./logger");
13
24
  var SupportedPlatform;
@@ -32,45 +43,47 @@ function platform() {
32
43
  throw new Error(`Platform "${pf}" is not supported.`);
33
44
  }
34
45
  exports.platform = platform;
35
- function buildBinaryNotAvailbleError(binaryVersion) {
36
- return new Error(`It seems that the UI Controller version "${binaryVersion}" for your system "${platform()} ${os_1.default.arch}" is not availble, Please contact as at info@askui.com for more information`);
46
+ function buildBinaryNotAvailableError(binaryVersion) {
47
+ return new Error(`There was an error during downloading and creating the askui UI Controller. You can try a fresh install.
48
+ If you specified a binary version it is possible that the askui UI Controller version "${binaryVersion}"
49
+ for your system "${platform()} ${os_1.default.arch}" is not available.
50
+ If this problem still occurs, please contact us at info@askui.com for more information`);
37
51
  }
38
- function getBinaryPath(version) {
52
+ function getBinaryFilePath(version) {
39
53
  return path_1.default.join((0, path_2.getPathToNodeModulesRoot)(), 'release', version, ...binarySubPathsByPlatform[platform()]);
40
54
  }
41
- exports.getBinaryPath = getBinaryPath;
55
+ exports.getBinaryFilePath = getBinaryFilePath;
42
56
  function getBinaryDownloadUrl(binaryVersion) {
43
57
  const baseUrl = `https://askui-public.s3.eu-central-1.amazonaws.com/releases/askui-ui-controller/${binaryVersion}`;
44
58
  const arch = os_1.default.arch();
45
59
  return `${baseUrl}/${platform()}/${arch}/${binarySubPathsByPlatform[platform()][1]}`;
46
60
  }
47
61
  function downloadServerBinaries(binaryVersion, proxyAgent) {
48
- return new Promise((resolve, reject) => {
49
- const url = getBinaryDownloadUrl(binaryVersion);
50
- const binaryOutputPath = getBinaryPath(binaryVersion);
51
- const binaryFolder = path_1.default.dirname(binaryOutputPath);
62
+ return __awaiter(this, void 0, void 0, function* () {
52
63
  logger_1.logger.info(`Start downloading UI Controller version "${binaryVersion}"`);
53
- if (!(fs_1.default.existsSync(binaryFolder))) {
54
- fs_1.default.mkdirSync(binaryFolder, { recursive: true });
55
- }
64
+ const url = getBinaryDownloadUrl(binaryVersion);
65
+ const binaryFilePath = getBinaryFilePath(binaryVersion);
66
+ const binaryFolderPath = path_1.default.dirname(binaryFilePath);
67
+ const tempFilePath = path_1.default.join(binaryFolderPath, 'askui-ui-controller.temp');
68
+ const pipeline = (0, util_1.promisify)(stream_1.default.pipeline);
56
69
  const downloadStream = got_1.default.stream(url, proxyAgent ? { agent: proxyAgent } : {});
57
- const fileWriterStream = fs_1.default.createWriteStream(binaryOutputPath);
58
- downloadStream.on('error', () => {
59
- reject();
60
- fs_1.default.unlink(binaryOutputPath, (err) => { logger_1.logger.error(err); });
61
- throw buildBinaryNotAvailbleError(binaryVersion);
62
- });
63
- fileWriterStream
64
- .on('error', () => {
65
- fs_1.default.unlink(binaryOutputPath, () => { });
66
- reject(new Error('oops, an error during the downloaded occurred, try again with fresh install'));
67
- })
68
- .on('finish', () => {
69
- logger_1.logger.info(`UI Controller version ${binaryVersion} for your system "${platform()} ${os_1.default.arch}" was downloaded`);
70
- logger_1.logger.debug(`Binary of UI Controller is located at "${binaryOutputPath}".`);
71
- resolve();
72
- });
73
- downloadStream.pipe(fileWriterStream);
70
+ const fileWriterStream = fs_1.default.createWriteStream(tempFilePath);
71
+ if (!(fs_1.default.existsSync(binaryFolderPath))) {
72
+ fs_1.default.mkdirSync(binaryFolderPath, { recursive: true });
73
+ }
74
+ try {
75
+ yield pipeline(downloadStream, fileWriterStream);
76
+ fs_1.default.rename(tempFilePath, binaryFilePath, () => {
77
+ logger_1.logger.info(`UI Controller version ${binaryVersion} for your system "${platform()} ${os_1.default.arch}" was downloaded`);
78
+ logger_1.logger.debug(`Binary of UI Controller is located at "${binaryFilePath}".`);
79
+ });
80
+ }
81
+ catch (error) {
82
+ logger_1.logger.error(error);
83
+ fs_1.default.unlink(tempFilePath, (err) => { logger_1.logger.error(err); });
84
+ throw buildBinaryNotAvailableError(binaryVersion);
85
+ }
86
+ return Promise.resolve();
74
87
  });
75
88
  }
76
89
  exports.downloadServerBinaries = downloadServerBinaries;
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,23 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const ui_controller_args_1 = require("./ui-controller-args");
4
+ describe('createCliFlagsFromArgs()', () => {
5
+ test('test createCliFlagsFromArgs should return -d 0 as default output', () => {
6
+ const expected = ['-d 0', '-p 6769', '--action_wait_time 1000', '--host 127.0.0.1', '-m ', '--log-level debug'];
7
+ const argsWithDefaults = (0, ui_controller_args_1.createArgsWithDefaults)();
8
+ const actual = (0, ui_controller_args_1.createCliFlagsFromArgs)(argsWithDefaults);
9
+ expect(actual).toStrictEqual(expected);
10
+ });
11
+ test('test createCliFlagsFromArgs output should include -d 0 when no display was selected', () => {
12
+ const expected = ['-d 0', '-p 6777', '--action_wait_time 1000', '--host 0.0.0.0', '-m ', '--log-level debug'];
13
+ const argsWithDefaults = (0, ui_controller_args_1.createArgsWithDefaults)({ port: 6777, host: '0.0.0.0' });
14
+ const actual = (0, ui_controller_args_1.createCliFlagsFromArgs)(argsWithDefaults);
15
+ expect(actual).toStrictEqual(expected);
16
+ });
17
+ test('test createCliFlagsFromArgs output should include the display that was selected ', () => {
18
+ const expected = ['-d 99', '-p 6777', '--action_wait_time 1000', '--host 0.0.0.0', '-m ', '--log-level debug'];
19
+ const argsWithDefaults = (0, ui_controller_args_1.createArgsWithDefaults)({ port: 6777, host: '0.0.0.0', display: 99 });
20
+ const actual = (0, ui_controller_args_1.createCliFlagsFromArgs)(argsWithDefaults);
21
+ expect(actual).toStrictEqual(expected);
22
+ });
23
+ });
@@ -14,7 +14,7 @@ class UiControllerDarwin extends ui_controller_facade_1.UiControllerFacade {
14
14
  this.makeDiskImageExecutable();
15
15
  }
16
16
  getStartingCommand() {
17
- return `"${path_1.default.dirname(this.binaryPath)}/askui-ui-controller.app/Contents/MacOS/askui-ui-controller"`;
17
+ return `"${path_1.default.dirname(this.binaryFilePath)}/askui-ui-controller.app/Contents/MacOS/askui-ui-controller"`;
18
18
  }
19
19
  makeDiskImageExecutable() {
20
20
  const mountPoint = '/Volumes/askui-ui-controller.dmg';
@@ -25,11 +25,11 @@ class UiControllerDarwin extends ui_controller_facade_1.UiControllerFacade {
25
25
  '-noautofsck',
26
26
  '-noautoopen',
27
27
  `-mountpoint "${mountPoint}"`,
28
- `"${this.binaryPath}"`,
28
+ `"${this.binaryFilePath}"`,
29
29
  ].join(' '));
30
30
  const appBaseName = 'askui-ui-controller.app';
31
31
  const appSrcPath = `${mountPoint}/${appBaseName}`;
32
- const appDestPath = `${path_1.default.dirname(this.binaryPath)}/${appBaseName}`;
32
+ const appDestPath = `${path_1.default.dirname(this.binaryFilePath)}/${appBaseName}`;
33
33
  fs_extra_1.default.removeSync(appDestPath);
34
34
  fs_extra_1.default.copySync(appSrcPath, appDestPath);
35
35
  (0, child_process_1.exec)(`hdiutil detach "${mountPoint}"`, (_exception, stdout) => logger_1.logger.debug(stdout));