@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,93 @@
|
|
|
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
|
+
AI_CALL_HARD_TIMEOUT_CODE: ()=>AI_CALL_HARD_TIMEOUT_CODE,
|
|
28
|
+
DEFAULT_AI_CALL_TIMEOUT_MS: ()=>DEFAULT_AI_CALL_TIMEOUT_MS,
|
|
29
|
+
buildRequestAbortSignal: ()=>buildRequestAbortSignal,
|
|
30
|
+
isHardTimeoutError: ()=>isHardTimeoutError,
|
|
31
|
+
resolveEffectiveTimeoutMs: ()=>resolveEffectiveTimeoutMs
|
|
32
|
+
});
|
|
33
|
+
const DEFAULT_AI_CALL_TIMEOUT_MS = 180000;
|
|
34
|
+
const AI_CALL_HARD_TIMEOUT_CODE = 'AI_CALL_HARD_TIMEOUT';
|
|
35
|
+
function resolveEffectiveTimeoutMs(modelConfig) {
|
|
36
|
+
const { timeout } = modelConfig;
|
|
37
|
+
if ('number' != typeof timeout) return DEFAULT_AI_CALL_TIMEOUT_MS;
|
|
38
|
+
if (timeout <= 0) return null;
|
|
39
|
+
return timeout;
|
|
40
|
+
}
|
|
41
|
+
function isHardTimeoutError(err) {
|
|
42
|
+
if (!err || 'object' != typeof err) return false;
|
|
43
|
+
const code = err.code;
|
|
44
|
+
if (code === AI_CALL_HARD_TIMEOUT_CODE) return true;
|
|
45
|
+
const cause = err.cause;
|
|
46
|
+
if (cause && 'object' == typeof cause && cause.code === AI_CALL_HARD_TIMEOUT_CODE) return true;
|
|
47
|
+
return false;
|
|
48
|
+
}
|
|
49
|
+
function buildRequestAbortSignal(timeoutMs, userSignal) {
|
|
50
|
+
const controller = new AbortController();
|
|
51
|
+
if (userSignal?.aborted) {
|
|
52
|
+
controller.abort(userSignal.reason);
|
|
53
|
+
return {
|
|
54
|
+
signal: controller.signal,
|
|
55
|
+
cleanup: ()=>{}
|
|
56
|
+
};
|
|
57
|
+
}
|
|
58
|
+
let timer;
|
|
59
|
+
if (null !== timeoutMs) {
|
|
60
|
+
timer = setTimeout(()=>{
|
|
61
|
+
const err = new Error(`AI call hard timeout after ${timeoutMs}ms (full request time exceeded)`);
|
|
62
|
+
err.code = AI_CALL_HARD_TIMEOUT_CODE;
|
|
63
|
+
controller.abort(err);
|
|
64
|
+
}, timeoutMs);
|
|
65
|
+
if ('function' == typeof timer.unref) timer.unref();
|
|
66
|
+
}
|
|
67
|
+
const onUserAbort = userSignal ? ()=>controller.abort(userSignal.reason) : void 0;
|
|
68
|
+
if (userSignal && onUserAbort) userSignal.addEventListener('abort', onUserAbort, {
|
|
69
|
+
once: true
|
|
70
|
+
});
|
|
71
|
+
return {
|
|
72
|
+
signal: controller.signal,
|
|
73
|
+
cleanup: ()=>{
|
|
74
|
+
if (timer) clearTimeout(timer);
|
|
75
|
+
if (userSignal && onUserAbort) userSignal.removeEventListener('abort', onUserAbort);
|
|
76
|
+
}
|
|
77
|
+
};
|
|
78
|
+
}
|
|
79
|
+
exports.AI_CALL_HARD_TIMEOUT_CODE = __webpack_exports__.AI_CALL_HARD_TIMEOUT_CODE;
|
|
80
|
+
exports.DEFAULT_AI_CALL_TIMEOUT_MS = __webpack_exports__.DEFAULT_AI_CALL_TIMEOUT_MS;
|
|
81
|
+
exports.buildRequestAbortSignal = __webpack_exports__.buildRequestAbortSignal;
|
|
82
|
+
exports.isHardTimeoutError = __webpack_exports__.isHardTimeoutError;
|
|
83
|
+
exports.resolveEffectiveTimeoutMs = __webpack_exports__.resolveEffectiveTimeoutMs;
|
|
84
|
+
for(var __rspack_i in __webpack_exports__)if (-1 === [
|
|
85
|
+
"AI_CALL_HARD_TIMEOUT_CODE",
|
|
86
|
+
"DEFAULT_AI_CALL_TIMEOUT_MS",
|
|
87
|
+
"buildRequestAbortSignal",
|
|
88
|
+
"isHardTimeoutError",
|
|
89
|
+
"resolveEffectiveTimeoutMs"
|
|
90
|
+
].indexOf(__rspack_i)) exports[__rspack_i] = __webpack_exports__[__rspack_i];
|
|
91
|
+
Object.defineProperty(exports, '__esModule', {
|
|
92
|
+
value: true
|
|
93
|
+
});
|
|
@@ -0,0 +1,281 @@
|
|
|
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
|
+
uiTarsPlanning: ()=>uiTarsPlanning
|
|
28
|
+
});
|
|
29
|
+
const logger_namespaceObject = require("@godscene/shared/logger");
|
|
30
|
+
const us_keyboard_layout_namespaceObject = require("@godscene/shared/us-keyboard-layout");
|
|
31
|
+
const utils_namespaceObject = require("@godscene/shared/utils");
|
|
32
|
+
const action_parser_namespaceObject = require("@ui-tars/action-parser");
|
|
33
|
+
const ui_tars_planning_js_namespaceObject = require("./prompt/ui-tars-planning.js");
|
|
34
|
+
const index_js_namespaceObject = require("./service-caller/index.js");
|
|
35
|
+
const debug = (0, logger_namespaceObject.getDebug)('ui-tars-planning');
|
|
36
|
+
const warnLog = (0, logger_namespaceObject.getDebug)('ui-tars-planning', {
|
|
37
|
+
console: true
|
|
38
|
+
});
|
|
39
|
+
const bboxSize = 10;
|
|
40
|
+
const pointToBbox = (point, width, height)=>[
|
|
41
|
+
Math.round(Math.max(point.x - bboxSize / 2, 0)),
|
|
42
|
+
Math.round(Math.max(point.y - bboxSize / 2, 0)),
|
|
43
|
+
Math.round(Math.min(point.x + bboxSize / 2, width)),
|
|
44
|
+
Math.round(Math.min(point.y + bboxSize / 2, height))
|
|
45
|
+
];
|
|
46
|
+
async function uiTarsPlanning(userInstruction, options) {
|
|
47
|
+
const { conversationHistory, context, modelConfig, actionContext } = options;
|
|
48
|
+
const { uiTarsModelVersion } = modelConfig;
|
|
49
|
+
let instruction = userInstruction;
|
|
50
|
+
if (actionContext) instruction = `<high_priority_knowledge>${actionContext}</high_priority_knowledge>\n<user_instruction>${userInstruction}</user_instruction>`;
|
|
51
|
+
const systemPrompt = (0, ui_tars_planning_js_namespaceObject.getUiTarsPlanningPrompt)() + instruction;
|
|
52
|
+
const screenshotBase64 = context.screenshot.base64;
|
|
53
|
+
conversationHistory.append({
|
|
54
|
+
role: 'user',
|
|
55
|
+
content: [
|
|
56
|
+
{
|
|
57
|
+
type: 'image_url',
|
|
58
|
+
image_url: {
|
|
59
|
+
url: screenshotBase64
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
]
|
|
63
|
+
});
|
|
64
|
+
const res = await (0, index_js_namespaceObject.callAIWithStringResponse)([
|
|
65
|
+
{
|
|
66
|
+
role: 'user',
|
|
67
|
+
content: systemPrompt
|
|
68
|
+
},
|
|
69
|
+
...conversationHistory.snapshot()
|
|
70
|
+
], modelConfig, {
|
|
71
|
+
abortSignal: options.abortSignal
|
|
72
|
+
});
|
|
73
|
+
let convertedText;
|
|
74
|
+
let parsed;
|
|
75
|
+
try {
|
|
76
|
+
convertedText = convertBboxToCoordinates(res.content);
|
|
77
|
+
const { shotSize } = context;
|
|
78
|
+
const parseResult = (0, action_parser_namespaceObject.actionParser)({
|
|
79
|
+
prediction: convertedText,
|
|
80
|
+
factor: [
|
|
81
|
+
1000,
|
|
82
|
+
1000
|
|
83
|
+
],
|
|
84
|
+
screenContext: {
|
|
85
|
+
width: shotSize.width,
|
|
86
|
+
height: shotSize.height
|
|
87
|
+
},
|
|
88
|
+
modelVer: uiTarsModelVersion
|
|
89
|
+
});
|
|
90
|
+
parsed = parseResult.parsed;
|
|
91
|
+
} catch (parseError) {
|
|
92
|
+
const errorMessage = parseError instanceof Error ? parseError.message : String(parseError);
|
|
93
|
+
throw new index_js_namespaceObject.AIResponseParseError(`Parse error: ${errorMessage}`, JSON.stringify(res.content, void 0, 2), res.usage);
|
|
94
|
+
}
|
|
95
|
+
const { shotSize } = context;
|
|
96
|
+
debug('ui-tars modelVer', uiTarsModelVersion, ', parsed', JSON.stringify(parsed));
|
|
97
|
+
const transformActions = [];
|
|
98
|
+
const unhandledActions = [];
|
|
99
|
+
let shouldContinue = true;
|
|
100
|
+
parsed.forEach((action)=>{
|
|
101
|
+
const actionType = (action.action_type || '').toLowerCase();
|
|
102
|
+
if ('click' === actionType) {
|
|
103
|
+
(0, utils_namespaceObject.assert)(action.action_inputs.start_box, 'start_box is required');
|
|
104
|
+
const point = getPoint(action.action_inputs.start_box, shotSize);
|
|
105
|
+
const locate = {
|
|
106
|
+
prompt: action.thought || '',
|
|
107
|
+
bbox: pointToBbox({
|
|
108
|
+
x: point[0],
|
|
109
|
+
y: point[1]
|
|
110
|
+
}, shotSize.width, shotSize.height)
|
|
111
|
+
};
|
|
112
|
+
transformActions.push({
|
|
113
|
+
type: 'Tap',
|
|
114
|
+
param: {
|
|
115
|
+
locate: locate
|
|
116
|
+
}
|
|
117
|
+
});
|
|
118
|
+
} else if ('left_double' === actionType) {
|
|
119
|
+
(0, utils_namespaceObject.assert)(action.action_inputs.start_box, 'start_box is required');
|
|
120
|
+
const point = getPoint(action.action_inputs.start_box, shotSize);
|
|
121
|
+
const locate = {
|
|
122
|
+
prompt: action.thought || '',
|
|
123
|
+
bbox: pointToBbox({
|
|
124
|
+
x: point[0],
|
|
125
|
+
y: point[1]
|
|
126
|
+
}, shotSize.width, shotSize.height)
|
|
127
|
+
};
|
|
128
|
+
transformActions.push({
|
|
129
|
+
type: 'DoubleClick',
|
|
130
|
+
param: {
|
|
131
|
+
locate: locate
|
|
132
|
+
},
|
|
133
|
+
thought: action.thought || ''
|
|
134
|
+
});
|
|
135
|
+
} else if ('right_single' === actionType) {
|
|
136
|
+
(0, utils_namespaceObject.assert)(action.action_inputs.start_box, 'start_box is required');
|
|
137
|
+
const point = getPoint(action.action_inputs.start_box, shotSize);
|
|
138
|
+
const locate = {
|
|
139
|
+
prompt: action.thought || '',
|
|
140
|
+
bbox: pointToBbox({
|
|
141
|
+
x: point[0],
|
|
142
|
+
y: point[1]
|
|
143
|
+
}, shotSize.width, shotSize.height)
|
|
144
|
+
};
|
|
145
|
+
transformActions.push({
|
|
146
|
+
type: 'RightClick',
|
|
147
|
+
param: {
|
|
148
|
+
locate: locate
|
|
149
|
+
},
|
|
150
|
+
thought: action.thought || ''
|
|
151
|
+
});
|
|
152
|
+
} else if ('drag' === actionType) {
|
|
153
|
+
(0, utils_namespaceObject.assert)(action.action_inputs.start_box, 'start_box is required');
|
|
154
|
+
(0, utils_namespaceObject.assert)(action.action_inputs.end_box, 'end_box is required');
|
|
155
|
+
const startPoint = getPoint(action.action_inputs.start_box, shotSize);
|
|
156
|
+
const endPoint = getPoint(action.action_inputs.end_box, shotSize);
|
|
157
|
+
transformActions.push({
|
|
158
|
+
type: 'DragAndDrop',
|
|
159
|
+
param: {
|
|
160
|
+
from: {
|
|
161
|
+
prompt: action.thought || '',
|
|
162
|
+
bbox: pointToBbox({
|
|
163
|
+
x: startPoint[0],
|
|
164
|
+
y: startPoint[1]
|
|
165
|
+
}, shotSize.width, shotSize.height)
|
|
166
|
+
},
|
|
167
|
+
to: {
|
|
168
|
+
prompt: action.thought || '',
|
|
169
|
+
bbox: pointToBbox({
|
|
170
|
+
x: endPoint[0],
|
|
171
|
+
y: endPoint[1]
|
|
172
|
+
}, shotSize.width, shotSize.height)
|
|
173
|
+
}
|
|
174
|
+
},
|
|
175
|
+
thought: action.thought || ''
|
|
176
|
+
});
|
|
177
|
+
} else if ('type' === actionType) transformActions.push({
|
|
178
|
+
type: 'Input',
|
|
179
|
+
param: {
|
|
180
|
+
value: action.action_inputs.content
|
|
181
|
+
},
|
|
182
|
+
thought: action.thought || ''
|
|
183
|
+
});
|
|
184
|
+
else if ('scroll' === actionType) transformActions.push({
|
|
185
|
+
type: 'Scroll',
|
|
186
|
+
param: {
|
|
187
|
+
direction: action.action_inputs.direction
|
|
188
|
+
},
|
|
189
|
+
thought: action.thought || ''
|
|
190
|
+
});
|
|
191
|
+
else if ('finished' === actionType) {
|
|
192
|
+
shouldContinue = false;
|
|
193
|
+
transformActions.push({
|
|
194
|
+
type: 'Finished',
|
|
195
|
+
param: {},
|
|
196
|
+
thought: action.thought || ''
|
|
197
|
+
});
|
|
198
|
+
} else if ('hotkey' === actionType) if (action.action_inputs.key) {
|
|
199
|
+
const keys = (0, us_keyboard_layout_namespaceObject.transformHotkeyInput)(action.action_inputs.key);
|
|
200
|
+
transformActions.push({
|
|
201
|
+
type: 'KeyboardPress',
|
|
202
|
+
param: {
|
|
203
|
+
keyName: keys.join('+')
|
|
204
|
+
},
|
|
205
|
+
thought: action.thought || ''
|
|
206
|
+
});
|
|
207
|
+
} else warnLog('No key found in action: hotkey. Will not perform action.');
|
|
208
|
+
else if ('wait' === actionType) transformActions.push({
|
|
209
|
+
type: 'Sleep',
|
|
210
|
+
param: {
|
|
211
|
+
timeMs: 1000
|
|
212
|
+
},
|
|
213
|
+
thought: action.thought || ''
|
|
214
|
+
});
|
|
215
|
+
else if (actionType) {
|
|
216
|
+
unhandledActions.push({
|
|
217
|
+
type: actionType,
|
|
218
|
+
thought: action.thought || ''
|
|
219
|
+
});
|
|
220
|
+
debug('Unhandled action type:', actionType, 'thought:', action.thought);
|
|
221
|
+
}
|
|
222
|
+
});
|
|
223
|
+
if (0 === transformActions.length) {
|
|
224
|
+
const errorDetails = [];
|
|
225
|
+
if (0 === parsed.length) {
|
|
226
|
+
errorDetails.push('Action parser returned no actions');
|
|
227
|
+
if (res.content.includes('Thought:') && !res.content.includes('Action:')) errorDetails.push('Response contains "Thought:" but missing "Action:" line');
|
|
228
|
+
else errorDetails.push('Response may be malformed or empty');
|
|
229
|
+
}
|
|
230
|
+
if (unhandledActions.length > 0) {
|
|
231
|
+
const types = unhandledActions.map((a)=>a.type).join(', ');
|
|
232
|
+
errorDetails.push(`Unhandled action types: ${types}`);
|
|
233
|
+
}
|
|
234
|
+
const errorMessage = [
|
|
235
|
+
'No actions found in UI-TARS response.',
|
|
236
|
+
...errorDetails
|
|
237
|
+
].join('\n');
|
|
238
|
+
throw new index_js_namespaceObject.AIResponseParseError(errorMessage, JSON.stringify(res.content, void 0, 2), res.usage);
|
|
239
|
+
}
|
|
240
|
+
debug('transformActions', JSON.stringify(transformActions, null, 2));
|
|
241
|
+
const log = (0, ui_tars_planning_js_namespaceObject.getSummary)(res.content);
|
|
242
|
+
conversationHistory.append({
|
|
243
|
+
role: 'assistant',
|
|
244
|
+
content: log
|
|
245
|
+
});
|
|
246
|
+
return {
|
|
247
|
+
actions: transformActions,
|
|
248
|
+
log,
|
|
249
|
+
usage: res.usage,
|
|
250
|
+
rawResponse: JSON.stringify(res.content, void 0, 2),
|
|
251
|
+
shouldContinuePlanning: shouldContinue
|
|
252
|
+
};
|
|
253
|
+
}
|
|
254
|
+
function convertBboxToCoordinates(text) {
|
|
255
|
+
const pattern = /<bbox>(\d+)\s+(\d+)\s+(\d+)\s+(\d+)<\/bbox>/g;
|
|
256
|
+
function replaceMatch(match, x1, y1, x2, y2) {
|
|
257
|
+
const x1Num = Number.parseInt(x1, 10);
|
|
258
|
+
const y1Num = Number.parseInt(y1, 10);
|
|
259
|
+
const x2Num = Number.parseInt(x2, 10);
|
|
260
|
+
const y2Num = Number.parseInt(y2, 10);
|
|
261
|
+
const x = Math.floor((x1Num + x2Num) / 2);
|
|
262
|
+
const y = Math.floor((y1Num + y2Num) / 2);
|
|
263
|
+
return `(${x},${y})`;
|
|
264
|
+
}
|
|
265
|
+
const cleanedText = text.replace(/\[EOS\]/g, '');
|
|
266
|
+
return cleanedText.replace(pattern, replaceMatch).trim();
|
|
267
|
+
}
|
|
268
|
+
function getPoint(startBox, size) {
|
|
269
|
+
const [x, y] = JSON.parse(startBox);
|
|
270
|
+
return [
|
|
271
|
+
x * size.width,
|
|
272
|
+
y * size.height
|
|
273
|
+
];
|
|
274
|
+
}
|
|
275
|
+
exports.uiTarsPlanning = __webpack_exports__.uiTarsPlanning;
|
|
276
|
+
for(var __rspack_i in __webpack_exports__)if (-1 === [
|
|
277
|
+
"uiTarsPlanning"
|
|
278
|
+
].indexOf(__rspack_i)) exports[__rspack_i] = __webpack_exports__[__rspack_i];
|
|
279
|
+
Object.defineProperty(exports, '__esModule', {
|
|
280
|
+
value: true
|
|
281
|
+
});
|