create-cogitator-app 0.2.0 → 0.3.0

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/lib.js CHANGED
@@ -60,6 +60,9 @@ function providerConfig(provider) {
60
60
  }
61
61
  }
62
62
 
63
+ // src/templates/versions.ts
64
+ var ZOD_VERSION = "^4.6.5";
65
+
63
66
  // src/templates/basic.ts
64
67
  var basicTemplate = {
65
68
  files(options) {
@@ -128,7 +131,7 @@ var basicTemplate = {
128
131
  dependencies() {
129
132
  return {
130
133
  "@cogitator-ai/core": "latest",
131
- zod: "^3.23.0"
134
+ zod: ZOD_VERSION
132
135
  };
133
136
  },
134
137
  devDependencies() {
@@ -237,7 +240,7 @@ var memoryTemplate = {
237
240
  "@cogitator-ai/core": "latest",
238
241
  "@cogitator-ai/memory": "latest",
239
242
  "@cogitator-ai/redis": "latest",
240
- zod: "^3.23.0"
243
+ zod: ZOD_VERSION
241
244
  };
242
245
  },
243
246
  devDependencies() {
@@ -358,7 +361,7 @@ var swarmTemplate = {
358
361
  ` })`,
359
362
  ``,
360
363
  ` console.log('Result:', result.output)`,
361
- ` console.log('Strategy:', result.strategy)`,
364
+ ` console.log('Strategy:', team.strategyType)`,
362
365
  ``,
363
366
  ` await team.close()`,
364
367
  `}`,
@@ -378,7 +381,7 @@ var swarmTemplate = {
378
381
  return {
379
382
  "@cogitator-ai/core": "latest",
380
383
  "@cogitator-ai/swarms": "latest",
381
- zod: "^3.23.0"
384
+ zod: ZOD_VERSION
382
385
  };
383
386
  },
384
387
  devDependencies() {
@@ -441,7 +444,7 @@ var workflowTemplate = {
441
444
  providerConfig(options.provider),
442
445
  `})`,
443
446
  ``,
444
- `interface WorkflowState {`,
447
+ `type WorkflowState = {`,
445
448
  ` input: string`,
446
449
  ` analysis?: string`,
447
450
  ` processed?: string`,
@@ -502,7 +505,7 @@ var workflowTemplate = {
502
505
  return {
503
506
  "@cogitator-ai/core": "latest",
504
507
  "@cogitator-ai/workflows": "latest",
505
- zod: "^3.23.0"
508
+ zod: ZOD_VERSION
506
509
  };
507
510
  },
508
511
  devDependencies() {
@@ -523,7 +526,9 @@ var workflowTemplate = {
523
526
  };
524
527
 
525
528
  // src/templates/api-server.ts
529
+ var BASE_PATH = "/api";
526
530
  var apiServerTemplate = {
531
+ healthPath: `${BASE_PATH}/health`,
527
532
  files(options) {
528
533
  const model = defaultModels[options.provider];
529
534
  const agentsTs = [
@@ -575,7 +580,7 @@ var apiServerTemplate = {
575
580
  ` cogitator,`,
576
581
  ` agents: { assistant, coder },`,
577
582
  ` config: {`,
578
- ` basePath: '/api',`,
583
+ ` basePath: '${BASE_PATH}',`,
579
584
  ` enableSwagger: true,`,
580
585
  ` cors: { origin: '*' },`,
581
586
  ` swagger: {`,
@@ -590,7 +595,7 @@ var apiServerTemplate = {
590
595
  ``,
591
596
  ` app.listen(port, () => {`,
592
597
  ` console.log(\`Server running at http://localhost:\${port}\`)`,
593
- ` console.log(\`Swagger docs at http://localhost:\${port}/api/docs\`)`,
598
+ ` console.log(\`Swagger docs at http://localhost:\${port}${BASE_PATH}/docs\`)`,
594
599
  ` })`,
595
600
  `}`,
596
601
  ``,
@@ -606,8 +611,8 @@ var apiServerTemplate = {
606
611
  return {
607
612
  "@cogitator-ai/core": "latest",
608
613
  "@cogitator-ai/express": "latest",
609
- express: "^4.21.0",
610
- zod: "^3.23.0"
614
+ express: "^5.2.1",
615
+ zod: ZOD_VERSION
611
616
  };
612
617
  },
613
618
  devDependencies() {
@@ -615,7 +620,7 @@ var apiServerTemplate = {
615
620
  typescript: "^5.8.0",
616
621
  tsx: "^4.19.0",
617
622
  "@types/node": "^22.0.0",
618
- "@types/express": "^5.0.0"
623
+ "@types/express": "^5.0.6"
619
624
  };
620
625
  },
621
626
  scripts() {
@@ -630,6 +635,7 @@ var apiServerTemplate = {
630
635
 
631
636
  // src/templates/nextjs.ts
632
637
  var nextjsTemplate = {
638
+ healthPath: "/api/health",
633
639
  files(options) {
634
640
  const model = defaultModels[options.provider];
635
641
  const agentTs = [
@@ -667,6 +673,12 @@ var nextjsTemplate = {
667
673
  `export const POST = createChatHandler(cogitator, agent)`,
668
674
  ``
669
675
  ].join("\n");
676
+ const healthRouteTs = [
677
+ `export function GET() {`,
678
+ ` return Response.json({ status: 'ok' })`,
679
+ `}`,
680
+ ``
681
+ ].join("\n");
670
682
  const pageTsx = [
671
683
  `'use client'`,
672
684
  ``,
@@ -833,6 +845,7 @@ var nextjsTemplate = {
833
845
  return [
834
846
  { path: "src/lib/agent.ts", content: agentTs },
835
847
  { path: "src/app/api/chat/route.ts", content: routeTs },
848
+ { path: "src/app/api/health/route.ts", content: healthRouteTs },
836
849
  { path: "src/app/page.tsx", content: pageTsx },
837
850
  { path: "src/app/layout.tsx", content: layoutTsx },
838
851
  { path: "src/app/globals.css", content: globalsCss },
@@ -849,7 +862,7 @@ var nextjsTemplate = {
849
862
  next: "^15.0.0",
850
863
  react: "^19.0.0",
851
864
  "react-dom": "^19.0.0",
852
- zod: "^3.23.0"
865
+ zod: ZOD_VERSION
853
866
  };
854
867
  },
855
868
  devDependencies() {
@@ -1026,12 +1039,33 @@ function generateDockerCompose(provider) {
1026
1039
  }
1027
1040
 
1028
1041
  // src/templates/base/cogitator-yml.ts
1029
- function generateCogitatorYml(provider) {
1030
- const model = defaultModels[provider];
1031
- const lines = [`provider: ${provider}`, `model: ${model}`, ""];
1042
+ function generateCogitatorYml(provider, template) {
1043
+ const lines = [
1044
+ "llm:",
1045
+ ` defaultProvider: ${provider}`,
1046
+ ` defaultModel: ${defaultModels[provider]}`
1047
+ ];
1032
1048
  if (provider === "ollama") {
1033
- lines.push("ollama:", " baseUrl: http://localhost:11434", "");
1049
+ lines.push(
1050
+ " providers:",
1051
+ " ollama:",
1052
+ " baseUrl: ${OLLAMA_BASE_URL:-http://localhost:11434}"
1053
+ );
1054
+ }
1055
+ if (template === "memory") {
1056
+ lines.push(
1057
+ "",
1058
+ "memory:",
1059
+ " adapter: redis",
1060
+ " redis:",
1061
+ " url: ${REDIS_URL:-redis://localhost:6379}"
1062
+ );
1063
+ }
1064
+ const healthPath = template ? getTemplate(template).healthPath : void 0;
1065
+ if (healthPath) {
1066
+ lines.push("", "deploy:", " health:", ` path: ${healthPath}`);
1034
1067
  }
1068
+ lines.push("");
1035
1069
  return { path: "cogitator.yml", content: lines.join("\n") };
1036
1070
  }
1037
1071
 
@@ -1054,6 +1088,10 @@ function devCommand(pm) {
1054
1088
  return `${pm} dev`;
1055
1089
  }
1056
1090
 
1091
+ // src/utils/links.ts
1092
+ var DOCS_URL = "https://cogitator.app/docs";
1093
+ var REPO_URL = "https://github.com/cogitator-ai/Cogitator-AI";
1094
+
1057
1095
  // src/templates/base/readme.ts
1058
1096
  var templateNames = {
1059
1097
  basic: "Basic Agent",
@@ -1069,7 +1107,7 @@ function generateReadme(options) {
1069
1107
  const content = [
1070
1108
  `# ${options.name}`,
1071
1109
  "",
1072
- `> Created with [create-cogitator-app](https://github.com/cogitator-ai/cogitator) \u2014 ${templateName} template`,
1110
+ `> Created with [create-cogitator-app](${REPO_URL}) \u2014 ${templateName} template`,
1073
1111
  "",
1074
1112
  "## Getting Started",
1075
1113
  "",
@@ -1084,8 +1122,8 @@ function generateReadme(options) {
1084
1122
  ...options.docker ? ["## Docker Services", "", "```bash", "docker compose up -d", "```", ""] : [],
1085
1123
  "## Learn More",
1086
1124
  "",
1087
- "- [Cogitator Documentation](https://cogitator.dev/docs)",
1088
- "- [GitHub Repository](https://github.com/cogitator-ai/cogitator)",
1125
+ `- [Cogitator Documentation](${DOCS_URL})`,
1126
+ `- [GitHub Repository](${REPO_URL})`,
1089
1127
  ""
1090
1128
  ];
1091
1129
  return { path: "README.md", content: content.join("\n") };
@@ -1103,22 +1141,38 @@ function generatePnpmWorkspace() {
1103
1141
  }
1104
1142
 
1105
1143
  // src/utils/git.ts
1106
- import { execSync as execSync2 } from "child_process";
1144
+ import { execFileSync } from "child_process";
1145
+ var FALLBACK_IDENTITY = [
1146
+ "-c",
1147
+ "user.name=create-cogitator-app",
1148
+ "-c",
1149
+ "user.email=create-cogitator-app@localhost"
1150
+ ];
1107
1151
  function isGitInstalled() {
1108
1152
  try {
1109
- execSync2("git --version", { stdio: "ignore" });
1153
+ execFileSync("git", ["--version"], { stdio: "ignore" });
1110
1154
  return true;
1111
1155
  } catch {
1112
1156
  return false;
1113
1157
  }
1114
1158
  }
1159
+ function hasIdentity(cwd) {
1160
+ try {
1161
+ const name = execFileSync("git", ["config", "user.name"], { cwd, encoding: "utf8" }).trim();
1162
+ const email = execFileSync("git", ["config", "user.email"], { cwd, encoding: "utf8" }).trim();
1163
+ return name.length > 0 && email.length > 0;
1164
+ } catch {
1165
+ return false;
1166
+ }
1167
+ }
1115
1168
  function initGitRepo(cwd) {
1116
- execSync2("git init", { cwd, stdio: "ignore" });
1117
- execSync2("git add -A", { cwd, stdio: "ignore" });
1118
- execSync2(
1119
- 'git -c user.name="Cogitator" -c user.email="init@cogitator.dev" commit -m "feat: initial project scaffold"',
1120
- { cwd, stdio: "ignore" }
1121
- );
1169
+ execFileSync("git", ["init"], { cwd, stdio: "ignore" });
1170
+ execFileSync("git", ["add", "-A"], { cwd, stdio: "ignore" });
1171
+ const identity = hasIdentity(cwd) ? [] : FALLBACK_IDENTITY;
1172
+ execFileSync("git", [...identity, "commit", "-m", "feat: initial project scaffold"], {
1173
+ cwd,
1174
+ stdio: "ignore"
1175
+ });
1122
1176
  }
1123
1177
 
1124
1178
  // src/scaffold.ts
@@ -1148,7 +1202,7 @@ function collectFiles(options) {
1148
1202
  files.push(...template.files(options));
1149
1203
  files.push(generateGitignore());
1150
1204
  files.push(generateEnvExample(options.provider, options.template));
1151
- files.push(generateCogitatorYml(options.provider));
1205
+ files.push(generateCogitatorYml(options.provider, options.template));
1152
1206
  files.push(generateReadme(options));
1153
1207
  if (options.template !== "nextjs") {
1154
1208
  files.push(generateTsconfig());
@@ -1161,6 +1215,17 @@ function collectFiles(options) {
1161
1215
  }
1162
1216
  return files;
1163
1217
  }
1218
+ function runStep(spinner2, messages, step) {
1219
+ spinner2.start(messages.start);
1220
+ try {
1221
+ step();
1222
+ spinner2.stop(messages.done);
1223
+ return { status: "done" };
1224
+ } catch (error) {
1225
+ spinner2.stop(messages.failed);
1226
+ return { status: "failed", error: error instanceof Error ? error : new Error(String(error)) };
1227
+ }
1228
+ }
1164
1229
  async function scaffold(options) {
1165
1230
  if (fs.existsSync(options.path) && fs.readdirSync(options.path).length > 0) {
1166
1231
  throw new Error(`Directory "${options.path}" already exists and is not empty`);
@@ -1173,22 +1238,25 @@ async function scaffold(options) {
1173
1238
  writeFile(options.path, file);
1174
1239
  }
1175
1240
  s.stop("Generated project files");
1176
- s.start("Installing dependencies");
1177
- try {
1178
- installDependencies(options.path, options.packageManager);
1179
- s.stop("Installed dependencies");
1180
- } catch {
1181
- s.stop("Failed to install dependencies \u2014 run manually");
1182
- }
1183
- if (options.git && isGitInstalled()) {
1184
- s.start("Initializing git repository");
1185
- try {
1186
- initGitRepo(options.path);
1187
- s.stop("Initialized git repository");
1188
- } catch {
1189
- s.stop("Failed to initialize git \u2014 run manually");
1190
- }
1191
- }
1241
+ const install = options.install === false ? { status: "skipped" } : runStep(
1242
+ s,
1243
+ {
1244
+ start: "Installing dependencies",
1245
+ done: "Installed dependencies",
1246
+ failed: `Failed to install dependencies, run "${options.packageManager} install" yourself`
1247
+ },
1248
+ () => installDependencies(options.path, options.packageManager)
1249
+ );
1250
+ const git = options.git && isGitInstalled() ? runStep(
1251
+ s,
1252
+ {
1253
+ start: "Initializing git repository",
1254
+ done: "Initialized git repository",
1255
+ failed: 'Failed to initialize git, run "git init" yourself'
1256
+ },
1257
+ () => initGitRepo(options.path)
1258
+ ) : { status: "skipped" };
1259
+ return { files: files.map((file) => file.path), install, git };
1192
1260
  }
1193
1261
 
1194
1262
  // src/prompts.ts
@@ -1224,6 +1292,10 @@ function parseArgs(args) {
1224
1292
  parsed.git = true;
1225
1293
  } else if (arg === "--no-git") {
1226
1294
  parsed.git = false;
1295
+ } else if (arg === "--install") {
1296
+ parsed.install = true;
1297
+ } else if (arg === "--no-install") {
1298
+ parsed.install = false;
1227
1299
  } else if (arg === "-y" || arg === "--yes") {
1228
1300
  parsed.yes = true;
1229
1301
  } else if (!arg.startsWith("-") && !parsed.name) {
@@ -1232,78 +1304,83 @@ function parseArgs(args) {
1232
1304
  }
1233
1305
  return parsed;
1234
1306
  }
1235
- async function collectOptions(args) {
1236
- const rawName = args.name || await p2.text({
1237
- message: "Where should we create your project?",
1238
- placeholder: "./my-agents",
1239
- defaultValue: "my-agents",
1240
- validate: (value) => {
1241
- if (value && !value.trim()) return "Project name is required";
1242
- return void 0;
1243
- }
1244
- });
1245
- if (p2.isCancel(rawName)) {
1307
+ var defaultAnswers = {
1308
+ name: "my-agents",
1309
+ template: "basic",
1310
+ provider: "ollama",
1311
+ docker: true,
1312
+ git: true
1313
+ };
1314
+ function unlessCancelled(answer) {
1315
+ if (p2.isCancel(answer)) {
1246
1316
  p2.cancel("Operation cancelled.");
1247
1317
  process.exit(0);
1248
1318
  }
1319
+ return answer;
1320
+ }
1321
+ async function collectOptions(args) {
1322
+ const interactive = !args.yes;
1323
+ const rawName = args.name || (interactive ? unlessCancelled(
1324
+ await p2.text({
1325
+ message: "Where should we create your project?",
1326
+ placeholder: `./${defaultAnswers.name}`,
1327
+ defaultValue: defaultAnswers.name,
1328
+ validate: (value) => {
1329
+ if (value && !value.trim()) return "Project name is required";
1330
+ return void 0;
1331
+ }
1332
+ })
1333
+ ) : defaultAnswers.name);
1249
1334
  const name = rawName.trim();
1250
1335
  const projectName = path2.basename(path2.normalize(name).replace(/^\.\//, "").replace(/^\.\\/, ""));
1251
1336
  const projectPath = path2.resolve(process.cwd(), name);
1252
- const template = args.template || await p2.select({
1253
- message: "Which template would you like?",
1254
- options: templateChoices
1255
- });
1256
- if (p2.isCancel(template)) {
1257
- p2.cancel("Operation cancelled.");
1258
- process.exit(0);
1259
- }
1260
- const provider = args.provider || await p2.select({
1261
- message: "Which LLM provider?",
1262
- options: [
1263
- {
1264
- value: "ollama",
1265
- label: "Ollama",
1266
- hint: "local, free \u2014 requires Ollama installed"
1267
- },
1268
- { value: "openai", label: "OpenAI", hint: "GPT-4o" },
1269
- { value: "anthropic", label: "Anthropic", hint: "Claude Sonnet" },
1270
- { value: "google", label: "Google Gemini", hint: "Gemini 2.5 Flash" }
1271
- ]
1272
- });
1273
- if (p2.isCancel(provider)) {
1274
- p2.cancel("Operation cancelled.");
1275
- process.exit(0);
1276
- }
1277
- const packageManager = args.packageManager || await p2.select({
1278
- message: "Package manager?",
1279
- options: [
1280
- { value: "pnpm", label: "pnpm" },
1281
- { value: "npm", label: "npm" },
1282
- { value: "yarn", label: "yarn" },
1283
- { value: "bun", label: "bun" }
1284
- ],
1285
- initialValue: detectPackageManager()
1286
- });
1287
- if (p2.isCancel(packageManager)) {
1288
- p2.cancel("Operation cancelled.");
1289
- process.exit(0);
1290
- }
1291
- const docker = args.docker ?? await p2.confirm({
1292
- message: "Include Docker Compose? (Redis + Postgres" + (provider === "ollama" ? " + Ollama)" : ")"),
1293
- initialValue: true
1294
- });
1295
- if (p2.isCancel(docker)) {
1296
- p2.cancel("Operation cancelled.");
1297
- process.exit(0);
1298
- }
1299
- const git = args.git ?? await p2.confirm({
1300
- message: "Initialize git repository?",
1301
- initialValue: true
1302
- });
1303
- if (p2.isCancel(git)) {
1304
- p2.cancel("Operation cancelled.");
1305
- process.exit(0);
1306
- }
1337
+ const template = args.template ?? (interactive ? unlessCancelled(
1338
+ await p2.select({
1339
+ message: "Which template would you like?",
1340
+ options: templateChoices,
1341
+ initialValue: defaultAnswers.template
1342
+ })
1343
+ ) : defaultAnswers.template);
1344
+ const provider = args.provider ?? (interactive ? unlessCancelled(
1345
+ await p2.select({
1346
+ message: "Which LLM provider?",
1347
+ options: [
1348
+ {
1349
+ value: "ollama",
1350
+ label: "Ollama",
1351
+ hint: `${defaultModels.ollama} \u2014 local, free, requires Ollama installed`
1352
+ },
1353
+ { value: "openai", label: "OpenAI", hint: defaultModels.openai },
1354
+ { value: "anthropic", label: "Anthropic", hint: defaultModels.anthropic },
1355
+ { value: "google", label: "Google Gemini", hint: defaultModels.google }
1356
+ ],
1357
+ initialValue: defaultAnswers.provider
1358
+ })
1359
+ ) : defaultAnswers.provider);
1360
+ const packageManager = args.packageManager ?? (interactive ? unlessCancelled(
1361
+ await p2.select({
1362
+ message: "Package manager?",
1363
+ options: [
1364
+ { value: "pnpm", label: "pnpm" },
1365
+ { value: "npm", label: "npm" },
1366
+ { value: "yarn", label: "yarn" },
1367
+ { value: "bun", label: "bun" }
1368
+ ],
1369
+ initialValue: detectPackageManager()
1370
+ })
1371
+ ) : detectPackageManager());
1372
+ const docker = args.docker ?? (interactive ? unlessCancelled(
1373
+ await p2.confirm({
1374
+ message: "Include Docker Compose? (Redis + Postgres" + (provider === "ollama" ? " + Ollama)" : ")"),
1375
+ initialValue: defaultAnswers.docker
1376
+ })
1377
+ ) : defaultAnswers.docker);
1378
+ const git = args.git ?? (interactive ? unlessCancelled(
1379
+ await p2.confirm({
1380
+ message: "Initialize git repository?",
1381
+ initialValue: defaultAnswers.git
1382
+ })
1383
+ ) : defaultAnswers.git);
1307
1384
  return {
1308
1385
  name: projectName,
1309
1386
  path: projectPath,
@@ -1311,7 +1388,8 @@ async function collectOptions(args) {
1311
1388
  provider,
1312
1389
  packageManager,
1313
1390
  docker,
1314
- git
1391
+ git,
1392
+ ...args.install !== void 0 && { install: args.install }
1315
1393
  };
1316
1394
  }
1317
1395
  export {