@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
|
@@ -4925,10 +4925,13 @@ function writeLine(message, target) {
|
|
|
4925
4925
|
target.write(`${message}
|
|
4926
4926
|
`);
|
|
4927
4927
|
}
|
|
4928
|
+
function echo(message, target = defaultStdoutTarget ?? processStream("stdout")) {
|
|
4929
|
+
writeLine(message, target);
|
|
4930
|
+
}
|
|
4928
4931
|
function echoError(message, target = defaultStderrTarget ?? processStream("stderr")) {
|
|
4929
4932
|
writeLine(message, target);
|
|
4930
4933
|
}
|
|
4931
|
-
var defaultStderrTarget;
|
|
4934
|
+
var defaultStdoutTarget, defaultStderrTarget;
|
|
4932
4935
|
|
|
4933
4936
|
// ../../node_modules/.bun/@gobing-ai+ts-utils@0.5.32/node_modules/@gobing-ai/ts-utils/dist/index.js
|
|
4934
4937
|
var init_dist = __esm(() => {
|
|
@@ -19830,7 +19833,7 @@ var init_runtime_node_bun = __esm(() => {
|
|
|
19830
19833
|
|
|
19831
19834
|
// ../../plugins/publishings/wechatmp-pub/src/index.ts
|
|
19832
19835
|
import { randomUUID as randomUUID2 } from "crypto";
|
|
19833
|
-
import { parseArgs } from "util";
|
|
19836
|
+
import { parseArgs as parseArgs2 } from "util";
|
|
19834
19837
|
|
|
19835
19838
|
// ../../packages/kk-core/src/content-limits.ts
|
|
19836
19839
|
var PLATFORM_CONTENT_LIMITS = Object.freeze({
|
|
@@ -20249,6 +20252,7 @@ async function trySelectors(page, selectors, options = {}) {
|
|
|
20249
20252
|
|
|
20250
20253
|
// ../../packages/publish-harness/src/browser.ts
|
|
20251
20254
|
import { join as join5, resolve as resolve5 } from "path";
|
|
20255
|
+
import { parseArgs } from "util";
|
|
20252
20256
|
|
|
20253
20257
|
// ../../node_modules/.bun/@gobing-ai+ts-browser-automation@0.5.32+0f5f0476d0d466a6/node_modules/@gobing-ai/ts-browser-automation/dist/errors.js
|
|
20254
20258
|
class BrowserAutomationError extends Error {
|
|
@@ -20285,6 +20289,20 @@ class PlaywrightUnavailableError extends BrowserAutomationError {
|
|
|
20285
20289
|
this.name = "PlaywrightUnavailableError";
|
|
20286
20290
|
}
|
|
20287
20291
|
}
|
|
20292
|
+
|
|
20293
|
+
class LoginTimeoutError extends BrowserAutomationError {
|
|
20294
|
+
constructor(message) {
|
|
20295
|
+
super(message);
|
|
20296
|
+
this.name = "LoginTimeoutError";
|
|
20297
|
+
}
|
|
20298
|
+
}
|
|
20299
|
+
|
|
20300
|
+
class OperationAbortedError extends BrowserAutomationError {
|
|
20301
|
+
constructor(message = "Browser automation operation was cancelled via AbortSignal.") {
|
|
20302
|
+
super(message);
|
|
20303
|
+
this.name = "OperationAbortedError";
|
|
20304
|
+
}
|
|
20305
|
+
}
|
|
20288
20306
|
// ../../node_modules/.bun/@gobing-ai+ts-browser-automation@0.5.32+0f5f0476d0d466a6/node_modules/@gobing-ai/ts-browser-automation/dist/launcher.js
|
|
20289
20307
|
import { mkdir } from "fs/promises";
|
|
20290
20308
|
|
|
@@ -20352,6 +20370,8 @@ function createPersistentLauncher(options = {}) {
|
|
|
20352
20370
|
}
|
|
20353
20371
|
|
|
20354
20372
|
// ../../node_modules/.bun/@gobing-ai+ts-browser-automation@0.5.32+0f5f0476d0d466a6/node_modules/@gobing-ai/ts-browser-automation/dist/operations.js
|
|
20373
|
+
var DEFAULT_TIMEOUT_MS = 30000;
|
|
20374
|
+
var POLL_INTERVAL_MS = 250;
|
|
20355
20375
|
var defaultLauncher;
|
|
20356
20376
|
function getDefaultLauncher() {
|
|
20357
20377
|
if (defaultLauncher === undefined)
|
|
@@ -20364,6 +20384,91 @@ async function openPersistentBrowser(options) {
|
|
|
20364
20384
|
headless: options.headless
|
|
20365
20385
|
});
|
|
20366
20386
|
}
|
|
20387
|
+
async function loginWithProfile(options) {
|
|
20388
|
+
assertNotAborted(options.signal);
|
|
20389
|
+
assertFiniteTimeoutMs(options.timeoutMs);
|
|
20390
|
+
const context = await (options.launcher ?? getDefaultLauncher()).launch({
|
|
20391
|
+
profileDir: resolveProfileDir(options.profileDir),
|
|
20392
|
+
headless: false
|
|
20393
|
+
});
|
|
20394
|
+
try {
|
|
20395
|
+
const page = await openPage(context);
|
|
20396
|
+
await page.goto(options.url);
|
|
20397
|
+
await pollPredicate(page, options.isAuthenticated, options.timeoutMs, options.signal);
|
|
20398
|
+
} finally {
|
|
20399
|
+
await context.close();
|
|
20400
|
+
}
|
|
20401
|
+
}
|
|
20402
|
+
async function withProfilePage(options, callback) {
|
|
20403
|
+
assertNotAborted(options.signal);
|
|
20404
|
+
if (options.isAuthenticated !== undefined)
|
|
20405
|
+
assertFiniteTimeoutMs(options.timeoutMs ?? DEFAULT_TIMEOUT_MS);
|
|
20406
|
+
const context = await (options.launcher ?? getDefaultLauncher()).launch({
|
|
20407
|
+
profileDir: resolveProfileDir(options.profileDir),
|
|
20408
|
+
headless: options.headless ?? false
|
|
20409
|
+
});
|
|
20410
|
+
try {
|
|
20411
|
+
const page = await openPage(context);
|
|
20412
|
+
if (options.url !== undefined)
|
|
20413
|
+
await page.goto(options.url);
|
|
20414
|
+
if (options.isAuthenticated !== undefined) {
|
|
20415
|
+
await pollPredicate(page, options.isAuthenticated, options.timeoutMs ?? DEFAULT_TIMEOUT_MS, options.signal);
|
|
20416
|
+
}
|
|
20417
|
+
return await callback({ context, page });
|
|
20418
|
+
} finally {
|
|
20419
|
+
await context.close();
|
|
20420
|
+
}
|
|
20421
|
+
}
|
|
20422
|
+
function assertNotAborted(signal) {
|
|
20423
|
+
if (signal?.aborted)
|
|
20424
|
+
throw new OperationAbortedError;
|
|
20425
|
+
}
|
|
20426
|
+
async function openPage(context) {
|
|
20427
|
+
const existing = context.pages()[0];
|
|
20428
|
+
return existing ?? await context.newPage();
|
|
20429
|
+
}
|
|
20430
|
+
function assertFiniteTimeoutMs(timeoutMs) {
|
|
20431
|
+
if (!Number.isFinite(timeoutMs) || timeoutMs < 0) {
|
|
20432
|
+
throw new TypeError(`timeoutMs must be a finite non-negative number of milliseconds; received ${timeoutMs}`);
|
|
20433
|
+
}
|
|
20434
|
+
}
|
|
20435
|
+
async function pollPredicate(page, predicate, timeoutMs, signal) {
|
|
20436
|
+
const timeoutError = new LoginTimeoutError(`Authentication was not confirmed within ${timeoutMs}ms. The profile's site session has likely ` + "expired or the sign-in was not completed: re-run loginWithProfile() with the same profileDir to sign in again.");
|
|
20437
|
+
let timer;
|
|
20438
|
+
let onAbort;
|
|
20439
|
+
let stopped = false;
|
|
20440
|
+
const deadline = new Promise((_, reject) => {
|
|
20441
|
+
timer = setTimeout(() => reject(timeoutError), timeoutMs);
|
|
20442
|
+
if (signal) {
|
|
20443
|
+
onAbort = () => reject(new OperationAbortedError);
|
|
20444
|
+
signal.addEventListener("abort", onAbort, { once: true });
|
|
20445
|
+
if (signal.aborted)
|
|
20446
|
+
onAbort();
|
|
20447
|
+
}
|
|
20448
|
+
});
|
|
20449
|
+
const poll = async () => {
|
|
20450
|
+
for (;; ) {
|
|
20451
|
+
if (stopped)
|
|
20452
|
+
return;
|
|
20453
|
+
assertNotAborted(signal);
|
|
20454
|
+
if (await predicate(page))
|
|
20455
|
+
return;
|
|
20456
|
+
await sleep(POLL_INTERVAL_MS);
|
|
20457
|
+
}
|
|
20458
|
+
};
|
|
20459
|
+
try {
|
|
20460
|
+
await Promise.race([poll(), deadline]);
|
|
20461
|
+
} finally {
|
|
20462
|
+
stopped = true;
|
|
20463
|
+
if (timer)
|
|
20464
|
+
clearTimeout(timer);
|
|
20465
|
+
if (signal && onAbort)
|
|
20466
|
+
signal.removeEventListener("abort", onAbort);
|
|
20467
|
+
}
|
|
20468
|
+
}
|
|
20469
|
+
function sleep(ms) {
|
|
20470
|
+
return new Promise((resolve) => setTimeout(resolve, ms));
|
|
20471
|
+
}
|
|
20367
20472
|
// ../../packages/publish-harness/src/browser.ts
|
|
20368
20473
|
init_dist();
|
|
20369
20474
|
|
|
@@ -20668,6 +20773,13 @@ function sha256Hex(value) {
|
|
|
20668
20773
|
|
|
20669
20774
|
// ../../packages/publish-harness/src/bot.ts
|
|
20670
20775
|
var DEFAULT_BOT_PROFILE_ROOT = join4(homedir4(), ".config", "kk", "browser-profiles");
|
|
20776
|
+
var MAX_IDENTITY_LENGTH = 128;
|
|
20777
|
+
function normalizeSessionIdentity(value) {
|
|
20778
|
+
if (typeof value !== "string")
|
|
20779
|
+
return;
|
|
20780
|
+
const cleaned = value.replace(/\p{Cc}/gu, "").trim().slice(0, MAX_IDENTITY_LENGTH);
|
|
20781
|
+
return cleaned.length === 0 ? undefined : cleaned;
|
|
20782
|
+
}
|
|
20671
20783
|
class BotError extends Error {
|
|
20672
20784
|
code;
|
|
20673
20785
|
details;
|
|
@@ -20693,7 +20805,11 @@ async function ensureProfileDir2(profileDir, headless) {
|
|
|
20693
20805
|
}
|
|
20694
20806
|
// ../../packages/publish-harness/src/browser-anti-detection.ts
|
|
20695
20807
|
var MAX_QUEUED_BYTES = 8 * 1024 * 1024;
|
|
20808
|
+
|
|
20696
20809
|
// ../../packages/publish-harness/src/browser.ts
|
|
20810
|
+
var DEFAULT_LOGIN_TIMEOUT_MS = 180000;
|
|
20811
|
+
var DEFAULT_OPEN_NAV_TIMEOUT_MS = 30000;
|
|
20812
|
+
var DEFAULT_CHECK_TIMEOUT_MS = 30000;
|
|
20697
20813
|
var DEFAULT_STEP_TIMEOUT_MS = 30000;
|
|
20698
20814
|
var DEFAULT_POLL_MS = 500;
|
|
20699
20815
|
var ATTACH_POLL_MS = 100;
|
|
@@ -20809,6 +20925,204 @@ function attachOwnershipClose(context, release) {
|
|
|
20809
20925
|
});
|
|
20810
20926
|
}
|
|
20811
20927
|
var kkBrowserLauncher = createKkBrowserLauncher();
|
|
20928
|
+
function resolveChannelProfileDir(channel, override) {
|
|
20929
|
+
const tiers = [override, process.env[`${channel.toUpperCase()}_PROFILE_DIR`], process.env.KK_BROWSER_PROFILE_DIR];
|
|
20930
|
+
const chosen = tiers.find((tier) => tier !== undefined && tier.trim().length > 0);
|
|
20931
|
+
return resolveBrowserProfileDir(channel, chosen);
|
|
20932
|
+
}
|
|
20933
|
+
async function checkChannelSession(config, opts) {
|
|
20934
|
+
const timeoutMs = opts.timeoutMs ?? DEFAULT_CHECK_TIMEOUT_MS;
|
|
20935
|
+
const passes = opts.headedOnly ? [false] : opts.headedFallback === false ? [true] : [true, false];
|
|
20936
|
+
let lastDetail = `${config.channel} readiness was never probed`;
|
|
20937
|
+
for (const headless of passes) {
|
|
20938
|
+
try {
|
|
20939
|
+
await withProfilePage({
|
|
20940
|
+
profileDir: opts.profileDir,
|
|
20941
|
+
headless,
|
|
20942
|
+
url: config.homeUrl,
|
|
20943
|
+
isAuthenticated: config.isAuthenticated,
|
|
20944
|
+
timeoutMs,
|
|
20945
|
+
launcher: opts.launcher ?? kkBrowserLauncher
|
|
20946
|
+
}, async () => true);
|
|
20947
|
+
return {
|
|
20948
|
+
status: "verified",
|
|
20949
|
+
profileDir: opts.profileDir,
|
|
20950
|
+
detail: `authenticated ${config.channel} session observed ${headless ? "headlessly" : "via a headed pass"} via profile ${opts.profileDir} (read-only)`
|
|
20951
|
+
};
|
|
20952
|
+
} catch (error) {
|
|
20953
|
+
if (error instanceof BrowserProfileMissingError) {
|
|
20954
|
+
return {
|
|
20955
|
+
status: "refused",
|
|
20956
|
+
profileDir: opts.profileDir,
|
|
20957
|
+
detail: `no ${config.channel} browser profile at ${opts.profileDir} \u2014 run the login command first`
|
|
20958
|
+
};
|
|
20959
|
+
}
|
|
20960
|
+
lastDetail = `${headless ? "headless" : "headed"} ${config.channel} readiness refused: ${errorMessage2(error)}`;
|
|
20961
|
+
}
|
|
20962
|
+
}
|
|
20963
|
+
return { status: "refused", profileDir: opts.profileDir, detail: lastDetail };
|
|
20964
|
+
}
|
|
20965
|
+
async function openChannelSession(config, request, deps = {}, stdout = echo) {
|
|
20966
|
+
if (lstat(request.profileDir) === null) {
|
|
20967
|
+
stdout(`${config.channel} profile open failed: no profile at ${request.profileDir} \u2014 run the login command first`);
|
|
20968
|
+
return 1;
|
|
20969
|
+
}
|
|
20970
|
+
let context;
|
|
20971
|
+
try {
|
|
20972
|
+
context = await (deps.launcher ?? kkBrowserLauncher).launch({
|
|
20973
|
+
profileDir: request.profileDir,
|
|
20974
|
+
headless: false
|
|
20975
|
+
});
|
|
20976
|
+
} catch (error) {
|
|
20977
|
+
stdout(`${config.channel} profile open failed: ${errorMessage2(error)}`);
|
|
20978
|
+
return 1;
|
|
20979
|
+
}
|
|
20980
|
+
const page = context.pages()[0] ?? await context.newPage();
|
|
20981
|
+
const onOpen = config.sessionState?.onOpen;
|
|
20982
|
+
if (onOpen !== undefined) {
|
|
20983
|
+
try {
|
|
20984
|
+
await onOpen({ context, page, profileDir: request.profileDir });
|
|
20985
|
+
} catch (error) {
|
|
20986
|
+
await context.close().catch(() => {});
|
|
20987
|
+
stdout(`${config.channel} profile open failed: ${errorMessage2(error)}`);
|
|
20988
|
+
return 1;
|
|
20989
|
+
}
|
|
20990
|
+
}
|
|
20991
|
+
try {
|
|
20992
|
+
await page.goto(request.url, { waitUntil: "commit", timeout: DEFAULT_OPEN_NAV_TIMEOUT_MS });
|
|
20993
|
+
} catch (error) {
|
|
20994
|
+
stdout(`${config.channel} profile open navigation failed: ${errorMessage2(error)}`);
|
|
20995
|
+
}
|
|
20996
|
+
await new Promise((resolveClose) => {
|
|
20997
|
+
context.once("close", () => resolveClose());
|
|
20998
|
+
});
|
|
20999
|
+
stdout(`${config.channel} profile open closed: ${request.profileDir}`);
|
|
21000
|
+
return 0;
|
|
21001
|
+
}
|
|
21002
|
+
async function loginWithAuthenticatedPage(config, opts) {
|
|
21003
|
+
const context = await opts.launcher.launch({ profileDir: opts.profileDir, headless: false });
|
|
21004
|
+
const sessionCaptured = config.sessionState?.onAuthenticated !== undefined;
|
|
21005
|
+
let captured = false;
|
|
21006
|
+
let facts = {};
|
|
21007
|
+
try {
|
|
21008
|
+
const page = context.pages()[0] ?? await context.newPage();
|
|
21009
|
+
await page.goto(opts.url);
|
|
21010
|
+
if (!await waitUntil(() => Promise.resolve(config.isAuthenticated(page)), opts.timeoutMs)) {
|
|
21011
|
+
throw new Error(`Authentication was not confirmed within ${opts.timeoutMs}ms \u2014 the profile's site session has likely ` + "expired or the sign-in was not completed: run the login command again to sign in again.");
|
|
21012
|
+
}
|
|
21013
|
+
await config.sessionState?.onAuthenticated?.({ context, page, profileDir: opts.profileDir });
|
|
21014
|
+
captured = sessionCaptured;
|
|
21015
|
+
if (opts.captureFacts) {
|
|
21016
|
+
facts = {
|
|
21017
|
+
...await captureSessionFacts(context, config.homeUrl),
|
|
21018
|
+
...config.readIdentity === undefined ? {} : { identity: await readIdentityOrUndefined(config.readIdentity, page) }
|
|
21019
|
+
};
|
|
21020
|
+
}
|
|
21021
|
+
} finally {
|
|
21022
|
+
try {
|
|
21023
|
+
await context.close();
|
|
21024
|
+
} catch {
|
|
21025
|
+
if (captured) {
|
|
21026
|
+
echoError(`${config.channel} browser context close failed after the authenticated session capture; saved state preserved`);
|
|
21027
|
+
}
|
|
21028
|
+
}
|
|
21029
|
+
}
|
|
21030
|
+
return facts;
|
|
21031
|
+
}
|
|
21032
|
+
async function runProfileCli(config, argv = process.argv.slice(2), deps = {}) {
|
|
21033
|
+
const stdout = deps.stdout ?? ((line) => {
|
|
21034
|
+
echo(line);
|
|
21035
|
+
});
|
|
21036
|
+
const usage = `usage: ${config.channel} profile-check [login|check|open] [--profile <dir>] [--url <url>] [--timeout <ms>] [--headed]`;
|
|
21037
|
+
let command;
|
|
21038
|
+
let profileDir;
|
|
21039
|
+
let timeoutMs;
|
|
21040
|
+
let headed = false;
|
|
21041
|
+
let url;
|
|
21042
|
+
try {
|
|
21043
|
+
const { positionals, values } = parseArgs({
|
|
21044
|
+
args: argv,
|
|
21045
|
+
allowPositionals: true,
|
|
21046
|
+
options: {
|
|
21047
|
+
profile: { type: "string" },
|
|
21048
|
+
timeout: { type: "string" },
|
|
21049
|
+
headed: { type: "boolean" },
|
|
21050
|
+
url: { type: "string" }
|
|
21051
|
+
}
|
|
21052
|
+
});
|
|
21053
|
+
command = positionals[0] ?? "check";
|
|
21054
|
+
headed = values.headed === true;
|
|
21055
|
+
url = values.url;
|
|
21056
|
+
if (command !== "login" && command !== "check" && command !== "open") {
|
|
21057
|
+
throw new Error(`unknown command '${command}'`);
|
|
21058
|
+
}
|
|
21059
|
+
if (command === "open" && (values.profile === undefined || url === undefined)) {
|
|
21060
|
+
throw new Error("open requires an explicit --profile <dir> and --url <url>");
|
|
21061
|
+
}
|
|
21062
|
+
if (values.timeout !== undefined) {
|
|
21063
|
+
timeoutMs = Number(values.timeout);
|
|
21064
|
+
if (!Number.isFinite(timeoutMs) || timeoutMs < 0) {
|
|
21065
|
+
throw new Error(`--timeout must be a non-negative number of ms, got '${values.timeout}'`);
|
|
21066
|
+
}
|
|
21067
|
+
}
|
|
21068
|
+
profileDir = resolveChannelProfileDir(config.channel, values.profile);
|
|
21069
|
+
} catch (error) {
|
|
21070
|
+
stdout(`${config.channel} profile-check: ${errorMessage2(error)} \u2014 ${usage}`);
|
|
21071
|
+
stdout(JSON.stringify({ status: "error", detail: errorMessage2(error) }));
|
|
21072
|
+
return 2;
|
|
21073
|
+
}
|
|
21074
|
+
if (command === "open") {
|
|
21075
|
+
return openChannelSession(config, { profileDir, url: url ?? "" }, deps, stdout);
|
|
21076
|
+
}
|
|
21077
|
+
if (command === "login") {
|
|
21078
|
+
const loginTimeoutMs = timeoutMs ?? config.loginTimeoutMs ?? DEFAULT_LOGIN_TIMEOUT_MS;
|
|
21079
|
+
const launcher = deps.launcher ?? kkBrowserLauncher;
|
|
21080
|
+
stdout(`${config.channel} profile login: a browser window is opening \u2014 sign in there; waiting up to ${Math.round(loginTimeoutMs / 1000)}s for the signed-in state`);
|
|
21081
|
+
try {
|
|
21082
|
+
const captureFacts = url !== undefined;
|
|
21083
|
+
if (!captureFacts && config.sessionState?.onAuthenticated === undefined) {
|
|
21084
|
+
await loginWithProfile({
|
|
21085
|
+
profileDir,
|
|
21086
|
+
url: config.homeUrl,
|
|
21087
|
+
isAuthenticated: config.isAuthenticated,
|
|
21088
|
+
timeoutMs: loginTimeoutMs,
|
|
21089
|
+
launcher
|
|
21090
|
+
});
|
|
21091
|
+
stdout(`${config.channel} profile login verified: ${profileDir}`);
|
|
21092
|
+
return 0;
|
|
21093
|
+
}
|
|
21094
|
+
const facts = await loginWithAuthenticatedPage(config, {
|
|
21095
|
+
profileDir,
|
|
21096
|
+
url: url ?? config.homeUrl,
|
|
21097
|
+
timeoutMs: loginTimeoutMs,
|
|
21098
|
+
launcher,
|
|
21099
|
+
captureFacts
|
|
21100
|
+
});
|
|
21101
|
+
stdout(`${config.channel} profile login verified: ${profileDir}`);
|
|
21102
|
+
if (url === undefined)
|
|
21103
|
+
return 0;
|
|
21104
|
+
stdout(JSON.stringify({
|
|
21105
|
+
status: "verified",
|
|
21106
|
+
profileDir,
|
|
21107
|
+
defaultUrl: config.homeUrl,
|
|
21108
|
+
...facts.expiresAt === undefined ? {} : { expiresAt: facts.expiresAt },
|
|
21109
|
+
...facts.identity === undefined ? {} : { identity: facts.identity }
|
|
21110
|
+
}));
|
|
21111
|
+
return 0;
|
|
21112
|
+
} catch (error) {
|
|
21113
|
+
stdout(`${config.channel} profile login failed: ${errorMessage2(error)}`);
|
|
21114
|
+
return 1;
|
|
21115
|
+
}
|
|
21116
|
+
}
|
|
21117
|
+
const result = await checkChannelSession(config, {
|
|
21118
|
+
profileDir,
|
|
21119
|
+
launcher: deps.launcher,
|
|
21120
|
+
headedOnly: headed || config.checkHeadedOnly === true,
|
|
21121
|
+
timeoutMs
|
|
21122
|
+
});
|
|
21123
|
+
stdout(JSON.stringify(result));
|
|
21124
|
+
return result.status === "verified" ? 0 : 1;
|
|
21125
|
+
}
|
|
20812
21126
|
async function waitUntil(predicate, timeoutMs, pollMs = DEFAULT_POLL_MS) {
|
|
20813
21127
|
const deadline = Date.now() + timeoutMs;
|
|
20814
21128
|
while (Date.now() < deadline) {
|
|
@@ -20893,6 +21207,29 @@ async function resolveSelector(page, selectors, opts = {}) {
|
|
|
20893
21207
|
}
|
|
20894
21208
|
return selector;
|
|
20895
21209
|
}
|
|
21210
|
+
async function captureSessionFacts(context, url) {
|
|
21211
|
+
let cookies;
|
|
21212
|
+
try {
|
|
21213
|
+
cookies = await context.cookies(url);
|
|
21214
|
+
} catch {
|
|
21215
|
+
return {};
|
|
21216
|
+
}
|
|
21217
|
+
let earliest;
|
|
21218
|
+
for (const cookie of cookies) {
|
|
21219
|
+
if (!cookie.httpOnly || cookie.expires <= 0)
|
|
21220
|
+
continue;
|
|
21221
|
+
if (earliest === undefined || cookie.expires < earliest)
|
|
21222
|
+
earliest = cookie.expires;
|
|
21223
|
+
}
|
|
21224
|
+
return earliest === undefined ? {} : { expiresAt: new Date(earliest * 1000).toISOString() };
|
|
21225
|
+
}
|
|
21226
|
+
async function readIdentityOrUndefined(readIdentity, page) {
|
|
21227
|
+
try {
|
|
21228
|
+
return normalizeSessionIdentity(await readIdentity(page));
|
|
21229
|
+
} catch {
|
|
21230
|
+
return;
|
|
21231
|
+
}
|
|
21232
|
+
}
|
|
20896
21233
|
function errorMessage2(error) {
|
|
20897
21234
|
return error instanceof Error ? error.message : String(error);
|
|
20898
21235
|
}
|
|
@@ -22815,7 +23152,15 @@ var TOKEN_LINK_SCRIPT = `(() => {
|
|
|
22815
23152
|
function fail(error) {
|
|
22816
23153
|
return ResultSchema.parse({ ok: false, target: TARGET, error: sanitizeSessionEvidence(error) });
|
|
22817
23154
|
}
|
|
22818
|
-
function
|
|
23155
|
+
function failNoEffect(error) {
|
|
23156
|
+
return ResultSchema.parse({
|
|
23157
|
+
ok: false,
|
|
23158
|
+
target: TARGET,
|
|
23159
|
+
error: sanitizeSessionEvidence(error),
|
|
23160
|
+
metadata: { itcDelivery: { schemaVersion: 1, effect: "none" } }
|
|
23161
|
+
});
|
|
23162
|
+
}
|
|
23163
|
+
function sleep2(ms) {
|
|
22819
23164
|
return new Promise((resolve) => setTimeout(resolve, ms));
|
|
22820
23165
|
}
|
|
22821
23166
|
function titleOf(content) {
|
|
@@ -23582,10 +23927,10 @@ async function composePodcast(input, deps, entry) {
|
|
|
23582
23927
|
const materialReady = await waitUntil(async () => {
|
|
23583
23928
|
const rowText = await page.evaluate(rowProbe);
|
|
23584
23929
|
return rowText !== null && !/\u8F6C\u7801\u4E2D|\u5BA1\u6838\u4E2D|\u5904\u7406\u4E2D/.test(rowText);
|
|
23585
|
-
},
|
|
23930
|
+
}, 40 * 60000);
|
|
23586
23931
|
if (!materialReady) {
|
|
23587
23932
|
const probeNow = String(await page.evaluate(reuseProbe) ?? "ERR");
|
|
23588
|
-
throw new Error(`\u64AD\u5BA2: \u97F3\u9891\u7D20\u6750 '${materialTitle}' \u672A\u5728
|
|
23933
|
+
throw new Error(`\u64AD\u5BA2: \u97F3\u9891\u7D20\u6750 '${materialTitle}' \u672A\u5728 40min \u5185\u5B8C\u6210\u8F6C\u7801/\u5BA1\u6838\uFF0C\u63D2\u5165\u672A\u6267\u884C\uFF08\u53EF\u91CD\u8DD1\uFF09` + ` \u2014 reuse \u7A97\u53E3 [${reuseHistory.join(",")}] \u6700\u8FD1\u8BFB=${probeNow.slice(0, 30)}`);
|
|
23589
23934
|
}
|
|
23590
23935
|
await clickSelector(page, await findSelector(page, [`${rowSelector} label.audio_item`, rowSelector], "\u64AD\u5BA2\u7D20\u6750 row", deps.stepTimeoutMs), deps.stepTimeoutMs);
|
|
23591
23936
|
await clickSelector(page, await findSelector(page, PODCAST_INSERT, "\u63D2\u5165 control", deps.stepTimeoutMs), deps.stepTimeoutMs);
|
|
@@ -23641,7 +23986,7 @@ async function saveDraft(input, deps, entry, composed) {
|
|
|
23641
23986
|
let stampAfter = deps.draftBaseline.stamp;
|
|
23642
23987
|
while (signal === null && attempts < deps.submitAttempts) {
|
|
23643
23988
|
attempts += 1;
|
|
23644
|
-
await
|
|
23989
|
+
await sleep2(deps.submitSettleMs);
|
|
23645
23990
|
if (await closeOpenDialogs(entry.editor) !== "closed") {
|
|
23646
23991
|
residuals += 1;
|
|
23647
23992
|
residualDialogs.push(await openDialogInventory(entry.editor));
|
|
@@ -23833,7 +24178,7 @@ async function savePublicDraft(deps, entry) {
|
|
|
23833
24178
|
if (typeof requestedUrl === "string" && normalizeSnapshotText(requestedUrl) !== composed.originalUrl)
|
|
23834
24179
|
return fail("public save readiness: requested \u539F\u6587\u94FE\u63A5 was not committed; no publish click attempted");
|
|
23835
24180
|
const canonicalUrlBeforeSave = canonicalSavedEditorUrl(entry.editor.url());
|
|
23836
|
-
await
|
|
24181
|
+
await sleep2(deps.submitSettleMs);
|
|
23837
24182
|
if (await closeOpenDialogs(entry.editor) !== "closed")
|
|
23838
24183
|
return fail("public save readiness: a residual editor dialog blocked \u4FDD\u5B58\u4E3A\u8349\u7A3F; no publish click attempted");
|
|
23839
24184
|
const saveControl = await findSelector(entry.editor, SAVE_DRAFT, "\u4FDD\u5B58\u4E3A\u8349\u7A3F control", deps.stepTimeoutMs);
|
|
@@ -23859,7 +24204,7 @@ async function savePublicDraft(deps, entry) {
|
|
|
23859
24204
|
return fail(`public save readiness: \u4FDD\u5B58\u4E3A\u8349\u7A3F did not expose a canonical saved editor URL (action=edit with appmsgid, not isNew=1) within ${deps.draftTimeoutMs}ms; no publish click attempted`);
|
|
23860
24205
|
}
|
|
23861
24206
|
const savedCanonicalUrl = canonicalUrl;
|
|
23862
|
-
await
|
|
24207
|
+
await sleep2(Math.min(Math.max(deps.pollMs, 25), 500));
|
|
23863
24208
|
await entry.editor.goto(savedCanonicalUrl, { timeout: deps.stepTimeoutMs });
|
|
23864
24209
|
let reloaded = null;
|
|
23865
24210
|
let reloadRefusal = null;
|
|
@@ -24048,7 +24393,7 @@ async function publishContent(input, deps, entry, composed) {
|
|
|
24048
24393
|
const notifySubscribers = shouldNotifySubscribers(deps.content);
|
|
24049
24394
|
let staleVersionRecoveryCount = 0;
|
|
24050
24395
|
let finalSavedEditorUrl = saved?.canonicalUrlForMetadata;
|
|
24051
|
-
await
|
|
24396
|
+
await sleep2(deps.submitSettleMs);
|
|
24052
24397
|
const control = await findSelector(entry.editor, PUBLISH_SEND, "\u53D1\u8868 control", deps.stepTimeoutMs);
|
|
24053
24398
|
const urlBefore = entry.editor.url();
|
|
24054
24399
|
await clickSelector(entry.editor, control, deps.stepTimeoutMs);
|
|
@@ -24197,14 +24542,27 @@ async function runMode(input, deps) {
|
|
|
24197
24542
|
if (cgi !== undefined)
|
|
24198
24543
|
return cgi;
|
|
24199
24544
|
}
|
|
24200
|
-
|
|
24201
|
-
|
|
24545
|
+
let entry;
|
|
24546
|
+
let composed;
|
|
24547
|
+
try {
|
|
24548
|
+
entry = await enterMode(deps, input.operation);
|
|
24549
|
+
composed = await compose(input, deps, entry);
|
|
24550
|
+
} catch (error) {
|
|
24551
|
+
return failNoEffect(error instanceof Error ? error.message : String(error));
|
|
24552
|
+
}
|
|
24202
24553
|
const diagnostics = [...composed.warnings, ...composed.enrichWarnings];
|
|
24203
24554
|
try {
|
|
24204
24555
|
const result = deps.publishStatus === "public" ? await publishContent(input, deps, entry, composed) : await saveDraft(input, deps, entry, composed);
|
|
24205
24556
|
if (!result.ok && diagnostics.length > 0) {
|
|
24206
24557
|
return { ...result, error: `${result.error} \u2014 compose diagnostics: ${diagnostics.join(" | ")}` };
|
|
24207
24558
|
}
|
|
24559
|
+
if (result.ok && composed.enrichWarnings.length > 0 && process.env.WECHATMP_ALLOW_PARTIAL_ENRICH !== "1") {
|
|
24560
|
+
return {
|
|
24561
|
+
...result,
|
|
24562
|
+
ok: false,
|
|
24563
|
+
error: `draft saved but enrichment did not apply \u2014 ${composed.enrichWarnings.join(" | ")} (set WECHATMP_ALLOW_PARTIAL_ENRICH=1 to accept a partial draft)`
|
|
24564
|
+
};
|
|
24565
|
+
}
|
|
24208
24566
|
return result;
|
|
24209
24567
|
} catch (error) {
|
|
24210
24568
|
const message = error instanceof Error ? error.message : String(error);
|
|
@@ -24537,12 +24895,25 @@ async function insertAudioMaterial(page, input) {
|
|
|
24537
24895
|
// ../../plugins/publishings/wechatmp-pub/src/index.ts
|
|
24538
24896
|
var CHANNEL = TARGET;
|
|
24539
24897
|
var CONSOLE_READY_TIMEOUT_MS = 30000;
|
|
24898
|
+
var LOGIN_TIMEOUT_MS = 180000;
|
|
24899
|
+
var POST_AUTH_SETTLE_MS = 1e4;
|
|
24540
24900
|
var SUBMIT_SETTLE_MS = 1500;
|
|
24541
24901
|
var DRAFT_SIGNAL_TIMEOUT_MS = 15000;
|
|
24542
24902
|
var SUBMIT_ATTEMPTS = 2;
|
|
24903
|
+
function noEffect() {
|
|
24904
|
+
return { itcDelivery: { schemaVersion: 1, effect: "none" } };
|
|
24905
|
+
}
|
|
24543
24906
|
function fail2(error) {
|
|
24544
24907
|
return ResultSchema.parse({ ok: false, target: TARGET, error: sanitizeSessionEvidence(error) });
|
|
24545
24908
|
}
|
|
24909
|
+
function refuse(error) {
|
|
24910
|
+
return ResultSchema.parse({
|
|
24911
|
+
ok: false,
|
|
24912
|
+
target: TARGET,
|
|
24913
|
+
error: sanitizeSessionEvidence(error),
|
|
24914
|
+
metadata: noEffect()
|
|
24915
|
+
});
|
|
24916
|
+
}
|
|
24546
24917
|
function isConsoleReady(page) {
|
|
24547
24918
|
return readConsoleToken(page.url()) !== undefined || page.url().includes(CONSOLE_HOME_FRAGMENT);
|
|
24548
24919
|
}
|
|
@@ -24587,74 +24958,24 @@ async function pollLogin(page, timeoutMs) {
|
|
|
24587
24958
|
throw new Error(`Authentication was not confirmed within ${deadline}ms \u2014 the saved session state has ` + "likely expired: re-run `bun src/profile-check.ts login` to sign in again.");
|
|
24588
24959
|
}
|
|
24589
24960
|
async function openWechatLogin(opts) {
|
|
24590
|
-
const
|
|
24591
|
-
|
|
24592
|
-
|
|
24593
|
-
|
|
24594
|
-
|
|
24595
|
-
|
|
24596
|
-
|
|
24597
|
-
|
|
24598
|
-
|
|
24599
|
-
|
|
24600
|
-
|
|
24601
|
-
|
|
24602
|
-
if (!ready)
|
|
24603
|
-
throw new Error(`QR scan not completed within ${timeoutMs / 1000}s`);
|
|
24604
|
-
await page.waitForTimeout(1e4);
|
|
24605
|
-
try {
|
|
24606
|
-
await persistWechatSessionState(context, opts.profileDir);
|
|
24607
|
-
} catch {
|
|
24608
|
-
throw new Error("wechatmp authenticated session snapshot failed");
|
|
24609
|
-
}
|
|
24610
|
-
} catch (error) {
|
|
24611
|
-
failed = true;
|
|
24612
|
-
failure = error;
|
|
24613
|
-
}
|
|
24614
|
-
try {
|
|
24615
|
-
await context.close();
|
|
24616
|
-
} catch {
|
|
24617
|
-
if (!failed)
|
|
24618
|
-
echoError("wechatmp browser context close failed after authenticated session snapshot; saved state preserved");
|
|
24619
|
-
}
|
|
24620
|
-
if (failed)
|
|
24621
|
-
throw failure;
|
|
24622
|
-
}
|
|
24623
|
-
async function openWechatSession(profileDir, opts = {}) {
|
|
24624
|
-
const { context } = await openWithState(profileDir, opts.headless ?? false, opts.url ?? CONSOLE_URL);
|
|
24625
|
-
const closable = context;
|
|
24626
|
-
await new Promise((resolveClose) => {
|
|
24627
|
-
closable.once("close", resolveClose);
|
|
24628
|
-
});
|
|
24961
|
+
const argv = ["login", "--profile", opts.profileDir];
|
|
24962
|
+
if (opts.timeoutMs !== undefined)
|
|
24963
|
+
argv.push("--timeout", String(Math.round(opts.timeoutMs)));
|
|
24964
|
+
const lines = [];
|
|
24965
|
+
const code = await runProfileCli(wechatSessionConfig, argv, {
|
|
24966
|
+
launcher: wechatBrowserLauncher,
|
|
24967
|
+
stdout: (line) => void lines.push(line)
|
|
24968
|
+
});
|
|
24969
|
+
if (code === 0)
|
|
24970
|
+
return;
|
|
24971
|
+
const failure = lines.find((line) => line.includes("profile login failed: "));
|
|
24972
|
+
throw new Error(failure === undefined ? "wechatmp login failed" : failure.replace(/^.*profile login failed: /, "").trim());
|
|
24629
24973
|
}
|
|
24630
24974
|
async function openWithState(profileDir, headless, url = CONSOLE_URL) {
|
|
24631
24975
|
const context = await openPersistentBrowser({ profileDir, headless, launcher: kkBrowserLauncher });
|
|
24632
24976
|
try {
|
|
24633
|
-
const stateFile = storageStatePath(profileDir);
|
|
24634
|
-
let state;
|
|
24635
|
-
try {
|
|
24636
|
-
state = JSON.parse(await createNodeFileSystem().readFile(stateFile));
|
|
24637
|
-
} catch {
|
|
24638
|
-
state = undefined;
|
|
24639
|
-
}
|
|
24640
|
-
const cookies = state?.cookies;
|
|
24641
|
-
if (!cookies || cookies.length === 0) {
|
|
24642
|
-
throw new BrowserProfileMissingError(`no saved console session state (${stateFile}) \u2014 run \`bun src/profile-check.ts login\` once`);
|
|
24643
|
-
}
|
|
24644
|
-
await context.addCookies(cookies);
|
|
24645
24977
|
const page = context.pages()[0] ?? await context.newPage();
|
|
24646
|
-
|
|
24647
|
-
for (const entry of origins) {
|
|
24648
|
-
const items = entry.localStorage ?? [];
|
|
24649
|
-
if (entry.origin === undefined || entry.origin.length === 0 || items.length === 0)
|
|
24650
|
-
continue;
|
|
24651
|
-
await page.goto(entry.origin).catch(() => {
|
|
24652
|
-
return;
|
|
24653
|
-
});
|
|
24654
|
-
await page.evaluate("(pairs) => { for (const pair of pairs) { window.localStorage.setItem(pair.name, pair.value); } }", items).catch(() => {
|
|
24655
|
-
return;
|
|
24656
|
-
});
|
|
24657
|
-
}
|
|
24978
|
+
await restoreWechatSessionState(context, page, profileDir);
|
|
24658
24979
|
await page.goto(url);
|
|
24659
24980
|
return { page, context };
|
|
24660
24981
|
} catch (error) {
|
|
@@ -24662,6 +24983,55 @@ async function openWithState(profileDir, headless, url = CONSOLE_URL) {
|
|
|
24662
24983
|
throw error;
|
|
24663
24984
|
}
|
|
24664
24985
|
}
|
|
24986
|
+
async function restoreWechatSessionState(context, page, profileDir) {
|
|
24987
|
+
const stateFile = storageStatePath(profileDir);
|
|
24988
|
+
let state;
|
|
24989
|
+
try {
|
|
24990
|
+
state = JSON.parse(await createNodeFileSystem().readFile(stateFile));
|
|
24991
|
+
} catch {
|
|
24992
|
+
state = undefined;
|
|
24993
|
+
}
|
|
24994
|
+
const cookies = state?.cookies;
|
|
24995
|
+
if (!cookies || cookies.length === 0) {
|
|
24996
|
+
throw new BrowserProfileMissingError(`no saved console session state (${stateFile}) \u2014 run \`bun src/profile-check.ts login\` once`);
|
|
24997
|
+
}
|
|
24998
|
+
await context.addCookies(cookies);
|
|
24999
|
+
for (const entry of state?.origins ?? []) {
|
|
25000
|
+
const items = entry.localStorage ?? [];
|
|
25001
|
+
if (entry.origin === undefined || entry.origin.length === 0 || items.length === 0)
|
|
25002
|
+
continue;
|
|
25003
|
+
await page.goto(entry.origin).catch(() => {
|
|
25004
|
+
return;
|
|
25005
|
+
});
|
|
25006
|
+
await page.evaluate("(pairs) => { for (const pair of pairs) { window.localStorage.setItem(pair.name, pair.value); } }", items).catch(() => {
|
|
25007
|
+
return;
|
|
25008
|
+
});
|
|
25009
|
+
}
|
|
25010
|
+
}
|
|
25011
|
+
var wechatBrowserLauncher = {
|
|
25012
|
+
launch: (request) => openPersistentBrowser({
|
|
25013
|
+
profileDir: request.profileDir,
|
|
25014
|
+
headless: request.headless,
|
|
25015
|
+
launcher: kkBrowserLauncher
|
|
25016
|
+
})
|
|
25017
|
+
};
|
|
25018
|
+
var wechatSessionConfig = {
|
|
25019
|
+
channel: CHANNEL,
|
|
25020
|
+
homeUrl: CONSOLE_URL,
|
|
25021
|
+
loginTimeoutMs: LOGIN_TIMEOUT_MS,
|
|
25022
|
+
isAuthenticated: (page) => isConsoleReady(page),
|
|
25023
|
+
sessionState: {
|
|
25024
|
+
onAuthenticated: async ({ context, page, profileDir }) => {
|
|
25025
|
+
await page.waitForTimeout(POST_AUTH_SETTLE_MS);
|
|
25026
|
+
try {
|
|
25027
|
+
await persistWechatSessionState(context, profileDir);
|
|
25028
|
+
} catch {
|
|
25029
|
+
throw new Error("wechatmp authenticated session snapshot failed");
|
|
25030
|
+
}
|
|
25031
|
+
},
|
|
25032
|
+
onOpen: ({ context, page, profileDir }) => restoreWechatSessionState(context, page, profileDir)
|
|
25033
|
+
}
|
|
25034
|
+
};
|
|
24665
25035
|
async function defaultOpenConsole(profileDir) {
|
|
24666
25036
|
const { page, context } = await openWithState(profileDir, true);
|
|
24667
25037
|
return {
|
|
@@ -24695,27 +25065,27 @@ class WechatmpBrowserTransport {
|
|
|
24695
25065
|
async publish(payload) {
|
|
24696
25066
|
const { content, options } = payload;
|
|
24697
25067
|
if (this.driver !== "script") {
|
|
24698
|
-
return
|
|
25068
|
+
return refuse(`unsupported driver '${this.driver}' for ${TARGET}: the console modes (${WECHATMP_OPERATIONS.join(", ")}) require the script driver (Playwright setInputFiles)`);
|
|
24699
25069
|
}
|
|
24700
25070
|
const requested = resolveWechatmpOperation(options, content);
|
|
24701
25071
|
if (requested.error !== undefined)
|
|
24702
|
-
return
|
|
25072
|
+
return refuse(requested.error);
|
|
24703
25073
|
const validation = await validateModeInput(requested.operation, content);
|
|
24704
25074
|
if (validation.error !== undefined)
|
|
24705
|
-
return
|
|
25075
|
+
return refuse(validation.error);
|
|
24706
25076
|
const profileDir = resolveBrowserProfileDir(TARGET, process.env.WECHATMP_PROFILE_DIR);
|
|
24707
25077
|
const publishStatus = content.metadata?.publishStatus === "public" ? "public" : "draft";
|
|
24708
25078
|
try {
|
|
24709
25079
|
await this.checkSession(profileDir);
|
|
24710
25080
|
} catch (error) {
|
|
24711
25081
|
const why = error instanceof BrowserProfileMissingError ? "no saved console profile \u2014 log in once via `bun src/profile-check.ts login`" : `console session preflight failed (${error instanceof Error ? error.message : String(error)})`;
|
|
24712
|
-
return
|
|
25082
|
+
return refuse(`${TARGET}-pub: ${why}`);
|
|
24713
25083
|
}
|
|
24714
25084
|
let opened;
|
|
24715
25085
|
try {
|
|
24716
25086
|
opened = await this.openPage(profileDir);
|
|
24717
25087
|
} catch (error) {
|
|
24718
|
-
return
|
|
25088
|
+
return refuse(error instanceof Error ? error.message : String(error));
|
|
24719
25089
|
}
|
|
24720
25090
|
let result;
|
|
24721
25091
|
try {
|
|
@@ -24776,7 +25146,7 @@ async function processPublishIO(inPath, outPath, transport) {
|
|
|
24776
25146
|
await fs.writeFile(outPath, JSON.stringify(ResultSchema.parse(result), null, 2));
|
|
24777
25147
|
}
|
|
24778
25148
|
async function main2(argv = process.argv.slice(2)) {
|
|
24779
|
-
const { values } =
|
|
25149
|
+
const { values } = parseArgs2({
|
|
24780
25150
|
argv,
|
|
24781
25151
|
options: {
|
|
24782
25152
|
in: { type: "string" },
|
|
@@ -24801,6 +25171,7 @@ if (import.meta.main) {
|
|
|
24801
25171
|
export {
|
|
24802
25172
|
CHANNEL,
|
|
24803
25173
|
CONSOLE_URL,
|
|
25174
|
+
LOGIN_TIMEOUT_MS,
|
|
24804
25175
|
WECHATMP_OPERATIONS,
|
|
24805
25176
|
WechatmpBrowserTransport,
|
|
24806
25177
|
checkWechatSession,
|
|
@@ -24810,10 +25181,12 @@ export {
|
|
|
24810
25181
|
main2 as main,
|
|
24811
25182
|
markdownToWechatHtml,
|
|
24812
25183
|
openWechatLogin,
|
|
24813
|
-
openWechatSession,
|
|
24814
25184
|
persistWechatSessionState,
|
|
24815
25185
|
processPublishIO,
|
|
25186
|
+
restoreWechatSessionState,
|
|
24816
25187
|
runMode,
|
|
24817
25188
|
storageStatePath,
|
|
25189
|
+
wechatBrowserLauncher,
|
|
25190
|
+
wechatSessionConfig,
|
|
24818
25191
|
wrapPlaywrightPage
|
|
24819
25192
|
};
|