@invokehq/cli 0.1.8 → 0.1.9

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.
Files changed (3) hide show
  1. package/index.js +88 -122
  2. package/package.json +35 -35
  3. package/trace.js +50 -63
package/index.js CHANGED
@@ -1,122 +1,88 @@
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);
1
+
2
+
3
+ const { Command } = require('commander');
4
+ const chalk = require('chalk');
5
+ const fs = require('fs-extra');
6
+ const path = require('path');
7
+ const pkg = require(path.resolve(__dirname, 'package.json'));
8
+
9
+ const program = new Command();
10
+ const CONTEXT_DIR = path.join(process.cwd(), '.agentgate');
11
+ const CONTEXT_FILE = path.join(CONTEXT_DIR, 'context.json');
12
+
13
+ function parseGitHubPath(input) {
14
+ // Handles https://github.com/owner/repo and git@github.com:owner/repo
15
+ const regex = /(?:https?:\/\/github\.com\/|git@github\.com:)([^/]+)\/([^/.]+?)(?:\.git)?(?:\/)?$/;
16
+ const match = input.match(regex);
17
+ return match ? `${match[1]}/${match[2]}` : input;
18
+ }
19
+
20
+ program
21
+ .name('agentgate')
22
+ .version(pkg.version);
23
+
24
+ program
25
+ .command('wrap')
26
+ .description('Prepare repository context')
27
+ .argument('<provider>', 'e.g., github')
28
+ .option('-p, --path <path>', 'Repository URL or owner/repo', '.')
29
+ .action(async (provider, options) => {
30
+ const normalizedProvider = provider.toLowerCase();
31
+ const supported = ['github'];
32
+
33
+ if (!supported.includes(normalizedProvider)) {
34
+ console.error(chalk.red(`Error: Unsupported provider "${provider}". Supported: ${supported.join(', ')}`));
35
+ process.exit(1);
36
+ }
37
+
38
+ let target = options.path;
39
+ if (normalizedProvider === 'github') target = parseGitHubPath(options.path);
40
+
41
+ console.log(chalk.blue(`[AgentGate] Wrapping ${chalk.bold(normalizedProvider)} repository: ${chalk.cyan(target)}...`));
42
+
43
+ const context = {
44
+ provider: normalizedProvider,
45
+ repoIdentifier: target,
46
+ timestamp: new Date().toISOString(),
47
+ status: 'wrapped'
48
+ };
49
+
50
+ try {
51
+ await fs.ensureDir(CONTEXT_DIR);
52
+ await fs.writeJson(CONTEXT_FILE, context, { spaces: 2 });
53
+ console.log(chalk.green(`✔ Context saved to .agentgate/context.json`));
54
+ } catch (err) {
55
+ console.error(chalk.red('Failed to save context:'), err.message);
56
+ }
57
+ });
58
+
59
+ program
60
+ .command('upload')
61
+ .description('Upload context to AgentGate')
62
+ .action(async () => {
63
+ if (!await fs.pathExists(CONTEXT_FILE)) {
64
+ console.error(chalk.red('Error: No context found. Run "agentgate wrap github --path <url>" first.'));
65
+ return;
66
+ }
67
+
68
+ const apiKey = process.env.AGENTGATE_API_KEY || process.env.TRACE_API_KEY;
69
+ if (!apiKey) {
70
+ console.warn(chalk.yellow('⚠ Warning: No AGENTGATE_API_KEY found in environment. The backend may reject this context.'));
71
+ }
72
+
73
+ try {
74
+ const context = await fs.readJson(CONTEXT_FILE);
75
+ console.log(chalk.blue(`[AgentGate] Synchronizing context for ${chalk.bold(context.repoIdentifier)} with backend...`));
76
+
77
+ context.status = 'active';
78
+ context.lastUploaded = new Date().toISOString();
79
+
80
+ await fs.writeJson(CONTEXT_FILE, context, { spaces: 2 });
81
+ await new Promise(r => setTimeout(r, 500)); // Simulating network latency
82
+ console.log(chalk.green(`✔ Success: Repository context is now active.`));
83
+ } catch (err) {
84
+ console.error(chalk.red('Upload failed:'), err.message);
85
+ }
86
+ });
87
+
88
+ program.parse(process.argv);
package/package.json CHANGED
@@ -1,35 +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
- }
1
+ {
2
+ "name": "@invokehq/cli",
3
+ "version": "0.1.9",
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 CHANGED
@@ -1,63 +1,50 @@
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 };
1
+ const fs = require('fs-extra');
2
+ const path = require('path');
3
+ const axios = require('axios');
4
+
5
+ // Load .env from the project root where the CLI is being executed
6
+ require('dotenv').config({ path: path.resolve(process.cwd(), '.env') });
7
+
8
+ // Load package info once at startup
9
+ const pkg = require(path.resolve(__dirname, 'package.json'));
10
+
11
+ const trace = {
12
+ call: async (action, params) => {
13
+ // Get context from the local wrap
14
+ const contextPath = path.join(process.cwd(), '.agentgate', 'context.json');
15
+
16
+ if (!(await fs.pathExists(contextPath))) {
17
+ throw new Error("Local context not found. Run 'agentgate wrap' first.");
18
+ }
19
+ const context = await fs.readJson(contextPath);
20
+
21
+ // The SDK now points to the Agentgate Backend Service
22
+ const AGENTGATE_SERVER = process.env.AGENTGATE_API_URL || "http://localhost:8000/call";
23
+
24
+ try {
25
+ const response = await axios.post(AGENTGATE_SERVER, {
26
+ action,
27
+ repository: context.repoIdentifier,
28
+ parameters: params
29
+ }, {
30
+ timeout: 10000, // 10 second timeout
31
+ headers: {
32
+ 'User-Agent': `agentgate-cli-sdk/${pkg.version}`,
33
+ 'Content-Type': 'application/json'
34
+ }
35
+ });
36
+
37
+ return response.data;
38
+ } catch (error) {
39
+ // Controllable: The SDK can handle specific error types from the server
40
+ if (error.code === 'ECONNREFUSED') {
41
+ throw new Error("Agentgate Backend is offline. Reliability check failed.");
42
+ }
43
+ throw new Error(
44
+ `Agentgate [${error.response?.status || 'Network'}]: ${error.response?.data?.error || error.response?.statusText || error.message}`
45
+ );
46
+ }
47
+ }
48
+ };
49
+
50
+ module.exports = { trace };