@web-auto/webauto 0.1.1 → 0.1.2
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.
- package/apps/desktop-console/default-settings.json +1 -0
- package/apps/desktop-console/dist/main/index.mjs +1618 -0
- package/apps/desktop-console/{src → dist}/main/preload.mjs +10 -0
- package/apps/desktop-console/dist/renderer/index.js +3063 -0
- package/apps/desktop-console/entry/ui-console.mjs +299 -0
- package/apps/webauto/entry/account.mjs +356 -0
- package/apps/webauto/entry/lib/account-detect.mjs +160 -0
- package/apps/webauto/entry/lib/account-store.mjs +587 -0
- package/apps/webauto/entry/lib/profilepool.mjs +1 -1
- package/apps/webauto/entry/xhs-install.mjs +27 -3
- package/apps/webauto/entry/xhs-status.mjs +152 -0
- package/apps/webauto/entry/xhs-unified.mjs +595 -17
- package/bin/webauto.mjs +247 -12
- package/dist/apps/webauto/server.js +66 -0
- package/dist/modules/camo-backend/src/index.js +575 -0
- package/dist/modules/camo-backend/src/internal/BrowserSession.js +817 -0
- package/dist/modules/camo-backend/src/internal/ElementRegistry.js +61 -0
- package/dist/modules/camo-backend/src/internal/ProfileLock.js +85 -0
- package/dist/modules/camo-backend/src/internal/SessionManager.js +172 -0
- package/dist/modules/camo-backend/src/internal/container-matcher.js +852 -0
- package/dist/modules/camo-backend/src/internal/engine-manager.js +258 -0
- package/dist/modules/camo-backend/src/internal/fingerprint.js +203 -0
- package/dist/modules/camo-backend/src/internal/pageRuntime.js +29 -0
- package/dist/modules/camo-backend/src/internal/runtimeInjector.js +30 -0
- package/dist/modules/camo-backend/src/internal/state-bus.js +46 -0
- package/dist/modules/camo-backend/src/internal/storage-paths.js +36 -0
- package/dist/modules/camo-backend/src/internal/ws-server.js +1202 -0
- package/dist/modules/camo-runtime/src/utils/browser-service.mjs +423 -0
- package/dist/modules/camo-runtime/src/utils/config.mjs +77 -0
- package/dist/modules/container-registry/src/index.js +184 -0
- package/dist/modules/logging/src/index.js +92 -0
- package/dist/modules/operations/src/builtin.js +27 -0
- package/dist/modules/operations/src/container-binding.js +75 -0
- package/dist/modules/operations/src/executor.js +146 -0
- package/dist/modules/operations/src/operations/click.js +167 -0
- package/dist/modules/operations/src/operations/extract.js +204 -0
- package/dist/modules/operations/src/operations/find-child.js +17 -0
- package/dist/modules/operations/src/operations/highlight.js +138 -0
- package/dist/modules/operations/src/operations/key.js +61 -0
- package/dist/modules/operations/src/operations/navigate.js +148 -0
- package/dist/modules/operations/src/operations/scroll.js +126 -0
- package/dist/modules/operations/src/operations/type.js +190 -0
- package/dist/modules/operations/src/queue.js +100 -0
- package/dist/modules/operations/src/registry.js +11 -0
- package/dist/modules/operations/src/system/mouse.js +33 -0
- package/dist/modules/state/src/atomic-json.js +33 -0
- package/dist/modules/workflow/blocks/AnchorVerificationBlock.js +71 -0
- package/dist/modules/workflow/blocks/BehaviorRandomizer.js +26 -0
- package/dist/modules/workflow/blocks/CallWorkflowBlock.js +38 -0
- package/dist/modules/workflow/blocks/CloseDetailBlock.js +209 -0
- package/dist/modules/workflow/blocks/CollectBatch.js +137 -0
- package/dist/modules/workflow/blocks/CollectCommentsBlock.js +415 -0
- package/dist/modules/workflow/blocks/CollectSearchListBlock.js +599 -0
- package/dist/modules/workflow/blocks/CollectWeiboPosts.js +229 -0
- package/dist/modules/workflow/blocks/DetectPageStateBlock.js +259 -0
- package/dist/modules/workflow/blocks/EnsureLoginBlock.js +162 -0
- package/dist/modules/workflow/blocks/EnsureSession.js +426 -0
- package/dist/modules/workflow/blocks/ErrorClassifier.js +164 -0
- package/dist/modules/workflow/blocks/ErrorRecoveryBlock.js +319 -0
- package/dist/modules/workflow/blocks/ExpandCommentsBlock.js +1032 -0
- package/dist/modules/workflow/blocks/ExtractDetailBlock.js +310 -0
- package/dist/modules/workflow/blocks/ExtractPostFields.js +88 -0
- package/dist/modules/workflow/blocks/GenerateSmartReplyBlock.js +68 -0
- package/dist/modules/workflow/blocks/GoToSearchBlock.js +497 -0
- package/dist/modules/workflow/blocks/GracefulFallbackBlock.js +104 -0
- package/dist/modules/workflow/blocks/HighlightBlock.js +66 -0
- package/dist/modules/workflow/blocks/InitAutoScroll.js +65 -0
- package/dist/modules/workflow/blocks/LoadContainerDefinition.js +50 -0
- package/dist/modules/workflow/blocks/LoadContainerIndex.js +43 -0
- package/dist/modules/workflow/blocks/LocateAndGuardBlock.js +176 -0
- package/dist/modules/workflow/blocks/LoginRecoveryBlock.js +242 -0
- package/dist/modules/workflow/blocks/MatchContainers.js +64 -0
- package/dist/modules/workflow/blocks/MonitoringBlock.js +190 -0
- package/dist/modules/workflow/blocks/OpenDetailBlock.js +1240 -0
- package/dist/modules/workflow/blocks/OrganizeXhsNotesBlock.js +117 -0
- package/dist/modules/workflow/blocks/PersistXhsNoteBlock.js +270 -0
- package/dist/modules/workflow/blocks/PickSinglePost.js +69 -0
- package/dist/modules/workflow/blocks/ProgressTracker.js +125 -0
- package/dist/modules/workflow/blocks/RecordFixtureBlock.js +44 -0
- package/dist/modules/workflow/blocks/RenderMarkdown.js +48 -0
- package/dist/modules/workflow/blocks/SaveFile.js +54 -0
- package/dist/modules/workflow/blocks/ScrollNextBatch.js +72 -0
- package/dist/modules/workflow/blocks/SessionHealthBlock.js +73 -0
- package/dist/modules/workflow/blocks/StartBrowserService.js +45 -0
- package/dist/modules/workflow/blocks/ValidateContainerDefinition.js +67 -0
- package/dist/modules/workflow/blocks/ValidateExtract.js +35 -0
- package/dist/modules/workflow/blocks/WaitSearchPermitBlock.js +162 -0
- package/dist/modules/workflow/blocks/WaitStable.js +74 -0
- package/dist/modules/workflow/blocks/WarmupCommentsBlock.js +120 -0
- package/dist/modules/workflow/blocks/WorkflowExecutor.js +156 -0
- package/dist/modules/workflow/blocks/XiaohongshuCollectFromLinksBlock.js +1004 -0
- package/dist/modules/workflow/blocks/XiaohongshuCollectLinksBlock.js +1049 -0
- package/dist/modules/workflow/blocks/XiaohongshuFullCollectBlock.js +782 -0
- package/dist/modules/workflow/blocks/helpers/anchorVerify.js +198 -0
- package/dist/modules/workflow/blocks/helpers/asyncWorkQueue.js +53 -0
- package/dist/modules/workflow/blocks/helpers/commentScroller.js +334 -0
- package/dist/modules/workflow/blocks/helpers/commentSectionLocator.js +126 -0
- package/dist/modules/workflow/blocks/helpers/containerAnchors.js +301 -0
- package/dist/modules/workflow/blocks/helpers/debugArtifacts.js +6 -0
- package/dist/modules/workflow/blocks/helpers/downloadPaths.js +29 -0
- package/dist/modules/workflow/blocks/helpers/expandCommentsController.js +53 -0
- package/dist/modules/workflow/blocks/helpers/expandCommentsExtractor.js +129 -0
- package/dist/modules/workflow/blocks/helpers/macosVisionOcrPlugin.js +116 -0
- package/dist/modules/workflow/blocks/helpers/mergeXhsMarkdown.js +109 -0
- package/dist/modules/workflow/blocks/helpers/openDetailController.js +56 -0
- package/dist/modules/workflow/blocks/helpers/openDetailTypes.js +7 -0
- package/dist/modules/workflow/blocks/helpers/openDetailViewport.js +474 -0
- package/dist/modules/workflow/blocks/helpers/openDetailWaiter.js +104 -0
- package/dist/modules/workflow/blocks/helpers/operationLogger.js +195 -0
- package/dist/modules/workflow/blocks/helpers/persistedNotes.js +107 -0
- package/dist/modules/workflow/blocks/helpers/replyExpander.js +260 -0
- package/dist/modules/workflow/blocks/helpers/scrollIntoView.js +138 -0
- package/dist/modules/workflow/blocks/helpers/searchExecutor.js +328 -0
- package/dist/modules/workflow/blocks/helpers/searchGate.js +46 -0
- package/dist/modules/workflow/blocks/helpers/searchPageState.js +164 -0
- package/dist/modules/workflow/blocks/helpers/searchResultWaiter.js +64 -0
- package/dist/modules/workflow/blocks/helpers/simpleAnchor.js +134 -0
- package/dist/modules/workflow/blocks/helpers/smartReply.js +40 -0
- package/dist/modules/workflow/blocks/helpers/systemInput.js +635 -0
- package/dist/modules/workflow/blocks/helpers/targetCountMode.js +9 -0
- package/dist/modules/workflow/blocks/helpers/xhsCliArgs.js +80 -0
- package/dist/modules/workflow/blocks/helpers/xhsCommentDom.js +805 -0
- package/dist/modules/workflow/blocks/helpers/xhsNoteOrganizer.js +140 -0
- package/dist/modules/workflow/blocks/restore/RestorePhaseBlock.js +204 -0
- package/dist/modules/workflow/config/workflowRegistry.js +32 -0
- package/dist/modules/workflow/definitions/batch-collect-workflow.js +63 -0
- package/dist/modules/workflow/definitions/scroll-extract-workflow.js +74 -0
- package/dist/modules/workflow/definitions/xiaohongshu-collect-workflow-v2.js +81 -0
- package/dist/modules/workflow/definitions/xiaohongshu-collect-workflow.js +57 -0
- package/dist/modules/workflow/definitions/xiaohongshu-full-collect-workflow-v3.js +68 -0
- package/dist/modules/workflow/definitions/xiaohongshu-note-collect.js +49 -0
- package/dist/modules/workflow/definitions/xiaohongshu-phase1-workflow-v3.js +30 -0
- package/dist/modules/workflow/definitions/xiaohongshu-phase2-links-workflow-v3.js +40 -0
- package/dist/modules/workflow/definitions/xiaohongshu-phase3-collect-workflow-v1.js +54 -0
- package/dist/modules/workflow/definitions/xiaohongshu-phase34-from-links-workflow-v3.js +25 -0
- package/dist/modules/workflow/src/WeiboEventDrivenWorkflowRunner.js +308 -0
- package/dist/modules/workflow/src/context.js +70 -0
- package/dist/modules/workflow/src/index.js +5 -0
- package/dist/modules/workflow/src/orchestrator.js +230 -0
- package/dist/modules/workflow/src/runner.js +55 -0
- package/dist/modules/workflow/src/runtime.js +70 -0
- package/dist/modules/workflow/workflows/WeiboFeedExtractionWorkflow.js +359 -0
- package/dist/modules/workflow/workflows/XiaohongshuLoginWorkflow.js +110 -0
- package/dist/modules/xiaohongshu/app/src/blocks/MatchCommentsBlock.js +139 -0
- package/dist/modules/xiaohongshu/app/src/blocks/Phase1EnsureServicesBlock.js +36 -0
- package/dist/modules/xiaohongshu/app/src/blocks/Phase1MonitorCookieBlock.js +213 -0
- package/dist/modules/xiaohongshu/app/src/blocks/Phase1StartProfileBlock.js +121 -0
- package/dist/modules/xiaohongshu/app/src/blocks/Phase2CollectLinksBlock.js +1249 -0
- package/dist/modules/xiaohongshu/app/src/blocks/Phase2SearchBlock.js +703 -0
- package/dist/modules/xiaohongshu/app/src/blocks/Phase34CloseDetailBlock.js +41 -0
- package/dist/modules/xiaohongshu/app/src/blocks/Phase34CloseTabsBlock.js +44 -0
- package/dist/modules/xiaohongshu/app/src/blocks/Phase34CollectCommentsBlock.js +150 -0
- package/dist/modules/xiaohongshu/app/src/blocks/Phase34ExtractDetailBlock.js +117 -0
- package/dist/modules/xiaohongshu/app/src/blocks/Phase34OpenDetailBlock.js +102 -0
- package/dist/modules/xiaohongshu/app/src/blocks/Phase34OpenTabsBlock.js +109 -0
- package/dist/modules/xiaohongshu/app/src/blocks/Phase34PersistDetailBlock.js +117 -0
- package/dist/modules/xiaohongshu/app/src/blocks/Phase34ProcessSingleNoteBlock.js +114 -0
- package/dist/modules/xiaohongshu/app/src/blocks/Phase34ValidateLinksBlock.js +90 -0
- package/dist/modules/xiaohongshu/app/src/blocks/Phase3InteractBlock.js +1009 -0
- package/dist/modules/xiaohongshu/app/src/blocks/Phase4MultiTabHarvestBlock.js +233 -0
- package/dist/modules/xiaohongshu/app/src/blocks/ReplyInteractBlock.js +291 -0
- package/dist/modules/xiaohongshu/app/src/blocks/XhsDiscoverFallbackBlock.js +240 -0
- package/dist/modules/xiaohongshu/app/src/blocks/helpers/commentMatchDsl.js +126 -0
- package/dist/modules/xiaohongshu/app/src/blocks/helpers/commentMatcher.js +99 -0
- package/dist/modules/xiaohongshu/app/src/blocks/helpers/evidence.js +27 -0
- package/dist/modules/xiaohongshu/app/src/blocks/helpers/sharding.js +42 -0
- package/dist/modules/xiaohongshu/app/src/blocks/helpers/xhsComments.js +270 -0
- package/dist/modules/xiaohongshu/app/src/index.js +9 -0
- package/dist/modules/xiaohongshu/app/src/utils/checkpoints.js +222 -0
- package/dist/modules/xiaohongshu/app/src/utils/controllerAction.js +43 -0
- package/dist/services/controller/src/controller.js +1476 -0
- package/dist/services/controller/src/index.js +2 -0
- package/dist/services/controller/src/payload-normalizer.js +129 -0
- package/dist/services/shared/heartbeat.js +120 -0
- package/dist/services/shared/lib/errorHandler.js +2 -0
- package/dist/services/shared/serviceProcessLogger.js +139 -0
- package/dist/services/unified-api/RemoteBrowserSession.js +176 -0
- package/dist/services/unified-api/RemoteSessionManager.js +148 -0
- package/dist/services/unified-api/container-operations-handler.js +115 -0
- package/dist/services/unified-api/server.js +652 -0
- package/dist/services/unified-api/state-registry.js +274 -0
- package/dist/services/unified-api/task-persistence.js +66 -0
- package/dist/services/unified-api/task-state.js +130 -0
- package/modules/camo-runtime/src/autoscript/action-providers/xhs/search.mjs +12 -5
- package/modules/xiaohongshu/app/pnpm-lock.yaml +24 -0
- package/package.json +37 -9
- package/.beads/README.md +0 -81
- package/.beads/config.yaml +0 -67
- package/.beads/interactions.jsonl +0 -0
- package/.beads/issues.jsonl +0 -180
- package/.beads/metadata.json +0 -4
- package/.claude/settings.local.json +0 -10
- package/.github/workflows/ci.yml +0 -55
- package/AGENTS.md +0 -253
- package/apps/desktop-console/README.md +0 -27
- package/apps/desktop-console/package-lock.json +0 -897
- package/apps/desktop-console/package.json +0 -20
- package/apps/desktop-console/scripts/build-and-install.mjs +0 -19
- package/apps/desktop-console/scripts/build.mjs +0 -45
- package/apps/desktop-console/scripts/test-preload.mjs +0 -13
- package/apps/desktop-console/src/main/config.mts +0 -26
- package/apps/desktop-console/src/main/core-daemon-manager.mts +0 -131
- package/apps/desktop-console/src/main/desktop-settings.mts +0 -267
- package/apps/desktop-console/src/main/heartbeat-watchdog.mts +0 -50
- package/apps/desktop-console/src/main/heartbeat-watchdog.test.mts +0 -68
- package/apps/desktop-console/src/main/index-streaming.test.mts +0 -20
- package/apps/desktop-console/src/main/index.mts +0 -980
- package/apps/desktop-console/src/main/profile-store.mts +0 -239
- package/apps/desktop-console/src/main/profile-store.test.mts +0 -54
- package/apps/desktop-console/src/main/state-bridge.mts +0 -114
- package/apps/desktop-console/src/main/task-state-types.ts +0 -32
- package/apps/desktop-console/src/renderer/hooks/use-task-state.mts +0 -120
- package/apps/desktop-console/src/renderer/index.mts +0 -133
- package/apps/desktop-console/src/renderer/index.test.mts +0 -34
- package/apps/desktop-console/src/renderer/path-helpers.mts +0 -46
- package/apps/desktop-console/src/renderer/path-helpers.test.mts +0 -14
- package/apps/desktop-console/src/renderer/tabs/debug.mts +0 -48
- package/apps/desktop-console/src/renderer/tabs/debug.test.mts +0 -22
- package/apps/desktop-console/src/renderer/tabs/logs.mts +0 -421
- package/apps/desktop-console/src/renderer/tabs/logs.test.mts +0 -27
- package/apps/desktop-console/src/renderer/tabs/preflight.mts +0 -486
- package/apps/desktop-console/src/renderer/tabs/preflight.test.mts +0 -33
- package/apps/desktop-console/src/renderer/tabs/profile-pool.mts +0 -213
- package/apps/desktop-console/src/renderer/tabs/results.mts +0 -171
- package/apps/desktop-console/src/renderer/tabs/run.test.mts +0 -63
- package/apps/desktop-console/src/renderer/tabs/runtime.mts +0 -151
- package/apps/desktop-console/src/renderer/tabs/settings.mts +0 -146
- package/apps/desktop-console/src/renderer/tabs/xiaohongshu/account-flow.mts +0 -486
- package/apps/desktop-console/src/renderer/tabs/xiaohongshu/guide-browser-check.mts +0 -56
- package/apps/desktop-console/src/renderer/tabs/xiaohongshu/helpers.mts +0 -262
- package/apps/desktop-console/src/renderer/tabs/xiaohongshu/layout-block.mts +0 -430
- package/apps/desktop-console/src/renderer/tabs/xiaohongshu/live-stats.mts +0 -847
- package/apps/desktop-console/src/renderer/tabs/xiaohongshu/run-flow.mts +0 -443
- package/apps/desktop-console/src/renderer/tabs/xiaohongshu-state.mts +0 -425
- package/apps/desktop-console/src/renderer/tabs/xiaohongshu.mts +0 -497
- package/apps/desktop-console/src/renderer/tabs/xiaohongshu.test.mts +0 -291
- package/apps/desktop-console/src/renderer/ui-components.mts +0 -31
- package/docs/README_camoufox_chinese.md +0 -141
- package/docs/USAGE_V3.md +0 -163
- package/docs/arch/OCR_MACOS_PLUGIN.md +0 -39
- package/docs/arch/PORTS.md +0 -40
- package/docs/arch/REGRESSION_CHECKLIST.md +0 -121
- package/docs/arch/SEARCH_GATE.md +0 -224
- package/docs/arch/VIEWPORT_SAFETY.md +0 -182
- package/docs/arch/XIAOHONGSHU_OFFLINE_MOCK_DESIGN.md +0 -267
- package/docs/xiaohongshu-container-driven-summary.md +0 -221
- package/docs/xiaohongshu-full-collect-runbook.md +0 -134
- package/docs/xiaohongshu-next-steps.md +0 -228
- package/docs/xiaohongshu-quickstart.md +0 -73
- package/docs/xiaohongshu-workflow-summary.md +0 -227
- package/modules/container-registry/tests/container-registry.test.ts +0 -16
- package/modules/logging/tests/logging.test.ts +0 -38
- package/modules/operations/tests/operations.test.ts +0 -22
- package/modules/operations/tests/viewport-filter.test.ts +0 -161
- package/modules/operations/tests/visible-only.test.ts +0 -250
- package/modules/session-manager/tests/session-manager.test.ts +0 -23
- package/modules/state/src/atomic-json.test.ts +0 -30
- package/modules/state/src/paths.test.ts +0 -59
- package/modules/state/src/xiaohongshu-collect-state.test.ts +0 -259
- package/modules/workflow/blocks/AnchorVerificationBlock.d.ts.map +0 -1
- package/modules/workflow/blocks/AnchorVerificationBlock.js.map +0 -1
- package/modules/workflow/blocks/DetectPageStateBlock.d.ts.map +0 -1
- package/modules/workflow/blocks/DetectPageStateBlock.js.map +0 -1
- package/modules/workflow/blocks/ErrorRecoveryBlock.d.ts.map +0 -1
- package/modules/workflow/blocks/ErrorRecoveryBlock.js.map +0 -1
- package/modules/workflow/blocks/WaitSearchPermitBlock.d.ts.map +0 -1
- package/modules/workflow/blocks/WaitSearchPermitBlock.js.map +0 -1
- package/modules/workflow/blocks/helpers/containerAnchors.d.ts.map +0 -1
- package/modules/workflow/blocks/helpers/containerAnchors.js.map +0 -1
- package/modules/workflow/blocks/helpers/downloadPaths.test.ts +0 -62
- package/modules/workflow/blocks/helpers/mergeXhsMarkdown.test.ts +0 -121
- package/modules/workflow/blocks/helpers/operationLogger.d.ts.map +0 -1
- package/modules/workflow/blocks/helpers/operationLogger.js.map +0 -1
- package/modules/workflow/blocks/helpers/persistedNotes.test.ts +0 -268
- package/modules/workflow/blocks/helpers/searchPageState.d.ts.map +0 -1
- package/modules/workflow/blocks/helpers/searchPageState.js.map +0 -1
- package/modules/workflow/blocks/helpers/targetCountMode.test.ts +0 -29
- package/modules/workflow/blocks/helpers/xhsCliArgs.test.ts +0 -75
- package/modules/workflow/tests/smartReply.test.ts +0 -32
- package/modules/xiaohongshu/app/src/blocks/Phase3Interact.matcher.test.ts +0 -33
- package/modules/xiaohongshu/app/src/utils/__tests__/checkpoints.test.ts +0 -141
- package/modules/xiaohongshu/app/tests/commentMatchDsl.test.ts +0 -50
- package/modules/xiaohongshu/app/tests/commentMatcher.test.ts +0 -46
- package/modules/xiaohongshu/app/tests/sharding.test.ts +0 -31
- package/package-scripts.json +0 -8
- package/runtime/infra/utils/README.md +0 -13
- package/runtime/infra/utils/scripts/README.md +0 -0
- package/runtime/infra/utils/scripts/development/eval-in-session.mjs +0 -40
- package/runtime/infra/utils/scripts/development/highlight-search-containers.mjs +0 -35
- package/runtime/infra/utils/scripts/service/kill-port.mjs +0 -24
- package/runtime/infra/utils/scripts/service/start-api.mjs +0 -39
- package/runtime/infra/utils/scripts/service/start-browser-service.mjs +0 -106
- package/runtime/infra/utils/scripts/service/stop-api.mjs +0 -18
- package/runtime/infra/utils/scripts/service/stop-browser-service.mjs +0 -104
- package/runtime/infra/utils/scripts/test-services.mjs +0 -94
- package/services/shared/heartbeat.test.ts +0 -102
- package/services/unified-api/__tests__/task-state.test.ts +0 -95
- package/sitecustomize.py +0 -19
- package/tests/README.md +0 -194
- package/tests/e2e/workflows/weibo-feed-extraction.test.ts +0 -171
- package/tests/fixtures/data/container-definitions.json +0 -67
- package/tests/fixtures/pages/simple-page.html +0 -69
- package/tests/integration/01-test-container-match.mjs +0 -188
- package/tests/integration/02-test-dom-branch.mjs +0 -161
- package/tests/integration/03-test-container-operation-system.mjs +0 -91
- package/tests/integration/05-test-container-lifecycle-events.mjs +0 -224
- package/tests/integration/05-test-container-lifecycle-with-events.mjs +0 -250
- package/tests/integration/06-test-container-dom-tree-drawing.mjs +0 -256
- package/tests/integration/07-test-weibo-container-lifecycle.mjs +0 -355
- package/tests/integration/08-test-weibo-feed-workflow.test.mjs +0 -164
- package/tests/integration/10-test-visual-analyzer.mjs +0 -312
- package/tests/integration/11-test-visual-loop.mjs +0 -284
- package/tests/integration/12-test-simple-visual-loop.mjs +0 -242
- package/tests/integration/13-test-visual-robust.mjs +0 -185
- package/tests/integration/14-test-visual-highlight-loop.mjs +0 -271
- package/tests/integration/inspect-page.mjs +0 -50
- package/tests/integration/run-all-tests.mjs +0 -95
- package/tests/patch_verification/CODEX_PATCH_TEST.md +0 -103
- package/tests/patch_verification/PHASE2_ANALYSIS.md +0 -179
- package/tests/patch_verification/PHASE2_OPTIMIZATION_REPORT.md +0 -55
- package/tests/patch_verification/PHASE2_TO_PHASE4_SUMMARY.md +0 -126
- package/tests/patch_verification/QUICK_TEST_SEQUENCE.md +0 -262
- package/tests/patch_verification/README.md +0 -143
- package/tests/patch_verification/RUN_TESTS.md +0 -60
- package/tests/patch_verification/TEST_EXECUTION.md +0 -99
- package/tests/patch_verification/TEST_PLAN.md +0 -328
- package/tests/patch_verification/TEST_RESULTS.md +0 -34
- package/tests/patch_verification/TOOL_TEST_PLAN.md +0 -48
- package/tests/patch_verification/run-tool-test.mjs +0 -121
- package/tests/patch_verification/temp_test_files/test01.txt +0 -1
- package/tests/patch_verification/temp_test_files/test02.txt +0 -3
- package/tests/patch_verification/temp_test_files/test02_gnu.txt +0 -3
- package/tests/patch_verification/temp_test_files/test03.txt +0 -1
- package/tests/patch_verification/temp_test_files/test03_multiline.txt +0 -5
- package/tests/patch_verification/temp_test_files/test04_function.ts +0 -5
- package/tests/patch_verification/temp_test_files/test05_import.ts +0 -4
- package/tests/patch_verification/temp_test_files/test06_special_chars.txt +0 -4
- package/tests/patch_verification/temp_test_files/test07_indentation.ts +0 -5
- package/tests/patch_verification/temp_test_files/test08_mismatch.txt +0 -1
- package/tests/patch_verification/temp_test_files/test_add_02.txt +0 -3
- package/tests/patch_verification/temp_test_files/test_simple.txt +0 -1
- package/tests/runner/TestReporter.mjs +0 -57
- package/tests/runner/TestRunner.mjs +0 -244
- package/tests/unit/commands/profile.test.mjs +0 -10
- package/tests/unit/container/change-notifier.test.mjs +0 -181
- package/tests/unit/lifecycle/session-registry.test.mjs +0 -135
- package/tests/unit/operations/registry.test.ts +0 -73
- package/tests/unit/utils/browser-service.test.mjs +0 -153
- package/tests/unit/utils/config.test.mjs +0 -166
- package/tests/unit/utils/fingerprint.test.mjs +0 -166
- package/tsconfig.json +0 -31
- package/tsconfig.services.json +0 -26
- /package/apps/desktop-console/{src → dist}/renderer/index.html +0 -0
- /package/apps/desktop-console/{src/renderer/tabs → dist/renderer}/run.mts +0 -0
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 小红书关键词完整采集 Workflow v3(Phase2 + Phase3/4 一体编排)
|
|
3
|
+
*
|
|
4
|
+
* 流程:
|
|
5
|
+
* - EnsureSession / EnsureLogin
|
|
6
|
+
* - WaitSearchPermit + GoToSearch(对话框搜索,避免 URL 直达)
|
|
7
|
+
* - XiaohongshuFullCollectBlock:列表 → 详情 → 评论 → 持久化(~/.webauto/download)
|
|
8
|
+
*/
|
|
9
|
+
export const xiaohongshuFullCollectWorkflowV3 = {
|
|
10
|
+
id: 'xiaohongshu-collect-full-v3',
|
|
11
|
+
name: '小红书关键词完整采集(Phase3/4 编排)',
|
|
12
|
+
steps: [
|
|
13
|
+
{
|
|
14
|
+
blockName: 'EnsureSession',
|
|
15
|
+
input: {
|
|
16
|
+
profileId: '$sessionId',
|
|
17
|
+
url: 'https://www.xiaohongshu.com',
|
|
18
|
+
},
|
|
19
|
+
},
|
|
20
|
+
{
|
|
21
|
+
blockName: 'EnsureLoginBlock',
|
|
22
|
+
input: {
|
|
23
|
+
sessionId: '$sessionId',
|
|
24
|
+
maxWaitMs: 180000,
|
|
25
|
+
checkIntervalMs: 5000,
|
|
26
|
+
},
|
|
27
|
+
},
|
|
28
|
+
{
|
|
29
|
+
blockName: 'WaitSearchPermitBlock',
|
|
30
|
+
input: {
|
|
31
|
+
sessionId: '$sessionId',
|
|
32
|
+
keyword: '$keyword',
|
|
33
|
+
},
|
|
34
|
+
},
|
|
35
|
+
{
|
|
36
|
+
blockName: 'GoToSearchBlock',
|
|
37
|
+
input: {
|
|
38
|
+
sessionId: '$sessionId',
|
|
39
|
+
keyword: '$keyword',
|
|
40
|
+
},
|
|
41
|
+
},
|
|
42
|
+
{
|
|
43
|
+
blockName: 'XiaohongshuFullCollectBlock',
|
|
44
|
+
input: {
|
|
45
|
+
sessionId: '$sessionId',
|
|
46
|
+
keyword: '$keyword',
|
|
47
|
+
env: '$env',
|
|
48
|
+
targetCount: '$targetCount',
|
|
49
|
+
maxWarmupRounds: '$maxWarmupRounds',
|
|
50
|
+
allowClickCommentButton: '$allowClickCommentButton',
|
|
51
|
+
enableOcr: true,
|
|
52
|
+
ocrLanguages: '$ocrLanguages',
|
|
53
|
+
ocrConcurrency: 1,
|
|
54
|
+
},
|
|
55
|
+
},
|
|
56
|
+
{
|
|
57
|
+
blockName: 'OrganizeXhsNotesBlock',
|
|
58
|
+
input: {
|
|
59
|
+
platform: 'xiaohongshu',
|
|
60
|
+
env: '$env',
|
|
61
|
+
keyword: '$keyword',
|
|
62
|
+
ocrLanguages: '$ocrLanguages',
|
|
63
|
+
runOcr: false,
|
|
64
|
+
},
|
|
65
|
+
},
|
|
66
|
+
],
|
|
67
|
+
};
|
|
68
|
+
//# sourceMappingURL=xiaohongshu-full-collect-workflow-v3.js.map
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 小红书单条笔记采集 Workflow(离线仿真版)
|
|
3
|
+
*
|
|
4
|
+
* 约定:
|
|
5
|
+
* - 详情页(或仿真详情页)已在当前 session 中打开,并匹配 xiaohongshu_detail.modal_shell;
|
|
6
|
+
* - 不负责打开/关闭详情,只做提取评论 + 持久化;
|
|
7
|
+
* - 适用于基于本地仿真 HTML 的离线回放测试。
|
|
8
|
+
*/
|
|
9
|
+
export const xiaohongshuNoteCollectWorkflow = {
|
|
10
|
+
id: 'xiaohongshu-note-collect',
|
|
11
|
+
name: '小红书单条笔记采集(离线仿真)',
|
|
12
|
+
steps: [
|
|
13
|
+
{
|
|
14
|
+
blockName: 'AnchorVerificationBlock',
|
|
15
|
+
input: {
|
|
16
|
+
sessionId: '$sessionId',
|
|
17
|
+
containerId: 'xiaohongshu_detail.modal_shell',
|
|
18
|
+
operation: 'enter',
|
|
19
|
+
},
|
|
20
|
+
},
|
|
21
|
+
{
|
|
22
|
+
blockName: 'ExtractDetailBlock',
|
|
23
|
+
input: {
|
|
24
|
+
sessionId: '$sessionId',
|
|
25
|
+
},
|
|
26
|
+
},
|
|
27
|
+
{
|
|
28
|
+
blockName: 'CollectCommentsBlock',
|
|
29
|
+
input: {
|
|
30
|
+
sessionId: '$sessionId',
|
|
31
|
+
},
|
|
32
|
+
},
|
|
33
|
+
{
|
|
34
|
+
blockName: 'PersistXhsNoteBlock',
|
|
35
|
+
input: {
|
|
36
|
+
sessionId: '$sessionId',
|
|
37
|
+
env: '$env',
|
|
38
|
+
platform: 'xiaohongshu',
|
|
39
|
+
keyword: '$keyword',
|
|
40
|
+
noteId: '$noteId',
|
|
41
|
+
detailUrl: '$detailUrl',
|
|
42
|
+
// 由 ExtractDetailBlock / CollectCommentsBlock 写入的上下文字段
|
|
43
|
+
detail: '$detail',
|
|
44
|
+
commentsResult: '$comments',
|
|
45
|
+
},
|
|
46
|
+
},
|
|
47
|
+
],
|
|
48
|
+
};
|
|
49
|
+
//# sourceMappingURL=xiaohongshu-note-collect.js.map
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 小红书 Phase1 Workflow v3(仅会话 + 登录)
|
|
3
|
+
*
|
|
4
|
+
* 流程:
|
|
5
|
+
* - EnsureSession(固定高视口,降低第二排误点)
|
|
6
|
+
* - EnsureLoginBlock(容器驱动登录探针)
|
|
7
|
+
*/
|
|
8
|
+
export const xiaohongshuPhase1WorkflowV3 = {
|
|
9
|
+
id: 'xiaohongshu-phase1-v3',
|
|
10
|
+
name: '小红书 Phase1(会话 + 登录)',
|
|
11
|
+
steps: [
|
|
12
|
+
{
|
|
13
|
+
blockName: 'EnsureSession',
|
|
14
|
+
input: {
|
|
15
|
+
profileId: '$sessionId',
|
|
16
|
+
url: 'https://www.xiaohongshu.com',
|
|
17
|
+
headless: '$headless',
|
|
18
|
+
},
|
|
19
|
+
},
|
|
20
|
+
{
|
|
21
|
+
blockName: 'EnsureLoginBlock',
|
|
22
|
+
input: {
|
|
23
|
+
sessionId: '$sessionId',
|
|
24
|
+
maxWaitMs: 0,
|
|
25
|
+
checkIntervalMs: 5000,
|
|
26
|
+
},
|
|
27
|
+
},
|
|
28
|
+
],
|
|
29
|
+
};
|
|
30
|
+
//# sourceMappingURL=xiaohongshu-phase1-workflow-v3.js.map
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 小红书 Phase2 Workflow v3(搜索 + 链接采集)
|
|
3
|
+
*
|
|
4
|
+
* 流程:
|
|
5
|
+
* - WaitSearchPermit(SearchGate)
|
|
6
|
+
* - GoToSearch(对话框搜索,禁止 URL 直达)
|
|
7
|
+
* - XiaohongshuCollectLinksBlock(点击采集安全链接,searchUrl 严格一致)
|
|
8
|
+
*/
|
|
9
|
+
export const xiaohongshuPhase2LinksWorkflowV3 = {
|
|
10
|
+
id: 'xiaohongshu-phase2-links-v3',
|
|
11
|
+
name: '小红书 Phase2(搜索 + 链接采集)',
|
|
12
|
+
steps: [
|
|
13
|
+
{
|
|
14
|
+
blockName: 'WaitSearchPermitBlock',
|
|
15
|
+
input: {
|
|
16
|
+
sessionId: '$sessionId',
|
|
17
|
+
keyword: '$keyword',
|
|
18
|
+
},
|
|
19
|
+
},
|
|
20
|
+
{
|
|
21
|
+
blockName: 'GoToSearchBlock',
|
|
22
|
+
input: {
|
|
23
|
+
sessionId: '$sessionId',
|
|
24
|
+
keyword: '$keyword',
|
|
25
|
+
env: '$env',
|
|
26
|
+
},
|
|
27
|
+
},
|
|
28
|
+
{
|
|
29
|
+
blockName: 'XiaohongshuCollectLinksBlock',
|
|
30
|
+
input: {
|
|
31
|
+
sessionId: '$sessionId',
|
|
32
|
+
keyword: '$keyword',
|
|
33
|
+
env: '$env',
|
|
34
|
+
targetCount: '$targetCount',
|
|
35
|
+
targetCountMode: '$targetCountMode',
|
|
36
|
+
},
|
|
37
|
+
},
|
|
38
|
+
],
|
|
39
|
+
};
|
|
40
|
+
//# sourceMappingURL=xiaohongshu-phase2-links-workflow-v3.js.map
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 小红书 Phase3 采集 Workflow v1(仅详情落盘)
|
|
3
|
+
*
|
|
4
|
+
* 流程:
|
|
5
|
+
* - EnsureSession / EnsureLogin
|
|
6
|
+
* - WaitSearchPermit + GoToSearch(对话框搜索)
|
|
7
|
+
* - XiaohongshuFullCollectBlock(mode=phase3):列表 → 详情 → 持久化(~/.webauto/download)
|
|
8
|
+
*/
|
|
9
|
+
export const xiaohongshuPhase3CollectWorkflowV1 = {
|
|
10
|
+
id: 'xiaohongshu-collect-phase3-v1',
|
|
11
|
+
name: '小红书 Phase3 采集(仅详情)',
|
|
12
|
+
steps: [
|
|
13
|
+
{
|
|
14
|
+
blockName: 'EnsureSession',
|
|
15
|
+
input: {
|
|
16
|
+
profileId: '$sessionId',
|
|
17
|
+
url: 'https://www.xiaohongshu.com',
|
|
18
|
+
},
|
|
19
|
+
},
|
|
20
|
+
{
|
|
21
|
+
blockName: 'EnsureLoginBlock',
|
|
22
|
+
input: {
|
|
23
|
+
sessionId: '$sessionId',
|
|
24
|
+
maxWaitMs: 180000,
|
|
25
|
+
checkIntervalMs: 5000,
|
|
26
|
+
},
|
|
27
|
+
},
|
|
28
|
+
{
|
|
29
|
+
blockName: 'WaitSearchPermitBlock',
|
|
30
|
+
input: {
|
|
31
|
+
sessionId: '$sessionId',
|
|
32
|
+
keyword: '$keyword',
|
|
33
|
+
},
|
|
34
|
+
},
|
|
35
|
+
{
|
|
36
|
+
blockName: 'GoToSearchBlock',
|
|
37
|
+
input: {
|
|
38
|
+
sessionId: '$sessionId',
|
|
39
|
+
keyword: '$keyword',
|
|
40
|
+
},
|
|
41
|
+
},
|
|
42
|
+
{
|
|
43
|
+
blockName: 'XiaohongshuFullCollectBlock',
|
|
44
|
+
input: {
|
|
45
|
+
sessionId: '$sessionId',
|
|
46
|
+
keyword: '$keyword',
|
|
47
|
+
env: '$env',
|
|
48
|
+
targetCount: '$targetCount',
|
|
49
|
+
mode: 'phase3',
|
|
50
|
+
},
|
|
51
|
+
},
|
|
52
|
+
],
|
|
53
|
+
};
|
|
54
|
+
//# sourceMappingURL=xiaohongshu-phase3-collect-workflow-v1.js.map
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 小红书 Phase3/4 Workflow v3(基于 Phase2 links)
|
|
3
|
+
*
|
|
4
|
+
* 流程:
|
|
5
|
+
* - XiaohongshuCollectFromLinksBlock:按 phase2-links.jsonl 逐条新开详情 tab → 详情+评论 → 落盘
|
|
6
|
+
* - 评论:rotate4(每 tab 50 条,开满 4 个后循环)
|
|
7
|
+
*/
|
|
8
|
+
export const xiaohongshuPhase34FromLinksWorkflowV3 = {
|
|
9
|
+
id: 'xiaohongshu-phase34-from-links-v3',
|
|
10
|
+
name: '小红书 Phase3/4(从 Phase2 links 采集详情+评论)',
|
|
11
|
+
steps: [
|
|
12
|
+
{
|
|
13
|
+
blockName: 'XiaohongshuCollectFromLinksBlock',
|
|
14
|
+
input: {
|
|
15
|
+
sessionId: '$sessionId',
|
|
16
|
+
keyword: '$keyword',
|
|
17
|
+
env: '$env',
|
|
18
|
+
targetCount: '$targetCount',
|
|
19
|
+
targetCountMode: '$targetCountMode',
|
|
20
|
+
maxComments: '$maxComments',
|
|
21
|
+
},
|
|
22
|
+
},
|
|
23
|
+
],
|
|
24
|
+
};
|
|
25
|
+
//# sourceMappingURL=xiaohongshu-phase34-from-links-workflow-v3.js.map
|
|
@@ -0,0 +1,308 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 微博事件驱动工作流驱动器
|
|
3
|
+
* 支持配置驱动的容器操作和事件处理
|
|
4
|
+
*/
|
|
5
|
+
import { EventEmitter } from 'events';
|
|
6
|
+
export class WeiboEventDrivenWorkflowRunner extends EventEmitter {
|
|
7
|
+
config;
|
|
8
|
+
context;
|
|
9
|
+
posts = [];
|
|
10
|
+
variables = new Map();
|
|
11
|
+
isRunning = false;
|
|
12
|
+
currentStepId = null;
|
|
13
|
+
constructor(config, context) {
|
|
14
|
+
super();
|
|
15
|
+
this.config = config;
|
|
16
|
+
this.context = context;
|
|
17
|
+
}
|
|
18
|
+
async execute() {
|
|
19
|
+
try {
|
|
20
|
+
this.isRunning = true;
|
|
21
|
+
this.emit('workflow:start', { config: this.config });
|
|
22
|
+
// Step 1: 初始化会话
|
|
23
|
+
await this.ensureSession();
|
|
24
|
+
// Step 2: 执行步骤
|
|
25
|
+
await this.runSteps();
|
|
26
|
+
// Step 3: 输出结果
|
|
27
|
+
await this.generateOutput();
|
|
28
|
+
this.emit('workflow:complete', { totalExtracted: this.posts.length });
|
|
29
|
+
return {
|
|
30
|
+
success: true,
|
|
31
|
+
posts: this.posts,
|
|
32
|
+
totalExtracted: this.posts.length
|
|
33
|
+
};
|
|
34
|
+
}
|
|
35
|
+
catch (error) {
|
|
36
|
+
this.emit('workflow:error', { error: error.message });
|
|
37
|
+
return {
|
|
38
|
+
success: false,
|
|
39
|
+
posts: this.posts,
|
|
40
|
+
totalExtracted: this.posts.length,
|
|
41
|
+
error: error.message
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
finally {
|
|
45
|
+
this.isRunning = false;
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
async runSteps() {
|
|
49
|
+
// 初始步骤
|
|
50
|
+
const firstStep = this.config.steps[0];
|
|
51
|
+
if (firstStep) {
|
|
52
|
+
await this.executeStep(firstStep);
|
|
53
|
+
}
|
|
54
|
+
// 后续步骤根据状态驱动
|
|
55
|
+
while (this.isRunning) {
|
|
56
|
+
const nextStep = this.findNextStep();
|
|
57
|
+
if (!nextStep)
|
|
58
|
+
break;
|
|
59
|
+
await this.executeStep(nextStep);
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
findNextStep() {
|
|
63
|
+
for (const step of this.config.steps) {
|
|
64
|
+
if (step.status === 'idle' && step.enter) {
|
|
65
|
+
const prevStep = this.config.steps.find(s => s.id === step.enter?.when.step);
|
|
66
|
+
if (prevStep && prevStep.status === step.enter.when.status) {
|
|
67
|
+
return step;
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
return null;
|
|
72
|
+
}
|
|
73
|
+
async executeStep(step) {
|
|
74
|
+
this.currentStepId = step.id;
|
|
75
|
+
step.status = 'running';
|
|
76
|
+
this.emit('step:start', { step });
|
|
77
|
+
try {
|
|
78
|
+
// 检查条件
|
|
79
|
+
if (step.condition && !this.evaluateCondition(step.condition)) {
|
|
80
|
+
step.status = 'skipped';
|
|
81
|
+
this.emit('step:skip', { step, reason: 'condition not met' });
|
|
82
|
+
return;
|
|
83
|
+
}
|
|
84
|
+
// 执行动作(支持重复)
|
|
85
|
+
if (step.repeat) {
|
|
86
|
+
await this.executeRepeatActions(step);
|
|
87
|
+
}
|
|
88
|
+
else {
|
|
89
|
+
for (const action of step.actions) {
|
|
90
|
+
await this.executeAction(action);
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
step.status = 'completed';
|
|
94
|
+
this.emit('step:complete', { step });
|
|
95
|
+
}
|
|
96
|
+
catch (error) {
|
|
97
|
+
step.status = 'failed';
|
|
98
|
+
this.emit('step:failed', { step, error: error.message });
|
|
99
|
+
throw error;
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
async executeRepeatActions(step) {
|
|
103
|
+
const max = this.parseValue(step.repeat?.max || 1);
|
|
104
|
+
let count = 0;
|
|
105
|
+
while (count < max && this.isRunning) {
|
|
106
|
+
// 检查退出条件
|
|
107
|
+
if (step.repeat?.until?.condition) {
|
|
108
|
+
if (this.evaluateCondition(step.repeat.until.condition)) {
|
|
109
|
+
break;
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
for (const action of step.actions) {
|
|
113
|
+
await this.executeAction(action);
|
|
114
|
+
}
|
|
115
|
+
count++;
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
parseValue(value) {
|
|
119
|
+
if (typeof value === 'number')
|
|
120
|
+
return value;
|
|
121
|
+
if (typeof value === 'string' && value.startsWith('{{') && value.endsWith('}}')) {
|
|
122
|
+
const key = value.slice(2, -2).trim();
|
|
123
|
+
if (key.startsWith('config.')) {
|
|
124
|
+
const val = this.config.config[key.split('.')[1]];
|
|
125
|
+
return typeof val === 'number' ? val : Number(val);
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
return Number(value);
|
|
129
|
+
}
|
|
130
|
+
async ensureSession() {
|
|
131
|
+
this.emit('session:init-start');
|
|
132
|
+
const sessions = await this.context.apiClient.post('/v1/controller/action', {
|
|
133
|
+
action: 'session:list',
|
|
134
|
+
payload: {}
|
|
135
|
+
});
|
|
136
|
+
const active = sessions.data?.data?.sessions?.find((s) => s.profileId === this.config.config.profile);
|
|
137
|
+
if (!active) {
|
|
138
|
+
await this.context.apiClient.post('/v1/controller/action', {
|
|
139
|
+
action: 'session:create',
|
|
140
|
+
payload: {
|
|
141
|
+
profile: this.config.config.profile,
|
|
142
|
+
url: this.config.config.url
|
|
143
|
+
}
|
|
144
|
+
});
|
|
145
|
+
await new Promise(r => setTimeout(r, 5000));
|
|
146
|
+
}
|
|
147
|
+
this.emit('session:init-complete');
|
|
148
|
+
}
|
|
149
|
+
async executeAction(action) {
|
|
150
|
+
switch (action.type) {
|
|
151
|
+
case 'session.ensure':
|
|
152
|
+
await this.ensureSession();
|
|
153
|
+
break;
|
|
154
|
+
case 'container.match':
|
|
155
|
+
await this.matchContainers(this.resolveConfig(action.config));
|
|
156
|
+
break;
|
|
157
|
+
case 'container.operation':
|
|
158
|
+
await this.executeContainerOperation(action);
|
|
159
|
+
break;
|
|
160
|
+
case 'extract':
|
|
161
|
+
await this.extractPost(action);
|
|
162
|
+
break;
|
|
163
|
+
case 'variable.set':
|
|
164
|
+
this.setVariable(action.containerId || 'root', action.config?.variable, action.config?.value);
|
|
165
|
+
break;
|
|
166
|
+
case 'variable.increment':
|
|
167
|
+
this.incrementVariable(action.containerId || 'root', action.config?.variable);
|
|
168
|
+
break;
|
|
169
|
+
case 'format.output':
|
|
170
|
+
await this.generateOutput(); // Use internal method directly
|
|
171
|
+
break;
|
|
172
|
+
default:
|
|
173
|
+
this.emit('action:unknown', { action });
|
|
174
|
+
}
|
|
175
|
+
if (action.delay) {
|
|
176
|
+
const delayMs = this.parseValue(action.delay);
|
|
177
|
+
if (delayMs > 0) {
|
|
178
|
+
await new Promise(r => setTimeout(r, delayMs));
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
resolveConfig(config) {
|
|
183
|
+
if (!config)
|
|
184
|
+
return {};
|
|
185
|
+
const resolved = {};
|
|
186
|
+
for (const [key, value] of Object.entries(config)) {
|
|
187
|
+
if (typeof value === 'string' && value.startsWith('{{') && value.endsWith('}}')) {
|
|
188
|
+
const varKey = value.slice(2, -2).trim();
|
|
189
|
+
if (varKey.startsWith('config.')) {
|
|
190
|
+
resolved[key] = this.config.config[varKey.split('.')[1]];
|
|
191
|
+
}
|
|
192
|
+
else {
|
|
193
|
+
resolved[key] = value;
|
|
194
|
+
}
|
|
195
|
+
}
|
|
196
|
+
else {
|
|
197
|
+
resolved[key] = value;
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
return resolved;
|
|
201
|
+
}
|
|
202
|
+
async matchContainers(config) {
|
|
203
|
+
const result = await this.context.apiClient.post('/v1/controller/action', {
|
|
204
|
+
action: 'containers:match',
|
|
205
|
+
payload: config
|
|
206
|
+
});
|
|
207
|
+
if (!result.data?.matched) {
|
|
208
|
+
throw new Error('Root container not matched');
|
|
209
|
+
}
|
|
210
|
+
this.setVariable('root', 'rootContainerId', result.data.container.id);
|
|
211
|
+
this.emit('container:match', { rootId: result.data.container.id });
|
|
212
|
+
}
|
|
213
|
+
async executeContainerOperation(action) {
|
|
214
|
+
if (!action.containerId || !action.operationId) {
|
|
215
|
+
throw new Error('containerId and operationId are required for container.operation');
|
|
216
|
+
}
|
|
217
|
+
const config = this.resolveConfig(action.config);
|
|
218
|
+
await this.context.apiClient.post('/v1/controller/action', {
|
|
219
|
+
action: 'container:operation',
|
|
220
|
+
payload: {
|
|
221
|
+
containerId: action.containerId,
|
|
222
|
+
operationId: action.operationId,
|
|
223
|
+
config,
|
|
224
|
+
sessionId: this.config.config.profile
|
|
225
|
+
}
|
|
226
|
+
});
|
|
227
|
+
this.emit('container:operation', { action });
|
|
228
|
+
}
|
|
229
|
+
async extractPost(action) {
|
|
230
|
+
if (!action.containerId)
|
|
231
|
+
return;
|
|
232
|
+
const res = await this.context.apiClient.post('/v1/controller/action', {
|
|
233
|
+
action: 'container:operation',
|
|
234
|
+
payload: {
|
|
235
|
+
containerId: action.containerId,
|
|
236
|
+
operationId: 'extract',
|
|
237
|
+
config: action.config || {},
|
|
238
|
+
sessionId: this.config.config.profile
|
|
239
|
+
}
|
|
240
|
+
});
|
|
241
|
+
const extracted = res.data?.data?.extracted?.[0];
|
|
242
|
+
if (extracted) {
|
|
243
|
+
this.posts.push(extracted);
|
|
244
|
+
this.emit('post:extracted', { extracted, total: this.posts.length });
|
|
245
|
+
}
|
|
246
|
+
}
|
|
247
|
+
setVariable(containerId, key, value) {
|
|
248
|
+
this.variables.set(`${containerId}.${key}`, value);
|
|
249
|
+
this.emit('variable:set', { containerId, key, value });
|
|
250
|
+
}
|
|
251
|
+
incrementVariable(containerId, key) {
|
|
252
|
+
const current = this.variables.get(`${containerId}.${key}`) || 0;
|
|
253
|
+
this.variables.set(`${containerId}.${key}`, current + 1);
|
|
254
|
+
this.emit('variable:increment', { containerId, key, value: current + 1 });
|
|
255
|
+
}
|
|
256
|
+
evaluateCondition(condition) {
|
|
257
|
+
const key = `${condition.scope}.${condition.variable}`;
|
|
258
|
+
const value = this.variables.get(key) || 0;
|
|
259
|
+
const targetValue = this.parseValue(condition.value);
|
|
260
|
+
switch (condition.operator) {
|
|
261
|
+
case 'lt': return value < targetValue;
|
|
262
|
+
case 'lte': return value <= targetValue;
|
|
263
|
+
case 'gt': return value > targetValue;
|
|
264
|
+
case 'gte': return value >= targetValue;
|
|
265
|
+
case 'eq': return value === targetValue;
|
|
266
|
+
default: return false;
|
|
267
|
+
}
|
|
268
|
+
}
|
|
269
|
+
async generateOutput() {
|
|
270
|
+
if (this.config.outputs.format !== 'markdown')
|
|
271
|
+
return;
|
|
272
|
+
const fs = await import('fs/promises');
|
|
273
|
+
const lines = [
|
|
274
|
+
'# 微博主页采集结果 (事件驱动版)',
|
|
275
|
+
'',
|
|
276
|
+
`采集时间:${new Date().toLocaleString('zh-CN')}`,
|
|
277
|
+
`帖子数量:${this.posts.length}`,
|
|
278
|
+
'',
|
|
279
|
+
'---',
|
|
280
|
+
''
|
|
281
|
+
];
|
|
282
|
+
this.posts.forEach((post, index) => {
|
|
283
|
+
lines.push(`## ${index + 1}. ${post.author || '未知作者'}`);
|
|
284
|
+
lines.push('');
|
|
285
|
+
if (post.content) {
|
|
286
|
+
lines.push(`**内容:** ${post.content.substring(0, 500)}${post.content.length > 500 ? '...' : ''}`);
|
|
287
|
+
lines.push('');
|
|
288
|
+
}
|
|
289
|
+
if (post.url) {
|
|
290
|
+
lines.push(`**链接:** ${post.url}`);
|
|
291
|
+
lines.push('');
|
|
292
|
+
}
|
|
293
|
+
if (post.timestamp) {
|
|
294
|
+
lines.push(`**时间:** ${post.timestamp}`);
|
|
295
|
+
lines.push('');
|
|
296
|
+
}
|
|
297
|
+
if (post.authorUrl) {
|
|
298
|
+
lines.push(`**作者链接:** ${post.authorUrl}`);
|
|
299
|
+
lines.push('');
|
|
300
|
+
}
|
|
301
|
+
lines.push('---');
|
|
302
|
+
lines.push('');
|
|
303
|
+
});
|
|
304
|
+
await fs.writeFile(this.config.outputs.file, lines.join('\n'), 'utf-8');
|
|
305
|
+
this.emit('output:generated', { file: this.config.outputs.file });
|
|
306
|
+
}
|
|
307
|
+
}
|
|
308
|
+
//# sourceMappingURL=WeiboEventDrivenWorkflowRunner.js.map
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
function sanitizeArg(arg) {
|
|
2
|
+
if (typeof arg === 'undefined') {
|
|
3
|
+
return null;
|
|
4
|
+
}
|
|
5
|
+
return arg;
|
|
6
|
+
}
|
|
7
|
+
function buildScript(fn, args) {
|
|
8
|
+
if (typeof fn === 'string' && (!args || args.length === 0)) {
|
|
9
|
+
return fn;
|
|
10
|
+
}
|
|
11
|
+
const source = typeof fn === 'function' ? fn.toString() : fn;
|
|
12
|
+
const serializedArgs = JSON.stringify((args || []).map(sanitizeArg));
|
|
13
|
+
return `(() => {
|
|
14
|
+
const __name = (target, value) => {
|
|
15
|
+
try {
|
|
16
|
+
Object.defineProperty(target, 'name', { value, configurable: true });
|
|
17
|
+
} catch {}
|
|
18
|
+
return target;
|
|
19
|
+
};
|
|
20
|
+
const __fn = ${source};
|
|
21
|
+
const __args = ${serializedArgs};
|
|
22
|
+
return Promise.resolve(__fn(...__args));
|
|
23
|
+
})()`;
|
|
24
|
+
}
|
|
25
|
+
export class BrowserWorkflowContextProvider {
|
|
26
|
+
serviceHost;
|
|
27
|
+
servicePort;
|
|
28
|
+
profile;
|
|
29
|
+
constructor(options) {
|
|
30
|
+
this.profile = options.profile;
|
|
31
|
+
this.serviceHost = options.host || '127.0.0.1';
|
|
32
|
+
this.servicePort = typeof options.port === 'number' ? options.port : 7704;
|
|
33
|
+
}
|
|
34
|
+
async createContext() {
|
|
35
|
+
return {
|
|
36
|
+
page: {
|
|
37
|
+
evaluate: async (fn, ...args) => this.evaluate(fn, args),
|
|
38
|
+
},
|
|
39
|
+
logger: console,
|
|
40
|
+
};
|
|
41
|
+
}
|
|
42
|
+
async evaluate(fn, args) {
|
|
43
|
+
const script = buildScript(fn, args);
|
|
44
|
+
if (process.env.WORKFLOW_CONTEXT_DEBUG === '1') {
|
|
45
|
+
console.debug('[workflow:context] evaluate fn:', typeof fn === 'function' ? fn.toString() : fn);
|
|
46
|
+
console.debug('[workflow:context] script:', script);
|
|
47
|
+
}
|
|
48
|
+
const response = await this.command('evaluate', {
|
|
49
|
+
profileId: this.profile,
|
|
50
|
+
script,
|
|
51
|
+
});
|
|
52
|
+
if (response?.ok === false) {
|
|
53
|
+
throw new Error(response?.error || 'evaluate failed');
|
|
54
|
+
}
|
|
55
|
+
return typeof response?.result === 'undefined' ? response : response.result;
|
|
56
|
+
}
|
|
57
|
+
async command(action, args) {
|
|
58
|
+
const resp = await fetch(`http://${this.serviceHost}:${this.servicePort}/command`, {
|
|
59
|
+
method: 'POST',
|
|
60
|
+
headers: { 'content-type': 'application/json' },
|
|
61
|
+
body: JSON.stringify({ action, args }),
|
|
62
|
+
});
|
|
63
|
+
const payload = await resp.json().catch(() => ({}));
|
|
64
|
+
if (!resp.ok) {
|
|
65
|
+
return { ok: false, error: payload?.error || `command ${action} failed: HTTP ${resp.status}` };
|
|
66
|
+
}
|
|
67
|
+
return payload;
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
//# sourceMappingURL=context.js.map
|