@agenticmail/enterprise 0.5.110 → 0.5.112

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,291 @@
1
+ import "./chunk-KFQGP6VL.js";
2
+
3
+ // src/cli-agent.ts
4
+ import { Hono } from "hono";
5
+ import { serve } from "@hono/node-server";
6
+ async function runAgent(_args) {
7
+ const DATABASE_URL = process.env.DATABASE_URL;
8
+ const JWT_SECRET = process.env.JWT_SECRET;
9
+ const AGENT_ID = process.env.AGENTICMAIL_AGENT_ID;
10
+ const PORT = parseInt(process.env.PORT || "3000", 10);
11
+ if (!DATABASE_URL) {
12
+ console.error("ERROR: DATABASE_URL is required");
13
+ process.exit(1);
14
+ }
15
+ if (!JWT_SECRET) {
16
+ console.error("ERROR: JWT_SECRET is required");
17
+ process.exit(1);
18
+ }
19
+ if (!AGENT_ID) {
20
+ console.error("ERROR: AGENTICMAIL_AGENT_ID is required");
21
+ process.exit(1);
22
+ }
23
+ console.log("\u{1F916} AgenticMail Agent Runtime");
24
+ console.log(` Agent ID: ${AGENT_ID}`);
25
+ console.log(" Connecting to database...");
26
+ const { createAdapter } = await import("./factory-GT6SUZSQ.js");
27
+ const db = await createAdapter({
28
+ type: DATABASE_URL.startsWith("postgres") ? "postgres" : "sqlite",
29
+ connectionString: DATABASE_URL
30
+ });
31
+ await db.migrate();
32
+ const { EngineDatabase } = await import("./db-adapter-65QMSGCB.js");
33
+ const engineDbInterface = db.getEngineDB();
34
+ if (!engineDbInterface) {
35
+ console.error("ERROR: Database does not support engine queries");
36
+ process.exit(1);
37
+ }
38
+ const adapterDialect = db.getDialect();
39
+ const dialectMap = {
40
+ sqlite: "sqlite",
41
+ postgres: "postgres",
42
+ supabase: "postgres",
43
+ neon: "postgres",
44
+ cockroachdb: "postgres"
45
+ };
46
+ const engineDialect = dialectMap[adapterDialect] || adapterDialect;
47
+ const engineDb = new EngineDatabase(engineDbInterface, engineDialect);
48
+ await engineDb.migrate();
49
+ const agentRow = await engineDb.query(
50
+ `SELECT id, name, display_name, config, state FROM managed_agents WHERE id = $1`,
51
+ [AGENT_ID]
52
+ );
53
+ if (!agentRow || agentRow.length === 0) {
54
+ console.error(`ERROR: Agent ${AGENT_ID} not found in database`);
55
+ process.exit(1);
56
+ }
57
+ const agent = agentRow[0];
58
+ console.log(` Agent: ${agent.display_name || agent.name}`);
59
+ console.log(` State: ${agent.state}`);
60
+ const { AgentLifecycleManager } = await import("./lifecycle-RHPPFTH7.js");
61
+ const lifecycle = new AgentLifecycleManager({ db: engineDb });
62
+ await lifecycle.loadFromDb();
63
+ const managed = lifecycle.getAgent(AGENT_ID);
64
+ if (!managed) {
65
+ console.error(`ERROR: Could not load agent ${AGENT_ID} from lifecycle`);
66
+ process.exit(1);
67
+ }
68
+ const config = managed.config;
69
+ console.log(` Model: ${config.model?.provider}/${config.model?.modelId}`);
70
+ let memoryManager;
71
+ try {
72
+ const { AgentMemoryManager } = await import("./agent-memory-G7YFTMDO.js");
73
+ memoryManager = new AgentMemoryManager(engineDb);
74
+ console.log(" Memory: DB-backed");
75
+ } catch {
76
+ console.log(" Memory: file-based fallback");
77
+ }
78
+ try {
79
+ const settings = await db.getSettings();
80
+ const keys = settings?.modelPricingConfig?.providerApiKeys;
81
+ if (keys && typeof keys === "object") {
82
+ const { PROVIDER_REGISTRY } = await import("./providers-DZDNNJTY.js");
83
+ for (const [providerId, apiKey] of Object.entries(keys)) {
84
+ const envVar = PROVIDER_REGISTRY[providerId]?.envKey;
85
+ if (envVar && apiKey && !process.env[envVar]) {
86
+ process.env[envVar] = apiKey;
87
+ console.log(` \u{1F511} Loaded API key for ${providerId}`);
88
+ }
89
+ }
90
+ }
91
+ } catch {
92
+ }
93
+ const { createAgentRuntime } = await import("./runtime-GBC7BO3X.js");
94
+ const getEmailConfig = (agentId) => {
95
+ const m = lifecycle.getAgent(agentId);
96
+ return m?.config?.emailConfig || null;
97
+ };
98
+ const onTokenRefresh = (agentId, tokens) => {
99
+ const m = lifecycle.getAgent(agentId);
100
+ if (m?.config?.emailConfig) {
101
+ if (tokens.accessToken) m.config.emailConfig.oauthAccessToken = tokens.accessToken;
102
+ if (tokens.refreshToken) m.config.emailConfig.oauthRefreshToken = tokens.refreshToken;
103
+ if (tokens.expiresAt) m.config.emailConfig.oauthTokenExpiry = tokens.expiresAt;
104
+ lifecycle.saveAgent(agentId).catch(() => {
105
+ });
106
+ }
107
+ };
108
+ let defaultModel;
109
+ const modelStr = process.env.AGENTICMAIL_MODEL || `${config.model?.provider}/${config.model?.modelId}`;
110
+ if (modelStr && modelStr.includes("/")) {
111
+ const [provider, ...rest] = modelStr.split("/");
112
+ defaultModel = {
113
+ provider,
114
+ modelId: rest.join("/"),
115
+ thinkingLevel: process.env.AGENTICMAIL_THINKING || config.model?.thinkingLevel
116
+ };
117
+ }
118
+ const runtime = createAgentRuntime({
119
+ engineDb,
120
+ adminDb: db,
121
+ defaultModel,
122
+ apiKeys: {},
123
+ gatewayEnabled: true,
124
+ getEmailConfig,
125
+ onTokenRefresh,
126
+ agentMemoryManager: memoryManager,
127
+ resumeOnStartup: true
128
+ });
129
+ await runtime.start();
130
+ const runtimeApp = runtime.getApp();
131
+ const app = new Hono();
132
+ app.get("/health", (c) => c.json({
133
+ status: "ok",
134
+ agentId: AGENT_ID,
135
+ agentName: agent.display_name || agent.name,
136
+ uptime: process.uptime()
137
+ }));
138
+ app.get("/ready", (c) => c.json({ ready: true, agentId: AGENT_ID }));
139
+ if (runtimeApp) {
140
+ app.route("/api/runtime", runtimeApp);
141
+ }
142
+ serve({ fetch: app.fetch, port: PORT }, (info) => {
143
+ console.log(`
144
+ \u2705 Agent runtime started`);
145
+ console.log(` Health: http://localhost:${info.port}/health`);
146
+ console.log(` Runtime: http://localhost:${info.port}/api/runtime`);
147
+ console.log("");
148
+ });
149
+ const shutdown = () => {
150
+ console.log("\n\u23F3 Shutting down agent...");
151
+ runtime.stop().then(() => db.disconnect()).then(() => {
152
+ console.log("\u2705 Agent shutdown complete");
153
+ process.exit(0);
154
+ });
155
+ setTimeout(() => process.exit(1), 1e4).unref();
156
+ };
157
+ process.on("SIGINT", shutdown);
158
+ process.on("SIGTERM", shutdown);
159
+ try {
160
+ await engineDb.query(
161
+ `UPDATE managed_agents SET state = 'running', updated_at = $1 WHERE id = $2`,
162
+ [(/* @__PURE__ */ new Date()).toISOString(), AGENT_ID]
163
+ );
164
+ console.log(" State: running");
165
+ } catch {
166
+ }
167
+ setTimeout(async () => {
168
+ try {
169
+ const orgRows = await engineDb.query(
170
+ `SELECT org_id FROM managed_agents WHERE id = $1`,
171
+ [AGENT_ID]
172
+ );
173
+ const orgId = orgRows?.[0]?.org_id;
174
+ if (!orgId) {
175
+ console.log("[onboarding] No org ID found, skipping");
176
+ return;
177
+ }
178
+ const pendingRows = await engineDb.query(
179
+ `SELECT r.id, r.policy_id, p.name as policy_name, p.content as policy_content, p.priority
180
+ FROM onboarding_records r
181
+ JOIN org_policies p ON r.policy_id = p.id
182
+ WHERE r.agent_id = $1 AND r.status = 'pending'`,
183
+ [AGENT_ID]
184
+ );
185
+ if (!pendingRows || pendingRows.length === 0) {
186
+ console.log("[onboarding] Already complete or no records");
187
+ } else {
188
+ console.log(`[onboarding] ${pendingRows.length} pending policies \u2014 auto-acknowledging...`);
189
+ const ts = (/* @__PURE__ */ new Date()).toISOString();
190
+ const policyNames = [];
191
+ for (const row of pendingRows) {
192
+ const policyName = row.policy_name || row.policy_id;
193
+ policyNames.push(policyName);
194
+ console.log(`[onboarding] Reading: ${policyName}`);
195
+ const { createHash } = await import("crypto");
196
+ const hash = createHash("sha256").update(row.policy_content || "").digest("hex").slice(0, 16);
197
+ await engineDb.query(
198
+ `UPDATE onboarding_records SET status = 'acknowledged', acknowledged_at = $1, verification_hash = $2, updated_at = $1 WHERE id = $3`,
199
+ [ts, hash, row.id]
200
+ );
201
+ console.log(`[onboarding] \u2705 Acknowledged: ${policyName}`);
202
+ if (memoryManager) {
203
+ try {
204
+ await memoryManager.storeMemory(AGENT_ID, {
205
+ content: `Organization policy "${policyName}" (${row.priority}): ${(row.policy_content || "").slice(0, 500)}`,
206
+ category: "org_knowledge",
207
+ importance: row.priority === "mandatory" ? "high" : "medium",
208
+ confidence: 1
209
+ });
210
+ } catch {
211
+ }
212
+ }
213
+ }
214
+ if (memoryManager) {
215
+ try {
216
+ await memoryManager.storeMemory(AGENT_ID, {
217
+ content: `Completed onboarding: read and acknowledged ${policyNames.length} organization policies: ${policyNames.join(", ")}.`,
218
+ category: "org_knowledge",
219
+ importance: "high",
220
+ confidence: 1
221
+ });
222
+ } catch {
223
+ }
224
+ }
225
+ console.log(`[onboarding] \u2705 Onboarding complete \u2014 ${policyNames.length} policies acknowledged`);
226
+ }
227
+ const managerEmail = config.managerEmail || (config.manager?.type === "external" ? config.manager.email : null);
228
+ const emailConfig = config.emailConfig;
229
+ if (managerEmail && emailConfig) {
230
+ console.log(`[welcome] Sending introduction email to ${managerEmail}...`);
231
+ try {
232
+ const { createEmailProvider } = await import("./agenticmail-TQQF7BI4.js");
233
+ const emailProvider = await createEmailProvider(emailConfig);
234
+ const agentName = config.displayName || config.name;
235
+ const role = config.identity?.role || "AI Agent";
236
+ const traits = config.identity?.traits || {};
237
+ const traitLines = Object.entries(traits).filter(([, v]) => v).map(([k, v]) => ` - ${k}: ${v}`).join("\n");
238
+ const policyCount = pendingRows?.length || 0;
239
+ const body = `Hello,
240
+
241
+ I'm ${agentName}, your new ${role}. I've just been deployed and have completed my onboarding \u2014 I've read and acknowledged all ${policyCount} organization policies.
242
+
243
+ About me:
244
+ - Role: ${role}
245
+ - Communication style: ${config.identity?.tone || "professional"}
246
+ - Language: ${config.identity?.language || "English"}
247
+ ${traitLines ? `- Personality traits:
248
+ ${traitLines}` : ""}
249
+
250
+ I'm ready to start working. Here's what I can help with:
251
+ - Responding to emails and communications
252
+ - Processing tasks and requests
253
+ - Following organization guidelines and escalation protocols
254
+
255
+ You can reach me by email at ${config.email?.address || emailConfig?.email || "my configured email address"}, or through the enterprise dashboard.
256
+
257
+ Looking forward to working with you!
258
+
259
+ Best regards,
260
+ ${agentName}`;
261
+ await emailProvider.send({
262
+ to: managerEmail,
263
+ subject: `Hi! I'm ${agentName}, your new ${role}`,
264
+ text: body
265
+ });
266
+ console.log(`[welcome] \u2705 Welcome email sent to ${managerEmail}`);
267
+ if (memoryManager) {
268
+ try {
269
+ await memoryManager.storeMemory(AGENT_ID, {
270
+ content: `Sent welcome introduction email to manager at ${managerEmail}. Introduced myself as ${agentName}, ${role}.`,
271
+ category: "interaction_pattern",
272
+ importance: "medium",
273
+ confidence: 1
274
+ });
275
+ } catch {
276
+ }
277
+ }
278
+ } catch (err) {
279
+ console.error(`[welcome] Failed to send welcome email: ${err.message}`);
280
+ }
281
+ } else {
282
+ if (!managerEmail) console.log("[welcome] No manager email configured, skipping welcome email");
283
+ }
284
+ } catch (err) {
285
+ console.error(`[onboarding] Error: ${err.message}`);
286
+ }
287
+ }, 3e3);
288
+ }
289
+ export {
290
+ runAgent
291
+ };
@@ -0,0 +1,306 @@
1
+ import "./chunk-KFQGP6VL.js";
2
+
3
+ // src/cli-agent.ts
4
+ import { Hono } from "hono";
5
+ import { serve } from "@hono/node-server";
6
+ async function runAgent(_args) {
7
+ const DATABASE_URL = process.env.DATABASE_URL;
8
+ const JWT_SECRET = process.env.JWT_SECRET;
9
+ const AGENT_ID = process.env.AGENTICMAIL_AGENT_ID;
10
+ const PORT = parseInt(process.env.PORT || "3000", 10);
11
+ if (!DATABASE_URL) {
12
+ console.error("ERROR: DATABASE_URL is required");
13
+ process.exit(1);
14
+ }
15
+ if (!JWT_SECRET) {
16
+ console.error("ERROR: JWT_SECRET is required");
17
+ process.exit(1);
18
+ }
19
+ if (!AGENT_ID) {
20
+ console.error("ERROR: AGENTICMAIL_AGENT_ID is required");
21
+ process.exit(1);
22
+ }
23
+ console.log("\u{1F916} AgenticMail Agent Runtime");
24
+ console.log(` Agent ID: ${AGENT_ID}`);
25
+ console.log(" Connecting to database...");
26
+ const { createAdapter } = await import("./factory-GT6SUZSQ.js");
27
+ const db = await createAdapter({
28
+ type: DATABASE_URL.startsWith("postgres") ? "postgres" : "sqlite",
29
+ connectionString: DATABASE_URL
30
+ });
31
+ await db.migrate();
32
+ const { EngineDatabase } = await import("./db-adapter-65QMSGCB.js");
33
+ const engineDbInterface = db.getEngineDB();
34
+ if (!engineDbInterface) {
35
+ console.error("ERROR: Database does not support engine queries");
36
+ process.exit(1);
37
+ }
38
+ const adapterDialect = db.getDialect();
39
+ const dialectMap = {
40
+ sqlite: "sqlite",
41
+ postgres: "postgres",
42
+ supabase: "postgres",
43
+ neon: "postgres",
44
+ cockroachdb: "postgres"
45
+ };
46
+ const engineDialect = dialectMap[adapterDialect] || adapterDialect;
47
+ const engineDb = new EngineDatabase(engineDbInterface, engineDialect);
48
+ await engineDb.migrate();
49
+ const agentRow = await engineDb.query(
50
+ `SELECT id, name, display_name, config, state FROM managed_agents WHERE id = $1`,
51
+ [AGENT_ID]
52
+ );
53
+ if (!agentRow || agentRow.length === 0) {
54
+ console.error(`ERROR: Agent ${AGENT_ID} not found in database`);
55
+ process.exit(1);
56
+ }
57
+ const agent = agentRow[0];
58
+ console.log(` Agent: ${agent.display_name || agent.name}`);
59
+ console.log(` State: ${agent.state}`);
60
+ const { AgentLifecycleManager } = await import("./lifecycle-RHPPFTH7.js");
61
+ const lifecycle = new AgentLifecycleManager({ db: engineDb });
62
+ await lifecycle.loadFromDb();
63
+ const managed = lifecycle.getAgent(AGENT_ID);
64
+ if (!managed) {
65
+ console.error(`ERROR: Could not load agent ${AGENT_ID} from lifecycle`);
66
+ process.exit(1);
67
+ }
68
+ const config = managed.config;
69
+ console.log(` Model: ${config.model?.provider}/${config.model?.modelId}`);
70
+ let memoryManager;
71
+ try {
72
+ const { AgentMemoryManager } = await import("./agent-memory-G7YFTMDO.js");
73
+ memoryManager = new AgentMemoryManager(engineDb);
74
+ console.log(" Memory: DB-backed");
75
+ } catch {
76
+ console.log(" Memory: file-based fallback");
77
+ }
78
+ try {
79
+ const settings = await db.getSettings();
80
+ const keys = settings?.modelPricingConfig?.providerApiKeys;
81
+ if (keys && typeof keys === "object") {
82
+ const { PROVIDER_REGISTRY } = await import("./providers-DZDNNJTY.js");
83
+ for (const [providerId, apiKey] of Object.entries(keys)) {
84
+ const envVar = PROVIDER_REGISTRY[providerId]?.envKey;
85
+ if (envVar && apiKey && !process.env[envVar]) {
86
+ process.env[envVar] = apiKey;
87
+ console.log(` \u{1F511} Loaded API key for ${providerId}`);
88
+ }
89
+ }
90
+ }
91
+ } catch {
92
+ }
93
+ const { createAgentRuntime } = await import("./runtime-GBC7BO3X.js");
94
+ const getEmailConfig = (agentId) => {
95
+ const m = lifecycle.getAgent(agentId);
96
+ return m?.config?.emailConfig || null;
97
+ };
98
+ const onTokenRefresh = (agentId, tokens) => {
99
+ const m = lifecycle.getAgent(agentId);
100
+ if (m?.config?.emailConfig) {
101
+ if (tokens.accessToken) m.config.emailConfig.oauthAccessToken = tokens.accessToken;
102
+ if (tokens.refreshToken) m.config.emailConfig.oauthRefreshToken = tokens.refreshToken;
103
+ if (tokens.expiresAt) m.config.emailConfig.oauthTokenExpiry = tokens.expiresAt;
104
+ lifecycle.saveAgent(agentId).catch(() => {
105
+ });
106
+ }
107
+ };
108
+ let defaultModel;
109
+ const modelStr = process.env.AGENTICMAIL_MODEL || `${config.model?.provider}/${config.model?.modelId}`;
110
+ if (modelStr && modelStr.includes("/")) {
111
+ const [provider, ...rest] = modelStr.split("/");
112
+ defaultModel = {
113
+ provider,
114
+ modelId: rest.join("/"),
115
+ thinkingLevel: process.env.AGENTICMAIL_THINKING || config.model?.thinkingLevel
116
+ };
117
+ }
118
+ const runtime = createAgentRuntime({
119
+ engineDb,
120
+ adminDb: db,
121
+ defaultModel,
122
+ apiKeys: {},
123
+ gatewayEnabled: true,
124
+ getEmailConfig,
125
+ onTokenRefresh,
126
+ agentMemoryManager: memoryManager,
127
+ resumeOnStartup: true
128
+ });
129
+ await runtime.start();
130
+ const runtimeApp = runtime.getApp();
131
+ const app = new Hono();
132
+ app.get("/health", (c) => c.json({
133
+ status: "ok",
134
+ agentId: AGENT_ID,
135
+ agentName: agent.display_name || agent.name,
136
+ uptime: process.uptime()
137
+ }));
138
+ app.get("/ready", (c) => c.json({ ready: true, agentId: AGENT_ID }));
139
+ if (runtimeApp) {
140
+ app.route("/api/runtime", runtimeApp);
141
+ }
142
+ serve({ fetch: app.fetch, port: PORT }, (info) => {
143
+ console.log(`
144
+ \u2705 Agent runtime started`);
145
+ console.log(` Health: http://localhost:${info.port}/health`);
146
+ console.log(` Runtime: http://localhost:${info.port}/api/runtime`);
147
+ console.log("");
148
+ });
149
+ const shutdown = () => {
150
+ console.log("\n\u23F3 Shutting down agent...");
151
+ runtime.stop().then(() => db.disconnect()).then(() => {
152
+ console.log("\u2705 Agent shutdown complete");
153
+ process.exit(0);
154
+ });
155
+ setTimeout(() => process.exit(1), 1e4).unref();
156
+ };
157
+ process.on("SIGINT", shutdown);
158
+ process.on("SIGTERM", shutdown);
159
+ try {
160
+ await engineDb.query(
161
+ `UPDATE managed_agents SET state = 'running', updated_at = $1 WHERE id = $2`,
162
+ [(/* @__PURE__ */ new Date()).toISOString(), AGENT_ID]
163
+ );
164
+ console.log(" State: running");
165
+ } catch {
166
+ }
167
+ setTimeout(async () => {
168
+ try {
169
+ const orgRows = await engineDb.query(
170
+ `SELECT org_id FROM managed_agents WHERE id = $1`,
171
+ [AGENT_ID]
172
+ );
173
+ const orgId = orgRows?.[0]?.org_id;
174
+ if (!orgId) {
175
+ console.log("[onboarding] No org ID found, skipping");
176
+ return;
177
+ }
178
+ const pendingRows = await engineDb.query(
179
+ `SELECT r.id, r.policy_id, p.name as policy_name, p.content as policy_content, p.priority
180
+ FROM onboarding_records r
181
+ JOIN org_policies p ON r.policy_id = p.id
182
+ WHERE r.agent_id = $1 AND r.status = 'pending'`,
183
+ [AGENT_ID]
184
+ );
185
+ if (!pendingRows || pendingRows.length === 0) {
186
+ console.log("[onboarding] Already complete or no records");
187
+ } else {
188
+ console.log(`[onboarding] ${pendingRows.length} pending policies \u2014 auto-acknowledging...`);
189
+ const ts = (/* @__PURE__ */ new Date()).toISOString();
190
+ const policyNames = [];
191
+ for (const row of pendingRows) {
192
+ const policyName = row.policy_name || row.policy_id;
193
+ policyNames.push(policyName);
194
+ console.log(`[onboarding] Reading: ${policyName}`);
195
+ const { createHash } = await import("crypto");
196
+ const hash = createHash("sha256").update(row.policy_content || "").digest("hex").slice(0, 16);
197
+ await engineDb.query(
198
+ `UPDATE onboarding_records SET status = 'acknowledged', acknowledged_at = $1, verification_hash = $2, updated_at = $1 WHERE id = $3`,
199
+ [ts, hash, row.id]
200
+ );
201
+ console.log(`[onboarding] \u2705 Acknowledged: ${policyName}`);
202
+ if (memoryManager) {
203
+ try {
204
+ await memoryManager.storeMemory(AGENT_ID, {
205
+ content: `Organization policy "${policyName}" (${row.priority}): ${(row.policy_content || "").slice(0, 500)}`,
206
+ category: "org_knowledge",
207
+ importance: row.priority === "mandatory" ? "high" : "medium",
208
+ confidence: 1
209
+ });
210
+ } catch {
211
+ }
212
+ }
213
+ }
214
+ if (memoryManager) {
215
+ try {
216
+ await memoryManager.storeMemory(AGENT_ID, {
217
+ content: `Completed onboarding: read and acknowledged ${policyNames.length} organization policies: ${policyNames.join(", ")}.`,
218
+ category: "org_knowledge",
219
+ importance: "high",
220
+ confidence: 1
221
+ });
222
+ } catch {
223
+ }
224
+ }
225
+ console.log(`[onboarding] \u2705 Onboarding complete \u2014 ${policyNames.length} policies acknowledged`);
226
+ }
227
+ const managerEmail = config.managerEmail || (config.manager?.type === "external" ? config.manager.email : null);
228
+ const emailConfig = config.emailConfig;
229
+ if (managerEmail && emailConfig) {
230
+ console.log(`[welcome] Sending introduction email to ${managerEmail}...`);
231
+ try {
232
+ const { createEmailProvider } = await import("./agenticmail-TQQF7BI4.js");
233
+ const providerType = emailConfig.provider || (emailConfig.oauthProvider === "google" ? "google" : emailConfig.oauthProvider === "microsoft" ? "microsoft" : "imap");
234
+ const emailProvider = createEmailProvider(providerType);
235
+ await emailProvider.connect({
236
+ agentId: AGENT_ID,
237
+ email: emailConfig.email || config.email?.address || "",
238
+ oauthAccessToken: emailConfig.oauthAccessToken,
239
+ oauthRefreshToken: emailConfig.oauthRefreshToken,
240
+ oauthClientId: emailConfig.oauthClientId,
241
+ oauthClientSecret: emailConfig.oauthClientSecret,
242
+ oauthTokenExpiry: emailConfig.oauthTokenExpiry,
243
+ imapHost: emailConfig.imapHost,
244
+ imapPort: emailConfig.imapPort,
245
+ smtpHost: emailConfig.smtpHost,
246
+ smtpPort: emailConfig.smtpPort,
247
+ password: emailConfig.password
248
+ });
249
+ const agentName = config.displayName || config.name;
250
+ const role = config.identity?.role || "AI Agent";
251
+ const traits = config.identity?.traits || {};
252
+ const traitLines = Object.entries(traits).filter(([, v]) => v).map(([k, v]) => ` - ${k}: ${v}`).join("\n");
253
+ const policyCount = pendingRows?.length || 0;
254
+ const body = `Hello,
255
+
256
+ I'm ${agentName}, your new ${role}. I've just been deployed and have completed my onboarding \u2014 I've read and acknowledged all ${policyCount} organization policies.
257
+
258
+ About me:
259
+ - Role: ${role}
260
+ - Communication style: ${config.identity?.tone || "professional"}
261
+ - Language: ${config.identity?.language || "English"}
262
+ ${traitLines ? `- Personality traits:
263
+ ${traitLines}` : ""}
264
+
265
+ I'm ready to start working. Here's what I can help with:
266
+ - Responding to emails and communications
267
+ - Processing tasks and requests
268
+ - Following organization guidelines and escalation protocols
269
+
270
+ You can reach me by email at ${config.email?.address || emailConfig?.email || "my configured email address"}, or through the enterprise dashboard.
271
+
272
+ Looking forward to working with you!
273
+
274
+ Best regards,
275
+ ${agentName}`;
276
+ await emailProvider.send({
277
+ to: managerEmail,
278
+ subject: `Hi! I'm ${agentName}, your new ${role}`,
279
+ text: body
280
+ });
281
+ console.log(`[welcome] \u2705 Welcome email sent to ${managerEmail}`);
282
+ if (memoryManager) {
283
+ try {
284
+ await memoryManager.storeMemory(AGENT_ID, {
285
+ content: `Sent welcome introduction email to manager at ${managerEmail}. Introduced myself as ${agentName}, ${role}.`,
286
+ category: "interaction_pattern",
287
+ importance: "medium",
288
+ confidence: 1
289
+ });
290
+ } catch {
291
+ }
292
+ }
293
+ } catch (err) {
294
+ console.error(`[welcome] Failed to send welcome email: ${err.message}`);
295
+ }
296
+ } else {
297
+ if (!managerEmail) console.log("[welcome] No manager email configured, skipping welcome email");
298
+ }
299
+ } catch (err) {
300
+ console.error(`[onboarding] Error: ${err.message}`);
301
+ }
302
+ }, 3e3);
303
+ }
304
+ export {
305
+ runAgent
306
+ };
@@ -0,0 +1,34 @@
1
+ import "./chunk-KFQGP6VL.js";
2
+
3
+ // src/cli-serve.ts
4
+ async function runServe(_args) {
5
+ const DATABASE_URL = process.env.DATABASE_URL;
6
+ const JWT_SECRET = process.env.JWT_SECRET;
7
+ const PORT = parseInt(process.env.PORT || "8080", 10);
8
+ if (!DATABASE_URL) {
9
+ console.error("ERROR: DATABASE_URL environment variable is required");
10
+ process.exit(1);
11
+ }
12
+ if (!JWT_SECRET) {
13
+ console.error("ERROR: JWT_SECRET environment variable is required");
14
+ process.exit(1);
15
+ }
16
+ const { createAdapter } = await import("./factory-GT6SUZSQ.js");
17
+ const { createServer } = await import("./server-4AXTAAPN.js");
18
+ const db = await createAdapter({
19
+ type: DATABASE_URL.startsWith("postgres") ? "postgres" : "sqlite",
20
+ connectionString: DATABASE_URL
21
+ });
22
+ await db.migrate();
23
+ const server = createServer({
24
+ port: PORT,
25
+ db,
26
+ jwtSecret: JWT_SECRET,
27
+ corsOrigins: ["*"]
28
+ });
29
+ await server.start();
30
+ console.log(`AgenticMail Enterprise server running on :${PORT}`);
31
+ }
32
+ export {
33
+ runServe
34
+ };
package/dist/cli.js CHANGED
@@ -47,14 +47,14 @@ Skill Development:
47
47
  `);
48
48
  break;
49
49
  case "serve":
50
- import("./cli-serve-5TA6CQB2.js").then((m) => m.runServe(args.slice(1))).catch(fatal);
50
+ import("./cli-serve-25MJKRJM.js").then((m) => m.runServe(args.slice(1))).catch(fatal);
51
51
  break;
52
52
  case "agent":
53
- import("./cli-agent-NNAYRQ6Y.js").then((m) => m.runAgent(args.slice(1))).catch(fatal);
53
+ import("./cli-agent-NOX4LJ62.js").then((m) => m.runAgent(args.slice(1))).catch(fatal);
54
54
  break;
55
55
  case "setup":
56
56
  default:
57
- import("./setup-AB2WNKDV.js").then((m) => m.runSetupWizard()).catch(fatal);
57
+ import("./setup-BRLWAAZT.js").then((m) => m.runSetupWizard()).catch(fatal);
58
58
  break;
59
59
  }
60
60
  function fatal(err) {
package/dist/index.js CHANGED
@@ -13,7 +13,7 @@ import {
13
13
  import {
14
14
  provision,
15
15
  runSetupWizard
16
- } from "./chunk-UWN7I2M2.js";
16
+ } from "./chunk-WJZ42G5N.js";
17
17
  import {
18
18
  ActionJournal,
19
19
  ActivityTracker,
@@ -60,7 +60,7 @@ import {
60
60
  executeTool,
61
61
  runAgentLoop,
62
62
  toolsToDefinitions
63
- } from "./chunk-24RMT4YR.js";
63
+ } from "./chunk-YRRKUCNF.js";
64
64
  import "./chunk-TYW5XTOW.js";
65
65
  import "./chunk-AQH4DFYV.js";
66
66
  import {
@@ -76,7 +76,7 @@ import {
76
76
  requireRole,
77
77
  securityHeaders,
78
78
  validate
79
- } from "./chunk-OAEIWLI5.js";
79
+ } from "./chunk-SAJR7T37.js";
80
80
  import "./chunk-3SMTCIR4.js";
81
81
  import "./chunk-RO537U6H.js";
82
82
  import "./chunk-DRXMYYKN.js";
@@ -90,7 +90,7 @@ import {
90
90
  AgentConfigGenerator,
91
91
  AgentLifecycleManager,
92
92
  DeploymentEngine
93
- } from "./chunk-NJEPWQ2G.js";
93
+ } from "./chunk-2AMNVQIQ.js";
94
94
  import {
95
95
  CircuitBreaker,
96
96
  CircuitOpenError,
@@ -0,0 +1,10 @@
1
+ import {
2
+ AgentLifecycleManager
3
+ } from "./chunk-2AMNVQIQ.js";
4
+ import "./chunk-JLSQOQ5L.js";
5
+ import "./chunk-T6FM7KNN.js";
6
+ import "./chunk-MINPSFLF.js";
7
+ import "./chunk-KFQGP6VL.js";
8
+ export {
9
+ AgentLifecycleManager
10
+ };