@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
|
@@ -0,0 +1,239 @@
|
|
|
1
|
+
import {
|
|
2
|
+
__require,
|
|
3
|
+
printWelcomeBanner
|
|
4
|
+
} from "./chunk-RH5Q7I3S.mjs";
|
|
5
|
+
|
|
6
|
+
// src/create.ts
|
|
7
|
+
import * as fs from "fs";
|
|
8
|
+
import * as path from "path";
|
|
9
|
+
async function createProject(options) {
|
|
10
|
+
const { name, template = "blank" } = options;
|
|
11
|
+
const targetDir = path.resolve(process.cwd(), name);
|
|
12
|
+
if (fs.existsSync(targetDir)) {
|
|
13
|
+
console.error(`[voltx] Directory "${name}" already exists.`);
|
|
14
|
+
process.exit(1);
|
|
15
|
+
}
|
|
16
|
+
fs.mkdirSync(targetDir, { recursive: true });
|
|
17
|
+
const templateDeps = {
|
|
18
|
+
blank: {
|
|
19
|
+
"@voltx/core": "^0.2.0",
|
|
20
|
+
"@voltx/server": "^0.2.0"
|
|
21
|
+
},
|
|
22
|
+
chatbot: {
|
|
23
|
+
"@voltx/core": "^0.2.0",
|
|
24
|
+
"@voltx/ai": "^0.2.0",
|
|
25
|
+
"@voltx/server": "^0.2.0",
|
|
26
|
+
"@voltx/agents": "^0.2.0",
|
|
27
|
+
"@voltx/memory": "^0.2.0",
|
|
28
|
+
"@voltx/auth": "^0.2.0",
|
|
29
|
+
"@voltx/ui": "^0.2.0"
|
|
30
|
+
},
|
|
31
|
+
"rag-app": {
|
|
32
|
+
"@voltx/core": "^0.2.0",
|
|
33
|
+
"@voltx/ai": "^0.2.0",
|
|
34
|
+
"@voltx/server": "^0.2.0",
|
|
35
|
+
"@voltx/rag": "^0.2.0",
|
|
36
|
+
"@voltx/db": "^0.2.0",
|
|
37
|
+
"@voltx/auth": "^0.2.0",
|
|
38
|
+
"@voltx/ui": "^0.2.0"
|
|
39
|
+
},
|
|
40
|
+
"agent-app": {
|
|
41
|
+
"@voltx/core": "^0.2.0",
|
|
42
|
+
"@voltx/ai": "^0.2.0",
|
|
43
|
+
"@voltx/server": "^0.2.0",
|
|
44
|
+
"@voltx/agents": "^0.2.0",
|
|
45
|
+
"@voltx/memory": "^0.2.0",
|
|
46
|
+
"@voltx/rag": "^0.2.0",
|
|
47
|
+
"@voltx/db": "^0.2.0",
|
|
48
|
+
"@voltx/auth": "^0.2.0",
|
|
49
|
+
"@voltx/ui": "^0.2.0"
|
|
50
|
+
}
|
|
51
|
+
};
|
|
52
|
+
const packageJson = {
|
|
53
|
+
name,
|
|
54
|
+
version: "0.1.0",
|
|
55
|
+
private: true,
|
|
56
|
+
scripts: {
|
|
57
|
+
dev: "tsx src/index.ts",
|
|
58
|
+
build: "tsc",
|
|
59
|
+
start: "node dist/index.js"
|
|
60
|
+
},
|
|
61
|
+
dependencies: templateDeps[template] ?? templateDeps["blank"],
|
|
62
|
+
devDependencies: {
|
|
63
|
+
typescript: "^5.7.0",
|
|
64
|
+
tsx: "^4.21.0",
|
|
65
|
+
"@types/node": "^22.0.0"
|
|
66
|
+
}
|
|
67
|
+
};
|
|
68
|
+
fs.writeFileSync(
|
|
69
|
+
path.join(targetDir, "package.json"),
|
|
70
|
+
JSON.stringify(packageJson, null, 2)
|
|
71
|
+
);
|
|
72
|
+
const hasDb = template === "rag-app" || template === "agent-app";
|
|
73
|
+
const provider = template === "rag-app" ? "openai" : "cerebras";
|
|
74
|
+
const model = template === "rag-app" ? "gpt-4o" : "llama-4-scout-17b-16e";
|
|
75
|
+
let configContent = `import { defineConfig } from "@voltx/core";
|
|
76
|
+
|
|
77
|
+
export default defineConfig({
|
|
78
|
+
name: "${name}",
|
|
79
|
+
port: 3000,
|
|
80
|
+
ai: {
|
|
81
|
+
provider: "${provider}",
|
|
82
|
+
model: "${model}",
|
|
83
|
+
},`;
|
|
84
|
+
if (hasDb) {
|
|
85
|
+
configContent += `
|
|
86
|
+
db: {
|
|
87
|
+
url: process.env.DATABASE_URL,
|
|
88
|
+
},`;
|
|
89
|
+
}
|
|
90
|
+
configContent += `
|
|
91
|
+
server: {
|
|
92
|
+
routesDir: "src/routes",
|
|
93
|
+
staticDir: "public",
|
|
94
|
+
cors: true,
|
|
95
|
+
},
|
|
96
|
+
});
|
|
97
|
+
`;
|
|
98
|
+
fs.writeFileSync(path.join(targetDir, "voltx.config.ts"), configContent);
|
|
99
|
+
fs.mkdirSync(path.join(targetDir, "src", "routes", "api"), { recursive: true });
|
|
100
|
+
fs.mkdirSync(path.join(targetDir, "public"), { recursive: true });
|
|
101
|
+
fs.writeFileSync(
|
|
102
|
+
path.join(targetDir, "src", "index.ts"),
|
|
103
|
+
`import { createApp } from "@voltx/core";
|
|
104
|
+
import config from "../voltx.config";
|
|
105
|
+
|
|
106
|
+
const app = createApp(config);
|
|
107
|
+
app.start();
|
|
108
|
+
`
|
|
109
|
+
);
|
|
110
|
+
fs.writeFileSync(
|
|
111
|
+
path.join(targetDir, "src", "routes", "index.ts"),
|
|
112
|
+
`// GET / \u2014 Health check
|
|
113
|
+
import type { Context } from "@voltx/server";
|
|
114
|
+
|
|
115
|
+
export function GET(c: Context) {
|
|
116
|
+
return c.json({ name: "${name}", status: "ok" });
|
|
117
|
+
}
|
|
118
|
+
`
|
|
119
|
+
);
|
|
120
|
+
if (template === "chatbot" || template === "agent-app") {
|
|
121
|
+
fs.writeFileSync(
|
|
122
|
+
path.join(targetDir, "src", "routes", "api", "chat.ts"),
|
|
123
|
+
`// POST /api/chat \u2014 Streaming chat with conversation memory
|
|
124
|
+
import type { Context } from "@voltx/server";
|
|
125
|
+
import { streamText } from "@voltx/ai";
|
|
126
|
+
import { createMemory } from "@voltx/memory";
|
|
127
|
+
|
|
128
|
+
// In-memory for dev; swap to createMemory("postgres", { url }) for production
|
|
129
|
+
const memory = createMemory({ maxMessages: 50 });
|
|
130
|
+
|
|
131
|
+
export async function POST(c: Context) {
|
|
132
|
+
const { messages, conversationId = "default" } = await c.req.json();
|
|
133
|
+
|
|
134
|
+
// Store the latest user message
|
|
135
|
+
const lastMessage = messages[messages.length - 1];
|
|
136
|
+
if (lastMessage?.role === "user") {
|
|
137
|
+
await memory.add(conversationId, { role: "user", content: lastMessage.content });
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
// Get conversation history from memory
|
|
141
|
+
const history = await memory.get(conversationId);
|
|
142
|
+
|
|
143
|
+
const result = await streamText({
|
|
144
|
+
model: "cerebras:llama-4-scout-17b-16e",
|
|
145
|
+
system: "You are a helpful AI assistant.",
|
|
146
|
+
messages: history.map((m) => ({ role: m.role, content: m.content })),
|
|
147
|
+
});
|
|
148
|
+
|
|
149
|
+
// Store assistant response after stream completes
|
|
150
|
+
result.text.then(async (text) => {
|
|
151
|
+
await memory.add(conversationId, { role: "assistant", content: text });
|
|
152
|
+
});
|
|
153
|
+
|
|
154
|
+
return result.toSSEResponse();
|
|
155
|
+
}
|
|
156
|
+
`
|
|
157
|
+
);
|
|
158
|
+
}
|
|
159
|
+
if (template === "rag-app") {
|
|
160
|
+
fs.mkdirSync(path.join(targetDir, "src", "routes", "api", "rag"), { recursive: true });
|
|
161
|
+
fs.writeFileSync(
|
|
162
|
+
path.join(targetDir, "src", "routes", "api", "rag", "query.ts"),
|
|
163
|
+
`// POST /api/rag/query \u2014 Query documents with RAG
|
|
164
|
+
import type { Context } from "@voltx/server";
|
|
165
|
+
import { streamText } from "@voltx/ai";
|
|
166
|
+
|
|
167
|
+
export async function POST(c: Context) {
|
|
168
|
+
const { question } = await c.req.json();
|
|
169
|
+
|
|
170
|
+
const result = await streamText({
|
|
171
|
+
model: "openai:gpt-4o",
|
|
172
|
+
system: "Answer the user's question. Be concise and helpful.",
|
|
173
|
+
messages: [{ role: "user", content: question }],
|
|
174
|
+
});
|
|
175
|
+
|
|
176
|
+
return result.toSSEResponse();
|
|
177
|
+
}
|
|
178
|
+
`
|
|
179
|
+
);
|
|
180
|
+
}
|
|
181
|
+
let envContent = "";
|
|
182
|
+
if (template === "rag-app") {
|
|
183
|
+
envContent += "# \u2500\u2500\u2500 LLM Provider \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\nOPENAI_API_KEY=sk-...\n\n";
|
|
184
|
+
envContent += "# \u2500\u2500\u2500 Database (Neon Postgres) \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\nDATABASE_URL=postgresql://user:pass@ep-xxx.us-east-2.aws.neon.tech/dbname?sslmode=require\n\n";
|
|
185
|
+
envContent += "# \u2500\u2500\u2500 Vector Database (Pinecone) \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\nPINECONE_API_KEY=pc-...\nPINECONE_INDEX=voltx-embeddings\n\n";
|
|
186
|
+
} else if (template === "chatbot" || template === "agent-app") {
|
|
187
|
+
envContent += "# \u2500\u2500\u2500 LLM Provider \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\nCEREBRAS_API_KEY=csk-...\n\n";
|
|
188
|
+
if (template === "agent-app") {
|
|
189
|
+
envContent += "# \u2500\u2500\u2500 Database (Neon Postgres \u2014 optional) \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\nDATABASE_URL=\n\n";
|
|
190
|
+
}
|
|
191
|
+
} else {
|
|
192
|
+
envContent += "# \u2500\u2500\u2500 LLM Provider (add your key) \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\n# OPENAI_API_KEY=sk-...\n# CEREBRAS_API_KEY=csk-...\n\n";
|
|
193
|
+
}
|
|
194
|
+
envContent += "# \u2500\u2500\u2500 App \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\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\nPORT=3000\nNODE_ENV=development\n";
|
|
195
|
+
fs.writeFileSync(path.join(targetDir, ".env.example"), envContent);
|
|
196
|
+
fs.writeFileSync(
|
|
197
|
+
path.join(targetDir, ".gitignore"),
|
|
198
|
+
"node_modules\ndist\n.env\n"
|
|
199
|
+
);
|
|
200
|
+
fs.writeFileSync(
|
|
201
|
+
path.join(targetDir, "tsconfig.json"),
|
|
202
|
+
JSON.stringify(
|
|
203
|
+
{
|
|
204
|
+
compilerOptions: {
|
|
205
|
+
target: "ES2022",
|
|
206
|
+
module: "ESNext",
|
|
207
|
+
moduleResolution: "bundler",
|
|
208
|
+
strict: true,
|
|
209
|
+
esModuleInterop: true,
|
|
210
|
+
skipLibCheck: true,
|
|
211
|
+
outDir: "dist",
|
|
212
|
+
rootDir: "src"
|
|
213
|
+
},
|
|
214
|
+
include: ["src"]
|
|
215
|
+
},
|
|
216
|
+
null,
|
|
217
|
+
2
|
|
218
|
+
)
|
|
219
|
+
);
|
|
220
|
+
printWelcomeBanner(name);
|
|
221
|
+
}
|
|
222
|
+
var isDirectRun = typeof __require !== "undefined" && __require.main === module && process.argv[1]?.includes("create");
|
|
223
|
+
if (isDirectRun) {
|
|
224
|
+
const projectName = process.argv[2];
|
|
225
|
+
if (!projectName) {
|
|
226
|
+
console.log("Usage: create-voltx-app <project-name> [--template chatbot]");
|
|
227
|
+
process.exit(1);
|
|
228
|
+
}
|
|
229
|
+
const templateFlag = process.argv.indexOf("--template");
|
|
230
|
+
const template = templateFlag !== -1 ? process.argv[templateFlag + 1] : "blank";
|
|
231
|
+
createProject({ name: projectName, template }).catch((err) => {
|
|
232
|
+
console.error("[voltx] Error:", err);
|
|
233
|
+
process.exit(1);
|
|
234
|
+
});
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
export {
|
|
238
|
+
createProject
|
|
239
|
+
};
|
|
@@ -0,0 +1,351 @@
|
|
|
1
|
+
import {
|
|
2
|
+
__require,
|
|
3
|
+
printWelcomeBanner
|
|
4
|
+
} from "./chunk-RH5Q7I3S.mjs";
|
|
5
|
+
|
|
6
|
+
// src/create.ts
|
|
7
|
+
import * as fs from "fs";
|
|
8
|
+
import * as path from "path";
|
|
9
|
+
async function createProject(options) {
|
|
10
|
+
const { name, template = "blank", auth = "none" } = options;
|
|
11
|
+
const targetDir = path.resolve(process.cwd(), name);
|
|
12
|
+
if (fs.existsSync(targetDir)) {
|
|
13
|
+
console.error(`[voltx] Directory "${name}" already exists.`);
|
|
14
|
+
process.exit(1);
|
|
15
|
+
}
|
|
16
|
+
fs.mkdirSync(targetDir, { recursive: true });
|
|
17
|
+
const templateDeps = {
|
|
18
|
+
blank: {
|
|
19
|
+
"@voltx/core": "^0.2.0",
|
|
20
|
+
"@voltx/server": "^0.2.0"
|
|
21
|
+
},
|
|
22
|
+
chatbot: {
|
|
23
|
+
"@voltx/core": "^0.2.0",
|
|
24
|
+
"@voltx/ai": "^0.2.0",
|
|
25
|
+
"@voltx/server": "^0.2.0",
|
|
26
|
+
"@voltx/memory": "^0.2.0"
|
|
27
|
+
},
|
|
28
|
+
"rag-app": {
|
|
29
|
+
"@voltx/core": "^0.2.0",
|
|
30
|
+
"@voltx/ai": "^0.2.0",
|
|
31
|
+
"@voltx/server": "^0.2.0",
|
|
32
|
+
"@voltx/rag": "^0.2.0",
|
|
33
|
+
"@voltx/db": "^0.2.0"
|
|
34
|
+
},
|
|
35
|
+
"agent-app": {
|
|
36
|
+
"@voltx/core": "^0.2.0",
|
|
37
|
+
"@voltx/ai": "^0.2.0",
|
|
38
|
+
"@voltx/server": "^0.2.0",
|
|
39
|
+
"@voltx/agents": "^0.2.0",
|
|
40
|
+
"@voltx/memory": "^0.2.0"
|
|
41
|
+
}
|
|
42
|
+
};
|
|
43
|
+
const packageJson = {
|
|
44
|
+
name,
|
|
45
|
+
version: "0.1.0",
|
|
46
|
+
private: true,
|
|
47
|
+
scripts: {
|
|
48
|
+
dev: "tsx src/index.ts",
|
|
49
|
+
build: "tsc",
|
|
50
|
+
start: "node dist/index.js"
|
|
51
|
+
},
|
|
52
|
+
dependencies: {
|
|
53
|
+
...templateDeps[template] ?? templateDeps["blank"],
|
|
54
|
+
...auth === "better-auth" ? { "@voltx/auth": "^0.2.0", "better-auth": "^1.5.0" } : {},
|
|
55
|
+
...auth === "jwt" ? { "@voltx/auth": "^0.2.0", "jose": "^6.0.0" } : {}
|
|
56
|
+
},
|
|
57
|
+
devDependencies: {
|
|
58
|
+
typescript: "^5.7.0",
|
|
59
|
+
tsx: "^4.21.0",
|
|
60
|
+
"@types/node": "^22.0.0"
|
|
61
|
+
}
|
|
62
|
+
};
|
|
63
|
+
fs.writeFileSync(
|
|
64
|
+
path.join(targetDir, "package.json"),
|
|
65
|
+
JSON.stringify(packageJson, null, 2)
|
|
66
|
+
);
|
|
67
|
+
const hasDb = template === "rag-app" || template === "agent-app" || auth === "better-auth";
|
|
68
|
+
const provider = template === "rag-app" ? "openai" : "cerebras";
|
|
69
|
+
const model = template === "rag-app" ? "gpt-4o" : "llama-4-scout-17b-16e";
|
|
70
|
+
let configContent = `import { defineConfig } from "@voltx/core";
|
|
71
|
+
|
|
72
|
+
export default defineConfig({
|
|
73
|
+
name: "${name}",
|
|
74
|
+
port: 3000,
|
|
75
|
+
ai: {
|
|
76
|
+
provider: "${provider}",
|
|
77
|
+
model: "${model}",
|
|
78
|
+
},`;
|
|
79
|
+
if (hasDb) {
|
|
80
|
+
configContent += `
|
|
81
|
+
db: {
|
|
82
|
+
url: process.env.DATABASE_URL,
|
|
83
|
+
},`;
|
|
84
|
+
}
|
|
85
|
+
if (auth !== "none") {
|
|
86
|
+
configContent += `
|
|
87
|
+
auth: {
|
|
88
|
+
provider: "${auth}",
|
|
89
|
+
},`;
|
|
90
|
+
}
|
|
91
|
+
configContent += `
|
|
92
|
+
server: {
|
|
93
|
+
routesDir: "src/routes",
|
|
94
|
+
staticDir: "public",
|
|
95
|
+
cors: true,
|
|
96
|
+
},
|
|
97
|
+
});
|
|
98
|
+
`;
|
|
99
|
+
fs.writeFileSync(path.join(targetDir, "voltx.config.ts"), configContent);
|
|
100
|
+
fs.mkdirSync(path.join(targetDir, "src", "routes", "api"), { recursive: true });
|
|
101
|
+
fs.mkdirSync(path.join(targetDir, "public"), { recursive: true });
|
|
102
|
+
fs.writeFileSync(
|
|
103
|
+
path.join(targetDir, "src", "index.ts"),
|
|
104
|
+
`import { createApp } from "@voltx/core";
|
|
105
|
+
import config from "../voltx.config";
|
|
106
|
+
|
|
107
|
+
const app = createApp(config);
|
|
108
|
+
app.start();
|
|
109
|
+
`
|
|
110
|
+
);
|
|
111
|
+
fs.writeFileSync(
|
|
112
|
+
path.join(targetDir, "src", "routes", "index.ts"),
|
|
113
|
+
`// GET / \u2014 Health check
|
|
114
|
+
import type { Context } from "@voltx/server";
|
|
115
|
+
|
|
116
|
+
export function GET(c: Context) {
|
|
117
|
+
return c.json({ name: "${name}", status: "ok" });
|
|
118
|
+
}
|
|
119
|
+
`
|
|
120
|
+
);
|
|
121
|
+
if (template === "chatbot" || template === "agent-app") {
|
|
122
|
+
fs.writeFileSync(
|
|
123
|
+
path.join(targetDir, "src", "routes", "api", "chat.ts"),
|
|
124
|
+
`// POST /api/chat \u2014 Streaming chat with conversation memory
|
|
125
|
+
import type { Context } from "@voltx/server";
|
|
126
|
+
import { streamText } from "@voltx/ai";
|
|
127
|
+
import { createMemory } from "@voltx/memory";
|
|
128
|
+
|
|
129
|
+
// In-memory for dev; swap to createMemory("postgres", { url }) for production
|
|
130
|
+
const memory = createMemory({ maxMessages: 50 });
|
|
131
|
+
|
|
132
|
+
export async function POST(c: Context) {
|
|
133
|
+
const { messages, conversationId = "default" } = await c.req.json();
|
|
134
|
+
|
|
135
|
+
// Store the latest user message
|
|
136
|
+
const lastMessage = messages[messages.length - 1];
|
|
137
|
+
if (lastMessage?.role === "user") {
|
|
138
|
+
await memory.add(conversationId, { role: "user", content: lastMessage.content });
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
// Get conversation history from memory
|
|
142
|
+
const history = await memory.get(conversationId);
|
|
143
|
+
|
|
144
|
+
const result = await streamText({
|
|
145
|
+
model: "cerebras:llama-4-scout-17b-16e",
|
|
146
|
+
system: "You are a helpful AI assistant.",
|
|
147
|
+
messages: history.map((m) => ({ role: m.role, content: m.content })),
|
|
148
|
+
});
|
|
149
|
+
|
|
150
|
+
// Store assistant response after stream completes
|
|
151
|
+
result.text.then(async (text) => {
|
|
152
|
+
await memory.add(conversationId, { role: "assistant", content: text });
|
|
153
|
+
});
|
|
154
|
+
|
|
155
|
+
return result.toSSEResponse();
|
|
156
|
+
}
|
|
157
|
+
`
|
|
158
|
+
);
|
|
159
|
+
}
|
|
160
|
+
if (template === "rag-app") {
|
|
161
|
+
fs.mkdirSync(path.join(targetDir, "src", "routes", "api", "rag"), { recursive: true });
|
|
162
|
+
fs.writeFileSync(
|
|
163
|
+
path.join(targetDir, "src", "routes", "api", "rag", "query.ts"),
|
|
164
|
+
`// POST /api/rag/query \u2014 Query documents with RAG
|
|
165
|
+
import type { Context } from "@voltx/server";
|
|
166
|
+
import { streamText } from "@voltx/ai";
|
|
167
|
+
import { createRAGPipeline, createEmbedder } from "@voltx/rag";
|
|
168
|
+
import { createVectorStore } from "@voltx/db";
|
|
169
|
+
|
|
170
|
+
const vectorStore = createVectorStore(); // swap to "pinecone" or "pgvector" for production
|
|
171
|
+
const embedder = createEmbedder({ model: "openai:text-embedding-3-small" });
|
|
172
|
+
const rag = createRAGPipeline({ embedder, vectorStore });
|
|
173
|
+
|
|
174
|
+
export async function POST(c: Context) {
|
|
175
|
+
const { question } = await c.req.json();
|
|
176
|
+
|
|
177
|
+
const context = await rag.getContext(question, { topK: 5 });
|
|
178
|
+
|
|
179
|
+
const result = await streamText({
|
|
180
|
+
model: "openai:gpt-4o",
|
|
181
|
+
system: \`Answer the user's question based on the following context. If the context doesn't contain relevant information, say so.\\n\\nContext:\\n\${context}\`,
|
|
182
|
+
messages: [{ role: "user", content: question }],
|
|
183
|
+
});
|
|
184
|
+
|
|
185
|
+
return result.toSSEResponse();
|
|
186
|
+
}
|
|
187
|
+
`
|
|
188
|
+
);
|
|
189
|
+
fs.writeFileSync(
|
|
190
|
+
path.join(targetDir, "src", "routes", "api", "rag", "ingest.ts"),
|
|
191
|
+
`// POST /api/rag/ingest \u2014 Ingest documents into the vector store
|
|
192
|
+
import type { Context } from "@voltx/server";
|
|
193
|
+
import { createRAGPipeline, createEmbedder } from "@voltx/rag";
|
|
194
|
+
import { createVectorStore } from "@voltx/db";
|
|
195
|
+
|
|
196
|
+
const vectorStore = createVectorStore();
|
|
197
|
+
const embedder = createEmbedder({ model: "openai:text-embedding-3-small" });
|
|
198
|
+
const rag = createRAGPipeline({ embedder, vectorStore });
|
|
199
|
+
|
|
200
|
+
export async function POST(c: Context) {
|
|
201
|
+
const { text, idPrefix } = await c.req.json();
|
|
202
|
+
|
|
203
|
+
if (!text || typeof text !== "string") {
|
|
204
|
+
return c.json({ error: "Missing 'text' field" }, 400);
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
const result = await rag.ingest(text, idPrefix ?? "doc");
|
|
208
|
+
return c.json({ status: "ok", chunks: result.chunks, ids: result.ids });
|
|
209
|
+
}
|
|
210
|
+
`
|
|
211
|
+
);
|
|
212
|
+
}
|
|
213
|
+
if (auth === "better-auth") {
|
|
214
|
+
fs.mkdirSync(path.join(targetDir, "src", "routes", "api", "auth"), { recursive: true });
|
|
215
|
+
fs.writeFileSync(
|
|
216
|
+
path.join(targetDir, "src", "routes", "api", "auth", "[...path].ts"),
|
|
217
|
+
`// ALL /api/auth/* \u2014 Better Auth handler
|
|
218
|
+
import type { Context } from "@voltx/server";
|
|
219
|
+
import { auth } from "../../../lib/auth";
|
|
220
|
+
import { createAuthHandler } from "@voltx/auth";
|
|
221
|
+
|
|
222
|
+
const handler = createAuthHandler(auth);
|
|
223
|
+
|
|
224
|
+
export const GET = (c: Context) => handler(c);
|
|
225
|
+
export const POST = (c: Context) => handler(c);
|
|
226
|
+
`
|
|
227
|
+
);
|
|
228
|
+
fs.mkdirSync(path.join(targetDir, "src", "lib"), { recursive: true });
|
|
229
|
+
fs.writeFileSync(
|
|
230
|
+
path.join(targetDir, "src", "lib", "auth.ts"),
|
|
231
|
+
`// Auth configuration \u2014 Better Auth with DB-backed sessions
|
|
232
|
+
import { createAuth, createAuthMiddleware } from "@voltx/auth";
|
|
233
|
+
|
|
234
|
+
export const auth = createAuth("better-auth", {
|
|
235
|
+
database: process.env.DATABASE_URL!,
|
|
236
|
+
emailAndPassword: true,
|
|
237
|
+
});
|
|
238
|
+
|
|
239
|
+
export const authMiddleware = createAuthMiddleware({
|
|
240
|
+
provider: auth,
|
|
241
|
+
publicPaths: ["/api/auth", "/api/health", "/"],
|
|
242
|
+
});
|
|
243
|
+
`
|
|
244
|
+
);
|
|
245
|
+
} else if (auth === "jwt") {
|
|
246
|
+
fs.mkdirSync(path.join(targetDir, "src", "lib"), { recursive: true });
|
|
247
|
+
fs.writeFileSync(
|
|
248
|
+
path.join(targetDir, "src", "lib", "auth.ts"),
|
|
249
|
+
`// Auth configuration \u2014 JWT (stateless)
|
|
250
|
+
import { createAuth, createAuthMiddleware } from "@voltx/auth";
|
|
251
|
+
|
|
252
|
+
export const jwt = createAuth("jwt", {
|
|
253
|
+
secret: process.env.JWT_SECRET!,
|
|
254
|
+
expiresIn: "7d",
|
|
255
|
+
});
|
|
256
|
+
|
|
257
|
+
export const authMiddleware = createAuthMiddleware({
|
|
258
|
+
provider: jwt,
|
|
259
|
+
publicPaths: ["/api/auth", "/api/health", "/"],
|
|
260
|
+
});
|
|
261
|
+
`
|
|
262
|
+
);
|
|
263
|
+
fs.writeFileSync(
|
|
264
|
+
path.join(targetDir, "src", "routes", "api", "auth.ts"),
|
|
265
|
+
`// POST /api/auth/login \u2014 Example JWT login route
|
|
266
|
+
import type { Context } from "@voltx/server";
|
|
267
|
+
import { jwt } from "../../lib/auth";
|
|
268
|
+
|
|
269
|
+
export async function POST(c: Context) {
|
|
270
|
+
const { email, password } = await c.req.json();
|
|
271
|
+
|
|
272
|
+
if (!email || !password) {
|
|
273
|
+
return c.json({ error: "Email and password are required" }, 400);
|
|
274
|
+
}
|
|
275
|
+
|
|
276
|
+
const token = await jwt.sign({ sub: email, email });
|
|
277
|
+
return c.json({ token });
|
|
278
|
+
}
|
|
279
|
+
`
|
|
280
|
+
);
|
|
281
|
+
}
|
|
282
|
+
let envContent = "";
|
|
283
|
+
if (template === "rag-app") {
|
|
284
|
+
envContent += "# \u2500\u2500\u2500 LLM Provider \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\nOPENAI_API_KEY=sk-...\n\n";
|
|
285
|
+
envContent += "# \u2500\u2500\u2500 Database (Neon Postgres) \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\nDATABASE_URL=postgresql://user:pass@ep-xxx.us-east-2.aws.neon.tech/dbname?sslmode=require\n\n";
|
|
286
|
+
envContent += "# \u2500\u2500\u2500 Vector Database (Pinecone) \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\nPINECONE_API_KEY=pc-...\nPINECONE_INDEX=voltx-embeddings\n\n";
|
|
287
|
+
} else if (template === "chatbot" || template === "agent-app") {
|
|
288
|
+
envContent += "# \u2500\u2500\u2500 LLM Provider \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\nCEREBRAS_API_KEY=csk-...\n\n";
|
|
289
|
+
if (template === "agent-app") {
|
|
290
|
+
envContent += "# \u2500\u2500\u2500 Database (Neon Postgres \u2014 optional) \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\nDATABASE_URL=\n\n";
|
|
291
|
+
}
|
|
292
|
+
} else {
|
|
293
|
+
envContent += "# \u2500\u2500\u2500 LLM Provider (add your key) \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\n# OPENAI_API_KEY=sk-...\n# CEREBRAS_API_KEY=csk-...\n\n";
|
|
294
|
+
}
|
|
295
|
+
if (auth === "better-auth") {
|
|
296
|
+
envContent += "# \u2500\u2500\u2500 Auth (Better Auth) \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\nBETTER_AUTH_SECRET=your-secret-key-min-32-chars-here\nBETTER_AUTH_URL=http://localhost:3000\n";
|
|
297
|
+
if (template !== "rag-app" && template !== "agent-app") {
|
|
298
|
+
envContent += "DATABASE_URL=postgresql://user:pass@ep-xxx.us-east-2.aws.neon.tech/dbname?sslmode=require\n";
|
|
299
|
+
}
|
|
300
|
+
envContent += "# GITHUB_CLIENT_ID=\n# GITHUB_CLIENT_SECRET=\n\n";
|
|
301
|
+
} else if (auth === "jwt") {
|
|
302
|
+
envContent += "# \u2500\u2500\u2500 Auth (JWT) \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\u2500\nJWT_SECRET=your-jwt-secret-key\n\n";
|
|
303
|
+
}
|
|
304
|
+
envContent += "# \u2500\u2500\u2500 App \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\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\nPORT=3000\nNODE_ENV=development\n";
|
|
305
|
+
fs.writeFileSync(path.join(targetDir, ".env.example"), envContent);
|
|
306
|
+
fs.writeFileSync(
|
|
307
|
+
path.join(targetDir, ".gitignore"),
|
|
308
|
+
"node_modules\ndist\n.env\n"
|
|
309
|
+
);
|
|
310
|
+
fs.writeFileSync(
|
|
311
|
+
path.join(targetDir, "tsconfig.json"),
|
|
312
|
+
JSON.stringify(
|
|
313
|
+
{
|
|
314
|
+
compilerOptions: {
|
|
315
|
+
target: "ES2022",
|
|
316
|
+
module: "ESNext",
|
|
317
|
+
moduleResolution: "bundler",
|
|
318
|
+
strict: true,
|
|
319
|
+
esModuleInterop: true,
|
|
320
|
+
skipLibCheck: true,
|
|
321
|
+
outDir: "dist",
|
|
322
|
+
rootDir: "src"
|
|
323
|
+
},
|
|
324
|
+
include: ["src"]
|
|
325
|
+
},
|
|
326
|
+
null,
|
|
327
|
+
2
|
|
328
|
+
)
|
|
329
|
+
);
|
|
330
|
+
printWelcomeBanner(name);
|
|
331
|
+
}
|
|
332
|
+
var isDirectRun = typeof __require !== "undefined" && __require.main === module && process.argv[1]?.includes("create");
|
|
333
|
+
if (isDirectRun) {
|
|
334
|
+
const projectName = process.argv[2];
|
|
335
|
+
if (!projectName) {
|
|
336
|
+
console.log("Usage: create-voltx-app <project-name> [--template chatbot] [--auth jwt]");
|
|
337
|
+
process.exit(1);
|
|
338
|
+
}
|
|
339
|
+
const templateFlag = process.argv.indexOf("--template");
|
|
340
|
+
const template = templateFlag !== -1 ? process.argv[templateFlag + 1] : "blank";
|
|
341
|
+
const authFlag = process.argv.indexOf("--auth");
|
|
342
|
+
const auth = authFlag !== -1 ? process.argv[authFlag + 1] : "none";
|
|
343
|
+
createProject({ name: projectName, template, auth }).catch((err) => {
|
|
344
|
+
console.error("[voltx] Error:", err);
|
|
345
|
+
process.exit(1);
|
|
346
|
+
});
|
|
347
|
+
}
|
|
348
|
+
|
|
349
|
+
export {
|
|
350
|
+
createProject
|
|
351
|
+
};
|