@adhdev/daemon-core 0.9.77-rc.22 → 0.9.77-rc.24

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
@@ -1367,6 +1367,15 @@ function triggerMeshQueue(components, meshId) {
1367
1367
  tryAssignQueueTask(components, meshId, nodeId, sessionId, providerType);
1368
1368
  }
1369
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
+ }
1370
1379
  }
1371
1380
  function buildMeshSystemMessage(args) {
1372
1381
  const metadata = formatCompletionMetadata(args.metadataEvent);
@@ -1430,12 +1439,26 @@ function injectMeshSystemMessage(components, args) {
1430
1439
  const nodeId = readNonEmptyString(args.nodeId) || readNonEmptyString(args.metadataEvent.meshNodeId);
1431
1440
  const providerType = readNonEmptyString(args.metadataEvent.providerType);
1432
1441
  if (sessionId && nodeId && providerType) {
1442
+ remoteIdleSessions.set(`${nodeId}:${sessionId}`, { nodeId, sessionId, providerType });
1433
1443
  setTimeout(() => {
1434
- 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
+ }
1435
1448
  }, 500);
1436
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
+ }
1437
1456
  } else if (args.event === "agent:stopped") {
1438
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
+ }
1439
1462
  if (sessionId) {
1440
1463
  updateSessionTaskStatus(args.meshId, sessionId, "failed");
1441
1464
  }
@@ -1602,7 +1625,7 @@ function setupMeshEventForwarding(components) {
1602
1625
  });
1603
1626
  });
1604
1627
  }
1605
- 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;
1606
1629
  var init_mesh_events = __esm({
1607
1630
  "src/mesh/mesh-events.ts"() {
1608
1631
  "use strict";
@@ -1610,6 +1633,7 @@ var init_mesh_events = __esm({
1610
1633
  init_logger();
1611
1634
  init_mesh_ledger();
1612
1635
  init_mesh_work_queue();
1636
+ remoteIdleSessions = /* @__PURE__ */ new Map();
1613
1637
  MAX_PENDING_EVENTS = 50;
1614
1638
  pendingMeshCoordinatorEvents = [];
1615
1639
  MESH_COORDINATOR_EVENTS = /* @__PURE__ */ new Set([