aamp-openclaw-plugin 0.1.31 → 0.1.32

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
@@ -2537,6 +2537,12 @@ var pendingTasks = /* @__PURE__ */ new Map();
2537
2537
  var activeTaskStreams = /* @__PURE__ */ new Map();
2538
2538
  var terminalTaskIds = new Set(loadTaskState(defaultTaskStatePath()).terminalTaskIds ?? []);
2539
2539
  var AAMP_SESSION_PREFIX = "aamp:";
2540
+ var DEFAULT_OPENCLAW_AGENT_ID = "main";
2541
+ var OPENCLAW_AGENT_SESSION_PREFIX = "agent:";
2542
+ var VALID_OPENCLAW_AGENT_ID_RE = /^[a-z0-9][a-z0-9_-]{0,63}$/i;
2543
+ var INVALID_OPENCLAW_AGENT_ID_RE = /[^a-z0-9_-]+/g;
2544
+ var LEADING_DASH_RE = /^-+/;
2545
+ var TRAILING_DASH_RE = /-+$/;
2540
2546
  var dispatchedSubtasks = /* @__PURE__ */ new Map();
2541
2547
  var waitingDispatches = /* @__PURE__ */ new Map();
2542
2548
  var aampClient = null;
@@ -2614,8 +2620,46 @@ function logTransportState(api, mode, email, previousMode) {
2614
2620
  function isSyntheticPendingKey(taskKey) {
2615
2621
  return taskKey.startsWith("result:") || taskKey.startsWith("help:");
2616
2622
  }
2623
+ function normalizeOpenClawAgentId(value) {
2624
+ const trimmed = typeof value === "string" ? value.trim() : "";
2625
+ if (!trimmed)
2626
+ return DEFAULT_OPENCLAW_AGENT_ID;
2627
+ if (VALID_OPENCLAW_AGENT_ID_RE.test(trimmed))
2628
+ return trimmed.toLowerCase();
2629
+ return trimmed.toLowerCase().replace(INVALID_OPENCLAW_AGENT_ID_RE, "-").replace(LEADING_DASH_RE, "").replace(TRAILING_DASH_RE, "").slice(0, 64) || DEFAULT_OPENCLAW_AGENT_ID;
2630
+ }
2631
+ function resolveDefaultOpenClawAgentId(config) {
2632
+ const agents = config?.agents?.list;
2633
+ if (!Array.isArray(agents) || agents.length === 0)
2634
+ return DEFAULT_OPENCLAW_AGENT_ID;
2635
+ const defaults = agents.filter((agent) => agent?.default);
2636
+ return normalizeOpenClawAgentId((defaults[0] ?? agents[0])?.id);
2637
+ }
2638
+ function stripOpenClawAgentScope(sessionKey) {
2639
+ const trimmed = sessionKey.trim();
2640
+ if (!trimmed.toLowerCase().startsWith(OPENCLAW_AGENT_SESSION_PREFIX))
2641
+ return trimmed;
2642
+ const parts = trimmed.split(":");
2643
+ if (parts.length < 3 || parts[0]?.toLowerCase() !== "agent")
2644
+ return trimmed;
2645
+ return parts.slice(2).join(":");
2646
+ }
2617
2647
  function isAampSessionKey(sessionKey) {
2618
- return typeof sessionKey === "string" && sessionKey.startsWith(AAMP_SESSION_PREFIX);
2648
+ return typeof sessionKey === "string" && stripOpenClawAgentScope(sessionKey).toLowerCase().startsWith(AAMP_SESSION_PREFIX);
2649
+ }
2650
+ function buildOpenClawMainSessionKey(mainKey, config) {
2651
+ const trimmed = mainKey.trim();
2652
+ if (!trimmed)
2653
+ return `${OPENCLAW_AGENT_SESSION_PREFIX}${resolveDefaultOpenClawAgentId(config)}:main`;
2654
+ if (trimmed.toLowerCase().startsWith(OPENCLAW_AGENT_SESSION_PREFIX))
2655
+ return trimmed;
2656
+ return `${OPENCLAW_AGENT_SESSION_PREFIX}${resolveDefaultOpenClawAgentId(config)}:${trimmed}`;
2657
+ }
2658
+ function buildAampConversationSessionKey(value, config) {
2659
+ return buildOpenClawMainSessionKey(`${AAMP_SESSION_PREFIX}default:${value}`, config);
2660
+ }
2661
+ function buildAampTaskSessionKey(taskId, config) {
2662
+ return buildAampConversationSessionKey(`task:${taskId}`, config);
2619
2663
  }
2620
2664
  function buildAampWakeSessionKey(kind, id) {
2621
2665
  return `${AAMP_SESSION_PREFIX}wake:${kind}:${id}`;
@@ -2856,10 +2900,11 @@ var src_default = {
2856
2900
  }
2857
2901
  function wakeAgentForPendingTask(task) {
2858
2902
  const fallbackSessionKey = buildAampWakeSessionKey("task", task.taskId);
2903
+ const openClawSessionKey = buildAampTaskSessionKey(task.taskId, api.config);
2859
2904
  const fallback = () => triggerHeartbeatWake(fallbackSessionKey, `task ${task.taskId}`);
2860
2905
  const dispatcher = channelRuntime?.reply?.dispatchReplyWithBufferedBlockDispatcher;
2861
2906
  api.logger.info(
2862
- `[AAMP] Wake requested for task ${task.taskId} \u2014 channelRuntime=${channelRuntime ? "yes" : "no"} channelCfg=${channelCfg ? "yes" : "no"} dispatcher=${typeof dispatcher === "function" ? "yes" : "no"} fallbackSession=${fallbackSessionKey}`
2907
+ `[AAMP] Wake requested for task ${task.taskId} \u2014 channelRuntime=${channelRuntime ? "yes" : "no"} channelCfg=${channelCfg ? "yes" : "no"} dispatcher=${typeof dispatcher === "function" ? "yes" : "no"} session=${openClawSessionKey} fallbackSession=${fallbackSessionKey}`
2863
2908
  );
2864
2909
  if (!channelRuntime || !channelCfg || typeof dispatcher !== "function") {
2865
2910
  fallback();
@@ -2879,7 +2924,7 @@ var src_default = {
2879
2924
  BodyForAgent: prompt,
2880
2925
  From: task.from,
2881
2926
  To: agentEmail,
2882
- SessionKey: `aamp:default:task:${task.taskId}`,
2927
+ SessionKey: openClawSessionKey,
2883
2928
  AccountId: "default",
2884
2929
  ChatType: "dm",
2885
2930
  Provider: "aamp",
@@ -3093,7 +3138,7 @@ ${notifyBody?.bodyText ?? "Sub-task completed."}${actionSection}`;
3093
3138
  BodyForAgent: prompt,
3094
3139
  From: result.from,
3095
3140
  To: agentEmail,
3096
- SessionKey: `aamp:default:${result.from}`,
3141
+ SessionKey: buildAampConversationSessionKey(result.from, api.config),
3097
3142
  AccountId: "default",
3098
3143
  ChatType: "dm",
3099
3144
  Provider: "aamp",
@@ -3170,7 +3215,7 @@ ${notifyBody?.bodyText ?? help.question}`;
3170
3215
  BodyForAgent: prompt,
3171
3216
  From: help.from,
3172
3217
  To: agentEmail,
3173
- SessionKey: `aamp:default:${help.from}`,
3218
+ SessionKey: buildAampConversationSessionKey(help.from, api.config),
3174
3219
  AccountId: "default",
3175
3220
  ChatType: "dm",
3176
3221
  Provider: "aamp",