@invokehq/cli 0.1.8
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/LICENSE +21 -0
- package/index.js +122 -0
- package/package.json +35 -0
- package/trace.js +63 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 joel4893
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/index.js
ADDED
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
const { Command } = require('commander');
|
|
4
|
+
const chalk = require('chalk');
|
|
5
|
+
const fs = require('fs-extra');
|
|
6
|
+
const os = require('os');
|
|
7
|
+
const path = require('path');
|
|
8
|
+
const pkg = require(path.resolve(__dirname, 'package.json'));
|
|
9
|
+
|
|
10
|
+
const program = new Command();
|
|
11
|
+
const CONTEXT_DIR = path.join(process.cwd(), '.agentgate');
|
|
12
|
+
const CONTEXT_FILE = path.join(CONTEXT_DIR, 'context.json');
|
|
13
|
+
const CONFIG_DIR = path.join(os.homedir(), '.invoke');
|
|
14
|
+
const CONFIG_FILE = path.join(CONFIG_DIR, 'config.json');
|
|
15
|
+
|
|
16
|
+
async function readConfig() {
|
|
17
|
+
if (!(await fs.pathExists(CONFIG_FILE))) {
|
|
18
|
+
return {};
|
|
19
|
+
}
|
|
20
|
+
return fs.readJson(CONFIG_FILE);
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
async function writeConfig(config) {
|
|
24
|
+
await fs.ensureDir(CONFIG_DIR);
|
|
25
|
+
await fs.writeJson(CONFIG_FILE, config, { spaces: 2 });
|
|
26
|
+
await fs.chmod(CONFIG_FILE, 0o600).catch(() => {});
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
function parseGitHubPath(input) {
|
|
30
|
+
// Handles https://github.com/owner/repo and git@github.com:owner/repo
|
|
31
|
+
const regex = /(?:https?:\/\/github\.com\/|git@github\.com:)([^/]+)\/([^/.]+?)(?:\.git)?(?:\/)?$/;
|
|
32
|
+
const match = input.match(regex);
|
|
33
|
+
return match ? `${match[1]}/${match[2]}` : input;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
program
|
|
37
|
+
.name('invoke')
|
|
38
|
+
.alias('agentgate')
|
|
39
|
+
.version(pkg.version);
|
|
40
|
+
|
|
41
|
+
program
|
|
42
|
+
.command('login')
|
|
43
|
+
.description('Authenticate to your Invoke runtime')
|
|
44
|
+
.requiredOption('--api-key <key>', 'Invoke API key')
|
|
45
|
+
.option('--base-url <url>', 'Invoke runtime URL', 'https://agentgate-ai.onrender.com')
|
|
46
|
+
.action(async (options) => {
|
|
47
|
+
const config = {
|
|
48
|
+
baseUrl: options.baseUrl.replace(/\/+$/, ''),
|
|
49
|
+
apiKey: options.apiKey,
|
|
50
|
+
updatedAt: new Date().toISOString()
|
|
51
|
+
};
|
|
52
|
+
|
|
53
|
+
await writeConfig(config);
|
|
54
|
+
console.log(chalk.green(`✔ Logged in to ${config.baseUrl}`));
|
|
55
|
+
});
|
|
56
|
+
|
|
57
|
+
program
|
|
58
|
+
.command('wrap')
|
|
59
|
+
.description('Prepare repository context')
|
|
60
|
+
.argument('<provider>', 'e.g., github')
|
|
61
|
+
.option('-p, --path <path>', 'Repository URL or owner/repo', '.')
|
|
62
|
+
.action(async (provider, options) => {
|
|
63
|
+
const normalizedProvider = provider.toLowerCase();
|
|
64
|
+
const supported = ['github'];
|
|
65
|
+
|
|
66
|
+
if (!supported.includes(normalizedProvider)) {
|
|
67
|
+
console.error(chalk.red(`Error: Unsupported provider "${provider}". Supported: ${supported.join(', ')}`));
|
|
68
|
+
process.exit(1);
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
let target = options.path;
|
|
72
|
+
if (normalizedProvider === 'github') target = parseGitHubPath(options.path);
|
|
73
|
+
|
|
74
|
+
console.log(chalk.blue(`[AgentGate] Wrapping ${chalk.bold(normalizedProvider)} repository: ${chalk.cyan(target)}...`));
|
|
75
|
+
|
|
76
|
+
const context = {
|
|
77
|
+
provider: normalizedProvider,
|
|
78
|
+
repoIdentifier: target,
|
|
79
|
+
timestamp: new Date().toISOString(),
|
|
80
|
+
status: 'wrapped'
|
|
81
|
+
};
|
|
82
|
+
|
|
83
|
+
try {
|
|
84
|
+
await fs.ensureDir(CONTEXT_DIR);
|
|
85
|
+
await fs.writeJson(CONTEXT_FILE, context, { spaces: 2 });
|
|
86
|
+
console.log(chalk.green(`✔ Context saved to .agentgate/context.json`));
|
|
87
|
+
} catch (err) {
|
|
88
|
+
console.error(chalk.red('Failed to save context:'), err.message);
|
|
89
|
+
}
|
|
90
|
+
});
|
|
91
|
+
|
|
92
|
+
program
|
|
93
|
+
.command('upload')
|
|
94
|
+
.description('Upload context to AgentGate')
|
|
95
|
+
.action(async () => {
|
|
96
|
+
if (!await fs.pathExists(CONTEXT_FILE)) {
|
|
97
|
+
console.error(chalk.red('Error: No context found. Run "invoke wrap github --path <url>" first.'));
|
|
98
|
+
return;
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
const config = await readConfig();
|
|
102
|
+
const apiKey = process.env.AGENTGATE_API_KEY || process.env.TRACE_API_KEY || config.apiKey;
|
|
103
|
+
if (!apiKey) {
|
|
104
|
+
console.warn(chalk.yellow('⚠ Warning: no Invoke API key found. Run "invoke login --api-key <key>" first.'));
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
try {
|
|
108
|
+
const context = await fs.readJson(CONTEXT_FILE);
|
|
109
|
+
console.log(chalk.blue(`[AgentGate] Synchronizing context for ${chalk.bold(context.repoIdentifier)} with backend...`));
|
|
110
|
+
|
|
111
|
+
context.status = 'active';
|
|
112
|
+
context.lastUploaded = new Date().toISOString();
|
|
113
|
+
|
|
114
|
+
await fs.writeJson(CONTEXT_FILE, context, { spaces: 2 });
|
|
115
|
+
await new Promise(r => setTimeout(r, 500)); // Simulating network latency
|
|
116
|
+
console.log(chalk.green(`✔ Success: Repository context is now active.`));
|
|
117
|
+
} catch (err) {
|
|
118
|
+
console.error(chalk.red('Upload failed:'), err.message);
|
|
119
|
+
}
|
|
120
|
+
});
|
|
121
|
+
|
|
122
|
+
program.parse(process.argv);
|
package/package.json
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@invokehq/cli",
|
|
3
|
+
"version": "0.1.8",
|
|
4
|
+
"description": "Invoke CLI",
|
|
5
|
+
"main": "trace.js",
|
|
6
|
+
"bin": {
|
|
7
|
+
"invoke": "index.js",
|
|
8
|
+
"agentgate": "index.js"
|
|
9
|
+
},
|
|
10
|
+
"scripts": {
|
|
11
|
+
"build": "echo 'no build step'"
|
|
12
|
+
},
|
|
13
|
+
"files": [
|
|
14
|
+
"index.js",
|
|
15
|
+
"trace.js"
|
|
16
|
+
],
|
|
17
|
+
"dependencies": {
|
|
18
|
+
"axios": "^1.6.0",
|
|
19
|
+
"axios-retry": "^4.5.0",
|
|
20
|
+
"chalk": "^4.1.2",
|
|
21
|
+
"commander": "^11.0.0",
|
|
22
|
+
"dotenv": "^16.4.5",
|
|
23
|
+
"fs-extra": "^11.1.1"
|
|
24
|
+
},
|
|
25
|
+
"engines": {
|
|
26
|
+
"node": ">=16.0.0"
|
|
27
|
+
},
|
|
28
|
+
"repository": {
|
|
29
|
+
"type": "git",
|
|
30
|
+
"url": "git+https://github.com/joel4893/agentgate-cli.git"
|
|
31
|
+
},
|
|
32
|
+
"publishConfig": {
|
|
33
|
+
"access": "public"
|
|
34
|
+
}
|
|
35
|
+
}
|
package/trace.js
ADDED
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
const fs = require('fs-extra');
|
|
2
|
+
const os = require('os');
|
|
3
|
+
const path = require('path');
|
|
4
|
+
const axios = require('axios');
|
|
5
|
+
|
|
6
|
+
// Load .env from the project root where the CLI is being executed
|
|
7
|
+
require('dotenv').config({ path: path.resolve(process.cwd(), '.env') });
|
|
8
|
+
|
|
9
|
+
// Load package info once at startup
|
|
10
|
+
const pkg = require(path.resolve(__dirname, 'package.json'));
|
|
11
|
+
const CONFIG_FILE = path.join(os.homedir(), '.invoke', 'config.json');
|
|
12
|
+
|
|
13
|
+
async function readConfig() {
|
|
14
|
+
if (!(await fs.pathExists(CONFIG_FILE))) {
|
|
15
|
+
return {};
|
|
16
|
+
}
|
|
17
|
+
return fs.readJson(CONFIG_FILE);
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
const trace = {
|
|
21
|
+
call: async (action, params) => {
|
|
22
|
+
// Get context from the local wrap
|
|
23
|
+
const contextPath = path.join(process.cwd(), '.agentgate', 'context.json');
|
|
24
|
+
|
|
25
|
+
if (!(await fs.pathExists(contextPath))) {
|
|
26
|
+
throw new Error("Local context not found. Run 'invoke wrap' first.");
|
|
27
|
+
}
|
|
28
|
+
const context = await fs.readJson(contextPath);
|
|
29
|
+
const config = await readConfig();
|
|
30
|
+
|
|
31
|
+
// The SDK now points to the Agentgate Backend Service
|
|
32
|
+
const baseUrl = process.env.AGENTGATE_API_URL || config.baseUrl || "http://localhost:8000";
|
|
33
|
+
const AGENTGATE_SERVER = `${baseUrl.replace(/\/+$/, '')}/call`;
|
|
34
|
+
const apiKey = process.env.AGENTGATE_API_KEY || process.env.TRACE_API_KEY || config.apiKey;
|
|
35
|
+
|
|
36
|
+
try {
|
|
37
|
+
const response = await axios.post(AGENTGATE_SERVER, {
|
|
38
|
+
action,
|
|
39
|
+
repository: context.repoIdentifier,
|
|
40
|
+
parameters: params
|
|
41
|
+
}, {
|
|
42
|
+
timeout: 10000, // 10 second timeout
|
|
43
|
+
headers: {
|
|
44
|
+
'User-Agent': `agentgate-cli-sdk/${pkg.version}`,
|
|
45
|
+
'Content-Type': 'application/json',
|
|
46
|
+
...(apiKey ? { Authorization: `Bearer ${apiKey}` } : {})
|
|
47
|
+
}
|
|
48
|
+
});
|
|
49
|
+
|
|
50
|
+
return response.data;
|
|
51
|
+
} catch (error) {
|
|
52
|
+
// Controllable: The SDK can handle specific error types from the server
|
|
53
|
+
if (error.code === 'ECONNREFUSED') {
|
|
54
|
+
throw new Error("Agentgate Backend is offline. Reliability check failed.");
|
|
55
|
+
}
|
|
56
|
+
throw new Error(
|
|
57
|
+
`Agentgate [${error.response?.status || 'Network'}]: ${error.response?.data?.error || error.response?.statusText || error.message}`
|
|
58
|
+
);
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
};
|
|
62
|
+
|
|
63
|
+
module.exports = { trace };
|