aamp-openclaw-plugin 0.1.32 → 0.1.33

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
@@ -2620,6 +2620,12 @@ function logTransportState(api, mode, email, previousMode) {
2620
2620
  function isSyntheticPendingKey(taskKey) {
2621
2621
  return taskKey.startsWith("result:") || taskKey.startsWith("help:");
2622
2622
  }
2623
+ function isTaskAwaitingHelpReply(task) {
2624
+ return task.awaitingHelpReply === true;
2625
+ }
2626
+ function isActionablePendingTask(taskKey, task) {
2627
+ return !isSyntheticPendingKey(taskKey) && !isTaskAwaitingHelpReply(task);
2628
+ }
2623
2629
  function normalizeOpenClawAgentId(value) {
2624
2630
  const trimmed = typeof value === "string" ? value.trim() : "";
2625
2631
  if (!trimmed)
@@ -2664,6 +2670,38 @@ function buildAampTaskSessionKey(taskId, config) {
2664
2670
  function buildAampWakeSessionKey(kind, id) {
2665
2671
  return `${AAMP_SESSION_PREFIX}wake:${kind}:${id}`;
2666
2672
  }
2673
+ function resolvePendingKeyFromSessionKey(sessionKey) {
2674
+ if (typeof sessionKey !== "string")
2675
+ return void 0;
2676
+ const normalized = stripOpenClawAgentScope(sessionKey).trim();
2677
+ if (!normalized)
2678
+ return void 0;
2679
+ const parts = normalized.split(":");
2680
+ if (parts[0]?.toLowerCase() !== "aamp")
2681
+ return void 0;
2682
+ if (parts[1]?.toLowerCase() === "wake") {
2683
+ const kind = parts[2]?.toLowerCase();
2684
+ const id = parts.slice(3).join(":").trim();
2685
+ if (!id)
2686
+ return void 0;
2687
+ if (kind === "task")
2688
+ return id;
2689
+ if (kind === "result" || kind === "help")
2690
+ return `${kind}:${id}`;
2691
+ return void 0;
2692
+ }
2693
+ if (parts[1]?.toLowerCase() === "default") {
2694
+ const kind = parts[2]?.toLowerCase();
2695
+ const id = parts.slice(3).join(":").trim();
2696
+ if (!id)
2697
+ return void 0;
2698
+ if (kind === "task")
2699
+ return id;
2700
+ if (kind === "result" || kind === "help")
2701
+ return `${kind}:${id}`;
2702
+ }
2703
+ return void 0;
2704
+ }
2667
2705
  function saveTerminalTaskIds() {
2668
2706
  saveTaskState({ terminalTaskIds: [...terminalTaskIds] }, defaultTaskStatePath());
2669
2707
  }
@@ -2706,7 +2744,7 @@ function nextPendingEntry() {
2706
2744
  if (notifications.length > 0) {
2707
2745
  return notifications.sort((a, b) => new Date(a[1].receivedAt).getTime() - new Date(b[1].receivedAt).getTime())[0];
2708
2746
  }
2709
- return entries.filter(([key]) => !key.startsWith("result:") && !key.startsWith("help:")).sort((a, b) => {
2747
+ return entries.filter(([key, task]) => isActionablePendingTask(key, task)).sort((a, b) => {
2710
2748
  const rankDiff = priorityRank(a[1].priority) - priorityRank(b[1].priority);
2711
2749
  if (rankDiff !== 0)
2712
2750
  return rankDiff;
@@ -3421,7 +3459,17 @@ ${notifyBody?.bodyText ?? help.question}`;
3421
3459
  }
3422
3460
  if (pendingTasks.size === 0)
3423
3461
  return {};
3424
- const nextEntry = nextPendingEntry();
3462
+ const targetedPendingKey = resolvePendingKeyFromSessionKey(ctx?.sessionKey);
3463
+ const targetedEntry = targetedPendingKey ? (() => {
3464
+ const targetedTask = pendingTasks.get(targetedPendingKey);
3465
+ if (!targetedTask)
3466
+ return void 0;
3467
+ if (!isSyntheticPendingKey(targetedPendingKey) && isTaskAwaitingHelpReply(targetedTask)) {
3468
+ return void 0;
3469
+ }
3470
+ return [targetedPendingKey, targetedTask];
3471
+ })() : void 0;
3472
+ const nextEntry = targetedPendingKey ? targetedEntry : nextPendingEntry();
3425
3473
  if (!nextEntry)
3426
3474
  return {};
3427
3475
  const [taskKey, task] = nextEntry;
@@ -3429,12 +3477,13 @@ ${notifyBody?.bodyText ?? help.question}`;
3429
3477
  if (isNotification && taskKey) {
3430
3478
  pendingTasks.delete(taskKey);
3431
3479
  }
3432
- const actionableTasks = [...pendingTasks.entries()].filter(([key]) => !key.startsWith("result:") && !key.startsWith("help:")).map(([, t]) => t).sort((a, b) => {
3480
+ const actionableTasks = [...pendingTasks.entries()].filter(([key, pendingTask]) => isActionablePendingTask(key, pendingTask)).map(([, t]) => t).sort((a, b) => {
3433
3481
  const rankDiff = priorityRank(a.priority) - priorityRank(b.priority);
3434
3482
  if (rankDiff !== 0)
3435
3483
  return rankDiff;
3436
3484
  return new Date(a.receivedAt).getTime() - new Date(b.receivedAt).getTime();
3437
3485
  });
3486
+ const otherActionableTasks = actionableTasks.filter((pendingTask) => pendingTask.taskId !== task.taskId);
3438
3487
  const hasAttachmentInfo = isNotification && (task.bodyText?.includes("aamp_download_attachment") ?? false);
3439
3488
  const actionRequiredSection = isNotification && actionableTasks.length > 0 ? [
3440
3489
  ``,
@@ -3468,8 +3517,8 @@ ${notifyBody?.bodyText ?? help.question}`;
3468
3517
  task.bodyText ? `
3469
3518
  ${task.bodyText}` : "",
3470
3519
  actionRequiredSection,
3471
- pendingTasks.size > 1 ? `
3472
- (+${pendingTasks.size - 1} more items queued)` : ""
3520
+ otherActionableTasks.length > 0 ? `
3521
+ (+${otherActionableTasks.length} more tasks queued)` : ""
3473
3522
  ] : [
3474
3523
  `## Pending AAMP Task (action required)`,
3475
3524
  ``,
@@ -3509,8 +3558,8 @@ ${task.bodyText}` : "",
3509
3558
  ${task.contextLinks.map((l) => ` - ${l}`).join("\n")}` : "",
3510
3559
  task.expiresAt ? `Expires: ${task.expiresAt}` : `Expires: none`,
3511
3560
  `Received: ${task.receivedAt}`,
3512
- pendingTasks.size > 1 ? `
3513
- (+${pendingTasks.size - 1} more tasks queued)` : ""
3561
+ otherActionableTasks.length > 0 ? `
3562
+ (+${otherActionableTasks.length} more tasks queued)` : ""
3514
3563
  ].filter(Boolean).join("\n");
3515
3564
  return { prependContext: lines };
3516
3565
  },
@@ -3749,12 +3798,16 @@ ${task.contextLinks.map((l) => ` - ${l}`).join("\n")}` : "",
3749
3798
  suggestedOptions: p.suggestedOptions ?? [],
3750
3799
  inReplyTo: task.messageId || void 0
3751
3800
  });
3801
+ pendingTasks.set(task.taskId, {
3802
+ ...task,
3803
+ awaitingHelpReply: true
3804
+ });
3752
3805
  api.logger.info(`[AAMP] \u2192 task.help_needed ${task.taskId}`);
3753
3806
  return {
3754
3807
  content: [
3755
3808
  {
3756
3809
  type: "text",
3757
- text: `Help request sent for task ${task.taskId}. The task remains pending until the dispatcher replies.`
3810
+ text: `Help request sent for task ${task.taskId}. The task is now suspended until the dispatcher replies.`
3758
3811
  }
3759
3812
  ]
3760
3813
  };
@@ -3774,7 +3827,7 @@ ${task.contextLinks.map((l) => ` - ${l}`).join("\n")}` : "",
3774
3827
  return rankDiff;
3775
3828
  return new Date(a.receivedAt).getTime() - new Date(b.receivedAt).getTime();
3776
3829
  }).map(
3777
- (t, i) => `${i + 1}. [${t.priority}] [${t.taskId}] "${t.title}"${t.bodyText ? `
3830
+ (t, i) => `${i + 1}. [${t.priority}] [${t.taskId}] "${t.title}"${isTaskAwaitingHelpReply(t) ? " (waiting for dispatcher reply)" : ""}${t.bodyText ? `
3778
3831
  Description: ${t.bodyText}` : ""} \u2014 from ${t.from} (received ${t.receivedAt})`
3779
3832
  );
3780
3833
  return {