@tulocode/cli 0.0.1
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/dist/index.js +85 -0
- package/package.json +38 -0
package/dist/index.js
ADDED
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
// src/index.ts
|
|
4
|
+
import { program } from "commander";
|
|
5
|
+
var DEFAULT_API_URL = "https://standing-minnow-13.convex.site/api/tools";
|
|
6
|
+
function getApiUrl() {
|
|
7
|
+
const opts = program.opts();
|
|
8
|
+
return opts.url || process.env.TULO_API_URL || DEFAULT_API_URL;
|
|
9
|
+
}
|
|
10
|
+
function getSecretKey() {
|
|
11
|
+
const key = process.env.TULO_SECRET_KEY;
|
|
12
|
+
if (!key) {
|
|
13
|
+
console.error("Error: TULO_SECRET_KEY environment variable is required");
|
|
14
|
+
process.exit(1);
|
|
15
|
+
}
|
|
16
|
+
return key;
|
|
17
|
+
}
|
|
18
|
+
async function listTools() {
|
|
19
|
+
const url = getApiUrl();
|
|
20
|
+
try {
|
|
21
|
+
const response = await fetch(url, {
|
|
22
|
+
method: "GET",
|
|
23
|
+
headers: { "Content-Type": "application/json" }
|
|
24
|
+
});
|
|
25
|
+
const data = await response.json();
|
|
26
|
+
console.log(JSON.stringify(data, null, 2));
|
|
27
|
+
} catch (err) {
|
|
28
|
+
console.error(`Error: Failed to fetch tools from ${url}`);
|
|
29
|
+
if (err instanceof Error) {
|
|
30
|
+
console.error(err.message);
|
|
31
|
+
}
|
|
32
|
+
process.exit(1);
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
async function invokeTool(toolName, argsJson) {
|
|
36
|
+
const url = getApiUrl();
|
|
37
|
+
const secretKey = getSecretKey();
|
|
38
|
+
let args = {};
|
|
39
|
+
if (argsJson) {
|
|
40
|
+
try {
|
|
41
|
+
args = JSON.parse(argsJson);
|
|
42
|
+
} catch {
|
|
43
|
+
console.error(`Error: Invalid JSON arguments: ${argsJson}`);
|
|
44
|
+
process.exit(1);
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
try {
|
|
48
|
+
const response = await fetch(url, {
|
|
49
|
+
method: "POST",
|
|
50
|
+
headers: {
|
|
51
|
+
"Content-Type": "application/json",
|
|
52
|
+
Authorization: `Bearer ${secretKey}`
|
|
53
|
+
},
|
|
54
|
+
body: JSON.stringify({ tool: toolName, args })
|
|
55
|
+
});
|
|
56
|
+
const data = await response.json();
|
|
57
|
+
if (!response.ok || data.success === false) {
|
|
58
|
+
console.error(JSON.stringify(data, null, 2));
|
|
59
|
+
process.exit(1);
|
|
60
|
+
}
|
|
61
|
+
console.log(JSON.stringify(data, null, 2));
|
|
62
|
+
} catch (err) {
|
|
63
|
+
console.error(`Error: Failed to invoke tool '${toolName}'`);
|
|
64
|
+
if (err instanceof Error) {
|
|
65
|
+
console.error(err.message);
|
|
66
|
+
}
|
|
67
|
+
process.exit(1);
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
program.name("tulo").description("CLI for Tulo API tools").version("0.0.1").option("--url <url>", "Override API URL", DEFAULT_API_URL);
|
|
71
|
+
program.command("tools").description("List available tools").action(async () => {
|
|
72
|
+
await listTools();
|
|
73
|
+
});
|
|
74
|
+
program.argument("[tool]", "Tool name to invoke").argument("[args]", "JSON arguments for the tool").action(async (tool, args) => {
|
|
75
|
+
if (!tool) {
|
|
76
|
+
program.help();
|
|
77
|
+
return;
|
|
78
|
+
}
|
|
79
|
+
if (tool === "tools") {
|
|
80
|
+
await listTools();
|
|
81
|
+
return;
|
|
82
|
+
}
|
|
83
|
+
await invokeTool(tool, args);
|
|
84
|
+
});
|
|
85
|
+
program.parse();
|
package/package.json
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@tulocode/cli",
|
|
3
|
+
"version": "0.0.1",
|
|
4
|
+
"description": "CLI for Tulo API tools",
|
|
5
|
+
"license": "ISC",
|
|
6
|
+
"author": "Andrew Arderne",
|
|
7
|
+
"type": "module",
|
|
8
|
+
"bin": {
|
|
9
|
+
"tulo": "dist/index.js"
|
|
10
|
+
},
|
|
11
|
+
"files": [
|
|
12
|
+
"dist"
|
|
13
|
+
],
|
|
14
|
+
"scripts": {
|
|
15
|
+
"build": "tsup src/index.ts --format esm --clean",
|
|
16
|
+
"prepublishOnly": "npm run build"
|
|
17
|
+
},
|
|
18
|
+
"dependencies": {
|
|
19
|
+
"commander": "^12.1.0"
|
|
20
|
+
},
|
|
21
|
+
"devDependencies": {
|
|
22
|
+
"tsup": "^8.3.0",
|
|
23
|
+
"typescript": "^5.0.0"
|
|
24
|
+
},
|
|
25
|
+
"engines": {
|
|
26
|
+
"node": ">=18"
|
|
27
|
+
},
|
|
28
|
+
"repository": {
|
|
29
|
+
"type": "git",
|
|
30
|
+
"url": "git+https://github.com/TuloCode/tulo-cli.git"
|
|
31
|
+
},
|
|
32
|
+
"keywords": [
|
|
33
|
+
"tulo",
|
|
34
|
+
"cli",
|
|
35
|
+
"crypto",
|
|
36
|
+
"accounting"
|
|
37
|
+
]
|
|
38
|
+
}
|