@gobing-ai/knowledge-kit 0.1.20 → 0.1.23
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.claude-plugin/marketplace.json +1 -1
- package/dist/board/collect/index.js +1 -0
- package/dist/board/daily-voice/index.js +1279 -261
- package/dist/board/itc/index.js +1 -0
- package/dist/index.js +13938 -8966
- package/package.json +1 -1
- package/plugins/generations/dailynews-gen/dist/index.js +285 -16
- package/plugins/generations/dailynews-gen/src/editorial-claims.ts +215 -0
- package/plugins/generations/dailynews-gen/src/index.ts +23 -4
- package/plugins/generations/dailynews-gen/src/script-builder.ts +10 -3
- package/plugins/generations/dailynews-gen/src/script-plan.ts +74 -14
- package/plugins/generations/gemini-tts/dist/index.js +47 -7
- package/plugins/generations/gemini-tts/src/gemini-client.ts +34 -6
- package/plugins/generations/music-gen/README.md +277 -0
- package/plugins/generations/music-gen/dist/index.js +23580 -0
- package/plugins/generations/music-gen/package.json +24 -0
- package/plugins/generations/music-gen/plugin.json +23 -0
- package/plugins/generations/music-gen/presets/SOURCE.md +39 -0
- package/plugins/generations/music-gen/presets/formats/clip.yaml +21 -0
- package/plugins/generations/music-gen/presets/formats/jingle.yaml +22 -0
- package/plugins/generations/music-gen/presets/formats/loop.yaml +21 -0
- package/plugins/generations/music-gen/presets/formats/song.yaml +36 -0
- package/plugins/generations/music-gen/presets/formats/underscore.yaml +22 -0
- package/plugins/generations/music-gen/presets/themes/ambient-tech.yaml +30 -0
- package/plugins/generations/music-gen/presets/themes/cinematic.yaml +30 -0
- package/plugins/generations/music-gen/presets/themes/lofi.yaml +30 -0
- package/plugins/generations/music-gen/presets/themes/synthwave.yaml +35 -0
- package/plugins/generations/music-gen/scripts/gen-preset-index.ts +181 -0
- package/plugins/generations/music-gen/scripts/resolve-preset.ts +64 -0
- package/plugins/generations/music-gen/src/adapter/index.ts +35 -0
- package/plugins/generations/music-gen/src/adapter/instance.ts +927 -0
- package/plugins/generations/music-gen/src/adapter/offline.ts +124 -0
- package/plugins/generations/music-gen/src/artifact.ts +223 -0
- package/plugins/generations/music-gen/src/audio/checks.ts +618 -0
- package/plugins/generations/music-gen/src/audio/master.ts +267 -0
- package/plugins/generations/music-gen/src/audio/measure.ts +507 -0
- package/plugins/generations/music-gen/src/audio/profile.ts +131 -0
- package/plugins/generations/music-gen/src/audio.ts +122 -0
- package/plugins/generations/music-gen/src/brief.ts +191 -0
- package/plugins/generations/music-gen/src/config.ts +451 -0
- package/plugins/generations/music-gen/src/content.ts +199 -0
- package/plugins/generations/music-gen/src/digest.ts +100 -0
- package/plugins/generations/music-gen/src/index.ts +147 -0
- package/plugins/generations/music-gen/src/job.ts +131 -0
- package/plugins/generations/music-gen/src/plugin.ts +371 -0
- package/plugins/generations/music-gen/src/presets.ts +951 -0
- package/plugins/generations/music-gen/src/render.ts +87 -0
- package/plugins/generations/music-gen/src/request.ts +102 -0
- package/plugins/generations/music-gen/src/spend.ts +495 -0
- package/plugins/generations/music-gen/tsconfig.json +8 -0
- package/plugins/generations/omni-voice-gen/uv.toml +5 -0
- package/plugins/generations/vibe-voice-tts/README.md +64 -0
- package/plugins/generations/vibe-voice-tts/dist/index.js +14259 -0
- package/plugins/generations/vibe-voice-tts/package.json +16 -0
- package/plugins/generations/vibe-voice-tts/plugin.json +6 -0
- package/plugins/generations/vibe-voice-tts/profiles.json +10 -0
- package/plugins/generations/vibe-voice-tts/pyproject.toml +9 -0
- package/plugins/generations/vibe-voice-tts/python/worker.py +566 -0
- package/plugins/generations/vibe-voice-tts/src/index.ts +88 -0
- package/plugins/generations/vibe-voice-tts/src/vibevoice-client.ts +828 -0
- package/plugins/generations/vibe-voice-tts/tsconfig.json +8 -0
- package/plugins/generations/vibe-voice-tts/uv.lock +1767 -0
- package/plugins/generations/vibe-voice-tts/uv.toml +4 -0
- package/plugins/generations/voice-gen/dist/index.js +31 -1
- package/plugins/generations/voice-gen/src/voicebox-client.ts +50 -1
- package/plugins/generations/voxcpm-tts/dist/index.js +81 -9
- package/plugins/generations/voxcpm-tts/python/worker.py +9 -0
- package/plugins/generations/voxcpm-tts/src/index.ts +41 -0
- package/plugins/generations/voxcpm-tts/src/voxcpm-client.ts +32 -11
- package/plugins/generations/voxcpm-tts/uv.toml +5 -0
- package/plugins/kk/README.md +21 -0
- package/plugins/kk/decisions/kk-safety.yaml +5 -2
- package/plugins/kk/plugin.json +1 -1
- package/plugins/kk/schedules/kk-serve.launchd.plist.tmpl +14 -2
- package/plugins/kk/scripts/cover-compositor.ts +380 -32
- package/plugins/kk/scripts/daily-cover-mock.ts +40 -3
- package/plugins/kk/scripts/daily-stages.ts +933 -60
- package/plugins/kk/scripts/episode-identity.ts +180 -0
- package/plugins/kk/scripts/kk-workflow-stages.ts +111 -12
- package/plugins/kk/scripts/music-stages.ts +624 -0
- package/plugins/kk/scripts/news-editorial-ledger.ts +906 -0
- package/plugins/kk/scripts/safety-artifact-check.ts +28 -5
- package/plugins/kk/scripts/source-citation.ts +187 -0
- package/plugins/kk/scripts/topic-selection-attempts.ts +446 -0
- package/plugins/kk/scripts/topic-selection-calibration.ts +161 -0
- package/plugins/kk/skills/content-judge/SKILL.md +11 -6
- package/plugins/kk/skills/content-judge/references/music-quality-rubric.md +147 -0
- package/plugins/kk/skills/content-judge/references/rubrics.md +15 -0
- package/plugins/kk/skills/content-safety/SKILL.md +12 -0
- package/plugins/kk/skills/music-authoring/SKILL.md +276 -0
- package/plugins/kk/skills/music-authoring/references/judge-input.md +117 -0
- package/plugins/kk/skills/news-editorial/SKILL.md +102 -15
- package/plugins/kk/skills/news-editorial/references/selection.md +4 -0
- package/plugins/kk/skills/news-editorial/references/style-contract.zh.md +58 -11
- package/plugins/kk/workflows/kk-daily-ai-voice.yaml +12 -11
- package/plugins/kk/workflows/kk-daily-ai-voice2.yaml +13 -12
- package/plugins/kk/workflows/kk-daily-safety.yaml +12 -10
- package/plugins/kk/workflows/kk-music.yaml +332 -0
- package/plugins/kk/workflows/kk-news-generate.yaml +81 -6
- package/plugins/kk/workflows/kk-publish.yaml +4 -1
- package/plugins/publishings/bilibili-pub/dist/index.js +11 -1
- package/plugins/publishings/bilibili-pub/dist/profile-check.js +11 -1
- package/plugins/publishings/cnblogs-pub/dist/index.js +11 -1
- package/plugins/publishings/cnblogs-pub/dist/profile-check.js +11 -1
- package/plugins/publishings/csdn-pub/dist/index.js +11 -1
- package/plugins/publishings/csdn-pub/dist/profile-check.js +11 -1
- package/plugins/publishings/infoq-pub/dist/index.js +11 -1
- package/plugins/publishings/infoq-pub/dist/profile-check.js +11 -1
- package/plugins/publishings/jike-pub/dist/index.js +11 -1
- package/plugins/publishings/jike-pub/dist/profile-check.js +11 -1
- package/plugins/publishings/juejin-pub/dist/index.js +11 -1
- package/plugins/publishings/juejin-pub/dist/profile-check.js +11 -1
- package/plugins/publishings/linkedin-pub/dist/index.js +62 -10
- package/plugins/publishings/linkedin-pub/dist/profile-check.js +16 -1
- package/plugins/publishings/linkedin-pub/src/index.ts +99 -12
- package/plugins/publishings/podcast-pub/dist/index.js +586 -20
- package/plugins/publishings/podcast-pub/src/corrections.ts +509 -0
- package/plugins/publishings/podcast-pub/src/index.ts +257 -5
- package/plugins/publishings/podcast-pub/src/show-notes-brief.ts +240 -0
- package/plugins/publishings/podcast-pub/src/show-notes.ts +69 -13
- package/plugins/publishings/shipinhao-pub/dist/index.js +59 -8
- package/plugins/publishings/shipinhao-pub/dist/profile-check.js +11 -1
- package/plugins/publishings/shipinhao-pub/src/audio-flow.ts +105 -6
- package/plugins/publishings/sspai-pub/dist/index.js +11 -1
- package/plugins/publishings/sspai-pub/dist/profile-check.js +11 -1
- package/plugins/publishings/substack-pub/dist/index.js +11 -1
- package/plugins/publishings/substack-pub/dist/profile-check.js +11 -1
- package/plugins/publishings/surfdash-pub/dist/index.js +80 -24
- package/plugins/publishings/surfdash-pub/src/digest-check.ts +7 -3
- package/plugins/publishings/surfdash-pub/src/index.ts +107 -18
- package/plugins/publishings/surfdash-pub/src/patch.ts +21 -3
- package/plugins/publishings/surfdash-pub/src/topic-claims.ts +3 -1
- package/plugins/publishings/threads-pub/dist/index.js +58 -6
- package/plugins/publishings/threads-pub/dist/profile-check.js +18 -2
- package/plugins/publishings/threads-pub/src/post-rail.ts +101 -4
- package/plugins/publishings/wechatmp-pub/dist/index.js +105 -35
- package/plugins/publishings/wechatmp-pub/dist/profile-check.js +11 -1
- package/plugins/publishings/wechatmp-pub/src/cgi-draft.ts +87 -53
- package/plugins/publishings/wechatmp-pub/src/enrich.ts +61 -3
- package/plugins/publishings/wechatmp-pub/src/flow.ts +28 -0
- package/plugins/publishings/weibo-pub/dist/index.js +11 -1
- package/plugins/publishings/weibo-pub/dist/profile-check.js +11 -1
- package/plugins/publishings/x-pub/dist/index.js +95 -10
- package/plugins/publishings/x-pub/dist/profile-check.js +11 -1
- package/plugins/publishings/x-pub/src/post-rail.ts +154 -12
- package/plugins/publishings/xhs-pub/dist/index.js +11 -1
- package/plugins/publishings/xhs-pub/dist/profile-check.js +11 -1
- package/plugins/publishings/xiaoyuzhou-pub/dist/index.js +11 -1
- package/plugins/publishings/xiaoyuzhou-pub/dist/profile-check.js +11 -1
|
@@ -56,7 +56,17 @@ export const THREADS_POST_SELECTORS = {
|
|
|
56
56
|
'div[aria-label^="Empty text field"]',
|
|
57
57
|
'div[role="textbox"][contenteditable="true"]',
|
|
58
58
|
],
|
|
59
|
-
|
|
59
|
+
// Threads renders the label as a CHILD div inside the role=button element, so `text-is` on the
|
|
60
|
+
// button misses whenever the button carries more than the bare label (measured 2026-11-20: the
|
|
61
|
+
// element with text "Post" was `DIV < DIV[role=button]`, and every selector below found nothing).
|
|
62
|
+
// The `:has` shapes match either nesting; the direct forms stay for the plain surface.
|
|
63
|
+
submit: [
|
|
64
|
+
'div[role="button"]:has(> div:text-is("Post")):visible',
|
|
65
|
+
'div[role="button"]:has(div:text-is("Post")):visible',
|
|
66
|
+
'div[role="button"]:text-is("Post"):visible',
|
|
67
|
+
'button:text-is("Post"):visible',
|
|
68
|
+
'div[role="button"][aria-label="Post"]:visible',
|
|
69
|
+
],
|
|
60
70
|
mediaButton: ['div[role="button"]:text-is("Attach media")', 'div[aria-label*="Attach media" i]'],
|
|
61
71
|
fileInput: ['input[type="file"]'],
|
|
62
72
|
mediaPreview: ['div[role="dialog"] img[src*="cdninstagram"], div[role="dialog"] img[src*="fbcdn"]'],
|
|
@@ -270,7 +280,12 @@ export class ThreadsPostBrowserTransport implements PublishTransport {
|
|
|
270
280
|
const value = String(
|
|
271
281
|
await editor
|
|
272
282
|
.evaluate(
|
|
273
|
-
|
|
283
|
+
// Playwright hands the element to this expression as its first
|
|
284
|
+
// parameter. The arrow IIFE that read `arguments[0]` had no `arguments`
|
|
285
|
+
// binding at all, so it threw into the `.catch('')` below and every
|
|
286
|
+
// typed post read as "not retained" (measured 2026-11-20: the composer
|
|
287
|
+
// screenshot showed the full text and Post enabled).
|
|
288
|
+
`(el) => (el.innerText || el.textContent || el.value || '')`,
|
|
274
289
|
)
|
|
275
290
|
.catch(() => ''),
|
|
276
291
|
);
|
|
@@ -308,14 +323,96 @@ export class ThreadsPostBrowserTransport implements PublishTransport {
|
|
|
308
323
|
|
|
309
324
|
const submit = await expectOutcome(
|
|
310
325
|
async () => {
|
|
326
|
+
// Prefer the role engine: Threads puts the label in a CHILD div of a role=button, so a
|
|
327
|
+
// CSS `:text-is` on the parent only matches when the parent holds nothing else, and a
|
|
328
|
+
// selector the harness has to normalize can degrade to a bare `div[role="button"]`
|
|
329
|
+
// whose FIRST match is the composer's Cancel — which is exactly the "Save to drafts?"
|
|
330
|
+
// leave-guard observed on 2026-11-20. `getByRole` derives the accessible name from the
|
|
331
|
+
// child text, so it names the control the user sees.
|
|
332
|
+
const roleEngine = page as unknown as {
|
|
333
|
+
getByRole?: (
|
|
334
|
+
role: string,
|
|
335
|
+
options: { name: string; exact: boolean },
|
|
336
|
+
) => { count(): Promise<number> };
|
|
337
|
+
};
|
|
338
|
+
const byRole = roleEngine.getByRole?.('button', { name: 'Post', exact: true });
|
|
339
|
+
const roleCount = byRole === undefined ? 0 : await byRole.count().catch(() => 0);
|
|
340
|
+
if (roleCount > 0) return `role:Post:${roleCount}`;
|
|
311
341
|
const found = await trySelectors(page, THREADS_POST_SELECTORS.submit);
|
|
312
342
|
return found.found ? (found.selector ?? THREADS_POST_SELECTORS.submit[0]) : null;
|
|
313
343
|
},
|
|
314
344
|
{ timeoutMs: this.stepTimeoutMs, label: 'threads post submit' },
|
|
315
345
|
);
|
|
316
|
-
if (!submit.ok)
|
|
317
|
-
|
|
346
|
+
if (!submit.ok) {
|
|
347
|
+
// The composer's Post control is a styled div whose text Playwright's `:text-is` must
|
|
348
|
+
// match exactly; a label tweak ("Post" → "Post\u00a0" / an icon-only button) leaves the
|
|
349
|
+
// selector list matching nothing while the button is plainly on screen. Report the
|
|
350
|
+
// dialog's actual clickable inventory instead of the timeout.
|
|
351
|
+
await evidence(page, '06-submit-missing');
|
|
352
|
+
const observable = page as unknown as { evaluate?: (script: string) => Promise<unknown> };
|
|
353
|
+
const inventory = await (observable.evaluate === undefined
|
|
354
|
+
? Promise.resolve(null)
|
|
355
|
+
: observable
|
|
356
|
+
.evaluate(`(() => {
|
|
357
|
+
// Search the WHOLE document, not one dialog: the composer may not be the first
|
|
358
|
+
// [role=dialog] in DOM order (which is why an earlier inventory listed the
|
|
359
|
+
// composer's chips but not its Post control), and Post may carry no role at all.
|
|
360
|
+
const hits = [...document.querySelectorAll('*')]
|
|
361
|
+
.filter((n) => n.children.length === 0 && (n.textContent || '').trim() === 'Post')
|
|
362
|
+
.map((n) => {
|
|
363
|
+
const p = n.parentElement;
|
|
364
|
+
return n.tagName + (n.getAttribute('role') ? '[role=' + n.getAttribute('role') + ']' : '')
|
|
365
|
+
+ (n.getAttribute('aria-label') ? '[aria=' + n.getAttribute('aria-label') + ']' : '')
|
|
366
|
+
+ ' < ' + (p?.tagName ?? '') + (p?.getAttribute('role') ? '[role=' + p.getAttribute('role') + ']' : '')
|
|
367
|
+
+ (p?.className ? '.' + String(p.className).split(/\\s+/).slice(0, 2).join('.') : '');
|
|
368
|
+
});
|
|
369
|
+
return hits.slice(0, 4).join(' | ') || 'no element whose text is exactly Post';
|
|
370
|
+
})()`)
|
|
371
|
+
.catch(() => null));
|
|
372
|
+
return fail(
|
|
373
|
+
`threads post control never attached: ${submit.error}${inventory ? ` (dialog buttons: ${String(inventory)})` : ''}`,
|
|
374
|
+
);
|
|
375
|
+
}
|
|
376
|
+
// The composer rides under a suggestions layer that intercepts pointer events
|
|
377
|
+
// (`<div class="__fb-light-mode …"> intercepts pointer events`, measured 2026-11-20). A
|
|
378
|
+
// forced click dispatches onto that layer and posts NOTHING — the profile stayed unchanged —
|
|
379
|
+
// so dismiss the layer first and click for real. The force click remains as a fallback for a
|
|
380
|
+
// surface that reports a transient overlay.
|
|
381
|
+
const dismiss = await page
|
|
382
|
+
.locator(
|
|
383
|
+
'div[role="button"]:text-is("Dismiss suggestions"), div[role="button"]:has(> div:text-is("Dismiss suggestions"))',
|
|
384
|
+
)
|
|
385
|
+
.first()
|
|
386
|
+
.click({ timeout: 3_000 })
|
|
387
|
+
.then(() => true)
|
|
388
|
+
.catch(() => false);
|
|
389
|
+
if (dismiss) await page.waitForTimeout(500);
|
|
390
|
+
const submitEvidence = String(submit.evidence);
|
|
391
|
+
if (submitEvidence.startsWith('role:Post:')) {
|
|
392
|
+
// The composer's Post is the LAST match (the feed's inline composer sits behind it).
|
|
393
|
+
const rolePost = (
|
|
394
|
+
page as unknown as {
|
|
395
|
+
getByRole: (
|
|
396
|
+
role: string,
|
|
397
|
+
options: { name: string; exact: boolean },
|
|
398
|
+
) => {
|
|
399
|
+
last(): { click(options: { timeout: number }): Promise<unknown> };
|
|
400
|
+
};
|
|
401
|
+
}
|
|
402
|
+
).getByRole('button', { name: 'Post', exact: true });
|
|
403
|
+
await rolePost.last().click({ timeout: this.stepTimeoutMs });
|
|
404
|
+
} else {
|
|
405
|
+
await page
|
|
406
|
+
.locator(submitEvidence)
|
|
407
|
+
.first()
|
|
408
|
+
.click({ timeout: this.stepTimeoutMs })
|
|
409
|
+
.catch(async () => {
|
|
410
|
+
await page.locator(submitEvidence).first().click({ force: true });
|
|
411
|
+
});
|
|
412
|
+
}
|
|
318
413
|
|
|
414
|
+
await page.waitForTimeout(2_500);
|
|
415
|
+
await evidence(page, '07-post-clicked');
|
|
319
416
|
const receipt = await expectOutcome(
|
|
320
417
|
async () => {
|
|
321
418
|
const id = await this.newestPostId(page, handle);
|
|
@@ -20810,6 +20810,9 @@ var MAX_QUEUED_BYTES = 8 * 1024 * 1024;
|
|
|
20810
20810
|
var DEFAULT_LOGIN_TIMEOUT_MS = 180000;
|
|
20811
20811
|
var DEFAULT_OPEN_NAV_TIMEOUT_MS = 30000;
|
|
20812
20812
|
var DEFAULT_CHECK_TIMEOUT_MS = 30000;
|
|
20813
|
+
var VERDICT_PRINT_MARGIN_MS = 2000;
|
|
20814
|
+
var MIN_PASS_BUDGET_MS = 5000;
|
|
20815
|
+
var PASS_LAUNCH_RESERVE_MS = 20000;
|
|
20813
20816
|
var DEFAULT_STEP_TIMEOUT_MS = 30000;
|
|
20814
20817
|
var DEFAULT_POLL_MS = 500;
|
|
20815
20818
|
var ATTACH_POLL_MS = 100;
|
|
@@ -20934,14 +20937,21 @@ async function checkChannelSession(config, opts) {
|
|
|
20934
20937
|
const timeoutMs = opts.timeoutMs ?? DEFAULT_CHECK_TIMEOUT_MS;
|
|
20935
20938
|
const passes = opts.headedOnly ? [false] : opts.headedFallback === false ? [true] : [true, false];
|
|
20936
20939
|
let lastDetail = `${config.channel} readiness was never probed`;
|
|
20940
|
+
const deadline = Date.now() + timeoutMs;
|
|
20941
|
+
const printMarginMs = Math.min(VERDICT_PRINT_MARGIN_MS, Math.floor(timeoutMs / 4));
|
|
20942
|
+
const minPassMs = Math.min(MIN_PASS_BUDGET_MS, Math.floor(timeoutMs / 3));
|
|
20943
|
+
const launchReserveMs = Math.min(PASS_LAUNCH_RESERVE_MS, Math.floor(timeoutMs / 3));
|
|
20937
20944
|
for (const headless of passes) {
|
|
20945
|
+
const remainingMs = deadline - Date.now() - printMarginMs - launchReserveMs;
|
|
20946
|
+
if (remainingMs < minPassMs)
|
|
20947
|
+
break;
|
|
20938
20948
|
try {
|
|
20939
20949
|
await withProfilePage({
|
|
20940
20950
|
profileDir: opts.profileDir,
|
|
20941
20951
|
headless,
|
|
20942
20952
|
url: config.homeUrl,
|
|
20943
20953
|
isAuthenticated: config.isAuthenticated,
|
|
20944
|
-
timeoutMs,
|
|
20954
|
+
timeoutMs: remainingMs,
|
|
20945
20955
|
launcher: opts.launcher ?? kkBrowserLauncher
|
|
20946
20956
|
}, async () => true);
|
|
20947
20957
|
return {
|
|
@@ -22130,9 +22140,49 @@ async function evaluateCgiVerdict(page, expression) {
|
|
|
22130
22140
|
function ambiguousSubmission(stage, detail) {
|
|
22131
22141
|
return new WechatCgiDraftError("ambiguous-submission", stage, detail, { ambiguousSubmission: true });
|
|
22132
22142
|
}
|
|
22143
|
+
async function readDraftList(page, session, stage) {
|
|
22144
|
+
const listUrl = buildUrl2(APPMSG_URL, {
|
|
22145
|
+
action: "list_ex",
|
|
22146
|
+
begin: "0",
|
|
22147
|
+
count: "5",
|
|
22148
|
+
token: session.token,
|
|
22149
|
+
lang: "zh_CN",
|
|
22150
|
+
f: "json"
|
|
22151
|
+
});
|
|
22152
|
+
let listVerdict;
|
|
22153
|
+
try {
|
|
22154
|
+
listVerdict = await evaluateCgiVerdict(page, cgiFetchExpression2({
|
|
22155
|
+
url: listUrl,
|
|
22156
|
+
method: "GET",
|
|
22157
|
+
fields: {},
|
|
22158
|
+
maxBytes: MAX_RESPONSE_BYTES2,
|
|
22159
|
+
timeoutMs: REQUEST_TIMEOUT_MS2
|
|
22160
|
+
}));
|
|
22161
|
+
} catch (error) {
|
|
22162
|
+
throw new WechatCgiDraftError("readback-failed", stage, `draft list readback ended before a receipt returned: ${stripQuery2(String(error))}`);
|
|
22163
|
+
}
|
|
22164
|
+
if (listVerdict?.kind !== "ok") {
|
|
22165
|
+
const detail = listVerdict?.kind === "http-status" ? `HTTP ${listVerdict.status}` : listVerdict?.kind === "too-large" ? `${MAX_RESPONSE_BYTES2}-byte bound exceeded` : listVerdict?.kind === "error" ? stripQuery2(listVerdict.detail) : "page returned no usable verdict";
|
|
22166
|
+
throw new WechatCgiDraftError("readback-failed", stage, `draft list readback failed: ${detail}`);
|
|
22167
|
+
}
|
|
22168
|
+
let list;
|
|
22169
|
+
try {
|
|
22170
|
+
list = JSON.parse(listVerdict.text);
|
|
22171
|
+
} catch {
|
|
22172
|
+
throw new WechatCgiDraftError("readback-failed", stage, "draft list receipt is not JSON");
|
|
22173
|
+
}
|
|
22174
|
+
return isRecord2(list) && Array.isArray(list.app_msg_list) ? list.app_msg_list.filter((item) => isRecord2(item)) : [];
|
|
22175
|
+
}
|
|
22176
|
+
function duplicateDraft(existing, title) {
|
|
22177
|
+
const id = existing.app_id !== undefined ? existing.app_id : existing.appmsgid;
|
|
22178
|
+
return new WechatCgiDraftError("duplicate-draft", "pre-create-lookup", `duplicate-draft: appmsgid ${String(id)} already holds "${title}" \u2014 delete it or finish it in the console`);
|
|
22179
|
+
}
|
|
22133
22180
|
async function createWechatArticleDraft(page, session, content, media) {
|
|
22134
|
-
|
|
22181
|
+
const certified = certifyCgiDraft(content);
|
|
22135
22182
|
assertMpOrigin2(page);
|
|
22183
|
+
const existing = (await readDraftList(page, session, "pre-create-lookup")).find((item) => item.title === certified.title);
|
|
22184
|
+
if (existing !== undefined)
|
|
22185
|
+
throw duplicateDraft(existing, certified.title);
|
|
22136
22186
|
const payload = buildCreateArticlePayload(session, content, media);
|
|
22137
22187
|
let createVerdict;
|
|
22138
22188
|
try {
|
|
@@ -22174,38 +22224,8 @@ async function createWechatArticleDraft(page, session, content, media) {
|
|
|
22174
22224
|
if (appMsgId === undefined || !/^-?\d{1,12}$/.test(appMsgId)) {
|
|
22175
22225
|
throw ambiguousSubmission("create-receipt", "create receipt did not return a safe numeric appMsgId");
|
|
22176
22226
|
}
|
|
22177
|
-
const
|
|
22178
|
-
|
|
22179
|
-
begin: "0",
|
|
22180
|
-
count: "5",
|
|
22181
|
-
token: session.token,
|
|
22182
|
-
lang: "zh_CN",
|
|
22183
|
-
f: "json"
|
|
22184
|
-
});
|
|
22185
|
-
let listVerdict;
|
|
22186
|
-
try {
|
|
22187
|
-
listVerdict = await evaluateCgiVerdict(page, cgiFetchExpression2({
|
|
22188
|
-
url: listUrl,
|
|
22189
|
-
method: "GET",
|
|
22190
|
-
fields: {},
|
|
22191
|
-
maxBytes: MAX_RESPONSE_BYTES2,
|
|
22192
|
-
timeoutMs: REQUEST_TIMEOUT_MS2
|
|
22193
|
-
}));
|
|
22194
|
-
} catch (error) {
|
|
22195
|
-
throw new WechatCgiDraftError("readback-failed", "readback", `draft list readback ended before a receipt returned: ${stripQuery2(String(error))}`);
|
|
22196
|
-
}
|
|
22197
|
-
if (listVerdict?.kind !== "ok") {
|
|
22198
|
-
const detail = listVerdict?.kind === "http-status" ? `HTTP ${listVerdict.status}` : listVerdict?.kind === "too-large" ? `${MAX_RESPONSE_BYTES2}-byte bound exceeded` : listVerdict?.kind === "error" ? stripQuery2(listVerdict.detail) : "page returned no usable verdict";
|
|
22199
|
-
throw new WechatCgiDraftError("readback-failed", "readback", `draft list readback failed: ${detail}`);
|
|
22200
|
-
}
|
|
22201
|
-
let list;
|
|
22202
|
-
try {
|
|
22203
|
-
list = JSON.parse(listVerdict.text);
|
|
22204
|
-
} catch {
|
|
22205
|
-
throw new WechatCgiDraftError("readback-failed", "readback", "draft list receipt is not JSON");
|
|
22206
|
-
}
|
|
22207
|
-
const items = isRecord2(list) && Array.isArray(list.app_msg_list) ? list.app_msg_list : [];
|
|
22208
|
-
const confirmed = items.some((item) => isRecord2(item) && item.title === content.title && (String(item.app_id) === appMsgId || String(item.appmsgid) === appMsgId));
|
|
22227
|
+
const items = await readDraftList(page, session, "readback");
|
|
22228
|
+
const confirmed = items.some((item) => item.title === content.title && (String(item.app_id) === appMsgId || String(item.appmsgid) === appMsgId));
|
|
22209
22229
|
if (!confirmed) {
|
|
22210
22230
|
throw new WechatCgiDraftError("readback-failed", "readback", "draft list did not confirm an item matching the created appMsgId and title");
|
|
22211
22231
|
}
|
|
@@ -22744,6 +22764,40 @@ var CLAIM_COMMITTED = `(() => {
|
|
|
22744
22764
|
const enabled = checkbox ? checkbox.checked === true : null;
|
|
22745
22765
|
return { enabled, text };
|
|
22746
22766
|
})()`;
|
|
22767
|
+
var REWARD_STATE = `(() => {
|
|
22768
|
+
const rows = [
|
|
22769
|
+
document.querySelector('.js_reward_allow_click'),
|
|
22770
|
+
document.querySelector('.js_reward_open'),
|
|
22771
|
+
document.querySelector('.setting-group__switch.js_reward_open'),
|
|
22772
|
+
].filter((el) => el !== null);
|
|
22773
|
+
if (rows.length === 0) return null;
|
|
22774
|
+
const blockedText = /\u65E0\u6CD5\u5F00\u542F\u8D5E\u8D4F|\u8FD8\u6CA1\u6709\u8D5E\u8D4F\u8D26\u6237|\u524D\u5F80\u5F00\u901A|\u672A\u5F00\u901A/;
|
|
22775
|
+
for (const el of rows) {
|
|
22776
|
+
const text = (el.textContent ?? '').replace(/\\s+/g, ' ').trim();
|
|
22777
|
+
const box = el.getBoundingClientRect();
|
|
22778
|
+
if (blockedText.test(text) || (box.width === 0 && box.height === 0)) {
|
|
22779
|
+
return { clickable: false, blocked: true, text: text.slice(0, 200) };
|
|
22780
|
+
}
|
|
22781
|
+
}
|
|
22782
|
+
return { clickable: true, blocked: false, text: '' };
|
|
22783
|
+
})()`;
|
|
22784
|
+
async function readRewardState(page) {
|
|
22785
|
+
try {
|
|
22786
|
+
const raw = await page.evaluate(REWARD_STATE);
|
|
22787
|
+
if (typeof raw !== "object" || raw === null)
|
|
22788
|
+
return null;
|
|
22789
|
+
const value = raw;
|
|
22790
|
+
if (typeof value.clickable !== "boolean" || typeof value.blocked !== "boolean")
|
|
22791
|
+
return null;
|
|
22792
|
+
return {
|
|
22793
|
+
clickable: value.clickable,
|
|
22794
|
+
blocked: value.blocked,
|
|
22795
|
+
text: typeof value.text === "string" ? value.text : ""
|
|
22796
|
+
};
|
|
22797
|
+
} catch {
|
|
22798
|
+
return null;
|
|
22799
|
+
}
|
|
22800
|
+
}
|
|
22747
22801
|
async function readChecked(page, expression) {
|
|
22748
22802
|
try {
|
|
22749
22803
|
const raw = await page.evaluate(expression);
|
|
@@ -22838,6 +22892,10 @@ async function enrichArticle(page, meta) {
|
|
|
22838
22892
|
const name = "\u8D5E\u8D4F";
|
|
22839
22893
|
if (await readChecked(page, COMMITTED.reward) !== true) {
|
|
22840
22894
|
const outcome = await step(name, async () => {
|
|
22895
|
+
const state = await readRewardState(page);
|
|
22896
|
+
if (state?.blocked === true) {
|
|
22897
|
+
throw new CapabilityError(`\u9700\u8981\u8D5E\u8D4F\u8D26\u6237\uFF08\u672C\u516C\u4F17\u53F7\u672A\u88AB\u6388\u6743\uFF0C\u5E73\u53F0\u539F\u6587\uFF1A${state.text === "" ? "\u65E0\u6CD5\u5F00\u542F\u8D5E\u8D4F" : state.text}\uFF09\u2014 \u8FD0\u8425\u8005\u5728\u5E73\u53F0\u5F00\u901A\u540E\u91CD\u8DD1\uFF0C\u672C\u6B21\u4E0D\u8BF7\u6C42\u8BE5\u5B57\u6BB5`);
|
|
22898
|
+
}
|
|
22841
22899
|
await openRow(ROW_REWARD, "\u8D5E\u8D4F");
|
|
22842
22900
|
const blocked = await tryFindSelector(page, [`${DIALOG} :has-text("\u524D\u5F80\u5F00\u901A")`, `${DIALOG} :has-text("\u65E0\u6CD5\u5F00\u542F")`], 1500);
|
|
22843
22901
|
if (blocked !== undefined)
|
|
@@ -24531,7 +24589,8 @@ async function runCgiDraft(input, deps) {
|
|
|
24531
24589
|
operation: input.operation,
|
|
24532
24590
|
publishStatus: deps.publishStatus,
|
|
24533
24591
|
stage: error.stage,
|
|
24534
|
-
...error.metadata.ambiguousSubmission === true ? { ambiguousSubmission: true } : {}
|
|
24592
|
+
...error.metadata.ambiguousSubmission === true ? { ambiguousSubmission: true } : {},
|
|
24593
|
+
...error.code === "duplicate-draft" ? { itcDelivery: { schemaVersion: 1, effect: "none" } } : {}
|
|
24535
24594
|
}
|
|
24536
24595
|
});
|
|
24537
24596
|
}
|
|
@@ -24791,6 +24850,17 @@ async function insertAudioMaterial(page, input) {
|
|
|
24791
24850
|
closed = await waitUntil(async () => !await page.locator(chooser).first().isVisible(), 1e4);
|
|
24792
24851
|
}
|
|
24793
24852
|
}
|
|
24853
|
+
if (!closed) {
|
|
24854
|
+
const pickerClose = await tryFindSelector(page, [
|
|
24855
|
+
`${chooser} .weui-desktop-dialog__close-btn`,
|
|
24856
|
+
`${chooser} .weui-desktop-dialog__close`,
|
|
24857
|
+
`${chooser} button:has-text("\u53D6\u6D88")`
|
|
24858
|
+
], 3000);
|
|
24859
|
+
if (pickerClose !== undefined) {
|
|
24860
|
+
await clickSelector(page, pickerClose, 3000);
|
|
24861
|
+
closed = await waitUntil(async () => !await page.locator(chooser).first().isVisible(), 1e4);
|
|
24862
|
+
}
|
|
24863
|
+
}
|
|
24794
24864
|
if (!closed) {
|
|
24795
24865
|
const inventory = await openDialogInventory(page);
|
|
24796
24866
|
return result(`\u97F3\u9891: \u5C01\u9762\u9009\u62E9\u5668\u5B8C\u6210\u540E\u672A\u5173\u95ED\uFF0C\u672A\u4FDD\u5B58\u97F3\u9891${inventory ? ` (dialogs: ${inventory})` : ""}`);
|
|
@@ -20473,6 +20473,9 @@ var MAX_QUEUED_BYTES = 8 * 1024 * 1024;
|
|
|
20473
20473
|
var DEFAULT_LOGIN_TIMEOUT_MS = 180000;
|
|
20474
20474
|
var DEFAULT_OPEN_NAV_TIMEOUT_MS = 30000;
|
|
20475
20475
|
var DEFAULT_CHECK_TIMEOUT_MS = 30000;
|
|
20476
|
+
var VERDICT_PRINT_MARGIN_MS = 2000;
|
|
20477
|
+
var MIN_PASS_BUDGET_MS = 5000;
|
|
20478
|
+
var PASS_LAUNCH_RESERVE_MS = 20000;
|
|
20476
20479
|
var DEFAULT_POLL_MS = 500;
|
|
20477
20480
|
function isInstantBrowserDeath(message) {
|
|
20478
20481
|
return /target page, context or browser has been closed|browser has been closed|target closed/i.test(message);
|
|
@@ -20595,14 +20598,21 @@ async function checkChannelSession(config, opts) {
|
|
|
20595
20598
|
const timeoutMs = opts.timeoutMs ?? DEFAULT_CHECK_TIMEOUT_MS;
|
|
20596
20599
|
const passes = opts.headedOnly ? [false] : opts.headedFallback === false ? [true] : [true, false];
|
|
20597
20600
|
let lastDetail = `${config.channel} readiness was never probed`;
|
|
20601
|
+
const deadline = Date.now() + timeoutMs;
|
|
20602
|
+
const printMarginMs = Math.min(VERDICT_PRINT_MARGIN_MS, Math.floor(timeoutMs / 4));
|
|
20603
|
+
const minPassMs = Math.min(MIN_PASS_BUDGET_MS, Math.floor(timeoutMs / 3));
|
|
20604
|
+
const launchReserveMs = Math.min(PASS_LAUNCH_RESERVE_MS, Math.floor(timeoutMs / 3));
|
|
20598
20605
|
for (const headless of passes) {
|
|
20606
|
+
const remainingMs = deadline - Date.now() - printMarginMs - launchReserveMs;
|
|
20607
|
+
if (remainingMs < minPassMs)
|
|
20608
|
+
break;
|
|
20599
20609
|
try {
|
|
20600
20610
|
await withProfilePage({
|
|
20601
20611
|
profileDir: opts.profileDir,
|
|
20602
20612
|
headless,
|
|
20603
20613
|
url: config.homeUrl,
|
|
20604
20614
|
isAuthenticated: config.isAuthenticated,
|
|
20605
|
-
timeoutMs,
|
|
20615
|
+
timeoutMs: remainingMs,
|
|
20606
20616
|
launcher: opts.launcher ?? kkBrowserLauncher
|
|
20607
20617
|
}, async () => true);
|
|
20608
20618
|
return {
|
|
@@ -35,6 +35,7 @@ export class WechatCgiDraftError extends Error {
|
|
|
35
35
|
| 'request-failed'
|
|
36
36
|
| 'receipt-invalid'
|
|
37
37
|
| 'readback-failed'
|
|
38
|
+
| 'duplicate-draft'
|
|
38
39
|
| 'ambiguous-submission',
|
|
39
40
|
readonly stage: string,
|
|
40
41
|
message: string,
|
|
@@ -421,10 +422,85 @@ function ambiguousSubmission(stage: string, detail: string): WechatCgiDraftError
|
|
|
421
422
|
}
|
|
422
423
|
|
|
423
424
|
/**
|
|
424
|
-
* The
|
|
425
|
-
*
|
|
426
|
-
*
|
|
427
|
-
*
|
|
425
|
+
* The console's own `list_ex` draft list, read on the authenticated page (task 0406 R4). One reader
|
|
426
|
+
* for both callers — the pre-create duplicate guard and the post-create readback — so the guard can
|
|
427
|
+
* never disagree with the confirmation about what the console holds. `stage` names the caller's
|
|
428
|
+
* step: a read failure is reported where it happened (nothing was created before the create).
|
|
429
|
+
*/
|
|
430
|
+
async function readDraftList(
|
|
431
|
+
page: WechatPage,
|
|
432
|
+
session: WechatCgiSession,
|
|
433
|
+
stage: string,
|
|
434
|
+
): Promise<Record<string, unknown>[]> {
|
|
435
|
+
const listUrl = buildUrl(APPMSG_URL, {
|
|
436
|
+
action: 'list_ex',
|
|
437
|
+
begin: '0',
|
|
438
|
+
count: '5',
|
|
439
|
+
token: session.token,
|
|
440
|
+
lang: 'zh_CN',
|
|
441
|
+
f: 'json',
|
|
442
|
+
});
|
|
443
|
+
let listVerdict: CgiVerdict | undefined;
|
|
444
|
+
try {
|
|
445
|
+
listVerdict = await evaluateCgiVerdict(
|
|
446
|
+
page,
|
|
447
|
+
cgiFetchExpression({
|
|
448
|
+
url: listUrl,
|
|
449
|
+
method: 'GET',
|
|
450
|
+
fields: {},
|
|
451
|
+
maxBytes: MAX_RESPONSE_BYTES,
|
|
452
|
+
timeoutMs: REQUEST_TIMEOUT_MS,
|
|
453
|
+
}),
|
|
454
|
+
);
|
|
455
|
+
} catch (error) {
|
|
456
|
+
throw new WechatCgiDraftError(
|
|
457
|
+
'readback-failed',
|
|
458
|
+
stage,
|
|
459
|
+
`draft list readback ended before a receipt returned: ${stripQuery(String(error))}`,
|
|
460
|
+
);
|
|
461
|
+
}
|
|
462
|
+
if (listVerdict?.kind !== 'ok') {
|
|
463
|
+
const detail =
|
|
464
|
+
listVerdict?.kind === 'http-status'
|
|
465
|
+
? `HTTP ${listVerdict.status}`
|
|
466
|
+
: listVerdict?.kind === 'too-large'
|
|
467
|
+
? `${MAX_RESPONSE_BYTES}-byte bound exceeded`
|
|
468
|
+
: listVerdict?.kind === 'error'
|
|
469
|
+
? stripQuery(listVerdict.detail)
|
|
470
|
+
: 'page returned no usable verdict';
|
|
471
|
+
throw new WechatCgiDraftError('readback-failed', stage, `draft list readback failed: ${detail}`);
|
|
472
|
+
}
|
|
473
|
+
let list: unknown;
|
|
474
|
+
try {
|
|
475
|
+
list = JSON.parse(listVerdict.text);
|
|
476
|
+
} catch {
|
|
477
|
+
throw new WechatCgiDraftError('readback-failed', stage, 'draft list receipt is not JSON');
|
|
478
|
+
}
|
|
479
|
+
return isRecord(list) && Array.isArray(list.app_msg_list)
|
|
480
|
+
? list.app_msg_list.filter((item): item is Record<string, unknown> => isRecord(item))
|
|
481
|
+
: [];
|
|
482
|
+
}
|
|
483
|
+
|
|
484
|
+
/**
|
|
485
|
+
* R4: the console already holds a draft with this exact title, so creating would only add a
|
|
486
|
+
* duplicate (3 drafts in one night, 2026-11-19). Refuse with the id that holds it and no side
|
|
487
|
+
* effect — a failed `effect: none` row is retryable once the operator clears the console draft.
|
|
488
|
+
*/
|
|
489
|
+
function duplicateDraft(existing: Record<string, unknown>, title: string): WechatCgiDraftError {
|
|
490
|
+
const id = existing.app_id !== undefined ? existing.app_id : existing.appmsgid;
|
|
491
|
+
return new WechatCgiDraftError(
|
|
492
|
+
'duplicate-draft',
|
|
493
|
+
'pre-create-lookup',
|
|
494
|
+
`duplicate-draft: appmsgid ${String(id)} already holds "${title}" — delete it or finish it in the console`,
|
|
495
|
+
);
|
|
496
|
+
}
|
|
497
|
+
|
|
498
|
+
/**
|
|
499
|
+
* The R2 create: eligibility re-asserted at the mutation boundary, a duplicate-title lookup
|
|
500
|
+
* (0406 R4) before anything is dispatched, ONE same-origin POST, receipt gated (HTTP ok, ret
|
|
501
|
+
* absent|0, safe numeric appMsgId), then the id+title readback. Any unverifiable create outcome
|
|
502
|
+
* throws ambiguous with metadata.ambiguousSubmission=true; readback failures throw readback-failed
|
|
503
|
+
* (the create receipt itself already verified). Never retries.
|
|
428
504
|
*/
|
|
429
505
|
export async function createWechatArticleDraft(
|
|
430
506
|
page: WechatPage,
|
|
@@ -432,8 +508,12 @@ export async function createWechatArticleDraft(
|
|
|
432
508
|
content: Content,
|
|
433
509
|
media: WechatArticleMedia,
|
|
434
510
|
): Promise<{ appMsgId: string; editPath: string }> {
|
|
435
|
-
|
|
511
|
+
const certified = certifyCgiDraft(content);
|
|
436
512
|
assertMpOrigin(page);
|
|
513
|
+
const existing = (await readDraftList(page, session, 'pre-create-lookup')).find(
|
|
514
|
+
(item) => item.title === certified.title,
|
|
515
|
+
);
|
|
516
|
+
if (existing !== undefined) throw duplicateDraft(existing, certified.title);
|
|
437
517
|
const payload = buildCreateArticlePayload(session, content, media);
|
|
438
518
|
let createVerdict: CgiVerdict | undefined;
|
|
439
519
|
try {
|
|
@@ -487,56 +567,10 @@ export async function createWechatArticleDraft(
|
|
|
487
567
|
if (appMsgId === undefined || !/^-?\d{1,12}$/.test(appMsgId)) {
|
|
488
568
|
throw ambiguousSubmission('create-receipt', 'create receipt did not return a safe numeric appMsgId');
|
|
489
569
|
}
|
|
490
|
-
const
|
|
491
|
-
action: 'list_ex',
|
|
492
|
-
begin: '0',
|
|
493
|
-
count: '5',
|
|
494
|
-
token: session.token,
|
|
495
|
-
lang: 'zh_CN',
|
|
496
|
-
f: 'json',
|
|
497
|
-
});
|
|
498
|
-
let listVerdict: CgiVerdict | undefined;
|
|
499
|
-
try {
|
|
500
|
-
listVerdict = await evaluateCgiVerdict(
|
|
501
|
-
page,
|
|
502
|
-
cgiFetchExpression({
|
|
503
|
-
url: listUrl,
|
|
504
|
-
method: 'GET',
|
|
505
|
-
fields: {},
|
|
506
|
-
maxBytes: MAX_RESPONSE_BYTES,
|
|
507
|
-
timeoutMs: REQUEST_TIMEOUT_MS,
|
|
508
|
-
}),
|
|
509
|
-
);
|
|
510
|
-
} catch (error) {
|
|
511
|
-
throw new WechatCgiDraftError(
|
|
512
|
-
'readback-failed',
|
|
513
|
-
'readback',
|
|
514
|
-
`draft list readback ended before a receipt returned: ${stripQuery(String(error))}`,
|
|
515
|
-
);
|
|
516
|
-
}
|
|
517
|
-
if (listVerdict?.kind !== 'ok') {
|
|
518
|
-
const detail =
|
|
519
|
-
listVerdict?.kind === 'http-status'
|
|
520
|
-
? `HTTP ${listVerdict.status}`
|
|
521
|
-
: listVerdict?.kind === 'too-large'
|
|
522
|
-
? `${MAX_RESPONSE_BYTES}-byte bound exceeded`
|
|
523
|
-
: listVerdict?.kind === 'error'
|
|
524
|
-
? stripQuery(listVerdict.detail)
|
|
525
|
-
: 'page returned no usable verdict';
|
|
526
|
-
throw new WechatCgiDraftError('readback-failed', 'readback', `draft list readback failed: ${detail}`);
|
|
527
|
-
}
|
|
528
|
-
let list: unknown;
|
|
529
|
-
try {
|
|
530
|
-
list = JSON.parse(listVerdict.text);
|
|
531
|
-
} catch {
|
|
532
|
-
throw new WechatCgiDraftError('readback-failed', 'readback', 'draft list receipt is not JSON');
|
|
533
|
-
}
|
|
534
|
-
const items = isRecord(list) && Array.isArray(list.app_msg_list) ? list.app_msg_list : [];
|
|
570
|
+
const items = await readDraftList(page, session, 'readback');
|
|
535
571
|
const confirmed = items.some(
|
|
536
572
|
(item) =>
|
|
537
|
-
|
|
538
|
-
item.title === content.title &&
|
|
539
|
-
(String(item.app_id) === appMsgId || String(item.appmsgid) === appMsgId),
|
|
573
|
+
item.title === content.title && (String(item.app_id) === appMsgId || String(item.appmsgid) === appMsgId),
|
|
540
574
|
);
|
|
541
575
|
if (!confirmed) {
|
|
542
576
|
throw new WechatCgiDraftError(
|
|
@@ -124,6 +124,52 @@ const CLAIM_COMMITTED = `(() => {
|
|
|
124
124
|
return { enabled, text };
|
|
125
125
|
})()`;
|
|
126
126
|
|
|
127
|
+
/**
|
|
128
|
+
* The 赞赏 row's own state, measured 2026-11-20 on a fresh 文章 draft (account without an authorized
|
|
129
|
+
* 赞赏 account): the row renders `.setting-group__switch.js_reward_allow_click` carrying the text
|
|
130
|
+
* `不开启 … 无法开启赞赏,因为还没有赞赏账户授权给本公众号`, its box is **0×0**, and the click the rail
|
|
131
|
+
* used to attempt therefore burned its full 8 s timeout (`赞赏: click: Timeout 8000ms exceeded`) on
|
|
132
|
+
* an element no operator action in this run could make clickable. One bounded read answers both
|
|
133
|
+
* questions — is the row blocked by text, and is there a box to click at all — before any click.
|
|
134
|
+
* Native CSS only: Playwright's `:visible` throws inside `evaluate` (task 0260 AC4).
|
|
135
|
+
*/
|
|
136
|
+
const REWARD_STATE = `(() => {
|
|
137
|
+
const rows = [
|
|
138
|
+
document.querySelector('.js_reward_allow_click'),
|
|
139
|
+
document.querySelector('.js_reward_open'),
|
|
140
|
+
document.querySelector('.setting-group__switch.js_reward_open'),
|
|
141
|
+
].filter((el) => el !== null);
|
|
142
|
+
if (rows.length === 0) return null;
|
|
143
|
+
const blockedText = /无法开启赞赏|还没有赞赏账户|前往开通|未开通/;
|
|
144
|
+
for (const el of rows) {
|
|
145
|
+
const text = (el.textContent ?? '').replace(/\\s+/g, ' ').trim();
|
|
146
|
+
const box = el.getBoundingClientRect();
|
|
147
|
+
if (blockedText.test(text) || (box.width === 0 && box.height === 0)) {
|
|
148
|
+
return { clickable: false, blocked: true, text: text.slice(0, 200) };
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
return { clickable: true, blocked: false, text: '' };
|
|
152
|
+
})()`;
|
|
153
|
+
|
|
154
|
+
/** `{ clickable, blocked, text }` from REWARD_STATE; `null` when the row is absent or unreadable. */
|
|
155
|
+
async function readRewardState(
|
|
156
|
+
page: WechatPage,
|
|
157
|
+
): Promise<{ clickable: boolean; blocked: boolean; text: string } | null> {
|
|
158
|
+
try {
|
|
159
|
+
const raw: unknown = await page.evaluate(REWARD_STATE);
|
|
160
|
+
if (typeof raw !== 'object' || raw === null) return null;
|
|
161
|
+
const value = raw as { clickable?: unknown; blocked?: unknown; text?: unknown };
|
|
162
|
+
if (typeof value.clickable !== 'boolean' || typeof value.blocked !== 'boolean') return null;
|
|
163
|
+
return {
|
|
164
|
+
clickable: value.clickable,
|
|
165
|
+
blocked: value.blocked,
|
|
166
|
+
text: typeof value.text === 'string' ? value.text : '',
|
|
167
|
+
};
|
|
168
|
+
} catch {
|
|
169
|
+
return null;
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
|
|
127
173
|
/** Read a settings checkbox's committed enabled state; `null` = unobservable (never "satisfied"). */
|
|
128
174
|
async function readChecked(page: WechatPage, expression: string): Promise<boolean | null> {
|
|
129
175
|
try {
|
|
@@ -259,10 +305,22 @@ export async function enrichArticle(page: WechatPage, meta: Record<string, unkno
|
|
|
259
305
|
const name = '赞赏';
|
|
260
306
|
if ((await readChecked(page, COMMITTED.reward)) !== true) {
|
|
261
307
|
const outcome = await step(name, async () => {
|
|
308
|
+
// Measured 2026-11-20: an account without an authorized 赞赏 account renders the row
|
|
309
|
+
// with the refusal already in it and a 0×0 box, so opening/closing it is impossible and
|
|
310
|
+
// the old path spent its whole 8 s click budget proving that. Read the row first — one
|
|
311
|
+
// bounded evaluation, no click, no dialog wait — and report the capability in one step.
|
|
312
|
+
const state = await readRewardState(page);
|
|
313
|
+
if (state?.blocked === true) {
|
|
314
|
+
throw new CapabilityError(
|
|
315
|
+
`需要赞赏账户(本公众号未被授权,平台原文:${state.text === '' ? '无法开启赞赏' : state.text})— 运营者在平台开通后重跑,本次不请求该字段`,
|
|
316
|
+
);
|
|
317
|
+
}
|
|
262
318
|
await openRow(ROW_REWARD, '赞赏');
|
|
263
|
-
// Measured 2026-10-13:
|
|
264
|
-
//
|
|
265
|
-
//
|
|
319
|
+
// Measured 2026-10-13: on other builds the prerequisite line appears only inside the
|
|
320
|
+
// dialog, so the post-open probe stays for that shape. It stays short on purpose — the
|
|
321
|
+
// row-level read above is what answers the measured 2026-11-20 account, and a longer
|
|
322
|
+
// window here only slows every healthy run (a 4 s probe pushed the enrichment suites
|
|
323
|
+
// past their own step budget).
|
|
266
324
|
const blocked = await tryFindSelector(
|
|
267
325
|
page,
|
|
268
326
|
[`${DIALOG} :has-text("前往开通")`, `${DIALOG} :has-text("无法开启")`],
|
|
@@ -2585,6 +2585,11 @@ async function runCgiDraft(input: ModeInput, deps: ModeRunDeps): Promise<Result
|
|
|
2585
2585
|
publishStatus: deps.publishStatus,
|
|
2586
2586
|
stage: error.stage,
|
|
2587
2587
|
...(error.metadata.ambiguousSubmission === true ? { ambiguousSubmission: true } : {}),
|
|
2588
|
+
// 0406 R4: the duplicate refusal dispatched nothing, so the row is honestly
|
|
2589
|
+
// `effect: none` — a bounded retry (not an operator resend) is the right next step.
|
|
2590
|
+
...(error.code === 'duplicate-draft'
|
|
2591
|
+
? { itcDelivery: { schemaVersion: 1, effect: 'none' as const } }
|
|
2592
|
+
: {}),
|
|
2588
2593
|
},
|
|
2589
2594
|
});
|
|
2590
2595
|
}
|
|
@@ -2945,6 +2950,29 @@ export async function insertAudioMaterial(
|
|
|
2945
2950
|
);
|
|
2946
2951
|
}
|
|
2947
2952
|
}
|
|
2953
|
+
if (!closed) {
|
|
2954
|
+
// 2026-11-20: the `完成` walk can leave the picker on screen (a
|
|
2955
|
+
// crop-confirm page whose 确定 sits outside the chooser subtree). Close
|
|
2956
|
+
// the PICKER only — the audio dialog behind it still holds the uploaded
|
|
2957
|
+
// file and the material title, so a global dialog sweep would discard
|
|
2958
|
+
// the audio we came for.
|
|
2959
|
+
const pickerClose = await tryFindSelector(
|
|
2960
|
+
page,
|
|
2961
|
+
[
|
|
2962
|
+
`${chooser} .weui-desktop-dialog__close-btn`,
|
|
2963
|
+
`${chooser} .weui-desktop-dialog__close`,
|
|
2964
|
+
`${chooser} button:has-text("取消")`,
|
|
2965
|
+
],
|
|
2966
|
+
3_000,
|
|
2967
|
+
);
|
|
2968
|
+
if (pickerClose !== undefined) {
|
|
2969
|
+
await clickSelector(page, pickerClose, 3_000);
|
|
2970
|
+
closed = await waitUntil(
|
|
2971
|
+
async () => !(await page.locator(chooser).first().isVisible()),
|
|
2972
|
+
10_000,
|
|
2973
|
+
);
|
|
2974
|
+
}
|
|
2975
|
+
}
|
|
2948
2976
|
if (!closed) {
|
|
2949
2977
|
// Live 2026-11-09 this stall is real — capture WHAT is on screen (the
|
|
2950
2978
|
// confirm dialog may not nest under the chooser selector, which would
|