dank-ai 1.0.2 → 1.0.4
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/package.json +41 -20
- package/.build-context-api-agent/Dockerfile +0 -3
- package/.build-context-basic-agent/Dockerfile +0 -3
- package/.build-context-prompt-only-agent/Dockerfile +0 -3
- package/.build-context-webhook-agent/Dockerfile +0 -3
- package/.env.example +0 -22
- package/agents/example-agent.js +0 -41
- package/dank.config.js +0 -210
- package/example/README.md +0 -176
- package/example/dank.config.js +0 -301
package/package.json
CHANGED
|
@@ -1,31 +1,52 @@
|
|
|
1
1
|
{
|
|
2
|
-
|
|
3
|
-
"version": "1.0.
|
|
4
|
-
"description": "Dank AI",
|
|
5
|
-
"main": "
|
|
2
|
+
"name": "dank-ai",
|
|
3
|
+
"version": "1.0.4",
|
|
4
|
+
"description": "Dank Agent Service - Docker-based AI agent orchestration platform",
|
|
5
|
+
"main": "lib/index.js",
|
|
6
|
+
"exports": {
|
|
7
|
+
".": "./lib/index.js",
|
|
8
|
+
"./lib": "./lib/index.js",
|
|
9
|
+
"./lib/*": "./lib/*"
|
|
10
|
+
},
|
|
11
|
+
"bin": {
|
|
12
|
+
"dank": "./bin/dank"
|
|
13
|
+
},
|
|
6
14
|
"scripts": {
|
|
7
|
-
"
|
|
8
|
-
"
|
|
9
|
-
"
|
|
10
|
-
"
|
|
11
|
-
"
|
|
12
|
-
"build": "dank build",
|
|
13
|
-
"clean": "dank clean"
|
|
15
|
+
"test": "echo \"Error: no test specified\" && exit 1",
|
|
16
|
+
"build": "echo \"Build completed\"",
|
|
17
|
+
"dev": "node bin/dank",
|
|
18
|
+
"install-global": "npm install -g .",
|
|
19
|
+
"docker:build-base": "docker build -t dank-agent-base -f docker/Dockerfile.base ."
|
|
14
20
|
},
|
|
15
21
|
"dependencies": {
|
|
16
|
-
"
|
|
22
|
+
"commander": "^11.0.0",
|
|
23
|
+
"chalk": "^4.1.2",
|
|
24
|
+
"dockerode": "^4.0.0",
|
|
25
|
+
"js-yaml": "^4.1.0",
|
|
26
|
+
"joi": "^17.9.2",
|
|
27
|
+
"winston": "^3.10.0",
|
|
28
|
+
"fs-extra": "^11.1.1",
|
|
29
|
+
"tar": "^6.1.15",
|
|
30
|
+
"uuid": "^9.0.0"
|
|
17
31
|
},
|
|
18
|
-
"
|
|
19
|
-
"
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
"automation",
|
|
23
|
-
"llm"
|
|
24
|
-
],
|
|
32
|
+
"devDependencies": {
|
|
33
|
+
"nodemon": "^3.0.1"
|
|
34
|
+
},
|
|
35
|
+
"keywords": ["agent", "ai", "docker", "orchestration", "llm", "automation"],
|
|
25
36
|
"author": "",
|
|
26
37
|
"license": "ISC",
|
|
38
|
+
"files": [
|
|
39
|
+
"lib/",
|
|
40
|
+
"bin/",
|
|
41
|
+
"docker/",
|
|
42
|
+
"templates/",
|
|
43
|
+
"README.md"
|
|
44
|
+
],
|
|
27
45
|
"engines": {
|
|
28
46
|
"node": ">=16.0.0",
|
|
29
47
|
"npm": ">=8.0.0"
|
|
48
|
+
},
|
|
49
|
+
"publishConfig": {
|
|
50
|
+
"access": "public"
|
|
30
51
|
}
|
|
31
|
-
}
|
|
52
|
+
}
|
package/.env.example
DELETED
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
# Dank AI Agent Environment Variables
|
|
2
|
-
# Copy this file to .env and fill in your API keys
|
|
3
|
-
|
|
4
|
-
# OpenAI Configuration
|
|
5
|
-
OPENAI_API_KEY=your_openai_api_key_here
|
|
6
|
-
OPENAI_MODEL=gpt-3.5-turbo
|
|
7
|
-
|
|
8
|
-
# Anthropic Configuration (optional)
|
|
9
|
-
ANTHROPIC_API_KEY=your_anthropic_api_key_here
|
|
10
|
-
ANTHROPIC_MODEL=claude-3-sonnet-20240229
|
|
11
|
-
|
|
12
|
-
# Google AI Configuration (optional)
|
|
13
|
-
GOOGLE_AI_API_KEY=your_google_ai_api_key_here
|
|
14
|
-
GOOGLE_AI_MODEL=gemini-pro
|
|
15
|
-
|
|
16
|
-
# Agent Configuration
|
|
17
|
-
DANK_LOG_LEVEL=info
|
|
18
|
-
DANK_MAX_CONCURRENT_AGENTS=3
|
|
19
|
-
|
|
20
|
-
# Docker Configuration (optional)
|
|
21
|
-
DOCKER_REGISTRY=your_registry_here
|
|
22
|
-
DOCKER_NAMESPACE=your_namespace_here
|
package/agents/example-agent.js
DELETED
|
@@ -1,41 +0,0 @@
|
|
|
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
DELETED
|
@@ -1,210 +0,0 @@
|
|
|
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
|
-
};
|
package/example/README.md
DELETED
|
@@ -1,176 +0,0 @@
|
|
|
1
|
-
# 🧪 Dank Agent HTTP Endpoints Test
|
|
2
|
-
|
|
3
|
-
This directory contains a test configuration with HTTP-enabled agents and their endpoints.
|
|
4
|
-
|
|
5
|
-
## 🚀 Quick Start
|
|
6
|
-
|
|
7
|
-
1. **Start the agents:**
|
|
8
|
-
```bash
|
|
9
|
-
cd test
|
|
10
|
-
dank run
|
|
11
|
-
```
|
|
12
|
-
|
|
13
|
-
2. **Test the endpoints:**
|
|
14
|
-
```bash
|
|
15
|
-
# Install axios for testing (if not already installed)
|
|
16
|
-
npm install axios
|
|
17
|
-
|
|
18
|
-
# Run endpoint tests
|
|
19
|
-
node test-endpoints.js
|
|
20
|
-
|
|
21
|
-
# Or run graceful tests (handles errors better)
|
|
22
|
-
node test-endpoints.js graceful
|
|
23
|
-
```
|
|
24
|
-
|
|
25
|
-
## 🤖 Agents & Endpoints
|
|
26
|
-
|
|
27
|
-
### API Agent (Port 3000)
|
|
28
|
-
A full-featured API agent with various endpoints:
|
|
29
|
-
|
|
30
|
-
**Endpoints:**
|
|
31
|
-
- `GET /` - Welcome message and endpoint list
|
|
32
|
-
- `GET /hello?name=YourName` - Simple greeting
|
|
33
|
-
- `POST /chat` - Chat with the AI agent
|
|
34
|
-
- `POST /analyze` - Analyze text content
|
|
35
|
-
- `GET /status` - Agent status and metrics
|
|
36
|
-
- `GET /metrics` - Performance metrics
|
|
37
|
-
|
|
38
|
-
**Example Usage:**
|
|
39
|
-
```bash
|
|
40
|
-
# Simple greeting
|
|
41
|
-
curl "http://localhost:3000/hello?name=Developer"
|
|
42
|
-
|
|
43
|
-
# Chat with agent
|
|
44
|
-
curl -X POST "http://localhost:3000/chat" \
|
|
45
|
-
-H "Content-Type: application/json" \
|
|
46
|
-
-d '{"message": "Hello, how can you help me?"}'
|
|
47
|
-
|
|
48
|
-
# Analyze text with sentiment
|
|
49
|
-
curl -X POST "http://localhost:3000/analyze" \
|
|
50
|
-
-H "Content-Type: application/json" \
|
|
51
|
-
-d '{"text": "This is amazing software!", "analysisType": "sentiment"}'
|
|
52
|
-
|
|
53
|
-
# Get agent status
|
|
54
|
-
curl "http://localhost:3000/status"
|
|
55
|
-
```
|
|
56
|
-
|
|
57
|
-
### Webhook Agent (Port 3001)
|
|
58
|
-
Specialized agent for handling webhooks from external services:
|
|
59
|
-
|
|
60
|
-
**Endpoints:**
|
|
61
|
-
- `GET /webhook/test` - Test endpoint status
|
|
62
|
-
- `POST /webhook/github` - GitHub webhook handler
|
|
63
|
-
- `POST /webhook/slack` - Slack webhook handler
|
|
64
|
-
- `POST /webhook/generic` - Generic webhook handler
|
|
65
|
-
|
|
66
|
-
**Example Usage:**
|
|
67
|
-
```bash
|
|
68
|
-
# Test webhook status
|
|
69
|
-
curl "http://localhost:3001/webhook/test"
|
|
70
|
-
|
|
71
|
-
# Simulate GitHub webhook
|
|
72
|
-
curl -X POST "http://localhost:3001/webhook/github" \
|
|
73
|
-
-H "X-GitHub-Event: push" \
|
|
74
|
-
-H "Content-Type: application/json" \
|
|
75
|
-
-d '{"repository": {"full_name": "user/repo"}}'
|
|
76
|
-
|
|
77
|
-
# Simulate Slack webhook
|
|
78
|
-
curl -X POST "http://localhost:3001/webhook/slack" \
|
|
79
|
-
-H "Content-Type: application/json" \
|
|
80
|
-
-d '{"text": "Hello!", "user_name": "testuser", "channel_name": "#general"}'
|
|
81
|
-
|
|
82
|
-
# Generic webhook with custom source
|
|
83
|
-
curl -X POST "http://localhost:3001/webhook/generic" \
|
|
84
|
-
-H "X-Webhook-Source: my-service" \
|
|
85
|
-
-H "Content-Type: application/json" \
|
|
86
|
-
-d '{"event": "user_signup", "data": {"email": "test@example.com"}}'
|
|
87
|
-
```
|
|
88
|
-
|
|
89
|
-
## 🔧 Features Demonstrated
|
|
90
|
-
|
|
91
|
-
### API Agent Features:
|
|
92
|
-
- ✅ **CORS enabled** - Cross-origin requests allowed
|
|
93
|
-
- ✅ **Rate limiting** - 100 requests per 15 minutes per IP
|
|
94
|
-
- ✅ **Input validation** - Proper error handling for missing data
|
|
95
|
-
- ✅ **JSON responses** - Consistent API response format
|
|
96
|
-
- ✅ **Error handling** - Graceful error responses
|
|
97
|
-
- ✅ **Metrics & monitoring** - Status and performance endpoints
|
|
98
|
-
|
|
99
|
-
### Webhook Agent Features:
|
|
100
|
-
- ✅ **Multiple webhook types** - GitHub, Slack, generic webhooks
|
|
101
|
-
- ✅ **Header processing** - Reads webhook-specific headers
|
|
102
|
-
- ✅ **Event logging** - Logs incoming webhook events
|
|
103
|
-
- ✅ **Flexible responses** - Different response formats per webhook type
|
|
104
|
-
|
|
105
|
-
### Security & Performance:
|
|
106
|
-
- ✅ **Port isolation** - Different ports for different services
|
|
107
|
-
- ✅ **Resource limits** - CPU and memory constraints
|
|
108
|
-
- ✅ **Request logging** - All requests are logged
|
|
109
|
-
- ✅ **Graceful error handling** - No crashes on bad requests
|
|
110
|
-
|
|
111
|
-
## 🧪 Testing Scenarios
|
|
112
|
-
|
|
113
|
-
The test script (`test-endpoints.js`) covers:
|
|
114
|
-
|
|
115
|
-
1. **Basic functionality** - All endpoints return expected responses
|
|
116
|
-
2. **Error handling** - Invalid requests return proper error messages
|
|
117
|
-
3. **Data processing** - POST endpoints process JSON payloads correctly
|
|
118
|
-
4. **Headers** - Webhook endpoints read custom headers
|
|
119
|
-
5. **Response formats** - All responses follow consistent JSON structure
|
|
120
|
-
|
|
121
|
-
## 📊 Expected Responses
|
|
122
|
-
|
|
123
|
-
### Successful API Response Format:
|
|
124
|
-
```json
|
|
125
|
-
{
|
|
126
|
-
"message": "Response message",
|
|
127
|
-
"agent": "agent-name",
|
|
128
|
-
"timestamp": "2024-01-01T12:00:00.000Z",
|
|
129
|
-
"data": { /* response data */ }
|
|
130
|
-
}
|
|
131
|
-
```
|
|
132
|
-
|
|
133
|
-
### Error Response Format:
|
|
134
|
-
```json
|
|
135
|
-
{
|
|
136
|
-
"error": "Error description",
|
|
137
|
-
"message": "Detailed error message",
|
|
138
|
-
"timestamp": "2024-01-01T12:00:00.000Z"
|
|
139
|
-
}
|
|
140
|
-
```
|
|
141
|
-
|
|
142
|
-
## 🔍 Monitoring
|
|
143
|
-
|
|
144
|
-
While agents are running, you can monitor them:
|
|
145
|
-
|
|
146
|
-
```bash
|
|
147
|
-
# Check agent status
|
|
148
|
-
dank status
|
|
149
|
-
|
|
150
|
-
# View agent logs
|
|
151
|
-
dank logs api-agent --follow
|
|
152
|
-
dank logs webhook-agent --follow
|
|
153
|
-
|
|
154
|
-
# Check container stats
|
|
155
|
-
docker stats $(docker ps -f name=dank- -q)
|
|
156
|
-
```
|
|
157
|
-
|
|
158
|
-
## 🚨 Troubleshooting
|
|
159
|
-
|
|
160
|
-
**Connection refused errors:**
|
|
161
|
-
- Make sure agents are running with `dank run`
|
|
162
|
-
- Check if ports 3000 and 3001 are available
|
|
163
|
-
- Verify Docker containers are running: `docker ps`
|
|
164
|
-
|
|
165
|
-
**Rate limit errors:**
|
|
166
|
-
- Wait 15 minutes for rate limit to reset
|
|
167
|
-
- Or restart the agents to reset counters
|
|
168
|
-
|
|
169
|
-
**JSON parsing errors:**
|
|
170
|
-
- Ensure Content-Type header is set to `application/json`
|
|
171
|
-
- Verify JSON payload is properly formatted
|
|
172
|
-
|
|
173
|
-
---
|
|
174
|
-
|
|
175
|
-
🔥 **Ready to test your HTTP-enabled Dank agents!** 🚀
|
|
176
|
-
|
package/example/dank.config.js
DELETED
|
@@ -1,301 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Dank Agent Configuration - Auto-Detection Features
|
|
3
|
-
*
|
|
4
|
-
* This file demonstrates the new auto-detection capabilities:
|
|
5
|
-
* - Event handlers are auto-enabled only when .addHandler() is used
|
|
6
|
-
* - Direct prompting is auto-enabled only when .setPrompt() + .setLLM() are set
|
|
7
|
-
* - HTTP API is auto-enabled only when routes (.get(), .post(), etc.) are added
|
|
8
|
-
*
|
|
9
|
-
* No more explicit .enableHttpApi() or .disableEventHandlers() calls needed!
|
|
10
|
-
* Run 'dank run' to start all defined agents.
|
|
11
|
-
*
|
|
12
|
-
* NOTE: This file uses the local development version (../lib/index.js).
|
|
13
|
-
* For production use, copy example/dank.config.template.js to your project
|
|
14
|
-
* and install dank via npm, then update the require statement.
|
|
15
|
-
*/
|
|
16
|
-
|
|
17
|
-
const { createAgent } = require("dank");
|
|
18
|
-
module.exports = {
|
|
19
|
-
// Project configuration
|
|
20
|
-
name: "test-project",
|
|
21
|
-
|
|
22
|
-
// Define your agents
|
|
23
|
-
agents: [
|
|
24
|
-
// 1. DIRECT PROMPTING ONLY - Auto-enabled because it has setPrompt() + setLLM() + handlers
|
|
25
|
-
createAgent("prompt-only-agent")
|
|
26
|
-
.setLLM("openai", {
|
|
27
|
-
apiKey:
|
|
28
|
-
"x",
|
|
29
|
-
model: "gpt-3.5-turbo",
|
|
30
|
-
temperature: 0.7,
|
|
31
|
-
})
|
|
32
|
-
//add in a pre-prompt pipeline that handler that can be used to modify and moderate requests to the prompt before it is sent to the LLM, and handler for when the llm responds with response but before it is sent to the client
|
|
33
|
-
.setPrompt("You are a helpful assistant that responds to direct prompts.") // ✅ Auto-enables direct prompting
|
|
34
|
-
.setBaseImage("nodejs-22") //latest is nodejs-20
|
|
35
|
-
.setPromptingServer({
|
|
36
|
-
protocol: "http",
|
|
37
|
-
port: 3000,
|
|
38
|
-
authentication: false,
|
|
39
|
-
maxConnections: 50,
|
|
40
|
-
})
|
|
41
|
-
|
|
42
|
-
// HTTP API auto-disabled (no routes added)
|
|
43
|
-
// Event handlers auto-enabled (handlers added below)
|
|
44
|
-
.setResources({
|
|
45
|
-
memory: "512m",
|
|
46
|
-
cpu: 1,
|
|
47
|
-
})
|
|
48
|
-
// Adding handlers auto-enables event handling ✅
|
|
49
|
-
.addHandler("request_output", (data) => {
|
|
50
|
-
console.log("[Prompt-Only Agent] LLM Response:", {
|
|
51
|
-
originalPrompt: data.prompt.substring(0, 50) + "...",
|
|
52
|
-
finalPrompt: data.finalPrompt
|
|
53
|
-
? data.finalPrompt.substring(0, 50) + "..."
|
|
54
|
-
: "N/A",
|
|
55
|
-
promptModified: data.promptModified,
|
|
56
|
-
response: data.response.substring(0, 100) + "...",
|
|
57
|
-
processingTime: data.processingTime + "ms",
|
|
58
|
-
model: data.model,
|
|
59
|
-
});
|
|
60
|
-
})
|
|
61
|
-
.addHandler("request_output:start", (data) => {
|
|
62
|
-
console.log(
|
|
63
|
-
"[Prompt-Only Agent] Processing prompt:",
|
|
64
|
-
data.conversationId
|
|
65
|
-
);
|
|
66
|
-
console.log("[Prompt-Only Agent] Original prompt:", data.prompt);
|
|
67
|
-
|
|
68
|
-
// Example: Add context to the prompt
|
|
69
|
-
const enhancedPrompt = `Context: You are a helpful assistant. Please be concise and friendly.
|
|
70
|
-
|
|
71
|
-
User Question: ${data.prompt}`;
|
|
72
|
-
|
|
73
|
-
console.log("[Prompt-Only Agent] Enhanced prompt:", enhancedPrompt);
|
|
74
|
-
|
|
75
|
-
// Return modified data - this will replace the prompt sent to the LLM
|
|
76
|
-
return {
|
|
77
|
-
prompt: enhancedPrompt,
|
|
78
|
-
};
|
|
79
|
-
})
|
|
80
|
-
.addHandler("request_output:end", (data) => {
|
|
81
|
-
console.log(
|
|
82
|
-
"[Prompt-Only Agent] Completed in:",
|
|
83
|
-
data.processingTime + "ms"
|
|
84
|
-
);
|
|
85
|
-
console.log(
|
|
86
|
-
"[Prompt-Only Agent] Original response:",
|
|
87
|
-
data.response.substring(0, 50) + "..."
|
|
88
|
-
);
|
|
89
|
-
|
|
90
|
-
// Example: Add a simple footer to the response
|
|
91
|
-
const enhancedResponse = `${data.response}\n\n[Enhanced by Dank Framework]`;
|
|
92
|
-
|
|
93
|
-
console.log(
|
|
94
|
-
"[Prompt-Only Agent] Enhanced response:",
|
|
95
|
-
enhancedResponse.substring(0, 100) + "..."
|
|
96
|
-
);
|
|
97
|
-
|
|
98
|
-
// Return modified data - this will replace the response sent to the caller
|
|
99
|
-
return {
|
|
100
|
-
response: "dank response:" + enhancedResponse,
|
|
101
|
-
};
|
|
102
|
-
})
|
|
103
|
-
.addHandler("error", (error) => {
|
|
104
|
-
console.error("[Prompt-Only Agent] Error:", error);
|
|
105
|
-
}),
|
|
106
|
-
|
|
107
|
-
/*
|
|
108
|
-
// 2. HTTP API ONLY - Auto-enabled because it has routes, auto-disabled direct prompting (no setPrompt)
|
|
109
|
-
createAgent('api-only-agent')
|
|
110
|
-
.setLLM('openai', {
|
|
111
|
-
apiKey: process.env.OPENAI_API_KEY,
|
|
112
|
-
model: 'gpt-4',
|
|
113
|
-
temperature: 0.5
|
|
114
|
-
})
|
|
115
|
-
// ❌ No setPrompt() = Direct prompting auto-disabled
|
|
116
|
-
.setBaseImage('nodejs-20')
|
|
117
|
-
// ❌ No more .disableDirectPrompting() or .enableHttpApi() needed!
|
|
118
|
-
// Direct prompting auto-disabled (no setPrompt())
|
|
119
|
-
// HTTP API auto-enabled (routes added below)
|
|
120
|
-
// Event handlers auto-enabled (handlers added below)
|
|
121
|
-
.enableHttp({
|
|
122
|
-
port: 3001,
|
|
123
|
-
cors: true,
|
|
124
|
-
rateLimit: {
|
|
125
|
-
windowMs: 15 * 60 * 1000,
|
|
126
|
-
max: 100
|
|
127
|
-
}
|
|
128
|
-
})
|
|
129
|
-
// Adding routes auto-enables HTTP API ✅
|
|
130
|
-
.get('/chat', (req, res) => {
|
|
131
|
-
res.json({
|
|
132
|
-
message: 'Hello from API-only agent!',
|
|
133
|
-
query: req.query,
|
|
134
|
-
timestamp: new Date().toISOString()
|
|
135
|
-
});
|
|
136
|
-
})
|
|
137
|
-
.post('/process', (req, res) => {
|
|
138
|
-
res.json({
|
|
139
|
-
processed: true,
|
|
140
|
-
input: req.body,
|
|
141
|
-
agent: 'api-only-agent',
|
|
142
|
-
timestamp: new Date().toISOString()
|
|
143
|
-
});
|
|
144
|
-
})
|
|
145
|
-
.setResources({
|
|
146
|
-
memory: '1g',
|
|
147
|
-
cpu: 2
|
|
148
|
-
})
|
|
149
|
-
// Adding handlers auto-enables event handling ✅
|
|
150
|
-
.addHandler('tool:http-server:*', (data) => {
|
|
151
|
-
console.log('[API-Only Agent] HTTP Activity:', {
|
|
152
|
-
type: data.type,
|
|
153
|
-
method: data.method,
|
|
154
|
-
path: data.path,
|
|
155
|
-
statusCode: data.statusCode
|
|
156
|
-
});
|
|
157
|
-
})
|
|
158
|
-
.addHandler('tool:http-server:call', (data) => {
|
|
159
|
-
console.log('[API-Only Agent] Incoming Request:', {
|
|
160
|
-
method: data.method,
|
|
161
|
-
path: data.path,
|
|
162
|
-
hasBody: !!data.body
|
|
163
|
-
});
|
|
164
|
-
})
|
|
165
|
-
.addHandler('tool:http-server:response:post', (data) => {
|
|
166
|
-
console.log('[API-Only Agent] POST Response:', {
|
|
167
|
-
path: data.path,
|
|
168
|
-
statusCode: data.statusCode,
|
|
169
|
-
processingTime: data.processingTime + 'ms'
|
|
170
|
-
});
|
|
171
|
-
}),
|
|
172
|
-
// 3. MINIMAL AGENT - Auto-disables everything (no setPrompt, no routes, no handlers)
|
|
173
|
-
createAgent('minimal-agent')
|
|
174
|
-
.setLLM('anthropic', {
|
|
175
|
-
apiKey: process.env.ANTHROPIC_API_KEY,
|
|
176
|
-
model: 'claude-3-sonnet-20240229',
|
|
177
|
-
temperature: 0.3
|
|
178
|
-
})
|
|
179
|
-
// ❌ No setPrompt() = Direct prompting auto-disabled
|
|
180
|
-
// ❌ No routes = HTTP API auto-disabled
|
|
181
|
-
// ❌ No handlers = Event handling auto-disabled
|
|
182
|
-
.setBaseImage('python-311')
|
|
183
|
-
// ❌ No more explicit disable calls needed!
|
|
184
|
-
// All features auto-disabled based on usage
|
|
185
|
-
.setResources({
|
|
186
|
-
memory: '1g',
|
|
187
|
-
cpu: 1
|
|
188
|
-
}),
|
|
189
|
-
// This agent only has basic LLM functionality available
|
|
190
|
-
|
|
191
|
-
// 4. EVENT HANDLERS ONLY - Auto-enabled because it has handlers, auto-disabled others
|
|
192
|
-
/*
|
|
193
|
-
createAgent('event-only-agent')
|
|
194
|
-
.setLLM('anthropic', {
|
|
195
|
-
apiKey: process.env.ANTHROPIC_API_KEY,
|
|
196
|
-
model: 'claude-3-sonnet-20240229',
|
|
197
|
-
temperature: 0.3
|
|
198
|
-
})
|
|
199
|
-
// ❌ No setPrompt() = Direct prompting auto-disabled
|
|
200
|
-
// ❌ No routes = HTTP API auto-disabled
|
|
201
|
-
// ✅ Has handlers = Event handling auto-enabled
|
|
202
|
-
.setBaseImage('python-311')
|
|
203
|
-
.setResources({
|
|
204
|
-
memory: '1g',
|
|
205
|
-
cpu: 1
|
|
206
|
-
})
|
|
207
|
-
// Adding handlers auto-enables event handling ✅
|
|
208
|
-
.addHandler('output', (data) => {
|
|
209
|
-
console.log('[Event-Only Agent] Processing output:', data);
|
|
210
|
-
})
|
|
211
|
-
.addHandler('error', (error) => {
|
|
212
|
-
console.error('[Event-Only Agent] Handling error:', error);
|
|
213
|
-
})
|
|
214
|
-
.addHandler('custom', (data) => {
|
|
215
|
-
console.log('[Event-Only Agent] Custom event:', data);
|
|
216
|
-
}),
|
|
217
|
-
*/
|
|
218
|
-
|
|
219
|
-
// 5. FULL-FEATURED AGENT - Auto-enables all features based on usage
|
|
220
|
-
/*
|
|
221
|
-
createAgent('full-featured-agent')
|
|
222
|
-
.setLLM('openai', {
|
|
223
|
-
apiKey: process.env.OPENAI_API_KEY,
|
|
224
|
-
model: 'gpt-4',
|
|
225
|
-
temperature: 0.6
|
|
226
|
-
})
|
|
227
|
-
.setPrompt('You are a versatile agent supporting all communication methods.') // ✅ Auto-enables direct prompting
|
|
228
|
-
.setBaseImage('latest')
|
|
229
|
-
.setPromptingServer({
|
|
230
|
-
protocol: 'websocket',
|
|
231
|
-
port: 3003,
|
|
232
|
-
authentication: true,
|
|
233
|
-
maxConnections: 100
|
|
234
|
-
})
|
|
235
|
-
.enableHttp({
|
|
236
|
-
port: 8080,
|
|
237
|
-
cors: true
|
|
238
|
-
})
|
|
239
|
-
// ❌ No more .enableHttpApi() or .enableEventHandlers() needed!
|
|
240
|
-
// Direct prompting auto-enabled (has setPrompt() + setLLM())
|
|
241
|
-
// HTTP API auto-enabled (routes added below)
|
|
242
|
-
// Event handlers auto-enabled (handlers added below)
|
|
243
|
-
|
|
244
|
-
// Adding routes auto-enables HTTP API ✅
|
|
245
|
-
.get('/status', (req, res) => {
|
|
246
|
-
res.json({
|
|
247
|
-
agent: 'full-featured-agent',
|
|
248
|
-
features: {
|
|
249
|
-
directPrompting: 'auto-enabled (has prompt + LLM)',
|
|
250
|
-
httpApi: 'auto-enabled (has routes)',
|
|
251
|
-
eventHandlers: 'auto-enabled (has handlers)'
|
|
252
|
-
},
|
|
253
|
-
timestamp: new Date().toISOString()
|
|
254
|
-
});
|
|
255
|
-
})
|
|
256
|
-
.post('/chat', (req, res) => {
|
|
257
|
-
res.json({
|
|
258
|
-
response: `I received: ${req.body.message}`,
|
|
259
|
-
via: 'HTTP API',
|
|
260
|
-
timestamp: new Date().toISOString()
|
|
261
|
-
});
|
|
262
|
-
})
|
|
263
|
-
.setResources({
|
|
264
|
-
memory: '2g',
|
|
265
|
-
cpu: 3
|
|
266
|
-
})
|
|
267
|
-
// Adding handlers auto-enables event handling ✅
|
|
268
|
-
.addHandler('output', (data) => {
|
|
269
|
-
console.log('[Full-Featured Agent] Output:', data);
|
|
270
|
-
})
|
|
271
|
-
.addHandler('error', (error) => {
|
|
272
|
-
console.error('[Full-Featured Agent] Error:', error);
|
|
273
|
-
})
|
|
274
|
-
.addHandler('heartbeat', () => {
|
|
275
|
-
console.log('[Full-Featured Agent] Heartbeat - All systems operational');
|
|
276
|
-
})
|
|
277
|
-
// Event patterns for all communication methods
|
|
278
|
-
.addHandler('request_output', (data) => {
|
|
279
|
-
console.log('[Full-Featured Agent] Direct Prompt Response:', {
|
|
280
|
-
conversationId: data.conversationId,
|
|
281
|
-
responseLength: data.response.length,
|
|
282
|
-
processingTime: data.processingTime + 'ms'
|
|
283
|
-
});
|
|
284
|
-
})
|
|
285
|
-
.addHandler('tool:http-server:call:post', (data) => {
|
|
286
|
-
console.log('[Full-Featured Agent] HTTP POST Call:', {
|
|
287
|
-
path: data.path,
|
|
288
|
-
bodySize: JSON.stringify(data.body).length
|
|
289
|
-
});
|
|
290
|
-
})
|
|
291
|
-
.addHandler('tool:http-server:response', (data) => {
|
|
292
|
-
console.log('[Full-Featured Agent] HTTP Response:', {
|
|
293
|
-
method: data.method,
|
|
294
|
-
path: data.path,
|
|
295
|
-
status: data.statusCode,
|
|
296
|
-
time: data.processingTime + 'ms'
|
|
297
|
-
});
|
|
298
|
-
})
|
|
299
|
-
*/
|
|
300
|
-
],
|
|
301
|
-
};
|