aamp-openclaw-plugin 0.1.16 → 0.1.17

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
@@ -16357,76 +16357,10 @@ var src_default = {
16357
16357
  function wakeAgentForPendingTask(task) {
16358
16358
  const sessionKey = dispatchSessionKey();
16359
16359
  const fallback = () => triggerHeartbeatWake(sessionKey, `task ${task.taskId}`);
16360
- const dispatcher = channelRuntime?.reply?.dispatchReplyWithBufferedBlockDispatcher;
16361
16360
  api.logger.info(
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}`
16361
+ `[AAMP] Wake requested for task ${task.taskId} \u2014 channelRuntime=${channelRuntime ? "yes" : "no"} channelCfg=${channelCfg ? "yes" : "no"} session=${sessionKey}`
16363
16362
  );
16364
- if (!channelRuntime || !channelCfg || typeof dispatcher !== "function") {
16365
- fallback();
16366
- return;
16367
- }
16368
- const prompt = [
16369
- "## New AAMP Task",
16370
- "",
16371
- "A new AAMP task just arrived.",
16372
- "Use the pending AAMP task in system context as the source of truth and handle it now.",
16373
- "Reply with aamp_send_result or aamp_send_help before responding."
16374
- ].join("\n");
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}`);
16387
- void Promise.resolve(dispatcher({
16388
- ctx: {
16389
- Body: task.bodyText || task.title,
16390
- BodyForAgent: prompt,
16391
- From: task.from,
16392
- To: agentEmail,
16393
- SessionKey: sessionKey,
16394
- AccountId: "default",
16395
- ChatType: "dm",
16396
- Provider: "aamp",
16397
- Surface: "aamp",
16398
- OriginatingChannel: "aamp",
16399
- OriginatingTo: task.from,
16400
- MessageSid: task.messageId || task.taskId,
16401
- Timestamp: Date.now(),
16402
- SenderName: task.from,
16403
- SenderId: task.from,
16404
- CommandAuthorized: true
16405
- },
16406
- cfg: channelCfg,
16407
- dispatcherOptions: {
16408
- deliver: async () => {
16409
- },
16410
- onError: (err) => {
16411
- api.logger.error(`[AAMP] Channel dispatch error for task ${task.taskId}: ${err instanceof Error ? err.message : String(err)}`);
16412
- }
16413
- }
16414
- })).then(() => {
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
- );
16420
- }).catch((err) => {
16421
- settled = true;
16422
- clearTimeout(fallbackTimer);
16423
- api.logger.error(`[AAMP] Channel dispatch failed for task ${task.taskId}: ${err.message}`);
16424
- fallback();
16425
- });
16426
- } catch (err) {
16427
- api.logger.error(`[AAMP] Channel dispatch threw synchronously for task ${task.taskId}: ${err.message}`);
16428
- fallback();
16429
- }
16363
+ fallback();
16430
16364
  }
16431
16365
  async function doConnect(identity) {
16432
16366
  if (reconcileTimer) {
@@ -16559,58 +16493,11 @@ Reason: ${result.errorMsg ?? "unknown"}`,
16559
16493
  messageId: "",
16560
16494
  receivedAt: (/* @__PURE__ */ new Date()).toISOString()
16561
16495
  });
16562
- if (channelRuntime && channelCfg) {
16563
- const notifyBody = pendingTasks.get(`result:${result.taskId}`);
16564
- const actionableTasks = [...pendingTasks.entries()].filter(([key]) => !key.startsWith("result:") && !key.startsWith("help:")).map(([, t]) => t);
16565
- const actionSection = actionableTasks.length > 0 ? `
16566
-
16567
- ### Action Required
16568
- You MUST call aamp_send_result to complete the pending task(s):
16569
- ${actionableTasks.map((t) => `- Task ID: ${t.taskId} | From: ${t.from} | Title: "${t.title}"`).join("\n")}` : "";
16570
- const prompt = `## Sub-task Update
16571
-
16572
- ${notifyBody?.bodyText ?? "Sub-task completed."}${actionSection}`;
16573
- channelRuntime.reply.dispatchReplyWithBufferedBlockDispatcher({
16574
- ctx: {
16575
- Body: `Sub-task result: ${result.taskId}`,
16576
- BodyForAgent: prompt,
16577
- From: result.from,
16578
- To: agentEmail,
16579
- SessionKey: dispatchSessionKey(),
16580
- AccountId: "default",
16581
- ChatType: "dm",
16582
- Provider: "aamp",
16583
- Surface: "aamp",
16584
- OriginatingChannel: "aamp",
16585
- OriginatingTo: result.from,
16586
- MessageSid: result.taskId,
16587
- Timestamp: Date.now(),
16588
- SenderName: result.from,
16589
- SenderId: result.from,
16590
- CommandAuthorized: true
16591
- },
16592
- cfg: channelCfg,
16593
- dispatcherOptions: {
16594
- deliver: async () => {
16595
- },
16596
- onError: (err) => {
16597
- api.logger.error(`[AAMP] Channel dispatch error: ${err instanceof Error ? err.message : String(err)}`);
16598
- }
16599
- }
16600
- }).then(() => {
16601
- api.logger.info(`[AAMP] Channel dispatch completed for sub-task result ${result.taskId}`);
16602
- pendingTasks.delete(`result:${result.taskId}`);
16603
- }).catch((err) => {
16604
- api.logger.error(`[AAMP] Channel dispatch failed: ${err.message}`);
16605
- });
16606
- } else {
16607
- const notifySessionKey = `agent:main:aamp-notify-${Date.now()}`;
16608
- try {
16609
- api.runtime.system.requestHeartbeatNow({ reason: "wake", sessionKey: notifySessionKey });
16610
- api.logger.info(`[AAMP] Heartbeat for sub-task result ${result.taskId}`);
16611
- } catch (err) {
16612
- api.logger.warn(`[AAMP] Heartbeat for sub-task result failed: ${err.message}`);
16613
- }
16496
+ try {
16497
+ api.runtime.system.requestHeartbeatNow({ reason: "wake", sessionKey: dispatchSessionKey() });
16498
+ api.logger.info(`[AAMP] Heartbeat for sub-task result ${result.taskId}`);
16499
+ } catch (err) {
16500
+ api.logger.warn(`[AAMP] Heartbeat for sub-task result failed: ${err.message}`);
16614
16501
  }
16615
16502
  }).catch((err) => {
16616
16503
  api.logger.error(`[AAMP] Sub-task result processing failed: ${err.message}`);
@@ -16640,51 +16527,11 @@ Suggested options: ${help.suggestedOptions.join(", ")}` : ""}`,
16640
16527
  messageId: "",
16641
16528
  receivedAt: (/* @__PURE__ */ new Date()).toISOString()
16642
16529
  });
16643
- if (channelRuntime && channelCfg) {
16644
- const notifyBody = pendingTasks.get(`help:${help.taskId}`);
16645
- const prompt = `## Sub-task Help Request
16646
-
16647
- ${notifyBody?.bodyText ?? help.question}`;
16648
- channelRuntime.reply.dispatchReplyWithBufferedBlockDispatcher({
16649
- ctx: {
16650
- Body: `Sub-task help: ${help.taskId}`,
16651
- BodyForAgent: prompt,
16652
- From: help.from,
16653
- To: agentEmail,
16654
- SessionKey: dispatchSessionKey(),
16655
- AccountId: "default",
16656
- ChatType: "dm",
16657
- Provider: "aamp",
16658
- Surface: "aamp",
16659
- OriginatingChannel: "aamp",
16660
- OriginatingTo: help.from,
16661
- MessageSid: help.taskId,
16662
- Timestamp: Date.now(),
16663
- SenderName: help.from,
16664
- SenderId: help.from,
16665
- CommandAuthorized: true
16666
- },
16667
- cfg: channelCfg,
16668
- dispatcherOptions: {
16669
- deliver: async () => {
16670
- },
16671
- onError: (err) => {
16672
- api.logger.error(`[AAMP] Channel dispatch error (help): ${err instanceof Error ? err.message : String(err)}`);
16673
- }
16674
- }
16675
- }).then(() => {
16676
- pendingTasks.delete(`help:${help.taskId}`);
16677
- }).catch((err) => {
16678
- api.logger.error(`[AAMP] Channel dispatch failed for help: ${err.message}`);
16679
- });
16680
- } else {
16681
- const helpSessionKey = `agent:main:aamp-notify-${Date.now()}`;
16682
- try {
16683
- api.runtime.system.requestHeartbeatNow({ reason: "wake", sessionKey: helpSessionKey });
16684
- api.logger.info(`[AAMP] Heartbeat fallback for sub-task help ${help.taskId}`);
16685
- } catch (err) {
16686
- api.logger.warn(`[AAMP] Heartbeat for sub-task help failed: ${err.message}`);
16687
- }
16530
+ try {
16531
+ api.runtime.system.requestHeartbeatNow({ reason: "wake", sessionKey: dispatchSessionKey() });
16532
+ api.logger.info(`[AAMP] Heartbeat fallback for sub-task help ${help.taskId}`);
16533
+ } catch (err) {
16534
+ api.logger.warn(`[AAMP] Heartbeat for sub-task help failed: ${err.message}`);
16688
16535
  }
16689
16536
  });
16690
16537
  aampClient.on("connected", () => {