android-midscene-automation 1.1.10 → 2.0.0

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 (739) hide show
  1. package/README.md +11 -1773
  2. package/bin/android-midscene-automation.js +2 -104
  3. package/package.json +6 -76
  4. package/AI/350/257/206/345/210/253/346/223/215/344/275/234/350/257/264/346/230/216.md +0 -442
  5. package/CHANGELOG.md +0 -284
  6. package/FAQ.md +0 -105
  7. package/USAGE.md +0 -1085
  8. package/artemis-main/.dockerignore +0 -15
  9. package/artemis-main/.env.example +0 -34
  10. package/artemis-main/CONTRIBUTING.md +0 -35
  11. package/artemis-main/Dockerfile +0 -68
  12. package/artemis-main/LICENSE +0 -202
  13. package/artemis-main/Makefile +0 -115
  14. package/artemis-main/README.md +0 -322
  15. package/artemis-main/README_CN.md +0 -320
  16. package/artemis-main/apps/__init__.py +0 -15
  17. package/artemis-main/apps/admin_console/__init__.py +0 -19
  18. package/artemis-main/apps/admin_console/core/__init__.py +0 -13
  19. package/artemis-main/apps/admin_console/core/config.py +0 -43
  20. package/artemis-main/apps/admin_console/core/security.py +0 -178
  21. package/artemis-main/apps/admin_console/core/state.py +0 -243
  22. package/artemis-main/apps/admin_console/database/__init__.py +0 -13
  23. package/artemis-main/apps/admin_console/database/connection.py +0 -60
  24. package/artemis-main/apps/admin_console/database/repositories/__init__.py +0 -13
  25. package/artemis-main/apps/admin_console/database/repositories/session_repository.py +0 -564
  26. package/artemis-main/apps/admin_console/database/repositories/step_repository.py +0 -512
  27. package/artemis-main/apps/admin_console/database/repositories/trace_repository.py +0 -133
  28. package/artemis-main/apps/admin_console/index.html +0 -3787
  29. package/artemis-main/apps/admin_console/replay_manager.py +0 -2585
  30. package/artemis-main/apps/admin_console/routers/__init__.py +0 -13
  31. package/artemis-main/apps/admin_console/routers/media.py +0 -198
  32. package/artemis-main/apps/admin_console/routers/replay.py +0 -91
  33. package/artemis-main/apps/admin_console/routers/sessions.py +0 -239
  34. package/artemis-main/apps/admin_console/routers/steps.py +0 -109
  35. package/artemis-main/apps/admin_console/routers/stream.py +0 -56
  36. package/artemis-main/apps/admin_console/routers/system.py +0 -761
  37. package/artemis-main/apps/admin_console/routers/tasks.py +0 -517
  38. package/artemis-main/apps/admin_console/schemas/__init__.py +0 -13
  39. package/artemis-main/apps/admin_console/schemas/task_schema.py +0 -47
  40. package/artemis-main/apps/admin_console/server.py +0 -541
  41. package/artemis-main/apps/admin_console/services/__init__.py +0 -13
  42. package/artemis-main/apps/admin_console/services/device_stream_service.py +0 -137
  43. package/artemis-main/apps/admin_console/services/ipc_service.py +0 -262
  44. package/artemis-main/apps/admin_console/services/media_service.py +0 -623
  45. package/artemis-main/apps/admin_console/services/model_service.py +0 -148
  46. package/artemis-main/apps/admin_console/services/task_preset_catalog.py +0 -514
  47. package/artemis-main/apps/admin_console/services/task_queue_service.py +0 -1719
  48. package/artemis-main/apps/admin_console/services/worker_process_io.py +0 -144
  49. package/artemis-main/apps/showcase_ui/README.md +0 -31
  50. package/artemis-main/apps/showcase_ui/angular.json +0 -132
  51. package/artemis-main/apps/showcase_ui/package-lock.json +0 -9472
  52. package/artemis-main/apps/showcase_ui/package.json +0 -39
  53. package/artemis-main/apps/showcase_ui/proxy.conf.json +0 -23
  54. package/artemis-main/apps/showcase_ui/public/favicon.ico +0 -0
  55. package/artemis-main/apps/showcase_ui/public/logo.png +0 -0
  56. package/artemis-main/apps/showcase_ui/public/logo.svg +0 -56
  57. package/artemis-main/apps/showcase_ui/src/app/app.component.html +0 -24
  58. package/artemis-main/apps/showcase_ui/src/app/app.component.scss +0 -49
  59. package/artemis-main/apps/showcase_ui/src/app/app.component.spec.ts +0 -42
  60. package/artemis-main/apps/showcase_ui/src/app/app.component.ts +0 -32
  61. package/artemis-main/apps/showcase_ui/src/app/app.config.ts +0 -29
  62. package/artemis-main/apps/showcase_ui/src/app/app.routes.ts +0 -27
  63. package/artemis-main/apps/showcase_ui/src/app/components/agent-stream/agent-stream-startup.spec.ts +0 -108
  64. package/artemis-main/apps/showcase_ui/src/app/components/agent-stream/agent-stream.component.html +0 -1436
  65. package/artemis-main/apps/showcase_ui/src/app/components/agent-stream/agent-stream.component.scss +0 -3973
  66. package/artemis-main/apps/showcase_ui/src/app/components/agent-stream/agent-stream.component.ts +0 -2235
  67. package/artemis-main/apps/showcase_ui/src/app/components/chat-interface/chat-interface.component.html +0 -380
  68. package/artemis-main/apps/showcase_ui/src/app/components/chat-interface/chat-interface.component.scss +0 -1171
  69. package/artemis-main/apps/showcase_ui/src/app/components/chat-interface/chat-interface.component.ts +0 -270
  70. package/artemis-main/apps/showcase_ui/src/app/components/floating-video-player/floating-video-player.component.html +0 -433
  71. package/artemis-main/apps/showcase_ui/src/app/components/floating-video-player/floating-video-player.component.scss +0 -987
  72. package/artemis-main/apps/showcase_ui/src/app/components/floating-video-player/floating-video-player.component.ts +0 -632
  73. package/artemis-main/apps/showcase_ui/src/app/components/legacy-agent-stream/legacy-agent-stream.component.html +0 -130
  74. package/artemis-main/apps/showcase_ui/src/app/components/legacy-agent-stream/legacy-agent-stream.component.scss +0 -406
  75. package/artemis-main/apps/showcase_ui/src/app/components/legacy-agent-stream/legacy-agent-stream.component.ts +0 -74
  76. package/artemis-main/apps/showcase_ui/src/app/components/nav-switcher/nav-switcher.component.scss +0 -115
  77. package/artemis-main/apps/showcase_ui/src/app/components/nav-switcher/nav-switcher.component.ts +0 -52
  78. package/artemis-main/apps/showcase_ui/src/app/core/data/smart-tasks.data.ts +0 -334
  79. package/artemis-main/apps/showcase_ui/src/app/core/i18n/language.service.spec.ts +0 -55
  80. package/artemis-main/apps/showcase_ui/src/app/core/i18n/language.service.ts +0 -61
  81. package/artemis-main/apps/showcase_ui/src/app/core/i18n/translate.pipe.ts +0 -11
  82. package/artemis-main/apps/showcase_ui/src/app/core/i18n/zh-cn.ts +0 -651
  83. package/artemis-main/apps/showcase_ui/src/app/core/models/markdown.model.ts +0 -43
  84. package/artemis-main/apps/showcase_ui/src/app/core/models/pro-tuning.model.spec.ts +0 -47
  85. package/artemis-main/apps/showcase_ui/src/app/core/models/pro-tuning.model.ts +0 -165
  86. package/artemis-main/apps/showcase_ui/src/app/core/models/session.model.ts +0 -85
  87. package/artemis-main/apps/showcase_ui/src/app/core/models/stream.model.ts +0 -246
  88. package/artemis-main/apps/showcase_ui/src/app/core/models/system.model.ts +0 -118
  89. package/artemis-main/apps/showcase_ui/src/app/core/services/task-recommendation.service.ts +0 -111
  90. package/artemis-main/apps/showcase_ui/src/app/pages/home/home.component.html +0 -2130
  91. package/artemis-main/apps/showcase_ui/src/app/pages/home/home.component.scss +0 -5204
  92. package/artemis-main/apps/showcase_ui/src/app/pages/home/home.component.ts +0 -1189
  93. package/artemis-main/apps/showcase_ui/src/app/pages/legacy-workspace/legacy-workspace.component.html +0 -39
  94. package/artemis-main/apps/showcase_ui/src/app/pages/legacy-workspace/legacy-workspace.component.scss +0 -151
  95. package/artemis-main/apps/showcase_ui/src/app/pages/legacy-workspace/legacy-workspace.component.ts +0 -58
  96. package/artemis-main/apps/showcase_ui/src/app/pages/workspace/workspace.component.html +0 -201
  97. package/artemis-main/apps/showcase_ui/src/app/pages/workspace/workspace.component.scss +0 -886
  98. package/artemis-main/apps/showcase_ui/src/app/pages/workspace/workspace.component.ts +0 -324
  99. package/artemis-main/apps/showcase_ui/src/app/services/agent.service.spec.ts +0 -418
  100. package/artemis-main/apps/showcase_ui/src/app/services/agent.service.ts +0 -2012
  101. package/artemis-main/apps/showcase_ui/src/app/services/system.service.spec.ts +0 -173
  102. package/artemis-main/apps/showcase_ui/src/app/services/system.service.ts +0 -620
  103. package/artemis-main/apps/showcase_ui/src/app/utils/action-formatter.util.spec.ts +0 -513
  104. package/artemis-main/apps/showcase_ui/src/app/utils/action-formatter.util.ts +0 -1015
  105. package/artemis-main/apps/showcase_ui/src/app/utils/image-overlay.util.spec.ts +0 -85
  106. package/artemis-main/apps/showcase_ui/src/app/utils/image-overlay.util.ts +0 -662
  107. package/artemis-main/apps/showcase_ui/src/app/utils/markdown-parser.util.spec.ts +0 -70
  108. package/artemis-main/apps/showcase_ui/src/app/utils/markdown-parser.util.ts +0 -383
  109. package/artemis-main/apps/showcase_ui/src/app/utils/recording-timeline.util.spec.ts +0 -107
  110. package/artemis-main/apps/showcase_ui/src/app/utils/recording-timeline.util.ts +0 -123
  111. package/artemis-main/apps/showcase_ui/src/app/utils/run-info.util.spec.ts +0 -92
  112. package/artemis-main/apps/showcase_ui/src/app/utils/run-info.util.ts +0 -116
  113. package/artemis-main/apps/showcase_ui/src/app/utils/stream-aggregator.util.spec.ts +0 -640
  114. package/artemis-main/apps/showcase_ui/src/app/utils/stream-aggregator.util.ts +0 -1021
  115. package/artemis-main/apps/showcase_ui/src/app/utils/tool-formatter.util.spec.ts +0 -375
  116. package/artemis-main/apps/showcase_ui/src/app/utils/tool-formatter.util.ts +0 -1419
  117. package/artemis-main/apps/showcase_ui/src/index.html +0 -37
  118. package/artemis-main/apps/showcase_ui/src/main.ts +0 -22
  119. package/artemis-main/apps/showcase_ui/src/styles.scss +0 -60
  120. package/artemis-main/apps/showcase_ui/tsconfig.app.json +0 -23
  121. package/artemis-main/apps/showcase_ui/tsconfig.json +0 -27
  122. package/artemis-main/apps/showcase_ui/tsconfig.spec.json +0 -23
  123. package/artemis-main/artemis/__init__.py +0 -44
  124. package/artemis-main/artemis/__main__.py +0 -18
  125. package/artemis-main/artemis/_legacy_imports.py +0 -94
  126. package/artemis-main/artemis/_version.py +0 -30
  127. package/artemis-main/artemis/agents/__init__.py +0 -17
  128. package/artemis-main/artemis/agents/checker/checker.json +0 -9
  129. package/artemis-main/artemis/agents/checker/checker.py +0 -859
  130. package/artemis-main/artemis/agents/diagnoser/diagnoser.json +0 -23
  131. package/artemis-main/artemis/agents/diagnoser/diagnoser.py +0 -608
  132. package/artemis-main/artemis/agents/explorer/constants.py +0 -52
  133. package/artemis-main/artemis/agents/explorer/explorer.json +0 -57
  134. package/artemis-main/artemis/agents/explorer/explorer.py +0 -473
  135. package/artemis-main/artemis/agents/explorer/geometry.py +0 -73
  136. package/artemis-main/artemis/agents/explorer/native_runner.py +0 -878
  137. package/artemis-main/artemis/agents/explorer/perception_tools.py +0 -632
  138. package/artemis-main/artemis/agents/explorer/run_setup.py +0 -403
  139. package/artemis-main/artemis/agents/explorer/screen_index.py +0 -266
  140. package/artemis-main/artemis/agents/explorer/tiers.py +0 -110
  141. package/artemis-main/artemis/agents/explorer/tool_declarations.py +0 -394
  142. package/artemis-main/artemis/agents/explorer/universal_runner.py +0 -317
  143. package/artemis-main/artemis/agents/flash/context_compressor.py +0 -452
  144. package/artemis-main/artemis/agents/flash/flash_runner.md +0 -51
  145. package/artemis-main/artemis/agents/flash/flash_summarizer.md +0 -53
  146. package/artemis-main/artemis/agents/flash/flash_summarizer_single.md +0 -54
  147. package/artemis-main/artemis/agents/flash/runner.py +0 -1167
  148. package/artemis-main/artemis/agents/flash/summarizer.py +0 -511
  149. package/artemis-main/artemis/agents/history_analyzer/history_analyzer.md +0 -8
  150. package/artemis-main/artemis/agents/history_analyzer/history_analyzer.py +0 -182
  151. package/artemis-main/artemis/agents/image_processor/image_processor.md +0 -74
  152. package/artemis-main/artemis/agents/image_processor/image_processor.py +0 -322
  153. package/artemis-main/artemis/agents/log_analyzer/log_analyzer.md +0 -15
  154. package/artemis-main/artemis/agents/log_analyzer/log_analyzer.py +0 -403
  155. package/artemis-main/artemis/agents/log_analyzer/log_reader_sub_agent.md +0 -8
  156. package/artemis-main/artemis/agents/log_analyzer/output_analyzer.md +0 -11
  157. package/artemis-main/artemis/agents/log_analyzer/output_analyzer.py +0 -163
  158. package/artemis-main/artemis/agents/object_detector/object_detector.json +0 -9
  159. package/artemis-main/artemis/agents/object_detector/object_detector.py +0 -211
  160. package/artemis-main/artemis/agents/operator/operator.json +0 -3
  161. package/artemis-main/artemis/agents/operator/operator.py +0 -1394
  162. package/artemis-main/artemis/agents/operator/prompts.py +0 -1064
  163. package/artemis-main/artemis/agents/outputter/outputter.md +0 -36
  164. package/artemis-main/artemis/agents/outputter/outputter.py +0 -552
  165. package/artemis-main/artemis/agents/planner/planner.json +0 -32
  166. package/artemis-main/artemis/agents/planner/planner.py +0 -436
  167. package/artemis-main/artemis/agents/prompt_assembly.py +0 -79
  168. package/artemis-main/artemis/agents/summarizer/summarizer.py +0 -190
  169. package/artemis-main/artemis/agents/validator/action_execution.py +0 -98
  170. package/artemis-main/artemis/agents/validator/categories.py +0 -33
  171. package/artemis-main/artemis/agents/validator/execution_loop.py +0 -488
  172. package/artemis-main/artemis/agents/validator/incidents.py +0 -120
  173. package/artemis-main/artemis/agents/validator/pixel_safety_net.md +0 -15
  174. package/artemis-main/artemis/agents/validator/precondition_pixel.py +0 -320
  175. package/artemis-main/artemis/agents/validator/precondition_xml.py +0 -672
  176. package/artemis-main/artemis/agents/validator/tool_declarations.py +0 -332
  177. package/artemis-main/artemis/agents/validator/validator.py +0 -188
  178. package/artemis-main/artemis/agents/video_analyzer/__init__.py +0 -15
  179. package/artemis-main/artemis/agents/video_analyzer/audio_native.py +0 -543
  180. package/artemis-main/artemis/agents/video_analyzer/blackboard.py +0 -821
  181. package/artemis-main/artemis/agents/video_analyzer/chunk_agentic.py +0 -455
  182. package/artemis-main/artemis/agents/video_analyzer/chunk_conversation.py +0 -491
  183. package/artemis-main/artemis/agents/video_analyzer/chunk_native.py +0 -437
  184. package/artemis-main/artemis/agents/video_analyzer/conflict_resolution.py +0 -137
  185. package/artemis-main/artemis/agents/video_analyzer/gemini_files.py +0 -162
  186. package/artemis-main/artemis/agents/video_analyzer/native_coordinator.py +0 -541
  187. package/artemis-main/artemis/agents/video_analyzer/reliability.py +0 -128
  188. package/artemis-main/artemis/agents/video_analyzer/universal_engine.py +0 -487
  189. package/artemis-main/artemis/agents/video_analyzer/universal_tools.py +0 -323
  190. package/artemis-main/artemis/agents/video_analyzer/video_analyzer.md +0 -51
  191. package/artemis-main/artemis/agents/video_analyzer/video_analyzer.py +0 -875
  192. package/artemis-main/artemis/agents/video_analyzer/video_sub_agent.md +0 -15
  193. package/artemis-main/artemis/agents/video_analyzer/video_sub_agent_audio.md +0 -12
  194. package/artemis-main/artemis/clients/accessibility_client.py +0 -438
  195. package/artemis-main/artemis/clients/screen_client_factory.py +0 -403
  196. package/artemis-main/artemis/config/__init__.py +0 -309
  197. package/artemis-main/artemis/config/agent.py +0 -1098
  198. package/artemis-main/artemis/config/constants.py +0 -151
  199. package/artemis-main/artemis/config/core/__init__.py +0 -24
  200. package/artemis-main/artemis/config/core/engine.py +0 -118
  201. package/artemis-main/artemis/config/core/interpolator.py +0 -78
  202. package/artemis-main/artemis/config/llm.py +0 -267
  203. package/artemis-main/artemis/config/paths.py +0 -244
  204. package/artemis-main/artemis/config/runtime.py +0 -197
  205. package/artemis-main/artemis/config/settings.py +0 -315
  206. package/artemis-main/artemis/constants.py +0 -47
  207. package/artemis-main/artemis/context.py +0 -289
  208. package/artemis-main/artemis/controllers/__init__.py +0 -41
  209. package/artemis-main/artemis/controllers/controller_factory.py +0 -41
  210. package/artemis-main/artemis/controllers/device_controller.py +0 -29
  211. package/artemis-main/artemis/controllers/types.py +0 -37
  212. package/artemis-main/artemis/controllers/unified_controller.py +0 -649
  213. package/artemis-main/artemis/core/__init__.py +0 -21
  214. package/artemis-main/artemis/core/diagnostics/__init__.py +0 -90
  215. package/artemis-main/artemis/core/diagnostics/adb_keys.py +0 -270
  216. package/artemis-main/artemis/core/diagnostics/adb_server_connection.py +0 -330
  217. package/artemis-main/artemis/core/diagnostics/device_smoke.py +0 -364
  218. package/artemis-main/artemis/core/diagnostics/emulator_manager.py +0 -501
  219. package/artemis-main/artemis/core/diagnostics/engine.py +0 -438
  220. package/artemis-main/artemis/core/diagnostics/hierarchy_parity.py +0 -216
  221. package/artemis-main/artemis/core/diagnostics/probes/adb_probe.py +0 -887
  222. package/artemis-main/artemis/core/diagnostics/probes/base.py +0 -45
  223. package/artemis-main/artemis/core/diagnostics/probes/credentials_probe.py +0 -296
  224. package/artemis-main/artemis/core/diagnostics/probes/host_probe.py +0 -427
  225. package/artemis-main/artemis/core/diagnostics/probes/runtime_probe.py +0 -169
  226. package/artemis-main/artemis/core/diagnostics/probes/toolchain_probe.py +0 -139
  227. package/artemis-main/artemis/core/diagnostics/readiness.py +0 -83
  228. package/artemis-main/artemis/core/diagnostics/schema.py +0 -118
  229. package/artemis-main/artemis/core/tool_declaration.py +0 -43
  230. package/artemis-main/artemis/core/tool_failure.py +0 -56
  231. package/artemis-main/artemis/data_engine/context_vars.py +0 -24
  232. package/artemis-main/artemis/data_engine/engine.py +0 -1615
  233. package/artemis-main/artemis/data_engine/history_reader.py +0 -142
  234. package/artemis-main/artemis/data_engine/models.py +0 -131
  235. package/artemis-main/artemis/data_engine/storage.py +0 -1245
  236. package/artemis-main/artemis/data_engine/trace.py +0 -727
  237. package/artemis-main/artemis/drivers/__init__.py +0 -48
  238. package/artemis-main/artemis/drivers/android/adb_driver.py +0 -507
  239. package/artemis-main/artemis/drivers/android/hierarchy.py +0 -64
  240. package/artemis-main/artemis/drivers/android/input_ime.py +0 -120
  241. package/artemis-main/artemis/drivers/android/recorder.py +0 -57
  242. package/artemis-main/artemis/drivers/base.py +0 -290
  243. package/artemis-main/artemis/drivers/cloud/cloud_driver.py +0 -117
  244. package/artemis-main/artemis/drivers/factory.py +0 -80
  245. package/artemis-main/artemis/drivers/mock/mock_driver.py +0 -198
  246. package/artemis-main/artemis/drivers/types.py +0 -67
  247. package/artemis-main/artemis/graph/checkpoints.py +0 -1243
  248. package/artemis-main/artemis/graph/graph.py +0 -1055
  249. package/artemis-main/artemis/graph/perception.py +0 -234
  250. package/artemis-main/artemis/graph/state.py +0 -151
  251. package/artemis-main/artemis/graph/visibility.py +0 -238
  252. package/artemis-main/artemis/interfaces/cli/__init__.py +0 -19
  253. package/artemis-main/artemis/interfaces/cli/commands/__init__.py +0 -15
  254. package/artemis-main/artemis/interfaces/cli/commands/batch.py +0 -278
  255. package/artemis-main/artemis/interfaces/cli/commands/doctor.py +0 -468
  256. package/artemis-main/artemis/interfaces/cli/commands/helper.py +0 -226
  257. package/artemis-main/artemis/interfaces/cli/commands/init.py +0 -193
  258. package/artemis-main/artemis/interfaces/cli/commands/mcp.py +0 -862
  259. package/artemis-main/artemis/interfaces/cli/commands/run.py +0 -463
  260. package/artemis-main/artemis/interfaces/cli/commands/server.py +0 -151
  261. package/artemis-main/artemis/interfaces/cli/commands/server_lifecycle.py +0 -328
  262. package/artemis-main/artemis/interfaces/cli/commands/trace.py +0 -111
  263. package/artemis-main/artemis/interfaces/cli/commands/ui.py +0 -404
  264. package/artemis-main/artemis/interfaces/cli/main.py +0 -109
  265. package/artemis-main/artemis/interfaces/sdk/__init__.py +0 -31
  266. package/artemis-main/artemis/interfaces/sdk/client.py +0 -19
  267. package/artemis-main/artemis/interfaces/sdk/task.py +0 -72
  268. package/artemis-main/artemis/llm/__init__.py +0 -25
  269. package/artemis-main/artemis/llm/fake_model.py +0 -179
  270. package/artemis-main/artemis/llm/google/__init__.py +0 -57
  271. package/artemis-main/artemis/llm/google/provider.py +0 -185
  272. package/artemis-main/artemis/llm/google/usage.py +0 -148
  273. package/artemis-main/artemis/llm/parser.py +0 -32
  274. package/artemis-main/artemis/llm/reliability.py +0 -267
  275. package/artemis-main/artemis/llm/router.py +0 -389
  276. package/artemis-main/artemis/llm/schemas.py +0 -36
  277. package/artemis-main/artemis/llm/structured.py +0 -196
  278. package/artemis-main/artemis/main.py +0 -58
  279. package/artemis-main/artemis/mcp/__init__.py +0 -20
  280. package/artemis-main/artemis/mcp/action_executor.py +0 -760
  281. package/artemis-main/artemis/mcp/action_manifest.py +0 -320
  282. package/artemis-main/artemis/mcp/action_names.py +0 -172
  283. package/artemis-main/artemis/mcp/action_server.py +0 -202
  284. package/artemis-main/artemis/mcp/action_session.py +0 -245
  285. package/artemis-main/artemis/mcp/action_specs.py +0 -868
  286. package/artemis-main/artemis/mcp/action_types.py +0 -86
  287. package/artemis-main/artemis/mcp/actuators/__init__.py +0 -21
  288. package/artemis-main/artemis/mcp/actuators/adb.py +0 -414
  289. package/artemis-main/artemis/mcp/actuators/base.py +0 -113
  290. package/artemis-main/artemis/mcp/actuators/mock.py +0 -70
  291. package/artemis-main/artemis/mcp/adb_server.py +0 -490
  292. package/artemis-main/artemis/mcp/observation.py +0 -133
  293. package/artemis-main/artemis/mcp/xml_search_server.py +0 -297
  294. package/artemis-main/artemis/memory/__init__.py +0 -90
  295. package/artemis-main/artemis/memory/chunking.py +0 -1843
  296. package/artemis-main/artemis/memory/context_policy.py +0 -226
  297. package/artemis-main/artemis/memory/step_capsule.md +0 -73
  298. package/artemis-main/artemis/memory/step_memory.py +0 -281
  299. package/artemis-main/artemis/memory/transcript.py +0 -798
  300. package/artemis-main/artemis/platform/__init__.py +0 -61
  301. package/artemis-main/artemis/platform/base.py +0 -104
  302. package/artemis-main/artemis/platform/darwin.py +0 -184
  303. package/artemis-main/artemis/platform/linux.py +0 -207
  304. package/artemis-main/artemis/platform/windows.py +0 -193
  305. package/artemis-main/artemis/resources/__init__.py +0 -46
  306. package/artemis-main/artemis/runtime/__init__.py +0 -108
  307. package/artemis-main/artemis/runtime/adb_endpoint.py +0 -173
  308. package/artemis-main/artemis/runtime/awake_lease.py +0 -283
  309. package/artemis-main/artemis/runtime/awake_service.py +0 -343
  310. package/artemis-main/artemis/runtime/cancel_requests.py +0 -254
  311. package/artemis-main/artemis/runtime/daemon_client.py +0 -422
  312. package/artemis-main/artemis/runtime/device_lock.py +0 -1013
  313. package/artemis-main/artemis/runtime/device_pool.py +0 -478
  314. package/artemis-main/artemis/runtime/helper_manager.py +0 -1030
  315. package/artemis-main/artemis/runtime/process_probe.py +0 -98
  316. package/artemis-main/artemis/runtime/server_lifecycle.py +0 -435
  317. package/artemis-main/artemis/runtime/supervisor.py +0 -121
  318. package/artemis-main/artemis/runtime/trace_store.py +0 -375
  319. package/artemis-main/artemis/sdk/__init__.py +0 -26
  320. package/artemis-main/artemis/sdk/agent.py +0 -485
  321. package/artemis-main/artemis/sdk/builders/__init__.py +0 -29
  322. package/artemis-main/artemis/sdk/builders/agent_config_builder.py +0 -474
  323. package/artemis-main/artemis/sdk/constants.py +0 -15
  324. package/artemis-main/artemis/sdk/run_outcome.py +0 -58
  325. package/artemis-main/artemis/sdk/types/__init__.py +0 -61
  326. package/artemis-main/artemis/sdk/types/agent.py +0 -89
  327. package/artemis-main/artemis/sdk/utils.py +0 -28
  328. package/artemis-main/artemis/services/llm.py +0 -1040
  329. package/artemis-main/artemis/services/token_meter.py +0 -267
  330. package/artemis-main/artemis/telemetry/__init__.py +0 -35
  331. package/artemis-main/artemis/telemetry/models.py +0 -64
  332. package/artemis-main/artemis/telemetry/replay.py +0 -34
  333. package/artemis-main/artemis/telemetry/storage/json_storage.py +0 -47
  334. package/artemis-main/artemis/telemetry/tracer.py +0 -85
  335. package/artemis-main/artemis/toolchain/__init__.py +0 -52
  336. package/artemis-main/artemis/toolchain/descriptors.py +0 -92
  337. package/artemis-main/artemis/toolchain/resolver.py +0 -185
  338. package/artemis-main/artemis/tools/base.py +0 -232
  339. package/artemis-main/artemis/tools/command_tool.py +0 -1240
  340. package/artemis-main/artemis/tools/committee_prompts.json +0 -5
  341. package/artemis-main/artemis/tools/committee_tool.py +0 -422
  342. package/artemis-main/artemis/tools/diagnoser_submit_answer_tool.py +0 -87
  343. package/artemis-main/artemis/tools/diagnostic_tool.py +0 -120
  344. package/artemis-main/artemis/tools/explorer_tool.py +0 -581
  345. package/artemis-main/artemis/tools/history/__init__.py +0 -398
  346. package/artemis-main/artemis/tools/history/replay.py +0 -120
  347. package/artemis-main/artemis/tools/history/screenshot.py +0 -139
  348. package/artemis-main/artemis/tools/history/search.py +0 -563
  349. package/artemis-main/artemis/tools/image_processor_tool.py +0 -124
  350. package/artemis-main/artemis/tools/index.py +0 -47
  351. package/artemis-main/artemis/tools/log_tool.py +0 -108
  352. package/artemis-main/artemis/tools/mobile/launch_app.py +0 -132
  353. package/artemis-main/artemis/tools/mobile/log_utils.py +0 -138
  354. package/artemis-main/artemis/tools/mobile/ocr.py +0 -202
  355. package/artemis-main/artemis/tools/mobile/read_hierarchy.py +0 -108
  356. package/artemis-main/artemis/tools/mobile/read_logs.py +0 -116
  357. package/artemis-main/artemis/tools/mobile/search_logs.py +0 -260
  358. package/artemis-main/artemis/tools/object_detection_tool.py +0 -244
  359. package/artemis-main/artemis/tools/scratchpad.py +0 -819
  360. package/artemis-main/artemis/tools/system/adb_shell.py +0 -31
  361. package/artemis-main/artemis/tools/tool_wrapper.py +0 -270
  362. package/artemis-main/artemis/tools/video_tool.py +0 -261
  363. package/artemis-main/artemis/tools/wait_tool.py +0 -97
  364. package/artemis-main/artemis/utils/app_launch_utils.py +0 -207
  365. package/artemis-main/artemis/utils/coordinates.py +0 -606
  366. package/artemis-main/artemis/utils/credentials_validator.py +0 -201
  367. package/artemis-main/artemis/utils/cv_canvas.py +0 -189
  368. package/artemis-main/artemis/utils/cython_compat.py +0 -45
  369. package/artemis-main/artemis/utils/element_hit_test.py +0 -80
  370. package/artemis-main/artemis/utils/image_diff.py +0 -335
  371. package/artemis-main/artemis/utils/image_hash.py +0 -80
  372. package/artemis-main/artemis/utils/notes.py +0 -470
  373. package/artemis-main/artemis/utils/ocr_api.py +0 -105
  374. package/artemis-main/artemis/utils/ocr_xml_fusion.py +0 -318
  375. package/artemis-main/artemis/utils/plan_grammar.py +0 -513
  376. package/artemis-main/artemis/utils/python_executor.py +0 -213
  377. package/artemis-main/artemis/utils/startup_progress.py +0 -60
  378. package/artemis-main/artemis/utils/task_tree.py +0 -1174
  379. package/artemis-main/artemis/utils/text.py +0 -37
  380. package/artemis-main/artemis/utils/ui_filter.py +0 -651
  381. package/artemis-main/artemis/utils/video.py +0 -685
  382. package/artemis-main/artemis/utils/visualization.py +0 -802
  383. package/artemis-main/config/artemis.example.jsonc +0 -12
  384. package/artemis-main/mcp_server/README.md +0 -111
  385. package/artemis-main/mcp_server/__init__.py +0 -21
  386. package/artemis-main/mcp_server/__main__.py +0 -20
  387. package/artemis-main/mcp_server/background/__init__.py +0 -15
  388. package/artemis-main/mcp_server/background/task_runner.py +0 -453
  389. package/artemis-main/mcp_server/base.py +0 -49
  390. package/artemis-main/mcp_server/notifiers/__init__.py +0 -74
  391. package/artemis-main/mcp_server/notifiers/agentapi.py +0 -289
  392. package/artemis-main/mcp_server/notifiers/base.py +0 -45
  393. package/artemis-main/mcp_server/notifiers/composite.py +0 -87
  394. package/artemis-main/mcp_server/notifiers/desktop.py +0 -108
  395. package/artemis-main/mcp_server/notifiers/file.py +0 -69
  396. package/artemis-main/mcp_server/notifiers/script.py +0 -90
  397. package/artemis-main/mcp_server/notifiers/webhook.py +0 -87
  398. package/artemis-main/mcp_server/rules.md +0 -68
  399. package/artemis-main/mcp_server/server.py +0 -106
  400. package/artemis-main/mcp_server/tools/__init__.py +0 -29
  401. package/artemis-main/mcp_server/tools/device_state.py +0 -107
  402. package/artemis-main/mcp_server/tools/diagnose.py +0 -1249
  403. package/artemis-main/mcp_server/tools/inspect_trace.py +0 -394
  404. package/artemis-main/mcp_server/tools/task_manager.py +0 -627
  405. package/artemis-main/mcp_server/tools/task_runner.py +0 -548
  406. package/artemis-main/mcp_server/utils/__init__.py +0 -15
  407. package/artemis-main/mcp_server/utils/device_utils.py +0 -180
  408. package/artemis-main/mcp_server/utils/env_utils.py +0 -65
  409. package/artemis-main/packages/artemis-accessibility-helper/ArtemisAccessibilityHelper.apk +0 -0
  410. package/artemis-main/packages/artemis-accessibility-helper/app/build.gradle.kts +0 -35
  411. package/artemis-main/packages/artemis-accessibility-helper/app/src/main/AndroidManifest.xml +0 -49
  412. package/artemis-main/packages/artemis-accessibility-helper/app/src/main/java/com/artemis/helper/A11yNode.java +0 -274
  413. package/artemis-main/packages/artemis-accessibility-helper/app/src/main/java/com/artemis/helper/ArtemisAccessibilityService.java +0 -227
  414. package/artemis-main/packages/artemis-accessibility-helper/app/src/main/java/com/artemis/helper/CommandServer.java +0 -463
  415. package/artemis-main/packages/artemis-accessibility-helper/app/src/main/java/com/artemis/helper/DisplayUtils.java +0 -111
  416. package/artemis-main/packages/artemis-accessibility-helper/app/src/main/java/com/artemis/helper/GestureController.java +0 -232
  417. package/artemis-main/packages/artemis-accessibility-helper/app/src/main/java/com/artemis/helper/HierarchyDumper.java +0 -832
  418. package/artemis-main/packages/artemis-accessibility-helper/app/src/main/java/com/artemis/helper/TokenReceiver.java +0 -36
  419. package/artemis-main/packages/artemis-accessibility-helper/app/src/main/java/com/artemis/helper/TokenStore.java +0 -38
  420. package/artemis-main/packages/artemis-accessibility-helper/app/src/main/java/com/artemis/helper/XmlUtils.java +0 -102
  421. package/artemis-main/packages/artemis-accessibility-helper/app/src/main/res/values/strings.xml +0 -4
  422. package/artemis-main/packages/artemis-accessibility-helper/app/src/main/res/xml/accessibility_service_config.xml +0 -10
  423. package/artemis-main/packages/artemis-accessibility-helper/build.gradle.kts +0 -3
  424. package/artemis-main/packages/artemis-accessibility-helper/build_apk.sh +0 -215
  425. package/artemis-main/packages/artemis-accessibility-helper/debug.keystore +0 -0
  426. package/artemis-main/packages/artemis-accessibility-helper/gradle.properties +0 -2
  427. package/artemis-main/packages/artemis-accessibility-helper/helper_manifest.json +0 -7
  428. package/artemis-main/packages/artemis-accessibility-helper/settings.gradle.kts +0 -17
  429. package/artemis-main/packages/artemis-client/DESIGN.md +0 -89
  430. package/artemis-main/packages/artemis-client/README.md +0 -112
  431. package/artemis-main/packages/artemis-client/examples/basic.py +0 -30
  432. package/artemis-main/packages/artemis-client/pyproject.toml +0 -36
  433. package/artemis-main/packages/artemis-client/src/artemis_client/__init__.py +0 -45
  434. package/artemis-main/packages/artemis-client/src/artemis_client/client.py +0 -401
  435. package/artemis-main/packages/artemis-client/src/artemis_client/errors.py +0 -66
  436. package/artemis-main/packages/artemis-client/src/artemis_client/models.py +0 -212
  437. package/artemis-main/packages/artemis-client/src/artemis_client/py.typed +0 -1
  438. package/artemis-main/packages/artemis-client/src/artemis_client/transport.py +0 -134
  439. package/artemis-main/packages/artemis-client/tests/test_client.py +0 -289
  440. package/artemis-main/packages/artemis-client/tests/test_transport.py +0 -85
  441. package/artemis-main/pyproject.toml +0 -259
  442. package/artemis-main/pyright-core.json +0 -17
  443. package/artemis-main/scripts/check_dependency_sources.py +0 -68
  444. package/artemis-main/scripts/install_deps.ps1 +0 -520
  445. package/artemis-main/scripts/install_deps.sh +0 -533
  446. package/artemis-main/scripts/quality_ratchet.py +0 -97
  447. package/artemis-main/scripts/real_device_video_acceptance.py +0 -483
  448. package/artemis-main/scripts/run_edge_case_part.py +0 -327
  449. package/artemis-main/scripts/run_ui.py +0 -242
  450. package/artemis-main/scripts/start.ps1 +0 -500
  451. package/artemis-main/scripts/test_all_edge_cases.py +0 -269
  452. package/artemis-main/scripts/verify_concurrency_and_devices.py +0 -385
  453. package/artemis-main/setup.py +0 -164
  454. package/artemis-main/start.bat +0 -35
  455. package/artemis-main/start.sh +0 -423
  456. package/artemis-main/third_party/mobile_use/LICENSE +0 -190
  457. package/artemis-main/third_party/mobile_use/METADATA +0 -27
  458. package/artemis-main/third_party/mobile_use/NOTICE +0 -12
  459. package/artemis-main/third_party/mobile_use/__init__.py +0 -19
  460. package/artemis-main/third_party/mobile_use/agents/__init__.py +0 -13
  461. package/artemis-main/third_party/mobile_use/agents/hopper/__init__.py +0 -13
  462. package/artemis-main/third_party/mobile_use/agents/hopper/hopper.md +0 -22
  463. package/artemis-main/third_party/mobile_use/agents/hopper/hopper.py +0 -80
  464. package/artemis-main/third_party/mobile_use/clients/__init__.py +0 -13
  465. package/artemis-main/third_party/mobile_use/clients/ui_automator_client.py +0 -482
  466. package/artemis-main/third_party/mobile_use/config/__init__.py +0 -13
  467. package/artemis-main/third_party/mobile_use/config/llm.py +0 -183
  468. package/artemis-main/third_party/mobile_use/config/output.py +0 -184
  469. package/artemis-main/third_party/mobile_use/context.py +0 -119
  470. package/artemis-main/third_party/mobile_use/controllers/__init__.py +0 -13
  471. package/artemis-main/third_party/mobile_use/controllers/platform_specific_commands_controller.py +0 -151
  472. package/artemis-main/third_party/mobile_use/controllers/types.py +0 -92
  473. package/artemis-main/third_party/mobile_use/controllers/unified_controller.py +0 -183
  474. package/artemis-main/third_party/mobile_use/graph.py +0 -54
  475. package/artemis-main/third_party/mobile_use/llm_service.py +0 -193
  476. package/artemis-main/third_party/mobile_use/main.py +0 -130
  477. package/artemis-main/third_party/mobile_use/sdk/__init__.py +0 -13
  478. package/artemis-main/third_party/mobile_use/sdk/agent.py +0 -1060
  479. package/artemis-main/third_party/mobile_use/sdk/builders/__init__.py +0 -13
  480. package/artemis-main/third_party/mobile_use/sdk/builders/agent_config_builder.py +0 -225
  481. package/artemis-main/third_party/mobile_use/sdk/builders/index.py +0 -33
  482. package/artemis-main/third_party/mobile_use/sdk/builders/task_request_builder.py +0 -243
  483. package/artemis-main/third_party/mobile_use/sdk/types/__init__.py +0 -13
  484. package/artemis-main/third_party/mobile_use/sdk/types/agent.py +0 -98
  485. package/artemis-main/third_party/mobile_use/sdk/types/exceptions.py +0 -109
  486. package/artemis-main/third_party/mobile_use/sdk/types/task.py +0 -234
  487. package/artemis-main/third_party/mobile_use/testing.py +0 -59
  488. package/artemis-main/third_party/mobile_use/tools/__init__.py +0 -13
  489. package/artemis-main/third_party/mobile_use/tools/index.py +0 -44
  490. package/artemis-main/third_party/mobile_use/tools/mobile/__init__.py +0 -13
  491. package/artemis-main/third_party/mobile_use/tools/mobile/launch_app.py +0 -89
  492. package/artemis-main/third_party/mobile_use/tools/tool_wrapper.py +0 -52
  493. package/artemis-main/third_party/mobile_use/utils/__init__.py +0 -13
  494. package/artemis-main/third_party/mobile_use/utils/app_launch_utils.py +0 -217
  495. package/artemis-main/third_party/mobile_use/utils/cli_helpers.py +0 -60
  496. package/artemis-main/third_party/mobile_use/utils/decorators.py +0 -158
  497. package/artemis-main/third_party/mobile_use/utils/file.py +0 -31
  498. package/artemis-main/third_party/mobile_use/utils/logger.py +0 -216
  499. package/artemis-main/third_party/mobile_use/utils/media.py +0 -213
  500. package/artemis-main/third_party/mobile_use/utils/shell_utils.py +0 -39
  501. package/artemis-main/third_party/mobile_use/utils/video.py +0 -398
  502. package/artemis-main/uv.lock +0 -4908
  503. package/bin/artemis-config.mjs +0 -15
  504. package/bin/artemis-embedded.py +0 -56
  505. package/bin/start-artemis.mjs +0 -30
  506. package/bin/start-dev.mjs +0 -112
  507. package/bin/sync-readme-docs.mjs +0 -49
  508. package/bin/test_artemis_embedded.py +0 -44
  509. package/index.html +0 -12
  510. package/remote-agent/index.ts +0 -232
  511. package/server/analytics.test.ts +0 -46
  512. package/server/analytics.ts +0 -24
  513. package/server/android-device-info.ts +0 -28
  514. package/server/android-sdk.ts +0 -104
  515. package/server/api-safety-analytics.test.ts +0 -57
  516. package/server/appium-auto-save.test.ts +0 -79
  517. package/server/appium-config.test.ts +0 -182
  518. package/server/appium-recorder/ai-deduplication.test.ts +0 -80
  519. package/server/appium-recorder/ai-deduplication.ts +0 -74
  520. package/server/appium-recorder/ai-observation.test.ts +0 -125
  521. package/server/appium-recorder/ai-observation.ts +0 -125
  522. package/server/appium-recorder/ai-recognition.test.ts +0 -27
  523. package/server/appium-recorder/ai-recognition.ts +0 -186
  524. package/server/appium-recorder/appium-runner.ts +0 -1985
  525. package/server/appium-recorder/appium-version.test.ts +0 -55
  526. package/server/appium-recorder/bounded-loop.test.ts +0 -55
  527. package/server/appium-recorder/bounded-loop.ts +0 -129
  528. package/server/appium-recorder/condition-timeout.ts +0 -4
  529. package/server/appium-recorder/element-tap.test.ts +0 -312
  530. package/server/appium-recorder/flow-layout.test.ts +0 -52
  531. package/server/appium-recorder/history-capture.ts +0 -35
  532. package/server/appium-recorder/image-check.ts +0 -174
  533. package/server/appium-recorder/managed-appium.ts +0 -198
  534. package/server/appium-recorder/managed-cleanup.test.ts +0 -113
  535. package/server/appium-recorder/open-gallery.ts +0 -61
  536. package/server/appium-recorder/prompt-optimizer.ts +0 -57
  537. package/server/appium-recorder/random-value-replay.test.ts +0 -76
  538. package/server/appium-recorder/random-value.test.ts +0 -114
  539. package/server/appium-recorder/random-value.ts +0 -34
  540. package/server/appium-recorder/replay-lifecycle.test.ts +0 -123
  541. package/server/appium-recorder/replay-log.ts +0 -13
  542. package/server/appium-recorder/replay-mp4.ts +0 -72
  543. package/server/appium-recorder/replay-video-segments.ts +0 -77
  544. package/server/appium-recorder/replay-video.ts +0 -125
  545. package/server/appium-recorder/report-summary.test.ts +0 -78
  546. package/server/appium-recorder/report-summary.ts +0 -60
  547. package/server/appium-recorder/report.ts +0 -935
  548. package/server/appium-recorder/repository.ts +0 -561
  549. package/server/appium-recorder/request-timeout.test.ts +0 -34
  550. package/server/appium-recorder/request-timeout.ts +0 -34
  551. package/server/appium-recorder/routes.ts +0 -524
  552. package/server/appium-recorder/run-history.ts +0 -53
  553. package/server/appium-recorder/scrcpy-recording-source.ts +0 -85
  554. package/server/appium-recorder/screenshot.ts +0 -22
  555. package/server/appium-recorder/script-export.ts +0 -80
  556. package/server/appium-recorder/script-import.test.ts +0 -45
  557. package/server/appium-recorder/stop-app.ts +0 -18
  558. package/server/appium-recorder/tree-dump.ts +0 -66
  559. package/server/appium-recorder/variable-store.ts +0 -22
  560. package/server/appium-recorder/variables.ts +0 -89
  561. package/server/appium-recorder/video-response.ts +0 -36
  562. package/server/appium-recorder/visual-change.ts +0 -184
  563. package/server/artemis.ts +0 -34
  564. package/server/config-access.test.ts +0 -27
  565. package/server/config-access.ts +0 -27
  566. package/server/config-store.ts +0 -137
  567. package/server/config.ts +0 -272
  568. package/server/device-locks/repository.ts +0 -147
  569. package/server/device-locks/service.ts +0 -72
  570. package/server/device-locks/types.ts +0 -22
  571. package/server/device-sessions/repository.ts +0 -169
  572. package/server/device-sessions/service.ts +0 -59
  573. package/server/device-sessions/types.ts +0 -24
  574. package/server/http-api.ts +0 -1505
  575. package/server/model-tester.ts +0 -121
  576. package/server/operations/repository.ts +0 -226
  577. package/server/operations/service.ts +0 -84
  578. package/server/operations/types.ts +0 -27
  579. package/server/paths.ts +0 -36
  580. package/server/remote-agents/protocol.ts +0 -40
  581. package/server/remote-agents/registry.test.ts +0 -65
  582. package/server/remote-agents/registry.ts +0 -191
  583. package/server/remote-agents/replay-integration.test.ts +0 -79
  584. package/server/remote-agents/routes.ts +0 -86
  585. package/server/request-body.test.ts +0 -40
  586. package/server/request-body.ts +0 -48
  587. package/server/script-agent.ts +0 -289
  588. package/server/script-db.ts +0 -255
  589. package/server/script-runner.ts +0 -554
  590. package/server/storage/sqlite.ts +0 -112
  591. package/server/test-case-import/formatter.ts +0 -28
  592. package/server/test-case-import/parsers/excel.ts +0 -69
  593. package/server/test-case-import/parsers/txt.ts +0 -11
  594. package/server/test-case-import/parsers/word.ts +0 -9
  595. package/server/test-case-import/service.ts +0 -58
  596. package/server/test-case-import/text-normalizer.ts +0 -98
  597. package/server/test-case-import/types.ts +0 -24
  598. package/server/test-case-import/validator.ts +0 -34
  599. package/src/App.vue +0 -1022
  600. package/src/analytics/summary.ts +0 -75
  601. package/src/api.ts +0 -320
  602. package/src/appium-recorder/AppiumPage.vue +0 -2836
  603. package/src/appium-recorder/RunHistoryDialog.vue +0 -203
  604. package/src/appium-recorder/action-descriptions.ts +0 -49
  605. package/src/appium-recorder/ai-deduplication.ts +0 -34
  606. package/src/appium-recorder/ai-prompt-presets.ts +0 -34
  607. package/src/appium-recorder/ai-recognition.ts +0 -48
  608. package/src/appium-recorder/api.ts +0 -209
  609. package/src/appium-recorder/bounded-loop.ts +0 -74
  610. package/src/appium-recorder/components/AiRecognitionPromptInput.vue +0 -41
  611. package/src/appium-recorder/components/AiRecognitionSettings.vue +0 -251
  612. package/src/appium-recorder/components/AiRecognitionTestDialog.vue +0 -86
  613. package/src/appium-recorder/components/BranchTimeoutSettings.vue +0 -23
  614. package/src/appium-recorder/components/BreakLoopSettings.vue +0 -45
  615. package/src/appium-recorder/components/ComponentInspector.vue +0 -33
  616. package/src/appium-recorder/components/ComponentTree.vue +0 -139
  617. package/src/appium-recorder/components/CoordinatePointPicker.vue +0 -23
  618. package/src/appium-recorder/components/FlowActionMenu.vue +0 -257
  619. package/src/appium-recorder/components/FlowCanvas.vue +0 -391
  620. package/src/appium-recorder/components/FlowNodeCard.vue +0 -318
  621. package/src/appium-recorder/components/FlowNodeSearch.vue +0 -62
  622. package/src/appium-recorder/components/FlowRoundedEdge.vue +0 -58
  623. package/src/appium-recorder/components/FlowStepEditor.vue +0 -541
  624. package/src/appium-recorder/components/ImageCheckDialog.vue +0 -172
  625. package/src/appium-recorder/components/LongPressSettings.vue +0 -58
  626. package/src/appium-recorder/components/LoopSettings.vue +0 -39
  627. package/src/appium-recorder/components/MergeBranchesDialog.vue +0 -102
  628. package/src/appium-recorder/components/NestedConditionBranches.vue +0 -403
  629. package/src/appium-recorder/components/NewScriptDialog.vue +0 -27
  630. package/src/appium-recorder/components/NodeDetail.vue +0 -179
  631. package/src/appium-recorder/components/PresetVariables.vue +0 -110
  632. package/src/appium-recorder/components/RandomValueSettings.vue +0 -139
  633. package/src/appium-recorder/components/RecordedSteps.vue +0 -468
  634. package/src/appium-recorder/components/RecorderWorkspace.vue +0 -132
  635. package/src/appium-recorder/components/ScriptParameterSettings.vue +0 -65
  636. package/src/appium-recorder/components/StageLogSettings.vue +0 -17
  637. package/src/appium-recorder/components/TextClickSettings.vue +0 -19
  638. package/src/appium-recorder/components/VariableExtractionSettings.vue +0 -19
  639. package/src/appium-recorder/components/VariableTable.vue +0 -82
  640. package/src/appium-recorder/components/VisualChangeDialog.vue +0 -151
  641. package/src/appium-recorder/components/VisualChangeEndPicker.vue +0 -21
  642. package/src/appium-recorder/coordinate-preview.ts +0 -37
  643. package/src/appium-recorder/flow-appearance.ts +0 -70
  644. package/src/appium-recorder/flow-copy.ts +0 -278
  645. package/src/appium-recorder/flow-graph.ts +0 -868
  646. package/src/appium-recorder/flow-insert.ts +0 -27
  647. package/src/appium-recorder/flow-labels.ts +0 -138
  648. package/src/appium-recorder/flow-layout.ts +0 -88
  649. package/src/appium-recorder/flow-merge.ts +0 -123
  650. package/src/appium-recorder/flow-normalize.ts +0 -77
  651. package/src/appium-recorder/flow-remove.ts +0 -75
  652. package/src/appium-recorder/flow-search.ts +0 -29
  653. package/src/appium-recorder/flow-unmerge.ts +0 -145
  654. package/src/appium-recorder/image-check.ts +0 -121
  655. package/src/appium-recorder/long-press.ts +0 -27
  656. package/src/appium-recorder/native-control-state.ts +0 -33
  657. package/src/appium-recorder/node-locators.ts +0 -25
  658. package/src/appium-recorder/node-timeout.ts +0 -1
  659. package/src/appium-recorder/random-value.ts +0 -60
  660. package/src/appium-recorder/report-summary.ts +0 -60
  661. package/src/appium-recorder/run-history.ts +0 -53
  662. package/src/appium-recorder/stage-log.ts +0 -21
  663. package/src/appium-recorder/text-click.ts +0 -9
  664. package/src/appium-recorder/tree.ts +0 -176
  665. package/src/appium-recorder/types.ts +0 -198
  666. package/src/appium-recorder/variable-presets.ts +0 -24
  667. package/src/appium-recorder/variables.ts +0 -34
  668. package/src/appium-recorder/visual-change-pairs.ts +0 -155
  669. package/src/appium-recorder/visual-change.ts +0 -87
  670. package/src/assets/appium-actions/add.svg +0 -7
  671. package/src/assets/appium-actions/android.svg +0 -6
  672. package/src/assets/appium-actions/back.svg +0 -6
  673. package/src/assets/appium-actions/bidirection.svg +0 -6
  674. package/src/assets/appium-actions/browser.svg +0 -6
  675. package/src/assets/appium-actions/clear.svg +0 -3
  676. package/src/assets/appium-actions/crosshair.svg +0 -6
  677. package/src/assets/appium-actions/eye.svg +0 -3
  678. package/src/assets/appium-actions/pause.svg +0 -7
  679. package/src/assets/appium-actions/phone.svg +0 -9
  680. package/src/assets/appium-actions/pin.svg +0 -6
  681. package/src/assets/appium-actions/power.svg +0 -6
  682. package/src/assets/appium-actions/select.svg +0 -3
  683. package/src/assets/appium-actions/sidebar.svg +0 -6
  684. package/src/assets/appium-actions/text.svg +0 -6
  685. package/src/assets/appium-actions/zoom.svg +0 -6
  686. package/src/assets/device-actions/back.svg +0 -5
  687. package/src/assets/device-actions/home.svg +0 -3
  688. package/src/assets/device-actions/power.svg +0 -5
  689. package/src/assets/device-actions/tasks.svg +0 -3
  690. package/src/assets/device-actions/volume-down.svg +0 -3
  691. package/src/assets/device-actions/volume-up.svg +0 -3
  692. package/src/components/AppSidebar.vue +0 -32
  693. package/src/components/MidsceneMaintenanceNotice.vue +0 -17
  694. package/src/components/analytics/AnalysisCharts.vue +0 -189
  695. package/src/components/analytics/ReportAnalysis.vue +0 -78
  696. package/src/components/config/AiDeduplicationSettings.vue +0 -70
  697. package/src/components/config/AiPromptPresetsSettings.vue +0 -113
  698. package/src/components/config/AppiumConfigPanel.vue +0 -113
  699. package/src/components/config/AppiumModelSettings.vue +0 -45
  700. package/src/components/config/BaseConfigPanel.vue +0 -106
  701. package/src/components/config/FlowAppearanceSettings.vue +0 -150
  702. package/src/components/config/MidsceneConfigPanel.vue +0 -211
  703. package/src/components/config/ReplayReportSummarySettings.vue +0 -118
  704. package/src/components/device/DeviceInfoTooltip.vue +0 -55
  705. package/src/components/device/DevicePreviewPanel.vue +0 -482
  706. package/src/components/generator/GeneratedCodePanel.vue +0 -70
  707. package/src/components/generator/TestCaseFileUpload.vue +0 -97
  708. package/src/components/help/HelpCenter.vue +0 -204
  709. package/src/components/help/MarkdownDocument.vue +0 -139
  710. package/src/composables/use-device-preview.ts +0 -279
  711. package/src/composables/use-initial-resource.ts +0 -17
  712. package/src/composables/use-script-execution.ts +0 -277
  713. package/src/config/credentials.ts +0 -2
  714. package/src/config/midscene-model-presets.ts +0 -103
  715. package/src/config/prompt-example.ts +0 -10
  716. package/src/config/prompt-presets.ts +0 -172
  717. package/src/config/use-appium-auto-save.ts +0 -75
  718. package/src/config/use-model-config.ts +0 -161
  719. package/src/main.ts +0 -10
  720. package/src/pages/AiGeneratorPage.vue +0 -273
  721. package/src/pages/AnalysisPage.vue +0 -60
  722. package/src/pages/ArtemisPage.vue +0 -72
  723. package/src/pages/AutomationPage.vue +0 -161
  724. package/src/pages/ConfigPage.vue +0 -165
  725. package/src/pages/GeneratorPage.vue +0 -104
  726. package/src/pages/ManualStepsPage.vue +0 -179
  727. package/src/script-generator/codegen.ts +0 -126
  728. package/src/script-generator/index.ts +0 -4
  729. package/src/script-generator/presets.ts +0 -37
  730. package/src/script-generator/step-options.ts +0 -52
  731. package/src/script-generator/types.ts +0 -27
  732. package/src/style.css +0 -4183
  733. package/src/types.ts +0 -167
  734. package/src/vite-env.d.ts +0 -1
  735. package/tsconfig.app.json +0 -8
  736. package/tsconfig.json +0 -11
  737. package/tsconfig.node.json +0 -16
  738. package/vite.config.ts +0 -28
  739. package//346/265/201/347/250/213/350/212/202/347/202/271/346/223/215/344/275/234/350/257/264/346/230/216.md +0 -408
@@ -1,2836 +0,0 @@
1
- <script setup lang="ts">
2
- import { computed, h, nextTick, onMounted, onUnmounted, provide, reactive, shallowRef, useTemplateRef, watch } from 'vue';
3
- import { flowBackgroundKey, normalizeFlowBackground, flowLineColorKey, normalizeFlowLineColor, flowLineStyleKey, normalizeFlowLineStyle, type FlowLineStyle, flowLayoutDirectionKey, normalizeFlowLayoutDirection, type FlowLayoutDirection, flowNodeColorKey, normalizeFlowNodeColor, flowNodeBorderColorKey, normalizeFlowNodeBorderColor } from './flow-appearance';
4
- import { useCoordinatePicker } from './coordinate-preview';
5
- import { DEFAULT_NODE_TIMEOUT_MS } from './node-timeout';
6
- import { aiPromptPresetsKey, DEFAULT_AI_PROMPT_PRESETS, type AiPromptPreset } from './ai-prompt-presets';
7
- import AiRecognitionPromptInput from './components/AiRecognitionPromptInput.vue';
8
- import { ElForm, ElFormItem, ElInputNumber, ElMessage, ElMessageBox, ElOption, ElSelect } from 'element-plus';
9
- import { ArrowDown, Check, CircleClose, CopyDocument, Delete, Document, Download, Edit, FolderOpened, Loading, Plus, Refresh, Upload, VideoPlay, View, Clock } from '@element-plus/icons-vue';
10
- import RunHistoryDialog from './RunHistoryDialog.vue';
11
- import type { AndroidDevice, AppPreset, DeviceAction } from '../types';
12
- import DevicePreviewPanel from '../components/device/DevicePreviewPanel.vue';
13
- import LoopSettings from './components/LoopSettings.vue';
14
- import BreakLoopSettings from './components/BreakLoopSettings.vue';
15
- import VisualChangeEndPicker from './components/VisualChangeEndPicker.vue';
16
- import PresetVariables from './components/PresetVariables.vue';
17
- import { insertBeforeSharedStep } from './flow-insert';
18
- import VariableExtractionSettings from './components/VariableExtractionSettings.vue';
19
- import ScriptParameterSettings from './components/ScriptParameterSettings.vue';
20
- import { validateVariables, validateExtraction, validateReturns, type TestVariable } from './variables';
21
- import { breakLoopTarget, continueLoopTarget, defaultLoopConfig, enclosingLoops, validateLoop, validateLoopSteps } from './bounded-loop';
22
- import {
23
- clearAppiumDeviceAppData,
24
- checkReportSummaryModel,
25
- deleteAppiumScript,
26
- downloadAppiumScript,
27
- getAppiumScripts,
28
- getAppiumTree,
29
- importAppiumScripts,
30
- launchAppiumDeviceApp,
31
- loadVariables,
32
- replayAppiumScript,
33
- saveAppiumScript,
34
- saveVariables,
35
- stopAppiumReplay,
36
- tapAppiumDevice,
37
- } from './api';
38
- import ComponentInspector from './components/ComponentInspector.vue';
39
- import RecorderWorkspace from './components/RecorderWorkspace.vue';
40
- import FlowCanvas from './components/FlowCanvas.vue';
41
- import LongPressSettings from './components/LongPressSettings.vue';
42
- import StageLogSettings from './components/StageLogSettings.vue';
43
- import TextClickSettings from './components/TextClickSettings.vue';
44
- import { textClickSelector } from './text-click';
45
- import { DEFAULT_LOG_PREFIX, validateStageLog } from './stage-log';
46
- import RandomValueSettings from './components/RandomValueSettings.vue';
47
- import { defaultRandomValue, validateRandomValue } from './random-value';
48
- import { variablePresetKey, variablePresetOptions, type VariablePresetContext } from './variable-presets';
49
- import RecordedSteps from './components/RecordedSteps.vue';
50
- import NewScriptDialog from './components/NewScriptDialog.vue';
51
- import VisualChangeDialog from './components/VisualChangeDialog.vue';
52
- import ImageCheckDialog from './components/ImageCheckDialog.vue';
53
- import AiRecognitionTestDialog from './components/AiRecognitionTestDialog.vue';
54
- import { validateAiRecognitionPrompt } from './ai-recognition';
55
- import { DEFAULT_REPORT_SUMMARY_PROMPT, REPORT_SUMMARY_PROMPT_PRESETS, type ReportSummaryConfig } from './report-summary';
56
- import { createImageCheckConfig, validateImageCheck, type ImageCheckConfig } from './image-check';
57
- import {
58
- createFlowClipboard,
59
- pasteFlowClipboard,
60
- type FlowClipboard,
61
- } from './flow-copy';
62
- import { labelFlowStep } from './flow-labels';
63
- import { validateLongPress } from './long-press';
64
- import { nativeControlName, matchesNativeControl } from './native-control-state';
65
- import { normalizeLegacyNestedConditionBranches } from './flow-normalize';
66
- import { removeFlowStep } from './flow-remove';
67
- import type { FlowActionGroup, InsertAction } from './flow-graph';
68
- import { findSmallestNodeAtPoint, flattenNodes, parseWindowHierarchy } from './tree';
69
- import {
70
- boundsToVisualRegion,
71
- createStepId,
72
- normalizeVisualChangeConfig,
73
- syncVisualChangeThreshold,
74
- visualRegionToBounds,
75
- } from './visual-change';
76
- import {
77
- findOpenVisualChangeStarts,
78
- nextVisualChangePairLabel,
79
- } from './visual-change-pairs';
80
- import type {
81
- AppiumNode,
82
- AppiumRecordedScript,
83
- AppiumRecordedStep,
84
- AppiumVisualChangeConfig,
85
- AppiumVisualChangeRegion,
86
- } from './types';
87
-
88
- type NodeStepType = 'tap' | 'input' | 'waitFor';
89
- type BranchName = 'yes' | 'no';
90
- type LegacyFlow = NonNullable<AppiumRecordedStep['flow']> & { scope?: string };
91
- type SwipeGesture = NonNullable<AppiumRecordedStep['swipe']>;
92
- type SwipeForm = SwipeGesture & { direction: string };
93
- type BranchTarget = {
94
- beforeStepId?: string;
95
- stepId: string;
96
- branch: BranchName;
97
- updateTarget?: boolean;
98
- entryTargetId?: string;
99
- nextTargetId?: string;
100
- };
101
- type RecorderAction = InsertAction;
102
-
103
- const WORKBENCH_TAB_STORAGE_KEY = 'android-midscene-automation:appium-workbench-tab';
104
- const workspaceRef = shallowRef<InstanceType<typeof RecorderWorkspace>>();
105
- const historyScript = shallowRef<{ id: string; name: string } | null>(null);
106
- const AUTO_TREE_REFRESH_INTERVAL_MS = 1800;
107
-
108
- const readonlyFlowActionGroups: FlowActionGroup[] = [];
109
- const readonlyFlowSelectedIndexes: number[] = [];
110
- const recordReplayVideo = shallowRef(false);
111
- const selectedReportTemplateName = shallowRef('');
112
-
113
- const props = defineProps<{
114
- aiRecognitionModelConfigured?: boolean;
115
- aiPromptPresets?: AiPromptPreset[];
116
- reportSummary?: ReportSummaryConfig;
117
- flowBackgroundColor?: string;
118
- flowNodeColor?: string;
119
- flowNodeBorderColor?: string;
120
- flowLineColor?: string;
121
- flowLineStyle?: FlowLineStyle;
122
- flowLayoutDirection?: FlowLayoutDirection;
123
- active: boolean;
124
- appPresets: AppPreset[];
125
- deviceActions: readonly DeviceAction[];
126
- playgroundAvailable: boolean;
127
- playgroundDeviceId: string;
128
- playgroundFrameUrl: string;
129
- playgroundPreviewError: string;
130
- devicePreviewUrl: string;
131
- androidDevices: AndroidDevice[];
132
- deviceWidth: number;
133
- deviceHeight: number;
134
- switchAndroidDevice: (deviceId: string) => Promise<void>;
135
- triggerDeviceKey: (keyCode: number) => Promise<void>;
136
- refreshDevicePreview: () => void | Promise<void>;
137
- swipeDevice: (
138
- startX: number,
139
- startY: number,
140
- endX: number,
141
- endY: number,
142
- duration?: number,
143
- ) => Promise<void>;
144
- }>();
145
-
146
- // provide/inject 随组件关系传递,放大弹窗 teleport 后也能使用同一颜色。
147
- provide(flowBackgroundKey, computed(() => normalizeFlowBackground(props.flowBackgroundColor)));
148
- provide(flowNodeColorKey, computed(() => normalizeFlowNodeColor(props.flowNodeColor)));
149
- provide(flowNodeBorderColorKey, computed(() => normalizeFlowNodeBorderColor(props.flowNodeBorderColor)));
150
- provide(flowLineColorKey, computed(() => normalizeFlowLineColor(props.flowLineColor)));
151
- provide(flowLineStyleKey, computed(() => normalizeFlowLineStyle(props.flowLineStyle)));
152
- provide(flowLayoutDirectionKey, computed(() => normalizeFlowLayoutDirection(props.flowLayoutDirection)));
153
- const availableAiPromptPresets = computed(() => props.aiPromptPresets ?? DEFAULT_AI_PROMPT_PRESETS);
154
- const availableReportTemplates = computed(() => [
155
- ...REPORT_SUMMARY_PROMPT_PRESETS,
156
- ...(props.reportSummary?.customPresets || []),
157
- ]);
158
- const selectedReportTemplate = computed(() => availableReportTemplates.value.find(item => item.name === selectedReportTemplateName.value));
159
- provide(aiPromptPresetsKey, availableAiPromptPresets);
160
- const selectedDeviceId = computed(() => props.playgroundDeviceId);
161
- const tree = shallowRef<AppiumNode | null>(null);
162
- const selectedNode = shallowRef<AppiumNode | null>(null);
163
- const scripts = shallowRef<AppiumRecordedScript[]>([]);
164
- const selectedScriptId = shallowRef('');
165
- const recordedStepsRef = useTemplateRef('recordedStepsRef');
166
- const newScriptDialogVisible = shallowRef(false);
167
- const newScriptRevision = shallowRef(0);
168
- const storedWorkbenchTab = window.localStorage.getItem(WORKBENCH_TAB_STORAGE_KEY);
169
- const activeWorkbenchTab = shallowRef<'recording' | 'scripts' | 'variables'>(storedWorkbenchTab === 'scripts' ? 'scripts' : storedWorkbenchTab === 'variables' ? 'variables' : 'recording');
170
- const steps = shallowRef<AppiumRecordedStep[]>([]);
171
- const aiRecognitionTestStep = shallowRef<AppiumRecordedStep | null>(null);
172
- const flowClipboard = shallowRef<FlowClipboard | null>(null);
173
- const rawXml = shallowRef('');
174
- const currentActivity = shallowRef('');
175
- const replayOutput = shallowRef('');
176
- const replayOutputDialogVisible = shallowRef(false);
177
- const linkedScriptDialogVisible = shallowRef(false);
178
- const linkedScriptEditingId = shallowRef('');
179
- const linkedScriptTargetId = shallowRef('');
180
- const linkedParameters = reactive<AppiumRecordedStep>({ id: 'link-parameters', type: 'runScript', label: '', parameters: [], returns: [] });
181
- const linkedScriptInsertIndex = shallowRef<number | undefined>();
182
- const linkedScriptBranchTarget = shallowRef<BranchTarget | null>(null);
183
- const linkedScriptExpectedActivity = shallowRef('');
184
- const linkedScriptPreviewVisible = shallowRef(false);
185
- const linkedScriptPreviewScriptId = shallowRef('');
186
- const linkedScriptPreviewResetToken = shallowRef(0);
187
- const visualChangeDialogVisible = shallowRef(false);
188
- const imageCheckDraft = shallowRef<AppiumRecordedStep | null>(null);
189
- let imageCheckIndex: number | undefined;
190
- let imageCheckBranch: BranchTarget | undefined;
191
- let imageCheckEditing = false;
192
- const imageCheckPicking = shallowRef(false);
193
- const visualChangePicking = shallowRef(false);
194
- const visualChangeInsertIndex = shallowRef<number | undefined>();
195
- const visualChangeBranchTarget = shallowRef<BranchTarget | null>(null);
196
- const visualChangeConfig = shallowRef<AppiumVisualChangeConfig>(normalizeVisualChangeConfig());
197
- const loadingTree = shallowRef(false);
198
- const saving = shallowRef(false);
199
- const importingScript = shallowRef(false);
200
- const scriptImportInput = shallowRef<HTMLInputElement | null>(null);
201
- const deletingScriptId = shallowRef('');
202
- const duplicatingScriptId = shallowRef('');
203
- const renamingScriptId = shallowRef('');
204
- const downloadingScriptId = shallowRef('');
205
- const replaying = shallowRef(false);
206
- const preparingReplay = shallowRef(false);
207
- const stoppingReplay = shallowRef(false);
208
- const activeReplayDeviceId = shallowRef('');
209
- const recordingTap = shallowRef(false);
210
- const resolvingNavigation = shallowRef(false);
211
- const launchingApp = shallowRef(false);
212
- const executingAppStepId = shallowRef('');
213
- const pendingNavigation = shallowRef<{
214
- beforeActivity: string;
215
- afterActivity: string;
216
- } | null>(null);
217
- type TreePayload = Awaited<ReturnType<typeof getAppiumTree>>;
218
- let treeRequest: Promise<TreePayload> | null = null;
219
- let autoTreeRefreshTimer: number | null = null;
220
- let autoTreeRefreshInFlight = false;
221
-
222
- const form = reactive({
223
- name: '',
224
- appPackage: '',
225
- appActivity: '',
226
- });
227
- const scriptVariables = shallowRef<TestVariable[]>([]);
228
- const globalVariables = shallowRef<TestVariable[]>([]);
229
- const variablePresetsLoading = shallowRef(false);
230
- const variablePresetsError = shallowRef('');
231
- const availableVariablePresets = computed(() => variablePresetOptions(globalVariables.value, scriptVariables.value));
232
- const pendingRandomValue = shallowRef<{ step: AppiumRecordedStep; index?: number; branchTarget?: BranchTarget } | null>(null);
233
- let variablePresetsRequest: Promise<void> | undefined;
234
-
235
- function refreshVariablePresets(): Promise<void> {
236
- if (variablePresetsRequest) return variablePresetsRequest;
237
- variablePresetsLoading.value = true;
238
- variablePresetsError.value = '';
239
- variablePresetsRequest = loadVariables('/api/appium-recorder/variables').then(result => {
240
- globalVariables.value = result.variables;
241
- }).catch(error => {
242
- variablePresetsError.value = error instanceof Error ? error.message : '预设变量加载失败';
243
- }).finally(() => {
244
- variablePresetsLoading.value = false;
245
- variablePresetsRequest = undefined;
246
- });
247
- return variablePresetsRequest;
248
- }
249
-
250
- const variablePresets: VariablePresetContext = {
251
- options: availableVariablePresets, loading: variablePresetsLoading, error: variablePresetsError,
252
- refresh: refreshVariablePresets, open: () => setActiveWorkbenchTab('variables'),
253
- };
254
- provide(variablePresetKey, variablePresets);
255
-
256
- function validateRandomValueTarget(step: AppiumRecordedStep) {
257
- if (!availableVariablePresets.value.some(variable => variable.name === step.randomValue?.name)) {
258
- throw new Error(`节点「${step.label}」请选择已有预设变量;没有对应 key 时请先到“预设变量”添加`);
259
- }
260
- }
261
-
262
- async function validateRandomValueTargets() {
263
- const randomSteps = steps.value.filter(step => step.type === 'randomValue');
264
- if (!randomSteps.length) return;
265
- await refreshVariablePresets();
266
- randomSteps.forEach(validateRandomValueTarget);
267
- steps.value = steps.value.map(step => step.randomValue && availableVariablePresets.value.some(variable => variable.name === step.randomValue!.name && variable.sensitive)
268
- ? { ...step, randomValue: { ...step.randomValue, sensitive: true } } : step);
269
- }
270
-
271
- function resumeRandomValue() {
272
- const pending = pendingRandomValue.value;
273
- if (!pending) return;
274
- setActiveWorkbenchTab('recording');
275
- void addAction('randomValue', pending.index, pending.branchTarget);
276
- }
277
-
278
- const savedDraftSnapshot = shallowRef('');
279
- const currentDraftSnapshot = computed(() => JSON.stringify({
280
- name: form.name,
281
- appPackage: form.appPackage,
282
- appActivity: form.appActivity,
283
- steps: steps.value,
284
- variables: scriptVariables.value,
285
- }));
286
- const flowClipboardCount = computed(() => flowClipboard.value?.steps.length || 0);
287
- const hasUnsavedChanges = computed(() => currentDraftSnapshot.value !== savedDraftSnapshot.value);
288
-
289
- function markDraftSaved() {
290
- savedDraftSnapshot.value = currentDraftSnapshot.value;
291
- }
292
-
293
- function onVariablesSaved(id: string, variables: TestVariable[]) {
294
- const script = scripts.value.find(item => item.id === id);
295
- if (script) script.variables = variables;
296
- if (id && selectedScriptId.value === id) {
297
- // 仅更新变量的已保存基线,不把尚未保存的节点标记为已保存。
298
- const snapshot = JSON.parse(savedDraftSnapshot.value);
299
- savedDraftSnapshot.value = JSON.stringify({ ...snapshot, variables });
300
- }
301
- }
302
-
303
- function warnBeforeUnload(event: BeforeUnloadEvent) {
304
- if (!hasUnsavedChanges.value) return;
305
- event.preventDefault();
306
- event.returnValue = '';
307
- }
308
-
309
- markDraftSaved();
310
-
311
- const selectedScript = computed(() => scripts.value.find((script) => script.id === selectedScriptId.value) || null);
312
- const linkableScripts = computed(() => scripts.value.filter((script) => script.id !== selectedScriptId.value));
313
- const linkedScriptTarget = computed(() => scripts.value.find((script) => script.id === linkedScriptTargetId.value) || null);
314
- const linkedScriptPreviewScript = computed(() => (
315
- scripts.value.find((script) => script.id === linkedScriptPreviewScriptId.value) || null
316
- ));
317
- const compatibleLinkableScripts = computed(() => linkableScripts.value.filter(
318
- (script) => script.appPackage === form.appPackage,
319
- ));
320
- const hasSelectedAppPackage = computed(() => props.appPresets.some((app) => app.packageName === form.appPackage));
321
- const scriptActivityMismatch = computed(() => {
322
- const expectedActivity = selectedScript.value?.appActivity?.trim();
323
- if (!expectedActivity) return false;
324
- return currentActivity.value !== expectedActivity;
325
- });
326
- const recordingBusy = computed(() => (
327
- recordingTap.value
328
- || resolvingNavigation.value
329
- || Boolean(pendingNavigation.value)
330
- ));
331
- const recordingLocked = computed(() => recordingBusy.value || replaying.value || preparingReplay.value);
332
- const newScriptDisabled = computed(() => saving.value || replaying.value || preparingReplay.value || recordingBusy.value || launchingApp.value || importingScript.value);
333
- const overlayBounds = computed(() => flattenNodes(tree.value).flatMap((node) => (
334
- node.bounds ? [{ id: node.id, ...node.bounds }] : []
335
- )));
336
- const selectedBounds = computed(() => {
337
- const bounds = selectedNode.value?.bounds;
338
- return bounds && selectedNode.value ? { id: selectedNode.value.id, ...bounds } : undefined;
339
- });
340
- const visualChangeSelectedRegion = computed(() => {
341
- if (imageCheckDraft.value?.imageCheck?.target === 'region') return visualRegionToBounds('image-check-region', imageCheckDraft.value.imageCheck.region);
342
- if (!visualChangeDialogVisible.value || visualChangeConfig.value.mode !== 'region') return undefined;
343
- return visualRegionToBounds('visual-change-region', visualChangeConfig.value.region);
344
- });
345
- const visualChangeRegionSelectionEnabled = computed(() => (
346
- (visualChangeDialogVisible.value && visualChangeConfig.value.mode === 'region') || imageCheckDraft.value?.imageCheck?.target === 'region'
347
- ));
348
-
349
- const coordinatePicker = useCoordinatePicker(
350
- computed(() => Boolean(selectedDeviceId.value) && !recordingLocked.value && !visualChangeRegionSelectionEnabled.value),
351
- () => workspaceRef.value?.showPreview(),
352
- );
353
- const pickingCoordinate = coordinatePicker.picking;
354
- watch([selectedDeviceId, () => props.active], () => coordinatePicker.cancel());
355
-
356
- function stepWithBranchTarget(step: AppiumRecordedStep, branchTarget: BranchTarget) {
357
- return {
358
- ...step,
359
- flow: {
360
- ...(step.flow || {}),
361
- parentConditionId: branchTarget.stepId,
362
- parentBranch: branchTarget.branch,
363
- ...(branchTarget.nextTargetId ? { successTargetId: branchTarget.nextTargetId } : {}),
364
- },
365
- };
366
- }
367
-
368
- function insertStep(step: AppiumRecordedStep, index?: number, branchTarget?: BranchTarget) {
369
- if (branchTarget?.beforeStepId) {
370
- steps.value = insertBeforeSharedStep(steps.value, branchTarget.beforeStepId, [step], [step.id]);
371
- return steps.value.find(item => item.id === step.id)!;
372
- }
373
- let nextSteps = [...steps.value];
374
- let insertedStep = branchTarget ? stepWithBranchTarget(step, branchTarget) : step;
375
- if (index === -1) {
376
- nextSteps.unshift(insertedStep);
377
- } else if (typeof index === 'number') {
378
- const previousStep = nextSteps[index];
379
- const previousTargetId = previousStep?.flow?.successTargetId;
380
- const shouldRewireSuccess = previousStep
381
- && previousTargetId
382
- && !(branchTarget && previousStep.id === branchTarget.stepId);
383
- if (shouldRewireSuccess) {
384
- insertedStep = {
385
- ...insertedStep,
386
- flow: {
387
- ...(insertedStep.flow || {}),
388
- successTargetId: previousTargetId,
389
- },
390
- };
391
- nextSteps[index] = {
392
- ...previousStep,
393
- flow: {
394
- ...(previousStep.flow || {}),
395
- successTargetId: insertedStep.id,
396
- },
397
- };
398
- }
399
- nextSteps.splice(index + 1, 0, insertedStep);
400
- } else {
401
- nextSteps.push(insertedStep);
402
- }
403
- if (branchTarget?.updateTarget) {
404
- const targetKey = branchTarget.branch === 'yes' ? 'yesTargetId' : 'noTargetId';
405
- nextSteps = nextSteps.map((item) => (
406
- item.id === branchTarget.stepId
407
- ? {
408
- ...item,
409
- flow: {
410
- ...(item.flow || {}),
411
- nodeKind: 'condition',
412
- [targetKey]: branchTarget.entryTargetId || insertedStep.id,
413
- },
414
- }
415
- : item
416
- ));
417
- }
418
- steps.value = nextSteps;
419
- return insertedStep;
420
- }
421
-
422
- function copyFlowNodes(indexes: number[]) {
423
- try {
424
- flowClipboard.value = createFlowClipboard(steps.value, indexes);
425
- ElMessage.success(`已复制 ${flowClipboardCount.value} 个节点`);
426
- } catch (error) {
427
- ElMessage.warning(error instanceof Error ? error.message : '复制节点失败');
428
- }
429
- }
430
-
431
- function pasteFlowNodes(index: number, branch?: BranchName, beforeStepId?: string) {
432
- if (!flowClipboard.value) {
433
- ElMessage.warning('请先复制节点');
434
- return;
435
- }
436
- if (recordingBusy.value) {
437
- ElMessage.warning('页面操作处理中,请稍后再粘贴');
438
- return;
439
- }
440
- try {
441
- const nextSteps = pasteFlowClipboard(steps.value, flowClipboard.value, {
442
- afterIndex: index,
443
- branch,
444
- beforeStepId,
445
- });
446
- validateLoopSteps(nextSteps);
447
- steps.value = nextSteps;
448
- ElMessage.success(`已粘贴 ${flowClipboardCount.value} 个节点${branch ? `到${branch === 'yes' ? '是' : '否'}分支` : ''}`);
449
- flowClipboard.value = null;
450
- } catch (error) {
451
- ElMessage.warning(error instanceof Error ? error.message : '粘贴节点失败');
452
- }
453
- }
454
-
455
- function normalizeLegacyFlowScope(step: AppiumRecordedStep): AppiumRecordedStep {
456
- const flow = step.flow as LegacyFlow | undefined;
457
- if (!flow?.scope) return step;
458
- const nextFlow = { ...flow };
459
- delete nextFlow.scope;
460
- return {
461
- ...step,
462
- flow: Object.keys(nextFlow).length ? nextFlow : undefined,
463
- };
464
- }
465
-
466
- function updateBranchTarget(stepId: string, branch: BranchName, targetId: string) {
467
- const targetKey = branch === 'yes' ? 'yesTargetId' : 'noTargetId';
468
- steps.value = steps.value.map((step) => (
469
- step.id === stepId
470
- ? {
471
- ...step,
472
- flow: {
473
- ...(step.flow || {}),
474
- nodeKind: 'condition',
475
- [targetKey]: targetId,
476
- },
477
- }
478
- : step
479
- ));
480
- }
481
-
482
- function attachStepToBranch(stepId: string, conditionId: string, branch: BranchName) {
483
- steps.value = steps.value.map((step) => (
484
- step.id === stepId
485
- ? {
486
- ...step,
487
- flow: {
488
- ...(step.flow || {}),
489
- parentConditionId: conditionId,
490
- parentBranch: branch,
491
- },
492
- }
493
- : step
494
- ));
495
- }
496
-
497
- function applyBranchTargetToInsertedStep(inserted: AppiumRecordedStep, branchTarget: BranchTarget) {
498
- attachStepToBranch(inserted.id, branchTarget.stepId, branchTarget.branch);
499
- if (branchTarget.nextTargetId) {
500
- steps.value = steps.value.map((step) => (
501
- step.id === inserted.id
502
- ? {
503
- ...step,
504
- flow: { ...(step.flow || {}), successTargetId: branchTarget.nextTargetId },
505
- }
506
- : step
507
- ));
508
- }
509
- if (branchTarget.updateTarget) {
510
- updateBranchTarget(
511
- branchTarget.stepId,
512
- branchTarget.branch,
513
- branchTarget.entryTargetId || inserted.id,
514
- );
515
- }
516
- }
517
-
518
- function branchContextForInsert(index: number, branch: BranchName) {
519
- const anchor = steps.value[index];
520
- if (!anchor) return undefined;
521
- if (anchor.flow?.nodeKind === 'condition') {
522
- return { condition: anchor, conditionIndex: index };
523
- }
524
- if (anchor.flow?.parentConditionId && anchor.flow.parentBranch === branch) {
525
- const conditionIndex = steps.value.findIndex((step) => step.id === anchor.flow?.parentConditionId);
526
- const condition = conditionIndex >= 0 ? steps.value[conditionIndex] : undefined;
527
- return condition ? { condition, conditionIndex } : undefined;
528
- }
529
- return undefined;
530
- }
531
-
532
- function nextBranchStepAfter(conditionId: string, branch: BranchName, index: number) {
533
- return steps.value.slice(index + 1).find((step) => (
534
- step.flow?.parentConditionId === conditionId && step.flow.parentBranch === branch
535
- ));
536
- }
537
-
538
- function createStep(type: NodeStepType, node: AppiumNode): AppiumRecordedStep {
539
- const labelMap = {
540
- tap: '点击',
541
- input: '输入',
542
- waitFor: '等待出现',
543
- };
544
- return {
545
- id: `step_${Date.now().toString(36)}_${Math.random().toString(36).slice(2, 8)}`,
546
- type,
547
- label: `${labelMap[type]} ${node.label}`,
548
- selector: node.selector,
549
- contextSelector: node.contextSelector,
550
- selectorChain: node.xpath && node.selector.value !== node.xpath
551
- ? [{ strategy: 'xpath', value: node.xpath, unique: true, matchCount: 1 }]
552
- : undefined,
553
- fallback: node.bounds ? { strategy: 'bounds', centerX: node.bounds.centerX, centerY: node.bounds.centerY } : undefined,
554
- timeoutMs: type === 'waitFor' ? DEFAULT_NODE_TIMEOUT_MS : undefined,
555
- pageBefore: currentPageSnapshot(node),
556
- snapshot: {
557
- text: node.text,
558
- resourceId: node.resourceId,
559
- contentDesc: node.contentDesc,
560
- className: node.className,
561
- },
562
- };
563
- }
564
-
565
- async function copyReplayOutput() {
566
- if (!replayOutput.value) return;
567
- await navigator.clipboard.writeText(replayOutput.value);
568
- ElMessage.success('回放输出已复制');
569
- }
570
-
571
- function clearReplayOutput() {
572
- replayOutput.value = '';
573
- replayOutputDialogVisible.value = false;
574
- }
575
-
576
- function createDelayStep(timeoutMs: number): AppiumRecordedStep {
577
- return {
578
- id: `step_${Date.now().toString(36)}_${Math.random().toString(36).slice(2, 8)}`,
579
- type: 'delay',
580
- label: `延时 ${timeoutMs}ms`,
581
- timeoutMs,
582
- };
583
- }
584
-
585
- function createNodeActionStep(
586
- type: AppiumRecordedStep['type'],
587
- label: string,
588
- node: AppiumNode,
589
- options: Pick<AppiumRecordedStep, 'timeoutMs' | 'value'> = {},
590
- ): AppiumRecordedStep {
591
- return {
592
- id: `step_${Date.now().toString(36)}_${Math.random().toString(36).slice(2, 8)}`,
593
- type,
594
- label: `${label} ${node.label}`,
595
- selector: node.selector,
596
- contextSelector: node.contextSelector,
597
- selectorChain: node.xpath && node.selector.value !== node.xpath
598
- ? [{ strategy: 'xpath', value: node.xpath, unique: true, matchCount: 1 }]
599
- : undefined,
600
- fallback: node.bounds ? { strategy: 'bounds', centerX: node.bounds.centerX, centerY: node.bounds.centerY } : undefined,
601
- ...options,
602
- pageBefore: currentPageSnapshot(node),
603
- snapshot: {
604
- text: node.text,
605
- resourceId: node.resourceId,
606
- contentDesc: node.contentDesc,
607
- className: node.className,
608
- },
609
- };
610
- }
611
-
612
- function createKeyStep(keyCode: number, label = '按返回键'): AppiumRecordedStep {
613
- return {
614
- id: `step_${Date.now().toString(36)}_${Math.random().toString(36).slice(2, 8)}`,
615
- type: 'key',
616
- label,
617
- keyCode,
618
- };
619
- }
620
-
621
- function swipePreset(direction: string): { direction: string; label: string; swipe: SwipeGesture } {
622
- const normalizedDirection = ({ 上: 'up', 下: 'down', 左: 'left', 右: 'right' } as Record<string, string>)[direction] || direction;
623
- const width = props.deviceWidth || 1080;
624
- const height = props.deviceHeight || 1920;
625
- const centerX = Math.round(width * 0.5);
626
- const centerY = Math.round(height * 0.5);
627
- const distanceX = Math.round(width * 0.35);
628
- const distanceY = Math.round(height * 0.35);
629
- const swipeMap: Record<string, SwipeGesture> = {
630
- up: { startX: centerX, startY: centerY + distanceY, endX: centerX, endY: centerY - distanceY, duration: 500 },
631
- down: { startX: centerX, startY: centerY - distanceY, endX: centerX, endY: centerY + distanceY, duration: 500 },
632
- left: { startX: centerX + distanceX, startY: centerY, endX: centerX - distanceX, endY: centerY, duration: 500 },
633
- right: { startX: centerX - distanceX, startY: centerY, endX: centerX + distanceX, endY: centerY, duration: 500 },
634
- };
635
- const labelMap: Record<string, string> = { up: '上滑', down: '下滑', left: '左滑', right: '右滑' };
636
- return {
637
- direction: normalizedDirection,
638
- label: labelMap[normalizedDirection] || '滑动',
639
- swipe: swipeMap[normalizedDirection] || swipeMap.up,
640
- };
641
- }
642
-
643
- function createSwipeStep(input: { label: string; swipe: SwipeGesture }): AppiumRecordedStep {
644
- return {
645
- id: `step_${Date.now().toString(36)}_${Math.random().toString(36).slice(2, 8)}`,
646
- type: 'swipe',
647
- label: input.label,
648
- swipe: input.swipe,
649
- };
650
- }
651
-
652
- function createWaitActivityStep(activity: string): AppiumRecordedStep {
653
- return {
654
- id: `step_${Date.now().toString(36)}_${Math.random().toString(36).slice(2, 8)}`,
655
- type: 'waitActivity',
656
- label: `等待 Activity ${activity}`,
657
- value: activity,
658
- timeoutMs: DEFAULT_NODE_TIMEOUT_MS,
659
- };
660
- }
661
-
662
- function createRunScriptStep(script: AppiumRecordedScript): AppiumRecordedStep {
663
- return {
664
- id: `step_${Date.now().toString(36)}_${Math.random().toString(36).slice(2, 8)}`,
665
- type: 'runScript',
666
- label: `连接脚本 ${script.name}`,
667
- value: script.id,
668
- flow: { nodeKind: 'action' },
669
- };
670
- }
671
-
672
- function createNoopStep(): AppiumRecordedStep {
673
- return {
674
- id: createStepId(),
675
- type: 'noop',
676
- label: '空节点',
677
- flow: { nodeKind: 'action' },
678
- };
679
- }
680
-
681
- function defaultVisualChangeRegion(): AppiumVisualChangeRegion {
682
- const width = props.deviceWidth || 1080;
683
- const height = props.deviceHeight || 1920;
684
- const regionWidth = Math.max(1, Math.round(width * 0.5));
685
- const regionHeight = Math.max(1, Math.round(height * 0.25));
686
- return {
687
- x: Math.max(0, Math.round((width - regionWidth) / 2)),
688
- y: Math.max(0, Math.round((height - regionHeight) / 2)),
689
- width: regionWidth,
690
- height: regionHeight,
691
- };
692
- }
693
-
694
- function updateImageCheck(config: ImageCheckConfig) {
695
- if (imageCheckDraft.value) imageCheckDraft.value = { ...imageCheckDraft.value, imageCheck: config };
696
- }
697
-
698
- function useImageCheckElement() {
699
- const node = selectedNode.value;
700
- if (!node?.bounds || !imageCheckDraft.value?.imageCheck) return;
701
- const located = createNodeActionStep('imageCheck', '图像判断', node);
702
- imageCheckDraft.value = { ...imageCheckDraft.value, selector: located.selector, contextSelector: located.contextSelector,
703
- selectorChain: located.selectorChain, fallback: undefined,
704
- imageCheck: { ...imageCheckDraft.value.imageCheck, target: 'element', region: boundsToVisualRegion(node.bounds) } };
705
- }
706
-
707
- function confirmImageCheck() {
708
- const draft = imageCheckDraft.value;
709
- if (!draft || recordingLocked.value) return;
710
- try {
711
- validateImageCheck(draft.imageCheck);
712
- if (draft.imageCheck?.target === 'element' && (!draft.selector || draft.selector.strategy === 'bounds')) throw new Error('请选择具有有效定位信息的组件');
713
- if (imageCheckEditing) {
714
- const index = steps.value.findIndex(step => step.id === draft.id);
715
- if (index < 0) throw new Error('原节点已删除');
716
- updateStep(index, draft);
717
- } else insertStep(draft, imageCheckIndex, imageCheckBranch);
718
- imageCheckDraft.value = null;
719
- imageCheckPicking.value = false;
720
- } catch (error) { ElMessage.warning((error as Error).message); }
721
- }
722
-
723
- function currentVisualChangeConfig() {
724
- const bounds = selectedNode.value?.bounds;
725
- return normalizeVisualChangeConfig({
726
- mode: bounds ? 'selectedElement' : 'region',
727
- region: bounds ? boundsToVisualRegion(bounds) : defaultVisualChangeRegion(),
728
- } as AppiumVisualChangeConfig);
729
- }
730
-
731
- function createVisualChangeStartStep(config: AppiumVisualChangeConfig): AppiumRecordedStep {
732
- const normalizedConfig = normalizeVisualChangeConfig(config);
733
- const pairId = createStepId();
734
- const pairLabel = nextVisualChangePairLabel(steps.value);
735
- const visualChange = {
736
- ...normalizedConfig,
737
- role: 'start' as const,
738
- pairId,
739
- pairLabel,
740
- startStepId: '',
741
- endStepId: '',
742
- };
743
- const node = normalizedConfig.mode === 'selectedElement' ? selectedNode.value : null;
744
- if (node) {
745
- const step = createNodeActionStep('visualChange', `${pairLabel}-开始节点`, node);
746
- return {
747
- ...step,
748
- label: `${pairLabel}-开始节点`,
749
- visualChange,
750
- flow: { ...(step.flow || {}), nodeKind: 'assertion' },
751
- };
752
- }
753
- return {
754
- id: createStepId(),
755
- type: 'visualChange',
756
- label: `${pairLabel}-开始节点`,
757
- visualChange,
758
- flow: { nodeKind: 'assertion' },
759
- };
760
- }
761
-
762
- function createVisualChangeEndStep(startStep: AppiumRecordedStep): AppiumRecordedStep {
763
- const config = normalizeVisualChangeConfig(startStep.visualChange);
764
- const id = createStepId();
765
- const pairLabel = config.pairLabel || '检测画面变化';
766
- const pairId = config.pairId || startStep.id;
767
- return {
768
- id,
769
- type: 'visualChange',
770
- label: `${pairLabel}-结束节点`,
771
- visualChange: {
772
- ...config,
773
- role: 'end',
774
- pairId,
775
- startStepId: startStep.id,
776
- endStepId: id,
777
- },
778
- flow: { nodeKind: 'assertion' },
779
- };
780
- }
781
-
782
- function linkedScriptExitActivity(script: AppiumRecordedScript) {
783
- for (let index = script.steps.length - 1; index >= 0; index -= 1) {
784
- const activity = script.steps[index]?.pageAfter?.activity;
785
- if (activity) return activity;
786
- }
787
- return script.appActivity;
788
- }
789
-
790
- function expectedActivityAfterStep(index?: number) {
791
- const scriptActivity = selectedScript.value?.appActivity || form.appActivity || currentActivity.value;
792
- if (typeof index !== 'number' || index < 0) return scriptActivity;
793
-
794
- const previousStep = steps.value[index];
795
- if (!previousStep) return scriptActivity;
796
- if (previousStep.type === 'runScript') {
797
- const script = scripts.value.find((item) => item.id === previousStep.value);
798
- if (script) return linkedScriptExitActivity(script);
799
- }
800
- return previousStep.pageAfter?.activity || previousStep.pageBefore?.activity || scriptActivity;
801
- }
802
-
803
- function wait(ms: number) {
804
- return new Promise((resolve) => setTimeout(resolve, ms));
805
- }
806
-
807
- function treeSignature(root: AppiumNode | null) {
808
- return flattenNodes(root)
809
- .slice(0, 300)
810
- .map((node) => [
811
- node.resourceId,
812
- node.text,
813
- node.contentDesc,
814
- node.className,
815
- node.xpath,
816
- ].join('|'))
817
- .join('\n');
818
- }
819
-
820
- async function fetchTreePayload(forceFresh = false) {
821
- if (forceFresh && treeRequest) await treeRequest.catch(() => undefined);
822
- if (treeRequest) return treeRequest;
823
-
824
- const request = getAppiumTree(selectedDeviceId.value);
825
- treeRequest = request;
826
- try {
827
- return await request;
828
- } finally {
829
- if (treeRequest === request) treeRequest = null;
830
- }
831
- }
832
-
833
- function applyTreeSnapshot(payload: TreePayload, parsedTree: AppiumNode | null, clearSelection: boolean) {
834
- const previousSelection = clearSelection ? null : selectedNode.value;
835
- rawXml.value = payload.xml;
836
- currentActivity.value = payload.activity || '';
837
- tree.value = parsedTree;
838
- selectedNode.value = previousSelection
839
- ? flattenNodes(parsedTree).find((node) => (
840
- node.id === previousSelection.id || node.xpath === previousSelection.xpath
841
- )) || null
842
- : null;
843
- }
844
-
845
- function currentPageSnapshot(node = selectedNode.value) {
846
- return {
847
- activity: currentActivity.value,
848
- packageName: node?.packageName || '',
849
- treeSignature: treeSignature(tree.value),
850
- selectedNodePath: node?.xpath || '',
851
- };
852
- }
853
-
854
- function ensureAppPackageSelected() {
855
- if (hasSelectedAppPackage.value) return true;
856
- ElMessage.warning('请先从预设 App 参数中选择 App 包名');
857
- return false;
858
- }
859
-
860
- function getSelectedNode() {
861
- if (selectedNode.value) return selectedNode.value;
862
- ElMessage.warning('请先选择组件');
863
- return null;
864
- }
865
-
866
- async function loadTreeSnapshot(clearSelection = true, forceFresh = false) {
867
- const payload = await fetchTreePayload(forceFresh);
868
- const parsedTree = parseWindowHierarchy(payload.xml);
869
- applyTreeSnapshot(payload, parsedTree, clearSelection);
870
- return {
871
- activity: payload.activity || '',
872
- signature: treeSignature(parsedTree),
873
- tree: parsedTree,
874
- };
875
- }
876
-
877
- function stopAutoTreeRefresh() {
878
- if (autoTreeRefreshTimer === null) return;
879
- window.clearTimeout(autoTreeRefreshTimer);
880
- autoTreeRefreshTimer = null;
881
- }
882
-
883
- function scheduleAutoTreeRefresh(delay = AUTO_TREE_REFRESH_INTERVAL_MS) {
884
- stopAutoTreeRefresh();
885
- if (!props.active || !selectedDeviceId.value || replaying.value) return;
886
- autoTreeRefreshTimer = window.setTimeout(() => {
887
- autoTreeRefreshTimer = null;
888
- void syncTreeWhenPageChanges();
889
- }, delay);
890
- }
891
-
892
- async function pauseAutoTreeRefresh() {
893
- stopAutoTreeRefresh();
894
- const pendingRequest = treeRequest;
895
- if (pendingRequest) await pendingRequest.catch(() => undefined);
896
- await wait(300);
897
- }
898
-
899
- async function syncTreeWhenPageChanges() {
900
- if (
901
- autoTreeRefreshInFlight
902
- || loadingTree.value
903
- || recordingBusy.value
904
- || replaying.value
905
- || launchingApp.value
906
- ) {
907
- scheduleAutoTreeRefresh();
908
- return;
909
- }
910
-
911
- autoTreeRefreshInFlight = true;
912
- try {
913
- const payload = await fetchTreePayload();
914
- const changed = (payload.activity || '') !== currentActivity.value
915
- || payload.xml !== rawXml.value;
916
- if (changed) {
917
- applyTreeSnapshot(payload, parseWindowHierarchy(payload.xml), false);
918
- }
919
- } catch {
920
- // A transient ADB/UIAutomator failure should not interrupt recording.
921
- } finally {
922
- autoTreeRefreshInFlight = false;
923
- scheduleAutoTreeRefresh();
924
- }
925
- }
926
-
927
- async function loadScripts() {
928
- const payload = await getAppiumScripts();
929
- scripts.value = payload.scripts || [];
930
- if (selectedScriptId.value && !scripts.value.some((script) => script.id === selectedScriptId.value)) {
931
- selectedScriptId.value = '';
932
- }
933
- }
934
-
935
- async function switchDevice(deviceId: string) {
936
- stopAutoTreeRefresh();
937
- tree.value = null;
938
- selectedNode.value = null;
939
- currentActivity.value = '';
940
- await props.switchAndroidDevice(deviceId);
941
- }
942
-
943
- async function triggerDeviceKey(keyCode: number) {
944
- if (!selectedDeviceId.value) return;
945
- try {
946
- await props.triggerDeviceKey(keyCode);
947
- scheduleAutoTreeRefresh(500);
948
- } catch (error) {
949
- ElMessage.error(error instanceof Error ? error.message : '设备操作失败');
950
- }
951
- }
952
-
953
- async function refreshTree() {
954
- if (loadingTree.value || replaying.value) return;
955
- if (!selectedDeviceId.value) {
956
- ElMessage.warning('请选择设备');
957
- return;
958
- }
959
- loadingTree.value = true;
960
- try {
961
- await loadTreeSnapshot(true, true);
962
- props.refreshDevicePreview();
963
- } catch (error) {
964
- ElMessage.error(error instanceof Error ? error.message : '刷新组件树失败');
965
- } finally {
966
- loadingTree.value = false;
967
- }
968
- }
969
-
970
- async function executeFlowStep(index: number) {
971
- const step = steps.value[index];
972
- if (step?.type === 'aiRecognition') {
973
- if (replaying.value || recordingBusy.value) { ElMessage.warning('设备正在执行操作,请稍后测试'); return; }
974
- aiRecognitionTestStep.value = { ...step };
975
- return;
976
- }
977
- if (!step || (step.type !== 'launchApp' && step.type !== 'clearAppData')) return;
978
- if (launchingApp.value) return;
979
- if (!selectedDeviceId.value) {
980
- ElMessage.warning('请选择设备');
981
- return;
982
- }
983
- const packageName = step.value?.trim() || form.appPackage;
984
- if (!packageName || !props.appPresets.some((app) => app.packageName === packageName)) {
985
- ElMessage.warning('当前节点没有匹配的预设 App');
986
- return;
987
- }
988
-
989
- if (step.type === 'clearAppData') {
990
- const confirmed = await ElMessageBox.confirm(
991
- 'Android 将清除该 App 的全部数据和缓存,登录状态与本地设置也会被重置。',
992
- '确认清理 App 缓存',
993
- {
994
- confirmButtonText: '确认清理',
995
- cancelButtonText: '取消',
996
- type: 'warning',
997
- center: true,
998
- },
999
- ).catch(() => false);
1000
- if (!confirmed) return;
1001
- }
1002
-
1003
- launchingApp.value = true;
1004
- executingAppStepId.value = step.id;
1005
- try {
1006
- if (step.type === 'clearAppData') {
1007
- await clearAppiumDeviceAppData({ deviceId: selectedDeviceId.value, packageName });
1008
- } else {
1009
- await launchAppiumDeviceApp({ deviceId: selectedDeviceId.value, packageName });
1010
- }
1011
- props.refreshDevicePreview();
1012
- await wait(800);
1013
- await loadTreeSnapshot(true, true);
1014
- props.refreshDevicePreview();
1015
- if (step.type === 'clearAppData') {
1016
- ElMessage.success('App 数据与缓存已清理');
1017
- } else if (scriptActivityMismatch.value) {
1018
- ElMessage.warning(`App 已启动,当前页面仍为 ${currentActivity.value || '-'}`);
1019
- } else {
1020
- ElMessage.success('已进入脚本绑定页面');
1021
- }
1022
- } catch (error) {
1023
- ElMessage.error(error instanceof Error ? error.message : 'App 操作失败');
1024
- } finally {
1025
- launchingApp.value = false;
1026
- executingAppStepId.value = '';
1027
- }
1028
- }
1029
-
1030
- function selectNodeFromPoint(point: { x: number; y: number }) {
1031
- if (pickingCoordinate.value) {
1032
- coordinatePicker.select(point);
1033
- return;
1034
- }
1035
- const node = findSmallestNodeAtPoint(tree.value, point.x, point.y);
1036
- if (node) {
1037
- selectedNode.value = node;
1038
- workspaceRef.value?.showTree();
1039
- return;
1040
- }
1041
- ElMessage.warning('未命中组件树节点');
1042
- }
1043
-
1044
- async function swipePreview(gesture: {
1045
- startX: number;
1046
- startY: number;
1047
- endX: number;
1048
- endY: number;
1049
- duration: number;
1050
- }) {
1051
- if (recordingBusy.value || replaying.value) return;
1052
- if (!selectedDeviceId.value) return;
1053
- try {
1054
- await props.swipeDevice(
1055
- gesture.startX,
1056
- gesture.startY,
1057
- gesture.endX,
1058
- gesture.endY,
1059
- gesture.duration,
1060
- );
1061
- scheduleAutoTreeRefresh(500);
1062
- } catch (error) {
1063
- ElMessage.error(error instanceof Error ? error.message : '滑动失败');
1064
- }
1065
- }
1066
-
1067
- async function recordTapStep(index?: number, branchTarget?: BranchTarget) {
1068
- if (!selectedNode.value || recordingTap.value) return;
1069
- if (!ensureAppPackageSelected()) return;
1070
- if (!selectedDeviceId.value) {
1071
- ElMessage.warning('请选择设备');
1072
- return;
1073
- }
1074
- const node = selectedNode.value;
1075
- const bounds = node.bounds;
1076
- if (!bounds) {
1077
- ElMessage.warning('当前组件没有可点击坐标');
1078
- return;
1079
- }
1080
- const beforeActivity = currentActivity.value;
1081
- const step = createStep('tap', node);
1082
- const inserted = insertStep(step, index, branchTarget);
1083
- recordingTap.value = true;
1084
- try {
1085
- await tapAppiumDevice({ deviceId: selectedDeviceId.value, x: bounds.centerX, y: bounds.centerY });
1086
- await wait(1200);
1087
- const after = await loadTreeSnapshot(true, true);
1088
- steps.value = steps.value.map((item) => (
1089
- item.id === step.id ? { ...item, pageAfter: currentPageSnapshot() } : item
1090
- ));
1091
- const activityChanged = Boolean(beforeActivity && after.activity && beforeActivity !== after.activity);
1092
- if (activityChanged) {
1093
- pendingNavigation.value = {
1094
- beforeActivity,
1095
- afterActivity: after.activity,
1096
- };
1097
- return step;
1098
- }
1099
- ElMessage.success('已录制点击');
1100
- return step;
1101
- } catch (error) {
1102
- ElMessage.error(error instanceof Error ? error.message : '录制点击失败');
1103
- return undefined;
1104
- } finally {
1105
- recordingTap.value = false;
1106
- }
1107
- }
1108
-
1109
- async function addStep(type: NodeStepType, index?: number, branchTarget?: BranchTarget) {
1110
- if (recordingBusy.value) return;
1111
- if (!selectedNode.value) return;
1112
- if (!ensureAppPackageSelected()) return;
1113
- if (type === 'tap') {
1114
- return recordTapStep(index, branchTarget);
1115
- }
1116
- const step = createStep(type, selectedNode.value);
1117
- if (type === 'input') {
1118
- const input = await ElMessageBox.prompt('', '录制输入', {
1119
- inputValue: '',
1120
- confirmButtonText: '添加',
1121
- cancelButtonText: '取消',
1122
- center: true,
1123
- }).catch(() => null);
1124
- if (!input) return;
1125
- step.value = input.value;
1126
- }
1127
- return insertStep(step, index, branchTarget);
1128
- }
1129
-
1130
- async function addDelayStep(index?: number, branchTarget?: BranchTarget) {
1131
- if (recordingBusy.value) return;
1132
- const input = await ElMessageBox.prompt('请输入延时时间,单位毫秒', '添加延时', {
1133
- inputValue: '1000',
1134
- inputPattern: /^[1-9]\d{0,5}$/,
1135
- inputErrorMessage: '请输入 1 到 999999 之间的整数',
1136
- confirmButtonText: '添加',
1137
- cancelButtonText: '取消',
1138
- }).catch(() => null);
1139
- if (!input) return;
1140
- const timeoutMs = Number(input.value);
1141
- const step = createDelayStep(timeoutMs);
1142
- return insertStep(step, index, branchTarget);
1143
- }
1144
-
1145
- function toSwipeNumber(value: unknown, fallback: number) {
1146
- const number = Number(value);
1147
- return Number.isFinite(number) ? Math.round(number) : fallback;
1148
- }
1149
-
1150
- function patchSwipeForm(form: SwipeForm, key: keyof SwipeGesture, value: unknown) {
1151
- form[key] = toSwipeNumber(value, form[key]);
1152
- }
1153
-
1154
- function renderSwipeForm(form: SwipeForm) {
1155
- const coordinateInput = (label: string, key: keyof SwipeGesture, min = 0) => h(ElFormItem, { label }, () => h(ElInputNumber, {
1156
- modelValue: form[key],
1157
- min,
1158
- max: 99999,
1159
- precision: 0,
1160
- controlsPosition: 'right',
1161
- 'onUpdate:modelValue': (value: number | undefined) => patchSwipeForm(form, key, value),
1162
- }));
1163
-
1164
- return h(ElForm, { labelPosition: 'top', size: 'small', class: 'appium-swipe-dialog-form' }, () => [
1165
- h(ElFormItem, { label: '滑动方向' }, () => h(ElSelect, {
1166
- modelValue: form.direction,
1167
- 'onUpdate:modelValue': (value: string) => {
1168
- const preset = swipePreset(value);
1169
- form.direction = preset.direction;
1170
- Object.assign(form, preset.swipe);
1171
- },
1172
- }, () => [
1173
- h(ElOption, { label: '上滑', value: 'up' }),
1174
- h(ElOption, { label: '下滑', value: 'down' }),
1175
- h(ElOption, { label: '左滑', value: 'left' }),
1176
- h(ElOption, { label: '右滑', value: 'right' }),
1177
- ])),
1178
- h('div', { class: 'appium-swipe-dialog-grid' }, () => [
1179
- coordinateInput('起点 X', 'startX'),
1180
- coordinateInput('起点 Y', 'startY'),
1181
- coordinateInput('终点 X', 'endX'),
1182
- coordinateInput('终点 Y', 'endY'),
1183
- coordinateInput('时长 ms', 'duration', 80),
1184
- ]),
1185
- ]);
1186
- }
1187
-
1188
- async function addSwipeStep(index?: number, branchTarget?: BranchTarget) {
1189
- const preset = swipePreset('up');
1190
- const form = reactive<SwipeForm>({
1191
- direction: preset.direction,
1192
- ...preset.swipe,
1193
- });
1194
- const result = await ElMessageBox({
1195
- title: '添加滑动',
1196
- message: renderSwipeForm(form),
1197
- showCancelButton: true,
1198
- confirmButtonText: '添加',
1199
- cancelButtonText: '取消',
1200
- customClass: 'appium-swipe-message-box',
1201
- }).catch(() => null);
1202
- if (!result) return;
1203
- const finalPreset = swipePreset(form.direction);
1204
- return insertStep(createSwipeStep({
1205
- label: finalPreset.label,
1206
- swipe: {
1207
- startX: toSwipeNumber(form.startX, finalPreset.swipe.startX),
1208
- startY: toSwipeNumber(form.startY, finalPreset.swipe.startY),
1209
- endX: toSwipeNumber(form.endX, finalPreset.swipe.endX),
1210
- endY: toSwipeNumber(form.endY, finalPreset.swipe.endY),
1211
- duration: Math.max(80, toSwipeNumber(form.duration, finalPreset.swipe.duration)),
1212
- },
1213
- }), index, branchTarget);
1214
- }
1215
-
1216
- function openLinkedScriptDialog(index?: number, branchTarget?: BranchTarget) {
1217
- linkedScriptEditingId.value = '';
1218
- if (!linkableScripts.value.length) {
1219
- ElMessage.warning('暂无可连接的已保存脚本');
1220
- return;
1221
- }
1222
- linkedScriptBranchTarget.value = branchTarget || null;
1223
- linkedScriptExpectedActivity.value = expectedActivityAfterStep(index);
1224
- if (!compatibleLinkableScripts.value.length) {
1225
- ElMessage.warning('没有属于当前 App 的可连接脚本');
1226
- linkedScriptExpectedActivity.value = '';
1227
- linkedScriptBranchTarget.value = null;
1228
- return;
1229
- }
1230
- linkedScriptTargetId.value = compatibleLinkableScripts.value[0]?.id || '';
1231
- linkedParameters.parameters = [];
1232
- linkedParameters.returns = [];
1233
- linkedScriptInsertIndex.value = index;
1234
- linkedScriptDialogVisible.value = true;
1235
- }
1236
-
1237
- function addLinkedScriptStep() {
1238
- try { validateVariables(linkedParameters.parameters); validateReturns(linkedParameters.returns); }
1239
- catch (error) { ElMessage.error(String(error)); return; }
1240
- const script = scripts.value.find((item) => item.id === linkedScriptTargetId.value);
1241
- if (!script) {
1242
- ElMessage.warning('请选择要连接的脚本');
1243
- return;
1244
- }
1245
- if (script.appPackage !== form.appPackage) {
1246
- ElMessage.error('连接脚本必须属于当前 App');
1247
- return;
1248
- }
1249
- const editingIndex = linkedScriptEditingId.value ? steps.value.findIndex(step => step.id === linkedScriptEditingId.value) : -1;
1250
- if (linkedScriptEditingId.value && editingIndex < 0) { ElMessage.warning('原节点已删除,请重新打开'); return; }
1251
- if (editingIndex >= 0) {
1252
- const original = steps.value[editingIndex]!;
1253
- updateStep(editingIndex, { ...original, value: script.id,
1254
- ...(original.label.startsWith('连接脚本 ') ? { label: `连接脚本 ${script.name}` } : {}),
1255
- parameters: JSON.parse(JSON.stringify(linkedParameters.parameters || [])), returns: JSON.parse(JSON.stringify(linkedParameters.returns || [])) });
1256
- } else insertStep(
1257
- { ...createRunScriptStep(script), parameters: JSON.parse(JSON.stringify(linkedParameters.parameters || [])), returns: JSON.parse(JSON.stringify(linkedParameters.returns || [])) },
1258
- linkedScriptInsertIndex.value,
1259
- linkedScriptBranchTarget.value || undefined,
1260
- );
1261
- linkedScriptInsertIndex.value = undefined;
1262
- linkedScriptBranchTarget.value = null;
1263
- linkedScriptExpectedActivity.value = '';
1264
- linkedScriptDialogVisible.value = false;
1265
- ElMessage.success(editingIndex >= 0 ? '已修改连接脚本' : '已添加连接脚本步骤');
1266
- linkedScriptEditingId.value = '';
1267
- }
1268
-
1269
- function closeLinkedScriptDialog() {
1270
- linkedScriptEditingId.value = '';
1271
- linkedScriptDialogVisible.value = false;
1272
- linkedScriptInsertIndex.value = undefined;
1273
- linkedScriptBranchTarget.value = null;
1274
- linkedScriptExpectedActivity.value = '';
1275
- }
1276
-
1277
- function openLinkedScriptPreview(scriptId = linkedScriptTargetId.value) {
1278
- const script = scripts.value.find((item) => item.id === scriptId);
1279
- if (!script) {
1280
- ElMessage.warning('请选择要预览的脚本');
1281
- return;
1282
- }
1283
- linkedScriptPreviewScriptId.value = script.id;
1284
- linkedScriptPreviewResetToken.value += 1;
1285
- linkedScriptPreviewVisible.value = true;
1286
- }
1287
-
1288
- function previewLinkedScriptStep(index: number) {
1289
- openLinkedScriptPreview(steps.value[index]?.value || '');
1290
- }
1291
-
1292
- function loadPreviewScriptForEditing() {
1293
- if (!linkedScriptPreviewScript.value) return;
1294
- linkedScriptPreviewVisible.value = false;
1295
- linkedScriptDialogVisible.value = false;
1296
- loadScript(linkedScriptPreviewScript.value);
1297
- }
1298
-
1299
- function openVisualChangeDialog(index?: number, branchTarget?: BranchTarget) {
1300
- visualChangeInsertIndex.value = index;
1301
- visualChangeBranchTarget.value = branchTarget || null;
1302
- visualChangeConfig.value = currentVisualChangeConfig();
1303
- visualChangePicking.value = false;
1304
- visualChangeDialogVisible.value = true;
1305
- }
1306
-
1307
- function closeVisualChangeDialog() {
1308
- visualChangeDialogVisible.value = false;
1309
- visualChangePicking.value = false;
1310
- visualChangeInsertIndex.value = undefined;
1311
- visualChangeBranchTarget.value = null;
1312
- }
1313
-
1314
- function updateVisualChangeConfig(config: AppiumVisualChangeConfig) {
1315
- visualChangeConfig.value = normalizeVisualChangeConfig(config);
1316
- }
1317
-
1318
- function pickVisualChangeRegion() {
1319
- if (!selectedDeviceId.value) {
1320
- ElMessage.warning('请选择设备');
1321
- return;
1322
- }
1323
- visualChangeConfig.value = normalizeVisualChangeConfig({
1324
- ...visualChangeConfig.value,
1325
- mode: 'region',
1326
- });
1327
- visualChangePicking.value = true;
1328
- workspaceRef.value?.showPreview();
1329
- ElMessage.info('请在设备预览中拖拽框选检测区域');
1330
- }
1331
-
1332
- function applyVisualChangeRegion(region: AppiumVisualChangeRegion) {
1333
- if (imageCheckDraft.value?.imageCheck) {
1334
- updateImageCheck({ ...imageCheckDraft.value.imageCheck, region, screenWidth: props.deviceWidth || 0, screenHeight: props.deviceHeight || 0 });
1335
- imageCheckPicking.value = false;
1336
- return;
1337
- }
1338
- visualChangeConfig.value = normalizeVisualChangeConfig({
1339
- ...visualChangeConfig.value,
1340
- mode: 'region',
1341
- region,
1342
- });
1343
- visualChangePicking.value = false;
1344
- ElMessage.success('已选择检测区域');
1345
- }
1346
-
1347
- function confirmVisualChangeStep() {
1348
- const config = normalizeVisualChangeConfig(visualChangeConfig.value);
1349
- if (config.mode === 'selectedElement' && !selectedNode.value?.bounds) {
1350
- ElMessage.warning('当前没有可用的选中元素,请先选择组件或改为手动框选区域');
1351
- return;
1352
- }
1353
- const step = createVisualChangeStartStep(config);
1354
- insertStep(
1355
- step,
1356
- visualChangeInsertIndex.value,
1357
- visualChangeBranchTarget.value || undefined,
1358
- );
1359
- closeVisualChangeDialog();
1360
- ElMessage.success('已添加检测画面变化开始节点');
1361
- }
1362
-
1363
- function isReadonlyFlowActionDisabled(_action: InsertAction) {
1364
- return true;
1365
- }
1366
-
1367
- function isReadonlyFlowAppExecutionDisabled(_action: 'launchApp' | 'clearAppData') {
1368
- return true;
1369
- }
1370
-
1371
- function isReadonlyFlowCopySelected(_index: number) {
1372
- return false;
1373
- }
1374
-
1375
- function addSharedAction(action: RecorderAction, index: number, beforeStepId?: string) {
1376
- if (!beforeStepId) return addAction(action, index);
1377
- const target = steps.value.find(step => step.id === beforeStepId);
1378
- if (!target) return;
1379
- return addAction(action, index, { beforeStepId, stepId: target.flow?.parentConditionId || '', branch: target.flow?.parentBranch || 'yes' });
1380
- }
1381
-
1382
- async function addAction(
1383
- action: RecorderAction,
1384
- index?: number,
1385
- branchTarget?: BranchTarget,
1386
- ) {
1387
- if (recordingBusy.value) return;
1388
- if (!ensureAppPackageSelected()) return;
1389
- if (action === 'clearAppData' && steps.value.some((step) => step.type === 'clearAppData')) {
1390
- ElMessage.warning('清理 App 缓存节点只能添加一个');
1391
- return;
1392
- }
1393
- if (action === 'clearAppData' && index !== -1) {
1394
- ElMessage.warning('清理 App 缓存只能从开始节点添加');
1395
- return;
1396
- }
1397
- if (action === 'runScript') {
1398
- openLinkedScriptDialog(index, branchTarget);
1399
- return;
1400
- }
1401
- if (action === 'delay') {
1402
- return addDelayStep(index, branchTarget);
1403
- }
1404
- if (action === 'openGallery') {
1405
- return insertStep({ id: createStepId(), type: 'openGallery', label: '启动相册', flow: { nodeKind: 'action' } }, index, branchTarget);
1406
- }
1407
- if (action === 'endFlow') {
1408
- return insertStep({ id: createStepId(), type: 'endFlow', label: '终止流程', flow: { nodeKind: 'action' } }, index, branchTarget);
1409
- }
1410
- if (action === 'loop') {
1411
- const step = reactive<AppiumRecordedStep>({
1412
- id: createStepId(), type: 'loop', label: '有界循环', loop: defaultLoopConfig(),
1413
- selector: selectedNode.value?.selector ? { ...selectedNode.value.selector } : { strategy: 'id', value: '' },
1414
- flow: { nodeKind: 'condition' },
1415
- });
1416
- const result = await ElMessageBox({
1417
- title: '添加有界循环',
1418
- message: h(ElForm, { labelPosition: 'top' }, () => h(LoopSettings, { step, onUpdate: (patch) => Object.assign(step, patch) })),
1419
- showCancelButton: true, confirmButtonText: '添加', cancelButtonText: '取消',
1420
- beforeClose: (action, _instance, done) => {
1421
- if (action === 'confirm') {
1422
- try { validateLoop(step); } catch (error) { ElMessage.warning((error as Error).message); return; }
1423
- }
1424
- done();
1425
- },
1426
- }).catch(() => null);
1427
- if (result) return insertStep({ ...step, loop: { ...step.loop! }, selector: { ...step.selector! } }, index, branchTarget);
1428
- return;
1429
- }
1430
- if (action === 'breakLoop') {
1431
- const step: AppiumRecordedStep = { id: createStepId(), type: 'breakLoop', label: '退出循环', flow: { nodeKind: 'action' } };
1432
- const scoped = reactive(branchTarget ? stepWithBranchTarget(step, branchTarget) : step);
1433
- const loops = enclosingLoops(steps.value, scoped);
1434
- if (!loops.length) { ElMessage.warning('退出循环只能添加在循环体内'); return; }
1435
- scoped.breakLoopTargetId = loops[0]!.id;
1436
- const result = await ElMessageBox({
1437
- title: '添加退出循环',
1438
- message: h(ElForm, { labelPosition: 'top' }, () => h(BreakLoopSettings, { step: scoped, steps: steps.value, onUpdate: (patch) => Object.assign(scoped, patch) })),
1439
- showCancelButton: true, confirmButtonText: '添加', cancelButtonText: '取消',
1440
- beforeClose: (action, _instance, done) => {
1441
- if (action === 'confirm') {
1442
- try { breakLoopTarget(steps.value, scoped); } catch (error) { ElMessage.warning((error as Error).message); return; }
1443
- }
1444
- done();
1445
- },
1446
- }).catch(() => null);
1447
- if (result) return insertStep({ ...step, breakLoopTargetId: scoped.breakLoopTargetId }, index, branchTarget);
1448
- return;
1449
- }
1450
- if (action === 'continueLoop') {
1451
- const step: AppiumRecordedStep = { id: createStepId(), type: 'continueLoop', label: '继续下一次循环', flow: { nodeKind: 'action' } };
1452
- const scoped = reactive(branchTarget ? stepWithBranchTarget(step, branchTarget) : step);
1453
- const loops = enclosingLoops(steps.value, scoped);
1454
- if (!loops.length) { ElMessage.warning('继续下一次循环只能添加在循环体内'); return; }
1455
- scoped.continueLoopTargetId = loops[0]!.id;
1456
- const result = await ElMessageBox({
1457
- title: '添加继续下一次循环',
1458
- message: h(ElForm, { labelPosition: 'top' }, () => h(BreakLoopSettings, {
1459
- step: scoped,
1460
- steps: steps.value,
1461
- mode: 'continue',
1462
- onUpdate: (patch) => Object.assign(scoped, patch),
1463
- })),
1464
- showCancelButton: true, confirmButtonText: '添加', cancelButtonText: '取消',
1465
- beforeClose: (action, _instance, done) => {
1466
- if (action === 'confirm') {
1467
- try { continueLoopTarget(steps.value, scoped); } catch (error) { ElMessage.warning((error as Error).message); return; }
1468
- }
1469
- done();
1470
- },
1471
- }).catch(() => null);
1472
- if (result) return insertStep({ ...step, continueLoopTargetId: scoped.continueLoopTargetId }, index, branchTarget);
1473
- return;
1474
- }
1475
- if (action === 'imageCheck') {
1476
- imageCheckIndex = index;
1477
- imageCheckBranch = branchTarget;
1478
- imageCheckEditing = false;
1479
- imageCheckPicking.value = false;
1480
- imageCheckDraft.value = { id: createStepId(), type: 'imageCheck', label: '图像判断', flow: { nodeKind: 'condition' },
1481
- imageCheck: { ...createImageCheckConfig(), region: defaultVisualChangeRegion(), screenWidth: props.deviceWidth || 0, screenHeight: props.deviceHeight || 0 } };
1482
- if (selectedNode.value?.bounds) useImageCheckElement();
1483
- return;
1484
- }
1485
- if (action === 'aiRecognition') {
1486
- const draft = reactive({ value: '', error: '' });
1487
- const result = await ElMessageBox({
1488
- title: '添加 AI 识别',
1489
- message: () => h(ElForm, { labelPosition: 'top', style: { width: 'min(380px, calc(100vw - 64px))' } },
1490
- () => h(ElFormItem, { label: '识别内容', error: draft.error },
1491
- () => h(AiRecognitionPromptInput, {
1492
- modelValue: draft.value, presets: availableAiPromptPresets.value,
1493
- placeholder: '例如:检查当前画面有没有显示黑屏',
1494
- 'onUpdate:modelValue': (value: string) => { draft.value = value; draft.error = ''; },
1495
- }))),
1496
- showCancelButton: true, confirmButtonText: '添加', cancelButtonText: '取消',
1497
- beforeClose: (action, _instance, done) => {
1498
- if (action === 'confirm') {
1499
- try { draft.value = validateAiRecognitionPrompt(draft.value); }
1500
- catch (error) { draft.error = error instanceof Error ? error.message : '识别内容无效'; return; }
1501
- }
1502
- done();
1503
- },
1504
- }).catch(() => null);
1505
- if (!result) return;
1506
- return insertStep({ id: createStepId(), type: 'aiRecognition', label: 'AI 识别', value: draft.value, aiBranchEnabled: false, timeoutMs: DEFAULT_NODE_TIMEOUT_MS, flow: { nodeKind: 'action' } }, index, branchTarget);
1507
- }
1508
- if (action === 'textClick') {
1509
- const step = reactive<AppiumRecordedStep>({
1510
- id: createStepId(), type: 'textClick', label: '文字点击', value: '', timeoutMs: DEFAULT_NODE_TIMEOUT_MS,
1511
- flow: { nodeKind: 'condition', textMatch: 'exact' },
1512
- });
1513
- const result = await ElMessageBox({
1514
- title: '添加文字点击',
1515
- message: h(ElForm, { labelPosition: 'top', style: { width: 'min(380px, calc(100vw - 64px))' } },
1516
- () => h(TextClickSettings, { step, onUpdate: (patch) => Object.assign(step, patch) })),
1517
- showCancelButton: true, confirmButtonText: '添加', cancelButtonText: '取消',
1518
- beforeClose: (action, _instance, done) => {
1519
- if (action === 'confirm') {
1520
- try { textClickSelector(step); }
1521
- catch (error) { ElMessage.warning((error as Error).message); return; }
1522
- }
1523
- done();
1524
- },
1525
- }).catch(() => null);
1526
- if (result) return insertStep({ ...step }, index, branchTarget);
1527
- return;
1528
- }
1529
- if (action === 'tap' || action === 'input' || action === 'waitFor') {
1530
- return addStep(action, index, branchTarget);
1531
- }
1532
- if (action === 'keyBack') {
1533
- return insertStep(createKeyStep(4, '系统返回'), index, branchTarget);
1534
- }
1535
- if (action === 'keyHome') {
1536
- return insertStep(createKeyStep(3, 'Home 键'), index, branchTarget);
1537
- }
1538
- if (action === 'keyRecent') {
1539
- return insertStep(createKeyStep(187, '最近任务'), index, branchTarget);
1540
- }
1541
- if (action === 'keyPower') {
1542
- return insertStep(createKeyStep(26, '电源键'), index, branchTarget);
1543
- }
1544
- if (action === 'waitActivity') {
1545
- const input = await ElMessageBox.prompt('请输入目标 Activity', '等待 Activity', {
1546
- inputValue: currentActivity.value,
1547
- confirmButtonText: '添加',
1548
- cancelButtonText: '取消',
1549
- }).catch(() => null);
1550
- if (input?.value) return insertStep(createWaitActivityStep(input.value), index, branchTarget);
1551
- return;
1552
- }
1553
- if (action === 'swipe') {
1554
- return addSwipeStep(index, branchTarget);
1555
- }
1556
- if (action === 'visualChange' || action === 'visualChangeStart') {
1557
- openVisualChangeDialog(index, branchTarget);
1558
- return;
1559
- }
1560
- if (action === 'visualChangeEnd') {
1561
- const candidates = findOpenVisualChangeStarts(steps.value, index, branchTarget);
1562
- if (!candidates.length) {
1563
- ElMessage.warning('当前分支没有可对应的检测画面变化开始节点');
1564
- return;
1565
- }
1566
- let selectedId = candidates.length === 1 ? candidates[0].id : '';
1567
- if (candidates.length > 1) {
1568
- selectedId = await new Promise<string>((resolve) => { void ElMessageBox({
1569
- title: '选择要结束的画面变化检测',
1570
- showConfirmButton: false,
1571
- showCancelButton: false,
1572
- callback: () => resolve(''),
1573
- message: h(VisualChangeEndPicker, {
1574
- candidates: candidates.map(step => ({ id: step.id, label: step.visualChange?.pairLabel || step.label, number: steps.value.findIndex(item => item.id === step.id) + 1 })),
1575
- onSelect: (id: string) => { resolve(id); ElMessageBox.close(); },
1576
- }),
1577
- }); });
1578
- if (!selectedId) return;
1579
- }
1580
- // 选择期间流程可能发生变化;插入前重新检查配对,不能使用过期候选。
1581
- const startStep = findOpenVisualChangeStarts(steps.value, index, branchTarget).find(step => step.id === selectedId);
1582
- if (!startStep) {
1583
- ElMessage.warning('该开始节点已结束或不再属于当前路径,请重新选择');
1584
- return;
1585
- }
1586
- const inserted = insertStep(createVisualChangeEndStep(startStep), index, branchTarget);
1587
- ElMessage.success(`已添加 ${inserted.label}`);
1588
- return inserted;
1589
- }
1590
- if (action === 'pinch') {
1591
- const input = await ElMessageBox.prompt('请输入缩放方向:放大 / 缩小', '添加双指缩放', {
1592
- inputValue: '放大',
1593
- inputPattern: /^(放大|缩小|out|in)$/,
1594
- inputErrorMessage: '只能输入 放大 或 缩小',
1595
- confirmButtonText: '添加',
1596
- cancelButtonText: '取消',
1597
- }).catch(() => null);
1598
- if (!input?.value) return;
1599
- const direction = input.value === '缩小' || input.value === 'in' ? 'in' : 'out';
1600
- return insertStep({
1601
- id: `step_${Date.now().toString(36)}_${Math.random().toString(36).slice(2, 8)}`,
1602
- type: 'pinch',
1603
- label: direction === 'out' ? '双指放大' : '双指缩小',
1604
- pinch: {
1605
- direction,
1606
- centerX: Math.round((props.deviceWidth || 1080) / 2),
1607
- centerY: Math.round((props.deviceHeight || 1920) / 2),
1608
- percent: 0.5,
1609
- },
1610
- }, index, branchTarget);
1611
- }
1612
- if (action === 'noop') {
1613
- return insertStep(createNoopStep(), index, branchTarget);
1614
- }
1615
- if (action === 'log') {
1616
- const step = reactive<AppiumRecordedStep>({
1617
- id: createStepId(), type: 'log', label: '输出日志', logPrefix: DEFAULT_LOG_PREFIX, value: '',
1618
- });
1619
- const result = await ElMessageBox({
1620
- title: '添加输出日志',
1621
- message: h(ElForm, { labelPosition: 'top', style: { width: 'min(380px, calc(100vw - 64px))' } }, () => h(StageLogSettings, {
1622
- step, onUpdate: (patch) => Object.assign(step, patch),
1623
- })),
1624
- showCancelButton: true, confirmButtonText: '添加', cancelButtonText: '取消',
1625
- beforeClose: (action, _instance, done) => {
1626
- const error = action === 'confirm' ? validateStageLog(step) : '';
1627
- if (error) { ElMessage.warning(error); return; }
1628
- done();
1629
- },
1630
- }).catch(() => null);
1631
- if (result) return insertStep({ ...step }, index, branchTarget);
1632
- return;
1633
- }
1634
- if (action === 'randomValue') {
1635
- const step = reactive<AppiumRecordedStep>(pendingRandomValue.value?.step || {
1636
- id: createStepId(), type: 'randomValue', label: '获取随机值', randomValue: { ...defaultRandomValue(), name: '' }, flow: { nodeKind: 'action' },
1637
- });
1638
- pendingRandomValue.value = null;
1639
- const dialogPresets: VariablePresetContext = { ...variablePresets, open: () => {
1640
- pendingRandomValue.value = { step: JSON.parse(JSON.stringify(step)), index, branchTarget };
1641
- ElMessageBox.close();
1642
- variablePresets.open();
1643
- } };
1644
- const result = await ElMessageBox({
1645
- title: '添加获取随机值',
1646
- message: h(ElForm, { labelPosition: 'top', style: { width: 'min(380px, calc(100vw - 64px))', maxHeight: '65vh', overflowY: 'auto', paddingRight: '4px' } }, () => h(RandomValueSettings, {
1647
- step, presets: dialogPresets, onUpdate: patch => Object.assign(step, patch),
1648
- })),
1649
- showCancelButton: true, confirmButtonText: '添加', cancelButtonText: '取消',
1650
- beforeClose: (action, _instance, done) => {
1651
- if (action === 'confirm') {
1652
- try {
1653
- validateRandomValueTarget(step);
1654
- validateRandomValue(step.randomValue);
1655
- if (availableVariablePresets.value.some(variable => variable.name === step.randomValue!.name && variable.sensitive)) step.randomValue!.sensitive = true;
1656
- } catch (error) { ElMessage.warning(error instanceof Error ? error.message : '随机值配置无效'); return; }
1657
- }
1658
- done();
1659
- },
1660
- }).catch(() => null);
1661
- if (result) return insertStep(JSON.parse(JSON.stringify(step)), index, branchTarget);
1662
- return;
1663
- }
1664
- if (action === 'launchApp') {
1665
- return insertStep({
1666
- id: `step_${Date.now().toString(36)}_${Math.random().toString(36).slice(2, 8)}`,
1667
- type: 'launchApp',
1668
- label: `启动 APP ${form.appPackage}`,
1669
- value: form.appPackage,
1670
- }, index, branchTarget);
1671
- }
1672
- if (action === 'stopApp') {
1673
- return insertStep({ id: createStepId(), type: 'stopApp', label: `杀死 APP ${form.appPackage}`,
1674
- value: form.appPackage, flow: { nodeKind: 'action' } }, index, branchTarget);
1675
- }
1676
- if (action === 'clearAppData') {
1677
- return insertStep({
1678
- id: `step_${Date.now().toString(36)}_${Math.random().toString(36).slice(2, 8)}`,
1679
- type: 'clearAppData',
1680
- label: `清理 APP 缓存(含数据)${form.appPackage}`,
1681
- value: form.appPackage,
1682
- }, index);
1683
- }
1684
- const node = getSelectedNode();
1685
- if (!node) return;
1686
- if (action === 'extractVariable') {
1687
- const step = reactive<AppiumRecordedStep>({ ...createNodeActionStep('extractVariable', '提取变量', node), extractVariable: { name: '', attribute: 'text', sensitive: false }, flow: { nodeKind: 'action' } });
1688
- const result = await ElMessageBox({
1689
- title: '提取组件到变量',
1690
- message: h(ElForm, { labelPosition: 'top' }, () => h(VariableExtractionSettings, { step, onUpdate: patch => Object.assign(step, patch) })),
1691
- showCancelButton: true, confirmButtonText: '添加', cancelButtonText: '取消',
1692
- beforeClose: (action, _instance, done) => {
1693
- if (action === 'confirm') {
1694
- try { validateExtraction(step.extractVariable); } catch (error) { ElMessage.error(String(error)); return; }
1695
- }
1696
- done();
1697
- },
1698
- }).catch(() => null);
1699
- if (result) return insertStep(JSON.parse(JSON.stringify(step)), index, branchTarget);
1700
- return;
1701
- }
1702
- if (action === 'checkboxState' || action === 'radioButtonState' || action === 'checkedState') {
1703
- const controlName = nativeControlName(action);
1704
- if (!matchesNativeControl(action, node.className) || node.checkable !== true) {
1705
- ElMessage.warning(`请选择原生 ${controlName} 元素,当前选中:${node.className || '未知类型'}`);
1706
- return;
1707
- }
1708
- const step = createNodeActionStep(action, action === 'checkedState' ? '判断勾选' : `判断 ${controlName} 状态`, node, { timeoutMs: DEFAULT_NODE_TIMEOUT_MS });
1709
- if ((!step.selector?.value || step.selector.strategy === 'bounds') && node.xpath) {
1710
- step.selector = { strategy: 'xpath', value: node.xpath };
1711
- step.contextSelector = undefined;
1712
- step.selectorChain = undefined;
1713
- }
1714
- if (!step.selector?.value || step.selector.strategy === 'bounds') {
1715
- ElMessage.warning(`当前 ${controlName} 没有可用的元素定位器`);
1716
- return;
1717
- }
1718
- // 只保存定位信息,回放时读取实时状态;坐标不能用于判断元素属性。
1719
- step.fallback = undefined;
1720
- step.flow = { nodeKind: 'condition' };
1721
- return insertStep(step, index, branchTarget);
1722
- }
1723
- if (action === 'popupCondition') {
1724
- const step = createNodeActionStep('assertExists', '判断存在', node, { timeoutMs: DEFAULT_NODE_TIMEOUT_MS });
1725
- const inserted = insertStep({ ...step, flow: { nodeKind: 'condition' } }, index, branchTarget);
1726
- ElMessage.success('已添加判断节点,请在节点面板配置是/否分支');
1727
- return inserted;
1728
- }
1729
- if (action === 'tapIfExists') {
1730
- return insertStep(createNodeActionStep('tapIfExists', '存在则点击', node, { timeoutMs: DEFAULT_NODE_TIMEOUT_MS }), index, branchTarget);
1731
- }
1732
- if (action === 'inputIfExists') {
1733
- const input = await ElMessageBox.prompt('', '存在则输入', {
1734
- inputValue: '',
1735
- confirmButtonText: '添加',
1736
- cancelButtonText: '取消',
1737
- center: true,
1738
- }).catch(() => null);
1739
- if (!input) return;
1740
- return insertStep(
1741
- createNodeActionStep('inputIfExists', '存在则输入', node, { timeoutMs: DEFAULT_NODE_TIMEOUT_MS, value: input.value }),
1742
- index,
1743
- branchTarget,
1744
- );
1745
- }
1746
- if (action === 'clearIfExists') {
1747
- return insertStep(createNodeActionStep('clearIfExists', '存在则清空', node, { timeoutMs: DEFAULT_NODE_TIMEOUT_MS }), index, branchTarget);
1748
- }
1749
- if (action === 'backIfExists') {
1750
- return insertStep(createNodeActionStep('backIfExists', '存在则返回', node, { timeoutMs: DEFAULT_NODE_TIMEOUT_MS }), index, branchTarget);
1751
- }
1752
- if (action === 'clearInput') {
1753
- return insertStep(createNodeActionStep('clearInput', '清空输入', node), index, branchTarget);
1754
- }
1755
- if (action === 'coordinateTap') {
1756
- if (!node.bounds) {
1757
- ElMessage.warning('当前组件没有可点击坐标');
1758
- return;
1759
- }
1760
- return insertStep({
1761
- id: `step_${Date.now().toString(36)}_${Math.random().toString(36).slice(2, 8)}`,
1762
- type: 'coordinateTap',
1763
- label: `点击坐标 ${node.bounds.centerX},${node.bounds.centerY}`,
1764
- fallback: { strategy: 'bounds', centerX: node.bounds.centerX, centerY: node.bounds.centerY },
1765
- }, index, branchTarget);
1766
- }
1767
- if (action === 'longPress') {
1768
- const step = reactive<AppiumRecordedStep>({
1769
- ...createNodeActionStep('longPress', '长按', node, { timeoutMs: 800 }),
1770
- longPressMode: 'element',
1771
- });
1772
- // 无 id/text 的组件仍可用组件树中的绝对 XPath 定位,不依赖录制坐标。
1773
- if ((!step.selector?.value || step.selector.strategy === 'bounds') && node.xpath) {
1774
- step.selector = { strategy: 'xpath', value: node.xpath };
1775
- step.contextSelector = undefined;
1776
- step.selectorChain = undefined;
1777
- }
1778
- const result = await ElMessageBox({
1779
- title: '添加长按',
1780
- message: h(ElForm, { labelPosition: 'top', size: 'small' }, () => [
1781
- h(ElFormItem, { label: '当前元素' }, () => h('div', { style: { overflowWrap: 'anywhere' } }, node.label)),
1782
- h(LongPressSettings, { step, onUpdate: (patch) => Object.assign(step, patch) }),
1783
- ]),
1784
- showCancelButton: true,
1785
- confirmButtonText: '添加',
1786
- cancelButtonText: '取消',
1787
- beforeClose: (action, _instance, done) => {
1788
- const error = action === 'confirm' ? validateLongPress(step) : '';
1789
- if (error) { ElMessage.warning(error); return; }
1790
- done();
1791
- },
1792
- }).catch(() => null);
1793
- if (!result) return;
1794
- return insertStep({ ...step }, index, branchTarget);
1795
- }
1796
- if (action === 'waitDisappear') {
1797
- return insertStep(createNodeActionStep('waitDisappear', '等待元素消失', node, { timeoutMs: DEFAULT_NODE_TIMEOUT_MS }), index, branchTarget);
1798
- }
1799
- }
1800
-
1801
- async function addBranchAction(index: number, branch: BranchName, action: RecorderAction) {
1802
- const context = branchContextForInsert(index, branch);
1803
- if (!context) return;
1804
- const { condition, conditionIndex } = context;
1805
- const existingBranchSteps = steps.value.filter((step) => (
1806
- step.flow?.parentConditionId === condition.id && step.flow.parentBranch === branch
1807
- ));
1808
- const currentTargetId = branch === 'yes' ? condition.flow?.yesTargetId : condition.flow?.noTargetId;
1809
- const currentTarget = steps.value.find((step) => step.id === currentTargetId);
1810
- const targetIsBranchStep = currentTarget?.flow?.parentConditionId === condition.id
1811
- && currentTarget.flow.parentBranch === branch;
1812
- const insertAtBranchEntry = index === conditionIndex;
1813
- const insertIndex = insertAtBranchEntry ? conditionIndex : index;
1814
- const nextTargetId = insertAtBranchEntry
1815
- ? nextBranchStepAfter(condition.id, branch, index)?.id || (!targetIsBranchStep ? currentTargetId : undefined)
1816
- : undefined;
1817
- const branchTarget: BranchTarget = {
1818
- stepId: condition.id,
1819
- branch,
1820
- updateTarget: insertAtBranchEntry || !currentTargetId || !targetIsBranchStep,
1821
- entryTargetId: insertAtBranchEntry ? undefined : existingBranchSteps[0]?.id,
1822
- nextTargetId,
1823
- };
1824
- const inserted = await addAction(action, insertIndex, branchTarget);
1825
- if (!inserted) return;
1826
- const currentInserted = steps.value.find((step) => step.id === inserted.id);
1827
- if (currentInserted?.flow?.parentConditionId === condition.id && currentInserted.flow.parentBranch === branch) return;
1828
- applyBranchTargetToInsertedStep(inserted, branchTarget);
1829
- }
1830
-
1831
- function continueOnActivityChange() {
1832
- if (!pendingNavigation.value || resolvingNavigation.value) return;
1833
- // 跨页面继续录制时,入口仍是首次录制页面,不能改成跳转后的页面。
1834
- form.appActivity ||= pendingNavigation.value.beforeActivity;
1835
- pendingNavigation.value = null;
1836
- ElMessage.success('已继续录制,后续操作将加入当前脚本');
1837
- }
1838
-
1839
- async function saveOnActivityChange() {
1840
- const pending = pendingNavigation.value;
1841
- if (!pending || resolvingNavigation.value) return;
1842
- if (!ensureAppPackageSelected()) return;
1843
- resolvingNavigation.value = true;
1844
- const activityName = (pending.beforeActivity || 'Activity').split(/[/.]/).filter(Boolean).pop() || 'Activity';
1845
- const scriptName = form.name.trim() || `${activityName}-${Date.now().toString(36).slice(-4)}`;
1846
- try {
1847
- const payload = await saveAppiumScript({
1848
- id: selectedScriptId.value || undefined,
1849
- name: scriptName,
1850
- appPackage: form.appPackage,
1851
- appActivity: form.appActivity || pending.beforeActivity,
1852
- deviceId: selectedDeviceId.value,
1853
- steps: steps.value,
1854
- variables: scriptVariables.value,
1855
- });
1856
- await loadScripts();
1857
- pendingNavigation.value = null;
1858
- resetCurrentScript();
1859
- form.appActivity = pending.afterActivity;
1860
- markDraftSaved();
1861
- ElMessage.success(`脚本「${payload.script.name}」已保存,可开始录制新 Activity`);
1862
- } catch (error) {
1863
- ElMessage.error(error instanceof Error ? error.message : '保存脚本失败');
1864
- } finally {
1865
- resolvingNavigation.value = false;
1866
- }
1867
- }
1868
-
1869
- function removeStep(index: number) {
1870
- if (recordingBusy.value) return;
1871
- steps.value = removeFlowStep(steps.value, index);
1872
- }
1873
-
1874
- function syncVisualChangePairConfig(
1875
- candidate: AppiumRecordedStep,
1876
- sourceConfig: NonNullable<AppiumRecordedStep['visualChange']>,
1877
- ) {
1878
- if (candidate.visualChange?.role !== 'end') return candidate;
1879
- if (!sourceConfig.pairId || candidate.visualChange.pairId !== sourceConfig.pairId) return candidate;
1880
- return {
1881
- ...candidate,
1882
- visualChange: {
1883
- ...candidate.visualChange,
1884
- mode: sourceConfig.mode,
1885
- region: sourceConfig.region,
1886
- pairLabel: sourceConfig.pairLabel,
1887
- durationMs: sourceConfig.durationMs,
1888
- intervalMs: sourceConfig.intervalMs,
1889
- changeRatioThreshold: sourceConfig.changeRatioThreshold,
1890
- pixelmatchThreshold: sourceConfig.pixelmatchThreshold,
1891
- },
1892
- };
1893
- }
1894
-
1895
- function updateStep(index: number, step: AppiumRecordedStep) {
1896
- if (recordingLocked.value) return;
1897
- const visualChange = step.visualChange?.role === 'start'
1898
- ? normalizeVisualChangeConfig(step.visualChange)
1899
- : undefined;
1900
- const nextSteps = steps.value.map((candidate, stepIndex) => (
1901
- stepIndex === index
1902
- ? step
1903
- : visualChange
1904
- ? syncVisualChangePairConfig(candidate, visualChange)
1905
- : candidate
1906
- ));
1907
- steps.value = syncVisualChangeThreshold(nextSteps, step);
1908
- }
1909
-
1910
- async function editInputStep(index: number) {
1911
- const step = steps.value[index];
1912
- if (step?.type === 'runScript' && !recordingBusy.value) {
1913
- const parentId = step.flow?.parentConditionId;
1914
- openLinkedScriptDialog(index - 1, parentId && step.flow?.parentBranch ? { stepId: parentId, branch: step.flow.parentBranch } : undefined);
1915
- if (!linkedScriptDialogVisible.value) return;
1916
- linkedScriptEditingId.value = step.id;
1917
- linkedScriptTargetId.value = step.value || '';
1918
- linkedParameters.parameters = JSON.parse(JSON.stringify(step.parameters || []));
1919
- linkedParameters.returns = JSON.parse(JSON.stringify(step.returns || []));
1920
- return;
1921
- }
1922
- if (step?.type === 'imageCheck' && !recordingBusy.value) {
1923
- imageCheckIndex = index;
1924
- imageCheckEditing = true;
1925
- imageCheckPicking.value = false;
1926
- imageCheckDraft.value = JSON.parse(JSON.stringify(step));
1927
- return;
1928
- }
1929
- if (!step || (step.type !== 'input' && step.type !== 'inputIfExists') || recordingBusy.value) return;
1930
- const input = await ElMessageBox.prompt('', '修改输入内容', {
1931
- inputValue: step.value || '',
1932
- confirmButtonText: '保存',
1933
- cancelButtonText: '取消',
1934
- center: true,
1935
- }).catch(() => null);
1936
- if (!input) return;
1937
- const nextSteps = [...steps.value];
1938
- nextSteps[index] = { ...step, value: input.value };
1939
- steps.value = nextSteps;
1940
- }
1941
-
1942
- function setActiveWorkbenchTab(tab: string | number) {
1943
- const nextTab = tab === 'scripts' ? 'scripts' : tab === 'variables' ? 'variables' : 'recording';
1944
- activeWorkbenchTab.value = nextTab;
1945
- window.localStorage.setItem(WORKBENCH_TAB_STORAGE_KEY, nextTab);
1946
- }
1947
-
1948
- function loadScript(script: AppiumRecordedScript) {
1949
- pendingRandomValue.value = null;
1950
- setActiveWorkbenchTab('recording');
1951
- flowClipboard.value = null;
1952
- selectedScriptId.value = script.id;
1953
- form.name = script.name;
1954
- form.appPackage = script.appPackage;
1955
- form.appActivity = script.appActivity;
1956
- scriptVariables.value = JSON.parse(JSON.stringify(script.variables || []));
1957
- if (script.deviceId && script.deviceId !== selectedDeviceId.value) {
1958
- void switchDevice(script.deviceId);
1959
- }
1960
- steps.value = normalizeLegacyNestedConditionBranches((script.steps || []).map(normalizeLegacyFlowScope));
1961
- markDraftSaved();
1962
- void nextTick(() => recordedStepsRef.value?.resetMainFlowPosition());
1963
- }
1964
-
1965
- function loadSelectedScript() {
1966
- if (selectedScript.value) {
1967
- loadScript(selectedScript.value);
1968
- return;
1969
- }
1970
- resetCurrentScript();
1971
- }
1972
-
1973
- function resetCurrentScript() {
1974
- pendingRandomValue.value = null;
1975
- void saveVariables('/api/appium-recorder/variables?draft=1', []).catch(() => ElMessage.error('变量草稿清理失败'));
1976
- scriptVariables.value = [];
1977
- flowClipboard.value = null;
1978
- selectedScriptId.value = '';
1979
- form.name = '';
1980
- form.appActivity = '';
1981
- steps.value = [];
1982
- replayOutput.value = '';
1983
- markDraftSaved();
1984
- }
1985
-
1986
- function requestNewScript() {
1987
- if (newScriptDisabled.value) return;
1988
- if (selectedScriptId.value || form.name.trim() || steps.value.length || scriptVariables.value.length) {
1989
- newScriptDialogVisible.value = true;
1990
- return;
1991
- }
1992
- startNewScript();
1993
- }
1994
-
1995
- function startNewScript() {
1996
- if (newScriptDisabled.value) return;
1997
- resetCurrentScript();
1998
- // 新脚本不沿用旧画布的展开、批量选择和缩放状态。
1999
- newScriptRevision.value += 1;
2000
- newScriptDialogVisible.value = false;
2001
- setActiveWorkbenchTab('recording');
2002
- }
2003
-
2004
- async function saveAndNewScript() {
2005
- if (newScriptDisabled.value) return;
2006
- // 保存成功后才重置,校验错误或网络异常均保留当前草稿。
2007
- if (await saveScript()) startNewScript();
2008
- }
2009
-
2010
- function formatScriptTime(value: string) {
2011
- if (!value) return '-';
2012
- const date = new Date(value);
2013
- return Number.isNaN(date.getTime()) ? '-' : date.toLocaleString();
2014
- }
2015
-
2016
- function cloneScriptSteps(stepList: AppiumRecordedStep[]) {
2017
- return JSON.parse(JSON.stringify(stepList || [])) as AppiumRecordedStep[];
2018
- }
2019
-
2020
- function isScriptNameTaken(name: string, exceptId = '') {
2021
- return scripts.value.some((script) => script.id !== exceptId && script.name === name);
2022
- }
2023
-
2024
- function createDuplicateScriptName(sourceName: string) {
2025
- const baseName = `${sourceName} Copy`;
2026
- if (!isScriptNameTaken(baseName)) return baseName;
2027
-
2028
- let suffix = 2;
2029
- let nextName = `${baseName} ${suffix}`;
2030
- while (isScriptNameTaken(nextName)) {
2031
- suffix += 1;
2032
- nextName = `${baseName} ${suffix}`;
2033
- }
2034
- return nextName;
2035
- }
2036
-
2037
- async function duplicateScript(script: AppiumRecordedScript) {
2038
- if (duplicatingScriptId.value) return;
2039
- duplicatingScriptId.value = script.id;
2040
- try {
2041
- const payload = await saveAppiumScript({
2042
- name: createDuplicateScriptName(script.name),
2043
- variables: script.variables || [],
2044
- appPackage: script.appPackage,
2045
- appActivity: script.appActivity,
2046
- deviceId: script.deviceId,
2047
- steps: cloneScriptSteps(script.steps),
2048
- });
2049
- await loadScripts();
2050
- ElMessage.success(`已复制为「${payload.script.name}」`);
2051
- } catch (error) {
2052
- ElMessage.error(error instanceof Error ? error.message : '复制脚本失败');
2053
- } finally {
2054
- duplicatingScriptId.value = '';
2055
- }
2056
- }
2057
-
2058
- async function renameScript(script: AppiumRecordedScript) {
2059
- if (renamingScriptId.value) return;
2060
- const input = await ElMessageBox.prompt('请输入新的脚本名称', '修改脚本名称', {
2061
- inputValue: script.name,
2062
- confirmButtonText: '保存',
2063
- cancelButtonText: '取消',
2064
- center: true,
2065
- inputValidator(value) {
2066
- const nextName = String(value || '').trim();
2067
- if (!nextName) return '脚本名称不能为空';
2068
- if (isScriptNameTaken(nextName, script.id)) return '脚本名称已存在';
2069
- return true;
2070
- },
2071
- }).catch(() => null);
2072
- const nextName = input ? String(input.value || '').trim() : '';
2073
- if (!nextName || nextName === script.name) return;
2074
-
2075
- const wasCurrentScript = selectedScriptId.value === script.id;
2076
- const hadUnsavedChanges = hasUnsavedChanges.value;
2077
- renamingScriptId.value = script.id;
2078
- try {
2079
- const payload = await saveAppiumScript({
2080
- id: script.id,
2081
- name: nextName,
2082
- appPackage: script.appPackage,
2083
- appActivity: script.appActivity,
2084
- deviceId: script.deviceId,
2085
- steps: cloneScriptSteps(script.steps),
2086
- });
2087
- await loadScripts();
2088
- if (wasCurrentScript) {
2089
- form.name = payload.script.name;
2090
- if (!hadUnsavedChanges) {
2091
- markDraftSaved();
2092
- }
2093
- }
2094
- ElMessage.success('脚本名称已修改');
2095
- } catch (error) {
2096
- ElMessage.error(error instanceof Error ? error.message : '修改脚本名称失败');
2097
- } finally {
2098
- renamingScriptId.value = '';
2099
- }
2100
- }
2101
-
2102
- async function removeScript(script: AppiumRecordedScript) {
2103
- try {
2104
- await ElMessageBox.confirm(`确定删除脚本「${script.name}」吗?`, '删除脚本', {
2105
- confirmButtonText: '删除',
2106
- cancelButtonText: '取消',
2107
- type: 'warning',
2108
- confirmButtonClass: 'el-button--danger',
2109
- });
2110
- } catch {
2111
- return;
2112
- }
2113
-
2114
- deletingScriptId.value = script.id;
2115
- const wasCurrent = selectedScriptId.value === script.id;
2116
- try {
2117
- await deleteAppiumScript(script.id);
2118
- await loadScripts();
2119
- if (wasCurrent) {
2120
- resetCurrentScript();
2121
- }
2122
- ElMessage.success('脚本已删除');
2123
- } catch (error) {
2124
- ElMessage.error(error instanceof Error ? error.message : '删除脚本失败');
2125
- } finally {
2126
- deletingScriptId.value = '';
2127
- }
2128
- }
2129
-
2130
- async function downloadScript(script: AppiumRecordedScript) {
2131
- if (downloadingScriptId.value) return;
2132
- downloadingScriptId.value = script.id;
2133
- try {
2134
- const { blob, fileName } = await downloadAppiumScript(script.id);
2135
- const url = URL.createObjectURL(blob);
2136
- const link = document.createElement('a');
2137
- link.href = url;
2138
- link.download = fileName;
2139
- document.body.appendChild(link);
2140
- link.click();
2141
- link.remove();
2142
- window.setTimeout(() => URL.revokeObjectURL(url), 1000);
2143
- } catch (error) {
2144
- ElMessage.error(error instanceof Error ? error.message : '导出脚本失败');
2145
- } finally {
2146
- downloadingScriptId.value = '';
2147
- }
2148
- }
2149
-
2150
- function chooseScriptImportFile() {
2151
- if (importingScript.value) return;
2152
- scriptImportInput.value?.click();
2153
- }
2154
-
2155
- async function importScriptFile(event: Event) {
2156
- const input = event.currentTarget as HTMLInputElement;
2157
- const files = Array.from(input.files || []);
2158
- input.value = '';
2159
- if (!files.length) return;
2160
- importingScript.value = true;
2161
-
2162
- const importedScripts: AppiumRecordedScript[] = [];
2163
- const failedFiles: Array<{ name: string; reason: string }> = [];
2164
- try {
2165
- const parsedFiles: Array<{ name: string; payload: unknown }> = [];
2166
- for (const file of files) {
2167
- try {
2168
- const payload = JSON.parse(await file.text()) as unknown;
2169
- parsedFiles.push({ name: file.name, payload });
2170
- } catch (error) {
2171
- failedFiles.push({
2172
- name: file.name,
2173
- reason: error instanceof Error ? error.message : '文件格式无效',
2174
- });
2175
- }
2176
- }
2177
-
2178
- if (parsedFiles.length) {
2179
- try {
2180
- const result = await importAppiumScripts(parsedFiles.map(item => item.payload));
2181
- importedScripts.push(...result.scripts);
2182
- } catch (error) {
2183
- const reason = error instanceof Error ? error.message : '导入失败';
2184
- failedFiles.push(...parsedFiles.map(file => ({ name: file.name, reason })));
2185
- }
2186
- }
2187
-
2188
- if (importedScripts.length) {
2189
- try {
2190
- await loadScripts();
2191
- } catch (error) {
2192
- ElMessage.warning(`脚本已导入,但刷新列表失败:${error instanceof Error ? error.message : '未知错误'}`);
2193
- return;
2194
- }
2195
- }
2196
-
2197
- if (!failedFiles.length) {
2198
- ElMessage.success(files.length === 1
2199
- ? `脚本「${importedScripts[0].name}」已导入`
2200
- : `已成功导入 ${importedScripts.length} 个脚本`);
2201
- return;
2202
- }
2203
-
2204
- const failedSummary = failedFiles
2205
- .map(({ name, reason }) => `${name}(${reason})`)
2206
- .join(';');
2207
- if (importedScripts.length) {
2208
- ElMessage.warning(`已导入 ${importedScripts.length} 个脚本,${failedFiles.length} 个失败:${failedSummary}`);
2209
- } else {
2210
- ElMessage.error(`导入失败:${failedSummary}`);
2211
- }
2212
- } finally {
2213
- importingScript.value = false;
2214
- }
2215
- }
2216
-
2217
- async function saveScript() {
2218
- if (!ensureAppPackageSelected()) return false;
2219
- const wasNew = !selectedScriptId.value;
2220
- saving.value = true;
2221
- try {
2222
- validateVariables(scriptVariables.value);
2223
- await validateRandomValueTargets();
2224
- const payload = await saveAppiumScript({
2225
- id: selectedScriptId.value || undefined,
2226
- name: form.name,
2227
- appPackage: form.appPackage,
2228
- appActivity: form.appActivity,
2229
- deviceId: selectedDeviceId.value,
2230
- steps: steps.value,
2231
- variables: scriptVariables.value,
2232
- });
2233
- await loadScripts();
2234
- selectedScriptId.value = payload.script.id;
2235
- if (wasNew) void saveVariables('/api/appium-recorder/variables?draft=1', []).catch(() => ElMessage.error('变量草稿清理失败'));
2236
- markDraftSaved();
2237
- ElMessage.success('Appium 脚本已保存');
2238
- return true;
2239
- } catch (error) {
2240
- ElMessage.error(error instanceof Error ? error.message : '保存失败');
2241
- return false;
2242
- } finally {
2243
- saving.value = false;
2244
- }
2245
- }
2246
-
2247
- async function replayScript() {
2248
- if (preparingReplay.value || replaying.value) return;
2249
- if (!selectedScript.value) {
2250
- ElMessage.warning('请选择已保存脚本');
2251
- return;
2252
- }
2253
- if (hasUnsavedChanges.value) {
2254
- const saved = await saveScript();
2255
- if (!saved || !selectedScript.value) return;
2256
- }
2257
- let reportSummaryEnabled = false;
2258
- let reportSummaryPrompt: string | undefined;
2259
- if (props.reportSummary?.enabled) {
2260
- preparingReplay.value = true;
2261
- try {
2262
- const status = await checkReportSummaryModel();
2263
- if (status.available) {
2264
- reportSummaryEnabled = true;
2265
- reportSummaryPrompt = selectedReportTemplate.value?.prompt || DEFAULT_REPORT_SUMMARY_PROMPT;
2266
- } else {
2267
- await ElMessageBox.alert(
2268
- `当前提示词优化模型不可用${status.message ? `:${status.message}` : ''}。本次将跳过 AI 总结并生成默认格式的基础报告。`,
2269
- '回放报告总结不可用',
2270
- { type: 'warning', confirmButtonText: '继续回放' },
2271
- ).catch(() => {});
2272
- }
2273
- } catch (error) {
2274
- await ElMessageBox.alert(
2275
- `无法检测提示词优化模型:${error instanceof Error ? error.message : '未知错误'}。本次将跳过 AI 总结并生成默认格式的基础报告。`,
2276
- '回放报告总结不可用',
2277
- { type: 'warning', confirmButtonText: '继续回放' },
2278
- ).catch(() => {});
2279
- } finally {
2280
- preparingReplay.value = false;
2281
- }
2282
- }
2283
- replaying.value = true;
2284
- stoppingReplay.value = false;
2285
- activeReplayDeviceId.value = selectedDeviceId.value;
2286
- replayOutput.value = '';
2287
- try {
2288
- await pauseAutoTreeRefresh();
2289
- const result = await replayAppiumScript(
2290
- {
2291
- id: selectedScript.value.id,
2292
- deviceId: activeReplayDeviceId.value,
2293
- recordVideo: recordReplayVideo.value,
2294
- reportSummaryEnabled,
2295
- reportSummaryPrompt,
2296
- },
2297
- (line) => {
2298
- replayOutput.value += `${replayOutput.value ? '\n' : ''}${line}`;
2299
- },
2300
- );
2301
- replayOutput.value = result.output || '';
2302
- if (result.stopped) {
2303
- ElMessage.info('回放已终止,报告、日志和截图回放已生成');
2304
- } else if (result.softFailureCount) {
2305
- ElMessage.warning(`回放完成,但存在 ${result.softFailureCount} 个视觉变化未达预期节点`);
2306
- } else if (result.success) {
2307
- ElMessage.success('回放完成');
2308
- } else {
2309
- ElMessage.error('回放失败,详情见回放输出');
2310
- }
2311
- } catch (error) {
2312
- const message = error instanceof Error ? error.message : '回放失败';
2313
- replayOutput.value += `${replayOutput.value ? '\n' : ''}${message}`;
2314
- ElMessage.error('回放失败,详情见回放输出');
2315
- } finally {
2316
- replaying.value = false;
2317
- stoppingReplay.value = false;
2318
- activeReplayDeviceId.value = '';
2319
- scheduleAutoTreeRefresh(800);
2320
- }
2321
- }
2322
-
2323
- async function stopReplay() {
2324
- if (!replaying.value || stoppingReplay.value) return;
2325
- stoppingReplay.value = true;
2326
- try {
2327
- const result = await stopAppiumReplay(activeReplayDeviceId.value);
2328
- if (!result.stopped) {
2329
- stoppingReplay.value = false;
2330
- ElMessage.warning('当前没有可终止的回放任务');
2331
- }
2332
- } catch (error) {
2333
- stoppingReplay.value = false;
2334
- ElMessage.error(error instanceof Error ? error.message : '终止回放失败');
2335
- }
2336
- }
2337
-
2338
- onMounted(() => {
2339
- window.addEventListener('beforeunload', warnBeforeUnload);
2340
- void loadScripts();
2341
- });
2342
-
2343
- onUnmounted(() => {
2344
- window.removeEventListener('beforeunload', warnBeforeUnload);
2345
- stopAutoTreeRefresh();
2346
- });
2347
-
2348
- watch(() => form.appPackage, (packageName) => {
2349
- if (!packageName) return;
2350
- steps.value = steps.value.map((step) => (
2351
- step.type === 'launchApp'
2352
- ? { ...step, label: `启动 APP ${packageName}`, value: packageName }
2353
- : step.type === 'clearAppData'
2354
- ? { ...step, label: `清理 APP 缓存(含数据)${packageName}`, value: packageName }
2355
- : step
2356
- ));
2357
- });
2358
-
2359
- watch(
2360
- () => [props.active, props.playgroundDeviceId] as const,
2361
- ([active, deviceId]) => {
2362
- stopAutoTreeRefresh();
2363
- if (active && deviceId) {
2364
- void refreshTree().finally(() => scheduleAutoTreeRefresh());
2365
- }
2366
- },
2367
- { immediate: true },
2368
- );
2369
- </script>
2370
-
2371
- <template>
2372
- <section class="appium-recorder-page">
2373
- <Teleport to="#appium-header-actions">
2374
- <div v-if="active" class="appium-header-actions">
2375
- <el-select
2376
- v-model="selectedScriptId"
2377
- clearable
2378
- placeholder="选择脚本"
2379
- class="appium-header-actions__script"
2380
- @change="loadSelectedScript"
2381
- >
2382
- <el-option v-for="script in scripts" :key="script.id" :label="script.name" :value="script.id" />
2383
- </el-select>
2384
- <el-button :icon="Plus" :disabled="newScriptDisabled || newScriptDialogVisible" @click="requestNewScript">新建</el-button>
2385
- <el-button :icon="Check" :loading="saving" @click="saveScript">保存</el-button>
2386
- <el-button-group class="replay-button-group">
2387
- <el-button
2388
- type="primary"
2389
- :icon="VideoPlay"
2390
- :loading="replaying || preparingReplay"
2391
- :disabled="!selectedScript"
2392
- @click="replayScript"
2393
- >
2394
- 回放
2395
- </el-button>
2396
- <el-popover trigger="click" placement="bottom" :width="320">
2397
- <template #reference><el-button type="primary" :icon="ArrowDown" :disabled="replaying || preparingReplay" aria-label="回放设置" title="回放设置" class="replay-settings-toggle" /></template>
2398
- <div class="replay-settings-panel">
2399
- <el-tooltip content="使用内置服务端后台录制,无需安装 scrcpy 或 FFmpeg。含敏感变量的运行不录制;分享 HTML 报告时需同时携带 MP4。" placement="bottom" :show-after="300">
2400
- <el-checkbox v-model="recordReplayVideo" :disabled="replaying || preparingReplay">录制回放视频</el-checkbox>
2401
- </el-tooltip>
2402
- <div class="replay-report-template">
2403
- <span>报告模板</span>
2404
- <el-select v-model="selectedReportTemplateName" clearable :disabled="replaying || preparingReplay || !reportSummary?.enabled" placeholder="默认测试报告(未选择时使用)">
2405
- <el-option v-for="template in availableReportTemplates" :key="template.name" :label="template.name" :value="template.name" />
2406
- </el-select>
2407
- <small v-if="!reportSummary?.enabled">需先在参数配置中开启回放报告总结。</small>
2408
- </div>
2409
- </div>
2410
- </el-popover>
2411
- </el-button-group>
2412
- <el-button
2413
- v-if="replaying"
2414
- type="danger"
2415
- :icon="CircleClose"
2416
- :loading="stoppingReplay"
2417
- @click="stopReplay"
2418
- >
2419
- 终止
2420
- </el-button>
2421
- </div>
2422
-
2423
- </Teleport>
2424
-
2425
- <RecorderWorkspace ref="workspaceRef">
2426
- <template #preview>
2427
- <DevicePreviewPanel
2428
- compact
2429
- :interaction-disabled="recordingBusy || replaying"
2430
- :available="playgroundAvailable"
2431
- :devices="androidDevices"
2432
- :selected-device-id="selectedDeviceId"
2433
- :frame-url="playgroundFrameUrl"
2434
- :image-url="devicePreviewUrl"
2435
- :preview-error="playgroundPreviewError"
2436
- :actions="deviceActions"
2437
- :overlay-bounds="overlayBounds"
2438
- :selected-bounds="selectedBounds"
2439
- :selected-region="visualChangeSelectedRegion"
2440
- :region-selection="visualChangeRegionSelectionEnabled"
2441
- :point-selection="pickingCoordinate"
2442
- @cancel-point-selection="coordinatePicker.cancel()"
2443
- :region-draw-mode="visualChangePicking || imageCheckPicking"
2444
- :device-width="deviceWidth"
2445
- :device-height="deviceHeight"
2446
- @switch-device="switchDevice"
2447
- @trigger-key="triggerDeviceKey"
2448
- @refresh-preview="refreshDevicePreview"
2449
- @tap="selectNodeFromPoint"
2450
- @region-select="applyVisualChangeRegion"
2451
- @swipe="swipePreview"
2452
- />
2453
- </template>
2454
- <template #tree>
2455
- <ComponentInspector :tree="tree" :node="selectedNode" :activity="currentActivity" :loading="loadingTree" :disabled="replaying" :recording="recordingTap" @refresh="refreshTree" @select="selectedNode = $event" />
2456
- </template>
2457
-
2458
- <el-card shadow="never" class="appium-recorder-card appium-recorder-card--workbench">
2459
- <el-tabs
2460
- :model-value="activeWorkbenchTab"
2461
- class="appium-workbench-tabs"
2462
- @tab-click="setActiveWorkbenchTab($event.paneName)"
2463
- >
2464
- <el-tab-pane label="当前录制" name="recording">
2465
- <div class="appium-workbench">
2466
- <section class="appium-workbench__section">
2467
- <h3>节点与脚本</h3>
2468
- <div class="appium-side-form">
2469
- <el-input v-model="form.name" placeholder="脚本名称" />
2470
- <el-select
2471
- v-model="form.appPackage"
2472
- filterable
2473
- placeholder="选择预设 App 参数"
2474
- >
2475
- <el-option
2476
- v-for="app in appPresets"
2477
- :key="app.id"
2478
- :label="`${app.name} · ${app.packageName}`"
2479
- :value="app.packageName"
2480
- />
2481
- </el-select>
2482
- </div>
2483
- </section>
2484
-
2485
- <section class="appium-workbench__section appium-workbench__flow">
2486
- <RecordedSteps
2487
- ref="recordedStepsRef"
2488
- :key="newScriptRevision"
2489
- :ai-recognition-model-configured="aiRecognitionModelConfigured"
2490
- :steps="steps"
2491
- :clipboard-count="flowClipboardCount"
2492
- :disabled="recordingLocked"
2493
- :remove-disabled="recordingLocked"
2494
- :merge-disabled="recordingBusy || replaying || saving"
2495
- :launching-step-id="executingAppStepId"
2496
- @remove="removeStep"
2497
- @copy="copyFlowNodes"
2498
- @paste="pasteFlowNodes"
2499
- @add-delay="addDelayStep"
2500
- @insert-action="(index, action, beforeStepId) => addSharedAction(action, index, beforeStepId)"
2501
- @insert-branch-action="addBranchAction"
2502
- @edit-input="editInputStep"
2503
- @preview-linked-script="previewLinkedScriptStep"
2504
- @execute-step="executeFlowStep"
2505
- @update-step="updateStep"
2506
- @replace-steps="!recordingBusy && !replaying && !saving && (steps = $event)"
2507
- />
2508
- </section>
2509
-
2510
- </div>
2511
- </el-tab-pane>
2512
-
2513
- <el-tab-pane label="脚本列表" name="scripts">
2514
- <div class="appium-script-list">
2515
- <div class="appium-script-list__toolbar">
2516
- <el-tooltip content="导入脚本(支持多选)" placement="top" :show-after="200"><span class="appium-script-icon">
2517
- <el-button size="small" :icon="Upload" aria-label="导入脚本" :loading="importingScript" @click="chooseScriptImportFile" />
2518
- </span></el-tooltip>
2519
- <input
2520
- ref="scriptImportInput"
2521
- class="appium-script-list__file-input"
2522
- type="file"
2523
- accept="application/json,.json"
2524
- multiple
2525
- @change="importScriptFile"
2526
- >
2527
- </div>
2528
- <el-empty v-if="!scripts.length" description="暂无录制脚本" />
2529
- <template v-else>
2530
- <article
2531
- v-for="script in scripts"
2532
- :key="script.id"
2533
- class="appium-script-list__item"
2534
- :class="{ 'appium-script-list__item--active': script.id === selectedScriptId }"
2535
- >
2536
- <div class="appium-script-list__main">
2537
- <strong>{{ script.name }}</strong>
2538
- <span>{{ script.appPackage }}</span>
2539
- <small>{{ script.steps.length }} 步 · {{ formatScriptTime(script.updatedAt) }}</small>
2540
- </div>
2541
- <div class="appium-script-list__actions">
2542
- <el-tooltip content="历史结果对比" placement="top" :show-after="200"><span class="appium-script-icon">
2543
- <el-button size="small" :icon="Clock" aria-label="历史结果对比" @click.stop="historyScript = { id: script.id, name: script.name }" />
2544
- </span></el-tooltip>
2545
- <el-tooltip content="加载" placement="top" :show-after="200"><span class="appium-script-icon">
2546
- <el-button size="small" :icon="FolderOpened" aria-label="加载" @click.stop="loadScript(script)" />
2547
- </span></el-tooltip>
2548
- <el-tooltip content="修改脚本名称" placement="top" :show-after="200"><span class="appium-script-icon">
2549
- <el-button
2550
- size="small"
2551
- :icon="Edit"
2552
- :loading="renamingScriptId === script.id"
2553
- aria-label="修改脚本名称"
2554
- @click.stop="renameScript(script)"
2555
- />
2556
- </span></el-tooltip>
2557
- <el-tooltip content="复制脚本" placement="top" :show-after="200"><span class="appium-script-icon">
2558
- <el-button
2559
- size="small"
2560
- :icon="CopyDocument"
2561
- :loading="duplicatingScriptId === script.id"
2562
- aria-label="复制脚本"
2563
- @click.stop="duplicateScript(script)"
2564
- />
2565
- </span></el-tooltip>
2566
- <el-tooltip content="下载脚本" placement="top" :show-after="200"><span class="appium-script-icon">
2567
- <el-button
2568
- size="small"
2569
- :icon="Download"
2570
- :loading="downloadingScriptId === script.id"
2571
- :disabled="Boolean(downloadingScriptId) && downloadingScriptId !== script.id"
2572
- aria-label="下载脚本"
2573
- @click.stop="downloadScript(script)"
2574
- />
2575
- </span></el-tooltip>
2576
- <el-tooltip content="删除脚本" placement="top" :show-after="200"><span class="appium-script-icon">
2577
- <el-button
2578
- size="small"
2579
- type="danger"
2580
- :icon="Delete"
2581
- :loading="deletingScriptId === script.id"
2582
- aria-label="删除脚本"
2583
- @click.stop="removeScript(script)"
2584
- />
2585
- </span></el-tooltip>
2586
- </div>
2587
- </article>
2588
- </template>
2589
- </div>
2590
- </el-tab-pane>
2591
- <el-tab-pane label="预设变量" name="variables" lazy>
2592
- <div v-if="pendingRandomValue" class="random-value-return">
2593
- <span>随机值节点配置已保留</span>
2594
- <el-button type="primary" plain :disabled="recordingLocked" @click="resumeRandomValue">返回节点配置</el-button>
2595
- </div>
2596
- <PresetVariables :key="`${selectedScriptId}:${newScriptRevision}`" v-model:variables="scriptVariables" v-model:globals="globalVariables" :script-id="selectedScriptId" :script-name="form.name" :disabled="recordingBusy || saving" @saved="onVariablesSaved" />
2597
- </el-tab-pane>
2598
- </el-tabs>
2599
- </el-card>
2600
- </RecorderWorkspace>
2601
-
2602
- <RunHistoryDialog v-if="historyScript" :script-id="historyScript.id" :script-name="historyScript.name" @close="historyScript = null" />
2603
- <NewScriptDialog
2604
- v-if="newScriptDialogVisible"
2605
- :script-name="form.name"
2606
- :saving="saving"
2607
- @save="saveAndNewScript"
2608
- @discard="startNewScript"
2609
- @cancel="newScriptDialogVisible = false"
2610
- />
2611
-
2612
-
2613
- <AiRecognitionTestDialog v-if="aiRecognitionTestStep" :step="aiRecognitionTestStep" :device-id="selectedDeviceId" :model-configured="Boolean(aiRecognitionModelConfigured)" @close="aiRecognitionTestStep = null" />
2614
- <ImageCheckDialog
2615
- v-if="imageCheckDraft?.imageCheck"
2616
- :timeout-branch="imageCheckDraft.timeoutBranch"
2617
- @timeout-branch="imageCheckDraft = { ...imageCheckDraft!, timeoutBranch: $event }"
2618
- :config="imageCheckDraft.imageCheck" :device-id="selectedDeviceId"
2619
- :has-element="Boolean(selectedNode?.bounds)" :editing="imageCheckEditing" :picking="imageCheckPicking"
2620
- @update="updateImageCheck" @close="imageCheckDraft = null; imageCheckPicking = false"
2621
- @confirm="confirmImageCheck" @use-element="useImageCheckElement"
2622
- @pick="imageCheckPicking = true; workspaceRef?.showPreview()"
2623
- />
2624
- <VisualChangeDialog
2625
- :model-value="visualChangeDialogVisible"
2626
- :config="visualChangeConfig"
2627
- :has-selected-element="Boolean(selectedNode?.bounds)"
2628
- :picking-region="visualChangePicking"
2629
- @update:model-value="$event ? (visualChangeDialogVisible = true) : closeVisualChangeDialog()"
2630
- @update:config="updateVisualChangeConfig"
2631
- @pick-region="pickVisualChangeRegion"
2632
- @confirm="confirmVisualChangeStep"
2633
- />
2634
-
2635
- <el-dialog
2636
- :model-value="Boolean(pendingNavigation)"
2637
- title="检测到 Activity 跳转"
2638
- width="560px"
2639
- :close-on-click-modal="false"
2640
- :close-on-press-escape="false"
2641
- :show-close="false"
2642
- >
2643
- <div class="appium-navigation-dialog">
2644
- <p>检测到 Activity 已跳转。可以继续在当前脚本中录制后续操作,或保存当前脚本并开始录制新页面。</p>
2645
- <dl>
2646
- <div>
2647
- <dt>点击前</dt>
2648
- <dd>{{ pendingNavigation?.beforeActivity || '-' }}</dd>
2649
- </div>
2650
- <div>
2651
- <dt>点击后</dt>
2652
- <dd>{{ pendingNavigation?.afterActivity || '-' }}</dd>
2653
- </div>
2654
- </dl>
2655
- </div>
2656
- <template #footer>
2657
- <div class="appium-navigation-footer">
2658
- <el-button :disabled="resolvingNavigation" @click="continueOnActivityChange">继续录制</el-button>
2659
- <el-button type="primary" :loading="resolvingNavigation" @click="saveOnActivityChange">保存脚本</el-button>
2660
- </div>
2661
- </template>
2662
- </el-dialog>
2663
-
2664
- <el-dialog
2665
- v-model="linkedScriptDialogVisible"
2666
- title="连接脚本"
2667
- width="640px"
2668
- class="appium-linked-script-dialog"
2669
- align-center
2670
- @closed="closeLinkedScriptDialog"
2671
- >
2672
- <el-form label-position="top">
2673
- <el-form-item :label="linkedScriptBranchTarget ? '分支录制 Activity' : '插入点 Activity'">
2674
- <code class="appium-linked-script-activity">{{ linkedScriptExpectedActivity || '-' }}</code>
2675
- </el-form-item>
2676
- <el-form-item label="选择同一 App 的脚本">
2677
- <div class="appium-linked-script-picker">
2678
- <el-select
2679
- v-model="linkedScriptTargetId"
2680
- filterable
2681
- placeholder="选择要连接的脚本"
2682
- class="appium-linked-script-select"
2683
- >
2684
- <el-option
2685
- v-for="script in compatibleLinkableScripts"
2686
- :key="script.id"
2687
- :label="`${script.name} · ${script.appActivity || '未绑定 Activity'} · ${script.steps.length} 步`"
2688
- :value="script.id"
2689
- />
2690
- </el-select>
2691
- <el-button
2692
- :icon="View"
2693
- :disabled="!linkedScriptTarget"
2694
- @click="openLinkedScriptPreview()"
2695
- >
2696
- 预览
2697
- </el-button>
2698
- </div>
2699
- </el-form-item>
2700
- <el-alert v-if="linkedScriptTarget" :closable="false" type="info" show-icon
2701
- :title="linkedScriptTarget.appActivity
2702
- ? `回放时等待进入 ${linkedScriptTarget.appActivity},请在前序步骤中完成页面跳转。`
2703
- : '此脚本未绑定入口 Activity,将直接从当前画面执行。请确保前序步骤已进入目标页面。'"
2704
- />
2705
- <ScriptParameterSettings :step="linkedParameters" @update="Object.assign(linkedParameters, $event)" />
2706
- </el-form>
2707
- <template #footer>
2708
- <el-button @click="closeLinkedScriptDialog">取消</el-button>
2709
- <el-button type="primary" @click="addLinkedScriptStep">{{ linkedScriptEditingId ? '保存' : '添加连接' }}</el-button>
2710
- </template>
2711
- </el-dialog>
2712
-
2713
- <el-dialog
2714
- v-model="linkedScriptPreviewVisible"
2715
- :title="linkedScriptPreviewScript ? `预览脚本:${linkedScriptPreviewScript.name}` : '预览脚本'"
2716
- width="86vw"
2717
- top="6vh"
2718
- class="appium-linked-script-preview-dialog"
2719
- :z-index="4000"
2720
- append-to-body
2721
- >
2722
- <template v-if="linkedScriptPreviewScript">
2723
- <div class="appium-linked-script-preview-meta">
2724
- <strong>{{ linkedScriptPreviewScript.name }}</strong>
2725
- <span>
2726
- {{ linkedScriptPreviewScript.appPackage || '-' }}
2727
- · {{ linkedScriptPreviewScript.appActivity || '未绑定 Activity' }}
2728
- · {{ linkedScriptPreviewScript.steps.length }} 步
2729
- </span>
2730
- </div>
2731
- <FlowCanvas
2732
- id="appium-linked-script-preview"
2733
- :ai-recognition-model-configured="aiRecognitionModelConfigured"
2734
- class="appium-linked-script-preview-canvas"
2735
- readonly
2736
- disabled
2737
- remove-disabled
2738
- :steps="linkedScriptPreviewScript.steps"
2739
- :expanded-step-index="null"
2740
- :copy-mode="false"
2741
- :selected-copy-indexes="readonlyFlowSelectedIndexes"
2742
- :reset-view-token="linkedScriptPreviewResetToken"
2743
- :start-action-groups="readonlyFlowActionGroups"
2744
- :main-action-groups="readonlyFlowActionGroups"
2745
- :can-open-insert-menu="false"
2746
- :is-start-action-disabled="isReadonlyFlowActionDisabled"
2747
- :is-insert-action-disabled="isReadonlyFlowActionDisabled"
2748
- :is-app-execution-disabled="isReadonlyFlowAppExecutionDisabled"
2749
- :label-step="labelFlowStep"
2750
- :is-copy-selected="isReadonlyFlowCopySelected"
2751
- />
2752
- </template>
2753
- <template #footer>
2754
- <el-button @click="linkedScriptPreviewVisible = false">关闭</el-button>
2755
- <el-button
2756
- type="primary"
2757
- :disabled="!linkedScriptPreviewScript"
2758
- @click="loadPreviewScriptForEditing"
2759
- >
2760
- 加载后修改
2761
- </el-button>
2762
- </template>
2763
- </el-dialog>
2764
-
2765
- <el-dialog
2766
- :model-value="stoppingReplay"
2767
- title="报告正在生成中"
2768
- width="420px"
2769
- align-center
2770
- append-to-body
2771
- :show-close="false"
2772
- :close-on-click-modal="false"
2773
- :close-on-press-escape="false"
2774
- >
2775
- <div class="appium-report-progress" role="status" aria-live="polite">
2776
- <el-icon class="is-loading" aria-hidden="true"><Loading /></el-icon>
2777
- <span>正在终止回放并生成报告、日志和截图回放,请稍候。</span>
2778
- </div>
2779
- </el-dialog>
2780
-
2781
- <el-dialog
2782
- v-model="replayOutputDialogVisible"
2783
- title="回放输出"
2784
- width="820px"
2785
- top="8vh"
2786
- class="appium-replay-dialog"
2787
- draggable
2788
- overflow
2789
- >
2790
- <pre class="appium-replay-output appium-replay-output--dialog">{{ replayOutput }}</pre>
2791
- <template #footer>
2792
- <el-button :icon="CopyDocument" :disabled="!replayOutput" @click="copyReplayOutput">复制</el-button>
2793
- <el-button :icon="Delete" :disabled="!replayOutput" @click="clearReplayOutput">清除</el-button>
2794
- <el-button type="primary" @click="replayOutputDialogVisible = false">关闭</el-button>
2795
- </template>
2796
- </el-dialog>
2797
-
2798
- <el-tooltip v-if="active" content="查看回放输出" placement="left">
2799
- <el-badge
2800
- :is-dot="Boolean(replayOutput) && !replayOutputDialogVisible"
2801
- class="appium-replay-fab"
2802
- >
2803
- <el-button
2804
- type="primary"
2805
- circle
2806
- :icon="Document"
2807
- :class="{ 'appium-replay-fab__button--running': replaying }"
2808
- aria-label="查看回放输出"
2809
- @click="replayOutputDialogVisible = true"
2810
- />
2811
- </el-badge>
2812
- </el-tooltip>
2813
- </section>
2814
- </template>
2815
-
2816
- <style scoped>
2817
- .appium-report-progress { display: flex; align-items: center; gap: 12px; line-height: 1.6; }
2818
- .random-value-return { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 12px 16px; color: var(--el-text-color-secondary); font-size: 13px; }
2819
- .appium-script-icon { display: inline-flex; }
2820
- .appium-script-icon .el-button { width: 30px; height: 30px; min-height: 30px; padding: 0; margin: 0; }
2821
- :deep(.appium-recorder-card--workbench > .el-card__body) { overflow: hidden; }
2822
- :deep(.appium-workbench-tabs > .el-tabs__content) { overflow: hidden; }
2823
- :deep(.appium-workbench-tabs .el-tab-pane) { height: 100%; overflow: auto; }
2824
- .appium-workbench { height: 100%; box-sizing: border-box; grid-template-rows: auto minmax(0, 1fr); gap: 12px; overflow: hidden; padding: 8px 16px 16px; }
2825
- .appium-workbench__flow { display: flex; flex-direction: column; min-height: 0; }
2826
- .appium-workbench__flow h3 { margin-bottom: 6px; }
2827
- .appium-workbench__flow :deep(.appium-recorded-steps-panel) { display: flex; flex-direction: column; flex: 1; min-height: 0; }
2828
- .appium-workbench__flow :deep(.appium-flow-toolbar) { flex: none; margin-bottom: 8px; }
2829
- .appium-workbench__flow :deep(.appium-flow-canvas--vue:not(.appium-flow-canvas--dialog)) { flex: 1; height: auto; min-height: 120px; }
2830
- .replay-button-group { display: inline-flex; flex-shrink: 0; }
2831
- .replay-settings-toggle { padding-inline: 8px; }
2832
- .replay-settings-panel { display: grid; gap: 14px; }
2833
- .replay-report-template { display: grid; gap: 6px; }
2834
- .replay-report-template > span { color: var(--el-text-color-regular); font-size: 13px; }
2835
- .replay-report-template small { color: var(--el-text-color-secondary); line-height: 1.5; }
2836
- </style>