askui 0.4.0 → 0.6.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.
Files changed (41) hide show
  1. package/dist/cjs/execution/config-error.d.ts +2 -0
  2. package/dist/cjs/execution/config-error.js +6 -0
  3. package/dist/cjs/execution/dsl.d.ts +387 -2
  4. package/dist/cjs/execution/dsl.js +405 -2
  5. package/dist/cjs/execution/inference-client.d.ts +2 -1
  6. package/dist/cjs/execution/inference-client.js +9 -3
  7. package/dist/cjs/execution/ui-control-client.js +4 -2
  8. package/dist/cjs/execution/ui-controller-client-interface.d.ts +13 -0
  9. package/dist/cjs/lib/copy-example-project.js +40 -4
  10. package/dist/cjs/lib/download-binaries.d.ts +7 -1
  11. package/dist/cjs/lib/download-binaries.js +2 -2
  12. package/dist/cjs/lib/ui-controller-args.d.ts +4 -0
  13. package/dist/cjs/lib/ui-controller-facade.js +4 -3
  14. package/dist/cjs/shared/proxy-agent-args.d.ts +35 -0
  15. package/dist/cjs/shared/proxy-agent-args.js +2 -0
  16. package/dist/cjs/utils/http/http-client-got.d.ts +11 -1
  17. package/dist/cjs/utils/http/http-client-got.js +5 -3
  18. package/dist/cjs/utils/proxy/proxy-builder.d.ts +4 -0
  19. package/dist/cjs/utils/proxy/proxy-builder.js +67 -0
  20. package/dist/esm/execution/config-error.d.ts +2 -0
  21. package/dist/esm/execution/config-error.js +2 -0
  22. package/dist/esm/execution/dsl.d.ts +387 -2
  23. package/dist/esm/execution/dsl.js +405 -2
  24. package/dist/esm/execution/inference-client.d.ts +2 -1
  25. package/dist/esm/execution/inference-client.js +9 -3
  26. package/dist/esm/execution/ui-control-client.js +4 -2
  27. package/dist/esm/execution/ui-controller-client-interface.d.ts +13 -0
  28. package/dist/esm/lib/copy-example-project.js +40 -4
  29. package/dist/esm/lib/download-binaries.d.ts +7 -1
  30. package/dist/esm/lib/download-binaries.js +2 -2
  31. package/dist/esm/lib/ui-controller-args.d.ts +4 -0
  32. package/dist/esm/lib/ui-controller-facade.js +4 -3
  33. package/dist/esm/shared/proxy-agent-args.d.ts +35 -0
  34. package/dist/esm/shared/proxy-agent-args.js +1 -0
  35. package/dist/esm/utils/http/http-client-got.d.ts +11 -1
  36. package/dist/esm/utils/http/http-client-got.js +5 -3
  37. package/dist/esm/utils/proxy/proxy-builder.d.ts +4 -0
  38. package/dist/esm/utils/proxy/proxy-builder.js +43 -0
  39. package/dist/example_projects_templates/typescript_jest/test/helper/jest.setup.ts +8 -3
  40. package/dist/example_projects_templates/typescript_jest/test/my-first-askui-test-suite.test.ts +5 -0
  41. package/package.json +5 -2
@@ -799,6 +799,120 @@ class FluentFilters extends FluentBase {
799
799
  exports.FluentFilters = FluentFilters;
800
800
  // Relations
801
801
  class FluentFiltersOrRelations extends FluentFilters {
802
+ /**
803
+ * Logic or operator
804
+ *
805
+ * **Examples:**
806
+ * ```text
807
+ * scene 1
808
+ * -------------- ---------------
809
+ * | button | | icon |
810
+ * -------------- ---------------
811
+ *
812
+ * scene 2
813
+ * -------------- ---------------
814
+ * | button | | text |
815
+ * -------------- ---------------
816
+ *
817
+ * ```
818
+ * In case, that your reference element can have multiple values, in the following example, the element right of the button can be either icon or text.
819
+ * You can use **the `or()` relation**, so your teststep is valid for both scenes
820
+ * ```typescript
821
+ * const button = await aui.get().button().rightOf().icon().or().text().exec();
822
+ * console.log(button);
823
+ * ```
824
+ * Returns the same button for both cases
825
+ * ```text
826
+ * console output: [
827
+ * DetectedElement {
828
+ * name: 'BUTTON',
829
+ * text: 'button',
830
+ * colors: [ 'red', 'black', 'red' ],
831
+ * bndbox: BoundingBox {
832
+ * xmin: 900,
833
+ * ymin: 910,
834
+ * xmax: 920,
835
+ * ymax: 930
836
+ * }
837
+ * }
838
+ * ]
839
+ * ```
840
+ *
841
+ * @return {FluentFilters}
842
+ */
843
+ or() {
844
+ this._textStr = 'or';
845
+ return new FluentFilters(this);
846
+ }
847
+ /**
848
+ * Logic and operator
849
+ *
850
+ * **Examples:**
851
+ * ```text
852
+ * example scene:
853
+ * -------------------------- --------------------------
854
+ * | icon user colored black | | icon user colored red |
855
+ * -------------------------- --------------------------
856
+ * ```
857
+ * ```typescript
858
+ * const icons = await aui.get().icon().withText('user').exec();
859
+ * console.log(icons);
860
+ * ```
861
+ * Using only the filter withText, the get command will return both icons because they share the same text
862
+ * ```text
863
+ * console output: [
864
+ * DetectedElement {
865
+ * name: 'ICON',
866
+ * text: 'user',
867
+ * colors: [ 'black', 'black', 'black' ],
868
+ * bndbox: BoundingBox {
869
+ * xmin: 1000,
870
+ * ymin: 1010,
871
+ * xmax: 1020,
872
+ * ymax: 1030
873
+ * }
874
+ * },
875
+ * DetectedElement {
876
+ * name: 'ICON',
877
+ * text: 'user',
878
+ * colors: [ 'red', 'red', 'red' ],
879
+ * bndbox: BoundingBox {
880
+ * xmin: 900,
881
+ * ymin: 910,
882
+ * xmax: 920,
883
+ * ymax: 930
884
+ * }
885
+ * }
886
+ * ]
887
+ * ```
888
+ * You can combine filters with **the `and()` relation** and specify exactly which icon you want
889
+ * ```typescript
890
+ * const icons = await aui.get().icon().withText('user').and().colored('red').exec()
891
+ * console.log(icons)
892
+ * ```
893
+ * The get command returns only the red icon although both icons have the same text
894
+ * ```text
895
+ * console output: [
896
+ * DetectedElement {
897
+ * name: 'ICON',
898
+ * text: 'user',
899
+ * colors: [ 'red', 'red', 'red' ],
900
+ * bndbox: BoundingBox {
901
+ * xmin: 900,
902
+ * ymin: 910,
903
+ * xmax: 920,
904
+ * ymax: 930
905
+ * }
906
+ * }
907
+ * ]
908
+ * ```
909
+ *
910
+ * @return {FluentFilters}
911
+ */
912
+ and() {
913
+ this._textStr = 'and';
914
+ return new FluentFilters(this);
915
+ }
802
916
  /**
803
917
  * Filters for an element inside another element.
804
918
  *
@@ -1711,6 +1825,120 @@ class FluentFiltersCondition extends FluentBase {
1711
1825
  exports.FluentFiltersCondition = FluentFiltersCondition;
1712
1826
  // Relations
1713
1827
  class FluentFiltersOrRelationsCondition extends FluentFiltersCondition {
1828
+ /**
1829
+ * Logic or operator
1830
+ *
1831
+ * **Examples:**
1832
+ * ```text
1833
+ * scene 1
1834
+ * -------------- ---------------
1835
+ * | button | | icon |
1836
+ * -------------- ---------------
1837
+ *
1838
+ * scene 2
1839
+ * -------------- ---------------
1840
+ * | button | | text |
1841
+ * -------------- ---------------
1842
+ *
1843
+ * ```
1844
+ * In case, that your reference element can have multiple values, in the following example, the element right of the button can be either icon or text.
1845
+ * You can use **the `or()` relation**, so your teststep is valid for both scenes
1846
+ * ```typescript
1847
+ * const button = await aui.get().button().rightOf().icon().or().text().exec();
1848
+ * console.log(button);
1849
+ * ```
1850
+ * Returns the same button for both cases
1851
+ * ```text
1852
+ * console output: [
1853
+ * DetectedElement {
1854
+ * name: 'BUTTON',
1855
+ * text: 'button',
1856
+ * colors: [ 'red', 'black', 'red' ],
1857
+ * bndbox: BoundingBox {
1858
+ * xmin: 900,
1859
+ * ymin: 910,
1860
+ * xmax: 920,
1861
+ * ymax: 930
1862
+ * }
1863
+ * }
1864
+ * ]
1865
+ * ```
1866
+ *
1867
+ * @return {FluentFiltersCondition}
1868
+ */
1869
+ or() {
1870
+ this._textStr = 'or';
1871
+ return new FluentFiltersCondition(this);
1872
+ }
1873
+ /**
1874
+ * Logic and operator
1875
+ *
1876
+ * **Examples:**
1877
+ * ```text
1878
+ * example scene:
1879
+ * -------------------------- --------------------------
1880
+ * | icon user colored black | | icon user colored red |
1881
+ * -------------------------- --------------------------
1882
+ * ```
1883
+ * ```typescript
1884
+ * const icons = await aui.get().icon().withText('user').exec();
1885
+ * console.log(icons);
1886
+ * ```
1887
+ * Using only the filter withText, the get command will return both icons because they share the same text
1888
+ * ```text
1889
+ * console output: [
1890
+ * DetectedElement {
1891
+ * name: 'ICON',
1892
+ * text: 'user',
1893
+ * colors: [ 'black', 'black', 'black' ],
1894
+ * bndbox: BoundingBox {
1895
+ * xmin: 1000,
1896
+ * ymin: 1010,
1897
+ * xmax: 1020,
1898
+ * ymax: 1030
1899
+ * }
1900
+ * },
1901
+ * DetectedElement {
1902
+ * name: 'ICON',
1903
+ * text: 'user',
1904
+ * colors: [ 'red', 'red', 'red' ],
1905
+ * bndbox: BoundingBox {
1906
+ * xmin: 900,
1907
+ * ymin: 910,
1908
+ * xmax: 920,
1909
+ * ymax: 930
1910
+ * }
1911
+ * }
1912
+ * ]
1913
+ * ```
1914
+ * You can combine filters with **the `and()` relation** and specify exactly which icon you want
1915
+ * ```typescript
1916
+ * const icons = await aui.get().icon().withText('user').and().colored('red').exec()
1917
+ * console.log(icons)
1918
+ * ```
1919
+ * The get command returns only the red icon although both icons have the same text
1920
+ * ```text
1921
+ * console output: [
1922
+ * DetectedElement {
1923
+ * name: 'ICON',
1924
+ * text: 'user',
1925
+ * colors: [ 'red', 'red', 'red' ],
1926
+ * bndbox: BoundingBox {
1927
+ * xmin: 900,
1928
+ * ymin: 910,
1929
+ * xmax: 920,
1930
+ * ymax: 930
1931
+ * }
1932
+ * }
1933
+ * ]
1934
+ * ```
1935
+ *
1936
+ * @return {FluentFiltersCondition}
1937
+ */
1938
+ and() {
1939
+ this._textStr = 'and';
1940
+ return new FluentFiltersCondition(this);
1941
+ }
1714
1942
  /**
1715
1943
  * Filters for an element inside another element.
1716
1944
  *
@@ -2933,6 +3161,120 @@ class FluentFiltersGetter extends FluentBase {
2933
3161
  exports.FluentFiltersGetter = FluentFiltersGetter;
2934
3162
  // Relations
2935
3163
  class FluentFiltersOrRelationsGetter extends FluentFiltersGetter {
3164
+ /**
3165
+ * Logic or operator
3166
+ *
3167
+ * **Examples:**
3168
+ * ```text
3169
+ * scene 1
3170
+ * -------------- ---------------
3171
+ * | button | | icon |
3172
+ * -------------- ---------------
3173
+ *
3174
+ * scene 2
3175
+ * -------------- ---------------
3176
+ * | button | | text |
3177
+ * -------------- ---------------
3178
+ *
3179
+ * ```
3180
+ * In case, that your reference element can have multiple values, in the following example, the element right of the button can be either icon or text.
3181
+ * You can use **the `or()` relation**, so your teststep is valid for both scenes
3182
+ * ```typescript
3183
+ * const button = await aui.get().button().rightOf().icon().or().text().exec();
3184
+ * console.log(button);
3185
+ * ```
3186
+ * Returns the same button for both cases
3187
+ * ```text
3188
+ * console output: [
3189
+ * DetectedElement {
3190
+ * name: 'BUTTON',
3191
+ * text: 'button',
3192
+ * colors: [ 'red', 'black', 'red' ],
3193
+ * bndbox: BoundingBox {
3194
+ * xmin: 900,
3195
+ * ymin: 910,
3196
+ * xmax: 920,
3197
+ * ymax: 930
3198
+ * }
3199
+ * }
3200
+ * ]
3201
+ * ```
3202
+ *
3203
+ * @return {FluentFiltersGetter}
3204
+ */
3205
+ or() {
3206
+ this._textStr = 'or';
3207
+ return new FluentFiltersGetter(this);
3208
+ }
3209
+ /**
3210
+ * Logic and operator
3211
+ *
3212
+ * **Examples:**
3213
+ * ```text
3214
+ * example scene:
3215
+ * -------------------------- --------------------------
3216
+ * | icon user colored black | | icon user colored red |
3217
+ * -------------------------- --------------------------
3218
+ * ```
3219
+ * ```typescript
3220
+ * const icons = await aui.get().icon().withText('user').exec();
3221
+ * console.log(icons);
3222
+ * ```
3223
+ * Using only the filter withText, the get command will return both icons because they share the same text
3224
+ * ```text
3225
+ * console output: [
3226
+ * DetectedElement {
3227
+ * name: 'ICON',
3228
+ * text: 'user',
3229
+ * colors: [ 'black', 'black', 'black' ],
3230
+ * bndbox: BoundingBox {
3231
+ * xmin: 1000,
3232
+ * ymin: 1010,
3233
+ * xmax: 1020,
3234
+ * ymax: 1030
3235
+ * }
3236
+ * },
3237
+ * DetectedElement {
3238
+ * name: 'ICON',
3239
+ * text: 'user',
3240
+ * colors: [ 'red', 'red', 'red' ],
3241
+ * bndbox: BoundingBox {
3242
+ * xmin: 900,
3243
+ * ymin: 910,
3244
+ * xmax: 920,
3245
+ * ymax: 930
3246
+ * }
3247
+ * }
3248
+ * ]
3249
+ * ```
3250
+ * You can combine filters with **the `and()` relation** and specify exactly which icon you want
3251
+ * ```typescript
3252
+ * const icons = await aui.get().icon().withText('user').and().colored('red').exec()
3253
+ * console.log(icons)
3254
+ * ```
3255
+ * The get command returns only the red icon although both icons have the same text
3256
+ * ```text
3257
+ * console output: [
3258
+ * DetectedElement {
3259
+ * name: 'ICON',
3260
+ * text: 'user',
3261
+ * colors: [ 'red', 'red', 'red' ],
3262
+ * bndbox: BoundingBox {
3263
+ * xmin: 900,
3264
+ * ymin: 910,
3265
+ * xmax: 920,
3266
+ * ymax: 930
3267
+ * }
3268
+ * }
3269
+ * ]
3270
+ * ```
3271
+ *
3272
+ * @return {FluentFiltersGetter}
3273
+ */
3274
+ and() {
3275
+ this._textStr = 'and';
3276
+ return new FluentFiltersGetter(this);
3277
+ }
2936
3278
  /**
2937
3279
  * Filters for an element inside another element.
2938
3280
  *
@@ -3114,7 +3456,32 @@ exports.FluentFiltersOrRelationsGetter = FluentFiltersOrRelationsGetter;
3114
3456
  // Commands
3115
3457
  class Getter extends FluentCommand {
3116
3458
  /**
3117
- * Returns the filtered element
3459
+ * Returns an array with all filtered elements.
3460
+ * A detected element has the following properties:
3461
+ * - `name` of the element
3462
+ * - `text` content of element
3463
+ * - `colors` of element
3464
+ * - `bndbox`: location of element described with coordinates of a bounding box
3465
+ * **Examples:**
3466
+ * ```typescript
3467
+ * const text = await aui.get().text().withText('Sign').exec();
3468
+ * console.log(text);
3469
+ * ```
3470
+ * ```text
3471
+ * console output: [
3472
+ * DetectedElement {
3473
+ * name: 'TEXT',
3474
+ * text: 'Sign In',
3475
+ * colors: [ 'black', 'gray', 'gray' ],
3476
+ * bndbox: BoundingBox {
3477
+ * xmin: 1128.2720982142857,
3478
+ * ymin: 160.21332310267857,
3479
+ * xmax: 1178.8204241071428,
3480
+ * ymax: 180.83512834821428
3481
+ * }
3482
+ * }
3483
+ * ]
3484
+ * ```
3118
3485
  *
3119
3486
  * @return {FluentFiltersGetter}
3120
3487
  */
@@ -3123,7 +3490,43 @@ class Getter extends FluentCommand {
3123
3490
  return new FluentFiltersGetter(this);
3124
3491
  }
3125
3492
  /**
3126
- * Returns all detected elements
3493
+ * Returns an array with all detected elements.
3494
+ * A detected element has the following properties:
3495
+ * - `name` of the element
3496
+ * - `text` content of element
3497
+ * - `colors` of element
3498
+ * - `bndbox`: location of element described with coordinates of a bounding box
3499
+ * **Examples:**
3500
+ * ```typescript
3501
+ * const detectedElements = await aui.getAll().exec();
3502
+ * console.log(detectedElements);
3503
+ * ```
3504
+ * ```text
3505
+ * console output: [
3506
+ * DetectedElement {
3507
+ * name: 'TEXT',
3508
+ * text: 'Sign In',
3509
+ * colors: [ 'black', 'gray', 'gray' ],
3510
+ * bndbox: BoundingBox {
3511
+ * xmin: 1128.2720982142857,
3512
+ * ymin: 160.21332310267857,
3513
+ * xmax: 1178.8204241071428,
3514
+ * ymax: 180.83512834821428
3515
+ * },
3516
+ * DetectedElement {
3517
+ * name: 'ICON',
3518
+ * text: 'search',
3519
+ * colors: [ 'black', 'red', 'gray' ],
3520
+ * bndbox: BoundingBox {
3521
+ * xmin: 250.8204241071428,
3522
+ * ymin: 300.21332310267857,
3523
+ * xmax: 450.6304241071428,
3524
+ * ymax: 950.47812834821428
3525
+ * },
3526
+ * ... 381 more items
3527
+ * }
3528
+ * ]
3529
+ * ```
3127
3530
  *
3128
3531
  * @return {ExecGetter}
3129
3532
  */
@@ -6,10 +6,11 @@ import { DetectedElement } from '../core/model/annotation-result/detected-elemen
6
6
  export declare class InferenceClient {
7
7
  baseUrl: string;
8
8
  httpClient: HttpClientGot;
9
+ resize?: number | undefined;
9
10
  readonly workspaceId?: string | undefined;
10
11
  apiVersion: string;
11
12
  url: string;
12
- constructor(baseUrl: string, httpClient: HttpClientGot, workspaceId?: string | undefined, apiVersion?: string);
13
+ constructor(baseUrl: string, httpClient: HttpClientGot, resize?: number | undefined, workspaceId?: string | undefined, apiVersion?: string);
13
14
  isImageRequired(instruction: string): Promise<boolean>;
14
15
  private resizeIfNeeded;
15
16
  inference(customElements?: CustomElement[], image?: string, instruction?: string): Promise<ControlCommand | Annotation>;
@@ -18,14 +18,20 @@ const ui_control_commands_1 = require("../core/ui-control-commands");
18
18
  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
+ const config_error_1 = require("./config-error");
21
22
  class InferenceClient {
22
- constructor(baseUrl, httpClient, workspaceId, apiVersion = 'v3') {
23
+ constructor(baseUrl, httpClient, resize, workspaceId, apiVersion = 'v3') {
23
24
  this.baseUrl = baseUrl;
24
25
  this.httpClient = httpClient;
26
+ this.resize = resize;
25
27
  this.workspaceId = workspaceId;
26
28
  this.apiVersion = apiVersion;
27
29
  const versionedBaseUrl = (0, url_join_1.default)(this.baseUrl, 'api', this.apiVersion);
28
30
  this.url = workspaceId ? (0, url_join_1.default)(versionedBaseUrl, 'workspaces', workspaceId) : versionedBaseUrl;
31
+ if (this.resize !== undefined && this.resize <= 0) {
32
+ throw new config_error_1.ConfigurationError(`Resize must be a positive number. The current resize value "${this.resize}" is not valid.`);
33
+ }
34
+ this.resize = this.resize ? Math.ceil(this.resize) : this.resize;
29
35
  }
30
36
  isImageRequired(instruction) {
31
37
  return __awaiter(this, void 0, void 0, function* () {
@@ -40,10 +46,10 @@ class InferenceClient {
40
46
  // eslint-disable-next-line class-methods-use-this
41
47
  resizeIfNeeded(customElements, image) {
42
48
  return __awaiter(this, void 0, void 0, function* () {
43
- if (!(image) || customElements.length > 0) {
49
+ if (!(image) || customElements.length > 0 || this.resize === undefined) {
44
50
  return { base64Image: image, resizeRatio: 1 };
45
51
  }
46
- return (0, transformations_1.resizeBase64ImageWithSameRatio)(image);
52
+ return (0, transformations_1.resizeBase64ImageWithSameRatio)(image, this.resize);
47
53
  });
48
54
  }
49
55
  inference(customElements = [], image, instruction) {
@@ -23,6 +23,7 @@ const annotation_level_1 = require("./annotation-level");
23
23
  const ui_control_client_error_1 = require("./ui-control-client-error");
24
24
  const read_environment_credentials_1 = require("./read-environment-credentials");
25
25
  const analytics_1 = require("../utils/analytics");
26
+ const proxy_builder_1 = require("../utils/proxy/proxy-builder");
26
27
  const getClientArgsWithDefaults = (clientArgs = {}) => (Object.assign({ uiControllerUrl: 'http://127.0.0.1:6769', inferenceServerUrl: 'https://inference.askui.com', annotationLevel: annotation_level_1.AnnotationLevel.DISABLED }, clientArgs));
27
28
  class UiControlClient extends dsl_1.ApiCommands {
28
29
  constructor(httpClient, clientArgs, workspaceId) {
@@ -39,7 +40,8 @@ class UiControlClient extends dsl_1.ApiCommands {
39
40
  const analyticsCookies = yield analytics.getAnalyticsCookies();
40
41
  const cas = getClientArgsWithDefaults(clientArgs);
41
42
  const credentialArgs = cas.credentials || (0, read_environment_credentials_1.envCredentials)();
42
- const httpClient = new http_client_got_1.HttpClientGot(credentialArgs === null || credentialArgs === void 0 ? void 0 : credentialArgs.token, analyticsHeaders, analyticsCookies);
43
+ const proxyAgentArgs = cas.proxyAgents || (yield (0, proxy_builder_1.buildProxyAgentArgsFromEnvironment)());
44
+ const httpClient = new http_client_got_1.HttpClientGot(credentialArgs === null || credentialArgs === void 0 ? void 0 : credentialArgs.token, analyticsHeaders, analyticsCookies, proxyAgentArgs);
43
45
  return new UiControlClient(httpClient, cas, credentialArgs === null || credentialArgs === void 0 ? void 0 : credentialArgs.workspaceId);
44
46
  });
45
47
  }
@@ -50,7 +52,7 @@ class UiControlClient extends dsl_1.ApiCommands {
50
52
  return this._uiControllerClient;
51
53
  }
52
54
  get inferenceClient() {
53
- return new inference_client_1.InferenceClient(this.clientArgs.inferenceServerUrl, this.httpClient, this.workspaceId);
55
+ return new inference_client_1.InferenceClient(this.clientArgs.inferenceServerUrl, this.httpClient, this.clientArgs.resize, this.workspaceId);
54
56
  }
55
57
  get executionRuntime() {
56
58
  return new execution_runtime_1.ExecutionRuntime(this.uiControllerClient, this.inferenceClient);
@@ -1,10 +1,19 @@
1
1
  import { AnnotationLevel } from './annotation-level';
2
2
  import { CredentialArgs } from './credentials-args';
3
+ import { ProxyAgentArgs } from '../shared/proxy-agent-args';
3
4
  /**
4
5
  * Configuration options for the askui UI Control Client
5
6
  *
6
7
  * @param {string} uiControllerUrl - Default: http://127.0.0.1:6769
7
8
  * The adress of the askui UI Controller server.
9
+ * @param {(number | undefined)} resize - Default: undefined
10
+ * The resizing will be skipped if it's undefined.
11
+ * The side length of the target image to resize to in px.
12
+ * Your screenshot image will be resized with the original aspect ratio,
13
+ * and the lengths image side will be equal to this number.
14
+ * This can be used to reduce the inference time by reducing
15
+ * the request size in case of a bad internet connection.
16
+ * But it can cause a decrease in the prediction quality.
8
17
  * @param {string} inferenceClientUrl - Default: https://inference.askui.com`
9
18
  * Address of the askui Inference server.
10
19
  * @param {AnnotationLevel} annotationLevel - Default: AnnotationLevel.DISABLED
@@ -13,12 +22,16 @@ import { CredentialArgs } from './credentials-args';
13
22
  * You have three options: `DISABLED`, `ON_FAILURE`, `ALL`.
14
23
  * @param {CredentialArgs} credentials - We need to provide credentials for
15
24
  * the authentication of the askui Inference Server.
25
+ * You have three options: `DISABLED`, `ON_FAILURE`, `ALL`.
26
+ * @param {ProxyAgentArgs} proxyAgents - To configure the proxy agents for http(s) requests.
16
27
  */
17
28
  export interface ClientArgs {
18
29
  readonly uiControllerUrl?: string;
19
30
  readonly inferenceServerUrl?: string;
20
31
  readonly annotationLevel?: AnnotationLevel;
21
32
  readonly credentials?: CredentialArgs;
33
+ readonly proxyAgents?: ProxyAgentArgs;
34
+ readonly resize?: number;
22
35
  }
23
36
  export interface ClientArgsWithDefaults extends ClientArgs {
24
37
  readonly uiControllerUrl: string;
@@ -1,4 +1,13 @@
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
  };
@@ -8,14 +17,36 @@ const commander_1 = require("commander");
8
17
  const path_1 = __importDefault(require("path"));
9
18
  const fs_extra_1 = __importDefault(require("fs-extra"));
10
19
  const path_2 = require("../utils/path");
20
+ const logger_1 = require("./logger");
11
21
  const createProgram = () => {
12
22
  const program = new commander_1.Command('askui');
13
23
  program.usage('<command> [options]');
14
24
  return program;
15
25
  };
16
- function copyExampleProject() {
17
- const exampleProjectPath = path_1.default.join('example_projects_templates', 'typescript_jest');
18
- fs_extra_1.default.copySync(path_1.default.join((0, path_2.getPathToNodeModulesRoot)(), exampleProjectPath), '.');
26
+ function replaceStringInFile(filePath, replace, replacement) {
27
+ return __awaiter(this, void 0, void 0, function* () {
28
+ try {
29
+ const data = yield fs_extra_1.default.readFile(filePath, 'utf8');
30
+ const result = data.replace(replace, replacement);
31
+ yield fs_extra_1.default.writeFile(filePath, result, 'utf8');
32
+ }
33
+ catch (error) {
34
+ logger_1.logger.error(`Could not replace '${replace}' with '${replacement}' in file '${path_1.default}'`);
35
+ logger_1.logger.error(error.message);
36
+ }
37
+ });
38
+ }
39
+ function copyExampleProject(options) {
40
+ return __awaiter(this, void 0, void 0, function* () {
41
+ const exampleProjectPath = path_1.default.join('example_projects_templates', 'typescript_jest');
42
+ fs_extra_1.default.copySync(path_1.default.join((0, path_2.getPathToNodeModulesRoot)(), exampleProjectPath), '.');
43
+ if (options['workspaceId']) {
44
+ yield replaceStringInFile('./test/helper/jest.setup.ts', '<your workspace id>', options['workspaceId']);
45
+ }
46
+ if (options['accessToken']) {
47
+ yield replaceStringInFile('./test/helper/jest.setup.ts', '<your access token>', options['accessToken']);
48
+ }
49
+ });
19
50
  }
20
51
  function init(argv) {
21
52
  const args = argv || process.argv;
@@ -23,7 +54,12 @@ function init(argv) {
23
54
  program
24
55
  .command('init')
25
56
  .description('creates a typescript example project')
26
- .action(() => { copyExampleProject(); });
57
+ .option('-w, --workspace-id <value>', 'a workspace id')
58
+ .option('-a, --access-token <value>', 'an access token for the workspace with the id')
59
+ .usage('[-w workspace_id] [-a access_token]')
60
+ .action((opts) => __awaiter(this, void 0, void 0, function* () {
61
+ yield copyExampleProject(opts);
62
+ }));
27
63
  return program.parse(args);
28
64
  }
29
65
  exports.init = init;
@@ -1,3 +1,6 @@
1
+ /// <reference types="node" />
2
+ import http from 'http';
3
+ import https from 'https';
1
4
  declare enum SupportedPlatform {
2
5
  LINUX = "linux",
3
6
  DARWIN = "darwin",
@@ -5,5 +8,8 @@ declare enum SupportedPlatform {
5
8
  }
6
9
  export declare function platform(): SupportedPlatform;
7
10
  export declare function getBinaryPath(version: string): string;
8
- export declare function downloadServerBinaries(binaryVersion: string): Promise<void>;
11
+ export declare function downloadServerBinaries(binaryVersion: string, proxyAgent?: {
12
+ http: http.Agent;
13
+ https: https.Agent;
14
+ }): Promise<void>;
9
15
  export {};
@@ -44,7 +44,7 @@ function getBinaryDownloadUrl(binaryVersion) {
44
44
  const arch = os_1.default.arch();
45
45
  return `${baseUrl}/${platform()}/${arch}/${binarySubPathsByPlatform[platform()][1]}`;
46
46
  }
47
- function downloadServerBinaries(binaryVersion) {
47
+ function downloadServerBinaries(binaryVersion, proxyAgent) {
48
48
  return new Promise((resolve, reject) => {
49
49
  const url = getBinaryDownloadUrl(binaryVersion);
50
50
  const binaryOutputPath = getBinaryPath(binaryVersion);
@@ -53,7 +53,7 @@ function downloadServerBinaries(binaryVersion) {
53
53
  if (!(fs_1.default.existsSync(binaryFolder))) {
54
54
  fs_1.default.mkdirSync(binaryFolder, { recursive: true });
55
55
  }
56
- const downloadStream = got_1.default.stream(url);
56
+ const downloadStream = got_1.default.stream(url, proxyAgent ? { agent: proxyAgent } : {});
57
57
  const fileWriterStream = fs_1.default.createWriteStream(binaryOutputPath);
58
58
  downloadStream.on('error', () => {
59
59
  reject();
@@ -1,3 +1,4 @@
1
+ import { ProxyAgentArgs } from '../shared/proxy-agent-args';
1
2
  import { LogLevels } from '../shared/log-levels';
2
3
  /**
3
4
  * Configuration options for the askui UI Controller
@@ -5,6 +6,7 @@ import { LogLevels } from '../shared/log-levels';
5
6
  * @param {number} display - Default: `0`
6
7
  * You can choose on which display you want to excecute all tests.
7
8
  * 0 is your main monitor.
9
+ *
8
10
  * If you want to use your second monitor you can change
9
11
  * the value to `1` (`2` for your third monitor etc.).
10
12
  * @param {string} binaryVersion - Default: `'latest'`
@@ -26,6 +28,7 @@ import { LogLevels } from '../shared/log-levels';
26
28
  * @param {string} logFilePath - Default: `'<temp-dir>/askui/askui-server.log'`
27
29
  * It is possible to specify a path for your log files.
28
30
  * Per default we create the askui-server.log file and askui folder in your temp folder.
31
+ * @param {ProxyAgentArgs} proxyAgents - To configure the proxy agents for our http(s) requests.
29
32
  */
30
33
  export interface UiControllerArgs {
31
34
  readonly display?: number;
@@ -37,6 +40,7 @@ export interface UiControllerArgs {
37
40
  readonly overWriteBinary?: boolean;
38
41
  readonly logLevel?: LogLevels;
39
42
  readonly logFilePath?: string;
43
+ readonly proxyAgents?: ProxyAgentArgs;
40
44
  }
41
45
  export interface UiControllerArgsWithDefaults extends UiControllerArgs {
42
46
  readonly display: number;