@agenticmail/enterprise 0.5.224 → 0.5.225
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/chunk-PAPADBZ7.js +3685 -0
- package/dist/chunk-TBG5SA5C.js +4463 -0
- package/dist/chunk-UHB3PVLC.js +1224 -0
- package/dist/cli-agent-JRAUHZUL.js +1719 -0
- package/dist/cli-serve-LNJZMBQU.js +114 -0
- package/dist/cli.js +3 -3
- package/dist/index.js +3 -3
- package/dist/runtime-NMUKKLGE.js +45 -0
- package/dist/server-K5SYZYZ2.js +15 -0
- package/dist/setup-N5RUFJ6B.js +20 -0
- package/package.json +1 -1
- package/src/cli-agent.ts +1 -1
- package/src/runtime/agent-loop.ts +11 -3
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
import "./chunk-KFQGP6VL.js";
|
|
2
|
+
|
|
3
|
+
// src/cli-serve.ts
|
|
4
|
+
import { existsSync, readFileSync } from "fs";
|
|
5
|
+
import { join } from "path";
|
|
6
|
+
import { homedir } from "os";
|
|
7
|
+
function loadEnvFile() {
|
|
8
|
+
const candidates = [
|
|
9
|
+
join(process.cwd(), ".env"),
|
|
10
|
+
join(homedir(), ".agenticmail", ".env")
|
|
11
|
+
];
|
|
12
|
+
for (const envPath of candidates) {
|
|
13
|
+
if (!existsSync(envPath)) continue;
|
|
14
|
+
try {
|
|
15
|
+
const content = readFileSync(envPath, "utf8");
|
|
16
|
+
for (const line of content.split("\n")) {
|
|
17
|
+
const trimmed = line.trim();
|
|
18
|
+
if (!trimmed || trimmed.startsWith("#")) continue;
|
|
19
|
+
const eq = trimmed.indexOf("=");
|
|
20
|
+
if (eq < 0) continue;
|
|
21
|
+
const key = trimmed.slice(0, eq).trim();
|
|
22
|
+
let val = trimmed.slice(eq + 1).trim();
|
|
23
|
+
if (val.startsWith('"') && val.endsWith('"') || val.startsWith("'") && val.endsWith("'")) {
|
|
24
|
+
val = val.slice(1, -1);
|
|
25
|
+
}
|
|
26
|
+
if (!process.env[key]) process.env[key] = val;
|
|
27
|
+
}
|
|
28
|
+
console.log(`Loaded config from ${envPath}`);
|
|
29
|
+
return;
|
|
30
|
+
} catch {
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
async function ensureSecrets() {
|
|
35
|
+
const { randomUUID } = await import("crypto");
|
|
36
|
+
const envDir = join(homedir(), ".agenticmail");
|
|
37
|
+
const envPath = join(envDir, ".env");
|
|
38
|
+
let dirty = false;
|
|
39
|
+
if (!process.env.JWT_SECRET) {
|
|
40
|
+
process.env.JWT_SECRET = randomUUID() + randomUUID();
|
|
41
|
+
dirty = true;
|
|
42
|
+
console.log("[startup] Generated new JWT_SECRET (existing sessions will need to re-login)");
|
|
43
|
+
}
|
|
44
|
+
if (!process.env.AGENTICMAIL_VAULT_KEY) {
|
|
45
|
+
process.env.AGENTICMAIL_VAULT_KEY = randomUUID() + randomUUID();
|
|
46
|
+
dirty = true;
|
|
47
|
+
console.log("[startup] Generated new AGENTICMAIL_VAULT_KEY");
|
|
48
|
+
console.log("[startup] \u26A0\uFE0F Previously encrypted credentials will need to be re-entered in the dashboard");
|
|
49
|
+
}
|
|
50
|
+
if (dirty) {
|
|
51
|
+
try {
|
|
52
|
+
if (!existsSync(envDir)) {
|
|
53
|
+
const { mkdirSync } = await import("fs");
|
|
54
|
+
mkdirSync(envDir, { recursive: true });
|
|
55
|
+
}
|
|
56
|
+
const { appendFileSync } = await import("fs");
|
|
57
|
+
const lines = [];
|
|
58
|
+
let existing = "";
|
|
59
|
+
if (existsSync(envPath)) {
|
|
60
|
+
existing = readFileSync(envPath, "utf8");
|
|
61
|
+
}
|
|
62
|
+
if (!existing.includes("JWT_SECRET=")) {
|
|
63
|
+
lines.push(`JWT_SECRET=${process.env.JWT_SECRET}`);
|
|
64
|
+
}
|
|
65
|
+
if (!existing.includes("AGENTICMAIL_VAULT_KEY=")) {
|
|
66
|
+
lines.push(`AGENTICMAIL_VAULT_KEY=${process.env.AGENTICMAIL_VAULT_KEY}`);
|
|
67
|
+
}
|
|
68
|
+
if (lines.length) {
|
|
69
|
+
appendFileSync(envPath, "\n" + lines.join("\n") + "\n", { mode: 384 });
|
|
70
|
+
console.log(`[startup] Saved secrets to ${envPath}`);
|
|
71
|
+
}
|
|
72
|
+
} catch (e) {
|
|
73
|
+
console.warn(`[startup] Could not save secrets to ${envPath}: ${e.message}`);
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
async function runServe(_args) {
|
|
78
|
+
loadEnvFile();
|
|
79
|
+
const DATABASE_URL = process.env.DATABASE_URL;
|
|
80
|
+
const PORT = parseInt(process.env.PORT || "8080", 10);
|
|
81
|
+
await ensureSecrets();
|
|
82
|
+
const JWT_SECRET = process.env.JWT_SECRET;
|
|
83
|
+
const VAULT_KEY = process.env.AGENTICMAIL_VAULT_KEY;
|
|
84
|
+
if (!DATABASE_URL) {
|
|
85
|
+
console.error("ERROR: DATABASE_URL is required.");
|
|
86
|
+
console.error("");
|
|
87
|
+
console.error("Set it via environment variable or .env file:");
|
|
88
|
+
console.error(" DATABASE_URL=postgresql://user:pass@host:5432/db npx @agenticmail/enterprise start");
|
|
89
|
+
console.error("");
|
|
90
|
+
console.error("Or create a .env file (in cwd or ~/.agenticmail/.env):");
|
|
91
|
+
console.error(" DATABASE_URL=postgresql://user:pass@host:5432/db");
|
|
92
|
+
console.error(" JWT_SECRET=your-secret-here");
|
|
93
|
+
console.error(" PORT=3200");
|
|
94
|
+
process.exit(1);
|
|
95
|
+
}
|
|
96
|
+
const { createAdapter } = await import("./factory-K32DV2DR.js");
|
|
97
|
+
const { createServer } = await import("./server-K5SYZYZ2.js");
|
|
98
|
+
const db = await createAdapter({
|
|
99
|
+
type: DATABASE_URL.startsWith("postgres") ? "postgres" : "sqlite",
|
|
100
|
+
connectionString: DATABASE_URL
|
|
101
|
+
});
|
|
102
|
+
await db.migrate();
|
|
103
|
+
const server = createServer({
|
|
104
|
+
port: PORT,
|
|
105
|
+
db,
|
|
106
|
+
jwtSecret: JWT_SECRET,
|
|
107
|
+
corsOrigins: ["*"]
|
|
108
|
+
});
|
|
109
|
+
await server.start();
|
|
110
|
+
console.log(`AgenticMail Enterprise server running on :${PORT}`);
|
|
111
|
+
}
|
|
112
|
+
export {
|
|
113
|
+
runServe
|
|
114
|
+
};
|
package/dist/cli.js
CHANGED
|
@@ -53,14 +53,14 @@ Skill Development:
|
|
|
53
53
|
break;
|
|
54
54
|
case "serve":
|
|
55
55
|
case "start":
|
|
56
|
-
import("./cli-serve-
|
|
56
|
+
import("./cli-serve-LNJZMBQU.js").then((m) => m.runServe(args.slice(1))).catch(fatal);
|
|
57
57
|
break;
|
|
58
58
|
case "agent":
|
|
59
|
-
import("./cli-agent-
|
|
59
|
+
import("./cli-agent-JRAUHZUL.js").then((m) => m.runAgent(args.slice(1))).catch(fatal);
|
|
60
60
|
break;
|
|
61
61
|
case "setup":
|
|
62
62
|
default:
|
|
63
|
-
import("./setup-
|
|
63
|
+
import("./setup-N5RUFJ6B.js").then((m) => m.runSetupWizard()).catch(fatal);
|
|
64
64
|
break;
|
|
65
65
|
}
|
|
66
66
|
function fatal(err) {
|
package/dist/index.js
CHANGED
|
@@ -7,7 +7,7 @@ import {
|
|
|
7
7
|
import {
|
|
8
8
|
provision,
|
|
9
9
|
runSetupWizard
|
|
10
|
-
} from "./chunk-
|
|
10
|
+
} from "./chunk-UHB3PVLC.js";
|
|
11
11
|
import {
|
|
12
12
|
AgenticMailManager,
|
|
13
13
|
GoogleEmailProvider,
|
|
@@ -28,7 +28,7 @@ import {
|
|
|
28
28
|
executeTool,
|
|
29
29
|
runAgentLoop,
|
|
30
30
|
toolsToDefinitions
|
|
31
|
-
} from "./chunk-
|
|
31
|
+
} from "./chunk-TBG5SA5C.js";
|
|
32
32
|
import {
|
|
33
33
|
ValidationError,
|
|
34
34
|
auditLogger,
|
|
@@ -42,7 +42,7 @@ import {
|
|
|
42
42
|
requireRole,
|
|
43
43
|
securityHeaders,
|
|
44
44
|
validate
|
|
45
|
-
} from "./chunk-
|
|
45
|
+
} from "./chunk-PAPADBZ7.js";
|
|
46
46
|
import "./chunk-OF4MUWWS.js";
|
|
47
47
|
import {
|
|
48
48
|
PROVIDER_REGISTRY,
|
|
@@ -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-TBG5SA5C.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-PAPADBZ7.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-UHB3PVLC.js";
|
|
10
|
+
import "./chunk-VQQ4SYYQ.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
package/src/cli-agent.ts
CHANGED
|
@@ -937,7 +937,7 @@ export async function runAgent(_args: string[]) {
|
|
|
937
937
|
error: result?.error?.message || result?.error,
|
|
938
938
|
modelUsed: result?.model || config.model,
|
|
939
939
|
tokensUsed: (usage.inputTokens || 0) + (usage.outputTokens || 0),
|
|
940
|
-
costUsd: usage.cost || 0,
|
|
940
|
+
costUsd: usage.costUsd || usage.cost || 0,
|
|
941
941
|
sessionId: session.id,
|
|
942
942
|
result: { messageCount: (result?.messages || []).length },
|
|
943
943
|
}).catch(() => {});
|
|
@@ -174,6 +174,7 @@ export interface AgentLoopResult {
|
|
|
174
174
|
turnCount: number;
|
|
175
175
|
textContent: string;
|
|
176
176
|
stopReason: string;
|
|
177
|
+
usage?: { inputTokens: number; outputTokens: number; costUsd: number };
|
|
177
178
|
}
|
|
178
179
|
|
|
179
180
|
export async function runAgentLoop(
|
|
@@ -210,6 +211,7 @@ export async function runAgentLoop(
|
|
|
210
211
|
var totalTextContent = '';
|
|
211
212
|
var lastStopReason = 'end_turn';
|
|
212
213
|
var sessionId = options.sessionId || ''; // Set by caller
|
|
214
|
+
var cumulativeUsage = { inputTokens: 0, outputTokens: 0, costUsd: 0 };
|
|
213
215
|
|
|
214
216
|
// Emit session start
|
|
215
217
|
var sessionStartEvent: StreamEvent = { type: 'session_start', sessionId: config.agentId };
|
|
@@ -218,7 +220,7 @@ export async function runAgentLoop(
|
|
|
218
220
|
while (maxTurns === 0 || turnCount < maxTurns) {
|
|
219
221
|
// Check abort
|
|
220
222
|
if (options.signal?.aborted) {
|
|
221
|
-
return buildResult(messages, 'paused', turnCount, totalTextContent, 'aborted');
|
|
223
|
+
return buildResult(messages, 'paused', turnCount, totalTextContent, 'aborted', cumulativeUsage);
|
|
222
224
|
}
|
|
223
225
|
|
|
224
226
|
turnCount++;
|
|
@@ -259,7 +261,7 @@ export async function runAgentLoop(
|
|
|
259
261
|
console.log(`[agent-loop] BUDGET EXCEEDED for agent ${config.agentId}: ${budgetResult.reason}`);
|
|
260
262
|
var budgetEvent: StreamEvent = { type: 'budget_exceeded', reason: budgetResult.reason || 'Budget limit reached' };
|
|
261
263
|
options.onEvent?.(budgetEvent);
|
|
262
|
-
return buildResult(messages, 'completed', turnCount, totalTextContent, 'budget_exceeded');
|
|
264
|
+
return buildResult(messages, 'completed', turnCount, totalTextContent, 'budget_exceeded', cumulativeUsage);
|
|
263
265
|
}
|
|
264
266
|
if (budgetResult.remainingUsd !== undefined && budgetResult.remainingUsd < 1.0) {
|
|
265
267
|
var warnEvent: StreamEvent = { type: 'budget_warning', remainingUsd: budgetResult.remainingUsd, usedUsd: 0 };
|
|
@@ -329,7 +331,7 @@ export async function runAgentLoop(
|
|
|
329
331
|
console.error(`[agent-loop] LLM call failed after ${llmAttempt + 1} attempts: ${err.message}`);
|
|
330
332
|
var errorEvent: StreamEvent = { type: 'error', message: err.message, retryable: isTransient };
|
|
331
333
|
options.onEvent?.(errorEvent);
|
|
332
|
-
return buildResult(messages, 'failed', turnCount, totalTextContent, 'error');
|
|
334
|
+
return buildResult(messages, 'failed', turnCount, totalTextContent, 'error', cumulativeUsage);
|
|
333
335
|
}
|
|
334
336
|
}
|
|
335
337
|
|
|
@@ -349,6 +351,9 @@ export async function runAgentLoop(
|
|
|
349
351
|
outputTokens: usageOutput,
|
|
350
352
|
costUsd,
|
|
351
353
|
});
|
|
354
|
+
cumulativeUsage.inputTokens += usageInput;
|
|
355
|
+
cumulativeUsage.outputTokens += usageOutput;
|
|
356
|
+
cumulativeUsage.costUsd += costUsd;
|
|
352
357
|
} catch {}
|
|
353
358
|
}
|
|
354
359
|
|
|
@@ -605,6 +610,7 @@ export async function runAgentLoop(
|
|
|
605
610
|
turnCount,
|
|
606
611
|
totalTextContent,
|
|
607
612
|
lastStopReason,
|
|
613
|
+
cumulativeUsage,
|
|
608
614
|
);
|
|
609
615
|
}
|
|
610
616
|
|
|
@@ -703,6 +709,7 @@ function buildResult(
|
|
|
703
709
|
turnCount: number,
|
|
704
710
|
textContent: string,
|
|
705
711
|
stopReason: string,
|
|
712
|
+
usage?: { inputTokens: number; outputTokens: number; costUsd: number },
|
|
706
713
|
): AgentLoopResult {
|
|
707
714
|
return {
|
|
708
715
|
messages,
|
|
@@ -711,6 +718,7 @@ function buildResult(
|
|
|
711
718
|
turnCount,
|
|
712
719
|
textContent,
|
|
713
720
|
stopReason,
|
|
721
|
+
usage,
|
|
714
722
|
};
|
|
715
723
|
}
|
|
716
724
|
|