aamp-openclaw-plugin 0.1.15 → 0.1.16

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
@@ -16222,6 +16222,9 @@ var transportMonitorTimer = null;
16222
16222
  var currentSessionKey = "agent:main:main";
16223
16223
  var channelRuntime = null;
16224
16224
  var channelCfg = null;
16225
+ function dispatchSessionKey() {
16226
+ return currentSessionKey || "agent:main:main";
16227
+ }
16225
16228
  function logTransportState(api, mode, email, previousMode) {
16226
16229
  if (mode === previousMode)
16227
16230
  return;
@@ -16352,10 +16355,11 @@ var src_default = {
16352
16355
  }
16353
16356
  }
16354
16357
  function wakeAgentForPendingTask(task) {
16355
- const fallback = () => triggerHeartbeatWake(currentSessionKey, `task ${task.taskId}`);
16358
+ const sessionKey = dispatchSessionKey();
16359
+ const fallback = () => triggerHeartbeatWake(sessionKey, `task ${task.taskId}`);
16356
16360
  const dispatcher = channelRuntime?.reply?.dispatchReplyWithBufferedBlockDispatcher;
16357
16361
  api.logger.info(
16358
- `[AAMP] Wake requested for task ${task.taskId} \u2014 channelRuntime=${channelRuntime ? "yes" : "no"} channelCfg=${channelCfg ? "yes" : "no"} dispatcher=${typeof dispatcher === "function" ? "yes" : "no"} session=${currentSessionKey}`
16362
+ `[AAMP] Wake requested for task ${task.taskId} \u2014 channelRuntime=${channelRuntime ? "yes" : "no"} channelCfg=${channelCfg ? "yes" : "no"} dispatcher=${typeof dispatcher === "function" ? "yes" : "no"} session=${sessionKey}`
16359
16363
  );
16360
16364
  if (!channelRuntime || !channelCfg || typeof dispatcher !== "function") {
16361
16365
  fallback();
@@ -16369,13 +16373,24 @@ var src_default = {
16369
16373
  "Reply with aamp_send_result or aamp_send_help before responding."
16370
16374
  ].join("\n");
16371
16375
  try {
16376
+ const startedAt = Date.now();
16377
+ let settled = false;
16378
+ const fallbackTimer = setTimeout(() => {
16379
+ if (settled || !pendingTasks.has(task.taskId))
16380
+ return;
16381
+ api.logger.warn(
16382
+ `[AAMP] Channel dispatch still pending after ${Date.now() - startedAt}ms for task ${task.taskId} \u2014 triggering heartbeat fallback`
16383
+ );
16384
+ fallback();
16385
+ }, 2e3);
16386
+ api.logger.info(`[AAMP] Channel dispatch starting for task ${task.taskId}`);
16372
16387
  void Promise.resolve(dispatcher({
16373
16388
  ctx: {
16374
16389
  Body: task.bodyText || task.title,
16375
16390
  BodyForAgent: prompt,
16376
16391
  From: task.from,
16377
16392
  To: agentEmail,
16378
- SessionKey: `aamp:default:task:${task.taskId}`,
16393
+ SessionKey: sessionKey,
16379
16394
  AccountId: "default",
16380
16395
  ChatType: "dm",
16381
16396
  Provider: "aamp",
@@ -16397,8 +16412,14 @@ var src_default = {
16397
16412
  }
16398
16413
  }
16399
16414
  })).then(() => {
16400
- api.logger.info(`[AAMP] Channel dispatch triggered for task ${task.taskId}`);
16415
+ settled = true;
16416
+ clearTimeout(fallbackTimer);
16417
+ api.logger.info(
16418
+ `[AAMP] Channel dispatch triggered for task ${task.taskId} after ${Date.now() - startedAt}ms`
16419
+ );
16401
16420
  }).catch((err) => {
16421
+ settled = true;
16422
+ clearTimeout(fallbackTimer);
16402
16423
  api.logger.error(`[AAMP] Channel dispatch failed for task ${task.taskId}: ${err.message}`);
16403
16424
  fallback();
16404
16425
  });
@@ -16555,7 +16576,7 @@ ${notifyBody?.bodyText ?? "Sub-task completed."}${actionSection}`;
16555
16576
  BodyForAgent: prompt,
16556
16577
  From: result.from,
16557
16578
  To: agentEmail,
16558
- SessionKey: `aamp:default:${result.from}`,
16579
+ SessionKey: dispatchSessionKey(),
16559
16580
  AccountId: "default",
16560
16581
  ChatType: "dm",
16561
16582
  Provider: "aamp",
@@ -16630,7 +16651,7 @@ ${notifyBody?.bodyText ?? help.question}`;
16630
16651
  BodyForAgent: prompt,
16631
16652
  From: help.from,
16632
16653
  To: agentEmail,
16633
- SessionKey: `aamp:default:${help.from}`,
16654
+ SessionKey: dispatchSessionKey(),
16634
16655
  AccountId: "default",
16635
16656
  ChatType: "dm",
16636
16657
  Provider: "aamp",
@@ -16676,6 +16697,10 @@ ${notifyBody?.bodyText ?? help.question}`;
16676
16697
  });
16677
16698
  aampClient.on("disconnected", (reason) => {
16678
16699
  lastDisconnectReason = reason;
16700
+ if (aampClient?.isUsingPollingFallback()) {
16701
+ lastTransportMode = "polling";
16702
+ return;
16703
+ }
16679
16704
  if (lastTransportMode !== "disconnected") {
16680
16705
  api.logger.warn(`[AAMP] Disconnected: ${reason} (will auto-reconnect)`);
16681
16706
  lastTransportMode = "disconnected";