@lightcone-ai/daemon 0.10.2 → 0.10.3
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/agent-manager.js +9 -86
package/package.json
CHANGED
package/src/agent-manager.js
CHANGED
|
@@ -144,7 +144,6 @@ export class AgentManager {
|
|
|
144
144
|
// key → true (spawn in progress)
|
|
145
145
|
this.starting = new Set();
|
|
146
146
|
this.directiveRefreshTimers = new Map();
|
|
147
|
-
this.directiveGovernanceCache = new Map();
|
|
148
147
|
}
|
|
149
148
|
|
|
150
149
|
_key(agentId, workspaceId) {
|
|
@@ -258,90 +257,6 @@ export class AgentManager {
|
|
|
258
257
|
return arg;
|
|
259
258
|
}
|
|
260
259
|
|
|
261
|
-
_normalizeDirectiveForLocalSpawn(directive, {
|
|
262
|
-
agentId,
|
|
263
|
-
workspaceId,
|
|
264
|
-
workspaceDir,
|
|
265
|
-
chatBridgePath,
|
|
266
|
-
config,
|
|
267
|
-
}) {
|
|
268
|
-
const authToken = config?.authToken || this.machineApiKey;
|
|
269
|
-
const userId = config?.userId ?? 'default';
|
|
270
|
-
const profileRoot = path.join(homedir(), '.lightcone', 'chrome-profiles');
|
|
271
|
-
const replacements = {
|
|
272
|
-
'${SERVER_URL}': this.serverUrl,
|
|
273
|
-
'${MACHINE_API_KEY}': authToken,
|
|
274
|
-
'${AGENT_ID}': agentId,
|
|
275
|
-
'${WORKSPACE_ID}': workspaceId ?? '',
|
|
276
|
-
'${WORKSPACE_DIR}': workspaceDir,
|
|
277
|
-
'${XHS_PROFILE_DIR}': path.join(profileRoot, `xhs-${userId}`),
|
|
278
|
-
'${DOUYIN_PROFILE_DIR}': path.join(profileRoot, `douyin-${userId}`),
|
|
279
|
-
'${KUAISHOU_PROFILE_DIR}': path.join(profileRoot, `kuaishou-${userId}`),
|
|
280
|
-
};
|
|
281
|
-
|
|
282
|
-
const normalized = this._replaceDirectiveValue(normalizeObject(directive), replacements);
|
|
283
|
-
const mcpServers = normalizeObject(normalized.mcp_servers);
|
|
284
|
-
const governanceLease = normalizeObject(normalized.policy_lease);
|
|
285
|
-
const leaseValidUntil = Date.parse(governanceLease.valid_until ?? '');
|
|
286
|
-
const leaseState = Number.isFinite(leaseValidUntil) && leaseValidUntil > Date.now() ? 'valid' : 'expired';
|
|
287
|
-
const governanceEnv = normalized.spawn_bundle_id || normalized.policy_version || normalized.directive_id
|
|
288
|
-
? {
|
|
289
|
-
LC_GOVERNANCE_DIRECTIVE_ID: normalized.directive_id ?? '',
|
|
290
|
-
LC_GOVERNANCE_SPAWN_BUNDLE_ID: normalized.spawn_bundle_id ?? '',
|
|
291
|
-
LC_GOVERNANCE_POLICY_VERSION: normalized.policy_version ?? '',
|
|
292
|
-
LC_GOVERNANCE_POLICY_LEASE_ID: governanceLease.lease_id ?? '',
|
|
293
|
-
LC_GOVERNANCE_POLICY_LEASE_STATE: leaseState,
|
|
294
|
-
LC_GOVERNANCE_POLICY_LEASE_JSON: JSON.stringify(governanceLease),
|
|
295
|
-
LC_GOVERNANCE_MCP_CLASSIFICATION_JSON: JSON.stringify(normalizeObject(normalized.mcp_classification)),
|
|
296
|
-
LC_GOVERNANCE_WORKSPACE_ID: workspaceId ?? '',
|
|
297
|
-
}
|
|
298
|
-
: {};
|
|
299
|
-
|
|
300
|
-
for (const [serverKey, rawServer] of Object.entries(mcpServers)) {
|
|
301
|
-
const server = normalizeObject(rawServer);
|
|
302
|
-
const args = Array.isArray(server.args) ? server.args.map((arg) => this._resolveDirectiveArgPath(String(arg), { chatBridgePath })) : [];
|
|
303
|
-
const env = Object.fromEntries(Object.entries(normalizeObject(server.env)).map(([k, v]) => [k, String(v ?? '')]));
|
|
304
|
-
const baseEnv = {};
|
|
305
|
-
if (serverKey === 'chat' || serverKey === 'publisher' || serverKey === 'platform') {
|
|
306
|
-
baseEnv.SERVER_URL = this.serverUrl;
|
|
307
|
-
baseEnv.MACHINE_API_KEY = authToken;
|
|
308
|
-
baseEnv.AGENT_ID = agentId;
|
|
309
|
-
baseEnv.WORKSPACE_ID = workspaceId ?? '';
|
|
310
|
-
baseEnv.WORKSPACE_DIR = workspaceDir;
|
|
311
|
-
} else if (serverKey === 'workspace-migrate') {
|
|
312
|
-
baseEnv.SERVER_URL = this.serverUrl;
|
|
313
|
-
baseEnv.MACHINE_API_KEY = authToken;
|
|
314
|
-
baseEnv.AGENT_ID = agentId;
|
|
315
|
-
}
|
|
316
|
-
mcpServers[serverKey] = {
|
|
317
|
-
...server,
|
|
318
|
-
args,
|
|
319
|
-
env: {
|
|
320
|
-
...env,
|
|
321
|
-
...baseEnv,
|
|
322
|
-
...(serverKey === 'chat' ? governanceEnv : {}),
|
|
323
|
-
},
|
|
324
|
-
};
|
|
325
|
-
}
|
|
326
|
-
|
|
327
|
-
normalized.mcp_servers = mcpServers;
|
|
328
|
-
return normalized;
|
|
329
|
-
}
|
|
330
|
-
|
|
331
|
-
_cacheDirectiveGovernanceContract(key, normalizedDirective, workspaceId) {
|
|
332
|
-
const lease = normalizeObject(normalizedDirective?.policy_lease);
|
|
333
|
-
const cached = {
|
|
334
|
-
directiveId: normalizedDirective?.directive_id ?? null,
|
|
335
|
-
spawnBundleId: normalizedDirective?.spawn_bundle_id ?? null,
|
|
336
|
-
policyVersion: normalizedDirective?.policy_version ?? null,
|
|
337
|
-
leaseId: lease.lease_id ?? null,
|
|
338
|
-
workspaceId: workspaceId ?? null,
|
|
339
|
-
updatedAt: new Date().toISOString(),
|
|
340
|
-
};
|
|
341
|
-
this.directiveGovernanceCache.set(key, cached);
|
|
342
|
-
return cached;
|
|
343
|
-
}
|
|
344
|
-
|
|
345
260
|
_replaceDirectiveValue(value, replacements) {
|
|
346
261
|
if (typeof value === 'string') return replacePlaceholders(value, replacements);
|
|
347
262
|
if (Array.isArray(value)) return value.map((item) => this._replaceDirectiveValue(item, replacements));
|
|
@@ -419,6 +334,7 @@ export class AgentManager {
|
|
|
419
334
|
agentId,
|
|
420
335
|
workspaceId,
|
|
421
336
|
startupMsg,
|
|
337
|
+
config,
|
|
422
338
|
}) {
|
|
423
339
|
const systemPrompt = typeof directive?.system_prompt === 'string'
|
|
424
340
|
? directive.system_prompt
|
|
@@ -428,13 +344,19 @@ export class AgentManager {
|
|
|
428
344
|
? `${codexBasePrompt}\n\nNew message received:\n\n${this._formatDeliveryText(startupMsg.message)}\n\nRespond as appropriate. Complete all required work before stopping.`
|
|
429
345
|
: codexBasePrompt;
|
|
430
346
|
|
|
347
|
+
const authToken = config?.authToken || this.machineApiKey;
|
|
348
|
+
const userId = config?.userId ?? 'default';
|
|
349
|
+
const profileRoot = path.join(homedir(), '.lightcone', 'chrome-profiles');
|
|
431
350
|
const baseReplacements = {
|
|
432
351
|
'__CHAT_BRIDGE_PATH__': chatBridgePath,
|
|
433
352
|
'__WORKSPACE_DIR__': workspaceDir,
|
|
434
353
|
'__SERVER_URL__': this.serverUrl,
|
|
435
|
-
'__MACHINE_API_KEY__':
|
|
354
|
+
'__MACHINE_API_KEY__': authToken,
|
|
436
355
|
'__AGENT_ID__': agentId,
|
|
437
356
|
'__WORKSPACE_ID__': workspaceId ?? '',
|
|
357
|
+
'${XHS_PROFILE_DIR}': path.join(profileRoot, `xhs-${userId}`),
|
|
358
|
+
'${DOUYIN_PROFILE_DIR}': path.join(profileRoot, `douyin-${userId}`),
|
|
359
|
+
'${KUAISHOU_PROFILE_DIR}': path.join(profileRoot, `kuaishou-${userId}`),
|
|
438
360
|
};
|
|
439
361
|
const mcpServers = this._resolveDirectiveMcpServers(directive, baseReplacements);
|
|
440
362
|
|
|
@@ -737,6 +659,7 @@ export class AgentManager {
|
|
|
737
659
|
agentId,
|
|
738
660
|
workspaceId,
|
|
739
661
|
startupMsg,
|
|
662
|
+
config: runtimeConfig,
|
|
740
663
|
});
|
|
741
664
|
} catch (err) {
|
|
742
665
|
console.log(`[AgentManager] Failed to build spawn plan for ${agentId}: ${err.message}`);
|