@godscene/core 1.7.11
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/LICENSE +21 -0
- package/README.md +9 -0
- package/dist/es/agent/agent.mjs +767 -0
- package/dist/es/agent/common.mjs +0 -0
- package/dist/es/agent/execution-session.mjs +39 -0
- package/dist/es/agent/index.mjs +6 -0
- package/dist/es/agent/task-builder.mjs +343 -0
- package/dist/es/agent/task-cache.mjs +212 -0
- package/dist/es/agent/tasks.mjs +428 -0
- package/dist/es/agent/ui-utils.mjs +101 -0
- package/dist/es/agent/utils.mjs +167 -0
- package/dist/es/ai-model/auto-glm/actions.mjs +237 -0
- package/dist/es/ai-model/auto-glm/index.mjs +6 -0
- package/dist/es/ai-model/auto-glm/parser.mjs +237 -0
- package/dist/es/ai-model/auto-glm/planning.mjs +69 -0
- package/dist/es/ai-model/auto-glm/prompt.mjs +220 -0
- package/dist/es/ai-model/auto-glm/util.mjs +7 -0
- package/dist/es/ai-model/connectivity.mjs +136 -0
- package/dist/es/ai-model/conversation-history.mjs +193 -0
- package/dist/es/ai-model/index.mjs +12 -0
- package/dist/es/ai-model/inspect.mjs +395 -0
- package/dist/es/ai-model/llm-planning.mjs +231 -0
- package/dist/es/ai-model/prompt/common.mjs +5 -0
- package/dist/es/ai-model/prompt/describe.mjs +64 -0
- package/dist/es/ai-model/prompt/extraction.mjs +129 -0
- package/dist/es/ai-model/prompt/llm-locator.mjs +49 -0
- package/dist/es/ai-model/prompt/llm-planning.mjs +584 -0
- package/dist/es/ai-model/prompt/llm-section-locator.mjs +42 -0
- package/dist/es/ai-model/prompt/order-sensitive-judge.mjs +33 -0
- package/dist/es/ai-model/prompt/playwright-generator.mjs +115 -0
- package/dist/es/ai-model/prompt/ui-tars-planning.mjs +34 -0
- package/dist/es/ai-model/prompt/util.mjs +57 -0
- package/dist/es/ai-model/prompt/yaml-generator.mjs +201 -0
- package/dist/es/ai-model/service-caller/codex-app-server.mjs +573 -0
- package/dist/es/ai-model/service-caller/image-detail.mjs +4 -0
- package/dist/es/ai-model/service-caller/index.mjs +648 -0
- package/dist/es/ai-model/service-caller/request-timeout.mjs +47 -0
- package/dist/es/ai-model/ui-tars-planning.mjs +247 -0
- package/dist/es/common.mjs +382 -0
- package/dist/es/device/device-options.mjs +0 -0
- package/dist/es/device/index.mjs +340 -0
- package/dist/es/dump/html-utils.mjs +290 -0
- package/dist/es/dump/index.mjs +3 -0
- package/dist/es/dump/screenshot-restoration.mjs +30 -0
- package/dist/es/dump/screenshot-store.mjs +125 -0
- package/dist/es/index.mjs +17 -0
- package/dist/es/report-cli.mjs +149 -0
- package/dist/es/report-generator.mjs +203 -0
- package/dist/es/report-markdown.mjs +216 -0
- package/dist/es/report.mjs +287 -0
- package/dist/es/screenshot-item.mjs +120 -0
- package/dist/es/service/index.mjs +272 -0
- package/dist/es/service/utils.mjs +13 -0
- package/dist/es/skill/index.mjs +35 -0
- package/dist/es/task-runner.mjs +261 -0
- package/dist/es/task-timing.mjs +10 -0
- package/dist/es/tree.mjs +11 -0
- package/dist/es/types.mjs +202 -0
- package/dist/es/utils.mjs +232 -0
- package/dist/es/yaml/builder.mjs +11 -0
- package/dist/es/yaml/index.mjs +4 -0
- package/dist/es/yaml/player.mjs +425 -0
- package/dist/es/yaml/utils.mjs +100 -0
- package/dist/es/yaml.mjs +0 -0
- package/dist/lib/agent/agent.js +815 -0
- package/dist/lib/agent/common.js +5 -0
- package/dist/lib/agent/execution-session.js +73 -0
- package/dist/lib/agent/index.js +76 -0
- package/dist/lib/agent/task-builder.js +380 -0
- package/dist/lib/agent/task-cache.js +264 -0
- package/dist/lib/agent/tasks.js +471 -0
- package/dist/lib/agent/ui-utils.js +153 -0
- package/dist/lib/agent/utils.js +238 -0
- package/dist/lib/ai-model/auto-glm/actions.js +271 -0
- package/dist/lib/ai-model/auto-glm/index.js +64 -0
- package/dist/lib/ai-model/auto-glm/parser.js +280 -0
- package/dist/lib/ai-model/auto-glm/planning.js +103 -0
- package/dist/lib/ai-model/auto-glm/prompt.js +257 -0
- package/dist/lib/ai-model/auto-glm/util.js +44 -0
- package/dist/lib/ai-model/connectivity.js +180 -0
- package/dist/lib/ai-model/conversation-history.js +227 -0
- package/dist/lib/ai-model/index.js +127 -0
- package/dist/lib/ai-model/inspect.js +441 -0
- package/dist/lib/ai-model/llm-planning.js +268 -0
- package/dist/lib/ai-model/prompt/common.js +39 -0
- package/dist/lib/ai-model/prompt/describe.js +98 -0
- package/dist/lib/ai-model/prompt/extraction.js +169 -0
- package/dist/lib/ai-model/prompt/llm-locator.js +86 -0
- package/dist/lib/ai-model/prompt/llm-planning.js +621 -0
- package/dist/lib/ai-model/prompt/llm-section-locator.js +79 -0
- package/dist/lib/ai-model/prompt/order-sensitive-judge.js +70 -0
- package/dist/lib/ai-model/prompt/playwright-generator.js +176 -0
- package/dist/lib/ai-model/prompt/ui-tars-planning.js +71 -0
- package/dist/lib/ai-model/prompt/util.js +103 -0
- package/dist/lib/ai-model/prompt/yaml-generator.js +262 -0
- package/dist/lib/ai-model/service-caller/codex-app-server.js +622 -0
- package/dist/lib/ai-model/service-caller/image-detail.js +38 -0
- package/dist/lib/ai-model/service-caller/index.js +716 -0
- package/dist/lib/ai-model/service-caller/request-timeout.js +93 -0
- package/dist/lib/ai-model/ui-tars-planning.js +281 -0
- package/dist/lib/common.js +491 -0
- package/dist/lib/device/device-options.js +18 -0
- package/dist/lib/device/index.js +467 -0
- package/dist/lib/dump/html-utils.js +366 -0
- package/dist/lib/dump/index.js +58 -0
- package/dist/lib/dump/screenshot-restoration.js +64 -0
- package/dist/lib/dump/screenshot-store.js +165 -0
- package/dist/lib/index.js +184 -0
- package/dist/lib/report-cli.js +189 -0
- package/dist/lib/report-generator.js +244 -0
- package/dist/lib/report-markdown.js +253 -0
- package/dist/lib/report.js +333 -0
- package/dist/lib/screenshot-item.js +154 -0
- package/dist/lib/service/index.js +306 -0
- package/dist/lib/service/utils.js +47 -0
- package/dist/lib/skill/index.js +69 -0
- package/dist/lib/task-runner.js +298 -0
- package/dist/lib/task-timing.js +44 -0
- package/dist/lib/tree.js +51 -0
- package/dist/lib/types.js +298 -0
- package/dist/lib/utils.js +314 -0
- package/dist/lib/yaml/builder.js +55 -0
- package/dist/lib/yaml/index.js +79 -0
- package/dist/lib/yaml/player.js +459 -0
- package/dist/lib/yaml/utils.js +153 -0
- package/dist/lib/yaml.js +18 -0
- package/dist/types/agent/agent.d.ts +220 -0
- package/dist/types/agent/common.d.ts +0 -0
- package/dist/types/agent/execution-session.d.ts +36 -0
- package/dist/types/agent/index.d.ts +9 -0
- package/dist/types/agent/task-builder.d.ts +34 -0
- package/dist/types/agent/task-cache.d.ts +49 -0
- package/dist/types/agent/tasks.d.ts +70 -0
- package/dist/types/agent/ui-utils.d.ts +14 -0
- package/dist/types/agent/utils.d.ts +25 -0
- package/dist/types/ai-model/auto-glm/actions.d.ts +78 -0
- package/dist/types/ai-model/auto-glm/index.d.ts +6 -0
- package/dist/types/ai-model/auto-glm/parser.d.ts +18 -0
- package/dist/types/ai-model/auto-glm/planning.d.ts +12 -0
- package/dist/types/ai-model/auto-glm/prompt.d.ts +27 -0
- package/dist/types/ai-model/auto-glm/util.d.ts +13 -0
- package/dist/types/ai-model/connectivity.d.ts +20 -0
- package/dist/types/ai-model/conversation-history.d.ts +105 -0
- package/dist/types/ai-model/index.d.ts +16 -0
- package/dist/types/ai-model/inspect.d.ts +67 -0
- package/dist/types/ai-model/llm-planning.d.ts +19 -0
- package/dist/types/ai-model/prompt/common.d.ts +2 -0
- package/dist/types/ai-model/prompt/describe.d.ts +1 -0
- package/dist/types/ai-model/prompt/extraction.d.ts +7 -0
- package/dist/types/ai-model/prompt/llm-locator.d.ts +3 -0
- package/dist/types/ai-model/prompt/llm-planning.d.ts +10 -0
- package/dist/types/ai-model/prompt/llm-section-locator.d.ts +3 -0
- package/dist/types/ai-model/prompt/order-sensitive-judge.d.ts +2 -0
- package/dist/types/ai-model/prompt/playwright-generator.d.ts +26 -0
- package/dist/types/ai-model/prompt/ui-tars-planning.d.ts +2 -0
- package/dist/types/ai-model/prompt/util.d.ts +33 -0
- package/dist/types/ai-model/prompt/yaml-generator.d.ts +102 -0
- package/dist/types/ai-model/service-caller/codex-app-server.d.ts +42 -0
- package/dist/types/ai-model/service-caller/image-detail.d.ts +2 -0
- package/dist/types/ai-model/service-caller/index.d.ts +60 -0
- package/dist/types/ai-model/service-caller/request-timeout.d.ts +32 -0
- package/dist/types/ai-model/ui-tars-planning.d.ts +72 -0
- package/dist/types/common.d.ts +288 -0
- package/dist/types/device/device-options.d.ts +155 -0
- package/dist/types/device/index.d.ts +2565 -0
- package/dist/types/dump/html-utils.d.ts +75 -0
- package/dist/types/dump/index.d.ts +5 -0
- package/dist/types/dump/screenshot-restoration.d.ts +8 -0
- package/dist/types/dump/screenshot-store.d.ts +49 -0
- package/dist/types/index.d.ts +21 -0
- package/dist/types/report-cli.d.ts +36 -0
- package/dist/types/report-generator.d.ts +88 -0
- package/dist/types/report-markdown.d.ts +24 -0
- package/dist/types/report.d.ts +52 -0
- package/dist/types/screenshot-item.d.ts +67 -0
- package/dist/types/service/index.d.ts +24 -0
- package/dist/types/service/utils.d.ts +2 -0
- package/dist/types/skill/index.d.ts +25 -0
- package/dist/types/task-runner.d.ts +50 -0
- package/dist/types/task-timing.d.ts +8 -0
- package/dist/types/tree.d.ts +4 -0
- package/dist/types/types.d.ts +684 -0
- package/dist/types/utils.d.ts +45 -0
- package/dist/types/yaml/builder.d.ts +2 -0
- package/dist/types/yaml/index.d.ts +4 -0
- package/dist/types/yaml/player.d.ts +34 -0
- package/dist/types/yaml/utils.d.ts +9 -0
- package/dist/types/yaml.d.ts +215 -0
- package/package.json +130 -0
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __webpack_require__ = {};
|
|
3
|
+
(()=>{
|
|
4
|
+
__webpack_require__.d = (exports1, definition)=>{
|
|
5
|
+
for(var key in definition)if (__webpack_require__.o(definition, key) && !__webpack_require__.o(exports1, key)) Object.defineProperty(exports1, key, {
|
|
6
|
+
enumerable: true,
|
|
7
|
+
get: definition[key]
|
|
8
|
+
});
|
|
9
|
+
};
|
|
10
|
+
})();
|
|
11
|
+
(()=>{
|
|
12
|
+
__webpack_require__.o = (obj, prop)=>Object.prototype.hasOwnProperty.call(obj, prop);
|
|
13
|
+
})();
|
|
14
|
+
(()=>{
|
|
15
|
+
__webpack_require__.r = (exports1)=>{
|
|
16
|
+
if ("u" > typeof Symbol && Symbol.toStringTag) Object.defineProperty(exports1, Symbol.toStringTag, {
|
|
17
|
+
value: 'Module'
|
|
18
|
+
});
|
|
19
|
+
Object.defineProperty(exports1, '__esModule', {
|
|
20
|
+
value: true
|
|
21
|
+
});
|
|
22
|
+
};
|
|
23
|
+
})();
|
|
24
|
+
var __webpack_exports__ = {};
|
|
25
|
+
__webpack_require__.r(__webpack_exports__);
|
|
26
|
+
__webpack_require__.d(__webpack_exports__, {
|
|
27
|
+
ExecutionSession: ()=>ExecutionSession
|
|
28
|
+
});
|
|
29
|
+
const external_task_runner_js_namespaceObject = require("../task-runner.js");
|
|
30
|
+
function _define_property(obj, key, value) {
|
|
31
|
+
if (key in obj) Object.defineProperty(obj, key, {
|
|
32
|
+
value: value,
|
|
33
|
+
enumerable: true,
|
|
34
|
+
configurable: true,
|
|
35
|
+
writable: true
|
|
36
|
+
});
|
|
37
|
+
else obj[key] = value;
|
|
38
|
+
return obj;
|
|
39
|
+
}
|
|
40
|
+
class ExecutionSession {
|
|
41
|
+
async append(tasks, options) {
|
|
42
|
+
await this.runner.append(tasks, options);
|
|
43
|
+
}
|
|
44
|
+
async appendAndRun(tasks, options) {
|
|
45
|
+
return this.runner.appendAndFlush(tasks, options);
|
|
46
|
+
}
|
|
47
|
+
async run(options) {
|
|
48
|
+
return this.runner.flush(options);
|
|
49
|
+
}
|
|
50
|
+
isInErrorState() {
|
|
51
|
+
return this.runner.isInErrorState();
|
|
52
|
+
}
|
|
53
|
+
latestErrorTask() {
|
|
54
|
+
return this.runner.latestErrorTask();
|
|
55
|
+
}
|
|
56
|
+
appendErrorPlan(errorMsg) {
|
|
57
|
+
return this.runner.appendErrorPlan(errorMsg);
|
|
58
|
+
}
|
|
59
|
+
getRunner() {
|
|
60
|
+
return this.runner;
|
|
61
|
+
}
|
|
62
|
+
constructor(name, contextProvider, options){
|
|
63
|
+
_define_property(this, "runner", void 0);
|
|
64
|
+
this.runner = new external_task_runner_js_namespaceObject.TaskRunner(name, contextProvider, options);
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
exports.ExecutionSession = __webpack_exports__.ExecutionSession;
|
|
68
|
+
for(var __rspack_i in __webpack_exports__)if (-1 === [
|
|
69
|
+
"ExecutionSession"
|
|
70
|
+
].indexOf(__rspack_i)) exports[__rspack_i] = __webpack_exports__[__rspack_i];
|
|
71
|
+
Object.defineProperty(exports, '__esModule', {
|
|
72
|
+
value: true
|
|
73
|
+
});
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __webpack_require__ = {};
|
|
3
|
+
(()=>{
|
|
4
|
+
__webpack_require__.d = (exports1, definition)=>{
|
|
5
|
+
for(var key in definition)if (__webpack_require__.o(definition, key) && !__webpack_require__.o(exports1, key)) Object.defineProperty(exports1, key, {
|
|
6
|
+
enumerable: true,
|
|
7
|
+
get: definition[key]
|
|
8
|
+
});
|
|
9
|
+
};
|
|
10
|
+
})();
|
|
11
|
+
(()=>{
|
|
12
|
+
__webpack_require__.o = (obj, prop)=>Object.prototype.hasOwnProperty.call(obj, prop);
|
|
13
|
+
})();
|
|
14
|
+
(()=>{
|
|
15
|
+
__webpack_require__.r = (exports1)=>{
|
|
16
|
+
if ("u" > typeof Symbol && Symbol.toStringTag) Object.defineProperty(exports1, Symbol.toStringTag, {
|
|
17
|
+
value: 'Module'
|
|
18
|
+
});
|
|
19
|
+
Object.defineProperty(exports1, '__esModule', {
|
|
20
|
+
value: true
|
|
21
|
+
});
|
|
22
|
+
};
|
|
23
|
+
})();
|
|
24
|
+
var __webpack_exports__ = {};
|
|
25
|
+
__webpack_require__.r(__webpack_exports__);
|
|
26
|
+
__webpack_require__.d(__webpack_exports__, {
|
|
27
|
+
typeStr: ()=>external_ui_utils_js_namespaceObject.typeStr,
|
|
28
|
+
paramStr: ()=>external_ui_utils_js_namespaceObject.paramStr,
|
|
29
|
+
getReportFileName: ()=>external_utils_js_namespaceObject.getReportFileName,
|
|
30
|
+
extractInsightParam: ()=>external_ui_utils_js_namespaceObject.extractInsightParam,
|
|
31
|
+
cacheFileExt: ()=>external_task_cache_js_namespaceObject.cacheFileExt,
|
|
32
|
+
taskTitleStr: ()=>external_ui_utils_js_namespaceObject.taskTitleStr,
|
|
33
|
+
commonContextParser: ()=>external_utils_js_namespaceObject.commonContextParser,
|
|
34
|
+
TaskCache: ()=>external_task_cache_js_namespaceObject.TaskCache,
|
|
35
|
+
locateParamStr: ()=>external_ui_utils_js_namespaceObject.locateParamStr,
|
|
36
|
+
createAgent: ()=>external_agent_js_namespaceObject.createAgent,
|
|
37
|
+
Agent: ()=>external_agent_js_namespaceObject.Agent,
|
|
38
|
+
TaskExecutor: ()=>external_tasks_js_namespaceObject.TaskExecutor,
|
|
39
|
+
printReportMsg: ()=>external_utils_js_namespaceObject.printReportMsg
|
|
40
|
+
});
|
|
41
|
+
const external_agent_js_namespaceObject = require("./agent.js");
|
|
42
|
+
const external_utils_js_namespaceObject = require("./utils.js");
|
|
43
|
+
const external_ui_utils_js_namespaceObject = require("./ui-utils.js");
|
|
44
|
+
const external_task_cache_js_namespaceObject = require("./task-cache.js");
|
|
45
|
+
const external_tasks_js_namespaceObject = require("./tasks.js");
|
|
46
|
+
exports.Agent = __webpack_exports__.Agent;
|
|
47
|
+
exports.TaskCache = __webpack_exports__.TaskCache;
|
|
48
|
+
exports.TaskExecutor = __webpack_exports__.TaskExecutor;
|
|
49
|
+
exports.cacheFileExt = __webpack_exports__.cacheFileExt;
|
|
50
|
+
exports.commonContextParser = __webpack_exports__.commonContextParser;
|
|
51
|
+
exports.createAgent = __webpack_exports__.createAgent;
|
|
52
|
+
exports.extractInsightParam = __webpack_exports__.extractInsightParam;
|
|
53
|
+
exports.getReportFileName = __webpack_exports__.getReportFileName;
|
|
54
|
+
exports.locateParamStr = __webpack_exports__.locateParamStr;
|
|
55
|
+
exports.paramStr = __webpack_exports__.paramStr;
|
|
56
|
+
exports.printReportMsg = __webpack_exports__.printReportMsg;
|
|
57
|
+
exports.taskTitleStr = __webpack_exports__.taskTitleStr;
|
|
58
|
+
exports.typeStr = __webpack_exports__.typeStr;
|
|
59
|
+
for(var __rspack_i in __webpack_exports__)if (-1 === [
|
|
60
|
+
"Agent",
|
|
61
|
+
"TaskCache",
|
|
62
|
+
"TaskExecutor",
|
|
63
|
+
"cacheFileExt",
|
|
64
|
+
"commonContextParser",
|
|
65
|
+
"createAgent",
|
|
66
|
+
"extractInsightParam",
|
|
67
|
+
"getReportFileName",
|
|
68
|
+
"locateParamStr",
|
|
69
|
+
"paramStr",
|
|
70
|
+
"printReportMsg",
|
|
71
|
+
"taskTitleStr",
|
|
72
|
+
"typeStr"
|
|
73
|
+
].indexOf(__rspack_i)) exports[__rspack_i] = __webpack_exports__[__rspack_i];
|
|
74
|
+
Object.defineProperty(exports, '__esModule', {
|
|
75
|
+
value: true
|
|
76
|
+
});
|
|
@@ -0,0 +1,380 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __webpack_require__ = {};
|
|
3
|
+
(()=>{
|
|
4
|
+
__webpack_require__.d = (exports1, definition)=>{
|
|
5
|
+
for(var key in definition)if (__webpack_require__.o(definition, key) && !__webpack_require__.o(exports1, key)) Object.defineProperty(exports1, key, {
|
|
6
|
+
enumerable: true,
|
|
7
|
+
get: definition[key]
|
|
8
|
+
});
|
|
9
|
+
};
|
|
10
|
+
})();
|
|
11
|
+
(()=>{
|
|
12
|
+
__webpack_require__.o = (obj, prop)=>Object.prototype.hasOwnProperty.call(obj, prop);
|
|
13
|
+
})();
|
|
14
|
+
(()=>{
|
|
15
|
+
__webpack_require__.r = (exports1)=>{
|
|
16
|
+
if ("u" > typeof Symbol && Symbol.toStringTag) Object.defineProperty(exports1, Symbol.toStringTag, {
|
|
17
|
+
value: 'Module'
|
|
18
|
+
});
|
|
19
|
+
Object.defineProperty(exports1, '__esModule', {
|
|
20
|
+
value: true
|
|
21
|
+
});
|
|
22
|
+
};
|
|
23
|
+
})();
|
|
24
|
+
var __webpack_exports__ = {};
|
|
25
|
+
__webpack_require__.r(__webpack_exports__);
|
|
26
|
+
__webpack_require__.d(__webpack_exports__, {
|
|
27
|
+
locatePlanForLocate: ()=>locatePlanForLocate,
|
|
28
|
+
TaskBuilder: ()=>TaskBuilder
|
|
29
|
+
});
|
|
30
|
+
const index_js_namespaceObject = require("../ai-model/index.js");
|
|
31
|
+
const external_task_timing_js_namespaceObject = require("../task-timing.js");
|
|
32
|
+
const external_types_js_namespaceObject = require("../types.js");
|
|
33
|
+
const external_utils_js_namespaceObject = require("../utils.js");
|
|
34
|
+
const extractor_namespaceObject = require("@godscene/shared/extractor");
|
|
35
|
+
const logger_namespaceObject = require("@godscene/shared/logger");
|
|
36
|
+
const utils_namespaceObject = require("@godscene/shared/utils");
|
|
37
|
+
const external_utils_js_namespaceObject_1 = require("./utils.js");
|
|
38
|
+
function _define_property(obj, key, value) {
|
|
39
|
+
if (key in obj) Object.defineProperty(obj, key, {
|
|
40
|
+
value: value,
|
|
41
|
+
enumerable: true,
|
|
42
|
+
configurable: true,
|
|
43
|
+
writable: true
|
|
44
|
+
});
|
|
45
|
+
else obj[key] = value;
|
|
46
|
+
return obj;
|
|
47
|
+
}
|
|
48
|
+
const debug = (0, logger_namespaceObject.getDebug)('agent:task-builder');
|
|
49
|
+
function hasNonEmptyCache(cache) {
|
|
50
|
+
return null != cache && 'object' == typeof cache && Object.keys(cache).length > 0;
|
|
51
|
+
}
|
|
52
|
+
function locatePlanForLocate(param) {
|
|
53
|
+
const locate = 'string' == typeof param ? {
|
|
54
|
+
prompt: param
|
|
55
|
+
} : param;
|
|
56
|
+
const locatePlan = {
|
|
57
|
+
type: 'Locate',
|
|
58
|
+
param: locate,
|
|
59
|
+
thought: ''
|
|
60
|
+
};
|
|
61
|
+
return locatePlan;
|
|
62
|
+
}
|
|
63
|
+
class TaskBuilder {
|
|
64
|
+
async build(plans, modelConfigForPlanning, modelConfigForDefaultIntent, options) {
|
|
65
|
+
const tasks = [];
|
|
66
|
+
const cacheable = options?.cacheable;
|
|
67
|
+
const context = {
|
|
68
|
+
tasks,
|
|
69
|
+
modelConfigForPlanning,
|
|
70
|
+
modelConfigForDefaultIntent,
|
|
71
|
+
cacheable,
|
|
72
|
+
deepLocate: options?.deepLocate,
|
|
73
|
+
abortSignal: options?.abortSignal
|
|
74
|
+
};
|
|
75
|
+
const planHandlers = new Map([
|
|
76
|
+
[
|
|
77
|
+
'Locate',
|
|
78
|
+
(plan)=>this.handleLocatePlan(plan, context)
|
|
79
|
+
],
|
|
80
|
+
[
|
|
81
|
+
'Finished',
|
|
82
|
+
(plan)=>this.handleFinishedPlan(plan, context)
|
|
83
|
+
]
|
|
84
|
+
]);
|
|
85
|
+
const defaultHandler = (plan)=>this.handleActionPlan(plan, context);
|
|
86
|
+
for (const plan of plans){
|
|
87
|
+
const handler = planHandlers.get(plan.type) ?? defaultHandler;
|
|
88
|
+
await handler(plan);
|
|
89
|
+
}
|
|
90
|
+
return {
|
|
91
|
+
tasks
|
|
92
|
+
};
|
|
93
|
+
}
|
|
94
|
+
handleFinishedPlan(plan, context) {
|
|
95
|
+
const taskActionFinished = {
|
|
96
|
+
type: 'Action Space',
|
|
97
|
+
subType: 'Finished',
|
|
98
|
+
param: null,
|
|
99
|
+
thought: plan.thought,
|
|
100
|
+
executor: async ()=>{}
|
|
101
|
+
};
|
|
102
|
+
context.tasks.push(taskActionFinished);
|
|
103
|
+
}
|
|
104
|
+
async handleLocatePlan(plan, context) {
|
|
105
|
+
const taskLocate = this.createLocateTask(plan, plan.param, context);
|
|
106
|
+
context.tasks.push(taskLocate);
|
|
107
|
+
}
|
|
108
|
+
async handleActionPlan(plan, context) {
|
|
109
|
+
const planType = plan.type;
|
|
110
|
+
const actionSpace = this.actionSpace;
|
|
111
|
+
const action = actionSpace.find((item)=>item.name === planType);
|
|
112
|
+
const param = plan.param;
|
|
113
|
+
if (!action) throw new Error(`Action type '${planType}' not found`);
|
|
114
|
+
const locateFields = action ? (0, index_js_namespaceObject.findAllMidsceneLocatorField)(action.paramSchema) : [];
|
|
115
|
+
const requiredLocateFields = action ? (0, index_js_namespaceObject.findAllMidsceneLocatorField)(action.paramSchema, true) : [];
|
|
116
|
+
locateFields.forEach((field)=>{
|
|
117
|
+
if (param[field]) {
|
|
118
|
+
const locatePlan = locatePlanForLocate(param[field]);
|
|
119
|
+
debug('will prepend locate param for field', `action.type=${planType}`, `param=${JSON.stringify(param[field])}`, `locatePlan=${JSON.stringify(locatePlan)}`, `hasBbox=${(0, external_utils_js_namespaceObject_1.ifPlanLocateParamIsBbox)(param[field])}`);
|
|
120
|
+
const locateTask = this.createLocateTask(locatePlan, param[field], context, (result)=>{
|
|
121
|
+
param[field] = result;
|
|
122
|
+
});
|
|
123
|
+
context.tasks.push(locateTask);
|
|
124
|
+
} else {
|
|
125
|
+
(0, utils_namespaceObject.assert)(!requiredLocateFields.includes(field), `Required locate field '${field}' is not provided for action ${planType}`);
|
|
126
|
+
debug(`field '${field}' is not provided for action ${planType}`);
|
|
127
|
+
}
|
|
128
|
+
});
|
|
129
|
+
const task = {
|
|
130
|
+
type: 'Action Space',
|
|
131
|
+
subType: planType,
|
|
132
|
+
thought: plan.thought,
|
|
133
|
+
param: plan.param,
|
|
134
|
+
executor: async (param, taskContext)=>{
|
|
135
|
+
const timing = taskContext.task.timing;
|
|
136
|
+
debug('executing action', planType, param, `taskContext.element.center: ${taskContext.element?.center}`);
|
|
137
|
+
const uiContext = taskContext.uiContext;
|
|
138
|
+
(0, utils_namespaceObject.assert)(uiContext, 'uiContext is required for Action task');
|
|
139
|
+
requiredLocateFields.forEach((field)=>{
|
|
140
|
+
(0, utils_namespaceObject.assert)(param[field], `field '${field}' is required for action ${planType} but not provided. Cannot execute action ${planType}.`);
|
|
141
|
+
});
|
|
142
|
+
(0, external_task_timing_js_namespaceObject.setTimingFieldOnce)(timing, 'beforeInvokeActionHookStart');
|
|
143
|
+
const delayBeforeRunner = action.delayBeforeRunner ?? 200;
|
|
144
|
+
try {
|
|
145
|
+
await Promise.all([
|
|
146
|
+
(async ()=>{
|
|
147
|
+
if (this.interface.beforeInvokeAction) {
|
|
148
|
+
debug(`will call "beforeInvokeAction" for interface with action name ${action.name}`);
|
|
149
|
+
await this.interface.beforeInvokeAction(action.name, param);
|
|
150
|
+
debug(`called "beforeInvokeAction" for interface with action name ${action.name}`);
|
|
151
|
+
}
|
|
152
|
+
})(),
|
|
153
|
+
delayBeforeRunner > 0 ? (0, external_utils_js_namespaceObject.sleep)(delayBeforeRunner) : Promise.resolve()
|
|
154
|
+
]);
|
|
155
|
+
} catch (originalError) {
|
|
156
|
+
const originalMessage = originalError?.message || String(originalError);
|
|
157
|
+
throw new Error(`error in running beforeInvokeAction for ${action.name}: ${originalMessage}`, {
|
|
158
|
+
cause: originalError
|
|
159
|
+
});
|
|
160
|
+
}
|
|
161
|
+
(0, external_task_timing_js_namespaceObject.setTimingFieldOnce)(timing, 'beforeInvokeActionHookEnd');
|
|
162
|
+
const { shrunkShotToLogicalRatio } = uiContext;
|
|
163
|
+
if (void 0 === shrunkShotToLogicalRatio) throw new Error('shrunkShotToLogicalRatio is not defined in Action task');
|
|
164
|
+
if (action.paramSchema) try {
|
|
165
|
+
param = (0, index_js_namespaceObject.parseActionParam)(param, action.paramSchema, {
|
|
166
|
+
shrunkShotToLogicalRatio
|
|
167
|
+
});
|
|
168
|
+
} catch (error) {
|
|
169
|
+
throw new Error(`Invalid parameters for action ${action.name}: ${error.message}\nParameters: ${JSON.stringify(param)}`, {
|
|
170
|
+
cause: error
|
|
171
|
+
});
|
|
172
|
+
}
|
|
173
|
+
(0, external_task_timing_js_namespaceObject.setTimingFieldOnce)(timing, 'callActionStart');
|
|
174
|
+
debug('calling action', action.name);
|
|
175
|
+
const actionFn = action.call.bind(this.interface);
|
|
176
|
+
const actionResult = await actionFn(param, taskContext);
|
|
177
|
+
(0, external_task_timing_js_namespaceObject.setTimingFieldOnce)(timing, 'callActionEnd');
|
|
178
|
+
debug('called action', action.name, 'result:', actionResult);
|
|
179
|
+
(0, external_task_timing_js_namespaceObject.setTimingFieldOnce)(timing, 'afterInvokeActionHookStart');
|
|
180
|
+
const delayAfterRunner = action.delayAfterRunner ?? this.waitAfterAction ?? 300;
|
|
181
|
+
if (delayAfterRunner > 0) await (0, external_utils_js_namespaceObject.sleep)(delayAfterRunner);
|
|
182
|
+
try {
|
|
183
|
+
if (this.interface.afterInvokeAction) {
|
|
184
|
+
debug(`will call "afterInvokeAction" for interface with action name ${action.name}`);
|
|
185
|
+
await this.interface.afterInvokeAction(action.name, param);
|
|
186
|
+
debug(`called "afterInvokeAction" for interface with action name ${action.name}`);
|
|
187
|
+
}
|
|
188
|
+
} catch (originalError) {
|
|
189
|
+
const originalMessage = originalError?.message || String(originalError);
|
|
190
|
+
throw new Error(`error in running afterInvokeAction for ${action.name}: ${originalMessage}`, {
|
|
191
|
+
cause: originalError
|
|
192
|
+
});
|
|
193
|
+
}
|
|
194
|
+
(0, external_task_timing_js_namespaceObject.setTimingFieldOnce)(timing, 'afterInvokeActionHookEnd');
|
|
195
|
+
return {
|
|
196
|
+
output: actionResult
|
|
197
|
+
};
|
|
198
|
+
}
|
|
199
|
+
};
|
|
200
|
+
context.tasks.push(task);
|
|
201
|
+
}
|
|
202
|
+
createLocateTask(plan, detailedLocateParam, context, onResult) {
|
|
203
|
+
const { cacheable, modelConfigForDefaultIntent, deepLocate, abortSignal } = context;
|
|
204
|
+
let locateParam = detailedLocateParam;
|
|
205
|
+
if ('string' == typeof locateParam) locateParam = {
|
|
206
|
+
prompt: locateParam
|
|
207
|
+
};
|
|
208
|
+
if (void 0 !== cacheable) locateParam = {
|
|
209
|
+
...locateParam,
|
|
210
|
+
cacheable
|
|
211
|
+
};
|
|
212
|
+
if (deepLocate && !locateParam.deepLocate) locateParam = {
|
|
213
|
+
...locateParam,
|
|
214
|
+
deepLocate: true
|
|
215
|
+
};
|
|
216
|
+
const taskLocator = {
|
|
217
|
+
type: 'Planning',
|
|
218
|
+
subType: 'Locate',
|
|
219
|
+
param: locateParam,
|
|
220
|
+
thought: plan.thought,
|
|
221
|
+
executor: async (param, taskContext)=>{
|
|
222
|
+
const { task } = taskContext;
|
|
223
|
+
let { uiContext } = taskContext;
|
|
224
|
+
(0, utils_namespaceObject.assert)(param?.prompt || param?.bbox, `No prompt or id or position or bbox to locate, param=${JSON.stringify(param)}`);
|
|
225
|
+
if (!uiContext) uiContext = await this.service.contextRetrieverFn();
|
|
226
|
+
(0, utils_namespaceObject.assert)(uiContext, 'uiContext is required for Service task');
|
|
227
|
+
const { shrunkShotToLogicalRatio } = uiContext;
|
|
228
|
+
if (void 0 === shrunkShotToLogicalRatio) throw new Error('shrunkShotToLogicalRatio is not defined in locate task');
|
|
229
|
+
let locateDump;
|
|
230
|
+
let locateResult;
|
|
231
|
+
const applyDump = (dump)=>{
|
|
232
|
+
if (!dump) return;
|
|
233
|
+
locateDump = dump;
|
|
234
|
+
task.log = {
|
|
235
|
+
dump,
|
|
236
|
+
rawResponse: dump.taskInfo?.rawResponse
|
|
237
|
+
};
|
|
238
|
+
task.usage = dump.taskInfo?.usage;
|
|
239
|
+
if (dump.taskInfo?.searchAreaUsage) task.searchAreaUsage = dump.taskInfo.searchAreaUsage;
|
|
240
|
+
if (dump.taskInfo?.reasoning_content) task.reasoning_content = dump.taskInfo.reasoning_content;
|
|
241
|
+
};
|
|
242
|
+
const planLocatedElement = (0, external_utils_js_namespaceObject_1.ifPlanLocateParamIsBbox)(param) ? (0, external_utils_js_namespaceObject_1.matchElementFromPlan)(param) : void 0;
|
|
243
|
+
const elementFromBbox = param.deepLocate ? void 0 : planLocatedElement;
|
|
244
|
+
const isPlanHit = !!elementFromBbox;
|
|
245
|
+
let rectFromXpath;
|
|
246
|
+
if (!isPlanHit && param.xpath && this.interface.rectMatchesCacheFeature) try {
|
|
247
|
+
rectFromXpath = await this.interface.rectMatchesCacheFeature({
|
|
248
|
+
xpaths: [
|
|
249
|
+
param.xpath
|
|
250
|
+
]
|
|
251
|
+
});
|
|
252
|
+
} catch {}
|
|
253
|
+
const elementFromXpath = rectFromXpath ? (0, extractor_namespaceObject.generateElementByRect)((0, external_utils_js_namespaceObject_1.transformLogicalRectToScreenshotRect)(rectFromXpath, shrunkShotToLogicalRatio), 'string' == typeof param.prompt ? param.prompt : param.prompt?.prompt || '') : void 0;
|
|
254
|
+
const isXpathHit = !!elementFromXpath;
|
|
255
|
+
const cachePrompt = param.prompt;
|
|
256
|
+
const locateCacheRecord = this.taskCache?.matchLocateCache(cachePrompt);
|
|
257
|
+
const cacheEntry = locateCacheRecord?.cacheContent?.cache;
|
|
258
|
+
const elementFromCacheResult = isPlanHit || isXpathHit ? null : await (0, external_utils_js_namespaceObject_1.matchElementFromCache)({
|
|
259
|
+
taskCache: this.taskCache,
|
|
260
|
+
interfaceInstance: this.interface
|
|
261
|
+
}, cacheEntry, cachePrompt, param.cacheable);
|
|
262
|
+
const elementFromCache = elementFromCacheResult ? (0, external_utils_js_namespaceObject_1.transformLogicalElementToScreenshot)(elementFromCacheResult, shrunkShotToLogicalRatio) : void 0;
|
|
263
|
+
const isCacheHit = !!elementFromCache;
|
|
264
|
+
let elementFromAiLocate;
|
|
265
|
+
const timing = taskContext.task.timing;
|
|
266
|
+
if (!isXpathHit && !isCacheHit && !isPlanHit) try {
|
|
267
|
+
(0, external_task_timing_js_namespaceObject.setTimingFieldOnce)(timing, 'callAiStart');
|
|
268
|
+
locateResult = await this.service.locate(param, {
|
|
269
|
+
context: uiContext,
|
|
270
|
+
planLocatedElement
|
|
271
|
+
}, modelConfigForDefaultIntent, abortSignal);
|
|
272
|
+
applyDump(locateResult.dump);
|
|
273
|
+
elementFromAiLocate = locateResult.element;
|
|
274
|
+
} catch (error) {
|
|
275
|
+
if (error instanceof external_types_js_namespaceObject.ServiceError) applyDump(error.dump);
|
|
276
|
+
throw error;
|
|
277
|
+
} finally{
|
|
278
|
+
(0, external_task_timing_js_namespaceObject.setTimingFieldOnce)(timing, 'callAiEnd');
|
|
279
|
+
}
|
|
280
|
+
const element = elementFromBbox || elementFromXpath || elementFromCache || elementFromAiLocate;
|
|
281
|
+
const locateCacheAlreadyExists = hasNonEmptyCache(locateCacheRecord?.cacheContent?.cache);
|
|
282
|
+
let currentCacheEntry;
|
|
283
|
+
if (element && this.taskCache && !isCacheHit && (!isPlanHit || !locateCacheAlreadyExists) && param?.cacheable !== false) if (this.interface.cacheFeatureForPoint) try {
|
|
284
|
+
let pointForCache = element.center;
|
|
285
|
+
if (1 !== shrunkShotToLogicalRatio) {
|
|
286
|
+
pointForCache = [
|
|
287
|
+
Math.round(element.center[0] / shrunkShotToLogicalRatio),
|
|
288
|
+
Math.round(element.center[1] / shrunkShotToLogicalRatio)
|
|
289
|
+
];
|
|
290
|
+
debug('Transformed coordinates for cacheFeatureForPoint: %o -> %o', element.center, pointForCache);
|
|
291
|
+
}
|
|
292
|
+
const feature = await this.interface.cacheFeatureForPoint(pointForCache, {
|
|
293
|
+
targetDescription: 'string' == typeof param.prompt ? param.prompt : param.prompt?.prompt,
|
|
294
|
+
modelConfig: modelConfigForDefaultIntent
|
|
295
|
+
});
|
|
296
|
+
if (hasNonEmptyCache(feature)) {
|
|
297
|
+
debug('update cache, prompt: %s, cache: %o', cachePrompt, feature);
|
|
298
|
+
currentCacheEntry = feature;
|
|
299
|
+
this.taskCache.updateOrAppendCacheRecord({
|
|
300
|
+
type: 'locate',
|
|
301
|
+
prompt: cachePrompt,
|
|
302
|
+
cache: feature
|
|
303
|
+
}, locateCacheRecord);
|
|
304
|
+
} else debug('no cache data returned, skip cache update, prompt: %s', cachePrompt);
|
|
305
|
+
} catch (error) {
|
|
306
|
+
debug('cacheFeatureForPoint failed: %s', error);
|
|
307
|
+
}
|
|
308
|
+
else debug('cacheFeatureForPoint is not supported, skip cache update');
|
|
309
|
+
if (!element) {
|
|
310
|
+
if (locateDump) throw new external_types_js_namespaceObject.ServiceError(`Element not found : ${param.prompt}`, locateDump);
|
|
311
|
+
throw new Error(`Element not found: ${param.prompt}`);
|
|
312
|
+
}
|
|
313
|
+
let hitBy;
|
|
314
|
+
if (isPlanHit) hitBy = {
|
|
315
|
+
from: 'Plan',
|
|
316
|
+
context: {
|
|
317
|
+
bbox: param.bbox
|
|
318
|
+
}
|
|
319
|
+
};
|
|
320
|
+
else if (isXpathHit) hitBy = {
|
|
321
|
+
from: 'User expected path',
|
|
322
|
+
context: {
|
|
323
|
+
xpath: param.xpath
|
|
324
|
+
}
|
|
325
|
+
};
|
|
326
|
+
else if (isCacheHit) hitBy = {
|
|
327
|
+
from: 'Cache',
|
|
328
|
+
context: {
|
|
329
|
+
cacheEntry,
|
|
330
|
+
cacheToSave: currentCacheEntry
|
|
331
|
+
}
|
|
332
|
+
};
|
|
333
|
+
if (this.interface.getElementFromPoint && element.center) try {
|
|
334
|
+
const [x, y] = element.center;
|
|
335
|
+
const data = await this.interface.getElementFromPoint({
|
|
336
|
+
x,
|
|
337
|
+
y
|
|
338
|
+
});
|
|
339
|
+
element.allPaths = data?.allPaths || [];
|
|
340
|
+
element.containerPaths = data?.containerPaths || [];
|
|
341
|
+
} catch (error) {
|
|
342
|
+
element.allPaths = [];
|
|
343
|
+
element.containerPaths = [];
|
|
344
|
+
}
|
|
345
|
+
onResult?.(element);
|
|
346
|
+
return {
|
|
347
|
+
output: {
|
|
348
|
+
element: {
|
|
349
|
+
...element,
|
|
350
|
+
dpr: uiContext.deprecatedDpr
|
|
351
|
+
}
|
|
352
|
+
},
|
|
353
|
+
hitBy
|
|
354
|
+
};
|
|
355
|
+
}
|
|
356
|
+
};
|
|
357
|
+
return taskLocator;
|
|
358
|
+
}
|
|
359
|
+
constructor({ interfaceInstance, service, taskCache, actionSpace, waitAfterAction }){
|
|
360
|
+
_define_property(this, "interface", void 0);
|
|
361
|
+
_define_property(this, "service", void 0);
|
|
362
|
+
_define_property(this, "taskCache", void 0);
|
|
363
|
+
_define_property(this, "actionSpace", void 0);
|
|
364
|
+
_define_property(this, "waitAfterAction", void 0);
|
|
365
|
+
this.interface = interfaceInstance;
|
|
366
|
+
this.service = service;
|
|
367
|
+
this.taskCache = taskCache;
|
|
368
|
+
this.actionSpace = actionSpace;
|
|
369
|
+
this.waitAfterAction = waitAfterAction;
|
|
370
|
+
}
|
|
371
|
+
}
|
|
372
|
+
exports.TaskBuilder = __webpack_exports__.TaskBuilder;
|
|
373
|
+
exports.locatePlanForLocate = __webpack_exports__.locatePlanForLocate;
|
|
374
|
+
for(var __rspack_i in __webpack_exports__)if (-1 === [
|
|
375
|
+
"TaskBuilder",
|
|
376
|
+
"locatePlanForLocate"
|
|
377
|
+
].indexOf(__rspack_i)) exports[__rspack_i] = __webpack_exports__[__rspack_i];
|
|
378
|
+
Object.defineProperty(exports, '__esModule', {
|
|
379
|
+
value: true
|
|
380
|
+
});
|