@adhdev/daemon-core 0.9.77-rc.22 → 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.mjs CHANGED
@@ -1361,6 +1361,15 @@ function triggerMeshQueue(components, meshId) {
1361
1361
  tryAssignQueueTask(components, meshId, nodeId, sessionId, providerType);
1362
1362
  }
1363
1363
  }
1364
+ for (const [key, idle] of remoteIdleSessions.entries()) {
1365
+ const node = mesh.nodes.find((n) => n.id === idle.nodeId);
1366
+ if (node) {
1367
+ const assigned = tryAssignQueueTask(components, meshId, idle.nodeId, idle.sessionId, idle.providerType);
1368
+ if (assigned) {
1369
+ remoteIdleSessions.delete(key);
1370
+ }
1371
+ }
1372
+ }
1364
1373
  }
1365
1374
  function buildMeshSystemMessage(args) {
1366
1375
  const metadata = formatCompletionMetadata(args.metadataEvent);
@@ -1424,12 +1433,26 @@ function injectMeshSystemMessage(components, args) {
1424
1433
  const nodeId = readNonEmptyString(args.nodeId) || readNonEmptyString(args.metadataEvent.meshNodeId);
1425
1434
  const providerType = readNonEmptyString(args.metadataEvent.providerType);
1426
1435
  if (sessionId && nodeId && providerType) {
1436
+ remoteIdleSessions.set(`${nodeId}:${sessionId}`, { nodeId, sessionId, providerType });
1427
1437
  setTimeout(() => {
1428
- tryAssignQueueTask(components, args.meshId, nodeId, sessionId, providerType);
1438
+ const assigned = tryAssignQueueTask(components, args.meshId, nodeId, sessionId, providerType);
1439
+ if (assigned) {
1440
+ remoteIdleSessions.delete(`${nodeId}:${sessionId}`);
1441
+ }
1429
1442
  }, 500);
1430
1443
  }
1444
+ } else if (args.event === "agent:generating_started") {
1445
+ const sessionId = readNonEmptyString(args.metadataEvent.targetSessionId);
1446
+ const nodeId = readNonEmptyString(args.nodeId) || readNonEmptyString(args.metadataEvent.meshNodeId);
1447
+ if (sessionId && nodeId) {
1448
+ remoteIdleSessions.delete(`${nodeId}:${sessionId}`);
1449
+ }
1431
1450
  } else if (args.event === "agent:stopped") {
1432
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
+ }
1433
1456
  if (sessionId) {
1434
1457
  updateSessionTaskStatus(args.meshId, sessionId, "failed");
1435
1458
  }
@@ -1596,7 +1619,7 @@ function setupMeshEventForwarding(components) {
1596
1619
  });
1597
1620
  });
1598
1621
  }
1599
- var MAX_PENDING_EVENTS, pendingMeshCoordinatorEvents, MESH_COORDINATOR_EVENTS, EVENT_TO_LEDGER_KIND;
1622
+ var remoteIdleSessions, MAX_PENDING_EVENTS, pendingMeshCoordinatorEvents, MESH_COORDINATOR_EVENTS, EVENT_TO_LEDGER_KIND;
1600
1623
  var init_mesh_events = __esm({
1601
1624
  "src/mesh/mesh-events.ts"() {
1602
1625
  "use strict";
@@ -1604,6 +1627,7 @@ var init_mesh_events = __esm({
1604
1627
  init_logger();
1605
1628
  init_mesh_ledger();
1606
1629
  init_mesh_work_queue();
1630
+ remoteIdleSessions = /* @__PURE__ */ new Map();
1607
1631
  MAX_PENDING_EVENTS = 50;
1608
1632
  pendingMeshCoordinatorEvents = [];
1609
1633
  MESH_COORDINATOR_EVENTS = /* @__PURE__ */ new Set([