@agenticmail/enterprise 0.5.7 → 0.5.9

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 CHANGED
@@ -12,7 +12,7 @@ import {
12
12
  executeTool,
13
13
  runAgentLoop,
14
14
  toolsToDefinitions
15
- } from "./chunk-FVXEXRP2.js";
15
+ } from "./chunk-2QYDZGOO.js";
16
16
  import {
17
17
  ValidationError,
18
18
  auditLogger,
@@ -26,7 +26,7 @@ import {
26
26
  requireRole,
27
27
  securityHeaders,
28
28
  validate
29
- } from "./chunk-TCIGK4HQ.js";
29
+ } from "./chunk-MUKGRCNR.js";
30
30
  import {
31
31
  PROVIDER_REGISTRY,
32
32
  listAllProviders,
@@ -36,7 +36,7 @@ import {
36
36
  import {
37
37
  provision,
38
38
  runSetupWizard
39
- } from "./chunk-BRKFYP4K.js";
39
+ } from "./chunk-HDS2JMQ6.js";
40
40
  import {
41
41
  ENGINE_TABLES,
42
42
  ENGINE_TABLES_POSTGRES,
@@ -46,7 +46,7 @@ import {
46
46
  MIGRATIONS_TABLE_POSTGRES,
47
47
  sqliteToMySQL,
48
48
  sqliteToPostgres
49
- } from "./chunk-SGBTJHEF.js";
49
+ } from "./chunk-IDTJIAJZ.js";
50
50
  import {
51
51
  deployToCloud,
52
52
  generateDockerCompose,
@@ -77,7 +77,7 @@ import {
77
77
  TenantManager,
78
78
  WorkforceManager,
79
79
  init_guardrails
80
- } from "./chunk-OZZ65RAG.js";
80
+ } from "./chunk-L3MSZRJB.js";
81
81
  import "./chunk-TYW5XTOW.js";
82
82
  import {
83
83
  CircuitBreaker,
@@ -91,14 +91,14 @@ import {
91
91
  BUILTIN_SKILLS,
92
92
  PRESET_PROFILES,
93
93
  PermissionEngine
94
- } from "./chunk-P2FILRUE.js";
94
+ } from "./chunk-LKAFZ343.js";
95
95
  import {
96
96
  DatabaseAdapter
97
97
  } from "./chunk-FLRYMSKY.js";
98
98
  import {
99
99
  createAdapter,
100
100
  getSupportedDatabases
101
- } from "./chunk-Q3ZHFVGV.js";
101
+ } from "./chunk-G5OKUKJH.js";
102
102
  import {
103
103
  AGENTICMAIL_TOOLS,
104
104
  ALL_TOOLS,
@@ -107,7 +107,7 @@ import {
107
107
  generateToolPolicy,
108
108
  getToolsBySkill,
109
109
  init_tool_catalog
110
- } from "./chunk-WI62KTVK.js";
110
+ } from "./chunk-X6UVWFHW.js";
111
111
  import {
112
112
  VALID_CATEGORIES,
113
113
  VALID_RISK_LEVELS,
@@ -117,7 +117,7 @@ import {
117
117
  collectCommunityToolIds,
118
118
  validateSkillManifest
119
119
  } from "./chunk-TY7NVD4U.js";
120
- import "./chunk-2ESYSVXG.js";
120
+ import "./chunk-KFQGP6VL.js";
121
121
 
122
122
  // src/engine/index.ts
123
123
  init_tool_catalog();
@@ -0,0 +1,320 @@
1
+ import {
2
+ DatabaseAdapter
3
+ } from "./chunk-FLRYMSKY.js";
4
+ import "./chunk-KFQGP6VL.js";
5
+
6
+ // src/db/mongodb.ts
7
+ import { randomUUID, createHash } from "crypto";
8
+ var mongoMod;
9
+ async function getMongo() {
10
+ if (!mongoMod) {
11
+ try {
12
+ const { resolveDriver } = await import("./resolve-driver-VQXMFKLJ.js");
13
+ mongoMod = await resolveDriver("mongodb", "MongoDB driver not found. Install it: npm install mongodb");
14
+ } catch {
15
+ throw new Error("MongoDB driver not found. Install: npm install mongodb");
16
+ }
17
+ }
18
+ return mongoMod;
19
+ }
20
+ var MongoAdapter = class extends DatabaseAdapter {
21
+ type = "mongodb";
22
+ client = null;
23
+ db = null;
24
+ async connect(config) {
25
+ const { MongoClient } = await getMongo();
26
+ const uri = config.connectionString || `mongodb://${config.host || "localhost"}:${config.port || 27017}`;
27
+ this.client = new MongoClient(uri);
28
+ await this.client.connect();
29
+ const dbName = config.database || new URL(uri.replace("mongodb+srv://", "https://")).pathname.slice(1) || "agenticmail";
30
+ this.db = this.client.db(dbName);
31
+ }
32
+ async disconnect() {
33
+ if (this.client) await this.client.close();
34
+ }
35
+ isConnected() {
36
+ return this.client !== null;
37
+ }
38
+ col(name) {
39
+ return this.db.collection(name);
40
+ }
41
+ async migrate() {
42
+ await this.col("agents").createIndex({ name: 1 }, { unique: true });
43
+ await this.col("agents").createIndex({ email: 1 }, { unique: true });
44
+ await this.col("agents").createIndex({ status: 1 });
45
+ await this.col("users").createIndex({ email: 1 }, { unique: true });
46
+ await this.col("users").createIndex({ ssoProvider: 1, ssoSubject: 1 });
47
+ await this.col("audit_log").createIndex({ timestamp: -1 });
48
+ await this.col("audit_log").createIndex({ actor: 1 });
49
+ await this.col("audit_log").createIndex({ action: 1 });
50
+ await this.col("api_keys").createIndex({ keyHash: 1 }, { unique: true });
51
+ await this.col("email_rules").createIndex({ agentId: 1 });
52
+ await this.col("settings").updateOne(
53
+ { _id: "default" },
54
+ { $setOnInsert: { name: "", subdomain: "", plan: "free", primaryColor: "#6366f1", createdAt: /* @__PURE__ */ new Date(), updatedAt: /* @__PURE__ */ new Date() } },
55
+ { upsert: true }
56
+ );
57
+ await this.col("retention_policy").updateOne(
58
+ { _id: "default" },
59
+ { $setOnInsert: { enabled: false, retainDays: 365, excludeTags: [], archiveFirst: true } },
60
+ { upsert: true }
61
+ );
62
+ }
63
+ // ─── Company ─────────────────────────────────────────────
64
+ async getSettings() {
65
+ const r = await this.col("settings").findOne({ _id: "default" });
66
+ if (!r) return null;
67
+ return { id: "default", name: r.name, domain: r.domain, subdomain: r.subdomain, smtpHost: r.smtpHost, smtpPort: r.smtpPort, smtpUser: r.smtpUser, smtpPass: r.smtpPass, dkimPrivateKey: r.dkimPrivateKey, logoUrl: r.logoUrl, primaryColor: r.primaryColor, ssoConfig: r.ssoConfig, toolSecurityConfig: r.toolSecurityConfig || {}, firewallConfig: r.firewallConfig || {}, modelPricingConfig: r.modelPricingConfig || {}, plan: r.plan, deploymentKeyHash: r.deploymentKeyHash, domainRegistrationId: r.domainRegistrationId, domainDnsChallenge: r.domainDnsChallenge, domainVerifiedAt: r.domainVerifiedAt || void 0, domainRegisteredAt: r.domainRegisteredAt || void 0, domainStatus: r.domainStatus || "unregistered", createdAt: r.createdAt, updatedAt: r.updatedAt };
68
+ }
69
+ async updateSettings(updates) {
70
+ const { id, ...rest } = updates;
71
+ await this.col("settings").updateOne({ _id: "default" }, { $set: { ...rest, updatedAt: /* @__PURE__ */ new Date() } }, { upsert: true });
72
+ return this.getSettings();
73
+ }
74
+ // ─── Agents ──────────────────────────────────────────────
75
+ async createAgent(input) {
76
+ const doc = {
77
+ _id: input.id || randomUUID(),
78
+ name: input.name,
79
+ email: input.email || `${input.name.toLowerCase().replace(/\s+/g, "-")}@localhost`,
80
+ role: input.role || "assistant",
81
+ status: "active",
82
+ metadata: input.metadata || {},
83
+ createdBy: input.createdBy,
84
+ createdAt: /* @__PURE__ */ new Date(),
85
+ updatedAt: /* @__PURE__ */ new Date()
86
+ };
87
+ await this.col("agents").insertOne(doc);
88
+ return this.docToAgent(doc);
89
+ }
90
+ async getAgent(id) {
91
+ const r = await this.col("agents").findOne({ _id: id });
92
+ return r ? this.docToAgent(r) : null;
93
+ }
94
+ async getAgentByName(name) {
95
+ const r = await this.col("agents").findOne({ name });
96
+ return r ? this.docToAgent(r) : null;
97
+ }
98
+ async listAgents(opts) {
99
+ const filter = {};
100
+ if (opts?.status) filter.status = opts.status;
101
+ const cursor = this.col("agents").find(filter).sort({ createdAt: -1 });
102
+ if (opts?.offset) cursor.skip(opts.offset);
103
+ if (opts?.limit) cursor.limit(opts.limit);
104
+ return (await cursor.toArray()).map((r) => this.docToAgent(r));
105
+ }
106
+ async updateAgent(id, updates) {
107
+ const set = { updatedAt: /* @__PURE__ */ new Date() };
108
+ for (const key of ["name", "email", "role", "status", "metadata"]) {
109
+ if (updates[key] !== void 0) set[key] = updates[key];
110
+ }
111
+ await this.col("agents").updateOne({ _id: id }, { $set: set });
112
+ return await this.getAgent(id);
113
+ }
114
+ async archiveAgent(id) {
115
+ await this.col("agents").updateOne({ _id: id }, { $set: { status: "archived", updatedAt: /* @__PURE__ */ new Date() } });
116
+ }
117
+ async deleteAgent(id) {
118
+ await this.col("agents").deleteOne({ _id: id });
119
+ }
120
+ async countAgents(status) {
121
+ const filter = {};
122
+ if (status) filter.status = status;
123
+ return this.col("agents").countDocuments(filter);
124
+ }
125
+ // ─── Users ───────────────────────────────────────────────
126
+ async createUser(input) {
127
+ let passwordHash = null;
128
+ if (input.password) {
129
+ const { default: bcrypt } = await import("bcryptjs");
130
+ passwordHash = await bcrypt.hash(input.password, 12);
131
+ }
132
+ const doc = {
133
+ _id: randomUUID(),
134
+ email: input.email,
135
+ name: input.name,
136
+ role: input.role,
137
+ passwordHash,
138
+ ssoProvider: input.ssoProvider || null,
139
+ ssoSubject: input.ssoSubject || null,
140
+ createdAt: /* @__PURE__ */ new Date(),
141
+ updatedAt: /* @__PURE__ */ new Date(),
142
+ lastLoginAt: null
143
+ };
144
+ await this.col("users").insertOne(doc);
145
+ return this.docToUser(doc);
146
+ }
147
+ async getUser(id) {
148
+ const r = await this.col("users").findOne({ _id: id });
149
+ return r ? this.docToUser(r) : null;
150
+ }
151
+ async getUserByEmail(email) {
152
+ const r = await this.col("users").findOne({ email });
153
+ return r ? this.docToUser(r) : null;
154
+ }
155
+ async getUserBySso(provider, subject) {
156
+ const r = await this.col("users").findOne({ ssoProvider: provider, ssoSubject: subject });
157
+ return r ? this.docToUser(r) : null;
158
+ }
159
+ async listUsers(opts) {
160
+ const cursor = this.col("users").find({}).sort({ createdAt: -1 });
161
+ if (opts?.offset) cursor.skip(opts.offset);
162
+ if (opts?.limit) cursor.limit(opts.limit);
163
+ return (await cursor.toArray()).map((r) => this.docToUser(r));
164
+ }
165
+ async updateUser(id, updates) {
166
+ const set = { updatedAt: /* @__PURE__ */ new Date() };
167
+ for (const key of ["email", "name", "role", "lastLoginAt"]) {
168
+ if (updates[key] !== void 0) set[key] = updates[key];
169
+ }
170
+ await this.col("users").updateOne({ _id: id }, { $set: set });
171
+ return await this.getUser(id);
172
+ }
173
+ async deleteUser(id) {
174
+ await this.col("users").deleteOne({ _id: id });
175
+ }
176
+ // ─── Audit ───────────────────────────────────────────────
177
+ async logEvent(event) {
178
+ await this.col("audit_log").insertOne({
179
+ _id: randomUUID(),
180
+ timestamp: /* @__PURE__ */ new Date(),
181
+ actor: event.actor,
182
+ actorType: event.actorType,
183
+ action: event.action,
184
+ resource: event.resource,
185
+ details: event.details || {},
186
+ ip: event.ip || null
187
+ });
188
+ }
189
+ async queryAudit(filters) {
190
+ const filter = {};
191
+ if (filters.actor) filter.actor = filters.actor;
192
+ if (filters.action) filter.action = filters.action;
193
+ if (filters.resource) filter.resource = { $regex: filters.resource, $options: "i" };
194
+ if (filters.from || filters.to) {
195
+ filter.timestamp = {};
196
+ if (filters.from) filter.timestamp.$gte = filters.from;
197
+ if (filters.to) filter.timestamp.$lte = filters.to;
198
+ }
199
+ const total = await this.col("audit_log").countDocuments(filter);
200
+ const cursor = this.col("audit_log").find(filter).sort({ timestamp: -1 });
201
+ if (filters.offset) cursor.skip(filters.offset);
202
+ if (filters.limit) cursor.limit(filters.limit);
203
+ const rows = await cursor.toArray();
204
+ return {
205
+ events: rows.map((r) => ({
206
+ id: r._id,
207
+ timestamp: r.timestamp,
208
+ actor: r.actor,
209
+ actorType: r.actorType,
210
+ action: r.action,
211
+ resource: r.resource,
212
+ details: r.details,
213
+ ip: r.ip
214
+ })),
215
+ total
216
+ };
217
+ }
218
+ // ─── API Keys ────────────────────────────────────────────
219
+ async createApiKey(input) {
220
+ const id = randomUUID();
221
+ const plaintext = `ek_${randomUUID().replace(/-/g, "")}`;
222
+ const keyHash = createHash("sha256").update(plaintext).digest("hex");
223
+ const keyPrefix = plaintext.substring(0, 11);
224
+ const doc = {
225
+ _id: id,
226
+ name: input.name,
227
+ keyHash,
228
+ keyPrefix,
229
+ scopes: input.scopes,
230
+ createdBy: input.createdBy,
231
+ createdAt: /* @__PURE__ */ new Date(),
232
+ lastUsedAt: null,
233
+ expiresAt: input.expiresAt || null,
234
+ revoked: false
235
+ };
236
+ await this.col("api_keys").insertOne(doc);
237
+ return { key: this.docToApiKey(doc), plaintext };
238
+ }
239
+ async getApiKey(id) {
240
+ const r = await this.col("api_keys").findOne({ _id: id });
241
+ return r ? this.docToApiKey(r) : null;
242
+ }
243
+ async validateApiKey(plaintext) {
244
+ const keyHash = createHash("sha256").update(plaintext).digest("hex");
245
+ const r = await this.col("api_keys").findOne({ keyHash, revoked: false });
246
+ if (!r) return null;
247
+ const key = this.docToApiKey(r);
248
+ if (key.expiresAt && /* @__PURE__ */ new Date() > key.expiresAt) return null;
249
+ await this.col("api_keys").updateOne({ _id: r._id }, { $set: { lastUsedAt: /* @__PURE__ */ new Date() } });
250
+ return key;
251
+ }
252
+ async listApiKeys(opts) {
253
+ const filter = {};
254
+ if (opts?.createdBy) filter.createdBy = opts.createdBy;
255
+ return (await this.col("api_keys").find(filter).sort({ createdAt: -1 }).toArray()).map((r) => this.docToApiKey(r));
256
+ }
257
+ async revokeApiKey(id) {
258
+ await this.col("api_keys").updateOne({ _id: id }, { $set: { revoked: true } });
259
+ }
260
+ // ─── Rules ───────────────────────────────────────────────
261
+ async createRule(rule) {
262
+ const doc = {
263
+ _id: randomUUID(),
264
+ ...rule,
265
+ createdAt: /* @__PURE__ */ new Date(),
266
+ updatedAt: /* @__PURE__ */ new Date()
267
+ };
268
+ await this.col("email_rules").insertOne(doc);
269
+ return this.docToRule(doc);
270
+ }
271
+ async getRules(agentId) {
272
+ const filter = {};
273
+ if (agentId) filter.$or = [{ agentId }, { agentId: null }];
274
+ return (await this.col("email_rules").find(filter).sort({ priority: -1 }).toArray()).map((r) => this.docToRule(r));
275
+ }
276
+ async updateRule(id, updates) {
277
+ const { id: _id, createdAt, ...rest } = updates;
278
+ await this.col("email_rules").updateOne({ _id: id }, { $set: { ...rest, updatedAt: /* @__PURE__ */ new Date() } });
279
+ const r = await this.col("email_rules").findOne({ _id: id });
280
+ return this.docToRule(r);
281
+ }
282
+ async deleteRule(id) {
283
+ await this.col("email_rules").deleteOne({ _id: id });
284
+ }
285
+ // ─── Retention ───────────────────────────────────────────
286
+ async getRetentionPolicy() {
287
+ const r = await this.col("retention_policy").findOne({ _id: "default" });
288
+ if (!r) return { enabled: false, retainDays: 365, archiveFirst: true };
289
+ return { enabled: r.enabled, retainDays: r.retainDays, excludeTags: r.excludeTags || [], archiveFirst: r.archiveFirst };
290
+ }
291
+ async setRetentionPolicy(policy) {
292
+ await this.col("retention_policy").updateOne({ _id: "default" }, { $set: policy }, { upsert: true });
293
+ }
294
+ // ─── Stats ───────────────────────────────────────────────
295
+ async getStats() {
296
+ const [totalAgents, activeAgents, totalUsers, totalAuditEvents] = await Promise.all([
297
+ this.col("agents").countDocuments(),
298
+ this.col("agents").countDocuments({ status: "active" }),
299
+ this.col("users").countDocuments(),
300
+ this.col("audit_log").countDocuments()
301
+ ]);
302
+ return { totalAgents, activeAgents, totalUsers, totalEmails: 0, totalAuditEvents };
303
+ }
304
+ // ─── Mappers ─────────────────────────────────────────────
305
+ docToAgent(r) {
306
+ return { id: r._id, name: r.name, email: r.email, role: r.role, status: r.status, metadata: r.metadata || {}, createdBy: r.createdBy, createdAt: r.createdAt, updatedAt: r.updatedAt };
307
+ }
308
+ docToUser(r) {
309
+ return { id: r._id, email: r.email, name: r.name, role: r.role, passwordHash: r.passwordHash, ssoProvider: r.ssoProvider, ssoSubject: r.ssoSubject, createdAt: r.createdAt, updatedAt: r.updatedAt, lastLoginAt: r.lastLoginAt || void 0 };
310
+ }
311
+ docToApiKey(r) {
312
+ return { id: r._id, name: r.name, keyHash: r.keyHash, keyPrefix: r.keyPrefix, scopes: r.scopes || [], createdBy: r.createdBy, createdAt: r.createdAt, lastUsedAt: r.lastUsedAt || void 0, expiresAt: r.expiresAt || void 0, revoked: r.revoked };
313
+ }
314
+ docToRule(r) {
315
+ return { id: r._id, name: r.name, agentId: r.agentId, conditions: r.conditions || {}, actions: r.actions || {}, priority: r.priority, enabled: r.enabled, createdAt: r.createdAt, updatedAt: r.updatedAt };
316
+ }
317
+ };
318
+ export {
319
+ MongoAdapter
320
+ };