@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/index.mjs CHANGED
@@ -1311,15 +1311,35 @@ function formatCompletionMetadata(event) {
1311
1311
  }
1312
1312
  function tryAssignQueueTask(components, meshId, nodeId, sessionId, providerType) {
1313
1313
  const task = claimNextTask(meshId, nodeId, sessionId);
1314
- if (!task) return false;
1314
+ if (!task) {
1315
+ return false;
1316
+ }
1315
1317
  LOG.info("MeshQueue", `Node ${nodeId} (${sessionId}) pulled task ${task.id}`);
1318
+ const mesh = getMesh(meshId);
1319
+ const node = mesh?.nodes.find((n) => n.id === nodeId);
1320
+ if (node?.daemonId && components.dispatchMeshCommand) {
1321
+ const isLocalNode = components.cliManager.adapters.has(sessionId);
1322
+ if (!isLocalNode) {
1323
+ components.dispatchMeshCommand(node.daemonId, "agent_command", {
1324
+ targetSessionId: sessionId,
1325
+ cliType: providerType,
1326
+ action: "send_chat",
1327
+ message: task.message
1328
+ }).catch((e) => {
1329
+ LOG.error("MeshQueue", `Failed to dispatch task via P2P to remote node ${nodeId}: ${e?.message}`);
1330
+ updateTaskStatus(meshId, task.id, "failed");
1331
+ });
1332
+ return true;
1333
+ }
1334
+ }
1316
1335
  components.cliManager.handleCliCommand("agent_command", {
1317
1336
  targetSessionId: sessionId,
1318
1337
  cliType: providerType,
1319
1338
  action: "send_chat",
1320
1339
  message: task.message
1321
1340
  }).catch((e) => {
1322
- LOG.error("MeshQueue", `Failed to dispatch task to node ${nodeId}: ${e?.message}`);
1341
+ LOG.error("MeshQueue", `Failed to dispatch task locally to node ${nodeId}: ${e?.message}`);
1342
+ updateTaskStatus(meshId, task.id, "failed");
1323
1343
  });
1324
1344
  return true;
1325
1345
  }
@@ -1389,7 +1409,7 @@ Do NOT retry on this node. Consider reassigning to a different node or asking th
1389
1409
  function injectMeshSystemMessage(components, args) {
1390
1410
  if (args.event === "agent:generating_completed") {
1391
1411
  const sessionId = readNonEmptyString(args.metadataEvent.targetSessionId);
1392
- const nodeId = readNonEmptyString(args.metadataEvent.nodeId) || readNonEmptyString(args.metadataEvent.meshNodeId);
1412
+ const nodeId = readNonEmptyString(args.nodeId) || readNonEmptyString(args.metadataEvent.meshNodeId);
1393
1413
  const providerType = readNonEmptyString(args.metadataEvent.providerType);
1394
1414
  if (sessionId) {
1395
1415
  updateSessionTaskStatus(args.meshId, sessionId, "completed");
@@ -1401,7 +1421,7 @@ function injectMeshSystemMessage(components, args) {
1401
1421
  }
1402
1422
  } else if (args.event === "agent:ready") {
1403
1423
  const sessionId = readNonEmptyString(args.metadataEvent.targetSessionId);
1404
- const nodeId = readNonEmptyString(args.metadataEvent.nodeId) || readNonEmptyString(args.metadataEvent.meshNodeId);
1424
+ const nodeId = readNonEmptyString(args.nodeId) || readNonEmptyString(args.metadataEvent.meshNodeId);
1405
1425
  const providerType = readNonEmptyString(args.metadataEvent.providerType);
1406
1426
  if (sessionId && nodeId && providerType) {
1407
1427
  setTimeout(() => {
@@ -1419,7 +1439,7 @@ function injectMeshSystemMessage(components, args) {
1419
1439
  try {
1420
1440
  appendLedgerEntry(args.meshId, {
1421
1441
  kind: ledgerKind,
1422
- nodeId: readNonEmptyString(args.metadataEvent.nodeId) || readNonEmptyString(args.metadataEvent.meshNodeId) || void 0,
1442
+ nodeId: readNonEmptyString(args.nodeId) || readNonEmptyString(args.metadataEvent.meshNodeId) || void 0,
1423
1443
  sessionId: readNonEmptyString(args.metadataEvent.targetSessionId) || void 0,
1424
1444
  providerType: readNonEmptyString(args.metadataEvent.providerType) || void 0,
1425
1445
  payload: {
@@ -1439,7 +1459,7 @@ function injectMeshSystemMessage(components, args) {
1439
1459
  const maxRetries = mesh?.policy?.maxTaskRetries ?? 1;
1440
1460
  recoveryContext = getSessionRecoveryContext(args.meshId, {
1441
1461
  sessionId: readNonEmptyString(args.metadataEvent.targetSessionId) || void 0,
1442
- nodeId: readNonEmptyString(args.metadataEvent.nodeId) || readNonEmptyString(args.metadataEvent.meshNodeId) || void 0,
1462
+ nodeId: readNonEmptyString(args.nodeId) || readNonEmptyString(args.metadataEvent.meshNodeId) || void 0,
1443
1463
  maxRetries
1444
1464
  });
1445
1465
  recoveryContext.failedProviderType = readNonEmptyString(args.metadataEvent.providerType) || null;
@@ -1534,6 +1554,7 @@ function handleMeshForwardEvent(components, payload) {
1534
1554
  const nodeLabel = nodeId ? `Node '${nodeId}'` : workspace ? `Agent at ${workspace}` : "Remote agent";
1535
1555
  return injectMeshSystemMessage(components, {
1536
1556
  meshId,
1557
+ nodeId,
1537
1558
  nodeLabel,
1538
1559
  event: eventName,
1539
1560
  metadataEvent: {
@@ -1563,10 +1584,12 @@ function setupMeshEventForwarding(components) {
1563
1584
  if (!meshId) return;
1564
1585
  const targetNode = mesh?.nodes?.find((n) => n.workspace === workspace);
1565
1586
  const runtimeNodeId = readNonEmptyString(settings.meshNodeId);
1587
+ const resolvedNodeId = targetNode?.id || runtimeNodeId;
1566
1588
  const nodeLabel = targetNode ? `Node '${targetNode.id}'` : runtimeNodeId ? `Node '${runtimeNodeId}'` : `Agent at ${workspace}`;
1567
1589
  injectMeshSystemMessage(components, {
1568
1590
  meshId,
1569
1591
  sourceInstanceId: instanceId,
1592
+ nodeId: resolvedNodeId,
1570
1593
  nodeLabel,
1571
1594
  event: event.event,
1572
1595
  metadataEvent: event
@@ -32112,7 +32135,8 @@ async function initDaemonComponents(config) {
32112
32135
  cdpManagers,
32113
32136
  sessionRegistry,
32114
32137
  detectedIdes: detectedIdesRef,
32115
- refreshProviderAvailability
32138
+ refreshProviderAvailability,
32139
+ dispatchMeshCommand: config.dispatchMeshCommand
32116
32140
  };
32117
32141
  setupMeshEventForwarding(components);
32118
32142
  return components;