@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.
Files changed (248) hide show
  1. package/README.md +43 -27
  2. package/dist/api/agent_api.d.ts +1 -1
  3. package/dist/api/agent_api.js +555 -0
  4. package/dist/api/autotest_agent.d.ts +0 -1
  5. package/dist/api/autotest_agent.js +205 -0
  6. package/dist/api/types.d.ts +0 -1
  7. package/dist/api/types.js +11 -0
  8. package/dist/autotest-cli.d.ts +1 -1
  9. package/dist/autotest-cli.js +391 -0
  10. package/dist/common/case_manager.d.ts +0 -1
  11. package/dist/common/case_manager.js +91 -0
  12. package/dist/common/collect_case.d.ts +0 -1
  13. package/dist/common/collect_case.js +128 -0
  14. package/dist/common/common_errors.d.ts +0 -1
  15. package/dist/common/common_errors.js +66 -0
  16. package/dist/common/config/config_validator.d.ts +0 -1
  17. package/dist/common/config/config_validator.js +28 -0
  18. package/dist/common/config/manager.d.ts +0 -1
  19. package/dist/common/config/manager.js +257 -0
  20. package/dist/common/config/output.d.ts +0 -1
  21. package/dist/common/config/output.js +59 -0
  22. package/dist/common/config/types.d.ts +2243 -2244
  23. package/dist/common/config/types.js +184 -0
  24. package/dist/common/dfx/client_factory.d.ts +0 -1
  25. package/dist/common/dfx/client_factory.js +62 -0
  26. package/dist/common/dfx/context.d.ts +0 -1
  27. package/dist/common/dfx/context.js +23 -0
  28. package/dist/common/dfx/index.d.ts +0 -1
  29. package/dist/common/dfx/index.js +15 -0
  30. package/dist/common/dfx/recorder.d.ts +0 -1
  31. package/dist/common/dfx/recorder.js +191 -0
  32. package/dist/common/dfx/recording_fetch.d.ts +0 -1
  33. package/dist/common/dfx/recording_fetch.js +228 -0
  34. package/dist/common/dfx/source.d.ts +0 -1
  35. package/dist/common/dfx/source.js +13 -0
  36. package/dist/common/image_cacher.d.ts +0 -1
  37. package/dist/common/image_cacher.js +36 -0
  38. package/dist/common/image_helper.d.ts +0 -1
  39. package/dist/common/image_helper.js +128 -0
  40. package/dist/common/image_similarity.d.ts +0 -1
  41. package/dist/common/image_similarity.js +171 -0
  42. package/dist/common/llm_cache/cache_transport.d.ts +2 -1
  43. package/dist/common/llm_cache/cache_transport.js +102 -0
  44. package/dist/common/llm_cache/prompt_cache.d.ts +53 -0
  45. package/dist/common/llm_cache/prompt_cache.js +113 -0
  46. package/dist/common/logger.d.ts +0 -1
  47. package/dist/common/logger.js +158 -0
  48. package/dist/common/model/custom_model.d.ts +0 -1
  49. package/dist/common/model/custom_model.js +467 -0
  50. package/dist/common/model/index.d.ts +0 -1
  51. package/dist/common/model/index.js +5 -0
  52. package/dist/common/path_utils.d.ts +0 -1
  53. package/dist/common/path_utils.js +81 -0
  54. package/dist/common/result_parser.d.ts +0 -1
  55. package/dist/common/result_parser.js +49 -0
  56. package/dist/common/usage/token_usage.d.ts +0 -1
  57. package/dist/common/usage/token_usage.js +117 -0
  58. package/dist/common/utils.d.ts +0 -1
  59. package/dist/common/utils.js +125 -0
  60. package/dist/core/agent/layered_agent/ability_helper.d.ts +0 -1
  61. package/dist/core/agent/layered_agent/ability_helper.js +125 -0
  62. package/dist/core/agent/layered_agent/agent.d.ts +0 -1
  63. package/dist/core/agent/layered_agent/agent.js +37 -0
  64. package/dist/core/agent/layered_agent/agent_registry.d.ts +0 -1
  65. package/dist/core/agent/layered_agent/agent_registry.js +75 -0
  66. package/dist/core/agent/layered_agent/decision.d.ts +0 -1
  67. package/dist/core/agent/layered_agent/decision.js +478 -0
  68. package/dist/core/agent/layered_agent/execute_agent/action_handler.d.ts +0 -1
  69. package/dist/core/agent/layered_agent/execute_agent/action_handler.js +155 -0
  70. package/dist/core/agent/layered_agent/execute_agent/agent_factory.d.ts +1 -2
  71. package/dist/core/agent/layered_agent/execute_agent/agent_factory.js +41 -0
  72. package/dist/core/agent/layered_agent/execute_agent/base_agent.d.ts +0 -1
  73. package/dist/core/agent/layered_agent/execute_agent/base_agent.js +112 -0
  74. package/dist/core/agent/layered_agent/execute_agent/general_agent.d.ts +0 -1
  75. package/dist/core/agent/layered_agent/execute_agent/general_agent.js +207 -0
  76. package/dist/core/agent/layered_agent/execute_agent/glm_agent.d.ts +0 -1
  77. package/dist/core/agent/layered_agent/execute_agent/glm_agent.js +241 -0
  78. package/dist/core/agent/layered_agent/execute_agent/i18n.d.ts +0 -1
  79. package/dist/core/agent/layered_agent/execute_agent/i18n.js +34 -0
  80. package/dist/core/agent/layered_agent/execute_agent/index.d.ts +0 -1
  81. package/dist/core/agent/layered_agent/execute_agent/index.js +67 -0
  82. package/dist/core/agent/layered_agent/execute_agent/mai_ui_agent.d.ts +0 -1
  83. package/dist/core/agent/layered_agent/execute_agent/mai_ui_agent.js +316 -0
  84. package/dist/core/agent/layered_agent/execute_agent/mcp_prompts.d.ts +0 -1
  85. package/dist/core/agent/layered_agent/execute_agent/mcp_prompts.js +154 -0
  86. package/dist/core/agent/layered_agent/execute_agent/parser/general_parser.d.ts +0 -1
  87. package/dist/core/agent/layered_agent/execute_agent/parser/general_parser.js +243 -0
  88. package/dist/core/agent/layered_agent/execute_agent/parser/glm_parser.d.ts +0 -1
  89. package/dist/core/agent/layered_agent/execute_agent/parser/glm_parser.js +139 -0
  90. package/dist/core/agent/layered_agent/execute_agent/parser/index.d.ts +0 -1
  91. package/dist/core/agent/layered_agent/execute_agent/parser/index.js +9 -0
  92. package/dist/core/agent/layered_agent/execute_agent/parser/mai_ui_parser.d.ts +0 -1
  93. package/dist/core/agent/layered_agent/execute_agent/parser/mai_ui_parser.js +94 -0
  94. package/dist/core/agent/layered_agent/execute_agent/prompts.d.ts +0 -1
  95. package/dist/core/agent/layered_agent/execute_agent/prompts.js +109 -0
  96. package/dist/core/agent/layered_agent/execute_agent/simple_reporter.d.ts +0 -1
  97. package/dist/core/agent/layered_agent/execute_agent/simple_reporter.js +33 -0
  98. package/dist/core/agent/layered_agent/execute_agent/utils.d.ts +0 -1
  99. package/dist/core/agent/layered_agent/execute_agent/utils.js +52 -0
  100. package/dist/core/agent/report_analyzer_agent/agent.d.ts +0 -1
  101. package/dist/core/agent/report_analyzer_agent/agent.js +565 -0
  102. package/dist/core/agent/report_analyzer_agent/config.d.ts +0 -1
  103. package/dist/core/agent/report_analyzer_agent/config.js +22 -0
  104. package/dist/core/agent/report_analyzer_agent/data_loader.d.ts +0 -1
  105. package/dist/core/agent/report_analyzer_agent/data_loader.js +255 -0
  106. package/dist/core/agent/report_analyzer_agent/guardrails.d.ts +0 -1
  107. package/dist/core/agent/report_analyzer_agent/guardrails.js +99 -0
  108. package/dist/core/agent/report_analyzer_agent/hooks.d.ts +0 -1
  109. package/dist/core/agent/report_analyzer_agent/hooks.js +31 -0
  110. package/dist/core/agent/report_analyzer_agent/index.d.ts +0 -1
  111. package/dist/core/agent/report_analyzer_agent/index.js +52 -0
  112. package/dist/core/agent/report_analyzer_agent/key_steps_builder.d.ts +0 -1
  113. package/dist/core/agent/report_analyzer_agent/key_steps_builder.js +42 -0
  114. package/dist/core/agent/report_analyzer_agent/mapping.d.ts +0 -1
  115. package/dist/core/agent/report_analyzer_agent/mapping.js +133 -0
  116. package/dist/core/agent/report_analyzer_agent/parse.d.ts +0 -1
  117. package/dist/core/agent/report_analyzer_agent/parse.js +375 -0
  118. package/dist/core/agent/report_analyzer_agent/prompt.d.ts +0 -1
  119. package/dist/core/agent/report_analyzer_agent/prompt.js +300 -0
  120. package/dist/core/agent/report_analyzer_agent/report_writer.d.ts +0 -1
  121. package/dist/core/agent/report_analyzer_agent/report_writer.js +558 -0
  122. package/dist/core/agent/report_analyzer_agent/tools.d.ts +0 -1
  123. package/dist/core/agent/report_analyzer_agent/tools.js +150 -0
  124. package/dist/core/agent/report_analyzer_agent/types.d.ts +0 -1
  125. package/dist/core/agent/report_analyzer_agent/types.js +274 -0
  126. package/dist/core/agent/rewrite_agent/agent.d.ts +0 -1
  127. package/dist/core/agent/rewrite_agent/agent.js +209 -0
  128. package/dist/core/agent/rewrite_agent/guardrails.d.ts +0 -1
  129. package/dist/core/agent/rewrite_agent/guardrails.js +95 -0
  130. package/dist/core/agent/rewrite_agent/mapping.d.ts +0 -1
  131. package/dist/core/agent/rewrite_agent/mapping.js +56 -0
  132. package/dist/core/agent/rewrite_agent/parse.d.ts +0 -1
  133. package/dist/core/agent/rewrite_agent/parse.js +121 -0
  134. package/dist/core/agent/rewrite_agent/types.d.ts +0 -1
  135. package/dist/core/agent/rewrite_agent/types.js +37 -0
  136. package/dist/core/agent/single_agent/agent.d.ts +0 -1
  137. package/dist/core/agent/single_agent/agent.js +798 -0
  138. package/dist/core/agent/single_agent/hook_manager.d.ts +0 -1
  139. package/dist/core/agent/single_agent/hook_manager.js +60 -0
  140. package/dist/core/agent/single_agent/hooks.d.ts +0 -1
  141. package/dist/core/agent/single_agent/hooks.js +288 -0
  142. package/dist/core/agent/single_agent/image_utils.d.ts +0 -1
  143. package/dist/core/agent/single_agent/image_utils.js +159 -0
  144. package/dist/core/agent/single_agent/scroll_search_agent.d.ts +0 -1
  145. package/dist/core/agent/single_agent/scroll_search_agent.js +376 -0
  146. package/dist/core/agent/single_agent/subagent_manager.d.ts +0 -1
  147. package/dist/core/agent/single_agent/subagent_manager.js +73 -0
  148. package/dist/core/agent/single_agent/tool_recorder_hook.d.ts +0 -1
  149. package/dist/core/agent/single_agent/tool_recorder_hook.js +42 -0
  150. package/dist/core/agent/types.d.ts +0 -1
  151. package/dist/core/agent/types.js +2 -0
  152. package/dist/core/agent/utils/message_builder.d.ts +0 -1
  153. package/dist/core/agent/utils/message_builder.js +138 -0
  154. package/dist/core/device/device_protocol.d.ts +0 -1
  155. package/dist/core/device/device_protocol.js +2 -0
  156. package/dist/core/device/hdc/apps.d.ts +0 -1
  157. package/dist/core/device/hdc/apps.js +437 -0
  158. package/dist/core/device/hdc/device.d.ts +0 -1
  159. package/dist/core/device/hdc/device.js +219 -0
  160. package/dist/core/device/hdc/index.d.ts +0 -1
  161. package/dist/core/device/hdc/index.js +31 -0
  162. package/dist/core/device/hdc/input.d.ts +0 -1
  163. package/dist/core/device/hdc/input.js +74 -0
  164. package/dist/core/device/hdc/screenshot.d.ts +0 -1
  165. package/dist/core/device/hdc/screenshot.js +171 -0
  166. package/dist/core/device/index.d.ts +0 -1
  167. package/dist/core/device/index.js +70 -0
  168. package/dist/core/device/types.d.ts +0 -1
  169. package/dist/core/device/types.js +2 -0
  170. package/dist/core/knowledge/knowledge_manager.d.ts +0 -1
  171. package/dist/core/knowledge/knowledge_manager.js +70 -0
  172. package/dist/core/knowledge/vectordb.d.ts +0 -1
  173. package/dist/core/knowledge/vectordb.js +283 -0
  174. package/dist/core/mcp/adapter_factory.d.ts +0 -1
  175. package/dist/core/mcp/adapter_factory.js +99 -0
  176. package/dist/core/mcp/android_adapter.d.ts +1 -2
  177. package/dist/core/mcp/android_adapter.js +286 -0
  178. package/dist/core/mcp/base_adapter.d.ts +0 -1
  179. package/dist/core/mcp/base_adapter.js +86 -0
  180. package/dist/core/mcp/harmony_hdc_adapter.d.ts +9 -1
  181. package/dist/core/mcp/harmony_hdc_adapter.js +782 -0
  182. package/dist/core/mcp/ios_adapter.d.ts +1 -2
  183. package/dist/core/mcp/ios_adapter.js +286 -0
  184. package/dist/core/mcp/local_tools.d.ts +0 -1
  185. package/dist/core/mcp/local_tools.js +41 -0
  186. package/dist/core/mcp/mcp_tools.d.ts +0 -1
  187. package/dist/core/mcp/mcp_tools.js +382 -0
  188. package/dist/core/mcp/types.d.ts +0 -1
  189. package/dist/core/mcp/types.js +6 -0
  190. package/dist/core/memory/compressed_session.d.ts +0 -1
  191. package/dist/core/memory/compressed_session.js +182 -0
  192. package/dist/core/memory/context_compressor.d.ts +0 -1
  193. package/dist/core/memory/context_compressor.js +176 -0
  194. package/dist/core/memory/index.d.ts +0 -1
  195. package/dist/core/memory/index.js +22 -0
  196. package/dist/core/memory/memory_manager.d.ts +0 -1
  197. package/dist/core/memory/memory_manager.js +28 -0
  198. package/dist/core/memory/reflector.d.ts +0 -1
  199. package/dist/core/memory/reflector.js +95 -0
  200. package/dist/core/memory/session_factory.d.ts +0 -1
  201. package/dist/core/memory/session_factory.js +29 -0
  202. package/dist/core/memory/tool_player.d.ts +0 -1
  203. package/dist/core/memory/tool_player.js +225 -0
  204. package/dist/core/memory/tool_recorder.d.ts +0 -1
  205. package/dist/core/memory/tool_recorder.js +126 -0
  206. package/dist/core/preprocessor/task_splitter.d.ts +0 -1
  207. package/dist/core/preprocessor/task_splitter.js +112 -0
  208. package/dist/core/prompt/prompt_loader.d.ts +0 -1
  209. package/dist/core/prompt/prompt_loader.js +313 -0
  210. package/dist/core/skill/skill_manager.d.ts +0 -1
  211. package/dist/core/skill/skill_manager.js +299 -0
  212. package/dist/data_types/action.d.ts +0 -1
  213. package/dist/data_types/action.js +2 -0
  214. package/dist/data_types/agent.d.ts +0 -1
  215. package/dist/data_types/agent.js +2 -0
  216. package/dist/data_types/device.d.ts +0 -1
  217. package/dist/data_types/device.js +2 -0
  218. package/dist/data_types/index.d.ts +0 -1
  219. package/dist/data_types/index.js +6 -0
  220. package/dist/data_types/report.d.ts +0 -1
  221. package/dist/data_types/report.js +6 -0
  222. package/dist/data_types/task.d.ts +0 -1
  223. package/dist/data_types/task.js +2 -0
  224. package/dist/index.d.ts +1 -2
  225. package/dist/index.js +164 -1
  226. package/dist/loop/cli.d.ts +0 -1
  227. package/dist/loop/cli.js +127 -0
  228. package/dist/loop/orchestrator.d.ts +0 -1
  229. package/dist/loop/orchestrator.js +314 -0
  230. package/dist/loop/result_writer.d.ts +0 -1
  231. package/dist/loop/result_writer.js +260 -0
  232. package/dist/loop/types.d.ts +0 -1
  233. package/dist/loop/types.js +82 -0
  234. package/dist/mcp-server/server.d.ts +0 -1
  235. package/dist/mcp-server/server.js +341 -0
  236. package/dist/mcp-server/types.d.ts +283 -118
  237. package/dist/mcp-server/types.js +202 -0
  238. package/dist/reporter/batch_summary.d.ts +0 -1
  239. package/dist/reporter/batch_summary.js +197 -0
  240. package/dist/reporter/generator.d.ts +0 -1
  241. package/dist/reporter/generator.js +772 -0
  242. package/dist/reporter/types.d.ts +14 -15
  243. package/dist/reporter/types.js +44 -0
  244. package/dist/tools/batch_runner.d.ts +1 -1
  245. package/dist/tools/batch_runner.js +731 -0
  246. package/package.json +5 -3
  247. package/dist/common/config/config.yaml +0 -113
  248. package/dist/hypium_generator/generator.d.ts +0 -38
@@ -0,0 +1,117 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.DashScopeTokenUsage = exports.TokenUsage = void 0;
4
+ exports.resolveTokenType = resolveTokenType;
5
+ const DASHSCOPE_DOMAINS = new Set(['dashscope.aliyuncs.com']);
6
+ class TokenUsage {
7
+ inputTokens;
8
+ outputTokens;
9
+ totalTokens;
10
+ cachedTokens;
11
+ reasoningTokens;
12
+ constructor(inputTokens = 0, outputTokens = 0, totalTokens = 0, cachedTokens = 0, reasoningTokens = 0) {
13
+ this.inputTokens = inputTokens;
14
+ this.outputTokens = outputTokens;
15
+ this.totalTokens = totalTokens;
16
+ this.cachedTokens = cachedTokens;
17
+ this.reasoningTokens = reasoningTokens;
18
+ }
19
+ get uncachedTokens() {
20
+ return this.inputTokens - this.cachedTokens;
21
+ }
22
+ get normalizedTokens() {
23
+ return this.uncachedTokens * 1.0 + this.cachedTokens * 0.2 + this.outputTokens * 1.0;
24
+ }
25
+ toDict() {
26
+ return {
27
+ input_tokens: this.inputTokens,
28
+ output_tokens: this.outputTokens,
29
+ total_tokens: this.totalTokens,
30
+ cached_tokens: this.cachedTokens,
31
+ reasoning_tokens: this.reasoningTokens,
32
+ normalized_tokens: Math.round(this.normalizedTokens * 10) / 10,
33
+ };
34
+ }
35
+ toString() {
36
+ return (`Tokens: total=${this.totalTokens} ` +
37
+ `input=${this.inputTokens} output=${this.outputTokens} ` +
38
+ `cached=${this.cachedTokens} ` +
39
+ `reasoning=${this.reasoningTokens} ` +
40
+ `normalized=${this.normalizedTokens.toFixed(1)}`);
41
+ }
42
+ static fromUsageObj(usageObj) {
43
+ if (!usageObj)
44
+ return null;
45
+ const inputTokens = usageObj.input_tokens ?? 0;
46
+ const outputTokens = usageObj.output_tokens ?? 0;
47
+ const totalTokens = usageObj.total_tokens ?? 0;
48
+ let cachedTokens = 0;
49
+ let reasoningTokens = 0;
50
+ const inputDetails = usageObj.input_tokens_details;
51
+ if (inputDetails) {
52
+ cachedTokens = inputDetails.cached_tokens ?? 0;
53
+ }
54
+ const outputDetails = usageObj.output_tokens_details;
55
+ if (outputDetails) {
56
+ reasoningTokens = outputDetails.reasoning_tokens ?? 0;
57
+ }
58
+ return new TokenUsage(inputTokens, outputTokens, totalTokens, cachedTokens, reasoningTokens);
59
+ }
60
+ }
61
+ exports.TokenUsage = TokenUsage;
62
+ class DashScopeTokenUsage extends TokenUsage {
63
+ cacheCreationTokens;
64
+ constructor(inputTokens = 0, outputTokens = 0, totalTokens = 0, cachedTokens = 0, reasoningTokens = 0, cacheCreationTokens = 0) {
65
+ super(inputTokens, outputTokens, totalTokens, cachedTokens, reasoningTokens);
66
+ this.cacheCreationTokens = cacheCreationTokens;
67
+ }
68
+ get uncachedTokens() {
69
+ return this.inputTokens - this.cachedTokens - this.cacheCreationTokens;
70
+ }
71
+ get normalizedTokens() {
72
+ return (this.uncachedTokens * 1.0 +
73
+ this.cacheCreationTokens * 1.25 +
74
+ this.cachedTokens * 0.2 +
75
+ this.outputTokens * 1.0);
76
+ }
77
+ toString() {
78
+ return (`Tokens: total=${this.totalTokens} ` +
79
+ `input=${this.inputTokens} output=${this.outputTokens} ` +
80
+ `cached=${this.cachedTokens} ` +
81
+ `reasoning=${this.reasoningTokens} ` +
82
+ `cache_creation=${this.cacheCreationTokens} ` +
83
+ `normalized=${this.normalizedTokens.toFixed(1)}`);
84
+ }
85
+ static fromUsageObj(usageObj) {
86
+ if (!usageObj)
87
+ return null;
88
+ const base = TokenUsage.fromUsageObj(usageObj);
89
+ if (!base)
90
+ return null;
91
+ let cacheCreationTokens = 0;
92
+ const inputDetails = usageObj.input_tokens_details;
93
+ if (inputDetails) {
94
+ cacheCreationTokens = inputDetails.cache_creation_input_tokens ?? 0;
95
+ }
96
+ return new DashScopeTokenUsage(base.inputTokens, base.outputTokens, base.totalTokens, base.cachedTokens, base.reasoningTokens, cacheCreationTokens);
97
+ }
98
+ }
99
+ exports.DashScopeTokenUsage = DashScopeTokenUsage;
100
+ function resolveTokenType(baseUrl) {
101
+ if (!baseUrl)
102
+ return TokenUsage;
103
+ try {
104
+ const url = new URL(baseUrl);
105
+ const domain = url.hostname.toLowerCase();
106
+ if (DASHSCOPE_DOMAINS.has(domain))
107
+ return DashScopeTokenUsage;
108
+ }
109
+ catch {
110
+ const lower = baseUrl.toLowerCase();
111
+ for (const d of DASHSCOPE_DOMAINS) {
112
+ if (lower.includes(d))
113
+ return DashScopeTokenUsage;
114
+ }
115
+ }
116
+ return TokenUsage;
117
+ }
@@ -41,4 +41,3 @@ export declare function normalizeToolCoordinates(toolName: string, args: Record<
41
41
  * Values >= 1000 are shown as `X.XK`, otherwise the raw number is returned.
42
42
  */
43
43
  export declare function formatTokenDisplay(total: number): string;
44
- //# sourceMappingURL=utils.d.ts.map
@@ -0,0 +1,125 @@
1
+ "use strict";
2
+ /**
3
+ * General utility functions ported from python/AutoTest/common/utils.py.
4
+ */
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.sanitizeFilename = sanitizeFilename;
7
+ exports.applyThinkingConfig = applyThinkingConfig;
8
+ exports.normalizeCoord = normalizeCoord;
9
+ exports.normalizeToolCoordinates = normalizeToolCoordinates;
10
+ exports.formatTokenDisplay = formatTokenDisplay;
11
+ /** Windows-invalid filename chars and control chars are stripped/replaced. */
12
+ const INVALID_FILENAME_CHARS = '/\\:*?"<>|';
13
+ /**
14
+ * Sanitize a string into a safe filename (Windows-compatible).
15
+ *
16
+ * Mirrors python `sanitize_filename`: replaces `/ \ : * ? " < > |` with `_`,
17
+ * drops control chars, strips leading/trailing dots and spaces, collapses
18
+ * repeated underscores, and truncates to `maxLength`.
19
+ */
20
+ function sanitizeFilename(name, maxLength = 50) {
21
+ if (!name)
22
+ return 'unnamed';
23
+ let s = name;
24
+ for (const ch of INVALID_FILENAME_CHARS) {
25
+ s = s.split(ch).join('_');
26
+ }
27
+ // Remove control chars (\x00-\x1f, \x7f-\x9f)
28
+ s = s.replace(/[\x00-\x1f\x7f-\x9f]/g, '');
29
+ // Strip leading/trailing dots and spaces
30
+ s = s.replace(/^[.\s]+/, '').replace(/[.\s]+$/, '');
31
+ // Collapse repeated underscores
32
+ s = s.replace(/_+/g, '_');
33
+ if (s.length > maxLength) {
34
+ s = s.slice(0, maxLength).replace(/_+$/, '');
35
+ }
36
+ return s || 'unnamed';
37
+ }
38
+ /**
39
+ * Inject `enable_thinking` into the LLM request `extra_body`.
40
+ *
41
+ * Mirrors python `apply_thinking_config`. Tri-state: `null` = skip (use model
42
+ * default), `true`/`false` = explicit value, written into
43
+ * `chat_template_kwargs.enable_thinking` (vLLM format). Mutates and returns
44
+ * `extraBody` in place.
45
+ */
46
+ function applyThinkingConfig(extraBody, enableThinking) {
47
+ if (enableThinking !== null) {
48
+ const kwargs = extraBody.chat_template_kwargs;
49
+ if (kwargs) {
50
+ kwargs.enable_thinking = enableThinking;
51
+ }
52
+ else {
53
+ extraBody.chat_template_kwargs = { enable_thinking: enableThinking };
54
+ }
55
+ }
56
+ return extraBody;
57
+ }
58
+ /**
59
+ * Normalize a single coordinate: keep if already in [0,1], else divide by 1000
60
+ * (per-mille → 0-1). Mirrors python `normalize_coord`.
61
+ */
62
+ function normalizeCoord(coord) {
63
+ if (coord >= 0 && coord <= 1)
64
+ return coord;
65
+ return coord / 1000;
66
+ }
67
+ const _COORD_TOOLS_POINT = new Set(['click', 'double_click', 'long_press', 'long_click', 'tap', 'double_tap']);
68
+ const _COORD_TOOLS_SWIPE = new Set(['swipe', 'drag']);
69
+ /**
70
+ * Coordinate defense layer: detect per-mille (0-1000) coordinates and
71
+ * selectively divide >1 values by 1000 to normalize to the 0-1 range.
72
+ *
73
+ * Mirrors python `normalize_tool_coordinates`. Covers both combine format
74
+ * (`pos`/`start`/`end` as [x,y]) and split format (`x`/`y`,
75
+ * `start_x`/`start_y`, `end_x`/`end_y`). Only values >1 are converted; values
76
+ * already in [0,1] are preserved (handles mixed output like [0.85, 780]).
77
+ *
78
+ * Mutates `args` in place. Returns true if any conversion occurred.
79
+ */
80
+ function normalizeToolCoordinates(toolName, args) {
81
+ const name = String(toolName ?? '').toLowerCase();
82
+ if (!_COORD_TOOLS_POINT.has(name) && !_COORD_TOOLS_SWIPE.has(name))
83
+ return false;
84
+ let converted = false;
85
+ const isNum = (v) => typeof v === 'number';
86
+ // ---- combine format: value is [x, y] ----
87
+ for (const field of ['pos', 'start', 'end']) {
88
+ const val = args[field];
89
+ if (Array.isArray(val) && val.length === 2 && isNum(val[0]) && isNum(val[1])) {
90
+ const [a, b] = val;
91
+ if (a > 1.0 || b > 1.0) {
92
+ args[field] = [
93
+ a > 1.0 ? a / 1000 : a,
94
+ b > 1.0 ? b / 1000 : b,
95
+ ];
96
+ converted = true;
97
+ }
98
+ }
99
+ }
100
+ // ---- split format: paired scalar coords ----
101
+ for (const [xKey, yKey] of [['x', 'y'], ['start_x', 'start_y'], ['end_x', 'end_y']]) {
102
+ if (xKey in args && yKey in args) {
103
+ const xv = args[xKey];
104
+ const yv = args[yKey];
105
+ if (isNum(xv) && isNum(yv)) {
106
+ if (xv > 1.0 || yv > 1.0) {
107
+ if (xv > 1.0)
108
+ args[xKey] = xv / 1000;
109
+ if (yv > 1.0)
110
+ args[yKey] = yv / 1000;
111
+ converted = true;
112
+ }
113
+ }
114
+ }
115
+ }
116
+ return converted;
117
+ }
118
+ /**
119
+ * Format a token count for display.
120
+ *
121
+ * Values >= 1000 are shown as `X.XK`, otherwise the raw number is returned.
122
+ */
123
+ function formatTokenDisplay(total) {
124
+ return total >= 1000 ? `${(total / 1000).toFixed(1)}K` : String(total);
125
+ }
@@ -33,4 +33,3 @@ export declare function getBundleInfo(driver: AbilityDriver, bundleName: string)
33
33
  export declare function getIconAbilities(driver: AbilityDriver, bundleName: string): IconAbilityInfo[];
34
34
  export declare function getMainAbility(driver: AbilityDriver, bundleName: string): IconAbilityInfo | null;
35
35
  export {};
36
- //# sourceMappingURL=ability_helper.d.ts.map
@@ -0,0 +1,125 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getHapInfo = getHapInfo;
4
+ exports.getHapVersionCode = getHapVersionCode;
5
+ exports.getBundleInfo = getBundleInfo;
6
+ exports.getIconAbilities = getIconAbilities;
7
+ exports.getMainAbility = getMainAbility;
8
+ function getHapInfo(hapPath) {
9
+ try {
10
+ const { execSync } = require('child_process');
11
+ const result = execSync(process.platform === 'win32'
12
+ ? `powershell -Command "Add-Type -AssemblyName System.IO.Compression.FileSystem; [System.IO.Compression.ZipFile]::OpenRead('${hapPath}').GetEntry('pack.info').Open() | ForEach-Object { [System.IO.StreamReader]::new($_).ReadToEnd() }"`
13
+ : `unzip -p "${hapPath}" pack.info`, { encoding: 'utf-8', timeout: 10000, windowsHide: true });
14
+ return JSON.parse(result);
15
+ }
16
+ catch {
17
+ return {};
18
+ }
19
+ }
20
+ function getHapVersionCode(hapPath) {
21
+ const info = getHapInfo(hapPath);
22
+ try {
23
+ const summary = info.summary;
24
+ const app = summary?.app;
25
+ const version = app?.version;
26
+ const code = version?.code;
27
+ return typeof code === 'number' ? code : -1;
28
+ }
29
+ catch {
30
+ return -1;
31
+ }
32
+ }
33
+ function getBundleInfo(driver, bundleName) {
34
+ const info = driver.executeShellCommand(`bm dump -n ${bundleName}`);
35
+ let bundleInfo = null;
36
+ const start = info.indexOf(':');
37
+ if (start < 0) {
38
+ throw new Error(`Can't get bundle-info for [${bundleName}], please check if application installed`);
39
+ }
40
+ try {
41
+ const jsonData = info.slice(start + 1).trim();
42
+ bundleInfo = JSON.parse(jsonData);
43
+ }
44
+ catch (e) {
45
+ driver.logError?.(`Fail get bundle info: ${e instanceof Error ? e.message : String(e)}`);
46
+ }
47
+ if (bundleInfo === null) {
48
+ throw new Error(`Can't get bundle-info for [${bundleName}], please check if application installed`);
49
+ }
50
+ return bundleInfo;
51
+ }
52
+ function isLauncherAbility(abilityInfo) {
53
+ const skills = abilityInfo.skills;
54
+ if (!skills || skills.length <= 0) {
55
+ return false;
56
+ }
57
+ for (const skill of skills) {
58
+ const actions = skill.actions ?? [];
59
+ if (actions.includes('action.system.home') || actions.includes('ohos.want.action.home')) {
60
+ return true;
61
+ }
62
+ return false;
63
+ }
64
+ return false;
65
+ }
66
+ function getIconAbilities(driver, bundleName) {
67
+ const result = [];
68
+ const bundleInfo = getBundleInfo(driver, bundleName);
69
+ const hapModuleInfos = bundleInfo.hapModuleInfos ?? [];
70
+ const mainEntry = bundleInfo.mainEntry;
71
+ for (const hapModuleInfo of hapModuleInfos) {
72
+ const abilityInfos = hapModuleInfo.abilityInfos;
73
+ const moduleMain = hapModuleInfo.mainAbility;
74
+ if (!abilityInfos) {
75
+ driver.logWarning?.('Fail to parse moduleInfo item, missing abilityInfos');
76
+ continue;
77
+ }
78
+ for (const abilityInfo of abilityInfos) {
79
+ try {
80
+ if (isLauncherAbility(abilityInfo)) {
81
+ result.push({
82
+ name: abilityInfo.name,
83
+ moduleName: abilityInfo.moduleName,
84
+ moduleMainAbility: moduleMain,
85
+ mainModule: mainEntry,
86
+ });
87
+ }
88
+ }
89
+ catch (e) {
90
+ driver.logWarning?.(`Fail to parse ability_info item, ${e instanceof Error ? e.message : String(e)}`);
91
+ }
92
+ }
93
+ }
94
+ return result;
95
+ }
96
+ function isEqualAndNotNone(a, b) {
97
+ return a === b && a !== null && a !== undefined && a !== '';
98
+ }
99
+ function getMainAbility(driver, bundleName) {
100
+ const abilities = getIconAbilities(driver, bundleName);
101
+ if (abilities.length <= 0) {
102
+ return null;
103
+ }
104
+ for (const item of abilities) {
105
+ let score = 0;
106
+ const name = item.name;
107
+ const moduleMainAbility = item.moduleMainAbility;
108
+ const moduleName = item.moduleName;
109
+ const mainModule = item.mainModule;
110
+ if (isEqualAndNotNone(name, moduleMainAbility)) {
111
+ score += 20;
112
+ }
113
+ if (isEqualAndNotNone(moduleName, mainModule)) {
114
+ score += 100;
115
+ }
116
+ item.score = score;
117
+ }
118
+ abilities.sort((a, b) => (b.score ?? 0) - (a.score ?? 0));
119
+ driver.logDebug?.(`all icon abilities: ${JSON.stringify(abilities)}`);
120
+ if (abilities.length > 1) {
121
+ const names = abilities.map((ability) => ability.name);
122
+ driver.logWarning?.(`bundle has multiple abilities, ${JSON.stringify(names)}`);
123
+ }
124
+ return abilities[0];
125
+ }
@@ -12,4 +12,3 @@ export declare class LayeredAgent {
12
12
  constructor(adapter: MCPDeviceAdapter, config: AppConfig, reportGenerator: ReportGenerator, hooks?: AgentHooks, llmCaller?: LLMCaller);
13
13
  run(args: SingleAgentArgs): Promise<AgentResult>;
14
14
  }
15
- //# sourceMappingURL=agent.d.ts.map
@@ -0,0 +1,37 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.LayeredAgent = void 0;
4
+ const decision_1 = require("./decision");
5
+ const agent_registry_1 = require("./agent_registry");
6
+ class LayeredAgent {
7
+ adapter;
8
+ config;
9
+ reportGenerator;
10
+ hooks;
11
+ llmCaller;
12
+ constructor(adapter, config, reportGenerator, hooks, llmCaller) {
13
+ this.adapter = adapter;
14
+ this.config = config;
15
+ this.reportGenerator = reportGenerator;
16
+ this.hooks = hooks;
17
+ this.llmCaller = llmCaller;
18
+ }
19
+ async run(args) {
20
+ agent_registry_1.agentRegistry.clear();
21
+ const result = await (0, decision_1.decisionChat)({
22
+ config: this.config,
23
+ adapter: this.adapter,
24
+ reportGenerator: this.reportGenerator,
25
+ args,
26
+ hooks: this.hooks,
27
+ llmCaller: this.llmCaller,
28
+ });
29
+ const status = (result.status || 'UNKNOWN');
30
+ return {
31
+ finalOutput: result.finalOutput,
32
+ status,
33
+ savedFiles: result.savedFiles,
34
+ };
35
+ }
36
+ }
37
+ exports.LayeredAgent = LayeredAgent;
@@ -31,4 +31,3 @@ declare class AgentRegistryImpl {
31
31
  }
32
32
  export declare const agentRegistry: AgentRegistryImpl;
33
33
  export type { AgentRegistryImpl };
34
- //# sourceMappingURL=agent_registry.d.ts.map
@@ -0,0 +1,75 @@
1
+ "use strict";
2
+ /**
3
+ * Global agent registry (aligned with python hybrid_agent/utils/agent_registry.py).
4
+ *
5
+ * Singleton for managing cross-module shared state: executor agent, tool
6
+ * manager (adapter), report generator, last click info, and generic key-value
7
+ * state. Backward-compatible with the old layered-only API (setExecutorAgent /
8
+ * getExecutorAgent delegate to the generic set/get).
9
+ */
10
+ Object.defineProperty(exports, "__esModule", { value: true });
11
+ exports.agentRegistry = void 0;
12
+ const logger_1 = require("../../../common/logger");
13
+ class AgentRegistryImpl {
14
+ static instance = null;
15
+ _state = new Map();
16
+ _initialized = false;
17
+ static getInstance() {
18
+ if (AgentRegistryImpl.instance === null) {
19
+ AgentRegistryImpl.instance = new AgentRegistryImpl();
20
+ }
21
+ return AgentRegistryImpl.instance;
22
+ }
23
+ // ---- Generic set/get (aligned with python AgentRegistry.set/get) ----
24
+ set(key, value) {
25
+ this._state.set(key, value);
26
+ this._initialized = true;
27
+ }
28
+ get(key, defaultValue) {
29
+ return this._state.get(key) ?? defaultValue;
30
+ }
31
+ clearKey(key) {
32
+ this._state.delete(key);
33
+ }
34
+ // ---- Executor agent (backward compat with layered agent_registry) ----
35
+ setExecutorAgent(agent) {
36
+ this.set('executor_agent', agent);
37
+ }
38
+ getExecutorAgent() {
39
+ return this.get('executor_agent', null);
40
+ }
41
+ // ---- Tool manager / adapter (aligned with python set_tool_manager) ----
42
+ setToolManager(adapter) {
43
+ this.set('tool_manager', adapter);
44
+ logger_1.logger.debug('[AgentRegistry] tool_manager (adapter) registered');
45
+ }
46
+ getToolManager() {
47
+ return this.get('tool_manager', null);
48
+ }
49
+ // ---- Report generator (aligned with python set_report_generator) ----
50
+ setReportGenerator(rg) {
51
+ this.set('report_generator', rg);
52
+ }
53
+ getReportGenerator() {
54
+ return this.get('report_generator', null);
55
+ }
56
+ // ---- Last click info (aligned with python set_last_click_info) ----
57
+ setLastClickInfo(info) {
58
+ this.set('last_click_info', info);
59
+ }
60
+ getLastClickInfo() {
61
+ return this.get('last_click_info', null);
62
+ }
63
+ clearLastClickInfo() {
64
+ this.clearKey('last_click_info');
65
+ }
66
+ // ---- Status / cleanup ----
67
+ isInitialized() {
68
+ return this._initialized;
69
+ }
70
+ clear() {
71
+ this._state.clear();
72
+ this._initialized = false;
73
+ }
74
+ }
75
+ exports.agentRegistry = AgentRegistryImpl.getInstance();
@@ -79,4 +79,3 @@ export interface DecisionChatArgs {
79
79
  }
80
80
  export declare function decisionChat(chatArgs: DecisionChatArgs): Promise<DecisionResult>;
81
81
  export type { AgentResult };
82
- //# sourceMappingURL=decision.d.ts.map