@autotest/agent 0.0.1 → 0.0.3
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/README.md +43 -27
- package/dist/api/agent_api.d.ts +1 -1
- package/dist/api/agent_api.js +555 -0
- package/dist/api/autotest_agent.d.ts +0 -1
- package/dist/api/autotest_agent.js +205 -0
- package/dist/api/types.d.ts +0 -1
- package/dist/api/types.js +11 -0
- package/dist/autotest-cli.d.ts +1 -1
- package/dist/autotest-cli.js +391 -0
- package/dist/common/case_manager.d.ts +0 -1
- package/dist/common/case_manager.js +91 -0
- package/dist/common/collect_case.d.ts +0 -1
- package/dist/common/collect_case.js +128 -0
- package/dist/common/common_errors.d.ts +0 -1
- package/dist/common/common_errors.js +66 -0
- package/dist/common/config/config_validator.d.ts +0 -1
- package/dist/common/config/config_validator.js +28 -0
- package/dist/common/config/manager.d.ts +0 -1
- package/dist/common/config/manager.js +257 -0
- package/dist/common/config/output.d.ts +0 -1
- package/dist/common/config/output.js +59 -0
- package/dist/common/config/types.d.ts +2243 -2244
- package/dist/common/config/types.js +184 -0
- package/dist/common/dfx/client_factory.d.ts +0 -1
- package/dist/common/dfx/client_factory.js +62 -0
- package/dist/common/dfx/context.d.ts +0 -1
- package/dist/common/dfx/context.js +23 -0
- package/dist/common/dfx/index.d.ts +0 -1
- package/dist/common/dfx/index.js +15 -0
- package/dist/common/dfx/recorder.d.ts +0 -1
- package/dist/common/dfx/recorder.js +191 -0
- package/dist/common/dfx/recording_fetch.d.ts +0 -1
- package/dist/common/dfx/recording_fetch.js +228 -0
- package/dist/common/dfx/source.d.ts +0 -1
- package/dist/common/dfx/source.js +13 -0
- package/dist/common/image_cacher.d.ts +0 -1
- package/dist/common/image_cacher.js +36 -0
- package/dist/common/image_helper.d.ts +0 -1
- package/dist/common/image_helper.js +128 -0
- package/dist/common/image_similarity.d.ts +0 -1
- package/dist/common/image_similarity.js +171 -0
- package/dist/common/llm_cache/cache_transport.d.ts +2 -1
- package/dist/common/llm_cache/cache_transport.js +102 -0
- package/dist/common/llm_cache/prompt_cache.d.ts +53 -0
- package/dist/common/llm_cache/prompt_cache.js +113 -0
- package/dist/common/logger.d.ts +0 -1
- package/dist/common/logger.js +158 -0
- package/dist/common/model/custom_model.d.ts +0 -1
- package/dist/common/model/custom_model.js +467 -0
- package/dist/common/model/index.d.ts +0 -1
- package/dist/common/model/index.js +5 -0
- package/dist/common/path_utils.d.ts +0 -1
- package/dist/common/path_utils.js +81 -0
- package/dist/common/result_parser.d.ts +0 -1
- package/dist/common/result_parser.js +49 -0
- package/dist/common/usage/token_usage.d.ts +0 -1
- package/dist/common/usage/token_usage.js +117 -0
- package/dist/common/utils.d.ts +0 -1
- package/dist/common/utils.js +125 -0
- package/dist/core/agent/layered_agent/ability_helper.d.ts +0 -1
- package/dist/core/agent/layered_agent/ability_helper.js +125 -0
- package/dist/core/agent/layered_agent/agent.d.ts +0 -1
- package/dist/core/agent/layered_agent/agent.js +37 -0
- package/dist/core/agent/layered_agent/agent_registry.d.ts +0 -1
- package/dist/core/agent/layered_agent/agent_registry.js +75 -0
- package/dist/core/agent/layered_agent/decision.d.ts +0 -1
- package/dist/core/agent/layered_agent/decision.js +478 -0
- package/dist/core/agent/layered_agent/execute_agent/action_handler.d.ts +0 -1
- package/dist/core/agent/layered_agent/execute_agent/action_handler.js +155 -0
- package/dist/core/agent/layered_agent/execute_agent/agent_factory.d.ts +1 -2
- package/dist/core/agent/layered_agent/execute_agent/agent_factory.js +41 -0
- package/dist/core/agent/layered_agent/execute_agent/base_agent.d.ts +0 -1
- package/dist/core/agent/layered_agent/execute_agent/base_agent.js +112 -0
- package/dist/core/agent/layered_agent/execute_agent/general_agent.d.ts +0 -1
- package/dist/core/agent/layered_agent/execute_agent/general_agent.js +207 -0
- package/dist/core/agent/layered_agent/execute_agent/glm_agent.d.ts +0 -1
- package/dist/core/agent/layered_agent/execute_agent/glm_agent.js +241 -0
- package/dist/core/agent/layered_agent/execute_agent/i18n.d.ts +0 -1
- package/dist/core/agent/layered_agent/execute_agent/i18n.js +34 -0
- package/dist/core/agent/layered_agent/execute_agent/index.d.ts +0 -1
- package/dist/core/agent/layered_agent/execute_agent/index.js +67 -0
- package/dist/core/agent/layered_agent/execute_agent/mai_ui_agent.d.ts +0 -1
- package/dist/core/agent/layered_agent/execute_agent/mai_ui_agent.js +316 -0
- package/dist/core/agent/layered_agent/execute_agent/mcp_prompts.d.ts +0 -1
- package/dist/core/agent/layered_agent/execute_agent/mcp_prompts.js +154 -0
- package/dist/core/agent/layered_agent/execute_agent/parser/general_parser.d.ts +0 -1
- package/dist/core/agent/layered_agent/execute_agent/parser/general_parser.js +243 -0
- package/dist/core/agent/layered_agent/execute_agent/parser/glm_parser.d.ts +0 -1
- package/dist/core/agent/layered_agent/execute_agent/parser/glm_parser.js +139 -0
- package/dist/core/agent/layered_agent/execute_agent/parser/index.d.ts +0 -1
- package/dist/core/agent/layered_agent/execute_agent/parser/index.js +9 -0
- package/dist/core/agent/layered_agent/execute_agent/parser/mai_ui_parser.d.ts +0 -1
- package/dist/core/agent/layered_agent/execute_agent/parser/mai_ui_parser.js +94 -0
- package/dist/core/agent/layered_agent/execute_agent/prompts.d.ts +0 -1
- package/dist/core/agent/layered_agent/execute_agent/prompts.js +109 -0
- package/dist/core/agent/layered_agent/execute_agent/simple_reporter.d.ts +0 -1
- package/dist/core/agent/layered_agent/execute_agent/simple_reporter.js +33 -0
- package/dist/core/agent/layered_agent/execute_agent/utils.d.ts +0 -1
- package/dist/core/agent/layered_agent/execute_agent/utils.js +52 -0
- package/dist/core/agent/report_analyzer_agent/agent.d.ts +0 -1
- package/dist/core/agent/report_analyzer_agent/agent.js +565 -0
- package/dist/core/agent/report_analyzer_agent/config.d.ts +0 -1
- package/dist/core/agent/report_analyzer_agent/config.js +22 -0
- package/dist/core/agent/report_analyzer_agent/data_loader.d.ts +0 -1
- package/dist/core/agent/report_analyzer_agent/data_loader.js +255 -0
- package/dist/core/agent/report_analyzer_agent/guardrails.d.ts +0 -1
- package/dist/core/agent/report_analyzer_agent/guardrails.js +99 -0
- package/dist/core/agent/report_analyzer_agent/hooks.d.ts +0 -1
- package/dist/core/agent/report_analyzer_agent/hooks.js +31 -0
- package/dist/core/agent/report_analyzer_agent/index.d.ts +0 -1
- package/dist/core/agent/report_analyzer_agent/index.js +52 -0
- package/dist/core/agent/report_analyzer_agent/key_steps_builder.d.ts +0 -1
- package/dist/core/agent/report_analyzer_agent/key_steps_builder.js +42 -0
- package/dist/core/agent/report_analyzer_agent/mapping.d.ts +0 -1
- package/dist/core/agent/report_analyzer_agent/mapping.js +133 -0
- package/dist/core/agent/report_analyzer_agent/parse.d.ts +0 -1
- package/dist/core/agent/report_analyzer_agent/parse.js +375 -0
- package/dist/core/agent/report_analyzer_agent/prompt.d.ts +0 -1
- package/dist/core/agent/report_analyzer_agent/prompt.js +300 -0
- package/dist/core/agent/report_analyzer_agent/report_writer.d.ts +0 -1
- package/dist/core/agent/report_analyzer_agent/report_writer.js +558 -0
- package/dist/core/agent/report_analyzer_agent/tools.d.ts +0 -1
- package/dist/core/agent/report_analyzer_agent/tools.js +150 -0
- package/dist/core/agent/report_analyzer_agent/types.d.ts +0 -1
- package/dist/core/agent/report_analyzer_agent/types.js +274 -0
- package/dist/core/agent/rewrite_agent/agent.d.ts +0 -1
- package/dist/core/agent/rewrite_agent/agent.js +209 -0
- package/dist/core/agent/rewrite_agent/guardrails.d.ts +0 -1
- package/dist/core/agent/rewrite_agent/guardrails.js +95 -0
- package/dist/core/agent/rewrite_agent/mapping.d.ts +0 -1
- package/dist/core/agent/rewrite_agent/mapping.js +56 -0
- package/dist/core/agent/rewrite_agent/parse.d.ts +0 -1
- package/dist/core/agent/rewrite_agent/parse.js +121 -0
- package/dist/core/agent/rewrite_agent/types.d.ts +0 -1
- package/dist/core/agent/rewrite_agent/types.js +37 -0
- package/dist/core/agent/single_agent/agent.d.ts +0 -1
- package/dist/core/agent/single_agent/agent.js +798 -0
- package/dist/core/agent/single_agent/hook_manager.d.ts +0 -1
- package/dist/core/agent/single_agent/hook_manager.js +60 -0
- package/dist/core/agent/single_agent/hooks.d.ts +0 -1
- package/dist/core/agent/single_agent/hooks.js +288 -0
- package/dist/core/agent/single_agent/image_utils.d.ts +0 -1
- package/dist/core/agent/single_agent/image_utils.js +159 -0
- package/dist/core/agent/single_agent/scroll_search_agent.d.ts +0 -1
- package/dist/core/agent/single_agent/scroll_search_agent.js +376 -0
- package/dist/core/agent/single_agent/subagent_manager.d.ts +0 -1
- package/dist/core/agent/single_agent/subagent_manager.js +73 -0
- package/dist/core/agent/single_agent/tool_recorder_hook.d.ts +0 -1
- package/dist/core/agent/single_agent/tool_recorder_hook.js +42 -0
- package/dist/core/agent/types.d.ts +0 -1
- package/dist/core/agent/types.js +2 -0
- package/dist/core/agent/utils/message_builder.d.ts +0 -1
- package/dist/core/agent/utils/message_builder.js +138 -0
- package/dist/core/device/device_protocol.d.ts +0 -1
- package/dist/core/device/device_protocol.js +2 -0
- package/dist/core/device/hdc/apps.d.ts +0 -1
- package/dist/core/device/hdc/apps.js +437 -0
- package/dist/core/device/hdc/device.d.ts +0 -1
- package/dist/core/device/hdc/device.js +219 -0
- package/dist/core/device/hdc/index.d.ts +0 -1
- package/dist/core/device/hdc/index.js +31 -0
- package/dist/core/device/hdc/input.d.ts +0 -1
- package/dist/core/device/hdc/input.js +74 -0
- package/dist/core/device/hdc/screenshot.d.ts +0 -1
- package/dist/core/device/hdc/screenshot.js +171 -0
- package/dist/core/device/index.d.ts +0 -1
- package/dist/core/device/index.js +70 -0
- package/dist/core/device/types.d.ts +0 -1
- package/dist/core/device/types.js +2 -0
- package/dist/core/knowledge/knowledge_manager.d.ts +0 -1
- package/dist/core/knowledge/knowledge_manager.js +70 -0
- package/dist/core/knowledge/vectordb.d.ts +0 -1
- package/dist/core/knowledge/vectordb.js +283 -0
- package/dist/core/mcp/adapter_factory.d.ts +0 -1
- package/dist/core/mcp/adapter_factory.js +99 -0
- package/dist/core/mcp/android_adapter.d.ts +1 -2
- package/dist/core/mcp/android_adapter.js +286 -0
- package/dist/core/mcp/base_adapter.d.ts +0 -1
- package/dist/core/mcp/base_adapter.js +86 -0
- package/dist/core/mcp/harmony_hdc_adapter.d.ts +9 -1
- package/dist/core/mcp/harmony_hdc_adapter.js +782 -0
- package/dist/core/mcp/ios_adapter.d.ts +1 -2
- package/dist/core/mcp/ios_adapter.js +286 -0
- package/dist/core/mcp/local_tools.d.ts +0 -1
- package/dist/core/mcp/local_tools.js +41 -0
- package/dist/core/mcp/mcp_tools.d.ts +0 -1
- package/dist/core/mcp/mcp_tools.js +382 -0
- package/dist/core/mcp/types.d.ts +0 -1
- package/dist/core/mcp/types.js +6 -0
- package/dist/core/memory/compressed_session.d.ts +0 -1
- package/dist/core/memory/compressed_session.js +182 -0
- package/dist/core/memory/context_compressor.d.ts +0 -1
- package/dist/core/memory/context_compressor.js +176 -0
- package/dist/core/memory/index.d.ts +0 -1
- package/dist/core/memory/index.js +22 -0
- package/dist/core/memory/memory_manager.d.ts +0 -1
- package/dist/core/memory/memory_manager.js +28 -0
- package/dist/core/memory/reflector.d.ts +0 -1
- package/dist/core/memory/reflector.js +95 -0
- package/dist/core/memory/session_factory.d.ts +0 -1
- package/dist/core/memory/session_factory.js +29 -0
- package/dist/core/memory/tool_player.d.ts +0 -1
- package/dist/core/memory/tool_player.js +225 -0
- package/dist/core/memory/tool_recorder.d.ts +0 -1
- package/dist/core/memory/tool_recorder.js +126 -0
- package/dist/core/preprocessor/task_splitter.d.ts +0 -1
- package/dist/core/preprocessor/task_splitter.js +112 -0
- package/dist/core/prompt/prompt_loader.d.ts +0 -1
- package/dist/core/prompt/prompt_loader.js +313 -0
- package/dist/core/skill/skill_manager.d.ts +0 -1
- package/dist/core/skill/skill_manager.js +299 -0
- package/dist/data_types/action.d.ts +0 -1
- package/dist/data_types/action.js +2 -0
- package/dist/data_types/agent.d.ts +0 -1
- package/dist/data_types/agent.js +2 -0
- package/dist/data_types/device.d.ts +0 -1
- package/dist/data_types/device.js +2 -0
- package/dist/data_types/index.d.ts +0 -1
- package/dist/data_types/index.js +6 -0
- package/dist/data_types/report.d.ts +0 -1
- package/dist/data_types/report.js +6 -0
- package/dist/data_types/task.d.ts +0 -1
- package/dist/data_types/task.js +2 -0
- package/dist/index.d.ts +1 -2
- package/dist/index.js +164 -1
- package/dist/loop/cli.d.ts +0 -1
- package/dist/loop/cli.js +127 -0
- package/dist/loop/orchestrator.d.ts +0 -1
- package/dist/loop/orchestrator.js +314 -0
- package/dist/loop/result_writer.d.ts +0 -1
- package/dist/loop/result_writer.js +260 -0
- package/dist/loop/types.d.ts +0 -1
- package/dist/loop/types.js +82 -0
- package/dist/mcp-server/server.d.ts +0 -1
- package/dist/mcp-server/server.js +341 -0
- package/dist/mcp-server/types.d.ts +283 -118
- package/dist/mcp-server/types.js +202 -0
- package/dist/reporter/batch_summary.d.ts +0 -1
- package/dist/reporter/batch_summary.js +197 -0
- package/dist/reporter/generator.d.ts +0 -1
- package/dist/reporter/generator.js +772 -0
- package/dist/reporter/types.d.ts +14 -15
- package/dist/reporter/types.js +44 -0
- package/dist/tools/batch_runner.d.ts +1 -1
- package/dist/tools/batch_runner.js +731 -0
- package/package.json +5 -3
- package/dist/common/config/config.yaml +0 -113
- package/dist/hypium_generator/generator.d.ts +0 -38
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Global hook registry for cross-cutting agent hooks (aligned with python
|
|
4
|
+
* hybrid_agent/hooks/hook_manager.py).
|
|
5
|
+
*
|
|
6
|
+
* Unlike the per-agent `AgentHooks` interface (wired directly into an agent),
|
|
7
|
+
* HookManager is a process-wide singleton where cross-cutting hooks (e.g.
|
|
8
|
+
* ToolRecorderHook) register themselves and get fired on every agent's
|
|
9
|
+
* lifecycle events. Errors in one hook are isolated (logged, never crash the
|
|
10
|
+
* agent).
|
|
11
|
+
*/
|
|
12
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
13
|
+
exports.hookManager = void 0;
|
|
14
|
+
const logger_1 = require("../../../common/logger");
|
|
15
|
+
class HookManagerImpl {
|
|
16
|
+
hooks = new Map();
|
|
17
|
+
register(name, hook) {
|
|
18
|
+
this.hooks.set(name, hook);
|
|
19
|
+
logger_1.logger.debug(`HookManager: registered hook '${name}'`);
|
|
20
|
+
}
|
|
21
|
+
unregister(name) {
|
|
22
|
+
this.hooks.delete(name);
|
|
23
|
+
}
|
|
24
|
+
clear() {
|
|
25
|
+
this.hooks.clear();
|
|
26
|
+
}
|
|
27
|
+
listHooks() {
|
|
28
|
+
return Array.from(this.hooks.keys());
|
|
29
|
+
}
|
|
30
|
+
/** Fire an event to all registered hooks. Errors are isolated (logged, never thrown). */
|
|
31
|
+
async fireEvent(event, ctx = {}) {
|
|
32
|
+
const methodName = this._eventToMethod(event);
|
|
33
|
+
for (const [name, hook] of this.hooks) {
|
|
34
|
+
const fn = hook[methodName];
|
|
35
|
+
if (!fn)
|
|
36
|
+
continue;
|
|
37
|
+
try {
|
|
38
|
+
await fn(ctx);
|
|
39
|
+
}
|
|
40
|
+
catch (e) {
|
|
41
|
+
logger_1.logger.error(`HookManager: hook '${name}' threw on ${event}: ${e instanceof Error ? e.message : String(e)}`);
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
_eventToMethod(event) {
|
|
46
|
+
// on_agent_start -> onAgentStart
|
|
47
|
+
const map = {
|
|
48
|
+
'on_agent_start': 'onAgentStart',
|
|
49
|
+
'on_agent_end': 'onAgentEnd',
|
|
50
|
+
'on_step_start': 'onStepStart',
|
|
51
|
+
'on_step_end': 'onStepEnd',
|
|
52
|
+
'on_llm_start': 'onLLMStart',
|
|
53
|
+
'on_llm_end': 'onLLMEnd',
|
|
54
|
+
'on_tool_start': 'onToolStart',
|
|
55
|
+
'on_tool_end': 'onToolEnd',
|
|
56
|
+
};
|
|
57
|
+
return map[event];
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
exports.hookManager = new HookManagerImpl();
|
|
@@ -20,4 +20,3 @@ export declare class SingleAgentHooks implements AgentHooks {
|
|
|
20
20
|
onToolStart(agentName: string, toolName: string, args?: Record<string, unknown>): Promise<void>;
|
|
21
21
|
onToolEnd(agentName: string, toolName: string, result: string, stepNumber: number): Promise<void>;
|
|
22
22
|
}
|
|
23
|
-
//# sourceMappingURL=hooks.d.ts.map
|
|
@@ -0,0 +1,288 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.SingleAgentHooks = void 0;
|
|
4
|
+
const common_errors_1 = require("../../../common/common_errors");
|
|
5
|
+
const token_usage_1 = require("../../../common/usage/token_usage");
|
|
6
|
+
const types_1 = require("../../../reporter/types");
|
|
7
|
+
const logger_1 = require("../../../common/logger");
|
|
8
|
+
function mkEvent(eventType, content, opts) {
|
|
9
|
+
return {
|
|
10
|
+
eventType,
|
|
11
|
+
timestamp: new Date().toISOString(),
|
|
12
|
+
content,
|
|
13
|
+
data: opts?.data ?? {},
|
|
14
|
+
screenshotPath: opts?.screenshotPath ?? null,
|
|
15
|
+
stepNumber: opts?.stepNumber ?? null,
|
|
16
|
+
};
|
|
17
|
+
}
|
|
18
|
+
const COMMON_ERRORS_PROMPT_LOCAL = common_errors_1.COMMON_ERRORS_PROMPT;
|
|
19
|
+
function _parseThinkingContent(text) {
|
|
20
|
+
const thinkingMatch = text.match(/<thinking>(.*?)<\/thinking>/s);
|
|
21
|
+
if (thinkingMatch) {
|
|
22
|
+
return thinkingMatch[1].trim();
|
|
23
|
+
}
|
|
24
|
+
return '';
|
|
25
|
+
}
|
|
26
|
+
function _parseJudgmentContent(text) {
|
|
27
|
+
const judgmentMatch = text.match(/<judgment>(.*?)<\/judgment>/s);
|
|
28
|
+
if (judgmentMatch) {
|
|
29
|
+
return judgmentMatch[1].trim();
|
|
30
|
+
}
|
|
31
|
+
const JUDGMENT_SECTION_RE = /##\s*(?:Judgment Process|判定过程)\s*\n(.*?)(?=\n##\s|\Z)/s;
|
|
32
|
+
const mdMatch = text.match(JUDGMENT_SECTION_RE);
|
|
33
|
+
if (mdMatch) {
|
|
34
|
+
return mdMatch[1].trim();
|
|
35
|
+
}
|
|
36
|
+
return '';
|
|
37
|
+
}
|
|
38
|
+
class SingleAgentHooks {
|
|
39
|
+
adapter;
|
|
40
|
+
reportGenerator;
|
|
41
|
+
tokenType;
|
|
42
|
+
toolCount;
|
|
43
|
+
historyActions;
|
|
44
|
+
stepStartTime;
|
|
45
|
+
agentConfig;
|
|
46
|
+
constructor(adapter, reportGenerator, tokenType, agentConfig) {
|
|
47
|
+
this.adapter = adapter;
|
|
48
|
+
this.reportGenerator = reportGenerator ?? null;
|
|
49
|
+
this.tokenType = tokenType ?? token_usage_1.TokenUsage;
|
|
50
|
+
this.toolCount = 0;
|
|
51
|
+
this.historyActions = [];
|
|
52
|
+
this.stepStartTime = 0;
|
|
53
|
+
this.agentConfig = agentConfig ?? null;
|
|
54
|
+
}
|
|
55
|
+
static _stripVerdict(text) {
|
|
56
|
+
const lines = text.split('\n');
|
|
57
|
+
const filtered = lines.filter((l) => !(/^\s*(verdict|任务结果)\s*[::]/i.test(l)));
|
|
58
|
+
return filtered.join('\n').trim();
|
|
59
|
+
}
|
|
60
|
+
async onAgentStart(agentName) {
|
|
61
|
+
logger_1.logger.info(`[${agentName}] Agent started`);
|
|
62
|
+
if (this.reportGenerator) {
|
|
63
|
+
this.reportGenerator.addEvent(mkEvent(types_1.EventType.PLANNER_START, `Agent ${agentName} started`));
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
async onAgentEnd(agentName, output) {
|
|
67
|
+
logger_1.logger.info(`[${agentName}] Agent finished: ${output}`);
|
|
68
|
+
if (this.reportGenerator) {
|
|
69
|
+
this.reportGenerator.addEvent(mkEvent(types_1.EventType.PLANNER_END, 'Agent finished', { data: { output: String(output) } }));
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
async onLLMStart(agentName, stepNumber) {
|
|
73
|
+
this.stepStartTime = Date.now();
|
|
74
|
+
logger_1.logger.info(`[${agentName}] Preparing LLM input with screenshot...`);
|
|
75
|
+
try {
|
|
76
|
+
const screenshot = await this.adapter.getScreenshot();
|
|
77
|
+
if (screenshot && screenshot.base64Data) {
|
|
78
|
+
if (this.reportGenerator) {
|
|
79
|
+
const screenshotPath = this.reportGenerator.saveScreenshot(screenshot.base64Data, screenshot.layoutData, `step_${this.toolCount + 1}`);
|
|
80
|
+
this.reportGenerator.addEvent(mkEvent(types_1.EventType.PLANNER_OBSERVATION, 'Current Screen Observation', { screenshotPath, stepNumber: this.toolCount + 1 }));
|
|
81
|
+
}
|
|
82
|
+
if (this.toolCount > 0) {
|
|
83
|
+
const historyText = this.historyActions.length > 0
|
|
84
|
+
? this.historyActions.slice(-10).join('\n')
|
|
85
|
+
: 'none';
|
|
86
|
+
const progressHint = `Observe UI content and changes from previous step, make next decision based on task breakdown and execution history.
|
|
87
|
+
[Progress: ${this.toolCount + 1}]
|
|
88
|
+
[Action history: ${historyText}]
|
|
89
|
+
${COMMON_ERRORS_PROMPT_LOCAL}`;
|
|
90
|
+
if (this.reportGenerator) {
|
|
91
|
+
this.reportGenerator.addEvent(mkEvent(types_1.EventType.PLANNER_THINKING, progressHint, { stepNumber: this.toolCount + 1 }));
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
catch (e) {
|
|
97
|
+
logger_1.logger.warn(`Failed to inject screenshot: ${e}`);
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
async onLLMEnd(agentName, stepNumber, response) {
|
|
101
|
+
logger_1.logger.info(`[${agentName}] --- LLM Response ---`);
|
|
102
|
+
const resp = response;
|
|
103
|
+
const output = resp?.output;
|
|
104
|
+
const step = this.toolCount + 1;
|
|
105
|
+
if (typeof output === 'string') {
|
|
106
|
+
const judgmentText = _parseJudgmentContent(output);
|
|
107
|
+
if (judgmentText) {
|
|
108
|
+
logger_1.logger.info(`[${agentName}] Judgment: ${judgmentText}`);
|
|
109
|
+
if (this.reportGenerator) {
|
|
110
|
+
this.reportGenerator.addEvent(mkEvent(types_1.EventType.PLANNER_END, judgmentText, { stepNumber: step }));
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
else {
|
|
114
|
+
const thinkingText = _parseThinkingContent(output);
|
|
115
|
+
if (thinkingText) {
|
|
116
|
+
logger_1.logger.info(`[${agentName}] Thinking: ${thinkingText}`);
|
|
117
|
+
if (this.reportGenerator) {
|
|
118
|
+
this.reportGenerator.addEvent(mkEvent(types_1.EventType.PLANNER_THINKING, SingleAgentHooks._stripVerdict(thinkingText), { stepNumber: step }));
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
else {
|
|
122
|
+
logger_1.logger.info(`[${agentName}] Text: ${output}`);
|
|
123
|
+
if (this.reportGenerator) {
|
|
124
|
+
this.reportGenerator.addEvent(mkEvent(types_1.EventType.PLANNER_THINKING, SingleAgentHooks._stripVerdict(output), { stepNumber: step }));
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
else if (output && Array.isArray(output)) {
|
|
130
|
+
for (const item of output) {
|
|
131
|
+
const itemType = item?.type;
|
|
132
|
+
if (itemType === 'reasoning') {
|
|
133
|
+
const summary = item?.summary;
|
|
134
|
+
if (summary) {
|
|
135
|
+
for (const s of summary) {
|
|
136
|
+
const text = s?.text ?? '';
|
|
137
|
+
const judgmentText = _parseJudgmentContent(text);
|
|
138
|
+
if (judgmentText) {
|
|
139
|
+
logger_1.logger.info(`[${agentName}] Judgment: ${judgmentText}`);
|
|
140
|
+
if (this.reportGenerator) {
|
|
141
|
+
this.reportGenerator.addEvent(mkEvent(types_1.EventType.PLANNER_END, judgmentText, { stepNumber: step }));
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
else {
|
|
145
|
+
const thinkingText = _parseThinkingContent(text);
|
|
146
|
+
if (thinkingText) {
|
|
147
|
+
logger_1.logger.info(`[${agentName}] Thinking: ${thinkingText}`);
|
|
148
|
+
if (this.reportGenerator) {
|
|
149
|
+
this.reportGenerator.addEvent(mkEvent(types_1.EventType.PLANNER_THINKING, SingleAgentHooks._stripVerdict(thinkingText), { stepNumber: step }));
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
else {
|
|
153
|
+
logger_1.logger.info(`[${agentName}] Reasoning: ${text}`);
|
|
154
|
+
if (this.reportGenerator) {
|
|
155
|
+
this.reportGenerator.addEvent(mkEvent(types_1.EventType.PLANNER_THINKING, SingleAgentHooks._stripVerdict(text), { stepNumber: step }));
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
const content = item?.content;
|
|
162
|
+
if (content && Array.isArray(content)) {
|
|
163
|
+
for (const c of content) {
|
|
164
|
+
const text = c?.text ?? '';
|
|
165
|
+
logger_1.logger.info(`[${agentName}] content: ${text}`);
|
|
166
|
+
if (this.reportGenerator) {
|
|
167
|
+
this.reportGenerator.addEvent(mkEvent(types_1.EventType.PLANNER_THINKING, SingleAgentHooks._stripVerdict(text), { stepNumber: step }));
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
if (itemType === 'message') {
|
|
173
|
+
const messageContent = item?.content;
|
|
174
|
+
if (messageContent && Array.isArray(messageContent)) {
|
|
175
|
+
for (const contentItem of messageContent) {
|
|
176
|
+
if (contentItem?.type === 'output_text') {
|
|
177
|
+
const text = contentItem?.text ?? '';
|
|
178
|
+
logger_1.logger.info(`[${agentName}] Text: ${text}`);
|
|
179
|
+
if (this.reportGenerator) {
|
|
180
|
+
this.reportGenerator.addEvent(mkEvent(types_1.EventType.PLANNER_OUTPUT, SingleAgentHooks._stripVerdict(text), { stepNumber: step }));
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
if (itemType === 'function_call') {
|
|
187
|
+
try {
|
|
188
|
+
const callArgs = JSON.parse(item?.arguments ?? '{}');
|
|
189
|
+
const callToolName = item?.name ?? '';
|
|
190
|
+
logger_1.logger.info(`[${agentName}] Tool: ${callToolName} args: ${JSON.stringify(callArgs)}`);
|
|
191
|
+
if (this.reportGenerator) {
|
|
192
|
+
this.reportGenerator.addEvent(mkEvent(types_1.EventType.PLANNER_TOOL_CALL, `Called: ${callToolName}`, { data: { tool_name: callToolName, arguments: callArgs }, stepNumber: step }));
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
catch {
|
|
196
|
+
logger_1.logger.warn(`Failed to parse tool args: ${item?.arguments}`);
|
|
197
|
+
}
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
const usage = resp?.usage;
|
|
202
|
+
if (usage) {
|
|
203
|
+
const tokenUsage = this.tokenType.fromUsageObj(usage);
|
|
204
|
+
if (!tokenUsage)
|
|
205
|
+
return;
|
|
206
|
+
logger_1.logger.info(`[${agentName}] ${tokenUsage.toString()}`);
|
|
207
|
+
if (this.reportGenerator) {
|
|
208
|
+
this.reportGenerator.addTokenUsage(tokenUsage, 'SingleAgent', this.toolCount + 1);
|
|
209
|
+
}
|
|
210
|
+
}
|
|
211
|
+
}
|
|
212
|
+
async onToolStart(agentName, toolName, args) {
|
|
213
|
+
logger_1.logger.info(`[${agentName}] Calling tool: ${toolName}`);
|
|
214
|
+
if (this.reportGenerator) {
|
|
215
|
+
try {
|
|
216
|
+
const screenshot = await this.adapter.getScreenshot();
|
|
217
|
+
const screenshotPath = this.reportGenerator.saveScreenshot(screenshot.base64Data, screenshot.layoutData, `step_${this.toolCount + 1}`);
|
|
218
|
+
const eventData = { tool_name: toolName };
|
|
219
|
+
if (args) {
|
|
220
|
+
eventData.arguments = args;
|
|
221
|
+
if ('log' in args) {
|
|
222
|
+
this.historyActions.push(`${this.historyActions.length + 1}. ${args.log}`);
|
|
223
|
+
}
|
|
224
|
+
if (['click', 'double_click', 'long_press', 'long_click'].includes(toolName)) {
|
|
225
|
+
eventData.action = toolName;
|
|
226
|
+
if ('x' in args && 'y' in args) {
|
|
227
|
+
eventData.point = [args.x, args.y];
|
|
228
|
+
}
|
|
229
|
+
else if ('pos' in args && Array.isArray(args.pos) && args.pos.length === 2) {
|
|
230
|
+
eventData.point = [args.pos[0], args.pos[1]];
|
|
231
|
+
}
|
|
232
|
+
}
|
|
233
|
+
else if (toolName === 'swipe') {
|
|
234
|
+
if ('start' in args && 'end' in args) {
|
|
235
|
+
const start = args.start;
|
|
236
|
+
const end = args.end;
|
|
237
|
+
if (Array.isArray(start) && start.length === 2 && Array.isArray(end) && end.length === 2) {
|
|
238
|
+
eventData.action = 'swipe';
|
|
239
|
+
eventData.start = [start[0], start[1]];
|
|
240
|
+
eventData.end = [end[0], end[1]];
|
|
241
|
+
}
|
|
242
|
+
}
|
|
243
|
+
else if ('start_x' in args && 'start_y' in args && 'end_x' in args && 'end_y' in args) {
|
|
244
|
+
eventData.action = 'swipe';
|
|
245
|
+
eventData.start = [args.start_x, args.start_y];
|
|
246
|
+
eventData.end = [args.end_x, args.end_y];
|
|
247
|
+
}
|
|
248
|
+
}
|
|
249
|
+
}
|
|
250
|
+
this.reportGenerator.addEvent(mkEvent(types_1.EventType.MCP_TOOL_START, `Starting: ${toolName}`, { data: eventData, screenshotPath, stepNumber: this.toolCount + 1 }));
|
|
251
|
+
}
|
|
252
|
+
catch (e) {
|
|
253
|
+
logger_1.logger.warn(`Failed to capture screenshot: ${e}`);
|
|
254
|
+
}
|
|
255
|
+
}
|
|
256
|
+
}
|
|
257
|
+
async onToolEnd(agentName, toolName, result, stepNumber) {
|
|
258
|
+
const resultStr = String(result).slice(0, 200);
|
|
259
|
+
const elapsed = this.stepStartTime ? (Date.now() - this.stepStartTime) / 1000 : 0;
|
|
260
|
+
const elapsedStr = elapsed < 60 ? `${elapsed.toFixed(1)}s` : `${(elapsed / 60).toFixed(1)}m`;
|
|
261
|
+
const stepMeta = `[Step ${this.toolCount + 1} | ${elapsedStr}]`;
|
|
262
|
+
logger_1.logger.info(`[${agentName}] ${stepMeta} Tool ${toolName} result: ${resultStr}`);
|
|
263
|
+
this.toolCount += 1;
|
|
264
|
+
if (this.reportGenerator) {
|
|
265
|
+
try {
|
|
266
|
+
const screenshot = await this.adapter.getScreenshot();
|
|
267
|
+
const screenshotPath = this.reportGenerator.saveScreenshot(screenshot.base64Data, screenshot.layoutData, `step_${this.toolCount}`);
|
|
268
|
+
const eventData = { tool_name: toolName, result: resultStr };
|
|
269
|
+
try {
|
|
270
|
+
const parsed = JSON.parse(String(result));
|
|
271
|
+
if (typeof parsed === 'object' && parsed !== null) {
|
|
272
|
+
Object.assign(eventData, parsed);
|
|
273
|
+
}
|
|
274
|
+
}
|
|
275
|
+
catch {
|
|
276
|
+
}
|
|
277
|
+
this.reportGenerator.addEvent(mkEvent(types_1.EventType.MCP_TOOL_END, `Completed: ${toolName}`, { data: eventData, screenshotPath, stepNumber: this.toolCount }));
|
|
278
|
+
}
|
|
279
|
+
catch (e) {
|
|
280
|
+
logger_1.logger.warn(`Failed to capture screenshot: ${e}`);
|
|
281
|
+
}
|
|
282
|
+
}
|
|
283
|
+
if (toolName === 'start_app' && result.includes('failed!')) {
|
|
284
|
+
throw new Error(`Task terminated: ${result}`);
|
|
285
|
+
}
|
|
286
|
+
}
|
|
287
|
+
}
|
|
288
|
+
exports.SingleAgentHooks = SingleAgentHooks;
|
|
@@ -35,4 +35,3 @@ export declare function injectScreenshotsAndHistory(prevScreenshot: string | nul
|
|
|
35
35
|
* Converts older image parts to text placeholders.
|
|
36
36
|
*/
|
|
37
37
|
export declare function manageImageHistory(items: Array<Record<string, unknown>>, maxImages?: number): Array<Record<string, unknown>>;
|
|
38
|
-
//# sourceMappingURL=image_utils.d.ts.map
|
|
@@ -0,0 +1,159 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Screenshot injection + action markers (aligned with python
|
|
4
|
+
* hybrid_agent/hooks/image_utils.py inject_screenshots_and_history).
|
|
5
|
+
*
|
|
6
|
+
* Provides:
|
|
7
|
+
* - compressScreenshot: resize via sharp for LLM context window
|
|
8
|
+
* - drawActionMarker: overlay click dot / swipe arrow via SVG→sharp composite
|
|
9
|
+
* - injectScreenshotsAndHistory: build user message with prev+current+history
|
|
10
|
+
* - manageImageHistory: strip old images from session items
|
|
11
|
+
*/
|
|
12
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
13
|
+
if (k2 === undefined) k2 = k;
|
|
14
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
15
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
16
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
17
|
+
}
|
|
18
|
+
Object.defineProperty(o, k2, desc);
|
|
19
|
+
}) : (function(o, m, k, k2) {
|
|
20
|
+
if (k2 === undefined) k2 = k;
|
|
21
|
+
o[k2] = m[k];
|
|
22
|
+
}));
|
|
23
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
24
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
25
|
+
}) : function(o, v) {
|
|
26
|
+
o["default"] = v;
|
|
27
|
+
});
|
|
28
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
29
|
+
var ownKeys = function(o) {
|
|
30
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
31
|
+
var ar = [];
|
|
32
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
33
|
+
return ar;
|
|
34
|
+
};
|
|
35
|
+
return ownKeys(o);
|
|
36
|
+
};
|
|
37
|
+
return function (mod) {
|
|
38
|
+
if (mod && mod.__esModule) return mod;
|
|
39
|
+
var result = {};
|
|
40
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
41
|
+
__setModuleDefault(result, mod);
|
|
42
|
+
return result;
|
|
43
|
+
};
|
|
44
|
+
})();
|
|
45
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
46
|
+
exports.compressScreenshot = compressScreenshot;
|
|
47
|
+
exports.drawActionMarker = drawActionMarker;
|
|
48
|
+
exports.injectScreenshotsAndHistory = injectScreenshotsAndHistory;
|
|
49
|
+
exports.manageImageHistory = manageImageHistory;
|
|
50
|
+
const image_helper_1 = require("../../../common/image_helper");
|
|
51
|
+
const logger_1 = require("../../../common/logger");
|
|
52
|
+
const MAX_SCREENSHOT_PIXELS = 1500;
|
|
53
|
+
/** Compress a base64 screenshot to a target pixel count. */
|
|
54
|
+
async function compressScreenshot(base64Data, maxPixels = MAX_SCREENSHOT_PIXELS) {
|
|
55
|
+
return (0, image_helper_1.compressBase64Image)(base64Data, maxPixels, 70);
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* Draw an action marker (click dot + crosshair, or swipe arrow) on a screenshot.
|
|
59
|
+
* Uses SVG → sharp composite for overlay drawing.
|
|
60
|
+
*/
|
|
61
|
+
async function drawActionMarker(base64Data, action) {
|
|
62
|
+
try {
|
|
63
|
+
const sharp = await Promise.resolve().then(() => __importStar(require('sharp')));
|
|
64
|
+
const img = Buffer.from(base64Data, 'base64');
|
|
65
|
+
const metadata = await sharp.default(img).metadata();
|
|
66
|
+
const w = metadata.width ?? 1080;
|
|
67
|
+
const h = metadata.height ?? 2400;
|
|
68
|
+
// Build SVG overlay for the marker
|
|
69
|
+
let svg = `<svg width="${w}" height="${h}" xmlns="http://www.w3.org/2000/svg">`;
|
|
70
|
+
if (action.type === 'click' && action.point) {
|
|
71
|
+
const [x, y] = action.point;
|
|
72
|
+
const px = Math.round(x * w);
|
|
73
|
+
const py = Math.round(y * h);
|
|
74
|
+
// Red dot with white border + crosshair
|
|
75
|
+
svg += `<circle cx="${px}" cy="${py}" r="14" fill="none" stroke="#fff" stroke-width="3"/>`;
|
|
76
|
+
svg += `<circle cx="${px}" cy="${py}" r="12" fill="rgba(220,38,38,0.7)" stroke="#fff" stroke-width="2"/>`;
|
|
77
|
+
svg += `<line x1="${px - 20}" y1="${py}" x2="${px + 20}" y2="${py}" stroke="#fff" stroke-width="2"/>`;
|
|
78
|
+
svg += `<line x1="${px}" y1="${py - 20}" x2="${px}" y2="${py + 20}" stroke="#fff" stroke-width="2"/>`;
|
|
79
|
+
}
|
|
80
|
+
else if (action.type === 'swipe' && action.start && action.end) {
|
|
81
|
+
const [sx, sy] = action.start;
|
|
82
|
+
const [ex, ey] = action.end;
|
|
83
|
+
const px1 = Math.round(sx * w), py1 = Math.round(sy * h);
|
|
84
|
+
const px2 = Math.round(ex * w), py2 = Math.round(ey * h);
|
|
85
|
+
// Red arrow line
|
|
86
|
+
svg += `<line x1="${px1}" y1="${py1}" x2="${px2}" y2="${py2}" stroke="rgba(220,38,38,0.8)" stroke-width="5" stroke-linecap="round"/>`;
|
|
87
|
+
svg += `<circle cx="${px1}" cy="${py1}" r="6" fill="rgba(220,38,38,0.8)"/>`;
|
|
88
|
+
// Arrowhead
|
|
89
|
+
const angle = Math.atan2(py2 - py1, px2 - px1);
|
|
90
|
+
const ah = 18;
|
|
91
|
+
svg += `<polygon points="${px2},${py2} ${px2 - ah * Math.cos(angle - 0.4)},${py2 - ah * Math.sin(angle - 0.4)} ${px2 - ah * Math.cos(angle + 0.4)},${py2 - ah * Math.sin(angle + 0.4)}" fill="rgba(220,38,38,0.9)"/>`;
|
|
92
|
+
}
|
|
93
|
+
svg += `</svg>`;
|
|
94
|
+
const overlay = Buffer.from(svg);
|
|
95
|
+
const result = await sharp.default(img)
|
|
96
|
+
.composite([{ input: overlay, top: 0, left: 0 }])
|
|
97
|
+
.jpeg({ quality: 70 })
|
|
98
|
+
.toBuffer();
|
|
99
|
+
return result.toString('base64');
|
|
100
|
+
}
|
|
101
|
+
catch (e) {
|
|
102
|
+
logger_1.logger.warn(`[image_utils] drawActionMarker failed: ${e instanceof Error ? e.message : String(e)}`);
|
|
103
|
+
return base64Data;
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
/**
|
|
107
|
+
* Build a user message with previous screenshot (with action marker) + current screenshot + progress history.
|
|
108
|
+
* Returns content blocks for the AI SDK user message.
|
|
109
|
+
*/
|
|
110
|
+
function injectScreenshotsAndHistory(prevScreenshot, currentScreenshot, historyActions, lastActionInfo) {
|
|
111
|
+
const blocks = [];
|
|
112
|
+
// 1. Previous screenshot (with action marker if available)
|
|
113
|
+
if (prevScreenshot) {
|
|
114
|
+
blocks.push({ type: 'text', text: '## Previous screen (with action marker)' });
|
|
115
|
+
blocks.push({
|
|
116
|
+
type: 'file',
|
|
117
|
+
data: `data:image/jpeg;base64,${prevScreenshot}`,
|
|
118
|
+
mediaType: 'image/jpeg',
|
|
119
|
+
});
|
|
120
|
+
}
|
|
121
|
+
// 2. Current screenshot
|
|
122
|
+
blocks.push({ type: 'text', text: '## Current screen' });
|
|
123
|
+
blocks.push({
|
|
124
|
+
type: 'file',
|
|
125
|
+
data: `data:image/jpeg;base64,${currentScreenshot}`,
|
|
126
|
+
mediaType: 'image/jpeg',
|
|
127
|
+
});
|
|
128
|
+
// 3. Progress history
|
|
129
|
+
if (historyActions.length > 0) {
|
|
130
|
+
blocks.push({ type: 'text', text: `## History\n${historyActions.join('\n')}` });
|
|
131
|
+
}
|
|
132
|
+
return blocks;
|
|
133
|
+
}
|
|
134
|
+
/**
|
|
135
|
+
* Strip old image parts from session items, keeping only the most recent N images.
|
|
136
|
+
* Converts older image parts to text placeholders.
|
|
137
|
+
*/
|
|
138
|
+
function manageImageHistory(items, maxImages = 3) {
|
|
139
|
+
let imageCount = 0;
|
|
140
|
+
// Walk backwards, count images, convert old ones to text
|
|
141
|
+
for (let i = items.length - 1; i >= 0; i--) {
|
|
142
|
+
const item = items[i];
|
|
143
|
+
const content = item['content'];
|
|
144
|
+
if (Array.isArray(content)) {
|
|
145
|
+
for (const part of content) {
|
|
146
|
+
if (part['type'] === 'file' || part['type'] === 'image' || part['type'] === 'input_image') {
|
|
147
|
+
imageCount++;
|
|
148
|
+
if (imageCount > maxImages) {
|
|
149
|
+
part['type'] = 'text';
|
|
150
|
+
part['text'] = '[previous screenshot omitted]';
|
|
151
|
+
delete part['data'];
|
|
152
|
+
delete part['image_url'];
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
return items;
|
|
159
|
+
}
|