@adhdev/daemon-core 0.9.77-rc.20 → 0.9.77-rc.22
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/dist/boot/daemon-lifecycle.d.ts +3 -0
- package/dist/index.js +31 -7
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +31 -7
- package/dist/index.mjs.map +1 -1
- package/dist/mesh/mesh-events.d.ts +2 -7
- package/package.json +1 -1
- package/src/boot/daemon-lifecycle.ts +5 -0
- package/src/mesh/mesh-events.ts +38 -9
|
@@ -57,6 +57,8 @@ export interface DaemonInitConfig {
|
|
|
57
57
|
workspace: string;
|
|
58
58
|
sessionId: string;
|
|
59
59
|
}) => void;
|
|
60
|
+
/** Relays a command to a remote mesh node daemon */
|
|
61
|
+
dispatchMeshCommand?: (daemonId: string, command: string, args: Record<string, unknown>) => Promise<any>;
|
|
60
62
|
}
|
|
61
63
|
export interface DaemonComponents {
|
|
62
64
|
providerLoader: ProviderLoader;
|
|
@@ -73,6 +75,7 @@ export interface DaemonComponents {
|
|
|
73
75
|
value: IDEInfo[];
|
|
74
76
|
};
|
|
75
77
|
refreshProviderAvailability: (providerType?: string) => Promise<void>;
|
|
78
|
+
dispatchMeshCommand?: (daemonId: string, command: string, args: Record<string, unknown>) => Promise<any>;
|
|
76
79
|
}
|
|
77
80
|
export interface DaemonDevSupportOptions {
|
|
78
81
|
components: DaemonComponents;
|
package/dist/index.js
CHANGED
|
@@ -1317,15 +1317,35 @@ function formatCompletionMetadata(event) {
|
|
|
1317
1317
|
}
|
|
1318
1318
|
function tryAssignQueueTask(components, meshId, nodeId, sessionId, providerType) {
|
|
1319
1319
|
const task = claimNextTask(meshId, nodeId, sessionId);
|
|
1320
|
-
if (!task)
|
|
1320
|
+
if (!task) {
|
|
1321
|
+
return false;
|
|
1322
|
+
}
|
|
1321
1323
|
LOG.info("MeshQueue", `Node ${nodeId} (${sessionId}) pulled task ${task.id}`);
|
|
1324
|
+
const mesh = getMesh(meshId);
|
|
1325
|
+
const node = mesh?.nodes.find((n) => n.id === nodeId);
|
|
1326
|
+
if (node?.daemonId && components.dispatchMeshCommand) {
|
|
1327
|
+
const isLocalNode = components.cliManager.adapters.has(sessionId);
|
|
1328
|
+
if (!isLocalNode) {
|
|
1329
|
+
components.dispatchMeshCommand(node.daemonId, "agent_command", {
|
|
1330
|
+
targetSessionId: sessionId,
|
|
1331
|
+
cliType: providerType,
|
|
1332
|
+
action: "send_chat",
|
|
1333
|
+
message: task.message
|
|
1334
|
+
}).catch((e) => {
|
|
1335
|
+
LOG.error("MeshQueue", `Failed to dispatch task via P2P to remote node ${nodeId}: ${e?.message}`);
|
|
1336
|
+
updateTaskStatus(meshId, task.id, "failed");
|
|
1337
|
+
});
|
|
1338
|
+
return true;
|
|
1339
|
+
}
|
|
1340
|
+
}
|
|
1322
1341
|
components.cliManager.handleCliCommand("agent_command", {
|
|
1323
1342
|
targetSessionId: sessionId,
|
|
1324
1343
|
cliType: providerType,
|
|
1325
1344
|
action: "send_chat",
|
|
1326
1345
|
message: task.message
|
|
1327
1346
|
}).catch((e) => {
|
|
1328
|
-
LOG.error("MeshQueue", `Failed to dispatch task to node ${nodeId}: ${e?.message}`);
|
|
1347
|
+
LOG.error("MeshQueue", `Failed to dispatch task locally to node ${nodeId}: ${e?.message}`);
|
|
1348
|
+
updateTaskStatus(meshId, task.id, "failed");
|
|
1329
1349
|
});
|
|
1330
1350
|
return true;
|
|
1331
1351
|
}
|
|
@@ -1395,7 +1415,7 @@ Do NOT retry on this node. Consider reassigning to a different node or asking th
|
|
|
1395
1415
|
function injectMeshSystemMessage(components, args) {
|
|
1396
1416
|
if (args.event === "agent:generating_completed") {
|
|
1397
1417
|
const sessionId = readNonEmptyString(args.metadataEvent.targetSessionId);
|
|
1398
|
-
const nodeId = readNonEmptyString(args.
|
|
1418
|
+
const nodeId = readNonEmptyString(args.nodeId) || readNonEmptyString(args.metadataEvent.meshNodeId);
|
|
1399
1419
|
const providerType = readNonEmptyString(args.metadataEvent.providerType);
|
|
1400
1420
|
if (sessionId) {
|
|
1401
1421
|
updateSessionTaskStatus(args.meshId, sessionId, "completed");
|
|
@@ -1407,7 +1427,7 @@ function injectMeshSystemMessage(components, args) {
|
|
|
1407
1427
|
}
|
|
1408
1428
|
} else if (args.event === "agent:ready") {
|
|
1409
1429
|
const sessionId = readNonEmptyString(args.metadataEvent.targetSessionId);
|
|
1410
|
-
const nodeId = readNonEmptyString(args.
|
|
1430
|
+
const nodeId = readNonEmptyString(args.nodeId) || readNonEmptyString(args.metadataEvent.meshNodeId);
|
|
1411
1431
|
const providerType = readNonEmptyString(args.metadataEvent.providerType);
|
|
1412
1432
|
if (sessionId && nodeId && providerType) {
|
|
1413
1433
|
setTimeout(() => {
|
|
@@ -1425,7 +1445,7 @@ function injectMeshSystemMessage(components, args) {
|
|
|
1425
1445
|
try {
|
|
1426
1446
|
appendLedgerEntry(args.meshId, {
|
|
1427
1447
|
kind: ledgerKind,
|
|
1428
|
-
nodeId: readNonEmptyString(args.
|
|
1448
|
+
nodeId: readNonEmptyString(args.nodeId) || readNonEmptyString(args.metadataEvent.meshNodeId) || void 0,
|
|
1429
1449
|
sessionId: readNonEmptyString(args.metadataEvent.targetSessionId) || void 0,
|
|
1430
1450
|
providerType: readNonEmptyString(args.metadataEvent.providerType) || void 0,
|
|
1431
1451
|
payload: {
|
|
@@ -1445,7 +1465,7 @@ function injectMeshSystemMessage(components, args) {
|
|
|
1445
1465
|
const maxRetries = mesh?.policy?.maxTaskRetries ?? 1;
|
|
1446
1466
|
recoveryContext = getSessionRecoveryContext(args.meshId, {
|
|
1447
1467
|
sessionId: readNonEmptyString(args.metadataEvent.targetSessionId) || void 0,
|
|
1448
|
-
nodeId: readNonEmptyString(args.
|
|
1468
|
+
nodeId: readNonEmptyString(args.nodeId) || readNonEmptyString(args.metadataEvent.meshNodeId) || void 0,
|
|
1449
1469
|
maxRetries
|
|
1450
1470
|
});
|
|
1451
1471
|
recoveryContext.failedProviderType = readNonEmptyString(args.metadataEvent.providerType) || null;
|
|
@@ -1540,6 +1560,7 @@ function handleMeshForwardEvent(components, payload) {
|
|
|
1540
1560
|
const nodeLabel = nodeId ? `Node '${nodeId}'` : workspace ? `Agent at ${workspace}` : "Remote agent";
|
|
1541
1561
|
return injectMeshSystemMessage(components, {
|
|
1542
1562
|
meshId,
|
|
1563
|
+
nodeId,
|
|
1543
1564
|
nodeLabel,
|
|
1544
1565
|
event: eventName,
|
|
1545
1566
|
metadataEvent: {
|
|
@@ -1569,10 +1590,12 @@ function setupMeshEventForwarding(components) {
|
|
|
1569
1590
|
if (!meshId) return;
|
|
1570
1591
|
const targetNode = mesh?.nodes?.find((n) => n.workspace === workspace);
|
|
1571
1592
|
const runtimeNodeId = readNonEmptyString(settings.meshNodeId);
|
|
1593
|
+
const resolvedNodeId = targetNode?.id || runtimeNodeId;
|
|
1572
1594
|
const nodeLabel = targetNode ? `Node '${targetNode.id}'` : runtimeNodeId ? `Node '${runtimeNodeId}'` : `Agent at ${workspace}`;
|
|
1573
1595
|
injectMeshSystemMessage(components, {
|
|
1574
1596
|
meshId,
|
|
1575
1597
|
sourceInstanceId: instanceId,
|
|
1598
|
+
nodeId: resolvedNodeId,
|
|
1576
1599
|
nodeLabel,
|
|
1577
1600
|
event: event.event,
|
|
1578
1601
|
metadataEvent: event
|
|
@@ -32324,7 +32347,8 @@ async function initDaemonComponents(config) {
|
|
|
32324
32347
|
cdpManagers,
|
|
32325
32348
|
sessionRegistry,
|
|
32326
32349
|
detectedIdes: detectedIdesRef,
|
|
32327
|
-
refreshProviderAvailability
|
|
32350
|
+
refreshProviderAvailability,
|
|
32351
|
+
dispatchMeshCommand: config.dispatchMeshCommand
|
|
32328
32352
|
};
|
|
32329
32353
|
setupMeshEventForwarding(components);
|
|
32330
32354
|
return components;
|