@agenticmail/openclaw 0.5.49 → 0.5.51
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 +40 -40
- package/dist/index.js +40 -40
- 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,37 +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
|
-
});
|
|
3131
|
-
if (!resp.ok) {
|
|
3132
|
-
const errBody = await resp.text().catch(() => "");
|
|
3133
|
-
console.warn(`[agenticmail] email wake failed (${resp.status}): ${errBody}`);
|
|
3134
|
-
}
|
|
3135
|
-
} 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})`);
|
|
3136
3129
|
}
|
|
3137
|
-
}
|
|
3130
|
+
} catch {
|
|
3138
3131
|
}
|
|
3139
3132
|
}
|
|
3140
|
-
} catch {
|
|
3141
3133
|
}
|
|
3134
|
+
} catch {
|
|
3142
3135
|
}
|
|
3143
3136
|
}
|
|
3144
3137
|
}
|
|
@@ -3150,14 +3143,21 @@ function activate(api) {
|
|
|
3150
3143
|
}
|
|
3151
3144
|
}
|
|
3152
3145
|
} catch {
|
|
3153
|
-
} finally {
|
|
3154
|
-
sseController = null;
|
|
3155
|
-
sseRetryMs = Math.min(sseRetryMs * 1.5, 6e4);
|
|
3156
|
-
setTimeout(startMainWatcher, sseRetryMs);
|
|
3157
3146
|
}
|
|
3147
|
+
scheduleReconnect();
|
|
3158
3148
|
})();
|
|
3159
3149
|
};
|
|
3160
|
-
|
|
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);
|
|
3161
3161
|
}
|
|
3162
3162
|
if (api?.registerCommand) {
|
|
3163
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,37 +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
|
-
});
|
|
3095
|
-
if (!resp.ok) {
|
|
3096
|
-
const errBody = await resp.text().catch(() => "");
|
|
3097
|
-
console.warn(`[agenticmail] email wake failed (${resp.status}): ${errBody}`);
|
|
3098
|
-
}
|
|
3099
|
-
} 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})`);
|
|
3100
3093
|
}
|
|
3101
|
-
}
|
|
3094
|
+
} catch {
|
|
3102
3095
|
}
|
|
3103
3096
|
}
|
|
3104
|
-
} catch {
|
|
3105
3097
|
}
|
|
3098
|
+
} catch {
|
|
3106
3099
|
}
|
|
3107
3100
|
}
|
|
3108
3101
|
}
|
|
@@ -3114,14 +3107,21 @@ function activate(api) {
|
|
|
3114
3107
|
}
|
|
3115
3108
|
}
|
|
3116
3109
|
} catch {
|
|
3117
|
-
} finally {
|
|
3118
|
-
sseController = null;
|
|
3119
|
-
sseRetryMs = Math.min(sseRetryMs * 1.5, 6e4);
|
|
3120
|
-
setTimeout(startMainWatcher, sseRetryMs);
|
|
3121
3110
|
}
|
|
3111
|
+
scheduleReconnect();
|
|
3122
3112
|
})();
|
|
3123
3113
|
};
|
|
3124
|
-
|
|
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);
|
|
3125
3125
|
}
|
|
3126
3126
|
if (api?.registerCommand) {
|
|
3127
3127
|
api.registerCommand({
|
package/package.json
CHANGED