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