askui 0.7.1 → 0.8.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/inference-response/inference-response.d.ts +7 -11
- package/dist/cjs/core/inference-response/inference-response.js +8 -13
- package/dist/cjs/core/inference-response/invalid-model-type-error.d.ts +4 -0
- package/dist/cjs/core/inference-response/invalid-model-type-error.js +9 -0
- package/dist/cjs/core/inference-response/model-type.d.ts +1 -0
- package/dist/cjs/core/inference-response/model-type.js +2 -0
- package/dist/cjs/execution/dsl.d.ts +592 -1333
- package/dist/cjs/execution/dsl.js +1111 -2383
- package/dist/cjs/execution/inference-client.d.ts +1 -0
- package/dist/cjs/execution/inference-client.js +17 -8
- package/dist/cjs/execution/ui-control-client.js +1 -0
- package/dist/cjs/utils/http/http-client-got.d.ts +5 -1
- package/dist/cjs/utils/http/http-client-got.js +12 -4
- package/dist/esm/core/inference-response/inference-response.d.ts +7 -11
- package/dist/esm/core/inference-response/inference-response.js +8 -13
- package/dist/esm/core/inference-response/invalid-model-type-error.d.ts +4 -0
- package/dist/esm/core/inference-response/invalid-model-type-error.js +5 -0
- package/dist/esm/core/inference-response/model-type.d.ts +1 -0
- package/dist/esm/core/inference-response/model-type.js +1 -0
- package/dist/esm/execution/dsl.d.ts +592 -1333
- package/dist/esm/execution/dsl.js +1119 -2391
- package/dist/esm/execution/inference-client.d.ts +1 -0
- package/dist/esm/execution/inference-client.js +17 -8
- package/dist/esm/execution/ui-control-client.js +1 -0
- package/dist/esm/utils/http/http-client-got.d.ts +5 -1
- package/dist/esm/utils/http/http-client-got.js +12 -4
- package/package.json +1 -1
|
@@ -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
|
|
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
|
|
42
|
+
const requestBody = {
|
|
40
43
|
instruction,
|
|
41
44
|
};
|
|
42
|
-
const
|
|
43
|
-
return
|
|
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 (!
|
|
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
|
|
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
|
|
65
|
-
|
|
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);
|
|
@@ -110,6 +110,7 @@ class UiControlClient extends dsl_1.ApiCommands {
|
|
|
110
110
|
customElements,
|
|
111
111
|
secretText,
|
|
112
112
|
});
|
|
113
|
+
this.secretText = undefined;
|
|
113
114
|
yield this.annotateByDefault(test_case_result_dto_1.TestStepState.PASSED, customElements);
|
|
114
115
|
return yield Promise.resolve();
|
|
115
116
|
}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
1
2
|
import { OptionsOfJSONResponseBody } from 'got';
|
|
2
3
|
import http from 'http';
|
|
3
4
|
import https from 'https';
|
|
@@ -17,6 +18,9 @@ export declare class HttpClientGot {
|
|
|
17
18
|
} | undefined);
|
|
18
19
|
private initHeaders;
|
|
19
20
|
private injectHeadersAndCookies;
|
|
20
|
-
post<T>(url: string, data: Record<string | number | symbol, unknown>): Promise<
|
|
21
|
+
post<T>(url: string, data: Record<string | number | symbol, unknown>): Promise<{
|
|
22
|
+
headers: http.IncomingHttpHeaders;
|
|
23
|
+
body: T;
|
|
24
|
+
}>;
|
|
21
25
|
get<T>(url: string, options?: OptionsOfJSONResponseBody): Promise<T>;
|
|
22
26
|
}
|
|
@@ -30,18 +30,26 @@ class HttpClientGot {
|
|
|
30
30
|
}
|
|
31
31
|
initHeaders(token, customHeaders = {}) {
|
|
32
32
|
const credentials = token ? new credentials_1.Credentials(token) : undefined;
|
|
33
|
-
this.headers = Object.assign(Object.assign({}, (credentials
|
|
33
|
+
this.headers = Object.assign(Object.assign({}, (credentials
|
|
34
|
+
? { Authorization: `Basic ${credentials === null || credentials === void 0 ? void 0 : credentials.base64Encoded}` }
|
|
35
|
+
: {})), customHeaders);
|
|
34
36
|
}
|
|
35
37
|
injectHeadersAndCookies(url, options) {
|
|
36
38
|
const cookieJar = new tough_cookie_1.CookieJar();
|
|
37
|
-
Object.keys(this.cookies)
|
|
39
|
+
Object.keys(this.cookies)
|
|
40
|
+
.map((key) => `${key}=${this.cookies[key]}`)
|
|
41
|
+
.forEach((cookie) => {
|
|
38
42
|
cookieJar.setCookieSync(cookie, url);
|
|
39
43
|
});
|
|
40
44
|
return Object.assign(Object.assign({}, options), { headers: this.headers, cookieJar });
|
|
41
45
|
}
|
|
42
46
|
post(url, data) {
|
|
43
47
|
return __awaiter(this, void 0, void 0, function* () {
|
|
44
|
-
const options = this.injectHeadersAndCookies(url, {
|
|
48
|
+
const options = this.injectHeadersAndCookies(url, {
|
|
49
|
+
json: data,
|
|
50
|
+
responseType: 'json',
|
|
51
|
+
throwHttpErrors: false,
|
|
52
|
+
});
|
|
45
53
|
const { body, statusCode, headers } = yield this.askuiGot.post(url, options);
|
|
46
54
|
if (headers['deprecation'] !== undefined) {
|
|
47
55
|
lib_1.logger.warn(headers['deprecation']);
|
|
@@ -49,7 +57,7 @@ class HttpClientGot {
|
|
|
49
57
|
if (statusCode !== 200) {
|
|
50
58
|
throw (0, custom_errors_1.httpClientErrorHandler)(statusCode, JSON.stringify(body));
|
|
51
59
|
}
|
|
52
|
-
return body;
|
|
60
|
+
return { headers, body };
|
|
53
61
|
});
|
|
54
62
|
}
|
|
55
63
|
get(url, options = { responseType: 'json' }) {
|
|
@@ -1,15 +1,11 @@
|
|
|
1
1
|
import { ControlCommand } from '../ui-control-commands/control-command';
|
|
2
2
|
import { Annotation } from '../annotation/annotation';
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
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
|
-
|
|
12
|
-
|
|
13
|
-
COMMANDS:
|
|
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 {};
|
|
@@ -1,21 +1,16 @@
|
|
|
1
1
|
import { ControlCommand } from '../ui-control-commands/control-command';
|
|
2
2
|
import { Annotation } from '../annotation/annotation';
|
|
3
|
+
import { InvalidModelTypeError } from './invalid-model-type-error';
|
|
3
4
|
export class InferenceResponse {
|
|
4
|
-
constructor(type, data) {
|
|
5
|
-
this.type = type;
|
|
6
|
-
this.data = data;
|
|
7
|
-
}
|
|
8
5
|
static fromJson(json, resizeRatio = 1, image) {
|
|
9
|
-
|
|
10
|
-
return this.createModels(inferenceResponse.type, inferenceResponse.data, resizeRatio, image);
|
|
6
|
+
return this.createModels(json.type, json.data, resizeRatio, image);
|
|
11
7
|
}
|
|
12
8
|
static createModels(type, data, resizeRatio, image) {
|
|
13
|
-
|
|
9
|
+
if (type === 'COMMANDS')
|
|
10
|
+
return ControlCommand.fromJson(data, resizeRatio);
|
|
11
|
+
if (type === 'DETECTED_ELEMENTS') {
|
|
12
|
+
return Annotation.fromJson({ image, detected_elements: data.detected_elements }, resizeRatio);
|
|
13
|
+
}
|
|
14
|
+
throw new InvalidModelTypeError(type);
|
|
14
15
|
}
|
|
15
16
|
}
|
|
16
|
-
InferenceResponse.models = {
|
|
17
|
-
DETECTED_ELEMENTS: (data, resizeRatio, image) => Annotation
|
|
18
|
-
.fromJson({ image, detected_elements: data.detected_elements }, resizeRatio),
|
|
19
|
-
COMMANDS: (data, resizeRatio) => ControlCommand
|
|
20
|
-
.fromJson(data, resizeRatio),
|
|
21
|
-
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare type ModelType = 'DETECTED_ELEMENTS' | 'COMMANDS';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|