@invokehq/cli 0.1.14 → 0.1.15

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 +40 -4
  2. package/package.json +1 -1
  3. package/trace.js +15 -3
package/index.js CHANGED
@@ -5,9 +5,35 @@ const fs = require('fs-extra');
5
5
  const path = require('path');
6
6
  const pkg = require(path.resolve(__dirname, 'package.json'));
7
7
  const os = require('os');
8
+ const readline = require('readline');
9
+
8
10
  const program = new Command();
9
11
  const CONTEXT_DIR = path.join(process.cwd(), '.agentgate');
10
12
  const CONTEXT_FILE = path.join(CONTEXT_DIR, 'context.json');
13
+ const CONFIG_FILE = path.join(os.homedir(), '.invoke', 'config.json');
14
+
15
+ /**
16
+ * Securely prompts for sensitive input (API Keys)
17
+ */
18
+ const PromptSecret = (query) => {
19
+ return new Promise((resolve) => {
20
+ const rl = readline.createInterface({
21
+ input: process.stdin,
22
+ output: process.stdout
23
+ });
24
+
25
+ // Masking logic for the terminal
26
+ const stdin = process.stdin;
27
+ const onData = (char) => {
28
+ if (char === '\n' || char === '\r' || char === '\u0004') stdin.removeListener('data', onData);
29
+ };
30
+
31
+ rl.question(chalk.cyan(query), (value) => {
32
+ rl.close();
33
+ resolve(value);
34
+ });
35
+ });
36
+ };
11
37
 
12
38
  function parseGitHubPath(input) {
13
39
  // Handles https://github.com/owner/repo and git@github.com:owner/repo
@@ -17,7 +43,7 @@ function parseGitHubPath(input) {
17
43
  }
18
44
 
19
45
  program
20
- .name('agentgate')
46
+ .name('invoke')
21
47
  .version(pkg.version);
22
48
 
23
49
  program
@@ -26,10 +52,14 @@ program
26
52
  .option('--api-key <key>', 'Invoke API key for non-interactive login')
27
53
  .option('--base-url <url>', 'Invoke runtime URL', 'https://api.invokehq.run')
28
54
  .action(async (options) => {
29
- const apiKey = options.apiKey || process.env.INVOKE_API_KEY;
55
+ let apiKey = options.apiKey || process.env.INVOKE_API_KEY;
30
56
 
31
57
  if (!apiKey) {
32
- console.error('Missing API key. Set INVOKE_API_KEY or run: invoke login --api-key <key>');
58
+ apiKey = await PromptSecret('Enter your Invoke API Key: ');
59
+ }
60
+
61
+ if (!apiKey) {
62
+ console.error(chalk.red('Error: API key is required.'));
33
63
  process.exit(1);
34
64
  }
35
65
 
@@ -87,7 +117,13 @@ program
87
117
  return;
88
118
  }
89
119
 
90
- const apiKey = process.env.AGENTGATE_API_KEY || process.env.TRACE_API_KEY;
120
+ let apiKey = process.env.AGENTGATE_API_KEY || process.env.TRACE_API_KEY;
121
+
122
+ if (!apiKey && await fs.pathExists(CONFIG_FILE)) {
123
+ const config = await fs.readJson(CONFIG_FILE);
124
+ apiKey = config.apiKey;
125
+ }
126
+
91
127
  if (!apiKey) {
92
128
  console.warn(chalk.yellow('⚠ Warning: No AGENTGATE_API_KEY found in environment. The backend may reject this context.'));
93
129
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@invokehq/cli",
3
- "version": "0.1.14",
3
+ "version": "0.1.15",
4
4
  "description": "Invoke CLI",
5
5
  "main": "trace.js",
6
6
  "bin": {
package/trace.js CHANGED
@@ -1,12 +1,14 @@
1
1
  const fs = require('fs-extra');
2
2
  const path = require('path');
3
3
  const axios = require('axios');
4
+ const os = require('os');
4
5
 
5
6
  // Load .env from the project root where the CLI is being executed
6
7
  require('dotenv').config({ path: path.resolve(process.cwd(), '.env') });
7
8
 
8
9
  // Load package info once at startup
9
10
  const pkg = require(path.resolve(__dirname, 'package.json'));
11
+ const CONFIG_FILE = path.join(os.homedir(), '.invoke', 'config.json');
10
12
 
11
13
  const trace = {
12
14
  call: async (action, params) => {
@@ -18,11 +20,20 @@ const trace = {
18
20
  }
19
21
  const context = await fs.readJson(contextPath);
20
22
 
23
+ // Attempt to load stored config from 'invoke login'
24
+ let storedConfig = {};
25
+ if (fs.existsSync(CONFIG_FILE)) {
26
+ storedConfig = fs.readJsonSync(CONFIG_FILE);
27
+ }
28
+
21
29
  // The SDK now points to the Agentgate Backend Service
22
- const AGENTGATE_SERVER = process.env.AGENTGATE_API_URL || "http://localhost:8000/call";
30
+ const baseUrl = process.env.AGENTGATE_API_URL || storedConfig.baseUrl || "http://localhost:8000";
31
+ const endpoint = baseUrl.endsWith('/call') ? baseUrl : `${baseUrl.replace(/\/+$/, '')}/call`;
32
+
33
+ const apiKey = process.env.AGENTGATE_API_KEY || storedConfig.apiKey;
23
34
 
24
35
  try {
25
- const response = await axios.post(AGENTGATE_SERVER, {
36
+ const response = await axios.post(endpoint, {
26
37
  action,
27
38
  repository: context.repoIdentifier,
28
39
  parameters: params
@@ -30,7 +41,8 @@ const trace = {
30
41
  timeout: 10000, // 10 second timeout
31
42
  headers: {
32
43
  'User-Agent': `agentgate-cli-sdk/${pkg.version}`,
33
- 'Content-Type': 'application/json'
44
+ 'Content-Type': 'application/json',
45
+ ...(apiKey ? { 'X-API-Key': apiKey } : {})
34
46
  }
35
47
  });
36
48