openclaw-quiubo 2.6.67 → 2.6.69

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
@@ -13485,8 +13485,10 @@ function resolveAccountId(config, agentId) {
13485
13485
  var activeToolCounts = /* @__PURE__ */ new Map();
13486
13486
  var lastSentAt = /* @__PURE__ */ new Map();
13487
13487
  var pendingIdle = /* @__PURE__ */ new Map();
13488
+ var orphanTimers = /* @__PURE__ */ new Map();
13488
13489
  var DEBOUNCE_MS = 2e3;
13489
13490
  var IDLE_DELAY_MS = 8e3;
13491
+ var ORPHAN_TIMEOUT_MS = 12e4;
13490
13492
  function isSessionWorking(sessionKey) {
13491
13493
  return (activeToolCounts.get(sessionKey) ?? 0) > 0 || pendingIdle.has(sessionKey);
13492
13494
  }
@@ -13527,6 +13529,20 @@ function generateLabel(toolName, params) {
13527
13529
  return "Working...";
13528
13530
  }
13529
13531
  }
13532
+ function sendIdleSignal(api, sessionKey, groupId, context) {
13533
+ const config = api.runtime?.config ?? api.config;
13534
+ const agentId = extractAgentIdFromSessionKey(sessionKey);
13535
+ const accountId = resolveAccountId(config, agentId);
13536
+ const client = clients.get(accountId);
13537
+ const accountCfg = accounts.get(accountId);
13538
+ if (!client || !accountCfg?.botIdentityId) return;
13539
+ client.sendActivity(groupId, {
13540
+ identityId: accountCfg.botIdentityId,
13541
+ state: "idle"
13542
+ }).catch((err) => {
13543
+ console.warn(`[quiubo] activity-hook ${context} idle failed: ${err}`);
13544
+ });
13545
+ }
13530
13546
  function registerActivityHook(api) {
13531
13547
  api.on(
13532
13548
  "before_tool_call",
@@ -13538,6 +13554,23 @@ function registerActivityHook(api) {
13538
13554
  const key = sessionKey;
13539
13555
  const prev = activeToolCounts.get(key) ?? 0;
13540
13556
  activeToolCounts.set(key, prev + 1);
13557
+ const existingOrphan = orphanTimers.get(key);
13558
+ if (existingOrphan) clearTimeout(existingOrphan);
13559
+ orphanTimers.set(key, setTimeout(() => {
13560
+ orphanTimers.delete(key);
13561
+ const stuck = activeToolCounts.get(key) ?? 0;
13562
+ if (stuck > 0) {
13563
+ console.warn(`[quiubo] activity-hook: force-clearing ${stuck} orphaned tool count(s) for ${key}`);
13564
+ activeToolCounts.set(key, 0);
13565
+ lastSentAt.delete(key);
13566
+ const pendingTimer2 = pendingIdle.get(key);
13567
+ if (pendingTimer2) {
13568
+ clearTimeout(pendingTimer2);
13569
+ pendingIdle.delete(key);
13570
+ }
13571
+ sendIdleSignal(api, sessionKey, groupId, "orphan");
13572
+ }
13573
+ }, ORPHAN_TIMEOUT_MS));
13541
13574
  const pendingTimer = pendingIdle.get(key);
13542
13575
  if (pendingTimer) {
13543
13576
  clearTimeout(pendingTimer);
@@ -13581,22 +13614,16 @@ function registerActivityHook(api) {
13581
13614
  const next = Math.max(0, prev - 1);
13582
13615
  activeToolCounts.set(key, next);
13583
13616
  if (next === 0) {
13617
+ const orphanTimer = orphanTimers.get(key);
13618
+ if (orphanTimer) {
13619
+ clearTimeout(orphanTimer);
13620
+ orphanTimers.delete(key);
13621
+ }
13584
13622
  const idleTimer = setTimeout(() => {
13585
13623
  pendingIdle.delete(key);
13586
13624
  lastSentAt.delete(key);
13587
13625
  if ((activeToolCounts.get(key) ?? 0) > 0) return;
13588
- const config = api.runtime?.config ?? api.config;
13589
- const agentId = extractAgentIdFromSessionKey(sessionKey);
13590
- const accountId = resolveAccountId(config, agentId);
13591
- const client = clients.get(accountId);
13592
- const accountCfg = accounts.get(accountId);
13593
- if (!client || !accountCfg?.botIdentityId) return;
13594
- client.sendActivity(groupId, {
13595
- identityId: accountCfg.botIdentityId,
13596
- state: "idle"
13597
- }).catch((err) => {
13598
- console.warn(`[quiubo] activity-hook idle failed: ${err}`);
13599
- });
13626
+ sendIdleSignal(api, sessionKey, groupId, "normal");
13600
13627
  }, IDLE_DELAY_MS);
13601
13628
  pendingIdle.set(key, idleTimer);
13602
13629
  }