@lightcone-ai/daemon 0.14.11 → 0.14.12
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/package.json +1 -1
- package/src/publish-job-runner.js +57 -18
package/package.json
CHANGED
|
@@ -7,6 +7,7 @@ import { KuaishouAdapter } from '../mcp-servers/publisher/adapters/kuaishou.js';
|
|
|
7
7
|
import { callOfficialTool } from '../mcp-servers/publisher/official-tool-client.js';
|
|
8
8
|
import { runPublishPrecheck } from '../mcp-servers/publisher/precheck.js';
|
|
9
9
|
import { withProfileLock } from './profile-lock.js';
|
|
10
|
+
import { profileDir as getBrowserProfileDir } from './browser-login.js';
|
|
10
11
|
|
|
11
12
|
const PLATFORM_ENV_KEYS = {
|
|
12
13
|
xhs: 'XHS_PROFILE_DIR',
|
|
@@ -36,10 +37,53 @@ function asObject(value) {
|
|
|
36
37
|
return {};
|
|
37
38
|
}
|
|
38
39
|
|
|
39
|
-
function
|
|
40
|
-
const
|
|
41
|
-
|
|
42
|
-
|
|
40
|
+
export function resolveProfileDir(platform, { ownerId } = {}) {
|
|
41
|
+
const envKey = PLATFORM_ENV_KEYS[platform];
|
|
42
|
+
const envValue = normalizeText(envKey ? process.env[envKey] : null);
|
|
43
|
+
if (envValue) {
|
|
44
|
+
return {
|
|
45
|
+
profileDir: envValue,
|
|
46
|
+
source: 'env',
|
|
47
|
+
envKey,
|
|
48
|
+
ownerId: normalizeText(ownerId),
|
|
49
|
+
};
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
const normalizedOwnerId = normalizeText(ownerId);
|
|
53
|
+
if (normalizedOwnerId) {
|
|
54
|
+
return {
|
|
55
|
+
profileDir: getBrowserProfileDir(platform, normalizedOwnerId),
|
|
56
|
+
source: 'owner',
|
|
57
|
+
envKey,
|
|
58
|
+
ownerId: normalizedOwnerId,
|
|
59
|
+
};
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
return {
|
|
63
|
+
profileDir: null,
|
|
64
|
+
source: 'missing_owner',
|
|
65
|
+
envKey,
|
|
66
|
+
ownerId: null,
|
|
67
|
+
};
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
export function resolveExistingProfileDir(platform, { ownerId } = {}) {
|
|
71
|
+
const resolved = resolveProfileDir(platform, { ownerId });
|
|
72
|
+
if (!resolved.profileDir) {
|
|
73
|
+
throw new Error('publish:job missing owner_id; server must include it for cross-machine profile resolution');
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
if (!existsSync(resolved.profileDir)) {
|
|
77
|
+
if (resolved.source === 'env') {
|
|
78
|
+
throw new Error(`Profile dir from ${resolved.envKey} not found: ${resolved.profileDir}`);
|
|
79
|
+
}
|
|
80
|
+
throw new Error(
|
|
81
|
+
`Profile dir for ${platform} not found at ${resolved.profileDir}; ` +
|
|
82
|
+
'user must complete browser-login on this machine first'
|
|
83
|
+
);
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
return resolved.profileDir;
|
|
43
87
|
}
|
|
44
88
|
|
|
45
89
|
function getAdapterClass(platform) {
|
|
@@ -53,22 +97,16 @@ function createStaticAdapter(platform) {
|
|
|
53
97
|
return new AdapterClass(null);
|
|
54
98
|
}
|
|
55
99
|
|
|
56
|
-
async function getAdapter(platform) {
|
|
57
|
-
const
|
|
58
|
-
|
|
59
|
-
throw new Error(`No profile dir for platform="${platform}". Has the user logged in and authorized this machine?`);
|
|
60
|
-
}
|
|
61
|
-
const cdp = await getSession(platform, profileDir);
|
|
100
|
+
async function getAdapter(platform, { ownerId } = {}) {
|
|
101
|
+
const resolvedProfileDir = resolveExistingProfileDir(platform, { ownerId });
|
|
102
|
+
const cdp = await getSession(platform, resolvedProfileDir);
|
|
62
103
|
const AdapterClass = getAdapterClass(platform);
|
|
63
104
|
return new AdapterClass(cdp);
|
|
64
105
|
}
|
|
65
106
|
|
|
66
|
-
async function withPublisherProfile(platform, fn) {
|
|
67
|
-
const
|
|
68
|
-
|
|
69
|
-
throw new Error(`No profile dir for platform="${platform}". Has the user logged in and authorized this machine?`);
|
|
70
|
-
}
|
|
71
|
-
return withProfileLock(platform, profileDir, {
|
|
107
|
+
async function withPublisherProfile(platform, { ownerId } = {}, fn) {
|
|
108
|
+
const resolvedProfileDir = resolveExistingProfileDir(platform, { ownerId });
|
|
109
|
+
return withProfileLock(platform, resolvedProfileDir, {
|
|
72
110
|
owner: `publisher:${platform}`,
|
|
73
111
|
timeoutMs: 30_000,
|
|
74
112
|
staleMs: 20 * 60 * 1000,
|
|
@@ -368,6 +406,7 @@ export async function runPublishJob({ serverUrl, machineApiKey, agentId, workspa
|
|
|
368
406
|
video,
|
|
369
407
|
cover,
|
|
370
408
|
} = buildJobInput(job);
|
|
409
|
+
const ownerId = normalizeText(job?.owner_id ?? job?.ownerId);
|
|
371
410
|
|
|
372
411
|
if (!platform) throw new Error('publish job missing platform');
|
|
373
412
|
if (!contentType) throw new Error('publish job missing content_type');
|
|
@@ -428,8 +467,8 @@ export async function runPublishJob({ serverUrl, machineApiKey, agentId, workspa
|
|
|
428
467
|
});
|
|
429
468
|
|
|
430
469
|
try {
|
|
431
|
-
const { publishResult, healthCheck } = await withPublisherProfile(platform, async () => {
|
|
432
|
-
const adapter = await getAdapter(platform);
|
|
470
|
+
const { publishResult, healthCheck } = await withPublisherProfile(platform, { ownerId }, async () => {
|
|
471
|
+
const adapter = await getAdapter(platform, { ownerId });
|
|
433
472
|
const prePublishLogin = await adapter.checkLoginStatus();
|
|
434
473
|
if (prePublishLogin?.loggedIn === false) {
|
|
435
474
|
throw new Error(`LOGIN_EXPIRED:${platform}`);
|