dank-ai 1.0.7 → 1.0.10

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/lib/project.js +12 -384
  2. package/package.json +1 -1
package/lib/project.js CHANGED
@@ -1,120 +1,31 @@
1
1
  /**
2
- * DankProject - Project Management Class
2
+ * Dank Project Management
3
3
  *
4
- * This class manages a collection of agents and provides
5
- * project-level configuration and operations.
4
+ * Handles project initialization, configuration generation, and scaffolding
6
5
  */
7
6
 
8
7
  const fs = require('fs-extra');
9
8
  const path = require('path');
10
- const yaml = require('js-yaml');
11
- const { DankAgent } = require('./agent');
12
9
 
13
10
  class DankProject {
14
11
  constructor(name, options = {}) {
15
12
  this.name = name;
16
13
  this.options = {
17
14
  configFile: 'dank.config.js',
18
- agentsDir: 'agents',
19
- outputDir: '.dank',
15
+ outputDir: 'output',
16
+ template: 'basic',
20
17
  ...options
21
18
  };
22
-
23
- this.agents = new Map();
24
- this.projectPath = process.cwd();
25
- this.configPath = path.join(this.projectPath, this.options.configFile);
26
- this.createdAt = new Date().toISOString();
27
- }
28
-
29
- /**
30
- * Add an agent to the project
31
- */
32
- addAgent(agent) {
33
- if (!(agent instanceof DankAgent)) {
34
- throw new Error('Agent must be an instance of DankAgent');
35
- }
36
-
37
- if (this.agents.has(agent.name)) {
38
- throw new Error(`Agent with name '${agent.name}' already exists`);
39
- }
40
-
41
- this.agents.set(agent.name, agent);
42
- return this;
43
- }
44
-
45
- /**
46
- * Remove an agent from the project
47
- */
48
- removeAgent(name) {
49
- if (!this.agents.has(name)) {
50
- throw new Error(`Agent '${name}' not found`);
51
- }
52
-
53
- this.agents.delete(name);
54
- return this;
55
- }
56
-
57
- /**
58
- * Get an agent by name
59
- */
60
- getAgent(name) {
61
- return this.agents.get(name);
62
- }
63
-
64
- /**
65
- * Get all agents
66
- */
67
- getAllAgents() {
68
- return Array.from(this.agents.values());
69
- }
70
-
71
- /**
72
- * Save project configuration to file
73
- */
74
- async save() {
75
- const config = this.toConfig();
76
-
77
- // Ensure output directory exists
78
- await fs.ensureDir(path.join(this.projectPath, this.options.outputDir));
79
-
80
- // Save as YAML for readability
81
- const yamlConfig = yaml.dump(config, {
82
- indent: 2,
83
- lineWidth: 120,
84
- noCompatMode: true
85
- });
86
-
87
- const configFile = path.join(this.projectPath, this.options.outputDir, 'project.yaml');
88
- await fs.writeFile(configFile, yamlConfig, 'utf8');
89
-
90
- console.log(`Project configuration saved to: ${configFile}`);
91
- return configFile;
19
+ this.projectPath = path.resolve(process.cwd(), name);
92
20
  }
93
21
 
94
22
  /**
95
- * Load project configuration from file
96
- */
97
- async load() {
98
- const configFile = path.join(this.projectPath, this.options.outputDir, 'project.yaml');
99
-
100
- if (!(await fs.pathExists(configFile))) {
101
- throw new Error(`Project configuration not found: ${configFile}`);
102
- }
103
-
104
- const yamlContent = await fs.readFile(configFile, 'utf8');
105
- const config = yaml.load(yamlContent);
106
-
107
- return this.fromConfig(config);
108
- }
109
-
110
- /**
111
- * Initialize a new project structure
23
+ * Initialize project structure and create example files
112
24
  */
113
25
  async init() {
114
26
  const projectDir = this.projectPath;
115
27
 
116
28
  // Create directory structure
117
- await fs.ensureDir(path.join(projectDir, this.options.agentsDir));
118
29
  await fs.ensureDir(path.join(projectDir, this.options.outputDir));
119
30
 
120
31
  // Create example config file
@@ -126,68 +37,23 @@ class DankProject {
126
37
  console.log(`Created example configuration: ${configPath}`);
127
38
  }
128
39
 
129
- // Create example agent
130
- const exampleAgent = this._generateExampleAgent();
131
- const agentPath = path.join(projectDir, this.options.agentsDir, 'example-agent.js');
132
-
133
- if (!(await fs.pathExists(agentPath))) {
134
- await fs.writeFile(agentPath, exampleAgent, 'utf8');
135
- console.log(`Created example agent: ${agentPath}`);
136
- }
137
-
138
40
  console.log(`\\nDank project '${this.name}' initialized!`);
139
41
  console.log(`\\nNext steps:`);
140
42
  console.log(`1. Edit ${this.options.configFile} to configure your agents`);
141
43
  console.log(`2. Run 'dank run' to start your agents`);
142
44
 
143
- return this;
144
- }
145
-
146
- /**
147
- * Convert project to configuration object
148
- */
149
- toConfig() {
150
45
  return {
151
- name: this.name,
152
- version: '1.0.0',
153
- createdAt: this.createdAt,
154
- options: this.options,
155
- agents: Object.fromEntries(
156
- Array.from(this.agents.entries()).map(([name, agent]) => [
157
- name,
158
- agent.toConfig()
159
- ])
160
- )
46
+ projectPath: projectDir,
47
+ configFile: configPath
161
48
  };
162
49
  }
163
50
 
164
- /**
165
- * Create project from configuration object
166
- */
167
- fromConfig(config) {
168
- this.name = config.name;
169
- this.createdAt = config.createdAt;
170
- this.options = { ...this.options, ...config.options };
171
-
172
- // Restore agents
173
- this.agents.clear();
174
- if (config.agents) {
175
- Object.entries(config.agents).forEach(([name, agentConfig]) => {
176
- const agent = DankAgent.fromConfig(agentConfig);
177
- this.agents.set(name, agent);
178
- });
179
- }
180
-
181
- return this;
182
- }
183
-
184
51
  /**
185
52
  * Generate example configuration file
186
53
  */
187
54
  _generateExampleConfig() {
188
- // Detect if we're in development mode (inside the dank repo)
189
- const isDevelopment = this.projectPath.includes('/dank') &&
190
- fs.existsSync(path.join(this.projectPath, '../lib/index.js'));
55
+ // Check if we're in development mode (local lib directory exists)
56
+ const isDevelopment = fs.existsSync(path.join(this.projectPath, '../lib/index.js'));
191
57
 
192
58
  const requirePath = isDevelopment ? '../lib/index.js' : 'dank-ai';
193
59
 
@@ -205,6 +71,7 @@ module.exports = {
205
71
  name: '${this.name}',
206
72
 
207
73
  // Define your agents
74
+ // Each agent can have custom Docker image configuration for production builds
208
75
  agents: [
209
76
  // Example 1: Direct Prompting Agent with Event Handlers
210
77
  createAgent('prompt-agent')
@@ -270,250 +137,11 @@ module.exports = {
270
137
  })
271
138
  .addHandler('error', (error) => {
272
139
  console.error('[Prompt Agent] System error:', error);
273
- }),
274
-
275
- // Example 2: HTTP API Agent with Tool Events
276
- createAgent('api-agent')
277
- .setLLM('openai', {
278
- apiKey: process.env.OPENAI_API_KEY,
279
- model: 'gpt-4',
280
- temperature: 0.3
281
- })
282
- .setPrompt('You are a specialized API assistant that helps with data processing and analysis.')
283
- .setBaseImage('nodejs-20')
284
- .setPromptingServer({
285
- protocol: 'http',
286
- port: 3001
287
- })
288
- .setResources({
289
- memory: '1g',
290
- cpu: 2
291
- })
292
- // HTTP API routes
293
- .get('/health', (req, res) => {
294
- res.json({ status: 'healthy', timestamp: new Date().toISOString() });
295
- })
296
- .post('/analyze', (req, res) => {
297
- res.json({
298
- message: 'Data analysis endpoint',
299
- data: req.body,
300
- timestamp: new Date().toISOString()
301
- });
302
- })
303
- .get('/status', (req, res) => {
304
- res.json({
305
- agent: 'api-agent',
306
- status: 'running',
307
- uptime: process.uptime()
308
- });
309
- })
310
- // Tool event handlers for HTTP requests
311
- .addHandler('tool:http-server:call', (data) => {
312
- console.log('[API Agent] HTTP Request:', {
313
- method: data.method,
314
- path: data.path,
315
- headers: data.headers,
316
- body: data.body,
317
- timestamp: data.timestamp
318
- });
319
- })
320
- .addHandler('tool:http-server:response', (data) => {
321
- console.log('[API Agent] HTTP Response:', {
322
- statusCode: data.statusCode,
323
- headers: data.headers,
324
- body: data.body,
325
- processingTime: data.processingTime,
326
- timestamp: data.timestamp
327
- });
328
- })
329
- .addHandler('tool:http-server:error', (data) => {
330
- console.error('[API Agent] HTTP Error:', {
331
- error: data.error,
332
- method: data.method,
333
- path: data.path,
334
- timestamp: data.timestamp
335
- });
336
- })
337
- .addHandler('output', (data) => {
338
- console.log('[API Agent] System output:', data);
339
- })
340
- .addHandler('error', (error) => {
341
- console.error('[API Agent] System error:', error);
342
- }),
343
-
344
- // Example 3: Multi-Modal Agent with All Features
345
- createAgent('multi-agent')
346
- .setLLM('openai', {
347
- apiKey: process.env.OPENAI_API_KEY,
348
- model: 'gpt-4',
349
- temperature: 0.5
350
- })
351
- .setPrompt('You are a versatile AI assistant that can handle both direct prompts and API requests. You excel at creative tasks and problem-solving.')
352
- .setBaseImage('nodejs-20')
353
- .setPromptingServer({
354
- protocol: 'http',
355
- port: 3002
356
- })
357
- .setResources({
358
- memory: '2g',
359
- cpu: 2
360
- })
361
- // HTTP API routes
362
- .get('/creative', (req, res) => {
363
- res.json({
364
- message: 'Creative writing endpoint',
365
- timestamp: new Date().toISOString()
366
- });
367
- })
368
- .post('/solve', (req, res) => {
369
- res.json({
370
- message: 'Problem solving endpoint',
371
- data: req.body,
372
- timestamp: new Date().toISOString()
373
- });
374
- })
375
- // Comprehensive event handling
376
- .addHandler('request_output:start', (data) => {
377
- console.log('[Multi Agent] Processing request:', data.conversationId);
378
- return {
379
- prompt: \`[Multi-Modal Assistant] \${data.prompt}\\n\\nPlease provide a comprehensive and creative response.\`
380
- };
381
- })
382
- .addHandler('request_output:end', (data) => {
383
- console.log('[Multi Agent] Response completed in:', data.processingTime + 'ms');
384
- return {
385
- response: \`\${data.response}\\n\\n✨ Enhanced by Multi-Modal Dank Agent\`
386
- };
387
- })
388
- .addHandler('tool:http-server:*', (data) => {
389
- console.log('[Multi Agent] HTTP Activity:', {
390
- type: data.type,
391
- method: data.method,
392
- path: data.path,
393
- timestamp: data.timestamp
394
- });
395
- })
396
- .addHandler('output', (data) => {
397
- console.log('[Multi Agent] System output:', data);
398
- })
399
- .addHandler('error', (error) => {
400
- console.error('[Multi Agent] System error:', error);
401
140
  })
402
141
  ]
403
142
  };
404
- `;
405
- }
406
-
407
- /**
408
- * Generate example agent file
409
- */
410
- _generateExampleAgent() {
411
- return `/**
412
- * Example Dank Agent
413
- *
414
- * This is an example of how to define a Dank agent with modern event handling.
415
- * You can create multiple agent files and import them in your config.
416
- */
417
-
418
- const { createAgent } = require('dank-ai');
419
-
420
- const exampleAgent = createAgent('example-agent')
421
- .setLLM('openai', {
422
- apiKey: process.env.OPENAI_API_KEY,
423
- model: 'gpt-3.5-turbo',
424
- temperature: 0.7
425
- })
426
- .setPrompt(\`
427
- You are a helpful AI assistant with the following capabilities:
428
- - Answer questions clearly and concisely
429
- - Provide code examples when appropriate
430
- - Be friendly and professional
431
- - Help with problem-solving and creative tasks
432
- \`)
433
- .setBaseImage('nodejs-20')
434
- .setPromptingServer({
435
- protocol: 'http',
436
- port: 3000
437
- })
438
- .setResources({
439
- memory: '512m',
440
- cpu: 1,
441
- timeout: 30000
442
- })
443
- // HTTP API routes
444
- .get('/info', (req, res) => {
445
- res.json({
446
- agent: 'example-agent',
447
- status: 'running',
448
- capabilities: ['direct-prompting', 'http-api'],
449
- timestamp: new Date().toISOString()
450
- });
451
- })
452
- .post('/chat', (req, res) => {
453
- res.json({
454
- message: 'Chat endpoint ready',
455
- data: req.body,
456
- timestamp: new Date().toISOString()
457
- });
458
- })
459
- // Event handlers for prompt processing
460
- .addHandler('request_output:start', (data) => {
461
- console.log(\`[\${new Date().toISOString()}] Processing prompt:\`, data.conversationId);
462
- console.log('Original prompt:', data.prompt);
463
-
464
- // Enhance the prompt
465
- const enhancedPrompt = \`[Enhanced] \${data.prompt}\\n\\nPlease provide a helpful and detailed response.\`;
466
-
467
- return {
468
- prompt: enhancedPrompt
469
- };
470
- })
471
- .addHandler('request_output', (data) => {
472
- console.log(\`[\${new Date().toISOString()}] LLM Response:\`, {
473
- conversationId: data.conversationId,
474
- promptModified: data.promptModified,
475
- processingTime: data.processingTime,
476
- model: data.model
477
- });
478
- })
479
- .addHandler('request_output:end', (data) => {
480
- console.log(\`[\${new Date().toISOString()}] Response completed in:\`, data.processingTime + 'ms');
481
-
482
- // Enhance the response
483
- const enhancedResponse = \`\${data.response}\\n\\n---\\n🤖 Powered by Dank Framework\`;
484
-
485
- return {
486
- response: enhancedResponse
487
- };
488
- })
489
- .addHandler('request_output:error', (data) => {
490
- console.error(\`[\${new Date().toISOString()}] Error processing prompt:\`, data.error);
491
- })
492
- // HTTP tool event handlers
493
- .addHandler('tool:http-server:call', (data) => {
494
- console.log(\`[\${new Date().toISOString()}] HTTP Request:\`, {
495
- method: data.method,
496
- path: data.path,
497
- body: data.body
498
- });
499
- })
500
- .addHandler('tool:http-server:response', (data) => {
501
- console.log(\`[\${new Date().toISOString()}] HTTP Response:\`, {
502
- statusCode: data.statusCode,
503
- processingTime: data.processingTime
504
- });
505
- })
506
- // System event handlers
507
- .addHandler('output', (data) => {
508
- console.log(\`[\${new Date().toISOString()}] Agent output:\`, data);
509
- })
510
- .addHandler('error', (error) => {
511
- console.error(\`[\${new Date().toISOString()}] Agent error:\`, error);
512
- });
513
-
514
- module.exports = exampleAgent;
515
143
  `;
516
144
  }
517
145
  }
518
146
 
519
- module.exports = { DankProject };
147
+ module.exports = { DankProject };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dank-ai",
3
- "version": "1.0.7",
3
+ "version": "1.0.10",
4
4
  "description": "Dank Agent Service - Docker-based AI agent orchestration platform",
5
5
  "main": "lib/index.js",
6
6
  "exports": {