@jackwener/opencli 1.6.1 → 1.6.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/CONTRIBUTING.md +1 -1
- package/README.md +27 -45
- package/README.zh-CN.md +32 -34
- package/autoresearch/browse-tasks.json +18 -20
- package/autoresearch/commands/debug.ts +163 -0
- package/autoresearch/commands/fix.ts +145 -0
- package/autoresearch/commands/plan.ts +88 -0
- package/autoresearch/commands/run.ts +138 -0
- package/autoresearch/config.ts +82 -0
- package/autoresearch/engine.ts +359 -0
- package/autoresearch/eval-all.ts +127 -0
- package/autoresearch/eval-browse.ts +1 -1
- package/autoresearch/eval-publish.ts +238 -0
- package/autoresearch/eval-save.ts +249 -0
- package/autoresearch/eval-skill.ts +14 -8
- package/autoresearch/eval-v2ex.ts +220 -0
- package/autoresearch/eval-zhihu.ts +230 -0
- package/autoresearch/logger.ts +69 -0
- package/autoresearch/presets/combined-reliability.ts +27 -0
- package/autoresearch/presets/index.ts +23 -0
- package/autoresearch/presets/operate-reliability.ts +24 -0
- package/autoresearch/presets/save-reliability.ts +26 -0
- package/autoresearch/presets/skill-quality.ts +20 -0
- package/autoresearch/presets/v2ex-reliability.ts +24 -0
- package/autoresearch/presets/zhihu-reliability.ts +25 -0
- package/autoresearch/publish-tasks.json +345 -0
- package/autoresearch/run-save.sh +11 -0
- package/autoresearch/save-adapters/xhs-explore-deep.ts +64 -0
- package/autoresearch/save-adapters/xhs-note-comments.ts +61 -0
- package/autoresearch/save-adapters/xhs-search-full.ts +62 -0
- package/autoresearch/save-adapters/zhihu-hot-detail.ts +52 -0
- package/autoresearch/save-adapters/zhihu-question-full.ts +57 -0
- package/autoresearch/save-adapters/zhihu-search-detail.ts +53 -0
- package/autoresearch/save-tasks.json +281 -0
- package/autoresearch/v2ex-tasks.json +899 -0
- package/autoresearch/zhihu-tasks.json +848 -0
- package/dist/browser/base-page.d.ts +4 -2
- package/dist/browser/base-page.js +37 -4
- package/dist/browser/bridge.js +10 -8
- package/dist/browser/cdp.js +2 -6
- package/dist/browser/daemon-client.d.ts +11 -1
- package/dist/browser/daemon-client.js +3 -0
- package/dist/browser/dom-helpers.d.ts +4 -2
- package/dist/browser/dom-helpers.js +42 -31
- package/dist/browser/dom-snapshot.js +23 -1
- package/dist/browser/page.d.ts +7 -2
- package/dist/browser/page.js +112 -30
- package/dist/browser.test.js +1 -1
- package/dist/build-manifest.d.ts +1 -0
- package/dist/build-manifest.js +1 -0
- package/dist/cli-manifest.json +1135 -184
- package/dist/cli.d.ts +2 -0
- package/dist/cli.js +48 -7
- package/dist/cli.test.d.ts +1 -0
- package/dist/cli.test.js +88 -0
- package/dist/clis/1688/item.d.ts +70 -0
- package/dist/clis/1688/item.js +187 -0
- package/dist/clis/1688/item.test.d.ts +1 -0
- package/dist/clis/1688/item.test.js +67 -0
- package/dist/clis/1688/search.d.ts +56 -0
- package/dist/clis/1688/search.js +309 -0
- package/dist/clis/1688/search.test.d.ts +1 -0
- package/dist/clis/1688/search.test.js +75 -0
- package/dist/clis/1688/shared.d.ts +112 -0
- package/dist/clis/1688/shared.js +514 -0
- package/dist/clis/1688/shared.test.d.ts +1 -0
- package/dist/clis/1688/shared.test.js +57 -0
- package/dist/clis/1688/store.d.ts +45 -0
- package/dist/clis/1688/store.js +226 -0
- package/dist/clis/1688/store.test.d.ts +1 -0
- package/dist/clis/1688/store.test.js +62 -0
- package/dist/clis/amazon/bestsellers.d.ts +0 -20
- package/dist/clis/amazon/bestsellers.js +6 -129
- package/dist/clis/amazon/bestsellers.test.js +12 -3
- package/dist/clis/amazon/movers-shakers.d.ts +1 -0
- package/dist/clis/amazon/movers-shakers.js +7 -0
- package/dist/clis/amazon/new-releases.d.ts +1 -0
- package/dist/clis/amazon/new-releases.js +7 -0
- package/dist/clis/amazon/rankings.d.ts +59 -0
- package/dist/clis/amazon/rankings.js +226 -0
- package/dist/clis/amazon/rankings.test.d.ts +1 -0
- package/dist/clis/amazon/rankings.test.js +41 -0
- package/dist/clis/amazon/shared.d.ts +11 -0
- package/dist/clis/amazon/shared.js +121 -11
- package/dist/clis/amazon/shared.test.js +11 -0
- package/dist/clis/bilibili/comments.js +2 -2
- package/dist/clis/bilibili/comments.test.js +3 -2
- package/dist/clis/bilibili/download.js +2 -1
- package/dist/clis/bilibili/subtitle.js +4 -3
- package/dist/clis/bilibili/subtitle.test.js +2 -1
- package/dist/clis/bilibili/utils.d.ts +5 -0
- package/dist/clis/bilibili/utils.js +30 -0
- package/dist/clis/bilibili/utils.test.d.ts +1 -0
- package/dist/clis/bilibili/utils.test.js +17 -0
- package/dist/clis/douban/marks.js +1 -1
- package/dist/clis/douban/subject.yaml +50 -19
- package/dist/clis/doubao/utils.js +32 -12
- package/dist/clis/douyin/_shared/browser-fetch.test.js +0 -1
- package/dist/clis/douyin/_shared/transcode.test.js +0 -2
- package/dist/clis/douyin/draft.test.js +0 -2
- package/dist/clis/facebook/search.test.js +0 -2
- package/dist/clis/gemini/ask.js +9 -3
- package/dist/clis/gemini/ask.test.d.ts +1 -0
- package/dist/clis/gemini/ask.test.js +100 -0
- package/dist/clis/gemini/reply-state.test.d.ts +1 -0
- package/dist/clis/gemini/reply-state.test.js +641 -0
- package/dist/clis/gemini/utils.d.ts +44 -1
- package/dist/clis/gemini/utils.js +528 -61
- package/dist/clis/gemini/utils.test.js +149 -2
- package/dist/clis/hupu/detail.d.ts +1 -0
- package/dist/clis/hupu/detail.js +72 -0
- package/dist/clis/hupu/hot.yaml +43 -0
- package/dist/clis/hupu/like.d.ts +1 -0
- package/dist/clis/hupu/like.js +75 -0
- package/dist/clis/hupu/reply.d.ts +1 -0
- package/dist/clis/hupu/reply.js +71 -0
- package/dist/clis/hupu/search.d.ts +1 -0
- package/dist/clis/hupu/search.js +59 -0
- package/dist/clis/hupu/unlike.d.ts +1 -0
- package/dist/clis/hupu/unlike.js +75 -0
- package/dist/clis/hupu/utils.d.ts +20 -0
- package/dist/clis/hupu/utils.js +319 -0
- package/dist/clis/instagram/_shared/private-publish.d.ts +138 -0
- package/dist/clis/instagram/_shared/private-publish.js +1030 -0
- package/dist/clis/instagram/_shared/private-publish.test.d.ts +1 -0
- package/dist/clis/instagram/_shared/private-publish.test.js +705 -0
- package/dist/clis/instagram/_shared/protocol-capture.d.ts +26 -0
- package/dist/clis/instagram/_shared/protocol-capture.js +282 -0
- package/dist/clis/instagram/_shared/protocol-capture.test.d.ts +1 -0
- package/dist/clis/instagram/_shared/protocol-capture.test.js +114 -0
- package/dist/clis/instagram/_shared/runtime-info.d.ts +9 -0
- package/dist/clis/instagram/_shared/runtime-info.js +81 -0
- package/dist/clis/instagram/note.d.ts +1 -0
- package/dist/clis/instagram/note.js +222 -0
- package/dist/clis/instagram/note.test.d.ts +1 -0
- package/dist/clis/instagram/note.test.js +81 -0
- package/dist/clis/instagram/post.d.ts +4 -0
- package/dist/clis/instagram/post.js +1496 -0
- package/dist/clis/instagram/post.test.d.ts +1 -0
- package/dist/clis/instagram/post.test.js +1647 -0
- package/dist/clis/instagram/reel.d.ts +1 -0
- package/dist/clis/instagram/reel.js +826 -0
- package/dist/clis/instagram/reel.test.d.ts +1 -0
- package/dist/clis/instagram/reel.test.js +167 -0
- package/dist/clis/instagram/story.d.ts +1 -0
- package/dist/clis/instagram/story.js +115 -0
- package/dist/clis/instagram/story.test.d.ts +1 -0
- package/dist/clis/instagram/story.test.js +167 -0
- package/dist/clis/sinafinance/stock-rank.d.ts +4 -0
- package/dist/clis/sinafinance/stock-rank.js +65 -0
- package/dist/clis/substack/utils.test.js +0 -2
- package/dist/clis/twitter/post.js +72 -45
- package/dist/clis/twitter/post.test.d.ts +1 -0
- package/dist/clis/twitter/post.test.js +116 -0
- package/dist/clis/twitter/reply.d.ts +12 -0
- package/dist/clis/twitter/reply.js +257 -35
- package/dist/clis/twitter/reply.test.d.ts +1 -0
- package/dist/clis/twitter/reply.test.js +151 -0
- package/dist/clis/xianyu/chat.d.ts +7 -0
- package/dist/clis/xianyu/chat.js +146 -0
- package/dist/clis/xianyu/chat.test.d.ts +1 -0
- package/dist/clis/xianyu/chat.test.js +15 -0
- package/dist/clis/xianyu/item.d.ts +7 -0
- package/dist/clis/xianyu/item.js +152 -0
- package/dist/clis/xianyu/item.test.d.ts +1 -0
- package/dist/clis/xianyu/item.test.js +56 -0
- package/dist/clis/xianyu/search.d.ts +10 -0
- package/dist/clis/xianyu/search.js +134 -0
- package/dist/clis/xianyu/search.test.d.ts +1 -0
- package/dist/clis/xianyu/search.test.js +17 -0
- package/dist/clis/xianyu/utils.d.ts +1 -0
- package/dist/clis/xianyu/utils.js +8 -0
- package/dist/clis/xiaoe/catalog.yaml +129 -0
- package/dist/clis/xiaoe/content.yaml +43 -0
- package/dist/clis/xiaoe/courses.yaml +73 -0
- package/dist/clis/xiaoe/detail.yaml +39 -0
- package/dist/clis/xiaoe/play-url.yaml +124 -0
- package/dist/clis/xiaohongshu/comments.test.js +0 -2
- package/dist/clis/xiaohongshu/creator-note-detail.test.js +0 -2
- package/dist/clis/xiaohongshu/creator-notes.test.js +0 -2
- package/dist/clis/xiaohongshu/download.test.js +0 -2
- package/dist/clis/xiaohongshu/note.test.js +0 -2
- package/dist/clis/xiaohongshu/publish.test.js +0 -2
- package/dist/clis/xiaohongshu/search.js +29 -20
- package/dist/clis/xiaohongshu/search.test.js +56 -48
- package/dist/clis/yuanbao/ask.d.ts +21 -0
- package/dist/clis/yuanbao/ask.js +427 -0
- package/dist/clis/yuanbao/ask.test.d.ts +1 -0
- package/dist/clis/yuanbao/ask.test.js +124 -0
- package/dist/clis/yuanbao/new.d.ts +1 -0
- package/dist/clis/yuanbao/new.js +70 -0
- package/dist/clis/yuanbao/new.test.d.ts +1 -0
- package/dist/clis/yuanbao/new.test.js +30 -0
- package/dist/clis/yuanbao/shared.d.ts +13 -0
- package/dist/clis/yuanbao/shared.js +49 -0
- package/dist/clis/zhihu/question.js +30 -19
- package/dist/clis/zhihu/question.test.js +34 -16
- package/dist/commanderAdapter.js +8 -4
- package/dist/commanderAdapter.test.js +42 -0
- package/dist/completion.js +3 -1
- package/dist/completion.test.d.ts +1 -0
- package/dist/completion.test.js +23 -0
- package/dist/doctor.js +1 -1
- package/dist/electron-apps.d.ts +2 -0
- package/dist/electron-apps.js +7 -1
- package/dist/errors.js +1 -1
- package/dist/execution.js +25 -35
- package/dist/explore.js +1 -1
- package/dist/launcher.d.ts +4 -0
- package/dist/launcher.js +64 -8
- package/dist/launcher.test.js +88 -7
- package/dist/output.d.ts +2 -0
- package/dist/output.js +10 -1
- package/dist/output.test.d.ts +0 -3
- package/dist/output.test.js +59 -92
- package/dist/pipeline/executor.test.js +0 -2
- package/dist/pipeline/steps/download.test.js +0 -2
- package/dist/registry.d.ts +2 -0
- package/dist/serialization.d.ts +1 -0
- package/dist/serialization.js +1 -0
- package/dist/types.d.ts +9 -2
- package/docs/.vitepress/config.mts +4 -0
- package/docs/adapters/browser/1688.md +52 -0
- package/docs/adapters/browser/36kr.md +2 -1
- package/docs/adapters/browser/doubao.md +5 -1
- package/docs/adapters/browser/hupu.md +53 -0
- package/docs/adapters/browser/sinafinance.md +32 -2
- package/docs/adapters/browser/weibo.md +6 -1
- package/docs/adapters/browser/wikipedia.md +2 -0
- package/docs/adapters/browser/xianyu.md +42 -0
- package/docs/adapters/browser/xiaoe.md +44 -0
- package/docs/adapters/browser/yuanbao.md +64 -0
- package/docs/adapters/index.md +14 -5
- package/docs/comparison.md +1 -1
- package/docs/developer/ai-workflow.md +2 -2
- package/docs/developer/contributing.md +1 -1
- package/docs/developer/testing.md +2 -0
- package/docs/guide/plugins.md +1 -0
- package/docs/guide/troubleshooting.md +11 -0
- package/docs/superpowers/specs/2026-04-03-v2ex-autoresearch-design.md +41 -0
- package/docs/zh/guide/plugins.md +1 -0
- package/extension/dist/background.js +1127 -0
- package/extension/src/background.test.ts +39 -0
- package/extension/src/background.ts +223 -34
- package/extension/src/cdp.ts +194 -4
- package/extension/src/protocol.ts +22 -1
- package/package.json +3 -2
- package/scripts/postinstall.js +1 -1
- package/skills/opencli-explorer/SKILL.md +1 -1
- package/skills/opencli-oneshot/SKILL.md +2 -2
- package/skills/opencli-operate/SKILL.md +120 -27
- package/skills/opencli-usage/SKILL.md +31 -20
- package/skills/opencli-usage/browser.md +114 -16
- package/skills/opencli-usage/public-api.md +32 -3
- package/skills/smart-search/SKILL.md +156 -0
- package/skills/smart-search/references/sources-ai.md +74 -0
- package/skills/smart-search/references/sources-info.md +43 -0
- package/skills/smart-search/references/sources-media.md +50 -0
- package/skills/smart-search/references/sources-other.md +42 -0
- package/skills/smart-search/references/sources-shopping.md +31 -0
- package/skills/smart-search/references/sources-social.md +51 -0
- package/skills/smart-search/references/sources-tech.md +42 -0
- package/skills/smart-search/references/sources-travel.md +20 -0
- package/src/browser/base-page.ts +41 -6
- package/src/browser/bridge.ts +11 -8
- package/src/browser/cdp.ts +1 -8
- package/src/browser/daemon-client.ts +11 -1
- package/src/browser/dom-helpers.ts +43 -31
- package/src/browser/dom-snapshot.ts +23 -1
- package/src/browser/page.ts +115 -31
- package/src/browser.test.ts +1 -1
- package/src/build-manifest.ts +2 -0
- package/src/cli.test.ts +133 -0
- package/src/cli.ts +73 -11
- package/src/clis/1688/item.test.ts +69 -0
- package/src/clis/1688/item.ts +282 -0
- package/src/clis/1688/search.test.ts +81 -0
- package/src/clis/1688/search.ts +402 -0
- package/src/clis/1688/shared.test.ts +75 -0
- package/src/clis/1688/shared.ts +623 -0
- package/src/clis/1688/store.test.ts +69 -0
- package/src/clis/1688/store.ts +300 -0
- package/src/clis/amazon/bestsellers.test.ts +12 -3
- package/src/clis/amazon/bestsellers.ts +6 -178
- package/src/clis/amazon/movers-shakers.ts +8 -0
- package/src/clis/amazon/new-releases.ts +8 -0
- package/src/clis/amazon/rankings.test.ts +47 -0
- package/src/clis/amazon/rankings.ts +312 -0
- package/src/clis/amazon/shared.test.ts +16 -0
- package/src/clis/amazon/shared.ts +134 -12
- package/src/clis/bilibili/comments.test.ts +4 -3
- package/src/clis/bilibili/comments.ts +2 -2
- package/src/clis/bilibili/download.ts +2 -1
- package/src/clis/bilibili/subtitle.test.ts +2 -1
- package/src/clis/bilibili/subtitle.ts +4 -3
- package/src/clis/bilibili/utils.test.ts +21 -0
- package/src/clis/bilibili/utils.ts +27 -0
- package/src/clis/douban/marks.ts +1 -1
- package/src/clis/douban/subject.yaml +50 -19
- package/src/clis/doubao/utils.ts +32 -12
- package/src/clis/douyin/_shared/browser-fetch.test.ts +0 -1
- package/src/clis/douyin/_shared/transcode.test.ts +0 -2
- package/src/clis/douyin/draft.test.ts +0 -2
- package/src/clis/facebook/search.test.ts +0 -2
- package/src/clis/gemini/ask.test.ts +116 -0
- package/src/clis/gemini/ask.ts +10 -3
- package/src/clis/gemini/reply-state.test.ts +708 -0
- package/src/clis/gemini/utils.test.ts +184 -2
- package/src/clis/gemini/utils.ts +588 -60
- package/src/clis/hupu/detail.ts +126 -0
- package/src/clis/hupu/hot.yaml +43 -0
- package/src/clis/hupu/like.ts +76 -0
- package/src/clis/hupu/reply.ts +76 -0
- package/src/clis/hupu/search.ts +95 -0
- package/src/clis/hupu/unlike.ts +76 -0
- package/src/clis/hupu/utils.ts +381 -0
- package/src/clis/instagram/_shared/private-publish.test.ts +827 -0
- package/src/clis/instagram/_shared/private-publish.ts +1303 -0
- package/src/clis/instagram/_shared/protocol-capture.test.ts +148 -0
- package/src/clis/instagram/_shared/protocol-capture.ts +321 -0
- package/src/clis/instagram/_shared/runtime-info.ts +91 -0
- package/src/clis/instagram/note.test.ts +96 -0
- package/src/clis/instagram/note.ts +254 -0
- package/src/clis/instagram/post.test.ts +1716 -0
- package/src/clis/instagram/post.ts +1620 -0
- package/src/clis/instagram/reel.test.ts +191 -0
- package/src/clis/instagram/reel.ts +886 -0
- package/src/clis/instagram/story.test.ts +191 -0
- package/src/clis/instagram/story.ts +151 -0
- package/src/clis/sinafinance/stock-rank.ts +68 -0
- package/src/clis/substack/utils.test.ts +0 -2
- package/src/clis/twitter/post.test.ts +157 -0
- package/src/clis/twitter/post.ts +82 -48
- package/src/clis/twitter/reply.test.ts +177 -0
- package/src/clis/twitter/reply.ts +285 -39
- package/src/clis/xianyu/chat.test.ts +20 -0
- package/src/clis/xianyu/chat.ts +175 -0
- package/src/clis/xianyu/item.test.ts +67 -0
- package/src/clis/xianyu/item.ts +172 -0
- package/src/clis/xianyu/search.test.ts +22 -0
- package/src/clis/xianyu/search.ts +151 -0
- package/src/clis/xianyu/utils.ts +9 -0
- package/src/clis/xiaoe/catalog.yaml +129 -0
- package/src/clis/xiaoe/content.yaml +43 -0
- package/src/clis/xiaoe/courses.yaml +73 -0
- package/src/clis/xiaoe/detail.yaml +39 -0
- package/src/clis/xiaoe/play-url.yaml +124 -0
- package/src/clis/xiaohongshu/comments.test.ts +0 -2
- package/src/clis/xiaohongshu/creator-note-detail.test.ts +0 -2
- package/src/clis/xiaohongshu/creator-notes.test.ts +0 -2
- package/src/clis/xiaohongshu/download.test.ts +0 -2
- package/src/clis/xiaohongshu/note.test.ts +0 -2
- package/src/clis/xiaohongshu/publish.test.ts +0 -2
- package/src/clis/xiaohongshu/search.test.ts +59 -48
- package/src/clis/xiaohongshu/search.ts +31 -21
- package/src/clis/yuanbao/ask.test.ts +156 -0
- package/src/clis/yuanbao/ask.ts +522 -0
- package/src/clis/yuanbao/new.test.ts +36 -0
- package/src/clis/yuanbao/new.ts +81 -0
- package/src/clis/yuanbao/shared.ts +57 -0
- package/src/clis/zhihu/question.test.ts +42 -17
- package/src/clis/zhihu/question.ts +31 -26
- package/src/commanderAdapter.test.ts +51 -0
- package/src/commanderAdapter.ts +8 -4
- package/src/completion.test.ts +30 -0
- package/src/completion.ts +3 -1
- package/src/doctor.ts +1 -1
- package/src/electron-apps.ts +9 -1
- package/src/errors.ts +1 -1
- package/src/execution.ts +26 -30
- package/src/explore.ts +1 -1
- package/src/launcher.test.ts +121 -7
- package/src/launcher.ts +87 -9
- package/src/output.test.ts +50 -90
- package/src/output.ts +10 -1
- package/src/pipeline/executor.test.ts +0 -2
- package/src/pipeline/steps/download.test.ts +0 -2
- package/src/registry.ts +2 -0
- package/src/serialization.ts +2 -0
- package/src/types.ts +9 -2
- package/tests/e2e/browser-auth.test.ts +9 -0
- package/CLI-EXPLORER.md +0 -724
- package/CLI-ONESHOT.md +0 -216
- package/SKILL.md +0 -59
|
@@ -0,0 +1,282 @@
|
|
|
1
|
+
import { CommandExecutionError } from '../../errors.js';
|
|
2
|
+
import { cli, Strategy } from '../../registry.js';
|
|
3
|
+
import type { IPage } from '../../types.js';
|
|
4
|
+
import { isRecord } from '../../utils.js';
|
|
5
|
+
import {
|
|
6
|
+
assertAuthenticatedState,
|
|
7
|
+
buildDetailUrl,
|
|
8
|
+
buildProvenance,
|
|
9
|
+
canonicalizeSellerUrl,
|
|
10
|
+
cleanMultilineText,
|
|
11
|
+
cleanText,
|
|
12
|
+
extractLocation,
|
|
13
|
+
extractMemberId,
|
|
14
|
+
extractOfferId,
|
|
15
|
+
extractShopId,
|
|
16
|
+
gotoAndReadState,
|
|
17
|
+
normalizePriceTiers,
|
|
18
|
+
parseMoqText,
|
|
19
|
+
parsePriceText,
|
|
20
|
+
toNumber,
|
|
21
|
+
uniqueNonEmpty,
|
|
22
|
+
} from './shared.js';
|
|
23
|
+
|
|
24
|
+
interface BuyerProtectionModel {
|
|
25
|
+
serviceName?: string;
|
|
26
|
+
shortBuyerDesc?: string;
|
|
27
|
+
packageBuyerDesc?: string;
|
|
28
|
+
textDesc?: string;
|
|
29
|
+
agreeDeliveryHours?: number;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
interface ItemBrowserPayload {
|
|
33
|
+
href?: string;
|
|
34
|
+
title?: string;
|
|
35
|
+
bodyText?: string;
|
|
36
|
+
offerTitle?: string;
|
|
37
|
+
offerId?: string | number;
|
|
38
|
+
seller?: {
|
|
39
|
+
companyName?: string;
|
|
40
|
+
memberId?: string;
|
|
41
|
+
winportUrl?: string;
|
|
42
|
+
sellerWinportUrlMap?: Record<string, string>;
|
|
43
|
+
};
|
|
44
|
+
trade?: {
|
|
45
|
+
beginAmount?: string | number;
|
|
46
|
+
priceDisplay?: string;
|
|
47
|
+
unit?: string;
|
|
48
|
+
saleCount?: string | number;
|
|
49
|
+
offerIDatacenterSellInfo?: Record<string, unknown>;
|
|
50
|
+
offerPriceModel?: {
|
|
51
|
+
currentPrices?: Array<{ beginAmount?: string | number; price?: string | number }>;
|
|
52
|
+
};
|
|
53
|
+
};
|
|
54
|
+
gallery?: {
|
|
55
|
+
mainImage?: string[];
|
|
56
|
+
offerImgList?: string[];
|
|
57
|
+
wlImageInfos?: Array<{ fullPathImageURI?: string }>;
|
|
58
|
+
};
|
|
59
|
+
shipping?: {
|
|
60
|
+
deliveryLimitText?: string;
|
|
61
|
+
logisticsText?: string;
|
|
62
|
+
protectionInfos?: BuyerProtectionModel[];
|
|
63
|
+
buyerProtectionModel?: BuyerProtectionModel[];
|
|
64
|
+
};
|
|
65
|
+
services?: BuyerProtectionModel[];
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
interface VisibleAttribute {
|
|
69
|
+
key: string;
|
|
70
|
+
value: string;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
function normalizeItemPayload(payload: ItemBrowserPayload): Record<string, unknown> {
|
|
74
|
+
const href = cleanText(payload.href);
|
|
75
|
+
const bodyText = cleanMultilineText(payload.bodyText);
|
|
76
|
+
const sellerName = cleanText(payload.seller?.companyName);
|
|
77
|
+
const sellerUrlRaw = cleanText(
|
|
78
|
+
payload.seller?.winportUrl
|
|
79
|
+
?? payload.seller?.sellerWinportUrlMap?.defaultUrl
|
|
80
|
+
?? payload.seller?.sellerWinportUrlMap?.indexUrl,
|
|
81
|
+
);
|
|
82
|
+
const sellerUrl = canonicalizeSellerUrl(sellerUrlRaw);
|
|
83
|
+
const offerId = cleanText(String(payload.offerId ?? '')) || extractOfferId(href) || null;
|
|
84
|
+
const memberId = cleanText(payload.seller?.memberId) || extractMemberId(sellerUrlRaw || href) || null;
|
|
85
|
+
const shopId = extractShopId(sellerUrl ?? href);
|
|
86
|
+
const unit = cleanText(payload.trade?.unit);
|
|
87
|
+
const priceDisplay = cleanText(payload.trade?.priceDisplay);
|
|
88
|
+
const priceRange = parsePriceText(priceDisplay ? `¥${priceDisplay}` : bodyText);
|
|
89
|
+
const moqText = extractMoqText(bodyText, payload.trade?.beginAmount, unit);
|
|
90
|
+
const moq = parseMoqText(moqText);
|
|
91
|
+
const services = uniqueServices(payload);
|
|
92
|
+
const serviceBadges = uniqueNonEmpty(services.map((service) => cleanText(service.serviceName)));
|
|
93
|
+
const attributes = normalizeVisibleAttributes(payload.trade?.offerIDatacenterSellInfo);
|
|
94
|
+
const priceTiers = normalizePriceTiers(payload.trade?.offerPriceModel?.currentPrices ?? [], unit || null);
|
|
95
|
+
const images = uniqueNonEmpty([
|
|
96
|
+
...(payload.gallery?.mainImage ?? []),
|
|
97
|
+
...(payload.gallery?.offerImgList ?? []),
|
|
98
|
+
...((payload.gallery?.wlImageInfos ?? []).map((item) => item.fullPathImageURI ?? '')),
|
|
99
|
+
]);
|
|
100
|
+
|
|
101
|
+
const detailUrl = offerId ? buildDetailUrl(offerId) : href;
|
|
102
|
+
const provenance = buildProvenance(href || detailUrl);
|
|
103
|
+
|
|
104
|
+
return {
|
|
105
|
+
offer_id: offerId,
|
|
106
|
+
member_id: memberId,
|
|
107
|
+
shop_id: shopId,
|
|
108
|
+
title: cleanText(payload.offerTitle) || stripAlibabaSuffix(payload.title) || firstNonEmptyLine(bodyText) || null,
|
|
109
|
+
item_url: detailUrl,
|
|
110
|
+
main_images: images,
|
|
111
|
+
price_text: priceRange.price_text || null,
|
|
112
|
+
price_tiers: priceTiers,
|
|
113
|
+
currency: priceRange.currency,
|
|
114
|
+
moq_text: moq.moq_text || null,
|
|
115
|
+
moq_value: moq.moq_value,
|
|
116
|
+
seller_name: sellerName || null,
|
|
117
|
+
seller_url: sellerUrl,
|
|
118
|
+
shop_name: sellerName || null,
|
|
119
|
+
origin_place: extractLocation(bodyText),
|
|
120
|
+
delivery_days_text: extractDeliveryDaysText(bodyText, services, payload.shipping),
|
|
121
|
+
customization_text: extractKeywordLine(bodyText, ['来样定制', '来图定制', '支持定制', '可定制', '定制']),
|
|
122
|
+
private_label_text: extractKeywordLine(bodyText, ['贴牌', '贴标', '定制logo', '打logo', 'OEM', 'ODM']),
|
|
123
|
+
visible_attributes: attributes,
|
|
124
|
+
sales_text: extractSalesText(bodyText),
|
|
125
|
+
service_badges: serviceBadges,
|
|
126
|
+
stock_quantity: extractStockQuantity(bodyText),
|
|
127
|
+
...provenance,
|
|
128
|
+
};
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
function normalizeVisibleAttributes(raw: unknown): VisibleAttribute[] {
|
|
132
|
+
if (!isRecord(raw)) return [];
|
|
133
|
+
return Object.entries(raw)
|
|
134
|
+
.filter(([key, value]) => key !== 'sellPointModel' && cleanText(key) && cleanText(String(value)))
|
|
135
|
+
.map(([key, value]) => ({ key: cleanText(key), value: cleanText(String(value)) }));
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
function uniqueServices(payload: ItemBrowserPayload): BuyerProtectionModel[] {
|
|
139
|
+
const combined = [
|
|
140
|
+
...(Array.isArray(payload.services) ? payload.services : []),
|
|
141
|
+
...(Array.isArray(payload.shipping?.protectionInfos) ? payload.shipping.protectionInfos : []),
|
|
142
|
+
...(Array.isArray(payload.shipping?.buyerProtectionModel) ? payload.shipping.buyerProtectionModel : []),
|
|
143
|
+
];
|
|
144
|
+
|
|
145
|
+
const seen = new Set<string>();
|
|
146
|
+
const result: BuyerProtectionModel[] = [];
|
|
147
|
+
for (const service of combined) {
|
|
148
|
+
const key = cleanText(service.serviceName);
|
|
149
|
+
if (!key || seen.has(key)) continue;
|
|
150
|
+
seen.add(key);
|
|
151
|
+
result.push(service);
|
|
152
|
+
}
|
|
153
|
+
return result;
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
function stripAlibabaSuffix(title: string | undefined): string {
|
|
157
|
+
return cleanText(title).replace(/\s*-\s*阿里巴巴$/, '').trim();
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
function firstNonEmptyLine(text: string): string {
|
|
161
|
+
return text.split('\n').map((line) => cleanText(line)).find(Boolean) ?? '';
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
function extractMoqText(bodyText: string, beginAmount: string | number | undefined, unit: string): string {
|
|
165
|
+
const lineMatch = bodyText.match(/\d+(?:\.\d+)?\s*(件|个|套|箱|包|双|台|把|只)\s*起批/);
|
|
166
|
+
if (lineMatch) return lineMatch[0];
|
|
167
|
+
|
|
168
|
+
const moqValue = toNumber(beginAmount);
|
|
169
|
+
if (moqValue !== null) {
|
|
170
|
+
return `${moqValue}${unit || ''}起批`;
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
return '';
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
function extractDeliveryDaysText(
|
|
177
|
+
bodyText: string,
|
|
178
|
+
services: BuyerProtectionModel[],
|
|
179
|
+
shipping: ItemBrowserPayload['shipping'],
|
|
180
|
+
): string | null {
|
|
181
|
+
const shippingText = cleanText(shipping?.deliveryLimitText) || cleanText(shipping?.logisticsText);
|
|
182
|
+
if (shippingText) return shippingText;
|
|
183
|
+
|
|
184
|
+
const textMatch = bodyText.match(/\d+\s*(?:小时|天)(?:内)?发货/);
|
|
185
|
+
if (textMatch) return textMatch[0];
|
|
186
|
+
|
|
187
|
+
const hourMatch = services.find((service) => typeof service.agreeDeliveryHours === 'number');
|
|
188
|
+
if (hourMatch && typeof hourMatch.agreeDeliveryHours === 'number') {
|
|
189
|
+
return `${hourMatch.agreeDeliveryHours}小时内发货`;
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
return null;
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
function extractKeywordLine(bodyText: string, keywords: string[]): string | null {
|
|
196
|
+
const lines = bodyText.split('\n').map((line) => cleanText(line)).filter(Boolean);
|
|
197
|
+
for (const line of lines) {
|
|
198
|
+
if (keywords.some((keyword) => line.includes(keyword))) {
|
|
199
|
+
return line;
|
|
200
|
+
}
|
|
201
|
+
}
|
|
202
|
+
return null;
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
function extractSalesText(bodyText: string): string | null {
|
|
206
|
+
const match = bodyText.match(/(?:全网销量|已售)\s*\d+(?:\.\d+)?\+?\s*[件套个单]?/);
|
|
207
|
+
return match ? cleanText(match[0]) : null;
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
function extractStockQuantity(bodyText: string): number | null {
|
|
211
|
+
const match = bodyText.match(/库存\s*(\d+)/);
|
|
212
|
+
return match ? Number.parseInt(match[1], 10) : null;
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
async function readItemPayload(page: IPage, itemUrl: string): Promise<ItemBrowserPayload> {
|
|
216
|
+
const state = await gotoAndReadState(page, itemUrl, 2500, 'item');
|
|
217
|
+
assertAuthenticatedState(state, 'item');
|
|
218
|
+
|
|
219
|
+
const payload = await page.evaluate(`
|
|
220
|
+
(() => {
|
|
221
|
+
const root = window.context ?? {};
|
|
222
|
+
const model = root.result?.global?.globalData?.model ?? null;
|
|
223
|
+
const toJson = (value) => JSON.parse(JSON.stringify(value ?? null));
|
|
224
|
+
return {
|
|
225
|
+
href: window.location.href,
|
|
226
|
+
title: document.title || '',
|
|
227
|
+
bodyText: document.body ? document.body.innerText || '' : '',
|
|
228
|
+
offerTitle: model?.offerTitleModel?.subject ?? '',
|
|
229
|
+
offerId: model?.tradeModel?.offerId ?? '',
|
|
230
|
+
seller: toJson(model?.sellerModel),
|
|
231
|
+
trade: toJson(model?.tradeModel),
|
|
232
|
+
gallery: toJson(root.result?.data?.gallery?.fields ?? null),
|
|
233
|
+
shipping: toJson(root.result?.data?.shippingServices?.fields ?? null),
|
|
234
|
+
services: toJson(root.result?.data?.shippingServices?.fields?.protectionInfos ?? []),
|
|
235
|
+
};
|
|
236
|
+
})()
|
|
237
|
+
`) as ItemBrowserPayload;
|
|
238
|
+
|
|
239
|
+
const resolvedOfferId = cleanText(String(payload.offerId ?? '')) || extractOfferId(cleanText(payload.href));
|
|
240
|
+
if (!resolvedOfferId) {
|
|
241
|
+
throw new CommandExecutionError(
|
|
242
|
+
'1688 item page did not expose product context',
|
|
243
|
+
'当前 tab 非商品详情上下文,请切到 detail.1688.com 商品页并重试',
|
|
244
|
+
);
|
|
245
|
+
}
|
|
246
|
+
|
|
247
|
+
return payload;
|
|
248
|
+
}
|
|
249
|
+
|
|
250
|
+
cli({
|
|
251
|
+
site: '1688',
|
|
252
|
+
name: 'item',
|
|
253
|
+
description: '1688 商品详情(公开商品字段、价格阶梯、卖家基础信息)',
|
|
254
|
+
domain: 'www.1688.com',
|
|
255
|
+
strategy: Strategy.COOKIE,
|
|
256
|
+
navigateBefore: false,
|
|
257
|
+
args: [
|
|
258
|
+
{
|
|
259
|
+
name: 'input',
|
|
260
|
+
required: true,
|
|
261
|
+
positional: true,
|
|
262
|
+
help: '1688 商品 URL 或 offer ID(如 887904326744)',
|
|
263
|
+
},
|
|
264
|
+
],
|
|
265
|
+
columns: ['offer_id', 'title', 'price_text', 'moq_text', 'seller_name', 'origin_place'],
|
|
266
|
+
func: async (page, kwargs) => {
|
|
267
|
+
const itemUrl = buildDetailUrl(String(kwargs.input ?? ''));
|
|
268
|
+
const payload = await readItemPayload(page, itemUrl);
|
|
269
|
+
return [normalizeItemPayload(payload)];
|
|
270
|
+
},
|
|
271
|
+
});
|
|
272
|
+
|
|
273
|
+
export const __test__ = {
|
|
274
|
+
normalizeItemPayload,
|
|
275
|
+
normalizeVisibleAttributes,
|
|
276
|
+
stripAlibabaSuffix,
|
|
277
|
+
extractMoqText,
|
|
278
|
+
extractDeliveryDaysText,
|
|
279
|
+
extractKeywordLine,
|
|
280
|
+
extractSalesText,
|
|
281
|
+
extractStockQuantity,
|
|
282
|
+
};
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
import { describe, expect, it } from 'vitest';
|
|
2
|
+
import { __test__ } from './search.js';
|
|
3
|
+
|
|
4
|
+
describe('1688 search normalization', () => {
|
|
5
|
+
it('normalizes search candidates into structured result rows', () => {
|
|
6
|
+
const result = __test__.normalizeSearchCandidate({
|
|
7
|
+
item_url: 'https://detail.1688.com/offer/887904326744.html',
|
|
8
|
+
title: '宿舍置物架桌面加高架',
|
|
9
|
+
container_text: '宿舍置物架桌面加高架 ¥56.00 2套起批 山东青岛 已售300+套',
|
|
10
|
+
price_text: '¥ 56 .00',
|
|
11
|
+
sales_text: '300+套',
|
|
12
|
+
moq_text: '2套起批',
|
|
13
|
+
tag_items: ['退货包运费', '回头率52%'],
|
|
14
|
+
hover_items: ['验厂报告'],
|
|
15
|
+
seller_name: '青岛沁澜衣品服装有限公司',
|
|
16
|
+
seller_url: 'https://yinuoweierfushi.1688.com/page/index.html?spm=a123',
|
|
17
|
+
}, 'https://s.1688.com/selloffer/offer_search.htm?charset=utf8&keywords=置物架');
|
|
18
|
+
|
|
19
|
+
expect(result.rank).toBe(0);
|
|
20
|
+
expect(result.offer_id).toBe('887904326744');
|
|
21
|
+
expect(result.shop_id).toBe('yinuoweierfushi');
|
|
22
|
+
expect(result.item_url).toBe('https://detail.1688.com/offer/887904326744.html');
|
|
23
|
+
expect(result.seller_url).toBe('https://yinuoweierfushi.1688.com');
|
|
24
|
+
expect(result.price_text).toBe('¥56.00');
|
|
25
|
+
expect(result.price_min).toBe(56);
|
|
26
|
+
expect(result.price_max).toBe(56);
|
|
27
|
+
expect(result.moq_value).toBe(2);
|
|
28
|
+
expect(result.location).toBe('山东青岛');
|
|
29
|
+
expect(result.sales_text).toBe('300+套');
|
|
30
|
+
expect(result.badges).toEqual(expect.arrayContaining(['退货包运费', '验厂报告']));
|
|
31
|
+
expect(result.return_rate_text).toBe('回头率52%');
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
it('does not use hover_price_text as MOQ source', () => {
|
|
35
|
+
const result = __test__.normalizeSearchCandidate({
|
|
36
|
+
item_url: 'https://detail.1688.com/offer/887904326744.html',
|
|
37
|
+
title: 'test',
|
|
38
|
+
container_text: 'test ¥56.00',
|
|
39
|
+
price_text: '¥ 56 .00',
|
|
40
|
+
hover_price_text: '¥56.00 3件起批',
|
|
41
|
+
moq_text: null,
|
|
42
|
+
}, 'https://s.1688.com/selloffer/offer_search.htm?charset=utf8&keywords=test');
|
|
43
|
+
// hover_price_text should not be used for MOQ extraction
|
|
44
|
+
expect(result.moq_text).toBeNull();
|
|
45
|
+
expect(result.moq_value).toBeNull();
|
|
46
|
+
});
|
|
47
|
+
|
|
48
|
+
it('extracts offer id from mobile detail search links', () => {
|
|
49
|
+
const result = __test__.normalizeSearchCandidate({
|
|
50
|
+
item_url: 'http://detail.m.1688.com/page/index.html?offerId=910933345396&sortType=&pageId=',
|
|
51
|
+
title: '',
|
|
52
|
+
container_text: '桌面书桌办公室工位收纳展示新中式博古架多层茶具厨房摆放置物架 ¥24.3 已售20+件',
|
|
53
|
+
price_text: '¥ 14 .28',
|
|
54
|
+
sales_text: '1500+件',
|
|
55
|
+
moq_text: '≥2个',
|
|
56
|
+
seller_name: '泰商国际贸易(宁阳)有限公司',
|
|
57
|
+
seller_url: 'http://tsgjmy.1688.com/',
|
|
58
|
+
}, 'https://s.1688.com/selloffer/offer_search.htm?charset=utf8&keywords=桌面置物架');
|
|
59
|
+
|
|
60
|
+
expect(result.offer_id).toBe('910933345396');
|
|
61
|
+
expect(result.shop_id).toBe('tsgjmy');
|
|
62
|
+
expect(result.item_url).toBe('https://detail.1688.com/offer/910933345396.html');
|
|
63
|
+
expect(result.title).toContain('桌面书桌办公室工位收纳展示');
|
|
64
|
+
expect(result.price_text).toBe('¥14.28');
|
|
65
|
+
expect(result.sales_text).toBe('1500+件');
|
|
66
|
+
expect(result.moq_text).toBe('≥2个');
|
|
67
|
+
expect(result.moq_value).toBe(2);
|
|
68
|
+
});
|
|
69
|
+
|
|
70
|
+
it('prefers offer id and falls back to item url for dedupe key', () => {
|
|
71
|
+
expect(__test__.buildDedupeKey({
|
|
72
|
+
offer_id: '123456',
|
|
73
|
+
item_url: 'https://detail.1688.com/offer/123456.html',
|
|
74
|
+
})).toBe('offer:123456');
|
|
75
|
+
expect(__test__.buildDedupeKey({
|
|
76
|
+
offer_id: null,
|
|
77
|
+
item_url: 'https://detail.1688.com/offer/123456.html',
|
|
78
|
+
})).toBe('url:https://detail.1688.com/offer/123456.html');
|
|
79
|
+
expect(__test__.buildDedupeKey({ offer_id: null, item_url: null })).toBeNull();
|
|
80
|
+
});
|
|
81
|
+
});
|