@invokehq/cli 0.1.11 → 0.1.12
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/index.js +86 -87
- package/package.json +1 -1
- package/trace.js +49 -49
package/index.js
CHANGED
|
@@ -1,88 +1,87 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
const
|
|
4
|
-
const
|
|
5
|
-
const
|
|
6
|
-
const
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
const
|
|
10
|
-
const
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
const
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
.
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
.
|
|
26
|
-
.
|
|
27
|
-
.
|
|
28
|
-
.
|
|
29
|
-
|
|
30
|
-
const
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
await fs.
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
.
|
|
61
|
-
.
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
context.
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
await
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
const { Command } = require('commander');
|
|
3
|
+
const chalk = require('chalk');
|
|
4
|
+
const fs = require('fs-extra');
|
|
5
|
+
const path = require('path');
|
|
6
|
+
const pkg = require(path.resolve(__dirname, 'package.json'));
|
|
7
|
+
|
|
8
|
+
const program = new Command();
|
|
9
|
+
const CONTEXT_DIR = path.join(process.cwd(), '.agentgate');
|
|
10
|
+
const CONTEXT_FILE = path.join(CONTEXT_DIR, 'context.json');
|
|
11
|
+
|
|
12
|
+
function parseGitHubPath(input) {
|
|
13
|
+
// Handles https://github.com/owner/repo and git@github.com:owner/repo
|
|
14
|
+
const regex = /(?:https?:\/\/github\.com\/|git@github\.com:)([^/]+)\/([^/.]+?)(?:\.git)?(?:\/)?$/;
|
|
15
|
+
const match = input.match(regex);
|
|
16
|
+
return match ? `${match[1]}/${match[2]}` : input;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
program
|
|
20
|
+
.name('agentgate')
|
|
21
|
+
.version(pkg.version);
|
|
22
|
+
|
|
23
|
+
program
|
|
24
|
+
.command('wrap')
|
|
25
|
+
.description('Prepare repository context')
|
|
26
|
+
.argument('<provider>', 'e.g., github')
|
|
27
|
+
.option('-p, --path <path>', 'Repository URL or owner/repo', '.')
|
|
28
|
+
.action(async (provider, options) => {
|
|
29
|
+
const normalizedProvider = provider.toLowerCase();
|
|
30
|
+
const supported = ['github'];
|
|
31
|
+
|
|
32
|
+
if (!supported.includes(normalizedProvider)) {
|
|
33
|
+
console.error(chalk.red(`Error: Unsupported provider "${provider}". Supported: ${supported.join(', ')}`));
|
|
34
|
+
process.exit(1);
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
let target = options.path;
|
|
38
|
+
if (normalizedProvider === 'github') target = parseGitHubPath(options.path);
|
|
39
|
+
|
|
40
|
+
console.log(chalk.blue(`[AgentGate] Wrapping ${chalk.bold(normalizedProvider)} repository: ${chalk.cyan(target)}...`));
|
|
41
|
+
|
|
42
|
+
const context = {
|
|
43
|
+
provider: normalizedProvider,
|
|
44
|
+
repoIdentifier: target,
|
|
45
|
+
timestamp: new Date().toISOString(),
|
|
46
|
+
status: 'wrapped'
|
|
47
|
+
};
|
|
48
|
+
|
|
49
|
+
try {
|
|
50
|
+
await fs.ensureDir(CONTEXT_DIR);
|
|
51
|
+
await fs.writeJson(CONTEXT_FILE, context, { spaces: 2 });
|
|
52
|
+
console.log(chalk.green(`✔ Context saved to .agentgate/context.json`));
|
|
53
|
+
} catch (err) {
|
|
54
|
+
console.error(chalk.red('Failed to save context:'), err.message);
|
|
55
|
+
}
|
|
56
|
+
});
|
|
57
|
+
|
|
58
|
+
program
|
|
59
|
+
.command('upload')
|
|
60
|
+
.description('Upload context to AgentGate')
|
|
61
|
+
.action(async () => {
|
|
62
|
+
if (!await fs.pathExists(CONTEXT_FILE)) {
|
|
63
|
+
console.error(chalk.red('Error: No context found. Run "agentgate wrap github --path <url>" first.'));
|
|
64
|
+
return;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
const apiKey = process.env.AGENTGATE_API_KEY || process.env.TRACE_API_KEY;
|
|
68
|
+
if (!apiKey) {
|
|
69
|
+
console.warn(chalk.yellow('⚠ Warning: No AGENTGATE_API_KEY found in environment. The backend may reject this context.'));
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
try {
|
|
73
|
+
const context = await fs.readJson(CONTEXT_FILE);
|
|
74
|
+
console.log(chalk.blue(`[AgentGate] Synchronizing context for ${chalk.bold(context.repoIdentifier)} with backend...`));
|
|
75
|
+
|
|
76
|
+
context.status = 'active';
|
|
77
|
+
context.lastUploaded = new Date().toISOString();
|
|
78
|
+
|
|
79
|
+
await fs.writeJson(CONTEXT_FILE, context, { spaces: 2 });
|
|
80
|
+
await new Promise(r => setTimeout(r, 500)); // Simulating network latency
|
|
81
|
+
console.log(chalk.green(`✔ Success: Repository context is now active.`));
|
|
82
|
+
} catch (err) {
|
|
83
|
+
console.error(chalk.red('Upload failed:'), err.message);
|
|
84
|
+
}
|
|
85
|
+
});
|
|
86
|
+
|
|
88
87
|
program.parse(process.argv);
|
package/package.json
CHANGED
package/trace.js
CHANGED
|
@@ -1,50 +1,50 @@
|
|
|
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
|
-
|
|
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
50
|
module.exports = { trace };
|