@voltx/cli 0.3.3 → 0.3.5

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 (58) hide show
  1. package/README.md +68 -14
  2. package/dist/build.d.mts +4 -3
  3. package/dist/build.d.ts +4 -3
  4. package/dist/build.js +56 -27
  5. package/dist/build.mjs +1 -2
  6. package/dist/chunk-2LHDOMF2.mjs +680 -0
  7. package/dist/chunk-4T26KROZ.mjs +456 -0
  8. package/dist/chunk-5DVBIJXU.mjs +84 -0
  9. package/dist/chunk-5RN2FYST.mjs +494 -0
  10. package/dist/chunk-65PVXS4D.mjs +894 -0
  11. package/dist/chunk-7JVIEGSA.mjs +141 -0
  12. package/dist/chunk-A4NA4AJN.mjs +786 -0
  13. package/dist/chunk-AAAHANST.mjs +839 -0
  14. package/dist/chunk-AD3WMFZF.mjs +205 -0
  15. package/dist/chunk-CFWXMM7Q.mjs +450 -0
  16. package/dist/chunk-CSSHLVYS.mjs +83 -0
  17. package/dist/chunk-CWOSNV5O.mjs +150 -0
  18. package/dist/chunk-EI6XBYKB.mjs +84 -0
  19. package/dist/chunk-EXMRIKIX.mjs +404 -0
  20. package/dist/chunk-FI2W4L4S.mjs +205 -0
  21. package/dist/chunk-FN7KZJ6H.mjs +363 -0
  22. package/dist/chunk-G2INQCCJ.mjs +907 -0
  23. package/dist/chunk-H2DTIOEO.mjs +150 -0
  24. package/dist/chunk-IS2WTE3C.mjs +138 -0
  25. package/dist/chunk-JECCDBYI.mjs +730 -0
  26. package/dist/chunk-KX2MRJUO.mjs +795 -0
  27. package/dist/chunk-LTGMHAZS.mjs +147 -0
  28. package/dist/chunk-OPO6RUFP.mjs +698 -0
  29. package/dist/chunk-P5FSO2UH.mjs +497 -0
  30. package/dist/chunk-PWQSKYAM.mjs +682 -0
  31. package/dist/chunk-Q5XCFN7L.mjs +1026 -0
  32. package/dist/chunk-QSU6FZC7.mjs +497 -0
  33. package/dist/chunk-RYWRFHEC.mjs +83 -0
  34. package/dist/chunk-SU4Q3PTH.mjs +201 -0
  35. package/dist/chunk-UO43CY7Y.mjs +497 -0
  36. package/dist/chunk-UXI3QSDN.mjs +121 -0
  37. package/dist/chunk-VD3CNPNP.mjs +123 -0
  38. package/dist/chunk-X6VOAPRJ.mjs +756 -0
  39. package/dist/cli.js +1023 -306
  40. package/dist/cli.mjs +7 -6
  41. package/dist/create.d.mts +1 -0
  42. package/dist/create.d.ts +1 -0
  43. package/dist/create.js +813 -189
  44. package/dist/create.mjs +1 -2
  45. package/dist/dev.d.mts +6 -4
  46. package/dist/dev.d.ts +6 -4
  47. package/dist/dev.js +119 -46
  48. package/dist/dev.mjs +1 -2
  49. package/dist/generate.js +13 -13
  50. package/dist/generate.mjs +1 -2
  51. package/dist/index.d.mts +1 -1
  52. package/dist/index.d.ts +1 -1
  53. package/dist/index.js +1010 -294
  54. package/dist/index.mjs +6 -7
  55. package/dist/start.js +7 -17
  56. package/dist/start.mjs +1 -2
  57. package/dist/welcome.mjs +0 -1
  58. package/package.json +11 -3
@@ -0,0 +1,141 @@
1
+ // src/generate.ts
2
+ import { existsSync, mkdirSync, writeFileSync } from "fs";
3
+ import { join, dirname } from "path";
4
+ async function runGenerate(options) {
5
+ const cwd = process.cwd();
6
+ const { type, name } = options;
7
+ switch (type) {
8
+ case "route":
9
+ generateRoute(cwd, name, options.method);
10
+ break;
11
+ case "agent":
12
+ generateAgent(cwd, name);
13
+ break;
14
+ case "tool":
15
+ generateTool(cwd, name);
16
+ break;
17
+ case "job":
18
+ generateJob(cwd, name);
19
+ break;
20
+ default:
21
+ console.error(`[voltx] Unknown generator type: ${type}`);
22
+ console.error("[voltx] Available: route, agent, tool, job");
23
+ process.exit(1);
24
+ }
25
+ }
26
+ function generateRoute(cwd, name, method = "POST") {
27
+ const routePath = name.startsWith("/") ? name.slice(1) : name;
28
+ const filePath = join(cwd, "api", `${routePath}.ts`);
29
+ if (existsSync(filePath)) {
30
+ console.error(`[voltx] Route already exists: api/${routePath}.ts`);
31
+ process.exit(1);
32
+ }
33
+ const upperMethod = method.toUpperCase();
34
+ const urlPath = "/api/" + routePath;
35
+ const content = `// ${upperMethod} ${urlPath}
36
+ import type { Context } from "@voltx/server";
37
+
38
+ export async function ${upperMethod}(c: Context) {
39
+ return c.json({ message: "Hello from ${urlPath}" });
40
+ }
41
+ `;
42
+ writeFileSafe(filePath, content);
43
+ console.log(` \u2713 Created route: api/${routePath}.ts`);
44
+ console.log(` ${upperMethod} ${urlPath}`);
45
+ }
46
+ function generateAgent(cwd, name) {
47
+ const filePath = join(cwd, "agents", `${name}.ts`);
48
+ if (existsSync(filePath)) {
49
+ console.error(`[voltx] Agent already exists: agents/${name}.ts`);
50
+ process.exit(1);
51
+ }
52
+ const content = `// Agent: ${name}
53
+ import { createAgent } from "@voltx/agents";
54
+
55
+ export const ${toCamelCase(name)} = createAgent({
56
+ name: "${name}",
57
+ model: "cerebras:llama3.1-8b",
58
+ instructions: "You are a helpful AI assistant named ${name}.",
59
+ tools: [
60
+ // Add tools here:
61
+ // {
62
+ // name: "example",
63
+ // description: "An example tool",
64
+ // parameters: { type: "object", properties: { input: { type: "string" } }, required: ["input"] },
65
+ // execute: async (params) => \`Processed: \${params.input}\`,
66
+ // },
67
+ ],
68
+ });
69
+ `;
70
+ writeFileSafe(filePath, content);
71
+ console.log(` \u2713 Created agent: agents/${name}.ts`);
72
+ }
73
+ function generateTool(cwd, name) {
74
+ const filePath = join(cwd, "tools", `${name}.ts`);
75
+ if (existsSync(filePath)) {
76
+ console.error(`[voltx] Tool already exists: tools/${name}.ts`);
77
+ process.exit(1);
78
+ }
79
+ const content = `// Tool: ${name}
80
+
81
+ export const ${toCamelCase(name)}Tool = {
82
+ name: "${name}",
83
+ description: "TODO: Describe what this tool does",
84
+ parameters: {
85
+ type: "object" as const,
86
+ properties: {
87
+ input: { type: "string", description: "The input to process" },
88
+ },
89
+ required: ["input"],
90
+ },
91
+ execute: async (params: { input: string }): Promise<string> => {
92
+ // TODO: Implement tool logic
93
+ return \`${name} result for: \${params.input}\`;
94
+ },
95
+ };
96
+ `;
97
+ writeFileSafe(filePath, content);
98
+ console.log(` \u2713 Created tool: tools/${name}.ts`);
99
+ }
100
+ function generateJob(cwd, name) {
101
+ const filePath = join(cwd, "jobs", `${name}.ts`);
102
+ if (existsSync(filePath)) {
103
+ console.error(`[voltx] Job already exists: jobs/${name}.ts`);
104
+ process.exit(1);
105
+ }
106
+ const content = `// Job: ${name}
107
+ // Runs on a schedule or triggered via ctx.jobs.enqueue("${name}", data)
108
+
109
+ export const config = {
110
+ // Cron schedule (uncomment to enable):
111
+ // schedule: "0 */6 * * *", // every 6 hours
112
+ //
113
+ // Or make it a queue job (triggered on-demand):
114
+ queue: true,
115
+ retries: 3,
116
+ timeout: "5m",
117
+ };
118
+
119
+ export async function run(ctx: any, data?: Record<string, unknown>) {
120
+ console.log("[job:${name}] Running...", data);
121
+
122
+ // TODO: Implement job logic
123
+
124
+ console.log("[job:${name}] Done.");
125
+ }
126
+ `;
127
+ writeFileSafe(filePath, content);
128
+ console.log(` \u2713 Created job: jobs/${name}.ts`);
129
+ }
130
+ function writeFileSafe(filePath, content) {
131
+ const dir = dirname(filePath);
132
+ mkdirSync(dir, { recursive: true });
133
+ writeFileSync(filePath, content, "utf-8");
134
+ }
135
+ function toCamelCase(str) {
136
+ return str.replace(/[-_](.)/g, (_, c) => c.toUpperCase()).replace(/^(.)/, (_, c) => c.toLowerCase());
137
+ }
138
+
139
+ export {
140
+ runGenerate
141
+ };