@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
|
@@ -19830,7 +19830,7 @@ var init_runtime_node_bun = __esm(() => {
|
|
|
19830
19830
|
|
|
19831
19831
|
// ../../plugins/publishings/x-pub/src/index.ts
|
|
19832
19832
|
import { createHmac, randomBytes as randomBytes2 } from "crypto";
|
|
19833
|
-
import { dirname as dirname4, extname, isAbsolute as
|
|
19833
|
+
import { dirname as dirname4, extname as extname2, isAbsolute as isAbsolute3 } from "path";
|
|
19834
19834
|
import { parseArgs } from "util";
|
|
19835
19835
|
|
|
19836
19836
|
// ../../packages/kk-core/src/content-limits.ts
|
|
@@ -21043,12 +21043,224 @@ function editorTextScript(selector) {
|
|
|
21043
21043
|
|
|
21044
21044
|
// ../../plugins/publishings/x-pub/src/index.ts
|
|
21045
21045
|
init_dist();
|
|
21046
|
-
|
|
21046
|
+
|
|
21047
|
+
// ../../plugins/publishings/x-pub/src/post-rail.ts
|
|
21048
|
+
import { extname, isAbsolute as isAbsolute2 } from "path";
|
|
21047
21049
|
var TARGET = "x";
|
|
21050
|
+
var LOGIN_INSTRUCTION = "bun plugins/publishings/x-pub/src/profile-check.ts login";
|
|
21051
|
+
var STEP_TIMEOUT_MS = 30000;
|
|
21052
|
+
var LOGIN_TIMEOUT_MS = 180000;
|
|
21053
|
+
var LOGIN_URL_RE = /\/(?:i\/flow\/login|login|account\/access)/;
|
|
21054
|
+
var COVER_EXTS = new Set([".png", ".jpg", ".jpeg", ".webp"]);
|
|
21055
|
+
var X_POST_URL = "https://x.com/home";
|
|
21056
|
+
var X_NEW_POST_BUTTON = '[data-testid="SideNav_NewTweet_Button"]';
|
|
21057
|
+
var X_COMPOSE_PATH = "/compose/post";
|
|
21058
|
+
var X_POST_SUBMIT = '[data-testid="tweetButton"]';
|
|
21059
|
+
var POST_SELECTORS = {
|
|
21060
|
+
text: ['[data-testid="tweetTextarea_0"]'],
|
|
21061
|
+
mediaButton: ['button[aria-label="Add photos or video"]', '[aria-label*="Add photos" i]'],
|
|
21062
|
+
fileInput: ['input[data-testid="fileInput"]', '[data-testid="fileInput"]'],
|
|
21063
|
+
mediaPreview: ['[data-testid="attachments"]', '[aria-label*="Media" i]'],
|
|
21064
|
+
profileLink: ['a[data-testid="AppTabBar_Profile_Link"]']
|
|
21065
|
+
};
|
|
21066
|
+
var isPostAuthenticated = async (page) => {
|
|
21067
|
+
if (LOGIN_URL_RE.test(page.url()))
|
|
21068
|
+
return false;
|
|
21069
|
+
return (await trySelectors(page, [X_NEW_POST_BUTTON], { visible: false })).found;
|
|
21070
|
+
};
|
|
21071
|
+
var POST_CONFIG = {
|
|
21072
|
+
channel: TARGET,
|
|
21073
|
+
homeUrl: X_POST_URL,
|
|
21074
|
+
isAuthenticated: isPostAuthenticated,
|
|
21075
|
+
loginTimeoutMs: LOGIN_TIMEOUT_MS,
|
|
21076
|
+
checkHeadedOnly: true
|
|
21077
|
+
};
|
|
21078
|
+
function fail(error) {
|
|
21079
|
+
return ResultSchema.parse({ ok: false, target: TARGET, error, effect: "none" });
|
|
21080
|
+
}
|
|
21081
|
+
function needsLogin(error) {
|
|
21082
|
+
const text = error instanceof Error ? error.message : String(error);
|
|
21083
|
+
return /login|sign in|logged out/i.test(text);
|
|
21084
|
+
}
|
|
21085
|
+
function errorMessage3(error) {
|
|
21086
|
+
return error instanceof Error ? error.message : String(error);
|
|
21087
|
+
}
|
|
21088
|
+
async function resolveCover(raw, fs = createNodeFileSystem()) {
|
|
21089
|
+
if (raw === undefined)
|
|
21090
|
+
return;
|
|
21091
|
+
if (typeof raw !== "string" || raw.trim() === "") {
|
|
21092
|
+
return { error: `x post cover must be a non-empty local path, got '${String(raw)}'` };
|
|
21093
|
+
}
|
|
21094
|
+
if (!isAbsolute2(raw))
|
|
21095
|
+
return { error: `x post cover must be an absolute path, got '${raw}'` };
|
|
21096
|
+
if (!COVER_EXTS.has(extname(raw).toLowerCase())) {
|
|
21097
|
+
return { error: `x post cover must be .png/.jpg/.jpeg/.webp, got '${extname(raw) || "(none)"}'` };
|
|
21098
|
+
}
|
|
21099
|
+
if (!await fs.exists(raw))
|
|
21100
|
+
return { error: `x post cover does not exist: ${raw}` };
|
|
21101
|
+
return { path: raw };
|
|
21102
|
+
}
|
|
21103
|
+
|
|
21104
|
+
class XPostBrowserTransport {
|
|
21105
|
+
kind = "browser";
|
|
21106
|
+
launcher;
|
|
21107
|
+
stepTimeoutMs;
|
|
21108
|
+
constructor(deps = {}) {
|
|
21109
|
+
this.launcher = deps.launcher ?? kkBrowserLauncher;
|
|
21110
|
+
this.stepTimeoutMs = deps.stepTimeoutMs ?? STEP_TIMEOUT_MS;
|
|
21111
|
+
}
|
|
21112
|
+
async publish(payload) {
|
|
21113
|
+
const requested = payload.content.metadata?.publishStatus;
|
|
21114
|
+
if (requested === "draft") {
|
|
21115
|
+
return fail("x post has no draft: the compose surface publishes immediately \u2014 plan this target dummy/off or launch it live");
|
|
21116
|
+
}
|
|
21117
|
+
if (requested !== undefined && requested !== "public") {
|
|
21118
|
+
return fail(`unknown publishStatus '${requested}' for x post: expected 'public' or absent`);
|
|
21119
|
+
}
|
|
21120
|
+
const text = (payload.content.body ?? payload.content.title ?? "").trim();
|
|
21121
|
+
if (text === "")
|
|
21122
|
+
return fail("x post requires non-empty Content.body or Content.title");
|
|
21123
|
+
const cover = await resolveCover(payload.content.metadata?.coverPath ?? payload.options?.coverPath ?? payload.content.metadata?.coverImage);
|
|
21124
|
+
if (cover !== undefined && "error" in cover)
|
|
21125
|
+
return fail(cover.error);
|
|
21126
|
+
const override = typeof payload.options?.profileDir === "string" ? payload.options.profileDir : undefined;
|
|
21127
|
+
const profileDir = resolveChannelProfileDir(POST_CONFIG.channel, override);
|
|
21128
|
+
const session = await checkChannelSession(POST_CONFIG, {
|
|
21129
|
+
profileDir,
|
|
21130
|
+
launcher: this.launcher,
|
|
21131
|
+
headedOnly: true,
|
|
21132
|
+
timeoutMs: this.stepTimeoutMs
|
|
21133
|
+
});
|
|
21134
|
+
if (session.status !== "verified") {
|
|
21135
|
+
return fail(`${TARGET} session preflight refused: ${session.detail} \u2014 run: ${LOGIN_INSTRUCTION}`);
|
|
21136
|
+
}
|
|
21137
|
+
try {
|
|
21138
|
+
return await withProfilePage({
|
|
21139
|
+
profileDir,
|
|
21140
|
+
url: X_POST_URL,
|
|
21141
|
+
isAuthenticated: isPostAuthenticated,
|
|
21142
|
+
headless: payload.options?.headless === true,
|
|
21143
|
+
launcher: this.launcher,
|
|
21144
|
+
timeoutMs: this.stepTimeoutMs
|
|
21145
|
+
}, async ({ page }) => this.runPostFlow(page, text, cover !== undefined && "path" in cover ? cover.path : undefined, profileDir));
|
|
21146
|
+
} catch (error) {
|
|
21147
|
+
const hint = needsLogin(error) ? ` \u2014 run: ${LOGIN_INSTRUCTION}` : "";
|
|
21148
|
+
return fail(`${errorMessage3(error)}${hint}`);
|
|
21149
|
+
}
|
|
21150
|
+
}
|
|
21151
|
+
async newestStatusId(page, handleHref) {
|
|
21152
|
+
const target = `https://x.com${handleHref}`;
|
|
21153
|
+
if (!page.url().startsWith(target)) {
|
|
21154
|
+
await page.goto(target, { waitUntil: "domcontentloaded", timeout: this.stepTimeoutMs });
|
|
21155
|
+
} else {
|
|
21156
|
+
await page.reload({ waitUntil: "domcontentloaded", timeout: this.stepTimeoutMs }).catch(() => {});
|
|
21157
|
+
}
|
|
21158
|
+
const link = page.locator('[data-testid="tweet"] a[href*="/status/"]').first();
|
|
21159
|
+
if (await link.count() === 0)
|
|
21160
|
+
return null;
|
|
21161
|
+
const href = await link.getAttribute("href").catch(() => null);
|
|
21162
|
+
return href === null ? null : /\/status\/(\d+)/.exec(href)?.[1] ?? null;
|
|
21163
|
+
}
|
|
21164
|
+
async openComposer(page) {
|
|
21165
|
+
if (!page.url().includes(X_COMPOSE_PATH)) {
|
|
21166
|
+
if (!page.url().startsWith("https://x.com/home")) {
|
|
21167
|
+
await page.goto(X_POST_URL, { waitUntil: "domcontentloaded", timeout: this.stepTimeoutMs });
|
|
21168
|
+
}
|
|
21169
|
+
const opener = await expectOutcome(async () => await page.locator(X_NEW_POST_BUTTON).count() > 0 ? "post button rendered" : null, { timeoutMs: this.stepTimeoutMs, label: "x nav post button" });
|
|
21170
|
+
if (!opener.ok)
|
|
21171
|
+
return `x home never rendered the Post button: ${opener.error}`;
|
|
21172
|
+
await page.locator(X_NEW_POST_BUTTON).first().click();
|
|
21173
|
+
}
|
|
21174
|
+
const composer = await expectOutcome(async () => {
|
|
21175
|
+
if (!page.url().includes(X_COMPOSE_PATH))
|
|
21176
|
+
return null;
|
|
21177
|
+
return await page.locator(POST_SELECTORS.text[0]).count() > 0 ? "composer open" : null;
|
|
21178
|
+
}, { timeoutMs: this.stepTimeoutMs, label: "x compose/post surface" });
|
|
21179
|
+
return composer.ok ? null : `x composer never opened at ${X_COMPOSE_PATH}: ${composer.error}`;
|
|
21180
|
+
}
|
|
21181
|
+
async typeAndEnable(page, text) {
|
|
21182
|
+
const textBox = page.locator(POST_SELECTORS.text[0]).first();
|
|
21183
|
+
const submit = page.locator(X_POST_SUBMIT).first();
|
|
21184
|
+
for (let attempt = 1;attempt <= 3; attempt++) {
|
|
21185
|
+
await page.keyboard.press("Escape").catch(() => {});
|
|
21186
|
+
await page.waitForTimeout(250);
|
|
21187
|
+
const focused = await textBox.click({ force: true }).then(() => true, () => textBox.focus().then(() => true).catch(() => false));
|
|
21188
|
+
if (!focused)
|
|
21189
|
+
return "x composer editor could not be focused";
|
|
21190
|
+
await page.waitForTimeout(300);
|
|
21191
|
+
await textBox.press("ControlOrMeta+a").catch(() => {});
|
|
21192
|
+
await textBox.press("Backspace").catch(() => {});
|
|
21193
|
+
await textBox.pressSequentially(text, { delay: 8 });
|
|
21194
|
+
const enabled = await expectOutcome(async () => await submit.isEnabled().catch(() => false) ? "post enabled" : null, { timeoutMs: Math.min(1e4, this.stepTimeoutMs), label: `x post enabled (attempt ${attempt})` });
|
|
21195
|
+
if (enabled.ok)
|
|
21196
|
+
return null;
|
|
21197
|
+
}
|
|
21198
|
+
return "x post submit never enabled \u2014 the editor did not accept the text in three attempts";
|
|
21199
|
+
}
|
|
21200
|
+
async runPostFlow(page, text, coverPath, profileDir) {
|
|
21201
|
+
const metadata = { operation: "post", driver: "script", publishStatus: "public", profileDir };
|
|
21202
|
+
const handle = await page.locator(POST_SELECTORS.profileLink[0]).first().getAttribute("href").catch(() => null);
|
|
21203
|
+
if (handle === null || handle.trim() === "") {
|
|
21204
|
+
return fail("x post could not read the profile link, so the status id cannot be confirmed");
|
|
21205
|
+
}
|
|
21206
|
+
const baselineId = await this.newestStatusId(page, handle).catch(() => null);
|
|
21207
|
+
const opened = await this.openComposer(page);
|
|
21208
|
+
if (opened !== null)
|
|
21209
|
+
return fail(opened);
|
|
21210
|
+
const typed = await this.typeAndEnable(page, text);
|
|
21211
|
+
if (typed !== null)
|
|
21212
|
+
return fail(`${typed}; refusing to claim a publish`);
|
|
21213
|
+
if (coverPath !== undefined) {
|
|
21214
|
+
const media = await expectOutcome(async () => {
|
|
21215
|
+
const found = await trySelectors(page, POST_SELECTORS.mediaButton);
|
|
21216
|
+
return found.found ? found.selector ?? POST_SELECTORS.mediaButton[0] : null;
|
|
21217
|
+
}, { timeoutMs: this.stepTimeoutMs, label: "x media button" });
|
|
21218
|
+
if (!media.ok)
|
|
21219
|
+
return fail(`x media control never attached: ${media.error}`);
|
|
21220
|
+
await page.locator(media.evidence).first().click();
|
|
21221
|
+
const input = await resolveSelector(page, POST_SELECTORS.fileInput, {
|
|
21222
|
+
timeoutMs: this.stepTimeoutMs,
|
|
21223
|
+
label: "x post media input"
|
|
21224
|
+
});
|
|
21225
|
+
await uploadFile(page, input, coverPath, { timeoutMs: this.stepTimeoutMs });
|
|
21226
|
+
const attached = await expectOutcome(async () => await page.locator(POST_SELECTORS.mediaPreview[0]).count() > 0 ? "media attached" : null, { timeoutMs: this.stepTimeoutMs, label: "x post media" });
|
|
21227
|
+
if (!attached.ok)
|
|
21228
|
+
return fail(`x post image was uploaded but never rendered: ${attached.error}`);
|
|
21229
|
+
const reEnabled = await expectOutcome(async () => await page.locator(X_POST_SUBMIT).first().isEnabled().catch(() => false) ? "post re-enabled" : null, { timeoutMs: this.stepTimeoutMs * 4, label: "x post submit enabled after media" });
|
|
21230
|
+
if (!reEnabled.ok)
|
|
21231
|
+
return fail(`x post submit stayed disabled after the media: ${reEnabled.error}`);
|
|
21232
|
+
}
|
|
21233
|
+
await page.locator(X_POST_SUBMIT).first().click();
|
|
21234
|
+
const receipt = await expectOutcome(async () => {
|
|
21235
|
+
const id = await this.newestStatusId(page, handle);
|
|
21236
|
+
if (id === null)
|
|
21237
|
+
return null;
|
|
21238
|
+
if (baselineId !== null && id === baselineId)
|
|
21239
|
+
return null;
|
|
21240
|
+
return `https://x.com${handle}/status/${id}`;
|
|
21241
|
+
}, { timeoutMs: this.stepTimeoutMs, label: "x status receipt" });
|
|
21242
|
+
if (!receipt.ok) {
|
|
21243
|
+
return fail(`x post receipt not confirmed \u2014 Post was clicked but no new status id appeared on the profile (${receipt.error}); an unobserved submit is never reported as published`);
|
|
21244
|
+
}
|
|
21245
|
+
const id = /\/status\/(\d+)/.exec(receipt.evidence)?.[1];
|
|
21246
|
+
return ResultSchema.parse({
|
|
21247
|
+
ok: true,
|
|
21248
|
+
target: TARGET,
|
|
21249
|
+
...id === undefined ? {} : { id },
|
|
21250
|
+
url: receipt.evidence,
|
|
21251
|
+
message: `x post published and confirmed in profile ${profileDir}`,
|
|
21252
|
+
metadata: { ...metadata, confirmedBy: "profile-timeline" }
|
|
21253
|
+
});
|
|
21254
|
+
}
|
|
21255
|
+
}
|
|
21256
|
+
|
|
21257
|
+
// ../../plugins/publishings/x-pub/src/index.ts
|
|
21258
|
+
var REQUEST_TIMEOUT_MS = 120000;
|
|
21259
|
+
var TARGET2 = "x";
|
|
21048
21260
|
var TWEETS_URL = "https://api.twitter.com/2/tweets";
|
|
21049
21261
|
var TOKEN_ENVS = ["X_API_KEY", "X_API_SECRET", "X_ACCESS_TOKEN", "X_ACCESS_TOKEN_SECRET"];
|
|
21050
|
-
function
|
|
21051
|
-
return ResultSchema.parse({ ok: false, target:
|
|
21262
|
+
function fail2(error) {
|
|
21263
|
+
return ResultSchema.parse({ ok: false, target: TARGET2, error });
|
|
21052
21264
|
}
|
|
21053
21265
|
function percentEncode(value) {
|
|
21054
21266
|
return encodeURIComponent(value).replace(/[!'()*]/g, (c) => `%${c.charCodeAt(0).toString(16).toUpperCase()}`);
|
|
@@ -21085,21 +21297,21 @@ class XPostApiTransport {
|
|
|
21085
21297
|
async publish(payload) {
|
|
21086
21298
|
const requestedStatus = payload.content.metadata?.publishStatus;
|
|
21087
21299
|
if (requestedStatus === "draft") {
|
|
21088
|
-
return
|
|
21300
|
+
return fail2("x post has no draft: the post API publishes immediately \u2014 plan this target dummy/off or launch it live");
|
|
21089
21301
|
}
|
|
21090
21302
|
if (requestedStatus !== undefined && requestedStatus !== "public") {
|
|
21091
|
-
return
|
|
21303
|
+
return fail2(`unknown publishStatus '${String(requestedStatus)}' (expected absent, 'draft' or 'public')`);
|
|
21092
21304
|
}
|
|
21093
21305
|
const missing = TOKEN_ENVS.filter((key) => {
|
|
21094
21306
|
const value = process.env[key];
|
|
21095
21307
|
return !value || value.trim().length === 0;
|
|
21096
21308
|
});
|
|
21097
21309
|
if (missing.length > 0) {
|
|
21098
|
-
return
|
|
21310
|
+
return fail2(`${missing.join(", ")} environment variable${missing.length > 1 ? "s are" : " is"} required: X developer user-context credentials. post does not fall back to a browser (X Automation Rules).`);
|
|
21099
21311
|
}
|
|
21100
21312
|
const text = payload.content.body.trim() || payload.content.title?.trim() || "";
|
|
21101
21313
|
if (text.length === 0) {
|
|
21102
|
-
return
|
|
21314
|
+
return fail2("X post requires Content.body or Content.title");
|
|
21103
21315
|
}
|
|
21104
21316
|
try {
|
|
21105
21317
|
const authorization = oauth1Header({
|
|
@@ -21121,29 +21333,29 @@ class XPostApiTransport {
|
|
|
21121
21333
|
});
|
|
21122
21334
|
if (!response.ok) {
|
|
21123
21335
|
const errorText = (await response.text()).slice(0, 1000);
|
|
21124
|
-
return
|
|
21336
|
+
return fail2(`X POST /2/tweets failed (HTTP ${response.status}): ${errorText.trim() || response.statusText}`);
|
|
21125
21337
|
}
|
|
21126
21338
|
const json = await response.json();
|
|
21127
21339
|
if (typeof json.data?.id !== "string") {
|
|
21128
|
-
return
|
|
21340
|
+
return fail2("X POST /2/tweets response missing data.id");
|
|
21129
21341
|
}
|
|
21130
21342
|
return ResultSchema.parse({
|
|
21131
21343
|
ok: true,
|
|
21132
|
-
target:
|
|
21344
|
+
target: TARGET2,
|
|
21133
21345
|
id: json.data.id,
|
|
21134
21346
|
url: `https://x.com/i/web/status/${json.data.id}`,
|
|
21135
21347
|
message: "Posted via X API v2",
|
|
21136
21348
|
metadata: { operation: "post" }
|
|
21137
21349
|
});
|
|
21138
21350
|
} catch (err) {
|
|
21139
|
-
return
|
|
21351
|
+
return fail2(`X post transport error: ${err instanceof Error ? err.message : String(err)}`);
|
|
21140
21352
|
}
|
|
21141
21353
|
}
|
|
21142
21354
|
}
|
|
21143
21355
|
var ARTICLE_CHANNEL = "x";
|
|
21144
21356
|
var X_ARTICLES_URL = "https://x.com/compose/articles";
|
|
21145
21357
|
var ARTICLE_EDIT_RE = /\/compose\/articles\/edit\/(\d+)/;
|
|
21146
|
-
var
|
|
21358
|
+
var LOGIN_URL_RE2 = /(\/i\/flow\/login|\/login)/;
|
|
21147
21359
|
var ARTICLE_SELECTORS = {
|
|
21148
21360
|
write: ['[data-testid="empty_state_button_text"]', 'button:has-text("Write")', '[aria-label*="Write" i]'],
|
|
21149
21361
|
title: ['textarea[placeholder="Add a title"]', '[data-testid="twitter-article-title"]'],
|
|
@@ -21152,13 +21364,13 @@ var ARTICLE_SELECTORS = {
|
|
|
21152
21364
|
fileInput: ['[data-testid="fileInput"]', 'input[type="file"][accept*="image"]'],
|
|
21153
21365
|
publish: ['[data-testid="publishButton"]', 'button:has-text("Publish")']
|
|
21154
21366
|
};
|
|
21155
|
-
var
|
|
21156
|
-
var
|
|
21157
|
-
var
|
|
21367
|
+
var STEP_TIMEOUT_MS2 = 30000;
|
|
21368
|
+
var LOGIN_TIMEOUT_MS2 = 180000;
|
|
21369
|
+
var LOGIN_INSTRUCTION2 = "bun plugins/publishings/x-pub/src/profile-check.ts login";
|
|
21158
21370
|
var LIVE_URL_ID_RE = /\/articles?\/(\d+)/;
|
|
21159
|
-
var
|
|
21371
|
+
var COVER_EXTS2 = new Set([".png", ".jpg", ".jpeg", ".webp"]);
|
|
21160
21372
|
var isArticleAuthenticated = async (page) => {
|
|
21161
|
-
if (
|
|
21373
|
+
if (LOGIN_URL_RE2.test(page.url()))
|
|
21162
21374
|
return false;
|
|
21163
21375
|
if ((await trySelectors(page, ARTICLE_SELECTORS.write, { visible: false })).found)
|
|
21164
21376
|
return true;
|
|
@@ -21168,26 +21380,26 @@ var ARTICLE_CONFIG = {
|
|
|
21168
21380
|
channel: ARTICLE_CHANNEL,
|
|
21169
21381
|
homeUrl: X_ARTICLES_URL,
|
|
21170
21382
|
isAuthenticated: isArticleAuthenticated,
|
|
21171
|
-
loginTimeoutMs:
|
|
21383
|
+
loginTimeoutMs: LOGIN_TIMEOUT_MS2,
|
|
21172
21384
|
checkHeadedOnly: true
|
|
21173
21385
|
};
|
|
21174
|
-
function
|
|
21386
|
+
function errorMessage4(error) {
|
|
21175
21387
|
return error instanceof Error ? error.message : String(error);
|
|
21176
21388
|
}
|
|
21177
|
-
function
|
|
21389
|
+
function needsLogin2(error) {
|
|
21178
21390
|
return error instanceof LoginTimeoutError || error instanceof BrowserProfileMissingError;
|
|
21179
21391
|
}
|
|
21180
|
-
async function
|
|
21392
|
+
async function resolveCover2(options, content) {
|
|
21181
21393
|
const raw = options?.coverPath ?? content.metadata?.coverImage;
|
|
21182
21394
|
if (raw === undefined)
|
|
21183
21395
|
return;
|
|
21184
21396
|
if (typeof raw !== "string" || raw.trim().length === 0) {
|
|
21185
21397
|
return { error: `cover path must be a non-empty local file path, got '${String(raw)}'` };
|
|
21186
21398
|
}
|
|
21187
|
-
if (!
|
|
21399
|
+
if (!isAbsolute3(raw)) {
|
|
21188
21400
|
return { error: `cover path must be an absolute path, got '${raw}'` };
|
|
21189
21401
|
}
|
|
21190
|
-
if (!
|
|
21402
|
+
if (!COVER_EXTS2.has(extname2(raw).toLowerCase())) {
|
|
21191
21403
|
return { error: `cover path must be a .png, .jpg, .jpeg or .webp file, got '${raw}'` };
|
|
21192
21404
|
}
|
|
21193
21405
|
if (!await createNodeFileSystem().exists(raw)) {
|
|
@@ -21204,19 +21416,19 @@ class XArticleBrowserTransport {
|
|
|
21204
21416
|
constructor(driver = "script", deps = {}) {
|
|
21205
21417
|
this.driver = driver;
|
|
21206
21418
|
this.launcher = deps.launcher ?? kkBrowserLauncher;
|
|
21207
|
-
this.stepTimeoutMs = deps.stepTimeoutMs ??
|
|
21419
|
+
this.stepTimeoutMs = deps.stepTimeoutMs ?? STEP_TIMEOUT_MS2;
|
|
21208
21420
|
}
|
|
21209
21421
|
async publish(payload) {
|
|
21210
21422
|
if (this.driver !== "script") {
|
|
21211
|
-
return
|
|
21423
|
+
return fail2(`unsupported driver '${this.driver}' for x article`);
|
|
21212
21424
|
}
|
|
21213
21425
|
const requested = payload.content.metadata?.publishStatus;
|
|
21214
21426
|
if (requested !== undefined && requested !== "draft" && requested !== "public") {
|
|
21215
|
-
return
|
|
21427
|
+
return fail2(`unknown publishStatus '${String(requested)}' (expected absent, 'draft' or 'public')`);
|
|
21216
21428
|
}
|
|
21217
|
-
const cover = await
|
|
21429
|
+
const cover = await resolveCover2(payload.options, payload.content);
|
|
21218
21430
|
if (cover !== undefined && "error" in cover)
|
|
21219
|
-
return
|
|
21431
|
+
return fail2(cover.error);
|
|
21220
21432
|
const override = typeof payload.options?.profileDir === "string" ? payload.options.profileDir : undefined;
|
|
21221
21433
|
const profileDir = resolveChannelProfileDir(ARTICLE_CHANNEL, override);
|
|
21222
21434
|
const session = await checkChannelSession(ARTICLE_CONFIG, {
|
|
@@ -21226,7 +21438,7 @@ class XArticleBrowserTransport {
|
|
|
21226
21438
|
timeoutMs: this.stepTimeoutMs
|
|
21227
21439
|
});
|
|
21228
21440
|
if (session.status !== "verified") {
|
|
21229
|
-
return
|
|
21441
|
+
return fail2(`${TARGET2} session preflight refused: ${session.detail} \u2014 run: ${LOGIN_INSTRUCTION2}`);
|
|
21230
21442
|
}
|
|
21231
21443
|
const publishStatus = requested === "public" ? "public" : "draft";
|
|
21232
21444
|
try {
|
|
@@ -21239,8 +21451,8 @@ class XArticleBrowserTransport {
|
|
|
21239
21451
|
timeoutMs: this.stepTimeoutMs
|
|
21240
21452
|
}, async ({ page }) => this.runArticleFlow(page, payload.content, publishStatus, cover?.path, profileDir));
|
|
21241
21453
|
} catch (error) {
|
|
21242
|
-
const hint =
|
|
21243
|
-
return
|
|
21454
|
+
const hint = needsLogin2(error) ? ` \u2014 run: ${LOGIN_INSTRUCTION2}` : "";
|
|
21455
|
+
return fail2(`${errorMessage4(error)}${hint}`);
|
|
21244
21456
|
}
|
|
21245
21457
|
}
|
|
21246
21458
|
async runArticleFlow(page, content, publishStatus, coverPath, profileDir) {
|
|
@@ -21273,22 +21485,22 @@ class XArticleBrowserTransport {
|
|
|
21273
21485
|
await page.locator('[role="dialog"] button:has-text("Apply") >> visible=true').first().click({ timeout: this.stepTimeoutMs });
|
|
21274
21486
|
const attached = await expectOutcome(async () => await page.evaluate(coverAttachedScript()) === true ? "cover image rendered in composer" : null, { timeoutMs: this.stepTimeoutMs, label: "cover attachment" });
|
|
21275
21487
|
if (!attached.ok)
|
|
21276
|
-
return
|
|
21488
|
+
return fail2(attached.error);
|
|
21277
21489
|
}
|
|
21278
21490
|
const draft = await expectOutcome(() => probeDraft(page), {
|
|
21279
21491
|
timeoutMs: this.stepTimeoutMs,
|
|
21280
21492
|
label: "x article draft"
|
|
21281
21493
|
});
|
|
21282
21494
|
if (!draft.ok)
|
|
21283
|
-
return
|
|
21495
|
+
return fail2(draft.error);
|
|
21284
21496
|
const id = ARTICLE_EDIT_RE.exec(draft.evidence)?.[1];
|
|
21285
21497
|
if (publishStatus === "draft") {
|
|
21286
21498
|
return ResultSchema.parse({
|
|
21287
21499
|
ok: true,
|
|
21288
|
-
target:
|
|
21500
|
+
target: TARGET2,
|
|
21289
21501
|
...id === undefined ? {} : { id },
|
|
21290
21502
|
url: draft.evidence,
|
|
21291
|
-
message: `${
|
|
21503
|
+
message: `${TARGET2} article draft saved (unpublished) in profile ${profileDir}`,
|
|
21292
21504
|
metadata
|
|
21293
21505
|
});
|
|
21294
21506
|
}
|
|
@@ -21302,13 +21514,13 @@ class XArticleBrowserTransport {
|
|
|
21302
21514
|
label: `x article publish '${publishSelector}'`
|
|
21303
21515
|
});
|
|
21304
21516
|
if (!live.ok)
|
|
21305
|
-
return
|
|
21517
|
+
return fail2(live.error);
|
|
21306
21518
|
return ResultSchema.parse({
|
|
21307
21519
|
ok: true,
|
|
21308
|
-
target:
|
|
21520
|
+
target: TARGET2,
|
|
21309
21521
|
...id === undefined ? {} : { id },
|
|
21310
21522
|
url: live.evidence,
|
|
21311
|
-
message: `${
|
|
21523
|
+
message: `${TARGET2} article published live in profile ${profileDir}`,
|
|
21312
21524
|
metadata
|
|
21313
21525
|
});
|
|
21314
21526
|
}
|
|
@@ -21328,7 +21540,9 @@ function getPublishTransport(operation = "post") {
|
|
|
21328
21540
|
if (process.env.KNOWLEDGE_KIT_PUBLISH_TRANSPORT === "fake") {
|
|
21329
21541
|
return operation === "article" ? new FakeBrowserTransport("script") : new FakeFileCliTransport;
|
|
21330
21542
|
}
|
|
21331
|
-
|
|
21543
|
+
if (operation === "article")
|
|
21544
|
+
return new XArticleBrowserTransport;
|
|
21545
|
+
return process.env.X_POST_TRANSPORT === "api" ? new XPostApiTransport : new XPostBrowserTransport;
|
|
21332
21546
|
}
|
|
21333
21547
|
async function writePublishResult(outputPath, result) {
|
|
21334
21548
|
const outDir = dirname4(outputPath);
|
|
@@ -21348,12 +21562,12 @@ async function processPublishIO(inputPath, outputPath, transport) {
|
|
|
21348
21562
|
}
|
|
21349
21563
|
} catch (error) {
|
|
21350
21564
|
const message = `Invalid Content input: ${error instanceof Error ? error.message : String(error)}`;
|
|
21351
|
-
await writePublishResult(outputPath,
|
|
21565
|
+
await writePublishResult(outputPath, fail2(message));
|
|
21352
21566
|
throw new Error(message);
|
|
21353
21567
|
}
|
|
21354
21568
|
const mode = resolveOperation(options, content);
|
|
21355
21569
|
if (mode.error !== undefined) {
|
|
21356
|
-
await writePublishResult(outputPath,
|
|
21570
|
+
await writePublishResult(outputPath, fail2(mode.error));
|
|
21357
21571
|
throw new Error(mode.error);
|
|
21358
21572
|
}
|
|
21359
21573
|
const operation = mode.operation;
|
|
@@ -21391,13 +21605,19 @@ export {
|
|
|
21391
21605
|
ARTICLE_CONFIG,
|
|
21392
21606
|
ARTICLE_EDIT_RE,
|
|
21393
21607
|
ARTICLE_SELECTORS,
|
|
21394
|
-
LOGIN_URL_RE,
|
|
21608
|
+
LOGIN_URL_RE2 as LOGIN_URL_RE,
|
|
21609
|
+
POST_CONFIG,
|
|
21610
|
+
POST_SELECTORS,
|
|
21395
21611
|
XArticleBrowserTransport,
|
|
21396
21612
|
XPostApiTransport,
|
|
21397
21613
|
X_ARTICLES_URL,
|
|
21614
|
+
X_NEW_POST_BUTTON,
|
|
21398
21615
|
X_OPERATIONS,
|
|
21616
|
+
X_POST_SUBMIT,
|
|
21617
|
+
X_POST_URL,
|
|
21399
21618
|
getPublishTransport,
|
|
21400
21619
|
isArticleAuthenticated,
|
|
21620
|
+
isPostAuthenticated,
|
|
21401
21621
|
main2 as main,
|
|
21402
21622
|
oauth1Header,
|
|
21403
21623
|
processPublishIO,
|
|
@@ -20482,6 +20482,7 @@ var MAX_QUEUED_BYTES = 8 * 1024 * 1024;
|
|
|
20482
20482
|
var DEFAULT_LOGIN_TIMEOUT_MS = 180000;
|
|
20483
20483
|
var DEFAULT_OPEN_NAV_TIMEOUT_MS = 30000;
|
|
20484
20484
|
var DEFAULT_CHECK_TIMEOUT_MS = 30000;
|
|
20485
|
+
var DEFAULT_POLL_MS = 500;
|
|
20485
20486
|
function isInstantBrowserDeath(message) {
|
|
20486
20487
|
return /target page, context or browser has been closed|browser has been closed|target closed/i.test(message);
|
|
20487
20488
|
}
|
|
@@ -20647,6 +20648,16 @@ async function openChannelSession(config, request, deps = {}, stdout = echo) {
|
|
|
20647
20648
|
return 1;
|
|
20648
20649
|
}
|
|
20649
20650
|
const page = context.pages()[0] ?? await context.newPage();
|
|
20651
|
+
const onOpen = config.sessionState?.onOpen;
|
|
20652
|
+
if (onOpen !== undefined) {
|
|
20653
|
+
try {
|
|
20654
|
+
await onOpen({ context, page, profileDir: request.profileDir });
|
|
20655
|
+
} catch (error) {
|
|
20656
|
+
await context.close().catch(() => {});
|
|
20657
|
+
stdout(`${config.channel} profile open failed: ${errorMessage2(error)}`);
|
|
20658
|
+
return 1;
|
|
20659
|
+
}
|
|
20660
|
+
}
|
|
20650
20661
|
try {
|
|
20651
20662
|
await page.goto(request.url, { waitUntil: "commit", timeout: DEFAULT_OPEN_NAV_TIMEOUT_MS });
|
|
20652
20663
|
} catch (error) {
|
|
@@ -20658,6 +20669,36 @@ async function openChannelSession(config, request, deps = {}, stdout = echo) {
|
|
|
20658
20669
|
stdout(`${config.channel} profile open closed: ${request.profileDir}`);
|
|
20659
20670
|
return 0;
|
|
20660
20671
|
}
|
|
20672
|
+
async function loginWithAuthenticatedPage(config, opts) {
|
|
20673
|
+
const context = await opts.launcher.launch({ profileDir: opts.profileDir, headless: false });
|
|
20674
|
+
const sessionCaptured = config.sessionState?.onAuthenticated !== undefined;
|
|
20675
|
+
let captured = false;
|
|
20676
|
+
let facts = {};
|
|
20677
|
+
try {
|
|
20678
|
+
const page = context.pages()[0] ?? await context.newPage();
|
|
20679
|
+
await page.goto(opts.url);
|
|
20680
|
+
if (!await waitUntil(() => Promise.resolve(config.isAuthenticated(page)), opts.timeoutMs)) {
|
|
20681
|
+
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.");
|
|
20682
|
+
}
|
|
20683
|
+
await config.sessionState?.onAuthenticated?.({ context, page, profileDir: opts.profileDir });
|
|
20684
|
+
captured = sessionCaptured;
|
|
20685
|
+
if (opts.captureFacts) {
|
|
20686
|
+
facts = {
|
|
20687
|
+
...await captureSessionFacts(context, config.homeUrl),
|
|
20688
|
+
...config.readIdentity === undefined ? {} : { identity: await readIdentityOrUndefined(config.readIdentity, page) }
|
|
20689
|
+
};
|
|
20690
|
+
}
|
|
20691
|
+
} finally {
|
|
20692
|
+
try {
|
|
20693
|
+
await context.close();
|
|
20694
|
+
} catch {
|
|
20695
|
+
if (captured) {
|
|
20696
|
+
echoError(`${config.channel} browser context close failed after the authenticated session capture; saved state preserved`);
|
|
20697
|
+
}
|
|
20698
|
+
}
|
|
20699
|
+
}
|
|
20700
|
+
return facts;
|
|
20701
|
+
}
|
|
20661
20702
|
async function runProfileCli(config, argv = process.argv.slice(2), deps = {}) {
|
|
20662
20703
|
const stdout = deps.stdout ?? ((line) => {
|
|
20663
20704
|
echo(line);
|
|
@@ -20708,7 +20749,8 @@ async function runProfileCli(config, argv = process.argv.slice(2), deps = {}) {
|
|
|
20708
20749
|
const launcher = deps.launcher ?? kkBrowserLauncher;
|
|
20709
20750
|
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`);
|
|
20710
20751
|
try {
|
|
20711
|
-
|
|
20752
|
+
const captureFacts = url !== undefined;
|
|
20753
|
+
if (!captureFacts && config.sessionState?.onAuthenticated === undefined) {
|
|
20712
20754
|
await loginWithProfile({
|
|
20713
20755
|
profileDir,
|
|
20714
20756
|
url: config.homeUrl,
|
|
@@ -20719,18 +20761,16 @@ async function runProfileCli(config, argv = process.argv.slice(2), deps = {}) {
|
|
|
20719
20761
|
stdout(`${config.channel} profile login verified: ${profileDir}`);
|
|
20720
20762
|
return 0;
|
|
20721
20763
|
}
|
|
20722
|
-
const facts = await
|
|
20764
|
+
const facts = await loginWithAuthenticatedPage(config, {
|
|
20723
20765
|
profileDir,
|
|
20724
|
-
|
|
20725
|
-
url,
|
|
20726
|
-
isAuthenticated: config.isAuthenticated,
|
|
20766
|
+
url: url ?? config.homeUrl,
|
|
20727
20767
|
timeoutMs: loginTimeoutMs,
|
|
20728
|
-
launcher
|
|
20729
|
-
|
|
20730
|
-
|
|
20731
|
-
...config.readIdentity === undefined ? {} : { identity: await readIdentityOrUndefined(config.readIdentity, page) }
|
|
20732
|
-
}));
|
|
20768
|
+
launcher,
|
|
20769
|
+
captureFacts
|
|
20770
|
+
});
|
|
20733
20771
|
stdout(`${config.channel} profile login verified: ${profileDir}`);
|
|
20772
|
+
if (url === undefined)
|
|
20773
|
+
return 0;
|
|
20734
20774
|
stdout(JSON.stringify({
|
|
20735
20775
|
status: "verified",
|
|
20736
20776
|
profileDir,
|
|
@@ -20753,6 +20793,16 @@ async function runProfileCli(config, argv = process.argv.slice(2), deps = {}) {
|
|
|
20753
20793
|
stdout(JSON.stringify(result));
|
|
20754
20794
|
return result.status === "verified" ? 0 : 1;
|
|
20755
20795
|
}
|
|
20796
|
+
async function waitUntil(predicate, timeoutMs, pollMs = DEFAULT_POLL_MS) {
|
|
20797
|
+
const deadline = Date.now() + timeoutMs;
|
|
20798
|
+
while (Date.now() < deadline) {
|
|
20799
|
+
if (await predicate()) {
|
|
20800
|
+
return true;
|
|
20801
|
+
}
|
|
20802
|
+
await new Promise((resolve) => setTimeout(resolve, pollMs));
|
|
20803
|
+
}
|
|
20804
|
+
return predicate();
|
|
20805
|
+
}
|
|
20756
20806
|
async function captureSessionFacts(context, url) {
|
|
20757
20807
|
let cookies;
|
|
20758
20808
|
try {
|
|
@@ -21050,6 +21100,8 @@ if (false) {}
|
|
|
21050
21100
|
var CJK_TERMINATORS = new Set(["\u3002", "\uFF01", "\uFF1F"]);
|
|
21051
21101
|
var LATIN_TERMINATORS = new Set([".", "!", "?"]);
|
|
21052
21102
|
var ATTACHED_CLOSERS = new Set(["\u201D", "\u2019", "\u300D", "\u300F", "\uFF09", ")", '"', "'"]);
|
|
21103
|
+
// ../../plugins/publishings/x-pub/src/post-rail.ts
|
|
21104
|
+
var COVER_EXTS = new Set([".png", ".jpg", ".jpeg", ".webp"]);
|
|
21053
21105
|
// ../../plugins/publishings/x-pub/src/index.ts
|
|
21054
21106
|
var ARTICLE_CHANNEL = "x";
|
|
21055
21107
|
var X_ARTICLES_URL = "https://x.com/compose/articles";
|
|
@@ -21063,7 +21115,7 @@ var ARTICLE_SELECTORS = {
|
|
|
21063
21115
|
publish: ['[data-testid="publishButton"]', 'button:has-text("Publish")']
|
|
21064
21116
|
};
|
|
21065
21117
|
var LOGIN_TIMEOUT_MS = 180000;
|
|
21066
|
-
var
|
|
21118
|
+
var COVER_EXTS2 = new Set([".png", ".jpg", ".jpeg", ".webp"]);
|
|
21067
21119
|
var isArticleAuthenticated = async (page) => {
|
|
21068
21120
|
if (LOGIN_URL_RE.test(page.url()))
|
|
21069
21121
|
return false;
|
|
@@ -31,6 +31,16 @@ import {
|
|
|
31
31
|
import { createNodeFileSystem } from '@gobing-ai/ts-runtime';
|
|
32
32
|
import { echoError } from '@gobing-ai/ts-utils';
|
|
33
33
|
import type { Page } from 'playwright';
|
|
34
|
+
import { XPostBrowserTransport } from './post-rail';
|
|
35
|
+
|
|
36
|
+
export {
|
|
37
|
+
isPostAuthenticated,
|
|
38
|
+
POST_CONFIG,
|
|
39
|
+
POST_SELECTORS,
|
|
40
|
+
X_NEW_POST_BUTTON,
|
|
41
|
+
X_POST_SUBMIT,
|
|
42
|
+
X_POST_URL,
|
|
43
|
+
} from './post-rail';
|
|
34
44
|
|
|
35
45
|
/** Per-request timeout (ms) for the X API call — Bun's `fetch` has no default deadline (R5). */
|
|
36
46
|
const REQUEST_TIMEOUT_MS = 120_000;
|
|
@@ -463,7 +473,11 @@ export function getPublishTransport(operation: 'post' | 'article' = 'post'): Pub
|
|
|
463
473
|
if (process.env.KNOWLEDGE_KIT_PUBLISH_TRANSPORT === 'fake') {
|
|
464
474
|
return operation === 'article' ? new FakeBrowserTransport('script') : new FakeFileCliTransport();
|
|
465
475
|
}
|
|
466
|
-
|
|
476
|
+
if (operation === 'article') return new XArticleBrowserTransport();
|
|
477
|
+
// kk bot first (2026-11-16 operator decision): the post rail drives the signed-in composer, so no
|
|
478
|
+
// X API credentials are needed. `X_POST_TRANSPORT=api` keeps the official API for callers that
|
|
479
|
+
// hold them.
|
|
480
|
+
return process.env.X_POST_TRANSPORT === 'api' ? new XPostApiTransport() : new XPostBrowserTransport();
|
|
467
481
|
}
|
|
468
482
|
|
|
469
483
|
async function writePublishResult(outputPath: string, result: Result): Promise<void> {
|