@gobing-ai/knowledge-kit 0.1.14 → 0.1.16
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 +2399 -177
- package/package.json +1 -1
- package/plugins/generations/content-gen/dist/index.js +60 -54
- package/plugins/generations/content-gen/src/storm.ts +94 -61
- package/plugins/generations/core-facts-gen/dist/index.js +3 -3
- package/plugins/generations/daily-article-gen/dist/index.js +3 -3
- package/plugins/generations/dailynews-gen/dist/index.js +73 -10
- package/plugins/generations/dailynews-gen/src/index.ts +23 -1
- package/plugins/generations/dailynews-gen/src/script-plan.ts +103 -5
- package/plugins/generations/episode-plan-gen/dist/index.js +3 -3
- package/plugins/generations/gemini-tts/dist/index.js +3 -3
- package/plugins/generations/image-gen/README.md +31 -10
- package/plugins/generations/image-gen/assets/sample/cover__quasi-news-podcast.jpg +0 -0
- package/plugins/generations/image-gen/assets/sample/daily-news-cover__quasi-news-podcast.jpg +0 -0
- package/plugins/generations/image-gen/assets/sample/daily-news-podcast-cover__clean-webapp-ui.jpg +0 -0
- package/plugins/generations/image-gen/assets/sample/daily-news-podcast-cover__cute.jpg +0 -0
- package/plugins/generations/image-gen/assets/sample/daily-news-podcast-cover__daily-news.jpg +0 -0
- package/plugins/generations/image-gen/assets/sample/daily-news-podcast-cover__editorial.jpg +0 -0
- package/plugins/generations/image-gen/assets/sample/daily-news-podcast-cover__fresh.jpg +0 -0
- package/plugins/generations/image-gen/assets/sample/daily-news-podcast-cover__minimalist.jpg +0 -0
- package/plugins/generations/image-gen/assets/sample/daily-news-podcast-cover__photorealistic.jpg +0 -0
- package/plugins/generations/image-gen/assets/sample/daily-news-podcast-cover__quasi-news-podcast.jpg +0 -0
- package/plugins/generations/image-gen/assets/sample/daily-news-podcast-cover__sketch.jpg +0 -0
- package/plugins/generations/image-gen/assets/sample/daily-news-podcast-cover__technical-diagram.jpg +0 -0
- package/plugins/generations/image-gen/assets/sample/daily-news-podcast-cover__vibrant.jpg +0 -0
- package/plugins/generations/image-gen/assets/sample/daily-news-podcast-cover__warm.jpg +0 -0
- package/plugins/generations/image-gen/assets/sample/daily-news-podcast-cover__xhs-knowledge.jpg +0 -0
- package/plugins/generations/image-gen/assets/sample/free__quasi-news-podcast.jpg +0 -0
- package/plugins/generations/image-gen/assets/sample/illustration__quasi-news-podcast.jpg +0 -0
- package/plugins/generations/image-gen/assets/sample/xhs-card__quasi-news-podcast.jpg +0 -0
- package/plugins/generations/image-gen/dist/index.js +3 -3
- package/plugins/generations/image-gen/presets/formats/daily-news-podcast-cover.yaml +18 -0
- package/plugins/generations/image-gen/presets/styles/quasi-news-podcast.yaml +9 -0
- package/plugins/generations/news-report-gen/dist/index.js +3 -3
- package/plugins/generations/voice-gen/dist/index.js +3 -3
- package/plugins/generations/voxcpm-tts/dist/index.js +3 -3
- package/plugins/ingestions/aihot-ingest/dist/index.js +3 -3
- package/plugins/ingestions/horizon-ingest/dist/index.js +3 -3
- package/plugins/ingestions/last30days-ingest/dist/index.js +3 -3
- package/plugins/ingestions/web-search/dist/index.js +3 -3
- package/plugins/kk/plugin.json +1 -1
- package/plugins/kk/publish-presets/daily-ai-voice-migration.json +12 -3
- package/plugins/kk/publish-presets/daily-ai-voice.json +11 -3
- package/plugins/kk/scripts/cover-compositor.ts +152 -0
- package/plugins/kk/scripts/daily-cover-mock.ts +164 -0
- package/plugins/kk/scripts/daily-scheduled-run.ts +192 -3
- package/plugins/kk/scripts/daily-stages.ts +599 -27
- package/plugins/kk/scripts/daily-triage-core.ts +451 -0
- package/plugins/kk/scripts/daily-triage.ts +74 -0
- package/plugins/kk/scripts/kk-workflow-stages.ts +51 -6
- package/plugins/kk/skills/content-judge/SKILL.md +5 -4
- package/plugins/kk/skills/content-judge/references/rubrics.md +14 -0
- package/plugins/kk/skills/content-safety/references/platforms/wechatmp.md +16 -10
- package/plugins/kk/skills/news-editorial/SKILL.md +122 -0
- package/plugins/kk/skills/news-editorial/references/selection.md +47 -0
- package/plugins/kk/skills/news-editorial/references/style-contract.zh.md +100 -0
- package/plugins/kk/skills/publish/SKILL.md +4 -4
- package/plugins/kk/skills/web-automation/SKILL.md +229 -77
- package/plugins/kk/skills/web-automation/references/browser-launch.md +127 -36
- package/plugins/kk/skills/wiki-authoring/SKILL.md +53 -0
- package/plugins/kk/skills/wiki-authoring/references/page-shapes.md +44 -0
- package/plugins/kk/workflows/kk-daily-ai-voice2.yaml +4 -6
- package/plugins/kk/workflows/kk-daily-ai-voice3.yaml +185 -224
- package/plugins/kk/workflows/kk-daily-publish3.yaml +16 -8
- package/plugins/kk/workflows/kk-daily-safety.yaml +32 -7
- package/plugins/publishings/bilibili-pub/dist/index.js +6 -4
- package/plugins/publishings/bilibili-pub/dist/profile-check.js +3 -1
- package/plugins/publishings/cnblogs-pub/dist/index.js +6 -4
- package/plugins/publishings/cnblogs-pub/dist/profile-check.js +3 -1
- package/plugins/publishings/csdn-pub/dist/index.js +6 -4
- package/plugins/publishings/csdn-pub/dist/profile-check.js +6 -4
- package/plugins/publishings/emdash-pub/dist/index.js +3 -3
- package/plugins/publishings/infoq-pub/dist/index.js +6 -4
- package/plugins/publishings/infoq-pub/dist/profile-check.js +6 -4
- package/plugins/publishings/jike-pub/dist/index.js +6 -4
- package/plugins/publishings/jike-pub/dist/profile-check.js +6 -4
- package/plugins/publishings/juejin-pub/dist/index.js +6 -4
- package/plugins/publishings/juejin-pub/dist/profile-check.js +6 -4
- package/plugins/publishings/linkedin-pub/dist/index.js +6 -4
- package/plugins/publishings/linkedin-pub/dist/profile-check.js +6 -4
- package/plugins/publishings/medium-pub/dist/index.js +3 -3
- package/plugins/publishings/podcast-pub/dist/index.js +148 -5
- package/plugins/publishings/podcast-pub/src/index.ts +71 -2
- package/plugins/publishings/podcast-pub/src/map.ts +3 -0
- package/plugins/publishings/podcast-pub/src/transcript.ts +195 -0
- package/plugins/publishings/qiita-pub/dist/index.js +3 -3
- package/plugins/publishings/shipinhao-pub/dist/index.js +227 -53
- package/plugins/publishings/shipinhao-pub/dist/profile-check.js +51 -2
- package/plugins/publishings/shipinhao-pub/plugin.json +2 -2
- package/plugins/publishings/shipinhao-pub/src/flow.ts +335 -79
- package/plugins/publishings/shipinhao-pub/src/index.ts +16 -8
- package/plugins/publishings/shipinhao-pub/src/profile-check.ts +1 -1
- package/plugins/publishings/shipinhao-pub/src/selectors.ts +103 -5
- package/plugins/publishings/sspai-pub/dist/index.js +6 -4
- package/plugins/publishings/sspai-pub/dist/profile-check.js +3 -1
- package/plugins/publishings/substack-pub/dist/index.js +6 -4
- package/plugins/publishings/substack-pub/dist/profile-check.js +6 -4
- package/plugins/publishings/surfdash-pub/dist/index.js +237 -14
- package/plugins/publishings/surfdash-pub/src/index.ts +127 -6
- package/plugins/publishings/surfdash-pub/src/topic-claims.ts +189 -0
- package/plugins/publishings/threads-pub/dist/index.js +3 -3
- package/plugins/publishings/wechatmp-pub/dist/index.js +62 -40
- package/plugins/publishings/wechatmp-pub/dist/profile-check.js +6 -4
- package/plugins/publishings/wechatmp-pub/src/enrich.ts +10 -3
- package/plugins/publishings/wechatmp-pub/src/flow.ts +73 -37
- package/plugins/publishings/wechatmp-pub/src/page.ts +14 -0
- package/plugins/publishings/weibo-pub/dist/index.js +6 -4
- package/plugins/publishings/weibo-pub/dist/profile-check.js +6 -4
- package/plugins/publishings/x-pub/dist/index.js +6 -4
- package/plugins/publishings/x-pub/dist/profile-check.js +6 -4
- package/plugins/publishings/xhs-pub/dist/index.js +562 -34
- package/plugins/publishings/xhs-pub/dist/profile-check.js +25 -4
- package/plugins/publishings/xhs-pub/src/errors.ts +45 -0
- package/plugins/publishings/xhs-pub/src/flow.ts +773 -45
- package/plugins/publishings/xhs-pub/src/page.ts +33 -0
- package/plugins/publishings/xiaoyuzhou-pub/dist/index.js +6 -4
- package/plugins/publishings/xiaoyuzhou-pub/dist/profile-check.js +3 -1
- package/plugins/publishings/zenn-pub/dist/index.js +3 -3
- package/plugins/kk/scripts/daily-voice-style.zh.md +0 -70
|
@@ -19905,7 +19905,7 @@ var PLATFORM_CONTENT_LIMITS = Object.freeze({
|
|
|
19905
19905
|
shortVideo: Object.freeze({
|
|
19906
19906
|
douyin: Object.freeze({ max: 1000, unit: "unicode_code_points" }),
|
|
19907
19907
|
kuaishou: Object.freeze({ max: 1000, unit: "unicode_code_points" }),
|
|
19908
|
-
shipinhao: Object.freeze({ max:
|
|
19908
|
+
shipinhao: Object.freeze({ max: 100, unit: "unicode_code_points" })
|
|
19909
19909
|
})
|
|
19910
19910
|
})
|
|
19911
19911
|
});
|
|
@@ -20073,11 +20073,11 @@ var PluginManifestSchemaBase = looseObject({
|
|
|
20073
20073
|
});
|
|
20074
20074
|
var PluginManifestSchema = PluginManifestSchemaBase.superRefine((manifest, ctx) => {
|
|
20075
20075
|
if (manifest.browserSession !== undefined) {
|
|
20076
|
-
if (manifest.kind !== "publish") {
|
|
20076
|
+
if (manifest.kind !== "publish" && manifest.kind !== "ingestion") {
|
|
20077
20077
|
ctx.addIssue({
|
|
20078
20078
|
code: "custom",
|
|
20079
20079
|
path: ["browserSession"],
|
|
20080
|
-
message: `browserSession requires kind "publish", not "${manifest.kind}"`
|
|
20080
|
+
message: `browserSession requires kind "publish" or "ingestion", not "${manifest.kind}"`
|
|
20081
20081
|
});
|
|
20082
20082
|
}
|
|
20083
20083
|
if (manifest.check === undefined) {
|
|
@@ -20701,10 +20701,12 @@ function sha256Hex(value) {
|
|
|
20701
20701
|
var DEFAULT_BOT_PROFILE_ROOT = join4(homedir4(), ".config", "kk", "browser-profiles");
|
|
20702
20702
|
class BotError extends Error {
|
|
20703
20703
|
code;
|
|
20704
|
-
|
|
20704
|
+
details;
|
|
20705
|
+
constructor(code, message, details = {}) {
|
|
20705
20706
|
super(message);
|
|
20706
20707
|
this.name = "BotError";
|
|
20707
20708
|
this.code = code;
|
|
20709
|
+
this.details = details;
|
|
20708
20710
|
}
|
|
20709
20711
|
}
|
|
20710
20712
|
// ../../packages/publish-harness/src/profile-dir.ts
|
|
@@ -21081,6 +21083,39 @@ function createAutomationGuard(options) {
|
|
|
21081
21083
|
};
|
|
21082
21084
|
}
|
|
21083
21085
|
|
|
21086
|
+
// ../../plugins/publishings/xhs-pub/src/errors.ts
|
|
21087
|
+
class PublishError extends Error {
|
|
21088
|
+
name;
|
|
21089
|
+
constructor(message, name = "PublishError") {
|
|
21090
|
+
super(message);
|
|
21091
|
+
this.name = name;
|
|
21092
|
+
}
|
|
21093
|
+
}
|
|
21094
|
+
|
|
21095
|
+
class AccountRiskControlError extends PublishError {
|
|
21096
|
+
constructor(message) {
|
|
21097
|
+
super(message, "AccountRiskControlError");
|
|
21098
|
+
}
|
|
21099
|
+
}
|
|
21100
|
+
|
|
21101
|
+
class TitleTooLongError extends PublishError {
|
|
21102
|
+
constructor(message) {
|
|
21103
|
+
super(message, "TitleTooLongError");
|
|
21104
|
+
}
|
|
21105
|
+
}
|
|
21106
|
+
|
|
21107
|
+
class ContentTooLongError extends PublishError {
|
|
21108
|
+
constructor(message) {
|
|
21109
|
+
super(message, "ContentTooLongError");
|
|
21110
|
+
}
|
|
21111
|
+
}
|
|
21112
|
+
|
|
21113
|
+
class DraftVerifyError extends PublishError {
|
|
21114
|
+
constructor(message) {
|
|
21115
|
+
super(message, "DraftVerifyError");
|
|
21116
|
+
}
|
|
21117
|
+
}
|
|
21118
|
+
|
|
21084
21119
|
// ../../plugins/publishings/xhs-pub/src/modes.ts
|
|
21085
21120
|
import { isAbsolute as isAbsolute2 } from "path";
|
|
21086
21121
|
var TARGET = "xhs";
|
|
@@ -21368,6 +21403,25 @@ function wrapPlaywrightPage(raw, shadow) {
|
|
|
21368
21403
|
}
|
|
21369
21404
|
return pw.waitForEvent(event, options);
|
|
21370
21405
|
},
|
|
21406
|
+
on: (event, handler) => {
|
|
21407
|
+
const raw2 = raw;
|
|
21408
|
+
raw2.on?.(event, handler);
|
|
21409
|
+
},
|
|
21410
|
+
off: (event, handler) => {
|
|
21411
|
+
const raw2 = raw;
|
|
21412
|
+
raw2.off?.(event, handler);
|
|
21413
|
+
},
|
|
21414
|
+
onContextResponse: (handler) => {
|
|
21415
|
+
const raw2 = raw;
|
|
21416
|
+
const ctx = raw2.context?.();
|
|
21417
|
+
ctx?.on?.("response", handler);
|
|
21418
|
+
},
|
|
21419
|
+
offContextResponse: (handler) => {
|
|
21420
|
+
const raw2 = raw;
|
|
21421
|
+
const ctx = raw2.context?.();
|
|
21422
|
+
ctx?.off?.("response", handler);
|
|
21423
|
+
},
|
|
21424
|
+
boundingBoxesOnScreen: (selector) => onScreen(selector).then((found) => found.map((entry) => entry.box)),
|
|
21371
21425
|
mouse: {
|
|
21372
21426
|
click: (x, y) => pw.mouse.click(x, y)
|
|
21373
21427
|
}
|
|
@@ -21409,13 +21463,11 @@ var NOTE_BODY = [
|
|
|
21409
21463
|
".ql-editor"
|
|
21410
21464
|
];
|
|
21411
21465
|
var NOTE_THUMBNAIL = ["img.preivew-image", ".img-preview img"];
|
|
21412
|
-
var IMAGE_FILE_INPUT = [
|
|
21413
|
-
'input[type="file"][accept*=".jpg"]',
|
|
21414
|
-
'input[type="file"].upload-input',
|
|
21415
|
-
'input[type="file"]'
|
|
21416
|
-
];
|
|
21417
21466
|
var VIDEO_FILE_INPUT = ['input[type="file"][accept*=".mp4"]', 'input[type="file"].upload-input'];
|
|
21418
21467
|
var VIDEO_EDITOR = ["div.tiptap.ProseMirror", 'div.tiptap[contenteditable="true"]', ".ProseMirror"];
|
|
21468
|
+
var IMAGE_MODE_SETTLE_MS = 1500;
|
|
21469
|
+
var CONSOLE_SETTLE_MS = 9000;
|
|
21470
|
+
var CONSOLE_SETTLE_QUIET_MS = 2000;
|
|
21419
21471
|
var ARTICLE_NEW = ["text=\u65B0\u7684\u521B\u4F5C", 'button:has-text("\u65B0\u7684\u521B\u4F5C")'];
|
|
21420
21472
|
var ARTICLE_EDITOR = ["div.tiptap.ProseMirror.ProseMirror-focused", "div.tiptap.ProseMirror", ".ProseMirror"];
|
|
21421
21473
|
var ARTICLE_LAYOUT = ['button:has-text("\u4E00\u952E\u6392\u7248")', "div.ailayout-btn_wrp", "div.ailayout-btn_label"];
|
|
@@ -21425,6 +21477,9 @@ var PODCAST_AUDIO_INPUT = ['input[type="file"][accept*=".mp3"]', 'input[type="fi
|
|
|
21425
21477
|
var PODCAST_MODAL_ADVANCE = ["\u53BB\u53D1\u5E03"];
|
|
21426
21478
|
var PODCAST_COVER_ZONE = '.d-modal div:has-text("\u8BBE\u7F6E\u5C01\u9762")';
|
|
21427
21479
|
var PODCAST_UPLOAD_ACK = "\u4E0A\u4F20\u6210\u529F";
|
|
21480
|
+
var PODCAST_TITLE_SELECTORS = ["input.d-text", 'input[placeholder*="\u6807\u9898"]', 'textarea[placeholder*="\u6807\u9898"]'];
|
|
21481
|
+
var PODCAST_COLLECTION_SELECTORS = ['button:has-text("\u52A0\u5165\u64AD\u5BA2\u5408\u96C6")', "text=\u52A0\u5165\u64AD\u5BA2\u5408\u96C6", "text=\u5408\u96C6"];
|
|
21482
|
+
var PODCAST_COLLECTION_DEFAULT = "\u54B8\u8BDD\u54B8\u8BF4\u4E4B\u6BCF\u65E5AI\u4E71\u7096";
|
|
21428
21483
|
var DRAFT_LABELS = ["\u6682\u5B58\u79BB\u5F00", "\u5B58\u8349\u7A3F", "\u4FDD\u5B58\u8349\u7A3F"];
|
|
21429
21484
|
var PUBLISH_LABELS = ["\u53D1\u5E03"];
|
|
21430
21485
|
var PUBLISH_CONFIRM = ["\u53D1\u5E03\u6210\u529F", "\u5DF2\u53D1\u5E03"];
|
|
@@ -21477,6 +21532,157 @@ async function clickLightControl(page, labels, timeoutMs, what) {
|
|
|
21477
21532
|
await page.locator(selector).first().click({ timeout: timeoutMs });
|
|
21478
21533
|
return { ok: true, label: label ?? "", selector };
|
|
21479
21534
|
}
|
|
21535
|
+
async function invokeHostSave(page) {
|
|
21536
|
+
try {
|
|
21537
|
+
const verdict = await page.evaluate(`(() => {
|
|
21538
|
+
const hosts = Array.from(document.querySelectorAll('xhs-publish-btn')).filter((el) => {
|
|
21539
|
+
const r = el.getBoundingClientRect();
|
|
21540
|
+
return r.width > 0 && r.height > 0;
|
|
21541
|
+
});
|
|
21542
|
+
for (const el of hosts) {
|
|
21543
|
+
for (const name of ['_onSave', '_onSaveDraft', '_onDraft']) {
|
|
21544
|
+
const fn = el[name];
|
|
21545
|
+
if (typeof fn === 'function') { fn.call(el); return 'kk-host-save:' + name; }
|
|
21546
|
+
}
|
|
21547
|
+
}
|
|
21548
|
+
return 'kk-host-save-none';
|
|
21549
|
+
})()`);
|
|
21550
|
+
const called = typeof verdict === "string" ? verdict : "";
|
|
21551
|
+
return called.startsWith("kk-host-save:") ? called.slice("kk-host-save:".length) : null;
|
|
21552
|
+
} catch {
|
|
21553
|
+
return null;
|
|
21554
|
+
}
|
|
21555
|
+
}
|
|
21556
|
+
var CAPTURE_INJECT_EXPR = `/* kk-capture-inject */ (() => {
|
|
21557
|
+
const w = window;
|
|
21558
|
+
if (w.__kkXhsArmed) return 'kk-capture-armed';
|
|
21559
|
+
w.__kkXhsArmed = true;
|
|
21560
|
+
w.__kkXhsOutcome = null;
|
|
21561
|
+
const signatures = [
|
|
21562
|
+
/HTTPBizError/,
|
|
21563
|
+
/"code"\\s*:\\s*-913\\d/,
|
|
21564
|
+
/\u7981\u6B62\u53D1\u7B14\u8BB0/,
|
|
21565
|
+
/note_id/,
|
|
21566
|
+
/\u8FDD\u53CD|\u8FDD\u89C4|\u5BA1\u6838\u672A\u901A\u8FC7|\u8D26\u53F7\u5F02\u5E38|\u65E0\u6CD5\u53D1\u5E03/,
|
|
21567
|
+
];
|
|
21568
|
+
const matches = (text) => signatures.some((re) => re.test(text));
|
|
21569
|
+
const record = (source, text) => {
|
|
21570
|
+
if (w.__kkXhsOutcome) return;
|
|
21571
|
+
const asString = String(text || '');
|
|
21572
|
+
if (!asString || !matches(asString)) return;
|
|
21573
|
+
w.__kkXhsOutcome = { source: source, text: asString.slice(0, 800) };
|
|
21574
|
+
};
|
|
21575
|
+
const proto = XMLHttpRequest.prototype;
|
|
21576
|
+
if (!proto.__kkPatched) {
|
|
21577
|
+
proto.__kkPatched = true;
|
|
21578
|
+
const open = proto.open;
|
|
21579
|
+
const send = proto.send;
|
|
21580
|
+
proto.open = function (method, url) { this.__kkUrl = url; return open.apply(this, arguments); };
|
|
21581
|
+
proto.send = function () {
|
|
21582
|
+
this.addEventListener('loadend', () => {
|
|
21583
|
+
try { record('xhr', (this.__kkUrl || '') + ' ' + this.responseText); } catch (e) {}
|
|
21584
|
+
});
|
|
21585
|
+
return send.apply(this, arguments);
|
|
21586
|
+
};
|
|
21587
|
+
}
|
|
21588
|
+
if (typeof w.fetch === 'function' && !w.fetch.__kkPatched) {
|
|
21589
|
+
const original = w.fetch;
|
|
21590
|
+
w.fetch = function () {
|
|
21591
|
+
return original.apply(this, arguments).then((response) => {
|
|
21592
|
+
try {
|
|
21593
|
+
response.clone().text().then((text) => record('fetch', (response.url || '') + ' ' + text)).catch(() => {});
|
|
21594
|
+
} catch (e) {}
|
|
21595
|
+
return response;
|
|
21596
|
+
});
|
|
21597
|
+
};
|
|
21598
|
+
w.fetch.__kkPatched = true;
|
|
21599
|
+
}
|
|
21600
|
+
if (!console.__kkPatched) {
|
|
21601
|
+
console.__kkPatched = true;
|
|
21602
|
+
for (const key of ['error', 'warn', 'log']) {
|
|
21603
|
+
const original = console[key].bind(console);
|
|
21604
|
+
console[key] = function () {
|
|
21605
|
+
try { record('console', Array.prototype.map.call(arguments, String).join(' ')); } catch (e) {}
|
|
21606
|
+
original.apply(console, arguments);
|
|
21607
|
+
};
|
|
21608
|
+
}
|
|
21609
|
+
}
|
|
21610
|
+
if (typeof MutationObserver === 'function' && document.body && !w.__kkXhsToastObs) {
|
|
21611
|
+
const toastRisk = /\u8FDD\u53CD|\u8FDD\u89C4|\u7981\u6B62\u53D1\u7B14\u8BB0|\u5BA1\u6838\u672A\u901A\u8FC7|\u8D26\u53F7\u5F02\u5E38|\u65E0\u6CD5\u53D1\u5E03/;
|
|
21612
|
+
const obs = new MutationObserver((muts) => {
|
|
21613
|
+
if (w.__kkXhsOutcome) return;
|
|
21614
|
+
for (const m of muts) {
|
|
21615
|
+
for (const n of m.addedNodes || []) {
|
|
21616
|
+
if (!n || n.nodeType !== 1) continue;
|
|
21617
|
+
const txt = String(n.textContent || '').trim();
|
|
21618
|
+
if (txt.length === 0 || txt.length > 300) continue;
|
|
21619
|
+
if (!toastRisk.test(txt)) continue;
|
|
21620
|
+
record('toast', txt);
|
|
21621
|
+
}
|
|
21622
|
+
}
|
|
21623
|
+
});
|
|
21624
|
+
obs.observe(document.body, { childList: true, subtree: true });
|
|
21625
|
+
w.__kkXhsToastObs = true;
|
|
21626
|
+
}
|
|
21627
|
+
return 'kk-capture-armed';
|
|
21628
|
+
})()`;
|
|
21629
|
+
var CAPTURE_READ_EXPR = `/* kk-capture-read */ (() => {
|
|
21630
|
+
const captured = window.__kkXhsOutcome;
|
|
21631
|
+
return captured ? JSON.stringify(captured) : 'kk-capture-none';
|
|
21632
|
+
})()`;
|
|
21633
|
+
async function armOutcomeCapture(page) {
|
|
21634
|
+
try {
|
|
21635
|
+
await page.evaluate(CAPTURE_INJECT_EXPR);
|
|
21636
|
+
} catch {}
|
|
21637
|
+
}
|
|
21638
|
+
async function readOutcomeCapture(page) {
|
|
21639
|
+
try {
|
|
21640
|
+
const read = await page.evaluate(CAPTURE_READ_EXPR);
|
|
21641
|
+
if (typeof read !== "string" || !read.startsWith("{"))
|
|
21642
|
+
return null;
|
|
21643
|
+
const parsed = JSON.parse(read);
|
|
21644
|
+
return typeof parsed.source === "string" && typeof parsed.text === "string" ? { source: parsed.source, text: parsed.text } : null;
|
|
21645
|
+
} catch {
|
|
21646
|
+
return null;
|
|
21647
|
+
}
|
|
21648
|
+
}
|
|
21649
|
+
var RISK_SIGNATURE = /\u7981\u6B62\u53D1\u7B14\u8BB0|\u8FDD\u53CD|\u8FDD\u89C4|\u5BA1\u6838\u672A\u901A\u8FC7|\u8D26\u53F7\u5F02\u5E38|\u65E0\u6CD5\u53D1\u5E03/;
|
|
21650
|
+
var CODE_SIGNATURE = /"code"\s*:\s*(-?\d+)/;
|
|
21651
|
+
var NOTE_ID_SIGNATURE = /"note_id"\s*:\s*"([^"]+)"/;
|
|
21652
|
+
function classifyOutcome(text) {
|
|
21653
|
+
const code = CODE_SIGNATURE.exec(text)?.[1] ?? null;
|
|
21654
|
+
const noteId = NOTE_ID_SIGNATURE.exec(text)?.[1] ?? null;
|
|
21655
|
+
if (code !== null && /^-913\d$/.test(code) || RISK_SIGNATURE.test(text)) {
|
|
21656
|
+
return { verdict: "risk", code, noteId };
|
|
21657
|
+
}
|
|
21658
|
+
if (noteId !== null && (code === null || code === "0"))
|
|
21659
|
+
return { verdict: "ok", code, noteId };
|
|
21660
|
+
return { verdict: "biz", code, noteId };
|
|
21661
|
+
}
|
|
21662
|
+
function assertCapturedOutcome(capture) {
|
|
21663
|
+
if (capture === null)
|
|
21664
|
+
return;
|
|
21665
|
+
const { verdict, code } = classifyOutcome(capture.text);
|
|
21666
|
+
if (verdict === "risk") {
|
|
21667
|
+
throw new AccountRiskControlError(`AccountRiskControlError: the ${capture.source} response matched risk-control signatures (code ${code ?? "unknown"}, matched: ${RISK_SIGNATURE.exec(capture.text)?.[0] ?? "-913x code"}) \u2014 the account is restricted from posting on ${TARGET}; not retryable`);
|
|
21668
|
+
}
|
|
21669
|
+
if (verdict === "biz") {
|
|
21670
|
+
throw new PublishError(`PublishError: the ${capture.source} response reported a platform error (code ${code ?? "unknown"}): ${capture.text.slice(0, 200)}`);
|
|
21671
|
+
}
|
|
21672
|
+
}
|
|
21673
|
+
function captureMetadata(capture) {
|
|
21674
|
+
if (capture === null)
|
|
21675
|
+
return {};
|
|
21676
|
+
const { verdict, code, noteId } = classifyOutcome(capture.text);
|
|
21677
|
+
return {
|
|
21678
|
+
serverCapture: {
|
|
21679
|
+
source: capture.source,
|
|
21680
|
+
verdict,
|
|
21681
|
+
...code !== null ? { code } : {},
|
|
21682
|
+
...noteId !== null ? { noteId } : {}
|
|
21683
|
+
}
|
|
21684
|
+
};
|
|
21685
|
+
}
|
|
21480
21686
|
async function clickActionControl(operation, deps, labels, what) {
|
|
21481
21687
|
let lastError = "";
|
|
21482
21688
|
for (const path of MODE_ACTION_PATHS[operation]) {
|
|
@@ -21548,33 +21754,155 @@ async function draftSignalEvidence(page, baseline) {
|
|
|
21548
21754
|
async function applyNoteTitle(deps) {
|
|
21549
21755
|
const selector = await findSelector(deps.page, NOTE_TITLE, "title input", deps.stepTimeoutMs);
|
|
21550
21756
|
await deps.page.locator(selector).first().fill(deps.content.title ?? "");
|
|
21757
|
+
await assertPlatformCounter(deps.page, TITLE_COUNTER_EXPR, XHS_NOTE_TITLE_MAX, "title");
|
|
21551
21758
|
}
|
|
21552
|
-
async function typeNoteBody(deps, selectors, what) {
|
|
21759
|
+
async function typeNoteBody(deps, selectors, what, text) {
|
|
21553
21760
|
const selector = await findSelector(deps.page, selectors, what, deps.stepTimeoutMs);
|
|
21554
21761
|
const body = deps.page.locator(selector).first();
|
|
21555
|
-
const
|
|
21762
|
+
const value = text ?? deps.content.body ?? "";
|
|
21556
21763
|
if (typeof body.type === "function") {
|
|
21557
21764
|
await body.click();
|
|
21558
|
-
await body.type(
|
|
21559
|
-
|
|
21765
|
+
await body.type(value, { delay: 5 });
|
|
21766
|
+
} else {
|
|
21767
|
+
await body.fill(value);
|
|
21768
|
+
}
|
|
21769
|
+
await assertPlatformCounter(deps.page, BODY_COUNTER_EXPR, XHS_NOTE_BODY_MAX, "body");
|
|
21770
|
+
}
|
|
21771
|
+
var TITLE_COUNTER_EXPR = `/* kk-counter-title */ (() => {
|
|
21772
|
+
const el = document.querySelector('div.title-container div.max_suffix');
|
|
21773
|
+
if (el && el.textContent && el.textContent.trim()) return el.textContent.trim();
|
|
21774
|
+
for (const node of document.querySelectorAll('div.title-container *')) {
|
|
21775
|
+
const t = (node.textContent || '').trim();
|
|
21776
|
+
if (/^\\d+\\/\\d+$/.test(t) && node.children.length === 0) return t;
|
|
21777
|
+
}
|
|
21778
|
+
return 'kk-counter-none';
|
|
21779
|
+
})()`;
|
|
21780
|
+
var BODY_COUNTER_EXPR = `/* kk-counter-body */ (() => {
|
|
21781
|
+
const err = document.querySelector('div.edit-container div.length-error');
|
|
21782
|
+
if (err && err.textContent && err.textContent.trim()) return err.textContent.trim();
|
|
21783
|
+
for (const node of document.querySelectorAll('div.edit-container *')) {
|
|
21784
|
+
const t = (node.textContent || '').trim();
|
|
21785
|
+
if (/^\\d+\\/\\d+$/.test(t) && node.children.length === 0) return t;
|
|
21786
|
+
}
|
|
21787
|
+
return 'kk-counter-none';
|
|
21788
|
+
})()`;
|
|
21789
|
+
function counterUnits(counter) {
|
|
21790
|
+
const current = Number.parseInt(counter.split("/")[0] ?? "", 10);
|
|
21791
|
+
return Number.isFinite(current) ? current : null;
|
|
21792
|
+
}
|
|
21793
|
+
async function readPlatformCounter(page, expression) {
|
|
21794
|
+
try {
|
|
21795
|
+
const read = await page.evaluate(expression);
|
|
21796
|
+
if (typeof read !== "string" || read.includes("kk-counter-none"))
|
|
21797
|
+
return null;
|
|
21798
|
+
return read.trim();
|
|
21799
|
+
} catch {
|
|
21800
|
+
return null;
|
|
21560
21801
|
}
|
|
21561
|
-
await body.fill(text);
|
|
21562
21802
|
}
|
|
21563
|
-
async function
|
|
21803
|
+
async function assertPlatformCounter(page, expression, max, what) {
|
|
21804
|
+
const counter = await readPlatformCounter(page, expression);
|
|
21805
|
+
if (counter === null)
|
|
21806
|
+
return;
|
|
21807
|
+
const units = counterUnits(counter);
|
|
21808
|
+
if (units === null || units <= max)
|
|
21809
|
+
return;
|
|
21810
|
+
const message = `the ${what} counter reads '${counter}' \u2014 ${units} units over the platform limit of ${max}; shorten the ${what} before saving (xhs counts units: 2 half-width chars = 1 unit)`;
|
|
21811
|
+
throw what === "title" ? new TitleTooLongError(`TitleTooLongError: ${message}`) : new ContentTooLongError(`ContentTooLongError: ${message}`);
|
|
21812
|
+
}
|
|
21813
|
+
function trackSpectrumUploads(page) {
|
|
21814
|
+
let count = 0;
|
|
21815
|
+
let anySeen = 0;
|
|
21816
|
+
const handler = (payload) => {
|
|
21817
|
+
anySeen += 1;
|
|
21818
|
+
const response = payload;
|
|
21819
|
+
if (response.status() === 200 && /ros-upload\.xiaohongshu\.com\/spectrum\//.test(response.url())) {
|
|
21820
|
+
count += 1;
|
|
21821
|
+
}
|
|
21822
|
+
};
|
|
21823
|
+
page.onContextResponse?.(handler);
|
|
21824
|
+
return {
|
|
21825
|
+
completions: async () => count,
|
|
21826
|
+
seen: () => anySeen,
|
|
21827
|
+
dispose: () => page.offContextResponse?.(handler)
|
|
21828
|
+
};
|
|
21829
|
+
}
|
|
21830
|
+
async function confirmThumbnails(deps, expected, uploads) {
|
|
21564
21831
|
const selector = await findSelector(deps.page, NOTE_THUMBNAIL, "thumbnail wait", deps.stepTimeoutMs);
|
|
21565
|
-
const
|
|
21832
|
+
const allDurable = async () => {
|
|
21833
|
+
const verdict = await deps.page.evaluate(`(() => {
|
|
21834
|
+
const imgs = Array.from(document.querySelectorAll("${selector}"));
|
|
21835
|
+
if (imgs.length < ${expected}) return 'kk-thumb-pending';
|
|
21836
|
+
return imgs.every((img) => /^https?:/.test(img.getAttribute("src") || ""))
|
|
21837
|
+
? 'kk-thumb-all-durable'
|
|
21838
|
+
: 'kk-thumb-pending';
|
|
21839
|
+
})()`);
|
|
21840
|
+
if (verdict === "kk-thumb-all-durable")
|
|
21841
|
+
return true;
|
|
21842
|
+
return await uploads.completions() >= expected;
|
|
21843
|
+
};
|
|
21844
|
+
const matches = await waitUntil(allDurable, deps.stepTimeoutMs);
|
|
21566
21845
|
const observed = await deps.page.locator(selector).count();
|
|
21567
21846
|
if (!matches || observed !== expected) {
|
|
21568
|
-
|
|
21847
|
+
const pending = await deps.page.evaluate(`/* kk-count-local-srcs */ (() => {
|
|
21848
|
+
return Array.from(document.querySelectorAll("${selector}"))
|
|
21849
|
+
.filter((img) => !/^https?:/.test(img.getAttribute("src") || "")).length;
|
|
21850
|
+
})()`);
|
|
21851
|
+
throw new Error(`thumbnail count: expected ${expected} durable previews, observed ${observed} previews with ${String(pending)} still on a local (blob/data) src, wire completions ${await uploads.completions()} [flow-20261110b] \u2014 the ${deps.stepTimeoutMs}ms window expired before the console finished uploading`);
|
|
21852
|
+
}
|
|
21853
|
+
return { completions: await uploads.completions() };
|
|
21854
|
+
}
|
|
21855
|
+
async function enterImageMode(deps, label) {
|
|
21856
|
+
if (!deps.page.clickAt || !deps.page.boundingBoxesOnScreen) {
|
|
21857
|
+
throw new Error("mode entry (image): this driver cannot read viewport boxes or click coordinates");
|
|
21858
|
+
}
|
|
21859
|
+
await settleConsole(deps);
|
|
21860
|
+
const selector = `text=${label}`;
|
|
21861
|
+
const deadline = Date.now() + deps.stepTimeoutMs;
|
|
21862
|
+
while (Date.now() < deadline) {
|
|
21863
|
+
const boxes = await deps.page.boundingBoxesOnScreen(selector).catch(() => []);
|
|
21864
|
+
const box = boxes[0];
|
|
21865
|
+
if (box) {
|
|
21866
|
+
await deps.page.clickAt(box.x + box.width / 2, box.y + box.height / 2);
|
|
21867
|
+
await findSelector(deps.page, ["text=\u4E0A\u4F20\u56FE\u7247\uFF0C\u6216\u5199\u6587\u5B57\u751F\u6210\u56FE\u7247"], "image editor settle", deps.stepTimeoutMs);
|
|
21868
|
+
await new Promise((resolve) => setTimeout(resolve, IMAGE_MODE_SETTLE_MS));
|
|
21869
|
+
return;
|
|
21870
|
+
}
|
|
21871
|
+
await new Promise((resolve) => setTimeout(resolve, POLL_MS));
|
|
21872
|
+
}
|
|
21873
|
+
throw new Error(`mode entry: no on-screen '${label}' tab found within ${deps.stepTimeoutMs}ms \u2014 the mode was not entered`);
|
|
21874
|
+
}
|
|
21875
|
+
async function settleConsole(deps) {
|
|
21876
|
+
let lastResponseAt = Date.now();
|
|
21877
|
+
deps.page.onContextResponse?.(() => {
|
|
21878
|
+
lastResponseAt = Date.now();
|
|
21879
|
+
});
|
|
21880
|
+
try {
|
|
21881
|
+
const start = Date.now();
|
|
21882
|
+
while (Date.now() - start < CONSOLE_SETTLE_MS) {
|
|
21883
|
+
if (Date.now() - lastResponseAt >= CONSOLE_SETTLE_QUIET_MS)
|
|
21884
|
+
return;
|
|
21885
|
+
await new Promise((resolve) => setTimeout(resolve, POLL_MS));
|
|
21886
|
+
}
|
|
21887
|
+
} finally {
|
|
21888
|
+
deps.page.offContextResponse?.(() => {
|
|
21889
|
+
lastResponseAt = Date.now();
|
|
21890
|
+
});
|
|
21569
21891
|
}
|
|
21570
21892
|
}
|
|
21571
21893
|
async function composeImageText(input, deps) {
|
|
21572
|
-
await
|
|
21573
|
-
const fileSelector = await findAttachedSelector(deps.page,
|
|
21574
|
-
|
|
21575
|
-
|
|
21576
|
-
|
|
21577
|
-
|
|
21894
|
+
await enterImageMode(deps, input.operation);
|
|
21895
|
+
const fileSelector = await findAttachedSelector(deps.page, ['input[type="file"]'], "image file input", deps.stepTimeoutMs);
|
|
21896
|
+
const uploads = trackSpectrumUploads(deps.page);
|
|
21897
|
+
try {
|
|
21898
|
+
await deps.page.setInputFiles(fileSelector, input.images);
|
|
21899
|
+
const confirmed = await confirmThumbnails(deps, input.images.length, uploads);
|
|
21900
|
+
await applyNoteTitle(deps);
|
|
21901
|
+
await typeNoteBody(deps, NOTE_BODY, "note body");
|
|
21902
|
+
return confirmed.completions;
|
|
21903
|
+
} finally {
|
|
21904
|
+
uploads.dispose();
|
|
21905
|
+
}
|
|
21578
21906
|
}
|
|
21579
21907
|
async function composeVideo(input, deps) {
|
|
21580
21908
|
await enterMode(deps, input.operation);
|
|
@@ -21682,6 +22010,50 @@ async function composePodcast(input, deps) {
|
|
|
21682
22010
|
await uploadPodcastCover(deps, input.cover);
|
|
21683
22011
|
await podcastAdvanceReady(deps);
|
|
21684
22012
|
await leavePodcastModal(deps);
|
|
22013
|
+
await applyPodcastFields(deps);
|
|
22014
|
+
}
|
|
22015
|
+
function podcastCollection(content) {
|
|
22016
|
+
const declared = content.metadata?.collection;
|
|
22017
|
+
return typeof declared === "string" && declared.trim().length > 0 ? declared.trim() : PODCAST_COLLECTION_DEFAULT;
|
|
22018
|
+
}
|
|
22019
|
+
function clipLine(text, cap) {
|
|
22020
|
+
return text.length > cap ? `${text.slice(0, cap - 1)}\u2026` : text;
|
|
22021
|
+
}
|
|
22022
|
+
function derivePodcastBody(content, max = XHS_NOTE_BODY_MAX) {
|
|
22023
|
+
const lines = (content.body ?? "").split(`
|
|
22024
|
+
`).map((line) => line.trim()).filter((line) => line.length > 0);
|
|
22025
|
+
const prose = lines.filter((line) => !line.startsWith("#"));
|
|
22026
|
+
const introSource = prose[0] ?? content.title ?? "";
|
|
22027
|
+
const intro = clipLine(introSource, 80);
|
|
22028
|
+
const closing = prose.length > 1 ? clipLine(prose[prose.length - 1] ?? "", 60) : "";
|
|
22029
|
+
const budget = max - (closing.length > 0 ? closing.length + 1 : 0);
|
|
22030
|
+
const parts = [intro];
|
|
22031
|
+
let used = intro.length;
|
|
22032
|
+
for (const line of lines.filter((line) => line.startsWith("## "))) {
|
|
22033
|
+
const bullet = `\xB7 ${line.slice(3).trim()}`;
|
|
22034
|
+
if (used + bullet.length + 1 > budget)
|
|
22035
|
+
break;
|
|
22036
|
+
parts.push(bullet);
|
|
22037
|
+
used += bullet.length + 1;
|
|
22038
|
+
}
|
|
22039
|
+
if (closing.length > 0)
|
|
22040
|
+
parts.push(closing);
|
|
22041
|
+
return parts.join(`
|
|
22042
|
+
`).slice(0, max);
|
|
22043
|
+
}
|
|
22044
|
+
async function applyPodcastFields(deps) {
|
|
22045
|
+
const title = deps.content.title ?? "";
|
|
22046
|
+
if (title.length > 0) {
|
|
22047
|
+
const selector = await findSelector(deps.page, PODCAST_TITLE_SELECTORS, "podcast title input", deps.stepTimeoutMs);
|
|
22048
|
+
await deps.page.locator(selector).first().fill(title);
|
|
22049
|
+
}
|
|
22050
|
+
await assertPlatformCounter(deps.page, TITLE_COUNTER_EXPR, XHS_NOTE_TITLE_MAX, "title");
|
|
22051
|
+
const body = derivePodcastBody(deps.content, XHS_NOTE_BODY_MAX);
|
|
22052
|
+
await typeNoteBody(deps, NOTE_BODY, "podcast body", body);
|
|
22053
|
+
const collection = podcastCollection(deps.content);
|
|
22054
|
+
const chip = await findSelector(deps.page, PODCAST_COLLECTION_SELECTORS, "\u52A0\u5165\u64AD\u5BA2\u5408\u96C6 control", deps.stepTimeoutMs);
|
|
22055
|
+
await deps.page.locator(chip).first().click({ timeout: deps.stepTimeoutMs });
|
|
22056
|
+
await deps.page.locator(`text=${collection}`).first().click({ timeout: deps.stepTimeoutMs });
|
|
21685
22057
|
}
|
|
21686
22058
|
async function uploadPodcastCover(deps, cover) {
|
|
21687
22059
|
const zone = deps.page.locator(PODCAST_COVER_ZONE).first();
|
|
@@ -21768,17 +22140,16 @@ async function podcastAdvanceReady(deps) {
|
|
|
21768
22140
|
async function compose(input, deps) {
|
|
21769
22141
|
switch (input.operation) {
|
|
21770
22142
|
case "\u4E0A\u4F20\u56FE\u6587":
|
|
21771
|
-
await composeImageText(input, deps);
|
|
21772
|
-
return;
|
|
22143
|
+
return { wireCompletions: await composeImageText(input, deps) };
|
|
21773
22144
|
case "\u4E0A\u4F20\u89C6\u9891":
|
|
21774
22145
|
await composeVideo(input, deps);
|
|
21775
|
-
return;
|
|
22146
|
+
return {};
|
|
21776
22147
|
case "\u5199\u957F\u6587":
|
|
21777
22148
|
await composeArticle(deps);
|
|
21778
|
-
return;
|
|
22149
|
+
return {};
|
|
21779
22150
|
case "\u53D1\u64AD\u5BA2":
|
|
21780
22151
|
await composePodcast(input, deps);
|
|
21781
|
-
return;
|
|
22152
|
+
return {};
|
|
21782
22153
|
}
|
|
21783
22154
|
}
|
|
21784
22155
|
function baseMetadata(input, deps) {
|
|
@@ -21795,21 +22166,35 @@ async function saveDraft(input, deps) {
|
|
|
21795
22166
|
let clicked = null;
|
|
21796
22167
|
let signal = null;
|
|
21797
22168
|
let attempts = 0;
|
|
22169
|
+
let capture = null;
|
|
22170
|
+
await armOutcomeCapture(deps.page);
|
|
21798
22171
|
while (signal === null && attempts < deps.submitAttempts) {
|
|
21799
22172
|
attempts += 1;
|
|
21800
22173
|
await sleep2(deps.submitSettleMs);
|
|
21801
|
-
const
|
|
22174
|
+
const method = await invokeHostSave(deps.page);
|
|
22175
|
+
const control = method !== null ? { ok: true, path: "shadow", label: `_onSave:${method}`, click: "shadow-host-method" } : await clickActionControl(input.operation, deps, DRAFT_LABELS, "draft control");
|
|
21802
22176
|
if (!control.ok)
|
|
21803
22177
|
return fail(control.error);
|
|
21804
22178
|
clicked = control;
|
|
21805
|
-
const outcome = await expectOutcome(() =>
|
|
22179
|
+
const outcome = await expectOutcome(async () => {
|
|
22180
|
+
if (capture === null)
|
|
22181
|
+
capture = await readOutcomeCapture(deps.page);
|
|
22182
|
+
return draftSignalEvidence(deps.page, deps.draftBaseline);
|
|
22183
|
+
}, {
|
|
21806
22184
|
timeoutMs: deps.submitSettleMs,
|
|
21807
22185
|
label: `draft confirmation '${control.label}'`,
|
|
21808
22186
|
pollMs: POLL_MS
|
|
21809
22187
|
});
|
|
21810
22188
|
if (outcome.ok)
|
|
21811
22189
|
signal = outcome.evidence;
|
|
22190
|
+
else {
|
|
22191
|
+
capture = capture ?? await readOutcomeCapture(deps.page);
|
|
22192
|
+
assertCapturedOutcome(capture);
|
|
22193
|
+
}
|
|
21812
22194
|
}
|
|
22195
|
+
if (capture === null)
|
|
22196
|
+
capture = await readOutcomeCapture(deps.page);
|
|
22197
|
+
assertCapturedOutcome(capture);
|
|
21813
22198
|
const draftCountAfter = await readDraftCount(deps.page);
|
|
21814
22199
|
if (signal === null || clicked === null) {
|
|
21815
22200
|
return fail(`draft confirmation: '${clicked?.label ?? DRAFT_LABELS[0]}' was clicked ${attempts}\xD7 but neither a fresh ${TARGET} save timestamp, a moved draft counter, nor a scoped '${DRAFT_TOASTS[0]}' toast was observed within ${deps.submitSettleMs}ms (before=${String(deps.draftBaseline.count)}, after=${String(draftCountAfter)})`);
|
|
@@ -21826,22 +22211,30 @@ async function saveDraft(input, deps) {
|
|
|
21826
22211
|
draftAttempts: attempts,
|
|
21827
22212
|
draftSignal: signal,
|
|
21828
22213
|
draftCountBefore: deps.draftBaseline.count,
|
|
21829
|
-
draftCountAfter
|
|
22214
|
+
draftCountAfter,
|
|
22215
|
+
...captureMetadata(capture)
|
|
21830
22216
|
}
|
|
21831
22217
|
});
|
|
21832
22218
|
}
|
|
21833
22219
|
async function publishNote(input, deps) {
|
|
21834
22220
|
await sleep2(deps.submitSettleMs);
|
|
22221
|
+
let capture = null;
|
|
22222
|
+
await armOutcomeCapture(deps.page);
|
|
21835
22223
|
const submitted = await clickActionControl(input.operation, deps, PUBLISH_LABELS, "publish control");
|
|
21836
22224
|
if (!submitted.ok)
|
|
21837
22225
|
return fail(submitted.error);
|
|
21838
22226
|
const urlBeforeSubmit = deps.page.url();
|
|
21839
22227
|
const confirmed = await waitUntil(async () => {
|
|
22228
|
+
if (capture === null)
|
|
22229
|
+
capture = await readOutcomeCapture(deps.page);
|
|
22230
|
+
assertCapturedOutcome(capture);
|
|
21840
22231
|
if (deps.page.url().includes(PUBLISHED_MARKER))
|
|
21841
22232
|
return true;
|
|
21842
22233
|
return await readScopedSignal(asPlaywrightPage(deps.page), PUBLISH_CONFIRM) !== null;
|
|
21843
22234
|
}, deps.stepTimeoutMs);
|
|
21844
22235
|
if (!confirmed) {
|
|
22236
|
+
capture = capture ?? await readOutcomeCapture(deps.page);
|
|
22237
|
+
assertCapturedOutcome(capture);
|
|
21845
22238
|
return fail(`publish submission: state unknown \u2014 the '${submitted.label}' click (${submitted.click}) was sent from ${urlBeforeSubmit} but no success state was observed (now ${deps.page.url()}). Check the ${TARGET} creator note manager before retrying: a retry could duplicate the post.`);
|
|
21846
22239
|
}
|
|
21847
22240
|
const url = deps.page.url();
|
|
@@ -21855,13 +22248,148 @@ async function publishNote(input, deps) {
|
|
|
21855
22248
|
publishControl: submitted.label,
|
|
21856
22249
|
publishPath: submitted.path,
|
|
21857
22250
|
publishClick: submitted.click,
|
|
21858
|
-
publishSignal: url.includes(PUBLISHED_MARKER) ? `url:${PUBLISHED_MARKER}` : "toast"
|
|
22251
|
+
publishSignal: url.includes(PUBLISHED_MARKER) ? `url:${PUBLISHED_MARKER}` : "toast",
|
|
22252
|
+
...captureMetadata(capture)
|
|
21859
22253
|
}
|
|
21860
22254
|
});
|
|
21861
22255
|
}
|
|
22256
|
+
function draftExpectation(input, deps) {
|
|
22257
|
+
switch (input.operation) {
|
|
22258
|
+
case "\u4E0A\u4F20\u56FE\u6587":
|
|
22259
|
+
return {
|
|
22260
|
+
slots: input.images.length,
|
|
22261
|
+
title: true,
|
|
22262
|
+
body: (deps.content.body ?? "").trim().length > 0,
|
|
22263
|
+
collection: null
|
|
22264
|
+
};
|
|
22265
|
+
case "\u4E0A\u4F20\u89C6\u9891":
|
|
22266
|
+
return { slots: null, title: true, body: (deps.content.body ?? "").trim().length > 0, collection: null };
|
|
22267
|
+
case "\u5199\u957F\u6587":
|
|
22268
|
+
return { slots: null, title: false, body: true, collection: null };
|
|
22269
|
+
case "\u53D1\u64AD\u5BA2":
|
|
22270
|
+
return { slots: null, title: true, body: true, collection: podcastCollection(deps.content) };
|
|
22271
|
+
}
|
|
22272
|
+
}
|
|
22273
|
+
var DRAFT_NAV_SELECTOR = "text=\u8349\u7A3F\u7BB1";
|
|
22274
|
+
var DRAFT_EDIT_SELECTOR = "text=\u7F16\u8F91";
|
|
22275
|
+
var VERIFY_SLOTS_EXPR = `/* kk-verify-slots */ (() => JSON.stringify({ count: document.querySelectorAll('img.preivew-image').length }))()`;
|
|
22276
|
+
var VERIFY_SRCS_EXPR = `/* kk-verify-srcs */ (() => JSON.stringify(Array.from(document.querySelectorAll('img.preivew-image')).map((img) => img.getAttribute('src') || '')))()`;
|
|
22277
|
+
var VERIFY_TITLE_EXPR = `/* kk-verify-title */ (() => {
|
|
22278
|
+
const input = document.querySelector('input.d-text') || document.querySelector('textarea[placeholder*="\u6807\u9898"]');
|
|
22279
|
+
return input ? (input.value || '') : '';
|
|
22280
|
+
})()`;
|
|
22281
|
+
var VERIFY_BODY_EXPR = `/* kk-verify-body */ (() => {
|
|
22282
|
+
for (const node of document.querySelectorAll('div.edit-container *')) {
|
|
22283
|
+
const t = (node.textContent || '').trim();
|
|
22284
|
+
if (/^\\d+\\/\\d+$/.test(t) && node.children.length === 0) return JSON.stringify({ counter: t });
|
|
22285
|
+
}
|
|
22286
|
+
const editor = document.querySelector('div.tiptap, .ProseMirror, .ql-editor');
|
|
22287
|
+
return JSON.stringify({ textLen: (editor?.textContent || '').trim().length });
|
|
22288
|
+
})()`;
|
|
22289
|
+
function collectionProbeExpr(collection) {
|
|
22290
|
+
const literal = JSON.stringify(collection);
|
|
22291
|
+
return `/* kk-verify-collection */ (() => (document.body.innerText.includes(${literal}) ? 'kk-verify-collection:yes' : 'kk-verify-collection:no'))()`;
|
|
22292
|
+
}
|
|
22293
|
+
async function verifyDraft(input, deps, wired) {
|
|
22294
|
+
const expectation = draftExpectation(input, deps);
|
|
22295
|
+
const nav = deps.page.locator(DRAFT_NAV_SELECTOR);
|
|
22296
|
+
const navAppeared = await waitUntil(async () => await nav.count().catch(() => 0) > 0, deps.stepTimeoutMs, POLL_MS);
|
|
22297
|
+
if (!navAppeared) {
|
|
22298
|
+
throw new DraftVerifyError(`DraftVerifyError: could not reopen the saved draft \u2014 '${DRAFT_NAV_SELECTOR}' matched nothing within ${deps.stepTimeoutMs}ms after the save; verify the draft box manually in profile ${deps.profileDir}`);
|
|
22299
|
+
}
|
|
22300
|
+
const navBox = (await deps.page.boundingBoxesOnScreen?.(DRAFT_NAV_SELECTOR).catch(() => []))?.[0];
|
|
22301
|
+
if (navBox && deps.page.clickAt) {
|
|
22302
|
+
await deps.page.clickAt(navBox.x + navBox.width / 2, navBox.y + navBox.height / 2);
|
|
22303
|
+
} else {
|
|
22304
|
+
await nav.first().click({ timeout: deps.stepTimeoutMs });
|
|
22305
|
+
}
|
|
22306
|
+
const edit = deps.page.locator(DRAFT_EDIT_SELECTOR);
|
|
22307
|
+
if (await edit.count().catch(() => 0) === 0) {
|
|
22308
|
+
throw new DraftVerifyError(`DraftVerifyError: the draft list shows no '${DRAFT_EDIT_SELECTOR}' control to reopen the saved note (2026-11-11 evidence: \u7F16\u8F91 1/18 on the draft list)`);
|
|
22309
|
+
}
|
|
22310
|
+
const editBox = (await deps.page.boundingBoxesOnScreen?.(DRAFT_EDIT_SELECTOR).catch(() => []))?.[0];
|
|
22311
|
+
if (editBox && deps.page.clickAt) {
|
|
22312
|
+
await deps.page.clickAt(editBox.x + editBox.width / 2, editBox.y + editBox.height / 2);
|
|
22313
|
+
} else {
|
|
22314
|
+
await edit.first().click({ timeout: deps.stepTimeoutMs });
|
|
22315
|
+
}
|
|
22316
|
+
const editorReady = await waitUntil(async () => {
|
|
22317
|
+
const slotsRead = await deps.page.evaluate(VERIFY_SLOTS_EXPR).catch(() => null);
|
|
22318
|
+
const titleRead = await deps.page.evaluate(VERIFY_TITLE_EXPR).catch(() => null);
|
|
22319
|
+
const bodyRead = await deps.page.evaluate(VERIFY_BODY_EXPR).catch(() => null);
|
|
22320
|
+
const count = typeof slotsRead === "string" ? JSON.parse(slotsRead).count : 0;
|
|
22321
|
+
const title = typeof titleRead === "string" ? titleRead : "";
|
|
22322
|
+
const body = typeof bodyRead === "string" ? JSON.parse(bodyRead) : {};
|
|
22323
|
+
const slotsVisible = expectation.slots !== null && (count ?? 0) > 0;
|
|
22324
|
+
const titleVisible = expectation.title && title.length > 0;
|
|
22325
|
+
const bodyVisible = expectation.body && (body.counter !== undefined || (body.textLen ?? 0) > 0);
|
|
22326
|
+
return Boolean(slotsVisible || titleVisible || bodyVisible);
|
|
22327
|
+
}, deps.stepTimeoutMs, POLL_MS);
|
|
22328
|
+
const problems = [];
|
|
22329
|
+
if (!editorReady) {
|
|
22330
|
+
problems.push("the reopened editor never rendered content within the step window (0 thumbnails, empty title)");
|
|
22331
|
+
}
|
|
22332
|
+
if (expectation.slots !== null) {
|
|
22333
|
+
const slotsRead = await deps.page.evaluate(VERIFY_SLOTS_EXPR);
|
|
22334
|
+
const count = typeof slotsRead === "string" ? JSON.parse(slotsRead).count : null;
|
|
22335
|
+
if (count !== expectation.slots) {
|
|
22336
|
+
problems.push(`expected ${expectation.slots} thumbnails on the reopened draft, the editor shows ${String(count)}`);
|
|
22337
|
+
} else {
|
|
22338
|
+
const srcsRead = await deps.page.evaluate(VERIFY_SRCS_EXPR);
|
|
22339
|
+
const srcs = typeof srcsRead === "string" ? JSON.parse(srcsRead) : [];
|
|
22340
|
+
const local = srcs.map((src, index) => src.startsWith("https://") ? null : index + 1).filter((slot) => slot !== null);
|
|
22341
|
+
const wireDone = expectation.slots !== null && (wired?.wireCompletions ?? 0) >= expectation.slots && count === expectation.slots;
|
|
22342
|
+
if (local.length > 0 && !wireDone) {
|
|
22343
|
+
problems.push(`slots ${local.join(", ")} still carry a non-https (blob/data/local) src \u2014 the server-side copy is missing`);
|
|
22344
|
+
}
|
|
22345
|
+
}
|
|
22346
|
+
}
|
|
22347
|
+
if (expectation.title) {
|
|
22348
|
+
const editorTitle = String(await deps.page.evaluate(VERIFY_TITLE_EXPR) ?? "");
|
|
22349
|
+
if (editorTitle !== (deps.content.title ?? "")) {
|
|
22350
|
+
problems.push(`title mismatch: content '${deps.content.title ?? ""}' vs reopened draft '${editorTitle}'`);
|
|
22351
|
+
}
|
|
22352
|
+
}
|
|
22353
|
+
if (expectation.body) {
|
|
22354
|
+
const bodyRead = await deps.page.evaluate(VERIFY_BODY_EXPR);
|
|
22355
|
+
const parsed = typeof bodyRead === "string" ? JSON.parse(bodyRead) : {};
|
|
22356
|
+
const units = parsed.counter !== undefined ? counterUnits(parsed.counter) : null;
|
|
22357
|
+
if (!((units ?? 0) > 0) && !((parsed.textLen ?? 0) > 0)) {
|
|
22358
|
+
problems.push("body: the reopened draft shows neither a readable N/M counter nor editor text");
|
|
22359
|
+
}
|
|
22360
|
+
}
|
|
22361
|
+
if (expectation.collection !== null) {
|
|
22362
|
+
const verdict = await deps.page.evaluate(collectionProbeExpr(expectation.collection));
|
|
22363
|
+
if (verdict !== "kk-verify-collection:yes") {
|
|
22364
|
+
problems.push(`collection: the reopened podcast draft does not show '${expectation.collection}'`);
|
|
22365
|
+
}
|
|
22366
|
+
}
|
|
22367
|
+
await deps.page.goto(PUBLISH_URL);
|
|
22368
|
+
if (problems.length > 0) {
|
|
22369
|
+
throw new DraftVerifyError(`DraftVerifyError: the saved draft does not verify after reopen \u2014 ${problems.join("; ")}`);
|
|
22370
|
+
}
|
|
22371
|
+
return {
|
|
22372
|
+
...expectation.slots !== null ? { slots: expectation.slots } : {},
|
|
22373
|
+
...expectation.title ? { titleChecked: true } : {},
|
|
22374
|
+
...expectation.body ? { bodyChecked: true } : {},
|
|
22375
|
+
...expectation.collection !== null ? { collection: expectation.collection } : {}
|
|
22376
|
+
};
|
|
22377
|
+
}
|
|
21862
22378
|
async function runMode(input, deps) {
|
|
21863
|
-
await compose(input, deps);
|
|
21864
|
-
|
|
22379
|
+
const wired = await compose(input, deps);
|
|
22380
|
+
if (deps.publishStatus === "public")
|
|
22381
|
+
return publishNote(input, deps);
|
|
22382
|
+
const saved = await saveDraft(input, deps);
|
|
22383
|
+
if (!saved.ok)
|
|
22384
|
+
return saved;
|
|
22385
|
+
let verified;
|
|
22386
|
+
try {
|
|
22387
|
+
verified = await verifyDraft(input, deps, wired);
|
|
22388
|
+
} catch (error) {
|
|
22389
|
+
const reason = error instanceof Error ? error.message : String(error);
|
|
22390
|
+
return fail(`draft saved but the reopen verification failed: ${reason}`);
|
|
22391
|
+
}
|
|
22392
|
+
return ResultSchema.parse({ ...saved, metadata: { ...saved.metadata, draftVerified: verified } });
|
|
21865
22393
|
}
|
|
21866
22394
|
|
|
21867
22395
|
// ../../plugins/publishings/xhs-pub/src/index.ts
|