@ui-tars-test/shared 0.3.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.
- package/dist/base/agent.d.ts +9 -0
- package/dist/base/agent.d.ts.map +1 -0
- package/dist/base/agent.js +54 -0
- package/dist/base/agent.js.map +1 -0
- package/dist/base/agent.mjs +10 -0
- package/dist/base/agent.mjs.map +1 -0
- package/dist/base/index.d.ts +4 -0
- package/dist/base/index.d.ts.map +1 -0
- package/dist/base/index.js +84 -0
- package/dist/base/index.js.map +1 -0
- package/dist/base/index.mjs +7 -0
- package/dist/base/operator.d.ts +140 -0
- package/dist/base/operator.d.ts.map +1 -0
- package/dist/base/operator.js +112 -0
- package/dist/base/operator.js.map +1 -0
- package/dist/base/operator.mjs +75 -0
- package/dist/base/operator.mjs.map +1 -0
- package/dist/base/parser.d.ts +11 -0
- package/dist/base/parser.d.ts.map +1 -0
- package/dist/base/parser.js +43 -0
- package/dist/base/parser.js.map +1 -0
- package/dist/base/parser.mjs +9 -0
- package/dist/base/parser.mjs.map +1 -0
- package/dist/types/actions.d.ts +224 -0
- package/dist/types/actions.d.ts.map +1 -0
- package/dist/types/actions.js +155 -0
- package/dist/types/actions.js.map +1 -0
- package/dist/types/actions.mjs +115 -0
- package/dist/types/actions.mjs.map +1 -0
- package/dist/types/agents.d.ts +108 -0
- package/dist/types/agents.d.ts.map +1 -0
- package/dist/types/agents.js +42 -0
- package/dist/types/agents.js.map +1 -0
- package/dist/types/agents.mjs +8 -0
- package/dist/types/agents.mjs.map +1 -0
- package/dist/types/archived.d.ts +44 -0
- package/dist/types/archived.d.ts.map +1 -0
- package/dist/types/archived.js +86 -0
- package/dist/types/archived.js.map +1 -0
- package/dist/types/archived.mjs +46 -0
- package/dist/types/archived.mjs.map +1 -0
- package/dist/types/index.d.ts +4 -0
- package/dist/types/index.d.ts.map +1 -0
- package/dist/types/index.js +84 -0
- package/dist/types/index.js.map +1 -0
- package/dist/types/index.mjs +7 -0
- package/dist/utils/actions.d.ts +15 -0
- package/dist/utils/actions.d.ts.map +1 -0
- package/dist/utils/actions.js +196 -0
- package/dist/utils/actions.js.map +1 -0
- package/dist/utils/actions.mjs +156 -0
- package/dist/utils/actions.mjs.map +1 -0
- package/dist/utils/coordinateNormalizer.d.ts +10 -0
- package/dist/utils/coordinateNormalizer.d.ts.map +1 -0
- package/dist/utils/coordinateNormalizer.js +59 -0
- package/dist/utils/coordinateNormalizer.js.map +1 -0
- package/dist/utils/coordinateNormalizer.mjs +25 -0
- package/dist/utils/coordinateNormalizer.mjs.map +1 -0
- package/dist/utils/index.d.ts +5 -0
- package/dist/utils/index.d.ts.map +1 -0
- package/dist/utils/index.js +93 -0
- package/dist/utils/index.js.map +1 -0
- package/dist/utils/index.mjs +8 -0
- package/dist/utils/sleep.d.ts +14 -0
- package/dist/utils/sleep.d.ts.map +1 -0
- package/dist/utils/sleep.js +45 -0
- package/dist/utils/sleep.js.map +1 -0
- package/dist/utils/sleep.mjs +11 -0
- package/dist/utils/sleep.mjs.map +1 -0
- package/dist/utils/systemPromptProcessor.d.ts +16 -0
- package/dist/utils/systemPromptProcessor.d.ts.map +1 -0
- package/dist/utils/systemPromptProcessor.js +61 -0
- package/dist/utils/systemPromptProcessor.js.map +1 -0
- package/dist/utils/systemPromptProcessor.mjs +24 -0
- package/dist/utils/systemPromptProcessor.mjs.map +1 -0
- package/package.json +66 -0
- package/src/base/agent.ts +13 -0
- package/src/base/index.ts +7 -0
- package/src/base/operator.ts +221 -0
- package/src/base/parser.ts +16 -0
- package/src/types/actions.ts +382 -0
- package/src/types/agents.ts +128 -0
- package/src/types/archived.ts +55 -0
- package/src/types/index.ts +8 -0
- package/src/utils/actions.ts +244 -0
- package/src/utils/coordinateNormalizer.ts +49 -0
- package/src/utils/index.ts +9 -0
- package/src/utils/sleep.ts +21 -0
- package/src/utils/systemPromptProcessor.ts +48 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"agent.d.ts","sourceRoot":"","sources":["../../src/base/agent.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,MAAM,cAAc,CAAC;AAEjC;;;;GAIG;AACH,8BAAsB,YAAa,SAAQ,KAAK;CAAG"}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) 2025 Bytedance, Inc. and its affiliates.
|
|
3
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
4
|
+
*/
|
|
5
|
+
"use strict";
|
|
6
|
+
var __webpack_require__ = {};
|
|
7
|
+
(()=>{
|
|
8
|
+
__webpack_require__.n = (module)=>{
|
|
9
|
+
var getter = module && module.__esModule ? ()=>module['default'] : ()=>module;
|
|
10
|
+
__webpack_require__.d(getter, {
|
|
11
|
+
a: getter
|
|
12
|
+
});
|
|
13
|
+
return getter;
|
|
14
|
+
};
|
|
15
|
+
})();
|
|
16
|
+
(()=>{
|
|
17
|
+
__webpack_require__.d = (exports1, definition)=>{
|
|
18
|
+
for(var key in definition)if (__webpack_require__.o(definition, key) && !__webpack_require__.o(exports1, key)) Object.defineProperty(exports1, key, {
|
|
19
|
+
enumerable: true,
|
|
20
|
+
get: definition[key]
|
|
21
|
+
});
|
|
22
|
+
};
|
|
23
|
+
})();
|
|
24
|
+
(()=>{
|
|
25
|
+
__webpack_require__.o = (obj, prop)=>Object.prototype.hasOwnProperty.call(obj, prop);
|
|
26
|
+
})();
|
|
27
|
+
(()=>{
|
|
28
|
+
__webpack_require__.r = (exports1)=>{
|
|
29
|
+
if ('undefined' != typeof Symbol && Symbol.toStringTag) Object.defineProperty(exports1, Symbol.toStringTag, {
|
|
30
|
+
value: 'Module'
|
|
31
|
+
});
|
|
32
|
+
Object.defineProperty(exports1, '__esModule', {
|
|
33
|
+
value: true
|
|
34
|
+
});
|
|
35
|
+
};
|
|
36
|
+
})();
|
|
37
|
+
var __webpack_exports__ = {};
|
|
38
|
+
__webpack_require__.r(__webpack_exports__);
|
|
39
|
+
__webpack_require__.d(__webpack_exports__, {
|
|
40
|
+
BaseGUIAgent: ()=>BaseGUIAgent
|
|
41
|
+
});
|
|
42
|
+
const agent_namespaceObject = require("@tarko/agent");
|
|
43
|
+
var agent_default = /*#__PURE__*/ __webpack_require__.n(agent_namespaceObject);
|
|
44
|
+
class BaseGUIAgent extends agent_default() {
|
|
45
|
+
}
|
|
46
|
+
exports.BaseGUIAgent = __webpack_exports__.BaseGUIAgent;
|
|
47
|
+
for(var __webpack_i__ in __webpack_exports__)if (-1 === [
|
|
48
|
+
"BaseGUIAgent"
|
|
49
|
+
].indexOf(__webpack_i__)) exports[__webpack_i__] = __webpack_exports__[__webpack_i__];
|
|
50
|
+
Object.defineProperty(exports, '__esModule', {
|
|
51
|
+
value: true
|
|
52
|
+
});
|
|
53
|
+
|
|
54
|
+
//# sourceMappingURL=agent.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"base/agent.js","sources":["webpack://@ui-tars-test/shared/webpack/runtime/compat_get_default_export","webpack://@ui-tars-test/shared/webpack/runtime/define_property_getters","webpack://@ui-tars-test/shared/webpack/runtime/has_own_property","webpack://@ui-tars-test/shared/webpack/runtime/make_namespace_object","webpack://@ui-tars-test/shared/./src/base/agent.ts"],"sourcesContent":["// getDefaultExport function for compatibility with non-ESM modules\n__webpack_require__.n = (module) => {\n\tvar getter = module && module.__esModule ?\n\t\t() => (module['default']) :\n\t\t() => (module);\n\t__webpack_require__.d(getter, { a: getter });\n\treturn getter;\n};\n","__webpack_require__.d = (exports, definition) => {\n\tfor(var key in definition) {\n if(__webpack_require__.o(definition, key) && !__webpack_require__.o(exports, key)) {\n Object.defineProperty(exports, key, { enumerable: true, get: definition[key] });\n }\n }\n};","__webpack_require__.o = (obj, prop) => (Object.prototype.hasOwnProperty.call(obj, prop))","// define __esModule on exports\n__webpack_require__.r = (exports) => {\n\tif(typeof Symbol !== 'undefined' && Symbol.toStringTag) {\n\t\tObject.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });\n\t}\n\tObject.defineProperty(exports, '__esModule', { value: true });\n};","/*\n * Copyright (c) 2025 Bytedance, Inc. and its affiliates.\n * SPDX-License-Identifier: Apache-2.0\n */\n\nimport Agent from '@tarko/agent';\n\n/**\n * @abstract\n * @class BaseGUIAgent\n * @classdesc Abstract base class for GUI Agents.\n */\nexport abstract class BaseGUIAgent extends Agent {}\n"],"names":["__webpack_require__","module","getter","definition","key","Object","obj","prop","Symbol","BaseGUIAgent","Agent"],"mappings":";;;;;;;IACAA,oBAAoB,CAAC,GAAG,CAACC;QACxB,IAAIC,SAASD,UAAUA,OAAO,UAAU,GACvC,IAAOA,MAAM,CAAC,UAAU,GACxB,IAAOA;QACRD,oBAAoB,CAAC,CAACE,QAAQ;YAAE,GAAGA;QAAO;QAC1C,OAAOA;IACR;;;ICPAF,oBAAoB,CAAC,GAAG,CAAC,UAASG;QACjC,IAAI,IAAIC,OAAOD,WACR,IAAGH,oBAAoB,CAAC,CAACG,YAAYC,QAAQ,CAACJ,oBAAoB,CAAC,CAAC,UAASI,MACzEC,OAAO,cAAc,CAAC,UAASD,KAAK;YAAE,YAAY;YAAM,KAAKD,UAAU,CAACC,IAAI;QAAC;IAGzF;;;ICNAJ,oBAAoB,CAAC,GAAG,CAACM,KAAKC,OAAUF,OAAO,SAAS,CAAC,cAAc,CAAC,IAAI,CAACC,KAAKC;;;ICClFP,oBAAoB,CAAC,GAAG,CAAC;QACxB,IAAG,AAAkB,eAAlB,OAAOQ,UAA0BA,OAAO,WAAW,EACrDH,OAAO,cAAc,CAAC,UAASG,OAAO,WAAW,EAAE;YAAE,OAAO;QAAS;QAEtEH,OAAO,cAAc,CAAC,UAAS,cAAc;YAAE,OAAO;QAAK;IAC5D;;;;;;;;;ACMO,MAAeI,qBAAqBC;AAAO"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"base/agent.mjs","sources":["webpack://@ui-tars-test/shared/./src/base/agent.ts"],"sourcesContent":["/*\n * Copyright (c) 2025 Bytedance, Inc. and its affiliates.\n * SPDX-License-Identifier: Apache-2.0\n */\n\nimport Agent from '@tarko/agent';\n\n/**\n * @abstract\n * @class BaseGUIAgent\n * @classdesc Abstract base class for GUI Agents.\n */\nexport abstract class BaseGUIAgent extends Agent {}\n"],"names":["BaseGUIAgent","Agent"],"mappings":";;;;;AAYO,MAAeA,qBAAqBC;AAAO"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/base/index.ts"],"names":[],"mappings":"AAIA,cAAc,SAAS,CAAC;AACxB,cAAc,UAAU,CAAC;AACzB,cAAc,YAAY,CAAC"}
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) 2025 Bytedance, Inc. and its affiliates.
|
|
3
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
4
|
+
*/
|
|
5
|
+
"use strict";
|
|
6
|
+
var __webpack_modules__ = {
|
|
7
|
+
"./agent": function(module) {
|
|
8
|
+
module.exports = require("./agent.js");
|
|
9
|
+
},
|
|
10
|
+
"./operator": function(module) {
|
|
11
|
+
module.exports = require("./operator.js");
|
|
12
|
+
},
|
|
13
|
+
"./parser": function(module) {
|
|
14
|
+
module.exports = require("./parser.js");
|
|
15
|
+
}
|
|
16
|
+
};
|
|
17
|
+
var __webpack_module_cache__ = {};
|
|
18
|
+
function __webpack_require__(moduleId) {
|
|
19
|
+
var cachedModule = __webpack_module_cache__[moduleId];
|
|
20
|
+
if (void 0 !== cachedModule) return cachedModule.exports;
|
|
21
|
+
var module = __webpack_module_cache__[moduleId] = {
|
|
22
|
+
exports: {}
|
|
23
|
+
};
|
|
24
|
+
__webpack_modules__[moduleId](module, module.exports, __webpack_require__);
|
|
25
|
+
return module.exports;
|
|
26
|
+
}
|
|
27
|
+
(()=>{
|
|
28
|
+
__webpack_require__.n = (module)=>{
|
|
29
|
+
var getter = module && module.__esModule ? ()=>module['default'] : ()=>module;
|
|
30
|
+
__webpack_require__.d(getter, {
|
|
31
|
+
a: getter
|
|
32
|
+
});
|
|
33
|
+
return getter;
|
|
34
|
+
};
|
|
35
|
+
})();
|
|
36
|
+
(()=>{
|
|
37
|
+
__webpack_require__.d = (exports1, definition)=>{
|
|
38
|
+
for(var key in definition)if (__webpack_require__.o(definition, key) && !__webpack_require__.o(exports1, key)) Object.defineProperty(exports1, key, {
|
|
39
|
+
enumerable: true,
|
|
40
|
+
get: definition[key]
|
|
41
|
+
});
|
|
42
|
+
};
|
|
43
|
+
})();
|
|
44
|
+
(()=>{
|
|
45
|
+
__webpack_require__.o = (obj, prop)=>Object.prototype.hasOwnProperty.call(obj, prop);
|
|
46
|
+
})();
|
|
47
|
+
(()=>{
|
|
48
|
+
__webpack_require__.r = (exports1)=>{
|
|
49
|
+
if ('undefined' != typeof Symbol && Symbol.toStringTag) Object.defineProperty(exports1, Symbol.toStringTag, {
|
|
50
|
+
value: 'Module'
|
|
51
|
+
});
|
|
52
|
+
Object.defineProperty(exports1, '__esModule', {
|
|
53
|
+
value: true
|
|
54
|
+
});
|
|
55
|
+
};
|
|
56
|
+
})();
|
|
57
|
+
var __webpack_exports__ = {};
|
|
58
|
+
(()=>{
|
|
59
|
+
__webpack_require__.r(__webpack_exports__);
|
|
60
|
+
var _agent__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__("./agent");
|
|
61
|
+
var __WEBPACK_REEXPORT_OBJECT__ = {};
|
|
62
|
+
for(var __WEBPACK_IMPORT_KEY__ in _agent__WEBPACK_IMPORTED_MODULE_0__)if ("default" !== __WEBPACK_IMPORT_KEY__) __WEBPACK_REEXPORT_OBJECT__[__WEBPACK_IMPORT_KEY__] = (function(key) {
|
|
63
|
+
return _agent__WEBPACK_IMPORTED_MODULE_0__[key];
|
|
64
|
+
}).bind(0, __WEBPACK_IMPORT_KEY__);
|
|
65
|
+
__webpack_require__.d(__webpack_exports__, __WEBPACK_REEXPORT_OBJECT__);
|
|
66
|
+
var _parser__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__("./parser");
|
|
67
|
+
var __WEBPACK_REEXPORT_OBJECT__ = {};
|
|
68
|
+
for(var __WEBPACK_IMPORT_KEY__ in _parser__WEBPACK_IMPORTED_MODULE_1__)if ("default" !== __WEBPACK_IMPORT_KEY__) __WEBPACK_REEXPORT_OBJECT__[__WEBPACK_IMPORT_KEY__] = (function(key) {
|
|
69
|
+
return _parser__WEBPACK_IMPORTED_MODULE_1__[key];
|
|
70
|
+
}).bind(0, __WEBPACK_IMPORT_KEY__);
|
|
71
|
+
__webpack_require__.d(__webpack_exports__, __WEBPACK_REEXPORT_OBJECT__);
|
|
72
|
+
var _operator__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__("./operator");
|
|
73
|
+
var __WEBPACK_REEXPORT_OBJECT__ = {};
|
|
74
|
+
for(var __WEBPACK_IMPORT_KEY__ in _operator__WEBPACK_IMPORTED_MODULE_2__)if ("default" !== __WEBPACK_IMPORT_KEY__) __WEBPACK_REEXPORT_OBJECT__[__WEBPACK_IMPORT_KEY__] = (function(key) {
|
|
75
|
+
return _operator__WEBPACK_IMPORTED_MODULE_2__[key];
|
|
76
|
+
}).bind(0, __WEBPACK_IMPORT_KEY__);
|
|
77
|
+
__webpack_require__.d(__webpack_exports__, __WEBPACK_REEXPORT_OBJECT__);
|
|
78
|
+
})();
|
|
79
|
+
for(var __webpack_i__ in __webpack_exports__)exports[__webpack_i__] = __webpack_exports__[__webpack_i__];
|
|
80
|
+
Object.defineProperty(exports, '__esModule', {
|
|
81
|
+
value: true
|
|
82
|
+
});
|
|
83
|
+
|
|
84
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"base/index.js","sources":["webpack://@ui-tars-test/shared/webpack/runtime/compat_get_default_export","webpack://@ui-tars-test/shared/webpack/runtime/define_property_getters","webpack://@ui-tars-test/shared/webpack/runtime/has_own_property","webpack://@ui-tars-test/shared/webpack/runtime/make_namespace_object"],"sourcesContent":["// getDefaultExport function for compatibility with non-ESM modules\n__webpack_require__.n = (module) => {\n\tvar getter = module && module.__esModule ?\n\t\t() => (module['default']) :\n\t\t() => (module);\n\t__webpack_require__.d(getter, { a: getter });\n\treturn getter;\n};\n","__webpack_require__.d = (exports, definition) => {\n\tfor(var key in definition) {\n if(__webpack_require__.o(definition, key) && !__webpack_require__.o(exports, key)) {\n Object.defineProperty(exports, key, { enumerable: true, get: definition[key] });\n }\n }\n};","__webpack_require__.o = (obj, prop) => (Object.prototype.hasOwnProperty.call(obj, prop))","// define __esModule on exports\n__webpack_require__.r = (exports) => {\n\tif(typeof Symbol !== 'undefined' && Symbol.toStringTag) {\n\t\tObject.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });\n\t}\n\tObject.defineProperty(exports, '__esModule', { value: true });\n};"],"names":["__webpack_require__","module","getter","definition","key","Object","obj","prop","Symbol"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;IACAA,oBAAoB,CAAC,GAAG,CAACC;QACxB,IAAIC,SAASD,UAAUA,OAAO,UAAU,GACvC,IAAOA,MAAM,CAAC,UAAU,GACxB,IAAOA;QACRD,oBAAoB,CAAC,CAACE,QAAQ;YAAE,GAAGA;QAAO;QAC1C,OAAOA;IACR;;;ICPAF,oBAAoB,CAAC,GAAG,CAAC,UAASG;QACjC,IAAI,IAAIC,OAAOD,WACR,IAAGH,oBAAoB,CAAC,CAACG,YAAYC,QAAQ,CAACJ,oBAAoB,CAAC,CAAC,UAASI,MACzEC,OAAO,cAAc,CAAC,UAASD,KAAK;YAAE,YAAY;YAAM,KAAKD,UAAU,CAACC,IAAI;QAAC;IAGzF;;;ICNAJ,oBAAoB,CAAC,GAAG,CAACM,KAAKC,OAAUF,OAAO,SAAS,CAAC,cAAc,CAAC,IAAI,CAACC,KAAKC;;;ICClFP,oBAAoB,CAAC,GAAG,CAAC;QACxB,IAAG,AAAkB,eAAlB,OAAOQ,UAA0BA,OAAO,WAAW,EACrDH,OAAO,cAAc,CAAC,UAASG,OAAO,WAAW,EAAE;YAAE,OAAO;QAAS;QAEtEH,OAAO,cAAc,CAAC,UAAS,cAAc;YAAE,OAAO;QAAK;IAC5D"}
|
|
@@ -0,0 +1,140 @@
|
|
|
1
|
+
import { ExecuteParams, ScreenshotOutput, ExecuteOutput, SupportedActionType } from '../types';
|
|
2
|
+
export interface ScreenContext {
|
|
3
|
+
screenWidth: number;
|
|
4
|
+
screenHeight: number;
|
|
5
|
+
scaleX: number;
|
|
6
|
+
scaleY: number;
|
|
7
|
+
}
|
|
8
|
+
/**
|
|
9
|
+
* @abstract
|
|
10
|
+
* @class BaseOperator
|
|
11
|
+
* @classdesc Abstract base class for Operators.
|
|
12
|
+
*/
|
|
13
|
+
export declare abstract class BaseOperator {
|
|
14
|
+
abstract doScreenshot(params?: unknown): Promise<unknown>;
|
|
15
|
+
abstract doExecute(params: unknown): Promise<unknown>;
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* @abstract
|
|
19
|
+
* @class Operator
|
|
20
|
+
* @classdesc Abstract base class for Operators.
|
|
21
|
+
*
|
|
22
|
+
* @example
|
|
23
|
+
* // Example of defining ACTION_SPACES for a custom Operator
|
|
24
|
+
* import type { GUIAction, ClickAction, DoubleClickAction, TypeAction, ScreenShotAction, SupportedActionType } from '../types/actions';
|
|
25
|
+
*
|
|
26
|
+
* class MyDesktopOperator extends Operator {
|
|
27
|
+
*
|
|
28
|
+
* // Implement the required abstract methods
|
|
29
|
+
* protected async initialize(): Promise<void> {
|
|
30
|
+
* // Implementation for initializing the operator
|
|
31
|
+
* // e.g., validate connections, setup resources
|
|
32
|
+
* // ...
|
|
33
|
+
* }
|
|
34
|
+
*
|
|
35
|
+
* supportedActions(): Array<SupportedActionType> {
|
|
36
|
+
* return [
|
|
37
|
+
* 'click',
|
|
38
|
+
* 'double_click',
|
|
39
|
+
* 'right_click',
|
|
40
|
+
* 'type',
|
|
41
|
+
* 'hotkey',
|
|
42
|
+
* 'scroll',
|
|
43
|
+
* 'drag',
|
|
44
|
+
* 'screenshot'
|
|
45
|
+
* ] as SupportedActionType[];
|
|
46
|
+
* }
|
|
47
|
+
*
|
|
48
|
+
* screenContext(): ScreenContext {
|
|
49
|
+
* // Implementation for getting screen context
|
|
50
|
+
* // ...
|
|
51
|
+
* return {
|
|
52
|
+
* screenWidth: 1920,
|
|
53
|
+
* screenHeight: 1080,
|
|
54
|
+
* scaleX: 1,
|
|
55
|
+
* scaleY: 1
|
|
56
|
+
* };
|
|
57
|
+
* }
|
|
58
|
+
*
|
|
59
|
+
* async screenshot(): Promise<ScreenshotOutput> {
|
|
60
|
+
* // Implementation for taking screenshots
|
|
61
|
+
* // ...
|
|
62
|
+
* return { }; // screenshot output
|
|
63
|
+
* }
|
|
64
|
+
*
|
|
65
|
+
* async execute(params: ExecuteParams): Promise<ExecuteOutput> {
|
|
66
|
+
* // Implementation for executing actions
|
|
67
|
+
* // ...
|
|
68
|
+
* return { }; // execution output
|
|
69
|
+
* }
|
|
70
|
+
* }
|
|
71
|
+
*/
|
|
72
|
+
export declare abstract class Operator extends BaseOperator {
|
|
73
|
+
private _initialized;
|
|
74
|
+
private _initializing;
|
|
75
|
+
private _initPromise;
|
|
76
|
+
constructor();
|
|
77
|
+
/**
|
|
78
|
+
* Initializes the operator
|
|
79
|
+
* @description Performs initialization operations for the operator, such as validating connections,
|
|
80
|
+
* setting up resources, and preparing the operation environment.
|
|
81
|
+
* @returns Promise that resolves when initialization is complete
|
|
82
|
+
* @throws Error if initialization fails
|
|
83
|
+
*/
|
|
84
|
+
doInitialize(): Promise<void>;
|
|
85
|
+
/**
|
|
86
|
+
* Implementation of initialization logic
|
|
87
|
+
* @description Subclasses should implement this method to perform their specific initialization
|
|
88
|
+
* @returns Promise that resolves when initialization is complete
|
|
89
|
+
* @throws Error if initialization fails
|
|
90
|
+
*/
|
|
91
|
+
protected abstract initialize(): Promise<void>;
|
|
92
|
+
/**
|
|
93
|
+
* Ensures the operator is initialized before performing operations
|
|
94
|
+
* @private
|
|
95
|
+
*/
|
|
96
|
+
private ensureInitialized;
|
|
97
|
+
/**
|
|
98
|
+
* Safely returns an array of supported action types with initialization guarantee
|
|
99
|
+
* @returns Array of action types supported by this operator
|
|
100
|
+
*/
|
|
101
|
+
getSupportedActions(): Array<SupportedActionType>;
|
|
102
|
+
/**
|
|
103
|
+
* Returns an array of supported action types
|
|
104
|
+
* @returns Array of action types supported by this operator
|
|
105
|
+
*/
|
|
106
|
+
protected abstract supportedActions(): Array<SupportedActionType>;
|
|
107
|
+
/**
|
|
108
|
+
* Safely returns the screen context with initialization guarantee
|
|
109
|
+
* @returns The screen context
|
|
110
|
+
*/
|
|
111
|
+
getScreenContext(): Promise<ScreenContext>;
|
|
112
|
+
/**
|
|
113
|
+
* Returns the screen context
|
|
114
|
+
* @returns The screen context
|
|
115
|
+
*/
|
|
116
|
+
protected abstract screenContext(): ScreenContext;
|
|
117
|
+
/**
|
|
118
|
+
* Safely takes a screenshot with initialization guarantee
|
|
119
|
+
* @returns Promise that resolves to the screenshot output
|
|
120
|
+
*/
|
|
121
|
+
doScreenshot(): Promise<ScreenshotOutput>;
|
|
122
|
+
/**
|
|
123
|
+
* Takes a screenshot
|
|
124
|
+
* @returns Promise that resolves to the screenshot output
|
|
125
|
+
*/
|
|
126
|
+
protected abstract screenshot(): Promise<ScreenshotOutput>;
|
|
127
|
+
/**
|
|
128
|
+
* Safely executes actions with initialization guarantee
|
|
129
|
+
* @param params - The parameters for the actions
|
|
130
|
+
* @returns Promise that resolves to the execution output
|
|
131
|
+
*/
|
|
132
|
+
doExecute(params: ExecuteParams): Promise<ExecuteOutput>;
|
|
133
|
+
/**
|
|
134
|
+
* Executes actions
|
|
135
|
+
* @param params - The parameters for the actions
|
|
136
|
+
* @returns Promise that resolves to the execution output
|
|
137
|
+
*/
|
|
138
|
+
protected abstract execute(params: ExecuteParams): Promise<ExecuteOutput>;
|
|
139
|
+
}
|
|
140
|
+
//# sourceMappingURL=operator.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"operator.d.ts","sourceRoot":"","sources":["../../src/base/operator.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,aAAa,EAAE,gBAAgB,EAAE,aAAa,EAAE,mBAAmB,EAAE,MAAM,UAAU,CAAC;AAE/F,MAAM,WAAW,aAAa;IAC5B,WAAW,EAAE,MAAM,CAAC;IACpB,YAAY,EAAE,MAAM,CAAC;IACrB,MAAM,EAAE,MAAM,CAAC;IACf,MAAM,EAAE,MAAM,CAAC;CAChB;AAED;;;;GAIG;AACH,8BAAsB,YAAY;IAChC,QAAQ,CAAC,YAAY,CAAC,MAAM,CAAC,EAAE,OAAO,GAAG,OAAO,CAAC,OAAO,CAAC;IACzD,QAAQ,CAAC,SAAS,CAAC,MAAM,EAAE,OAAO,GAAG,OAAO,CAAC,OAAO,CAAC;CACtD;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAsDG;AACH,8BAAsB,QAAS,SAAQ,YAAY;IAEjD,OAAO,CAAC,YAAY,CAAS;IAC7B,OAAO,CAAC,aAAa,CAAS;IAC9B,OAAO,CAAC,YAAY,CAA8B;;IAOlD;;;;;;OAMG;IACG,YAAY,IAAI,OAAO,CAAC,IAAI,CAAC;IAyBnC;;;;;OAKG;IACH,SAAS,CAAC,QAAQ,CAAC,UAAU,IAAI,OAAO,CAAC,IAAI,CAAC;IAE9C;;;OAGG;YACW,iBAAiB;IAQ/B;;;OAGG;IACH,mBAAmB,IAAI,KAAK,CAAC,mBAAmB,CAAC;IAKjD;;;OAGG;IACH,SAAS,CAAC,QAAQ,CAAC,gBAAgB,IAAI,KAAK,CAAC,mBAAmB,CAAC;IAEjE;;;OAGG;IACG,gBAAgB,IAAI,OAAO,CAAC,aAAa,CAAC;IAKhD;;;OAGG;IACH,SAAS,CAAC,QAAQ,CAAC,aAAa,IAAI,aAAa;IAEjD;;;OAGG;IACG,YAAY,IAAI,OAAO,CAAC,gBAAgB,CAAC;IAc/C;;;OAGG;IACH,SAAS,CAAC,QAAQ,CAAC,UAAU,IAAI,OAAO,CAAC,gBAAgB,CAAC;IAE1D;;;;OAIG;IACG,SAAS,CAAC,MAAM,EAAE,aAAa,GAAG,OAAO,CAAC,aAAa,CAAC;IAa9D;;;;OAIG;IACH,SAAS,CAAC,QAAQ,CAAC,OAAO,CAAC,MAAM,EAAE,aAAa,GAAG,OAAO,CAAC,aAAa,CAAC;CAC1E"}
|
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) 2025 Bytedance, Inc. and its affiliates.
|
|
3
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
4
|
+
*/
|
|
5
|
+
"use strict";
|
|
6
|
+
var __webpack_require__ = {};
|
|
7
|
+
(()=>{
|
|
8
|
+
__webpack_require__.d = (exports1, definition)=>{
|
|
9
|
+
for(var key in definition)if (__webpack_require__.o(definition, key) && !__webpack_require__.o(exports1, key)) Object.defineProperty(exports1, key, {
|
|
10
|
+
enumerable: true,
|
|
11
|
+
get: definition[key]
|
|
12
|
+
});
|
|
13
|
+
};
|
|
14
|
+
})();
|
|
15
|
+
(()=>{
|
|
16
|
+
__webpack_require__.o = (obj, prop)=>Object.prototype.hasOwnProperty.call(obj, prop);
|
|
17
|
+
})();
|
|
18
|
+
(()=>{
|
|
19
|
+
__webpack_require__.r = (exports1)=>{
|
|
20
|
+
if ('undefined' != typeof Symbol && Symbol.toStringTag) Object.defineProperty(exports1, Symbol.toStringTag, {
|
|
21
|
+
value: 'Module'
|
|
22
|
+
});
|
|
23
|
+
Object.defineProperty(exports1, '__esModule', {
|
|
24
|
+
value: true
|
|
25
|
+
});
|
|
26
|
+
};
|
|
27
|
+
})();
|
|
28
|
+
var __webpack_exports__ = {};
|
|
29
|
+
__webpack_require__.r(__webpack_exports__);
|
|
30
|
+
__webpack_require__.d(__webpack_exports__, {
|
|
31
|
+
BaseOperator: ()=>BaseOperator,
|
|
32
|
+
Operator: ()=>Operator
|
|
33
|
+
});
|
|
34
|
+
function _define_property(obj, key, value) {
|
|
35
|
+
if (key in obj) Object.defineProperty(obj, key, {
|
|
36
|
+
value: value,
|
|
37
|
+
enumerable: true,
|
|
38
|
+
configurable: true,
|
|
39
|
+
writable: true
|
|
40
|
+
});
|
|
41
|
+
else obj[key] = value;
|
|
42
|
+
return obj;
|
|
43
|
+
}
|
|
44
|
+
class BaseOperator {
|
|
45
|
+
}
|
|
46
|
+
class Operator extends BaseOperator {
|
|
47
|
+
async doInitialize() {
|
|
48
|
+
if (this._initialized) return;
|
|
49
|
+
if (this._initializing && this._initPromise) return this._initPromise;
|
|
50
|
+
this._initializing = true;
|
|
51
|
+
this._initPromise = (async ()=>{
|
|
52
|
+
try {
|
|
53
|
+
await this.initialize();
|
|
54
|
+
this._initialized = true;
|
|
55
|
+
} finally{
|
|
56
|
+
this._initializing = false;
|
|
57
|
+
}
|
|
58
|
+
})();
|
|
59
|
+
return this._initPromise;
|
|
60
|
+
}
|
|
61
|
+
async ensureInitialized() {
|
|
62
|
+
if (this._initialized || this._initializing) {
|
|
63
|
+
if (this._initializing && this._initPromise) await this._initPromise;
|
|
64
|
+
} else await this.doInitialize();
|
|
65
|
+
}
|
|
66
|
+
getSupportedActions() {
|
|
67
|
+
return this.supportedActions();
|
|
68
|
+
}
|
|
69
|
+
async getScreenContext() {
|
|
70
|
+
await this.ensureInitialized();
|
|
71
|
+
return this.screenContext();
|
|
72
|
+
}
|
|
73
|
+
async doScreenshot() {
|
|
74
|
+
try {
|
|
75
|
+
await this.ensureInitialized();
|
|
76
|
+
return await this.screenshot();
|
|
77
|
+
} catch (error) {
|
|
78
|
+
console.error('Error in doScreenshot:', error);
|
|
79
|
+
return {
|
|
80
|
+
base64: '',
|
|
81
|
+
status: 'failed',
|
|
82
|
+
errorMessage: error.message
|
|
83
|
+
};
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
async doExecute(params) {
|
|
87
|
+
try {
|
|
88
|
+
await this.ensureInitialized();
|
|
89
|
+
return await this.execute(params);
|
|
90
|
+
} catch (error) {
|
|
91
|
+
console.error('Error in doExecute:', error);
|
|
92
|
+
return {
|
|
93
|
+
status: 'failed',
|
|
94
|
+
errorMessage: error.message
|
|
95
|
+
};
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
constructor(){
|
|
99
|
+
super(), _define_property(this, "_initialized", false), _define_property(this, "_initializing", false), _define_property(this, "_initPromise", null);
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
exports.BaseOperator = __webpack_exports__.BaseOperator;
|
|
103
|
+
exports.Operator = __webpack_exports__.Operator;
|
|
104
|
+
for(var __webpack_i__ in __webpack_exports__)if (-1 === [
|
|
105
|
+
"BaseOperator",
|
|
106
|
+
"Operator"
|
|
107
|
+
].indexOf(__webpack_i__)) exports[__webpack_i__] = __webpack_exports__[__webpack_i__];
|
|
108
|
+
Object.defineProperty(exports, '__esModule', {
|
|
109
|
+
value: true
|
|
110
|
+
});
|
|
111
|
+
|
|
112
|
+
//# sourceMappingURL=operator.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"base/operator.js","sources":["webpack://@ui-tars-test/shared/webpack/runtime/define_property_getters","webpack://@ui-tars-test/shared/webpack/runtime/has_own_property","webpack://@ui-tars-test/shared/webpack/runtime/make_namespace_object","webpack://@ui-tars-test/shared/./src/base/operator.ts"],"sourcesContent":["__webpack_require__.d = (exports, definition) => {\n\tfor(var key in definition) {\n if(__webpack_require__.o(definition, key) && !__webpack_require__.o(exports, key)) {\n Object.defineProperty(exports, key, { enumerable: true, get: definition[key] });\n }\n }\n};","__webpack_require__.o = (obj, prop) => (Object.prototype.hasOwnProperty.call(obj, prop))","// define __esModule on exports\n__webpack_require__.r = (exports) => {\n\tif(typeof Symbol !== 'undefined' && Symbol.toStringTag) {\n\t\tObject.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });\n\t}\n\tObject.defineProperty(exports, '__esModule', { value: true });\n};","/*\n * Copyright (c) 2025 Bytedance, Inc. and its affiliates.\n * SPDX-License-Identifier: Apache-2.0\n */\n\nimport { ExecuteParams, ScreenshotOutput, ExecuteOutput, SupportedActionType } from '../types';\n\nexport interface ScreenContext {\n screenWidth: number;\n screenHeight: number;\n scaleX: number;\n scaleY: number;\n}\n\n/**\n * @abstract\n * @class BaseOperator\n * @classdesc Abstract base class for Operators.\n */\nexport abstract class BaseOperator {\n abstract doScreenshot(params?: unknown): Promise<unknown>;\n abstract doExecute(params: unknown): Promise<unknown>;\n}\n\n/**\n * @abstract\n * @class Operator\n * @classdesc Abstract base class for Operators.\n *\n * @example\n * // Example of defining ACTION_SPACES for a custom Operator\n * import type { GUIAction, ClickAction, DoubleClickAction, TypeAction, ScreenShotAction, SupportedActionType } from '../types/actions';\n *\n * class MyDesktopOperator extends Operator {\n *\n * // Implement the required abstract methods\n * protected async initialize(): Promise<void> {\n * // Implementation for initializing the operator\n * // e.g., validate connections, setup resources\n * // ...\n * }\n *\n * supportedActions(): Array<SupportedActionType> {\n * return [\n * 'click',\n * 'double_click',\n * 'right_click',\n * 'type',\n * 'hotkey',\n * 'scroll',\n * 'drag',\n * 'screenshot'\n * ] as SupportedActionType[];\n * }\n *\n * screenContext(): ScreenContext {\n * // Implementation for getting screen context\n * // ...\n * return {\n * screenWidth: 1920,\n * screenHeight: 1080,\n * scaleX: 1,\n * scaleY: 1\n * };\n * }\n *\n * async screenshot(): Promise<ScreenshotOutput> {\n * // Implementation for taking screenshots\n * // ...\n * return { }; // screenshot output\n * }\n *\n * async execute(params: ExecuteParams): Promise<ExecuteOutput> {\n * // Implementation for executing actions\n * // ...\n * return { }; // execution output\n * }\n * }\n */\nexport abstract class Operator extends BaseOperator {\n // Track initialization state\n private _initialized = false;\n private _initializing = false;\n private _initPromise: Promise<void> | null = null;\n\n constructor() {\n super();\n // this.ensureInitialized();\n }\n\n /**\n * Initializes the operator\n * @description Performs initialization operations for the operator, such as validating connections,\n * setting up resources, and preparing the operation environment.\n * @returns Promise that resolves when initialization is complete\n * @throws Error if initialization fails\n */\n async doInitialize(): Promise<void> {\n // If already initialized, return immediately\n if (this._initialized) {\n return;\n }\n\n // If initialization is in progress, wait for it to complete\n if (this._initializing && this._initPromise) {\n return this._initPromise;\n }\n\n // Start initialization\n this._initializing = true;\n this._initPromise = (async () => {\n try {\n await this.initialize();\n this._initialized = true;\n } finally {\n this._initializing = false;\n }\n })();\n\n return this._initPromise;\n }\n\n /**\n * Implementation of initialization logic\n * @description Subclasses should implement this method to perform their specific initialization\n * @returns Promise that resolves when initialization is complete\n * @throws Error if initialization fails\n */\n protected abstract initialize(): Promise<void>;\n\n /**\n * Ensures the operator is initialized before performing operations\n * @private\n */\n private async ensureInitialized(): Promise<void> {\n if (!this._initialized && !this._initializing) {\n await this.doInitialize();\n } else if (this._initializing && this._initPromise) {\n await this._initPromise;\n }\n }\n\n /**\n * Safely returns an array of supported action types with initialization guarantee\n * @returns Array of action types supported by this operator\n */\n getSupportedActions(): Array<SupportedActionType> {\n // await this.ensureInitialized();\n return this.supportedActions();\n }\n\n /**\n * Returns an array of supported action types\n * @returns Array of action types supported by this operator\n */\n protected abstract supportedActions(): Array<SupportedActionType>;\n\n /**\n * Safely returns the screen context with initialization guarantee\n * @returns The screen context\n */\n async getScreenContext(): Promise<ScreenContext> {\n await this.ensureInitialized();\n return this.screenContext();\n }\n\n /**\n * Returns the screen context\n * @returns The screen context\n */\n protected abstract screenContext(): ScreenContext;\n\n /**\n * Safely takes a screenshot with initialization guarantee\n * @returns Promise that resolves to the screenshot output\n */\n async doScreenshot(): Promise<ScreenshotOutput> {\n try {\n await this.ensureInitialized();\n return await this.screenshot();\n } catch (error) {\n console.error('Error in doScreenshot:', error);\n return {\n base64: '',\n status: 'failed',\n errorMessage: (error as Error).message,\n };\n }\n }\n\n /**\n * Takes a screenshot\n * @returns Promise that resolves to the screenshot output\n */\n protected abstract screenshot(): Promise<ScreenshotOutput>;\n\n /**\n * Safely executes actions with initialization guarantee\n * @param params - The parameters for the actions\n * @returns Promise that resolves to the execution output\n */\n async doExecute(params: ExecuteParams): Promise<ExecuteOutput> {\n try {\n await this.ensureInitialized();\n return await this.execute(params);\n } catch (error) {\n console.error('Error in doExecute:', error);\n return {\n status: 'failed',\n errorMessage: (error as Error).message,\n };\n }\n }\n\n /**\n * Executes actions\n * @param params - The parameters for the actions\n * @returns Promise that resolves to the execution output\n */\n protected abstract execute(params: ExecuteParams): Promise<ExecuteOutput>;\n}\n"],"names":["__webpack_require__","definition","key","Object","obj","prop","Symbol","BaseOperator","Operator","error","console","params"],"mappings":";;;;;;;IAAAA,oBAAoB,CAAC,GAAG,CAAC,UAASC;QACjC,IAAI,IAAIC,OAAOD,WACR,IAAGD,oBAAoB,CAAC,CAACC,YAAYC,QAAQ,CAACF,oBAAoB,CAAC,CAAC,UAASE,MACzEC,OAAO,cAAc,CAAC,UAASD,KAAK;YAAE,YAAY;YAAM,KAAKD,UAAU,CAACC,IAAI;QAAC;IAGzF;;;ICNAF,oBAAoB,CAAC,GAAG,CAACI,KAAKC,OAAUF,OAAO,SAAS,CAAC,cAAc,CAAC,IAAI,CAACC,KAAKC;;;ICClFL,oBAAoB,CAAC,GAAG,CAAC;QACxB,IAAG,AAAkB,eAAlB,OAAOM,UAA0BA,OAAO,WAAW,EACrDH,OAAO,cAAc,CAAC,UAASG,OAAO,WAAW,EAAE;YAAE,OAAO;QAAS;QAEtEH,OAAO,cAAc,CAAC,UAAS,cAAc;YAAE,OAAO;QAAK;IAC5D;;;;;;;;ACHC;;;;;;;;;;AAgBM,MAAeI;AAGtB;AAyDO,MAAeC,iBAAiBD;IAkBrC,MAAM,eAA8B;QAElC,IAAI,IAAI,CAAC,YAAY,EACnB;QAIF,IAAI,IAAI,CAAC,aAAa,IAAI,IAAI,CAAC,YAAY,EACzC,OAAO,IAAI,CAAC,YAAY;QAI1B,IAAI,CAAC,aAAa,GAAG;QACrB,IAAI,CAAC,YAAY,GAAI;YACnB,IAAI;gBACF,MAAM,IAAI,CAAC,UAAU;gBACrB,IAAI,CAAC,YAAY,GAAG;YACtB,SAAU;gBACR,IAAI,CAAC,aAAa,GAAG;YACvB;QACF;QAEA,OAAO,IAAI,CAAC,YAAY;IAC1B;IAcA,MAAc,oBAAmC;QAC/C,IAAI,AAAC,IAAI,CAAC,YAAY,IAAK,IAAI,CAAC,aAAa,EAEtC;YAAA,IAAI,IAAI,CAAC,aAAa,IAAI,IAAI,CAAC,YAAY,EAChD,MAAM,IAAI,CAAC,YAAY;QACzB,OAHE,MAAM,IAAI,CAAC,YAAY;IAI3B;IAMA,sBAAkD;QAEhD,OAAO,IAAI,CAAC,gBAAgB;IAC9B;IAYA,MAAM,mBAA2C;QAC/C,MAAM,IAAI,CAAC,iBAAiB;QAC5B,OAAO,IAAI,CAAC,aAAa;IAC3B;IAYA,MAAM,eAA0C;QAC9C,IAAI;YACF,MAAM,IAAI,CAAC,iBAAiB;YAC5B,OAAO,MAAM,IAAI,CAAC,UAAU;QAC9B,EAAE,OAAOE,OAAO;YACdC,QAAQ,KAAK,CAAC,0BAA0BD;YACxC,OAAO;gBACL,QAAQ;gBACR,QAAQ;gBACR,cAAeA,MAAgB,OAAO;YACxC;QACF;IACF;IAaA,MAAM,UAAUE,MAAqB,EAA0B;QAC7D,IAAI;YACF,MAAM,IAAI,CAAC,iBAAiB;YAC5B,OAAO,MAAM,IAAI,CAAC,OAAO,CAACA;QAC5B,EAAE,OAAOF,OAAO;YACdC,QAAQ,KAAK,CAAC,uBAAuBD;YACrC,OAAO;gBACL,QAAQ;gBACR,cAAeA,MAAgB,OAAO;YACxC;QACF;IACF;IA/HA,aAAc;QACZ,KAAK,IALP,uBAAQ,gBAAe,QACvB,uBAAQ,iBAAgB,QACxB,uBAAQ,gBAAqC;IAK7C;AAoIF"}
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) 2025 Bytedance, Inc. and its affiliates.
|
|
3
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
4
|
+
*/
|
|
5
|
+
function _define_property(obj, key, value) {
|
|
6
|
+
if (key in obj) Object.defineProperty(obj, key, {
|
|
7
|
+
value: value,
|
|
8
|
+
enumerable: true,
|
|
9
|
+
configurable: true,
|
|
10
|
+
writable: true
|
|
11
|
+
});
|
|
12
|
+
else obj[key] = value;
|
|
13
|
+
return obj;
|
|
14
|
+
}
|
|
15
|
+
class BaseOperator {
|
|
16
|
+
}
|
|
17
|
+
class Operator extends BaseOperator {
|
|
18
|
+
async doInitialize() {
|
|
19
|
+
if (this._initialized) return;
|
|
20
|
+
if (this._initializing && this._initPromise) return this._initPromise;
|
|
21
|
+
this._initializing = true;
|
|
22
|
+
this._initPromise = (async ()=>{
|
|
23
|
+
try {
|
|
24
|
+
await this.initialize();
|
|
25
|
+
this._initialized = true;
|
|
26
|
+
} finally{
|
|
27
|
+
this._initializing = false;
|
|
28
|
+
}
|
|
29
|
+
})();
|
|
30
|
+
return this._initPromise;
|
|
31
|
+
}
|
|
32
|
+
async ensureInitialized() {
|
|
33
|
+
if (this._initialized || this._initializing) {
|
|
34
|
+
if (this._initializing && this._initPromise) await this._initPromise;
|
|
35
|
+
} else await this.doInitialize();
|
|
36
|
+
}
|
|
37
|
+
getSupportedActions() {
|
|
38
|
+
return this.supportedActions();
|
|
39
|
+
}
|
|
40
|
+
async getScreenContext() {
|
|
41
|
+
await this.ensureInitialized();
|
|
42
|
+
return this.screenContext();
|
|
43
|
+
}
|
|
44
|
+
async doScreenshot() {
|
|
45
|
+
try {
|
|
46
|
+
await this.ensureInitialized();
|
|
47
|
+
return await this.screenshot();
|
|
48
|
+
} catch (error) {
|
|
49
|
+
console.error('Error in doScreenshot:', error);
|
|
50
|
+
return {
|
|
51
|
+
base64: '',
|
|
52
|
+
status: 'failed',
|
|
53
|
+
errorMessage: error.message
|
|
54
|
+
};
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
async doExecute(params) {
|
|
58
|
+
try {
|
|
59
|
+
await this.ensureInitialized();
|
|
60
|
+
return await this.execute(params);
|
|
61
|
+
} catch (error) {
|
|
62
|
+
console.error('Error in doExecute:', error);
|
|
63
|
+
return {
|
|
64
|
+
status: 'failed',
|
|
65
|
+
errorMessage: error.message
|
|
66
|
+
};
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
constructor(){
|
|
70
|
+
super(), _define_property(this, "_initialized", false), _define_property(this, "_initializing", false), _define_property(this, "_initPromise", null);
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
export { BaseOperator, Operator };
|
|
74
|
+
|
|
75
|
+
//# sourceMappingURL=operator.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"base/operator.mjs","sources":["webpack://@ui-tars-test/shared/./src/base/operator.ts"],"sourcesContent":["/*\n * Copyright (c) 2025 Bytedance, Inc. and its affiliates.\n * SPDX-License-Identifier: Apache-2.0\n */\n\nimport { ExecuteParams, ScreenshotOutput, ExecuteOutput, SupportedActionType } from '../types';\n\nexport interface ScreenContext {\n screenWidth: number;\n screenHeight: number;\n scaleX: number;\n scaleY: number;\n}\n\n/**\n * @abstract\n * @class BaseOperator\n * @classdesc Abstract base class for Operators.\n */\nexport abstract class BaseOperator {\n abstract doScreenshot(params?: unknown): Promise<unknown>;\n abstract doExecute(params: unknown): Promise<unknown>;\n}\n\n/**\n * @abstract\n * @class Operator\n * @classdesc Abstract base class for Operators.\n *\n * @example\n * // Example of defining ACTION_SPACES for a custom Operator\n * import type { GUIAction, ClickAction, DoubleClickAction, TypeAction, ScreenShotAction, SupportedActionType } from '../types/actions';\n *\n * class MyDesktopOperator extends Operator {\n *\n * // Implement the required abstract methods\n * protected async initialize(): Promise<void> {\n * // Implementation for initializing the operator\n * // e.g., validate connections, setup resources\n * // ...\n * }\n *\n * supportedActions(): Array<SupportedActionType> {\n * return [\n * 'click',\n * 'double_click',\n * 'right_click',\n * 'type',\n * 'hotkey',\n * 'scroll',\n * 'drag',\n * 'screenshot'\n * ] as SupportedActionType[];\n * }\n *\n * screenContext(): ScreenContext {\n * // Implementation for getting screen context\n * // ...\n * return {\n * screenWidth: 1920,\n * screenHeight: 1080,\n * scaleX: 1,\n * scaleY: 1\n * };\n * }\n *\n * async screenshot(): Promise<ScreenshotOutput> {\n * // Implementation for taking screenshots\n * // ...\n * return { }; // screenshot output\n * }\n *\n * async execute(params: ExecuteParams): Promise<ExecuteOutput> {\n * // Implementation for executing actions\n * // ...\n * return { }; // execution output\n * }\n * }\n */\nexport abstract class Operator extends BaseOperator {\n // Track initialization state\n private _initialized = false;\n private _initializing = false;\n private _initPromise: Promise<void> | null = null;\n\n constructor() {\n super();\n // this.ensureInitialized();\n }\n\n /**\n * Initializes the operator\n * @description Performs initialization operations for the operator, such as validating connections,\n * setting up resources, and preparing the operation environment.\n * @returns Promise that resolves when initialization is complete\n * @throws Error if initialization fails\n */\n async doInitialize(): Promise<void> {\n // If already initialized, return immediately\n if (this._initialized) {\n return;\n }\n\n // If initialization is in progress, wait for it to complete\n if (this._initializing && this._initPromise) {\n return this._initPromise;\n }\n\n // Start initialization\n this._initializing = true;\n this._initPromise = (async () => {\n try {\n await this.initialize();\n this._initialized = true;\n } finally {\n this._initializing = false;\n }\n })();\n\n return this._initPromise;\n }\n\n /**\n * Implementation of initialization logic\n * @description Subclasses should implement this method to perform their specific initialization\n * @returns Promise that resolves when initialization is complete\n * @throws Error if initialization fails\n */\n protected abstract initialize(): Promise<void>;\n\n /**\n * Ensures the operator is initialized before performing operations\n * @private\n */\n private async ensureInitialized(): Promise<void> {\n if (!this._initialized && !this._initializing) {\n await this.doInitialize();\n } else if (this._initializing && this._initPromise) {\n await this._initPromise;\n }\n }\n\n /**\n * Safely returns an array of supported action types with initialization guarantee\n * @returns Array of action types supported by this operator\n */\n getSupportedActions(): Array<SupportedActionType> {\n // await this.ensureInitialized();\n return this.supportedActions();\n }\n\n /**\n * Returns an array of supported action types\n * @returns Array of action types supported by this operator\n */\n protected abstract supportedActions(): Array<SupportedActionType>;\n\n /**\n * Safely returns the screen context with initialization guarantee\n * @returns The screen context\n */\n async getScreenContext(): Promise<ScreenContext> {\n await this.ensureInitialized();\n return this.screenContext();\n }\n\n /**\n * Returns the screen context\n * @returns The screen context\n */\n protected abstract screenContext(): ScreenContext;\n\n /**\n * Safely takes a screenshot with initialization guarantee\n * @returns Promise that resolves to the screenshot output\n */\n async doScreenshot(): Promise<ScreenshotOutput> {\n try {\n await this.ensureInitialized();\n return await this.screenshot();\n } catch (error) {\n console.error('Error in doScreenshot:', error);\n return {\n base64: '',\n status: 'failed',\n errorMessage: (error as Error).message,\n };\n }\n }\n\n /**\n * Takes a screenshot\n * @returns Promise that resolves to the screenshot output\n */\n protected abstract screenshot(): Promise<ScreenshotOutput>;\n\n /**\n * Safely executes actions with initialization guarantee\n * @param params - The parameters for the actions\n * @returns Promise that resolves to the execution output\n */\n async doExecute(params: ExecuteParams): Promise<ExecuteOutput> {\n try {\n await this.ensureInitialized();\n return await this.execute(params);\n } catch (error) {\n console.error('Error in doExecute:', error);\n return {\n status: 'failed',\n errorMessage: (error as Error).message,\n };\n }\n }\n\n /**\n * Executes actions\n * @param params - The parameters for the actions\n * @returns Promise that resolves to the execution output\n */\n protected abstract execute(params: ExecuteParams): Promise<ExecuteOutput>;\n}\n"],"names":["BaseOperator","Operator","error","console","params"],"mappings":";;;;AAGC;;;;;;;;;;AAgBM,MAAeA;AAGtB;AAyDO,MAAeC,iBAAiBD;IAkBrC,MAAM,eAA8B;QAElC,IAAI,IAAI,CAAC,YAAY,EACnB;QAIF,IAAI,IAAI,CAAC,aAAa,IAAI,IAAI,CAAC,YAAY,EACzC,OAAO,IAAI,CAAC,YAAY;QAI1B,IAAI,CAAC,aAAa,GAAG;QACrB,IAAI,CAAC,YAAY,GAAI;YACnB,IAAI;gBACF,MAAM,IAAI,CAAC,UAAU;gBACrB,IAAI,CAAC,YAAY,GAAG;YACtB,SAAU;gBACR,IAAI,CAAC,aAAa,GAAG;YACvB;QACF;QAEA,OAAO,IAAI,CAAC,YAAY;IAC1B;IAcA,MAAc,oBAAmC;QAC/C,IAAI,AAAC,IAAI,CAAC,YAAY,IAAK,IAAI,CAAC,aAAa,EAEtC;YAAA,IAAI,IAAI,CAAC,aAAa,IAAI,IAAI,CAAC,YAAY,EAChD,MAAM,IAAI,CAAC,YAAY;QACzB,OAHE,MAAM,IAAI,CAAC,YAAY;IAI3B;IAMA,sBAAkD;QAEhD,OAAO,IAAI,CAAC,gBAAgB;IAC9B;IAYA,MAAM,mBAA2C;QAC/C,MAAM,IAAI,CAAC,iBAAiB;QAC5B,OAAO,IAAI,CAAC,aAAa;IAC3B;IAYA,MAAM,eAA0C;QAC9C,IAAI;YACF,MAAM,IAAI,CAAC,iBAAiB;YAC5B,OAAO,MAAM,IAAI,CAAC,UAAU;QAC9B,EAAE,OAAOE,OAAO;YACdC,QAAQ,KAAK,CAAC,0BAA0BD;YACxC,OAAO;gBACL,QAAQ;gBACR,QAAQ;gBACR,cAAeA,MAAgB,OAAO;YACxC;QACF;IACF;IAaA,MAAM,UAAUE,MAAqB,EAA0B;QAC7D,IAAI;YACF,MAAM,IAAI,CAAC,iBAAiB;YAC5B,OAAO,MAAM,IAAI,CAAC,OAAO,CAACA;QAC5B,EAAE,OAAOF,OAAO;YACdC,QAAQ,KAAK,CAAC,uBAAuBD;YACrC,OAAO;gBACL,QAAQ;gBACR,cAAeA,MAAgB,OAAO;YACxC;QACF;IACF;IA/HA,aAAc;QACZ,KAAK,IALP,uBAAQ,gBAAe,QACvB,uBAAQ,iBAAgB,QACxB,uBAAQ,gBAAqC;IAK7C;AAoIF"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { ParsedGUIResponse } from '../types';
|
|
2
|
+
export declare abstract class BaseActionParser {
|
|
3
|
+
/**
|
|
4
|
+
* Parse model output
|
|
5
|
+
* @param input Model output string
|
|
6
|
+
* @returns Parsed ParsedGUIResponse object, returns null if parsing fails
|
|
7
|
+
* There is no need to throw error, the error message is returned in ParsedGUIResponse
|
|
8
|
+
*/
|
|
9
|
+
abstract parsePrediction(input: string): ParsedGUIResponse | null;
|
|
10
|
+
}
|
|
11
|
+
//# sourceMappingURL=parser.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"parser.d.ts","sourceRoot":"","sources":["../../src/base/parser.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,iBAAiB,EAAE,MAAM,UAAU,CAAC;AAE7C,8BAAsB,gBAAgB;IACpC;;;;;OAKG;IACH,QAAQ,CAAC,eAAe,CAAC,KAAK,EAAE,MAAM,GAAG,iBAAiB,GAAG,IAAI;CAClE"}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) 2025 Bytedance, Inc. and its affiliates.
|
|
3
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
4
|
+
*/
|
|
5
|
+
"use strict";
|
|
6
|
+
var __webpack_require__ = {};
|
|
7
|
+
(()=>{
|
|
8
|
+
__webpack_require__.d = (exports1, definition)=>{
|
|
9
|
+
for(var key in definition)if (__webpack_require__.o(definition, key) && !__webpack_require__.o(exports1, key)) Object.defineProperty(exports1, key, {
|
|
10
|
+
enumerable: true,
|
|
11
|
+
get: definition[key]
|
|
12
|
+
});
|
|
13
|
+
};
|
|
14
|
+
})();
|
|
15
|
+
(()=>{
|
|
16
|
+
__webpack_require__.o = (obj, prop)=>Object.prototype.hasOwnProperty.call(obj, prop);
|
|
17
|
+
})();
|
|
18
|
+
(()=>{
|
|
19
|
+
__webpack_require__.r = (exports1)=>{
|
|
20
|
+
if ('undefined' != typeof Symbol && Symbol.toStringTag) Object.defineProperty(exports1, Symbol.toStringTag, {
|
|
21
|
+
value: 'Module'
|
|
22
|
+
});
|
|
23
|
+
Object.defineProperty(exports1, '__esModule', {
|
|
24
|
+
value: true
|
|
25
|
+
});
|
|
26
|
+
};
|
|
27
|
+
})();
|
|
28
|
+
var __webpack_exports__ = {};
|
|
29
|
+
__webpack_require__.r(__webpack_exports__);
|
|
30
|
+
__webpack_require__.d(__webpack_exports__, {
|
|
31
|
+
BaseActionParser: ()=>BaseActionParser
|
|
32
|
+
});
|
|
33
|
+
class BaseActionParser {
|
|
34
|
+
}
|
|
35
|
+
exports.BaseActionParser = __webpack_exports__.BaseActionParser;
|
|
36
|
+
for(var __webpack_i__ in __webpack_exports__)if (-1 === [
|
|
37
|
+
"BaseActionParser"
|
|
38
|
+
].indexOf(__webpack_i__)) exports[__webpack_i__] = __webpack_exports__[__webpack_i__];
|
|
39
|
+
Object.defineProperty(exports, '__esModule', {
|
|
40
|
+
value: true
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
//# sourceMappingURL=parser.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"base/parser.js","sources":["webpack://@ui-tars-test/shared/webpack/runtime/define_property_getters","webpack://@ui-tars-test/shared/webpack/runtime/has_own_property","webpack://@ui-tars-test/shared/webpack/runtime/make_namespace_object","webpack://@ui-tars-test/shared/./src/base/parser.ts"],"sourcesContent":["__webpack_require__.d = (exports, definition) => {\n\tfor(var key in definition) {\n if(__webpack_require__.o(definition, key) && !__webpack_require__.o(exports, key)) {\n Object.defineProperty(exports, key, { enumerable: true, get: definition[key] });\n }\n }\n};","__webpack_require__.o = (obj, prop) => (Object.prototype.hasOwnProperty.call(obj, prop))","// define __esModule on exports\n__webpack_require__.r = (exports) => {\n\tif(typeof Symbol !== 'undefined' && Symbol.toStringTag) {\n\t\tObject.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });\n\t}\n\tObject.defineProperty(exports, '__esModule', { value: true });\n};","/*\n * Copyright (c) 2025 Bytedance, Inc. and its affiliates.\n * SPDX-License-Identifier: Apache-2.0\n */\n\nimport { ParsedGUIResponse } from '../types';\n\nexport abstract class BaseActionParser {\n /**\n * Parse model output\n * @param input Model output string\n * @returns Parsed ParsedGUIResponse object, returns null if parsing fails\n * There is no need to throw error, the error message is returned in ParsedGUIResponse\n */\n abstract parsePrediction(input: string): ParsedGUIResponse | null;\n}\n"],"names":["__webpack_require__","definition","key","Object","obj","prop","Symbol","BaseActionParser"],"mappings":";;;;;;;IAAAA,oBAAoB,CAAC,GAAG,CAAC,UAASC;QACjC,IAAI,IAAIC,OAAOD,WACR,IAAGD,oBAAoB,CAAC,CAACC,YAAYC,QAAQ,CAACF,oBAAoB,CAAC,CAAC,UAASE,MACzEC,OAAO,cAAc,CAAC,UAASD,KAAK;YAAE,YAAY;YAAM,KAAKD,UAAU,CAACC,IAAI;QAAC;IAGzF;;;ICNAF,oBAAoB,CAAC,GAAG,CAACI,KAAKC,OAAUF,OAAO,SAAS,CAAC,cAAc,CAAC,IAAI,CAACC,KAAKC;;;ICClFL,oBAAoB,CAAC,GAAG,CAAC;QACxB,IAAG,AAAkB,eAAlB,OAAOM,UAA0BA,OAAO,WAAW,EACrDH,OAAO,cAAc,CAAC,UAASG,OAAO,WAAW,EAAE;YAAE,OAAO;QAAS;QAEtEH,OAAO,cAAc,CAAC,UAAS,cAAc;YAAE,OAAO;QAAK;IAC5D;;;;;;;ACCO,MAAeI;AAQtB"}
|