@agenticmail/core 0.6.1 → 0.7.1

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 CHANGED
@@ -3190,15 +3190,18 @@ function buildInboundSecurityAdvisory(security, attachments) {
3190
3190
  }
3191
3191
 
3192
3192
  // src/storage/db.ts
3193
- var import_better_sqlite3 = __toESM(require("better-sqlite3"), 1);
3193
+ var import_node_module = require("module");
3194
+ var import_meta = {};
3195
+ var require2 = (0, import_node_module.createRequire)(import_meta.url);
3196
+ var { DatabaseSync } = require2("node:sqlite");
3194
3197
  var db = null;
3195
3198
  function getDatabase(config) {
3196
3199
  if (db) return db;
3197
3200
  ensureDataDir(config);
3198
3201
  const dbPath = `${config.dataDir}/agenticmail.db`;
3199
- db = new import_better_sqlite3.default(dbPath);
3200
- db.pragma("journal_mode = WAL");
3201
- db.pragma("foreign_keys = ON");
3202
+ db = new DatabaseSync(dbPath);
3203
+ db.exec("PRAGMA journal_mode = WAL");
3204
+ db.exec("PRAGMA foreign_keys = ON");
3202
3205
  runMigrations(db);
3203
3206
  return db;
3204
3207
  }
@@ -3208,6 +3211,19 @@ function closeDatabase() {
3208
3211
  db = null;
3209
3212
  }
3210
3213
  }
3214
+ function runTransactionally(database, fn) {
3215
+ database.exec("BEGIN");
3216
+ try {
3217
+ fn();
3218
+ database.exec("COMMIT");
3219
+ } catch (err) {
3220
+ try {
3221
+ database.exec("ROLLBACK");
3222
+ } catch {
3223
+ }
3224
+ throw err;
3225
+ }
3226
+ }
3211
3227
  var MIGRATIONS = {
3212
3228
  "001_init.sql": `
3213
3229
  CREATE TABLE IF NOT EXISTS agents (
@@ -3468,19 +3484,18 @@ function runMigrations(database) {
3468
3484
  const applied = new Set(appliedStmt.all().map((r) => r.name));
3469
3485
  const insertStmt = database.prepare("INSERT INTO _migrations (name) VALUES (?)");
3470
3486
  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
3487
  for (const [name, sql] of sortedMigrations) {
3476
3488
  if (applied.has(name)) continue;
3477
- runMigration(name, sql);
3489
+ runTransactionally(database, () => {
3490
+ database.exec(sql);
3491
+ insertStmt.run(name);
3492
+ });
3478
3493
  }
3479
3494
  }
3480
3495
  function createTestDatabase() {
3481
- const testDb = new import_better_sqlite3.default(":memory:");
3482
- testDb.pragma("journal_mode = WAL");
3483
- testDb.pragma("foreign_keys = ON");
3496
+ const testDb = new DatabaseSync(":memory:");
3497
+ testDb.exec("PRAGMA journal_mode = WAL");
3498
+ testDb.exec("PRAGMA foreign_keys = ON");
3484
3499
  for (const sql of Object.values(MIGRATIONS)) {
3485
3500
  testDb.exec(sql);
3486
3501
  }
@@ -7159,8 +7174,8 @@ var import_node_child_process4 = require("child_process");
7159
7174
  var import_node_fs6 = require("fs");
7160
7175
  var import_node_path7 = require("path");
7161
7176
  var import_node_os6 = require("os");
7162
- var import_node_module = require("module");
7163
- var import_meta = {};
7177
+ var import_node_module2 = require("module");
7178
+ var import_meta2 = {};
7164
7179
  var PLIST_LABEL = "com.agenticmail.server";
7165
7180
  var SYSTEMD_UNIT = "agenticmail.service";
7166
7181
  var ServiceManager = class {
@@ -7204,7 +7219,7 @@ var ServiceManager = class {
7204
7219
  */
7205
7220
  getApiEntryPath() {
7206
7221
  try {
7207
- const req = (0, import_node_module.createRequire)(import_meta.url);
7222
+ const req = (0, import_node_module2.createRequire)(import_meta2.url);
7208
7223
  const resolved = req.resolve("@agenticmail/api");
7209
7224
  if ((0, import_node_fs6.existsSync)(resolved)) return resolved;
7210
7225
  } catch {
@@ -7260,7 +7275,7 @@ var ServiceManager = class {
7260
7275
  */
7261
7276
  getVersion() {
7262
7277
  try {
7263
- const req = (0, import_node_module.createRequire)(import_meta.url);
7278
+ const req = (0, import_node_module2.createRequire)(import_meta2.url);
7264
7279
  const pkgJson = req.resolve("@agenticmail/cli/package.json");
7265
7280
  if ((0, import_node_fs6.existsSync)(pkgJson)) {
7266
7281
  const pkg = JSON.parse((0, import_node_fs6.readFileSync)(pkgJson, "utf-8"));
package/dist/index.d.cts CHANGED
@@ -1,5 +1,5 @@
1
1
  import { EventEmitter } from 'node:events';
2
- import Database, { Database as Database$1 } from 'better-sqlite3';
2
+ import * as node_sqlite from 'node:sqlite';
3
3
  import { ImapFlow } from 'imapflow';
4
4
 
5
5
  interface SendMailOptions {
@@ -291,6 +291,20 @@ declare class StalwartAdmin {
291
291
  }): Promise<void>;
292
292
  }
293
293
 
294
+ declare const DatabaseSync: typeof node_sqlite.DatabaseSync;
295
+ type DatabaseSync = InstanceType<typeof node_sqlite.DatabaseSync>;
296
+ /**
297
+ * Public type alias for the database instance. Consumers should
298
+ * `import { type Database } from '@agenticmail/core'` rather than
299
+ * importing from `node:sqlite` directly — this insulates them from any
300
+ * future swap (back to better-sqlite3, or to a remote driver) without
301
+ * a cascade of changes across the workspace.
302
+ */
303
+ type Database = DatabaseSync;
304
+ declare function getDatabase(config: AgenticMailConfig): Database;
305
+ declare function closeDatabase(): void;
306
+ declare function createTestDatabase(): Database;
307
+
294
308
  /** Predefined agent roles */
295
309
  type AgentRole = 'secretary' | 'assistant' | 'researcher' | 'writer' | 'custom';
296
310
  declare const AGENT_ROLES: readonly AgentRole[];
@@ -319,7 +333,7 @@ interface CreateAgentOptions {
319
333
  declare class AccountManager {
320
334
  private db;
321
335
  private stalwart;
322
- constructor(db: Database.Database, stalwart: StalwartAdmin);
336
+ constructor(db: Database, stalwart: StalwartAdmin);
323
337
  create(options: CreateAgentOptions): Promise<Agent>;
324
338
  getById(id: string): Promise<Agent | null>;
325
339
  getByApiKey(apiKey: string): Promise<Agent | null>;
@@ -399,7 +413,7 @@ declare class AgentDeletionService {
399
413
  private db;
400
414
  private accountManager;
401
415
  private config;
402
- constructor(db: Database.Database, accountManager: AccountManager, config: AgenticMailConfig);
416
+ constructor(db: Database, accountManager: AccountManager, config: AgenticMailConfig);
403
417
  archiveAndDelete(agentId: string, options?: ArchiveAndDeleteOptions): Promise<DeletionReport>;
404
418
  getReport(deletionId: string): DeletionReport | null;
405
419
  listReports(): DeletionSummary[];
@@ -615,10 +629,6 @@ declare function buildInboundSecurityAdvisory(security: {
615
629
  size?: number;
616
630
  }> | undefined): SecurityAdvisory;
617
631
 
618
- declare function getDatabase(config: AgenticMailConfig): Database.Database;
619
- declare function closeDatabase(): void;
620
- declare function createTestDatabase(): Database.Database;
621
-
622
632
  interface SearchableEmail {
623
633
  agentId: string;
624
634
  messageId: string;
@@ -630,7 +640,7 @@ interface SearchableEmail {
630
640
  }
631
641
  declare class EmailSearchIndex {
632
642
  private db;
633
- constructor(db: Database.Database);
643
+ constructor(db: Database);
634
644
  index(email: SearchableEmail): void;
635
645
  search(agentId: string, query: string, limit?: number): SearchableEmail[];
636
646
  deleteByAgent(agentId: string): void;
@@ -658,7 +668,7 @@ interface DomainSetupResult {
658
668
  declare class DomainManager {
659
669
  private db;
660
670
  private stalwart;
661
- constructor(db: Database.Database, stalwart: StalwartAdmin);
671
+ constructor(db: Database, stalwart: StalwartAdmin);
662
672
  setup(domain: string): Promise<DomainSetupResult>;
663
673
  private generateDnsRecords;
664
674
  get(domain: string): Promise<DomainInfo | null>;
@@ -1097,7 +1107,7 @@ interface LocalSmtpConfig {
1097
1107
  pass: string;
1098
1108
  }
1099
1109
  interface GatewayManagerOptions {
1100
- db: Database.Database;
1110
+ db: Database;
1101
1111
  stalwart: StalwartAdmin;
1102
1112
  accountManager?: AccountManager;
1103
1113
  localSmtp?: LocalSmtpConfig;
@@ -1367,7 +1377,7 @@ declare function extractVerificationCode(smsBody: string): string | null;
1367
1377
  declare class SmsManager {
1368
1378
  private db;
1369
1379
  private initialized;
1370
- constructor(db: Database$1);
1380
+ constructor(db: Database);
1371
1381
  private ensureTable;
1372
1382
  /** Get SMS config from agent metadata */
1373
1383
  getSmsConfig(agentId: string): SmsConfig | null;
@@ -1753,4 +1763,4 @@ declare class SetupManager {
1753
1763
  isInitialized(): boolean;
1754
1764
  }
1755
1765
 
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 };
1766
+ 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 Database, { Database as Database$1 } from 'better-sqlite3';
2
+ import * as node_sqlite from 'node:sqlite';
3
3
  import { ImapFlow } from 'imapflow';
4
4
 
5
5
  interface SendMailOptions {
@@ -291,6 +291,20 @@ declare class StalwartAdmin {
291
291
  }): Promise<void>;
292
292
  }
293
293
 
294
+ declare const DatabaseSync: typeof node_sqlite.DatabaseSync;
295
+ type DatabaseSync = InstanceType<typeof node_sqlite.DatabaseSync>;
296
+ /**
297
+ * Public type alias for the database instance. Consumers should
298
+ * `import { type Database } from '@agenticmail/core'` rather than
299
+ * importing from `node:sqlite` directly — this insulates them from any
300
+ * future swap (back to better-sqlite3, or to a remote driver) without
301
+ * a cascade of changes across the workspace.
302
+ */
303
+ type Database = DatabaseSync;
304
+ declare function getDatabase(config: AgenticMailConfig): Database;
305
+ declare function closeDatabase(): void;
306
+ declare function createTestDatabase(): Database;
307
+
294
308
  /** Predefined agent roles */
295
309
  type AgentRole = 'secretary' | 'assistant' | 'researcher' | 'writer' | 'custom';
296
310
  declare const AGENT_ROLES: readonly AgentRole[];
@@ -319,7 +333,7 @@ interface CreateAgentOptions {
319
333
  declare class AccountManager {
320
334
  private db;
321
335
  private stalwart;
322
- constructor(db: Database.Database, stalwart: StalwartAdmin);
336
+ constructor(db: Database, stalwart: StalwartAdmin);
323
337
  create(options: CreateAgentOptions): Promise<Agent>;
324
338
  getById(id: string): Promise<Agent | null>;
325
339
  getByApiKey(apiKey: string): Promise<Agent | null>;
@@ -399,7 +413,7 @@ declare class AgentDeletionService {
399
413
  private db;
400
414
  private accountManager;
401
415
  private config;
402
- constructor(db: Database.Database, accountManager: AccountManager, config: AgenticMailConfig);
416
+ constructor(db: Database, accountManager: AccountManager, config: AgenticMailConfig);
403
417
  archiveAndDelete(agentId: string, options?: ArchiveAndDeleteOptions): Promise<DeletionReport>;
404
418
  getReport(deletionId: string): DeletionReport | null;
405
419
  listReports(): DeletionSummary[];
@@ -615,10 +629,6 @@ declare function buildInboundSecurityAdvisory(security: {
615
629
  size?: number;
616
630
  }> | undefined): SecurityAdvisory;
617
631
 
618
- declare function getDatabase(config: AgenticMailConfig): Database.Database;
619
- declare function closeDatabase(): void;
620
- declare function createTestDatabase(): Database.Database;
621
-
622
632
  interface SearchableEmail {
623
633
  agentId: string;
624
634
  messageId: string;
@@ -630,7 +640,7 @@ interface SearchableEmail {
630
640
  }
631
641
  declare class EmailSearchIndex {
632
642
  private db;
633
- constructor(db: Database.Database);
643
+ constructor(db: Database);
634
644
  index(email: SearchableEmail): void;
635
645
  search(agentId: string, query: string, limit?: number): SearchableEmail[];
636
646
  deleteByAgent(agentId: string): void;
@@ -658,7 +668,7 @@ interface DomainSetupResult {
658
668
  declare class DomainManager {
659
669
  private db;
660
670
  private stalwart;
661
- constructor(db: Database.Database, stalwart: StalwartAdmin);
671
+ constructor(db: Database, stalwart: StalwartAdmin);
662
672
  setup(domain: string): Promise<DomainSetupResult>;
663
673
  private generateDnsRecords;
664
674
  get(domain: string): Promise<DomainInfo | null>;
@@ -1097,7 +1107,7 @@ interface LocalSmtpConfig {
1097
1107
  pass: string;
1098
1108
  }
1099
1109
  interface GatewayManagerOptions {
1100
- db: Database.Database;
1110
+ db: Database;
1101
1111
  stalwart: StalwartAdmin;
1102
1112
  accountManager?: AccountManager;
1103
1113
  localSmtp?: LocalSmtpConfig;
@@ -1367,7 +1377,7 @@ declare function extractVerificationCode(smsBody: string): string | null;
1367
1377
  declare class SmsManager {
1368
1378
  private db;
1369
1379
  private initialized;
1370
- constructor(db: Database$1);
1380
+ constructor(db: Database);
1371
1381
  private ensureTable;
1372
1382
  /** Get SMS config from agent metadata */
1373
1383
  getSmsConfig(agentId: string): SmsConfig | null;
@@ -1753,4 +1763,4 @@ declare class SetupManager {
1753
1763
  isInitialized(): boolean;
1754
1764
  }
1755
1765
 
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 };
1766
+ 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,17 @@ function buildInboundSecurityAdvisory(security, attachments) {
2433
2433
  }
2434
2434
 
2435
2435
  // src/storage/db.ts
2436
- import Database from "better-sqlite3";
2436
+ import { createRequire } from "module";
2437
+ var require2 = createRequire(import.meta.url);
2438
+ var { DatabaseSync } = require2("node:sqlite");
2437
2439
  var db = null;
2438
2440
  function getDatabase(config) {
2439
2441
  if (db) return db;
2440
2442
  ensureDataDir(config);
2441
2443
  const dbPath = `${config.dataDir}/agenticmail.db`;
2442
- db = new Database(dbPath);
2443
- db.pragma("journal_mode = WAL");
2444
- db.pragma("foreign_keys = ON");
2444
+ db = new DatabaseSync(dbPath);
2445
+ db.exec("PRAGMA journal_mode = WAL");
2446
+ db.exec("PRAGMA foreign_keys = ON");
2445
2447
  runMigrations(db);
2446
2448
  return db;
2447
2449
  }
@@ -2451,6 +2453,19 @@ function closeDatabase() {
2451
2453
  db = null;
2452
2454
  }
2453
2455
  }
2456
+ function runTransactionally(database, fn) {
2457
+ database.exec("BEGIN");
2458
+ try {
2459
+ fn();
2460
+ database.exec("COMMIT");
2461
+ } catch (err) {
2462
+ try {
2463
+ database.exec("ROLLBACK");
2464
+ } catch {
2465
+ }
2466
+ throw err;
2467
+ }
2468
+ }
2454
2469
  var MIGRATIONS = {
2455
2470
  "001_init.sql": `
2456
2471
  CREATE TABLE IF NOT EXISTS agents (
@@ -2711,19 +2726,18 @@ function runMigrations(database) {
2711
2726
  const applied = new Set(appliedStmt.all().map((r) => r.name));
2712
2727
  const insertStmt = database.prepare("INSERT INTO _migrations (name) VALUES (?)");
2713
2728
  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
2729
  for (const [name, sql] of sortedMigrations) {
2719
2730
  if (applied.has(name)) continue;
2720
- runMigration(name, sql);
2731
+ runTransactionally(database, () => {
2732
+ database.exec(sql);
2733
+ insertStmt.run(name);
2734
+ });
2721
2735
  }
2722
2736
  }
2723
2737
  function createTestDatabase() {
2724
- const testDb = new Database(":memory:");
2725
- testDb.pragma("journal_mode = WAL");
2726
- testDb.pragma("foreign_keys = ON");
2738
+ const testDb = new DatabaseSync(":memory:");
2739
+ testDb.exec("PRAGMA journal_mode = WAL");
2740
+ testDb.exec("PRAGMA foreign_keys = ON");
2727
2741
  for (const sql of Object.values(MIGRATIONS)) {
2728
2742
  testDb.exec(sql);
2729
2743
  }
@@ -6401,7 +6415,7 @@ import { execFileSync as execFileSync3, execSync as execSync2 } from "child_proc
6401
6415
  import { existsSync as existsSync6, readFileSync as readFileSync3, writeFileSync as writeFileSync4, unlinkSync, mkdirSync as mkdirSync5, chmodSync } from "fs";
6402
6416
  import { join as join8 } from "path";
6403
6417
  import { homedir as homedir7, platform as platform4 } from "os";
6404
- import { createRequire } from "module";
6418
+ import { createRequire as createRequire2 } from "module";
6405
6419
  var PLIST_LABEL = "com.agenticmail.server";
6406
6420
  var SYSTEMD_UNIT = "agenticmail.service";
6407
6421
  var ServiceManager = class {
@@ -6445,7 +6459,7 @@ var ServiceManager = class {
6445
6459
  */
6446
6460
  getApiEntryPath() {
6447
6461
  try {
6448
- const req = createRequire(import.meta.url);
6462
+ const req = createRequire2(import.meta.url);
6449
6463
  const resolved = req.resolve("@agenticmail/api");
6450
6464
  if (existsSync6(resolved)) return resolved;
6451
6465
  } catch {
@@ -6501,7 +6515,7 @@ var ServiceManager = class {
6501
6515
  */
6502
6516
  getVersion() {
6503
6517
  try {
6504
- const req = createRequire(import.meta.url);
6518
+ const req = createRequire2(import.meta.url);
6505
6519
  const pkgJson = req.resolve("@agenticmail/cli/package.json");
6506
6520
  if (existsSync6(pkgJson)) {
6507
6521
  const pkg = JSON.parse(readFileSync3(pkgJson, "utf-8"));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@agenticmail/core",
3
- "version": "0.6.1",
3
+ "version": "0.7.1",
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",
@@ -20,21 +20,19 @@
20
20
  "LICENSE"
21
21
  ],
22
22
  "scripts": {
23
- "build": "tsup src/index.ts --format esm,cjs --dts --clean",
24
- "dev": "tsup src/index.ts --format esm,cjs --dts --watch",
23
+ "build": "tsup --config tsup.config.ts",
24
+ "dev": "tsup --config tsup.config.ts --watch",
25
25
  "test": "vitest run",
26
26
  "test:watch": "vitest",
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": ">=20"
44
+ "node": ">=22"
47
45
  },
48
46
  "repository": {
49
47
  "type": "git",