create-agent-factory 0.1.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.
Files changed (2) hide show
  1. package/dist/index.js +375 -0
  2. package/package.json +39 -0
package/dist/index.js ADDED
@@ -0,0 +1,375 @@
1
+ #!/usr/bin/env node
2
+
3
+ // src/index.ts
4
+ import { program } from "commander";
5
+ import prompts from "prompts";
6
+
7
+ // src/create-project.ts
8
+ import { mkdir, writeFile } from "fs/promises";
9
+ import { join } from "path";
10
+ import chalk from "chalk";
11
+ import ora from "ora";
12
+
13
+ // src/templates/index.ts
14
+ function getTemplates(projectName) {
15
+ return {
16
+ "package.json": getPackageJson(projectName),
17
+ "tsconfig.json": getTsConfig(),
18
+ "af.config.ts": getAfConfig(),
19
+ "src/agent.ts": getAgentTs(projectName),
20
+ "src/context.ts": getContextTs(),
21
+ "src/tools.ts": getToolsTs(),
22
+ "src/workflows/.gitkeep": "",
23
+ "tests/basic.test.yaml": getBasicTestYaml(),
24
+ ".env.example": getEnvExample(),
25
+ "README.md": getReadme(projectName),
26
+ ".gitignore": getGitignore()
27
+ };
28
+ }
29
+ function getPackageJson(name) {
30
+ return JSON.stringify({
31
+ name,
32
+ version: "0.1.0",
33
+ type: "module",
34
+ scripts: {
35
+ dev: "af dev",
36
+ build: "af build",
37
+ test: "af test",
38
+ deploy: "af deploy"
39
+ },
40
+ dependencies: {
41
+ "@marco-kueks/agent-factory-core": "^0.1.0"
42
+ },
43
+ devDependencies: {
44
+ "@marco-kueks/agent-factory-cli": "^0.1.0",
45
+ "bun-types": "^1.0.0",
46
+ typescript: "^5.3.0"
47
+ }
48
+ }, null, 2);
49
+ }
50
+ function getTsConfig() {
51
+ return JSON.stringify({
52
+ compilerOptions: {
53
+ target: "ES2022",
54
+ module: "ESNext",
55
+ moduleResolution: "bundler",
56
+ lib: ["ES2022"],
57
+ strict: true,
58
+ esModuleInterop: true,
59
+ skipLibCheck: true,
60
+ forceConsistentCasingInFileNames: true,
61
+ outDir: "dist",
62
+ rootDir: "src",
63
+ types: ["bun-types"]
64
+ },
65
+ include: ["src/**/*"],
66
+ exclude: ["node_modules", "dist"]
67
+ }, null, 2);
68
+ }
69
+ function getAfConfig() {
70
+ return `import { defineConfig } from '@marco-kueks/agent-factory-core'
71
+
72
+ export default defineConfig({
73
+ port: 3000,
74
+ host: 'localhost',
75
+ cors: {
76
+ origins: ['http://localhost:3000'],
77
+ credentials: true,
78
+ },
79
+ logging: {
80
+ level: 'info',
81
+ format: 'pretty',
82
+ },
83
+ })
84
+ `;
85
+ }
86
+ function getAgentTs(name) {
87
+ const displayName = name.split("-").map((word) => word.charAt(0).toUpperCase() + word.slice(1)).join(" ");
88
+ return `import { defineAgent } from '@marco-kueks/agent-factory-core'
89
+ import { context } from './context'
90
+ import { tools } from './tools'
91
+
92
+ export default defineAgent({
93
+ name: '${name}',
94
+ version: '0.1.0',
95
+ description: '${displayName} Agent',
96
+ model: {
97
+ provider: 'anthropic',
98
+ name: 'claude-sonnet-4-20250514',
99
+ temperature: 0.7,
100
+ maxTokens: 4096,
101
+ },
102
+ systemPrompt: \`You are ${displayName}, a helpful AI assistant.
103
+
104
+ Your capabilities:
105
+ - Answer questions accurately and helpfully
106
+ - Use available tools when appropriate
107
+ - Maintain conversation context
108
+
109
+ Always be concise, accurate, and helpful.\`,
110
+ tools,
111
+ context,
112
+ state: {
113
+ storage: 'memory',
114
+ ttl: 3600,
115
+ },
116
+ })
117
+ `;
118
+ }
119
+ function getContextTs() {
120
+ return `import { defineContext } from '@marco-kueks/agent-factory-core'
121
+
122
+ export const context = defineContext(async (request) => {
123
+ const { conversationId, userId, channel, state } = request
124
+
125
+ return {
126
+ additionalContext: \`
127
+ Current conversation: \${conversationId}
128
+ Channel: \${channel}
129
+ \`,
130
+ variables: {
131
+ userId,
132
+ timestamp: new Date().toISOString(),
133
+ },
134
+ }
135
+ })
136
+ `;
137
+ }
138
+ function getToolsTs() {
139
+ return `import { defineTools } from '@marco-kueks/agent-factory-core'
140
+
141
+ export const tools = defineTools([
142
+ {
143
+ name: 'get_current_time',
144
+ description: 'Get the current date and time',
145
+ parameters: {
146
+ type: 'object',
147
+ properties: {
148
+ timezone: {
149
+ type: 'string',
150
+ description: 'Timezone (e.g., "America/New_York", "UTC")',
151
+ },
152
+ },
153
+ },
154
+ handler: async (params) => {
155
+ const timezone = (params.timezone as string) || 'UTC'
156
+ const now = new Date()
157
+ return {
158
+ timestamp: now.toISOString(),
159
+ formatted: now.toLocaleString('en-US', { timeZone: timezone }),
160
+ timezone,
161
+ }
162
+ },
163
+ },
164
+ {
165
+ name: 'calculate',
166
+ description: 'Perform a mathematical calculation',
167
+ parameters: {
168
+ type: 'object',
169
+ properties: {
170
+ expression: {
171
+ type: 'string',
172
+ description: 'Mathematical expression to evaluate (e.g., "2 + 2")',
173
+ },
174
+ },
175
+ required: ['expression'],
176
+ },
177
+ handler: async (params) => {
178
+ const expression = params.expression as string
179
+ const sanitized = expression.replace(/[^0-9+-*/().\\s]/g, '')
180
+ try {
181
+ const result = new Function(\`return \${sanitized}\`)()
182
+ return { expression, result }
183
+ } catch {
184
+ return { expression, error: 'Invalid expression' }
185
+ }
186
+ },
187
+ },
188
+ ])
189
+ `;
190
+ }
191
+ function getBasicTestYaml() {
192
+ return `name: Basic conversation test
193
+ description: Verify the agent responds correctly to basic queries
194
+
195
+ conversation:
196
+ - role: user
197
+ content: Hello, what can you do?
198
+ - role: assistant
199
+ assertions:
200
+ - type: contains
201
+ value: help
202
+
203
+ - role: user
204
+ content: What time is it?
205
+ - role: assistant
206
+ assertions:
207
+ - type: toolCalled
208
+ value: get_current_time
209
+ `;
210
+ }
211
+ function getEnvExample() {
212
+ return `# Anthropic API Key
213
+ ANTHROPIC_API_KEY=your_api_key_here
214
+
215
+ # Optional: OpenAI API Key (if using OpenAI models)
216
+ # OPENAI_API_KEY=your_openai_api_key
217
+
218
+ # Optional: Custom API endpoint
219
+ # AGENT_FACTORY_API_URL=https://api.agent-factory.dev
220
+ `;
221
+ }
222
+ function getReadme(name) {
223
+ const displayName = name.split("-").map((word) => word.charAt(0).toUpperCase() + word.slice(1)).join(" ");
224
+ return `# ${displayName}
225
+
226
+ An AI agent built with Agent Factory.
227
+
228
+ ## Getting Started
229
+
230
+ 1. Install dependencies:
231
+ \`\`\`bash
232
+ bun install
233
+ \`\`\`
234
+
235
+ 2. Set up your environment:
236
+ \`\`\`bash
237
+ cp .env.example .env
238
+ # Edit .env and add your API keys
239
+ \`\`\`
240
+
241
+ 3. Start the development server:
242
+ \`\`\`bash
243
+ bun run dev
244
+ \`\`\`
245
+
246
+ 4. Open http://localhost:3000 to chat with your agent.
247
+
248
+ ## Project Structure
249
+
250
+ - \`src/agent.ts\` - Main agent definition (system prompt, model config)
251
+ - \`src/context.ts\` - Dynamic context injection
252
+ - \`src/tools.ts\` - Custom tools for the agent
253
+ - \`src/workflows/\` - Multi-step workflows (coming soon)
254
+ - \`tests/\` - Test conversations
255
+ - \`af.config.ts\` - Framework configuration
256
+
257
+ ## Commands
258
+
259
+ - \`bun run dev\` - Start development server with hot reload
260
+ - \`bun run build\` - Build and validate the agent
261
+ - \`bun run test\` - Run test conversations
262
+ - \`bun run deploy\` - Deploy to Agent Factory cloud
263
+
264
+ ## Documentation
265
+
266
+ Visit [agent-factory.dev/docs](https://agent-factory.dev/docs) for full documentation.
267
+ `;
268
+ }
269
+ function getGitignore() {
270
+ return `# Dependencies
271
+ node_modules/
272
+
273
+ # Build output
274
+ dist/
275
+
276
+ # Environment
277
+ .env
278
+ .env.local
279
+ .env.*.local
280
+
281
+ # IDE
282
+ .idea/
283
+ .vscode/
284
+ *.swp
285
+ *.swo
286
+
287
+ # OS
288
+ .DS_Store
289
+ Thumbs.db
290
+
291
+ # Logs
292
+ *.log
293
+ logs/
294
+ `;
295
+ }
296
+
297
+ // src/create-project.ts
298
+ async function createProject(name, options) {
299
+ const projectPath = join(process.cwd(), name);
300
+ const spinner = ora();
301
+ console.log();
302
+ console.log(chalk.bold(`Creating ${chalk.cyan(name)}...`));
303
+ console.log();
304
+ spinner.start("Creating project structure");
305
+ try {
306
+ await mkdir(projectPath, { recursive: true });
307
+ await mkdir(join(projectPath, "src"), { recursive: true });
308
+ await mkdir(join(projectPath, "src", "workflows"), { recursive: true });
309
+ await mkdir(join(projectPath, "tests"), { recursive: true });
310
+ spinner.succeed("Project structure created");
311
+ spinner.start("Writing template files");
312
+ const templates = getTemplates(name);
313
+ for (const [filePath, content] of Object.entries(templates)) {
314
+ const fullPath = join(projectPath, filePath);
315
+ await writeFile(fullPath, content, "utf-8");
316
+ }
317
+ spinner.succeed("Template files written");
318
+ if (options.install) {
319
+ spinner.start("Installing dependencies");
320
+ const proc = Bun.spawn(["bun", "install"], {
321
+ cwd: projectPath,
322
+ stdout: "pipe",
323
+ stderr: "pipe"
324
+ });
325
+ await proc.exited;
326
+ if (proc.exitCode === 0) {
327
+ spinner.succeed("Dependencies installed");
328
+ } else {
329
+ spinner.warn("Failed to install dependencies. Run `bun install` manually.");
330
+ }
331
+ }
332
+ console.log();
333
+ console.log(chalk.green("Success!"), `Created ${chalk.cyan(name)} at ${chalk.gray(projectPath)}`);
334
+ console.log();
335
+ console.log("Next steps:");
336
+ console.log();
337
+ console.log(chalk.gray(" $"), chalk.cyan(`cd ${name}`));
338
+ if (!options.install) {
339
+ console.log(chalk.gray(" $"), chalk.cyan("bun install"));
340
+ }
341
+ console.log(chalk.gray(" $"), chalk.cyan("bun run dev"));
342
+ console.log();
343
+ console.log("Documentation:", chalk.blue("https://agent-factory.dev/docs"));
344
+ console.log();
345
+ } catch (error) {
346
+ spinner.fail("Failed to create project");
347
+ console.error(error);
348
+ process.exit(1);
349
+ }
350
+ }
351
+
352
+ // src/index.ts
353
+ async function askProjectName() {
354
+ const response = await prompts({
355
+ type: "text",
356
+ name: "name",
357
+ message: "What is your agent name?",
358
+ validate: (value) => {
359
+ if (!value)
360
+ return "Agent name is required";
361
+ if (!/^[a-z0-9-]+$/.test(value)) {
362
+ return "Agent name must be lowercase alphanumeric with hyphens";
363
+ }
364
+ return true;
365
+ }
366
+ });
367
+ if (!response.name) {
368
+ process.exit(1);
369
+ }
370
+ return response.name;
371
+ }
372
+ program.name("create-agent-factory").description("Create a new Agent Factory project").argument("[name]", "Project name").option("-t, --template <template>", "Template to use", "default").option("--no-install", "Skip dependency installation").action(async (name, options) => {
373
+ const projectName = name || await askProjectName();
374
+ await createProject(projectName, options);
375
+ }).parse();
package/package.json ADDED
@@ -0,0 +1,39 @@
1
+ {
2
+ "name": "create-agent-factory",
3
+ "version": "0.1.0",
4
+ "description": "Create new Agent Factory projects with a single command",
5
+ "keywords": ["ai", "agents", "scaffolding", "create", "generator", "llm"],
6
+ "author": "marco-kueks",
7
+ "license": "MIT",
8
+ "repository": {
9
+ "type": "git",
10
+ "url": "git+https://github.com/MarcoNaik/agent-factory.git",
11
+ "directory": "packages/create-agent-factory"
12
+ },
13
+ "homepage": "https://github.com/MarcoNaik/agent-factory#readme",
14
+ "bugs": {
15
+ "url": "https://github.com/MarcoNaik/agent-factory/issues"
16
+ },
17
+ "type": "module",
18
+ "bin": {
19
+ "create-agent-factory": "./dist/index.js"
20
+ },
21
+ "main": "./dist/index.js",
22
+ "files": ["dist"],
23
+ "scripts": {
24
+ "build": "bun build ./src/index.ts --outdir ./dist --target node --external commander --external prompts --external chalk --external ora && chmod +x ./dist/index.js",
25
+ "dev": "bun run ./src/index.ts",
26
+ "test": "bun test"
27
+ },
28
+ "dependencies": {
29
+ "chalk": "^5.3.0",
30
+ "commander": "^12.0.0",
31
+ "ora": "^8.0.0",
32
+ "prompts": "^2.4.2"
33
+ },
34
+ "devDependencies": {
35
+ "@types/prompts": "^2.4.9",
36
+ "bun-types": "^1.0.0",
37
+ "typescript": "^5.3.0"
38
+ }
39
+ }