Skip to content

Commit bdba1a6

Browse files
committed
add CLI client option to CLI
1 parent e8be62c commit bdba1a6

File tree

2 files changed

+58
-3
lines changed

2 files changed

+58
-3
lines changed

typescript-sdk/packages/cli/package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,8 @@
2626
"dependencies": {
2727
"@types/inquirer": "^9.0.8",
2828
"commander": "^12.1.0",
29-
"inquirer": "^12.6.3"
29+
"inquirer": "^12.6.3",
30+
"giget": "^1.3.0"
3031
},
3132
"devDependencies": {
3233
"@types/jest": "^29.5.14",

typescript-sdk/packages/cli/src/index.ts

Lines changed: 56 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,11 @@ import { spawn } from "child_process";
55
import fs from "fs";
66
import path from "path";
77

8+
// Import giget with proper typing
9+
const { downloadTemplate } = require("giget") as {
10+
downloadTemplate: (template: string, options: { dir: string; install: boolean }) => Promise<void>;
11+
};
12+
813
const program = new Command();
914

1015
// Dark purple color
@@ -41,6 +46,7 @@ async function createProject() {
4146
message: "What client do you want to use?",
4247
choices: [
4348
"CopilotKit/Next.js",
49+
"CLI client",
4450
new inquirer.Separator("Other clients coming soon (SMS, Whatsapp, Slack ...)"),
4551
],
4652
},
@@ -49,6 +55,13 @@ async function createProject() {
4955
console.log(`\nSelected client: ${answers.client}`);
5056
console.log("Initializing your project...\n");
5157

58+
// Handle CLI client option
59+
if (answers.client === "CLI client") {
60+
await handleCliClient();
61+
return;
62+
}
63+
64+
// Continue with existing CopilotKit/Next.js logic
5265
const packageJsonPath = path.join(process.cwd(), "package.json");
5366
const packageJsonExists = fs.existsSync(packageJsonPath);
5467

@@ -122,7 +135,7 @@ async function createProject() {
122135

123136
// Run copilotkit init with framework flags
124137
console.log("\n🚀 Running CopilotKit initialization...\n");
125-
138+
126139
const options = program.opts();
127140
const frameworkArgs = [];
128141

@@ -154,6 +167,48 @@ async function createProject() {
154167
});
155168
}
156169

170+
async function handleCliClient() {
171+
console.log("🔧 Setting up CLI client...\n");
172+
173+
const projectName = await inquirer.prompt([
174+
{
175+
type: "input",
176+
name: "name",
177+
message: "What would you like to name your CLI project?",
178+
default: "my-ag-ui-cli-app",
179+
validate: (input) => {
180+
if (!input.trim()) {
181+
return "Project name cannot be empty";
182+
}
183+
if (!/^[a-zA-Z0-9-_]+$/.test(input)) {
184+
return "Project name can only contain letters, numbers, hyphens, and underscores";
185+
}
186+
return true;
187+
},
188+
},
189+
]);
190+
191+
try {
192+
console.log(`📥 Downloading CLI client template: ${projectName.name}\n`);
193+
194+
await downloadTemplate("gh:ag-ui-protocol/ag-ui/typescript-sdk/apps/client-cli-example", {
195+
dir: projectName.name,
196+
install: false,
197+
});
198+
199+
console.log("✅ CLI client template downloaded successfully!");
200+
console.log(`\n📁 Project created in: ${projectName.name}`);
201+
console.log("\n🚀 Next steps:");
202+
console.log(` cd ${projectName.name}`);
203+
console.log(" npm install");
204+
console.log(" npm run dev");
205+
console.log("\n💡 Check the README.md for more information on how to use your CLI client!");
206+
} catch (error) {
207+
console.log("❌ Failed to download CLI client template:", error);
208+
process.exit(1);
209+
}
210+
}
211+
157212
program.name("create-ag-ui-app").description("AG-UI CLI").version("0.0.1-alpha.1");
158213

159214
// Add framework flags
@@ -166,7 +221,6 @@ program
166221
.option("--llamaindex", "Use the LlamaIndex framework")
167222
.option("--agno", "Use the Agno framework");
168223

169-
170224
program.action(async () => {
171225
await createProject();
172226
});

0 commit comments

Comments
 (0)