@agenticmail/enterprise 0.5.195 → 0.5.196
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/cli-serve-LGKXTAZ3.js +114 -0
- package/dist/cli.js +1 -1
- package/package.json +1 -1
- package/src/cli-serve.ts +59 -1
|
@@ -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-P7UOPB2B.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,7 +53,7 @@ Skill Development:
|
|
|
53
53
|
break;
|
|
54
54
|
case "serve":
|
|
55
55
|
case "start":
|
|
56
|
-
import("./cli-serve-
|
|
56
|
+
import("./cli-serve-LGKXTAZ3.js").then((m) => m.runServe(args.slice(1))).catch(fatal);
|
|
57
57
|
break;
|
|
58
58
|
case "agent":
|
|
59
59
|
import("./cli-agent-XYXSRD2Q.js").then((m) => m.runAgent(args.slice(1))).catch(fatal);
|
package/package.json
CHANGED
package/src/cli-serve.ts
CHANGED
|
@@ -43,13 +43,71 @@ function loadEnvFile(): void {
|
|
|
43
43
|
}
|
|
44
44
|
}
|
|
45
45
|
|
|
46
|
+
/**
|
|
47
|
+
* If JWT_SECRET or AGENTICMAIL_VAULT_KEY are missing, generate them
|
|
48
|
+
* and append to ~/.agenticmail/.env so they persist across restarts.
|
|
49
|
+
*/
|
|
50
|
+
async function ensureSecrets(): Promise<void> {
|
|
51
|
+
const { randomUUID } = await import('crypto');
|
|
52
|
+
const envDir = join(homedir(), '.agenticmail');
|
|
53
|
+
const envPath = join(envDir, '.env');
|
|
54
|
+
let dirty = false;
|
|
55
|
+
|
|
56
|
+
if (!process.env.JWT_SECRET) {
|
|
57
|
+
process.env.JWT_SECRET = randomUUID() + randomUUID();
|
|
58
|
+
dirty = true;
|
|
59
|
+
console.log('[startup] Generated new JWT_SECRET (existing sessions will need to re-login)');
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
if (!process.env.AGENTICMAIL_VAULT_KEY) {
|
|
63
|
+
process.env.AGENTICMAIL_VAULT_KEY = randomUUID() + randomUUID();
|
|
64
|
+
dirty = true;
|
|
65
|
+
console.log('[startup] Generated new AGENTICMAIL_VAULT_KEY');
|
|
66
|
+
console.log('[startup] ⚠️ Previously encrypted credentials will need to be re-entered in the dashboard');
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
if (dirty) {
|
|
70
|
+
try {
|
|
71
|
+
if (!existsSync(envDir)) {
|
|
72
|
+
const { mkdirSync } = await import('fs');
|
|
73
|
+
mkdirSync(envDir, { recursive: true });
|
|
74
|
+
}
|
|
75
|
+
// Append new secrets to .env (don't overwrite existing)
|
|
76
|
+
const { appendFileSync } = await import('fs');
|
|
77
|
+
const lines: string[] = [];
|
|
78
|
+
// Read existing to avoid duplicates
|
|
79
|
+
let existing = '';
|
|
80
|
+
if (existsSync(envPath)) {
|
|
81
|
+
existing = readFileSync(envPath, 'utf8');
|
|
82
|
+
}
|
|
83
|
+
if (!existing.includes('JWT_SECRET=')) {
|
|
84
|
+
lines.push(`JWT_SECRET=${process.env.JWT_SECRET}`);
|
|
85
|
+
}
|
|
86
|
+
if (!existing.includes('AGENTICMAIL_VAULT_KEY=')) {
|
|
87
|
+
lines.push(`AGENTICMAIL_VAULT_KEY=${process.env.AGENTICMAIL_VAULT_KEY}`);
|
|
88
|
+
}
|
|
89
|
+
if (lines.length) {
|
|
90
|
+
appendFileSync(envPath, '\n' + lines.join('\n') + '\n', { mode: 0o600 });
|
|
91
|
+
console.log(`[startup] Saved secrets to ${envPath}`);
|
|
92
|
+
}
|
|
93
|
+
} catch (e: any) {
|
|
94
|
+
console.warn(`[startup] Could not save secrets to ${envPath}: ${e.message}`);
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
|
|
46
99
|
export async function runServe(_args: string[]) {
|
|
47
100
|
loadEnvFile();
|
|
48
101
|
|
|
49
102
|
const DATABASE_URL = process.env.DATABASE_URL;
|
|
50
|
-
const JWT_SECRET = process.env.JWT_SECRET || 'auto-' + Date.now();
|
|
51
103
|
const PORT = parseInt(process.env.PORT || '8080', 10);
|
|
52
104
|
|
|
105
|
+
// Auto-generate and persist secrets if missing
|
|
106
|
+
await ensureSecrets();
|
|
107
|
+
|
|
108
|
+
const JWT_SECRET = process.env.JWT_SECRET!;
|
|
109
|
+
const VAULT_KEY = process.env.AGENTICMAIL_VAULT_KEY!;
|
|
110
|
+
|
|
53
111
|
if (!DATABASE_URL) {
|
|
54
112
|
console.error('ERROR: DATABASE_URL is required.');
|
|
55
113
|
console.error('');
|