agentgate 0.1.4 → 0.1.5
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/package.json +1 -1
- package/src/cli.js +16 -21
- package/src/lib/db.js +7 -4
package/package.json
CHANGED
package/src/cli.js
CHANGED
|
@@ -12,10 +12,9 @@ function printUsage() {
|
|
|
12
12
|
console.log(`
|
|
13
13
|
agentgate - API gateway for AI agents with human-in-the-loop write approval
|
|
14
14
|
|
|
15
|
-
Usage: agentgate
|
|
15
|
+
Usage: agentgate <command> [options]
|
|
16
16
|
|
|
17
17
|
Commands:
|
|
18
|
-
(default) Start the agentgate server
|
|
19
18
|
start Start the agentgate server
|
|
20
19
|
keys list List all API keys
|
|
21
20
|
keys create <name> Create a new API key
|
|
@@ -25,37 +24,33 @@ Options:
|
|
|
25
24
|
-p, --port <port> Port to run server on (default: 3050, or PORT env)
|
|
26
25
|
-h, --help Show this help message
|
|
27
26
|
|
|
27
|
+
Environment:
|
|
28
|
+
PORT Server port (default: 3050)
|
|
29
|
+
AGENTGATE_DATA_DIR Data directory (default: ~/.agentgate/)
|
|
30
|
+
|
|
28
31
|
Examples:
|
|
29
|
-
agentgate
|
|
32
|
+
agentgate start
|
|
30
33
|
agentgate start --port 8080
|
|
31
34
|
agentgate keys create my-agent
|
|
32
35
|
agentgate keys list
|
|
33
36
|
`);
|
|
34
37
|
}
|
|
35
38
|
|
|
36
|
-
async function startServer(args) {
|
|
37
|
-
// Parse port from args
|
|
38
|
-
const portIdx = args.findIndex(a => a === '-p' || a === '--port');
|
|
39
|
-
if (portIdx !== -1 && args[portIdx + 1]) {
|
|
40
|
-
process.env.PORT = args[portIdx + 1];
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
// Import and run the server
|
|
44
|
-
await import('./index.js');
|
|
45
|
-
}
|
|
46
|
-
|
|
47
39
|
async function main() {
|
|
48
|
-
if (command === '-h' || command === '--help') {
|
|
40
|
+
if (!command || command === '-h' || command === '--help') {
|
|
49
41
|
printUsage();
|
|
50
42
|
process.exit(0);
|
|
51
43
|
}
|
|
52
44
|
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
45
|
+
if (command === 'start') {
|
|
46
|
+
// Parse port from args
|
|
47
|
+
const portIdx = args.findIndex(a => a === '-p' || a === '--port');
|
|
48
|
+
if (portIdx !== -1 && args[portIdx + 1]) {
|
|
49
|
+
process.env.PORT = args[portIdx + 1];
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
// Import and run the server
|
|
53
|
+
await import('./index.js');
|
|
59
54
|
} else if (command === 'keys') {
|
|
60
55
|
const subcommand = args[0];
|
|
61
56
|
const { createApiKey, listApiKeys, deleteApiKey } = await import('./lib/db.js');
|
package/src/lib/db.js
CHANGED
|
@@ -1,11 +1,14 @@
|
|
|
1
1
|
import Database from 'better-sqlite3';
|
|
2
2
|
import { nanoid } from 'nanoid';
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
3
|
+
import { join } from 'path';
|
|
4
|
+
import { homedir } from 'os';
|
|
5
|
+
import { mkdirSync } from 'fs';
|
|
5
6
|
import bcrypt from 'bcrypt';
|
|
6
7
|
|
|
7
|
-
|
|
8
|
-
const
|
|
8
|
+
// Data directory: AGENTGATE_DATA_DIR env var, or ~/.agentgate/
|
|
9
|
+
const dataDir = process.env.AGENTGATE_DATA_DIR || join(homedir(), '.agentgate');
|
|
10
|
+
mkdirSync(dataDir, { recursive: true });
|
|
11
|
+
const dbPath = join(dataDir, 'data.db');
|
|
9
12
|
|
|
10
13
|
const db = new Database(dbPath);
|
|
11
14
|
|