@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.
- package/.claude-plugin/marketplace.json +1 -1
- package/dist/board/daily-voice/index.js +40 -7
- package/dist/index.js +8428 -4448
- package/package.json +1 -1
- 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/kk/config.example.yaml +7 -2
- package/plugins/kk/decisions/extract/ai-news.yaml +5 -2
- package/plugins/kk/plugin.json +1 -1
- package/plugins/kk/publish-presets/chinese-article.json +8 -2
- package/plugins/kk/publish-presets/daily-ai-voice-migration.json +1 -1
- package/plugins/kk/publish-presets/daily-ai-voice.json +57 -16
- package/plugins/kk/publish-presets/itc-main.json +36 -9
- package/plugins/kk/publish-presets/technical-article.json +8 -2
- package/plugins/kk/schedules/kk-daily-ai-voice3.cron.tmpl +8 -9
- package/plugins/kk/schedules/kk-daily-publish3-cn-peak.cron.tmpl +13 -19
- package/plugins/kk/schedules/kk-daily-publish3-overseas.cron.tmpl +11 -9
- package/plugins/kk/scripts/daily-stages.ts +238 -14
- package/plugins/kk/scripts/daily-triage-core.ts +43 -25
- package/plugins/kk/scripts/daily-triage.ts +1 -1
- 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/publish/SKILL.md +15 -2
- package/plugins/kk/skills/web-automation/SKILL.md +31 -1
- package/plugins/kk/workflows/kk-article-generate.yaml +485 -0
- package/plugins/kk/workflows/kk-collect.yaml +8 -4
- package/plugins/kk/workflows/kk-daily-ai-voice.yaml +2 -1
- package/plugins/kk/workflows/kk-daily-ai-voice2.yaml +4 -2
- package/plugins/kk/workflows/kk-daily-safety.yaml +5 -7
- package/plugins/kk/workflows/kk-news-generate.yaml +410 -0
- package/plugins/kk/workflows/kk-publish.yaml +236 -0
- package/plugins/publishings/bilibili-pub/dist/profile-check.js +49 -10
- package/plugins/publishings/cnblogs-pub/dist/profile-check.js +60 -10
- package/plugins/publishings/csdn-pub/dist/profile-check.js +60 -10
- package/plugins/publishings/infoq-pub/dist/profile-check.js +60 -10
- package/plugins/publishings/jike-pub/dist/profile-check.js +60 -10
- package/plugins/publishings/juejin-pub/dist/profile-check.js +60 -10
- package/plugins/publishings/linkedin-pub/dist/index.js +43 -6
- package/plugins/publishings/linkedin-pub/dist/profile-check.js +92 -15
- package/plugins/publishings/linkedin-pub/src/index.ts +52 -6
- package/plugins/publishings/shipinhao-pub/dist/index.js +391 -32
- package/plugins/publishings/shipinhao-pub/dist/profile-check.js +52 -11
- package/plugins/publishings/shipinhao-pub/plugin.json +1 -1
- package/plugins/publishings/shipinhao-pub/src/audio-flow.ts +393 -0
- package/plugins/publishings/shipinhao-pub/src/flow.ts +243 -14
- package/plugins/publishings/shipinhao-pub/src/selectors.ts +13 -0
- package/plugins/publishings/sspai-pub/dist/profile-check.js +60 -10
- package/plugins/publishings/substack-pub/dist/profile-check.js +60 -10
- package/plugins/publishings/surfdash-pub/dist/index.js +50 -8
- package/plugins/publishings/surfdash-pub/src/index.ts +59 -8
- package/plugins/publishings/surfdash-pub/src/topic-claims.ts +34 -3
- package/plugins/publishings/threads-pub/dist/index.js +9196 -296
- package/plugins/publishings/threads-pub/dist/profile-check.js +21139 -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 +454 -81
- package/plugins/publishings/wechatmp-pub/dist/profile-check.js +401 -102
- package/plugins/publishings/wechatmp-pub/src/flow.ts +42 -4
- package/plugins/publishings/wechatmp-pub/src/index.ts +142 -102
- package/plugins/publishings/wechatmp-pub/src/profile-check.ts +36 -58
- package/plugins/publishings/weibo-pub/dist/index.js +136 -22
- package/plugins/publishings/weibo-pub/dist/profile-check.js +61 -11
- package/plugins/publishings/weibo-pub/src/index.ts +208 -22
- package/plugins/publishings/x-pub/dist/index.js +263 -43
- package/plugins/publishings/x-pub/dist/profile-check.js +63 -11
- 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 +193 -201
- package/plugins/publishings/xhs-pub/dist/profile-check.js +380 -85
- package/plugins/publishings/xhs-pub/src/automation-guard.ts +2 -3
- package/plugins/publishings/xhs-pub/src/flow.ts +177 -205
- package/plugins/publishings/xhs-pub/src/index.ts +65 -59
- package/plugins/publishings/xhs-pub/src/modes.ts +1 -1
- package/plugins/publishings/xhs-pub/src/page.ts +2 -2
- package/plugins/publishings/xhs-pub/src/profile-check.ts +86 -150
- package/plugins/publishings/xiaoyuzhou-pub/dist/profile-check.js +60 -10
- package/plugins/kk/scripts/daily-scheduled-run.ts +0 -581
- package/plugins/kk/scripts/voice3-publish-window.ts +0 -206
- package/plugins/kk/workflows/kk-daily-ai-voice3.yaml +0 -903
- package/plugins/kk/workflows/kk-daily-publish3.yaml +0 -353
- package/plugins/kk/workflows/kk-itc-author.yaml +0 -484
- package/plugins/kk/workflows/kk-itc-publish-tail.yaml +0 -112
- package/plugins/kk/workflows/kk-itc.yaml +0 -291
|
@@ -20355,6 +20355,16 @@ async function openChannelSession(config, request, deps = {}, stdout = echo) {
|
|
|
20355
20355
|
return 1;
|
|
20356
20356
|
}
|
|
20357
20357
|
const page = context.pages()[0] ?? await context.newPage();
|
|
20358
|
+
const onOpen = config.sessionState?.onOpen;
|
|
20359
|
+
if (onOpen !== undefined) {
|
|
20360
|
+
try {
|
|
20361
|
+
await onOpen({ context, page, profileDir: request.profileDir });
|
|
20362
|
+
} catch (error) {
|
|
20363
|
+
await context.close().catch(() => {});
|
|
20364
|
+
stdout(`${config.channel} profile open failed: ${errorMessage2(error)}`);
|
|
20365
|
+
return 1;
|
|
20366
|
+
}
|
|
20367
|
+
}
|
|
20358
20368
|
try {
|
|
20359
20369
|
await page.goto(request.url, { waitUntil: "commit", timeout: DEFAULT_OPEN_NAV_TIMEOUT_MS });
|
|
20360
20370
|
} catch (error) {
|
|
@@ -20366,6 +20376,36 @@ async function openChannelSession(config, request, deps = {}, stdout = echo) {
|
|
|
20366
20376
|
stdout(`${config.channel} profile open closed: ${request.profileDir}`);
|
|
20367
20377
|
return 0;
|
|
20368
20378
|
}
|
|
20379
|
+
async function loginWithAuthenticatedPage(config, opts) {
|
|
20380
|
+
const context = await opts.launcher.launch({ profileDir: opts.profileDir, headless: false });
|
|
20381
|
+
const sessionCaptured = config.sessionState?.onAuthenticated !== undefined;
|
|
20382
|
+
let captured = false;
|
|
20383
|
+
let facts = {};
|
|
20384
|
+
try {
|
|
20385
|
+
const page = context.pages()[0] ?? await context.newPage();
|
|
20386
|
+
await page.goto(opts.url);
|
|
20387
|
+
if (!await waitUntil(() => Promise.resolve(config.isAuthenticated(page)), opts.timeoutMs)) {
|
|
20388
|
+
throw new Error(`Authentication was not confirmed within ${opts.timeoutMs}ms \u2014 the profile's site session has likely ` + "expired or the sign-in was not completed: run the login command again to sign in again.");
|
|
20389
|
+
}
|
|
20390
|
+
await config.sessionState?.onAuthenticated?.({ context, page, profileDir: opts.profileDir });
|
|
20391
|
+
captured = sessionCaptured;
|
|
20392
|
+
if (opts.captureFacts) {
|
|
20393
|
+
facts = {
|
|
20394
|
+
...await captureSessionFacts(context, config.homeUrl),
|
|
20395
|
+
...config.readIdentity === undefined ? {} : { identity: await readIdentityOrUndefined(config.readIdentity, page) }
|
|
20396
|
+
};
|
|
20397
|
+
}
|
|
20398
|
+
} finally {
|
|
20399
|
+
try {
|
|
20400
|
+
await context.close();
|
|
20401
|
+
} catch {
|
|
20402
|
+
if (captured) {
|
|
20403
|
+
echoError(`${config.channel} browser context close failed after the authenticated session capture; saved state preserved`);
|
|
20404
|
+
}
|
|
20405
|
+
}
|
|
20406
|
+
}
|
|
20407
|
+
return facts;
|
|
20408
|
+
}
|
|
20369
20409
|
async function runProfileCli(config, argv = process.argv.slice(2), deps = {}) {
|
|
20370
20410
|
const stdout = deps.stdout ?? ((line) => {
|
|
20371
20411
|
echo(line);
|
|
@@ -20416,7 +20456,8 @@ async function runProfileCli(config, argv = process.argv.slice(2), deps = {}) {
|
|
|
20416
20456
|
const launcher = deps.launcher ?? kkBrowserLauncher;
|
|
20417
20457
|
stdout(`${config.channel} profile login: a browser window is opening \u2014 sign in there; waiting up to ${Math.round(loginTimeoutMs / 1000)}s for the signed-in state`);
|
|
20418
20458
|
try {
|
|
20419
|
-
|
|
20459
|
+
const captureFacts = url !== undefined;
|
|
20460
|
+
if (!captureFacts && config.sessionState?.onAuthenticated === undefined) {
|
|
20420
20461
|
await loginWithProfile({
|
|
20421
20462
|
profileDir,
|
|
20422
20463
|
url: config.homeUrl,
|
|
@@ -20427,18 +20468,16 @@ async function runProfileCli(config, argv = process.argv.slice(2), deps = {}) {
|
|
|
20427
20468
|
stdout(`${config.channel} profile login verified: ${profileDir}`);
|
|
20428
20469
|
return 0;
|
|
20429
20470
|
}
|
|
20430
|
-
const facts = await
|
|
20471
|
+
const facts = await loginWithAuthenticatedPage(config, {
|
|
20431
20472
|
profileDir,
|
|
20432
|
-
|
|
20433
|
-
url,
|
|
20434
|
-
isAuthenticated: config.isAuthenticated,
|
|
20473
|
+
url: url ?? config.homeUrl,
|
|
20435
20474
|
timeoutMs: loginTimeoutMs,
|
|
20436
|
-
launcher
|
|
20437
|
-
|
|
20438
|
-
|
|
20439
|
-
...config.readIdentity === undefined ? {} : { identity: await readIdentityOrUndefined(config.readIdentity, page) }
|
|
20440
|
-
}));
|
|
20475
|
+
launcher,
|
|
20476
|
+
captureFacts
|
|
20477
|
+
});
|
|
20441
20478
|
stdout(`${config.channel} profile login verified: ${profileDir}`);
|
|
20479
|
+
if (url === undefined)
|
|
20480
|
+
return 0;
|
|
20442
20481
|
stdout(JSON.stringify({
|
|
20443
20482
|
status: "verified",
|
|
20444
20483
|
profileDir,
|
|
@@ -20565,7 +20604,9 @@ var SHP_VIDEO_SELECTORS = {
|
|
|
20565
20604
|
originalAgreementCheckbox: 'div.declare-body-wrapper input[type="checkbox"].ant-checkbox-input',
|
|
20566
20605
|
originalConfirmLabel: "\u58F0\u660E\u539F\u521B",
|
|
20567
20606
|
saveButton: ['button:text-is("\u4FDD\u5B58\u8349\u7A3F")'],
|
|
20568
|
-
publishButton: ['button:text-is("\u53D1\u8868")', '[role="button"]:text-is("\u53D1\u8868")']
|
|
20607
|
+
publishButton: ['button:text-is("\u53D1\u8868")', '[role="button"]:text-is("\u53D1\u8868")'],
|
|
20608
|
+
collectionEntry: ['button:has-text("\u5408\u96C6")', 'div:has-text("\u5408\u96C6")', 'span:has-text("\u5408\u96C6")'],
|
|
20609
|
+
collectionLabel: "\u5408\u96C6"
|
|
20569
20610
|
};
|
|
20570
20611
|
var SHP_AUDIO_SELECTORS = {
|
|
20571
20612
|
...SHP_VIDEO_SELECTORS,
|
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
"entry": "./dist/index.js",
|
|
5
5
|
"check": "./dist/profile-check.js",
|
|
6
6
|
"version": "1.0.0",
|
|
7
|
-
"description": "shipinhao (channels.weixin.qq.com) publish via a script browser transport with wujie-app shadowRoot traversal; four post kinds (shortVideo 视频, audio 音频, image 图文, music 音乐 — audio is the first deliverable); draft by default, public only on an explicit publishStatus with a fresh works receipt, requested-only 声明原创 declaration",
|
|
7
|
+
"description": "shipinhao (channels.weixin.qq.com) publish via a script browser transport with wujie-app shadowRoot traversal; four post kinds (shortVideo 视频, audio 音频, image 图文, music 音乐 — audio is the first deliverable and rides its own /platform/post/createAudio surface: required 封面, optional 合集, no draft); draft by default for the video rails, public only on an explicit publishStatus with a fresh works receipt, requested-only 声明原创 declaration",
|
|
8
8
|
"browserSession": {
|
|
9
9
|
"profileName": "shipinhao",
|
|
10
10
|
"homeUrl": "https://channels.weixin.qq.com/platform"
|
|
@@ -0,0 +1,393 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* shipinhao 音频 (audio) post flow — the dedicated `/platform/post/createAudio` surface.
|
|
3
|
+
*
|
|
4
|
+
* WHY this file exists (2026-11-16, the "shipinhao audio never publishes" failure): the audio
|
|
5
|
+
* operation used to drive the VIDEO create surface (`/platform/post/create`, reached from the
|
|
6
|
+
* dashboard's 发表视频), feeding the .mp3 to the video intake. The platform then transcodes it as a
|
|
7
|
+
* video — the cover sits at 封面预览 生成中 forever — so the post never persisted and the receipt
|
|
8
|
+
* stage could only report `uncertain / effect unknown` (2026-11-15 run:
|
|
9
|
+
* `kk-news-generate-20261115-1794799176832`, receipt status `uncertain`).
|
|
10
|
+
*
|
|
11
|
+
* Live recon 2026-11-16 pinned the real surface: dashboard → `内容管理` → `音频` (`音频管理`,
|
|
12
|
+
* `/platform/post/audioManager`, which also carries the 音频 | 合集 tabs) → `发表音频`
|
|
13
|
+
* (`/platform/post/createAudio`) with, in order: 音频 (上传文件 / 从视频选音频), 文件
|
|
14
|
+
* (drag-drop zone, WAV/MP3, ≥10 s, ≥64 kbps, ≤1 GB), 封面 (1:1, jpg/png, ≤8 MB), 标题 (≤40),
|
|
15
|
+
* 描述 (textarea, ≤3000), 合集 (`选择合集`, per-kind list: 不加合集 / <collections> / 创建新合集),
|
|
16
|
+
* 定时发表, and ONE submit rail — `发表音频`. There is no 保存草稿 on this surface, which is why a
|
|
17
|
+
* `publishStatus: 'draft'` request is refused here instead of being approximated.
|
|
18
|
+
*
|
|
19
|
+
* The receipt is the audio LIST, not a URL shape: the site returns to `/platform/post/audioManager`
|
|
20
|
+
* and the new row (title + 发布时间 + status) is the works record. A submit whose row never appears
|
|
21
|
+
* is `unknown`, never `published`.
|
|
22
|
+
*/
|
|
23
|
+
|
|
24
|
+
import { type Result, ResultSchema } from '@gobing-ai/kk-core';
|
|
25
|
+
import type { Page } from 'playwright';
|
|
26
|
+
import { SHP_TARGET, type ShipinhaoOperationName } from './selectors';
|
|
27
|
+
|
|
28
|
+
/** The 音频 manager and create routes (recon-Grounded 2026-11-16). */
|
|
29
|
+
export const SHP_AUDIO_MANAGER_PATH = '/platform/post/audioManager';
|
|
30
|
+
export const SHP_AUDIO_CREATE_PATH = '/platform/post/createAudio';
|
|
31
|
+
|
|
32
|
+
/** 标题 hard cap on the audio form (0/40 counter, live recon 2026-11-16). */
|
|
33
|
+
export const SHP_AUDIO_TITLE_MAX = 40;
|
|
34
|
+
/** 描述 hard cap on the audio form (0/3000 counter, live recon 2026-11-16). */
|
|
35
|
+
export const SHP_AUDIO_DESCRIPTION_MAX = 3000;
|
|
36
|
+
/** Budget for the fresh-row receipt in 音频管理 after 发表音频 (recon: the list re-renders in seconds). */
|
|
37
|
+
export const SHP_AUDIO_RECEIPT_MS = 30_000;
|
|
38
|
+
|
|
39
|
+
/** Test seam for the receipt clock: the 30 s production value made the suite unrunnable. */
|
|
40
|
+
let receiptBudgetMs: number | null = null;
|
|
41
|
+
export function setAudioReceiptBudgetForTests(ms: number | null): void {
|
|
42
|
+
receiptBudgetMs = ms;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
/** Everything the audio flow needs; the caller owns the pre-browser ladder and the session check. */
|
|
46
|
+
export interface AudioFlowInput {
|
|
47
|
+
page: Page;
|
|
48
|
+
title: string;
|
|
49
|
+
body: string;
|
|
50
|
+
tags: readonly string[];
|
|
51
|
+
/** One local audio file (the episode mp3). */
|
|
52
|
+
media: readonly string[];
|
|
53
|
+
coverPath?: string;
|
|
54
|
+
collection?: string;
|
|
55
|
+
publishPublic: boolean;
|
|
56
|
+
operation: ShipinhaoOperationName;
|
|
57
|
+
profileDir: string;
|
|
58
|
+
stepTimeoutMs: number;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
/** A typed failure Result, matching the flow's `stageFail` shape without importing the video flow. */
|
|
62
|
+
function stageFail(message: string, stage: string, metadata: Record<string, unknown>, evidence?: string): Result {
|
|
63
|
+
return ResultSchema.parse({
|
|
64
|
+
ok: false,
|
|
65
|
+
target: SHP_TARGET,
|
|
66
|
+
error: message,
|
|
67
|
+
effect: 'unknown',
|
|
68
|
+
metadata: { ...metadata, stage, ...(evidence === undefined ? {} : { evidence }) },
|
|
69
|
+
});
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
/** Poll `probe` until it returns a non-null value, or the budget runs out. */
|
|
73
|
+
export async function expectOutcome<T>(
|
|
74
|
+
probe: () => Promise<T | null>,
|
|
75
|
+
timeoutMs: number,
|
|
76
|
+
label: string,
|
|
77
|
+
): Promise<{ ok: true; evidence: T } | { ok: false; error: string }> {
|
|
78
|
+
const deadline = Date.now() + timeoutMs;
|
|
79
|
+
let last = `${label} never observed`;
|
|
80
|
+
for (;;) {
|
|
81
|
+
try {
|
|
82
|
+
const value = await probe();
|
|
83
|
+
if (value !== null) return { ok: true, evidence: value };
|
|
84
|
+
} catch (error) {
|
|
85
|
+
last = `${label}: ${error instanceof Error ? error.message : String(error)}`;
|
|
86
|
+
}
|
|
87
|
+
if (Date.now() >= deadline) return { ok: false, error: last };
|
|
88
|
+
await new Promise((resolve) => setTimeout(resolve, 500));
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
/** The 描述 text: the body's trimmed plain text plus the topic tags, clipped to the form's cap. */
|
|
93
|
+
export function buildAudioDescription(body: string, tags: readonly string[]): string {
|
|
94
|
+
const topicLine = tags.map((tag) => `#${tag.replace(/^#/, '')}`).join(' ');
|
|
95
|
+
const combined = topicLine.length > 0 ? `${body.trim()}\n\n${topicLine}` : body.trim();
|
|
96
|
+
return combined.slice(0, SHP_AUDIO_DESCRIPTION_MAX);
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
/** The 标题: clipped to 40 by code point so a long title is a clipped title, never a failed fill. */
|
|
100
|
+
export function clipAudioTitle(title: string): string {
|
|
101
|
+
return Array.from(title.trim()).slice(0, SHP_AUDIO_TITLE_MAX).join('');
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
/**
|
|
105
|
+
* Navigate dashboard → 内容管理 → 音频 → 发表音频 and confirm the create surface, returning a typed
|
|
106
|
+
* failure instead of throwing when any hop is missing (the SPA's submenu only exists while hovered,
|
|
107
|
+
* so the click is dispatched on the anchor once the menu is open).
|
|
108
|
+
*/
|
|
109
|
+
async function openAudioCreate(page: Page, stepTimeoutMs: number): Promise<string | null> {
|
|
110
|
+
await page.goto('https://channels.weixin.qq.com/platform', {
|
|
111
|
+
waitUntil: 'domcontentloaded',
|
|
112
|
+
timeout: stepTimeoutMs,
|
|
113
|
+
});
|
|
114
|
+
await page.waitForTimeout(8_000);
|
|
115
|
+
const menu = page.locator('a:has-text("内容管理")').first();
|
|
116
|
+
await menu.hover({ timeout: stepTimeoutMs });
|
|
117
|
+
await page.waitForTimeout(2_000);
|
|
118
|
+
// The submenu exists only while 内容管理 is hovered, and the anchor is an SPA link: click it
|
|
119
|
+
// through the DOM (a Playwright click rejects the item once the hover moves).
|
|
120
|
+
const clicked = await page.evaluate(`(() => {
|
|
121
|
+
const anchor = Array.from(document.querySelectorAll('a')).find((el) => (el.textContent || '').trim() === '音频');
|
|
122
|
+
if (!anchor) return false;
|
|
123
|
+
anchor.click();
|
|
124
|
+
return true;
|
|
125
|
+
})()`);
|
|
126
|
+
if (!clicked) return '音频 submenu entry not found under 内容管理';
|
|
127
|
+
const manager = await expectOutcome(
|
|
128
|
+
async () => (page.url().includes(SHP_AUDIO_MANAGER_PATH) ? page.url() : null),
|
|
129
|
+
stepTimeoutMs,
|
|
130
|
+
'音频管理 page',
|
|
131
|
+
);
|
|
132
|
+
if (!manager.ok) return `音频管理 page never opened: ${manager.error}`;
|
|
133
|
+
const entry = page.locator('button:has-text("发表音频")').first();
|
|
134
|
+
// The URL flips before the manager renders its header button — poll, do not count once.
|
|
135
|
+
const ready = await expectOutcome(
|
|
136
|
+
async () => ((await entry.count()) > 0 ? '发表音频 entry rendered' : null),
|
|
137
|
+
stepTimeoutMs,
|
|
138
|
+
'音频管理 发表音频 entry',
|
|
139
|
+
);
|
|
140
|
+
if (!ready.ok) return `发表音频 entry never rendered on 音频管理: ${ready.error}`;
|
|
141
|
+
await entry.click({ timeout: stepTimeoutMs });
|
|
142
|
+
const create = await expectOutcome(
|
|
143
|
+
async () => (page.url().includes(SHP_AUDIO_CREATE_PATH) ? page.url() : null),
|
|
144
|
+
stepTimeoutMs,
|
|
145
|
+
'发表音频 form',
|
|
146
|
+
);
|
|
147
|
+
if (!create.ok) return `发表音频 form never opened: ${create.error}`;
|
|
148
|
+
return null;
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
/** Upload the mp3 through the drop zone's file chooser and wait for the file chip to render. */
|
|
152
|
+
async function attachAudio(page: Page, file: string, stepTimeoutMs: number): Promise<string | null> {
|
|
153
|
+
const zone = page.locator('text=拖拽到此处上传').first();
|
|
154
|
+
if ((await zone.count()) === 0) return 'audio drop zone (拖拽到此处上传) not found';
|
|
155
|
+
const chooserPromise = page.waitForEvent('filechooser', { timeout: stepTimeoutMs }).catch(() => null);
|
|
156
|
+
await zone.click({ timeout: stepTimeoutMs });
|
|
157
|
+
const chooser = await chooserPromise;
|
|
158
|
+
if (chooser === null) return 'clicking the audio drop zone opened no file chooser';
|
|
159
|
+
await chooser.setFiles(file);
|
|
160
|
+
const name = file.split('/').pop() ?? '';
|
|
161
|
+
const attached = await expectOutcome(
|
|
162
|
+
async () => ((await page.locator(`text=${name.slice(0, 12)}`).count()) > 0 ? 'file chip rendered' : null),
|
|
163
|
+
60_000,
|
|
164
|
+
'audio file chip',
|
|
165
|
+
);
|
|
166
|
+
if (!attached.ok) return `the file was handed to the form but no file chip appeared: ${attached.error}`;
|
|
167
|
+
return null;
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
/**
|
|
171
|
+
* Attach the 封面: click the tile above the 封面宽高比 hint, hand the file to the chooser, then
|
|
172
|
+
* confirm the 编辑音频封面 crop dialog (确认). Success = the form's 「请上传封面」 validation text is
|
|
173
|
+
* gone and a preview is rendered — a cover the form rejected must never reach the submit click.
|
|
174
|
+
*/
|
|
175
|
+
export async function attachAudioCover(page: Page, coverPath: string, stepTimeoutMs: number): Promise<string | null> {
|
|
176
|
+
const hint = page.locator('text=封面宽高比').first();
|
|
177
|
+
if ((await hint.count()) === 0) return '音频 封面 hint (封面宽高比) not found';
|
|
178
|
+
await hint.scrollIntoViewIfNeeded();
|
|
179
|
+
const box = await hint.boundingBox();
|
|
180
|
+
if (box === null) return '音频 封面 tile has no layout box';
|
|
181
|
+
const chooserPromise = page.waitForEvent('filechooser', { timeout: stepTimeoutMs }).catch(() => null);
|
|
182
|
+
// The tile is the dashed “+” square directly above the hint text.
|
|
183
|
+
await page.mouse.click(box.x + 40, box.y - 70);
|
|
184
|
+
const chooser = await chooserPromise;
|
|
185
|
+
if (chooser === null) return 'clicking the 封面 tile opened no file chooser';
|
|
186
|
+
await chooser.setFiles(coverPath);
|
|
187
|
+
const cropped = await expectOutcome(
|
|
188
|
+
async () => {
|
|
189
|
+
const confirm = page.locator('button:text-is("确认")').first();
|
|
190
|
+
if ((await confirm.count()) === 0 || !(await confirm.isVisible().catch(() => false))) return null;
|
|
191
|
+
await confirm.click({ timeout: 4_000 }).catch(() => {});
|
|
192
|
+
return 'crop confirmed';
|
|
193
|
+
},
|
|
194
|
+
stepTimeoutMs,
|
|
195
|
+
'编辑音频封面 crop dialog',
|
|
196
|
+
);
|
|
197
|
+
if (!cropped.ok) return `the 封面 crop dialog never appeared: ${cropped.error}`;
|
|
198
|
+
const cleared = await expectOutcome(
|
|
199
|
+
async () => ((await page.locator('text=请上传封面').count()) === 0 ? 'cover accepted' : null),
|
|
200
|
+
stepTimeoutMs,
|
|
201
|
+
'音频 封面 validation',
|
|
202
|
+
);
|
|
203
|
+
if (!cleared.ok) return `the 封面 was uploaded but the form still reports 「请上传封面」: ${cleared.error}`;
|
|
204
|
+
return null;
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
/** Open the 合集 picker, click the exact collection, and verify the row reads it back. */
|
|
208
|
+
export async function selectAudioCollection(
|
|
209
|
+
page: Page,
|
|
210
|
+
collection: string,
|
|
211
|
+
stepTimeoutMs: number,
|
|
212
|
+
): Promise<string | null> {
|
|
213
|
+
const picker = page.locator('div.display-text:has-text("选择合集")').first();
|
|
214
|
+
if ((await picker.count()) === 0) return '合集 picker (选择合集) not found on the audio form';
|
|
215
|
+
await picker.scrollIntoViewIfNeeded();
|
|
216
|
+
// The same node keeps the selection — only its text changes to the collection name — so hold it;
|
|
217
|
+
// a text re-query for 选择合集 would resolve to nothing after the click.
|
|
218
|
+
const row = await picker.elementHandle();
|
|
219
|
+
await picker.click({ timeout: stepTimeoutMs });
|
|
220
|
+
await page.waitForTimeout(2_000);
|
|
221
|
+
// Exact text only: the 标题 input carries "每日AI乱炖 · 2026-11-15", so a substring match would
|
|
222
|
+
// click our own title instead of the collection option.
|
|
223
|
+
const option = page.getByText(collection, { exact: true });
|
|
224
|
+
if ((await option.count()) === 0) return `合集 '${collection}' is not among this account's 音频 collections`;
|
|
225
|
+
await option.last().click({ timeout: stepTimeoutMs });
|
|
226
|
+
const readback = await expectOutcome(
|
|
227
|
+
async () => {
|
|
228
|
+
const text = ((await row?.textContent()) ?? '').trim();
|
|
229
|
+
return text.includes(collection) ? text : null;
|
|
230
|
+
},
|
|
231
|
+
stepTimeoutMs,
|
|
232
|
+
'合集 readback',
|
|
233
|
+
);
|
|
234
|
+
if (!readback.ok) return `合集 '${collection}' was clicked but the form does not show it: ${readback.error}`;
|
|
235
|
+
return null;
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
/**
|
|
239
|
+
* How many rows in 音频管理 carry `title`. The list is a div grid (no `<tr>`), so this counts the
|
|
240
|
+
* title text nodes; a re-publish of the same title raises the count, which is what the fresh-row
|
|
241
|
+
* contract needs.
|
|
242
|
+
*/
|
|
243
|
+
export async function countAudioRows(page: Page, title: string): Promise<number> {
|
|
244
|
+
try {
|
|
245
|
+
return await page.getByText(title, { exact: false }).count();
|
|
246
|
+
} catch {
|
|
247
|
+
return 0;
|
|
248
|
+
}
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
/**
|
|
252
|
+
* Run the audio post. Returns a `Result` — `ok: true` only when the audio list carries the new row.
|
|
253
|
+
*/
|
|
254
|
+
export async function runAudioPostFlow(input: AudioFlowInput): Promise<Result> {
|
|
255
|
+
const { collection, publishPublic, operation, profileDir } = input;
|
|
256
|
+
const metadata: Record<string, unknown> = {
|
|
257
|
+
operation,
|
|
258
|
+
driver: 'script',
|
|
259
|
+
publishStatus: publishPublic ? 'public' : 'draft',
|
|
260
|
+
profileDir,
|
|
261
|
+
...(collection !== undefined ? { collection } : {}),
|
|
262
|
+
};
|
|
263
|
+
// 发表音频 is the only submit rail on this surface: a draft request cannot be honoured.
|
|
264
|
+
if (!publishPublic) {
|
|
265
|
+
return stageFail(
|
|
266
|
+
'shipinhao 音频 has no draft rail — the 发表音频 form offers only 发表音频 (no 保存草稿); request publishStatus: public or publish nothing',
|
|
267
|
+
'draft-unsupported',
|
|
268
|
+
metadata,
|
|
269
|
+
);
|
|
270
|
+
}
|
|
271
|
+
// 封面 is MANDATORY on the audio form: submitting without one fails client-side validation with
|
|
272
|
+
// 「请上传封面」 and silently produces no works row (live recon 2026-11-16 — this is what made every
|
|
273
|
+
// audio publish end `uncertain`). The refusal is pre-browser; a supplied cover is attached through
|
|
274
|
+
// the form's own crop dialog inside pendingAudioFlow.
|
|
275
|
+
if (input.coverPath === undefined) {
|
|
276
|
+
return stageFail(
|
|
277
|
+
'shipinhao 音频 requires a cover (封面) — the form refuses to submit without one (「请上传封面」); pass coverPath',
|
|
278
|
+
'audio-cover',
|
|
279
|
+
metadata,
|
|
280
|
+
);
|
|
281
|
+
}
|
|
282
|
+
return pendingAudioFlow(input, metadata);
|
|
283
|
+
}
|
|
284
|
+
|
|
285
|
+
/**
|
|
286
|
+
* The recon-grounded steps: open 音频管理 → 发表音频, upload, 标题/描述, 封面 (crop dialog 确认),
|
|
287
|
+
* 合集 by exact text, submit, then the fresh-row receipt. Exported for the stage tests, which drive
|
|
288
|
+
* the steps against a fake page.
|
|
289
|
+
*/
|
|
290
|
+
export async function pendingAudioFlow(input: AudioFlowInput, metadata: Record<string, unknown>): Promise<Result> {
|
|
291
|
+
const { page, title, body, tags, media, collection, profileDir, stepTimeoutMs } = input;
|
|
292
|
+
const audio = media[0];
|
|
293
|
+
if (audio === undefined) return stageFail('shipinhao 音频 requires one audio file', 'media', metadata);
|
|
294
|
+
|
|
295
|
+
const opened = await openAudioCreate(page, stepTimeoutMs);
|
|
296
|
+
if (opened !== null) return stageFail(opened, 'audio-open', metadata);
|
|
297
|
+
|
|
298
|
+
const attached = await attachAudio(page, audio, stepTimeoutMs);
|
|
299
|
+
if (attached !== null) return stageFail(attached, 'audio-upload', metadata);
|
|
300
|
+
|
|
301
|
+
const clipped = clipAudioTitle(title);
|
|
302
|
+
const description = buildAudioDescription(body, tags);
|
|
303
|
+
const titleInput = page.locator('input[placeholder="请填写标题"]').first();
|
|
304
|
+
if ((await titleInput.count()) === 0) return stageFail('音频 标题 input not found', 'audio-title', metadata);
|
|
305
|
+
await titleInput.fill(clipped);
|
|
306
|
+
const titleOk = await expectOutcome(
|
|
307
|
+
async () => ((await titleInput.inputValue()) === clipped ? 'title retained' : null),
|
|
308
|
+
stepTimeoutMs,
|
|
309
|
+
'音频 标题 readback',
|
|
310
|
+
);
|
|
311
|
+
if (!titleOk.ok) return stageFail(`音频 标题 readback failed: ${titleOk.error}`, 'audio-title', metadata);
|
|
312
|
+
|
|
313
|
+
const descriptionBox = page.locator('textarea[placeholder="请填写描述"]').first();
|
|
314
|
+
if ((await descriptionBox.count()) === 0)
|
|
315
|
+
return stageFail('音频 描述 textarea not found', 'audio-description', metadata);
|
|
316
|
+
await descriptionBox.fill(description);
|
|
317
|
+
const descriptionOk = await expectOutcome(
|
|
318
|
+
async () => ((await descriptionBox.inputValue()).length > 0 ? 'description retained' : null),
|
|
319
|
+
stepTimeoutMs,
|
|
320
|
+
'音频 描述 readback',
|
|
321
|
+
);
|
|
322
|
+
if (!descriptionOk.ok) {
|
|
323
|
+
return stageFail(`音频 描述 readback failed: ${descriptionOk.error}`, 'audio-description', metadata);
|
|
324
|
+
}
|
|
325
|
+
|
|
326
|
+
const coverPath = input.coverPath;
|
|
327
|
+
if (coverPath !== undefined) {
|
|
328
|
+
const cover = await attachAudioCover(page, coverPath, stepTimeoutMs);
|
|
329
|
+
if (cover !== null) return stageFail(cover, 'audio-cover', metadata);
|
|
330
|
+
}
|
|
331
|
+
|
|
332
|
+
if (collection !== undefined) {
|
|
333
|
+
const selected = await selectAudioCollection(page, collection, stepTimeoutMs);
|
|
334
|
+
if (selected !== null) return stageFail(selected, 'collection-select', metadata);
|
|
335
|
+
} else {
|
|
336
|
+
// Absence is explicit: 不加合集 is the form's default, and a post must never inherit a
|
|
337
|
+
// previously chosen collection silently.
|
|
338
|
+
const readback = await page.locator('div.display-text:has-text("选择合集")').count();
|
|
339
|
+
if (readback === 0) {
|
|
340
|
+
return stageFail('合集 row missing before submit', 'collection-select', metadata);
|
|
341
|
+
}
|
|
342
|
+
}
|
|
343
|
+
|
|
344
|
+
// Fresh-row contract: record how many 音频 rows already carry this title, submit, then require
|
|
345
|
+
// the count to INCREASE. A count that only holds steady means the submit restored an existing
|
|
346
|
+
// row, never that it published ours (the video rail's fresh-receipt rule, restated for a list).
|
|
347
|
+
const baseline = await countAudioRows(page, clipped);
|
|
348
|
+
|
|
349
|
+
const submit = page.locator('button:has-text("发表音频")').first();
|
|
350
|
+
if ((await submit.count()) === 0) return stageFail('发表音频 submit control not found', 'audio-submit', metadata);
|
|
351
|
+
if (await submit.isDisabled()) return stageFail('发表音频 submit control is disabled', 'audio-submit', metadata);
|
|
352
|
+
await submit.click({ timeout: stepTimeoutMs });
|
|
353
|
+
|
|
354
|
+
// Some submissions raise a confirmation; click it once when it appears.
|
|
355
|
+
await page.waitForTimeout(3_000);
|
|
356
|
+
for (const label of ['确认发表', '确定']) {
|
|
357
|
+
const confirm = page.locator(`button:text-is("${label}")`).first();
|
|
358
|
+
if ((await confirm.count()) > 0 && (await confirm.isVisible().catch(() => false))) {
|
|
359
|
+
await confirm.click({ timeout: 5_000 }).catch(() => {});
|
|
360
|
+
break;
|
|
361
|
+
}
|
|
362
|
+
}
|
|
363
|
+
|
|
364
|
+
// Receipt: the 音频 list row. The site returns to /platform/post/audioManager and renders the
|
|
365
|
+
// new row there; the table is div-based, so the row is found by its title text, never by `tr`.
|
|
366
|
+
const receipt = await expectOutcome(
|
|
367
|
+
async () => {
|
|
368
|
+
if (!page.url().includes(SHP_AUDIO_MANAGER_PATH)) return null;
|
|
369
|
+
const count = await countAudioRows(page, clipped);
|
|
370
|
+
if (count <= baseline) return null;
|
|
371
|
+
return { url: page.url(), rows: count };
|
|
372
|
+
},
|
|
373
|
+
// The site's own list pagination settles in well under a minute; the submit click already
|
|
374
|
+
// proved the form accepted the post, so a longer wait only delays a truthful `unknown`.
|
|
375
|
+
receiptBudgetMs ?? SHP_AUDIO_RECEIPT_MS,
|
|
376
|
+
'音频 list row',
|
|
377
|
+
);
|
|
378
|
+
if (!receipt.ok) {
|
|
379
|
+
return stageFail(
|
|
380
|
+
'shipinhao 音频 publish-receipt not confirmed — 发表音频 was clicked but no new row carrying the title appeared in 音频管理; a submit without a works row is unknown and is never reported as published',
|
|
381
|
+
'audio-receipt',
|
|
382
|
+
metadata,
|
|
383
|
+
receipt.error,
|
|
384
|
+
);
|
|
385
|
+
}
|
|
386
|
+
return ResultSchema.parse({
|
|
387
|
+
ok: true,
|
|
388
|
+
target: SHP_TARGET,
|
|
389
|
+
url: receipt.evidence.url,
|
|
390
|
+
message: `shipinhao audio published and confirmed in the 音频 list (${profileDir})`,
|
|
391
|
+
metadata: { ...metadata, confirmedBy: 'audio-list-row', rowsWithTitle: receipt.evidence.rows },
|
|
392
|
+
});
|
|
393
|
+
}
|