@agenticmail/api 0.5.61 → 0.6.0
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 +83 -15
- package/package.json +5 -2
package/dist/index.js
CHANGED
|
@@ -1539,30 +1539,64 @@ async function closeCaches() {
|
|
|
1539
1539
|
}
|
|
1540
1540
|
receiverCache.clear();
|
|
1541
1541
|
}
|
|
1542
|
-
async function findUidByMessageId(receiver, messageId, maxAttempts =
|
|
1542
|
+
async function findUidByMessageId(receiver, messageId, maxAttempts = 8) {
|
|
1543
|
+
const target = normalizeMessageId(messageId);
|
|
1543
1544
|
const client = receiver.getImapClient();
|
|
1544
|
-
|
|
1545
|
+
const tryHeaderSearch = async () => {
|
|
1546
|
+
const lock = await client.getMailboxLock("INBOX");
|
|
1545
1547
|
try {
|
|
1546
|
-
const
|
|
1547
|
-
|
|
1548
|
-
|
|
1549
|
-
|
|
1550
|
-
|
|
1551
|
-
|
|
1552
|
-
|
|
1553
|
-
|
|
1548
|
+
const results = await client.search(
|
|
1549
|
+
{ header: ["Message-ID", messageId] },
|
|
1550
|
+
{ uid: true }
|
|
1551
|
+
);
|
|
1552
|
+
if (Array.isArray(results) && results.length > 0) {
|
|
1553
|
+
return results[results.length - 1];
|
|
1554
|
+
}
|
|
1555
|
+
} finally {
|
|
1556
|
+
lock.release();
|
|
1557
|
+
}
|
|
1558
|
+
return 0;
|
|
1559
|
+
};
|
|
1560
|
+
const tryEnvelopeScan = async () => {
|
|
1561
|
+
const lock = await client.getMailboxLock("INBOX");
|
|
1562
|
+
try {
|
|
1563
|
+
const status = await client.status("INBOX", { messages: true });
|
|
1564
|
+
const total = status?.messages ?? 0;
|
|
1565
|
+
if (total === 0) return 0;
|
|
1566
|
+
const start = Math.max(1, total - 9);
|
|
1567
|
+
const range = `${start}:${total}`;
|
|
1568
|
+
let bestUid = 0;
|
|
1569
|
+
for await (const msg of client.fetch(range, { uid: true, envelope: true })) {
|
|
1570
|
+
if (!msg.envelope?.messageId) continue;
|
|
1571
|
+
if (normalizeMessageId(msg.envelope.messageId) === target) {
|
|
1572
|
+
if (msg.uid > bestUid) bestUid = msg.uid;
|
|
1554
1573
|
}
|
|
1555
|
-
} finally {
|
|
1556
|
-
lock.release();
|
|
1557
1574
|
}
|
|
1558
|
-
|
|
1575
|
+
return bestUid;
|
|
1576
|
+
} finally {
|
|
1577
|
+
lock.release();
|
|
1559
1578
|
}
|
|
1560
|
-
|
|
1561
|
-
|
|
1579
|
+
};
|
|
1580
|
+
const delays = [0, 250, 500, 750, 1e3, 1250, 1500, 2e3];
|
|
1581
|
+
for (let i = 0; i < maxAttempts; i++) {
|
|
1582
|
+
if (delays[i]) await new Promise((r) => setTimeout(r, delays[i]));
|
|
1583
|
+
try {
|
|
1584
|
+
const headerHit = await tryHeaderSearch();
|
|
1585
|
+
if (headerHit > 0) return headerHit;
|
|
1586
|
+
const scanHit = await tryEnvelopeScan();
|
|
1587
|
+
if (scanHit > 0) return scanHit;
|
|
1588
|
+
} catch (err) {
|
|
1589
|
+
if (i === maxAttempts - 1) {
|
|
1590
|
+
console.warn(`[mail] findUidByMessageId attempt ${i + 1} failed for ${messageId}: ${err.message}`);
|
|
1591
|
+
}
|
|
1562
1592
|
}
|
|
1563
1593
|
}
|
|
1564
1594
|
return 0;
|
|
1565
1595
|
}
|
|
1596
|
+
function normalizeMessageId(id) {
|
|
1597
|
+
if (!id) return "";
|
|
1598
|
+
return id.trim().replace(/^<+|>+$/g, "").toLowerCase();
|
|
1599
|
+
}
|
|
1566
1600
|
async function notifyLocalRecipientsOfNewMail(accountManager, toField, ccField, bccField, fromAgent, subject, messageId, config) {
|
|
1567
1601
|
const collected = [];
|
|
1568
1602
|
const push = (v) => {
|
|
@@ -4477,6 +4511,35 @@ function createStorageRoutes(rawDb, accountManager, config, dialect = "sqlite")
|
|
|
4477
4511
|
}
|
|
4478
4512
|
|
|
4479
4513
|
// src/app.ts
|
|
4514
|
+
var integrationRouteFactoryPromise = (async () => {
|
|
4515
|
+
try {
|
|
4516
|
+
const mod = await import("@agenticmail/claudecode/http-routes");
|
|
4517
|
+
if (typeof mod.createIntegrationRoutes === "function") {
|
|
4518
|
+
return mod.createIntegrationRoutes;
|
|
4519
|
+
}
|
|
4520
|
+
return null;
|
|
4521
|
+
} catch {
|
|
4522
|
+
return null;
|
|
4523
|
+
}
|
|
4524
|
+
})();
|
|
4525
|
+
async function prepareIntegrations() {
|
|
4526
|
+
await integrationRouteFactoryPromise;
|
|
4527
|
+
}
|
|
4528
|
+
var __cachedIntegrationFactory = null;
|
|
4529
|
+
var __integrationFactorySettled = false;
|
|
4530
|
+
integrationRouteFactoryPromise.then(
|
|
4531
|
+
(factory) => {
|
|
4532
|
+
__cachedIntegrationFactory = factory;
|
|
4533
|
+
__integrationFactorySettled = true;
|
|
4534
|
+
},
|
|
4535
|
+
() => {
|
|
4536
|
+
__integrationFactorySettled = true;
|
|
4537
|
+
}
|
|
4538
|
+
);
|
|
4539
|
+
function readResolvedFactory(_p) {
|
|
4540
|
+
if (!__integrationFactorySettled) return null;
|
|
4541
|
+
return __cachedIntegrationFactory;
|
|
4542
|
+
}
|
|
4480
4543
|
function createApp(configOverrides) {
|
|
4481
4544
|
const config = resolveConfig(configOverrides);
|
|
4482
4545
|
const db = getDatabase(config);
|
|
@@ -4518,6 +4581,10 @@ function createApp(configOverrides) {
|
|
|
4518
4581
|
);
|
|
4519
4582
|
app2.use("/api/agenticmail", createHealthRoutes(stalwart));
|
|
4520
4583
|
app2.use("/api/agenticmail", createInboundRoutes(accountManager, config, gatewayManager));
|
|
4584
|
+
const integrationFactory = readResolvedFactory(integrationRouteFactoryPromise);
|
|
4585
|
+
if (integrationFactory) {
|
|
4586
|
+
app2.use("/api/agenticmail", integrationFactory());
|
|
4587
|
+
}
|
|
4521
4588
|
app2.use("/api/agenticmail", createAuthMiddleware(config.masterKey, accountManager, db));
|
|
4522
4589
|
app2.use("/api/agenticmail", createAccountRoutes(accountManager, db, config));
|
|
4523
4590
|
app2.use("/api/agenticmail", createMailRoutes(accountManager, config, db, gatewayManager));
|
|
@@ -4540,6 +4607,7 @@ function createApp(configOverrides) {
|
|
|
4540
4607
|
import { readFileSync as readFileSync2 } from "fs";
|
|
4541
4608
|
import { fileURLToPath as fileURLToPath2 } from "url";
|
|
4542
4609
|
import { dirname as dirname2, join as join2 } from "path";
|
|
4610
|
+
await prepareIntegrations();
|
|
4543
4611
|
function getLocalIp() {
|
|
4544
4612
|
const nets = networkInterfaces();
|
|
4545
4613
|
for (const iface of Object.values(nets)) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@agenticmail/api",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.6.0",
|
|
4
4
|
"description": "REST API server for AgenticMail — email and SMS endpoints for AI agents",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "dist/index.js",
|
|
@@ -19,7 +19,7 @@
|
|
|
19
19
|
"LICENSE"
|
|
20
20
|
],
|
|
21
21
|
"scripts": {
|
|
22
|
-
"build": "tsup src/index.ts --format esm --dts --clean",
|
|
22
|
+
"build": "tsup src/index.ts --format esm --dts --clean --external @agenticmail/claudecode",
|
|
23
23
|
"dev": "tsx watch src/index.ts",
|
|
24
24
|
"start": "node dist/index.js",
|
|
25
25
|
"test": "vitest run --passWithNoTests",
|
|
@@ -34,6 +34,9 @@
|
|
|
34
34
|
"express-rate-limit": "^7.5.0",
|
|
35
35
|
"uuid": "^11.1.0"
|
|
36
36
|
},
|
|
37
|
+
"optionalDependencies": {
|
|
38
|
+
"@agenticmail/claudecode": "^0.1.0"
|
|
39
|
+
},
|
|
37
40
|
"devDependencies": {
|
|
38
41
|
"@types/cors": "^2.8.17",
|
|
39
42
|
"@types/express": "^5.0.0",
|