dank-ai 1.0.37 → 1.0.38

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/agent.js CHANGED
@@ -16,8 +16,8 @@ class DankAgent {
16
16
  this.name = name;
17
17
  this.config = this._validateConfig(config);
18
18
  this.handlers = new Map();
19
- // id is required and must be set via setId() - validated in _validateConfig
20
- this.id = this.config.id;
19
+ // id is optional during construction - must be set via setId() before use
20
+ this.id = this.config.id || null;
21
21
  this.status = 'defined'; // defined, building, running, stopped, error
22
22
  this.containerId = null;
23
23
  this.createdAt = new Date().toISOString();
@@ -564,11 +564,39 @@ class DankAgent {
564
564
  return this;
565
565
  }
566
566
 
567
+ /**
568
+ * Validate that agent ID is set (required for all operations)
569
+ * @private
570
+ */
571
+ _validateId() {
572
+ if (!this.id || !this.config.id) {
573
+ throw new Error(
574
+ `Agent ID is required for agent "${this.name}". ` +
575
+ `Use .setId(uuidv4) to set a unique UUIDv4 identifier. ` +
576
+ `Example: createAgent('${this.name}').setId(require('uuid').v4())`
577
+ );
578
+ }
579
+
580
+ // Validate UUIDv4 format
581
+ const trimmedId = this.id.trim();
582
+ if (!validateUUID(trimmedId)) {
583
+ throw new Error(`Agent ID must be a valid UUIDv4 for agent "${this.name}". Received: ${trimmedId}`);
584
+ }
585
+
586
+ const uuidRegex = /^[0-9a-f]{8}-[0-9a-f]{4}-4[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i;
587
+ if (!uuidRegex.test(trimmedId)) {
588
+ throw new Error(`Agent ID must be a valid UUIDv4 for agent "${this.name}". Received: ${trimmedId}`);
589
+ }
590
+ }
591
+
567
592
  /**
568
593
  * Finalize agent configuration by auto-detecting features
569
594
  * This should be called before the agent is deployed
570
595
  */
571
596
  finalize() {
597
+ // Validate that ID is set before finalization (REQUIRED)
598
+ this._validateId();
599
+
572
600
  this._autoDetectFeatures();
573
601
  return this;
574
602
  }
@@ -607,6 +635,9 @@ class DankAgent {
607
635
  * Get the complete agent configuration for serialization
608
636
  */
609
637
  toConfig() {
638
+ // Validate ID before serialization
639
+ this._validateId();
640
+
610
641
  return {
611
642
  name: this.name,
612
643
  id: this.id,
@@ -640,28 +671,27 @@ class DankAgent {
640
671
  * Validate agent configuration
641
672
  */
642
673
  _validateConfig(config) {
643
- // Validate ID separately (must be UUIDv4)
644
- if (!config.id) {
645
- throw new Error('Agent ID is required. Use .setId(uuidv4) to set a unique UUIDv4 identifier.');
646
- }
647
-
648
- if (typeof config.id !== 'string') {
649
- throw new Error('Agent ID must be a string');
650
- }
651
-
652
- const trimmedId = config.id.trim();
653
- if (!validateUUID(trimmedId)) {
654
- throw new Error(`Agent ID must be a valid UUIDv4. Received: ${trimmedId}`);
655
- }
656
-
657
- // Check if it's actually v4 (UUIDv4 has '4' in the version position)
658
- const uuidRegex = /^[0-9a-f]{8}-[0-9a-f]{4}-4[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i;
659
- if (!uuidRegex.test(trimmedId)) {
660
- throw new Error(`Agent ID must be a valid UUIDv4. Received: ${trimmedId}`);
674
+ // ID is optional during construction - will be validated when setId() is called
675
+ // or when the agent is finalized/used
676
+ if (config.id) {
677
+ if (typeof config.id !== 'string') {
678
+ throw new Error('Agent ID must be a string');
679
+ }
680
+
681
+ const trimmedId = config.id.trim();
682
+ if (!validateUUID(trimmedId)) {
683
+ throw new Error(`Agent ID must be a valid UUIDv4. Received: ${trimmedId}`);
684
+ }
685
+
686
+ // Check if it's actually v4 (UUIDv4 has '4' in the version position)
687
+ const uuidRegex = /^[0-9a-f]{8}-[0-9a-f]{4}-4[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i;
688
+ if (!uuidRegex.test(trimmedId)) {
689
+ throw new Error(`Agent ID must be a valid UUIDv4. Received: ${trimmedId}`);
690
+ }
661
691
  }
662
692
 
663
693
  const schema = Joi.object({
664
- id: Joi.string().required(), // Required UUIDv4 - validated above
694
+ id: Joi.string().optional(), // Optional during construction, required via setId()
665
695
 
666
696
  llm: Joi.object({
667
697
  provider: Joi.string().valid(...SUPPORTED_LLMS).required(),
@@ -12,6 +12,15 @@ const analytics = require('../analytics');
12
12
  * Extract deployment metadata from an agent configuration
13
13
  */
14
14
  function extractAgentMetadata(agent, buildOptions, imageName) {
15
+ // Validate that agent ID is set (required)
16
+ if (!agent.id || !agent.config?.id) {
17
+ throw new Error(
18
+ `Agent ID is required for agent "${agent.name}". ` +
19
+ `Use .setId(uuidv4) to set a unique UUIDv4 identifier. ` +
20
+ `Example: createAgent('${agent.name}').setId(require('uuid').v4())`
21
+ );
22
+ }
23
+
15
24
  const config = agent.config || {};
16
25
  const dockerConfig = config.docker || {};
17
26
  const communication = config.communication || {};
package/lib/config.js CHANGED
@@ -120,6 +120,15 @@ class AgentConfig {
120
120
  * Generate environment variables for agent container
121
121
  */
122
122
  static generateContainerEnv(agent) {
123
+ // Validate that agent ID is set (required)
124
+ if (!agent.id || !agent.config?.id) {
125
+ throw new Error(
126
+ `Agent ID is required for agent "${agent.name}". ` +
127
+ `Use .setId(uuidv4) to set a unique UUIDv4 identifier. ` +
128
+ `Example: createAgent('${agent.name}').setId(require('uuid').v4())`
129
+ );
130
+ }
131
+
123
132
  const env = {
124
133
  AGENT_NAME: agent.name,
125
134
  AGENT_ID: agent.id,
@@ -1399,9 +1399,20 @@ class DockerManager {
1399
1399
  });
1400
1400
 
1401
1401
  // Finalize agent configuration (auto-detect features)
1402
+ // This will validate that agent.id is set (required)
1402
1403
  agent.finalize();
1403
1404
 
1404
1405
  const imageName = `dank-agent-${agent.name.toLowerCase()}`;
1406
+
1407
+ // Ensure agent.id is set (should be validated by finalize(), but double-check for safety)
1408
+ if (!agent.id) {
1409
+ throw new Error(
1410
+ `Agent ID is required for agent "${agent.name}". ` +
1411
+ `Use .setId(uuidv4) to set a unique UUIDv4 identifier. ` +
1412
+ `Example: createAgent('${agent.name}').setId(require('uuid').v4())`
1413
+ );
1414
+ }
1415
+
1405
1416
  const containerName = `dank-${agent.name.toLowerCase()}-${agent.id
1406
1417
  .split("_")
1407
1418
  .pop()}`;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dank-ai",
3
- "version": "1.0.37",
3
+ "version": "1.0.38",
4
4
  "description": "Dank Agent Service - Docker-based AI agent orchestration platform",
5
5
  "main": "lib/index.js",
6
6
  "exports": {