@autotest/agent 0.0.6 → 0.0.7

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 (153) hide show
  1. package/README.md +7 -0
  2. package/dist/api/agent_api.d.ts +2 -2
  3. package/dist/autotest-cli.js +1 -397
  4. package/dist/common/config/config.yaml +4 -0
  5. package/dist/common/config/manager.d.ts +4 -4
  6. package/dist/common/config/types.d.ts +5 -0
  7. package/dist/common/dfx/index.d.ts +1 -1
  8. package/dist/core/agent/single_agent/agent.d.ts +1 -0
  9. package/dist/core/device/device_protocol.d.ts +1 -1
  10. package/dist/core/knowledge/knowledge_manager.d.ts +3 -3
  11. package/dist/core/knowledge/vectordb.d.ts +5 -5
  12. package/dist/core/mcp/harmony_hdc_adapter.d.ts +1 -0
  13. package/dist/core/mcp/mcp_tools.d.ts +1 -0
  14. package/dist/core/mcp/verify_tool.d.ts +12 -0
  15. package/dist/core/prompt/templates/single/single_v2.0.md +15 -0
  16. package/dist/data_types/device.d.ts +1 -1
  17. package/dist/data_types/index.d.ts +1 -1
  18. package/dist/index.d.ts +4 -4
  19. package/dist/index.js +1 -163
  20. package/dist/tools/batch_runner.js +1 -745
  21. package/dist/tools/case_runner/runner.js +1 -410
  22. package/dist/tools/config/config_tool.js +1 -339
  23. package/dist/tools/prompt_compare/compare_runner.js +1 -360
  24. package/package.json +2 -2
  25. package/dist/api/agent_api.js +0 -550
  26. package/dist/api/autotest_agent.js +0 -205
  27. package/dist/api/types.js +0 -11
  28. package/dist/common/case_manager.js +0 -91
  29. package/dist/common/collect_case.js +0 -128
  30. package/dist/common/common_errors.js +0 -66
  31. package/dist/common/config/config_validator.js +0 -28
  32. package/dist/common/config/manager.js +0 -257
  33. package/dist/common/config/output.js +0 -59
  34. package/dist/common/config/types.js +0 -185
  35. package/dist/common/dfx/client_factory.js +0 -62
  36. package/dist/common/dfx/context.js +0 -23
  37. package/dist/common/dfx/index.js +0 -15
  38. package/dist/common/dfx/recorder.js +0 -191
  39. package/dist/common/dfx/recording_fetch.js +0 -228
  40. package/dist/common/dfx/source.js +0 -13
  41. package/dist/common/image_cacher.js +0 -36
  42. package/dist/common/image_helper.js +0 -128
  43. package/dist/common/image_similarity.js +0 -171
  44. package/dist/common/llm_cache/cache_transport.js +0 -102
  45. package/dist/common/llm_cache/prompt_cache.js +0 -113
  46. package/dist/common/logger.js +0 -158
  47. package/dist/common/model/custom_model.js +0 -487
  48. package/dist/common/model/index.js +0 -5
  49. package/dist/common/path_utils.js +0 -88
  50. package/dist/common/result_parser.js +0 -49
  51. package/dist/common/usage/token_usage.js +0 -117
  52. package/dist/common/utils.js +0 -125
  53. package/dist/core/agent/layered_agent/ability_helper.js +0 -125
  54. package/dist/core/agent/layered_agent/agent.js +0 -37
  55. package/dist/core/agent/layered_agent/agent_registry.js +0 -82
  56. package/dist/core/agent/layered_agent/decision.js +0 -518
  57. package/dist/core/agent/layered_agent/execute_agent/action_handler.js +0 -155
  58. package/dist/core/agent/layered_agent/execute_agent/agent_factory.js +0 -41
  59. package/dist/core/agent/layered_agent/execute_agent/base_agent.js +0 -112
  60. package/dist/core/agent/layered_agent/execute_agent/general_agent.js +0 -207
  61. package/dist/core/agent/layered_agent/execute_agent/glm_agent.js +0 -241
  62. package/dist/core/agent/layered_agent/execute_agent/i18n.js +0 -34
  63. package/dist/core/agent/layered_agent/execute_agent/index.js +0 -67
  64. package/dist/core/agent/layered_agent/execute_agent/mai_ui_agent.js +0 -316
  65. package/dist/core/agent/layered_agent/execute_agent/mcp_prompts.js +0 -154
  66. package/dist/core/agent/layered_agent/execute_agent/parser/general_parser.js +0 -243
  67. package/dist/core/agent/layered_agent/execute_agent/parser/glm_parser.js +0 -139
  68. package/dist/core/agent/layered_agent/execute_agent/parser/index.js +0 -9
  69. package/dist/core/agent/layered_agent/execute_agent/parser/mai_ui_parser.js +0 -94
  70. package/dist/core/agent/layered_agent/execute_agent/prompts.js +0 -109
  71. package/dist/core/agent/layered_agent/execute_agent/simple_reporter.js +0 -33
  72. package/dist/core/agent/layered_agent/execute_agent/utils.js +0 -52
  73. package/dist/core/agent/report_analyzer_agent/agent.js +0 -565
  74. package/dist/core/agent/report_analyzer_agent/config.js +0 -22
  75. package/dist/core/agent/report_analyzer_agent/data_loader.js +0 -255
  76. package/dist/core/agent/report_analyzer_agent/guardrails.js +0 -99
  77. package/dist/core/agent/report_analyzer_agent/hooks.js +0 -31
  78. package/dist/core/agent/report_analyzer_agent/index.js +0 -52
  79. package/dist/core/agent/report_analyzer_agent/key_steps_builder.js +0 -42
  80. package/dist/core/agent/report_analyzer_agent/mapping.js +0 -133
  81. package/dist/core/agent/report_analyzer_agent/parse.js +0 -375
  82. package/dist/core/agent/report_analyzer_agent/prompt.js +0 -300
  83. package/dist/core/agent/report_analyzer_agent/report_writer.js +0 -558
  84. package/dist/core/agent/report_analyzer_agent/tools.js +0 -150
  85. package/dist/core/agent/report_analyzer_agent/types.js +0 -274
  86. package/dist/core/agent/rewrite_agent/agent.js +0 -209
  87. package/dist/core/agent/rewrite_agent/guardrails.js +0 -95
  88. package/dist/core/agent/rewrite_agent/mapping.js +0 -56
  89. package/dist/core/agent/rewrite_agent/parse.js +0 -121
  90. package/dist/core/agent/rewrite_agent/types.js +0 -37
  91. package/dist/core/agent/single_agent/agent.js +0 -801
  92. package/dist/core/agent/single_agent/hook_manager.js +0 -59
  93. package/dist/core/agent/single_agent/hooks.js +0 -288
  94. package/dist/core/agent/single_agent/image_utils.js +0 -158
  95. package/dist/core/agent/single_agent/scroll_search_agent.js +0 -405
  96. package/dist/core/agent/single_agent/subagent_manager.js +0 -72
  97. package/dist/core/agent/single_agent/tool_recorder_hook.js +0 -42
  98. package/dist/core/agent/types.js +0 -2
  99. package/dist/core/agent/utils/message_builder.js +0 -138
  100. package/dist/core/device/device_protocol.js +0 -2
  101. package/dist/core/device/hdc/apps.js +0 -437
  102. package/dist/core/device/hdc/device.js +0 -219
  103. package/dist/core/device/hdc/index.js +0 -31
  104. package/dist/core/device/hdc/input.js +0 -74
  105. package/dist/core/device/hdc/screenshot.js +0 -171
  106. package/dist/core/device/index.js +0 -70
  107. package/dist/core/device/types.js +0 -2
  108. package/dist/core/knowledge/knowledge_manager.js +0 -70
  109. package/dist/core/knowledge/vectordb.js +0 -283
  110. package/dist/core/mcp/adapter_factory.js +0 -99
  111. package/dist/core/mcp/android_adapter.js +0 -286
  112. package/dist/core/mcp/base_adapter.js +0 -86
  113. package/dist/core/mcp/harmony_hdc_adapter.js +0 -798
  114. package/dist/core/mcp/ios_adapter.js +0 -286
  115. package/dist/core/mcp/local_tools.js +0 -41
  116. package/dist/core/mcp/mcp_tools.js +0 -473
  117. package/dist/core/mcp/types.js +0 -6
  118. package/dist/core/memory/_utils.js +0 -140
  119. package/dist/core/memory/compressed_session.js +0 -182
  120. package/dist/core/memory/context_compressor.js +0 -176
  121. package/dist/core/memory/index.js +0 -22
  122. package/dist/core/memory/memory_manager.js +0 -28
  123. package/dist/core/memory/reflector.js +0 -95
  124. package/dist/core/memory/replan_manager.js +0 -12
  125. package/dist/core/memory/session_factory.js +0 -29
  126. package/dist/core/memory/tool_player.js +0 -225
  127. package/dist/core/memory/tool_player_popup.js +0 -276
  128. package/dist/core/memory/tool_player_replan.js +0 -226
  129. package/dist/core/memory/tool_player_xpath.js +0 -139
  130. package/dist/core/memory/tool_recorder.js +0 -126
  131. package/dist/core/preprocessor/task_splitter.js +0 -112
  132. package/dist/core/prompt/prompt_loader.js +0 -315
  133. package/dist/core/skill/skill_manager.js +0 -302
  134. package/dist/data_types/action.js +0 -2
  135. package/dist/data_types/agent.js +0 -2
  136. package/dist/data_types/case.js +0 -57
  137. package/dist/data_types/device.js +0 -2
  138. package/dist/data_types/index.js +0 -11
  139. package/dist/data_types/report.js +0 -6
  140. package/dist/data_types/screen.js +0 -23
  141. package/dist/data_types/task.js +0 -2
  142. package/dist/loop/cli.js +0 -127
  143. package/dist/loop/orchestrator.js +0 -314
  144. package/dist/loop/result_writer.js +0 -260
  145. package/dist/loop/types.js +0 -82
  146. package/dist/mcp-server/server.js +0 -341
  147. package/dist/mcp-server/types.js +0 -224
  148. package/dist/reporter/batch_summary.js +0 -197
  149. package/dist/reporter/generator.js +0 -286
  150. package/dist/reporter/html_template/index.js +0 -529
  151. package/dist/reporter/json_report.js +0 -6
  152. package/dist/reporter/types.js +0 -45
  153. package/dist/tools/case_runner/report.js +0 -264
@@ -1,31 +0,0 @@
1
- "use strict";
2
- /**
3
- * HDC utilities for HarmonyOS device interaction.
4
- */
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.resetDevice = exports.launchApp = exports.home = exports.back = exports.swipe = exports.longPress = exports.doubleTap = exports.tap = exports.getCurrentApp = exports.getAppDisplayName = exports.listSupportedApps = exports.getAppName = exports.getPackageName = exports.BUNDLE_NAME_TO_APP_NAME = exports.TOP_225_APP = exports.APP_ABILITIES = exports.APP_PACKAGES = exports.clearText = exports.typeText = exports.inputText = exports.getScreenshot = void 0;
7
- var screenshot_1 = require("./screenshot");
8
- Object.defineProperty(exports, "getScreenshot", { enumerable: true, get: function () { return screenshot_1.getScreenshot; } });
9
- var input_1 = require("./input");
10
- Object.defineProperty(exports, "inputText", { enumerable: true, get: function () { return input_1.inputText; } });
11
- Object.defineProperty(exports, "typeText", { enumerable: true, get: function () { return input_1.typeText; } });
12
- Object.defineProperty(exports, "clearText", { enumerable: true, get: function () { return input_1.clearText; } });
13
- var apps_1 = require("./apps");
14
- Object.defineProperty(exports, "APP_PACKAGES", { enumerable: true, get: function () { return apps_1.APP_PACKAGES; } });
15
- Object.defineProperty(exports, "APP_ABILITIES", { enumerable: true, get: function () { return apps_1.APP_ABILITIES; } });
16
- Object.defineProperty(exports, "TOP_225_APP", { enumerable: true, get: function () { return apps_1.TOP_225_APP; } });
17
- Object.defineProperty(exports, "BUNDLE_NAME_TO_APP_NAME", { enumerable: true, get: function () { return apps_1.BUNDLE_NAME_TO_APP_NAME; } });
18
- Object.defineProperty(exports, "getPackageName", { enumerable: true, get: function () { return apps_1.getPackageName; } });
19
- Object.defineProperty(exports, "getAppName", { enumerable: true, get: function () { return apps_1.getAppName; } });
20
- Object.defineProperty(exports, "listSupportedApps", { enumerable: true, get: function () { return apps_1.listSupportedApps; } });
21
- var device_1 = require("./device");
22
- Object.defineProperty(exports, "getAppDisplayName", { enumerable: true, get: function () { return device_1.getAppDisplayName; } });
23
- Object.defineProperty(exports, "getCurrentApp", { enumerable: true, get: function () { return device_1.getCurrentApp; } });
24
- Object.defineProperty(exports, "tap", { enumerable: true, get: function () { return device_1.tap; } });
25
- Object.defineProperty(exports, "doubleTap", { enumerable: true, get: function () { return device_1.doubleTap; } });
26
- Object.defineProperty(exports, "longPress", { enumerable: true, get: function () { return device_1.longPress; } });
27
- Object.defineProperty(exports, "swipe", { enumerable: true, get: function () { return device_1.swipe; } });
28
- Object.defineProperty(exports, "back", { enumerable: true, get: function () { return device_1.back; } });
29
- Object.defineProperty(exports, "home", { enumerable: true, get: function () { return device_1.home; } });
30
- Object.defineProperty(exports, "launchApp", { enumerable: true, get: function () { return device_1.launchApp; } });
31
- Object.defineProperty(exports, "resetDevice", { enumerable: true, get: function () { return device_1.resetDevice; } });
@@ -1,74 +0,0 @@
1
- "use strict";
2
- /**
3
- * Input utilities for HarmonyOS device text input.
4
- *
5
- * Uses `hdc shell uitest uiInput text` to inject text into the focused field.
6
- *
7
- * All methods are **async** to avoid blocking the Node.js event loop.
8
- */
9
- Object.defineProperty(exports, "__esModule", { value: true });
10
- exports.inputText = inputText;
11
- exports.typeText = typeText;
12
- exports.clearText = clearText;
13
- const logger_1 = require("../../../common/logger");
14
- /** HarmonyOS key code for ENTER. */
15
- const KEY_ENTER = 2054;
16
- /** HarmonyOS key code for DELETE. */
17
- const KEY_DELETE = 2055;
18
- /** Ctrl key code used together with A for select-all. */
19
- const KEY_CTRL = 2072;
20
- /** A key code used together with Ctrl for select-all. */
21
- const KEY_A = 2017;
22
- /** Escape a string for safe inclusion in a double-quoted shell argument. */
23
- function escapeForShell(text) {
24
- return text.replace(/"/g, '\\"').replace(/\$/g, '\\$');
25
- }
26
- /** Inject text into the currently focused input field. */
27
- async function inputText(driver, text) {
28
- try {
29
- await driver.shell(`uitest uiInput text "${escapeForShell(text)}"`);
30
- }
31
- catch (e) {
32
- logger_1.logger.error(`[HDC] Failed to input text: ${e instanceof Error ? e.message : String(e)}`);
33
- try {
34
- await driver.shell('uitest uiInput click 10 10');
35
- await driver.shell(`uitest uiInput text "${escapeForShell(text)}"`);
36
- }
37
- catch (e2) {
38
- logger_1.logger.error(`[HDC] input text fallback also failed: ${e2 instanceof Error ? e2.message : String(e2)}`);
39
- }
40
- }
41
- }
42
- /**
43
- * Type text into the currently focused input field.
44
- *
45
- * Supports multi-line text by splitting on newlines and sending ENTER key
46
- * events (key code 2054) between lines.
47
- */
48
- async function typeText(driver, text) {
49
- if (text.includes('\n')) {
50
- const lines = text.split('\n');
51
- for (let i = 0; i < lines.length; i++) {
52
- const line = lines[i];
53
- if (line) {
54
- await inputText(driver, line);
55
- }
56
- if (i < lines.length - 1) {
57
- try {
58
- await driver.shell(`uitest uiInput keyEvent ${KEY_ENTER}`);
59
- }
60
- catch (e) {
61
- logger_1.logger.error(`[HDC] ENTER keyEvent failed: ${e instanceof Error ? e.message : String(e)}`);
62
- }
63
- }
64
- }
65
- }
66
- else {
67
- await inputText(driver, text);
68
- }
69
- }
70
- /** Clear text in the currently focused input field (select-all then delete). */
71
- async function clearText(driver) {
72
- await driver.shell(`uitest uiInput combinationKeyEvent ${KEY_CTRL} ${KEY_A}`);
73
- await driver.shell(`uitest uiInput keyEvent ${KEY_DELETE}`);
74
- }
@@ -1,171 +0,0 @@
1
- "use strict";
2
- /**
3
- * Screenshot utilities for capturing the HarmonyOS device screen.
4
- *
5
- * Uses `hdc shell snapshot_display` to capture and `hdc file recv` to pull the
6
- * image. A fallback black image is returned when capture fails.
7
- *
8
- * All methods are **async** to avoid blocking the Node.js event loop.
9
- */
10
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
11
- if (k2 === undefined) k2 = k;
12
- var desc = Object.getOwnPropertyDescriptor(m, k);
13
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
14
- desc = { enumerable: true, get: function() { return m[k]; } };
15
- }
16
- Object.defineProperty(o, k2, desc);
17
- }) : (function(o, m, k, k2) {
18
- if (k2 === undefined) k2 = k;
19
- o[k2] = m[k];
20
- }));
21
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
22
- Object.defineProperty(o, "default", { enumerable: true, value: v });
23
- }) : function(o, v) {
24
- o["default"] = v;
25
- });
26
- var __importStar = (this && this.__importStar) || (function () {
27
- var ownKeys = function(o) {
28
- ownKeys = Object.getOwnPropertyNames || function (o) {
29
- var ar = [];
30
- for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
31
- return ar;
32
- };
33
- return ownKeys(o);
34
- };
35
- return function (mod) {
36
- if (mod && mod.__esModule) return mod;
37
- var result = {};
38
- if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
39
- __setModuleDefault(result, mod);
40
- return result;
41
- };
42
- })();
43
- Object.defineProperty(exports, "__esModule", { value: true });
44
- exports.getScreenshot = getScreenshot;
45
- const fs = __importStar(require("fs"));
46
- const path = __importStar(require("path"));
47
- const os = __importStar(require("os"));
48
- const logger_1 = require("../../../common/logger");
49
- const DEFAULT_WIDTH = 1080;
50
- const DEFAULT_HEIGHT = 2400;
51
- /**
52
- * Minimal 16×16 black JPEG (base64). Returned on capture failure so the model
53
- * still receives a valid (black) image frame and the report has something to
54
- * render — matching the hdc screenshot fallback which returns a real
55
- * black image. Width/height reported as the screen defaults so downstream
56
- * screen-size learning is not polluted by the tiny image's real dimensions.
57
- */
58
- const BLACK_FALLBACK_JPEG_B64 = '/9j/2wBDAAoHBwgHBgoICAgLCgoLDhgQDg0NDh0VFhEYIx8lJCIfIiEmKzcvJik0KSEiMEExNDk7Pj4+JS5ESUM8SDc9Pjv/2wBDAQoLCw4NDhwQEBw7KCIoOzs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozv/wAARCAAQABADASIAAhEBAxEB/8QAFQABAQAAAAAAAAAAAAAAAAAAAAf/xAAUEAEAAAAAAAAAAAAAAAAAAAAA/8QAFAEBAAAAAAAAAAAAAAAAAAAAAP/EABQRAQAAAAAAAAAAAAAAAAAAAAD/2gAMAwEAAhEDEQA/AIyAD//Z';
59
- /**
60
- * Capture a screenshot from the connected HarmonyOS device.
61
- *
62
- * @param driver The hdc driver instance.
63
- * @param withLayout Whether to also capture the UI layout.
64
- * @returns Screenshot object containing base64 data and dimensions.
65
- */
66
- async function getScreenshot(driver, withLayout = true) {
67
- const tmpDir = os.tmpdir();
68
- const stamp = `${Date.now()}_${Math.random().toString(36).slice(2, 8)}`;
69
- const remoteShot = `/data/local/tmp/screenshot_${stamp}.jpeg`;
70
- const localShot = path.join(tmpDir, `screenshot_${stamp}.jpeg`);
71
- const remoteLayout = `/data/local/tmp/layout_${stamp}.json`;
72
- const localLayout = path.join(tmpDir, `layout_${stamp}.json`);
73
- try {
74
- await driver.shell(`snapshot_display -f ${remoteShot}`);
75
- const recvOk = await driver.fileRecv(remoteShot, localShot);
76
- if (!recvOk || !fs.existsSync(localShot)) {
77
- logger_1.logger.warn(`[screenshot] capture failed: snapshot_display or file recv failed`);
78
- return createFallbackScreenshot(false);
79
- }
80
- const imageBuffer = fs.readFileSync(localShot);
81
- const base64Data = imageBuffer.toString('base64');
82
- const { width, height } = readJpegSize(imageBuffer);
83
- let layoutData = '';
84
- if (withLayout) {
85
- try {
86
- await driver.shell(`uitest dumpLayout -p ${remoteLayout}`);
87
- const layoutRecvOk = await driver.fileRecv(remoteLayout, localLayout);
88
- if (layoutRecvOk && fs.existsSync(localLayout)) {
89
- layoutData = fs.readFileSync(localLayout, 'utf-8');
90
- }
91
- }
92
- catch (e) {
93
- logger_1.logger.error(`Layout error: ${e instanceof Error ? e.message : String(e)}`);
94
- layoutData = '';
95
- }
96
- }
97
- return {
98
- base64Data,
99
- layoutData,
100
- width,
101
- height,
102
- isSensitive: false,
103
- screenshotPath: null,
104
- };
105
- }
106
- catch (e) {
107
- logger_1.logger.error(`Screenshot error: ${e instanceof Error ? e.message : String(e)}`);
108
- return createFallbackScreenshot(false);
109
- }
110
- finally {
111
- cleanupFile(localShot);
112
- cleanupFile(localLayout);
113
- try {
114
- await driver.shell(`rm -f ${remoteShot} ${remoteLayout}`);
115
- }
116
- catch {
117
- // ignore remote cleanup failures
118
- }
119
- }
120
- }
121
- /** Create a black fallback image when screenshot capture fails. */
122
- function createFallbackScreenshot(isSensitive) {
123
- return {
124
- base64Data: BLACK_FALLBACK_JPEG_B64,
125
- layoutData: '',
126
- width: DEFAULT_WIDTH,
127
- height: DEFAULT_HEIGHT,
128
- isSensitive,
129
- screenshotPath: null,
130
- };
131
- }
132
- /** Parse the width and height from a JPEG buffer, with a default fallback. */
133
- function readJpegSize(buf) {
134
- try {
135
- if (buf.length < 4 || buf[0] !== 0xff || buf[1] !== 0xd8) {
136
- return { width: DEFAULT_WIDTH, height: DEFAULT_HEIGHT };
137
- }
138
- let i = 2;
139
- while (i < buf.length) {
140
- if (buf[i] !== 0xff) {
141
- i += 1;
142
- continue;
143
- }
144
- const marker = buf[i + 1];
145
- // SOF0..SOF15 (except SOF4/DHT/JPG variants) carry frame dimensions.
146
- if (marker >= 0xc0 && marker <= 0xcf && marker !== 0xc4 && marker !== 0xc8 && marker !== 0xcc) {
147
- const height = buf.readUInt16BE(i + 5);
148
- const width = buf.readUInt16BE(i + 7);
149
- if (height > 0 && width > 0) {
150
- return { width, height };
151
- }
152
- }
153
- const segLen = buf.readUInt16BE(i + 2);
154
- i += 2 + segLen;
155
- }
156
- }
157
- catch {
158
- // fall through to defaults
159
- }
160
- return { width: DEFAULT_WIDTH, height: DEFAULT_HEIGHT };
161
- }
162
- function cleanupFile(filePath) {
163
- try {
164
- if (filePath && fs.existsSync(filePath)) {
165
- fs.unlinkSync(filePath);
166
- }
167
- }
168
- catch {
169
- // ignore cleanup failures
170
- }
171
- }
@@ -1,70 +0,0 @@
1
- "use strict";
2
- /**
3
- * Device layer entry point.
4
- *
5
- * Re-exports the device protocol types and provides a `createDevice` factory
6
- * with a pluggable registry. `MockDevice` is available for offline/test runs.
7
- */
8
- Object.defineProperty(exports, "__esModule", { value: true });
9
- exports.MockDevice = void 0;
10
- exports.createDevice = createDevice;
11
- const logger_1 = require("../../common/logger");
12
- /**
13
- * Minimal in-memory device for tests/offline runs. Implements DeviceProtocol
14
- * with no-op actions and canned responses; records calls for assertions.
15
- */
16
- class MockDevice {
17
- deviceId;
18
- calls = [];
19
- _currentApp = 'System Home';
20
- constructor(deviceId = 'MOCK_DEVICE') {
21
- this.deviceId = deviceId;
22
- }
23
- getScreenshot() {
24
- return {
25
- base64Data: '',
26
- layoutData: '',
27
- width: 1080,
28
- height: 2400,
29
- isSensitive: false,
30
- screenshotPath: null,
31
- };
32
- }
33
- tap(x, y) { this.calls.push({ tool: 'tap', args: { x, y } }); }
34
- doubleTap(x, y) { this.calls.push({ tool: 'doubleTap', args: { x, y } }); }
35
- longPress(x, y, durationMs = 800) { this.calls.push({ tool: 'longPress', args: { x, y, durationMs } }); }
36
- swipe(sx, sy, ex, ey) { this.calls.push({ tool: 'swipe', args: { sx, sy, ex, ey } }); }
37
- typeText(text) { this.calls.push({ tool: 'typeText', args: { text } }); }
38
- clearText() { this.calls.push({ tool: 'clearText', args: {} }); }
39
- back() { this.calls.push({ tool: 'back', args: {} }); }
40
- home() { this.calls.push({ tool: 'home', args: {} }); }
41
- launchApp(appName) { this.calls.push({ tool: 'launchApp', args: { appName } }); this._currentApp = appName; return true; }
42
- getCurrentApp() { return this._currentApp; }
43
- listTools() { return []; }
44
- callTool(toolName, toolArgs) {
45
- this.calls.push({ tool: toolName, args: toolArgs });
46
- return { output: `mock ${toolName} ok`, success: true, errorMsg: '' };
47
- }
48
- cleanUp() { }
49
- }
50
- exports.MockDevice = MockDevice;
51
- const DEVICE_REGISTRY = {
52
- MockDevice: (opts) => new MockDevice(opts.deviceSn || undefined),
53
- };
54
- /**
55
- * Create a device by implementation name.
56
- * 'MockDevice' returns an in-memory mock; real HDC devices are created via the
57
- * MCP adapter factory (`createAdapterFromDeviceInfo`), which is the Node
58
- * equivalent of HDCDevice.
59
- */
60
- function createDevice(opts = {}) {
61
- const impl = opts.deviceImpl ?? 'HDCDevice';
62
- const factory = DEVICE_REGISTRY[impl];
63
- if (factory)
64
- return factory(opts);
65
- // HDCDevice / HDCDeviceInner are served by the MCP adapter factory, not here.
66
- logger_1.logger.warn(`createDevice: '${impl}' is not a DeviceProtocol impl; ` +
67
- `real HDC devices should be created via createAdapterFromDeviceInfo. ` +
68
- `Falling back to MockDevice.`);
69
- return new MockDevice(opts.deviceSn || undefined);
70
- }
@@ -1,2 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
@@ -1,70 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.KnowledgeManager = void 0;
4
- const logger_1 = require("../../common/logger");
5
- const vectordb_1 = require("./vectordb");
6
- class KnowledgeManagerImpl {
7
- ldManager = null;
8
- initialized = false;
9
- init() {
10
- if (this.initialized)
11
- return;
12
- this.ldManager = vectordb_1.LanceDBManager.getInstance();
13
- this.initialized = true;
14
- }
15
- addKnowledge(task) {
16
- this.init();
17
- const ragContent = this.ldManager.search(task);
18
- const taskWithReferenceInfo = ragContent
19
- ? `${task}\nReference info: ${ragContent}`
20
- : task;
21
- return taskWithReferenceInfo;
22
- }
23
- async enrichTask(task) {
24
- this.init();
25
- const ragContent = this.ldManager.search(task);
26
- if (!ragContent)
27
- return task;
28
- logger_1.logger.debug(`KnowledgeManager.enrichTask: enriched task with ${ragContent.length} chars of reference info`);
29
- return `${task}\nReference info: ${ragContent}`;
30
- }
31
- async search(query, topK = 5) {
32
- this.init();
33
- const results = this.ldManager.searchRaw(query, topK);
34
- if (results.length === 0)
35
- return [];
36
- return results.map((doc) => doc.text);
37
- }
38
- async addDocument(doc, metadata) {
39
- this.init();
40
- const knowledgeDoc = {
41
- id: `doc:${Date.now()}`,
42
- text: doc,
43
- metadata,
44
- };
45
- this.ldManager.addDocument(knowledgeDoc);
46
- logger_1.logger.debug(`KnowledgeManager.addDocument: added doc length=${doc.length}`);
47
- }
48
- /**
49
- * Incremental single-doc write.
50
- * Delegates to LanceDBManager.addSingle (non-destructive + jsonl fallback).
51
- */
52
- writeKnowledge(doc) {
53
- this.init();
54
- this.ldManager.addSingle({
55
- id: `doc:${Date.now()}`,
56
- text: doc.text,
57
- metadata: {
58
- ...(doc.category ? { category: doc.category } : {}),
59
- ...(doc.source ? { source: doc.source } : {}),
60
- },
61
- });
62
- logger_1.logger.debug(`KnowledgeManager.writeKnowledge: added doc length=${doc.text.length}`);
63
- }
64
- async deleteCollection() {
65
- this.init();
66
- this.ldManager.deleteCollection();
67
- logger_1.logger.debug('KnowledgeManager.deleteCollection: cleared');
68
- }
69
- }
70
- exports.KnowledgeManager = new KnowledgeManagerImpl();