@web-auto/webauto 0.1.1 → 0.1.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (354) hide show
  1. package/apps/desktop-console/default-settings.json +1 -0
  2. package/apps/desktop-console/dist/main/index.mjs +1618 -0
  3. package/apps/desktop-console/{src → dist}/main/preload.mjs +10 -0
  4. package/apps/desktop-console/dist/renderer/index.js +3063 -0
  5. package/apps/desktop-console/entry/ui-console.mjs +299 -0
  6. package/apps/webauto/entry/account.mjs +356 -0
  7. package/apps/webauto/entry/lib/account-detect.mjs +160 -0
  8. package/apps/webauto/entry/lib/account-store.mjs +587 -0
  9. package/apps/webauto/entry/lib/profilepool.mjs +1 -1
  10. package/apps/webauto/entry/xhs-install.mjs +27 -3
  11. package/apps/webauto/entry/xhs-status.mjs +152 -0
  12. package/apps/webauto/entry/xhs-unified.mjs +595 -17
  13. package/bin/webauto.mjs +263 -15
  14. package/dist/apps/webauto/server.js +66 -0
  15. package/dist/modules/camo-backend/src/index.js +575 -0
  16. package/dist/modules/camo-backend/src/internal/BrowserSession.js +817 -0
  17. package/dist/modules/camo-backend/src/internal/ElementRegistry.js +61 -0
  18. package/dist/modules/camo-backend/src/internal/ProfileLock.js +85 -0
  19. package/dist/modules/camo-backend/src/internal/SessionManager.js +172 -0
  20. package/dist/modules/camo-backend/src/internal/container-matcher.js +852 -0
  21. package/dist/modules/camo-backend/src/internal/engine-manager.js +258 -0
  22. package/dist/modules/camo-backend/src/internal/fingerprint.js +203 -0
  23. package/dist/modules/camo-backend/src/internal/pageRuntime.js +29 -0
  24. package/dist/modules/camo-backend/src/internal/runtimeInjector.js +30 -0
  25. package/dist/modules/camo-backend/src/internal/state-bus.js +46 -0
  26. package/dist/modules/camo-backend/src/internal/storage-paths.js +36 -0
  27. package/dist/modules/camo-backend/src/internal/ws-server.js +1202 -0
  28. package/dist/modules/camo-runtime/src/utils/browser-service.mjs +423 -0
  29. package/dist/modules/camo-runtime/src/utils/config.mjs +77 -0
  30. package/dist/modules/container-registry/src/index.js +184 -0
  31. package/dist/modules/logging/src/index.js +92 -0
  32. package/dist/modules/operations/src/builtin.js +27 -0
  33. package/dist/modules/operations/src/container-binding.js +75 -0
  34. package/dist/modules/operations/src/executor.js +146 -0
  35. package/dist/modules/operations/src/operations/click.js +167 -0
  36. package/dist/modules/operations/src/operations/extract.js +204 -0
  37. package/dist/modules/operations/src/operations/find-child.js +17 -0
  38. package/dist/modules/operations/src/operations/highlight.js +138 -0
  39. package/dist/modules/operations/src/operations/key.js +61 -0
  40. package/dist/modules/operations/src/operations/navigate.js +148 -0
  41. package/dist/modules/operations/src/operations/scroll.js +126 -0
  42. package/dist/modules/operations/src/operations/type.js +190 -0
  43. package/dist/modules/operations/src/queue.js +100 -0
  44. package/dist/modules/operations/src/registry.js +11 -0
  45. package/dist/modules/operations/src/system/mouse.js +33 -0
  46. package/dist/modules/state/src/atomic-json.js +33 -0
  47. package/dist/modules/workflow/blocks/AnchorVerificationBlock.js +71 -0
  48. package/dist/modules/workflow/blocks/BehaviorRandomizer.js +26 -0
  49. package/dist/modules/workflow/blocks/CallWorkflowBlock.js +38 -0
  50. package/dist/modules/workflow/blocks/CloseDetailBlock.js +209 -0
  51. package/dist/modules/workflow/blocks/CollectBatch.js +137 -0
  52. package/dist/modules/workflow/blocks/CollectCommentsBlock.js +415 -0
  53. package/dist/modules/workflow/blocks/CollectSearchListBlock.js +599 -0
  54. package/dist/modules/workflow/blocks/CollectWeiboPosts.js +229 -0
  55. package/dist/modules/workflow/blocks/DetectPageStateBlock.js +259 -0
  56. package/dist/modules/workflow/blocks/EnsureLoginBlock.js +162 -0
  57. package/dist/modules/workflow/blocks/EnsureSession.js +426 -0
  58. package/dist/modules/workflow/blocks/ErrorClassifier.js +164 -0
  59. package/dist/modules/workflow/blocks/ErrorRecoveryBlock.js +319 -0
  60. package/dist/modules/workflow/blocks/ExpandCommentsBlock.js +1032 -0
  61. package/dist/modules/workflow/blocks/ExtractDetailBlock.js +310 -0
  62. package/dist/modules/workflow/blocks/ExtractPostFields.js +88 -0
  63. package/dist/modules/workflow/blocks/GenerateSmartReplyBlock.js +68 -0
  64. package/dist/modules/workflow/blocks/GoToSearchBlock.js +497 -0
  65. package/dist/modules/workflow/blocks/GracefulFallbackBlock.js +104 -0
  66. package/dist/modules/workflow/blocks/HighlightBlock.js +66 -0
  67. package/dist/modules/workflow/blocks/InitAutoScroll.js +65 -0
  68. package/dist/modules/workflow/blocks/LoadContainerDefinition.js +50 -0
  69. package/dist/modules/workflow/blocks/LoadContainerIndex.js +43 -0
  70. package/dist/modules/workflow/blocks/LocateAndGuardBlock.js +176 -0
  71. package/dist/modules/workflow/blocks/LoginRecoveryBlock.js +242 -0
  72. package/dist/modules/workflow/blocks/MatchContainers.js +64 -0
  73. package/dist/modules/workflow/blocks/MonitoringBlock.js +190 -0
  74. package/dist/modules/workflow/blocks/OpenDetailBlock.js +1240 -0
  75. package/dist/modules/workflow/blocks/OrganizeXhsNotesBlock.js +117 -0
  76. package/dist/modules/workflow/blocks/PersistXhsNoteBlock.js +270 -0
  77. package/dist/modules/workflow/blocks/PickSinglePost.js +69 -0
  78. package/dist/modules/workflow/blocks/ProgressTracker.js +125 -0
  79. package/dist/modules/workflow/blocks/RecordFixtureBlock.js +44 -0
  80. package/dist/modules/workflow/blocks/RenderMarkdown.js +48 -0
  81. package/dist/modules/workflow/blocks/SaveFile.js +54 -0
  82. package/dist/modules/workflow/blocks/ScrollNextBatch.js +72 -0
  83. package/dist/modules/workflow/blocks/SessionHealthBlock.js +73 -0
  84. package/dist/modules/workflow/blocks/StartBrowserService.js +45 -0
  85. package/dist/modules/workflow/blocks/ValidateContainerDefinition.js +67 -0
  86. package/dist/modules/workflow/blocks/ValidateExtract.js +35 -0
  87. package/dist/modules/workflow/blocks/WaitSearchPermitBlock.js +162 -0
  88. package/dist/modules/workflow/blocks/WaitStable.js +74 -0
  89. package/dist/modules/workflow/blocks/WarmupCommentsBlock.js +120 -0
  90. package/dist/modules/workflow/blocks/WorkflowExecutor.js +156 -0
  91. package/dist/modules/workflow/blocks/XiaohongshuCollectFromLinksBlock.js +1004 -0
  92. package/dist/modules/workflow/blocks/XiaohongshuCollectLinksBlock.js +1049 -0
  93. package/dist/modules/workflow/blocks/XiaohongshuFullCollectBlock.js +782 -0
  94. package/dist/modules/workflow/blocks/helpers/anchorVerify.js +198 -0
  95. package/dist/modules/workflow/blocks/helpers/asyncWorkQueue.js +53 -0
  96. package/dist/modules/workflow/blocks/helpers/commentScroller.js +334 -0
  97. package/dist/modules/workflow/blocks/helpers/commentSectionLocator.js +126 -0
  98. package/dist/modules/workflow/blocks/helpers/containerAnchors.js +301 -0
  99. package/dist/modules/workflow/blocks/helpers/debugArtifacts.js +6 -0
  100. package/dist/modules/workflow/blocks/helpers/downloadPaths.js +29 -0
  101. package/dist/modules/workflow/blocks/helpers/expandCommentsController.js +53 -0
  102. package/dist/modules/workflow/blocks/helpers/expandCommentsExtractor.js +129 -0
  103. package/dist/modules/workflow/blocks/helpers/macosVisionOcrPlugin.js +116 -0
  104. package/dist/modules/workflow/blocks/helpers/mergeXhsMarkdown.js +109 -0
  105. package/dist/modules/workflow/blocks/helpers/openDetailController.js +56 -0
  106. package/dist/modules/workflow/blocks/helpers/openDetailTypes.js +7 -0
  107. package/dist/modules/workflow/blocks/helpers/openDetailViewport.js +474 -0
  108. package/dist/modules/workflow/blocks/helpers/openDetailWaiter.js +104 -0
  109. package/dist/modules/workflow/blocks/helpers/operationLogger.js +195 -0
  110. package/dist/modules/workflow/blocks/helpers/persistedNotes.js +107 -0
  111. package/dist/modules/workflow/blocks/helpers/replyExpander.js +260 -0
  112. package/dist/modules/workflow/blocks/helpers/scrollIntoView.js +138 -0
  113. package/dist/modules/workflow/blocks/helpers/searchExecutor.js +328 -0
  114. package/dist/modules/workflow/blocks/helpers/searchGate.js +46 -0
  115. package/dist/modules/workflow/blocks/helpers/searchPageState.js +164 -0
  116. package/dist/modules/workflow/blocks/helpers/searchResultWaiter.js +64 -0
  117. package/dist/modules/workflow/blocks/helpers/simpleAnchor.js +134 -0
  118. package/dist/modules/workflow/blocks/helpers/smartReply.js +40 -0
  119. package/dist/modules/workflow/blocks/helpers/systemInput.js +635 -0
  120. package/dist/modules/workflow/blocks/helpers/targetCountMode.js +9 -0
  121. package/dist/modules/workflow/blocks/helpers/xhsCliArgs.js +80 -0
  122. package/dist/modules/workflow/blocks/helpers/xhsCommentDom.js +805 -0
  123. package/dist/modules/workflow/blocks/helpers/xhsNoteOrganizer.js +140 -0
  124. package/dist/modules/workflow/blocks/restore/RestorePhaseBlock.js +204 -0
  125. package/dist/modules/workflow/config/workflowRegistry.js +32 -0
  126. package/dist/modules/workflow/definitions/batch-collect-workflow.js +63 -0
  127. package/dist/modules/workflow/definitions/scroll-extract-workflow.js +74 -0
  128. package/dist/modules/workflow/definitions/xiaohongshu-collect-workflow-v2.js +81 -0
  129. package/dist/modules/workflow/definitions/xiaohongshu-collect-workflow.js +57 -0
  130. package/dist/modules/workflow/definitions/xiaohongshu-full-collect-workflow-v3.js +68 -0
  131. package/dist/modules/workflow/definitions/xiaohongshu-note-collect.js +49 -0
  132. package/dist/modules/workflow/definitions/xiaohongshu-phase1-workflow-v3.js +30 -0
  133. package/dist/modules/workflow/definitions/xiaohongshu-phase2-links-workflow-v3.js +40 -0
  134. package/dist/modules/workflow/definitions/xiaohongshu-phase3-collect-workflow-v1.js +54 -0
  135. package/dist/modules/workflow/definitions/xiaohongshu-phase34-from-links-workflow-v3.js +25 -0
  136. package/dist/modules/workflow/src/WeiboEventDrivenWorkflowRunner.js +308 -0
  137. package/dist/modules/workflow/src/context.js +70 -0
  138. package/dist/modules/workflow/src/index.js +5 -0
  139. package/dist/modules/workflow/src/orchestrator.js +230 -0
  140. package/dist/modules/workflow/src/runner.js +55 -0
  141. package/dist/modules/workflow/src/runtime.js +70 -0
  142. package/dist/modules/workflow/workflows/WeiboFeedExtractionWorkflow.js +359 -0
  143. package/dist/modules/workflow/workflows/XiaohongshuLoginWorkflow.js +110 -0
  144. package/dist/modules/xiaohongshu/app/src/blocks/MatchCommentsBlock.js +139 -0
  145. package/dist/modules/xiaohongshu/app/src/blocks/Phase1EnsureServicesBlock.js +36 -0
  146. package/dist/modules/xiaohongshu/app/src/blocks/Phase1MonitorCookieBlock.js +213 -0
  147. package/dist/modules/xiaohongshu/app/src/blocks/Phase1StartProfileBlock.js +121 -0
  148. package/dist/modules/xiaohongshu/app/src/blocks/Phase2CollectLinksBlock.js +1249 -0
  149. package/dist/modules/xiaohongshu/app/src/blocks/Phase2SearchBlock.js +703 -0
  150. package/dist/modules/xiaohongshu/app/src/blocks/Phase34CloseDetailBlock.js +41 -0
  151. package/dist/modules/xiaohongshu/app/src/blocks/Phase34CloseTabsBlock.js +44 -0
  152. package/dist/modules/xiaohongshu/app/src/blocks/Phase34CollectCommentsBlock.js +150 -0
  153. package/dist/modules/xiaohongshu/app/src/blocks/Phase34ExtractDetailBlock.js +117 -0
  154. package/dist/modules/xiaohongshu/app/src/blocks/Phase34OpenDetailBlock.js +102 -0
  155. package/dist/modules/xiaohongshu/app/src/blocks/Phase34OpenTabsBlock.js +109 -0
  156. package/dist/modules/xiaohongshu/app/src/blocks/Phase34PersistDetailBlock.js +117 -0
  157. package/dist/modules/xiaohongshu/app/src/blocks/Phase34ProcessSingleNoteBlock.js +114 -0
  158. package/dist/modules/xiaohongshu/app/src/blocks/Phase34ValidateLinksBlock.js +90 -0
  159. package/dist/modules/xiaohongshu/app/src/blocks/Phase3InteractBlock.js +1009 -0
  160. package/dist/modules/xiaohongshu/app/src/blocks/Phase4MultiTabHarvestBlock.js +233 -0
  161. package/dist/modules/xiaohongshu/app/src/blocks/ReplyInteractBlock.js +291 -0
  162. package/dist/modules/xiaohongshu/app/src/blocks/XhsDiscoverFallbackBlock.js +240 -0
  163. package/dist/modules/xiaohongshu/app/src/blocks/helpers/commentMatchDsl.js +126 -0
  164. package/dist/modules/xiaohongshu/app/src/blocks/helpers/commentMatcher.js +99 -0
  165. package/dist/modules/xiaohongshu/app/src/blocks/helpers/evidence.js +27 -0
  166. package/dist/modules/xiaohongshu/app/src/blocks/helpers/sharding.js +42 -0
  167. package/dist/modules/xiaohongshu/app/src/blocks/helpers/xhsComments.js +270 -0
  168. package/dist/modules/xiaohongshu/app/src/index.js +9 -0
  169. package/dist/modules/xiaohongshu/app/src/utils/checkpoints.js +222 -0
  170. package/dist/modules/xiaohongshu/app/src/utils/controllerAction.js +43 -0
  171. package/dist/services/controller/src/controller.js +1476 -0
  172. package/dist/services/controller/src/index.js +2 -0
  173. package/dist/services/controller/src/payload-normalizer.js +129 -0
  174. package/dist/services/shared/heartbeat.js +120 -0
  175. package/dist/services/shared/lib/errorHandler.js +2 -0
  176. package/dist/services/shared/serviceProcessLogger.js +139 -0
  177. package/dist/services/unified-api/RemoteBrowserSession.js +176 -0
  178. package/dist/services/unified-api/RemoteSessionManager.js +148 -0
  179. package/dist/services/unified-api/container-operations-handler.js +115 -0
  180. package/dist/services/unified-api/server.js +652 -0
  181. package/dist/services/unified-api/state-registry.js +274 -0
  182. package/dist/services/unified-api/task-persistence.js +66 -0
  183. package/dist/services/unified-api/task-state.js +130 -0
  184. package/modules/camo-runtime/src/autoscript/action-providers/xhs/search.mjs +12 -5
  185. package/modules/xiaohongshu/app/pnpm-lock.yaml +24 -0
  186. package/package.json +38 -10
  187. package/.beads/README.md +0 -81
  188. package/.beads/config.yaml +0 -67
  189. package/.beads/interactions.jsonl +0 -0
  190. package/.beads/issues.jsonl +0 -180
  191. package/.beads/metadata.json +0 -4
  192. package/.claude/settings.local.json +0 -10
  193. package/.github/workflows/ci.yml +0 -55
  194. package/AGENTS.md +0 -253
  195. package/apps/desktop-console/README.md +0 -27
  196. package/apps/desktop-console/package-lock.json +0 -897
  197. package/apps/desktop-console/package.json +0 -20
  198. package/apps/desktop-console/scripts/build-and-install.mjs +0 -19
  199. package/apps/desktop-console/scripts/build.mjs +0 -45
  200. package/apps/desktop-console/scripts/test-preload.mjs +0 -13
  201. package/apps/desktop-console/src/main/config.mts +0 -26
  202. package/apps/desktop-console/src/main/core-daemon-manager.mts +0 -131
  203. package/apps/desktop-console/src/main/desktop-settings.mts +0 -267
  204. package/apps/desktop-console/src/main/heartbeat-watchdog.mts +0 -50
  205. package/apps/desktop-console/src/main/heartbeat-watchdog.test.mts +0 -68
  206. package/apps/desktop-console/src/main/index-streaming.test.mts +0 -20
  207. package/apps/desktop-console/src/main/index.mts +0 -980
  208. package/apps/desktop-console/src/main/profile-store.mts +0 -239
  209. package/apps/desktop-console/src/main/profile-store.test.mts +0 -54
  210. package/apps/desktop-console/src/main/state-bridge.mts +0 -114
  211. package/apps/desktop-console/src/main/task-state-types.ts +0 -32
  212. package/apps/desktop-console/src/renderer/hooks/use-task-state.mts +0 -120
  213. package/apps/desktop-console/src/renderer/index.mts +0 -133
  214. package/apps/desktop-console/src/renderer/index.test.mts +0 -34
  215. package/apps/desktop-console/src/renderer/path-helpers.mts +0 -46
  216. package/apps/desktop-console/src/renderer/path-helpers.test.mts +0 -14
  217. package/apps/desktop-console/src/renderer/tabs/debug.mts +0 -48
  218. package/apps/desktop-console/src/renderer/tabs/debug.test.mts +0 -22
  219. package/apps/desktop-console/src/renderer/tabs/logs.mts +0 -421
  220. package/apps/desktop-console/src/renderer/tabs/logs.test.mts +0 -27
  221. package/apps/desktop-console/src/renderer/tabs/preflight.mts +0 -486
  222. package/apps/desktop-console/src/renderer/tabs/preflight.test.mts +0 -33
  223. package/apps/desktop-console/src/renderer/tabs/profile-pool.mts +0 -213
  224. package/apps/desktop-console/src/renderer/tabs/results.mts +0 -171
  225. package/apps/desktop-console/src/renderer/tabs/run.test.mts +0 -63
  226. package/apps/desktop-console/src/renderer/tabs/runtime.mts +0 -151
  227. package/apps/desktop-console/src/renderer/tabs/settings.mts +0 -146
  228. package/apps/desktop-console/src/renderer/tabs/xiaohongshu/account-flow.mts +0 -486
  229. package/apps/desktop-console/src/renderer/tabs/xiaohongshu/guide-browser-check.mts +0 -56
  230. package/apps/desktop-console/src/renderer/tabs/xiaohongshu/helpers.mts +0 -262
  231. package/apps/desktop-console/src/renderer/tabs/xiaohongshu/layout-block.mts +0 -430
  232. package/apps/desktop-console/src/renderer/tabs/xiaohongshu/live-stats.mts +0 -847
  233. package/apps/desktop-console/src/renderer/tabs/xiaohongshu/run-flow.mts +0 -443
  234. package/apps/desktop-console/src/renderer/tabs/xiaohongshu-state.mts +0 -425
  235. package/apps/desktop-console/src/renderer/tabs/xiaohongshu.mts +0 -497
  236. package/apps/desktop-console/src/renderer/tabs/xiaohongshu.test.mts +0 -291
  237. package/apps/desktop-console/src/renderer/ui-components.mts +0 -31
  238. package/docs/README_camoufox_chinese.md +0 -141
  239. package/docs/USAGE_V3.md +0 -163
  240. package/docs/arch/OCR_MACOS_PLUGIN.md +0 -39
  241. package/docs/arch/PORTS.md +0 -40
  242. package/docs/arch/REGRESSION_CHECKLIST.md +0 -121
  243. package/docs/arch/SEARCH_GATE.md +0 -224
  244. package/docs/arch/VIEWPORT_SAFETY.md +0 -182
  245. package/docs/arch/XIAOHONGSHU_OFFLINE_MOCK_DESIGN.md +0 -267
  246. package/docs/xiaohongshu-container-driven-summary.md +0 -221
  247. package/docs/xiaohongshu-full-collect-runbook.md +0 -134
  248. package/docs/xiaohongshu-next-steps.md +0 -228
  249. package/docs/xiaohongshu-quickstart.md +0 -73
  250. package/docs/xiaohongshu-workflow-summary.md +0 -227
  251. package/modules/container-registry/tests/container-registry.test.ts +0 -16
  252. package/modules/logging/tests/logging.test.ts +0 -38
  253. package/modules/operations/tests/operations.test.ts +0 -22
  254. package/modules/operations/tests/viewport-filter.test.ts +0 -161
  255. package/modules/operations/tests/visible-only.test.ts +0 -250
  256. package/modules/session-manager/tests/session-manager.test.ts +0 -23
  257. package/modules/state/src/atomic-json.test.ts +0 -30
  258. package/modules/state/src/paths.test.ts +0 -59
  259. package/modules/state/src/xiaohongshu-collect-state.test.ts +0 -259
  260. package/modules/workflow/blocks/AnchorVerificationBlock.d.ts.map +0 -1
  261. package/modules/workflow/blocks/AnchorVerificationBlock.js.map +0 -1
  262. package/modules/workflow/blocks/DetectPageStateBlock.d.ts.map +0 -1
  263. package/modules/workflow/blocks/DetectPageStateBlock.js.map +0 -1
  264. package/modules/workflow/blocks/ErrorRecoveryBlock.d.ts.map +0 -1
  265. package/modules/workflow/blocks/ErrorRecoveryBlock.js.map +0 -1
  266. package/modules/workflow/blocks/WaitSearchPermitBlock.d.ts.map +0 -1
  267. package/modules/workflow/blocks/WaitSearchPermitBlock.js.map +0 -1
  268. package/modules/workflow/blocks/helpers/containerAnchors.d.ts.map +0 -1
  269. package/modules/workflow/blocks/helpers/containerAnchors.js.map +0 -1
  270. package/modules/workflow/blocks/helpers/downloadPaths.test.ts +0 -62
  271. package/modules/workflow/blocks/helpers/mergeXhsMarkdown.test.ts +0 -121
  272. package/modules/workflow/blocks/helpers/operationLogger.d.ts.map +0 -1
  273. package/modules/workflow/blocks/helpers/operationLogger.js.map +0 -1
  274. package/modules/workflow/blocks/helpers/persistedNotes.test.ts +0 -268
  275. package/modules/workflow/blocks/helpers/searchPageState.d.ts.map +0 -1
  276. package/modules/workflow/blocks/helpers/searchPageState.js.map +0 -1
  277. package/modules/workflow/blocks/helpers/targetCountMode.test.ts +0 -29
  278. package/modules/workflow/blocks/helpers/xhsCliArgs.test.ts +0 -75
  279. package/modules/workflow/tests/smartReply.test.ts +0 -32
  280. package/modules/xiaohongshu/app/src/blocks/Phase3Interact.matcher.test.ts +0 -33
  281. package/modules/xiaohongshu/app/src/utils/__tests__/checkpoints.test.ts +0 -141
  282. package/modules/xiaohongshu/app/tests/commentMatchDsl.test.ts +0 -50
  283. package/modules/xiaohongshu/app/tests/commentMatcher.test.ts +0 -46
  284. package/modules/xiaohongshu/app/tests/sharding.test.ts +0 -31
  285. package/package-scripts.json +0 -8
  286. package/runtime/infra/utils/README.md +0 -13
  287. package/runtime/infra/utils/scripts/README.md +0 -0
  288. package/runtime/infra/utils/scripts/development/eval-in-session.mjs +0 -40
  289. package/runtime/infra/utils/scripts/development/highlight-search-containers.mjs +0 -35
  290. package/runtime/infra/utils/scripts/service/kill-port.mjs +0 -24
  291. package/runtime/infra/utils/scripts/service/start-api.mjs +0 -39
  292. package/runtime/infra/utils/scripts/service/start-browser-service.mjs +0 -106
  293. package/runtime/infra/utils/scripts/service/stop-api.mjs +0 -18
  294. package/runtime/infra/utils/scripts/service/stop-browser-service.mjs +0 -104
  295. package/runtime/infra/utils/scripts/test-services.mjs +0 -94
  296. package/services/shared/heartbeat.test.ts +0 -102
  297. package/services/unified-api/__tests__/task-state.test.ts +0 -95
  298. package/sitecustomize.py +0 -19
  299. package/tests/README.md +0 -194
  300. package/tests/e2e/workflows/weibo-feed-extraction.test.ts +0 -171
  301. package/tests/fixtures/data/container-definitions.json +0 -67
  302. package/tests/fixtures/pages/simple-page.html +0 -69
  303. package/tests/integration/01-test-container-match.mjs +0 -188
  304. package/tests/integration/02-test-dom-branch.mjs +0 -161
  305. package/tests/integration/03-test-container-operation-system.mjs +0 -91
  306. package/tests/integration/05-test-container-lifecycle-events.mjs +0 -224
  307. package/tests/integration/05-test-container-lifecycle-with-events.mjs +0 -250
  308. package/tests/integration/06-test-container-dom-tree-drawing.mjs +0 -256
  309. package/tests/integration/07-test-weibo-container-lifecycle.mjs +0 -355
  310. package/tests/integration/08-test-weibo-feed-workflow.test.mjs +0 -164
  311. package/tests/integration/10-test-visual-analyzer.mjs +0 -312
  312. package/tests/integration/11-test-visual-loop.mjs +0 -284
  313. package/tests/integration/12-test-simple-visual-loop.mjs +0 -242
  314. package/tests/integration/13-test-visual-robust.mjs +0 -185
  315. package/tests/integration/14-test-visual-highlight-loop.mjs +0 -271
  316. package/tests/integration/inspect-page.mjs +0 -50
  317. package/tests/integration/run-all-tests.mjs +0 -95
  318. package/tests/patch_verification/CODEX_PATCH_TEST.md +0 -103
  319. package/tests/patch_verification/PHASE2_ANALYSIS.md +0 -179
  320. package/tests/patch_verification/PHASE2_OPTIMIZATION_REPORT.md +0 -55
  321. package/tests/patch_verification/PHASE2_TO_PHASE4_SUMMARY.md +0 -126
  322. package/tests/patch_verification/QUICK_TEST_SEQUENCE.md +0 -262
  323. package/tests/patch_verification/README.md +0 -143
  324. package/tests/patch_verification/RUN_TESTS.md +0 -60
  325. package/tests/patch_verification/TEST_EXECUTION.md +0 -99
  326. package/tests/patch_verification/TEST_PLAN.md +0 -328
  327. package/tests/patch_verification/TEST_RESULTS.md +0 -34
  328. package/tests/patch_verification/TOOL_TEST_PLAN.md +0 -48
  329. package/tests/patch_verification/run-tool-test.mjs +0 -121
  330. package/tests/patch_verification/temp_test_files/test01.txt +0 -1
  331. package/tests/patch_verification/temp_test_files/test02.txt +0 -3
  332. package/tests/patch_verification/temp_test_files/test02_gnu.txt +0 -3
  333. package/tests/patch_verification/temp_test_files/test03.txt +0 -1
  334. package/tests/patch_verification/temp_test_files/test03_multiline.txt +0 -5
  335. package/tests/patch_verification/temp_test_files/test04_function.ts +0 -5
  336. package/tests/patch_verification/temp_test_files/test05_import.ts +0 -4
  337. package/tests/patch_verification/temp_test_files/test06_special_chars.txt +0 -4
  338. package/tests/patch_verification/temp_test_files/test07_indentation.ts +0 -5
  339. package/tests/patch_verification/temp_test_files/test08_mismatch.txt +0 -1
  340. package/tests/patch_verification/temp_test_files/test_add_02.txt +0 -3
  341. package/tests/patch_verification/temp_test_files/test_simple.txt +0 -1
  342. package/tests/runner/TestReporter.mjs +0 -57
  343. package/tests/runner/TestRunner.mjs +0 -244
  344. package/tests/unit/commands/profile.test.mjs +0 -10
  345. package/tests/unit/container/change-notifier.test.mjs +0 -181
  346. package/tests/unit/lifecycle/session-registry.test.mjs +0 -135
  347. package/tests/unit/operations/registry.test.ts +0 -73
  348. package/tests/unit/utils/browser-service.test.mjs +0 -153
  349. package/tests/unit/utils/config.test.mjs +0 -166
  350. package/tests/unit/utils/fingerprint.test.mjs +0 -166
  351. package/tsconfig.json +0 -31
  352. package/tsconfig.services.json +0 -26
  353. /package/apps/desktop-console/{src → dist}/renderer/index.html +0 -0
  354. /package/apps/desktop-console/{src/renderer/tabs → dist/renderer}/run.mts +0 -0
@@ -0,0 +1,575 @@
1
+ import http from 'http';
2
+ import { fileURLToPath } from 'node:url';
3
+ import os from 'node:os';
4
+ import { spawnSync } from 'node:child_process';
5
+ import { SessionManager, SESSION_CLOSED_EVENT, } from './internal/SessionManager.js';
6
+ import { BrowserWsServer } from './internal/ws-server.js';
7
+ import { logDebug } from '../../../modules/logging/src/index.js';
8
+ import { installServiceProcessLogger } from '../../../services/shared/serviceProcessLogger.js';
9
+ import { startHeartbeatWriter } from '../../../services/shared/heartbeat.js';
10
+ const clients = new Set();
11
+ const autoLoops = new Map();
12
+ function readNumber(value) {
13
+ if (!value)
14
+ return null;
15
+ const parsed = Number(value);
16
+ if (!Number.isFinite(parsed) || parsed <= 0)
17
+ return null;
18
+ return parsed;
19
+ }
20
+ function getDisplayMetrics() {
21
+ const envWidth = readNumber(process.env.WEBAUTO_SCREEN_WIDTH);
22
+ const envHeight = readNumber(process.env.WEBAUTO_SCREEN_HEIGHT);
23
+ if (envWidth && envHeight) {
24
+ return { width: envWidth, height: envHeight, source: 'env' };
25
+ }
26
+ if (os.platform() === 'darwin') {
27
+ try {
28
+ const sp = spawnSync('system_profiler', ['SPDisplaysDataType', '-json'], { encoding: 'utf8' });
29
+ const spJson = sp.status === 0 && sp.stdout ? JSON.parse(sp.stdout) : null;
30
+ let width = null;
31
+ let height = null;
32
+ const displays = spJson?.SPDisplaysDataType;
33
+ if (Array.isArray(displays) && displays.length > 0) {
34
+ const first = displays[0];
35
+ const gpus = first?._items;
36
+ const maybe = Array.isArray(gpus) && gpus.length > 0 ? gpus[0] : first;
37
+ const resStr = maybe?.spdisplays_ndrvs?.[0]?._spdisplays_resolution || maybe?._spdisplays_resolution;
38
+ if (typeof resStr === 'string') {
39
+ const m = resStr.match(/(\d+)\s*x\s*(\d+)/i);
40
+ if (m) {
41
+ width = readNumber(m[1]);
42
+ height = readNumber(m[2]);
43
+ }
44
+ }
45
+ }
46
+ const osascript = spawnSync('osascript', [
47
+ '-l',
48
+ 'JavaScript',
49
+ '-e',
50
+ `ObjC.import('AppKit');
51
+ const s = $.NSScreen.mainScreen;
52
+ const f = s.frame;
53
+ const v = s.visibleFrame;
54
+ JSON.stringify({
55
+ width: Number(f.size.width),
56
+ height: Number(f.size.height),
57
+ workWidth: Number(v.size.width),
58
+ workHeight: Number(v.size.height)
59
+ });`,
60
+ ], { encoding: 'utf8' });
61
+ const vf = osascript.status === 0 && osascript.stdout ? JSON.parse(osascript.stdout.trim()) : null;
62
+ const finalW = readNumber(vf?.width) || width;
63
+ const finalH = readNumber(vf?.height) || height;
64
+ const workWidth = readNumber(vf?.workWidth);
65
+ const workHeight = readNumber(vf?.workHeight);
66
+ if (!finalW || !finalH)
67
+ return null;
68
+ return {
69
+ width: finalW,
70
+ height: finalH,
71
+ ...(workWidth ? { workWidth } : {}),
72
+ ...(workHeight ? { workHeight } : {}),
73
+ source: 'darwin',
74
+ };
75
+ }
76
+ catch {
77
+ return null;
78
+ }
79
+ }
80
+ if (os.platform() !== 'win32')
81
+ return null;
82
+ try {
83
+ const script = [
84
+ 'Add-Type -AssemblyName System.Windows.Forms;',
85
+ '$screen=[System.Windows.Forms.Screen]::PrimaryScreen;',
86
+ '$b=$screen.Bounds;',
87
+ '$w=$screen.WorkingArea;',
88
+ '$video=Get-CimInstance Win32_VideoController | Select-Object -First 1;',
89
+ '$nw=$null;$nh=$null;',
90
+ 'if ($video) { $nw=$video.CurrentHorizontalResolution; $nh=$video.CurrentVerticalResolution }',
91
+ '$o=[pscustomobject]@{width=$b.Width;height=$b.Height;workWidth=$w.Width;workHeight=$w.Height;nativeWidth=$nw;nativeHeight=$nh};',
92
+ '$o | ConvertTo-Json -Compress',
93
+ ].join(' ');
94
+ const res = spawnSync('powershell', ['-NoProfile', '-Command', script], {
95
+ encoding: 'utf8',
96
+ windowsHide: true,
97
+ });
98
+ if (res.status !== 0 || !res.stdout)
99
+ return null;
100
+ const payload = JSON.parse(res.stdout.trim());
101
+ const nativeWidth = readNumber(payload?.nativeWidth);
102
+ const nativeHeight = readNumber(payload?.nativeHeight);
103
+ const width = readNumber(payload?.width) || nativeWidth || null;
104
+ const height = readNumber(payload?.height) || nativeHeight || null;
105
+ const workWidth = readNumber(payload?.workWidth);
106
+ const workHeight = readNumber(payload?.workHeight);
107
+ if (!width || !height)
108
+ return null;
109
+ return {
110
+ width,
111
+ height,
112
+ ...(workWidth ? { workWidth } : {}),
113
+ ...(workHeight ? { workHeight } : {}),
114
+ ...(nativeWidth ? { nativeWidth } : {}),
115
+ ...(nativeHeight ? { nativeHeight } : {}),
116
+ source: 'win32',
117
+ };
118
+ }
119
+ catch {
120
+ return null;
121
+ }
122
+ }
123
+ export async function startBrowserService(opts = {}) {
124
+ const { logEvent } = installServiceProcessLogger({ serviceName: 'browser-service' });
125
+ const host = opts.host || '127.0.0.1';
126
+ const port = Number(opts.port || 7704);
127
+ const sessionManager = new SessionManager();
128
+ const enableWs = opts.enableWs ?? process.env.BROWSER_SERVICE_DISABLE_WS !== '1';
129
+ const wsHost = opts.wsHost || '127.0.0.1';
130
+ const wsPort = Number(opts.wsPort || 8765);
131
+ const autoExit = process.env.BROWSER_SERVICE_AUTO_EXIT === '1';
132
+ const heartbeat = startHeartbeatWriter({ initialStatus: 'idle' });
133
+ let heartbeatStatus = 'idle';
134
+ let hasActiveSession = false;
135
+ const setHeartbeatStatus = (next) => {
136
+ if (heartbeatStatus === next)
137
+ return;
138
+ heartbeatStatus = next;
139
+ heartbeat.setStatus(next);
140
+ };
141
+ const markSessionStarted = () => {
142
+ hasActiveSession = true;
143
+ setHeartbeatStatus('running');
144
+ };
145
+ const markAllSessionsClosed = () => {
146
+ if (!hasActiveSession)
147
+ return;
148
+ setHeartbeatStatus('stopped');
149
+ };
150
+ logDebug('browser-service', 'start', { host, port, wsHost, wsPort, enableWs, autoExit });
151
+ let wsServer = null;
152
+ const server = http.createServer((req, res) => {
153
+ void (async () => {
154
+ const url = new URL(req.url || '/', `http://${req.headers.host}`);
155
+ res.setHeader('Access-Control-Allow-Origin', '*');
156
+ res.setHeader('Access-Control-Allow-Methods', 'GET, POST, OPTIONS');
157
+ res.setHeader('Access-Control-Allow-Headers', 'Content-Type');
158
+ if (req.method === 'OPTIONS') {
159
+ res.writeHead(200);
160
+ res.end();
161
+ return;
162
+ }
163
+ if (url.pathname === '/health') {
164
+ res.writeHead(200, { 'Content-Type': 'application/json' });
165
+ res.end(JSON.stringify({ ok: true }));
166
+ return;
167
+ }
168
+ if (url.pathname === '/events') {
169
+ res.writeHead(200, {
170
+ 'Content-Type': 'text/event-stream',
171
+ Connection: 'keep-alive',
172
+ 'Cache-Control': 'no-cache',
173
+ });
174
+ clients.add(res);
175
+ req.on('close', () => clients.delete(res));
176
+ return;
177
+ }
178
+ if (url.pathname === '/command' && req.method === 'POST') {
179
+ const chunks = [];
180
+ req.on('data', (chunk) => chunks.push(chunk));
181
+ req.on('end', async () => {
182
+ try {
183
+ const payload = JSON.parse(Buffer.concat(chunks).toString('utf-8'));
184
+ const t0 = Date.now();
185
+ const action = String(payload?.action || '');
186
+ const profileId = String(payload?.args?.profileId || payload?.args?.profile || payload?.args?.sessionId || '');
187
+ logEvent('browser.command.start', { action, profileId });
188
+ const result = await handleCommand(payload, sessionManager, wsServer, { onSessionStart: markSessionStarted });
189
+ logEvent('browser.command.done', { action, profileId, ok: result.ok, ms: Date.now() - t0 });
190
+ res.writeHead(result.ok ? 200 : 500, { 'Content-Type': 'application/json' });
191
+ res.end(JSON.stringify(result.body));
192
+ }
193
+ catch (err) {
194
+ logEvent('browser.command.error', { error: err?.message || String(err) });
195
+ res.writeHead(500, { 'Content-Type': 'application/json' });
196
+ res.end(JSON.stringify({ error: err.message }));
197
+ }
198
+ });
199
+ return;
200
+ }
201
+ res.writeHead(404);
202
+ res.end();
203
+ })().catch((err) => {
204
+ logEvent('http.request.error', {
205
+ method: req?.method,
206
+ url: req?.url,
207
+ error: { message: err?.message || String(err), stack: err?.stack },
208
+ });
209
+ try {
210
+ if (!res.headersSent)
211
+ res.writeHead(500, { 'Content-Type': 'application/json' });
212
+ res.end(JSON.stringify({ ok: false, error: 'Internal Server Error' }));
213
+ }
214
+ catch {
215
+ // ignore
216
+ }
217
+ });
218
+ });
219
+ server.listen(port, host, () => {
220
+ console.log(`BrowserService listening on http://${host}:${port}`);
221
+ });
222
+ if (enableWs) {
223
+ wsServer = new BrowserWsServer({ host: wsHost, port: wsPort, sessionManager });
224
+ try {
225
+ await wsServer.start();
226
+ }
227
+ catch (err) {
228
+ console.warn('[browser-service] failed to start WebSocket server:', err.message);
229
+ }
230
+ }
231
+ const stopWsServer = async () => {
232
+ if (!wsServer)
233
+ return;
234
+ await wsServer.stop().catch(() => { });
235
+ };
236
+ const shutdown = async () => {
237
+ heartbeat.stop();
238
+ server.close();
239
+ clients.forEach((client) => client.end());
240
+ autoLoops.forEach((timer) => clearInterval(timer));
241
+ await stopWsServer();
242
+ await sessionManager.shutdown();
243
+ };
244
+ process.on('SIGINT', shutdown);
245
+ process.on('SIGTERM', shutdown);
246
+ process.on(SESSION_CLOSED_EVENT, () => {
247
+ if (!managerIsIdle(sessionManager))
248
+ return;
249
+ markAllSessionsClosed();
250
+ if (autoExit || hasActiveSession) {
251
+ shutdown().finally(() => process.exit(0));
252
+ }
253
+ });
254
+ }
255
+ function managerIsIdle(manager) {
256
+ return manager.listSessions().length === 0;
257
+ }
258
+ async function handleCommand(payload, manager, wsServer, options = {}) {
259
+ const action = payload.action;
260
+ const args = payload.args ?? payload;
261
+ switch (action) {
262
+ case 'start': {
263
+ const opts = {
264
+ profileId: args.profileId || 'default',
265
+ sessionName: args.profileId || 'default',
266
+ headless: !!args.headless,
267
+ initialUrl: args.url,
268
+ engine: args.engine || 'camoufox',
269
+ fingerprintPlatform: args.fingerprintPlatform || null,
270
+ ...(args.ownerPid ? { ownerPid: args.ownerPid } : {}),
271
+ };
272
+ const res = await manager.createSession(opts);
273
+ options.onSessionStart?.();
274
+ broadcast('browser:started', { profileId: opts.profileId, sessionId: res.sessionId });
275
+ return { ok: true, body: { ok: true, sessionId: res.sessionId, profileId: opts.profileId } };
276
+ }
277
+ case 'goto': {
278
+ const profileId = args.profileId || 'default';
279
+ const session = manager.getSession(profileId);
280
+ if (!session)
281
+ throw new Error(`session for profile ${profileId} not started`);
282
+ await session.goto(args.url);
283
+ broadcast('page:navigated', { profileId, url: args.url });
284
+ return { ok: true, body: { ok: true } };
285
+ }
286
+ case 'getCookies': {
287
+ const profileId = args.profileId || 'default';
288
+ const session = manager.getSession(profileId);
289
+ if (!session)
290
+ throw new Error(`session for profile ${profileId} not started`);
291
+ const cookies = await session.getCookies();
292
+ return { ok: true, body: { ok: true, cookies } };
293
+ }
294
+ case 'saveCookies': {
295
+ const profileId = args.profileId || 'default';
296
+ const session = manager.getSession(profileId);
297
+ if (!session)
298
+ throw new Error(`session for profile ${profileId} not started`);
299
+ if (!args.path)
300
+ throw new Error('path required');
301
+ const result = await session.saveCookiesToFile(args.path);
302
+ return { ok: true, body: { ok: true, ...result } };
303
+ }
304
+ case 'saveCookiesIfStable': {
305
+ const profileId = args.profileId || 'default';
306
+ const session = manager.getSession(profileId);
307
+ if (!session)
308
+ throw new Error(`session for profile ${profileId} not started`);
309
+ if (!args.path)
310
+ throw new Error('path required');
311
+ const result = await session.saveCookiesIfStable(args.path, { minDelayMs: args.minDelayMs });
312
+ return { ok: true, body: { ok: true, saved: !!result, ...result } };
313
+ }
314
+ case 'loadCookies': {
315
+ const profileId = args.profileId || 'default';
316
+ const session = manager.getSession(profileId);
317
+ if (!session)
318
+ throw new Error(`session for profile ${profileId} not started`);
319
+ if (!args.path)
320
+ throw new Error('path required');
321
+ const result = await session.injectCookiesFromFile(args.path);
322
+ return { ok: true, body: { ok: true, ...result } };
323
+ }
324
+ case 'getStatus': {
325
+ return { ok: true, body: { ok: true, sessions: manager.listSessions() } };
326
+ }
327
+ case 'system:display': {
328
+ const metrics = getDisplayMetrics();
329
+ return { ok: true, body: { ok: true, metrics: metrics || null } };
330
+ }
331
+ case 'window:move': {
332
+ const profileId = args.profileId || 'default';
333
+ const session = manager.getSession(profileId);
334
+ if (!session)
335
+ throw new Error(`session for profile ${profileId} not started`);
336
+ const { x, y } = args;
337
+ await session.evaluate(`window.moveTo(${x}, ${y})`);
338
+ return { ok: true, body: { ok: true } };
339
+ }
340
+ case 'window:resize': {
341
+ const profileId = args.profileId || 'default';
342
+ const session = manager.getSession(profileId);
343
+ if (!session)
344
+ throw new Error(`session for profile ${profileId} not started`);
345
+ const { width, height } = args;
346
+ await session.evaluate(`window.resizeTo(${width}, ${height})`);
347
+ return { ok: true, body: { ok: true } };
348
+ }
349
+ case 'stop': {
350
+ const profileId = args.profileId || 'default';
351
+ const deleted = await manager.deleteSession(profileId);
352
+ return { ok: true, body: { ok: deleted } };
353
+ }
354
+ case 'service:shutdown': {
355
+ console.log('[BrowserService] Received shutdown command, gracefully terminating...');
356
+ const response = { ok: true, body: { message: 'Browser service shutting down' } };
357
+ setImmediate(async () => {
358
+ try {
359
+ if (wsServer) {
360
+ await wsServer.stop().catch(() => { });
361
+ }
362
+ await manager.shutdown();
363
+ console.log('[BrowserService] Shutdown complete');
364
+ process.exit(0);
365
+ }
366
+ catch (err) {
367
+ console.error('[BrowserService] Error during shutdown:', err);
368
+ process.exit(1);
369
+ }
370
+ });
371
+ return response;
372
+ }
373
+ case 'screenshot': {
374
+ const profileId = args.profileId || 'default';
375
+ const session = manager.getSession(profileId);
376
+ if (!session)
377
+ throw new Error(`session for profile ${profileId} not started`);
378
+ const buffer = await session.screenshot(!!args.fullPage);
379
+ return { ok: true, body: { success: true, data: buffer.toString('base64') } };
380
+ }
381
+ case 'evaluate': {
382
+ const profileId = args.profileId || 'default';
383
+ const session = manager.getSession(profileId);
384
+ if (!session)
385
+ throw new Error(`session for profile ${profileId} not started`);
386
+ const script = args.script;
387
+ if (!script || typeof script !== 'string')
388
+ throw new Error('script (string) is required');
389
+ const result = await session.evaluate(script);
390
+ return { ok: true, body: { ok: true, result } };
391
+ }
392
+ case 'page:list': {
393
+ const profileId = args.profileId || 'default';
394
+ const session = manager.getSession(profileId);
395
+ if (!session)
396
+ throw new Error(`session for profile ${profileId} not started`);
397
+ const pages = session.listPages();
398
+ const activeIndex = pages.find((p) => p.active)?.index ?? 0;
399
+ return { ok: true, body: { ok: true, pages, activeIndex } };
400
+ }
401
+ case 'page:new':
402
+ case 'newPage': {
403
+ const profileId = args.profileId || 'default';
404
+ const session = manager.getSession(profileId);
405
+ if (!session)
406
+ throw new Error(`session for profile ${profileId} not started`);
407
+ const url = args.url ? String(args.url) : undefined;
408
+ const result = await session.newPage(url);
409
+ broadcast('page:created', { profileId, index: result.index, url: result.url });
410
+ return { ok: true, body: { ok: true, ...result } };
411
+ }
412
+ case 'page:switch':
413
+ case 'switchControl': {
414
+ const profileId = args.profileId || 'default';
415
+ const session = manager.getSession(profileId);
416
+ if (!session)
417
+ throw new Error(`session for profile ${profileId} not started`);
418
+ const index = Number(args.index);
419
+ const result = await session.switchPage(index);
420
+ broadcast('page:switched', { profileId, index: result.index, url: result.url });
421
+ return { ok: true, body: { ok: true, ...result } };
422
+ }
423
+ case 'page:close': {
424
+ const profileId = args.profileId || 'default';
425
+ const session = manager.getSession(profileId);
426
+ if (!session)
427
+ throw new Error(`session for profile ${profileId} not started`);
428
+ const hasIndex = typeof args.index !== 'undefined' && args.index !== null;
429
+ const index = hasIndex ? Number(args.index) : undefined;
430
+ const result = await session.closePage(index);
431
+ broadcast('page:closed', { profileId, closedIndex: result.closedIndex, activeIndex: result.activeIndex });
432
+ return { ok: true, body: { ok: true, ...result } };
433
+ }
434
+ case 'page:back': {
435
+ const profileId = args.profileId || 'default';
436
+ const session = manager.getSession(profileId);
437
+ if (!session)
438
+ throw new Error(`session for profile ${profileId} not started`);
439
+ const result = await session.goBack();
440
+ broadcast('page:navigated', { profileId, url: result.url, via: 'page:back' });
441
+ return { ok: true, body: { ok: true, ...result } };
442
+ }
443
+ case 'page:setViewport': {
444
+ const profileId = args.profileId || 'default';
445
+ const session = manager.getSession(profileId);
446
+ if (!session)
447
+ throw new Error(`session for profile ${profileId} not started`);
448
+ const width = Number(args.width);
449
+ const height = Number(args.height);
450
+ const size = await session.setViewportSize({ width, height });
451
+ broadcast('page:viewport', { profileId, ...size });
452
+ return { ok: true, body: { ok: true, ...size } };
453
+ }
454
+ case 'autoCookies:start': {
455
+ const profileId = args.profileId || 'default';
456
+ const interval = Math.max(1000, Number(args.intervalMs) || 2500);
457
+ const existing = autoLoops.get(profileId);
458
+ if (existing)
459
+ clearInterval(existing);
460
+ const timer = setInterval(async () => {
461
+ const session = manager.getSession(profileId);
462
+ if (!session)
463
+ return;
464
+ try {
465
+ await session.saveCookiesForActivePage();
466
+ }
467
+ catch {
468
+ // ignore
469
+ }
470
+ }, interval);
471
+ autoLoops.set(profileId, timer);
472
+ return { ok: true, body: { ok: true } };
473
+ }
474
+ case 'autoCookies:stop': {
475
+ const profileId = args.profileId || 'default';
476
+ const timer = autoLoops.get(profileId);
477
+ if (timer)
478
+ clearInterval(timer);
479
+ autoLoops.delete(profileId);
480
+ return { ok: true, body: { ok: true } };
481
+ }
482
+ case 'autoCookies:status': {
483
+ const profileId = args.profileId || 'default';
484
+ return { ok: true, body: { ok: !!autoLoops.get(profileId) } };
485
+ }
486
+ case 'mouse:click': {
487
+ const profileId = args.profileId || 'default';
488
+ const session = manager.getSession(profileId);
489
+ if (!session)
490
+ throw new Error(`session for profile ${profileId} not started`);
491
+ const { x, y, button, clicks, delay } = args;
492
+ await session.mouseClick({ x: Number(x), y: Number(y), button, clicks, delay });
493
+ return { ok: true, body: { ok: true } };
494
+ }
495
+ case 'mouse:move': {
496
+ const profileId = args.profileId || 'default';
497
+ const session = manager.getSession(profileId);
498
+ if (!session)
499
+ throw new Error(`session for profile ${profileId} not started`);
500
+ const { x, y, steps } = args;
501
+ await session.mouseMove({ x: Number(x), y: Number(y), steps });
502
+ return { ok: true, body: { ok: true } };
503
+ }
504
+ case 'mouse:wheel': {
505
+ const profileId = args.profileId || 'default';
506
+ const session = manager.getSession(profileId);
507
+ if (!session)
508
+ throw new Error(`session for profile ${profileId} not started`);
509
+ const { deltaY, deltaX } = args;
510
+ await session.mouseWheel({ deltaY: Number(deltaY) || 0, deltaX: Number(deltaX) || 0 });
511
+ return { ok: true, body: { ok: true } };
512
+ }
513
+ case 'keyboard:type': {
514
+ const profileId = args.profileId || 'default';
515
+ const session = manager.getSession(profileId);
516
+ if (!session)
517
+ throw new Error(`session for profile ${profileId} not started`);
518
+ const { text, delay, submit } = args;
519
+ await session.keyboardType({
520
+ text: String(text ?? ''),
521
+ delay: typeof delay === 'number' ? delay : undefined,
522
+ submit: !!submit,
523
+ });
524
+ return { ok: true, body: { ok: true } };
525
+ }
526
+ case 'keyboard:press': {
527
+ const profileId = args.profileId || 'default';
528
+ const session = manager.getSession(profileId);
529
+ if (!session)
530
+ throw new Error(`session for profile ${profileId} not started`);
531
+ const { key, delay } = args;
532
+ await session.keyboardPress({
533
+ key: String(key ?? 'Enter'),
534
+ delay: typeof delay === 'number' ? delay : undefined,
535
+ });
536
+ return { ok: true, body: { ok: true } };
537
+ }
538
+ default:
539
+ throw new Error(`Unknown action: ${action}`);
540
+ }
541
+ }
542
+ function broadcast(event, data) {
543
+ const payload = `event: ${event}\ndata: ${JSON.stringify(data)}\n\n`;
544
+ clients.forEach((client) => {
545
+ try {
546
+ client.write(payload);
547
+ }
548
+ catch {
549
+ clients.delete(client);
550
+ }
551
+ });
552
+ }
553
+ export function parseBrowserServiceCliArgs(argv = process.argv) {
554
+ const hostArg = argv.indexOf('--host');
555
+ const portArg = argv.indexOf('--port');
556
+ const wsPortArg = argv.indexOf('--ws-port');
557
+ const wsHostArg = argv.indexOf('--ws-host');
558
+ const busUrlArg = argv.indexOf('--bus-url');
559
+ const disableWs = argv.includes('--no-ws');
560
+ return {
561
+ host: hostArg >= 0 ? argv[hostArg + 1] : '127.0.0.1',
562
+ port: portArg >= 0 ? Number(argv[portArg + 1]) : 7704,
563
+ wsPort: wsPortArg >= 0 ? Number(argv[wsPortArg + 1]) : 8765,
564
+ wsHost: wsHostArg >= 0 ? argv[wsHostArg + 1] : '127.0.0.1',
565
+ busUrl: busUrlArg >= 0 ? argv[busUrlArg + 1] : undefined,
566
+ enableWs: !disableWs,
567
+ };
568
+ }
569
+ export async function runBrowserServiceCli(argv = process.argv) {
570
+ await startBrowserService(parseBrowserServiceCliArgs(argv));
571
+ }
572
+ if (fileURLToPath(import.meta.url) === process.argv[1]) {
573
+ void runBrowserServiceCli(process.argv);
574
+ }
575
+ //# sourceMappingURL=index.js.map