dank-ai 1.0.7 ā 1.0.9
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/lib/project.js +18 -254
- package/package.json +1 -1
package/lib/project.js
CHANGED
|
@@ -1,14 +1,11 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
2
|
+
* Dank Project Management
|
|
3
3
|
*
|
|
4
|
-
*
|
|
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 = {}) {
|
|
@@ -16,99 +13,15 @@ class DankProject {
|
|
|
16
13
|
this.options = {
|
|
17
14
|
configFile: 'dank.config.js',
|
|
18
15
|
agentsDir: 'agents',
|
|
19
|
-
outputDir: '
|
|
16
|
+
outputDir: 'output',
|
|
17
|
+
template: 'basic',
|
|
20
18
|
...options
|
|
21
19
|
};
|
|
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);
|
|
20
|
+
this.projectPath = path.resolve(process.cwd(), name);
|
|
62
21
|
}
|
|
63
22
|
|
|
64
23
|
/**
|
|
65
|
-
*
|
|
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;
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
/**
|
|
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
|
|
24
|
+
* Initialize project structure and create example files
|
|
112
25
|
*/
|
|
113
26
|
async init() {
|
|
114
27
|
const projectDir = this.projectPath;
|
|
@@ -126,68 +39,23 @@ class DankProject {
|
|
|
126
39
|
console.log(`Created example configuration: ${configPath}`);
|
|
127
40
|
}
|
|
128
41
|
|
|
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
42
|
console.log(`\\nDank project '${this.name}' initialized!`);
|
|
139
43
|
console.log(`\\nNext steps:`);
|
|
140
44
|
console.log(`1. Edit ${this.options.configFile} to configure your agents`);
|
|
141
45
|
console.log(`2. Run 'dank run' to start your agents`);
|
|
142
46
|
|
|
143
|
-
return this;
|
|
144
|
-
}
|
|
145
|
-
|
|
146
|
-
/**
|
|
147
|
-
* Convert project to configuration object
|
|
148
|
-
*/
|
|
149
|
-
toConfig() {
|
|
150
47
|
return {
|
|
151
|
-
|
|
152
|
-
|
|
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
|
-
)
|
|
48
|
+
projectPath: projectDir,
|
|
49
|
+
configFile: configPath
|
|
161
50
|
};
|
|
162
51
|
}
|
|
163
52
|
|
|
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
53
|
/**
|
|
185
54
|
* Generate example configuration file
|
|
186
55
|
*/
|
|
187
56
|
_generateExampleConfig() {
|
|
188
|
-
//
|
|
189
|
-
const isDevelopment = this.projectPath
|
|
190
|
-
fs.existsSync(path.join(this.projectPath, '../lib/index.js'));
|
|
57
|
+
// Check if we're in development mode (local lib directory exists)
|
|
58
|
+
const isDevelopment = fs.existsSync(path.join(this.projectPath, '../lib/index.js'));
|
|
191
59
|
|
|
192
60
|
const requirePath = isDevelopment ? '../lib/index.js' : 'dank-ai';
|
|
193
61
|
|
|
@@ -205,6 +73,7 @@ module.exports = {
|
|
|
205
73
|
name: '${this.name}',
|
|
206
74
|
|
|
207
75
|
// Define your agents
|
|
76
|
+
// Each agent can have custom Docker image configuration for production builds
|
|
208
77
|
agents: [
|
|
209
78
|
// Example 1: Direct Prompting Agent with Event Handlers
|
|
210
79
|
createAgent('prompt-agent')
|
|
@@ -358,6 +227,12 @@ module.exports = {
|
|
|
358
227
|
memory: '2g',
|
|
359
228
|
cpu: 2
|
|
360
229
|
})
|
|
230
|
+
// Agent image configuration for Docker builds
|
|
231
|
+
.setAgentImageConfig({
|
|
232
|
+
registry: 'ghcr.io',
|
|
233
|
+
namespace: 'mycompany',
|
|
234
|
+
tag: 'latest'
|
|
235
|
+
})
|
|
361
236
|
// HTTP API routes
|
|
362
237
|
.get('/creative', (req, res) => {
|
|
363
238
|
res.json({
|
|
@@ -401,119 +276,8 @@ module.exports = {
|
|
|
401
276
|
})
|
|
402
277
|
]
|
|
403
278
|
};
|
|
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
279
|
`;
|
|
516
280
|
}
|
|
517
281
|
}
|
|
518
282
|
|
|
519
|
-
module.exports = { DankProject };
|
|
283
|
+
module.exports = { DankProject };
|