@agenticmail/openclaw 0.5.46 → 0.5.47
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.cjs +74 -0
- package/dist/index.js +74 -0
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -3078,6 +3078,80 @@ function activate(api) {
|
|
|
3078
3078
|
if (api?.registerService) {
|
|
3079
3079
|
api.registerService(createMailMonitorService(ctx));
|
|
3080
3080
|
}
|
|
3081
|
+
{
|
|
3082
|
+
const gatewayPort = process.env.OPENCLAW_PORT || process.env.PORT || "3000";
|
|
3083
|
+
const agentApiKey = ctx.config.apiKey;
|
|
3084
|
+
const sseUrl = `${ctx.config.apiUrl}/api/agenticmail/events`;
|
|
3085
|
+
let sseRetryMs = 5e3;
|
|
3086
|
+
let sseController = null;
|
|
3087
|
+
const startMainWatcher = () => {
|
|
3088
|
+
if (sseController) return;
|
|
3089
|
+
sseController = new AbortController();
|
|
3090
|
+
(async () => {
|
|
3091
|
+
try {
|
|
3092
|
+
const res = await fetch(sseUrl, {
|
|
3093
|
+
headers: { "Authorization": `Bearer ${agentApiKey}`, "Accept": "text/event-stream" },
|
|
3094
|
+
signal: sseController.signal
|
|
3095
|
+
});
|
|
3096
|
+
if (!res.ok || !res.body) return;
|
|
3097
|
+
sseRetryMs = 5e3;
|
|
3098
|
+
const reader = res.body.getReader();
|
|
3099
|
+
const decoder = new TextDecoder();
|
|
3100
|
+
let buffer = "";
|
|
3101
|
+
try {
|
|
3102
|
+
while (true) {
|
|
3103
|
+
const { done, value } = await reader.read();
|
|
3104
|
+
if (done) break;
|
|
3105
|
+
buffer += decoder.decode(value, { stream: true });
|
|
3106
|
+
let boundary;
|
|
3107
|
+
while ((boundary = buffer.indexOf("\n\n")) !== -1) {
|
|
3108
|
+
const frame = buffer.slice(0, boundary);
|
|
3109
|
+
buffer = buffer.slice(boundary + 2);
|
|
3110
|
+
for (const line of frame.split("\n")) {
|
|
3111
|
+
if (line.startsWith("data: ")) {
|
|
3112
|
+
try {
|
|
3113
|
+
const event = JSON.parse(line.slice(6));
|
|
3114
|
+
if (event.type === "new" && event.uid) {
|
|
3115
|
+
const from = event.from ?? "unknown";
|
|
3116
|
+
const subject = event.subject ?? "(no subject)";
|
|
3117
|
+
const wakeText = `New email received from ${from}: "${subject}". Read it with agenticmail_read(uid=${event.uid}), assess urgency, and decide: if urgent or time-sensitive, notify the user now. Otherwise, note it in memory and batch-notify later.`;
|
|
3118
|
+
try {
|
|
3119
|
+
await fetch(`http://127.0.0.1:${gatewayPort}/api/cron/wake`, {
|
|
3120
|
+
method: "POST",
|
|
3121
|
+
headers: { "Content-Type": "application/json" },
|
|
3122
|
+
body: JSON.stringify({ text: wakeText, mode: "now" }),
|
|
3123
|
+
signal: AbortSignal.timeout(5e3)
|
|
3124
|
+
});
|
|
3125
|
+
console.log(`[agenticmail] Wake event sent for new email from ${from}: "${subject}"`);
|
|
3126
|
+
} catch (wakeErr) {
|
|
3127
|
+
console.warn(`[agenticmail] Failed to send wake event: ${wakeErr.message}`);
|
|
3128
|
+
}
|
|
3129
|
+
}
|
|
3130
|
+
} catch {
|
|
3131
|
+
}
|
|
3132
|
+
}
|
|
3133
|
+
}
|
|
3134
|
+
}
|
|
3135
|
+
}
|
|
3136
|
+
} finally {
|
|
3137
|
+
try {
|
|
3138
|
+
reader.cancel();
|
|
3139
|
+
} catch {
|
|
3140
|
+
}
|
|
3141
|
+
}
|
|
3142
|
+
} catch (err) {
|
|
3143
|
+
if (err.name !== "AbortError") {
|
|
3144
|
+
console.warn(`[agenticmail] Main email watcher error: ${err.message}`);
|
|
3145
|
+
}
|
|
3146
|
+
} finally {
|
|
3147
|
+
sseController = null;
|
|
3148
|
+
sseRetryMs = Math.min(sseRetryMs * 1.5, 6e4);
|
|
3149
|
+
setTimeout(startMainWatcher, sseRetryMs);
|
|
3150
|
+
}
|
|
3151
|
+
})();
|
|
3152
|
+
};
|
|
3153
|
+
setTimeout(startMainWatcher, 3e3);
|
|
3154
|
+
}
|
|
3081
3155
|
if (api?.registerCommand) {
|
|
3082
3156
|
api.registerCommand({
|
|
3083
3157
|
name: "agenticmail",
|
package/dist/index.js
CHANGED
|
@@ -3042,6 +3042,80 @@ function activate(api) {
|
|
|
3042
3042
|
if (api?.registerService) {
|
|
3043
3043
|
api.registerService(createMailMonitorService(ctx));
|
|
3044
3044
|
}
|
|
3045
|
+
{
|
|
3046
|
+
const gatewayPort = process.env.OPENCLAW_PORT || process.env.PORT || "3000";
|
|
3047
|
+
const agentApiKey = ctx.config.apiKey;
|
|
3048
|
+
const sseUrl = `${ctx.config.apiUrl}/api/agenticmail/events`;
|
|
3049
|
+
let sseRetryMs = 5e3;
|
|
3050
|
+
let sseController = null;
|
|
3051
|
+
const startMainWatcher = () => {
|
|
3052
|
+
if (sseController) return;
|
|
3053
|
+
sseController = new AbortController();
|
|
3054
|
+
(async () => {
|
|
3055
|
+
try {
|
|
3056
|
+
const res = await fetch(sseUrl, {
|
|
3057
|
+
headers: { "Authorization": `Bearer ${agentApiKey}`, "Accept": "text/event-stream" },
|
|
3058
|
+
signal: sseController.signal
|
|
3059
|
+
});
|
|
3060
|
+
if (!res.ok || !res.body) return;
|
|
3061
|
+
sseRetryMs = 5e3;
|
|
3062
|
+
const reader = res.body.getReader();
|
|
3063
|
+
const decoder = new TextDecoder();
|
|
3064
|
+
let buffer = "";
|
|
3065
|
+
try {
|
|
3066
|
+
while (true) {
|
|
3067
|
+
const { done, value } = await reader.read();
|
|
3068
|
+
if (done) break;
|
|
3069
|
+
buffer += decoder.decode(value, { stream: true });
|
|
3070
|
+
let boundary;
|
|
3071
|
+
while ((boundary = buffer.indexOf("\n\n")) !== -1) {
|
|
3072
|
+
const frame = buffer.slice(0, boundary);
|
|
3073
|
+
buffer = buffer.slice(boundary + 2);
|
|
3074
|
+
for (const line of frame.split("\n")) {
|
|
3075
|
+
if (line.startsWith("data: ")) {
|
|
3076
|
+
try {
|
|
3077
|
+
const event = JSON.parse(line.slice(6));
|
|
3078
|
+
if (event.type === "new" && event.uid) {
|
|
3079
|
+
const from = event.from ?? "unknown";
|
|
3080
|
+
const subject = event.subject ?? "(no subject)";
|
|
3081
|
+
const wakeText = `New email received from ${from}: "${subject}". Read it with agenticmail_read(uid=${event.uid}), assess urgency, and decide: if urgent or time-sensitive, notify the user now. Otherwise, note it in memory and batch-notify later.`;
|
|
3082
|
+
try {
|
|
3083
|
+
await fetch(`http://127.0.0.1:${gatewayPort}/api/cron/wake`, {
|
|
3084
|
+
method: "POST",
|
|
3085
|
+
headers: { "Content-Type": "application/json" },
|
|
3086
|
+
body: JSON.stringify({ text: wakeText, mode: "now" }),
|
|
3087
|
+
signal: AbortSignal.timeout(5e3)
|
|
3088
|
+
});
|
|
3089
|
+
console.log(`[agenticmail] Wake event sent for new email from ${from}: "${subject}"`);
|
|
3090
|
+
} catch (wakeErr) {
|
|
3091
|
+
console.warn(`[agenticmail] Failed to send wake event: ${wakeErr.message}`);
|
|
3092
|
+
}
|
|
3093
|
+
}
|
|
3094
|
+
} catch {
|
|
3095
|
+
}
|
|
3096
|
+
}
|
|
3097
|
+
}
|
|
3098
|
+
}
|
|
3099
|
+
}
|
|
3100
|
+
} finally {
|
|
3101
|
+
try {
|
|
3102
|
+
reader.cancel();
|
|
3103
|
+
} catch {
|
|
3104
|
+
}
|
|
3105
|
+
}
|
|
3106
|
+
} catch (err) {
|
|
3107
|
+
if (err.name !== "AbortError") {
|
|
3108
|
+
console.warn(`[agenticmail] Main email watcher error: ${err.message}`);
|
|
3109
|
+
}
|
|
3110
|
+
} finally {
|
|
3111
|
+
sseController = null;
|
|
3112
|
+
sseRetryMs = Math.min(sseRetryMs * 1.5, 6e4);
|
|
3113
|
+
setTimeout(startMainWatcher, sseRetryMs);
|
|
3114
|
+
}
|
|
3115
|
+
})();
|
|
3116
|
+
};
|
|
3117
|
+
setTimeout(startMainWatcher, 3e3);
|
|
3118
|
+
}
|
|
3045
3119
|
if (api?.registerCommand) {
|
|
3046
3120
|
api.registerCommand({
|
|
3047
3121
|
name: "agenticmail",
|
package/package.json
CHANGED