@gobing-ai/knowledge-kit 0.1.19 → 0.1.22
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/.claude-plugin/marketplace.json +1 -1
- package/dist/board/collect/index.js +1 -0
- package/dist/board/daily-voice/index.js +1315 -264
- package/dist/board/itc/index.js +1 -0
- package/dist/index.js +14674 -8775
- package/package.json +1 -1
- package/plugins/generations/dailynews-gen/dist/index.js +285 -16
- package/plugins/generations/dailynews-gen/src/editorial-claims.ts +215 -0
- package/plugins/generations/dailynews-gen/src/index.ts +23 -4
- package/plugins/generations/dailynews-gen/src/script-builder.ts +10 -3
- package/plugins/generations/dailynews-gen/src/script-plan.ts +74 -14
- package/plugins/generations/image-gen/README.md +31 -31
- package/plugins/generations/image-gen/assets/sample/provenance.json +314 -0
- package/plugins/generations/image-gen/config.example.yaml +3 -0
- package/plugins/generations/image-gen/dist/index.js +154 -14
- package/plugins/generations/image-gen/presets/SOURCE.md +65 -0
- package/plugins/generations/image-gen/scripts/eval-style-presets.ts +513 -0
- package/plugins/generations/image-gen/scripts/gen-samples.ts +57 -7
- package/plugins/generations/image-gen/src/presets.ts +6 -5
- package/plugins/generations/image-gen/src/providers/h3-local.ts +196 -0
- package/plugins/generations/image-gen/src/providers/types.ts +11 -1
- package/plugins/generations/music-gen/README.md +277 -0
- package/plugins/generations/music-gen/dist/index.js +23544 -0
- package/plugins/generations/music-gen/package.json +24 -0
- package/plugins/generations/music-gen/plugin.json +23 -0
- package/plugins/generations/music-gen/presets/SOURCE.md +39 -0
- package/plugins/generations/music-gen/presets/formats/clip.yaml +21 -0
- package/plugins/generations/music-gen/presets/formats/jingle.yaml +22 -0
- package/plugins/generations/music-gen/presets/formats/loop.yaml +21 -0
- package/plugins/generations/music-gen/presets/formats/song.yaml +31 -0
- package/plugins/generations/music-gen/presets/formats/underscore.yaml +22 -0
- package/plugins/generations/music-gen/presets/themes/ambient-tech.yaml +30 -0
- package/plugins/generations/music-gen/presets/themes/cinematic.yaml +30 -0
- package/plugins/generations/music-gen/presets/themes/lofi.yaml +30 -0
- package/plugins/generations/music-gen/presets/themes/synthwave.yaml +30 -0
- package/plugins/generations/music-gen/scripts/gen-preset-index.ts +181 -0
- package/plugins/generations/music-gen/scripts/resolve-preset.ts +64 -0
- package/plugins/generations/music-gen/src/adapter/index.ts +35 -0
- package/plugins/generations/music-gen/src/adapter/instance.ts +904 -0
- package/plugins/generations/music-gen/src/adapter/offline.ts +124 -0
- package/plugins/generations/music-gen/src/artifact.ts +223 -0
- package/plugins/generations/music-gen/src/audio/checks.ts +618 -0
- package/plugins/generations/music-gen/src/audio/master.ts +267 -0
- package/plugins/generations/music-gen/src/audio/measure.ts +507 -0
- package/plugins/generations/music-gen/src/audio/profile.ts +131 -0
- package/plugins/generations/music-gen/src/audio.ts +122 -0
- package/plugins/generations/music-gen/src/brief.ts +191 -0
- package/plugins/generations/music-gen/src/config.ts +451 -0
- package/plugins/generations/music-gen/src/content.ts +199 -0
- package/plugins/generations/music-gen/src/digest.ts +100 -0
- package/plugins/generations/music-gen/src/index.ts +147 -0
- package/plugins/generations/music-gen/src/job.ts +131 -0
- package/plugins/generations/music-gen/src/plugin.ts +371 -0
- package/plugins/generations/music-gen/src/presets.ts +918 -0
- package/plugins/generations/music-gen/src/render.ts +87 -0
- package/plugins/generations/music-gen/src/request.ts +102 -0
- package/plugins/generations/music-gen/src/spend.ts +495 -0
- package/plugins/generations/music-gen/tsconfig.json +8 -0
- package/plugins/kk/config.example.yaml +3 -0
- package/plugins/kk/decisions/extract/ai-news.yaml +5 -2
- package/plugins/kk/plugin.json +1 -1
- package/plugins/kk/publish-presets/daily-ai-voice.json +48 -7
- package/plugins/kk/schedules/kk-serve.launchd.plist.tmpl +2 -1
- package/plugins/kk/scripts/cover-compositor.ts +380 -32
- package/plugins/kk/scripts/daily-cover-mock.ts +40 -3
- package/plugins/kk/scripts/daily-stages.ts +897 -34
- package/plugins/kk/scripts/episode-identity.ts +180 -0
- package/plugins/kk/scripts/kk-workflow-stages.ts +37 -1
- package/plugins/kk/scripts/music-stages.ts +624 -0
- package/plugins/kk/scripts/news-editorial-ledger.ts +906 -0
- package/plugins/kk/scripts/source-citation.ts +187 -0
- package/plugins/kk/scripts/topic-selection-attempts.ts +446 -0
- package/plugins/kk/scripts/topic-selection-calibration.ts +161 -0
- package/plugins/kk/skills/content-judge/SKILL.md +11 -6
- package/plugins/kk/skills/content-judge/references/music-quality-rubric.md +147 -0
- package/plugins/kk/skills/content-judge/references/rubrics.md +15 -0
- package/plugins/kk/skills/content-safety/SKILL.md +12 -0
- package/plugins/kk/skills/image-authoring/SKILL.md +7 -3
- package/plugins/kk/skills/image-authoring/references/providers.md +27 -0
- package/plugins/kk/skills/image-authoring/references/style-extraction.md +1 -1
- package/plugins/kk/skills/music-authoring/SKILL.md +276 -0
- package/plugins/kk/skills/music-authoring/references/judge-input.md +117 -0
- package/plugins/kk/skills/news-editorial/SKILL.md +102 -15
- package/plugins/kk/skills/news-editorial/references/selection.md +4 -0
- package/plugins/kk/skills/news-editorial/references/style-contract.zh.md +58 -11
- package/plugins/kk/skills/publish/SKILL.md +11 -0
- package/plugins/kk/skills/web-automation/SKILL.md +31 -1
- package/plugins/kk/workflows/kk-collect.yaml +8 -4
- package/plugins/kk/workflows/kk-daily-ai-voice.yaml +10 -9
- package/plugins/kk/workflows/kk-daily-ai-voice2.yaml +11 -9
- package/plugins/kk/workflows/kk-music.yaml +328 -0
- package/plugins/kk/workflows/kk-news-generate.yaml +58 -3
- package/plugins/publishings/bilibili-pub/dist/index.js +11 -1
- package/plugins/publishings/bilibili-pub/dist/profile-check.js +11 -1
- package/plugins/publishings/cnblogs-pub/dist/index.js +11 -1
- package/plugins/publishings/cnblogs-pub/dist/profile-check.js +11 -1
- package/plugins/publishings/csdn-pub/dist/index.js +11 -1
- package/plugins/publishings/csdn-pub/dist/profile-check.js +11 -1
- package/plugins/publishings/infoq-pub/dist/index.js +11 -1
- package/plugins/publishings/infoq-pub/dist/profile-check.js +11 -1
- package/plugins/publishings/jike-pub/dist/index.js +11 -1
- package/plugins/publishings/jike-pub/dist/profile-check.js +11 -1
- package/plugins/publishings/juejin-pub/dist/index.js +11 -1
- package/plugins/publishings/juejin-pub/dist/profile-check.js +11 -1
- package/plugins/publishings/linkedin-pub/dist/index.js +54 -7
- package/plugins/publishings/linkedin-pub/dist/profile-check.js +43 -6
- package/plugins/publishings/linkedin-pub/src/index.ts +52 -6
- package/plugins/publishings/podcast-pub/dist/index.js +586 -20
- package/plugins/publishings/podcast-pub/src/corrections.ts +509 -0
- package/plugins/publishings/podcast-pub/src/index.ts +257 -5
- package/plugins/publishings/podcast-pub/src/show-notes-brief.ts +240 -0
- package/plugins/publishings/podcast-pub/src/show-notes.ts +69 -13
- package/plugins/publishings/shipinhao-pub/dist/index.js +437 -32
- package/plugins/publishings/shipinhao-pub/dist/profile-check.js +14 -2
- package/plugins/publishings/shipinhao-pub/plugin.json +1 -1
- package/plugins/publishings/shipinhao-pub/src/audio-flow.ts +492 -0
- package/plugins/publishings/shipinhao-pub/src/flow.ts +227 -12
- package/plugins/publishings/shipinhao-pub/src/selectors.ts +13 -0
- package/plugins/publishings/sspai-pub/dist/index.js +11 -1
- package/plugins/publishings/sspai-pub/dist/profile-check.js +11 -1
- package/plugins/publishings/substack-pub/dist/index.js +11 -1
- package/plugins/publishings/substack-pub/dist/profile-check.js +11 -1
- package/plugins/publishings/surfdash-pub/dist/index.js +122 -28
- package/plugins/publishings/surfdash-pub/src/digest-check.ts +7 -3
- package/plugins/publishings/surfdash-pub/src/index.ts +159 -25
- package/plugins/publishings/surfdash-pub/src/topic-claims.ts +37 -4
- package/plugins/publishings/threads-pub/dist/index.js +9206 -296
- package/plugins/publishings/threads-pub/dist/profile-check.js +21149 -0
- package/plugins/publishings/threads-pub/package.json +3 -1
- package/plugins/publishings/threads-pub/plugin.json +6 -1
- package/plugins/publishings/threads-pub/src/index.ts +8 -1
- package/plugins/publishings/threads-pub/src/post-rail.ts +357 -0
- package/plugins/publishings/threads-pub/src/profile-check.ts +17 -0
- package/plugins/publishings/wechatmp-pub/dist/index.js +18 -1
- package/plugins/publishings/wechatmp-pub/dist/profile-check.js +11 -1
- package/plugins/publishings/wechatmp-pub/src/flow.ts +13 -0
- package/plugins/publishings/weibo-pub/dist/index.js +57 -3
- package/plugins/publishings/weibo-pub/dist/profile-check.js +11 -1
- package/plugins/publishings/weibo-pub/src/index.ts +74 -2
- package/plugins/publishings/x-pub/dist/index.js +274 -44
- package/plugins/publishings/x-pub/dist/profile-check.js +14 -2
- package/plugins/publishings/x-pub/src/index.ts +15 -1
- package/plugins/publishings/x-pub/src/post-rail.ts +334 -0
- package/plugins/publishings/xhs-pub/dist/index.js +11 -1
- package/plugins/publishings/xhs-pub/dist/profile-check.js +11 -1
- package/plugins/publishings/xiaoyuzhou-pub/dist/index.js +11 -1
- package/plugins/publishings/xiaoyuzhou-pub/dist/profile-check.js +11 -1
|
@@ -20758,6 +20758,9 @@ async function ensureProfileDir2(profileDir, headless) {
|
|
|
20758
20758
|
var MAX_QUEUED_BYTES = 8 * 1024 * 1024;
|
|
20759
20759
|
// ../../packages/publish-harness/src/browser.ts
|
|
20760
20760
|
var DEFAULT_CHECK_TIMEOUT_MS = 30000;
|
|
20761
|
+
var VERDICT_PRINT_MARGIN_MS = 2000;
|
|
20762
|
+
var MIN_PASS_BUDGET_MS = 5000;
|
|
20763
|
+
var PASS_LAUNCH_RESERVE_MS = 20000;
|
|
20761
20764
|
var DEFAULT_POLL_MS = 500;
|
|
20762
20765
|
function isInstantBrowserDeath(message) {
|
|
20763
20766
|
return /target page, context or browser has been closed|browser has been closed|target closed/i.test(message);
|
|
@@ -20880,14 +20883,21 @@ async function checkChannelSession(config, opts) {
|
|
|
20880
20883
|
const timeoutMs = opts.timeoutMs ?? DEFAULT_CHECK_TIMEOUT_MS;
|
|
20881
20884
|
const passes = opts.headedOnly ? [false] : opts.headedFallback === false ? [true] : [true, false];
|
|
20882
20885
|
let lastDetail = `${config.channel} readiness was never probed`;
|
|
20886
|
+
const deadline = Date.now() + timeoutMs;
|
|
20887
|
+
const printMarginMs = Math.min(VERDICT_PRINT_MARGIN_MS, Math.floor(timeoutMs / 4));
|
|
20888
|
+
const minPassMs = Math.min(MIN_PASS_BUDGET_MS, Math.floor(timeoutMs / 3));
|
|
20889
|
+
const launchReserveMs = Math.min(PASS_LAUNCH_RESERVE_MS, Math.floor(timeoutMs / 3));
|
|
20883
20890
|
for (const headless of passes) {
|
|
20891
|
+
const remainingMs = deadline - Date.now() - printMarginMs - launchReserveMs;
|
|
20892
|
+
if (remainingMs < minPassMs)
|
|
20893
|
+
break;
|
|
20884
20894
|
try {
|
|
20885
20895
|
await withProfilePage({
|
|
20886
20896
|
profileDir: opts.profileDir,
|
|
20887
20897
|
headless,
|
|
20888
20898
|
url: config.homeUrl,
|
|
20889
20899
|
isAuthenticated: config.isAuthenticated,
|
|
20890
|
-
timeoutMs,
|
|
20900
|
+
timeoutMs: remainingMs,
|
|
20891
20901
|
launcher: opts.launcher ?? kkBrowserLauncher
|
|
20892
20902
|
}, async () => true);
|
|
20893
20903
|
return {
|
|
@@ -21028,7 +21038,9 @@ var SHP_VIDEO_SELECTORS = {
|
|
|
21028
21038
|
originalAgreementCheckbox: 'div.declare-body-wrapper input[type="checkbox"].ant-checkbox-input',
|
|
21029
21039
|
originalConfirmLabel: "\u58F0\u660E\u539F\u521B",
|
|
21030
21040
|
saveButton: ['button:text-is("\u4FDD\u5B58\u8349\u7A3F")'],
|
|
21031
|
-
publishButton: ['button:text-is("\u53D1\u8868")', '[role="button"]:text-is("\u53D1\u8868")']
|
|
21041
|
+
publishButton: ['button:text-is("\u53D1\u8868")', '[role="button"]:text-is("\u53D1\u8868")'],
|
|
21042
|
+
collectionEntry: ['button:has-text("\u5408\u96C6")', 'div:has-text("\u5408\u96C6")', 'span:has-text("\u5408\u96C6")'],
|
|
21043
|
+
collectionLabel: "\u5408\u96C6"
|
|
21032
21044
|
};
|
|
21033
21045
|
var SHP_AUDIO_SELECTORS = {
|
|
21034
21046
|
...SHP_VIDEO_SELECTORS,
|
|
@@ -21071,14 +21083,296 @@ var SHP_CONFIG = {
|
|
|
21071
21083
|
checkHeadedOnly: false
|
|
21072
21084
|
};
|
|
21073
21085
|
|
|
21086
|
+
// ../../plugins/publishings/shipinhao-pub/src/audio-flow.ts
|
|
21087
|
+
var SHP_AUDIO_MANAGER_PATH = "/platform/post/audioManager";
|
|
21088
|
+
var SHP_AUDIO_CREATE_PATH = "/platform/post/createAudio";
|
|
21089
|
+
var SHP_AUDIO_TITLE_MAX = 40;
|
|
21090
|
+
var SHP_AUDIO_DESCRIPTION_MAX = 3000;
|
|
21091
|
+
var SHP_AUDIO_RECEIPT_MS = 30000;
|
|
21092
|
+
var receiptBudgetMs = null;
|
|
21093
|
+
function stageFail(message, stage, metadata, evidence) {
|
|
21094
|
+
return ResultSchema.parse({
|
|
21095
|
+
ok: false,
|
|
21096
|
+
target: SHP_TARGET,
|
|
21097
|
+
error: message,
|
|
21098
|
+
effect: "unknown",
|
|
21099
|
+
metadata: { ...metadata, stage, ...evidence === undefined ? {} : { evidence } }
|
|
21100
|
+
});
|
|
21101
|
+
}
|
|
21102
|
+
async function expectOutcome2(probe, timeoutMs, label) {
|
|
21103
|
+
const deadline = Date.now() + timeoutMs;
|
|
21104
|
+
let last = `${label} never observed`;
|
|
21105
|
+
for (;; ) {
|
|
21106
|
+
try {
|
|
21107
|
+
const value = await probe();
|
|
21108
|
+
if (value !== null)
|
|
21109
|
+
return { ok: true, evidence: value };
|
|
21110
|
+
} catch (error) {
|
|
21111
|
+
last = `${label}: ${error instanceof Error ? error.message : String(error)}`;
|
|
21112
|
+
}
|
|
21113
|
+
if (Date.now() >= deadline)
|
|
21114
|
+
return { ok: false, error: last };
|
|
21115
|
+
await new Promise((resolve) => setTimeout(resolve, 500));
|
|
21116
|
+
}
|
|
21117
|
+
}
|
|
21118
|
+
function buildAudioDescription(body, tags) {
|
|
21119
|
+
const topicLine = tags.map((tag) => `#${tag.replace(/^#/, "")}`).join(" ");
|
|
21120
|
+
const combined = topicLine.length > 0 ? `${body.trim()}
|
|
21121
|
+
|
|
21122
|
+
${topicLine}` : body.trim();
|
|
21123
|
+
return combined.slice(0, SHP_AUDIO_DESCRIPTION_MAX);
|
|
21124
|
+
}
|
|
21125
|
+
function clipAudioTitle(title) {
|
|
21126
|
+
return Array.from(title.trim()).slice(0, SHP_AUDIO_TITLE_MAX).join("");
|
|
21127
|
+
}
|
|
21128
|
+
async function openAudioCreate(page, stepTimeoutMs) {
|
|
21129
|
+
await page.goto("https://channels.weixin.qq.com/platform", {
|
|
21130
|
+
waitUntil: "domcontentloaded",
|
|
21131
|
+
timeout: stepTimeoutMs
|
|
21132
|
+
});
|
|
21133
|
+
await page.waitForTimeout(8000);
|
|
21134
|
+
const menu = page.locator('a:has-text("\u5185\u5BB9\u7BA1\u7406")').first();
|
|
21135
|
+
await menu.hover({ timeout: stepTimeoutMs });
|
|
21136
|
+
await page.waitForTimeout(2000);
|
|
21137
|
+
const clicked = await page.evaluate(`(() => {
|
|
21138
|
+
const anchor = Array.from(document.querySelectorAll('a')).find((el) => (el.textContent || '').trim() === '\u97F3\u9891');
|
|
21139
|
+
if (!anchor) return false;
|
|
21140
|
+
anchor.click();
|
|
21141
|
+
return true;
|
|
21142
|
+
})()`);
|
|
21143
|
+
if (!clicked)
|
|
21144
|
+
return "\u97F3\u9891 submenu entry not found under \u5185\u5BB9\u7BA1\u7406";
|
|
21145
|
+
const manager = await expectOutcome2(async () => page.url().includes(SHP_AUDIO_MANAGER_PATH) ? page.url() : null, stepTimeoutMs, "\u97F3\u9891\u7BA1\u7406 page");
|
|
21146
|
+
if (!manager.ok)
|
|
21147
|
+
return `\u97F3\u9891\u7BA1\u7406 page never opened: ${manager.error}`;
|
|
21148
|
+
const entry = page.locator('button:has-text("\u53D1\u8868\u97F3\u9891")').first();
|
|
21149
|
+
const ready = await expectOutcome2(async () => await entry.count() > 0 ? "\u53D1\u8868\u97F3\u9891 entry rendered" : null, stepTimeoutMs, "\u97F3\u9891\u7BA1\u7406 \u53D1\u8868\u97F3\u9891 entry");
|
|
21150
|
+
if (!ready.ok)
|
|
21151
|
+
return `\u53D1\u8868\u97F3\u9891 entry never rendered on \u97F3\u9891\u7BA1\u7406: ${ready.error}`;
|
|
21152
|
+
await entry.click({ timeout: stepTimeoutMs });
|
|
21153
|
+
const create = await expectOutcome2(async () => page.url().includes(SHP_AUDIO_CREATE_PATH) ? page.url() : null, stepTimeoutMs, "\u53D1\u8868\u97F3\u9891 form");
|
|
21154
|
+
if (!create.ok)
|
|
21155
|
+
return `\u53D1\u8868\u97F3\u9891 form never opened: ${create.error}`;
|
|
21156
|
+
return null;
|
|
21157
|
+
}
|
|
21158
|
+
async function attachAudio(page, file, stepTimeoutMs) {
|
|
21159
|
+
const zone = page.locator("text=\u62D6\u62FD\u5230\u6B64\u5904\u4E0A\u4F20").first();
|
|
21160
|
+
if (await zone.count() === 0)
|
|
21161
|
+
return "audio drop zone (\u62D6\u62FD\u5230\u6B64\u5904\u4E0A\u4F20) not found";
|
|
21162
|
+
const chooserPromise = page.waitForEvent("filechooser", { timeout: stepTimeoutMs }).catch(() => null);
|
|
21163
|
+
await zone.click({ timeout: stepTimeoutMs });
|
|
21164
|
+
const chooser = await chooserPromise;
|
|
21165
|
+
if (chooser === null)
|
|
21166
|
+
return "clicking the audio drop zone opened no file chooser";
|
|
21167
|
+
await chooser.setFiles(file);
|
|
21168
|
+
const name = file.split("/").pop() ?? "";
|
|
21169
|
+
const attached = await expectOutcome2(async () => await page.locator(`text=${name.slice(0, 12)}`).count() > 0 ? "file chip rendered" : null, 60000, "audio file chip");
|
|
21170
|
+
if (!attached.ok)
|
|
21171
|
+
return `the file was handed to the form but no file chip appeared: ${attached.error}`;
|
|
21172
|
+
return null;
|
|
21173
|
+
}
|
|
21174
|
+
async function attachAudioCover(page, coverPath, stepTimeoutMs) {
|
|
21175
|
+
const hint = page.locator("text=\u5C01\u9762\u5BBD\u9AD8\u6BD4").first();
|
|
21176
|
+
if (await hint.count() === 0)
|
|
21177
|
+
return "\u97F3\u9891 \u5C01\u9762 hint (\u5C01\u9762\u5BBD\u9AD8\u6BD4) not found";
|
|
21178
|
+
await hint.scrollIntoViewIfNeeded();
|
|
21179
|
+
const box = await hint.boundingBox();
|
|
21180
|
+
if (box === null)
|
|
21181
|
+
return "\u97F3\u9891 \u5C01\u9762 tile has no layout box";
|
|
21182
|
+
const chooserPromise = page.waitForEvent("filechooser", { timeout: stepTimeoutMs }).catch(() => null);
|
|
21183
|
+
await page.mouse.click(box.x + 40, box.y - 70);
|
|
21184
|
+
const chooser = await chooserPromise;
|
|
21185
|
+
if (chooser === null)
|
|
21186
|
+
return "clicking the \u5C01\u9762 tile opened no file chooser";
|
|
21187
|
+
await chooser.setFiles(coverPath);
|
|
21188
|
+
const settled = await expectOutcome2(async () => await coverUploadPending(page) ? null : "cover upload settled", stepTimeoutMs, "\u97F3\u9891 \u5C01\u9762 upload");
|
|
21189
|
+
if (!settled.ok)
|
|
21190
|
+
return `the \u5C01\u9762 file was chosen but its upload never settled: ${settled.error}`;
|
|
21191
|
+
let cropSeen = false;
|
|
21192
|
+
const cropReady = await expectOutcome2(async () => {
|
|
21193
|
+
const dialog = page.locator(CROP_DIALOG).first();
|
|
21194
|
+
const open = await dialog.count() > 0 && await dialog.isVisible().catch(() => false);
|
|
21195
|
+
if (!open)
|
|
21196
|
+
return cropSeen ? "crop dialog closed before it was ready" : null;
|
|
21197
|
+
cropSeen = true;
|
|
21198
|
+
const cropper = page.locator(CROP_IMAGE).first();
|
|
21199
|
+
return await cropper.count() > 0 && await cropper.isVisible().catch(() => false) ? "cropper ready" : null;
|
|
21200
|
+
}, stepTimeoutMs, "\u7F16\u8F91\u97F3\u9891\u5C01\u9762 crop dialog");
|
|
21201
|
+
if (!cropReady.ok)
|
|
21202
|
+
return `the \u5C01\u9762 crop dialog never appeared or its cropper never mounted: ${cropReady.error}`;
|
|
21203
|
+
const cropped = await expectOutcome2(async () => {
|
|
21204
|
+
const dialog = page.locator(CROP_DIALOG).first();
|
|
21205
|
+
if (await dialog.count() === 0 || !await dialog.isVisible().catch(() => false)) {
|
|
21206
|
+
return "crop dialog closed";
|
|
21207
|
+
}
|
|
21208
|
+
await page.locator(`${CROP_DIALOG} button:text-is("\u786E\u8BA4")`).last().click({ timeout: 4000 }).catch(() => {});
|
|
21209
|
+
return null;
|
|
21210
|
+
}, stepTimeoutMs, "\u7F16\u8F91\u97F3\u9891\u5C01\u9762 crop confirm");
|
|
21211
|
+
if (!cropped.ok)
|
|
21212
|
+
return `the \u5C01\u9762 crop dialog never closed: ${cropped.error}`;
|
|
21213
|
+
const cleared = await expectOutcome2(async () => await page.locator("text=\u8BF7\u4E0A\u4F20\u5C01\u9762").count() === 0 ? "cover accepted" : null, stepTimeoutMs, "\u97F3\u9891 \u5C01\u9762 validation");
|
|
21214
|
+
if (!cleared.ok)
|
|
21215
|
+
return `the \u5C01\u9762 was uploaded but the form still reports \u300C\u8BF7\u4E0A\u4F20\u5C01\u9762\u300D: ${cleared.error}`;
|
|
21216
|
+
return null;
|
|
21217
|
+
}
|
|
21218
|
+
var AUDIO_FORM_REFUSALS = ["\u8BF7\u4E0A\u4F20\u5C01\u9762", "\u8BF7\u4E0A\u4F20\u97F3\u9891", "\u8BF7\u586B\u5199\u6807\u9898", "\u8BF7\u586B\u5199\u63CF\u8FF0", "\u8BF7\u9009\u62E9\u5408\u96C6"];
|
|
21219
|
+
async function readSubmitRefusal(page) {
|
|
21220
|
+
for (const text of AUDIO_FORM_REFUSALS) {
|
|
21221
|
+
try {
|
|
21222
|
+
if (await page.locator(`text=${text}`).count() > 0)
|
|
21223
|
+
return text;
|
|
21224
|
+
} catch {}
|
|
21225
|
+
}
|
|
21226
|
+
return null;
|
|
21227
|
+
}
|
|
21228
|
+
var CROP_DIALOG = '.weui-desktop-dialog:has(.cropper-wrap), .weui-desktop-dialog:has-text("\u7F16\u8F91\u97F3\u9891\u5C01\u9762")';
|
|
21229
|
+
var CROP_IMAGE = `${CROP_DIALOG} .cropper-wrap img, ${CROP_DIALOG} .croppie-container img, ${CROP_DIALOG} img`;
|
|
21230
|
+
async function coverUploadPending(page) {
|
|
21231
|
+
try {
|
|
21232
|
+
return await page.locator("text=/\\d{1,3}%/").count() > 0;
|
|
21233
|
+
} catch {
|
|
21234
|
+
return false;
|
|
21235
|
+
}
|
|
21236
|
+
}
|
|
21237
|
+
async function selectAudioCollection(page, collection, stepTimeoutMs) {
|
|
21238
|
+
const picker = page.locator('div.display-text:has-text("\u9009\u62E9\u5408\u96C6")').first();
|
|
21239
|
+
if (await picker.count() === 0)
|
|
21240
|
+
return "\u5408\u96C6 picker (\u9009\u62E9\u5408\u96C6) not found on the audio form";
|
|
21241
|
+
await picker.scrollIntoViewIfNeeded();
|
|
21242
|
+
const row = await picker.elementHandle();
|
|
21243
|
+
await picker.click({ timeout: stepTimeoutMs });
|
|
21244
|
+
await page.waitForTimeout(2000);
|
|
21245
|
+
const option = page.getByText(collection, { exact: true });
|
|
21246
|
+
if (await option.count() === 0)
|
|
21247
|
+
return `\u5408\u96C6 '${collection}' is not among this account's \u97F3\u9891 collections`;
|
|
21248
|
+
await option.last().click({ timeout: stepTimeoutMs });
|
|
21249
|
+
const readback = await expectOutcome2(async () => {
|
|
21250
|
+
const text = (await row?.textContent() ?? "").trim();
|
|
21251
|
+
return text.includes(collection) ? text : null;
|
|
21252
|
+
}, stepTimeoutMs, "\u5408\u96C6 readback");
|
|
21253
|
+
if (!readback.ok)
|
|
21254
|
+
return `\u5408\u96C6 '${collection}' was clicked but the form does not show it: ${readback.error}`;
|
|
21255
|
+
return null;
|
|
21256
|
+
}
|
|
21257
|
+
async function countAudioRows(page, title) {
|
|
21258
|
+
try {
|
|
21259
|
+
return await page.getByText(title, { exact: false }).count();
|
|
21260
|
+
} catch {
|
|
21261
|
+
return 0;
|
|
21262
|
+
}
|
|
21263
|
+
}
|
|
21264
|
+
async function runAudioPostFlow(input) {
|
|
21265
|
+
const { collection, publishPublic, operation, profileDir } = input;
|
|
21266
|
+
const metadata = {
|
|
21267
|
+
operation,
|
|
21268
|
+
driver: "script",
|
|
21269
|
+
publishStatus: publishPublic ? "public" : "draft",
|
|
21270
|
+
profileDir,
|
|
21271
|
+
...collection !== undefined ? { collection } : {}
|
|
21272
|
+
};
|
|
21273
|
+
if (!publishPublic) {
|
|
21274
|
+
return stageFail("shipinhao \u97F3\u9891 has no draft rail \u2014 the \u53D1\u8868\u97F3\u9891 form offers only \u53D1\u8868\u97F3\u9891 (no \u4FDD\u5B58\u8349\u7A3F); request publishStatus: public or publish nothing", "draft-unsupported", metadata);
|
|
21275
|
+
}
|
|
21276
|
+
if (input.coverPath === undefined) {
|
|
21277
|
+
return stageFail("shipinhao \u97F3\u9891 requires a cover (\u5C01\u9762) \u2014 the form refuses to submit without one (\u300C\u8BF7\u4E0A\u4F20\u5C01\u9762\u300D); pass coverPath", "audio-cover", metadata);
|
|
21278
|
+
}
|
|
21279
|
+
return pendingAudioFlow(input, metadata);
|
|
21280
|
+
}
|
|
21281
|
+
async function pendingAudioFlow(input, metadata) {
|
|
21282
|
+
const { page, title, body, tags, media, collection, profileDir, stepTimeoutMs } = input;
|
|
21283
|
+
const audio = media[0];
|
|
21284
|
+
if (audio === undefined)
|
|
21285
|
+
return stageFail("shipinhao \u97F3\u9891 requires one audio file", "media", metadata);
|
|
21286
|
+
const opened = await openAudioCreate(page, stepTimeoutMs);
|
|
21287
|
+
if (opened !== null)
|
|
21288
|
+
return stageFail(opened, "audio-open", metadata);
|
|
21289
|
+
const attached = await attachAudio(page, audio, stepTimeoutMs);
|
|
21290
|
+
if (attached !== null)
|
|
21291
|
+
return stageFail(attached, "audio-upload", metadata);
|
|
21292
|
+
const clipped = clipAudioTitle(title);
|
|
21293
|
+
const description = buildAudioDescription(body, tags);
|
|
21294
|
+
const titleInput = page.locator('input[placeholder="\u8BF7\u586B\u5199\u6807\u9898"]').first();
|
|
21295
|
+
if (await titleInput.count() === 0)
|
|
21296
|
+
return stageFail("\u97F3\u9891 \u6807\u9898 input not found", "audio-title", metadata);
|
|
21297
|
+
await titleInput.fill(clipped);
|
|
21298
|
+
const titleOk = await expectOutcome2(async () => await titleInput.inputValue() === clipped ? "title retained" : null, stepTimeoutMs, "\u97F3\u9891 \u6807\u9898 readback");
|
|
21299
|
+
if (!titleOk.ok)
|
|
21300
|
+
return stageFail(`\u97F3\u9891 \u6807\u9898 readback failed: ${titleOk.error}`, "audio-title", metadata);
|
|
21301
|
+
const descriptionBox = page.locator('textarea[placeholder="\u8BF7\u586B\u5199\u63CF\u8FF0"]').first();
|
|
21302
|
+
if (await descriptionBox.count() === 0)
|
|
21303
|
+
return stageFail("\u97F3\u9891 \u63CF\u8FF0 textarea not found", "audio-description", metadata);
|
|
21304
|
+
await descriptionBox.fill(description);
|
|
21305
|
+
const descriptionOk = await expectOutcome2(async () => (await descriptionBox.inputValue()).length > 0 ? "description retained" : null, stepTimeoutMs, "\u97F3\u9891 \u63CF\u8FF0 readback");
|
|
21306
|
+
if (!descriptionOk.ok) {
|
|
21307
|
+
return stageFail(`\u97F3\u9891 \u63CF\u8FF0 readback failed: ${descriptionOk.error}`, "audio-description", metadata);
|
|
21308
|
+
}
|
|
21309
|
+
const coverPath = input.coverPath;
|
|
21310
|
+
if (coverPath !== undefined) {
|
|
21311
|
+
const cover = await attachAudioCover(page, coverPath, stepTimeoutMs);
|
|
21312
|
+
if (cover !== null)
|
|
21313
|
+
return stageFail(cover, "audio-cover", metadata);
|
|
21314
|
+
}
|
|
21315
|
+
if (collection !== undefined) {
|
|
21316
|
+
const selected = await selectAudioCollection(page, collection, stepTimeoutMs);
|
|
21317
|
+
if (selected !== null)
|
|
21318
|
+
return stageFail(selected, "collection-select", metadata);
|
|
21319
|
+
} else {
|
|
21320
|
+
const readback = await page.locator('div.display-text:has-text("\u9009\u62E9\u5408\u96C6")').count();
|
|
21321
|
+
if (readback === 0) {
|
|
21322
|
+
return stageFail("\u5408\u96C6 row missing before submit", "collection-select", metadata);
|
|
21323
|
+
}
|
|
21324
|
+
}
|
|
21325
|
+
const baseline = await countAudioRows(page, clipped);
|
|
21326
|
+
const submit = page.locator('button:has-text("\u53D1\u8868\u97F3\u9891")').first();
|
|
21327
|
+
if (await submit.count() === 0)
|
|
21328
|
+
return stageFail("\u53D1\u8868\u97F3\u9891 submit control not found", "audio-submit", metadata);
|
|
21329
|
+
if (await submit.isDisabled())
|
|
21330
|
+
return stageFail("\u53D1\u8868\u97F3\u9891 submit control is disabled", "audio-submit", metadata);
|
|
21331
|
+
await submit.click({ timeout: stepTimeoutMs });
|
|
21332
|
+
await page.waitForTimeout(3000);
|
|
21333
|
+
for (const label of ["\u786E\u8BA4\u53D1\u8868", "\u786E\u5B9A"]) {
|
|
21334
|
+
const confirm = page.locator(`button:text-is("${label}")`).first();
|
|
21335
|
+
if (await confirm.count() > 0 && await confirm.isVisible().catch(() => false)) {
|
|
21336
|
+
await confirm.click({ timeout: 5000 }).catch(() => {});
|
|
21337
|
+
break;
|
|
21338
|
+
}
|
|
21339
|
+
}
|
|
21340
|
+
if (page.url().includes(SHP_AUDIO_CREATE_PATH)) {
|
|
21341
|
+
const refusal = await readSubmitRefusal(page);
|
|
21342
|
+
if (refusal !== null) {
|
|
21343
|
+
return stageFail(`shipinhao \u97F3\u9891 submit was refused by the form: \u300C${refusal}\u300D \u2014 nothing was published`, "audio-submit-validation", metadata, `inline validation: ${refusal}`);
|
|
21344
|
+
}
|
|
21345
|
+
}
|
|
21346
|
+
const receipt = await expectOutcome2(async () => {
|
|
21347
|
+
if (!page.url().includes(SHP_AUDIO_MANAGER_PATH))
|
|
21348
|
+
return null;
|
|
21349
|
+
const count = await countAudioRows(page, clipped);
|
|
21350
|
+
if (count <= baseline)
|
|
21351
|
+
return null;
|
|
21352
|
+
return { url: page.url(), rows: count };
|
|
21353
|
+
}, receiptBudgetMs ?? SHP_AUDIO_RECEIPT_MS, "\u97F3\u9891 list row");
|
|
21354
|
+
if (!receipt.ok) {
|
|
21355
|
+
return stageFail("shipinhao \u97F3\u9891 publish-receipt not confirmed \u2014 \u53D1\u8868\u97F3\u9891 was clicked but no new row carrying the title appeared in \u97F3\u9891\u7BA1\u7406; a submit without a works row is unknown and is never reported as published", "audio-receipt", metadata, receipt.error);
|
|
21356
|
+
}
|
|
21357
|
+
return ResultSchema.parse({
|
|
21358
|
+
ok: true,
|
|
21359
|
+
target: SHP_TARGET,
|
|
21360
|
+
url: receipt.evidence.url,
|
|
21361
|
+
message: `shipinhao audio published and confirmed in the \u97F3\u9891 list (${profileDir})`,
|
|
21362
|
+
metadata: { ...metadata, confirmedBy: "audio-list-row", rowsWithTitle: receipt.evidence.rows }
|
|
21363
|
+
});
|
|
21364
|
+
}
|
|
21365
|
+
|
|
21074
21366
|
// ../../plugins/publishings/shipinhao-pub/src/flow.ts
|
|
21075
21367
|
var STEP_TIMEOUT_MS = 30000;
|
|
21368
|
+
var PREFLIGHT_TIMEOUT_MS = 180000;
|
|
21369
|
+
var COLLECTION_PROBE_MS = 2000;
|
|
21076
21370
|
var MAX_VIDEO_BYTES = 2 * 1024 * 1024 * 1024;
|
|
21077
21371
|
var SHP_LOGIN_INSTRUCTION = "bun plugins/publishings/shipinhao-pub/src/profile-check.ts login";
|
|
21078
21372
|
function fail(target, error) {
|
|
21079
21373
|
return ResultSchema.parse({ ok: false, target, error: boundedDetail(error) });
|
|
21080
21374
|
}
|
|
21081
|
-
function
|
|
21375
|
+
function stageFail2(target, error, stage, metadata, evidence, effect = "none") {
|
|
21082
21376
|
return ResultSchema.parse({
|
|
21083
21377
|
ok: false,
|
|
21084
21378
|
target,
|
|
@@ -21375,12 +21669,20 @@ function resolveOriginal(raw) {
|
|
|
21375
21669
|
}
|
|
21376
21670
|
return { original: raw };
|
|
21377
21671
|
}
|
|
21672
|
+
function resolveCollection(raw) {
|
|
21673
|
+
if (raw === undefined)
|
|
21674
|
+
return {};
|
|
21675
|
+
if (typeof raw !== "string" || raw.trim().length === 0) {
|
|
21676
|
+
return { error: `collection must be a nonempty string when present, got '${bounded(raw)}'` };
|
|
21677
|
+
}
|
|
21678
|
+
return { collection: raw.trim() };
|
|
21679
|
+
}
|
|
21378
21680
|
function unsupportedFields(payload, operation) {
|
|
21379
21681
|
const perOperation = {
|
|
21380
|
-
shortVideo: ["images", "categories", "publishTime", "scheduling"],
|
|
21682
|
+
shortVideo: ["images", "categories", "publishTime", "scheduling", "collection"],
|
|
21381
21683
|
audio: ["videoPath", "images", "categories", "publishTime", "scheduling"],
|
|
21382
|
-
music: ["videoPath", "images", "categories", "publishTime", "scheduling"],
|
|
21383
|
-
image: ["videoPath", "coverPath", "categories", "publishTime", "scheduling"]
|
|
21684
|
+
music: ["videoPath", "images", "categories", "publishTime", "scheduling", "collection"],
|
|
21685
|
+
image: ["videoPath", "coverPath", "categories", "publishTime", "scheduling", "collection"]
|
|
21384
21686
|
};
|
|
21385
21687
|
const refused = [];
|
|
21386
21688
|
for (const [container, source] of [
|
|
@@ -21409,6 +21711,40 @@ function editingFormReadyScript(mode, titleSelector, editorSelector) {
|
|
|
21409
21711
|
return JSON.stringify({ ready: title !== null && editor !== null });
|
|
21410
21712
|
})()`;
|
|
21411
21713
|
}
|
|
21714
|
+
function collectionScript(mode, action, label, name) {
|
|
21715
|
+
return `${rootScriptPrefix(mode)} // kk-shp-collection
|
|
21716
|
+
const label = ${JSON.stringify(label)};
|
|
21717
|
+
const name = ${JSON.stringify(name)};
|
|
21718
|
+
const action = ${JSON.stringify(action)};
|
|
21719
|
+
const roots = [document, root].filter(Boolean);
|
|
21720
|
+
const ownText = (el) => Array.from(el.childNodes).filter((n) => n.nodeType === 3).map((n) => (n.textContent || '').trim()).join(' ').trim();
|
|
21721
|
+
const rendered = (el) => { const r = el.getBoundingClientRect(); return r.width > 0 && r.height > 0; };
|
|
21722
|
+
const all = [];
|
|
21723
|
+
for (const scope of roots) {
|
|
21724
|
+
if (!scope || !scope.querySelectorAll) continue;
|
|
21725
|
+
for (const el of scope.querySelectorAll('*')) all.push(el);
|
|
21726
|
+
}
|
|
21727
|
+
const row = all.find((el) => rendered(el) && ownText(el).startsWith(label));
|
|
21728
|
+
if (action === 'click-entry') {
|
|
21729
|
+
if (!row) return JSON.stringify({ ok: false, reason: 'entry-absent' });
|
|
21730
|
+
const target = row.closest('button, div, li, label') || row;
|
|
21731
|
+
target.click();
|
|
21732
|
+
return JSON.stringify({ ok: true, text: String(row.textContent || '').trim().slice(0, 80) });
|
|
21733
|
+
}
|
|
21734
|
+
if (action === 'click-option') {
|
|
21735
|
+
const exact = all.filter((el) => rendered(el) && ownText(el) === name);
|
|
21736
|
+
if (exact.length > 0) {
|
|
21737
|
+
const option = exact[exact.length - 1];
|
|
21738
|
+
(option.closest('li, div, label, button') || option).click();
|
|
21739
|
+
return JSON.stringify({ ok: true, how: 'text' });
|
|
21740
|
+
}
|
|
21741
|
+
const near = all.filter((el) => rendered(el) && ownText(el).includes(name)).map((el) => ownText(el).slice(0, 40));
|
|
21742
|
+
return JSON.stringify({ ok: false, reason: 'option-absent', seen: [...new Set(near)].slice(0, 8) });
|
|
21743
|
+
}
|
|
21744
|
+
const state = row === undefined ? '' : String(row.textContent || '').trim().slice(0, 120);
|
|
21745
|
+
return JSON.stringify({ ok: state.includes(name), text: state });
|
|
21746
|
+
})()`;
|
|
21747
|
+
}
|
|
21412
21748
|
function originalEntryScript(mode, action) {
|
|
21413
21749
|
const ensure = action === "ensure";
|
|
21414
21750
|
return `${rootScriptPrefix(mode)}
|
|
@@ -21548,11 +21884,13 @@ class ShipinhaoBrowserTransport {
|
|
|
21548
21884
|
operation;
|
|
21549
21885
|
launcher;
|
|
21550
21886
|
stepTimeoutMs;
|
|
21887
|
+
preflightTimeoutMs;
|
|
21551
21888
|
constructor(operation = "shortVideo", driver = "script", deps = {}) {
|
|
21552
21889
|
this.operation = operation;
|
|
21553
21890
|
this.driver = driver;
|
|
21554
21891
|
this.launcher = deps.launcher ?? kkBrowserLauncher;
|
|
21555
21892
|
this.stepTimeoutMs = deps.stepTimeoutMs ?? STEP_TIMEOUT_MS;
|
|
21893
|
+
this.preflightTimeoutMs = deps.preflightTimeoutMs ?? PREFLIGHT_TIMEOUT_MS;
|
|
21556
21894
|
}
|
|
21557
21895
|
async publish(payload) {
|
|
21558
21896
|
if (this.driver !== "script") {
|
|
@@ -21590,7 +21928,7 @@ class ShipinhaoBrowserTransport {
|
|
|
21590
21928
|
if (audio.error !== undefined)
|
|
21591
21929
|
return fail(SHP_TARGET, audio.error);
|
|
21592
21930
|
media = [audio.path];
|
|
21593
|
-
const cover = await resolveCoverPath(payload.content.metadata?.coverPath ?? payload.options?.coverPath);
|
|
21931
|
+
const cover = await resolveCoverPath(payload.content.metadata?.coverPath ?? payload.options?.coverPath ?? metadataRecord.coverImage);
|
|
21594
21932
|
if (cover.error !== undefined)
|
|
21595
21933
|
return fail(SHP_TARGET, cover.error);
|
|
21596
21934
|
coverPath = cover.path;
|
|
@@ -21606,6 +21944,9 @@ class ShipinhaoBrowserTransport {
|
|
|
21606
21944
|
const original = resolveOriginal(payload.content.metadata?.original);
|
|
21607
21945
|
if (original.error !== undefined)
|
|
21608
21946
|
return fail(SHP_TARGET, original.error);
|
|
21947
|
+
const collection = resolveCollection(payload.options?.collection ?? payload.content.metadata?.collection);
|
|
21948
|
+
if (collection.error !== undefined)
|
|
21949
|
+
return fail(SHP_TARGET, collection.error);
|
|
21609
21950
|
const unsupported = unsupportedFields(payload, this.operation);
|
|
21610
21951
|
if (unsupported.length > 0) {
|
|
21611
21952
|
return fail(SHP_TARGET, `unsupported field(s) ${unsupported.join(", ")} for shipinhao ${this.operation}: implemented fields are title/description/tags/media/cover/original declaration only, and scheduling/publishTime is an unported vendor enhancement (shipinhao.js:7-9)`);
|
|
@@ -21615,11 +21956,10 @@ class ShipinhaoBrowserTransport {
|
|
|
21615
21956
|
const session = await checkChannelSession(SHP_CONFIG, {
|
|
21616
21957
|
profileDir,
|
|
21617
21958
|
launcher: this.launcher,
|
|
21618
|
-
|
|
21619
|
-
timeoutMs: this.stepTimeoutMs
|
|
21959
|
+
timeoutMs: this.preflightTimeoutMs
|
|
21620
21960
|
});
|
|
21621
21961
|
if (session.status !== "verified") {
|
|
21622
|
-
return
|
|
21962
|
+
return stageFail2(SHP_TARGET, `${SHP_TARGET} session preflight refused \u2014 run: ${SHP_LOGIN_INSTRUCTION} \u2014 detail: ${session.detail}`, "session-preflight", { operation: this.operation, publishStatus: "draft" }, undefined, "none");
|
|
21623
21963
|
}
|
|
21624
21964
|
try {
|
|
21625
21965
|
return await withProfilePage({
|
|
@@ -21629,53 +21969,71 @@ class ShipinhaoBrowserTransport {
|
|
|
21629
21969
|
headless: payload.options?.headless === true,
|
|
21630
21970
|
launcher: this.launcher,
|
|
21631
21971
|
timeoutMs: this.stepTimeoutMs
|
|
21632
|
-
}, async ({ page }) =>
|
|
21972
|
+
}, async ({ page }) => {
|
|
21973
|
+
if (this.operation === "audio") {
|
|
21974
|
+
return runAudioPostFlow({
|
|
21975
|
+
page,
|
|
21976
|
+
title,
|
|
21977
|
+
body,
|
|
21978
|
+
tags: tags.tags,
|
|
21979
|
+
media,
|
|
21980
|
+
coverPath,
|
|
21981
|
+
collection: collection.collection,
|
|
21982
|
+
publishPublic: requested === "public",
|
|
21983
|
+
operation: this.operation,
|
|
21984
|
+
profileDir,
|
|
21985
|
+
stepTimeoutMs: this.stepTimeoutMs
|
|
21986
|
+
});
|
|
21987
|
+
}
|
|
21988
|
+
return this.runPostFlow(page, POST_FLOW_SPECS[this.operation], title, body, tags.tags, original.original === true, collection.collection, media, coverPath, requested === "public", profileDir);
|
|
21989
|
+
});
|
|
21633
21990
|
} catch (error) {
|
|
21634
21991
|
const detail = errorMessage3(error);
|
|
21635
21992
|
return fail(SHP_TARGET, needsLogin(error) ? `${SHP_TARGET} session failed \u2014 run: ${SHP_LOGIN_INSTRUCTION} \u2014 detail: ${detail}` : detail);
|
|
21636
21993
|
}
|
|
21637
21994
|
}
|
|
21638
|
-
async runPostFlow(page, spec, title, body, tags, declareOriginal, media, coverPath, publishPublic, profileDir) {
|
|
21995
|
+
async runPostFlow(page, spec, title, body, tags, declareOriginal, collection, media, coverPath, publishPublic, profileDir) {
|
|
21639
21996
|
const publishStatus = publishPublic ? "public" : "draft";
|
|
21640
21997
|
const metadata = {
|
|
21641
21998
|
operation: this.operation,
|
|
21642
21999
|
driver: this.driver,
|
|
21643
22000
|
publishStatus,
|
|
21644
22001
|
profileDir,
|
|
21645
|
-
...declareOriginal ? { original: true } : {}
|
|
22002
|
+
...declareOriginal ? { original: true } : {},
|
|
22003
|
+
...collection !== undefined ? { collection } : {}
|
|
21646
22004
|
};
|
|
21647
22005
|
const entrySnapshot = await readRootSnapshot(page);
|
|
21648
22006
|
if (entrySnapshot.shadowFileInputs + entrySnapshot.directFileInputs === 0) {
|
|
21649
22007
|
const entryRoot = await resolveCreatorRoot(page);
|
|
21650
22008
|
if (entryRoot.error !== undefined)
|
|
21651
|
-
return
|
|
22009
|
+
return stageFail2(SHP_TARGET, entryRoot.error, "root-resolve", metadata);
|
|
21652
22010
|
try {
|
|
21653
22011
|
const entry = (await resolveRootLocator(page, entryRoot.mode, spec.selectors.createEntry, "shipinhao create entry", this.stepTimeoutMs)).locator;
|
|
21654
22012
|
await entry.click();
|
|
21655
22013
|
} catch (error) {
|
|
21656
|
-
return
|
|
22014
|
+
return stageFail2(SHP_TARGET, `shipinhao create entry click failed \u2014 ${errorMessage3(error)}`, "entry-open", metadata);
|
|
21657
22015
|
}
|
|
21658
22016
|
const opened = await expectOutcome(async () => {
|
|
21659
22017
|
const snapshot = await readRootSnapshot(page);
|
|
21660
22018
|
return snapshot.shadowFileInputs + snapshot.directFileInputs > 0 ? "create surface open" : null;
|
|
21661
22019
|
}, { timeoutMs: this.stepTimeoutMs, label: "shipinhao create surface" });
|
|
21662
22020
|
if (!opened.ok)
|
|
21663
|
-
return
|
|
22021
|
+
return stageFail2(SHP_TARGET, `shipinhao create surface never opened after the entry click \u2014 no media file input appeared in the active root \u2014 ${opened.error}`, "entry-open", metadata);
|
|
21664
22022
|
}
|
|
21665
22023
|
const root = await resolveCreatorRoot(page);
|
|
21666
22024
|
if (root.error !== undefined)
|
|
21667
|
-
return
|
|
22025
|
+
return stageFail2(SHP_TARGET, root.error, "root-resolve", metadata);
|
|
21668
22026
|
const mode = root.mode;
|
|
21669
22027
|
try {
|
|
21670
22028
|
const resolved = await resolveRootLocator(page, mode, spec.fileSelectors, `shipinhao ${spec.mediaLabel} file input`, this.stepTimeoutMs);
|
|
21671
22029
|
if (resolved.selector === 'input[type="file"]' && await resolved.locator.count() !== 1) {
|
|
21672
|
-
return
|
|
22030
|
+
return stageFail2(SHP_TARGET, `shipinhao ${spec.mediaLabel} file input ambiguous: the untyped input[type=file] candidate matched more than one input in the ${mode === "wujie" ? "wujie shadowRoot" : "document"} root \u2014 the vendor resolves a unique untyped input or nothing (shipinhao.js:580-583)`, "root-resolve", metadata);
|
|
21673
22031
|
}
|
|
21674
22032
|
await resolved.locator.setInputFiles(media.length === 1 ? media[0] : media, {
|
|
21675
22033
|
timeout: this.stepTimeoutMs
|
|
21676
22034
|
});
|
|
21677
22035
|
} catch (error) {
|
|
21678
|
-
return
|
|
22036
|
+
return stageFail2(SHP_TARGET, `shipinhao ${spec.mediaLabel} file input/attach failed on ${page.url()}: ${errorMessage3(error)}`, "upload-timeout", metadata);
|
|
21679
22037
|
}
|
|
21680
22038
|
let titleSelector;
|
|
21681
22039
|
let editorSelector;
|
|
@@ -21683,23 +22041,23 @@ class ShipinhaoBrowserTransport {
|
|
|
21683
22041
|
titleSelector = (await resolveRootLocator(page, mode, spec.selectors.titleInput, "shipinhao title input", this.stepTimeoutMs)).selector;
|
|
21684
22042
|
editorSelector = (await resolveRootLocator(page, mode, spec.selectors.descriptionEditor, "shipinhao description editor", this.stepTimeoutMs)).selector;
|
|
21685
22043
|
} catch (error) {
|
|
21686
|
-
return
|
|
22044
|
+
return stageFail2(SHP_TARGET, `shipinhao media processing not confirmed: the file was assigned but the post-upload editing form never appeared \u2014 ${errorMessage3(error)}; refusing to claim an uploaded ${spec.mediaLabel}`, "upload-processing", metadata);
|
|
21687
22045
|
}
|
|
21688
22046
|
const formReady = await expectOutcome(async () => {
|
|
21689
22047
|
const raw = String(await page.evaluate(editingFormReadyScript(mode, titleSelector, editorSelector)));
|
|
21690
22048
|
return JSON.parse(raw).ready === true ? "editing form observed in the active root" : null;
|
|
21691
22049
|
}, { timeoutMs: SHP_UPLOAD_TIMEOUT_MS, label: "shipinhao media processing" });
|
|
21692
22050
|
if (!formReady.ok) {
|
|
21693
|
-
return
|
|
22051
|
+
return stageFail2(SHP_TARGET, `shipinhao media processing not confirmed within the ${SHP_UPLOAD_TIMEOUT_MS}ms ceiling \u2014 the file was assigned but no editing form appeared; refusing to claim an uploaded ${spec.mediaLabel}`, "upload-processing", metadata);
|
|
21694
22052
|
}
|
|
21695
22053
|
try {
|
|
21696
22054
|
const titleInput = (await resolveRootLocator(page, mode, spec.selectors.titleInput, "shipinhao title input", this.stepTimeoutMs)).locator;
|
|
21697
22055
|
await titleInput.fill(title);
|
|
21698
22056
|
const readback = await expectOutcome(async () => normalizeText(String(await page.evaluate(titleValueScript(mode, titleSelector)))) === normalizeText(title) ? "title read back" : null, { timeoutMs: this.stepTimeoutMs, label: "shipinhao title readback" });
|
|
21699
22057
|
if (!readback.ok)
|
|
21700
|
-
return
|
|
22058
|
+
return stageFail2(SHP_TARGET, `shipinhao title readback failed \u2014 the editor did not retain the requested title \u2014 ${readback.error}`, "title-readback", metadata);
|
|
21701
22059
|
} catch (error) {
|
|
21702
|
-
return
|
|
22060
|
+
return stageFail2(SHP_TARGET, `shipinhao title fill failed \u2014 ${errorMessage3(error)}`, "title-readback", metadata);
|
|
21703
22061
|
}
|
|
21704
22062
|
const { description, html } = buildShipinhaoDescription(body, tags);
|
|
21705
22063
|
try {
|
|
@@ -21710,9 +22068,14 @@ class ShipinhaoBrowserTransport {
|
|
|
21710
22068
|
return editorText.length > 0 && normalizeText(editorText).includes(normalizeText(description)) && tags.every((tag) => editorText.includes(`#${tag.replace(/^#/, "")}`)) ? "description and topics read back" : null;
|
|
21711
22069
|
}, { timeoutMs: this.stepTimeoutMs, label: "shipinhao description paste readback" });
|
|
21712
22070
|
if (!readback.ok)
|
|
21713
|
-
return
|
|
22071
|
+
return stageFail2(SHP_TARGET, `shipinhao description readback failed \u2014 the editor did not retain the pasted description/topics \u2014 ${readback.error}`, "description-paste-readback", metadata);
|
|
21714
22072
|
} catch (error) {
|
|
21715
|
-
return
|
|
22073
|
+
return stageFail2(SHP_TARGET, `shipinhao description paste failed \u2014 ${errorMessage3(error)}`, "description-paste-readback", metadata);
|
|
22074
|
+
}
|
|
22075
|
+
if (collection !== undefined) {
|
|
22076
|
+
const collected = await this.selectCollectionFlow(page, mode, spec, collection, metadata);
|
|
22077
|
+
if (collected !== undefined)
|
|
22078
|
+
return collected;
|
|
21716
22079
|
}
|
|
21717
22080
|
if (declareOriginal) {
|
|
21718
22081
|
const declaration = await this.declareOriginalFlow(page, mode, metadata);
|
|
@@ -21731,17 +22094,17 @@ class ShipinhaoBrowserTransport {
|
|
|
21731
22094
|
const resolved = await resolveRootLocator(page, mode, submitSelectors, "shipinhao submit control", this.stepTimeoutMs);
|
|
21732
22095
|
submitLocator = resolved.locator;
|
|
21733
22096
|
} catch (error) {
|
|
21734
|
-
return
|
|
22097
|
+
return stageFail2(SHP_TARGET, publishPublic ? `shipinhao publish control never attached: ${errorMessage3(error)} (the vendor resolves \u53D1\u8868 by exact text, shipinhao.js:2312-2316)` : `shipinhao draft-save control never attached: ${errorMessage3(error)} \u2014 the vendor never saves a draft, so a missing current control is a typed failure, not a manufactured draft and never a publish click`, stage, metadata);
|
|
21735
22098
|
}
|
|
21736
22099
|
if (!await submitLocator.isVisible().catch(() => false)) {
|
|
21737
|
-
return
|
|
22100
|
+
return stageFail2(SHP_TARGET, "shipinhao submit control attached but not visible; refusing to submit through a hidden control", stage, metadata);
|
|
21738
22101
|
}
|
|
21739
22102
|
const enabled = await expectOutcome(async () => await submitLocator.isEnabled() ? "enabled" : null, {
|
|
21740
22103
|
timeoutMs: this.stepTimeoutMs,
|
|
21741
22104
|
label: "shipinhao submit control enabled"
|
|
21742
22105
|
});
|
|
21743
22106
|
if (!enabled.ok) {
|
|
21744
|
-
return
|
|
22107
|
+
return stageFail2(SHP_TARGET, `shipinhao submit control never became clickable \u2014 ${enabled.error}`, stage, metadata);
|
|
21745
22108
|
}
|
|
21746
22109
|
const receiptStage = publishPublic ? "publish-receipt" : "draft-receipt";
|
|
21747
22110
|
const beforeReceipts = new Set(await readReceiptUrls(page));
|
|
@@ -21775,10 +22138,10 @@ class ShipinhaoBrowserTransport {
|
|
|
21775
22138
|
return url;
|
|
21776
22139
|
}, { timeoutMs: this.stepTimeoutMs, label: `shipinhao ${receiptStage} confirmation` });
|
|
21777
22140
|
if (!confirmed.ok) {
|
|
21778
|
-
return
|
|
22141
|
+
return stageFail2(SHP_TARGET, publishPublic ? "shipinhao publish-receipt not confirmed \u2014 no fresh id-bearing works/record receipt with persisted state appeared; a clicked \u53D1\u8868 without a works record is unknown (shipinhao.js:2326) and is never reported as published" : "shipinhao draft-receipt not confirmed \u2014 no fresh id-bearing receipt with persisted title/description state appeared; fill alone is never a saved draft", receiptStage, metadata, `still on ${page.url()}; ${beforeReceipts.size} pre-existing receipt-shaped url(s)`, "unknown");
|
|
21779
22142
|
}
|
|
21780
22143
|
if (confirmed.evidence.startsWith("stale-state: ") || confirmed.evidence.startsWith("ambiguous-receipt: ")) {
|
|
21781
|
-
return
|
|
22144
|
+
return stageFail2(SHP_TARGET, confirmed.evidence.startsWith("stale-state: ") ? "shipinhao receipt appeared but the persisted title/description(/original/cover) state no longer matches the requested content; refusing to claim success" : "shipinhao receipt is ambiguous (no single id-bearing works URL among the fresh receipts); refusing to claim success", receiptStage, metadata, confirmed.evidence, "unknown");
|
|
21782
22145
|
}
|
|
21783
22146
|
const url = confirmed.evidence;
|
|
21784
22147
|
return ResultSchema.parse({
|
|
@@ -21790,8 +22153,50 @@ class ShipinhaoBrowserTransport {
|
|
|
21790
22153
|
metadata: { ...metadata, confirmedBy: receiptStage }
|
|
21791
22154
|
});
|
|
21792
22155
|
}
|
|
22156
|
+
async selectCollectionFlow(page, mode, spec, collection, metadata) {
|
|
22157
|
+
const failCollection = (message, stage, evidence) => stageFail2(SHP_TARGET, message, stage, metadata, evidence);
|
|
22158
|
+
const label = spec.selectors.collectionLabel;
|
|
22159
|
+
const read = (raw) => {
|
|
22160
|
+
try {
|
|
22161
|
+
return JSON.parse(raw);
|
|
22162
|
+
} catch {
|
|
22163
|
+
return { ok: false, reason: "unreadable-probe" };
|
|
22164
|
+
}
|
|
22165
|
+
};
|
|
22166
|
+
const entry = read(String(await page.evaluate(collectionScript(mode, "click-entry", label, collection))));
|
|
22167
|
+
if (!entry.ok) {
|
|
22168
|
+
return failCollection(`shipinhao \u5408\u96C6 (collection) row not found on the ${this.operation} form \u2014 refusing to publish outside the requested \u5408\u96C6 '${collection}'`, "collection-select", entry.reason);
|
|
22169
|
+
}
|
|
22170
|
+
const option = await expectOutcome(async () => {
|
|
22171
|
+
const picked = read(String(await page.evaluate(collectionScript(mode, "click-option", label, collection))));
|
|
22172
|
+
if (picked.ok)
|
|
22173
|
+
return "option clicked";
|
|
22174
|
+
const selects = page.locator("select");
|
|
22175
|
+
const count = await selects.count();
|
|
22176
|
+
for (let i = 0;i < count; i++) {
|
|
22177
|
+
try {
|
|
22178
|
+
await selects.nth(i).selectOption({ label: collection }, { timeout: COLLECTION_PROBE_MS });
|
|
22179
|
+
return "option selected";
|
|
22180
|
+
} catch {}
|
|
22181
|
+
}
|
|
22182
|
+
return null;
|
|
22183
|
+
}, { timeoutMs: this.stepTimeoutMs, label: "shipinhao \u5408\u96C6 option" });
|
|
22184
|
+
if (!option.ok) {
|
|
22185
|
+
const seen = read(String(await page.evaluate(collectionScript(mode, "click-option", label, collection))));
|
|
22186
|
+
return failCollection(`shipinhao \u5408\u96C6 '${collection}' is not among the collections the account offers \u2014 refusing to publish outside it`, "collection-select", `${option.error}; seen: ${(seen.seen ?? []).join(" | ")}`);
|
|
22187
|
+
}
|
|
22188
|
+
const commit = await expectOutcome(async () => {
|
|
22189
|
+
const state = read(String(await page.evaluate(collectionScript(mode, "read", label, collection))));
|
|
22190
|
+
return state.ok ? "collection read back" : null;
|
|
22191
|
+
}, { timeoutMs: this.stepTimeoutMs, label: "shipinhao \u5408\u96C6 readback" });
|
|
22192
|
+
if (!commit.ok) {
|
|
22193
|
+
const state = read(String(await page.evaluate(collectionScript(mode, "read", label, collection))));
|
|
22194
|
+
return failCollection(`shipinhao \u5408\u96C6 '${collection}' was clicked but the form does not show it committed \u2014 refusing to submit`, "collection-readback", `row text: ${state.text ?? "<absent>"} \u2014 ${commit.error}`);
|
|
22195
|
+
}
|
|
22196
|
+
return;
|
|
22197
|
+
}
|
|
21793
22198
|
async declareOriginalFlow(page, mode, metadata) {
|
|
21794
|
-
const failDeclaration = (message, evidence) =>
|
|
22199
|
+
const failDeclaration = (message, evidence) => stageFail2(SHP_TARGET, message, "original-declare", metadata, evidence);
|
|
21795
22200
|
const entry = JSON.parse(String(await page.evaluate(originalEntryScript(mode, "ensure"))));
|
|
21796
22201
|
if (!entry.ok) {
|
|
21797
22202
|
return failDeclaration(entry.reason === "ambiguous" ? `shipinhao \u58F0\u660E\u539F\u521B entry checkbox is ambiguous (${entry.count} equally-scored \u539F\u521B candidates, shipinhao.js:2233-2261); refusing the requested declaration rather than guessing` : "shipinhao \u58F0\u660E\u539F\u521B entry checkbox not found \u2014 the requested original declaration cannot be verified on this page; refusing (the vendor skips with a log only because it never treats the claim as operator-asserted, shipinhao.js:2274)");
|
|
@@ -21825,7 +22230,7 @@ class ShipinhaoBrowserTransport {
|
|
|
21825
22230
|
return;
|
|
21826
22231
|
}
|
|
21827
22232
|
async attachCoverFlow(page, mode, coverPath, metadata) {
|
|
21828
|
-
const failCover = (message, stage, evidence) =>
|
|
22233
|
+
const failCover = (message, stage, evidence) => stageFail2(SHP_TARGET, message, stage, metadata, evidence);
|
|
21829
22234
|
const before = JSON.parse(String(await page.evaluate(coverSlotEvidenceScript(mode))));
|
|
21830
22235
|
if (!before.found || before.descriptor === undefined) {
|
|
21831
22236
|
return failCover("shipinhao vertical cover slot (\u4E2A\u4EBA\u4E3B\u9875\u5361\u7247 3:4, div.cover-preview-wrap) not found \u2014 refusing the requested cover (shipinhao.js:2128-2144)", "cover-open");
|