askui 0.29.0 → 0.31.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 (84) hide show
  1. package/dist/cjs/core/cache/cache-config.d.ts +5 -0
  2. package/dist/cjs/core/cache/cache-config.js +2 -0
  3. package/dist/cjs/core/cache/cache-entry-reference.d.ts +7 -0
  4. package/dist/cjs/core/cache/cache-entry-reference.js +20 -0
  5. package/dist/cjs/core/cache/cache-entry.d.ts +11 -0
  6. package/dist/cjs/core/cache/cache-entry.js +47 -0
  7. package/dist/cjs/core/cache/cache-interface.d.ts +11 -0
  8. package/dist/cjs/core/cache/cache-interface.js +2 -0
  9. package/dist/cjs/core/cache/cache-manager.d.ts +24 -0
  10. package/dist/cjs/core/cache/cache-manager.js +145 -0
  11. package/dist/cjs/core/cache/cahe-file.d.ts +19 -0
  12. package/dist/cjs/core/cache/cahe-file.js +128 -0
  13. package/dist/cjs/core/cache/dummy-cache-manager.d.ts +12 -0
  14. package/dist/cjs/core/cache/dummy-cache-manager.js +27 -0
  15. package/dist/cjs/core/cache/image-reference.d.ts +10 -0
  16. package/dist/cjs/core/cache/image-reference.js +40 -0
  17. package/dist/cjs/core/cache/index.d.ts +7 -0
  18. package/dist/cjs/core/cache/index.js +13 -0
  19. package/dist/cjs/core/model/annotation-result/boundary-box.js +1 -1
  20. package/dist/cjs/core/model/custom-element.d.ts +1 -0
  21. package/dist/cjs/core/model/custom-element.js +3 -0
  22. package/dist/cjs/core/models/anthropic/askui-agent.d.ts +2 -2
  23. package/dist/cjs/core/models/anthropic/askui-agent.js +33 -33
  24. package/dist/cjs/core/models/anthropic/tools/os-agent-tools.d.ts +47 -3
  25. package/dist/cjs/core/models/anthropic/tools/os-agent-tools.js +220 -23
  26. package/dist/cjs/core/ui-control-commands/action.d.ts +1 -0
  27. package/dist/cjs/core/ui-control-commands/action.js +10 -2
  28. package/dist/cjs/core/ui-control-commands/control-command.d.ts +1 -0
  29. package/dist/cjs/core/ui-control-commands/control-command.js +7 -0
  30. package/dist/cjs/execution/dsl.d.ts +12 -5
  31. package/dist/cjs/execution/dsl.js +30 -15
  32. package/dist/cjs/execution/execution-runtime.d.ts +1 -1
  33. package/dist/cjs/execution/execution-runtime.js +21 -17
  34. package/dist/cjs/execution/inference-client.d.ts +5 -3
  35. package/dist/cjs/execution/inference-client.js +22 -3
  36. package/dist/cjs/execution/ui-control-client-dependency-builder.js +6 -1
  37. package/dist/cjs/execution/ui-control-client.d.ts +2 -2
  38. package/dist/cjs/execution/ui-control-client.js +29 -12
  39. package/dist/cjs/execution/ui-controller-client-interface.d.ts +2 -0
  40. package/dist/cjs/utils/base_64_image/base-64-image.d.ts +2 -0
  41. package/dist/cjs/utils/base_64_image/base-64-image.js +27 -4
  42. package/dist/esm/core/cache/cache-config.d.ts +5 -0
  43. package/dist/esm/core/cache/cache-config.js +1 -0
  44. package/dist/esm/core/cache/cache-entry-reference.d.ts +7 -0
  45. package/dist/esm/core/cache/cache-entry-reference.js +16 -0
  46. package/dist/esm/core/cache/cache-entry.d.ts +11 -0
  47. package/dist/esm/core/cache/cache-entry.js +43 -0
  48. package/dist/esm/core/cache/cache-interface.d.ts +11 -0
  49. package/dist/esm/core/cache/cache-interface.js +1 -0
  50. package/dist/esm/core/cache/cache-manager.d.ts +24 -0
  51. package/dist/esm/core/cache/cache-manager.js +141 -0
  52. package/dist/esm/core/cache/cahe-file.d.ts +19 -0
  53. package/dist/esm/core/cache/cahe-file.js +121 -0
  54. package/dist/esm/core/cache/dummy-cache-manager.d.ts +12 -0
  55. package/dist/esm/core/cache/dummy-cache-manager.js +23 -0
  56. package/dist/esm/core/cache/image-reference.d.ts +10 -0
  57. package/dist/esm/core/cache/image-reference.js +36 -0
  58. package/dist/esm/core/cache/index.d.ts +7 -0
  59. package/dist/esm/core/cache/index.js +5 -0
  60. package/dist/esm/core/model/annotation-result/boundary-box.js +1 -1
  61. package/dist/esm/core/model/custom-element.d.ts +1 -0
  62. package/dist/esm/core/model/custom-element.js +3 -0
  63. package/dist/esm/core/models/anthropic/askui-agent.d.ts +2 -2
  64. package/dist/esm/core/models/anthropic/askui-agent.js +34 -34
  65. package/dist/esm/core/models/anthropic/tools/os-agent-tools.d.ts +47 -3
  66. package/dist/esm/core/models/anthropic/tools/os-agent-tools.js +215 -22
  67. package/dist/esm/core/ui-control-commands/action.d.ts +1 -0
  68. package/dist/esm/core/ui-control-commands/action.js +10 -2
  69. package/dist/esm/core/ui-control-commands/control-command.d.ts +1 -0
  70. package/dist/esm/core/ui-control-commands/control-command.js +7 -0
  71. package/dist/esm/execution/dsl.d.ts +12 -5
  72. package/dist/esm/execution/dsl.js +30 -15
  73. package/dist/esm/execution/execution-runtime.d.ts +1 -1
  74. package/dist/esm/execution/execution-runtime.js +21 -17
  75. package/dist/esm/execution/inference-client.d.ts +5 -3
  76. package/dist/esm/execution/inference-client.js +22 -3
  77. package/dist/esm/execution/ui-control-client-dependency-builder.js +6 -1
  78. package/dist/esm/execution/ui-control-client.d.ts +2 -2
  79. package/dist/esm/execution/ui-control-client.js +29 -12
  80. package/dist/esm/execution/ui-controller-client-interface.d.ts +2 -0
  81. package/dist/esm/utils/base_64_image/base-64-image.d.ts +2 -0
  82. package/dist/esm/utils/base_64_image/base-64-image.js +27 -4
  83. package/package.json +1 -1
  84. package/dist/example_projects_templates/templates/askui-helper-windows.nj +0 -32
@@ -0,0 +1,141 @@
1
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3
+ return new (P || (P = Promise))(function (resolve, reject) {
4
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
5
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
6
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
7
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
8
+ });
9
+ };
10
+ import { ControlCommandCode } from '../ui-control-commands';
11
+ import { InputEvent } from '../ui-control-commands/input-event';
12
+ import { Base64Image } from '../../utils/base_64_image/base-64-image';
13
+ import { CacheEntry } from './cache-entry';
14
+ import { ImageReference } from './image-reference';
15
+ import { CacheEntryReference } from './cache-entry-reference';
16
+ import { CacheFile } from './cahe-file';
17
+ export class CacheManager {
18
+ constructor(config) {
19
+ var _a;
20
+ this.relevantData = {};
21
+ this.referenceWidth = 32;
22
+ this.referenceHeight = 16;
23
+ this.defaultValidationType = 'PixelPerfect';
24
+ this.validationType = (_a = config.validationType) !== null && _a !== void 0 ? _a : this.defaultValidationType;
25
+ this.cacheFile = new CacheFile(config.cacheFilePath);
26
+ }
27
+ loadFromFile() {
28
+ this.cacheFile.loadFromFile();
29
+ this.relevantData = this.cacheFile.getDataForValidationType(this.validationType);
30
+ }
31
+ saveToFile() {
32
+ this.cacheFile.saveToFile(this.validationType, this.relevantData);
33
+ }
34
+ add(key, value) {
35
+ if (this.relevantData[key] === undefined) {
36
+ this.relevantData[key] = [];
37
+ }
38
+ this.relevantData[key].push(value);
39
+ }
40
+ addCacheEntryFromControlCommand(instruction, controlCommand, customElements, image) {
41
+ return __awaiter(this, void 0, void 0, function* () {
42
+ let imageReference;
43
+ if (image !== undefined) {
44
+ const moveAction = controlCommand.actions.find((action) => action.inputEvent === InputEvent.MOUSE_MOVE);
45
+ const x = moveAction === null || moveAction === void 0 ? void 0 : moveAction.position.x;
46
+ const y = moveAction === null || moveAction === void 0 ? void 0 : moveAction.position.y;
47
+ if (x !== undefined && y !== undefined) {
48
+ const xTopLeft = Math.max(0, (x - this.referenceWidth / 2));
49
+ const yTopLeft = Math.max(0, (y - this.referenceHeight / 2));
50
+ const base64Image = yield Base64Image.fromString(image);
51
+ const croppedImage = yield base64Image.cropRegion(xTopLeft, yTopLeft, this.referenceWidth, this.referenceHeight);
52
+ imageReference = new ImageReference(croppedImage.toString(true), this.referenceWidth, this.referenceHeight, xTopLeft, yTopLeft);
53
+ }
54
+ }
55
+ const cacheEntry = new CacheEntry(image === undefined, controlCommand, new CacheEntryReference(imageReference));
56
+ const cacheKey = this.encodeKey(instruction, customElements);
57
+ this.add(cacheKey, cacheEntry);
58
+ });
59
+ }
60
+ isImageRequired(instruction, customElements) {
61
+ const cacheKey = this.encodeKey(instruction, customElements);
62
+ const cacheEntries = this.getCacheEntriesByKey(cacheKey);
63
+ if (cacheEntries.length === 0) {
64
+ return undefined;
65
+ }
66
+ return cacheEntries.find((entry) => entry.alwaysValid === false) !== undefined;
67
+ }
68
+ getCachedControlCommand(instruction, customElements, image) {
69
+ return __awaiter(this, void 0, void 0, function* () {
70
+ const cacheKey = this.encodeKey(instruction, customElements);
71
+ const cacheEntry = yield this.getValidCacheEntry(cacheKey, image);
72
+ if (cacheEntry === undefined || cacheEntry.controlCommand.code !== ControlCommandCode.OK) {
73
+ return undefined;
74
+ }
75
+ return cacheEntry.controlCommand;
76
+ });
77
+ }
78
+ // eslint-disable-next-line class-methods-use-this
79
+ encodeKey(instruction, customElements) {
80
+ let key = instruction;
81
+ if (customElements.length > 0) {
82
+ key += ` with CustomElements:${customElements.map((element, index) => `${index}:${element.asString()}`).join(',')}`;
83
+ }
84
+ return key;
85
+ }
86
+ getCacheEntriesByKey(key) {
87
+ if (this.relevantData[key] === undefined) {
88
+ return [];
89
+ }
90
+ const entries = this.relevantData[key];
91
+ if (entries === undefined) {
92
+ return [];
93
+ }
94
+ return entries;
95
+ }
96
+ getValidCacheEntry(key, screenshot) {
97
+ return __awaiter(this, void 0, void 0, function* () {
98
+ const cacheEntries = this.getCacheEntriesByKey(key);
99
+ if (cacheEntries.length === 0) {
100
+ return undefined;
101
+ }
102
+ if (this.validationType === 'PixelPerfect') {
103
+ /* eslint-disable no-restricted-syntax, no-await-in-loop */
104
+ for (const cacheEntry of cacheEntries) {
105
+ if (cacheEntry.alwaysValid) {
106
+ return cacheEntry;
107
+ }
108
+ const isValid = yield this.validateAccordingToPixelPerfect(cacheEntry, screenshot);
109
+ if (isValid) {
110
+ /* eslint-enable no-restricted-syntax, no-await-in-loop */
111
+ return cacheEntry;
112
+ }
113
+ }
114
+ /* eslint-enable no-restricted-syntax, no-await-in-loop */
115
+ }
116
+ return undefined;
117
+ });
118
+ }
119
+ // eslint-disable-next-line class-methods-use-this
120
+ validateAccordingToPixelPerfect(cacheEntry, screenshot) {
121
+ return __awaiter(this, void 0, void 0, function* () {
122
+ var _a;
123
+ if (screenshot === undefined) {
124
+ return false;
125
+ }
126
+ if (((_a = cacheEntry.reference) === null || _a === void 0 ? void 0 : _a.image) === undefined) {
127
+ return false;
128
+ }
129
+ try {
130
+ const referenceImage = yield Base64Image.fromString(screenshot);
131
+ const croppedScreenshot = yield referenceImage.cropRegion(cacheEntry.reference.image.xTopLeft, cacheEntry.reference.image.yTopLeft, cacheEntry.reference.image.width, cacheEntry.reference.image.height);
132
+ const croppedReferenceImageString = croppedScreenshot.toString(true);
133
+ const isValid = croppedReferenceImageString === cacheEntry.reference.image.base64Image;
134
+ return isValid;
135
+ }
136
+ catch (error) {
137
+ return false;
138
+ }
139
+ });
140
+ }
141
+ }
@@ -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,121 @@
1
+ import fs from 'fs';
2
+ import path from 'path';
3
+ import { logger } from '../../lib';
4
+ import { CacheEntry } from './cache-entry';
5
+ export class CacheFile {
6
+ constructor(filePath) {
7
+ this.createAt = new Date();
8
+ this.version = 1;
9
+ this.type = 'AskUI-Cache';
10
+ this.data = {};
11
+ this.filePath = filePath;
12
+ }
13
+ loadFromFileVersion1(json) {
14
+ if (json.version !== 1) {
15
+ throw new Error(`Unsupported key 'version' in the cache file: '${json.version}'. Only version 1 is supported.`);
16
+ }
17
+ if (json.data === undefined) {
18
+ throw new Error("Key 'data' is required in the cache file.");
19
+ }
20
+ if (json.createAt === undefined) {
21
+ throw new Error("Key 'createAt' is required in the cache file.");
22
+ }
23
+ if (json.version === undefined) {
24
+ throw new Error("Key 'version' is required in the cache file.");
25
+ }
26
+ if (json.type !== 'AskUI-Cache') {
27
+ throw new Error(`Unsupported key 'type' in the cache file: '${json.type}'. Only 'AskUI-Cache' is supported.`);
28
+ }
29
+ this.createAt = new Date(json.createAt);
30
+ this.version = json.version;
31
+ this.type = json.type;
32
+ this.data = Object.keys(json.data).reduce((acc, validationType) => {
33
+ var _a, _b;
34
+ const nextAcc = Object.assign({}, acc);
35
+ const validationEntries = (_b = (_a = json.data) === null || _a === void 0 ? void 0 : _a[validationType]) !== null && _b !== void 0 ? _b : {};
36
+ nextAcc[validationType] = Object.keys(validationEntries).reduce((innerAcc, instruction) => {
37
+ var _a;
38
+ const nextInnerAcc = Object.assign({}, innerAcc);
39
+ const rawEntries = (_a = validationEntries[instruction]) !== null && _a !== void 0 ? _a : [];
40
+ nextInnerAcc[instruction] = rawEntries
41
+ .map((entry) => CacheEntry.fromJson(entry))
42
+ .filter((entry) => entry !== undefined);
43
+ return nextInnerAcc;
44
+ }, {});
45
+ return nextAcc;
46
+ }, {});
47
+ }
48
+ loadFromFile() {
49
+ if (this.filePath === undefined) {
50
+ logger.debug('The cache file path is not set. Skipping the cache load.');
51
+ return;
52
+ }
53
+ logger.debug(`Loading the cache from file '${this.filePath}'.`);
54
+ if (!fs.existsSync(this.filePath)) {
55
+ logger.warn(`The cache file does not exist: '${this.filePath}'. Skipping the cache load.`);
56
+ return;
57
+ }
58
+ const data = fs.readFileSync(this.filePath, 'utf8');
59
+ const json = JSON.parse(data);
60
+ if (json.version !== 1) {
61
+ throw new Error(`Unsupported key 'version' in the cache file: '${json.version}'. Only version 1 is supported.`);
62
+ }
63
+ this.loadFromFileVersion1(json);
64
+ }
65
+ getDataForValidationType(validationType) {
66
+ var _a;
67
+ return (_a = this.data[validationType]) !== null && _a !== void 0 ? _a : {};
68
+ }
69
+ getData() {
70
+ return this.data;
71
+ }
72
+ saveToFile(validationType, relevantData) {
73
+ if (this.filePath === undefined) {
74
+ logger.debug('The cache file path is not set. Skipping the cache save.');
75
+ return;
76
+ }
77
+ try {
78
+ logger.debug(`Saving the cache to file '${this.filePath}'.`);
79
+ this.setRelevantData(validationType, relevantData);
80
+ const jsonObject = this.asJsonObject();
81
+ const jsonString = JSON.stringify(jsonObject, null, 2);
82
+ // create the directory if it doesn't exist
83
+ if (!fs.existsSync(path.dirname(this.filePath))) {
84
+ fs.mkdirSync(path.dirname(this.filePath), { recursive: true });
85
+ }
86
+ fs.writeFileSync(this.filePath, jsonString, 'utf8');
87
+ logger.info(`The cache was saved successfully to '${this.filePath}'.`);
88
+ }
89
+ catch (error) {
90
+ logger.error(`An error occurred while saving the cache to file '${this.filePath}': '${error}'`);
91
+ throw error;
92
+ }
93
+ }
94
+ setRelevantData(validationType, relevantData) {
95
+ this.data[validationType] = relevantData;
96
+ }
97
+ asJsonObject() {
98
+ return {
99
+ createAt: this.createAt.toISOString(),
100
+ data: Object.keys(this.data).reduce((acc, validationType) => {
101
+ const validationData = this.data[validationType];
102
+ if (validationData === undefined) {
103
+ return acc;
104
+ }
105
+ const nextAcc = Object.assign({}, acc);
106
+ nextAcc[validationType] = Object.keys(validationData).reduce((innerAcc, instruction) => {
107
+ const entries = validationData[instruction];
108
+ if (entries !== undefined) {
109
+ const nextInnerAcc = Object.assign({}, innerAcc);
110
+ nextInnerAcc[instruction] = entries;
111
+ return nextInnerAcc;
112
+ }
113
+ return innerAcc;
114
+ }, {});
115
+ return nextAcc;
116
+ }, {}),
117
+ type: this.type,
118
+ version: this.version,
119
+ };
120
+ }
121
+ }
@@ -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,23 @@
1
+ export class DummyCacheManager {
2
+ // eslint-disable-next-line class-methods-use-this
3
+ add(_key, _value) {
4
+ }
5
+ // eslint-disable-next-line class-methods-use-this
6
+ addCacheEntryFromControlCommand(_instruction, _controlCommand, _customElements, _image) {
7
+ return Promise.resolve();
8
+ }
9
+ // eslint-disable-next-line class-methods-use-this
10
+ isImageRequired(_instruction, _customElements) {
11
+ return undefined;
12
+ }
13
+ // eslint-disable-next-line class-methods-use-this
14
+ getCachedControlCommand(_instruction, _customElements, _image) {
15
+ return Promise.resolve(undefined);
16
+ }
17
+ // eslint-disable-next-line class-methods-use-this
18
+ loadFromFile() {
19
+ }
20
+ // eslint-disable-next-line class-methods-use-this
21
+ saveToFile() {
22
+ }
23
+ }
@@ -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,36 @@
1
+ export class ImageReference {
2
+ constructor(base64Image, width, height, xTopLeft, yTopLeft) {
3
+ this.base64Image = base64Image;
4
+ this.width = width;
5
+ this.height = height;
6
+ this.xTopLeft = xTopLeft;
7
+ this.yTopLeft = yTopLeft;
8
+ }
9
+ static fromJson(json) {
10
+ if (json.base64Image === undefined) {
11
+ throw new Error('the key "base64Image" is required');
12
+ }
13
+ if (json.width === undefined) {
14
+ throw new Error('the key "width" is required');
15
+ }
16
+ if (json.height === undefined) {
17
+ throw new Error('the key "height" is required');
18
+ }
19
+ if (json.xTopLeft === undefined) {
20
+ throw new Error('the key "xTopLeft" is required');
21
+ }
22
+ if (json.yTopLeft === undefined) {
23
+ throw new Error('the key "yTopLeft" is required');
24
+ }
25
+ return new ImageReference(json.base64Image, json.width, json.height, json.xTopLeft, json.yTopLeft);
26
+ }
27
+ toJson() {
28
+ return {
29
+ base64Image: this.base64Image,
30
+ height: this.height,
31
+ width: this.width,
32
+ xTopLeft: this.xTopLeft,
33
+ yTopLeft: this.yTopLeft,
34
+ };
35
+ }
36
+ }
@@ -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,5 @@
1
+ export { ImageReference } from './image-reference';
2
+ export { CacheEntryReference } from './cache-entry-reference';
3
+ export { CacheEntry } from './cache-entry';
4
+ export { DummyCacheManager } from './dummy-cache-manager';
5
+ export { CacheManager } from './cache-manager';
@@ -17,7 +17,7 @@ export class BoundingBox {
17
17
  this.ymax = ymax;
18
18
  }
19
19
  static fromJson(boundinBox, resizeRatio = 1) {
20
- return new BoundingBox(boundinBox.xmin * resizeRatio, boundinBox.ymin * resizeRatio, boundinBox.xmax * resizeRatio, boundinBox.ymax * resizeRatio);
20
+ return new BoundingBox(Math.round(boundinBox.xmin * resizeRatio), Math.round(boundinBox.ymin * resizeRatio), Math.round(boundinBox.xmax * resizeRatio), Math.round(boundinBox.ymax * resizeRatio));
21
21
  }
22
22
  /**
23
23
  *
@@ -19,4 +19,5 @@ export declare class CustomElement implements CustomElementJson {
19
19
  static fromJsonWithImagePathOrImage(ceJson: CustomElementJson): Promise<CustomElement>;
20
20
  static fromJson(ceJson: CustomElementJson): CustomElement;
21
21
  validate(): void;
22
+ asString(): string;
22
23
  }
@@ -43,6 +43,9 @@ export class CustomElement {
43
43
  throw new ValidationError(e.errors.join(', '));
44
44
  }
45
45
  }
46
+ asString() {
47
+ return `name:${this.name}-customImage:${this.customImage}-threshold:${this.threshold}-stopThreshold:${this.stopThreshold}-rotationDegreePerStep:${this.rotationDegreePerStep}-imageCompareFormat:${this.imageCompareFormat}-mask:${this.mask}`;
48
+ }
46
49
  }
47
50
  CustomElement.schema = object({
48
51
  mask: array().optional().min(3, 'mask must contain at least 3 points'),
@@ -4,12 +4,12 @@ import { ExecutionRuntime } from '../../../execution/execution-runtime';
4
4
  export declare class AskUIAgent extends ClaudeAgent {
5
5
  private osAgentHandler;
6
6
  private executionRuntime;
7
+ private runtime;
7
8
  constructor(executionRuntime: ExecutionRuntime);
8
9
  isConnected(): boolean;
9
10
  initializeOsAgentHandler(): Promise<void>;
10
11
  getOsAgentHandler(): OsAgentHandler;
11
- configureAsDesktopAgent(): Promise<void>;
12
- configureAsAndroidAgent(): Promise<void>;
12
+ configureAgent(): Promise<void>;
13
13
  private static DesktopSystemPrompt;
14
14
  private static AndroidSystemPrompt;
15
15
  }
@@ -7,12 +7,13 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
7
7
  step((generator = generator.apply(thisArg, _arguments || [])).next());
8
8
  });
9
9
  };
10
- import { DesktopPressAndReleaseKeysTool, MouseClickTool, MouseMoveTool, MouseScrollTool, OsAgentHandler, ScreenShotTool, TypeTool, AgentErrorTool, AndroidSequenceKeyPressTool, AndroidSingleKeyPressTool, ExecuteShellCommandTool, DesktopKeyHoldDownTool, DesktopKeyReleaseTool, MouseReleaseLeftButtonTool, MouseHoldLeftButtonDownTool, MouseDragAndDropTool, WaitTool, PrintTool, } from './tools/os-agent-tools';
10
+ import { DesktopPressAndReleaseKeysTool, MouseClickTool, MouseMoveTool, MouseScrollTool, OsAgentHandler, ScreenShotTool, TypeTool, AgentErrorTool, AndroidSequenceKeyPressTool, AndroidSingleKeyPressTool, ExecuteShellCommandTool, DesktopKeyHoldDownTool, DesktopKeyReleaseTool, MouseReleaseLeftButtonTool, MouseHoldLeftButtonDownTool, MouseDragAndDropTool, WaitTool, PrintTool, AndroidSwipeTool, AndroidDragAndDropTool, AndroidTapTool, AndroidShellCommandTool, } from './tools/os-agent-tools';
11
11
  import { ClaudeAgent } from './claude-agent';
12
12
  export class AskUIAgent extends ClaudeAgent {
13
13
  constructor(executionRuntime) {
14
14
  super((params) => executionRuntime.predictActResponse(params));
15
15
  this.osAgentHandler = undefined;
16
+ this.runtime = 'desktop';
16
17
  this.executionRuntime = executionRuntime;
17
18
  }
18
19
  isConnected() {
@@ -21,6 +22,7 @@ export class AskUIAgent extends ClaudeAgent {
21
22
  initializeOsAgentHandler() {
22
23
  return __awaiter(this, void 0, void 0, function* () {
23
24
  this.osAgentHandler = yield OsAgentHandler.createInstance(this.executionRuntime);
25
+ this.runtime = this.osAgentHandler.runtime;
24
26
  });
25
27
  }
26
28
  getOsAgentHandler() {
@@ -29,50 +31,48 @@ export class AskUIAgent extends ClaudeAgent {
29
31
  }
30
32
  return this.osAgentHandler;
31
33
  }
32
- configureAsDesktopAgent() {
34
+ configureAgent() {
33
35
  return __awaiter(this, void 0, void 0, function* () {
34
36
  if (!this.osAgentHandler) {
35
37
  throw new Error('Agent OS client is not connected');
36
38
  }
37
- const tools = [
39
+ let systemPrompt = AskUIAgent.DesktopSystemPrompt;
40
+ let tools = [
38
41
  new AgentErrorTool(),
39
42
  new PrintTool(),
40
- new ScreenShotTool(this.osAgentHandler),
41
- new MouseMoveTool(this.osAgentHandler),
42
- new MouseClickTool(this.osAgentHandler),
43
- new MouseScrollTool(this.osAgentHandler),
44
- new TypeTool(this.osAgentHandler),
45
- new DesktopPressAndReleaseKeysTool(this.osAgentHandler),
46
- new DesktopKeyHoldDownTool(this.osAgentHandler),
47
- new DesktopKeyReleaseTool(this.osAgentHandler),
48
- new MouseHoldLeftButtonDownTool(this.osAgentHandler),
49
- new MouseReleaseLeftButtonTool(this.osAgentHandler),
50
- new MouseDragAndDropTool(this.osAgentHandler),
51
43
  new WaitTool(),
52
- ];
53
- this.setTools(tools);
54
- this.setSystemPrompt(AskUIAgent.DesktopSystemPrompt);
55
- });
56
- }
57
- configureAsAndroidAgent() {
58
- return __awaiter(this, void 0, void 0, function* () {
59
- if (!this.osAgentHandler) {
60
- throw new Error('Agent OS client is not connected');
61
- }
62
- const tools = [
63
- new AgentErrorTool(),
64
44
  new ScreenShotTool(this.osAgentHandler),
65
- new MouseMoveTool(this.osAgentHandler),
66
- new MouseClickTool(this.osAgentHandler),
67
- new MouseScrollTool(this.osAgentHandler),
68
- new AndroidSingleKeyPressTool(this.osAgentHandler),
69
- new AndroidSequenceKeyPressTool(this.osAgentHandler),
70
45
  new TypeTool(this.osAgentHandler),
71
- new ExecuteShellCommandTool(this.osAgentHandler),
72
- new WaitTool(),
73
46
  ];
47
+ if (this.runtime === 'desktop') {
48
+ tools = [
49
+ ...tools,
50
+ new MouseMoveTool(this.osAgentHandler),
51
+ new MouseClickTool(this.osAgentHandler),
52
+ new MouseScrollTool(this.osAgentHandler),
53
+ new DesktopPressAndReleaseKeysTool(this.osAgentHandler),
54
+ new DesktopKeyHoldDownTool(this.osAgentHandler),
55
+ new DesktopKeyReleaseTool(this.osAgentHandler),
56
+ new MouseHoldLeftButtonDownTool(this.osAgentHandler),
57
+ new MouseReleaseLeftButtonTool(this.osAgentHandler),
58
+ new MouseDragAndDropTool(this.osAgentHandler),
59
+ new ExecuteShellCommandTool(this.osAgentHandler),
60
+ ];
61
+ }
62
+ if (this.runtime === 'android') {
63
+ tools = [
64
+ ...tools,
65
+ new AndroidSingleKeyPressTool(this.osAgentHandler),
66
+ new AndroidSequenceKeyPressTool(this.osAgentHandler),
67
+ new AndroidSwipeTool(this.osAgentHandler),
68
+ new AndroidDragAndDropTool(this.osAgentHandler),
69
+ new AndroidTapTool(this.osAgentHandler),
70
+ new AndroidShellCommandTool(this.osAgentHandler),
71
+ ];
72
+ systemPrompt = AskUIAgent.AndroidSystemPrompt;
73
+ }
74
74
  this.setTools(tools);
75
- this.setSystemPrompt(AskUIAgent.AndroidSystemPrompt);
75
+ this.setSystemPrompt(systemPrompt);
76
76
  });
77
77
  }
78
78
  }
@@ -5,13 +5,14 @@ import { ExecutionRuntime } from '../../../../execution/execution-runtime';
5
5
  import { ControlCommand } from '../../../ui-control-commands';
6
6
  export declare class OsAgentHandler {
7
7
  private AgentOsClient;
8
- private targetResolution;
9
8
  private screenDimensions;
9
+ runtime: 'android' | 'desktop';
10
+ private targetResolution;
10
11
  private paddingInfo;
11
12
  constructor(AgentOsClient: ExecutionRuntime, screenDimensions: {
12
13
  width: number;
13
14
  height: number;
14
- });
15
+ }, runtime: 'android' | 'desktop');
15
16
  private updatePaddingInfo;
16
17
  static createInstance(AgentOsClient: ExecutionRuntime): Promise<OsAgentHandler>;
17
18
  getTargetResolution(): {
@@ -27,7 +28,7 @@ export declare class OsAgentHandler {
27
28
  scaleCoordinates(source: 'api' | 'computer', x: number, y: number): [number, number];
28
29
  requestControl(controlCommand: ControlCommand): Promise<void>;
29
30
  mouseMove(x: number, y: number): Promise<void>;
30
- mouseClick(button: "left" | "right" | "middle", doubleClick: boolean): Promise<void>;
31
+ mouseClick(button: 'left' | 'right' | 'middle', doubleClick: boolean): Promise<void>;
31
32
  mouseScroll(dx: number, dy: number): Promise<void>;
32
33
  mouseHoldLeftButtonDown(): Promise<void>;
33
34
  mouseReleaseLeftButton(): Promise<void>;
@@ -38,6 +39,10 @@ export declare class OsAgentHandler {
38
39
  androidKeyPress(key: ANDROID_KEY): Promise<void>;
39
40
  androidKeySequencePress(keys: ANDROID_KEY[]): Promise<void>;
40
41
  executeShellCommand(command: string): Promise<void>;
42
+ AndroidSwipeTool(startX: number, startY: number, endX: number, endY: number): Promise<void>;
43
+ AndroidDragAndDropTool(startX: number, startY: number, endX: number, endY: number): Promise<void>;
44
+ AndroidTapTool(x: number, y: number): Promise<void>;
45
+ executeAndroidShellCommand(command: string): Promise<void>;
41
46
  }
42
47
  export declare class ScreenShotTool extends BaseAgentTool {
43
48
  private osAgentHandler;
@@ -175,3 +180,42 @@ export declare class PrintTool extends BaseAgentTool {
175
180
  }): Promise<ToolResult>;
176
181
  toParams(): BetaTool;
177
182
  }
183
+ export declare class AndroidSwipeTool extends BaseAgentTool {
184
+ private osAgentHandler;
185
+ constructor(osAgentHandler: OsAgentHandler);
186
+ execute(command: {
187
+ startX: number;
188
+ startY: number;
189
+ endX: number;
190
+ endY: number;
191
+ }): Promise<ToolResult>;
192
+ toParams(): BetaTool;
193
+ }
194
+ export declare class AndroidDragAndDropTool extends BaseAgentTool {
195
+ private osAgentHandler;
196
+ constructor(osAgentHandler: OsAgentHandler);
197
+ execute(command: {
198
+ startX: number;
199
+ startY: number;
200
+ endX: number;
201
+ endY: number;
202
+ }): Promise<ToolResult>;
203
+ toParams(): BetaTool;
204
+ }
205
+ export declare class AndroidTapTool extends BaseAgentTool {
206
+ private osAgentHandler;
207
+ constructor(osAgentHandler: OsAgentHandler);
208
+ execute(command: {
209
+ x: number;
210
+ y: number;
211
+ }): Promise<ToolResult>;
212
+ toParams(): BetaTool;
213
+ }
214
+ export declare class AndroidShellCommandTool extends BaseAgentTool {
215
+ private osAgentHandler;
216
+ constructor(osAgentHandler: OsAgentHandler);
217
+ execute(command: {
218
+ command: string;
219
+ }): Promise<ToolResult>;
220
+ toParams(): BetaTool;
221
+ }