@lightcone-ai/daemon 0.15.62 → 0.15.63
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/mcp-servers/publisher/index.js +18 -11
- package/package.json +1 -1
|
@@ -74,6 +74,10 @@ function getProfileDir(platform, credentialId = null) {
|
|
|
74
74
|
return process.env[key] ?? null;
|
|
75
75
|
}
|
|
76
76
|
|
|
77
|
+
function sessionKeyFor(platform, credentialId = null) {
|
|
78
|
+
return credentialId ? `${platform}:cred-${credentialId}` : platform;
|
|
79
|
+
}
|
|
80
|
+
|
|
77
81
|
function getAdapterClass(platform) {
|
|
78
82
|
const AdapterClass = ADAPTER_REGISTRY[platform];
|
|
79
83
|
if (!AdapterClass) throw new Error(`Unknown platform: ${platform}`);
|
|
@@ -96,7 +100,7 @@ async function getAdapter(platform, credentialId = null) {
|
|
|
96
100
|
}
|
|
97
101
|
// Pool session by (platform, credentialId) when credential is specified — different
|
|
98
102
|
// credentials on the same platform must NOT share a CDP session (D17 §6.6 isolation).
|
|
99
|
-
const sessionKey =
|
|
103
|
+
const sessionKey = sessionKeyFor(platform, credentialId);
|
|
100
104
|
const cdp = await getSession(sessionKey, profileDir);
|
|
101
105
|
return createAdapter(platform, cdp);
|
|
102
106
|
}
|
|
@@ -113,7 +117,7 @@ async function withPublisherProfile(platform, fn, credentialId = null) {
|
|
|
113
117
|
owner: `publisher:${lockKey}`,
|
|
114
118
|
timeoutMs: 30_000,
|
|
115
119
|
staleMs: 20 * 60 * 1000,
|
|
116
|
-
}, fn);
|
|
120
|
+
}, () => fn(profileDir));
|
|
117
121
|
}
|
|
118
122
|
|
|
119
123
|
async function api(method, path, body) {
|
|
@@ -474,22 +478,25 @@ server.tool(
|
|
|
474
478
|
|
|
475
479
|
server.tool(
|
|
476
480
|
'check_login_status',
|
|
477
|
-
'
|
|
481
|
+
'检查指定平台账号的浏览器 Profile 是否仍处于登录状态。如果有多个账号,必须传真实 credential_id。',
|
|
478
482
|
{
|
|
479
483
|
platform: z.enum(['xhs', 'douyin', 'kuaishou', 'bilibili']).describe('目标平台'),
|
|
484
|
+
credential_id: z.string().optional().describe('可选。真实 credential UUID;多账号场景必须传入,检测会使用 ~/.lightcone/chrome-profiles/cred-{credential_id}。'),
|
|
480
485
|
},
|
|
481
|
-
async ({ platform }) => {
|
|
486
|
+
async ({ platform, credential_id }) => {
|
|
482
487
|
const label = PLATFORM_LABELS[platform] ?? platform;
|
|
488
|
+
const sessionKey = sessionKeyFor(platform, credential_id ?? null);
|
|
483
489
|
try {
|
|
484
|
-
const { loggedIn, url, profileDir } = await withPublisherProfile(platform, async () => {
|
|
485
|
-
const adapter = await getAdapter(platform);
|
|
486
|
-
|
|
487
|
-
|
|
490
|
+
const { loggedIn, url, profileDir } = await withPublisherProfile(platform, async (resolvedProfileDir) => {
|
|
491
|
+
const adapter = await getAdapter(platform, credential_id ?? null);
|
|
492
|
+
const status = await adapter.checkLoginStatus();
|
|
493
|
+
return { ...status, profileDir: resolvedProfileDir };
|
|
494
|
+
}, credential_id ?? null);
|
|
488
495
|
// Always close session after login check so the Chrome profile is free
|
|
489
496
|
// for the daemon's publish job (which runs in a separate process)
|
|
490
|
-
closeSession(
|
|
497
|
+
closeSession(sessionKey);
|
|
491
498
|
if (loggedIn) {
|
|
492
|
-
return { content: [{ type: 'text', text: `✓ ${label}
|
|
499
|
+
return { content: [{ type: 'text', text: `✓ ${label} 已登录,可以发布内容。\nprofileDir=${profileDir}` }] };
|
|
493
500
|
} else {
|
|
494
501
|
return {
|
|
495
502
|
content: [{ type: 'text', text: `${label} 未登录或登录已过期。\n调试信息: url=${url}\nprofileDir=${profileDir}\n请在「连接外部账号」中重新扫码连接。` }],
|
|
@@ -497,7 +504,7 @@ server.tool(
|
|
|
497
504
|
};
|
|
498
505
|
}
|
|
499
506
|
} catch (err) {
|
|
500
|
-
closeSession(
|
|
507
|
+
closeSession(sessionKey);
|
|
501
508
|
return { content: [{ type: 'text', text: `检查失败: ${err.message}` }], isError: true };
|
|
502
509
|
}
|
|
503
510
|
}
|