@agenticmail/enterprise 0.5.264 → 0.5.265

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.
@@ -0,0 +1,45 @@
1
+ import {
2
+ AgentRuntime,
3
+ EmailChannel,
4
+ FollowUpScheduler,
5
+ SessionManager,
6
+ SubAgentManager,
7
+ ToolRegistry,
8
+ callLLM,
9
+ createAgentRuntime,
10
+ createNoopHooks,
11
+ createRuntimeHooks,
12
+ estimateMessageTokens,
13
+ estimateTokens,
14
+ executeTool,
15
+ runAgentLoop,
16
+ toolsToDefinitions
17
+ } from "./chunk-G5GAUJXJ.js";
18
+ import {
19
+ PROVIDER_REGISTRY,
20
+ listAllProviders,
21
+ resolveApiKeyForProvider,
22
+ resolveProvider
23
+ } from "./chunk-UF3ZJMJO.js";
24
+ import "./chunk-KFQGP6VL.js";
25
+ export {
26
+ AgentRuntime,
27
+ EmailChannel,
28
+ FollowUpScheduler,
29
+ PROVIDER_REGISTRY,
30
+ SessionManager,
31
+ SubAgentManager,
32
+ ToolRegistry,
33
+ callLLM,
34
+ createAgentRuntime,
35
+ createNoopHooks,
36
+ createRuntimeHooks,
37
+ estimateMessageTokens,
38
+ estimateTokens,
39
+ executeTool,
40
+ listAllProviders,
41
+ resolveApiKeyForProvider,
42
+ resolveProvider,
43
+ runAgentLoop,
44
+ toolsToDefinitions
45
+ };
@@ -0,0 +1,15 @@
1
+ import {
2
+ createServer
3
+ } from "./chunk-LMB7DQL3.js";
4
+ import "./chunk-OF4MUWWS.js";
5
+ import "./chunk-UF3ZJMJO.js";
6
+ import "./chunk-3OC6RH7W.js";
7
+ import "./chunk-2DDKGTD6.js";
8
+ import "./chunk-YVK6F5OD.js";
9
+ import "./chunk-MKRNEM5A.js";
10
+ import "./chunk-DRXMYYKN.js";
11
+ import "./chunk-6WSX7QXF.js";
12
+ import "./chunk-KFQGP6VL.js";
13
+ export {
14
+ createServer
15
+ };
@@ -0,0 +1,20 @@
1
+ import {
2
+ promptCompanyInfo,
3
+ promptDatabase,
4
+ promptDeployment,
5
+ promptDomain,
6
+ promptRegistration,
7
+ provision,
8
+ runSetupWizard
9
+ } from "./chunk-ENUTKURJ.js";
10
+ import "./chunk-ULRBF2T7.js";
11
+ import "./chunk-KFQGP6VL.js";
12
+ export {
13
+ promptCompanyInfo,
14
+ promptDatabase,
15
+ promptDeployment,
16
+ promptDomain,
17
+ promptRegistration,
18
+ provision,
19
+ runSetupWizard
20
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@agenticmail/enterprise",
3
- "version": "0.5.264",
3
+ "version": "0.5.265",
4
4
  "description": "AgenticMail Enterprise — cloud-hosted AI agent identity, email, auth & compliance for organizations",
5
5
  "type": "module",
6
6
  "bin": {
@@ -82,7 +82,7 @@ export class DatabaseConnectionManager {
82
82
  private drivers = new Map<DatabaseType, DatabaseDriver>();
83
83
  private rateLimiter = new RateLimiter();
84
84
  private stats = new Map<string, { queries: number; errors: number; totalTimeMs: number; lastActivity: number }>();
85
- private engineDb?: { execute(sql: string, params?: any[]): Promise<any>; all?(sql: string, params?: any[]): Promise<any[]> };
85
+ private engineDb?: { run?(sql: string, params?: any[]): Promise<any>; execute?(sql: string, params?: any[]): Promise<any>; all?(sql: string, params?: any[]): Promise<any[]>; get?(sql: string, params?: any[]): Promise<any> };
86
86
  private vault?: {
87
87
  storeSecret(orgId: string, name: string, category: string, plaintext: string, metadata?: Record<string, any>): Promise<any>;
88
88
  getSecret(orgId: string, name: string, category: string): Promise<{ plaintext: string } | null>;
@@ -102,6 +102,29 @@ export class DatabaseConnectionManager {
102
102
  await this.init();
103
103
  }
104
104
 
105
+ /** Normalize DB execute — adapters may have run() or execute() */
106
+ private async dbRun(sql: string, params?: any[]): Promise<any> {
107
+ if (!this.engineDb) throw new Error('No database');
108
+ const fn = this.engineDb.run || this.engineDb.execute;
109
+ if (!fn) throw new Error('DB adapter has no run/execute method');
110
+ return fn.call(this.engineDb, sql, params);
111
+ }
112
+
113
+ private async dbAll(sql: string, params?: any[]): Promise<any[]> {
114
+ if (!this.engineDb) return [];
115
+ if (this.engineDb.all) return this.engineDb.all(sql, params) as Promise<any[]>;
116
+ // Fallback: execute returns rows for some adapters
117
+ const result = await this.dbRun(sql, params);
118
+ return Array.isArray(result) ? result : [];
119
+ }
120
+
121
+ private async dbGet(sql: string, params?: any[]): Promise<any> {
122
+ if (!this.engineDb) return null;
123
+ if (this.engineDb.get) return this.engineDb.get(sql, params);
124
+ const rows = await this.dbAll(sql, params);
125
+ return rows?.[0] || null;
126
+ }
127
+
105
128
  async init(): Promise<void> {
106
129
  await this.ensureTable();
107
130
  await this.loadConnections();
@@ -111,39 +134,46 @@ export class DatabaseConnectionManager {
111
134
 
112
135
  private async ensureTable(): Promise<void> {
113
136
  if (!this.engineDb) return;
137
+ // Detect dialect: if db has .dialect or if run/execute name hints at postgres
138
+ const isPostgres = (this.engineDb as any).dialect === 'postgres' || !!(this.engineDb as any).unsafe;
139
+ const now = isPostgres ? 'NOW()' : "(datetime('now'))";
140
+ const jsonType = isPostgres ? 'JSONB' : 'TEXT';
141
+ const boolType = isPostgres ? 'BOOLEAN' : 'INTEGER';
142
+ const boolFalse = isPostgres ? 'FALSE' : '0';
143
+ const boolTrue = isPostgres ? 'TRUE' : '1';
114
144
  try {
115
- await this.engineDb.execute(`
145
+ await this.dbRun(`
116
146
  CREATE TABLE IF NOT EXISTS database_connections (
117
147
  id TEXT PRIMARY KEY,
118
148
  org_id TEXT NOT NULL,
119
149
  name TEXT NOT NULL,
120
150
  type TEXT NOT NULL,
121
- config JSONB NOT NULL DEFAULT '{}',
151
+ config ${jsonType} NOT NULL DEFAULT '{}',
122
152
  status TEXT NOT NULL DEFAULT 'inactive',
123
153
  last_tested_at TEXT,
124
154
  last_error TEXT,
125
- created_at TEXT NOT NULL DEFAULT (datetime('now')),
126
- updated_at TEXT NOT NULL DEFAULT (datetime('now'))
155
+ created_at TEXT NOT NULL DEFAULT ${now},
156
+ updated_at TEXT NOT NULL DEFAULT ${now}
127
157
  )
128
158
  `);
129
- await this.engineDb.execute(`
159
+ await this.dbRun(`
130
160
  CREATE TABLE IF NOT EXISTS agent_database_access (
131
161
  id TEXT PRIMARY KEY,
132
162
  org_id TEXT NOT NULL,
133
163
  agent_id TEXT NOT NULL,
134
164
  connection_id TEXT NOT NULL REFERENCES database_connections(id) ON DELETE CASCADE,
135
165
  permissions TEXT NOT NULL DEFAULT '["read"]',
136
- query_limits JSONB,
137
- schema_access JSONB,
138
- log_all_queries INTEGER NOT NULL DEFAULT 0,
139
- require_approval INTEGER NOT NULL DEFAULT 0,
140
- enabled INTEGER NOT NULL DEFAULT 1,
141
- created_at TEXT NOT NULL DEFAULT (datetime('now')),
142
- updated_at TEXT NOT NULL DEFAULT (datetime('now')),
166
+ query_limits ${jsonType},
167
+ schema_access ${jsonType},
168
+ log_all_queries ${boolType} NOT NULL DEFAULT ${boolFalse},
169
+ require_approval ${boolType} NOT NULL DEFAULT ${boolFalse},
170
+ enabled ${boolType} NOT NULL DEFAULT ${boolTrue},
171
+ created_at TEXT NOT NULL DEFAULT ${now},
172
+ updated_at TEXT NOT NULL DEFAULT ${now},
143
173
  UNIQUE(agent_id, connection_id)
144
174
  )
145
175
  `);
146
- await this.engineDb.execute(`
176
+ await this.dbRun(`
147
177
  CREATE TABLE IF NOT EXISTS database_audit_log (
148
178
  id TEXT PRIMARY KEY,
149
179
  org_id TEXT NOT NULL,
@@ -156,14 +186,14 @@ export class DatabaseConnectionManager {
156
186
  param_count INTEGER NOT NULL DEFAULT 0,
157
187
  rows_affected INTEGER NOT NULL DEFAULT 0,
158
188
  execution_time_ms INTEGER NOT NULL DEFAULT 0,
159
- success INTEGER NOT NULL DEFAULT 1,
189
+ success ${boolType} NOT NULL DEFAULT ${boolTrue},
160
190
  error TEXT,
161
- timestamp TEXT NOT NULL DEFAULT (datetime('now'))
191
+ timestamp TEXT NOT NULL DEFAULT ${now}
162
192
  )
163
193
  `);
164
194
  // Index for audit log queries
165
- await this.engineDb.execute(`CREATE INDEX IF NOT EXISTS idx_db_audit_agent ON database_audit_log(agent_id, timestamp)`).catch(() => {});
166
- await this.engineDb.execute(`CREATE INDEX IF NOT EXISTS idx_db_audit_conn ON database_audit_log(connection_id, timestamp)`).catch(() => {});
195
+ await this.dbRun(`CREATE INDEX IF NOT EXISTS idx_db_audit_agent ON database_audit_log(agent_id, timestamp)`).catch(() => {});
196
+ await this.dbRun(`CREATE INDEX IF NOT EXISTS idx_db_audit_conn ON database_audit_log(connection_id, timestamp)`).catch(() => {});
167
197
  } catch (err: any) {
168
198
  console.error(`[db-access] Table creation failed:`, err.message);
169
199
  }
@@ -172,8 +202,7 @@ export class DatabaseConnectionManager {
172
202
  private async loadConnections(): Promise<void> {
173
203
  if (!this.engineDb) return;
174
204
  try {
175
- const getter = (this.engineDb as any).all || ((sql: string, params?: any[]) => this.engineDb!.execute(sql, params));
176
- const rows = await getter.call(this.engineDb, 'SELECT * FROM database_connections');
205
+ const rows = await this.dbAll('SELECT * FROM database_connections');
177
206
  for (const row of (rows || [])) {
178
207
  const config = this.rowToConfig(row);
179
208
  this.configs.set(config.id, config);
@@ -186,8 +215,7 @@ export class DatabaseConnectionManager {
186
215
  private async loadAgentAccess(): Promise<void> {
187
216
  if (!this.engineDb) return;
188
217
  try {
189
- const getter = (this.engineDb as any).all || ((sql: string, params?: any[]) => this.engineDb!.execute(sql, params));
190
- const rows = await getter.call(this.engineDb, 'SELECT * FROM agent_database_access WHERE enabled = 1');
218
+ const rows = await this.dbAll('SELECT * FROM agent_database_access WHERE enabled = 1');
191
219
  for (const row of (rows || [])) {
192
220
  const access = this.rowToAccess(row);
193
221
  const list = this.agentAccess.get(access.agentId) || [];
@@ -216,7 +244,7 @@ export class DatabaseConnectionManager {
216
244
 
217
245
  // Store config (without credentials) in DB
218
246
  if (this.engineDb) {
219
- await this.engineDb.execute(
247
+ await this.dbRun(
220
248
  `INSERT INTO database_connections (id, org_id, name, type, config, status, created_at, updated_at) VALUES (?, ?, ?, ?, ?, ?, ?, ?)`,
221
249
  [id, full.orgId, full.name, full.type, JSON.stringify(this.configToStorable(full)), full.status, now, now]
222
250
  );
@@ -241,7 +269,7 @@ export class DatabaseConnectionManager {
241
269
  }
242
270
 
243
271
  if (this.engineDb) {
244
- await this.engineDb.execute(
272
+ await this.dbRun(
245
273
  `UPDATE database_connections SET name = ?, type = ?, config = ?, status = ?, updated_at = ? WHERE id = ?`,
246
274
  [updated.name, updated.type, JSON.stringify(this.configToStorable(updated)), updated.status, updated.updatedAt, id]
247
275
  );
@@ -272,8 +300,8 @@ export class DatabaseConnectionManager {
272
300
  }
273
301
 
274
302
  if (this.engineDb) {
275
- await this.engineDb.execute('DELETE FROM agent_database_access WHERE connection_id = ?', [id]);
276
- await this.engineDb.execute('DELETE FROM database_connections WHERE id = ?', [id]);
303
+ await this.dbRun('DELETE FROM agent_database_access WHERE connection_id = ?', [id]);
304
+ await this.dbRun('DELETE FROM database_connections WHERE id = ?', [id]);
277
305
  }
278
306
 
279
307
  this.configs.delete(id);
@@ -304,7 +332,7 @@ export class DatabaseConnectionManager {
304
332
  const full: AgentDatabaseAccess = { ...access, id, createdAt: now, updatedAt: now };
305
333
 
306
334
  if (this.engineDb) {
307
- await this.engineDb.execute(
335
+ await this.dbRun(
308
336
  `INSERT INTO agent_database_access (id, org_id, agent_id, connection_id, permissions, query_limits, schema_access, log_all_queries, require_approval, enabled, created_at, updated_at)
309
337
  VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)`,
310
338
  [
@@ -325,7 +353,7 @@ export class DatabaseConnectionManager {
325
353
 
326
354
  async revokeAccess(agentId: string, connectionId: string): Promise<boolean> {
327
355
  if (this.engineDb) {
328
- await this.engineDb.execute(
356
+ await this.dbRun(
329
357
  'DELETE FROM agent_database_access WHERE agent_id = ? AND connection_id = ?',
330
358
  [agentId, connectionId]
331
359
  );
@@ -349,7 +377,7 @@ export class DatabaseConnectionManager {
349
377
  this.agentAccess.set(agentId, list);
350
378
 
351
379
  if (this.engineDb) {
352
- await this.engineDb.execute(
380
+ await this.dbRun(
353
381
  `UPDATE agent_database_access SET permissions = ?, query_limits = ?, schema_access = ?, log_all_queries = ?, require_approval = ?, enabled = ?, updated_at = ? WHERE agent_id = ? AND connection_id = ?`,
354
382
  [
355
383
  JSON.stringify(updated.permissions), JSON.stringify(updated.queryLimits || null),
@@ -625,7 +653,7 @@ export class DatabaseConnectionManager {
625
653
  ): Promise<void> {
626
654
  if (!this.engineDb) return;
627
655
  try {
628
- await this.engineDb.execute(
656
+ await this.dbRun(
629
657
  `INSERT INTO database_audit_log (id, org_id, agent_id, connection_id, connection_name, operation, query, param_count, rows_affected, execution_time_ms, success, error, timestamp)
630
658
  VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)`,
631
659
  [
@@ -648,8 +676,7 @@ export class DatabaseConnectionManager {
648
676
  if (opts.connectionId) { conditions.push('connection_id = ?'); params.push(opts.connectionId); }
649
677
  params.push(opts.limit ?? 100, opts.offset ?? 0);
650
678
 
651
- const getter = (this.engineDb as any).all || ((sql: string, p?: any[]) => this.engineDb!.execute(sql, p));
652
- return getter.call(this.engineDb,
679
+ return this.dbAll(
653
680
  `SELECT * FROM database_audit_log WHERE ${conditions.join(' AND ')} ORDER BY timestamp DESC LIMIT ? OFFSET ?`,
654
681
  params
655
682
  );