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>;
|
|
@@ -13,6 +13,7 @@ import { Annotation } from '../core/annotation/annotation';
|
|
|
13
13
|
import { resizeBase64ImageWithSameRatio } from '../utils/transformations';
|
|
14
14
|
import { InferenceResponseError } from './inference-response-error';
|
|
15
15
|
import { ConfigurationError } from './config-error';
|
|
16
|
+
import { logger } from '../lib/logger';
|
|
16
17
|
export class InferenceClient {
|
|
17
18
|
constructor(baseUrl, httpClient, resize, workspaceId, apiVersion = 'v3') {
|
|
18
19
|
this.baseUrl = baseUrl;
|
|
@@ -21,7 +22,9 @@ export class InferenceClient {
|
|
|
21
22
|
this.workspaceId = workspaceId;
|
|
22
23
|
this.apiVersion = apiVersion;
|
|
23
24
|
const versionedBaseUrl = urljoin(this.baseUrl, 'api', this.apiVersion);
|
|
24
|
-
this.url = workspaceId
|
|
25
|
+
this.url = workspaceId
|
|
26
|
+
? urljoin(versionedBaseUrl, 'workspaces', workspaceId)
|
|
27
|
+
: versionedBaseUrl;
|
|
25
28
|
if (this.resize !== undefined && this.resize <= 0) {
|
|
26
29
|
throw new ConfigurationError(`Resize must be a positive number. The current resize value "${this.resize}" is not valid.`);
|
|
27
30
|
}
|
|
@@ -30,17 +33,17 @@ export class InferenceClient {
|
|
|
30
33
|
isImageRequired(instruction) {
|
|
31
34
|
return __awaiter(this, void 0, void 0, function* () {
|
|
32
35
|
const url = urljoin(this.url, 'instruction', 'is-image-required');
|
|
33
|
-
const
|
|
36
|
+
const requestBody = {
|
|
34
37
|
instruction,
|
|
35
38
|
};
|
|
36
|
-
const
|
|
37
|
-
return
|
|
39
|
+
const response = yield this.httpClient.post(url, requestBody);
|
|
40
|
+
return response.body.isImageRequired;
|
|
38
41
|
});
|
|
39
42
|
}
|
|
40
43
|
// eslint-disable-next-line class-methods-use-this
|
|
41
44
|
resizeIfNeeded(customElements, image) {
|
|
42
45
|
return __awaiter(this, void 0, void 0, function* () {
|
|
43
|
-
if (!
|
|
46
|
+
if (!image || customElements.length > 0 || this.resize === undefined) {
|
|
44
47
|
return { base64Image: image, resizeRatio: 1 };
|
|
45
48
|
}
|
|
46
49
|
return resizeBase64ImageWithSameRatio(image, this.resize);
|
|
@@ -49,16 +52,22 @@ export class InferenceClient {
|
|
|
49
52
|
inference(customElements = [], image, instruction) {
|
|
50
53
|
return __awaiter(this, void 0, void 0, function* () {
|
|
51
54
|
const resizedImage = yield this.resizeIfNeeded(customElements, image);
|
|
52
|
-
const
|
|
55
|
+
const requestBody = {
|
|
53
56
|
image: resizedImage.base64Image,
|
|
54
57
|
instruction,
|
|
55
58
|
customElements,
|
|
56
59
|
};
|
|
57
60
|
const url = urljoin(this.url, 'inference');
|
|
58
|
-
const
|
|
59
|
-
|
|
61
|
+
const response = yield this.httpClient.post(url, requestBody);
|
|
62
|
+
InferenceClient.logMetaInformation(response);
|
|
63
|
+
return InferenceResponse.fromJson(response.body, resizedImage.resizeRatio, image);
|
|
60
64
|
});
|
|
61
65
|
}
|
|
66
|
+
static logMetaInformation(response) {
|
|
67
|
+
if (response.headers['askui-usage-warnings'] !== undefined) {
|
|
68
|
+
logger.warn(response.headers['askui-usage-warnings']);
|
|
69
|
+
}
|
|
70
|
+
}
|
|
62
71
|
predictControlCommand(instruction, customElements = [], image) {
|
|
63
72
|
return __awaiter(this, void 0, void 0, function* () {
|
|
64
73
|
const inferenceResponse = yield this.inference(customElements, image, instruction);
|
|
@@ -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
|
}
|
|
@@ -24,18 +24,26 @@ export class HttpClientGot {
|
|
|
24
24
|
}
|
|
25
25
|
initHeaders(token, customHeaders = {}) {
|
|
26
26
|
const credentials = token ? new Credentials(token) : undefined;
|
|
27
|
-
this.headers = Object.assign(Object.assign({}, (credentials
|
|
27
|
+
this.headers = Object.assign(Object.assign({}, (credentials
|
|
28
|
+
? { Authorization: `Basic ${credentials === null || credentials === void 0 ? void 0 : credentials.base64Encoded}` }
|
|
29
|
+
: {})), customHeaders);
|
|
28
30
|
}
|
|
29
31
|
injectHeadersAndCookies(url, options) {
|
|
30
32
|
const cookieJar = new CookieJar();
|
|
31
|
-
Object.keys(this.cookies)
|
|
33
|
+
Object.keys(this.cookies)
|
|
34
|
+
.map((key) => `${key}=${this.cookies[key]}`)
|
|
35
|
+
.forEach((cookie) => {
|
|
32
36
|
cookieJar.setCookieSync(cookie, url);
|
|
33
37
|
});
|
|
34
38
|
return Object.assign(Object.assign({}, options), { headers: this.headers, cookieJar });
|
|
35
39
|
}
|
|
36
40
|
post(url, data) {
|
|
37
41
|
return __awaiter(this, void 0, void 0, function* () {
|
|
38
|
-
const options = this.injectHeadersAndCookies(url, {
|
|
42
|
+
const options = this.injectHeadersAndCookies(url, {
|
|
43
|
+
json: data,
|
|
44
|
+
responseType: 'json',
|
|
45
|
+
throwHttpErrors: false,
|
|
46
|
+
});
|
|
39
47
|
const { body, statusCode, headers } = yield this.askuiGot.post(url, options);
|
|
40
48
|
if (headers['deprecation'] !== undefined) {
|
|
41
49
|
logger.warn(headers['deprecation']);
|
|
@@ -43,7 +51,7 @@ export class HttpClientGot {
|
|
|
43
51
|
if (statusCode !== 200) {
|
|
44
52
|
throw httpClientErrorHandler(statusCode, JSON.stringify(body));
|
|
45
53
|
}
|
|
46
|
-
return body;
|
|
54
|
+
return { headers, body };
|
|
47
55
|
});
|
|
48
56
|
}
|
|
49
57
|
get(url, options = { responseType: 'json' }) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "askui",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.8.0",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"author": "askui GmbH <info@askui.com> (http://www.askui.com/)",
|
|
6
6
|
"description": "Reliable, automated end-to-end-testing that depends on what is shown on your screen instead of the technology you are running on",
|