aamp-openclaw-plugin 0.1.15 → 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 +21 -149
- package/dist/index.js.map +2 -2
- package/package.json +1 -1
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,60 +16355,12 @@ var src_default = {
|
|
|
16352
16355
|
}
|
|
16353
16356
|
}
|
|
16354
16357
|
function wakeAgentForPendingTask(task) {
|
|
16355
|
-
const
|
|
16356
|
-
const
|
|
16358
|
+
const sessionKey = dispatchSessionKey();
|
|
16359
|
+
const fallback = () => triggerHeartbeatWake(sessionKey, `task ${task.taskId}`);
|
|
16357
16360
|
api.logger.info(
|
|
16358
|
-
`[AAMP] Wake requested for task ${task.taskId} \u2014 channelRuntime=${channelRuntime ? "yes" : "no"} channelCfg=${channelCfg ? "yes" : "no"}
|
|
16361
|
+
`[AAMP] Wake requested for task ${task.taskId} \u2014 channelRuntime=${channelRuntime ? "yes" : "no"} channelCfg=${channelCfg ? "yes" : "no"} session=${sessionKey}`
|
|
16359
16362
|
);
|
|
16360
|
-
|
|
16361
|
-
fallback();
|
|
16362
|
-
return;
|
|
16363
|
-
}
|
|
16364
|
-
const prompt = [
|
|
16365
|
-
"## New AAMP Task",
|
|
16366
|
-
"",
|
|
16367
|
-
"A new AAMP task just arrived.",
|
|
16368
|
-
"Use the pending AAMP task in system context as the source of truth and handle it now.",
|
|
16369
|
-
"Reply with aamp_send_result or aamp_send_help before responding."
|
|
16370
|
-
].join("\n");
|
|
16371
|
-
try {
|
|
16372
|
-
void Promise.resolve(dispatcher({
|
|
16373
|
-
ctx: {
|
|
16374
|
-
Body: task.bodyText || task.title,
|
|
16375
|
-
BodyForAgent: prompt,
|
|
16376
|
-
From: task.from,
|
|
16377
|
-
To: agentEmail,
|
|
16378
|
-
SessionKey: `aamp:default:task:${task.taskId}`,
|
|
16379
|
-
AccountId: "default",
|
|
16380
|
-
ChatType: "dm",
|
|
16381
|
-
Provider: "aamp",
|
|
16382
|
-
Surface: "aamp",
|
|
16383
|
-
OriginatingChannel: "aamp",
|
|
16384
|
-
OriginatingTo: task.from,
|
|
16385
|
-
MessageSid: task.messageId || task.taskId,
|
|
16386
|
-
Timestamp: Date.now(),
|
|
16387
|
-
SenderName: task.from,
|
|
16388
|
-
SenderId: task.from,
|
|
16389
|
-
CommandAuthorized: true
|
|
16390
|
-
},
|
|
16391
|
-
cfg: channelCfg,
|
|
16392
|
-
dispatcherOptions: {
|
|
16393
|
-
deliver: async () => {
|
|
16394
|
-
},
|
|
16395
|
-
onError: (err) => {
|
|
16396
|
-
api.logger.error(`[AAMP] Channel dispatch error for task ${task.taskId}: ${err instanceof Error ? err.message : String(err)}`);
|
|
16397
|
-
}
|
|
16398
|
-
}
|
|
16399
|
-
})).then(() => {
|
|
16400
|
-
api.logger.info(`[AAMP] Channel dispatch triggered for task ${task.taskId}`);
|
|
16401
|
-
}).catch((err) => {
|
|
16402
|
-
api.logger.error(`[AAMP] Channel dispatch failed for task ${task.taskId}: ${err.message}`);
|
|
16403
|
-
fallback();
|
|
16404
|
-
});
|
|
16405
|
-
} catch (err) {
|
|
16406
|
-
api.logger.error(`[AAMP] Channel dispatch threw synchronously for task ${task.taskId}: ${err.message}`);
|
|
16407
|
-
fallback();
|
|
16408
|
-
}
|
|
16363
|
+
fallback();
|
|
16409
16364
|
}
|
|
16410
16365
|
async function doConnect(identity) {
|
|
16411
16366
|
if (reconcileTimer) {
|
|
@@ -16538,58 +16493,11 @@ Reason: ${result.errorMsg ?? "unknown"}`,
|
|
|
16538
16493
|
messageId: "",
|
|
16539
16494
|
receivedAt: (/* @__PURE__ */ new Date()).toISOString()
|
|
16540
16495
|
});
|
|
16541
|
-
|
|
16542
|
-
|
|
16543
|
-
|
|
16544
|
-
|
|
16545
|
-
|
|
16546
|
-
### Action Required
|
|
16547
|
-
You MUST call aamp_send_result to complete the pending task(s):
|
|
16548
|
-
${actionableTasks.map((t) => `- Task ID: ${t.taskId} | From: ${t.from} | Title: "${t.title}"`).join("\n")}` : "";
|
|
16549
|
-
const prompt = `## Sub-task Update
|
|
16550
|
-
|
|
16551
|
-
${notifyBody?.bodyText ?? "Sub-task completed."}${actionSection}`;
|
|
16552
|
-
channelRuntime.reply.dispatchReplyWithBufferedBlockDispatcher({
|
|
16553
|
-
ctx: {
|
|
16554
|
-
Body: `Sub-task result: ${result.taskId}`,
|
|
16555
|
-
BodyForAgent: prompt,
|
|
16556
|
-
From: result.from,
|
|
16557
|
-
To: agentEmail,
|
|
16558
|
-
SessionKey: `aamp:default:${result.from}`,
|
|
16559
|
-
AccountId: "default",
|
|
16560
|
-
ChatType: "dm",
|
|
16561
|
-
Provider: "aamp",
|
|
16562
|
-
Surface: "aamp",
|
|
16563
|
-
OriginatingChannel: "aamp",
|
|
16564
|
-
OriginatingTo: result.from,
|
|
16565
|
-
MessageSid: result.taskId,
|
|
16566
|
-
Timestamp: Date.now(),
|
|
16567
|
-
SenderName: result.from,
|
|
16568
|
-
SenderId: result.from,
|
|
16569
|
-
CommandAuthorized: true
|
|
16570
|
-
},
|
|
16571
|
-
cfg: channelCfg,
|
|
16572
|
-
dispatcherOptions: {
|
|
16573
|
-
deliver: async () => {
|
|
16574
|
-
},
|
|
16575
|
-
onError: (err) => {
|
|
16576
|
-
api.logger.error(`[AAMP] Channel dispatch error: ${err instanceof Error ? err.message : String(err)}`);
|
|
16577
|
-
}
|
|
16578
|
-
}
|
|
16579
|
-
}).then(() => {
|
|
16580
|
-
api.logger.info(`[AAMP] Channel dispatch completed for sub-task result ${result.taskId}`);
|
|
16581
|
-
pendingTasks.delete(`result:${result.taskId}`);
|
|
16582
|
-
}).catch((err) => {
|
|
16583
|
-
api.logger.error(`[AAMP] Channel dispatch failed: ${err.message}`);
|
|
16584
|
-
});
|
|
16585
|
-
} else {
|
|
16586
|
-
const notifySessionKey = `agent:main:aamp-notify-${Date.now()}`;
|
|
16587
|
-
try {
|
|
16588
|
-
api.runtime.system.requestHeartbeatNow({ reason: "wake", sessionKey: notifySessionKey });
|
|
16589
|
-
api.logger.info(`[AAMP] Heartbeat for sub-task result ${result.taskId}`);
|
|
16590
|
-
} catch (err) {
|
|
16591
|
-
api.logger.warn(`[AAMP] Heartbeat for sub-task result failed: ${err.message}`);
|
|
16592
|
-
}
|
|
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}`);
|
|
16593
16501
|
}
|
|
16594
16502
|
}).catch((err) => {
|
|
16595
16503
|
api.logger.error(`[AAMP] Sub-task result processing failed: ${err.message}`);
|
|
@@ -16619,51 +16527,11 @@ Suggested options: ${help.suggestedOptions.join(", ")}` : ""}`,
|
|
|
16619
16527
|
messageId: "",
|
|
16620
16528
|
receivedAt: (/* @__PURE__ */ new Date()).toISOString()
|
|
16621
16529
|
});
|
|
16622
|
-
|
|
16623
|
-
|
|
16624
|
-
|
|
16625
|
-
|
|
16626
|
-
|
|
16627
|
-
channelRuntime.reply.dispatchReplyWithBufferedBlockDispatcher({
|
|
16628
|
-
ctx: {
|
|
16629
|
-
Body: `Sub-task help: ${help.taskId}`,
|
|
16630
|
-
BodyForAgent: prompt,
|
|
16631
|
-
From: help.from,
|
|
16632
|
-
To: agentEmail,
|
|
16633
|
-
SessionKey: `aamp:default:${help.from}`,
|
|
16634
|
-
AccountId: "default",
|
|
16635
|
-
ChatType: "dm",
|
|
16636
|
-
Provider: "aamp",
|
|
16637
|
-
Surface: "aamp",
|
|
16638
|
-
OriginatingChannel: "aamp",
|
|
16639
|
-
OriginatingTo: help.from,
|
|
16640
|
-
MessageSid: help.taskId,
|
|
16641
|
-
Timestamp: Date.now(),
|
|
16642
|
-
SenderName: help.from,
|
|
16643
|
-
SenderId: help.from,
|
|
16644
|
-
CommandAuthorized: true
|
|
16645
|
-
},
|
|
16646
|
-
cfg: channelCfg,
|
|
16647
|
-
dispatcherOptions: {
|
|
16648
|
-
deliver: async () => {
|
|
16649
|
-
},
|
|
16650
|
-
onError: (err) => {
|
|
16651
|
-
api.logger.error(`[AAMP] Channel dispatch error (help): ${err instanceof Error ? err.message : String(err)}`);
|
|
16652
|
-
}
|
|
16653
|
-
}
|
|
16654
|
-
}).then(() => {
|
|
16655
|
-
pendingTasks.delete(`help:${help.taskId}`);
|
|
16656
|
-
}).catch((err) => {
|
|
16657
|
-
api.logger.error(`[AAMP] Channel dispatch failed for help: ${err.message}`);
|
|
16658
|
-
});
|
|
16659
|
-
} else {
|
|
16660
|
-
const helpSessionKey = `agent:main:aamp-notify-${Date.now()}`;
|
|
16661
|
-
try {
|
|
16662
|
-
api.runtime.system.requestHeartbeatNow({ reason: "wake", sessionKey: helpSessionKey });
|
|
16663
|
-
api.logger.info(`[AAMP] Heartbeat fallback for sub-task help ${help.taskId}`);
|
|
16664
|
-
} catch (err) {
|
|
16665
|
-
api.logger.warn(`[AAMP] Heartbeat for sub-task help failed: ${err.message}`);
|
|
16666
|
-
}
|
|
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}`);
|
|
16667
16535
|
}
|
|
16668
16536
|
});
|
|
16669
16537
|
aampClient.on("connected", () => {
|
|
@@ -16676,6 +16544,10 @@ ${notifyBody?.bodyText ?? help.question}`;
|
|
|
16676
16544
|
});
|
|
16677
16545
|
aampClient.on("disconnected", (reason) => {
|
|
16678
16546
|
lastDisconnectReason = reason;
|
|
16547
|
+
if (aampClient?.isUsingPollingFallback()) {
|
|
16548
|
+
lastTransportMode = "polling";
|
|
16549
|
+
return;
|
|
16550
|
+
}
|
|
16679
16551
|
if (lastTransportMode !== "disconnected") {
|
|
16680
16552
|
api.logger.warn(`[AAMP] Disconnected: ${reason} (will auto-reconnect)`);
|
|
16681
16553
|
lastTransportMode = "disconnected";
|