@agenticmail/core 0.6.1 → 0.7.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.cjs +24 -12
- package/dist/index.d.cts +52 -12
- package/dist/index.d.ts +52 -12
- package/dist/index.js +24 -12
- package/package.json +2 -4
package/dist/index.cjs
CHANGED
|
@@ -3190,15 +3190,15 @@ function buildInboundSecurityAdvisory(security, attachments) {
|
|
|
3190
3190
|
}
|
|
3191
3191
|
|
|
3192
3192
|
// src/storage/db.ts
|
|
3193
|
-
var
|
|
3193
|
+
var import_node_sqlite = require("sqlite");
|
|
3194
3194
|
var db = null;
|
|
3195
3195
|
function getDatabase(config) {
|
|
3196
3196
|
if (db) return db;
|
|
3197
3197
|
ensureDataDir(config);
|
|
3198
3198
|
const dbPath = `${config.dataDir}/agenticmail.db`;
|
|
3199
|
-
db = new
|
|
3200
|
-
db.
|
|
3201
|
-
db.
|
|
3199
|
+
db = new import_node_sqlite.DatabaseSync(dbPath);
|
|
3200
|
+
db.exec("PRAGMA journal_mode = WAL");
|
|
3201
|
+
db.exec("PRAGMA foreign_keys = ON");
|
|
3202
3202
|
runMigrations(db);
|
|
3203
3203
|
return db;
|
|
3204
3204
|
}
|
|
@@ -3208,6 +3208,19 @@ function closeDatabase() {
|
|
|
3208
3208
|
db = null;
|
|
3209
3209
|
}
|
|
3210
3210
|
}
|
|
3211
|
+
function runTransactionally(database, fn) {
|
|
3212
|
+
database.exec("BEGIN");
|
|
3213
|
+
try {
|
|
3214
|
+
fn();
|
|
3215
|
+
database.exec("COMMIT");
|
|
3216
|
+
} catch (err) {
|
|
3217
|
+
try {
|
|
3218
|
+
database.exec("ROLLBACK");
|
|
3219
|
+
} catch {
|
|
3220
|
+
}
|
|
3221
|
+
throw err;
|
|
3222
|
+
}
|
|
3223
|
+
}
|
|
3211
3224
|
var MIGRATIONS = {
|
|
3212
3225
|
"001_init.sql": `
|
|
3213
3226
|
CREATE TABLE IF NOT EXISTS agents (
|
|
@@ -3468,19 +3481,18 @@ function runMigrations(database) {
|
|
|
3468
3481
|
const applied = new Set(appliedStmt.all().map((r) => r.name));
|
|
3469
3482
|
const insertStmt = database.prepare("INSERT INTO _migrations (name) VALUES (?)");
|
|
3470
3483
|
const sortedMigrations = Object.entries(MIGRATIONS).sort(([a], [b]) => a.localeCompare(b));
|
|
3471
|
-
const runMigration = database.transaction((name, sql) => {
|
|
3472
|
-
database.exec(sql);
|
|
3473
|
-
insertStmt.run(name);
|
|
3474
|
-
});
|
|
3475
3484
|
for (const [name, sql] of sortedMigrations) {
|
|
3476
3485
|
if (applied.has(name)) continue;
|
|
3477
|
-
|
|
3486
|
+
runTransactionally(database, () => {
|
|
3487
|
+
database.exec(sql);
|
|
3488
|
+
insertStmt.run(name);
|
|
3489
|
+
});
|
|
3478
3490
|
}
|
|
3479
3491
|
}
|
|
3480
3492
|
function createTestDatabase() {
|
|
3481
|
-
const testDb = new
|
|
3482
|
-
testDb.
|
|
3483
|
-
testDb.
|
|
3493
|
+
const testDb = new import_node_sqlite.DatabaseSync(":memory:");
|
|
3494
|
+
testDb.exec("PRAGMA journal_mode = WAL");
|
|
3495
|
+
testDb.exec("PRAGMA foreign_keys = ON");
|
|
3484
3496
|
for (const sql of Object.values(MIGRATIONS)) {
|
|
3485
3497
|
testDb.exec(sql);
|
|
3486
3498
|
}
|
package/dist/index.d.cts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { EventEmitter } from 'node:events';
|
|
2
|
-
import
|
|
2
|
+
import { DatabaseSync } from 'node:sqlite';
|
|
3
3
|
import { ImapFlow } from 'imapflow';
|
|
4
4
|
|
|
5
5
|
interface SendMailOptions {
|
|
@@ -291,6 +291,50 @@ declare class StalwartAdmin {
|
|
|
291
291
|
}): Promise<void>;
|
|
292
292
|
}
|
|
293
293
|
|
|
294
|
+
/**
|
|
295
|
+
* SQLite storage layer for AgenticMail.
|
|
296
|
+
*
|
|
297
|
+
* Migrated from `better-sqlite3` to Node's built-in `node:sqlite` module
|
|
298
|
+
* (stable since Node 22). The migration eliminates native compilation
|
|
299
|
+
* entirely — `better-sqlite3` ships pre-built binaries per
|
|
300
|
+
* NODE_MODULE_VERSION and intermittently lags new Node releases (Node
|
|
301
|
+
* 25.5.0 was a real example: prebuilds missing, node-gyp fails on the
|
|
302
|
+
* fallback compile-from-source path, fresh `npm install -g
|
|
303
|
+
* @agenticmail/cli` fails for users on bleeding-edge Node). `node:sqlite`
|
|
304
|
+
* is part of Node itself, so by definition it always matches the
|
|
305
|
+
* runtime — no prebuilds, no gyp, no binding errors.
|
|
306
|
+
*
|
|
307
|
+
* # API shape differences this file accommodates
|
|
308
|
+
*
|
|
309
|
+
* - `new DatabaseSync(path)` instead of `new Database(path)`.
|
|
310
|
+
* - No `db.pragma(x)` — use `db.exec("PRAGMA " + x)`.
|
|
311
|
+
* - No `db.transaction(fn)` — wrap in BEGIN/COMMIT manually (see
|
|
312
|
+
* `runTransactionally` below). Migrations are the only transaction
|
|
313
|
+
* site in core right now; if more callers need transactions later
|
|
314
|
+
* they should reuse the same helper.
|
|
315
|
+
* - `stmt.run(...)` still returns `{ changes, lastInsertRowid }`.
|
|
316
|
+
* One subtle gotcha: `lastInsertRowid` is a `bigint` in node:sqlite
|
|
317
|
+
* where better-sqlite3 returned a `number`. Consumers that compare
|
|
318
|
+
* with `===` or pass it to `Number(...)` need to be aware, but no
|
|
319
|
+
* site inside AgenticMail today does that — all our rowids are
|
|
320
|
+
* opaque or string-typed.
|
|
321
|
+
* - The class type is `DatabaseSync`; we re-export it as `Database`
|
|
322
|
+
* so consumer files can keep saying `Database` instead of plumbing
|
|
323
|
+
* `DatabaseSync` through everywhere.
|
|
324
|
+
*/
|
|
325
|
+
|
|
326
|
+
/**
|
|
327
|
+
* Public type alias for the database instance. Consumers should
|
|
328
|
+
* `import { type Database } from '@agenticmail/core'` rather than
|
|
329
|
+
* importing from `node:sqlite` directly — this insulates them from any
|
|
330
|
+
* future swap (back to better-sqlite3, or to a remote driver) without
|
|
331
|
+
* a cascade of changes across the workspace.
|
|
332
|
+
*/
|
|
333
|
+
type Database = DatabaseSync;
|
|
334
|
+
declare function getDatabase(config: AgenticMailConfig): Database;
|
|
335
|
+
declare function closeDatabase(): void;
|
|
336
|
+
declare function createTestDatabase(): Database;
|
|
337
|
+
|
|
294
338
|
/** Predefined agent roles */
|
|
295
339
|
type AgentRole = 'secretary' | 'assistant' | 'researcher' | 'writer' | 'custom';
|
|
296
340
|
declare const AGENT_ROLES: readonly AgentRole[];
|
|
@@ -319,7 +363,7 @@ interface CreateAgentOptions {
|
|
|
319
363
|
declare class AccountManager {
|
|
320
364
|
private db;
|
|
321
365
|
private stalwart;
|
|
322
|
-
constructor(db: Database
|
|
366
|
+
constructor(db: Database, stalwart: StalwartAdmin);
|
|
323
367
|
create(options: CreateAgentOptions): Promise<Agent>;
|
|
324
368
|
getById(id: string): Promise<Agent | null>;
|
|
325
369
|
getByApiKey(apiKey: string): Promise<Agent | null>;
|
|
@@ -399,7 +443,7 @@ declare class AgentDeletionService {
|
|
|
399
443
|
private db;
|
|
400
444
|
private accountManager;
|
|
401
445
|
private config;
|
|
402
|
-
constructor(db: Database
|
|
446
|
+
constructor(db: Database, accountManager: AccountManager, config: AgenticMailConfig);
|
|
403
447
|
archiveAndDelete(agentId: string, options?: ArchiveAndDeleteOptions): Promise<DeletionReport>;
|
|
404
448
|
getReport(deletionId: string): DeletionReport | null;
|
|
405
449
|
listReports(): DeletionSummary[];
|
|
@@ -615,10 +659,6 @@ declare function buildInboundSecurityAdvisory(security: {
|
|
|
615
659
|
size?: number;
|
|
616
660
|
}> | undefined): SecurityAdvisory;
|
|
617
661
|
|
|
618
|
-
declare function getDatabase(config: AgenticMailConfig): Database.Database;
|
|
619
|
-
declare function closeDatabase(): void;
|
|
620
|
-
declare function createTestDatabase(): Database.Database;
|
|
621
|
-
|
|
622
662
|
interface SearchableEmail {
|
|
623
663
|
agentId: string;
|
|
624
664
|
messageId: string;
|
|
@@ -630,7 +670,7 @@ interface SearchableEmail {
|
|
|
630
670
|
}
|
|
631
671
|
declare class EmailSearchIndex {
|
|
632
672
|
private db;
|
|
633
|
-
constructor(db: Database
|
|
673
|
+
constructor(db: Database);
|
|
634
674
|
index(email: SearchableEmail): void;
|
|
635
675
|
search(agentId: string, query: string, limit?: number): SearchableEmail[];
|
|
636
676
|
deleteByAgent(agentId: string): void;
|
|
@@ -658,7 +698,7 @@ interface DomainSetupResult {
|
|
|
658
698
|
declare class DomainManager {
|
|
659
699
|
private db;
|
|
660
700
|
private stalwart;
|
|
661
|
-
constructor(db: Database
|
|
701
|
+
constructor(db: Database, stalwart: StalwartAdmin);
|
|
662
702
|
setup(domain: string): Promise<DomainSetupResult>;
|
|
663
703
|
private generateDnsRecords;
|
|
664
704
|
get(domain: string): Promise<DomainInfo | null>;
|
|
@@ -1097,7 +1137,7 @@ interface LocalSmtpConfig {
|
|
|
1097
1137
|
pass: string;
|
|
1098
1138
|
}
|
|
1099
1139
|
interface GatewayManagerOptions {
|
|
1100
|
-
db: Database
|
|
1140
|
+
db: Database;
|
|
1101
1141
|
stalwart: StalwartAdmin;
|
|
1102
1142
|
accountManager?: AccountManager;
|
|
1103
1143
|
localSmtp?: LocalSmtpConfig;
|
|
@@ -1367,7 +1407,7 @@ declare function extractVerificationCode(smsBody: string): string | null;
|
|
|
1367
1407
|
declare class SmsManager {
|
|
1368
1408
|
private db;
|
|
1369
1409
|
private initialized;
|
|
1370
|
-
constructor(db: Database
|
|
1410
|
+
constructor(db: Database);
|
|
1371
1411
|
private ensureTable;
|
|
1372
1412
|
/** Get SMS config from agent metadata */
|
|
1373
1413
|
getSmsConfig(agentId: string): SmsConfig | null;
|
|
@@ -1753,4 +1793,4 @@ declare class SetupManager {
|
|
|
1753
1793
|
isInitialized(): boolean;
|
|
1754
1794
|
}
|
|
1755
1795
|
|
|
1756
|
-
export { AGENT_ROLES, AccountManager, type AddressInfo, type Agent, AgentDeletionService, type AgentRole, AgenticMailClient, type AgenticMailClientOptions, type AgenticMailConfig, type ArchiveAndDeleteOptions, type ArchivedEmail, type Attachment, type AttachmentAdvisory, CloudflareClient, type CreateAgentOptions, DEFAULT_AGENT_NAME, DEFAULT_AGENT_ROLE, DNSConfigurator, type DeletionReport, type DeletionSummary, DependencyChecker, DependencyInstaller, type DependencyStatus, type DnsRecord, type DnsSetupResult, type DomainInfo, DomainManager, type DomainModeConfig, type DomainPurchaseResult, DomainPurchaser, type DomainSearchResult, type DomainSetupResult, type EmailEnvelope, type EmailRouteAction, type EmailRouteClass, type EmailRouteClassification, type EmailRouteInput, EmailSearchIndex, type FolderInfo, type GatewayConfig, GatewayManager, type GatewayManagerOptions, type GatewayMode, type GatewayStatus, type InboundEmail, type InboxEvent, type InboxExpungeEvent, type InboxFlagsEvent, type InboxNewEvent, InboxWatcher, type InboxWatcherOptions, type InstallProgress, type LinkAdvisory, type LocalSmtpConfig, MailReceiver, type MailReceiverOptions, MailSender, type MailSenderOptions, type MailboxInfo, type OutboundCategory, type OutboundScanInput, type OutboundScanResult, type OutboundWarning, type ParsedAttachment, type ParsedEmail, type ParsedSms, type PurchasedDomain, RELAY_PRESETS, RelayBridge, type RelayBridgeOptions, type RelayConfig, RelayGateway, type RelayProvider, type RelaySearchResult, SPAM_THRESHOLD, type SanitizeDetection, type SanitizeResult, type SearchCriteria, type SearchableEmail, type SecurityAdvisory, type SendMailOptions, type SendResult, type SendResultWithRaw, ServiceManager, type ServiceStatus, type SetupConfig, SetupManager, type SetupResult, type Severity, type SmsConfig, SmsManager, type SmsMessage, SmsPoller, type SpamCategory, type SpamResult, type SpamRuleMatch, StalwartAdmin, type StalwartAdminOptions, type StalwartPrincipal, type TunnelConfig, TunnelManager, WARNING_THRESHOLD, type WatcherOptions, buildInboundSecurityAdvisory, classifyEmailRoute, closeDatabase, createTestDatabase, debug, debugWarn, ensureDataDir, extractVerificationCode, flushTelemetry, getDatabase, isInternalEmail, isValidPhoneNumber, normalizePhoneNumber, parseEmail, parseGoogleVoiceSms, recordToolCall, resolveConfig, sanitizeEmail, saveConfig, scanOutboundEmail, scoreEmail, setTelemetryVersion, startRelayBridge };
|
|
1796
|
+
export { AGENT_ROLES, AccountManager, type AddressInfo, type Agent, AgentDeletionService, type AgentRole, AgenticMailClient, type AgenticMailClientOptions, type AgenticMailConfig, type ArchiveAndDeleteOptions, type ArchivedEmail, type Attachment, type AttachmentAdvisory, CloudflareClient, type CreateAgentOptions, DEFAULT_AGENT_NAME, DEFAULT_AGENT_ROLE, DNSConfigurator, type Database, type DeletionReport, type DeletionSummary, DependencyChecker, DependencyInstaller, type DependencyStatus, type DnsRecord, type DnsSetupResult, type DomainInfo, DomainManager, type DomainModeConfig, type DomainPurchaseResult, DomainPurchaser, type DomainSearchResult, type DomainSetupResult, type EmailEnvelope, type EmailRouteAction, type EmailRouteClass, type EmailRouteClassification, type EmailRouteInput, EmailSearchIndex, type FolderInfo, type GatewayConfig, GatewayManager, type GatewayManagerOptions, type GatewayMode, type GatewayStatus, type InboundEmail, type InboxEvent, type InboxExpungeEvent, type InboxFlagsEvent, type InboxNewEvent, InboxWatcher, type InboxWatcherOptions, type InstallProgress, type LinkAdvisory, type LocalSmtpConfig, MailReceiver, type MailReceiverOptions, MailSender, type MailSenderOptions, type MailboxInfo, type OutboundCategory, type OutboundScanInput, type OutboundScanResult, type OutboundWarning, type ParsedAttachment, type ParsedEmail, type ParsedSms, type PurchasedDomain, RELAY_PRESETS, RelayBridge, type RelayBridgeOptions, type RelayConfig, RelayGateway, type RelayProvider, type RelaySearchResult, SPAM_THRESHOLD, type SanitizeDetection, type SanitizeResult, type SearchCriteria, type SearchableEmail, type SecurityAdvisory, type SendMailOptions, type SendResult, type SendResultWithRaw, ServiceManager, type ServiceStatus, type SetupConfig, SetupManager, type SetupResult, type Severity, type SmsConfig, SmsManager, type SmsMessage, SmsPoller, type SpamCategory, type SpamResult, type SpamRuleMatch, StalwartAdmin, type StalwartAdminOptions, type StalwartPrincipal, type TunnelConfig, TunnelManager, WARNING_THRESHOLD, type WatcherOptions, buildInboundSecurityAdvisory, classifyEmailRoute, closeDatabase, createTestDatabase, debug, debugWarn, ensureDataDir, extractVerificationCode, flushTelemetry, getDatabase, isInternalEmail, isValidPhoneNumber, normalizePhoneNumber, parseEmail, parseGoogleVoiceSms, recordToolCall, resolveConfig, sanitizeEmail, saveConfig, scanOutboundEmail, scoreEmail, setTelemetryVersion, startRelayBridge };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { EventEmitter } from 'node:events';
|
|
2
|
-
import
|
|
2
|
+
import { DatabaseSync } from 'node:sqlite';
|
|
3
3
|
import { ImapFlow } from 'imapflow';
|
|
4
4
|
|
|
5
5
|
interface SendMailOptions {
|
|
@@ -291,6 +291,50 @@ declare class StalwartAdmin {
|
|
|
291
291
|
}): Promise<void>;
|
|
292
292
|
}
|
|
293
293
|
|
|
294
|
+
/**
|
|
295
|
+
* SQLite storage layer for AgenticMail.
|
|
296
|
+
*
|
|
297
|
+
* Migrated from `better-sqlite3` to Node's built-in `node:sqlite` module
|
|
298
|
+
* (stable since Node 22). The migration eliminates native compilation
|
|
299
|
+
* entirely — `better-sqlite3` ships pre-built binaries per
|
|
300
|
+
* NODE_MODULE_VERSION and intermittently lags new Node releases (Node
|
|
301
|
+
* 25.5.0 was a real example: prebuilds missing, node-gyp fails on the
|
|
302
|
+
* fallback compile-from-source path, fresh `npm install -g
|
|
303
|
+
* @agenticmail/cli` fails for users on bleeding-edge Node). `node:sqlite`
|
|
304
|
+
* is part of Node itself, so by definition it always matches the
|
|
305
|
+
* runtime — no prebuilds, no gyp, no binding errors.
|
|
306
|
+
*
|
|
307
|
+
* # API shape differences this file accommodates
|
|
308
|
+
*
|
|
309
|
+
* - `new DatabaseSync(path)` instead of `new Database(path)`.
|
|
310
|
+
* - No `db.pragma(x)` — use `db.exec("PRAGMA " + x)`.
|
|
311
|
+
* - No `db.transaction(fn)` — wrap in BEGIN/COMMIT manually (see
|
|
312
|
+
* `runTransactionally` below). Migrations are the only transaction
|
|
313
|
+
* site in core right now; if more callers need transactions later
|
|
314
|
+
* they should reuse the same helper.
|
|
315
|
+
* - `stmt.run(...)` still returns `{ changes, lastInsertRowid }`.
|
|
316
|
+
* One subtle gotcha: `lastInsertRowid` is a `bigint` in node:sqlite
|
|
317
|
+
* where better-sqlite3 returned a `number`. Consumers that compare
|
|
318
|
+
* with `===` or pass it to `Number(...)` need to be aware, but no
|
|
319
|
+
* site inside AgenticMail today does that — all our rowids are
|
|
320
|
+
* opaque or string-typed.
|
|
321
|
+
* - The class type is `DatabaseSync`; we re-export it as `Database`
|
|
322
|
+
* so consumer files can keep saying `Database` instead of plumbing
|
|
323
|
+
* `DatabaseSync` through everywhere.
|
|
324
|
+
*/
|
|
325
|
+
|
|
326
|
+
/**
|
|
327
|
+
* Public type alias for the database instance. Consumers should
|
|
328
|
+
* `import { type Database } from '@agenticmail/core'` rather than
|
|
329
|
+
* importing from `node:sqlite` directly — this insulates them from any
|
|
330
|
+
* future swap (back to better-sqlite3, or to a remote driver) without
|
|
331
|
+
* a cascade of changes across the workspace.
|
|
332
|
+
*/
|
|
333
|
+
type Database = DatabaseSync;
|
|
334
|
+
declare function getDatabase(config: AgenticMailConfig): Database;
|
|
335
|
+
declare function closeDatabase(): void;
|
|
336
|
+
declare function createTestDatabase(): Database;
|
|
337
|
+
|
|
294
338
|
/** Predefined agent roles */
|
|
295
339
|
type AgentRole = 'secretary' | 'assistant' | 'researcher' | 'writer' | 'custom';
|
|
296
340
|
declare const AGENT_ROLES: readonly AgentRole[];
|
|
@@ -319,7 +363,7 @@ interface CreateAgentOptions {
|
|
|
319
363
|
declare class AccountManager {
|
|
320
364
|
private db;
|
|
321
365
|
private stalwart;
|
|
322
|
-
constructor(db: Database
|
|
366
|
+
constructor(db: Database, stalwart: StalwartAdmin);
|
|
323
367
|
create(options: CreateAgentOptions): Promise<Agent>;
|
|
324
368
|
getById(id: string): Promise<Agent | null>;
|
|
325
369
|
getByApiKey(apiKey: string): Promise<Agent | null>;
|
|
@@ -399,7 +443,7 @@ declare class AgentDeletionService {
|
|
|
399
443
|
private db;
|
|
400
444
|
private accountManager;
|
|
401
445
|
private config;
|
|
402
|
-
constructor(db: Database
|
|
446
|
+
constructor(db: Database, accountManager: AccountManager, config: AgenticMailConfig);
|
|
403
447
|
archiveAndDelete(agentId: string, options?: ArchiveAndDeleteOptions): Promise<DeletionReport>;
|
|
404
448
|
getReport(deletionId: string): DeletionReport | null;
|
|
405
449
|
listReports(): DeletionSummary[];
|
|
@@ -615,10 +659,6 @@ declare function buildInboundSecurityAdvisory(security: {
|
|
|
615
659
|
size?: number;
|
|
616
660
|
}> | undefined): SecurityAdvisory;
|
|
617
661
|
|
|
618
|
-
declare function getDatabase(config: AgenticMailConfig): Database.Database;
|
|
619
|
-
declare function closeDatabase(): void;
|
|
620
|
-
declare function createTestDatabase(): Database.Database;
|
|
621
|
-
|
|
622
662
|
interface SearchableEmail {
|
|
623
663
|
agentId: string;
|
|
624
664
|
messageId: string;
|
|
@@ -630,7 +670,7 @@ interface SearchableEmail {
|
|
|
630
670
|
}
|
|
631
671
|
declare class EmailSearchIndex {
|
|
632
672
|
private db;
|
|
633
|
-
constructor(db: Database
|
|
673
|
+
constructor(db: Database);
|
|
634
674
|
index(email: SearchableEmail): void;
|
|
635
675
|
search(agentId: string, query: string, limit?: number): SearchableEmail[];
|
|
636
676
|
deleteByAgent(agentId: string): void;
|
|
@@ -658,7 +698,7 @@ interface DomainSetupResult {
|
|
|
658
698
|
declare class DomainManager {
|
|
659
699
|
private db;
|
|
660
700
|
private stalwart;
|
|
661
|
-
constructor(db: Database
|
|
701
|
+
constructor(db: Database, stalwart: StalwartAdmin);
|
|
662
702
|
setup(domain: string): Promise<DomainSetupResult>;
|
|
663
703
|
private generateDnsRecords;
|
|
664
704
|
get(domain: string): Promise<DomainInfo | null>;
|
|
@@ -1097,7 +1137,7 @@ interface LocalSmtpConfig {
|
|
|
1097
1137
|
pass: string;
|
|
1098
1138
|
}
|
|
1099
1139
|
interface GatewayManagerOptions {
|
|
1100
|
-
db: Database
|
|
1140
|
+
db: Database;
|
|
1101
1141
|
stalwart: StalwartAdmin;
|
|
1102
1142
|
accountManager?: AccountManager;
|
|
1103
1143
|
localSmtp?: LocalSmtpConfig;
|
|
@@ -1367,7 +1407,7 @@ declare function extractVerificationCode(smsBody: string): string | null;
|
|
|
1367
1407
|
declare class SmsManager {
|
|
1368
1408
|
private db;
|
|
1369
1409
|
private initialized;
|
|
1370
|
-
constructor(db: Database
|
|
1410
|
+
constructor(db: Database);
|
|
1371
1411
|
private ensureTable;
|
|
1372
1412
|
/** Get SMS config from agent metadata */
|
|
1373
1413
|
getSmsConfig(agentId: string): SmsConfig | null;
|
|
@@ -1753,4 +1793,4 @@ declare class SetupManager {
|
|
|
1753
1793
|
isInitialized(): boolean;
|
|
1754
1794
|
}
|
|
1755
1795
|
|
|
1756
|
-
export { AGENT_ROLES, AccountManager, type AddressInfo, type Agent, AgentDeletionService, type AgentRole, AgenticMailClient, type AgenticMailClientOptions, type AgenticMailConfig, type ArchiveAndDeleteOptions, type ArchivedEmail, type Attachment, type AttachmentAdvisory, CloudflareClient, type CreateAgentOptions, DEFAULT_AGENT_NAME, DEFAULT_AGENT_ROLE, DNSConfigurator, type DeletionReport, type DeletionSummary, DependencyChecker, DependencyInstaller, type DependencyStatus, type DnsRecord, type DnsSetupResult, type DomainInfo, DomainManager, type DomainModeConfig, type DomainPurchaseResult, DomainPurchaser, type DomainSearchResult, type DomainSetupResult, type EmailEnvelope, type EmailRouteAction, type EmailRouteClass, type EmailRouteClassification, type EmailRouteInput, EmailSearchIndex, type FolderInfo, type GatewayConfig, GatewayManager, type GatewayManagerOptions, type GatewayMode, type GatewayStatus, type InboundEmail, type InboxEvent, type InboxExpungeEvent, type InboxFlagsEvent, type InboxNewEvent, InboxWatcher, type InboxWatcherOptions, type InstallProgress, type LinkAdvisory, type LocalSmtpConfig, MailReceiver, type MailReceiverOptions, MailSender, type MailSenderOptions, type MailboxInfo, type OutboundCategory, type OutboundScanInput, type OutboundScanResult, type OutboundWarning, type ParsedAttachment, type ParsedEmail, type ParsedSms, type PurchasedDomain, RELAY_PRESETS, RelayBridge, type RelayBridgeOptions, type RelayConfig, RelayGateway, type RelayProvider, type RelaySearchResult, SPAM_THRESHOLD, type SanitizeDetection, type SanitizeResult, type SearchCriteria, type SearchableEmail, type SecurityAdvisory, type SendMailOptions, type SendResult, type SendResultWithRaw, ServiceManager, type ServiceStatus, type SetupConfig, SetupManager, type SetupResult, type Severity, type SmsConfig, SmsManager, type SmsMessage, SmsPoller, type SpamCategory, type SpamResult, type SpamRuleMatch, StalwartAdmin, type StalwartAdminOptions, type StalwartPrincipal, type TunnelConfig, TunnelManager, WARNING_THRESHOLD, type WatcherOptions, buildInboundSecurityAdvisory, classifyEmailRoute, closeDatabase, createTestDatabase, debug, debugWarn, ensureDataDir, extractVerificationCode, flushTelemetry, getDatabase, isInternalEmail, isValidPhoneNumber, normalizePhoneNumber, parseEmail, parseGoogleVoiceSms, recordToolCall, resolveConfig, sanitizeEmail, saveConfig, scanOutboundEmail, scoreEmail, setTelemetryVersion, startRelayBridge };
|
|
1796
|
+
export { AGENT_ROLES, AccountManager, type AddressInfo, type Agent, AgentDeletionService, type AgentRole, AgenticMailClient, type AgenticMailClientOptions, type AgenticMailConfig, type ArchiveAndDeleteOptions, type ArchivedEmail, type Attachment, type AttachmentAdvisory, CloudflareClient, type CreateAgentOptions, DEFAULT_AGENT_NAME, DEFAULT_AGENT_ROLE, DNSConfigurator, type Database, type DeletionReport, type DeletionSummary, DependencyChecker, DependencyInstaller, type DependencyStatus, type DnsRecord, type DnsSetupResult, type DomainInfo, DomainManager, type DomainModeConfig, type DomainPurchaseResult, DomainPurchaser, type DomainSearchResult, type DomainSetupResult, type EmailEnvelope, type EmailRouteAction, type EmailRouteClass, type EmailRouteClassification, type EmailRouteInput, EmailSearchIndex, type FolderInfo, type GatewayConfig, GatewayManager, type GatewayManagerOptions, type GatewayMode, type GatewayStatus, type InboundEmail, type InboxEvent, type InboxExpungeEvent, type InboxFlagsEvent, type InboxNewEvent, InboxWatcher, type InboxWatcherOptions, type InstallProgress, type LinkAdvisory, type LocalSmtpConfig, MailReceiver, type MailReceiverOptions, MailSender, type MailSenderOptions, type MailboxInfo, type OutboundCategory, type OutboundScanInput, type OutboundScanResult, type OutboundWarning, type ParsedAttachment, type ParsedEmail, type ParsedSms, type PurchasedDomain, RELAY_PRESETS, RelayBridge, type RelayBridgeOptions, type RelayConfig, RelayGateway, type RelayProvider, type RelaySearchResult, SPAM_THRESHOLD, type SanitizeDetection, type SanitizeResult, type SearchCriteria, type SearchableEmail, type SecurityAdvisory, type SendMailOptions, type SendResult, type SendResultWithRaw, ServiceManager, type ServiceStatus, type SetupConfig, SetupManager, type SetupResult, type Severity, type SmsConfig, SmsManager, type SmsMessage, SmsPoller, type SpamCategory, type SpamResult, type SpamRuleMatch, StalwartAdmin, type StalwartAdminOptions, type StalwartPrincipal, type TunnelConfig, TunnelManager, WARNING_THRESHOLD, type WatcherOptions, buildInboundSecurityAdvisory, classifyEmailRoute, closeDatabase, createTestDatabase, debug, debugWarn, ensureDataDir, extractVerificationCode, flushTelemetry, getDatabase, isInternalEmail, isValidPhoneNumber, normalizePhoneNumber, parseEmail, parseGoogleVoiceSms, recordToolCall, resolveConfig, sanitizeEmail, saveConfig, scanOutboundEmail, scoreEmail, setTelemetryVersion, startRelayBridge };
|
package/dist/index.js
CHANGED
|
@@ -2433,15 +2433,15 @@ function buildInboundSecurityAdvisory(security, attachments) {
|
|
|
2433
2433
|
}
|
|
2434
2434
|
|
|
2435
2435
|
// src/storage/db.ts
|
|
2436
|
-
import
|
|
2436
|
+
import { DatabaseSync } from "sqlite";
|
|
2437
2437
|
var db = null;
|
|
2438
2438
|
function getDatabase(config) {
|
|
2439
2439
|
if (db) return db;
|
|
2440
2440
|
ensureDataDir(config);
|
|
2441
2441
|
const dbPath = `${config.dataDir}/agenticmail.db`;
|
|
2442
|
-
db = new
|
|
2443
|
-
db.
|
|
2444
|
-
db.
|
|
2442
|
+
db = new DatabaseSync(dbPath);
|
|
2443
|
+
db.exec("PRAGMA journal_mode = WAL");
|
|
2444
|
+
db.exec("PRAGMA foreign_keys = ON");
|
|
2445
2445
|
runMigrations(db);
|
|
2446
2446
|
return db;
|
|
2447
2447
|
}
|
|
@@ -2451,6 +2451,19 @@ function closeDatabase() {
|
|
|
2451
2451
|
db = null;
|
|
2452
2452
|
}
|
|
2453
2453
|
}
|
|
2454
|
+
function runTransactionally(database, fn) {
|
|
2455
|
+
database.exec("BEGIN");
|
|
2456
|
+
try {
|
|
2457
|
+
fn();
|
|
2458
|
+
database.exec("COMMIT");
|
|
2459
|
+
} catch (err) {
|
|
2460
|
+
try {
|
|
2461
|
+
database.exec("ROLLBACK");
|
|
2462
|
+
} catch {
|
|
2463
|
+
}
|
|
2464
|
+
throw err;
|
|
2465
|
+
}
|
|
2466
|
+
}
|
|
2454
2467
|
var MIGRATIONS = {
|
|
2455
2468
|
"001_init.sql": `
|
|
2456
2469
|
CREATE TABLE IF NOT EXISTS agents (
|
|
@@ -2711,19 +2724,18 @@ function runMigrations(database) {
|
|
|
2711
2724
|
const applied = new Set(appliedStmt.all().map((r) => r.name));
|
|
2712
2725
|
const insertStmt = database.prepare("INSERT INTO _migrations (name) VALUES (?)");
|
|
2713
2726
|
const sortedMigrations = Object.entries(MIGRATIONS).sort(([a], [b]) => a.localeCompare(b));
|
|
2714
|
-
const runMigration = database.transaction((name, sql) => {
|
|
2715
|
-
database.exec(sql);
|
|
2716
|
-
insertStmt.run(name);
|
|
2717
|
-
});
|
|
2718
2727
|
for (const [name, sql] of sortedMigrations) {
|
|
2719
2728
|
if (applied.has(name)) continue;
|
|
2720
|
-
|
|
2729
|
+
runTransactionally(database, () => {
|
|
2730
|
+
database.exec(sql);
|
|
2731
|
+
insertStmt.run(name);
|
|
2732
|
+
});
|
|
2721
2733
|
}
|
|
2722
2734
|
}
|
|
2723
2735
|
function createTestDatabase() {
|
|
2724
|
-
const testDb = new
|
|
2725
|
-
testDb.
|
|
2726
|
-
testDb.
|
|
2736
|
+
const testDb = new DatabaseSync(":memory:");
|
|
2737
|
+
testDb.exec("PRAGMA journal_mode = WAL");
|
|
2738
|
+
testDb.exec("PRAGMA foreign_keys = ON");
|
|
2727
2739
|
for (const sql of Object.values(MIGRATIONS)) {
|
|
2728
2740
|
testDb.exec(sql);
|
|
2729
2741
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@agenticmail/core",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.7.0",
|
|
4
4
|
"description": "Core SDK for AgenticMail — email, SMS, and phone number access for AI agents",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "dist/index.js",
|
|
@@ -27,14 +27,12 @@
|
|
|
27
27
|
"prepublishOnly": "npm run build"
|
|
28
28
|
},
|
|
29
29
|
"dependencies": {
|
|
30
|
-
"better-sqlite3": "^11.8.0",
|
|
31
30
|
"imapflow": "^1.0.170",
|
|
32
31
|
"mailparser": "^3.7.2",
|
|
33
32
|
"nodemailer": "^8.0.1",
|
|
34
33
|
"uuid": "^11.1.0"
|
|
35
34
|
},
|
|
36
35
|
"devDependencies": {
|
|
37
|
-
"@types/better-sqlite3": "^7.6.13",
|
|
38
36
|
"@types/mailparser": "^3.4.6",
|
|
39
37
|
"@types/nodemailer": "^6.4.17",
|
|
40
38
|
"@types/uuid": "^10.0.0",
|
|
@@ -43,7 +41,7 @@
|
|
|
43
41
|
"vitest": "^3.0.0"
|
|
44
42
|
},
|
|
45
43
|
"engines": {
|
|
46
|
-
"node": ">=
|
|
44
|
+
"node": ">=22"
|
|
47
45
|
},
|
|
48
46
|
"repository": {
|
|
49
47
|
"type": "git",
|