@inkeep/create-agents 0.2.0 → 0.2.2

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/utils.js CHANGED
@@ -1,19 +1,20 @@
1
- import color from 'picocolors';
2
1
  import * as p from '@clack/prompts';
3
- import fs from 'fs-extra';
4
2
  import { exec } from 'child_process';
5
- import { promisify } from 'util';
3
+ import fs from 'fs-extra';
6
4
  import path from 'path';
5
+ import color from 'picocolors';
6
+ import { promisify } from 'util';
7
+ import { cloneTemplate, getAvailableTemplates } from './templates.js';
7
8
  const execAsync = promisify(exec);
8
- export const defaultDualModelConfigurations = {
9
+ export const defaultGoogleModelConfigurations = {
9
10
  base: {
10
- model: 'anthropic/claude-sonnet-4-20250514',
11
+ model: 'google/gemini-2.5-flash',
11
12
  },
12
13
  structuredOutput: {
13
- model: 'openai/gpt-4.1-mini-2025-04-14',
14
+ model: 'google/gemini-2.5-flash-lite',
14
15
  },
15
16
  summarizer: {
16
- model: 'openai/gpt-4.1-nano-2025-04-14',
17
+ model: 'google/gemini-2.5-flash-lite',
17
18
  },
18
19
  };
19
20
  export const defaultOpenaiModelConfigurations = {
@@ -32,17 +33,42 @@ export const defaultAnthropicModelConfigurations = {
32
33
  model: 'anthropic/claude-sonnet-4-20250514',
33
34
  },
34
35
  structuredOutput: {
35
- model: 'anthropic/claude-sonnet-4-20250514',
36
+ model: 'anthropic/claude-3-5-haiku-20241022',
36
37
  },
37
38
  summarizer: {
38
- model: 'anthropic/claude-sonnet-4-20250514',
39
+ model: 'anthropic/claude-3-5-haiku-20241022',
39
40
  },
40
41
  };
41
42
  export const createAgents = async (args = {}) => {
42
- let { projectId, dirName, openAiKey, anthropicKey } = args;
43
+ let { dirName, openAiKey, anthropicKey, googleKey, template, customProjectId } = args;
43
44
  const tenantId = 'default';
44
45
  const manageApiPort = '3002';
45
46
  const runApiPort = '3003';
47
+ let projectId;
48
+ let templateName;
49
+ // Determine project ID and template based on user input
50
+ if (customProjectId) {
51
+ // User provided custom project ID - use it as-is, no template needed
52
+ projectId = customProjectId;
53
+ templateName = ''; // No template will be cloned
54
+ }
55
+ else if (template) {
56
+ // User provided template - validate it exists and use template name as project ID
57
+ const availableTemplates = await getAvailableTemplates();
58
+ if (!availableTemplates.includes(template)) {
59
+ p.cancel(`${color.red('✗')} Template "${template}" not found\n\n` +
60
+ `${color.yellow('Available templates:')}\n` +
61
+ ` • ${availableTemplates.join('\n • ')}\n`);
62
+ process.exit(0);
63
+ }
64
+ projectId = template;
65
+ templateName = template;
66
+ }
67
+ else {
68
+ // No template or custom project ID provided - use defaults
69
+ projectId = 'weather-graph';
70
+ templateName = 'weather-graph';
71
+ }
46
72
  p.intro(color.inverse(' Create Agents Directory '));
47
73
  // Prompt for directory name if not provided
48
74
  if (!dirName) {
@@ -63,27 +89,15 @@ export const createAgents = async (args = {}) => {
63
89
  }
64
90
  dirName = dirResponse;
65
91
  }
66
- // Prompt for project ID
67
- if (!projectId) {
68
- const projectIdResponse = await p.text({
69
- message: 'Enter your project ID:',
70
- placeholder: '(default)',
71
- defaultValue: 'default',
72
- });
73
- if (p.isCancel(projectIdResponse)) {
74
- p.cancel('Operation cancelled');
75
- process.exit(0);
76
- }
77
- projectId = projectIdResponse;
78
- }
92
+ // Project ID is already determined above based on template/customProjectId logic
79
93
  // If keys aren't provided via CLI args, prompt for provider selection and keys
80
94
  if (!anthropicKey && !openAiKey) {
81
95
  const providerChoice = await p.select({
82
96
  message: 'Which AI provider(s) would you like to use?',
83
97
  options: [
84
- { value: 'both', label: 'Both Anthropic and OpenAI (recommended)' },
85
- { value: 'anthropic', label: 'Anthropic only' },
86
- { value: 'openai', label: 'OpenAI only' },
98
+ { value: 'anthropic', label: 'Anthropic' },
99
+ { value: 'openai', label: 'OpenAI' },
100
+ { value: 'google', label: 'Google' },
87
101
  ],
88
102
  });
89
103
  if (p.isCancel(providerChoice)) {
@@ -91,7 +105,7 @@ export const createAgents = async (args = {}) => {
91
105
  process.exit(0);
92
106
  }
93
107
  // Prompt for keys based on selection
94
- if (providerChoice === 'anthropic' || providerChoice === 'both') {
108
+ if (providerChoice === 'anthropic') {
95
109
  const anthropicKeyResponse = await p.text({
96
110
  message: 'Enter your Anthropic API key:',
97
111
  placeholder: 'sk-ant-...',
@@ -108,7 +122,7 @@ export const createAgents = async (args = {}) => {
108
122
  }
109
123
  anthropicKey = anthropicKeyResponse;
110
124
  }
111
- if (providerChoice === 'openai' || providerChoice === 'both') {
125
+ else if (providerChoice === 'openai') {
112
126
  const openAiKeyResponse = await p.text({
113
127
  message: 'Enter your OpenAI API key:',
114
128
  placeholder: 'sk-...',
@@ -125,47 +139,41 @@ export const createAgents = async (args = {}) => {
125
139
  }
126
140
  openAiKey = openAiKeyResponse;
127
141
  }
128
- }
129
- else {
130
- // If some keys are provided via CLI args, prompt for missing ones
131
- if (!anthropicKey) {
132
- const anthropicKeyResponse = await p.text({
133
- message: 'Enter your Anthropic API key (optional):',
134
- placeholder: 'sk-ant-...',
135
- defaultValue: '',
136
- });
137
- if (p.isCancel(anthropicKeyResponse)) {
138
- p.cancel('Operation cancelled');
139
- process.exit(0);
140
- }
141
- anthropicKey = anthropicKeyResponse || undefined;
142
- }
143
- if (!openAiKey) {
144
- const openAiKeyResponse = await p.text({
145
- message: 'Enter your OpenAI API key (optional):',
146
- placeholder: 'sk-...',
147
- defaultValue: '',
142
+ else if (providerChoice === 'google') {
143
+ const googleKeyResponse = await p.text({
144
+ message: 'Enter your Google API key:',
145
+ placeholder: 'AIzaSy...',
146
+ validate: (value) => {
147
+ if (!value || value.trim() === '') {
148
+ return 'Google API key is required';
149
+ }
150
+ return undefined;
151
+ },
148
152
  });
149
- if (p.isCancel(openAiKeyResponse)) {
153
+ if (p.isCancel(googleKeyResponse)) {
150
154
  p.cancel('Operation cancelled');
151
155
  process.exit(0);
152
156
  }
153
- openAiKey = openAiKeyResponse || undefined;
157
+ googleKey = googleKeyResponse;
154
158
  }
155
159
  }
156
160
  let defaultModelSettings = {};
157
- if (anthropicKey && openAiKey) {
158
- defaultModelSettings = defaultDualModelConfigurations;
159
- }
160
- else if (anthropicKey) {
161
+ if (anthropicKey) {
161
162
  defaultModelSettings = defaultAnthropicModelConfigurations;
162
163
  }
163
164
  else if (openAiKey) {
164
165
  defaultModelSettings = defaultOpenaiModelConfigurations;
165
166
  }
167
+ else if (googleKey) {
168
+ defaultModelSettings = defaultGoogleModelConfigurations;
169
+ }
166
170
  const s = p.spinner();
167
171
  s.start('Creating directory structure...');
168
172
  try {
173
+ const agentsTemplateRepo = 'https://github.com/inkeep/create-agents-template';
174
+ const projectTemplateRepo = templateName
175
+ ? `https://github.com/inkeep/agents-cookbook/templates/${templateName}`
176
+ : null;
169
177
  const directoryPath = path.resolve(process.cwd(), dirName);
170
178
  // Check if directory already exists
171
179
  if (await fs.pathExists(directoryPath)) {
@@ -180,8 +188,10 @@ export const createAgents = async (args = {}) => {
180
188
  s.start('Cleaning existing directory...');
181
189
  await fs.emptyDir(directoryPath);
182
190
  }
183
- // Create the project directory
184
- await fs.ensureDir(directoryPath);
191
+ // Clone the template repository
192
+ s.message('Building template...');
193
+ await cloneTemplate(agentsTemplateRepo, directoryPath);
194
+ // Change to the project directory
185
195
  process.chdir(directoryPath);
186
196
  const config = {
187
197
  dirName,
@@ -189,28 +199,31 @@ export const createAgents = async (args = {}) => {
189
199
  projectId,
190
200
  openAiKey,
191
201
  anthropicKey,
202
+ googleKey,
192
203
  manageApiPort: manageApiPort || '3002',
193
204
  runApiPort: runApiPort || '3003',
194
205
  modelSettings: defaultModelSettings,
206
+ customProject: customProjectId ? true : false,
195
207
  };
196
- // Create workspace structure
197
- s.message('Setting up workspace structure...');
198
- await createWorkspaceStructure(projectId);
199
- // Setup package configurations
200
- s.message('Creating package configurations...');
201
- await setupPackageConfigurations(dirName);
208
+ // Create workspace structure for project-specific files
209
+ s.message('Setting up project structure...');
210
+ await createWorkspaceStructure();
202
211
  // Create environment files
203
212
  s.message('Setting up environment files...');
204
213
  await createEnvironmentFiles(config);
205
- // Create service files
206
- s.message('Creating service files...');
207
- await createServiceFiles(config);
208
- // Create documentation
209
- s.message('Creating documentation...');
210
- await createDocumentation(config);
211
- // Create turbo config
212
- s.message('Setting up Turbo...');
213
- await createTurboConfig();
214
+ // Create project template folder (only if template is specified)
215
+ if (projectTemplateRepo) {
216
+ s.message('Creating project template folder...');
217
+ const templateTargetPath = `src/${projectId}`;
218
+ await cloneTemplate(projectTemplateRepo, templateTargetPath);
219
+ }
220
+ else {
221
+ s.message('Creating empty project folder...');
222
+ await fs.ensureDir(`src/${projectId}`);
223
+ }
224
+ // create or overwrite inkeep.config.ts
225
+ s.message('Creating inkeep.config.ts...');
226
+ await createInkeepConfig(config);
214
227
  // Install dependencies
215
228
  s.message('Installing dependencies (this may take a while)...');
216
229
  await installDependencies();
@@ -218,8 +231,9 @@ export const createAgents = async (args = {}) => {
218
231
  s.message('Setting up database...');
219
232
  await setupDatabase();
220
233
  // Setup project in database
221
- s.message('Setting up project in database...');
222
- await setupProjectInDatabase();
234
+ s.message('Pushing project...');
235
+ await setupProjectInDatabase(config);
236
+ s.message('Project setup complete!');
223
237
  s.stop();
224
238
  // Success message with next steps
225
239
  p.note(`${color.green('✓')} Project created at: ${color.cyan(directoryPath)}\n\n` +
@@ -236,7 +250,7 @@ export const createAgents = async (args = {}) => {
236
250
  ` • Manage UI: Available with management API\n` +
237
251
  `\n${color.yellow('Configuration:')}\n` +
238
252
  ` • Edit .env for environment variables\n` +
239
- ` • Edit src/${projectId}/weather.graph.ts for agent definitions\n` +
253
+ ` • Edit files in src/${projectId}/ for agent definitions\n` +
240
254
  ` • Use 'inkeep push' to deploy agents to the platform\n` +
241
255
  ` • Use 'inkeep chat' to test your agents locally\n`, 'Ready to go!');
242
256
  }
@@ -246,138 +260,9 @@ export const createAgents = async (args = {}) => {
246
260
  process.exit(1);
247
261
  }
248
262
  };
249
- async function createWorkspaceStructure(projectId) {
263
+ async function createWorkspaceStructure() {
250
264
  // Create the workspace directory structure
251
- await fs.ensureDir(`src/${projectId}`);
252
- await fs.ensureDir('apps/manage-api/src');
253
- await fs.ensureDir('apps/run-api/src');
254
- await fs.ensureDir('apps/shared');
255
- await fs.ensureDir('scripts');
256
- }
257
- async function setupPackageConfigurations(dirName) {
258
- // Root package.json (workspace root)
259
- const rootPackageJson = {
260
- name: dirName,
261
- version: '0.1.0',
262
- description: 'An Inkeep Agent Framework directory',
263
- private: true,
264
- type: 'module',
265
- scripts: {
266
- dev: 'turbo dev',
267
- 'db:push': 'drizzle-kit push',
268
- setup: 'node scripts/setup.js',
269
- 'dev:setup': 'node scripts/dev-setup.js',
270
- start: 'pnpm dev:setup'
271
- },
272
- dependencies: {},
273
- devDependencies: {
274
- '@biomejs/biome': '^1.8.0',
275
- '@inkeep/agents-cli': '^0.1.1',
276
- 'drizzle-kit': '^0.31.4',
277
- tsx: '^4.19.0',
278
- turbo: '^2.5.5',
279
- "concurrently": '^8.2.0',
280
- 'wait-on': '^8.0.0',
281
- },
282
- engines: {
283
- node: '>=22.x',
284
- },
285
- packageManager: 'pnpm@10.10.0',
286
- pnpm: {
287
- onlyBuiltDependencies: [
288
- 'keytar'
289
- ]
290
- },
291
- };
292
- await fs.writeJson('package.json', rootPackageJson, { spaces: 2 });
293
- // Create pnpm-workspace.yaml for pnpm workspaces
294
- const pnpmWorkspace = `packages:
295
- - "apps/*"
296
- `;
297
- await fs.writeFile('pnpm-workspace.yaml', pnpmWorkspace);
298
- // Add shared dependencies to root package.json
299
- rootPackageJson.dependencies = {
300
- '@inkeep/agents-core': '^0.1.0',
301
- '@inkeep/agents-sdk': '^0.1.0',
302
- dotenv: '^16.0.0',
303
- zod: '^4.1.5',
304
- };
305
- await fs.writeJson('package.json', rootPackageJson, { spaces: 2 });
306
- // Manage API package
307
- const manageApiPackageJson = {
308
- name: `@${dirName}/manage-api`,
309
- version: '0.1.0',
310
- description: 'Manage API for agents',
311
- type: 'module',
312
- scripts: {
313
- build: 'tsc',
314
- dev: 'tsx watch src/index.ts',
315
- start: 'node dist/index.js',
316
- },
317
- dependencies: {
318
- '@inkeep/agents-manage-api': '^0.1.1',
319
- '@inkeep/agents-core': '^0.1.0',
320
- '@hono/node-server': '^1.14.3',
321
- },
322
- devDependencies: {
323
- '@types/node': '^20.12.0',
324
- tsx: '^4.19.0',
325
- typescript: '^5.4.0',
326
- },
327
- engines: {
328
- node: '>=22.x',
329
- },
330
- };
331
- await fs.writeJson('apps/manage-api/package.json', manageApiPackageJson, { spaces: 2 });
332
- // Run API package
333
- const runApiPackageJson = {
334
- name: `@${dirName}/run-api`,
335
- version: '0.1.0',
336
- description: 'Run API for agents',
337
- type: 'module',
338
- scripts: {
339
- dev: 'tsx watch src/index.ts',
340
- start: 'node dist/index.js',
341
- },
342
- dependencies: {
343
- '@inkeep/agents-run-api': '^0.1.1',
344
- '@inkeep/agents-core': '^0.1.0',
345
- '@hono/node-server': '^1.14.3',
346
- },
347
- devDependencies: {
348
- '@types/node': '^20.12.0',
349
- tsx: '^4.19.0',
350
- typescript: '^5.4.0',
351
- },
352
- engines: {
353
- node: '>=22.x',
354
- },
355
- };
356
- await fs.writeJson('apps/run-api/package.json', runApiPackageJson, { spaces: 2 });
357
- // TypeScript configs for API services
358
- const apiTsConfig = {
359
- compilerOptions: {
360
- target: 'ES2022',
361
- module: 'ESNext',
362
- moduleResolution: 'bundler',
363
- strict: true,
364
- esModuleInterop: true,
365
- skipLibCheck: true,
366
- forceConsistentCasingInFileNames: true,
367
- declaration: true,
368
- outDir: './dist',
369
- rootDir: '..',
370
- allowImportingTsExtensions: false,
371
- resolveJsonModule: true,
372
- isolatedModules: true,
373
- noEmit: false,
374
- },
375
- include: ['src/**/*', '../shared/**/*'],
376
- exclude: ['node_modules', 'dist', '**/*.test.ts'],
377
- };
378
- await fs.writeJson('apps/manage-api/tsconfig.json', apiTsConfig, { spaces: 2 });
379
- await fs.writeJson('apps/run-api/tsconfig.json', apiTsConfig, { spaces: 2 });
380
- // No tsconfig needed for UI since we're using the packaged version
265
+ await fs.ensureDir(`src`);
381
266
  }
382
267
  async function createEnvironmentFiles(config) {
383
268
  // Root .env file
@@ -385,642 +270,82 @@ async function createEnvironmentFiles(config) {
385
270
  ENVIRONMENT=development
386
271
 
387
272
  # Database
388
- DB_FILE_NAME=file:./local.db
273
+ DB_FILE_NAME=file:${process.cwd()}/local.db
389
274
 
390
275
  # AI Provider Keys
391
276
  ANTHROPIC_API_KEY=${config.anthropicKey || 'your-anthropic-key-here'}
392
277
  OPENAI_API_KEY=${config.openAiKey || 'your-openai-key-here'}
278
+ GOOGLE_GENERATIVE_AI_API_KEY=${config.googleKey || 'your-google-key-here'}
393
279
 
394
- # Logging
395
- LOG_LEVEL=debug
396
-
397
- # Service Ports
398
- MANAGE_API_PORT=${config.manageApiPort}
399
- RUN_API_PORT=${config.runApiPort}
280
+ # Inkeep API URLs
281
+ INKEEP_AGENTS_MANAGE_API_URL="http://localhost:3002"
282
+ INKEEP_AGENTS_RUN_API_URL="http://localhost:3003"
400
283
 
401
- # UI Configuration (for dashboard)
284
+ # SigNoz
285
+ SIGNOZ_URL=your-signoz-url-here
286
+ SIGNOZ_API_KEY=your-signoz-api-key-here
402
287
 
288
+ # Nango
289
+ NANGO_HOST=your-nango-host-here
290
+ NANGO_CONNECT_BASE_URL=your-nango-connect-base-url-here
291
+ NANGO_SECRET_KEY=
403
292
  `;
404
293
  await fs.writeFile('.env', envContent);
405
- // Create .env.example
406
- const envExample = envContent.replace(/=.+$/gm, '=');
407
- await fs.writeFile('.env.example', envExample);
408
- // Create setup script
409
- await createSetupScript(config);
410
- // Create dev-setup script
411
- await createDevSetupScript(config);
412
- // Create .env files for each API service
413
- const runApiEnvContent = `# Environment
414
- ENVIRONMENT=development
415
-
416
- # Database (relative path from API directory)
417
- DB_FILE_NAME=file:../../local.db
418
-
419
- # AI Provider Keys
420
- ANTHROPIC_API_KEY=${config.anthropicKey || 'your-anthropic-key-here'}
421
- OPENAI_API_KEY=${config.openAiKey || 'your-openai-key-here'}
422
-
423
- AGENTS_RUN_API_URL=http://localhost:${config.runApiPort}
424
- `;
425
- const manageApiEnvContent = `# Environment
426
- ENVIRONMENT=development
427
-
428
- # Database (relative path from API directory)
429
- DB_FILE_NAME=file:../../local.db
430
-
431
- AGENTS_MANAGE_API_URL=http://localhost:${config.manageApiPort}
432
- `;
433
- await fs.writeFile('apps/manage-api/.env', manageApiEnvContent);
434
- await fs.writeFile('apps/run-api/.env', runApiEnvContent);
435
- // Create .gitignore
436
- const gitignore = `# Dependencies
437
- node_modules/
438
- .pnpm-store/
439
-
440
- # Environment variables
441
- .env
442
- .env.local
443
- .env.development.local
444
- .env.test.local
445
- .env.production.local
446
-
447
- # Build outputs
448
- dist/
449
- build/
450
- .next/
451
- .turbo/
452
-
453
- # Logs
454
- *.log
455
- logs/
456
-
457
- # Database
458
- *.db
459
- *.sqlite
460
- *.sqlite3
461
-
462
- # IDE
463
- .vscode/
464
- .idea/
465
- *.swp
466
- *.swo
467
-
468
- # OS
469
- .DS_Store
470
- Thumbs.db
471
-
472
- # Coverage
473
- coverage/
474
- .nyc_output/
475
-
476
- # Temporary files
477
- *.tmp
478
- *.temp
479
- .cache/
480
-
481
- # Runtime data
482
- pids/
483
- *.pid
484
- *.seed
485
- *.pid.lock
486
- `;
487
- await fs.writeFile('.gitignore', gitignore);
488
- // Create biome.json
489
- const biomeConfig = {
490
- linter: {
491
- enabled: true,
492
- rules: {
493
- recommended: true,
494
- },
495
- },
496
- formatter: {
497
- enabled: true,
498
- indentStyle: 'space',
499
- indentWidth: 2,
500
- },
501
- organizeImports: {
502
- enabled: true,
503
- },
504
- javascript: {
505
- formatter: {
506
- semicolons: 'always',
507
- quoteStyle: 'single',
508
- },
509
- },
510
- };
511
- await fs.writeJson('biome.json', biomeConfig, { spaces: 2 });
512
- }
513
- async function createSetupScript(config) {
514
- const setupScriptContent = `#!/usr/bin/env node
515
-
516
- import { createDatabaseClient, createProject, getProject } from '@inkeep/agents-core';
517
- import dotenv from 'dotenv';
518
-
519
- // Load environment variables
520
- dotenv.config();
521
-
522
- const dbUrl = process.env.DB_FILE_NAME || 'file:local.db';
523
- const tenantId = '${config.tenantId}';
524
- const projectId = '${config.projectId}';
525
- const projectName = '${config.projectId}';
526
- const projectDescription = 'Generated Inkeep Agents project';
527
-
528
- async function setupProject() {
529
- console.log('🚀 Setting up your Inkeep Agents project...');
530
-
531
- try {
532
- const dbClient = createDatabaseClient({ url: dbUrl });
533
-
534
- // Check if project already exists
535
- console.log('📋 Checking if project already exists...');
536
- try {
537
- const existingProject = await getProject(dbClient)({
538
- id: projectId,
539
- tenantId: tenantId
540
- });
541
-
542
- if (existingProject) {
543
- console.log('✅ Project already exists in database:', existingProject.name);
544
- console.log('🎯 Project ID:', projectId);
545
- console.log('🏢 Tenant ID:', tenantId);
546
- return;
547
- }
548
- } catch (error) {
549
- // Project doesn't exist, continue with creation
550
- }
551
-
552
- // Create the project in the database
553
- console.log('📦 Creating project in database...');
554
- await createProject(dbClient)({
555
- id: projectId,
556
- tenantId: tenantId,
557
- name: projectName,
558
- description: projectDescription,
559
- models: ${JSON.stringify(config.modelSettings, null, 2)},
560
- });
561
-
562
- console.log('✅ Project created successfully!');
563
- console.log('🎯 Project ID:', projectId);
564
- console.log('🏢 Tenant ID:', tenantId);
565
- console.log('');
566
- console.log('🎉 Setup complete! Your development servers are running.');
567
- console.log('');
568
- console.log('📋 Available URLs:');
569
- console.log(' - Management UI: http://localhost:${config.manageApiPort}');
570
- console.log(' - Runtime API: http://localhost:${config.runApiPort}');
571
- console.log('');
572
- console.log('🚀 Ready to build agents!');
573
-
574
- } catch (error) {
575
- console.error('❌ Failed to setup project:', error);
576
- process.exit(1);
577
- }
578
- }
579
-
580
- setupProject();
581
- `;
582
- await fs.writeFile('scripts/setup.js', setupScriptContent);
583
- // Make the script executable
584
- await fs.chmod('scripts/setup.js', 0o755);
585
- }
586
- async function createDevSetupScript(config) {
587
- const devSetupScriptContent = `#!/usr/bin/env node
588
-
589
- import { spawn } from 'child_process';
590
- import { promisify } from 'util';
591
- import { exec } from 'child_process';
592
-
593
- const execAsync = promisify(exec);
594
-
595
- async function devSetup() {
596
- console.log('🚀 Starting Inkeep Agents development environment...');
597
- console.log('');
598
-
599
- try {
600
- // Start development servers in background
601
- console.log('📡 Starting development servers...');
602
- const devProcess = spawn('pnpm', ['dev'], {
603
- stdio: ['pipe', 'pipe', 'pipe'],
604
- detached: false
605
- });
606
-
607
- // Give servers time to start
608
- console.log('⏳ Waiting for servers to start...');
609
- await new Promise(resolve => setTimeout(resolve, 5000));
610
-
611
- console.log('');
612
- console.log('📦 Servers are ready! Setting up project in database...');
613
-
614
- // Run the setup script
615
- await execAsync('pnpm setup');
616
-
617
- console.log('');
618
- console.log('🎉 Development environment is ready!');
619
- console.log('');
620
- console.log('📋 Available URLs:');
621
- console.log(\` - Management UI: http://localhost:${config.manageApiPort}\`);
622
- console.log(\` - Runtime API: http://localhost:${config.runApiPort}\`);
623
- console.log('');
624
- console.log('✨ The servers will continue running. Press Ctrl+C to stop.');
625
-
626
- // Keep the script running so servers don't terminate
627
- process.on('SIGINT', () => {
628
- console.log('\\n👋 Shutting down development servers...');
629
- devProcess.kill();
630
- process.exit(0);
631
- });
632
-
633
- // Wait for the dev process to finish or be killed
634
- devProcess.on('close', (code) => {
635
- console.log(\`Development servers stopped with code \${code}\`);
636
- process.exit(code);
637
- });
638
-
639
- } catch (error) {
640
- console.error('❌ Failed to start development environment:', error.message);
641
- process.exit(1);
642
- }
643
294
  }
644
-
645
- devSetup();
646
- `;
647
- await fs.writeFile('scripts/dev-setup.js', devSetupScriptContent);
648
- await fs.chmod('scripts/dev-setup.js', 0o755);
649
- }
650
- async function createServiceFiles(config) {
651
- const agentsGraph = `import { agent, agentGraph, mcpTool } from '@inkeep/agents-sdk';
652
-
653
- // MCP Tools
654
- const forecastWeatherTool = mcpTool({
655
- id: 'fUI2riwrBVJ6MepT8rjx0',
656
- name: 'Forecast weather',
657
- serverUrl: 'https://weather-forecast-mcp.vercel.app/mcp',
658
- });
659
-
660
- const geocodeAddressTool = mcpTool({
661
- id: 'fdxgfv9HL7SXlfynPx8hf',
662
- name: 'Geocode address',
663
- serverUrl: 'https://geocoder-mcp.vercel.app/mcp',
664
- });
665
-
666
- // Agents
667
- const weatherAssistant = agent({
668
- id: 'weather-assistant',
669
- name: 'Weather assistant',
670
- description: 'Responsible for routing between the geocoder agent and weather forecast agent',
671
- prompt:
672
- 'You are a helpful assistant. When the user asks about the weather in a given location, first ask the geocoder agent for the coordinates, and then pass those coordinates to the weather forecast agent to get the weather forecast',
673
- canDelegateTo: () => [weatherForecaster, geocoderAgent],
674
- });
675
-
676
- const weatherForecaster = agent({
677
- id: 'weather-forecaster',
678
- name: 'Weather forecaster',
679
- description:
680
- 'This agent is responsible for taking in coordinates and returning the forecast for the weather at that location',
681
- prompt:
682
- 'You are a helpful assistant responsible for taking in coordinates and returning the forecast for that location using your forecasting tool',
683
- canUse: () => [forecastWeatherTool],
684
- });
685
-
686
- const geocoderAgent = agent({
687
- id: 'geocoder-agent',
688
- name: 'Geocoder agent',
689
- description: 'Responsible for converting location or address into coordinates',
690
- prompt:
691
- 'You are a helpful assistant responsible for converting location or address into coordinates using your geocode tool',
692
- canUse: () => [geocodeAddressTool],
693
- });
694
-
695
- // Agent Graph
696
- export const weatherGraph = agentGraph({
697
- id: 'weather-graph',
698
- name: 'Weather graph',
699
- defaultAgent: weatherAssistant,
700
- agents: () => [weatherAssistant, weatherForecaster, geocoderAgent],
701
- });`;
702
- await fs.writeFile(`src/${config.projectId}/weather.graph.ts`, agentsGraph);
703
- // Inkeep config (if using CLI)
295
+ async function createInkeepConfig(config) {
704
296
  const inkeepConfig = `import { defineConfig } from '@inkeep/agents-cli/config';
705
297
 
706
- const config = defineConfig({
707
- tenantId: "${config.tenantId}",
708
- projectId: "${config.projectId}",
709
- agentsManageApiUrl: \`http://localhost:\${process.env.MANAGE_API_PORT || '3002'}\`,
710
- agentsRunApiUrl: \`http://localhost:\${process.env.RUN_API_PORT || '3003'}\`,
711
- modelSettings: ${JSON.stringify(config.modelSettings, null, 2)},
712
- });
713
-
714
- export default config;`;
298
+ const config = defineConfig({
299
+ tenantId: "${config.tenantId}",
300
+ projectId: "${config.projectId}",
301
+ agentsManageApiUrl: 'http://localhost:3002',
302
+ agentsRunApiUrl: 'http://localhost:3003',
303
+ modelSettings: ${JSON.stringify(config.modelSettings, null, 2)},
304
+ });
305
+
306
+ export default config;`;
715
307
  await fs.writeFile(`src/${config.projectId}/inkeep.config.ts`, inkeepConfig);
716
- // Create .env file for the project directory (for inkeep CLI commands)
717
- const projectEnvContent = `# Environment
718
- ENVIRONMENT=development
719
-
720
- # Database (relative path from project directory)
721
- DB_FILE_NAME=file:../../local.db
722
- `;
723
- await fs.writeFile(`src/${config.projectId}/.env`, projectEnvContent);
724
- // Shared credential stores
725
- const credentialStoresFile = `import {
726
- InMemoryCredentialStore,
727
- createNangoCredentialStore,
728
- createKeyChainStore,
729
- } from '@inkeep/agents-core';
730
-
731
- // Shared credential stores configuration for all services
732
- export const credentialStores = [
733
- new InMemoryCredentialStore('memory-default'),
734
- ...(process.env.NANGO_SECRET_KEY
735
- ? [
736
- createNangoCredentialStore('nango-default', {
737
- apiUrl: process.env.NANGO_HOST || 'https://api.nango.dev',
738
- secretKey: process.env.NANGO_SECRET_KEY,
739
- }),
740
- ]
741
- : []),
742
- createKeyChainStore('keychain-default'),
743
- ];
744
- `;
745
- await fs.writeFile('apps/shared/credential-stores.ts', credentialStoresFile);
746
- // Manage API
747
- const manageApiIndex = `import { serve } from '@hono/node-server';
748
- import { createManagementApp } from '@inkeep/agents-manage-api';
749
- import { getLogger } from '@inkeep/agents-core';
750
- import { credentialStores } from '../../shared/credential-stores.js';
751
-
752
- const logger = getLogger('management-api');
753
-
754
- // Create the Hono app
755
- const app = createManagementApp({
756
- serverConfig: {
757
- port: Number(process.env.MANAGE_API_PORT) || 3002,
758
- serverOptions: {
759
- requestTimeout: 60000,
760
- keepAliveTimeout: 60000,
761
- keepAlive: true,
762
- },
763
- },
764
- credentialStores,
765
- });
766
-
767
- const port = Number(process.env.MANAGE_API_PORT) || 3002;
768
-
769
- // Start the server using @hono/node-server
770
- serve(
771
- {
772
- fetch: app.fetch,
773
- port,
774
- },
775
- (info) => {
776
- logger.info({}, \`📝 Management API running on http://localhost:\${info.port}\`);
777
- logger.info({}, \`📝 OpenAPI documentation available at http://localhost:\${info.port}/openapi.json\`);
778
- }
779
- );`;
780
- await fs.writeFile('apps/manage-api/src/index.ts', manageApiIndex);
781
- // Run API
782
- const runApiIndex = `import { serve } from '@hono/node-server';
783
- import { createExecutionApp } from '@inkeep/agents-run-api';
784
- import { credentialStores } from '../../shared/credential-stores.js';
785
- import { getLogger } from '@inkeep/agents-core';
786
-
787
- const logger = getLogger('execution-api');
788
-
789
-
790
- // Create the Hono app
791
- const app = createExecutionApp({
792
- serverConfig: {
793
- port: Number(process.env.RUN_API_PORT) || 3003,
794
- serverOptions: {
795
- requestTimeout: 120000,
796
- keepAliveTimeout: 60000,
797
- keepAlive: true,
798
- },
799
- },
800
- credentialStores,
801
- });
802
-
803
- const port = Number(process.env.RUN_API_PORT) || 3003;
804
-
805
- // Start the server using @hono/node-server
806
- serve(
807
- {
808
- fetch: app.fetch,
809
- port,
810
- },
811
- (info) => {
812
- logger.info({}, \`📝 Run API running on http://localhost:\${info.port}\`);
813
- logger.info({}, \`📝 OpenAPI documentation available at http://localhost:\${info.port}/openapi.json\`);
814
- }
815
- );`;
816
- await fs.writeFile('apps/run-api/src/index.ts', runApiIndex);
817
- // Database configuration
818
- const drizzleConfig = `import { defineConfig } from 'drizzle-kit';
819
-
820
- export default defineConfig({
821
- schema: 'node_modules/@inkeep/agents-core/dist/db/schema.js',
822
- dialect: 'sqlite',
823
- dbCredentials: {
824
- url: process.env.DB_FILE_NAME || 'file:./local.db'
825
- },
308
+ if (config.customProject) {
309
+ const customIndexContent = `import { project } from '@inkeep/agents-sdk';
310
+
311
+ export const myProject = project({
312
+ id: "${config.projectId}",
313
+ name: "${config.projectId}",
314
+ description: "",
315
+ graphs: () => [],
826
316
  });`;
827
- await fs.writeFile('drizzle.config.ts', drizzleConfig);
828
- }
829
- async function createTurboConfig() {
830
- const turboConfig = {
831
- $schema: 'https://turbo.build/schema.json',
832
- ui: 'tui',
833
- globalDependencies: ['**/.env', '**/.env.local', '**/.env.*'],
834
- globalEnv: [
835
- 'NODE_ENV',
836
- 'CI',
837
- 'ANTHROPIC_API_KEY',
838
- 'OPENAI_API_KEY',
839
- 'ENVIRONMENT',
840
- 'DB_FILE_NAME',
841
- 'MANAGE_API_PORT',
842
- 'RUN_API_PORT',
843
- 'LOG_LEVEL',
844
- 'NANGO_SECRET_KEY',
845
- ],
846
- tasks: {
847
- build: {
848
- dependsOn: ['^build'],
849
- inputs: ['$TURBO_DEFAULT$', '.env*'],
850
- outputs: ['dist/**', 'build/**', '.next/**', '!.next/cache/**'],
851
- },
852
- dev: {
853
- cache: false,
854
- persistent: true,
855
- },
856
- start: {
857
- dependsOn: ['build'],
858
- cache: false,
859
- },
860
- 'db:push': {
861
- cache: false,
862
- inputs: ['drizzle.config.ts', 'src/data/db/schema.ts'],
863
- },
864
- },
865
- };
866
- await fs.writeJson('turbo.json', turboConfig, { spaces: 2 });
867
- }
868
- async function createDocumentation(config) {
869
- const readme = `# ${config.dirName}
870
-
871
- An Inkeep Agent Framework project with multi-service architecture.
872
-
873
- ## Architecture
874
-
875
- This project follows a workspace structure with the following services:
876
-
877
- - **Agents Manage API** (Port 3002): Agent configuration and managemen
878
- - Handles entity management and configuration endpoints.
879
- - **Agents Run API** (Port 3003): Agent execution and chat processing
880
- - Handles agent communication. You can interact with your agents either over MCP from an MCP client or through our React UI components library
881
- - **Agents Manage UI** (Port 3000): Web interface available via \`inkeep dev\`
882
- - The agent framework visual builder. From the builder you can create, manage and visualize all your graphs.
883
-
884
- ## Quick Start
885
- 1. **Install the Inkeep CLI:**
886
- \`\`\`bash
887
- pnpm install -g @inkeep/agents-cli
888
- \`\`\`
889
-
890
- 1. **Start services:**
891
- \`\`\`bash
892
- # Start Agents Manage API and Agents Run API
893
- pnpm dev
894
-
895
- # Start the Dashboard
896
- inkeep dev
897
- \`\`\`
898
-
899
- 3. **Deploy your first agent graph:**
900
- \`\`\`bash
901
- # Navigate to your project's graph directory
902
- cd src/${config.projectId}/
903
-
904
- # Push the weather graph to create it
905
- inkeep push weather.graph.ts
906
- \`\`\`
907
- - Follow the prompts to create the project and graph
908
- - Click on the \"View graph in UI:\" link to see the graph in the management dashboard
909
-
910
- ## Project Structure
911
-
912
- \`\`\`
913
- ${config.dirName}/
914
- ├── src/
915
- │ ├── /${config.projectId} # Agent configurations
916
- ├── apps/
917
- │ ├── manage-api/ # Agents Manage API service
918
- │ ├── run-api/ # Agents Run API service
919
- │ └── shared/ # Shared code between API services
920
- │ └── credential-stores.ts # Shared credential store configuration
921
- ├── turbo.json # Turbo configuration
922
- ├── pnpm-workspace.yaml # pnpm workspace configuration
923
- └── package.json # Root package configuration
924
- \`\`\`
925
-
926
- ## Configuration
927
-
928
- ### Environment Variables
929
-
930
- Environment variables are defined in the following places:
931
-
932
- - \`apps/manage-api/.env\`: Agents Manage API environment variables
933
- - \`apps/run-api/.env\`: Agents Run API environment variables
934
- - \`src/${config.projectId}/.env\`: Inkeep CLI environment variables
935
- - \`.env\`: Root environment variables
936
-
937
- To change the API keys used by your agents modify \`apps/run-api/.env\`. You are required to define at least one LLM provider key.
938
-
939
- \`\`\`bash
940
- # AI Provider Keys
941
- ANTHROPIC_API_KEY=your-anthropic-key-here
942
- OPENAI_API_KEY=your-openai-key-here
943
- \`\`\`
944
-
945
-
946
-
947
- ### Agent Configuration
948
-
949
- Your graphs are defined in \`src/${config.projectId}/weather.graph.ts\`. The default setup includes:
950
-
951
- - **Weather Graph**: A graph that can forecast the weather in a given location.
952
-
953
- Your inkeep configuration is defined in \`src/${config.projectId}/inkeep.config.ts\`. The inkeep configuration is used to configure defaults for the inkeep CLI. The configuration includes:
954
-
955
- - \`tenantId\`: The tenant ID
956
- - \`projectId\`: The project ID
957
- - \`agentsManageApiUrl\`: The Manage API URL
958
- - \`agentsRunApiUrl\`: The Run API URL
959
-
960
-
961
- ## Development
962
-
963
- ### Updating Your Agents
964
-
965
- 1. Edit \`src/${config.projectId}/weather.graph.ts\`
966
- 2. Push the graph to the platform to update: \`inkeep pus weather.graph.ts\`
967
-
968
- ### API Documentation
969
-
970
- Once services are running, view the OpenAPI documentation:
971
-
972
- - Manage API: http://localhost:${config.manageApiPort}/docs
973
- - Run API: http://localhost:${config.runApiPort}/docs
974
-
975
- ## Learn More
976
-
977
- - [Inkeep Documentation](https://docs.inkeep.com)
978
-
979
- ## Troubleshooting
980
-
981
- ## Inkeep CLI commands
982
-
983
- - Ensure you are runnning commands from \`cd src/${config.projectId}\`.
984
- - Validate the \`inkeep.config.ts\` file has the correct api urls.
985
- - Validate that the \`.env\` file in \`src/${config.projectId}\` has the correct \`DB_FILE_NAME\`.
986
-
987
- ### Services won't start
988
-
989
- 1. Ensure all dependencies are installed: \`pnpm install\`
990
- 2. Check that ports 3000-3003 are available
991
-
992
- ### Agents won't respond
993
-
994
- 1. Ensure that the Agents Run API is running and includes a valid Anthropic or OpenAI API key in its .env file
995
- `;
996
- await fs.writeFile('README.md', readme);
317
+ await fs.writeFile(`src/${config.projectId}/index.ts`, customIndexContent);
318
+ }
997
319
  }
998
320
  async function installDependencies() {
999
321
  await execAsync('pnpm install');
1000
322
  }
1001
- async function setupProjectInDatabase() {
1002
- const s = p.spinner();
1003
- s.start('🚀 Starting development servers and setting up database...');
323
+ async function setupProjectInDatabase(config) {
324
+ // Start development servers in background
325
+ const { spawn } = await import('child_process');
326
+ const devProcess = spawn('pnpm', ['dev:apis'], {
327
+ stdio: ['pipe', 'pipe', 'pipe'],
328
+ detached: true, // Detach so we can kill the process group
329
+ cwd: process.cwd(),
330
+ });
331
+ // Give servers time to start
332
+ await new Promise((resolve) => setTimeout(resolve, 5000));
333
+ // Run inkeep push
1004
334
  try {
1005
- // Start development servers in background
1006
- const { spawn } = await import('child_process');
1007
- const devProcess = spawn('pnpm', ['dev'], {
1008
- stdio: ['pipe', 'pipe', 'pipe'],
1009
- detached: true, // Detach so we can kill the process group
1010
- cwd: process.cwd()
1011
- });
1012
- // Give servers time to start
1013
- await new Promise(resolve => setTimeout(resolve, 5000));
1014
- s.message('📦 Servers ready! Creating project in database...');
1015
- // Run the database setup
1016
- await execAsync('node scripts/setup.js');
335
+ // Suppress all output
336
+ const { stdout, stderr } = await execAsync(`pnpm inkeep push --project src/${config.projectId}`);
337
+ }
338
+ catch (error) {
339
+ //Continue despite error - user can setup project manually
340
+ }
341
+ finally {
1017
342
  // Kill the dev servers and their child processes
1018
343
  if (devProcess.pid) {
1019
344
  try {
1020
345
  // Kill the entire process group
1021
346
  process.kill(-devProcess.pid, 'SIGTERM');
1022
347
  // Wait a moment for graceful shutdown
1023
- await new Promise(resolve => setTimeout(resolve, 1000));
348
+ await new Promise((resolve) => setTimeout(resolve, 1000));
1024
349
  // Force kill if still running
1025
350
  try {
1026
351
  process.kill(-devProcess.pid, 'SIGKILL');
@@ -1034,18 +359,13 @@ async function setupProjectInDatabase() {
1034
359
  console.log('Note: Dev servers may still be running in background');
1035
360
  }
1036
361
  }
1037
- s.stop('✅ Project successfully created and configured in database!');
1038
- }
1039
- catch (error) {
1040
- s.stop('❌ Failed to setup project in database');
1041
- console.error('Setup error:', error);
1042
- // Continue anyway - user can run setup manually
1043
362
  }
1044
363
  }
1045
364
  async function setupDatabase() {
1046
365
  try {
1047
366
  // Run drizzle-kit push to create database file and apply schema
1048
367
  await execAsync('pnpm db:push');
368
+ await new Promise((resolve) => setTimeout(resolve, 1000));
1049
369
  }
1050
370
  catch (error) {
1051
371
  throw new Error(`Failed to setup database: ${error instanceof Error ? error.message : 'Unknown error'}`);