agentgate 0.1.0 → 0.1.2
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 +2 -3
- package/src/cli.js +85 -51
package/package.json
CHANGED
|
@@ -1,12 +1,11 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "agentgate",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.2",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "API gateway for AI agents with human-in-the-loop write approval",
|
|
6
6
|
"main": "src/index.js",
|
|
7
7
|
"bin": {
|
|
8
|
-
"agentgate": "src/
|
|
9
|
-
"agentgate-keys": "src/cli.js"
|
|
8
|
+
"agentgate": "src/cli.js"
|
|
10
9
|
},
|
|
11
10
|
"engines": {
|
|
12
11
|
"node": ">=18"
|
package/src/cli.js
CHANGED
|
@@ -1,73 +1,107 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
|
|
3
|
-
import {
|
|
3
|
+
import { fileURLToPath } from 'url';
|
|
4
|
+
import { dirname } from 'path';
|
|
5
|
+
|
|
6
|
+
const __filename = fileURLToPath(import.meta.url);
|
|
7
|
+
const __dirname = dirname(__filename);
|
|
4
8
|
|
|
5
9
|
const [,, command, ...args] = process.argv;
|
|
6
10
|
|
|
7
11
|
function printUsage() {
|
|
8
12
|
console.log(`
|
|
9
|
-
|
|
13
|
+
agentgate - API gateway for AI agents with human-in-the-loop write approval
|
|
14
|
+
|
|
15
|
+
Usage: agentgate <command> [options]
|
|
10
16
|
|
|
11
17
|
Commands:
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
18
|
+
start Start the agentgate server
|
|
19
|
+
keys list List all API keys
|
|
20
|
+
keys create <name> Create a new API key
|
|
21
|
+
keys delete <id> Delete an API key by ID
|
|
22
|
+
|
|
23
|
+
Options:
|
|
24
|
+
-p, --port <port> Port to run server on (default: 3050, or PORT env)
|
|
25
|
+
-h, --help Show this help message
|
|
26
|
+
|
|
27
|
+
Examples:
|
|
28
|
+
agentgate start
|
|
29
|
+
agentgate start --port 8080
|
|
30
|
+
agentgate keys create my-agent
|
|
31
|
+
agentgate keys list
|
|
15
32
|
`);
|
|
16
33
|
}
|
|
17
34
|
|
|
18
35
|
async function main() {
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
if (keys.length === 0) {
|
|
23
|
-
console.log('No API keys found.');
|
|
24
|
-
} else {
|
|
25
|
-
console.log('\nAPI Keys:\n');
|
|
26
|
-
for (const k of keys) {
|
|
27
|
-
console.log(` ID: ${k.id}`);
|
|
28
|
-
console.log(` Name: ${k.name}`);
|
|
29
|
-
console.log(` Key: ${k.key_prefix} (hashed - full key shown only at creation)`);
|
|
30
|
-
console.log(` Created: ${k.created_at}`);
|
|
31
|
-
console.log('');
|
|
32
|
-
}
|
|
33
|
-
}
|
|
34
|
-
break;
|
|
36
|
+
if (!command || command === '-h' || command === '--help') {
|
|
37
|
+
printUsage();
|
|
38
|
+
process.exit(0);
|
|
35
39
|
}
|
|
36
40
|
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
process.exit(1);
|
|
41
|
+
if (command === 'start') {
|
|
42
|
+
// Parse port from args
|
|
43
|
+
const portIdx = args.findIndex(a => a === '-p' || a === '--port');
|
|
44
|
+
if (portIdx !== -1 && args[portIdx + 1]) {
|
|
45
|
+
process.env.PORT = args[portIdx + 1];
|
|
43
46
|
}
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
47
|
+
|
|
48
|
+
// Import and run the server
|
|
49
|
+
await import('./index.js');
|
|
50
|
+
} else if (command === 'keys') {
|
|
51
|
+
const subcommand = args[0];
|
|
52
|
+
const { createApiKey, listApiKeys, deleteApiKey } = await import('./lib/db.js');
|
|
53
|
+
|
|
54
|
+
switch (subcommand) {
|
|
55
|
+
case 'list': {
|
|
56
|
+
const keys = listApiKeys();
|
|
57
|
+
if (keys.length === 0) {
|
|
58
|
+
console.log('No API keys found.');
|
|
59
|
+
} else {
|
|
60
|
+
console.log('\nAPI Keys:\n');
|
|
61
|
+
for (const k of keys) {
|
|
62
|
+
console.log(` ID: ${k.id}`);
|
|
63
|
+
console.log(` Name: ${k.name}`);
|
|
64
|
+
console.log(` Prefix: ${k.key_prefix}...`);
|
|
65
|
+
console.log(` Created: ${k.created_at}`);
|
|
66
|
+
console.log('');
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
break;
|
|
58
70
|
}
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
71
|
+
case 'create': {
|
|
72
|
+
const name = args[1];
|
|
73
|
+
if (!name) {
|
|
74
|
+
console.error('Error: Please provide a name for the API key');
|
|
75
|
+
console.error('Usage: agentgate keys create <name>');
|
|
76
|
+
process.exit(1);
|
|
77
|
+
}
|
|
78
|
+
const result = createApiKey(name);
|
|
79
|
+
console.log('\n✅ API key created!\n');
|
|
80
|
+
console.log(` Name: ${name}`);
|
|
81
|
+
console.log(` Key: ${result.key}`);
|
|
82
|
+
console.log('\n⚠️ Save this key now - it cannot be retrieved later!\n');
|
|
83
|
+
break;
|
|
64
84
|
}
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
85
|
+
case 'delete': {
|
|
86
|
+
const id = args[1];
|
|
87
|
+
if (!id) {
|
|
88
|
+
console.error('Error: Please provide the ID of the key to delete');
|
|
89
|
+
console.error('Usage: agentgate keys delete <id>');
|
|
90
|
+
process.exit(1);
|
|
91
|
+
}
|
|
92
|
+
deleteApiKey(id);
|
|
93
|
+
console.log(`\n✅ API key ${id} deleted.\n`);
|
|
94
|
+
break;
|
|
95
|
+
}
|
|
96
|
+
default:
|
|
97
|
+
console.error(`Unknown keys subcommand: ${subcommand}`);
|
|
98
|
+
console.error('Available: list, create, delete');
|
|
99
|
+
process.exit(1);
|
|
100
|
+
}
|
|
101
|
+
} else {
|
|
102
|
+
console.error(`Unknown command: ${command}`);
|
|
69
103
|
printUsage();
|
|
70
|
-
|
|
104
|
+
process.exit(1);
|
|
71
105
|
}
|
|
72
106
|
}
|
|
73
107
|
|