@agenticmail/openclaw 0.5.48 → 0.5.50
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 +41 -59
- package/dist/index.js +41 -59
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -3079,21 +3079,20 @@ function activate(api) {
|
|
|
3079
3079
|
api.registerService(createMailMonitorService(ctx));
|
|
3080
3080
|
}
|
|
3081
3081
|
{
|
|
3082
|
-
|
|
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 = () => {
|
|
3082
|
+
let startMainWatcher2 = function() {
|
|
3088
3083
|
if (sseController) return;
|
|
3089
3084
|
sseController = new AbortController();
|
|
3085
|
+
const ctrl = sseController;
|
|
3090
3086
|
(async () => {
|
|
3091
3087
|
try {
|
|
3092
3088
|
const res = await fetch(sseUrl, {
|
|
3093
3089
|
headers: { "Authorization": `Bearer ${agentApiKey}`, "Accept": "text/event-stream" },
|
|
3094
|
-
signal:
|
|
3090
|
+
signal: ctrl.signal
|
|
3095
3091
|
});
|
|
3096
|
-
if (!res.ok || !res.body)
|
|
3092
|
+
if (!res.ok || !res.body) {
|
|
3093
|
+
scheduleReconnect();
|
|
3094
|
+
return;
|
|
3095
|
+
}
|
|
3097
3096
|
sseRetryMs = 5e3;
|
|
3098
3097
|
const reader = res.body.getReader();
|
|
3099
3098
|
const decoder = new TextDecoder();
|
|
@@ -3108,52 +3107,31 @@ function activate(api) {
|
|
|
3108
3107
|
const frame = buffer.slice(0, boundary);
|
|
3109
3108
|
buffer = buffer.slice(boundary + 2);
|
|
3110
3109
|
for (const line of frame.split("\n")) {
|
|
3111
|
-
if (line.startsWith("data: "))
|
|
3112
|
-
|
|
3113
|
-
|
|
3114
|
-
|
|
3115
|
-
|
|
3116
|
-
|
|
3117
|
-
|
|
3118
|
-
|
|
3119
|
-
|
|
3120
|
-
|
|
3121
|
-
|
|
3122
|
-
|
|
3123
|
-
|
|
3124
|
-
|
|
3125
|
-
|
|
3126
|
-
|
|
3127
|
-
|
|
3128
|
-
|
|
3129
|
-
|
|
3130
|
-
event: "system",
|
|
3131
|
-
text: wakeText,
|
|
3132
|
-
sessionTarget: "main"
|
|
3133
|
-
}),
|
|
3134
|
-
signal: AbortSignal.timeout(5e3)
|
|
3135
|
-
});
|
|
3136
|
-
if (resp.ok) {
|
|
3137
|
-
wakeSuccess = true;
|
|
3138
|
-
console.log(`[agenticmail] Wake event sent via webhook for new email from ${from}: "${subject}"`);
|
|
3139
|
-
}
|
|
3140
|
-
} catch {
|
|
3141
|
-
}
|
|
3142
|
-
}
|
|
3143
|
-
if (!wakeSuccess && api?.callTool) {
|
|
3144
|
-
try {
|
|
3145
|
-
await api.callTool("cron", { action: "wake", text: wakeText, mode: "now" });
|
|
3146
|
-
wakeSuccess = true;
|
|
3147
|
-
console.log(`[agenticmail] Wake event sent via cron tool for new email from ${from}: "${subject}"`);
|
|
3148
|
-
} catch {
|
|
3110
|
+
if (!line.startsWith("data: ")) continue;
|
|
3111
|
+
try {
|
|
3112
|
+
const event = JSON.parse(line.slice(6));
|
|
3113
|
+
if (event.type === "new" && event.uid) {
|
|
3114
|
+
const from = event.from ?? "unknown";
|
|
3115
|
+
const subject = event.subject ?? "(no subject)";
|
|
3116
|
+
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.`;
|
|
3117
|
+
const hooksToken = process.env.OPENCLAW_HOOKS_TOKEN;
|
|
3118
|
+
const gwPort = process.env.OPENCLAW_PORT || "18789";
|
|
3119
|
+
if (hooksToken) {
|
|
3120
|
+
try {
|
|
3121
|
+
const resp = await fetch(`http://127.0.0.1:${gwPort}/hooks/wake`, {
|
|
3122
|
+
method: "POST",
|
|
3123
|
+
headers: { "Content-Type": "application/json", "Authorization": `Bearer ${hooksToken}` },
|
|
3124
|
+
body: JSON.stringify({ text: wakeText, mode: "now" }),
|
|
3125
|
+
signal: AbortSignal.timeout(5e3)
|
|
3126
|
+
});
|
|
3127
|
+
if (!resp.ok) {
|
|
3128
|
+
console.warn(`[agenticmail] email wake failed (${resp.status})`);
|
|
3149
3129
|
}
|
|
3150
|
-
}
|
|
3151
|
-
if (!wakeSuccess) {
|
|
3152
|
-
console.warn(`[agenticmail] Could not send wake event for email from ${from}: "${subject}"`);
|
|
3130
|
+
} catch {
|
|
3153
3131
|
}
|
|
3154
3132
|
}
|
|
3155
|
-
} catch {
|
|
3156
3133
|
}
|
|
3134
|
+
} catch {
|
|
3157
3135
|
}
|
|
3158
3136
|
}
|
|
3159
3137
|
}
|
|
@@ -3164,18 +3142,22 @@ function activate(api) {
|
|
|
3164
3142
|
} catch {
|
|
3165
3143
|
}
|
|
3166
3144
|
}
|
|
3167
|
-
} catch
|
|
3168
|
-
if (err.name !== "AbortError") {
|
|
3169
|
-
console.warn(`[agenticmail] Main email watcher error: ${err.message}`);
|
|
3170
|
-
}
|
|
3171
|
-
} finally {
|
|
3172
|
-
sseController = null;
|
|
3173
|
-
sseRetryMs = Math.min(sseRetryMs * 1.5, 6e4);
|
|
3174
|
-
setTimeout(startMainWatcher, sseRetryMs);
|
|
3145
|
+
} catch {
|
|
3175
3146
|
}
|
|
3147
|
+
scheduleReconnect();
|
|
3176
3148
|
})();
|
|
3177
3149
|
};
|
|
3178
|
-
|
|
3150
|
+
var startMainWatcher = startMainWatcher2;
|
|
3151
|
+
const agentApiKey = ctx.config.apiKey;
|
|
3152
|
+
const sseUrl = `${ctx.config.apiUrl}/api/agenticmail/events`;
|
|
3153
|
+
let sseRetryMs = 5e3;
|
|
3154
|
+
let sseController = null;
|
|
3155
|
+
const scheduleReconnect = () => {
|
|
3156
|
+
sseController = null;
|
|
3157
|
+
sseRetryMs = Math.min(sseRetryMs * 1.5, 6e4);
|
|
3158
|
+
setTimeout(startMainWatcher2, sseRetryMs);
|
|
3159
|
+
};
|
|
3160
|
+
setTimeout(startMainWatcher2, 3e3);
|
|
3179
3161
|
}
|
|
3180
3162
|
if (api?.registerCommand) {
|
|
3181
3163
|
api.registerCommand({
|
package/dist/index.js
CHANGED
|
@@ -3043,21 +3043,20 @@ function activate(api) {
|
|
|
3043
3043
|
api.registerService(createMailMonitorService(ctx));
|
|
3044
3044
|
}
|
|
3045
3045
|
{
|
|
3046
|
-
|
|
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 = () => {
|
|
3046
|
+
let startMainWatcher2 = function() {
|
|
3052
3047
|
if (sseController) return;
|
|
3053
3048
|
sseController = new AbortController();
|
|
3049
|
+
const ctrl = sseController;
|
|
3054
3050
|
(async () => {
|
|
3055
3051
|
try {
|
|
3056
3052
|
const res = await fetch(sseUrl, {
|
|
3057
3053
|
headers: { "Authorization": `Bearer ${agentApiKey}`, "Accept": "text/event-stream" },
|
|
3058
|
-
signal:
|
|
3054
|
+
signal: ctrl.signal
|
|
3059
3055
|
});
|
|
3060
|
-
if (!res.ok || !res.body)
|
|
3056
|
+
if (!res.ok || !res.body) {
|
|
3057
|
+
scheduleReconnect();
|
|
3058
|
+
return;
|
|
3059
|
+
}
|
|
3061
3060
|
sseRetryMs = 5e3;
|
|
3062
3061
|
const reader = res.body.getReader();
|
|
3063
3062
|
const decoder = new TextDecoder();
|
|
@@ -3072,52 +3071,31 @@ function activate(api) {
|
|
|
3072
3071
|
const frame = buffer.slice(0, boundary);
|
|
3073
3072
|
buffer = buffer.slice(boundary + 2);
|
|
3074
3073
|
for (const line of frame.split("\n")) {
|
|
3075
|
-
if (line.startsWith("data: "))
|
|
3076
|
-
|
|
3077
|
-
|
|
3078
|
-
|
|
3079
|
-
|
|
3080
|
-
|
|
3081
|
-
|
|
3082
|
-
|
|
3083
|
-
|
|
3084
|
-
|
|
3085
|
-
|
|
3086
|
-
|
|
3087
|
-
|
|
3088
|
-
|
|
3089
|
-
|
|
3090
|
-
|
|
3091
|
-
|
|
3092
|
-
|
|
3093
|
-
|
|
3094
|
-
event: "system",
|
|
3095
|
-
text: wakeText,
|
|
3096
|
-
sessionTarget: "main"
|
|
3097
|
-
}),
|
|
3098
|
-
signal: AbortSignal.timeout(5e3)
|
|
3099
|
-
});
|
|
3100
|
-
if (resp.ok) {
|
|
3101
|
-
wakeSuccess = true;
|
|
3102
|
-
console.log(`[agenticmail] Wake event sent via webhook for new email from ${from}: "${subject}"`);
|
|
3103
|
-
}
|
|
3104
|
-
} catch {
|
|
3105
|
-
}
|
|
3106
|
-
}
|
|
3107
|
-
if (!wakeSuccess && api?.callTool) {
|
|
3108
|
-
try {
|
|
3109
|
-
await api.callTool("cron", { action: "wake", text: wakeText, mode: "now" });
|
|
3110
|
-
wakeSuccess = true;
|
|
3111
|
-
console.log(`[agenticmail] Wake event sent via cron tool for new email from ${from}: "${subject}"`);
|
|
3112
|
-
} catch {
|
|
3074
|
+
if (!line.startsWith("data: ")) continue;
|
|
3075
|
+
try {
|
|
3076
|
+
const event = JSON.parse(line.slice(6));
|
|
3077
|
+
if (event.type === "new" && event.uid) {
|
|
3078
|
+
const from = event.from ?? "unknown";
|
|
3079
|
+
const subject = event.subject ?? "(no subject)";
|
|
3080
|
+
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.`;
|
|
3081
|
+
const hooksToken = process.env.OPENCLAW_HOOKS_TOKEN;
|
|
3082
|
+
const gwPort = process.env.OPENCLAW_PORT || "18789";
|
|
3083
|
+
if (hooksToken) {
|
|
3084
|
+
try {
|
|
3085
|
+
const resp = await fetch(`http://127.0.0.1:${gwPort}/hooks/wake`, {
|
|
3086
|
+
method: "POST",
|
|
3087
|
+
headers: { "Content-Type": "application/json", "Authorization": `Bearer ${hooksToken}` },
|
|
3088
|
+
body: JSON.stringify({ text: wakeText, mode: "now" }),
|
|
3089
|
+
signal: AbortSignal.timeout(5e3)
|
|
3090
|
+
});
|
|
3091
|
+
if (!resp.ok) {
|
|
3092
|
+
console.warn(`[agenticmail] email wake failed (${resp.status})`);
|
|
3113
3093
|
}
|
|
3114
|
-
}
|
|
3115
|
-
if (!wakeSuccess) {
|
|
3116
|
-
console.warn(`[agenticmail] Could not send wake event for email from ${from}: "${subject}"`);
|
|
3094
|
+
} catch {
|
|
3117
3095
|
}
|
|
3118
3096
|
}
|
|
3119
|
-
} catch {
|
|
3120
3097
|
}
|
|
3098
|
+
} catch {
|
|
3121
3099
|
}
|
|
3122
3100
|
}
|
|
3123
3101
|
}
|
|
@@ -3128,18 +3106,22 @@ function activate(api) {
|
|
|
3128
3106
|
} catch {
|
|
3129
3107
|
}
|
|
3130
3108
|
}
|
|
3131
|
-
} catch
|
|
3132
|
-
if (err.name !== "AbortError") {
|
|
3133
|
-
console.warn(`[agenticmail] Main email watcher error: ${err.message}`);
|
|
3134
|
-
}
|
|
3135
|
-
} finally {
|
|
3136
|
-
sseController = null;
|
|
3137
|
-
sseRetryMs = Math.min(sseRetryMs * 1.5, 6e4);
|
|
3138
|
-
setTimeout(startMainWatcher, sseRetryMs);
|
|
3109
|
+
} catch {
|
|
3139
3110
|
}
|
|
3111
|
+
scheduleReconnect();
|
|
3140
3112
|
})();
|
|
3141
3113
|
};
|
|
3142
|
-
|
|
3114
|
+
var startMainWatcher = startMainWatcher2;
|
|
3115
|
+
const agentApiKey = ctx.config.apiKey;
|
|
3116
|
+
const sseUrl = `${ctx.config.apiUrl}/api/agenticmail/events`;
|
|
3117
|
+
let sseRetryMs = 5e3;
|
|
3118
|
+
let sseController = null;
|
|
3119
|
+
const scheduleReconnect = () => {
|
|
3120
|
+
sseController = null;
|
|
3121
|
+
sseRetryMs = Math.min(sseRetryMs * 1.5, 6e4);
|
|
3122
|
+
setTimeout(startMainWatcher2, sseRetryMs);
|
|
3123
|
+
};
|
|
3124
|
+
setTimeout(startMainWatcher2, 3e3);
|
|
3143
3125
|
}
|
|
3144
3126
|
if (api?.registerCommand) {
|
|
3145
3127
|
api.registerCommand({
|
package/package.json
CHANGED