@gobing-ai/knowledge-kit 0.1.17 → 0.1.20
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.claude-plugin/marketplace.json +1 -1
- package/dist/board/daily-voice/index.js +40 -7
- package/dist/index.js +8428 -4448
- package/package.json +1 -1
- package/plugins/generations/image-gen/README.md +31 -31
- package/plugins/generations/image-gen/assets/sample/provenance.json +314 -0
- package/plugins/generations/image-gen/config.example.yaml +3 -0
- package/plugins/generations/image-gen/dist/index.js +154 -14
- package/plugins/generations/image-gen/presets/SOURCE.md +65 -0
- package/plugins/generations/image-gen/scripts/eval-style-presets.ts +513 -0
- package/plugins/generations/image-gen/scripts/gen-samples.ts +57 -7
- package/plugins/generations/image-gen/src/presets.ts +6 -5
- package/plugins/generations/image-gen/src/providers/h3-local.ts +196 -0
- package/plugins/generations/image-gen/src/providers/types.ts +11 -1
- package/plugins/kk/config.example.yaml +7 -2
- package/plugins/kk/decisions/extract/ai-news.yaml +5 -2
- package/plugins/kk/plugin.json +1 -1
- package/plugins/kk/publish-presets/chinese-article.json +8 -2
- package/plugins/kk/publish-presets/daily-ai-voice-migration.json +1 -1
- package/plugins/kk/publish-presets/daily-ai-voice.json +57 -16
- package/plugins/kk/publish-presets/itc-main.json +36 -9
- package/plugins/kk/publish-presets/technical-article.json +8 -2
- package/plugins/kk/schedules/kk-daily-ai-voice3.cron.tmpl +8 -9
- package/plugins/kk/schedules/kk-daily-publish3-cn-peak.cron.tmpl +13 -19
- package/plugins/kk/schedules/kk-daily-publish3-overseas.cron.tmpl +11 -9
- package/plugins/kk/scripts/daily-stages.ts +238 -14
- package/plugins/kk/scripts/daily-triage-core.ts +43 -25
- package/plugins/kk/scripts/daily-triage.ts +1 -1
- package/plugins/kk/skills/image-authoring/SKILL.md +7 -3
- package/plugins/kk/skills/image-authoring/references/providers.md +27 -0
- package/plugins/kk/skills/image-authoring/references/style-extraction.md +1 -1
- package/plugins/kk/skills/publish/SKILL.md +15 -2
- package/plugins/kk/skills/web-automation/SKILL.md +31 -1
- package/plugins/kk/workflows/kk-article-generate.yaml +485 -0
- package/plugins/kk/workflows/kk-collect.yaml +8 -4
- package/plugins/kk/workflows/kk-daily-ai-voice.yaml +2 -1
- package/plugins/kk/workflows/kk-daily-ai-voice2.yaml +4 -2
- package/plugins/kk/workflows/kk-daily-safety.yaml +5 -7
- package/plugins/kk/workflows/kk-news-generate.yaml +410 -0
- package/plugins/kk/workflows/kk-publish.yaml +236 -0
- package/plugins/publishings/bilibili-pub/dist/profile-check.js +49 -10
- package/plugins/publishings/cnblogs-pub/dist/profile-check.js +60 -10
- package/plugins/publishings/csdn-pub/dist/profile-check.js +60 -10
- package/plugins/publishings/infoq-pub/dist/profile-check.js +60 -10
- package/plugins/publishings/jike-pub/dist/profile-check.js +60 -10
- package/plugins/publishings/juejin-pub/dist/profile-check.js +60 -10
- package/plugins/publishings/linkedin-pub/dist/index.js +43 -6
- package/plugins/publishings/linkedin-pub/dist/profile-check.js +92 -15
- package/plugins/publishings/linkedin-pub/src/index.ts +52 -6
- package/plugins/publishings/shipinhao-pub/dist/index.js +391 -32
- package/plugins/publishings/shipinhao-pub/dist/profile-check.js +52 -11
- package/plugins/publishings/shipinhao-pub/plugin.json +1 -1
- package/plugins/publishings/shipinhao-pub/src/audio-flow.ts +393 -0
- package/plugins/publishings/shipinhao-pub/src/flow.ts +243 -14
- package/plugins/publishings/shipinhao-pub/src/selectors.ts +13 -0
- package/plugins/publishings/sspai-pub/dist/profile-check.js +60 -10
- package/plugins/publishings/substack-pub/dist/profile-check.js +60 -10
- package/plugins/publishings/surfdash-pub/dist/index.js +50 -8
- package/plugins/publishings/surfdash-pub/src/index.ts +59 -8
- package/plugins/publishings/surfdash-pub/src/topic-claims.ts +34 -3
- package/plugins/publishings/threads-pub/dist/index.js +9196 -296
- package/plugins/publishings/threads-pub/dist/profile-check.js +21139 -0
- package/plugins/publishings/threads-pub/package.json +3 -1
- package/plugins/publishings/threads-pub/plugin.json +6 -1
- package/plugins/publishings/threads-pub/src/index.ts +8 -1
- package/plugins/publishings/threads-pub/src/post-rail.ts +357 -0
- package/plugins/publishings/threads-pub/src/profile-check.ts +17 -0
- package/plugins/publishings/wechatmp-pub/dist/index.js +454 -81
- package/plugins/publishings/wechatmp-pub/dist/profile-check.js +401 -102
- package/plugins/publishings/wechatmp-pub/src/flow.ts +42 -4
- package/plugins/publishings/wechatmp-pub/src/index.ts +142 -102
- package/plugins/publishings/wechatmp-pub/src/profile-check.ts +36 -58
- package/plugins/publishings/weibo-pub/dist/index.js +136 -22
- package/plugins/publishings/weibo-pub/dist/profile-check.js +61 -11
- package/plugins/publishings/weibo-pub/src/index.ts +208 -22
- package/plugins/publishings/x-pub/dist/index.js +263 -43
- package/plugins/publishings/x-pub/dist/profile-check.js +63 -11
- package/plugins/publishings/x-pub/src/index.ts +15 -1
- package/plugins/publishings/x-pub/src/post-rail.ts +334 -0
- package/plugins/publishings/xhs-pub/dist/index.js +193 -201
- package/plugins/publishings/xhs-pub/dist/profile-check.js +380 -85
- package/plugins/publishings/xhs-pub/src/automation-guard.ts +2 -3
- package/plugins/publishings/xhs-pub/src/flow.ts +177 -205
- package/plugins/publishings/xhs-pub/src/index.ts +65 -59
- package/plugins/publishings/xhs-pub/src/modes.ts +1 -1
- package/plugins/publishings/xhs-pub/src/page.ts +2 -2
- package/plugins/publishings/xhs-pub/src/profile-check.ts +86 -150
- package/plugins/publishings/xiaoyuzhou-pub/dist/profile-check.js +60 -10
- package/plugins/kk/scripts/daily-scheduled-run.ts +0 -581
- package/plugins/kk/scripts/voice3-publish-window.ts +0 -206
- package/plugins/kk/workflows/kk-daily-ai-voice3.yaml +0 -903
- package/plugins/kk/workflows/kk-daily-publish3.yaml +0 -353
- package/plugins/kk/workflows/kk-itc-author.yaml +0 -484
- package/plugins/kk/workflows/kk-itc-publish-tail.yaml +0 -112
- package/plugins/kk/workflows/kk-itc.yaml +0 -291
|
@@ -21626,98 +21626,70 @@ async function invokeHostSave(page) {
|
|
|
21626
21626
|
return null;
|
|
21627
21627
|
}
|
|
21628
21628
|
}
|
|
21629
|
-
var
|
|
21630
|
-
|
|
21631
|
-
|
|
21632
|
-
|
|
21633
|
-
|
|
21634
|
-
|
|
21635
|
-
|
|
21636
|
-
|
|
21637
|
-
|
|
21638
|
-
|
|
21639
|
-
|
|
21640
|
-
|
|
21641
|
-
const matches = (text) => signatures.some((re) => re.test(text));
|
|
21642
|
-
const record = (source, text) => {
|
|
21643
|
-
if (w.__kkXhsOutcome) return;
|
|
21644
|
-
const asString = String(text || '');
|
|
21645
|
-
if (!asString || !matches(asString)) return;
|
|
21646
|
-
w.__kkXhsOutcome = { source: source, text: asString.slice(0, 800) };
|
|
21647
|
-
};
|
|
21648
|
-
const proto = XMLHttpRequest.prototype;
|
|
21649
|
-
if (!proto.__kkPatched) {
|
|
21650
|
-
proto.__kkPatched = true;
|
|
21651
|
-
const open = proto.open;
|
|
21652
|
-
const send = proto.send;
|
|
21653
|
-
proto.open = function (method, url) { this.__kkUrl = url; return open.apply(this, arguments); };
|
|
21654
|
-
proto.send = function () {
|
|
21655
|
-
this.addEventListener('loadend', () => {
|
|
21656
|
-
try { record('xhr', (this.__kkUrl || '') + ' ' + this.responseText); } catch (e) {}
|
|
21657
|
-
});
|
|
21658
|
-
return send.apply(this, arguments);
|
|
21659
|
-
};
|
|
21629
|
+
var RISK_LEAVES_EXPR = `/* kk-risk-leaves */ (() => JSON.stringify(
|
|
21630
|
+
Array.from(document.querySelectorAll('body *')).filter((el) => el.children.length === 0)
|
|
21631
|
+
.map((el) => String(el.textContent || '').trim())
|
|
21632
|
+
.filter((text) => text.length > 0 && text.length <= 300 && /\u7981\u6B62\u53D1\u7B14\u8BB0|\u8FDD\u53CD|\u8FDD\u89C4|\u5BA1\u6838\u672A\u901A\u8FC7|\u8D26\u53F7\u5F02\u5E38|\u65E0\u6CD5\u53D1\u5E03/.test(text))
|
|
21633
|
+
))()`;
|
|
21634
|
+
async function armOutcomeCapture(page, timeoutMs) {
|
|
21635
|
+
const riskLeaves = async () => {
|
|
21636
|
+
try {
|
|
21637
|
+
const value = JSON.parse(String(await page.evaluate(RISK_LEAVES_EXPR)));
|
|
21638
|
+
return Array.isArray(value) ? value.filter((text) => typeof text === "string") : [];
|
|
21639
|
+
} catch {
|
|
21640
|
+
return [];
|
|
21660
21641
|
}
|
|
21661
|
-
|
|
21662
|
-
|
|
21663
|
-
|
|
21664
|
-
|
|
21665
|
-
|
|
21666
|
-
|
|
21667
|
-
|
|
21668
|
-
return response;
|
|
21669
|
-
});
|
|
21670
|
-
};
|
|
21671
|
-
w.fetch.__kkPatched = true;
|
|
21672
|
-
}
|
|
21673
|
-
if (!console.__kkPatched) {
|
|
21674
|
-
console.__kkPatched = true;
|
|
21675
|
-
for (const key of ['error', 'warn', 'log']) {
|
|
21676
|
-
const original = console[key].bind(console);
|
|
21677
|
-
console[key] = function () {
|
|
21678
|
-
try { record('console', Array.prototype.map.call(arguments, String).join(' ')); } catch (e) {}
|
|
21679
|
-
original.apply(console, arguments);
|
|
21680
|
-
};
|
|
21681
|
-
}
|
|
21642
|
+
};
|
|
21643
|
+
const baseline = new Set(await riskLeaves());
|
|
21644
|
+
let capture = null;
|
|
21645
|
+
const pending = new Set;
|
|
21646
|
+
const record = (source, text) => {
|
|
21647
|
+
if (capture === null && /HTTPBizError|"code"\s*:\s*-913\d|note_id|\u7981\u6B62\u53D1\u7B14\u8BB0|\u8FDD\u53CD|\u8FDD\u89C4|\u5BA1\u6838\u672A\u901A\u8FC7|\u8D26\u53F7\u5F02\u5E38|\u65E0\u6CD5\u53D1\u5E03/.test(text)) {
|
|
21648
|
+
capture = { source, text: text.slice(0, 800) };
|
|
21682
21649
|
}
|
|
21683
|
-
|
|
21684
|
-
|
|
21685
|
-
|
|
21686
|
-
|
|
21687
|
-
|
|
21688
|
-
|
|
21689
|
-
|
|
21690
|
-
|
|
21691
|
-
|
|
21692
|
-
|
|
21693
|
-
|
|
21694
|
-
|
|
21695
|
-
|
|
21696
|
-
|
|
21697
|
-
|
|
21698
|
-
|
|
21650
|
+
};
|
|
21651
|
+
const responseHandler = (payload) => {
|
|
21652
|
+
const read = (async () => {
|
|
21653
|
+
let timer;
|
|
21654
|
+
try {
|
|
21655
|
+
const response = payload;
|
|
21656
|
+
const source = response.request?.().resourceType();
|
|
21657
|
+
if (source !== "xhr" && source !== "fetch")
|
|
21658
|
+
return;
|
|
21659
|
+
const text = await Promise.race([
|
|
21660
|
+
response.text(),
|
|
21661
|
+
new Promise((resolve) => {
|
|
21662
|
+
timer = setTimeout(() => resolve(""), timeoutMs);
|
|
21663
|
+
})
|
|
21664
|
+
]);
|
|
21665
|
+
record(source, text);
|
|
21666
|
+
} catch {} finally {
|
|
21667
|
+
clearTimeout(timer);
|
|
21668
|
+
}
|
|
21669
|
+
})();
|
|
21670
|
+
pending.add(read);
|
|
21671
|
+
read.finally(() => pending.delete(read));
|
|
21672
|
+
};
|
|
21673
|
+
const consoleHandler = (payload) => {
|
|
21674
|
+
try {
|
|
21675
|
+
record("console", payload.text());
|
|
21676
|
+
} catch {}
|
|
21677
|
+
};
|
|
21678
|
+
page.onContextResponse?.(responseHandler);
|
|
21679
|
+
page.on?.("console", consoleHandler);
|
|
21680
|
+
return {
|
|
21681
|
+
read: async () => {
|
|
21682
|
+
await Promise.all(pending);
|
|
21683
|
+
for (const text of await riskLeaves())
|
|
21684
|
+
if (!baseline.has(text))
|
|
21685
|
+
record("toast", text);
|
|
21686
|
+
return capture;
|
|
21687
|
+
},
|
|
21688
|
+
dispose: () => {
|
|
21689
|
+
page.offContextResponse?.(responseHandler);
|
|
21690
|
+
page.off?.("console", consoleHandler);
|
|
21699
21691
|
}
|
|
21700
|
-
|
|
21701
|
-
})()`;
|
|
21702
|
-
var CAPTURE_READ_EXPR = `/* kk-capture-read */ (() => {
|
|
21703
|
-
const captured = window.__kkXhsOutcome;
|
|
21704
|
-
return captured ? JSON.stringify(captured) : 'kk-capture-none';
|
|
21705
|
-
})()`;
|
|
21706
|
-
async function armOutcomeCapture(page) {
|
|
21707
|
-
try {
|
|
21708
|
-
await page.evaluate(CAPTURE_INJECT_EXPR);
|
|
21709
|
-
} catch {}
|
|
21710
|
-
}
|
|
21711
|
-
async function readOutcomeCapture(page) {
|
|
21712
|
-
try {
|
|
21713
|
-
const read = await page.evaluate(CAPTURE_READ_EXPR);
|
|
21714
|
-
if (typeof read !== "string" || !read.startsWith("{"))
|
|
21715
|
-
return null;
|
|
21716
|
-
const parsed = JSON.parse(read);
|
|
21717
|
-
return typeof parsed.source === "string" && typeof parsed.text === "string" ? { source: parsed.source, text: parsed.text } : null;
|
|
21718
|
-
} catch {
|
|
21719
|
-
return null;
|
|
21720
|
-
}
|
|
21692
|
+
};
|
|
21721
21693
|
}
|
|
21722
21694
|
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/;
|
|
21723
21695
|
var CODE_SIGNATURE = /"code"\s*:\s*(-?\d+)/;
|
|
@@ -21947,9 +21919,10 @@ async function enterImageMode(deps, label) {
|
|
|
21947
21919
|
}
|
|
21948
21920
|
async function settleConsole(deps) {
|
|
21949
21921
|
let lastResponseAt = Date.now();
|
|
21950
|
-
|
|
21922
|
+
const handler = () => {
|
|
21951
21923
|
lastResponseAt = Date.now();
|
|
21952
|
-
}
|
|
21924
|
+
};
|
|
21925
|
+
deps.page.onContextResponse?.(handler);
|
|
21953
21926
|
try {
|
|
21954
21927
|
const start = Date.now();
|
|
21955
21928
|
while (Date.now() - start < CONSOLE_SETTLE_MS) {
|
|
@@ -21958,9 +21931,7 @@ async function settleConsole(deps) {
|
|
|
21958
21931
|
await new Promise((resolve) => setTimeout(resolve, POLL_MS));
|
|
21959
21932
|
}
|
|
21960
21933
|
} finally {
|
|
21961
|
-
deps.page.offContextResponse?.(
|
|
21962
|
-
lastResponseAt = Date.now();
|
|
21963
|
-
});
|
|
21934
|
+
deps.page.offContextResponse?.(handler);
|
|
21964
21935
|
}
|
|
21965
21936
|
}
|
|
21966
21937
|
async function composeImageText(input, deps) {
|
|
@@ -22240,91 +22211,99 @@ async function saveDraft(input, deps) {
|
|
|
22240
22211
|
let signal = null;
|
|
22241
22212
|
let attempts = 0;
|
|
22242
22213
|
let capture = null;
|
|
22243
|
-
await armOutcomeCapture(deps.page);
|
|
22244
|
-
|
|
22245
|
-
attempts
|
|
22246
|
-
|
|
22247
|
-
|
|
22248
|
-
|
|
22249
|
-
|
|
22250
|
-
|
|
22251
|
-
|
|
22252
|
-
|
|
22253
|
-
|
|
22254
|
-
capture
|
|
22255
|
-
|
|
22256
|
-
|
|
22257
|
-
|
|
22258
|
-
|
|
22259
|
-
|
|
22260
|
-
|
|
22261
|
-
|
|
22262
|
-
|
|
22263
|
-
|
|
22264
|
-
|
|
22265
|
-
|
|
22214
|
+
const outcomeCapture = await armOutcomeCapture(deps.page, deps.stepTimeoutMs);
|
|
22215
|
+
try {
|
|
22216
|
+
while (signal === null && attempts < deps.submitAttempts) {
|
|
22217
|
+
attempts += 1;
|
|
22218
|
+
await sleep2(deps.submitSettleMs);
|
|
22219
|
+
const method = await invokeHostSave(deps.page);
|
|
22220
|
+
const control = method !== null ? { ok: true, path: "shadow", label: `_onSave:${method}`, click: "shadow-host-method" } : await clickActionControl(input.operation, deps, DRAFT_LABELS, "draft control");
|
|
22221
|
+
if (!control.ok)
|
|
22222
|
+
return fail(control.error);
|
|
22223
|
+
clicked = control;
|
|
22224
|
+
const outcome = await expectOutcome(async () => {
|
|
22225
|
+
if (capture === null)
|
|
22226
|
+
capture = await outcomeCapture.read();
|
|
22227
|
+
return draftSignalEvidence(deps.page, deps.draftBaseline);
|
|
22228
|
+
}, {
|
|
22229
|
+
timeoutMs: deps.submitSettleMs,
|
|
22230
|
+
label: `draft confirmation '${control.label}'`,
|
|
22231
|
+
pollMs: POLL_MS
|
|
22232
|
+
});
|
|
22233
|
+
if (outcome.ok)
|
|
22234
|
+
signal = outcome.evidence;
|
|
22235
|
+
else {
|
|
22236
|
+
capture = capture ?? await outcomeCapture.read();
|
|
22237
|
+
assertCapturedOutcome(capture);
|
|
22238
|
+
}
|
|
22266
22239
|
}
|
|
22267
|
-
|
|
22268
|
-
|
|
22269
|
-
capture
|
|
22270
|
-
|
|
22271
|
-
|
|
22272
|
-
|
|
22273
|
-
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)})`);
|
|
22274
|
-
}
|
|
22275
|
-
return ResultSchema.parse({
|
|
22276
|
-
ok: true,
|
|
22277
|
-
target: TARGET,
|
|
22278
|
-
message: `${TARGET} draft saved (unpublished) in profile ${deps.profileDir} via '${clicked.label}' (${input.operation})`,
|
|
22279
|
-
metadata: {
|
|
22280
|
-
...baseMetadata(input, deps),
|
|
22281
|
-
draftControl: clicked.label,
|
|
22282
|
-
draftClick: clicked.click,
|
|
22283
|
-
draftPath: clicked.path,
|
|
22284
|
-
draftAttempts: attempts,
|
|
22285
|
-
draftSignal: signal,
|
|
22286
|
-
draftCountBefore: deps.draftBaseline.count,
|
|
22287
|
-
draftCountAfter,
|
|
22288
|
-
...captureMetadata(capture)
|
|
22240
|
+
if (capture === null)
|
|
22241
|
+
capture = await outcomeCapture.read();
|
|
22242
|
+
assertCapturedOutcome(capture);
|
|
22243
|
+
const draftCountAfter = await readDraftCount(deps.page);
|
|
22244
|
+
if (signal === null || clicked === null) {
|
|
22245
|
+
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)})`);
|
|
22289
22246
|
}
|
|
22290
|
-
|
|
22247
|
+
return ResultSchema.parse({
|
|
22248
|
+
ok: true,
|
|
22249
|
+
target: TARGET,
|
|
22250
|
+
message: `${TARGET} draft saved (unpublished) in profile ${deps.profileDir} via '${clicked.label}' (${input.operation})`,
|
|
22251
|
+
metadata: {
|
|
22252
|
+
...baseMetadata(input, deps),
|
|
22253
|
+
draftControl: clicked.label,
|
|
22254
|
+
draftClick: clicked.click,
|
|
22255
|
+
draftPath: clicked.path,
|
|
22256
|
+
draftAttempts: attempts,
|
|
22257
|
+
draftSignal: signal,
|
|
22258
|
+
draftCountBefore: deps.draftBaseline.count,
|
|
22259
|
+
draftCountAfter,
|
|
22260
|
+
...captureMetadata(capture)
|
|
22261
|
+
}
|
|
22262
|
+
});
|
|
22263
|
+
} finally {
|
|
22264
|
+
outcomeCapture.dispose();
|
|
22265
|
+
}
|
|
22291
22266
|
}
|
|
22292
22267
|
async function publishNote(input, deps) {
|
|
22293
22268
|
await sleep2(deps.submitSettleMs);
|
|
22294
22269
|
let capture = null;
|
|
22295
|
-
await armOutcomeCapture(deps.page);
|
|
22296
|
-
|
|
22297
|
-
|
|
22298
|
-
|
|
22299
|
-
|
|
22300
|
-
|
|
22301
|
-
|
|
22302
|
-
capture
|
|
22303
|
-
|
|
22304
|
-
|
|
22305
|
-
|
|
22306
|
-
|
|
22307
|
-
|
|
22308
|
-
|
|
22309
|
-
|
|
22310
|
-
|
|
22311
|
-
|
|
22312
|
-
|
|
22313
|
-
const url = deps.page.url();
|
|
22314
|
-
return ResultSchema.parse({
|
|
22315
|
-
ok: true,
|
|
22316
|
-
target: TARGET,
|
|
22317
|
-
...url !== PUBLISH_URL ? { url } : {},
|
|
22318
|
-
message: `${TARGET} ${input.operation} post published`,
|
|
22319
|
-
metadata: {
|
|
22320
|
-
...baseMetadata(input, deps),
|
|
22321
|
-
publishControl: submitted.label,
|
|
22322
|
-
publishPath: submitted.path,
|
|
22323
|
-
publishClick: submitted.click,
|
|
22324
|
-
publishSignal: url.includes(PUBLISHED_MARKER) ? `url:${PUBLISHED_MARKER}` : "toast",
|
|
22325
|
-
...captureMetadata(capture)
|
|
22270
|
+
const outcomeCapture = await armOutcomeCapture(deps.page, deps.stepTimeoutMs);
|
|
22271
|
+
try {
|
|
22272
|
+
const submitted = await clickActionControl(input.operation, deps, PUBLISH_LABELS, "publish control");
|
|
22273
|
+
if (!submitted.ok)
|
|
22274
|
+
return fail(submitted.error);
|
|
22275
|
+
const urlBeforeSubmit = deps.page.url();
|
|
22276
|
+
const confirmed = await waitUntil(async () => {
|
|
22277
|
+
if (capture === null)
|
|
22278
|
+
capture = await outcomeCapture.read();
|
|
22279
|
+
assertCapturedOutcome(capture);
|
|
22280
|
+
if (deps.page.url().includes(PUBLISHED_MARKER))
|
|
22281
|
+
return true;
|
|
22282
|
+
return await readScopedSignal(asPlaywrightPage(deps.page), PUBLISH_CONFIRM) !== null;
|
|
22283
|
+
}, deps.stepTimeoutMs);
|
|
22284
|
+
if (!confirmed) {
|
|
22285
|
+
capture = capture ?? await outcomeCapture.read();
|
|
22286
|
+
assertCapturedOutcome(capture);
|
|
22287
|
+
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.`);
|
|
22326
22288
|
}
|
|
22327
|
-
|
|
22289
|
+
const url = deps.page.url();
|
|
22290
|
+
return ResultSchema.parse({
|
|
22291
|
+
ok: true,
|
|
22292
|
+
target: TARGET,
|
|
22293
|
+
...url !== PUBLISH_URL ? { url } : {},
|
|
22294
|
+
message: `${TARGET} ${input.operation} post published`,
|
|
22295
|
+
metadata: {
|
|
22296
|
+
...baseMetadata(input, deps),
|
|
22297
|
+
publishControl: submitted.label,
|
|
22298
|
+
publishPath: submitted.path,
|
|
22299
|
+
publishClick: submitted.click,
|
|
22300
|
+
publishSignal: url.includes(PUBLISHED_MARKER) ? `url:${PUBLISHED_MARKER}` : "toast",
|
|
22301
|
+
...captureMetadata(capture)
|
|
22302
|
+
}
|
|
22303
|
+
});
|
|
22304
|
+
} finally {
|
|
22305
|
+
outcomeCapture.dispose();
|
|
22306
|
+
}
|
|
22328
22307
|
}
|
|
22329
22308
|
function draftExpectation(input, deps) {
|
|
22330
22309
|
switch (input.operation) {
|
|
@@ -22468,13 +22447,21 @@ async function runMode(input, deps) {
|
|
|
22468
22447
|
// ../../plugins/publishings/xhs-pub/src/index.ts
|
|
22469
22448
|
var CHANNEL = "xhs";
|
|
22470
22449
|
var LOGIN_TIMEOUT_MS = 120000;
|
|
22471
|
-
var PREFLIGHT_TIMEOUT_MS =
|
|
22450
|
+
var PREFLIGHT_TIMEOUT_MS = 90000;
|
|
22472
22451
|
var SUBMIT_SETTLE_MS = 2500;
|
|
22473
22452
|
var SUBMIT_ATTEMPTS = 3;
|
|
22474
22453
|
var AUTH_GATE = ["div.creator-tab", "text=\u4E0A\u4F20\u56FE\u6587"];
|
|
22475
22454
|
function fail2(error) {
|
|
22476
22455
|
return ResultSchema.parse({ ok: false, target: TARGET, error });
|
|
22477
22456
|
}
|
|
22457
|
+
function refuse(error) {
|
|
22458
|
+
return ResultSchema.parse({
|
|
22459
|
+
ok: false,
|
|
22460
|
+
target: TARGET,
|
|
22461
|
+
error,
|
|
22462
|
+
metadata: { itcDelivery: { schemaVersion: 1, effect: "none" } }
|
|
22463
|
+
});
|
|
22464
|
+
}
|
|
22478
22465
|
async function planVisit(primary, content) {
|
|
22479
22466
|
const raw = content.metadata?.followUps;
|
|
22480
22467
|
if (raw === undefined)
|
|
@@ -22485,6 +22472,7 @@ async function planVisit(primary, content) {
|
|
|
22485
22472
|
};
|
|
22486
22473
|
}
|
|
22487
22474
|
const followUps = [];
|
|
22475
|
+
const primaryStatus = content.metadata?.publishStatus;
|
|
22488
22476
|
for (const [index, entry] of raw.entries()) {
|
|
22489
22477
|
const label = `followUps[${index}]`;
|
|
22490
22478
|
const parsed = ContentSchema.safeParse(entry);
|
|
@@ -22498,12 +22486,13 @@ async function planVisit(primary, content) {
|
|
|
22498
22486
|
followUps.push({ operation, error: requested.error });
|
|
22499
22487
|
continue;
|
|
22500
22488
|
}
|
|
22501
|
-
const
|
|
22489
|
+
const followUpContent = parsed.data.metadata?.publishStatus === undefined && primaryStatus !== undefined ? { ...parsed.data, metadata: { ...parsed.data.metadata ?? {}, publishStatus: primaryStatus } } : parsed.data;
|
|
22490
|
+
const validation = await validateModeInput(requested.operation, followUpContent);
|
|
22502
22491
|
if (validation.error !== undefined) {
|
|
22503
22492
|
followUps.push({ operation, error: validation.error });
|
|
22504
22493
|
continue;
|
|
22505
22494
|
}
|
|
22506
|
-
followUps.push({ content:
|
|
22495
|
+
followUps.push({ content: followUpContent, operation: requested.operation, input: validation.input });
|
|
22507
22496
|
}
|
|
22508
22497
|
return { plan: { primary, followUps } };
|
|
22509
22498
|
}
|
|
@@ -22544,62 +22533,56 @@ async function checkXhsProfileSession(opts) {
|
|
|
22544
22533
|
profileDir: opts.profileDir,
|
|
22545
22534
|
launcher: opts.launcher,
|
|
22546
22535
|
timeoutMs: opts.timeoutMs ?? PREFLIGHT_TIMEOUT_MS,
|
|
22547
|
-
headedOnly:
|
|
22536
|
+
headedOnly: true
|
|
22548
22537
|
});
|
|
22549
22538
|
}
|
|
22550
22539
|
|
|
22551
22540
|
class XhsBrowserTransport {
|
|
22552
22541
|
kind = "browser";
|
|
22553
22542
|
driver;
|
|
22554
|
-
|
|
22543
|
+
readinessTimeoutMs;
|
|
22555
22544
|
stepTimeoutMs;
|
|
22556
22545
|
submitSettleMs;
|
|
22557
22546
|
submitAttempts;
|
|
22558
22547
|
openPage;
|
|
22559
22548
|
automation;
|
|
22560
|
-
preflight;
|
|
22561
22549
|
constructor(driver = "script", opts) {
|
|
22562
22550
|
this.driver = driver;
|
|
22563
|
-
this.
|
|
22551
|
+
this.readinessTimeoutMs = Math.min(opts?.loginTimeoutMs ?? PREFLIGHT_TIMEOUT_MS, PREFLIGHT_TIMEOUT_MS);
|
|
22564
22552
|
this.stepTimeoutMs = opts?.stepTimeoutMs ?? STEP_TIMEOUT_MS;
|
|
22565
22553
|
this.submitSettleMs = opts?.submitSettleMs ?? SUBMIT_SETTLE_MS;
|
|
22566
22554
|
this.submitAttempts = opts?.submitAttempts ?? SUBMIT_ATTEMPTS;
|
|
22567
22555
|
this.openPage = opts?.openPage ?? defaultOpenPage;
|
|
22568
22556
|
this.automation = opts?.automation ?? createAutomationGuard();
|
|
22569
|
-
this.preflight = opts?.preflight ?? ((profileDir) => checkXhsProfileSession({ profileDir }));
|
|
22570
22557
|
}
|
|
22571
22558
|
async publish(payload) {
|
|
22572
22559
|
if (this.driver !== "script") {
|
|
22573
|
-
return
|
|
22560
|
+
return refuse(`unsupported driver '${this.driver}' for ${TARGET}: the console modes (${XHS_OPERATIONS.join(", ")}) require the script driver (Playwright setInputFiles)`);
|
|
22574
22561
|
}
|
|
22575
22562
|
const requested = resolveXhsOperation(payload.options, payload.content);
|
|
22576
22563
|
if (requested.error !== undefined)
|
|
22577
|
-
return
|
|
22564
|
+
return refuse(requested.error);
|
|
22578
22565
|
const operation = requested.operation;
|
|
22579
22566
|
const validation = await validateModeInput(operation, payload.content);
|
|
22580
22567
|
if (validation.error !== undefined)
|
|
22581
|
-
return
|
|
22568
|
+
return refuse(validation.error);
|
|
22582
22569
|
const input = validation.input;
|
|
22583
22570
|
const visited = await planVisit({ content: payload.content, input }, payload.content);
|
|
22584
22571
|
if (visited.error !== undefined)
|
|
22585
|
-
return
|
|
22572
|
+
return refuse(visited.error);
|
|
22586
22573
|
const visit = visited.plan;
|
|
22587
22574
|
const override = typeof payload.options?.profileDir === "string" ? payload.options.profileDir : undefined;
|
|
22588
22575
|
const profileDir = resolveChannelProfileDir(CHANNEL, override);
|
|
22589
22576
|
const cap = this.automation.allow("publish");
|
|
22590
22577
|
if (!cap.allowed)
|
|
22591
|
-
return
|
|
22592
|
-
const session = await this.preflight(profileDir);
|
|
22593
|
-
if (session.status !== "verified") {
|
|
22594
|
-
return fail2(`session preflight refused (no headed visit attempted): ${session.detail}`);
|
|
22595
|
-
}
|
|
22596
|
-
this.automation.record("publish");
|
|
22578
|
+
return refuse(`automation cap: ${cap.reason}`);
|
|
22597
22579
|
let opened;
|
|
22598
22580
|
try {
|
|
22599
22581
|
opened = await this.openPage(profileDir);
|
|
22600
22582
|
} catch (error) {
|
|
22601
|
-
return
|
|
22583
|
+
return refuse(error instanceof Error ? error.message : String(error));
|
|
22602
22584
|
}
|
|
22585
|
+
this.automation.record("publish");
|
|
22603
22586
|
const { page, close } = opened;
|
|
22604
22587
|
try {
|
|
22605
22588
|
const primary = await this.runStep(visit.primary.input, visit.primary.content, page, profileDir);
|
|
@@ -22616,18 +22599,26 @@ class XhsBrowserTransport {
|
|
|
22616
22599
|
}
|
|
22617
22600
|
}
|
|
22618
22601
|
async runStep(input, content, page, profileDir) {
|
|
22619
|
-
|
|
22602
|
+
try {
|
|
22603
|
+
const started = Date.now();
|
|
22604
|
+
let timer;
|
|
22620
22605
|
try {
|
|
22621
|
-
|
|
22606
|
+
const ready = async () => {
|
|
22607
|
+
await page.goto(PUBLISH_URL, { timeout: this.readinessTimeoutMs });
|
|
22608
|
+
return waitUntil(() => isXhsConsoleReady(page), Math.max(0, this.readinessTimeoutMs - (Date.now() - started)), Math.min(500, this.readinessTimeoutMs));
|
|
22609
|
+
};
|
|
22610
|
+
const gated = await Promise.race([
|
|
22611
|
+
ready(),
|
|
22612
|
+
new Promise((resolve) => {
|
|
22613
|
+
timer = setTimeout(() => resolve(false), this.readinessTimeoutMs);
|
|
22614
|
+
})
|
|
22615
|
+
]);
|
|
22616
|
+
if (!gated)
|
|
22617
|
+
throw new Error(`no authenticated console after ${this.readinessTimeoutMs}ms`);
|
|
22622
22618
|
} catch (error) {
|
|
22623
|
-
|
|
22624
|
-
}
|
|
22625
|
-
|
|
22626
|
-
try {
|
|
22627
|
-
await act("creator page goto", () => page.goto(PUBLISH_URL, { timeout: this.loginTimeoutMs }));
|
|
22628
|
-
const gated = await waitUntil(() => isXhsConsoleReady(page), this.loginTimeoutMs);
|
|
22629
|
-
if (!gated) {
|
|
22630
|
-
return fail2(`login timeout after ${this.loginTimeoutMs}ms: no authenticated ${CHANNEL} creator console in ${profileDir}`);
|
|
22619
|
+
return refuse(`session readiness refused: ${error instanceof Error ? error.message : String(error)} in ${profileDir} \u2014 run kk bot login xhs`);
|
|
22620
|
+
} finally {
|
|
22621
|
+
clearTimeout(timer);
|
|
22631
22622
|
}
|
|
22632
22623
|
const publishStatus = content.metadata?.publishStatus === "public" ? "public" : "draft";
|
|
22633
22624
|
const draftBaseline = publishStatus === "draft" ? await readDraftBaseline(page) : { count: null, stamps: [] };
|
|
@@ -22708,6 +22699,7 @@ export {
|
|
|
22708
22699
|
CREATOR_TAB_COUNT,
|
|
22709
22700
|
LOGIN_TIMEOUT_MS,
|
|
22710
22701
|
MODE_LIMITS,
|
|
22702
|
+
PREFLIGHT_TIMEOUT_MS,
|
|
22711
22703
|
PUBLISH_URL,
|
|
22712
22704
|
XHS_OPERATIONS,
|
|
22713
22705
|
XhsBrowserTransport,
|