openclaw-quiubo 2.6.66 → 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
@@ -13469,7 +13469,11 @@ function extractAgentIdFromSessionKey(key) {
13469
13469
  return match?.[1] ?? "main";
13470
13470
  }
13471
13471
  function resolveAccountId(config, agentId) {
13472
- const bindings = config?.bindings ?? [];
13472
+ let resolvedConfig = config;
13473
+ if (!resolvedConfig?.bindings && typeof resolvedConfig?.loadConfig === "function") {
13474
+ resolvedConfig = resolvedConfig.loadConfig();
13475
+ }
13476
+ const bindings = resolvedConfig?.bindings ?? [];
13473
13477
  const matched = bindings.find(
13474
13478
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
13475
13479
  (b) => b?.match?.channel === "quiubo" && b?.agentId === agentId
@@ -13481,8 +13485,10 @@ function resolveAccountId(config, agentId) {
13481
13485
  var activeToolCounts = /* @__PURE__ */ new Map();
13482
13486
  var lastSentAt = /* @__PURE__ */ new Map();
13483
13487
  var pendingIdle = /* @__PURE__ */ new Map();
13488
+ var orphanTimers = /* @__PURE__ */ new Map();
13484
13489
  var DEBOUNCE_MS = 2e3;
13485
13490
  var IDLE_DELAY_MS = 8e3;
13491
+ var ORPHAN_TIMEOUT_MS = 12e4;
13486
13492
  function isSessionWorking(sessionKey) {
13487
13493
  return (activeToolCounts.get(sessionKey) ?? 0) > 0 || pendingIdle.has(sessionKey);
13488
13494
  }
@@ -13523,6 +13529,20 @@ function generateLabel(toolName, params) {
13523
13529
  return "Working...";
13524
13530
  }
13525
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
+ }
13526
13546
  function registerActivityHook(api) {
13527
13547
  api.on(
13528
13548
  "before_tool_call",
@@ -13534,6 +13554,23 @@ function registerActivityHook(api) {
13534
13554
  const key = sessionKey;
13535
13555
  const prev = activeToolCounts.get(key) ?? 0;
13536
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));
13537
13574
  const pendingTimer = pendingIdle.get(key);
13538
13575
  if (pendingTimer) {
13539
13576
  clearTimeout(pendingTimer);
@@ -13577,22 +13614,16 @@ function registerActivityHook(api) {
13577
13614
  const next = Math.max(0, prev - 1);
13578
13615
  activeToolCounts.set(key, next);
13579
13616
  if (next === 0) {
13617
+ const orphanTimer = orphanTimers.get(key);
13618
+ if (orphanTimer) {
13619
+ clearTimeout(orphanTimer);
13620
+ orphanTimers.delete(key);
13621
+ }
13580
13622
  const idleTimer = setTimeout(() => {
13581
13623
  pendingIdle.delete(key);
13582
13624
  lastSentAt.delete(key);
13583
13625
  if ((activeToolCounts.get(key) ?? 0) > 0) return;
13584
- const config = api.runtime?.config ?? api.config;
13585
- const agentId = extractAgentIdFromSessionKey(sessionKey);
13586
- const accountId = resolveAccountId(config, agentId);
13587
- const client = clients.get(accountId);
13588
- const accountCfg = accounts.get(accountId);
13589
- if (!client || !accountCfg?.botIdentityId) return;
13590
- client.sendActivity(groupId, {
13591
- identityId: accountCfg.botIdentityId,
13592
- state: "idle"
13593
- }).catch((err) => {
13594
- console.warn(`[quiubo] activity-hook idle failed: ${err}`);
13595
- });
13626
+ sendIdleSignal(api, sessionKey, groupId, "normal");
13596
13627
  }, IDLE_DELAY_MS);
13597
13628
  pendingIdle.set(key, idleTimer);
13598
13629
  }