@invokehq/cli 0.2.2 → 0.2.4
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/README.md +887 -0
- package/agentify.py +1913 -0
- package/bin/invoke.js +74 -0
- package/package.json +19 -25
- package/pyproject.toml +28 -0
- package/LICENSE +0 -21
- package/index.js +0 -421
- package/trace.js +0 -62
package/bin/invoke.js
ADDED
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
const { spawn, spawnSync } = require("node:child_process");
|
|
4
|
+
const path = require("node:path");
|
|
5
|
+
|
|
6
|
+
const cliPath = path.resolve(__dirname, "..", "agentify.py");
|
|
7
|
+
|
|
8
|
+
function candidates() {
|
|
9
|
+
if (process.env.INVOKE_PYTHON) {
|
|
10
|
+
return [{ command: process.env.INVOKE_PYTHON, args: [] }];
|
|
11
|
+
}
|
|
12
|
+
if (process.env.AGENTGATE_PYTHON) {
|
|
13
|
+
return [{ command: process.env.AGENTGATE_PYTHON, args: [] }];
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
if (process.platform === "win32") {
|
|
17
|
+
return [
|
|
18
|
+
{ command: "py", args: ["-3"] },
|
|
19
|
+
{ command: "python", args: [] },
|
|
20
|
+
{ command: "python3", args: [] },
|
|
21
|
+
];
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
return [
|
|
25
|
+
{ command: "python3", args: [] },
|
|
26
|
+
{ command: "python", args: [] },
|
|
27
|
+
];
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
function findPython() {
|
|
31
|
+
for (const candidate of candidates()) {
|
|
32
|
+
const check = spawnSync(candidate.command, [...candidate.args, "--version"], {
|
|
33
|
+
encoding: "utf8",
|
|
34
|
+
stdio: "pipe",
|
|
35
|
+
});
|
|
36
|
+
if (check.status === 0) {
|
|
37
|
+
return candidate;
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
return null;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
function normalizeArgs(argv) {
|
|
44
|
+
if (argv[0] === "agentify") {
|
|
45
|
+
return argv.slice(1);
|
|
46
|
+
}
|
|
47
|
+
return argv;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
const python = findPython();
|
|
51
|
+
|
|
52
|
+
if (!python) {
|
|
53
|
+
console.error(
|
|
54
|
+
"invoke: Python 3 is required. Install Python 3 or set INVOKE_PYTHON to its executable path."
|
|
55
|
+
);
|
|
56
|
+
process.exit(127);
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
const child = spawn(python.command, [...python.args, cliPath, ...normalizeArgs(process.argv.slice(2))], {
|
|
60
|
+
stdio: "inherit",
|
|
61
|
+
});
|
|
62
|
+
|
|
63
|
+
child.on("error", (error) => {
|
|
64
|
+
console.error(`invoke: failed to start Python: ${error.message}`);
|
|
65
|
+
process.exit(127);
|
|
66
|
+
});
|
|
67
|
+
|
|
68
|
+
child.on("exit", (code, signal) => {
|
|
69
|
+
if (signal) {
|
|
70
|
+
process.kill(process.pid, signal);
|
|
71
|
+
return;
|
|
72
|
+
}
|
|
73
|
+
process.exit(code ?? 1);
|
|
74
|
+
});
|
package/package.json
CHANGED
|
@@ -1,35 +1,29 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@invokehq/cli",
|
|
3
|
-
"version": "0.2.
|
|
4
|
-
"description": "Invoke
|
|
5
|
-
"
|
|
3
|
+
"version": "0.2.4",
|
|
4
|
+
"description": "CLI for Invoke, execution reliability infrastructure for AI agents.",
|
|
5
|
+
"license": "Apache-2.0",
|
|
6
6
|
"bin": {
|
|
7
|
-
"invoke": "
|
|
8
|
-
"
|
|
9
|
-
},
|
|
10
|
-
"scripts": {
|
|
11
|
-
"build": "echo 'no build step'"
|
|
7
|
+
"invoke": "bin/invoke.js",
|
|
8
|
+
"agentify": "bin/invoke.js"
|
|
12
9
|
},
|
|
13
10
|
"files": [
|
|
14
|
-
"
|
|
15
|
-
"
|
|
11
|
+
"agentify.py",
|
|
12
|
+
"bin",
|
|
13
|
+
"README.md",
|
|
14
|
+
"pyproject.toml"
|
|
16
15
|
],
|
|
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
16
|
"engines": {
|
|
26
|
-
"node": ">=
|
|
17
|
+
"node": ">=18"
|
|
27
18
|
},
|
|
28
|
-
"
|
|
29
|
-
"
|
|
30
|
-
"url": "git+https://github.com/joel4893/agentgate-cli.git"
|
|
19
|
+
"scripts": {
|
|
20
|
+
"test": "node --test tests/node/*.test.js"
|
|
31
21
|
},
|
|
32
|
-
"
|
|
33
|
-
"
|
|
34
|
-
|
|
22
|
+
"keywords": [
|
|
23
|
+
"invoke",
|
|
24
|
+
"mcp",
|
|
25
|
+
"ai-agents",
|
|
26
|
+
"cli",
|
|
27
|
+
"npx"
|
|
28
|
+
]
|
|
35
29
|
}
|
package/pyproject.toml
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
requires = ["setuptools>=61.0"]
|
|
3
|
+
build-backend = "setuptools.build_meta"
|
|
4
|
+
|
|
5
|
+
[project]
|
|
6
|
+
name = "invoke-cli"
|
|
7
|
+
version = "0.1.0"
|
|
8
|
+
description = "Generate Invoke-ready MCP wrappers for PostgreSQL, OpenAPI, and SaaS apps."
|
|
9
|
+
readme = "README.md"
|
|
10
|
+
requires-python = ">=3.8"
|
|
11
|
+
license = {text = "Apache-2.0"}
|
|
12
|
+
authors = [
|
|
13
|
+
{name = "Joel", email = "joel@example.com"}
|
|
14
|
+
]
|
|
15
|
+
keywords = ["mcp", "ai-agents", "llm", "automation", "gateway"]
|
|
16
|
+
dependencies = [
|
|
17
|
+
"httpx>=0.24.0",
|
|
18
|
+
]
|
|
19
|
+
|
|
20
|
+
[project.optional-dependencies]
|
|
21
|
+
dev = ["build", "twine"]
|
|
22
|
+
|
|
23
|
+
[project.scripts]
|
|
24
|
+
invoke = "agentify:main"
|
|
25
|
+
agentify = "agentify:main"
|
|
26
|
+
|
|
27
|
+
[tool.setuptools.py-modules]
|
|
28
|
+
modules = ["agentify"]
|
package/LICENSE
DELETED
|
@@ -1,21 +0,0 @@
|
|
|
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
DELETED
|
@@ -1,421 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
const { Command } = require('commander');
|
|
3
|
-
const axios = require('axios');
|
|
4
|
-
const chalk = require('chalk');
|
|
5
|
-
const fs = require('fs-extra');
|
|
6
|
-
const os = require('os');
|
|
7
|
-
const path = require('path');
|
|
8
|
-
const readline = require('readline');
|
|
9
|
-
const pkg = require(path.resolve(__dirname, 'package.json'));
|
|
10
|
-
|
|
11
|
-
const program = new Command();
|
|
12
|
-
const DEFAULT_BASE_URL = process.env.INVOKE_BASE_URL || process.env.AGENTGATE_API_URL || 'https://api.invokehq.run';
|
|
13
|
-
const CONTEXT_DIR = path.join(process.cwd(), '.agentgate');
|
|
14
|
-
const CONTEXT_FILE = path.join(CONTEXT_DIR, 'context.json');
|
|
15
|
-
const CONFIG_DIR = path.join(os.homedir(), '.invoke');
|
|
16
|
-
const CONFIG_FILE = path.join(CONFIG_DIR, 'config.json');
|
|
17
|
-
|
|
18
|
-
async function readConfig() {
|
|
19
|
-
if (!(await fs.pathExists(CONFIG_FILE))) {
|
|
20
|
-
return {};
|
|
21
|
-
}
|
|
22
|
-
return fs.readJson(CONFIG_FILE);
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
async function writeConfig(config) {
|
|
26
|
-
await fs.ensureDir(CONFIG_DIR);
|
|
27
|
-
await fs.writeJson(CONFIG_FILE, config, { spaces: 2 });
|
|
28
|
-
await fs.chmod(CONFIG_FILE, 0o600).catch(() => {});
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
async function readContext() {
|
|
32
|
-
if (!(await fs.pathExists(CONTEXT_FILE))) {
|
|
33
|
-
return null;
|
|
34
|
-
}
|
|
35
|
-
return fs.readJson(CONTEXT_FILE);
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
async function promptSecret(query) {
|
|
39
|
-
if (!process.stdin.isTTY) {
|
|
40
|
-
return '';
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
return new Promise((resolve) => {
|
|
44
|
-
const mutableStdout = new (require('stream').Writable)({
|
|
45
|
-
write(chunk, encoding, callback) {
|
|
46
|
-
if (!this.muted) {
|
|
47
|
-
process.stdout.write(chunk, encoding);
|
|
48
|
-
}
|
|
49
|
-
callback();
|
|
50
|
-
}
|
|
51
|
-
});
|
|
52
|
-
|
|
53
|
-
const rl = readline.createInterface({
|
|
54
|
-
input: process.stdin,
|
|
55
|
-
output: mutableStdout,
|
|
56
|
-
terminal: true
|
|
57
|
-
});
|
|
58
|
-
|
|
59
|
-
mutableStdout.muted = false;
|
|
60
|
-
rl.question(chalk.cyan(query), (answer) => {
|
|
61
|
-
rl.close();
|
|
62
|
-
process.stdout.write('\n');
|
|
63
|
-
resolve(answer.trim());
|
|
64
|
-
});
|
|
65
|
-
mutableStdout.muted = true;
|
|
66
|
-
});
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
function maskKey(apiKey) {
|
|
70
|
-
if (!apiKey) {
|
|
71
|
-
return 'not set';
|
|
72
|
-
}
|
|
73
|
-
if (apiKey.length <= 10) {
|
|
74
|
-
return `${apiKey.slice(0, 4)}...`;
|
|
75
|
-
}
|
|
76
|
-
return `${apiKey.slice(0, 8)}...${apiKey.slice(-4)}`;
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
function parseJsonArg(value) {
|
|
80
|
-
if (!value) {
|
|
81
|
-
return {};
|
|
82
|
-
}
|
|
83
|
-
const source = value.startsWith('@')
|
|
84
|
-
? fs.readFileSync(path.resolve(process.cwd(), value.slice(1)), 'utf8')
|
|
85
|
-
: value;
|
|
86
|
-
try {
|
|
87
|
-
const parsed = JSON.parse(source);
|
|
88
|
-
if (!parsed || typeof parsed !== 'object' || Array.isArray(parsed)) {
|
|
89
|
-
throw new Error('JSON value must be an object');
|
|
90
|
-
}
|
|
91
|
-
return parsed;
|
|
92
|
-
} catch (error) {
|
|
93
|
-
throw new Error(`Invalid JSON: ${error.message}`);
|
|
94
|
-
}
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
function printJson(data) {
|
|
98
|
-
console.log(JSON.stringify(data, null, 2));
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
async function runtimeRequest(method, route, { data, query, allowMissingKey = false } = {}) {
|
|
102
|
-
const config = await readConfig();
|
|
103
|
-
const baseUrl = (process.env.INVOKE_BASE_URL || process.env.AGENTGATE_API_URL || config.baseUrl || DEFAULT_BASE_URL).replace(/\/+$/, '');
|
|
104
|
-
const apiKey = process.env.INVOKE_API_KEY || process.env.AGENTGATE_API_KEY || process.env.TRACE_API_KEY || config.apiKey;
|
|
105
|
-
|
|
106
|
-
if (!apiKey && !allowMissingKey) {
|
|
107
|
-
throw new Error('Not logged in. Run "invoke login" first.');
|
|
108
|
-
}
|
|
109
|
-
|
|
110
|
-
try {
|
|
111
|
-
const response = await axios({
|
|
112
|
-
method,
|
|
113
|
-
url: `${baseUrl}${route}`,
|
|
114
|
-
params: query,
|
|
115
|
-
data,
|
|
116
|
-
timeout: 15000,
|
|
117
|
-
headers: {
|
|
118
|
-
'User-Agent': `invoke-cli/${pkg.version}`,
|
|
119
|
-
'Content-Type': 'application/json',
|
|
120
|
-
...(apiKey ? { 'X-API-Key': apiKey } : {})
|
|
121
|
-
}
|
|
122
|
-
});
|
|
123
|
-
return { baseUrl, data: response.data };
|
|
124
|
-
} catch (error) {
|
|
125
|
-
if (error.response) {
|
|
126
|
-
const detail = error.response.data?.detail || error.response.data?.error || error.response.statusText;
|
|
127
|
-
throw new Error(`Invoke API ${error.response.status}: ${typeof detail === 'string' ? detail : JSON.stringify(detail)}`);
|
|
128
|
-
}
|
|
129
|
-
if (error.code === 'ECONNREFUSED') {
|
|
130
|
-
throw new Error(`Could not reach Invoke runtime at ${baseUrl}`);
|
|
131
|
-
}
|
|
132
|
-
throw error;
|
|
133
|
-
}
|
|
134
|
-
}
|
|
135
|
-
|
|
136
|
-
function parseGitHubPath(input) {
|
|
137
|
-
// Handles https://github.com/owner/repo and git@github.com:owner/repo
|
|
138
|
-
const regex = /(?:https?:\/\/github\.com\/|git@github\.com:)([^/]+)\/([^/.]+?)(?:\.git)?(?:\/)?$/;
|
|
139
|
-
const match = input.match(regex);
|
|
140
|
-
return match ? `${match[1]}/${match[2]}` : input;
|
|
141
|
-
}
|
|
142
|
-
|
|
143
|
-
program
|
|
144
|
-
.name('invoke')
|
|
145
|
-
.alias('agentgate')
|
|
146
|
-
.version(pkg.version);
|
|
147
|
-
|
|
148
|
-
program
|
|
149
|
-
.command('login')
|
|
150
|
-
.description('Authenticate to your Invoke runtime')
|
|
151
|
-
.option('--base-url <url>', 'Invoke runtime URL')
|
|
152
|
-
.action(async (options) => {
|
|
153
|
-
const baseUrl = (options.baseUrl || DEFAULT_BASE_URL).replace(/\/+$/, '');
|
|
154
|
-
let apiKey = process.env.INVOKE_API_KEY || process.env.AGENTGATE_API_KEY || process.env.TRACE_API_KEY;
|
|
155
|
-
|
|
156
|
-
if (!apiKey) {
|
|
157
|
-
console.log(chalk.dim(`Using Invoke runtime: ${baseUrl}`));
|
|
158
|
-
console.log(chalk.dim('Paste your Invoke API key. Input is hidden.'));
|
|
159
|
-
apiKey = await promptSecret('Invoke API key: ');
|
|
160
|
-
}
|
|
161
|
-
|
|
162
|
-
if (!apiKey) {
|
|
163
|
-
console.error(chalk.red('Error: no API key provided. Run "invoke login" or set INVOKE_API_KEY for automation.'));
|
|
164
|
-
process.exit(1);
|
|
165
|
-
}
|
|
166
|
-
|
|
167
|
-
await writeConfig({
|
|
168
|
-
baseUrl,
|
|
169
|
-
apiKey,
|
|
170
|
-
updatedAt: new Date().toISOString()
|
|
171
|
-
});
|
|
172
|
-
|
|
173
|
-
console.log(chalk.green(`✔ Logged in to Invoke (${baseUrl})`));
|
|
174
|
-
});
|
|
175
|
-
|
|
176
|
-
program
|
|
177
|
-
.command('logout')
|
|
178
|
-
.description('Remove saved Invoke credentials')
|
|
179
|
-
.action(async () => {
|
|
180
|
-
await fs.remove(CONFIG_FILE);
|
|
181
|
-
console.log(chalk.green('✔ Logged out'));
|
|
182
|
-
});
|
|
183
|
-
|
|
184
|
-
program
|
|
185
|
-
.command('status')
|
|
186
|
-
.description('Show login and project context')
|
|
187
|
-
.action(async () => {
|
|
188
|
-
const config = await readConfig();
|
|
189
|
-
const context = await readContext();
|
|
190
|
-
console.log(chalk.bold('Invoke CLI status'));
|
|
191
|
-
console.log(`Version: ${pkg.version}`);
|
|
192
|
-
console.log(`Runtime: ${config.baseUrl || DEFAULT_BASE_URL}`);
|
|
193
|
-
console.log(`API key: ${maskKey(process.env.INVOKE_API_KEY || process.env.AGENTGATE_API_KEY || process.env.TRACE_API_KEY || config.apiKey)}`);
|
|
194
|
-
console.log(`Config: ${await fs.pathExists(CONFIG_FILE) ? CONFIG_FILE : 'not saved'}`);
|
|
195
|
-
console.log(`Project: ${context ? `${context.provider}:${context.repoIdentifier}` : 'not wrapped'}`);
|
|
196
|
-
});
|
|
197
|
-
|
|
198
|
-
program
|
|
199
|
-
.command('config')
|
|
200
|
-
.description('Show or update CLI config')
|
|
201
|
-
.argument('[key]', 'Config key to set, currently only base-url')
|
|
202
|
-
.argument('[value]', 'Value for the config key')
|
|
203
|
-
.action(async (key, value) => {
|
|
204
|
-
const config = await readConfig();
|
|
205
|
-
if (!key) {
|
|
206
|
-
printJson({
|
|
207
|
-
baseUrl: config.baseUrl || DEFAULT_BASE_URL,
|
|
208
|
-
apiKey: maskKey(config.apiKey),
|
|
209
|
-
configFile: CONFIG_FILE
|
|
210
|
-
});
|
|
211
|
-
return;
|
|
212
|
-
}
|
|
213
|
-
if (key !== 'base-url') {
|
|
214
|
-
console.error(chalk.red('Error: only "base-url" can be set.'));
|
|
215
|
-
process.exit(1);
|
|
216
|
-
}
|
|
217
|
-
if (!value) {
|
|
218
|
-
console.error(chalk.red('Error: missing value.'));
|
|
219
|
-
process.exit(1);
|
|
220
|
-
}
|
|
221
|
-
await writeConfig({ ...config, baseUrl: value.replace(/\/+$/, ''), updatedAt: new Date().toISOString() });
|
|
222
|
-
console.log(chalk.green(`✔ base-url set to ${value.replace(/\/+$/, '')}`));
|
|
223
|
-
});
|
|
224
|
-
|
|
225
|
-
program
|
|
226
|
-
.command('wrap')
|
|
227
|
-
.description('Prepare repository context')
|
|
228
|
-
.argument('<provider>', 'e.g., github')
|
|
229
|
-
.option('-p, --path <path>', 'Repository URL or owner/repo', '.')
|
|
230
|
-
.action(async (provider, options) => {
|
|
231
|
-
const normalizedProvider = provider.toLowerCase();
|
|
232
|
-
const supported = ['github'];
|
|
233
|
-
|
|
234
|
-
if (!supported.includes(normalizedProvider)) {
|
|
235
|
-
console.error(chalk.red(`Error: Unsupported provider "${provider}". Supported: ${supported.join(', ')}`));
|
|
236
|
-
process.exit(1);
|
|
237
|
-
}
|
|
238
|
-
|
|
239
|
-
let target = options.path;
|
|
240
|
-
if (normalizedProvider === 'github') target = parseGitHubPath(options.path);
|
|
241
|
-
|
|
242
|
-
console.log(chalk.blue(`[AgentGate] Wrapping ${chalk.bold(normalizedProvider)} repository: ${chalk.cyan(target)}...`));
|
|
243
|
-
|
|
244
|
-
const context = {
|
|
245
|
-
provider: normalizedProvider,
|
|
246
|
-
repoIdentifier: target,
|
|
247
|
-
timestamp: new Date().toISOString(),
|
|
248
|
-
status: 'wrapped'
|
|
249
|
-
};
|
|
250
|
-
|
|
251
|
-
try {
|
|
252
|
-
await fs.ensureDir(CONTEXT_DIR);
|
|
253
|
-
await fs.writeJson(CONTEXT_FILE, context, { spaces: 2 });
|
|
254
|
-
console.log(chalk.green(`✔ Context saved to .agentgate/context.json`));
|
|
255
|
-
} catch (err) {
|
|
256
|
-
console.error(chalk.red('Failed to save context:'), err.message);
|
|
257
|
-
}
|
|
258
|
-
});
|
|
259
|
-
|
|
260
|
-
program
|
|
261
|
-
.command('upload')
|
|
262
|
-
.description('Mark local context as active')
|
|
263
|
-
.action(async () => {
|
|
264
|
-
if (!await fs.pathExists(CONTEXT_FILE)) {
|
|
265
|
-
console.error(chalk.red('Error: No context found. Run "invoke wrap github --path <url>" first.'));
|
|
266
|
-
return;
|
|
267
|
-
}
|
|
268
|
-
|
|
269
|
-
try {
|
|
270
|
-
const context = await fs.readJson(CONTEXT_FILE);
|
|
271
|
-
console.log(chalk.blue(`[Invoke] Activating context for ${chalk.bold(context.repoIdentifier)}...`));
|
|
272
|
-
context.status = 'active';
|
|
273
|
-
context.lastUploaded = new Date().toISOString();
|
|
274
|
-
await fs.writeJson(CONTEXT_FILE, context, { spaces: 2 });
|
|
275
|
-
console.log(chalk.green('✔ Context is active.'));
|
|
276
|
-
} catch (err) {
|
|
277
|
-
console.error(chalk.red('Upload failed:'), err.message);
|
|
278
|
-
}
|
|
279
|
-
});
|
|
280
|
-
|
|
281
|
-
program
|
|
282
|
-
.command('tools')
|
|
283
|
-
.description('List available tools')
|
|
284
|
-
.argument('[query]', 'Optional discovery query')
|
|
285
|
-
.option('--limit <number>', 'Maximum tools to return', '10')
|
|
286
|
-
.option('--json', 'Print raw JSON')
|
|
287
|
-
.action(async (query, options) => {
|
|
288
|
-
try {
|
|
289
|
-
const limit = Number.parseInt(options.limit, 10);
|
|
290
|
-
const route = query ? '/discover' : '/tools';
|
|
291
|
-
const { data } = await runtimeRequest('get', route, { query: query ? { q: query, limit } : undefined });
|
|
292
|
-
if (options.json) {
|
|
293
|
-
printJson(data);
|
|
294
|
-
return;
|
|
295
|
-
}
|
|
296
|
-
const tools = data.tools || [];
|
|
297
|
-
if (!tools.length) {
|
|
298
|
-
console.log(chalk.yellow('No tools found.'));
|
|
299
|
-
return;
|
|
300
|
-
}
|
|
301
|
-
for (const tool of tools) {
|
|
302
|
-
const key = tool.key || tool.name || tool.id;
|
|
303
|
-
const summary = tool.description || tool.summary || tool.capability_card?.description || '';
|
|
304
|
-
console.log(`${chalk.cyan(key)}${summary ? ` - ${summary}` : ''}`);
|
|
305
|
-
}
|
|
306
|
-
} catch (error) {
|
|
307
|
-
console.error(chalk.red(error.message));
|
|
308
|
-
process.exit(1);
|
|
309
|
-
}
|
|
310
|
-
});
|
|
311
|
-
|
|
312
|
-
program
|
|
313
|
-
.command('call')
|
|
314
|
-
.description('Call a tool through Invoke')
|
|
315
|
-
.argument('<tool>', 'Tool key, for example linear.create_issue')
|
|
316
|
-
.argument('[params]', 'JSON params object, or @file.json', '{}')
|
|
317
|
-
.option('--agent-id <id>', 'Agent identifier', 'cli')
|
|
318
|
-
.option('--idempotency-key <key>', 'Idempotency key for safe retries')
|
|
319
|
-
.option('--json', 'Print raw JSON')
|
|
320
|
-
.action(async (tool, paramsArg, options) => {
|
|
321
|
-
try {
|
|
322
|
-
const params = parseJsonArg(paramsArg);
|
|
323
|
-
const context = await readContext();
|
|
324
|
-
const body = {
|
|
325
|
-
tool,
|
|
326
|
-
params,
|
|
327
|
-
agent_id: options.agentId,
|
|
328
|
-
context: {
|
|
329
|
-
source: 'invoke-cli',
|
|
330
|
-
...(context ? { project: context } : {})
|
|
331
|
-
}
|
|
332
|
-
};
|
|
333
|
-
if (options.idempotencyKey) {
|
|
334
|
-
body.idempotency_key = options.idempotencyKey;
|
|
335
|
-
}
|
|
336
|
-
const { data } = await runtimeRequest('post', '/call', { data: body });
|
|
337
|
-
if (options.json) {
|
|
338
|
-
printJson(data);
|
|
339
|
-
return;
|
|
340
|
-
}
|
|
341
|
-
console.log(chalk.green(`Status: ${data.status || (data.success ? 'success' : 'unknown')}`));
|
|
342
|
-
if (data.approval_id) {
|
|
343
|
-
console.log(chalk.yellow(`Approval required: ${data.approval_id}`));
|
|
344
|
-
}
|
|
345
|
-
if (data.latency_ms !== undefined) {
|
|
346
|
-
console.log(`Latency: ${data.latency_ms}ms`);
|
|
347
|
-
}
|
|
348
|
-
printJson(data.result || data);
|
|
349
|
-
} catch (error) {
|
|
350
|
-
console.error(chalk.red(error.message));
|
|
351
|
-
process.exit(1);
|
|
352
|
-
}
|
|
353
|
-
});
|
|
354
|
-
|
|
355
|
-
async function listApprovals(options = {}) {
|
|
356
|
-
const { data } = await runtimeRequest('get', '/approvals');
|
|
357
|
-
if (options.json) {
|
|
358
|
-
printJson(data);
|
|
359
|
-
return;
|
|
360
|
-
}
|
|
361
|
-
const limit = Number.parseInt(options.limit || '20', 10);
|
|
362
|
-
const items = (data.approvals || []).slice(0, limit);
|
|
363
|
-
if (!items.length) {
|
|
364
|
-
console.log(chalk.green('No pending approvals.'));
|
|
365
|
-
return;
|
|
366
|
-
}
|
|
367
|
-
for (const item of items) {
|
|
368
|
-
console.log(`${chalk.cyan(item.id)} ${item.status || ''} ${item.tool || item.tool_key || ''} ${item.reason || ''}`);
|
|
369
|
-
}
|
|
370
|
-
}
|
|
371
|
-
|
|
372
|
-
const approvals = program
|
|
373
|
-
.command('approvals')
|
|
374
|
-
.description('List and manage pending approvals')
|
|
375
|
-
.option('--limit <number>', 'Maximum approvals to show', '20')
|
|
376
|
-
.option('--json', 'Print raw JSON')
|
|
377
|
-
.action(async (options) => {
|
|
378
|
-
try {
|
|
379
|
-
await listApprovals(options);
|
|
380
|
-
} catch (error) {
|
|
381
|
-
console.error(chalk.red(error.message));
|
|
382
|
-
process.exit(1);
|
|
383
|
-
}
|
|
384
|
-
});
|
|
385
|
-
|
|
386
|
-
approvals
|
|
387
|
-
.command('list')
|
|
388
|
-
.description('List approvals')
|
|
389
|
-
.option('--limit <number>', 'Maximum approvals to show', '20')
|
|
390
|
-
.option('--json', 'Print raw JSON')
|
|
391
|
-
.action(async (options) => {
|
|
392
|
-
try {
|
|
393
|
-
await listApprovals(options);
|
|
394
|
-
} catch (error) {
|
|
395
|
-
console.error(chalk.red(error.message));
|
|
396
|
-
process.exit(1);
|
|
397
|
-
}
|
|
398
|
-
});
|
|
399
|
-
|
|
400
|
-
for (const action of ['approve', 'reject']) {
|
|
401
|
-
approvals
|
|
402
|
-
.command(`${action} <id>`)
|
|
403
|
-
.description(`${action[0].toUpperCase()}${action.slice(1)} an approval`)
|
|
404
|
-
.option('--json', 'Print raw JSON')
|
|
405
|
-
.action(async (id, options) => {
|
|
406
|
-
try {
|
|
407
|
-
const { data } = await runtimeRequest('post', `/approvals/${id}/${action}`, { data: {} });
|
|
408
|
-
if (options.json) {
|
|
409
|
-
printJson(data);
|
|
410
|
-
return;
|
|
411
|
-
}
|
|
412
|
-
console.log(chalk.green(`✔ ${action}d ${id}`));
|
|
413
|
-
printJson(data);
|
|
414
|
-
} catch (error) {
|
|
415
|
-
console.error(chalk.red(error.message));
|
|
416
|
-
process.exit(1);
|
|
417
|
-
}
|
|
418
|
-
});
|
|
419
|
-
}
|
|
420
|
-
|
|
421
|
-
program.parse(process.argv);
|
package/trace.js
DELETED
|
@@ -1,62 +0,0 @@
|
|
|
1
|
-
const fs = require('fs-extra');
|
|
2
|
-
const path = require('path');
|
|
3
|
-
const axios = require('axios');
|
|
4
|
-
const os = require('os');
|
|
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
|
-
const DEFAULT_BASE_URL = process.env.INVOKE_BASE_URL || process.env.AGENTGATE_API_URL || "https://api.invokehq.run";
|
|
13
|
-
|
|
14
|
-
const trace = {
|
|
15
|
-
call: async (action, params) => {
|
|
16
|
-
// Get context from the local wrap
|
|
17
|
-
const contextPath = path.join(process.cwd(), '.agentgate', 'context.json');
|
|
18
|
-
|
|
19
|
-
if (!(await fs.pathExists(contextPath))) {
|
|
20
|
-
throw new Error("Local context not found. Run 'agentgate wrap' first.");
|
|
21
|
-
}
|
|
22
|
-
const context = await fs.readJson(contextPath);
|
|
23
|
-
|
|
24
|
-
// Attempt to load stored config from 'invoke login'
|
|
25
|
-
let storedConfig = {};
|
|
26
|
-
if (fs.existsSync(CONFIG_FILE)) {
|
|
27
|
-
storedConfig = fs.readJsonSync(CONFIG_FILE);
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
const baseUrl = process.env.INVOKE_BASE_URL || process.env.AGENTGATE_API_URL || storedConfig.baseUrl || DEFAULT_BASE_URL;
|
|
31
|
-
const endpoint = baseUrl.endsWith('/call') ? baseUrl : `${baseUrl.replace(/\/+$/, '')}/call`;
|
|
32
|
-
|
|
33
|
-
const apiKey = process.env.INVOKE_API_KEY || process.env.AGENTGATE_API_KEY || process.env.TRACE_API_KEY || storedConfig.apiKey;
|
|
34
|
-
|
|
35
|
-
try {
|
|
36
|
-
const response = await axios.post(endpoint, {
|
|
37
|
-
action,
|
|
38
|
-
repository: context.repoIdentifier,
|
|
39
|
-
parameters: params
|
|
40
|
-
}, {
|
|
41
|
-
timeout: 10000, // 10 second timeout
|
|
42
|
-
headers: {
|
|
43
|
-
'User-Agent': `invoke-cli-sdk/${pkg.version}`,
|
|
44
|
-
'Content-Type': 'application/json',
|
|
45
|
-
...(apiKey ? { 'X-API-Key': apiKey } : {})
|
|
46
|
-
}
|
|
47
|
-
});
|
|
48
|
-
|
|
49
|
-
return response.data;
|
|
50
|
-
} catch (error) {
|
|
51
|
-
// Controllable: The SDK can handle specific error types from the server
|
|
52
|
-
if (error.code === 'ECONNREFUSED') {
|
|
53
|
-
throw new Error("Agentgate Backend is offline. Reliability check failed.");
|
|
54
|
-
}
|
|
55
|
-
throw new Error(
|
|
56
|
-
`Agentgate [${error.response?.status || 'Network'}]: ${error.response?.data?.error || error.response?.statusText || error.message}`
|
|
57
|
-
);
|
|
58
|
-
}
|
|
59
|
-
}
|
|
60
|
-
};
|
|
61
|
-
|
|
62
|
-
module.exports = { trace };
|