dank-ai 1.0.32 → 1.0.34
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/README.md +49 -52
- package/bin/dank +1 -0
- package/docker/entrypoint.js +140 -353
- package/lib/agent.js +105 -30
- package/lib/cli/init.js +1 -14
- package/lib/cli/production-build.js +6 -8
- package/lib/config.js +34 -33
- package/lib/constants.js +23 -6
- package/lib/docker/manager.js +135 -26
- package/lib/project.js +1 -4
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -208,7 +208,6 @@ const agent = createAgent('my-agent')
|
|
|
208
208
|
})
|
|
209
209
|
.setPrompt('Your system prompt here')
|
|
210
210
|
.setPromptingServer({
|
|
211
|
-
protocol: 'http',
|
|
212
211
|
port: 3000,
|
|
213
212
|
authentication: false,
|
|
214
213
|
maxConnections: 50
|
|
@@ -220,6 +219,45 @@ const agent = createAgent('my-agent')
|
|
|
220
219
|
});
|
|
221
220
|
```
|
|
222
221
|
|
|
222
|
+
### Adding HTTP Routes
|
|
223
|
+
|
|
224
|
+
HTTP automatically enables when you add routes. Here's a simple "Hello World" POST endpoint:
|
|
225
|
+
|
|
226
|
+
```javascript
|
|
227
|
+
const agent = createAgent('hello-agent')
|
|
228
|
+
.setLLM('openai', {
|
|
229
|
+
apiKey: process.env.OPENAI_API_KEY,
|
|
230
|
+
model: 'gpt-3.5-turbo'
|
|
231
|
+
})
|
|
232
|
+
.setPromptingServer({
|
|
233
|
+
port: 3000
|
|
234
|
+
})
|
|
235
|
+
// Add a POST endpoint (HTTP auto-enables)
|
|
236
|
+
.post('/hello', (req, res) => {
|
|
237
|
+
res.json({
|
|
238
|
+
message: 'Hello, World!',
|
|
239
|
+
received: req.body,
|
|
240
|
+
timestamp: new Date().toISOString()
|
|
241
|
+
});
|
|
242
|
+
});
|
|
243
|
+
```
|
|
244
|
+
|
|
245
|
+
**Test it:**
|
|
246
|
+
```bash
|
|
247
|
+
curl -X POST http://localhost:3000/hello \
|
|
248
|
+
-H "Content-Type: application/json" \
|
|
249
|
+
-d '{"name": "User"}'
|
|
250
|
+
```
|
|
251
|
+
|
|
252
|
+
**Response:**
|
|
253
|
+
```json
|
|
254
|
+
{
|
|
255
|
+
"message": "Hello, World!",
|
|
256
|
+
"received": {"name": "User"},
|
|
257
|
+
"timestamp": "2024-01-15T10:30:00.000Z"
|
|
258
|
+
}
|
|
259
|
+
```
|
|
260
|
+
|
|
223
261
|
### Supported LLM Providers
|
|
224
262
|
|
|
225
263
|
#### OpenAI
|
|
@@ -287,7 +325,7 @@ Dank provides a comprehensive event system with three main sources of events. Ea
|
|
|
287
325
|
#### 🎯 **Event Handler Patterns**
|
|
288
326
|
|
|
289
327
|
##### **1. Direct Prompting Events** (`request_output`)
|
|
290
|
-
Events triggered when agents receive and respond to direct prompts via
|
|
328
|
+
Events triggered when agents receive and respond to direct prompts via HTTP:
|
|
291
329
|
|
|
292
330
|
```javascript
|
|
293
331
|
agent
|
|
@@ -405,35 +443,10 @@ Events triggered by tool usage, following the pattern `tool:<tool-name>:<action>
|
|
|
405
443
|
|
|
406
444
|
```javascript
|
|
407
445
|
agent
|
|
408
|
-
//
|
|
409
|
-
.addHandler('tool:
|
|
410
|
-
// Listen to ALL HTTP
|
|
411
|
-
console.log('HTTP
|
|
412
|
-
})
|
|
413
|
-
|
|
414
|
-
.addHandler('tool:http-server:call', (data) => {
|
|
415
|
-
// All incoming HTTP requests
|
|
416
|
-
console.log('Request:', data.method, data.path, data.body);
|
|
417
|
-
})
|
|
418
|
-
|
|
419
|
-
.addHandler('tool:http-server:response', (data) => {
|
|
420
|
-
// All HTTP responses
|
|
421
|
-
console.log('Response:', data.statusCode, data.processingTime);
|
|
422
|
-
})
|
|
423
|
-
|
|
424
|
-
.addHandler('tool:http-server:call:post', (data) => {
|
|
425
|
-
// Only POST requests
|
|
426
|
-
console.log('POST Request:', data.path, data.body);
|
|
427
|
-
})
|
|
428
|
-
|
|
429
|
-
.addHandler('tool:http-server:response:get', (data) => {
|
|
430
|
-
// Only GET responses
|
|
431
|
-
console.log('GET Response:', data.path, data.responseData);
|
|
432
|
-
})
|
|
433
|
-
|
|
434
|
-
.addHandler('tool:http-server:error', (data) => {
|
|
435
|
-
// HTTP server errors
|
|
436
|
-
console.error('HTTP Error:', data.error);
|
|
446
|
+
// Example: Tool events for built-in tools
|
|
447
|
+
.addHandler('tool:httpRequest:*', (data) => {
|
|
448
|
+
// Listen to ALL HTTP request tool events
|
|
449
|
+
console.log('HTTP Request Tool:', data);
|
|
437
450
|
});
|
|
438
451
|
```
|
|
439
452
|
|
|
@@ -441,10 +454,10 @@ agent
|
|
|
441
454
|
- `tool:<tool-name>:*` - All events for a specific tool
|
|
442
455
|
- `tool:<tool-name>:call` - Tool invocation/input events
|
|
443
456
|
- `tool:<tool-name>:response` - Tool output/result events
|
|
444
|
-
- `tool:<tool-name>:call:<method>` - Specific method calls (e.g., POST, GET)
|
|
445
|
-
- `tool:<tool-name>:response:<method>` - Specific method responses
|
|
446
457
|
- `tool:<tool-name>:error` - Tool-specific errors
|
|
447
458
|
|
|
459
|
+
**Note:** HTTP API routes (added via `.get()`, `.post()`, etc.) are part of the main HTTP server, not a separate tool. They don't emit tool events.
|
|
460
|
+
|
|
448
461
|
##### **3. System Events** (Legacy/System)
|
|
449
462
|
Traditional system-level events:
|
|
450
463
|
|
|
@@ -480,10 +493,6 @@ agent
|
|
|
480
493
|
console.log('Any tool activity:', data);
|
|
481
494
|
})
|
|
482
495
|
|
|
483
|
-
// Listen to all HTTP responses
|
|
484
|
-
.addHandler('tool:http-server:response:*', (data) => {
|
|
485
|
-
console.log('Any HTTP response:', data);
|
|
486
|
-
})
|
|
487
496
|
|
|
488
497
|
// Listen to all request outputs
|
|
489
498
|
.addHandler('request_output:*', (data) => {
|
|
@@ -517,7 +526,6 @@ agent
|
|
|
517
526
|
prompt: "User's input prompt",
|
|
518
527
|
response: "LLM's response",
|
|
519
528
|
conversationId: "unique-conversation-id",
|
|
520
|
-
context: { protocol: "websocket", clientId: "..." },
|
|
521
529
|
usage: { total_tokens: 150, prompt_tokens: 50, completion_tokens: 100 },
|
|
522
530
|
model: "gpt-3.5-turbo",
|
|
523
531
|
processingTime: 1250,
|
|
@@ -550,27 +558,20 @@ Each communication method can be enabled/disabled independently:
|
|
|
550
558
|
createAgent('flexible-agent')
|
|
551
559
|
// Configure direct prompting with specific settings
|
|
552
560
|
.setPromptingServer({
|
|
553
|
-
protocol: 'websocket',
|
|
554
561
|
port: 3000,
|
|
555
562
|
authentication: false,
|
|
556
563
|
maxConnections: 50
|
|
557
564
|
})
|
|
558
565
|
.disableDirectPrompting() // Disable if needed
|
|
559
566
|
|
|
560
|
-
// Enable HTTP API
|
|
561
|
-
.enableHttp({ port: 3001 })
|
|
562
|
-
|
|
563
567
|
// Listen to direct prompting events only
|
|
564
568
|
.addHandler('request_output', (data) => {
|
|
565
|
-
console.log('
|
|
569
|
+
console.log('HTTP response:', data.response);
|
|
566
570
|
})
|
|
567
571
|
|
|
568
|
-
// HTTP
|
|
572
|
+
// Add HTTP API routes (HTTP auto-enables)
|
|
569
573
|
.get('/api/status', (req, res) => {
|
|
570
574
|
res.json({ status: 'ok' });
|
|
571
|
-
})
|
|
572
|
-
.addHandler('tool:http-server:*', (data) => {
|
|
573
|
-
console.log('HTTP activity:', data);
|
|
574
575
|
});
|
|
575
576
|
```
|
|
576
577
|
|
|
@@ -629,7 +630,6 @@ module.exports = {
|
|
|
629
630
|
})
|
|
630
631
|
.setPrompt('You are a professional customer service representative.')
|
|
631
632
|
.setPromptingServer({
|
|
632
|
-
protocol: 'http',
|
|
633
633
|
port: 3000,
|
|
634
634
|
authentication: true,
|
|
635
635
|
maxConnections: 100
|
|
@@ -659,7 +659,6 @@ module.exports = {
|
|
|
659
659
|
})
|
|
660
660
|
.setPrompt('You are a data analysis expert.')
|
|
661
661
|
.setPromptingServer({
|
|
662
|
-
protocol: 'http',
|
|
663
662
|
port: 3001,
|
|
664
663
|
authentication: false,
|
|
665
664
|
maxConnections: 50
|
|
@@ -737,7 +736,7 @@ dank build:prod --config production.config.js --output-metadata deployment.json
|
|
|
737
736
|
|
|
738
737
|
The `--output-metadata` option generates a JSON file containing all deployment information needed for your backend infrastructure:
|
|
739
738
|
- **Base image** used (`setBaseImage()` value)
|
|
740
|
-
- **Prompting server** configuration (
|
|
739
|
+
- **Prompting server** configuration (port, authentication, maxConnections)
|
|
741
740
|
- **Resource limits** (memory, CPU, timeout)
|
|
742
741
|
- **Ports** that need to be opened
|
|
743
742
|
- **Features enabled** (direct prompting, HTTP API, event handlers)
|
|
@@ -763,7 +762,6 @@ This metadata file is perfect for CI/CD pipelines to automatically configure you
|
|
|
763
762
|
"tag": "nodejs-20"
|
|
764
763
|
},
|
|
765
764
|
"promptingServer": {
|
|
766
|
-
"protocol": "http",
|
|
767
765
|
"port": 3000,
|
|
768
766
|
"authentication": false,
|
|
769
767
|
"maxConnections": 50,
|
|
@@ -777,7 +775,6 @@ This metadata file is perfect for CI/CD pipelines to automatically configure you
|
|
|
777
775
|
"ports": [
|
|
778
776
|
{
|
|
779
777
|
"port": 3000,
|
|
780
|
-
"protocol": "http",
|
|
781
778
|
"description": "Direct prompting server"
|
|
782
779
|
}
|
|
783
780
|
],
|
package/bin/dank
CHANGED
|
@@ -90,6 +90,7 @@ program
|
|
|
90
90
|
.option('--registry <registry>', 'Docker registry URL (e.g., docker.io, ghcr.io)')
|
|
91
91
|
.option('--namespace <namespace>', 'Docker namespace/organization')
|
|
92
92
|
.option('--tag-by-agent', 'Use agent name as the image tag (common image name)')
|
|
93
|
+
.option('--base-image-override <image>', 'Override base image for all agents (production builds only)')
|
|
93
94
|
.option('--json', 'Output machine-readable JSON summary to stdout')
|
|
94
95
|
.option('--output-metadata <file>', 'Output deployment metadata JSON file')
|
|
95
96
|
.option('--force', 'Force rebuild without cache')
|