@voltx/cli 0.2.0 → 0.3.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/README.md +65 -0
- package/dist/build.d.mts +19 -0
- package/dist/build.d.ts +19 -0
- package/dist/build.js +145 -0
- package/dist/build.mjs +7 -0
- package/dist/chunk-AONHLE42.mjs +141 -0
- package/dist/chunk-BIE3F5AW.mjs +261 -0
- package/dist/chunk-BLBAHJXR.mjs +239 -0
- package/dist/chunk-IGBR4TFT.mjs +351 -0
- package/dist/chunk-IV352HZA.mjs +107 -0
- package/dist/chunk-KFHPTRKZ.mjs +405 -0
- package/dist/chunk-L3247M3A.mjs +81 -0
- package/dist/chunk-RN7BUALR.mjs +120 -0
- package/dist/chunk-SGL7RBD5.mjs +355 -0
- package/dist/chunk-TUZ3MHD4.mjs +355 -0
- package/dist/chunk-Y6FXYEAI.mjs +10 -0
- package/dist/chunk-ZA7EJWJI.mjs +221 -0
- package/dist/chunk-ZB2F3WTS.mjs +121 -0
- package/dist/chunk-ZLIPYI22.mjs +350 -0
- package/dist/cli.js +945 -59
- package/dist/cli.mjs +123 -23
- package/dist/create.d.mts +1 -0
- package/dist/create.d.ts +1 -0
- package/dist/create.js +308 -36
- package/dist/create.mjs +3 -2
- package/dist/dev.d.mts +19 -0
- package/dist/dev.d.ts +19 -0
- package/dist/dev.js +144 -0
- package/dist/dev.mjs +7 -0
- package/dist/generate.d.mts +13 -0
- package/dist/generate.d.ts +13 -0
- package/dist/generate.js +165 -0
- package/dist/generate.mjs +7 -0
- package/dist/index.d.mts +5 -1
- package/dist/index.d.ts +5 -1
- package/dist/index.js +770 -39
- package/dist/index.mjs +21 -4
- package/dist/start.d.mts +16 -0
- package/dist/start.d.ts +16 -0
- package/dist/start.js +105 -0
- package/dist/start.mjs +7 -0
- package/dist/welcome.js +1 -1
- package/dist/welcome.mjs +2 -1
- package/package.json +24 -22
- package/LICENSE +0 -21
package/dist/dev.js
ADDED
|
@@ -0,0 +1,144 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
|
|
20
|
+
// src/dev.ts
|
|
21
|
+
var dev_exports = {};
|
|
22
|
+
__export(dev_exports, {
|
|
23
|
+
runDev: () => runDev
|
|
24
|
+
});
|
|
25
|
+
module.exports = __toCommonJS(dev_exports);
|
|
26
|
+
var import_node_child_process = require("child_process");
|
|
27
|
+
var import_node_path = require("path");
|
|
28
|
+
var import_node_fs = require("fs");
|
|
29
|
+
async function runDev(options = {}) {
|
|
30
|
+
const cwd = process.cwd();
|
|
31
|
+
const {
|
|
32
|
+
port,
|
|
33
|
+
entry = findEntryPoint(cwd),
|
|
34
|
+
clearScreen = true
|
|
35
|
+
} = options;
|
|
36
|
+
if (!entry) {
|
|
37
|
+
console.error("[voltx] Could not find entry point. Expected src/index.ts or src/index.js");
|
|
38
|
+
process.exit(1);
|
|
39
|
+
}
|
|
40
|
+
const entryPath = (0, import_node_path.resolve)(cwd, entry);
|
|
41
|
+
if (!(0, import_node_fs.existsSync)(entryPath)) {
|
|
42
|
+
console.error(`[voltx] Entry file not found: ${entry}`);
|
|
43
|
+
process.exit(1);
|
|
44
|
+
}
|
|
45
|
+
const envFile = (0, import_node_path.resolve)(cwd, ".env");
|
|
46
|
+
const env = {
|
|
47
|
+
...process.env,
|
|
48
|
+
NODE_ENV: "development"
|
|
49
|
+
};
|
|
50
|
+
if (port) {
|
|
51
|
+
env.PORT = String(port);
|
|
52
|
+
}
|
|
53
|
+
printDevBanner(entry, port);
|
|
54
|
+
const tsxArgs = ["watch"];
|
|
55
|
+
if (clearScreen) {
|
|
56
|
+
tsxArgs.push("--clear-screen=false");
|
|
57
|
+
}
|
|
58
|
+
const watchDirs = [
|
|
59
|
+
"src/routes",
|
|
60
|
+
"src/agents",
|
|
61
|
+
"src/tools",
|
|
62
|
+
"src/jobs",
|
|
63
|
+
"src/lib",
|
|
64
|
+
"voltx.config.ts",
|
|
65
|
+
...options.watch ?? []
|
|
66
|
+
];
|
|
67
|
+
tsxArgs.push("--ignore=node_modules", "--ignore=dist", "--ignore=.turbo");
|
|
68
|
+
tsxArgs.push(entry);
|
|
69
|
+
const tsxBin = findTsxBin(cwd);
|
|
70
|
+
let child;
|
|
71
|
+
if (tsxBin) {
|
|
72
|
+
child = (0, import_node_child_process.spawn)(tsxBin, tsxArgs, {
|
|
73
|
+
cwd,
|
|
74
|
+
env,
|
|
75
|
+
stdio: "inherit"
|
|
76
|
+
});
|
|
77
|
+
} else {
|
|
78
|
+
child = (0, import_node_child_process.spawn)("npx", ["tsx", ...tsxArgs], {
|
|
79
|
+
cwd,
|
|
80
|
+
env,
|
|
81
|
+
stdio: "inherit"
|
|
82
|
+
});
|
|
83
|
+
}
|
|
84
|
+
const signals = ["SIGINT", "SIGTERM"];
|
|
85
|
+
for (const signal of signals) {
|
|
86
|
+
process.on(signal, () => {
|
|
87
|
+
child.kill(signal);
|
|
88
|
+
});
|
|
89
|
+
}
|
|
90
|
+
child.on("error", (err) => {
|
|
91
|
+
if (err.code === "ENOENT") {
|
|
92
|
+
console.error("[voltx] tsx not found. Install it with: npm install -D tsx");
|
|
93
|
+
console.error("[voltx] Or run your app directly: npx tsx watch src/index.ts");
|
|
94
|
+
} else {
|
|
95
|
+
console.error("[voltx] Dev server error:", err.message);
|
|
96
|
+
}
|
|
97
|
+
process.exit(1);
|
|
98
|
+
});
|
|
99
|
+
child.on("exit", (code) => {
|
|
100
|
+
process.exit(code ?? 0);
|
|
101
|
+
});
|
|
102
|
+
}
|
|
103
|
+
function findEntryPoint(cwd) {
|
|
104
|
+
const candidates = [
|
|
105
|
+
"src/index.ts",
|
|
106
|
+
"src/index.js",
|
|
107
|
+
"src/index.mts",
|
|
108
|
+
"src/main.ts",
|
|
109
|
+
"src/main.js",
|
|
110
|
+
"index.ts",
|
|
111
|
+
"index.js"
|
|
112
|
+
];
|
|
113
|
+
for (const candidate of candidates) {
|
|
114
|
+
if ((0, import_node_fs.existsSync)((0, import_node_path.join)(cwd, candidate))) {
|
|
115
|
+
return candidate;
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
return null;
|
|
119
|
+
}
|
|
120
|
+
function findTsxBin(cwd) {
|
|
121
|
+
const localBin = (0, import_node_path.join)(cwd, "node_modules", ".bin", "tsx");
|
|
122
|
+
if ((0, import_node_fs.existsSync)(localBin)) return localBin;
|
|
123
|
+
const parentBin = (0, import_node_path.join)(cwd, "..", "node_modules", ".bin", "tsx");
|
|
124
|
+
if ((0, import_node_fs.existsSync)(parentBin)) return parentBin;
|
|
125
|
+
const rootBin = (0, import_node_path.join)(cwd, "..", "..", "node_modules", ".bin", "tsx");
|
|
126
|
+
if ((0, import_node_fs.existsSync)(rootBin)) return rootBin;
|
|
127
|
+
return null;
|
|
128
|
+
}
|
|
129
|
+
function printDevBanner(entry, port) {
|
|
130
|
+
console.log("");
|
|
131
|
+
console.log(" \u26A1 VoltX Dev Server");
|
|
132
|
+
console.log(" \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500");
|
|
133
|
+
console.log(` Entry: ${entry}`);
|
|
134
|
+
if (port) {
|
|
135
|
+
console.log(` Port: ${port}`);
|
|
136
|
+
}
|
|
137
|
+
console.log(` Mode: development (hot reload)`);
|
|
138
|
+
console.log(" \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500");
|
|
139
|
+
console.log("");
|
|
140
|
+
}
|
|
141
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
142
|
+
0 && (module.exports = {
|
|
143
|
+
runDev
|
|
144
|
+
});
|
package/dist/dev.mjs
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
type GeneratorType = "route" | "agent" | "tool" | "job";
|
|
2
|
+
interface GenerateOptions {
|
|
3
|
+
type: GeneratorType;
|
|
4
|
+
name: string;
|
|
5
|
+
/** HTTP method for routes (default: POST) */
|
|
6
|
+
method?: string;
|
|
7
|
+
}
|
|
8
|
+
/**
|
|
9
|
+
* Generate a new file from a template.
|
|
10
|
+
*/
|
|
11
|
+
declare function runGenerate(options: GenerateOptions): Promise<void>;
|
|
12
|
+
|
|
13
|
+
export { type GenerateOptions, type GeneratorType, runGenerate };
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
type GeneratorType = "route" | "agent" | "tool" | "job";
|
|
2
|
+
interface GenerateOptions {
|
|
3
|
+
type: GeneratorType;
|
|
4
|
+
name: string;
|
|
5
|
+
/** HTTP method for routes (default: POST) */
|
|
6
|
+
method?: string;
|
|
7
|
+
}
|
|
8
|
+
/**
|
|
9
|
+
* Generate a new file from a template.
|
|
10
|
+
*/
|
|
11
|
+
declare function runGenerate(options: GenerateOptions): Promise<void>;
|
|
12
|
+
|
|
13
|
+
export { type GenerateOptions, type GeneratorType, runGenerate };
|
package/dist/generate.js
ADDED
|
@@ -0,0 +1,165 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
|
|
20
|
+
// src/generate.ts
|
|
21
|
+
var generate_exports = {};
|
|
22
|
+
__export(generate_exports, {
|
|
23
|
+
runGenerate: () => runGenerate
|
|
24
|
+
});
|
|
25
|
+
module.exports = __toCommonJS(generate_exports);
|
|
26
|
+
var import_node_fs = require("fs");
|
|
27
|
+
var import_node_path = require("path");
|
|
28
|
+
async function runGenerate(options) {
|
|
29
|
+
const cwd = process.cwd();
|
|
30
|
+
const { type, name } = options;
|
|
31
|
+
switch (type) {
|
|
32
|
+
case "route":
|
|
33
|
+
generateRoute(cwd, name, options.method);
|
|
34
|
+
break;
|
|
35
|
+
case "agent":
|
|
36
|
+
generateAgent(cwd, name);
|
|
37
|
+
break;
|
|
38
|
+
case "tool":
|
|
39
|
+
generateTool(cwd, name);
|
|
40
|
+
break;
|
|
41
|
+
case "job":
|
|
42
|
+
generateJob(cwd, name);
|
|
43
|
+
break;
|
|
44
|
+
default:
|
|
45
|
+
console.error(`[voltx] Unknown generator type: ${type}`);
|
|
46
|
+
console.error("[voltx] Available: route, agent, tool, job");
|
|
47
|
+
process.exit(1);
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
function generateRoute(cwd, name, method = "POST") {
|
|
51
|
+
const routePath = name.startsWith("/") ? name.slice(1) : name;
|
|
52
|
+
const filePath = (0, import_node_path.join)(cwd, "src", "routes", `${routePath}.ts`);
|
|
53
|
+
if ((0, import_node_fs.existsSync)(filePath)) {
|
|
54
|
+
console.error(`[voltx] Route already exists: src/routes/${routePath}.ts`);
|
|
55
|
+
process.exit(1);
|
|
56
|
+
}
|
|
57
|
+
const upperMethod = method.toUpperCase();
|
|
58
|
+
const urlPath = "/" + routePath;
|
|
59
|
+
const content = `// ${upperMethod} ${urlPath}
|
|
60
|
+
import type { Context } from "@voltx/server";
|
|
61
|
+
|
|
62
|
+
export async function ${upperMethod}(c: Context) {
|
|
63
|
+
return c.json({ message: "Hello from ${urlPath}" });
|
|
64
|
+
}
|
|
65
|
+
`;
|
|
66
|
+
writeFileSafe(filePath, content);
|
|
67
|
+
console.log(` \u2713 Created route: src/routes/${routePath}.ts`);
|
|
68
|
+
console.log(` ${upperMethod} ${urlPath}`);
|
|
69
|
+
}
|
|
70
|
+
function generateAgent(cwd, name) {
|
|
71
|
+
const filePath = (0, import_node_path.join)(cwd, "src", "agents", `${name}.ts`);
|
|
72
|
+
if ((0, import_node_fs.existsSync)(filePath)) {
|
|
73
|
+
console.error(`[voltx] Agent already exists: src/agents/${name}.ts`);
|
|
74
|
+
process.exit(1);
|
|
75
|
+
}
|
|
76
|
+
const content = `// Agent: ${name}
|
|
77
|
+
import { createAgent } from "@voltx/agents";
|
|
78
|
+
|
|
79
|
+
export const ${toCamelCase(name)} = createAgent({
|
|
80
|
+
name: "${name}",
|
|
81
|
+
model: "cerebras:llama-4-scout-17b-16e",
|
|
82
|
+
instructions: "You are a helpful AI assistant named ${name}.",
|
|
83
|
+
tools: [
|
|
84
|
+
// Add tools here:
|
|
85
|
+
// {
|
|
86
|
+
// name: "example",
|
|
87
|
+
// description: "An example tool",
|
|
88
|
+
// parameters: { type: "object", properties: { input: { type: "string" } }, required: ["input"] },
|
|
89
|
+
// execute: async (params) => \`Processed: \${params.input}\`,
|
|
90
|
+
// },
|
|
91
|
+
],
|
|
92
|
+
});
|
|
93
|
+
`;
|
|
94
|
+
writeFileSafe(filePath, content);
|
|
95
|
+
console.log(` \u2713 Created agent: src/agents/${name}.ts`);
|
|
96
|
+
}
|
|
97
|
+
function generateTool(cwd, name) {
|
|
98
|
+
const filePath = (0, import_node_path.join)(cwd, "src", "tools", `${name}.ts`);
|
|
99
|
+
if ((0, import_node_fs.existsSync)(filePath)) {
|
|
100
|
+
console.error(`[voltx] Tool already exists: src/tools/${name}.ts`);
|
|
101
|
+
process.exit(1);
|
|
102
|
+
}
|
|
103
|
+
const content = `// Tool: ${name}
|
|
104
|
+
|
|
105
|
+
export const ${toCamelCase(name)}Tool = {
|
|
106
|
+
name: "${name}",
|
|
107
|
+
description: "TODO: Describe what this tool does",
|
|
108
|
+
parameters: {
|
|
109
|
+
type: "object" as const,
|
|
110
|
+
properties: {
|
|
111
|
+
input: { type: "string", description: "The input to process" },
|
|
112
|
+
},
|
|
113
|
+
required: ["input"],
|
|
114
|
+
},
|
|
115
|
+
execute: async (params: { input: string }): Promise<string> => {
|
|
116
|
+
// TODO: Implement tool logic
|
|
117
|
+
return \`${name} result for: \${params.input}\`;
|
|
118
|
+
},
|
|
119
|
+
};
|
|
120
|
+
`;
|
|
121
|
+
writeFileSafe(filePath, content);
|
|
122
|
+
console.log(` \u2713 Created tool: src/tools/${name}.ts`);
|
|
123
|
+
}
|
|
124
|
+
function generateJob(cwd, name) {
|
|
125
|
+
const filePath = (0, import_node_path.join)(cwd, "src", "jobs", `${name}.ts`);
|
|
126
|
+
if ((0, import_node_fs.existsSync)(filePath)) {
|
|
127
|
+
console.error(`[voltx] Job already exists: src/jobs/${name}.ts`);
|
|
128
|
+
process.exit(1);
|
|
129
|
+
}
|
|
130
|
+
const content = `// Job: ${name}
|
|
131
|
+
// Runs on a schedule or triggered via ctx.jobs.enqueue("${name}", data)
|
|
132
|
+
|
|
133
|
+
export const config = {
|
|
134
|
+
// Cron schedule (uncomment to enable):
|
|
135
|
+
// schedule: "0 */6 * * *", // every 6 hours
|
|
136
|
+
//
|
|
137
|
+
// Or make it a queue job (triggered on-demand):
|
|
138
|
+
queue: true,
|
|
139
|
+
retries: 3,
|
|
140
|
+
timeout: "5m",
|
|
141
|
+
};
|
|
142
|
+
|
|
143
|
+
export async function run(ctx: any, data?: Record<string, unknown>) {
|
|
144
|
+
console.log("[job:${name}] Running...", data);
|
|
145
|
+
|
|
146
|
+
// TODO: Implement job logic
|
|
147
|
+
|
|
148
|
+
console.log("[job:${name}] Done.");
|
|
149
|
+
}
|
|
150
|
+
`;
|
|
151
|
+
writeFileSafe(filePath, content);
|
|
152
|
+
console.log(` \u2713 Created job: src/jobs/${name}.ts`);
|
|
153
|
+
}
|
|
154
|
+
function writeFileSafe(filePath, content) {
|
|
155
|
+
const dir = (0, import_node_path.dirname)(filePath);
|
|
156
|
+
(0, import_node_fs.mkdirSync)(dir, { recursive: true });
|
|
157
|
+
(0, import_node_fs.writeFileSync)(filePath, content, "utf-8");
|
|
158
|
+
}
|
|
159
|
+
function toCamelCase(str) {
|
|
160
|
+
return str.replace(/[-_](.)/g, (_, c) => c.toUpperCase()).replace(/^(.)/, (_, c) => c.toLowerCase());
|
|
161
|
+
}
|
|
162
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
163
|
+
0 && (module.exports = {
|
|
164
|
+
runGenerate
|
|
165
|
+
});
|
package/dist/index.d.mts
CHANGED
|
@@ -1,5 +1,9 @@
|
|
|
1
1
|
export { CreateProjectOptions, createProject } from './create.mjs';
|
|
2
|
+
export { DevOptions, runDev } from './dev.mjs';
|
|
3
|
+
export { BuildOptions, runBuild } from './build.mjs';
|
|
4
|
+
export { StartOptions, runStart } from './start.mjs';
|
|
5
|
+
export { GenerateOptions, GeneratorType, runGenerate } from './generate.mjs';
|
|
2
6
|
|
|
3
|
-
declare const CLI_VERSION = "0.
|
|
7
|
+
declare const CLI_VERSION = "0.2.0";
|
|
4
8
|
|
|
5
9
|
export { CLI_VERSION };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,9 @@
|
|
|
1
1
|
export { CreateProjectOptions, createProject } from './create.js';
|
|
2
|
+
export { DevOptions, runDev } from './dev.js';
|
|
3
|
+
export { BuildOptions, runBuild } from './build.js';
|
|
4
|
+
export { StartOptions, runStart } from './start.js';
|
|
5
|
+
export { GenerateOptions, GeneratorType, runGenerate } from './generate.js';
|
|
2
6
|
|
|
3
|
-
declare const CLI_VERSION = "0.
|
|
7
|
+
declare const CLI_VERSION = "0.2.0";
|
|
4
8
|
|
|
5
9
|
export { CLI_VERSION };
|