@gobing-ai/knowledge-kit 0.1.23 → 0.1.24
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/index.js +117 -56
- package/package.json +5 -5
- package/plugins/generations/content-gen/dist/index.js +9 -9
- package/plugins/generations/core-facts-gen/dist/index.js +12 -12
- package/plugins/generations/daily-article-gen/dist/index.js +12 -12
- package/plugins/generations/dailynews-gen/dist/index.js +11 -11
- package/plugins/generations/dailynews-gen/src/script-plan.ts +2 -2
- package/plugins/generations/episode-plan-gen/dist/index.js +12 -12
- package/plugins/generations/gemini-tts/dist/index.js +9 -9
- package/plugins/generations/image-gen/dist/index.js +9 -9
- package/plugins/generations/music-gen/dist/index.js +16 -16
- package/plugins/generations/news-report-gen/dist/index.js +12 -12
- package/plugins/generations/vibe-voice-tts/dist/index.js +9 -9
- package/plugins/generations/voice-gen/dist/index.js +9 -9
- package/plugins/generations/voxcpm-tts/dist/index.js +9 -9
- package/plugins/ingestions/aihot-ingest/dist/index.js +12 -12
- package/plugins/ingestions/horizon-ingest/dist/index.js +12 -12
- package/plugins/ingestions/karakeep-local/dist/index.js +13 -13
- package/plugins/ingestions/last30days-ingest/dist/index.js +12 -12
- package/plugins/ingestions/web-search/dist/index.js +10 -10
- package/plugins/kk/plugin.json +1 -1
- package/plugins/kk/publish-presets/daily-ai-voice.json +16 -16
- package/plugins/kk/scripts/cover-compositor.ts +104 -26
- package/plugins/kk/scripts/daily-stages.ts +217 -33
- package/plugins/kk/scripts/kk-workflow-stages.ts +144 -6
- package/plugins/kk/scripts/series-names.ts +16 -3
- package/plugins/kk/skills/news-editorial/SKILL.md +1 -1
- package/plugins/kk/skills/news-editorial/references/style-contract.zh.md +3 -3
- package/plugins/kk/workflows/kk-news-generate.yaml +3 -0
- package/plugins/publishings/bilibili-pub/dist/index.js +22 -22
- package/plugins/publishings/bilibili-pub/dist/profile-check.js +22 -22
- package/plugins/publishings/cnblogs-pub/dist/index.js +22 -22
- package/plugins/publishings/cnblogs-pub/dist/profile-check.js +22 -22
- package/plugins/publishings/csdn-pub/dist/index.js +22 -22
- package/plugins/publishings/csdn-pub/dist/profile-check.js +22 -22
- package/plugins/publishings/emdash-pub/dist/index.js +9 -9
- package/plugins/publishings/infoq-pub/dist/index.js +22 -22
- package/plugins/publishings/infoq-pub/dist/profile-check.js +22 -22
- package/plugins/publishings/jike-pub/dist/index.js +22 -22
- package/plugins/publishings/jike-pub/dist/profile-check.js +22 -22
- package/plugins/publishings/juejin-pub/dist/index.js +22 -22
- package/plugins/publishings/juejin-pub/dist/profile-check.js +22 -22
- package/plugins/publishings/linkedin-pub/dist/index.js +82 -24
- package/plugins/publishings/linkedin-pub/dist/profile-check.js +22 -22
- package/plugins/publishings/linkedin-pub/src/index.ts +93 -6
- package/plugins/publishings/medium-pub/dist/index.js +9 -9
- package/plugins/publishings/podcast-pub/dist/index.js +240 -37
- package/plugins/publishings/podcast-pub/src/index.ts +154 -3
- package/plugins/publishings/podcast-pub/src/seo.ts +25 -8
- package/plugins/publishings/podcast-pub/src/show-notes-brief.ts +93 -23
- package/plugins/publishings/podcast-pub/src/show-notes.ts +26 -6
- package/plugins/publishings/qiita-pub/dist/index.js +9 -9
- package/plugins/publishings/shipinhao-pub/dist/index.js +23 -23
- package/plugins/publishings/shipinhao-pub/dist/profile-check.js +23 -23
- package/plugins/publishings/shipinhao-pub/src/selectors.ts +2 -1
- package/plugins/publishings/sspai-pub/dist/index.js +22 -22
- package/plugins/publishings/sspai-pub/dist/profile-check.js +22 -22
- package/plugins/publishings/substack-pub/dist/index.js +22 -22
- package/plugins/publishings/substack-pub/dist/profile-check.js +22 -22
- package/plugins/publishings/surfdash-pub/dist/index.js +200 -92
- package/plugins/publishings/surfdash-pub/src/digest-check.ts +30 -1
- package/plugins/publishings/surfdash-pub/src/index.ts +94 -75
- package/plugins/publishings/surfdash-pub/src/media-upload.ts +83 -0
- package/plugins/publishings/surfdash-pub/src/patch.ts +28 -23
- package/plugins/publishings/surfdash-pub/src/topic-claims.ts +12 -4
- package/plugins/publishings/threads-pub/dist/index.js +36 -22
- package/plugins/publishings/threads-pub/dist/profile-check.js +27 -22
- package/plugins/publishings/threads-pub/src/post-rail.ts +20 -0
- package/plugins/publishings/wechatmp-pub/dist/index.js +180 -64
- package/plugins/publishings/wechatmp-pub/dist/profile-check.js +27 -23
- package/plugins/publishings/wechatmp-pub/src/enrich.ts +56 -10
- package/plugins/publishings/wechatmp-pub/src/flow.ts +155 -43
- package/plugins/publishings/wechatmp-pub/src/modes.ts +30 -12
- package/plugins/publishings/weibo-pub/dist/index.js +22 -22
- package/plugins/publishings/weibo-pub/dist/profile-check.js +22 -22
- package/plugins/publishings/x-pub/dist/index.js +51 -45
- package/plugins/publishings/x-pub/dist/profile-check.js +22 -22
- package/plugins/publishings/x-pub/src/post-rail.ts +40 -47
- package/plugins/publishings/xhs-pub/dist/index.js +22 -22
- package/plugins/publishings/xhs-pub/dist/profile-check.js +22 -22
- package/plugins/publishings/xiaoyuzhou-pub/dist/index.js +22 -22
- package/plugins/publishings/xiaoyuzhou-pub/dist/profile-check.js +22 -22
- package/plugins/publishings/zenn-pub/dist/index.js +9 -9
|
@@ -24,7 +24,7 @@ import {
|
|
|
24
24
|
WechatCgiDraftError,
|
|
25
25
|
} from './cgi-draft';
|
|
26
26
|
import { prepareArticleMedia, type WechatArticleMedia } from './cgi-media';
|
|
27
|
-
import {
|
|
27
|
+
import { enrichArticleDetailed } from './enrich';
|
|
28
28
|
import {
|
|
29
29
|
artifactPaths,
|
|
30
30
|
CREATE_TYPES,
|
|
@@ -1270,12 +1270,7 @@ export async function setCover(
|
|
|
1270
1270
|
* seeded. The flow *does* attach that file as the first body image, so 从正文选择 resolves it with no
|
|
1271
1271
|
* library dependency — which is the route a cover-carrying article should take (2026-11-12).
|
|
1272
1272
|
*/
|
|
1273
|
-
function
|
|
1274
|
-
const meta = content.metadata?.wechatmp;
|
|
1275
|
-
if (meta !== null && typeof meta === 'object' && !Array.isArray(meta)) {
|
|
1276
|
-
const declared = (meta as Record<string, unknown>).coverSource;
|
|
1277
|
-
if (declared === 'body' || declared === 'library') return declared;
|
|
1278
|
-
}
|
|
1273
|
+
function genericCoverPathOf(content: Content): string | undefined {
|
|
1279
1274
|
const generic = content.metadata?.coverImage;
|
|
1280
1275
|
const genericPath =
|
|
1281
1276
|
typeof generic === 'string'
|
|
@@ -1283,7 +1278,25 @@ function coverSourceOf(content: Content): 'library' | 'body' {
|
|
|
1283
1278
|
: typeof (generic as { path?: unknown } | undefined)?.path === 'string'
|
|
1284
1279
|
? (generic as { path: string }).path
|
|
1285
1280
|
: undefined;
|
|
1286
|
-
return genericPath !== undefined && genericPath.length > 0 ?
|
|
1281
|
+
return genericPath !== undefined && genericPath.length > 0 ? genericPath : undefined;
|
|
1282
|
+
}
|
|
1283
|
+
|
|
1284
|
+
function libraryCoverFallback(content: Content): string | undefined {
|
|
1285
|
+
const meta = content.metadata?.wechatmp;
|
|
1286
|
+
if (meta !== null && typeof meta === 'object' && !Array.isArray(meta)) {
|
|
1287
|
+
const coverPath = (meta as Record<string, unknown>).coverPath;
|
|
1288
|
+
if (typeof coverPath === 'string' && coverPath.trim().length > 0) return coverPath.trim();
|
|
1289
|
+
}
|
|
1290
|
+
return genericCoverPathOf(content);
|
|
1291
|
+
}
|
|
1292
|
+
|
|
1293
|
+
function coverSourceOf(content: Content): 'library' | 'body' {
|
|
1294
|
+
const meta = content.metadata?.wechatmp;
|
|
1295
|
+
if (meta !== null && typeof meta === 'object' && !Array.isArray(meta)) {
|
|
1296
|
+
const declared = (meta as Record<string, unknown>).coverSource;
|
|
1297
|
+
if (declared === 'body' || declared === 'library') return declared;
|
|
1298
|
+
}
|
|
1299
|
+
return genericCoverPathOf(content) !== undefined ? 'body' : 'library';
|
|
1287
1300
|
}
|
|
1288
1301
|
|
|
1289
1302
|
/** The audio-embed block of `metadata.wechatmp`, or null when this run embeds no audio. Shared by
|
|
@@ -1311,12 +1324,14 @@ export async function enrichArticleDraft(
|
|
|
1311
1324
|
page: WechatPage,
|
|
1312
1325
|
content: Content,
|
|
1313
1326
|
stepTimeoutMs: number,
|
|
1314
|
-
): Promise<{ enrichWarnings: string[]; coverWarnings: string[] }> {
|
|
1327
|
+
): Promise<{ enrichWarnings: string[]; capabilityWarnings: string[]; coverWarnings: string[] }> {
|
|
1315
1328
|
const enrichMeta = content.metadata?.wechatmp;
|
|
1316
1329
|
if (enrichMeta === undefined || typeof enrichMeta !== 'object' || Array.isArray(enrichMeta))
|
|
1317
|
-
return { enrichWarnings: [], coverWarnings: [] };
|
|
1330
|
+
return { enrichWarnings: [], capabilityWarnings: [], coverWarnings: [] };
|
|
1318
1331
|
const meta = enrichMeta as Record<string, unknown>;
|
|
1319
|
-
const
|
|
1332
|
+
const detailed = await enrichArticleDetailed(page, meta);
|
|
1333
|
+
const enrichWarnings = [...detailed.warnings];
|
|
1334
|
+
const capabilityWarnings = [...detailed.capabilityWarnings];
|
|
1320
1335
|
const audio = audioBlockOf(content);
|
|
1321
1336
|
let audioFailed = false;
|
|
1322
1337
|
let coverSeeded = false;
|
|
@@ -1347,7 +1362,7 @@ export async function enrichArticleDraft(
|
|
|
1347
1362
|
if (cover !== null) coverWarnings.push(cover);
|
|
1348
1363
|
}
|
|
1349
1364
|
}
|
|
1350
|
-
return { enrichWarnings, coverWarnings };
|
|
1365
|
+
return { enrichWarnings, capabilityWarnings, coverWarnings };
|
|
1351
1366
|
}
|
|
1352
1367
|
|
|
1353
1368
|
/** Compose 文章 (createType 0): body images, title, body + 一键排版, 摘要, 作者, cover, settings. */
|
|
@@ -1363,8 +1378,9 @@ async function composeArticle(
|
|
|
1363
1378
|
// Images go in AFTER the body: the v2 editor's own `execCommand('insertHTML')` body path
|
|
1364
1379
|
// REPLACES the document, so an image attached first is silently wiped — and with it the
|
|
1365
1380
|
// 默认首图为封面 / 从正文选择 material (measured 2026-11-12: bodyImgs 2 → 0, then 2 again when
|
|
1366
|
-
// re-attached after the body).
|
|
1367
|
-
|
|
1381
|
+
// re-attached after the body). Only attach body images when non-empty (`coverSource: 'library'`
|
|
1382
|
+
// with no body illustrations keeps input.images empty so the cover never lands in the body).
|
|
1383
|
+
if (input.images.length > 0) await attachImages(page, input.images, deps);
|
|
1368
1384
|
for (const warning of [
|
|
1369
1385
|
await fillOptional(page, DIGEST_INPUT, input.digest ?? '', '摘要', deps),
|
|
1370
1386
|
await fillOptional(page, AUTHOR_INPUT, authorOf(deps.content), '作者', deps),
|
|
@@ -1379,21 +1395,25 @@ async function composeArticle(
|
|
|
1379
1395
|
const audioRuns = audioBlockOf(deps.content) !== null;
|
|
1380
1396
|
if (!(coverSource === 'library' && audioRuns)) {
|
|
1381
1397
|
const cover = await setCover(page, coverSource, deps, {
|
|
1382
|
-
// Requested identity = the article's first body image (
|
|
1383
|
-
//
|
|
1384
|
-
//
|
|
1385
|
-
requested: input.images[0],
|
|
1398
|
+
// Requested identity = the article's first body image (从正文选择), or
|
|
1399
|
+
// `metadata.wechatmp.coverPath` / `metadata.coverImage` when `coverSource: 'library'`
|
|
1400
|
+
// omits body attachment and no audio uploaded it cleanly first.
|
|
1401
|
+
requested: input.images[0] ?? libraryCoverFallback(deps.content),
|
|
1386
1402
|
});
|
|
1387
1403
|
if (cover !== null) warnings.push(cover);
|
|
1388
1404
|
}
|
|
1389
|
-
const { enrichWarnings, coverWarnings } = await enrichArticleDraft(
|
|
1405
|
+
const { enrichWarnings, capabilityWarnings, coverWarnings } = await enrichArticleDraft(
|
|
1406
|
+
page,
|
|
1407
|
+
deps.content,
|
|
1408
|
+
deps.stepTimeoutMs,
|
|
1409
|
+
);
|
|
1390
1410
|
warnings.push(...coverWarnings);
|
|
1391
1411
|
// Layout is deliberately last: 原文链接, media insertion, and cover commitment must be part of
|
|
1392
1412
|
// the body the platform formats, and the native auto-save acknowledgement must settle before
|
|
1393
1413
|
// 保存为草稿 or the public saved-editor readback begins.
|
|
1394
1414
|
const layout = await applyLayout(page, deps);
|
|
1395
1415
|
if (layout !== null) warnings.push(layout);
|
|
1396
|
-
return { warnings, titlePath, enrichWarnings };
|
|
1416
|
+
return { warnings, titlePath, enrichWarnings, capabilityWarnings };
|
|
1397
1417
|
}
|
|
1398
1418
|
|
|
1399
1419
|
/** Compose 贴图 (createType 8): ≥1 image is the message; title and body are 选填. */
|
|
@@ -1694,6 +1714,7 @@ interface ComposeReport {
|
|
|
1694
1714
|
warnings: string[];
|
|
1695
1715
|
titlePath: 'absent' | 'mirror-agreed' | 'mirror-unread';
|
|
1696
1716
|
enrichWarnings: string[];
|
|
1717
|
+
capabilityWarnings?: string[];
|
|
1697
1718
|
}
|
|
1698
1719
|
|
|
1699
1720
|
/** Compose the requested mode's post. Exhaustive over {@link ModeInput}. */
|
|
@@ -2627,17 +2648,22 @@ export async function runMode(input: ModeInput, deps: ModeRunDeps): Promise<Resu
|
|
|
2627
2648
|
if (!result.ok && diagnostics.length > 0) {
|
|
2628
2649
|
return { ...result, error: `${result.error} — compose diagnostics: ${diagnostics.join(' | ')}` };
|
|
2629
2650
|
}
|
|
2630
|
-
// Requested enrichment that did not take is a FAILURE, not a warning (2026-11-15).
|
|
2631
|
-
//
|
|
2632
|
-
//
|
|
2633
|
-
//
|
|
2634
|
-
|
|
2635
|
-
|
|
2636
|
-
|
|
2651
|
+
// Requested enrichment that did not take is a FAILURE, not a warning (2026-11-15).
|
|
2652
|
+
// WECHATMP_ALLOW_PARTIAL_ENRICH=1 tolerates ONLY account capability refusals (赞赏账户,
|
|
2653
|
+
// 原文链接行不存在) — never real non-capability failures (音频, 原创声明, 原文链接保存失败,
|
|
2654
|
+
// 合集, 创作来源).
|
|
2655
|
+
const capabilitySet = new Set(composed.capabilityWarnings ?? []);
|
|
2656
|
+
const blockingEnrichWarnings = composed.enrichWarnings.filter((warning) => !capabilitySet.has(warning));
|
|
2657
|
+
const partialAllowed = process.env.WECHATMP_ALLOW_PARTIAL_ENRICH === '1';
|
|
2658
|
+
const fatalEnrichWarnings = partialAllowed ? blockingEnrichWarnings : composed.enrichWarnings;
|
|
2659
|
+
if (result.ok && fatalEnrichWarnings.length > 0) {
|
|
2660
|
+
const capabilityOnly = blockingEnrichWarnings.length === 0;
|
|
2637
2661
|
return {
|
|
2638
2662
|
...result,
|
|
2639
2663
|
ok: false,
|
|
2640
|
-
error: `draft saved but enrichment did not apply — ${
|
|
2664
|
+
error: `draft saved but enrichment did not apply — ${fatalEnrichWarnings.join(' | ')}${
|
|
2665
|
+
capabilityOnly ? ' (set WECHATMP_ALLOW_PARTIAL_ENRICH=1 to accept a partial draft)' : ''
|
|
2666
|
+
}`,
|
|
2641
2667
|
};
|
|
2642
2668
|
}
|
|
2643
2669
|
return result;
|
|
@@ -2744,6 +2770,14 @@ function escapeHtml(text: string): string {
|
|
|
2744
2770
|
return text.replace(/&/g, '&').replace(/</g, '<').replace(/>/g, '>').replace(/"/g, '"');
|
|
2745
2771
|
}
|
|
2746
2772
|
|
|
2773
|
+
async function evalOrFallback(page: WechatPage, script: string, fallback: string): Promise<string> {
|
|
2774
|
+
try {
|
|
2775
|
+
return String((await page.evaluate(script)) ?? fallback);
|
|
2776
|
+
} catch {
|
|
2777
|
+
return fallback;
|
|
2778
|
+
}
|
|
2779
|
+
}
|
|
2780
|
+
|
|
2747
2781
|
/**
|
|
2748
2782
|
* Audio at the article top (operator request 2026-09-29; upload path added 2026-10-10).
|
|
2749
2783
|
*
|
|
@@ -2759,7 +2793,17 @@ function escapeHtml(text: string): string {
|
|
|
2759
2793
|
export async function insertAudioMaterial(
|
|
2760
2794
|
page: WechatPage,
|
|
2761
2795
|
input: { title: string; audioPath: string; coverPath: string },
|
|
2796
|
+
timing: {
|
|
2797
|
+
uploadWaitMs?: number;
|
|
2798
|
+
saveCloseWaitMs?: number;
|
|
2799
|
+
saveDispatchWaitMs?: number;
|
|
2800
|
+
rowRetries?: number;
|
|
2801
|
+
} = {},
|
|
2762
2802
|
): Promise<{ warning: string; coverSeeded: boolean }> {
|
|
2803
|
+
const uploadWaitMs = timing.uploadWaitMs ?? 120_000;
|
|
2804
|
+
const saveCloseWaitMs = timing.saveCloseWaitMs ?? 30_000;
|
|
2805
|
+
const saveDispatchWaitMs = timing.saveDispatchWaitMs ?? 10_000;
|
|
2806
|
+
const postUploadRowRetries = timing.rowRetries ?? 15;
|
|
2763
2807
|
const { title, audioPath, coverPath } = input;
|
|
2764
2808
|
// The library demonstrably holds the episode cover once the picker verified the unique same-name
|
|
2765
2809
|
// row (0260 R1 refined 2026-11-09): failures AFTER that point must not suppress the deferred
|
|
@@ -2842,17 +2886,46 @@ export async function insertAudioMaterial(
|
|
|
2842
2886
|
})()`;
|
|
2843
2887
|
|
|
2844
2888
|
/** Upload the audio + its cover, acknowledge the rules, and 保存. Returns a structured outcome. */
|
|
2845
|
-
const upload = async (): Promise<{ warning: string; coverSeeded: boolean }> => {
|
|
2889
|
+
const upload = async (): Promise<{ warning: string; coverSeeded: boolean; sawLiveUpload: boolean }> => {
|
|
2890
|
+
let sawLiveUpload = false;
|
|
2891
|
+
const failUpload = (warning: string) => ({ ...result(warning), sawLiveUpload });
|
|
2892
|
+
const uploadDialog = '.weui-desktop-dialog:visible:has(h3.weui-desktop-dialog__title:text-is("上传音频"))';
|
|
2893
|
+
const isLiveUploadForm = async (): Promise<boolean> => {
|
|
2894
|
+
if ((await page.locator(uploadDialog).count()) === 0) return false;
|
|
2895
|
+
try {
|
|
2896
|
+
const titleText =
|
|
2897
|
+
(await page.locator(`${uploadDialog} h3.weui-desktop-dialog__title`).first().textContent?.()) ?? '';
|
|
2898
|
+
return titleText.trim() === '上传音频';
|
|
2899
|
+
} catch {
|
|
2900
|
+
return false;
|
|
2901
|
+
}
|
|
2902
|
+
};
|
|
2846
2903
|
const uploadControl = await trySelectors(page, UPLOAD_AUDIO);
|
|
2847
|
-
if (!uploadControl.found) return
|
|
2904
|
+
if (!uploadControl.found) return failUpload('音频: 上传音频 control not found in the audio dialog');
|
|
2848
2905
|
// Click the winner, never a joined union: `text=…, css…` mixes selector engines and
|
|
2849
2906
|
// Playwright parses the whole string as CSS — zero matches (DOM fixture 0260).
|
|
2850
2907
|
await clickSelector(page, uploadControl.selector ?? UPLOAD_AUDIO[0] ?? 'text=上传音频', 8_000);
|
|
2851
2908
|
const audioInput = await trySelectors(page, AUDIO_UPLOAD_INPUT, { visible: false });
|
|
2852
|
-
if (!audioInput.found) return
|
|
2909
|
+
if (!audioInput.found) return failUpload('音频: no audio file input appeared');
|
|
2853
2910
|
await uploadFile(asPlaywrightPage(page), audioInput.selector ?? AUDIO_UPLOAD_INPUT.join(', '), audioPath, {
|
|
2854
|
-
timeoutMs:
|
|
2911
|
+
timeoutMs: 120_000,
|
|
2855
2912
|
});
|
|
2913
|
+
sawLiveUpload = await isLiveUploadForm();
|
|
2914
|
+
if (sawLiveUpload) {
|
|
2915
|
+
const uploaded = await waitUntil(
|
|
2916
|
+
async () =>
|
|
2917
|
+
(await page.locator(`${uploadDialog} button:has-text("重新上传")`).count()) > 0 &&
|
|
2918
|
+
/100%/.test(
|
|
2919
|
+
await evalOrFallback(
|
|
2920
|
+
page,
|
|
2921
|
+
`(() => { const d = [...document.querySelectorAll('.weui-desktop-dialog')].find((el) => el.offsetWidth > 0 && el.querySelector('input[name=audio_id]')); return d ? (d.textContent ?? '') : ''; })()`,
|
|
2922
|
+
'',
|
|
2923
|
+
),
|
|
2924
|
+
),
|
|
2925
|
+
uploadWaitMs,
|
|
2926
|
+
);
|
|
2927
|
+
if (!uploaded) return failUpload('音频: 音频文件上传未完成(未达到 100%),未保存音频');
|
|
2928
|
+
}
|
|
2856
2929
|
// The form requires a cover before it will save.
|
|
2857
2930
|
const coverControl = await trySelectors(page, UPLOAD_COVER);
|
|
2858
2931
|
if (coverControl.found) {
|
|
@@ -2873,13 +2946,13 @@ export async function insertAudioMaterial(
|
|
|
2873
2946
|
),
|
|
2874
2947
|
5_000,
|
|
2875
2948
|
);
|
|
2876
|
-
if (!libraryReady) return
|
|
2949
|
+
if (!libraryReady) return failUpload('音频: 封面素材库加载未完成,未上传重复封面');
|
|
2877
2950
|
existing = Number(
|
|
2878
2951
|
await page.evaluate(
|
|
2879
2952
|
`([...document.querySelectorAll('.weui-desktop-img-picker__item')].filter(row => row.offsetWidth > 0 && row.querySelector('.weui-desktop-img-picker__img-title')?.textContent?.trim() === ${JSON.stringify(coverName)})).length`,
|
|
2880
2953
|
),
|
|
2881
2954
|
);
|
|
2882
|
-
if (existing > 1) return
|
|
2955
|
+
if (existing > 1) return failUpload('音频: 内容绑定封面存在多个同名素材,未猜测选择');
|
|
2883
2956
|
}
|
|
2884
2957
|
let uploadPath = coverPath;
|
|
2885
2958
|
let temporaryDir: string | undefined;
|
|
@@ -2916,7 +2989,7 @@ export async function insertAudioMaterial(
|
|
|
2916
2989
|
),
|
|
2917
2990
|
30_000,
|
|
2918
2991
|
);
|
|
2919
|
-
if (!selected) return
|
|
2992
|
+
if (!selected) return failUpload('音频: 上传封面未出现唯一已选中的同名图片,未提交封面');
|
|
2920
2993
|
// The picker just proved the library holds the unique same-name cover; every
|
|
2921
2994
|
// failure past this point leaves the cover in the 图片库 (cover rescue valid).
|
|
2922
2995
|
libraryHasCover = true;
|
|
@@ -2927,6 +3000,9 @@ export async function insertAudioMaterial(
|
|
|
2927
3000
|
30_000,
|
|
2928
3001
|
);
|
|
2929
3002
|
await clickSelector(page, next, 8_000);
|
|
3003
|
+
if (sawLiveUpload && (await page.locator(`${chooser} button:has-text("上一步")`).count()) > 0) {
|
|
3004
|
+
await page.waitForTimeout?.(2_000);
|
|
3005
|
+
}
|
|
2930
3006
|
const finish = await findSelector(
|
|
2931
3007
|
page,
|
|
2932
3008
|
[`${chooser} button:has-text("完成"):not(.weui-desktop-btn_disabled)`],
|
|
@@ -2978,7 +3054,7 @@ export async function insertAudioMaterial(
|
|
|
2978
3054
|
// confirm dialog may not nest under the chooser selector, which would
|
|
2979
3055
|
// explain the 确定 retry missing it) before giving up on the audio save.
|
|
2980
3056
|
const inventory = await openDialogInventory(page);
|
|
2981
|
-
return
|
|
3057
|
+
return failUpload(
|
|
2982
3058
|
`音频: 封面选择器完成后未关闭,未保存音频${inventory ? ` (dialogs: ${inventory})` : ''}`,
|
|
2983
3059
|
);
|
|
2984
3060
|
}
|
|
@@ -2994,15 +3070,42 @@ export async function insertAudioMaterial(
|
|
|
2994
3070
|
const titleInput = await trySelectors(page, AUDIO_TITLE_INPUT);
|
|
2995
3071
|
if (titleInput.found) await fillSelector(page, titleInput.selector ?? AUDIO_TITLE_INPUT.join(', '), title);
|
|
2996
3072
|
const agreed = String(await page.evaluate(AGREE));
|
|
2997
|
-
if (agreed !== 'checked') return
|
|
3073
|
+
if (agreed !== 'checked') return failUpload(`音频: 服务规则勾选失败 (${agreed})`);
|
|
2998
3074
|
const save = await findSelector(
|
|
2999
3075
|
page,
|
|
3000
3076
|
UPLOAD_SAVE.map((selector) => `${selector}:not(.weui-desktop-btn_disabled):not([disabled])`),
|
|
3001
3077
|
'音频上传完成且封面已提交后的保存按钮',
|
|
3002
3078
|
90_000,
|
|
3003
3079
|
);
|
|
3080
|
+
if (sawLiveUpload) {
|
|
3081
|
+
await evalOrFallback(
|
|
3082
|
+
page,
|
|
3083
|
+
'(() => { window.__kkToasts = []; new MutationObserver(() => { const t = document.querySelector(".weui-desktop-toast"); if (t && t.textContent) window.__kkToasts.push(t.textContent.trim().slice(0, 200)); }).observe(document.body, { subtree: true, childList: true, characterData: true }); })()',
|
|
3084
|
+
'',
|
|
3085
|
+
);
|
|
3086
|
+
}
|
|
3004
3087
|
await clickSelector(page, save, 8_000);
|
|
3005
|
-
|
|
3088
|
+
if (sawLiveUpload) {
|
|
3089
|
+
let formClosed = await waitUntil(async () => !(await isLiveUploadForm()), saveCloseWaitMs);
|
|
3090
|
+
if (!formClosed) {
|
|
3091
|
+
const dispatched = await evalOrFallback(
|
|
3092
|
+
page,
|
|
3093
|
+
'(() => { const form = [...document.querySelectorAll(".weui-desktop-dialog")].find((d) => d.querySelector(".title_form_wrp")); const btn = form && [...form.querySelectorAll("button")].find((b) => (b.textContent ?? "").trim() === "保存"); if (!btn) return "no-btn"; btn.click(); return btn.disabled ? "was-disabled" : "clicked"; })()',
|
|
3094
|
+
'null',
|
|
3095
|
+
);
|
|
3096
|
+
formClosed = await waitUntil(async () => !(await isLiveUploadForm()), saveDispatchWaitMs);
|
|
3097
|
+
if (!formClosed) {
|
|
3098
|
+
const saveDiagnostics = `(() => {
|
|
3099
|
+
const form = [...document.querySelectorAll(".weui-desktop-dialog")].find((d) => d.querySelector(".title_form_wrp"));
|
|
3100
|
+
const btn = form && [...form.querySelectorAll("button")].find((b) => (b.textContent ?? "").trim() === "保存");
|
|
3101
|
+
return JSON.stringify({ btn: btn ? { disabled: btn.disabled, offW: btn.offsetWidth } : null, toasts: (window.__kkToasts ?? []).slice(-3) });
|
|
3102
|
+
})()`;
|
|
3103
|
+
const diag = (await evalOrFallback(page, saveDiagnostics, '')).slice(0, 400);
|
|
3104
|
+
return failUpload(`音频: 保存失败,上传弹窗未关闭(dispatch=${dispatched} ${diag})`);
|
|
3105
|
+
}
|
|
3106
|
+
}
|
|
3107
|
+
}
|
|
3108
|
+
return failUpload('');
|
|
3006
3109
|
};
|
|
3007
3110
|
|
|
3008
3111
|
/** One MATCH read; a throwing probe stays 'error' (unknown, never treated as missing). */
|
|
@@ -3014,9 +3117,9 @@ export async function insertAudioMaterial(
|
|
|
3014
3117
|
}
|
|
3015
3118
|
};
|
|
3016
3119
|
/** Poll the picker while rows stream in; 'missing' keeps polling, JSON answers settle it. */
|
|
3017
|
-
const awaitMatch = async (): Promise<string> => {
|
|
3120
|
+
const awaitMatch = async (retries: number = AUDIO_ROW_RETRIES): Promise<string> => {
|
|
3018
3121
|
let match = await matchOnce();
|
|
3019
|
-
for (let i = 0; match === 'missing' && i <
|
|
3122
|
+
for (let i = 0; match === 'missing' && i < retries; i += 1) {
|
|
3020
3123
|
await page.waitForTimeout?.(AUDIO_ROW_SETTLE_MS);
|
|
3021
3124
|
match = await matchOnce();
|
|
3022
3125
|
}
|
|
@@ -3033,16 +3136,18 @@ export async function insertAudioMaterial(
|
|
|
3033
3136
|
await page.evaluate(`document.querySelector(${JSON.stringify(AUDIO_MENU)})?.click()`);
|
|
3034
3137
|
await waitForVisible(page, AUDIO_DIALOG, AUDIO_DIALOG_TIMEOUT_MS);
|
|
3035
3138
|
let match = await awaitMatch();
|
|
3139
|
+
let postSavePoll = false;
|
|
3036
3140
|
if (match === 'missing') {
|
|
3037
3141
|
// No reusable material: upload one, then POLL until the new row actually exists — never
|
|
3038
3142
|
// assume the upload auto-selected a default row (task 0260 AC2).
|
|
3039
3143
|
const uploadResult = await upload();
|
|
3144
|
+
postSavePoll = uploadResult.sawLiveUpload;
|
|
3040
3145
|
if (uploadResult.warning !== '') {
|
|
3041
|
-
await page.evaluate(CANCEL);
|
|
3146
|
+
if (!uploadResult.sawLiveUpload) await page.evaluate(CANCEL);
|
|
3042
3147
|
return result(uploadResult.warning);
|
|
3043
3148
|
}
|
|
3044
3149
|
await waitForVisible(page, AUDIO_DIALOG, AUDIO_DIALOG_TIMEOUT_MS);
|
|
3045
|
-
match = await awaitMatch();
|
|
3150
|
+
match = await awaitMatch(postSavePoll ? postUploadRowRetries : AUDIO_ROW_RETRIES);
|
|
3046
3151
|
if (match === 'missing') {
|
|
3047
3152
|
await page.evaluate(CANCEL);
|
|
3048
3153
|
return result(`音频: 保存后素材列表未出现「${title}」,未插入音频`);
|
|
@@ -3070,7 +3175,14 @@ export async function insertAudioMaterial(
|
|
|
3070
3175
|
await page.evaluate(CANCEL);
|
|
3071
3176
|
return result('音频: 素材匹配探测返回未知结果,未插入音频');
|
|
3072
3177
|
}
|
|
3073
|
-
|
|
3178
|
+
let inserted = (await page.evaluate(INSERT)) === true;
|
|
3179
|
+
if (!inserted && postSavePoll) {
|
|
3180
|
+
for (let i = 0; !inserted && i < 5; i += 1) {
|
|
3181
|
+
await page.waitForTimeout?.(500);
|
|
3182
|
+
inserted = (await page.evaluate(INSERT)) === true;
|
|
3183
|
+
}
|
|
3184
|
+
}
|
|
3185
|
+
if (!inserted) {
|
|
3074
3186
|
await page.evaluate(CANCEL);
|
|
3075
3187
|
return result('音频: 插入按钮未找到,请手动插入');
|
|
3076
3188
|
}
|
|
@@ -208,14 +208,29 @@ async function resolveMediaPath(content: Content, spec: MediaSpec): Promise<{ pa
|
|
|
208
208
|
return { path };
|
|
209
209
|
}
|
|
210
210
|
|
|
211
|
+
/** Whether `content.metadata.wechatmp.coverSource === 'library'`. */
|
|
212
|
+
export function isLibraryCover(content: Content): boolean {
|
|
213
|
+
const wechatmp = content.metadata?.wechatmp;
|
|
214
|
+
return (
|
|
215
|
+
typeof wechatmp === 'object' &&
|
|
216
|
+
wechatmp !== null &&
|
|
217
|
+
!Array.isArray(wechatmp) &&
|
|
218
|
+
(wechatmp as Record<string, unknown>).coverSource === 'library'
|
|
219
|
+
);
|
|
220
|
+
}
|
|
221
|
+
|
|
211
222
|
/**
|
|
212
223
|
* The body-image set for the two image-carrying modes, in attachment order.
|
|
213
224
|
*
|
|
214
|
-
* `metadata.images` is the repo's ordered convention (xhs reads the same key).
|
|
215
|
-
*
|
|
216
|
-
*
|
|
225
|
+
* `metadata.images` is the repo's ordered convention (xhs reads the same key). When `coverSource`
|
|
226
|
+
* is `'library'` (the daily 文章 + audio rail), the cover comes from 图片库 via the audio upload's
|
|
227
|
+
* seeded cover — validating `coverPath`/`coverImage` stays active, but the cover file is NOT
|
|
228
|
+
* injected into the article body. When `coverSource` is `'body'` or omitted, `coverPath`/`coverImage`
|
|
229
|
+
* are prepended so 默认首图为封面 resolves the cover from the first body image (discovery §5.2).
|
|
217
230
|
*/
|
|
218
|
-
async function resolveBodyImages(
|
|
231
|
+
async function resolveBodyImages(
|
|
232
|
+
content: Content,
|
|
233
|
+
): Promise<{ paths?: string[]; hasValidatedCover?: boolean; error?: string }> {
|
|
219
234
|
const ordered = content.metadata?.images;
|
|
220
235
|
if (ordered !== undefined && !Array.isArray(ordered)) {
|
|
221
236
|
return { error: 'images validation: metadata.images must be an array' };
|
|
@@ -225,9 +240,9 @@ async function resolveBodyImages(content: Content): Promise<{ paths?: string[];
|
|
|
225
240
|
typeof content.metadata?.wechatmp === 'object' && content.metadata.wechatmp !== null
|
|
226
241
|
? (content.metadata.wechatmp as Record<string, unknown>).coverPath
|
|
227
242
|
: undefined;
|
|
228
|
-
const candidates: Array<{ path: string; what: string }> = [];
|
|
243
|
+
const candidates: Array<{ path: string; what: string; coverOnly: boolean }> = [];
|
|
229
244
|
if (typeof cover === 'string' && cover.length > 0)
|
|
230
|
-
candidates.push({ path: cover, what: 'metadata.wechatmp.coverPath' });
|
|
245
|
+
candidates.push({ path: cover, what: 'metadata.wechatmp.coverPath', coverOnly: true });
|
|
231
246
|
// Repo-wide single-cover convention (itc pipeline writes this; surfdash/xhs read it too).
|
|
232
247
|
const genericCover = content.metadata?.coverImage;
|
|
233
248
|
const genericCoverPath =
|
|
@@ -237,17 +252,19 @@ async function resolveBodyImages(content: Content): Promise<{ paths?: string[];
|
|
|
237
252
|
? (genericCover as { path: string }).path
|
|
238
253
|
: undefined;
|
|
239
254
|
if (genericCoverPath !== undefined && genericCoverPath.length > 0)
|
|
240
|
-
candidates.push({ path: genericCoverPath, what: 'metadata.coverImage' });
|
|
255
|
+
candidates.push({ path: genericCoverPath, what: 'metadata.coverImage', coverOnly: true });
|
|
241
256
|
for (const [index, image] of descriptors.entries()) {
|
|
242
257
|
const path = typeof image === 'string' ? image : (image as { path?: unknown })?.path;
|
|
243
258
|
if (typeof path !== 'string' || path.length === 0) {
|
|
244
259
|
return { error: `images validation: images[${index}] carries no path` };
|
|
245
260
|
}
|
|
246
|
-
candidates.push({ path, what: `metadata.images[${index}]
|
|
261
|
+
candidates.push({ path, what: `metadata.images[${index}]`, coverOnly: false });
|
|
247
262
|
}
|
|
248
263
|
|
|
264
|
+
const skipCoverInBody = isLibraryCover(content);
|
|
249
265
|
const paths: string[] = [];
|
|
250
|
-
|
|
266
|
+
let hasValidatedCover = false;
|
|
267
|
+
for (const { path, what, coverOnly } of candidates) {
|
|
251
268
|
if (!isAbsolute(path)) {
|
|
252
269
|
return { error: `images validation: ${what} must be absolute, got '${path}'` };
|
|
253
270
|
}
|
|
@@ -259,9 +276,10 @@ async function resolveBodyImages(content: Content): Promise<{ paths?: string[];
|
|
|
259
276
|
if (!(await createNodeFileSystem().exists(path))) {
|
|
260
277
|
return { error: `images validation: ${what} does not exist: '${path}'` };
|
|
261
278
|
}
|
|
262
|
-
|
|
279
|
+
if (coverOnly) hasValidatedCover = true;
|
|
280
|
+
if (!(skipCoverInBody && coverOnly)) paths.push(path);
|
|
263
281
|
}
|
|
264
|
-
return { paths };
|
|
282
|
+
return { paths, hasValidatedCover };
|
|
265
283
|
}
|
|
266
284
|
|
|
267
285
|
/**
|
|
@@ -359,7 +377,7 @@ export async function validateModeInput(operation: WechatmpOperation, content: C
|
|
|
359
377
|
if (digest.error) return { error: digest.error };
|
|
360
378
|
const images = await resolveBodyImages(content);
|
|
361
379
|
if (images.error) return { error: images.error };
|
|
362
|
-
if ((images.paths ?? []).length === 0) {
|
|
380
|
+
if ((images.paths ?? []).length === 0 && !(isLibraryCover(content) && images.hasValidatedCover === true)) {
|
|
363
381
|
return {
|
|
364
382
|
error: 'cover validation: 文章 takes its cover from a body image (默认首图为封面) but none was supplied — set metadata.wechatmp.coverPath, metadata.coverImage or metadata.images[]',
|
|
365
383
|
};
|