@gobing-ai/knowledge-kit 0.1.17 → 0.1.20

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (95) hide show
  1. package/.claude-plugin/marketplace.json +1 -1
  2. package/dist/board/daily-voice/index.js +40 -7
  3. package/dist/index.js +8428 -4448
  4. package/package.json +1 -1
  5. package/plugins/generations/image-gen/README.md +31 -31
  6. package/plugins/generations/image-gen/assets/sample/provenance.json +314 -0
  7. package/plugins/generations/image-gen/config.example.yaml +3 -0
  8. package/plugins/generations/image-gen/dist/index.js +154 -14
  9. package/plugins/generations/image-gen/presets/SOURCE.md +65 -0
  10. package/plugins/generations/image-gen/scripts/eval-style-presets.ts +513 -0
  11. package/plugins/generations/image-gen/scripts/gen-samples.ts +57 -7
  12. package/plugins/generations/image-gen/src/presets.ts +6 -5
  13. package/plugins/generations/image-gen/src/providers/h3-local.ts +196 -0
  14. package/plugins/generations/image-gen/src/providers/types.ts +11 -1
  15. package/plugins/kk/config.example.yaml +7 -2
  16. package/plugins/kk/decisions/extract/ai-news.yaml +5 -2
  17. package/plugins/kk/plugin.json +1 -1
  18. package/plugins/kk/publish-presets/chinese-article.json +8 -2
  19. package/plugins/kk/publish-presets/daily-ai-voice-migration.json +1 -1
  20. package/plugins/kk/publish-presets/daily-ai-voice.json +57 -16
  21. package/plugins/kk/publish-presets/itc-main.json +36 -9
  22. package/plugins/kk/publish-presets/technical-article.json +8 -2
  23. package/plugins/kk/schedules/kk-daily-ai-voice3.cron.tmpl +8 -9
  24. package/plugins/kk/schedules/kk-daily-publish3-cn-peak.cron.tmpl +13 -19
  25. package/plugins/kk/schedules/kk-daily-publish3-overseas.cron.tmpl +11 -9
  26. package/plugins/kk/scripts/daily-stages.ts +238 -14
  27. package/plugins/kk/scripts/daily-triage-core.ts +43 -25
  28. package/plugins/kk/scripts/daily-triage.ts +1 -1
  29. package/plugins/kk/skills/image-authoring/SKILL.md +7 -3
  30. package/plugins/kk/skills/image-authoring/references/providers.md +27 -0
  31. package/plugins/kk/skills/image-authoring/references/style-extraction.md +1 -1
  32. package/plugins/kk/skills/publish/SKILL.md +15 -2
  33. package/plugins/kk/skills/web-automation/SKILL.md +31 -1
  34. package/plugins/kk/workflows/kk-article-generate.yaml +485 -0
  35. package/plugins/kk/workflows/kk-collect.yaml +8 -4
  36. package/plugins/kk/workflows/kk-daily-ai-voice.yaml +2 -1
  37. package/plugins/kk/workflows/kk-daily-ai-voice2.yaml +4 -2
  38. package/plugins/kk/workflows/kk-daily-safety.yaml +5 -7
  39. package/plugins/kk/workflows/kk-news-generate.yaml +410 -0
  40. package/plugins/kk/workflows/kk-publish.yaml +236 -0
  41. package/plugins/publishings/bilibili-pub/dist/profile-check.js +49 -10
  42. package/plugins/publishings/cnblogs-pub/dist/profile-check.js +60 -10
  43. package/plugins/publishings/csdn-pub/dist/profile-check.js +60 -10
  44. package/plugins/publishings/infoq-pub/dist/profile-check.js +60 -10
  45. package/plugins/publishings/jike-pub/dist/profile-check.js +60 -10
  46. package/plugins/publishings/juejin-pub/dist/profile-check.js +60 -10
  47. package/plugins/publishings/linkedin-pub/dist/index.js +43 -6
  48. package/plugins/publishings/linkedin-pub/dist/profile-check.js +92 -15
  49. package/plugins/publishings/linkedin-pub/src/index.ts +52 -6
  50. package/plugins/publishings/shipinhao-pub/dist/index.js +391 -32
  51. package/plugins/publishings/shipinhao-pub/dist/profile-check.js +52 -11
  52. package/plugins/publishings/shipinhao-pub/plugin.json +1 -1
  53. package/plugins/publishings/shipinhao-pub/src/audio-flow.ts +393 -0
  54. package/plugins/publishings/shipinhao-pub/src/flow.ts +243 -14
  55. package/plugins/publishings/shipinhao-pub/src/selectors.ts +13 -0
  56. package/plugins/publishings/sspai-pub/dist/profile-check.js +60 -10
  57. package/plugins/publishings/substack-pub/dist/profile-check.js +60 -10
  58. package/plugins/publishings/surfdash-pub/dist/index.js +50 -8
  59. package/plugins/publishings/surfdash-pub/src/index.ts +59 -8
  60. package/plugins/publishings/surfdash-pub/src/topic-claims.ts +34 -3
  61. package/plugins/publishings/threads-pub/dist/index.js +9196 -296
  62. package/plugins/publishings/threads-pub/dist/profile-check.js +21139 -0
  63. package/plugins/publishings/threads-pub/package.json +3 -1
  64. package/plugins/publishings/threads-pub/plugin.json +6 -1
  65. package/plugins/publishings/threads-pub/src/index.ts +8 -1
  66. package/plugins/publishings/threads-pub/src/post-rail.ts +357 -0
  67. package/plugins/publishings/threads-pub/src/profile-check.ts +17 -0
  68. package/plugins/publishings/wechatmp-pub/dist/index.js +454 -81
  69. package/plugins/publishings/wechatmp-pub/dist/profile-check.js +401 -102
  70. package/plugins/publishings/wechatmp-pub/src/flow.ts +42 -4
  71. package/plugins/publishings/wechatmp-pub/src/index.ts +142 -102
  72. package/plugins/publishings/wechatmp-pub/src/profile-check.ts +36 -58
  73. package/plugins/publishings/weibo-pub/dist/index.js +136 -22
  74. package/plugins/publishings/weibo-pub/dist/profile-check.js +61 -11
  75. package/plugins/publishings/weibo-pub/src/index.ts +208 -22
  76. package/plugins/publishings/x-pub/dist/index.js +263 -43
  77. package/plugins/publishings/x-pub/dist/profile-check.js +63 -11
  78. package/plugins/publishings/x-pub/src/index.ts +15 -1
  79. package/plugins/publishings/x-pub/src/post-rail.ts +334 -0
  80. package/plugins/publishings/xhs-pub/dist/index.js +193 -201
  81. package/plugins/publishings/xhs-pub/dist/profile-check.js +380 -85
  82. package/plugins/publishings/xhs-pub/src/automation-guard.ts +2 -3
  83. package/plugins/publishings/xhs-pub/src/flow.ts +177 -205
  84. package/plugins/publishings/xhs-pub/src/index.ts +65 -59
  85. package/plugins/publishings/xhs-pub/src/modes.ts +1 -1
  86. package/plugins/publishings/xhs-pub/src/page.ts +2 -2
  87. package/plugins/publishings/xhs-pub/src/profile-check.ts +86 -150
  88. package/plugins/publishings/xiaoyuzhou-pub/dist/profile-check.js +60 -10
  89. package/plugins/kk/scripts/daily-scheduled-run.ts +0 -581
  90. package/plugins/kk/scripts/voice3-publish-window.ts +0 -206
  91. package/plugins/kk/workflows/kk-daily-ai-voice3.yaml +0 -903
  92. package/plugins/kk/workflows/kk-daily-publish3.yaml +0 -353
  93. package/plugins/kk/workflows/kk-itc-author.yaml +0 -484
  94. package/plugins/kk/workflows/kk-itc-publish-tail.yaml +0 -112
  95. package/plugins/kk/workflows/kk-itc.yaml +0 -291
@@ -21028,7 +21028,9 @@ var SHP_VIDEO_SELECTORS = {
21028
21028
  originalAgreementCheckbox: 'div.declare-body-wrapper input[type="checkbox"].ant-checkbox-input',
21029
21029
  originalConfirmLabel: "\u58F0\u660E\u539F\u521B",
21030
21030
  saveButton: ['button:text-is("\u4FDD\u5B58\u8349\u7A3F")'],
21031
- publishButton: ['button:text-is("\u53D1\u8868")', '[role="button"]:text-is("\u53D1\u8868")']
21031
+ publishButton: ['button:text-is("\u53D1\u8868")', '[role="button"]:text-is("\u53D1\u8868")'],
21032
+ collectionEntry: ['button:has-text("\u5408\u96C6")', 'div:has-text("\u5408\u96C6")', 'span:has-text("\u5408\u96C6")'],
21033
+ collectionLabel: "\u5408\u96C6"
21032
21034
  };
21033
21035
  var SHP_AUDIO_SELECTORS = {
21034
21036
  ...SHP_VIDEO_SELECTORS,
@@ -21071,19 +21073,265 @@ var SHP_CONFIG = {
21071
21073
  checkHeadedOnly: false
21072
21074
  };
21073
21075
 
21076
+ // ../../plugins/publishings/shipinhao-pub/src/audio-flow.ts
21077
+ var SHP_AUDIO_MANAGER_PATH = "/platform/post/audioManager";
21078
+ var SHP_AUDIO_CREATE_PATH = "/platform/post/createAudio";
21079
+ var SHP_AUDIO_TITLE_MAX = 40;
21080
+ var SHP_AUDIO_DESCRIPTION_MAX = 3000;
21081
+ var SHP_AUDIO_RECEIPT_MS = 30000;
21082
+ var receiptBudgetMs = null;
21083
+ function stageFail(message, stage, metadata, evidence) {
21084
+ return ResultSchema.parse({
21085
+ ok: false,
21086
+ target: SHP_TARGET,
21087
+ error: message,
21088
+ effect: "unknown",
21089
+ metadata: { ...metadata, stage, ...evidence === undefined ? {} : { evidence } }
21090
+ });
21091
+ }
21092
+ async function expectOutcome2(probe, timeoutMs, label) {
21093
+ const deadline = Date.now() + timeoutMs;
21094
+ let last = `${label} never observed`;
21095
+ for (;; ) {
21096
+ try {
21097
+ const value = await probe();
21098
+ if (value !== null)
21099
+ return { ok: true, evidence: value };
21100
+ } catch (error) {
21101
+ last = `${label}: ${error instanceof Error ? error.message : String(error)}`;
21102
+ }
21103
+ if (Date.now() >= deadline)
21104
+ return { ok: false, error: last };
21105
+ await new Promise((resolve) => setTimeout(resolve, 500));
21106
+ }
21107
+ }
21108
+ function buildAudioDescription(body, tags) {
21109
+ const topicLine = tags.map((tag) => `#${tag.replace(/^#/, "")}`).join(" ");
21110
+ const combined = topicLine.length > 0 ? `${body.trim()}
21111
+
21112
+ ${topicLine}` : body.trim();
21113
+ return combined.slice(0, SHP_AUDIO_DESCRIPTION_MAX);
21114
+ }
21115
+ function clipAudioTitle(title) {
21116
+ return Array.from(title.trim()).slice(0, SHP_AUDIO_TITLE_MAX).join("");
21117
+ }
21118
+ async function openAudioCreate(page, stepTimeoutMs) {
21119
+ await page.goto("https://channels.weixin.qq.com/platform", {
21120
+ waitUntil: "domcontentloaded",
21121
+ timeout: stepTimeoutMs
21122
+ });
21123
+ await page.waitForTimeout(8000);
21124
+ const menu = page.locator('a:has-text("\u5185\u5BB9\u7BA1\u7406")').first();
21125
+ await menu.hover({ timeout: stepTimeoutMs });
21126
+ await page.waitForTimeout(2000);
21127
+ const clicked = await page.evaluate(`(() => {
21128
+ const anchor = Array.from(document.querySelectorAll('a')).find((el) => (el.textContent || '').trim() === '\u97F3\u9891');
21129
+ if (!anchor) return false;
21130
+ anchor.click();
21131
+ return true;
21132
+ })()`);
21133
+ if (!clicked)
21134
+ return "\u97F3\u9891 submenu entry not found under \u5185\u5BB9\u7BA1\u7406";
21135
+ const manager = await expectOutcome2(async () => page.url().includes(SHP_AUDIO_MANAGER_PATH) ? page.url() : null, stepTimeoutMs, "\u97F3\u9891\u7BA1\u7406 page");
21136
+ if (!manager.ok)
21137
+ return `\u97F3\u9891\u7BA1\u7406 page never opened: ${manager.error}`;
21138
+ const entry = page.locator('button:has-text("\u53D1\u8868\u97F3\u9891")').first();
21139
+ 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");
21140
+ if (!ready.ok)
21141
+ return `\u53D1\u8868\u97F3\u9891 entry never rendered on \u97F3\u9891\u7BA1\u7406: ${ready.error}`;
21142
+ await entry.click({ timeout: stepTimeoutMs });
21143
+ const create = await expectOutcome2(async () => page.url().includes(SHP_AUDIO_CREATE_PATH) ? page.url() : null, stepTimeoutMs, "\u53D1\u8868\u97F3\u9891 form");
21144
+ if (!create.ok)
21145
+ return `\u53D1\u8868\u97F3\u9891 form never opened: ${create.error}`;
21146
+ return null;
21147
+ }
21148
+ async function attachAudio(page, file, stepTimeoutMs) {
21149
+ const zone = page.locator("text=\u62D6\u62FD\u5230\u6B64\u5904\u4E0A\u4F20").first();
21150
+ if (await zone.count() === 0)
21151
+ return "audio drop zone (\u62D6\u62FD\u5230\u6B64\u5904\u4E0A\u4F20) not found";
21152
+ const chooserPromise = page.waitForEvent("filechooser", { timeout: stepTimeoutMs }).catch(() => null);
21153
+ await zone.click({ timeout: stepTimeoutMs });
21154
+ const chooser = await chooserPromise;
21155
+ if (chooser === null)
21156
+ return "clicking the audio drop zone opened no file chooser";
21157
+ await chooser.setFiles(file);
21158
+ const name = file.split("/").pop() ?? "";
21159
+ const attached = await expectOutcome2(async () => await page.locator(`text=${name.slice(0, 12)}`).count() > 0 ? "file chip rendered" : null, 60000, "audio file chip");
21160
+ if (!attached.ok)
21161
+ return `the file was handed to the form but no file chip appeared: ${attached.error}`;
21162
+ return null;
21163
+ }
21164
+ async function attachAudioCover(page, coverPath, stepTimeoutMs) {
21165
+ const hint = page.locator("text=\u5C01\u9762\u5BBD\u9AD8\u6BD4").first();
21166
+ if (await hint.count() === 0)
21167
+ return "\u97F3\u9891 \u5C01\u9762 hint (\u5C01\u9762\u5BBD\u9AD8\u6BD4) not found";
21168
+ await hint.scrollIntoViewIfNeeded();
21169
+ const box = await hint.boundingBox();
21170
+ if (box === null)
21171
+ return "\u97F3\u9891 \u5C01\u9762 tile has no layout box";
21172
+ const chooserPromise = page.waitForEvent("filechooser", { timeout: stepTimeoutMs }).catch(() => null);
21173
+ await page.mouse.click(box.x + 40, box.y - 70);
21174
+ const chooser = await chooserPromise;
21175
+ if (chooser === null)
21176
+ return "clicking the \u5C01\u9762 tile opened no file chooser";
21177
+ await chooser.setFiles(coverPath);
21178
+ const cropped = await expectOutcome2(async () => {
21179
+ const confirm = page.locator('button:text-is("\u786E\u8BA4")').first();
21180
+ if (await confirm.count() === 0 || !await confirm.isVisible().catch(() => false))
21181
+ return null;
21182
+ await confirm.click({ timeout: 4000 }).catch(() => {});
21183
+ return "crop confirmed";
21184
+ }, stepTimeoutMs, "\u7F16\u8F91\u97F3\u9891\u5C01\u9762 crop dialog");
21185
+ if (!cropped.ok)
21186
+ return `the \u5C01\u9762 crop dialog never appeared: ${cropped.error}`;
21187
+ 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");
21188
+ if (!cleared.ok)
21189
+ return `the \u5C01\u9762 was uploaded but the form still reports \u300C\u8BF7\u4E0A\u4F20\u5C01\u9762\u300D: ${cleared.error}`;
21190
+ return null;
21191
+ }
21192
+ async function selectAudioCollection(page, collection, stepTimeoutMs) {
21193
+ const picker = page.locator('div.display-text:has-text("\u9009\u62E9\u5408\u96C6")').first();
21194
+ if (await picker.count() === 0)
21195
+ return "\u5408\u96C6 picker (\u9009\u62E9\u5408\u96C6) not found on the audio form";
21196
+ await picker.scrollIntoViewIfNeeded();
21197
+ const row = await picker.elementHandle();
21198
+ await picker.click({ timeout: stepTimeoutMs });
21199
+ await page.waitForTimeout(2000);
21200
+ const option = page.getByText(collection, { exact: true });
21201
+ if (await option.count() === 0)
21202
+ return `\u5408\u96C6 '${collection}' is not among this account's \u97F3\u9891 collections`;
21203
+ await option.last().click({ timeout: stepTimeoutMs });
21204
+ const readback = await expectOutcome2(async () => {
21205
+ const text = (await row?.textContent() ?? "").trim();
21206
+ return text.includes(collection) ? text : null;
21207
+ }, stepTimeoutMs, "\u5408\u96C6 readback");
21208
+ if (!readback.ok)
21209
+ return `\u5408\u96C6 '${collection}' was clicked but the form does not show it: ${readback.error}`;
21210
+ return null;
21211
+ }
21212
+ async function countAudioRows(page, title) {
21213
+ try {
21214
+ return await page.getByText(title, { exact: false }).count();
21215
+ } catch {
21216
+ return 0;
21217
+ }
21218
+ }
21219
+ async function runAudioPostFlow(input) {
21220
+ const { collection, publishPublic, operation, profileDir } = input;
21221
+ const metadata = {
21222
+ operation,
21223
+ driver: "script",
21224
+ publishStatus: publishPublic ? "public" : "draft",
21225
+ profileDir,
21226
+ ...collection !== undefined ? { collection } : {}
21227
+ };
21228
+ if (!publishPublic) {
21229
+ 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);
21230
+ }
21231
+ if (input.coverPath === undefined) {
21232
+ 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);
21233
+ }
21234
+ return pendingAudioFlow(input, metadata);
21235
+ }
21236
+ async function pendingAudioFlow(input, metadata) {
21237
+ const { page, title, body, tags, media, collection, profileDir, stepTimeoutMs } = input;
21238
+ const audio = media[0];
21239
+ if (audio === undefined)
21240
+ return stageFail("shipinhao \u97F3\u9891 requires one audio file", "media", metadata);
21241
+ const opened = await openAudioCreate(page, stepTimeoutMs);
21242
+ if (opened !== null)
21243
+ return stageFail(opened, "audio-open", metadata);
21244
+ const attached = await attachAudio(page, audio, stepTimeoutMs);
21245
+ if (attached !== null)
21246
+ return stageFail(attached, "audio-upload", metadata);
21247
+ const clipped = clipAudioTitle(title);
21248
+ const description = buildAudioDescription(body, tags);
21249
+ const titleInput = page.locator('input[placeholder="\u8BF7\u586B\u5199\u6807\u9898"]').first();
21250
+ if (await titleInput.count() === 0)
21251
+ return stageFail("\u97F3\u9891 \u6807\u9898 input not found", "audio-title", metadata);
21252
+ await titleInput.fill(clipped);
21253
+ const titleOk = await expectOutcome2(async () => await titleInput.inputValue() === clipped ? "title retained" : null, stepTimeoutMs, "\u97F3\u9891 \u6807\u9898 readback");
21254
+ if (!titleOk.ok)
21255
+ return stageFail(`\u97F3\u9891 \u6807\u9898 readback failed: ${titleOk.error}`, "audio-title", metadata);
21256
+ const descriptionBox = page.locator('textarea[placeholder="\u8BF7\u586B\u5199\u63CF\u8FF0"]').first();
21257
+ if (await descriptionBox.count() === 0)
21258
+ return stageFail("\u97F3\u9891 \u63CF\u8FF0 textarea not found", "audio-description", metadata);
21259
+ await descriptionBox.fill(description);
21260
+ const descriptionOk = await expectOutcome2(async () => (await descriptionBox.inputValue()).length > 0 ? "description retained" : null, stepTimeoutMs, "\u97F3\u9891 \u63CF\u8FF0 readback");
21261
+ if (!descriptionOk.ok) {
21262
+ return stageFail(`\u97F3\u9891 \u63CF\u8FF0 readback failed: ${descriptionOk.error}`, "audio-description", metadata);
21263
+ }
21264
+ const coverPath = input.coverPath;
21265
+ if (coverPath !== undefined) {
21266
+ const cover = await attachAudioCover(page, coverPath, stepTimeoutMs);
21267
+ if (cover !== null)
21268
+ return stageFail(cover, "audio-cover", metadata);
21269
+ }
21270
+ if (collection !== undefined) {
21271
+ const selected = await selectAudioCollection(page, collection, stepTimeoutMs);
21272
+ if (selected !== null)
21273
+ return stageFail(selected, "collection-select", metadata);
21274
+ } else {
21275
+ const readback = await page.locator('div.display-text:has-text("\u9009\u62E9\u5408\u96C6")').count();
21276
+ if (readback === 0) {
21277
+ return stageFail("\u5408\u96C6 row missing before submit", "collection-select", metadata);
21278
+ }
21279
+ }
21280
+ const baseline = await countAudioRows(page, clipped);
21281
+ const submit = page.locator('button:has-text("\u53D1\u8868\u97F3\u9891")').first();
21282
+ if (await submit.count() === 0)
21283
+ return stageFail("\u53D1\u8868\u97F3\u9891 submit control not found", "audio-submit", metadata);
21284
+ if (await submit.isDisabled())
21285
+ return stageFail("\u53D1\u8868\u97F3\u9891 submit control is disabled", "audio-submit", metadata);
21286
+ await submit.click({ timeout: stepTimeoutMs });
21287
+ await page.waitForTimeout(3000);
21288
+ for (const label of ["\u786E\u8BA4\u53D1\u8868", "\u786E\u5B9A"]) {
21289
+ const confirm = page.locator(`button:text-is("${label}")`).first();
21290
+ if (await confirm.count() > 0 && await confirm.isVisible().catch(() => false)) {
21291
+ await confirm.click({ timeout: 5000 }).catch(() => {});
21292
+ break;
21293
+ }
21294
+ }
21295
+ const receipt = await expectOutcome2(async () => {
21296
+ if (!page.url().includes(SHP_AUDIO_MANAGER_PATH))
21297
+ return null;
21298
+ const count = await countAudioRows(page, clipped);
21299
+ if (count <= baseline)
21300
+ return null;
21301
+ return { url: page.url(), rows: count };
21302
+ }, receiptBudgetMs ?? SHP_AUDIO_RECEIPT_MS, "\u97F3\u9891 list row");
21303
+ if (!receipt.ok) {
21304
+ 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);
21305
+ }
21306
+ return ResultSchema.parse({
21307
+ ok: true,
21308
+ target: SHP_TARGET,
21309
+ url: receipt.evidence.url,
21310
+ message: `shipinhao audio published and confirmed in the \u97F3\u9891 list (${profileDir})`,
21311
+ metadata: { ...metadata, confirmedBy: "audio-list-row", rowsWithTitle: receipt.evidence.rows }
21312
+ });
21313
+ }
21314
+
21074
21315
  // ../../plugins/publishings/shipinhao-pub/src/flow.ts
21075
21316
  var STEP_TIMEOUT_MS = 30000;
21317
+ var PREFLIGHT_TIMEOUT_MS = 180000;
21318
+ var COLLECTION_PROBE_MS = 2000;
21076
21319
  var MAX_VIDEO_BYTES = 2 * 1024 * 1024 * 1024;
21077
21320
  var SHP_LOGIN_INSTRUCTION = "bun plugins/publishings/shipinhao-pub/src/profile-check.ts login";
21078
21321
  function fail(target, error) {
21079
21322
  return ResultSchema.parse({ ok: false, target, error: boundedDetail(error) });
21080
21323
  }
21081
- function stageFail(target, error, stage, metadata, evidence) {
21324
+ function stageFail2(target, error, stage, metadata, evidence, effect = "none") {
21082
21325
  return ResultSchema.parse({
21083
21326
  ok: false,
21084
21327
  target,
21085
21328
  error: boundedDetail(error),
21086
- metadata: { ...metadata, stage, ...evidence === undefined ? {} : { evidence: boundedDetail(evidence) } }
21329
+ metadata: {
21330
+ ...metadata,
21331
+ stage,
21332
+ ...evidence === undefined ? {} : { evidence: boundedDetail(evidence) },
21333
+ ...effect === "none" ? { itcDelivery: { schemaVersion: 1, effect: "none" } } : {}
21334
+ }
21087
21335
  });
21088
21336
  }
21089
21337
  function boundedDetail(detail) {
@@ -21370,12 +21618,20 @@ function resolveOriginal(raw) {
21370
21618
  }
21371
21619
  return { original: raw };
21372
21620
  }
21621
+ function resolveCollection(raw) {
21622
+ if (raw === undefined)
21623
+ return {};
21624
+ if (typeof raw !== "string" || raw.trim().length === 0) {
21625
+ return { error: `collection must be a nonempty string when present, got '${bounded(raw)}'` };
21626
+ }
21627
+ return { collection: raw.trim() };
21628
+ }
21373
21629
  function unsupportedFields(payload, operation) {
21374
21630
  const perOperation = {
21375
- shortVideo: ["images", "categories", "publishTime", "scheduling"],
21631
+ shortVideo: ["images", "categories", "publishTime", "scheduling", "collection"],
21376
21632
  audio: ["videoPath", "images", "categories", "publishTime", "scheduling"],
21377
- music: ["videoPath", "images", "categories", "publishTime", "scheduling"],
21378
- image: ["videoPath", "coverPath", "categories", "publishTime", "scheduling"]
21633
+ music: ["videoPath", "images", "categories", "publishTime", "scheduling", "collection"],
21634
+ image: ["videoPath", "coverPath", "categories", "publishTime", "scheduling", "collection"]
21379
21635
  };
21380
21636
  const refused = [];
21381
21637
  for (const [container, source] of [
@@ -21404,6 +21660,40 @@ function editingFormReadyScript(mode, titleSelector, editorSelector) {
21404
21660
  return JSON.stringify({ ready: title !== null && editor !== null });
21405
21661
  })()`;
21406
21662
  }
21663
+ function collectionScript(mode, action, label, name) {
21664
+ return `${rootScriptPrefix(mode)} // kk-shp-collection
21665
+ const label = ${JSON.stringify(label)};
21666
+ const name = ${JSON.stringify(name)};
21667
+ const action = ${JSON.stringify(action)};
21668
+ const roots = [document, root].filter(Boolean);
21669
+ const ownText = (el) => Array.from(el.childNodes).filter((n) => n.nodeType === 3).map((n) => (n.textContent || '').trim()).join(' ').trim();
21670
+ const rendered = (el) => { const r = el.getBoundingClientRect(); return r.width > 0 && r.height > 0; };
21671
+ const all = [];
21672
+ for (const scope of roots) {
21673
+ if (!scope || !scope.querySelectorAll) continue;
21674
+ for (const el of scope.querySelectorAll('*')) all.push(el);
21675
+ }
21676
+ const row = all.find((el) => rendered(el) && ownText(el).startsWith(label));
21677
+ if (action === 'click-entry') {
21678
+ if (!row) return JSON.stringify({ ok: false, reason: 'entry-absent' });
21679
+ const target = row.closest('button, div, li, label') || row;
21680
+ target.click();
21681
+ return JSON.stringify({ ok: true, text: String(row.textContent || '').trim().slice(0, 80) });
21682
+ }
21683
+ if (action === 'click-option') {
21684
+ const exact = all.filter((el) => rendered(el) && ownText(el) === name);
21685
+ if (exact.length > 0) {
21686
+ const option = exact[exact.length - 1];
21687
+ (option.closest('li, div, label, button') || option).click();
21688
+ return JSON.stringify({ ok: true, how: 'text' });
21689
+ }
21690
+ const near = all.filter((el) => rendered(el) && ownText(el).includes(name)).map((el) => ownText(el).slice(0, 40));
21691
+ return JSON.stringify({ ok: false, reason: 'option-absent', seen: [...new Set(near)].slice(0, 8) });
21692
+ }
21693
+ const state = row === undefined ? '' : String(row.textContent || '').trim().slice(0, 120);
21694
+ return JSON.stringify({ ok: state.includes(name), text: state });
21695
+ })()`;
21696
+ }
21407
21697
  function originalEntryScript(mode, action) {
21408
21698
  const ensure = action === "ensure";
21409
21699
  return `${rootScriptPrefix(mode)}
@@ -21543,11 +21833,13 @@ class ShipinhaoBrowserTransport {
21543
21833
  operation;
21544
21834
  launcher;
21545
21835
  stepTimeoutMs;
21836
+ preflightTimeoutMs;
21546
21837
  constructor(operation = "shortVideo", driver = "script", deps = {}) {
21547
21838
  this.operation = operation;
21548
21839
  this.driver = driver;
21549
21840
  this.launcher = deps.launcher ?? kkBrowserLauncher;
21550
21841
  this.stepTimeoutMs = deps.stepTimeoutMs ?? STEP_TIMEOUT_MS;
21842
+ this.preflightTimeoutMs = deps.preflightTimeoutMs ?? PREFLIGHT_TIMEOUT_MS;
21551
21843
  }
21552
21844
  async publish(payload) {
21553
21845
  if (this.driver !== "script") {
@@ -21585,7 +21877,7 @@ class ShipinhaoBrowserTransport {
21585
21877
  if (audio.error !== undefined)
21586
21878
  return fail(SHP_TARGET, audio.error);
21587
21879
  media = [audio.path];
21588
- const cover = await resolveCoverPath(payload.content.metadata?.coverPath ?? payload.options?.coverPath);
21880
+ const cover = await resolveCoverPath(payload.content.metadata?.coverPath ?? payload.options?.coverPath ?? metadataRecord.coverImage);
21589
21881
  if (cover.error !== undefined)
21590
21882
  return fail(SHP_TARGET, cover.error);
21591
21883
  coverPath = cover.path;
@@ -21601,6 +21893,9 @@ class ShipinhaoBrowserTransport {
21601
21893
  const original = resolveOriginal(payload.content.metadata?.original);
21602
21894
  if (original.error !== undefined)
21603
21895
  return fail(SHP_TARGET, original.error);
21896
+ const collection = resolveCollection(payload.options?.collection ?? payload.content.metadata?.collection);
21897
+ if (collection.error !== undefined)
21898
+ return fail(SHP_TARGET, collection.error);
21604
21899
  const unsupported = unsupportedFields(payload, this.operation);
21605
21900
  if (unsupported.length > 0) {
21606
21901
  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)`);
@@ -21610,11 +21905,10 @@ class ShipinhaoBrowserTransport {
21610
21905
  const session = await checkChannelSession(SHP_CONFIG, {
21611
21906
  profileDir,
21612
21907
  launcher: this.launcher,
21613
- headedFallback: false,
21614
- timeoutMs: this.stepTimeoutMs
21908
+ timeoutMs: this.preflightTimeoutMs
21615
21909
  });
21616
21910
  if (session.status !== "verified") {
21617
- return fail(SHP_TARGET, `${SHP_TARGET} session preflight refused \u2014 run: ${SHP_LOGIN_INSTRUCTION} \u2014 detail: ${session.detail}`);
21911
+ 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");
21618
21912
  }
21619
21913
  try {
21620
21914
  return await withProfilePage({
@@ -21624,53 +21918,71 @@ class ShipinhaoBrowserTransport {
21624
21918
  headless: payload.options?.headless === true,
21625
21919
  launcher: this.launcher,
21626
21920
  timeoutMs: this.stepTimeoutMs
21627
- }, async ({ page }) => this.runPostFlow(page, POST_FLOW_SPECS[this.operation], title, body, tags.tags, original.original === true, media, coverPath, requested === "public", profileDir));
21921
+ }, async ({ page }) => {
21922
+ if (this.operation === "audio") {
21923
+ return runAudioPostFlow({
21924
+ page,
21925
+ title,
21926
+ body,
21927
+ tags: tags.tags,
21928
+ media,
21929
+ coverPath,
21930
+ collection: collection.collection,
21931
+ publishPublic: requested === "public",
21932
+ operation: this.operation,
21933
+ profileDir,
21934
+ stepTimeoutMs: this.stepTimeoutMs
21935
+ });
21936
+ }
21937
+ return this.runPostFlow(page, POST_FLOW_SPECS[this.operation], title, body, tags.tags, original.original === true, collection.collection, media, coverPath, requested === "public", profileDir);
21938
+ });
21628
21939
  } catch (error) {
21629
21940
  const detail = errorMessage3(error);
21630
21941
  return fail(SHP_TARGET, needsLogin(error) ? `${SHP_TARGET} session failed \u2014 run: ${SHP_LOGIN_INSTRUCTION} \u2014 detail: ${detail}` : detail);
21631
21942
  }
21632
21943
  }
21633
- async runPostFlow(page, spec, title, body, tags, declareOriginal, media, coverPath, publishPublic, profileDir) {
21944
+ async runPostFlow(page, spec, title, body, tags, declareOriginal, collection, media, coverPath, publishPublic, profileDir) {
21634
21945
  const publishStatus = publishPublic ? "public" : "draft";
21635
21946
  const metadata = {
21636
21947
  operation: this.operation,
21637
21948
  driver: this.driver,
21638
21949
  publishStatus,
21639
21950
  profileDir,
21640
- ...declareOriginal ? { original: true } : {}
21951
+ ...declareOriginal ? { original: true } : {},
21952
+ ...collection !== undefined ? { collection } : {}
21641
21953
  };
21642
21954
  const entrySnapshot = await readRootSnapshot(page);
21643
21955
  if (entrySnapshot.shadowFileInputs + entrySnapshot.directFileInputs === 0) {
21644
21956
  const entryRoot = await resolveCreatorRoot(page);
21645
21957
  if (entryRoot.error !== undefined)
21646
- return stageFail(SHP_TARGET, entryRoot.error, "root-resolve", metadata);
21958
+ return stageFail2(SHP_TARGET, entryRoot.error, "root-resolve", metadata);
21647
21959
  try {
21648
21960
  const entry = (await resolveRootLocator(page, entryRoot.mode, spec.selectors.createEntry, "shipinhao create entry", this.stepTimeoutMs)).locator;
21649
21961
  await entry.click();
21650
21962
  } catch (error) {
21651
- return stageFail(SHP_TARGET, `shipinhao create entry click failed \u2014 ${errorMessage3(error)}`, "entry-open", metadata);
21963
+ return stageFail2(SHP_TARGET, `shipinhao create entry click failed \u2014 ${errorMessage3(error)}`, "entry-open", metadata);
21652
21964
  }
21653
21965
  const opened = await expectOutcome(async () => {
21654
21966
  const snapshot = await readRootSnapshot(page);
21655
21967
  return snapshot.shadowFileInputs + snapshot.directFileInputs > 0 ? "create surface open" : null;
21656
21968
  }, { timeoutMs: this.stepTimeoutMs, label: "shipinhao create surface" });
21657
21969
  if (!opened.ok)
21658
- return stageFail(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);
21970
+ 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);
21659
21971
  }
21660
21972
  const root = await resolveCreatorRoot(page);
21661
21973
  if (root.error !== undefined)
21662
- return stageFail(SHP_TARGET, root.error, "root-resolve", metadata);
21974
+ return stageFail2(SHP_TARGET, root.error, "root-resolve", metadata);
21663
21975
  const mode = root.mode;
21664
21976
  try {
21665
21977
  const resolved = await resolveRootLocator(page, mode, spec.fileSelectors, `shipinhao ${spec.mediaLabel} file input`, this.stepTimeoutMs);
21666
21978
  if (resolved.selector === 'input[type="file"]' && await resolved.locator.count() !== 1) {
21667
- return stageFail(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);
21979
+ 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);
21668
21980
  }
21669
21981
  await resolved.locator.setInputFiles(media.length === 1 ? media[0] : media, {
21670
21982
  timeout: this.stepTimeoutMs
21671
21983
  });
21672
21984
  } catch (error) {
21673
- return stageFail(SHP_TARGET, `shipinhao ${spec.mediaLabel} file input/attach failed on ${page.url()}: ${errorMessage3(error)}`, "upload-timeout", metadata);
21985
+ return stageFail2(SHP_TARGET, `shipinhao ${spec.mediaLabel} file input/attach failed on ${page.url()}: ${errorMessage3(error)}`, "upload-timeout", metadata);
21674
21986
  }
21675
21987
  let titleSelector;
21676
21988
  let editorSelector;
@@ -21678,23 +21990,23 @@ class ShipinhaoBrowserTransport {
21678
21990
  titleSelector = (await resolveRootLocator(page, mode, spec.selectors.titleInput, "shipinhao title input", this.stepTimeoutMs)).selector;
21679
21991
  editorSelector = (await resolveRootLocator(page, mode, spec.selectors.descriptionEditor, "shipinhao description editor", this.stepTimeoutMs)).selector;
21680
21992
  } catch (error) {
21681
- return stageFail(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);
21993
+ 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);
21682
21994
  }
21683
21995
  const formReady = await expectOutcome(async () => {
21684
21996
  const raw = String(await page.evaluate(editingFormReadyScript(mode, titleSelector, editorSelector)));
21685
21997
  return JSON.parse(raw).ready === true ? "editing form observed in the active root" : null;
21686
21998
  }, { timeoutMs: SHP_UPLOAD_TIMEOUT_MS, label: "shipinhao media processing" });
21687
21999
  if (!formReady.ok) {
21688
- return stageFail(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);
22000
+ 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);
21689
22001
  }
21690
22002
  try {
21691
22003
  const titleInput = (await resolveRootLocator(page, mode, spec.selectors.titleInput, "shipinhao title input", this.stepTimeoutMs)).locator;
21692
22004
  await titleInput.fill(title);
21693
22005
  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" });
21694
22006
  if (!readback.ok)
21695
- return stageFail(SHP_TARGET, `shipinhao title readback failed \u2014 the editor did not retain the requested title \u2014 ${readback.error}`, "title-readback", metadata);
22007
+ return stageFail2(SHP_TARGET, `shipinhao title readback failed \u2014 the editor did not retain the requested title \u2014 ${readback.error}`, "title-readback", metadata);
21696
22008
  } catch (error) {
21697
- return stageFail(SHP_TARGET, `shipinhao title fill failed \u2014 ${errorMessage3(error)}`, "title-readback", metadata);
22009
+ return stageFail2(SHP_TARGET, `shipinhao title fill failed \u2014 ${errorMessage3(error)}`, "title-readback", metadata);
21698
22010
  }
21699
22011
  const { description, html } = buildShipinhaoDescription(body, tags);
21700
22012
  try {
@@ -21705,9 +22017,14 @@ class ShipinhaoBrowserTransport {
21705
22017
  return editorText.length > 0 && normalizeText(editorText).includes(normalizeText(description)) && tags.every((tag) => editorText.includes(`#${tag.replace(/^#/, "")}`)) ? "description and topics read back" : null;
21706
22018
  }, { timeoutMs: this.stepTimeoutMs, label: "shipinhao description paste readback" });
21707
22019
  if (!readback.ok)
21708
- return stageFail(SHP_TARGET, `shipinhao description readback failed \u2014 the editor did not retain the pasted description/topics \u2014 ${readback.error}`, "description-paste-readback", metadata);
22020
+ 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);
21709
22021
  } catch (error) {
21710
- return stageFail(SHP_TARGET, `shipinhao description paste failed \u2014 ${errorMessage3(error)}`, "description-paste-readback", metadata);
22022
+ return stageFail2(SHP_TARGET, `shipinhao description paste failed \u2014 ${errorMessage3(error)}`, "description-paste-readback", metadata);
22023
+ }
22024
+ if (collection !== undefined) {
22025
+ const collected = await this.selectCollectionFlow(page, mode, spec, collection, metadata);
22026
+ if (collected !== undefined)
22027
+ return collected;
21711
22028
  }
21712
22029
  if (declareOriginal) {
21713
22030
  const declaration = await this.declareOriginalFlow(page, mode, metadata);
@@ -21726,17 +22043,17 @@ class ShipinhaoBrowserTransport {
21726
22043
  const resolved = await resolveRootLocator(page, mode, submitSelectors, "shipinhao submit control", this.stepTimeoutMs);
21727
22044
  submitLocator = resolved.locator;
21728
22045
  } catch (error) {
21729
- return stageFail(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);
22046
+ 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);
21730
22047
  }
21731
22048
  if (!await submitLocator.isVisible().catch(() => false)) {
21732
- return stageFail(SHP_TARGET, "shipinhao submit control attached but not visible; refusing to submit through a hidden control", stage, metadata);
22049
+ return stageFail2(SHP_TARGET, "shipinhao submit control attached but not visible; refusing to submit through a hidden control", stage, metadata);
21733
22050
  }
21734
22051
  const enabled = await expectOutcome(async () => await submitLocator.isEnabled() ? "enabled" : null, {
21735
22052
  timeoutMs: this.stepTimeoutMs,
21736
22053
  label: "shipinhao submit control enabled"
21737
22054
  });
21738
22055
  if (!enabled.ok) {
21739
- return stageFail(SHP_TARGET, `shipinhao submit control never became clickable \u2014 ${enabled.error}`, stage, metadata);
22056
+ return stageFail2(SHP_TARGET, `shipinhao submit control never became clickable \u2014 ${enabled.error}`, stage, metadata);
21740
22057
  }
21741
22058
  const receiptStage = publishPublic ? "publish-receipt" : "draft-receipt";
21742
22059
  const beforeReceipts = new Set(await readReceiptUrls(page));
@@ -21770,10 +22087,10 @@ class ShipinhaoBrowserTransport {
21770
22087
  return url;
21771
22088
  }, { timeoutMs: this.stepTimeoutMs, label: `shipinhao ${receiptStage} confirmation` });
21772
22089
  if (!confirmed.ok) {
21773
- return stageFail(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)`);
22090
+ 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");
21774
22091
  }
21775
22092
  if (confirmed.evidence.startsWith("stale-state: ") || confirmed.evidence.startsWith("ambiguous-receipt: ")) {
21776
- return stageFail(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);
22093
+ 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");
21777
22094
  }
21778
22095
  const url = confirmed.evidence;
21779
22096
  return ResultSchema.parse({
@@ -21785,8 +22102,50 @@ class ShipinhaoBrowserTransport {
21785
22102
  metadata: { ...metadata, confirmedBy: receiptStage }
21786
22103
  });
21787
22104
  }
22105
+ async selectCollectionFlow(page, mode, spec, collection, metadata) {
22106
+ const failCollection = (message, stage, evidence) => stageFail2(SHP_TARGET, message, stage, metadata, evidence);
22107
+ const label = spec.selectors.collectionLabel;
22108
+ const read = (raw) => {
22109
+ try {
22110
+ return JSON.parse(raw);
22111
+ } catch {
22112
+ return { ok: false, reason: "unreadable-probe" };
22113
+ }
22114
+ };
22115
+ const entry = read(String(await page.evaluate(collectionScript(mode, "click-entry", label, collection))));
22116
+ if (!entry.ok) {
22117
+ 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);
22118
+ }
22119
+ const option = await expectOutcome(async () => {
22120
+ const picked = read(String(await page.evaluate(collectionScript(mode, "click-option", label, collection))));
22121
+ if (picked.ok)
22122
+ return "option clicked";
22123
+ const selects = page.locator("select");
22124
+ const count = await selects.count();
22125
+ for (let i = 0;i < count; i++) {
22126
+ try {
22127
+ await selects.nth(i).selectOption({ label: collection }, { timeout: COLLECTION_PROBE_MS });
22128
+ return "option selected";
22129
+ } catch {}
22130
+ }
22131
+ return null;
22132
+ }, { timeoutMs: this.stepTimeoutMs, label: "shipinhao \u5408\u96C6 option" });
22133
+ if (!option.ok) {
22134
+ const seen = read(String(await page.evaluate(collectionScript(mode, "click-option", label, collection))));
22135
+ 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(" | ")}`);
22136
+ }
22137
+ const commit = await expectOutcome(async () => {
22138
+ const state = read(String(await page.evaluate(collectionScript(mode, "read", label, collection))));
22139
+ return state.ok ? "collection read back" : null;
22140
+ }, { timeoutMs: this.stepTimeoutMs, label: "shipinhao \u5408\u96C6 readback" });
22141
+ if (!commit.ok) {
22142
+ const state = read(String(await page.evaluate(collectionScript(mode, "read", label, collection))));
22143
+ 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}`);
22144
+ }
22145
+ return;
22146
+ }
21788
22147
  async declareOriginalFlow(page, mode, metadata) {
21789
- const failDeclaration = (message, evidence) => stageFail(SHP_TARGET, message, "original-declare", metadata, evidence);
22148
+ const failDeclaration = (message, evidence) => stageFail2(SHP_TARGET, message, "original-declare", metadata, evidence);
21790
22149
  const entry = JSON.parse(String(await page.evaluate(originalEntryScript(mode, "ensure"))));
21791
22150
  if (!entry.ok) {
21792
22151
  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)");
@@ -21820,7 +22179,7 @@ class ShipinhaoBrowserTransport {
21820
22179
  return;
21821
22180
  }
21822
22181
  async attachCoverFlow(page, mode, coverPath, metadata) {
21823
- const failCover = (message, stage, evidence) => stageFail(SHP_TARGET, message, stage, metadata, evidence);
22182
+ const failCover = (message, stage, evidence) => stageFail2(SHP_TARGET, message, stage, metadata, evidence);
21824
22183
  const before = JSON.parse(String(await page.evaluate(coverSlotEvidenceScript(mode))));
21825
22184
  if (!before.found || before.descriptor === undefined) {
21826
22185
  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");