@agenticmail/enterprise 0.5.108 → 0.5.109

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,170 @@
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-XFBP3QXE.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-QDXLDBI4.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
+ }
168
+ export {
169
+ runAgent
170
+ };
package/dist/cli.js CHANGED
@@ -50,7 +50,7 @@ Skill Development:
50
50
  import("./cli-serve-5TA6CQB2.js").then((m) => m.runServe(args.slice(1))).catch(fatal);
51
51
  break;
52
52
  case "agent":
53
- import("./cli-agent-DIJ7RGQF.js").then((m) => m.runAgent(args.slice(1))).catch(fatal);
53
+ import("./cli-agent-6UAOW6T3.js").then((m) => m.runAgent(args.slice(1))).catch(fatal);
54
54
  break;
55
55
  case "setup":
56
56
  default:
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@agenticmail/enterprise",
3
- "version": "0.5.108",
3
+ "version": "0.5.109",
4
4
  "description": "AgenticMail Enterprise — cloud-hosted AI agent identity, email, auth & compliance for organizations",
5
5
  "type": "module",
6
6
  "bin": {
package/src/cli-agent.ts CHANGED
@@ -73,8 +73,8 @@ export async function runAgent(_args: string[]) {
73
73
  console.log(` State: ${agent.state}`);
74
74
 
75
75
  // 4. Initialize lifecycle (manages agent state, config decryption)
76
- const { AgentLifecycle } = await import('./engine/lifecycle.js');
77
- const lifecycle = new AgentLifecycle(engineDb);
76
+ const { AgentLifecycleManager } = await import('./engine/lifecycle.js');
77
+ const lifecycle = new AgentLifecycleManager({ db: engineDb });
78
78
  await lifecycle.loadFromDb();
79
79
 
80
80
  const managed = lifecycle.getAgent(AGENT_ID);