@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.
- 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 +263 -15
- 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 +38 -10
- 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,310 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Workflow Block: ExtractDetailBlock
|
|
3
|
+
*
|
|
4
|
+
* 提取详情页内容(header/content/gallery)
|
|
5
|
+
*/
|
|
6
|
+
import { logControllerActionError, logControllerActionResult, logControllerActionStart, } from './helpers/operationLogger.js';
|
|
7
|
+
/**
|
|
8
|
+
* 提取详情页内容
|
|
9
|
+
*
|
|
10
|
+
* @param input - 输入参数
|
|
11
|
+
* @returns Promise<ExtractDetailOutput>
|
|
12
|
+
*/
|
|
13
|
+
export async function execute(input) {
|
|
14
|
+
const { sessionId, serviceUrl = 'http://127.0.0.1:7701' } = input;
|
|
15
|
+
const profile = sessionId;
|
|
16
|
+
const controllerUrl = `${serviceUrl}/v1/controller/action`;
|
|
17
|
+
async function controllerAction(action, payload = {}) {
|
|
18
|
+
const opId = logControllerActionStart(action, payload, { source: 'ExtractDetailBlock' });
|
|
19
|
+
try {
|
|
20
|
+
const response = await fetch(controllerUrl, {
|
|
21
|
+
method: 'POST',
|
|
22
|
+
headers: { 'Content-Type': 'application/json' },
|
|
23
|
+
body: JSON.stringify({ action, payload }),
|
|
24
|
+
// 防御性超时,避免 containers:match / operation 长时间挂起
|
|
25
|
+
signal: AbortSignal.timeout ? AbortSignal.timeout(10000) : undefined
|
|
26
|
+
});
|
|
27
|
+
if (!response.ok) {
|
|
28
|
+
throw new Error(`HTTP ${response.status}: ${await response.text()}`);
|
|
29
|
+
}
|
|
30
|
+
const data = await response.json();
|
|
31
|
+
const result = data.data || data;
|
|
32
|
+
logControllerActionResult(opId, action, result, { source: 'ExtractDetailBlock' });
|
|
33
|
+
return result;
|
|
34
|
+
}
|
|
35
|
+
catch (error) {
|
|
36
|
+
logControllerActionError(opId, action, error, payload, { source: 'ExtractDetailBlock' });
|
|
37
|
+
throw error;
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
async function extractContainer(containerId) {
|
|
41
|
+
const result = await controllerAction('container:operation', {
|
|
42
|
+
containerId,
|
|
43
|
+
operationId: 'extract',
|
|
44
|
+
config: {},
|
|
45
|
+
sessionId: profile
|
|
46
|
+
});
|
|
47
|
+
return result.data?.extracted?.[0] || result.extracted?.[0] || {};
|
|
48
|
+
}
|
|
49
|
+
async function extractGalleryImagesFromDom(rootSelectors = []) {
|
|
50
|
+
try {
|
|
51
|
+
const result = await controllerAction('browser:execute', {
|
|
52
|
+
profile,
|
|
53
|
+
script: `(() => {
|
|
54
|
+
const urls = new Set();
|
|
55
|
+
|
|
56
|
+
const rootSelectors = ${JSON.stringify(rootSelectors)};
|
|
57
|
+
const fallbackSelectors = [
|
|
58
|
+
".media-container img",
|
|
59
|
+
".note-slider-list img",
|
|
60
|
+
".note-img img",
|
|
61
|
+
".note-scroller img",
|
|
62
|
+
"img[src*='sns-img']",
|
|
63
|
+
"img[data-src*='sns-img']"
|
|
64
|
+
];
|
|
65
|
+
|
|
66
|
+
const selectors = [];
|
|
67
|
+
|
|
68
|
+
// 优先:基于 gallery 容器 selector 的 root 内部查找 IMG
|
|
69
|
+
if (Array.isArray(rootSelectors) && rootSelectors.length > 0) {
|
|
70
|
+
for (const sel of rootSelectors) {
|
|
71
|
+
if (typeof sel !== 'string' || !sel.trim()) continue;
|
|
72
|
+
selectors.push(sel + " img");
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
// 兜底:保留原有的一组全局 IMG selectors
|
|
77
|
+
selectors.push(...fallbackSelectors);
|
|
78
|
+
|
|
79
|
+
// 辅助函数:从单个节点提取 src / data-src / background-image
|
|
80
|
+
const addUrlFromNode = (node) => {
|
|
81
|
+
if (!node) return;
|
|
82
|
+
|
|
83
|
+
// 1) IMG / SOURCE 类节点
|
|
84
|
+
let src =
|
|
85
|
+
node.currentSrc ||
|
|
86
|
+
node.src ||
|
|
87
|
+
(typeof node.getAttribute === "function" &&
|
|
88
|
+
(node.getAttribute("src") || node.getAttribute("data-src")));
|
|
89
|
+
|
|
90
|
+
// 2) 背景图:检查 inline style 与 computed style 的 background-image
|
|
91
|
+
if (!src && typeof window !== "undefined") {
|
|
92
|
+
try {
|
|
93
|
+
const style = window.getComputedStyle(node);
|
|
94
|
+
const bg = style && (style.backgroundImage || style.background);
|
|
95
|
+
if (bg && bg.includes("url(")) {
|
|
96
|
+
// 解析 url("...") / url('...') / url(...)
|
|
97
|
+
const match = bg.match(/url\\(([^)]+)\\)/);
|
|
98
|
+
if (match && match[1]) {
|
|
99
|
+
src = match[1].trim().replace(/^['"]|['"]$/g, "");
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
} catch (_) {
|
|
103
|
+
// ignore style errors
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
if (typeof src === "string") {
|
|
108
|
+
const trimmed = src.trim();
|
|
109
|
+
if (trimmed) {
|
|
110
|
+
urls.add(trimmed);
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
};
|
|
114
|
+
|
|
115
|
+
// 先扫 IMG
|
|
116
|
+
for (const sel of selectors) {
|
|
117
|
+
try {
|
|
118
|
+
document.querySelectorAll(sel).forEach((node) => {
|
|
119
|
+
addUrlFromNode(node);
|
|
120
|
+
});
|
|
121
|
+
} catch (_) {
|
|
122
|
+
// 单个 selector 出错不影响整体
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
// 再在 gallery root 内扫描可能只用背景图渲染的节点(基于 computedStyle.backgroundImage)
|
|
127
|
+
const roots = [];
|
|
128
|
+
if (Array.isArray(rootSelectors) && rootSelectors.length > 0) {
|
|
129
|
+
for (const sel of rootSelectors) {
|
|
130
|
+
try {
|
|
131
|
+
const el = document.querySelector(sel);
|
|
132
|
+
if (el) roots.push(el);
|
|
133
|
+
} catch (_) {}
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
if (!roots.length && document.body) {
|
|
137
|
+
roots.push(document.body);
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
const MAX_BG_NODES = 400;
|
|
141
|
+
for (const root of roots) {
|
|
142
|
+
try {
|
|
143
|
+
const nodes = root.querySelectorAll('*');
|
|
144
|
+
const len = Math.min(nodes.length, MAX_BG_NODES);
|
|
145
|
+
for (let i = 0; i < len; i++) {
|
|
146
|
+
addUrlFromNode(nodes[i]);
|
|
147
|
+
}
|
|
148
|
+
} catch (_) {
|
|
149
|
+
// ignore
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
return Array.from(urls);
|
|
154
|
+
})()`
|
|
155
|
+
});
|
|
156
|
+
const payload = result.result || result.data?.result || result;
|
|
157
|
+
if (Array.isArray(payload)) {
|
|
158
|
+
return payload.filter((v) => typeof v === 'string' && v.trim().length > 0);
|
|
159
|
+
}
|
|
160
|
+
if (payload && Array.isArray(payload.urls)) {
|
|
161
|
+
return payload.urls.filter((v) => typeof v === 'string' && v.trim().length > 0);
|
|
162
|
+
}
|
|
163
|
+
return [];
|
|
164
|
+
}
|
|
165
|
+
catch (e) {
|
|
166
|
+
console.warn(`[ExtractDetail] fallback DOM image extraction error: ${e?.message || e}`);
|
|
167
|
+
return [];
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
try {
|
|
171
|
+
const { verifyAnchorByContainerId, getPrimarySelectorByContainerId } = await import('./helpers/containerAnchors.js');
|
|
172
|
+
// 1. 直接使用固定的详情子容器 ID(避免依赖 containers:match)
|
|
173
|
+
const headerNode = { id: 'xiaohongshu_detail.header' };
|
|
174
|
+
const contentNode = { id: 'xiaohongshu_detail.content' };
|
|
175
|
+
const galleryNode = { id: 'xiaohongshu_detail.gallery' };
|
|
176
|
+
// 3. 提取数据
|
|
177
|
+
const detail = {};
|
|
178
|
+
let headerRect;
|
|
179
|
+
let contentRect;
|
|
180
|
+
let galleryRect;
|
|
181
|
+
// 3.1 header:高亮 + Rect + 数据
|
|
182
|
+
if (headerNode?.id) {
|
|
183
|
+
try {
|
|
184
|
+
const anchor = await verifyAnchorByContainerId(headerNode.id, profile, serviceUrl, '2px solid #ff8800', 1500);
|
|
185
|
+
if (anchor.found && anchor.rect) {
|
|
186
|
+
headerRect = anchor.rect;
|
|
187
|
+
console.log(`[ExtractDetail] header rect: ${JSON.stringify(anchor.rect)}`);
|
|
188
|
+
}
|
|
189
|
+
else {
|
|
190
|
+
console.warn(`[ExtractDetail] header anchor verify failed: ${anchor.error || 'not found'}`);
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
catch (e) {
|
|
194
|
+
console.warn(`[ExtractDetail] header anchor verify error: ${e.message}`);
|
|
195
|
+
}
|
|
196
|
+
detail.header = await extractContainer(headerNode.id);
|
|
197
|
+
}
|
|
198
|
+
// 3.2 content:高亮 + Rect + 数据
|
|
199
|
+
if (contentNode?.id) {
|
|
200
|
+
try {
|
|
201
|
+
const anchor = await verifyAnchorByContainerId(contentNode.id, profile, serviceUrl, '2px solid #00aa00', 1500);
|
|
202
|
+
if (anchor.found && anchor.rect) {
|
|
203
|
+
contentRect = anchor.rect;
|
|
204
|
+
console.log(`[ExtractDetail] content rect: ${JSON.stringify(anchor.rect)}`);
|
|
205
|
+
}
|
|
206
|
+
else {
|
|
207
|
+
console.warn(`[ExtractDetail] content anchor verify failed: ${anchor.error || 'not found'}`);
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
catch (e) {
|
|
211
|
+
console.warn(`[ExtractDetail] content anchor verify error: ${e.message}`);
|
|
212
|
+
}
|
|
213
|
+
detail.content = await extractContainer(contentNode.id);
|
|
214
|
+
}
|
|
215
|
+
// 3.3 gallery:高亮 + Rect + 数据
|
|
216
|
+
if (galleryNode?.id) {
|
|
217
|
+
let galleryAnchorOk = false;
|
|
218
|
+
try {
|
|
219
|
+
const anchor = await verifyAnchorByContainerId(galleryNode.id, profile, serviceUrl, '2px solid #0088ff', 1500);
|
|
220
|
+
if (anchor.found && anchor.rect) {
|
|
221
|
+
galleryRect = anchor.rect;
|
|
222
|
+
galleryAnchorOk = true;
|
|
223
|
+
console.log(`[ExtractDetail] gallery rect: ${JSON.stringify(anchor.rect)}`);
|
|
224
|
+
}
|
|
225
|
+
else {
|
|
226
|
+
console.warn(`[ExtractDetail] gallery anchor verify failed: ${anchor.error || 'not found'}`);
|
|
227
|
+
}
|
|
228
|
+
}
|
|
229
|
+
catch (e) {
|
|
230
|
+
console.warn(`[ExtractDetail] gallery anchor verify error: ${e.message}`);
|
|
231
|
+
}
|
|
232
|
+
// 「无锚不动」:如果 gallery 容器锚点未命中,则不做任何图片提取,避免误采头像 / 推荐流图片。
|
|
233
|
+
if (!galleryAnchorOk) {
|
|
234
|
+
console.warn('[ExtractDetail] gallery anchor not found, skip gallery extraction entirely');
|
|
235
|
+
}
|
|
236
|
+
else {
|
|
237
|
+
const galleryData = (await extractContainer(galleryNode.id)) || {};
|
|
238
|
+
// 处理图片字段:兼容字符串 / 对象数组,并在为空时用 DOM 兜底
|
|
239
|
+
let images = [];
|
|
240
|
+
const rawImages = galleryData.images;
|
|
241
|
+
if (Array.isArray(rawImages)) {
|
|
242
|
+
images = rawImages
|
|
243
|
+
.map((item) => {
|
|
244
|
+
if (!item)
|
|
245
|
+
return '';
|
|
246
|
+
if (typeof item === 'string')
|
|
247
|
+
return item;
|
|
248
|
+
if (typeof item === 'object') {
|
|
249
|
+
return (item.src || item.url || item.href || '').trim();
|
|
250
|
+
}
|
|
251
|
+
return '';
|
|
252
|
+
})
|
|
253
|
+
.filter((v) => v.length > 0);
|
|
254
|
+
}
|
|
255
|
+
else if (typeof rawImages === 'string') {
|
|
256
|
+
const v = rawImages.trim();
|
|
257
|
+
if (v)
|
|
258
|
+
images.push(v);
|
|
259
|
+
}
|
|
260
|
+
// 若容器未返回图片,则尝试直接从 DOM 中聚合一次(优先基于 gallery 容器 selector 作为 root)
|
|
261
|
+
if (images.length === 0) {
|
|
262
|
+
const gallerySelector = (await getPrimarySelectorByContainerId(galleryNode.id)) || '';
|
|
263
|
+
const domImages = await extractGalleryImagesFromDom(gallerySelector ? [gallerySelector] : []);
|
|
264
|
+
if (domImages.length > 0) {
|
|
265
|
+
images = domImages;
|
|
266
|
+
}
|
|
267
|
+
}
|
|
268
|
+
if (images.length > 0) {
|
|
269
|
+
// 去重,避免 swiper 结构中的 duplicate slide 导致重复图片
|
|
270
|
+
images = Array.from(new Set(images));
|
|
271
|
+
console.log(`[ExtractDetail] gallery images count after dedupe: ${images.length}`);
|
|
272
|
+
galleryData.images = images;
|
|
273
|
+
}
|
|
274
|
+
else {
|
|
275
|
+
console.warn('[ExtractDetail] gallery images still empty after DOM fallback');
|
|
276
|
+
}
|
|
277
|
+
detail.gallery = galleryData;
|
|
278
|
+
}
|
|
279
|
+
}
|
|
280
|
+
// 4. Rect 规则验证:header 在顶部,content 在中部,gallery 在下方
|
|
281
|
+
let verified = false;
|
|
282
|
+
if (headerRect && contentRect && galleryRect) {
|
|
283
|
+
const headerOk = headerRect.y < 300 && headerRect.height > 0;
|
|
284
|
+
const contentOk = contentRect.y > headerRect.y && contentRect.height > 0;
|
|
285
|
+
const galleryOk = galleryRect.y > contentRect.y && galleryRect.height > 0;
|
|
286
|
+
verified = headerOk && contentOk && galleryOk;
|
|
287
|
+
console.log(`[ExtractDetail] Rect validation: header=${headerOk}, content=${contentOk}, gallery=${galleryOk}`);
|
|
288
|
+
}
|
|
289
|
+
return {
|
|
290
|
+
success: true,
|
|
291
|
+
detail,
|
|
292
|
+
anchor: {
|
|
293
|
+
headerContainerId: headerNode?.id,
|
|
294
|
+
headerRect,
|
|
295
|
+
contentContainerId: contentNode?.id,
|
|
296
|
+
contentRect,
|
|
297
|
+
galleryContainerId: galleryNode?.id,
|
|
298
|
+
galleryRect,
|
|
299
|
+
verified
|
|
300
|
+
}
|
|
301
|
+
};
|
|
302
|
+
}
|
|
303
|
+
catch (error) {
|
|
304
|
+
return {
|
|
305
|
+
success: false,
|
|
306
|
+
error: `ExtractDetail failed: ${error.message}`
|
|
307
|
+
};
|
|
308
|
+
}
|
|
309
|
+
}
|
|
310
|
+
//# sourceMappingURL=ExtractDetailBlock.js.map
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Workflow Block: ExtractPostFields
|
|
3
|
+
*
|
|
4
|
+
* 抽取单条帖子字段数据,包含链接过滤
|
|
5
|
+
*/
|
|
6
|
+
/**
|
|
7
|
+
* 抽取字段
|
|
8
|
+
*
|
|
9
|
+
* @param input - 输入参数
|
|
10
|
+
* @returns Promise<ExtractPostFieldsOutput>
|
|
11
|
+
*/
|
|
12
|
+
export async function execute(input) {
|
|
13
|
+
const { sessionId, containerSelector, index = 0, serviceUrl = 'http://127.0.0.1:7704' } = input;
|
|
14
|
+
const commandUrl = `${serviceUrl}/command`;
|
|
15
|
+
try {
|
|
16
|
+
const evalRes = await fetch(commandUrl, {
|
|
17
|
+
method: 'POST',
|
|
18
|
+
headers: { 'Content-Type': 'application/json' },
|
|
19
|
+
body: JSON.stringify({
|
|
20
|
+
action: 'evaluate',
|
|
21
|
+
args: {
|
|
22
|
+
profileId: sessionId,
|
|
23
|
+
script: `
|
|
24
|
+
(() => {
|
|
25
|
+
const containers = document.querySelectorAll('${containerSelector}');
|
|
26
|
+
if (!containers || containers.length === 0) {
|
|
27
|
+
return { error: 'No containers found' };
|
|
28
|
+
}
|
|
29
|
+
const index = ${index};
|
|
30
|
+
if (index >= containers.length) {
|
|
31
|
+
return { error: 'Index out of range' };
|
|
32
|
+
}
|
|
33
|
+
const element = containers[index];
|
|
34
|
+
|
|
35
|
+
const getText = (selector) => {
|
|
36
|
+
const node = element.querySelector(selector);
|
|
37
|
+
return node ? node.textContent?.trim() : '';
|
|
38
|
+
};
|
|
39
|
+
|
|
40
|
+
// 过滤链接:只保留帖子链接
|
|
41
|
+
const isPostUrl = (url) => {
|
|
42
|
+
if (!url) return false;
|
|
43
|
+
// 帖子URL: weibo.com/数字/帖子ID,其中帖子ID长度>4位
|
|
44
|
+
return /^https?:\\/\\/(?:www\\.)?weibo\\.com\\/\\d+\\/[a-zA-Z0-9]{5,}/.test(url) ||
|
|
45
|
+
/^https?:\\/\\/(?:m\\.)?weibo\\.com\\/detail\\/[a-zA-Z0-9]{5,}/.test(url);
|
|
46
|
+
};
|
|
47
|
+
|
|
48
|
+
const isProfileUrl = (url) => {
|
|
49
|
+
if (!url) return false;
|
|
50
|
+
// 用户主页: /u/数字ID 或 单段用户名
|
|
51
|
+
return /^https?:\\/\\/(?:www\\.)?weibo\\.com\\/u\\/\\d+/.test(url) ||
|
|
52
|
+
/^https?:\\/\\/(?:www\\.)?weibo\\.com\\/[a-zA-Z0-9_-]{1,16}\\/?$/.test(url);
|
|
53
|
+
};
|
|
54
|
+
|
|
55
|
+
const links = Array.from(element.querySelectorAll('a'))
|
|
56
|
+
.map(a => a.href)
|
|
57
|
+
.filter(url => isPostUrl(url) && !isProfileUrl(url));
|
|
58
|
+
|
|
59
|
+
return {
|
|
60
|
+
author: getText('.woo-font.woo-font--headline'),
|
|
61
|
+
content: getText('.detail_wbtext_4CRf9, .detail_wbtext_4CRf9 *'),
|
|
62
|
+
time: getText('time, .wb_time'),
|
|
63
|
+
postLinks: links
|
|
64
|
+
};
|
|
65
|
+
})()
|
|
66
|
+
`
|
|
67
|
+
}
|
|
68
|
+
})
|
|
69
|
+
});
|
|
70
|
+
const evalData = await evalRes.json();
|
|
71
|
+
if (!evalData.success || evalData.data?.error) {
|
|
72
|
+
return {
|
|
73
|
+
fields: {},
|
|
74
|
+
error: evalData.data?.error || 'Failed to extract fields'
|
|
75
|
+
};
|
|
76
|
+
}
|
|
77
|
+
return {
|
|
78
|
+
fields: evalData.data
|
|
79
|
+
};
|
|
80
|
+
}
|
|
81
|
+
catch (error) {
|
|
82
|
+
return {
|
|
83
|
+
fields: {},
|
|
84
|
+
error: `Extract error: ${error.message}`
|
|
85
|
+
};
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
//# sourceMappingURL=ExtractPostFields.js.map
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Block: GenerateSmartReply
|
|
3
|
+
*
|
|
4
|
+
* 职责:
|
|
5
|
+
* - 构造 prompt(<note> + <comment>)
|
|
6
|
+
* - 调用 OpenAI-compatible Chat API 生成 <= N 字回复
|
|
7
|
+
*
|
|
8
|
+
* Dev 模式:
|
|
9
|
+
* - 默认返回 mock 回复(避免误触发真实外部请求/成本)
|
|
10
|
+
*/
|
|
11
|
+
import { buildSmartReplyUserPrompt, mockSmartReply, sanitizeSmartReply } from './helpers/smartReply.js';
|
|
12
|
+
function resolveBaseUrl(baseUrl) {
|
|
13
|
+
const s = String(baseUrl || '').trim();
|
|
14
|
+
if (!s)
|
|
15
|
+
return '';
|
|
16
|
+
return s.endsWith('/') ? s.slice(0, -1) : s;
|
|
17
|
+
}
|
|
18
|
+
export async function execute(input) {
|
|
19
|
+
const maxChars = typeof input.maxChars === 'number' ? input.maxChars : 20;
|
|
20
|
+
const dev = input.dev === true;
|
|
21
|
+
const dryRun = input.dryRun === true;
|
|
22
|
+
const note = String(input.note || '');
|
|
23
|
+
const comment = String(input.comment || '');
|
|
24
|
+
const apiKey = String(input.apiKey || process.env.WEBAUTO_CHAT_API_KEY || '').trim();
|
|
25
|
+
const model = String(input.model || process.env.WEBAUTO_CHAT_MODEL || 'gpt-4o-mini').trim();
|
|
26
|
+
const baseUrl = resolveBaseUrl(String(input.baseUrl || process.env.WEBAUTO_CHAT_BASE_URL || 'https://api.openai.com'));
|
|
27
|
+
if (dryRun || dev || !apiKey || !baseUrl) {
|
|
28
|
+
return { success: true, reply: mockSmartReply(note, comment, maxChars), usedMock: true };
|
|
29
|
+
}
|
|
30
|
+
try {
|
|
31
|
+
const userPrompt = buildSmartReplyUserPrompt({ note, comment, maxChars });
|
|
32
|
+
const systemPrompt = '你是一个真实的小红书用户,擅长用自然、简短、拟人的口吻互动。';
|
|
33
|
+
const body = {
|
|
34
|
+
model,
|
|
35
|
+
messages: [
|
|
36
|
+
{ role: 'system', content: systemPrompt },
|
|
37
|
+
{ role: 'user', content: userPrompt },
|
|
38
|
+
],
|
|
39
|
+
temperature: typeof input.temperature === 'number' ? input.temperature : 0.7,
|
|
40
|
+
max_tokens: 80,
|
|
41
|
+
};
|
|
42
|
+
const res = await fetch(`${baseUrl}/v1/chat/completions`, {
|
|
43
|
+
method: 'POST',
|
|
44
|
+
headers: {
|
|
45
|
+
'Content-Type': 'application/json',
|
|
46
|
+
Authorization: `Bearer ${apiKey}`,
|
|
47
|
+
},
|
|
48
|
+
body: JSON.stringify(body),
|
|
49
|
+
signal: AbortSignal.timeout(25000),
|
|
50
|
+
});
|
|
51
|
+
const json = await res.json().catch(() => ({}));
|
|
52
|
+
if (!res.ok) {
|
|
53
|
+
const msg = json?.error?.message || `HTTP ${res.status}`;
|
|
54
|
+
throw new Error(msg);
|
|
55
|
+
}
|
|
56
|
+
const content = json?.choices?.[0]?.message?.content ??
|
|
57
|
+
json?.choices?.[0]?.text ??
|
|
58
|
+
'';
|
|
59
|
+
const reply = sanitizeSmartReply(String(content || ''), maxChars);
|
|
60
|
+
if (!reply)
|
|
61
|
+
throw new Error('empty reply');
|
|
62
|
+
return { success: true, reply, usedMock: false };
|
|
63
|
+
}
|
|
64
|
+
catch (e) {
|
|
65
|
+
return { success: false, reply: '', usedMock: false, error: e?.message || String(e) };
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
//# sourceMappingURL=GenerateSmartReplyBlock.js.map
|