dank-ai 1.0.1 → 1.0.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/.build-context-api-agent/Dockerfile +3 -0
- package/.build-context-basic-agent/Dockerfile +3 -0
- package/.build-context-prompt-only-agent/Dockerfile +3 -0
- package/.build-context-webhook-agent/Dockerfile +3 -0
- package/.env.example +22 -0
- package/README.md +66 -1290
- package/agents/example-agent.js +41 -0
- package/dank.config.js +210 -0
- package/docker/package-lock.json +2899 -0
- package/docker/package.json +7 -6
- package/example/README.md +176 -0
- package/example/dank.config.js +301 -0
- package/lib/agent.js +14 -19
- package/lib/cli/init.js +52 -7
- package/lib/project.js +16 -4
- package/package.json +20 -41
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Example Dank Agent
|
|
3
|
+
*
|
|
4
|
+
* This is an example of how to define a Dank agent.
|
|
5
|
+
* You can create multiple agent files and import them in your config.
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
const { createAgent } = require('dank');
|
|
9
|
+
|
|
10
|
+
const exampleAgent = createAgent('example-agent')
|
|
11
|
+
.setLLM('openai', {
|
|
12
|
+
apiKey: process.env.OPENAI_API_KEY,
|
|
13
|
+
model: 'gpt-3.5-turbo'
|
|
14
|
+
})
|
|
15
|
+
.setPrompt(`
|
|
16
|
+
You are a helpful AI assistant with the following capabilities:
|
|
17
|
+
- Answer questions clearly and concisely
|
|
18
|
+
- Provide code examples when appropriate
|
|
19
|
+
- Be friendly and professional
|
|
20
|
+
`)
|
|
21
|
+
.setResources({
|
|
22
|
+
memory: '512m',
|
|
23
|
+
cpu: 1,
|
|
24
|
+
timeout: 30000
|
|
25
|
+
})
|
|
26
|
+
.addHandlers({
|
|
27
|
+
output: (data) => {
|
|
28
|
+
console.log(`[${new Date().toISOString()}] Agent output:`, data);
|
|
29
|
+
},
|
|
30
|
+
error: (error) => {
|
|
31
|
+
console.error(`[${new Date().toISOString()}] Agent error:`, error);
|
|
32
|
+
},
|
|
33
|
+
start: () => {
|
|
34
|
+
console.log('Agent started successfully');
|
|
35
|
+
},
|
|
36
|
+
stop: () => {
|
|
37
|
+
console.log('Agent stopped');
|
|
38
|
+
}
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
module.exports = exampleAgent;
|
package/dank.config.js
ADDED
|
@@ -0,0 +1,210 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Dank Agent Configuration
|
|
3
|
+
*
|
|
4
|
+
* This file defines your AI agents and their configurations.
|
|
5
|
+
* Run 'dank run' to start all defined agents.
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
const { createAgent } = require('dank');
|
|
9
|
+
|
|
10
|
+
module.exports = {
|
|
11
|
+
// Project configuration
|
|
12
|
+
name: 'my-test-project',
|
|
13
|
+
|
|
14
|
+
// Define your agents
|
|
15
|
+
agents: [
|
|
16
|
+
// Example 1: Direct Prompting Agent with Event Handlers
|
|
17
|
+
createAgent('prompt-agent')
|
|
18
|
+
.setLLM('openai', {
|
|
19
|
+
apiKey: process.env.OPENAI_API_KEY,
|
|
20
|
+
model: 'gpt-3.5-turbo',
|
|
21
|
+
temperature: 0.7
|
|
22
|
+
})
|
|
23
|
+
.setPrompt('You are a helpful AI assistant. Be concise and friendly in your responses.')
|
|
24
|
+
.setBaseImage('nodejs-20')
|
|
25
|
+
.setPromptingServer({
|
|
26
|
+
protocol: 'http',
|
|
27
|
+
port: 3000
|
|
28
|
+
})
|
|
29
|
+
.setResources({
|
|
30
|
+
memory: '512m',
|
|
31
|
+
cpu: 1
|
|
32
|
+
})
|
|
33
|
+
// Event handlers for prompt modification and response enhancement
|
|
34
|
+
.addHandler('request_output:start', (data) => {
|
|
35
|
+
console.log('[Prompt Agent] Processing prompt:', data.conversationId);
|
|
36
|
+
console.log('[Prompt Agent] Original prompt:', data.prompt);
|
|
37
|
+
|
|
38
|
+
// Enhance the prompt with context
|
|
39
|
+
const enhancedPrompt = `Context: You are a helpful AI assistant. Please be concise and friendly.\n\nUser Question: ${data.prompt}\n\nPlease provide a clear, helpful response.`;
|
|
40
|
+
|
|
41
|
+
console.log('[Prompt Agent] Enhanced prompt:', enhancedPrompt);
|
|
42
|
+
|
|
43
|
+
return {
|
|
44
|
+
prompt: enhancedPrompt
|
|
45
|
+
};
|
|
46
|
+
})
|
|
47
|
+
.addHandler('request_output', (data) => {
|
|
48
|
+
console.log('[Prompt Agent] LLM Response:', {
|
|
49
|
+
prompt: data.prompt,
|
|
50
|
+
finalPrompt: data.finalPrompt,
|
|
51
|
+
promptModified: data.promptModified,
|
|
52
|
+
response: data.response,
|
|
53
|
+
conversationId: data.conversationId,
|
|
54
|
+
processingTime: data.processingTime,
|
|
55
|
+
usage: data.usage,
|
|
56
|
+
model: data.model
|
|
57
|
+
});
|
|
58
|
+
})
|
|
59
|
+
.addHandler('request_output:end', (data) => {
|
|
60
|
+
console.log('[Prompt Agent] Completed in:', data.processingTime + 'ms');
|
|
61
|
+
console.log('[Prompt Agent] Original response:', data.response ? data.response.substring(0, 50) + '...' : 'N/A');
|
|
62
|
+
|
|
63
|
+
// Enhance the response with metadata
|
|
64
|
+
const enhancedResponse = `${data.response}\n\n---\n🤖 Generated by Dank Framework Agent\n⏱️ Processing time: ${data.processingTime}ms\n`;
|
|
65
|
+
|
|
66
|
+
console.log('[Prompt Agent] Enhanced response:', enhancedResponse.substring(0, 100) + '...');
|
|
67
|
+
|
|
68
|
+
return {
|
|
69
|
+
response: enhancedResponse
|
|
70
|
+
};
|
|
71
|
+
})
|
|
72
|
+
.addHandler('request_output:error', (data) => {
|
|
73
|
+
console.error('[Prompt Agent] Error processing prompt:', data.error);
|
|
74
|
+
})
|
|
75
|
+
.addHandler('output', (data) => {
|
|
76
|
+
console.log('[Prompt Agent] System output:', data);
|
|
77
|
+
})
|
|
78
|
+
.addHandler('error', (error) => {
|
|
79
|
+
console.error('[Prompt Agent] System error:', error);
|
|
80
|
+
}),
|
|
81
|
+
|
|
82
|
+
// Example 2: HTTP API Agent with Tool Events
|
|
83
|
+
createAgent('api-agent')
|
|
84
|
+
.setLLM('openai', {
|
|
85
|
+
apiKey: process.env.OPENAI_API_KEY,
|
|
86
|
+
model: 'gpt-4',
|
|
87
|
+
temperature: 0.3
|
|
88
|
+
})
|
|
89
|
+
.setPrompt('You are a specialized API assistant that helps with data processing and analysis.')
|
|
90
|
+
.setBaseImage('nodejs-20')
|
|
91
|
+
.setPromptingServer({
|
|
92
|
+
protocol: 'http',
|
|
93
|
+
port: 3001
|
|
94
|
+
})
|
|
95
|
+
.setResources({
|
|
96
|
+
memory: '1g',
|
|
97
|
+
cpu: 2
|
|
98
|
+
})
|
|
99
|
+
// HTTP API routes
|
|
100
|
+
.get('/health', (req, res) => {
|
|
101
|
+
res.json({ status: 'healthy', timestamp: new Date().toISOString() });
|
|
102
|
+
})
|
|
103
|
+
.post('/analyze', (req, res) => {
|
|
104
|
+
res.json({
|
|
105
|
+
message: 'Data analysis endpoint',
|
|
106
|
+
data: req.body,
|
|
107
|
+
timestamp: new Date().toISOString()
|
|
108
|
+
});
|
|
109
|
+
})
|
|
110
|
+
.get('/status', (req, res) => {
|
|
111
|
+
res.json({
|
|
112
|
+
agent: 'api-agent',
|
|
113
|
+
status: 'running',
|
|
114
|
+
uptime: process.uptime()
|
|
115
|
+
});
|
|
116
|
+
})
|
|
117
|
+
// Tool event handlers for HTTP requests
|
|
118
|
+
.addHandler('tool:http-server:call', (data) => {
|
|
119
|
+
console.log('[API Agent] HTTP Request:', {
|
|
120
|
+
method: data.method,
|
|
121
|
+
path: data.path,
|
|
122
|
+
headers: data.headers,
|
|
123
|
+
body: data.body,
|
|
124
|
+
timestamp: data.timestamp
|
|
125
|
+
});
|
|
126
|
+
})
|
|
127
|
+
.addHandler('tool:http-server:response', (data) => {
|
|
128
|
+
console.log('[API Agent] HTTP Response:', {
|
|
129
|
+
statusCode: data.statusCode,
|
|
130
|
+
headers: data.headers,
|
|
131
|
+
body: data.body,
|
|
132
|
+
processingTime: data.processingTime,
|
|
133
|
+
timestamp: data.timestamp
|
|
134
|
+
});
|
|
135
|
+
})
|
|
136
|
+
.addHandler('tool:http-server:error', (data) => {
|
|
137
|
+
console.error('[API Agent] HTTP Error:', {
|
|
138
|
+
error: data.error,
|
|
139
|
+
method: data.method,
|
|
140
|
+
path: data.path,
|
|
141
|
+
timestamp: data.timestamp
|
|
142
|
+
});
|
|
143
|
+
})
|
|
144
|
+
.addHandler('output', (data) => {
|
|
145
|
+
console.log('[API Agent] System output:', data);
|
|
146
|
+
})
|
|
147
|
+
.addHandler('error', (error) => {
|
|
148
|
+
console.error('[API Agent] System error:', error);
|
|
149
|
+
}),
|
|
150
|
+
|
|
151
|
+
// Example 3: Multi-Modal Agent with All Features
|
|
152
|
+
createAgent('multi-agent')
|
|
153
|
+
.setLLM('openai', {
|
|
154
|
+
apiKey: process.env.OPENAI_API_KEY,
|
|
155
|
+
model: 'gpt-4',
|
|
156
|
+
temperature: 0.5
|
|
157
|
+
})
|
|
158
|
+
.setPrompt('You are a versatile AI assistant that can handle both direct prompts and API requests. You excel at creative tasks and problem-solving.')
|
|
159
|
+
.setBaseImage('nodejs-20')
|
|
160
|
+
.setPromptingServer({
|
|
161
|
+
protocol: 'http',
|
|
162
|
+
port: 3002
|
|
163
|
+
})
|
|
164
|
+
.setResources({
|
|
165
|
+
memory: '2g',
|
|
166
|
+
cpu: 2
|
|
167
|
+
})
|
|
168
|
+
// HTTP API routes
|
|
169
|
+
.get('/creative', (req, res) => {
|
|
170
|
+
res.json({
|
|
171
|
+
message: 'Creative writing endpoint',
|
|
172
|
+
timestamp: new Date().toISOString()
|
|
173
|
+
});
|
|
174
|
+
})
|
|
175
|
+
.post('/solve', (req, res) => {
|
|
176
|
+
res.json({
|
|
177
|
+
message: 'Problem solving endpoint',
|
|
178
|
+
data: req.body,
|
|
179
|
+
timestamp: new Date().toISOString()
|
|
180
|
+
});
|
|
181
|
+
})
|
|
182
|
+
// Comprehensive event handling
|
|
183
|
+
.addHandler('request_output:start', (data) => {
|
|
184
|
+
console.log('[Multi Agent] Processing request:', data.conversationId);
|
|
185
|
+
return {
|
|
186
|
+
prompt: `[Multi-Modal Assistant] ${data.prompt}\n\nPlease provide a comprehensive and creative response.`
|
|
187
|
+
};
|
|
188
|
+
})
|
|
189
|
+
.addHandler('request_output:end', (data) => {
|
|
190
|
+
console.log('[Multi Agent] Response completed in:', data.processingTime + 'ms');
|
|
191
|
+
return {
|
|
192
|
+
response: `${data.response}\n\n✨ Enhanced by Multi-Modal Dank Agent`
|
|
193
|
+
};
|
|
194
|
+
})
|
|
195
|
+
.addHandler('tool:http-server:*', (data) => {
|
|
196
|
+
console.log('[Multi Agent] HTTP Activity:', {
|
|
197
|
+
type: data.type,
|
|
198
|
+
method: data.method,
|
|
199
|
+
path: data.path,
|
|
200
|
+
timestamp: data.timestamp
|
|
201
|
+
});
|
|
202
|
+
})
|
|
203
|
+
.addHandler('output', (data) => {
|
|
204
|
+
console.log('[Multi Agent] System output:', data);
|
|
205
|
+
})
|
|
206
|
+
.addHandler('error', (error) => {
|
|
207
|
+
console.error('[Multi Agent] System error:', error);
|
|
208
|
+
})
|
|
209
|
+
]
|
|
210
|
+
};
|