@agenticmail/api 0.9.27 → 0.9.28
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/README.md +11 -0
- package/dist/index.js +46 -7
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -408,6 +408,17 @@ JSON parse errors (malformed request bodies) return a clear 400 error rather tha
|
|
|
408
408
|
|
|
409
409
|
---
|
|
410
410
|
|
|
411
|
+
## External inbox exposure — what `/gateway/relay` actually opens up
|
|
412
|
+
|
|
413
|
+
> **The `POST /gateway/relay` endpoint (the one `agenticmail setup-email` calls) makes every sub-agent publicly reachable from the internet via plus-addressing.** This is by design — agents that can only email each other aren't very useful for talking to real people — but the implications surprise some operators:
|
|
414
|
+
|
|
415
|
+
- **Plus-addresses are publicly guessable.** Once relay is connected, anyone can hit `your-relay+secretary@gmail.com`, `your-relay+kepler@gmail.com`, etc. and the corresponding agent's AgenticMail inbox receives the message. The `+sub` part is not a secret.
|
|
416
|
+
- **External mail wakes the dispatcher identically to internal `@localhost` mail.** The API publishes the same SSE `new-mail` event regardless of source; the host integration (`@agenticmail/claudecode`, `@agenticmail/codex`) spawns a worker turn either way.
|
|
417
|
+
- **The host bridges take a different path.** Mail to `your-relay+claudecode@gmail.com` / `your-relay+codex@gmail.com` routes to `handleBridgeMail` in the dispatcher, which uses the host SDK's `resume` option to wake the operator's last session headlessly. If that fails it falls through to the bridge-escalation email configured via `setup_operator_email`.
|
|
418
|
+
- **Spam = worker turns.** Throttles in order of escalation: the `wake-budget` guard in `dispatcher.handleEvent` (automatic, default cap per minute per agent), the built-in relay-level spam filter (runs before publishing the SSE event), and `metadata.host`-based fencing for agents that should stay internal-only.
|
|
419
|
+
|
|
420
|
+
---
|
|
421
|
+
|
|
411
422
|
## License
|
|
412
423
|
|
|
413
424
|
[MIT](./LICENSE) - Ope Olatunji ([@ope-olatunji](https://github.com/ope-olatunji))
|
package/dist/index.js
CHANGED
|
@@ -1956,18 +1956,45 @@ function normalizeWakeList(value) {
|
|
|
1956
1956
|
return void 0;
|
|
1957
1957
|
}
|
|
1958
1958
|
function deriveDefaultWakeList(toField) {
|
|
1959
|
-
|
|
1960
|
-
|
|
1961
|
-
|
|
1959
|
+
const localNames = extractLocalNames(toField);
|
|
1960
|
+
return localNames.length > 0 ? localNames : void 0;
|
|
1961
|
+
}
|
|
1962
|
+
function extractLocalNames(field) {
|
|
1963
|
+
if (!field) return [];
|
|
1964
|
+
const arr = Array.isArray(field) ? field : String(field).split(",");
|
|
1965
|
+
const out = [];
|
|
1962
1966
|
for (const raw of arr) {
|
|
1963
1967
|
const trimmed = String(raw).slice(0, 500).trim().toLowerCase();
|
|
1964
1968
|
const m = trimmed.match(/<([^>]+)>/);
|
|
1965
1969
|
const bare = (m ? m[1] : trimmed).trim();
|
|
1966
1970
|
if (!bare.endsWith("@localhost")) continue;
|
|
1967
1971
|
const name = bare.replace(/@localhost$/i, "");
|
|
1968
|
-
if (name)
|
|
1972
|
+
if (name) out.push(name);
|
|
1969
1973
|
}
|
|
1970
|
-
return
|
|
1974
|
+
return out;
|
|
1975
|
+
}
|
|
1976
|
+
function deriveWakeFromBody(body, candidateNames) {
|
|
1977
|
+
if (!body || candidateNames.length === 0) return [];
|
|
1978
|
+
const sample = body.length > 2e4 ? body.slice(0, 2e4) : body;
|
|
1979
|
+
const found = /* @__PURE__ */ new Set();
|
|
1980
|
+
for (const raw of candidateNames) {
|
|
1981
|
+
const name = String(raw).trim().toLowerCase();
|
|
1982
|
+
if (!name) continue;
|
|
1983
|
+
const esc = name.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
1984
|
+
const patterns = [
|
|
1985
|
+
// Greeting / handoff anchors:
|
|
1986
|
+
// "Marlow —" "Marlow:" "Marlow,"
|
|
1987
|
+
new RegExp(`(?:^|[\\n.])\\s*${esc}\\s*[\u2014\u2013\\-:,]`, "i"),
|
|
1988
|
+
// Mention syntax:
|
|
1989
|
+
// "@marlow"
|
|
1990
|
+
new RegExp(`@${esc}\\b`, "i"),
|
|
1991
|
+
// Conversational handoff phrases:
|
|
1992
|
+
// "over to marlow" "handing off to marlow" "next up: marlow"
|
|
1993
|
+
new RegExp(`\\b(?:hi|hey|hello|over to|hand(?:ing)? off to|dispatch(?:ing)? to|assigning to|next up:?|next slice:?)\\s+${esc}\\b`, "i")
|
|
1994
|
+
];
|
|
1995
|
+
if (patterns.some((p) => p.test(sample))) found.add(name);
|
|
1996
|
+
}
|
|
1997
|
+
return Array.from(found);
|
|
1971
1998
|
}
|
|
1972
1999
|
function wakeHeaders(wakeList) {
|
|
1973
2000
|
if (wakeList === void 0) return {};
|
|
@@ -2113,7 +2140,13 @@ function createMailRoutes(accountManager, config, db, gatewayManager) {
|
|
|
2113
2140
|
const ownerName2 = agent.metadata?.ownerName;
|
|
2114
2141
|
const fromName2 = ownerName2 ? `${agent.name} from ${ownerName2}` : agent.name;
|
|
2115
2142
|
const explicitWakeForPersist = normalizeWakeList(wake);
|
|
2116
|
-
|
|
2143
|
+
let wakeListForPersist;
|
|
2144
|
+
if (wake !== void 0) {
|
|
2145
|
+
wakeListForPersist = explicitWakeForPersist;
|
|
2146
|
+
} else {
|
|
2147
|
+
const bodyDerived = deriveWakeFromBody(typeof text === "string" ? text : "", extractLocalNames(cc));
|
|
2148
|
+
wakeListForPersist = bodyDerived.length > 0 ? bodyDerived : deriveDefaultWakeList(to);
|
|
2149
|
+
}
|
|
2117
2150
|
const mailOptions = {
|
|
2118
2151
|
to,
|
|
2119
2152
|
subject,
|
|
@@ -2197,7 +2230,13 @@ function createMailRoutes(accountManager, config, db, gatewayManager) {
|
|
|
2197
2230
|
const ownerName = agent.metadata?.ownerName;
|
|
2198
2231
|
const fromName = ownerName ? `${agent.name} from ${ownerName}` : agent.name;
|
|
2199
2232
|
const explicitWake = normalizeWakeList(wake);
|
|
2200
|
-
|
|
2233
|
+
let wakeList;
|
|
2234
|
+
if (wake !== void 0) {
|
|
2235
|
+
wakeList = explicitWake;
|
|
2236
|
+
} else {
|
|
2237
|
+
const bodyDerived = deriveWakeFromBody(typeof text === "string" ? text : "", extractLocalNames(cc));
|
|
2238
|
+
wakeList = bodyDerived.length > 0 ? bodyDerived : deriveDefaultWakeList(to);
|
|
2239
|
+
}
|
|
2201
2240
|
const customHeaders = wakeHeaders(wakeList);
|
|
2202
2241
|
const mailOpts = {
|
|
2203
2242
|
to,
|