@adhdev/daemon-core 0.9.77-rc.21 → 0.9.77-rc.23
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 +47 -4
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +47 -4
- 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 +67 -5
|
@@ -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
|
@@ -1321,13 +1321,31 @@ function tryAssignQueueTask(components, meshId, nodeId, sessionId, providerType)
|
|
|
1321
1321
|
return false;
|
|
1322
1322
|
}
|
|
1323
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
|
+
}
|
|
1324
1341
|
components.cliManager.handleCliCommand("agent_command", {
|
|
1325
1342
|
targetSessionId: sessionId,
|
|
1326
1343
|
cliType: providerType,
|
|
1327
1344
|
action: "send_chat",
|
|
1328
1345
|
message: task.message
|
|
1329
1346
|
}).catch((e) => {
|
|
1330
|
-
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");
|
|
1331
1349
|
});
|
|
1332
1350
|
return true;
|
|
1333
1351
|
}
|
|
@@ -1349,6 +1367,15 @@ function triggerMeshQueue(components, meshId) {
|
|
|
1349
1367
|
tryAssignQueueTask(components, meshId, nodeId, sessionId, providerType);
|
|
1350
1368
|
}
|
|
1351
1369
|
}
|
|
1370
|
+
for (const [key, idle] of remoteIdleSessions.entries()) {
|
|
1371
|
+
const node = mesh.nodes.find((n) => n.id === idle.nodeId);
|
|
1372
|
+
if (node) {
|
|
1373
|
+
const assigned = tryAssignQueueTask(components, meshId, idle.nodeId, idle.sessionId, idle.providerType);
|
|
1374
|
+
if (assigned) {
|
|
1375
|
+
remoteIdleSessions.delete(key);
|
|
1376
|
+
}
|
|
1377
|
+
}
|
|
1378
|
+
}
|
|
1352
1379
|
}
|
|
1353
1380
|
function buildMeshSystemMessage(args) {
|
|
1354
1381
|
const metadata = formatCompletionMetadata(args.metadataEvent);
|
|
@@ -1412,12 +1439,26 @@ function injectMeshSystemMessage(components, args) {
|
|
|
1412
1439
|
const nodeId = readNonEmptyString(args.nodeId) || readNonEmptyString(args.metadataEvent.meshNodeId);
|
|
1413
1440
|
const providerType = readNonEmptyString(args.metadataEvent.providerType);
|
|
1414
1441
|
if (sessionId && nodeId && providerType) {
|
|
1442
|
+
remoteIdleSessions.set(`${nodeId}:${sessionId}`, { nodeId, sessionId, providerType });
|
|
1415
1443
|
setTimeout(() => {
|
|
1416
|
-
tryAssignQueueTask(components, args.meshId, nodeId, sessionId, providerType);
|
|
1444
|
+
const assigned = tryAssignQueueTask(components, args.meshId, nodeId, sessionId, providerType);
|
|
1445
|
+
if (assigned) {
|
|
1446
|
+
remoteIdleSessions.delete(`${nodeId}:${sessionId}`);
|
|
1447
|
+
}
|
|
1417
1448
|
}, 500);
|
|
1418
1449
|
}
|
|
1450
|
+
} else if (args.event === "agent:generating_started") {
|
|
1451
|
+
const sessionId = readNonEmptyString(args.metadataEvent.targetSessionId);
|
|
1452
|
+
const nodeId = readNonEmptyString(args.nodeId) || readNonEmptyString(args.metadataEvent.meshNodeId);
|
|
1453
|
+
if (sessionId && nodeId) {
|
|
1454
|
+
remoteIdleSessions.delete(`${nodeId}:${sessionId}`);
|
|
1455
|
+
}
|
|
1419
1456
|
} else if (args.event === "agent:stopped") {
|
|
1420
1457
|
const sessionId = readNonEmptyString(args.metadataEvent.targetSessionId);
|
|
1458
|
+
const nodeId = readNonEmptyString(args.nodeId) || readNonEmptyString(args.metadataEvent.meshNodeId);
|
|
1459
|
+
if (sessionId && nodeId) {
|
|
1460
|
+
remoteIdleSessions.delete(`${nodeId}:${sessionId}`);
|
|
1461
|
+
}
|
|
1421
1462
|
if (sessionId) {
|
|
1422
1463
|
updateSessionTaskStatus(args.meshId, sessionId, "failed");
|
|
1423
1464
|
}
|
|
@@ -1584,7 +1625,7 @@ function setupMeshEventForwarding(components) {
|
|
|
1584
1625
|
});
|
|
1585
1626
|
});
|
|
1586
1627
|
}
|
|
1587
|
-
var MAX_PENDING_EVENTS, pendingMeshCoordinatorEvents, MESH_COORDINATOR_EVENTS, EVENT_TO_LEDGER_KIND;
|
|
1628
|
+
var remoteIdleSessions, MAX_PENDING_EVENTS, pendingMeshCoordinatorEvents, MESH_COORDINATOR_EVENTS, EVENT_TO_LEDGER_KIND;
|
|
1588
1629
|
var init_mesh_events = __esm({
|
|
1589
1630
|
"src/mesh/mesh-events.ts"() {
|
|
1590
1631
|
"use strict";
|
|
@@ -1592,6 +1633,7 @@ var init_mesh_events = __esm({
|
|
|
1592
1633
|
init_logger();
|
|
1593
1634
|
init_mesh_ledger();
|
|
1594
1635
|
init_mesh_work_queue();
|
|
1636
|
+
remoteIdleSessions = /* @__PURE__ */ new Map();
|
|
1595
1637
|
MAX_PENDING_EVENTS = 50;
|
|
1596
1638
|
pendingMeshCoordinatorEvents = [];
|
|
1597
1639
|
MESH_COORDINATOR_EVENTS = /* @__PURE__ */ new Set([
|
|
@@ -32329,7 +32371,8 @@ async function initDaemonComponents(config) {
|
|
|
32329
32371
|
cdpManagers,
|
|
32330
32372
|
sessionRegistry,
|
|
32331
32373
|
detectedIdes: detectedIdesRef,
|
|
32332
|
-
refreshProviderAvailability
|
|
32374
|
+
refreshProviderAvailability,
|
|
32375
|
+
dispatchMeshCommand: config.dispatchMeshCommand
|
|
32333
32376
|
};
|
|
32334
32377
|
setupMeshEventForwarding(components);
|
|
32335
32378
|
return components;
|