@adhdev/daemon-standalone 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/index.js CHANGED
@@ -32536,13 +32536,31 @@ Follow these recovery rules:
32536
32536
  return false;
32537
32537
  }
32538
32538
  LOG2.info("MeshQueue", `Node ${nodeId} (${sessionId}) pulled task ${task.id}`);
32539
+ const mesh = getMesh(meshId);
32540
+ const node = mesh?.nodes.find((n) => n.id === nodeId);
32541
+ if (node?.daemonId && components.dispatchMeshCommand) {
32542
+ const isLocalNode = components.cliManager.adapters.has(sessionId);
32543
+ if (!isLocalNode) {
32544
+ components.dispatchMeshCommand(node.daemonId, "agent_command", {
32545
+ targetSessionId: sessionId,
32546
+ cliType: providerType,
32547
+ action: "send_chat",
32548
+ message: task.message
32549
+ }).catch((e) => {
32550
+ LOG2.error("MeshQueue", `Failed to dispatch task via P2P to remote node ${nodeId}: ${e?.message}`);
32551
+ updateTaskStatus(meshId, task.id, "failed");
32552
+ });
32553
+ return true;
32554
+ }
32555
+ }
32539
32556
  components.cliManager.handleCliCommand("agent_command", {
32540
32557
  targetSessionId: sessionId,
32541
32558
  cliType: providerType,
32542
32559
  action: "send_chat",
32543
32560
  message: task.message
32544
32561
  }).catch((e) => {
32545
- LOG2.error("MeshQueue", `Failed to dispatch task to node ${nodeId}: ${e?.message}`);
32562
+ LOG2.error("MeshQueue", `Failed to dispatch task locally to node ${nodeId}: ${e?.message}`);
32563
+ updateTaskStatus(meshId, task.id, "failed");
32546
32564
  });
32547
32565
  return true;
32548
32566
  }
@@ -32564,6 +32582,15 @@ Follow these recovery rules:
32564
32582
  tryAssignQueueTask(components, meshId, nodeId, sessionId, providerType);
32565
32583
  }
32566
32584
  }
32585
+ for (const [key, idle] of remoteIdleSessions.entries()) {
32586
+ const node = mesh.nodes.find((n) => n.id === idle.nodeId);
32587
+ if (node) {
32588
+ const assigned = tryAssignQueueTask(components, meshId, idle.nodeId, idle.sessionId, idle.providerType);
32589
+ if (assigned) {
32590
+ remoteIdleSessions.delete(key);
32591
+ }
32592
+ }
32593
+ }
32567
32594
  }
32568
32595
  function buildMeshSystemMessage(args) {
32569
32596
  const metadata = formatCompletionMetadata(args.metadataEvent);
@@ -32627,12 +32654,26 @@ Do NOT retry on this node. Consider reassigning to a different node or asking th
32627
32654
  const nodeId = readNonEmptyString(args.nodeId) || readNonEmptyString(args.metadataEvent.meshNodeId);
32628
32655
  const providerType = readNonEmptyString(args.metadataEvent.providerType);
32629
32656
  if (sessionId && nodeId && providerType) {
32657
+ remoteIdleSessions.set(`${nodeId}:${sessionId}`, { nodeId, sessionId, providerType });
32630
32658
  setTimeout(() => {
32631
- tryAssignQueueTask(components, args.meshId, nodeId, sessionId, providerType);
32659
+ const assigned = tryAssignQueueTask(components, args.meshId, nodeId, sessionId, providerType);
32660
+ if (assigned) {
32661
+ remoteIdleSessions.delete(`${nodeId}:${sessionId}`);
32662
+ }
32632
32663
  }, 500);
32633
32664
  }
32665
+ } else if (args.event === "agent:generating_started") {
32666
+ const sessionId = readNonEmptyString(args.metadataEvent.targetSessionId);
32667
+ const nodeId = readNonEmptyString(args.nodeId) || readNonEmptyString(args.metadataEvent.meshNodeId);
32668
+ if (sessionId && nodeId) {
32669
+ remoteIdleSessions.delete(`${nodeId}:${sessionId}`);
32670
+ }
32634
32671
  } else if (args.event === "agent:stopped") {
32635
32672
  const sessionId = readNonEmptyString(args.metadataEvent.targetSessionId);
32673
+ const nodeId = readNonEmptyString(args.nodeId) || readNonEmptyString(args.metadataEvent.meshNodeId);
32674
+ if (sessionId && nodeId) {
32675
+ remoteIdleSessions.delete(`${nodeId}:${sessionId}`);
32676
+ }
32636
32677
  if (sessionId) {
32637
32678
  updateSessionTaskStatus(args.meshId, sessionId, "failed");
32638
32679
  }
@@ -32799,6 +32840,7 @@ Do NOT retry on this node. Consider reassigning to a different node or asking th
32799
32840
  });
32800
32841
  });
32801
32842
  }
32843
+ var remoteIdleSessions;
32802
32844
  var MAX_PENDING_EVENTS;
32803
32845
  var pendingMeshCoordinatorEvents;
32804
32846
  var MESH_COORDINATOR_EVENTS;
@@ -32810,6 +32852,7 @@ Do NOT retry on this node. Consider reassigning to a different node or asking th
32810
32852
  init_logger();
32811
32853
  init_mesh_ledger();
32812
32854
  init_mesh_work_queue();
32855
+ remoteIdleSessions = /* @__PURE__ */ new Map();
32813
32856
  MAX_PENDING_EVENTS = 50;
32814
32857
  pendingMeshCoordinatorEvents = [];
32815
32858
  MESH_COORDINATOR_EVENTS = /* @__PURE__ */ new Set([
@@ -63320,7 +63363,8 @@ data: ${JSON.stringify(msg.data)}
63320
63363
  cdpManagers,
63321
63364
  sessionRegistry,
63322
63365
  detectedIdes: detectedIdesRef,
63323
- refreshProviderAvailability
63366
+ refreshProviderAvailability,
63367
+ dispatchMeshCommand: config2.dispatchMeshCommand
63324
63368
  };
63325
63369
  setupMeshEventForwarding(components);
63326
63370
  return components;