@memberjunction/ai-agent-manager 2.111.0 → 2.112.0
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/.turbo/turbo-build.log +1 -1
- package/CHANGELOG.md +6 -11
- package/dist/agent-spec-sync.d.ts +1 -1
- package/dist/agent-spec-sync.d.ts.map +1 -1
- package/dist/agent-spec-sync.js +76 -83
- package/dist/agent-spec-sync.js.map +1 -1
- package/dist/agents/architect-agent.d.ts.map +1 -1
- package/dist/agents/architect-agent.js +14 -18
- package/dist/agents/architect-agent.js.map +1 -1
- package/dist/agents/builder-agent.d.ts.map +1 -1
- package/dist/agents/builder-agent.js +7 -7
- package/dist/agents/builder-agent.js.map +1 -1
- package/package.json +5 -6
- package/src/agent-spec-sync.ts +1733 -1799
- package/src/agents/architect-agent.ts +385 -378
- package/src/agents/builder-agent.ts +124 -133
package/.turbo/turbo-build.log
CHANGED
package/CHANGELOG.md
CHANGED
|
@@ -1,21 +1,16 @@
|
|
|
1
1
|
# @memberjunction/ai-agent-manager
|
|
2
2
|
|
|
3
|
-
## 2.
|
|
4
|
-
|
|
5
|
-
### Minor Changes
|
|
6
|
-
|
|
7
|
-
- 664fd6c: Migration
|
|
3
|
+
## 2.112.0
|
|
8
4
|
|
|
9
5
|
### Patch Changes
|
|
10
6
|
|
|
11
7
|
- 621960a: Patch
|
|
12
|
-
- Updated dependencies [
|
|
8
|
+
- Updated dependencies [c126b59]
|
|
13
9
|
- Updated dependencies [ed74bb8]
|
|
14
|
-
- @memberjunction/
|
|
15
|
-
- @memberjunction/ai-core-plus@2.
|
|
16
|
-
- @memberjunction/
|
|
17
|
-
- @memberjunction/core-entities@2.
|
|
18
|
-
- @memberjunction/global@2.111.0
|
|
10
|
+
- @memberjunction/global@2.112.0
|
|
11
|
+
- @memberjunction/ai-core-plus@2.112.0
|
|
12
|
+
- @memberjunction/ai-agents@2.112.0
|
|
13
|
+
- @memberjunction/core-entities@2.112.0
|
|
19
14
|
|
|
20
15
|
## 2.110.1
|
|
21
16
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"agent-spec-sync.d.ts","sourceRoot":"","sources":["../src/agent-spec-sync.ts"],"names":[],"mappings":"AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"agent-spec-sync.d.ts","sourceRoot":"","sources":["../src/agent-spec-sync.ts"],"names":[],"mappings":"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"}
|
package/dist/agent-spec-sync.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.AgentSpecSync = void 0;
|
|
4
|
-
const
|
|
4
|
+
const global_1 = require("@memberjunction/global");
|
|
5
5
|
/**
|
|
6
6
|
* AgentSpecSync provides a high-level interface for working with AI Agent metadata in MemberJunction.
|
|
7
7
|
*
|
|
@@ -91,7 +91,7 @@ class AgentSpecSync {
|
|
|
91
91
|
Name: '',
|
|
92
92
|
StartingPayloadValidationMode: 'Fail',
|
|
93
93
|
Actions: [],
|
|
94
|
-
SubAgents: []
|
|
94
|
+
SubAgents: [],
|
|
95
95
|
};
|
|
96
96
|
}
|
|
97
97
|
this._contextUser = contextUser;
|
|
@@ -106,7 +106,7 @@ class AgentSpecSync {
|
|
|
106
106
|
Entity: entity,
|
|
107
107
|
Operation: operation,
|
|
108
108
|
ID: id,
|
|
109
|
-
Description: description
|
|
109
|
+
Description: description,
|
|
110
110
|
});
|
|
111
111
|
}
|
|
112
112
|
/**
|
|
@@ -171,11 +171,11 @@ class AgentSpecSync {
|
|
|
171
171
|
*/
|
|
172
172
|
static async LoadByName(agentName, contextUser, includeSubAgents = true) {
|
|
173
173
|
// Find agent by name
|
|
174
|
-
const rv = new
|
|
174
|
+
const rv = new global_1.RunView();
|
|
175
175
|
const result = await rv.RunView({
|
|
176
176
|
EntityName: 'AI Agents',
|
|
177
177
|
ExtraFilter: `Name='${agentName.replace(/'/g, "''")}'`,
|
|
178
|
-
ResultType: 'entity_object'
|
|
178
|
+
ResultType: 'entity_object',
|
|
179
179
|
}, contextUser);
|
|
180
180
|
if (!result.Success) {
|
|
181
181
|
throw new Error(`Failed to find agent by name: ${result.ErrorMessage}`);
|
|
@@ -230,8 +230,8 @@ class AgentSpecSync {
|
|
|
230
230
|
* @throws {Error} If agent is not found
|
|
231
231
|
*/
|
|
232
232
|
async loadFromEntities(agentId, includeSubAgents) {
|
|
233
|
-
const md = new
|
|
234
|
-
const rv = new
|
|
233
|
+
const md = new global_1.Metadata();
|
|
234
|
+
const rv = new global_1.RunView();
|
|
235
235
|
// Step 1: Load the main agent entity
|
|
236
236
|
const agentEntity = await md.GetEntityObject('AI Agents', this._contextUser);
|
|
237
237
|
const loaded = await agentEntity.Load(agentId);
|
|
@@ -245,32 +245,32 @@ class AgentSpecSync {
|
|
|
245
245
|
EntityName: 'AI Agent Actions',
|
|
246
246
|
ExtraFilter: `AgentID='${agentId}'`,
|
|
247
247
|
OrderBy: 'Status, ActionID',
|
|
248
|
-
ResultType: 'entity_object'
|
|
248
|
+
ResultType: 'entity_object',
|
|
249
249
|
},
|
|
250
250
|
{
|
|
251
251
|
EntityName: 'AI Agents',
|
|
252
252
|
ExtraFilter: `ParentID='${agentId}'`,
|
|
253
253
|
OrderBy: 'ExecutionOrder, Name',
|
|
254
|
-
ResultType: 'entity_object'
|
|
254
|
+
ResultType: 'entity_object',
|
|
255
255
|
},
|
|
256
256
|
{
|
|
257
257
|
EntityName: 'MJ: AI Agent Relationships',
|
|
258
258
|
ExtraFilter: `AgentID='${agentId}' AND Status='Active'`,
|
|
259
259
|
OrderBy: '__mj_CreatedAt',
|
|
260
|
-
ResultType: 'entity_object'
|
|
260
|
+
ResultType: 'entity_object',
|
|
261
261
|
},
|
|
262
262
|
{
|
|
263
263
|
EntityName: 'MJ: AI Agent Prompts',
|
|
264
264
|
ExtraFilter: `AgentID='${agentId}'`,
|
|
265
265
|
OrderBy: 'ExecutionOrder',
|
|
266
|
-
ResultType: 'entity_object'
|
|
266
|
+
ResultType: 'entity_object',
|
|
267
267
|
},
|
|
268
268
|
{
|
|
269
269
|
EntityName: 'MJ: AI Agent Steps',
|
|
270
270
|
ExtraFilter: `AgentID='${agentId}'`,
|
|
271
271
|
OrderBy: 'Name',
|
|
272
|
-
ResultType: 'entity_object'
|
|
273
|
-
}
|
|
272
|
+
ResultType: 'entity_object',
|
|
273
|
+
},
|
|
274
274
|
], this._contextUser);
|
|
275
275
|
// Check for errors
|
|
276
276
|
if (!actionsResult.Success) {
|
|
@@ -297,7 +297,7 @@ class AgentSpecSync {
|
|
|
297
297
|
EntityName: 'MJ: AI Agent Step Paths',
|
|
298
298
|
ExtraFilter: `OriginStepID IN (${stepIds})`,
|
|
299
299
|
OrderBy: 'Priority DESC',
|
|
300
|
-
ResultType: 'entity_object'
|
|
300
|
+
ResultType: 'entity_object',
|
|
301
301
|
}, this._contextUser);
|
|
302
302
|
if (!pathsResult.Success) {
|
|
303
303
|
throw new Error(`Failed to load step paths: ${pathsResult.ErrorMessage}`);
|
|
@@ -308,7 +308,7 @@ class AgentSpecSync {
|
|
|
308
308
|
pathsResult = {
|
|
309
309
|
Success: true,
|
|
310
310
|
Results: [],
|
|
311
|
-
RowCount: 0
|
|
311
|
+
RowCount: 0,
|
|
312
312
|
};
|
|
313
313
|
}
|
|
314
314
|
// Step 2c: Load full AI Prompt records to get PromptText, PromptRole, PromptPosition
|
|
@@ -320,7 +320,7 @@ class AgentSpecSync {
|
|
|
320
320
|
EntityName: 'AI Prompts',
|
|
321
321
|
ExtraFilter: `ID IN (${promptIds})`,
|
|
322
322
|
OrderBy: 'Name',
|
|
323
|
-
ResultType: 'entity_object'
|
|
323
|
+
ResultType: 'entity_object',
|
|
324
324
|
}, this._contextUser);
|
|
325
325
|
if (!fullPromptsResult.Success) {
|
|
326
326
|
throw new Error(`Failed to load AI prompts: ${fullPromptsResult.ErrorMessage}`);
|
|
@@ -331,7 +331,7 @@ class AgentSpecSync {
|
|
|
331
331
|
fullPromptsResult = {
|
|
332
332
|
Success: true,
|
|
333
333
|
Results: [],
|
|
334
|
-
RowCount: 0
|
|
334
|
+
RowCount: 0,
|
|
335
335
|
};
|
|
336
336
|
}
|
|
337
337
|
// Step 3: Map entities to raw spec format
|
|
@@ -351,11 +351,11 @@ class AgentSpecSync {
|
|
|
351
351
|
subAgentSpec.SubAgent = {
|
|
352
352
|
...fullSubAgentSpec,
|
|
353
353
|
// Ensure we preserve any relationship-specific overrides
|
|
354
|
-
StartingPayloadValidationMode: subAgentSpec.SubAgent.StartingPayloadValidationMode || fullSubAgentSpec.StartingPayloadValidationMode
|
|
354
|
+
StartingPayloadValidationMode: subAgentSpec.SubAgent.StartingPayloadValidationMode || fullSubAgentSpec.StartingPayloadValidationMode,
|
|
355
355
|
};
|
|
356
356
|
}
|
|
357
357
|
catch (error) {
|
|
358
|
-
(0,
|
|
358
|
+
(0, global_1.LogError)(`Failed to load sub-agent ${subAgentSpec.SubAgent.ID}: ${error instanceof Error ? error.message : String(error)}`);
|
|
359
359
|
// Continue with partial data rather than failing completely
|
|
360
360
|
}
|
|
361
361
|
}
|
|
@@ -424,18 +424,18 @@ class AgentSpecSync {
|
|
|
424
424
|
FunctionalRequirements: agent.FunctionalRequirements || null,
|
|
425
425
|
TechnicalDesign: agent.TechnicalDesign || null,
|
|
426
426
|
// Map actions
|
|
427
|
-
Actions: actions.map(action => this.mapActionEntityToSpec(action)),
|
|
427
|
+
Actions: actions.map((action) => this.mapActionEntityToSpec(action)),
|
|
428
428
|
// Map sub-agents (both child and related)
|
|
429
429
|
SubAgents: [
|
|
430
|
-
...childAgents.map(child => this.mapChildAgentToSpec(child)),
|
|
431
|
-
...relatedAgents.map(rel => this.mapRelatedAgentToSpec(rel))
|
|
430
|
+
...childAgents.map((child) => this.mapChildAgentToSpec(child)),
|
|
431
|
+
...relatedAgents.map((rel) => this.mapRelatedAgentToSpec(rel)),
|
|
432
432
|
],
|
|
433
433
|
// Map prompts (agent-level prompts for Loop agents)
|
|
434
|
-
Prompts: agentPrompts.map(agentPrompt => this.mapPromptEntityToSpec(agentPrompt, fullPrompts)),
|
|
434
|
+
Prompts: agentPrompts.map((agentPrompt) => this.mapPromptEntityToSpec(agentPrompt, fullPrompts)),
|
|
435
435
|
// Map steps (for Flow agents)
|
|
436
|
-
Steps: steps.map(step => this.mapStepEntityToSpec(step)),
|
|
436
|
+
Steps: steps.map((step) => this.mapStepEntityToSpec(step)),
|
|
437
437
|
// Map paths (for Flow agents)
|
|
438
|
-
Paths: paths.map(path => this.mapPathEntityToSpec(path))
|
|
438
|
+
Paths: paths.map((path) => this.mapPathEntityToSpec(path)),
|
|
439
439
|
};
|
|
440
440
|
return spec;
|
|
441
441
|
}
|
|
@@ -456,7 +456,7 @@ class AgentSpecSync {
|
|
|
456
456
|
ResultExpirationMode: action.ResultExpirationMode || undefined,
|
|
457
457
|
CompactMode: action.CompactMode || undefined,
|
|
458
458
|
CompactLength: action.CompactLength || undefined,
|
|
459
|
-
CompactPromptID: action.CompactPromptID || null
|
|
459
|
+
CompactPromptID: action.CompactPromptID || null,
|
|
460
460
|
};
|
|
461
461
|
}
|
|
462
462
|
/**
|
|
@@ -472,8 +472,8 @@ class AgentSpecSync {
|
|
|
472
472
|
SubAgent: {
|
|
473
473
|
ID: childAgent.ID,
|
|
474
474
|
Name: childAgent.Name || '',
|
|
475
|
-
StartingPayloadValidationMode: 'Fail'
|
|
476
|
-
}
|
|
475
|
+
StartingPayloadValidationMode: 'Fail',
|
|
476
|
+
},
|
|
477
477
|
};
|
|
478
478
|
}
|
|
479
479
|
/**
|
|
@@ -489,12 +489,12 @@ class AgentSpecSync {
|
|
|
489
489
|
SubAgent: {
|
|
490
490
|
ID: relationship.SubAgentID,
|
|
491
491
|
Name: relationship.SubAgent || '',
|
|
492
|
-
StartingPayloadValidationMode: 'Fail'
|
|
492
|
+
StartingPayloadValidationMode: 'Fail',
|
|
493
493
|
},
|
|
494
494
|
AgentRelationshipID: relationship.ID,
|
|
495
495
|
SubAgentInputMapping: this.parseJsonField(relationship.SubAgentInputMapping),
|
|
496
496
|
SubAgentOutputMapping: this.parseJsonField(relationship.SubAgentOutputMapping),
|
|
497
|
-
SubAgentContextPaths: this.parseJsonField(relationship.SubAgentContextPaths)
|
|
497
|
+
SubAgentContextPaths: this.parseJsonField(relationship.SubAgentContextPaths),
|
|
498
498
|
};
|
|
499
499
|
}
|
|
500
500
|
/**
|
|
@@ -515,7 +515,7 @@ class AgentSpecSync {
|
|
|
515
515
|
PromptID: agentPrompt.PromptID || '',
|
|
516
516
|
PromptText: '',
|
|
517
517
|
PromptRole: 'System',
|
|
518
|
-
PromptPosition: 'First'
|
|
518
|
+
PromptPosition: 'First',
|
|
519
519
|
};
|
|
520
520
|
}
|
|
521
521
|
return {
|
|
@@ -523,7 +523,7 @@ class AgentSpecSync {
|
|
|
523
523
|
PromptID: fullPrompt.ID || '',
|
|
524
524
|
PromptText: fullPrompt.TemplateText || '',
|
|
525
525
|
PromptRole: fullPrompt.PromptRole || 'System',
|
|
526
|
-
PromptPosition: fullPrompt.PromptPosition || 'First'
|
|
526
|
+
PromptPosition: fullPrompt.PromptPosition || 'First',
|
|
527
527
|
};
|
|
528
528
|
}
|
|
529
529
|
/**
|
|
@@ -544,7 +544,7 @@ class AgentSpecSync {
|
|
|
544
544
|
SubAgentID: step.SubAgentID || undefined,
|
|
545
545
|
PromptID: step.PromptID || undefined,
|
|
546
546
|
ActionInputMapping: this.parseJsonField(step.ActionInputMapping),
|
|
547
|
-
ActionOutputMapping: this.parseJsonField(step.ActionOutputMapping)
|
|
547
|
+
ActionOutputMapping: this.parseJsonField(step.ActionOutputMapping),
|
|
548
548
|
};
|
|
549
549
|
}
|
|
550
550
|
/**
|
|
@@ -561,7 +561,7 @@ class AgentSpecSync {
|
|
|
561
561
|
DestinationStepID: path.DestinationStepID,
|
|
562
562
|
Condition: path.Condition || undefined,
|
|
563
563
|
Description: path.Description || undefined,
|
|
564
|
-
Priority: path.Priority
|
|
564
|
+
Priority: path.Priority,
|
|
565
565
|
};
|
|
566
566
|
}
|
|
567
567
|
// ===== SAVING METHODS =====
|
|
@@ -598,7 +598,7 @@ class AgentSpecSync {
|
|
|
598
598
|
return {
|
|
599
599
|
agentId: this.spec.ID,
|
|
600
600
|
success: true,
|
|
601
|
-
mutations: []
|
|
601
|
+
mutations: [],
|
|
602
602
|
};
|
|
603
603
|
}
|
|
604
604
|
try {
|
|
@@ -629,7 +629,7 @@ class AgentSpecSync {
|
|
|
629
629
|
return {
|
|
630
630
|
agentId,
|
|
631
631
|
success: true,
|
|
632
|
-
mutations: this.getMutations()
|
|
632
|
+
mutations: this.getMutations(),
|
|
633
633
|
};
|
|
634
634
|
}
|
|
635
635
|
catch (error) {
|
|
@@ -637,7 +637,7 @@ class AgentSpecSync {
|
|
|
637
637
|
return {
|
|
638
638
|
agentId: this.spec.ID || '',
|
|
639
639
|
success: false,
|
|
640
|
-
mutations: this.getMutations()
|
|
640
|
+
mutations: this.getMutations(),
|
|
641
641
|
};
|
|
642
642
|
}
|
|
643
643
|
}
|
|
@@ -650,7 +650,7 @@ class AgentSpecSync {
|
|
|
650
650
|
* @throws {Error} If validation fails or save fails
|
|
651
651
|
*/
|
|
652
652
|
async saveAgentEntity(validate) {
|
|
653
|
-
const md = new
|
|
653
|
+
const md = new global_1.Metadata();
|
|
654
654
|
const agentEntity = await md.GetEntityObject('AI Agents', this._contextUser);
|
|
655
655
|
// Track if this is an update or create
|
|
656
656
|
const isUpdate = !!this.spec.ID;
|
|
@@ -683,12 +683,8 @@ class AgentSpecSync {
|
|
|
683
683
|
// Serialize JSON fields
|
|
684
684
|
agentEntity.PayloadDownstreamPaths = JSON.stringify(this.spec.PayloadDownstreamPaths || ['*']);
|
|
685
685
|
agentEntity.PayloadUpstreamPaths = JSON.stringify(this.spec.PayloadUpstreamPaths || ['*']);
|
|
686
|
-
agentEntity.PayloadSelfReadPaths = this.spec.PayloadSelfReadPaths
|
|
687
|
-
|
|
688
|
-
: null;
|
|
689
|
-
agentEntity.PayloadSelfWritePaths = this.spec.PayloadSelfWritePaths
|
|
690
|
-
? JSON.stringify(this.spec.PayloadSelfWritePaths)
|
|
691
|
-
: null;
|
|
686
|
+
agentEntity.PayloadSelfReadPaths = this.spec.PayloadSelfReadPaths ? JSON.stringify(this.spec.PayloadSelfReadPaths) : null;
|
|
687
|
+
agentEntity.PayloadSelfWritePaths = this.spec.PayloadSelfWritePaths ? JSON.stringify(this.spec.PayloadSelfWritePaths) : null;
|
|
692
688
|
agentEntity.PayloadScope = this.spec.PayloadScope || null;
|
|
693
689
|
// Validation fields
|
|
694
690
|
agentEntity.FinalPayloadValidation = this.spec.FinalPayloadValidation || null;
|
|
@@ -724,7 +720,7 @@ class AgentSpecSync {
|
|
|
724
720
|
if (validate) {
|
|
725
721
|
const validation = agentEntity.Validate();
|
|
726
722
|
if (!validation.Success) {
|
|
727
|
-
const errors = validation.Errors.map(e => e.Message).join(', ');
|
|
723
|
+
const errors = validation.Errors.map((e) => e.Message).join(', ');
|
|
728
724
|
throw new Error(`Agent validation failed: ${errors}`);
|
|
729
725
|
}
|
|
730
726
|
}
|
|
@@ -754,7 +750,7 @@ class AgentSpecSync {
|
|
|
754
750
|
if (!this.spec.Actions || this.spec.Actions.length === 0) {
|
|
755
751
|
return;
|
|
756
752
|
}
|
|
757
|
-
const md = new
|
|
753
|
+
const md = new global_1.Metadata();
|
|
758
754
|
for (const actionSpec of this.spec.Actions) {
|
|
759
755
|
const actionEntity = await md.GetEntityObject('AI Agent Actions', this._contextUser);
|
|
760
756
|
// Track if this is an update or create
|
|
@@ -830,7 +826,7 @@ class AgentSpecSync {
|
|
|
830
826
|
// Set ParentID in the sub-agent spec before creating it
|
|
831
827
|
const childSpec = {
|
|
832
828
|
...SubAgentSpec.SubAgent,
|
|
833
|
-
ParentID: parentId
|
|
829
|
+
ParentID: parentId,
|
|
834
830
|
};
|
|
835
831
|
// Recursively create the sub-agent using AgentSpecSync
|
|
836
832
|
const childSync = new AgentSpecSync(childSpec, this._contextUser);
|
|
@@ -846,7 +842,7 @@ class AgentSpecSync {
|
|
|
846
842
|
// Set ParentID in the sub-agent spec
|
|
847
843
|
const childSpec = {
|
|
848
844
|
...SubAgentSpec.SubAgent,
|
|
849
|
-
ParentID: parentId
|
|
845
|
+
ParentID: parentId,
|
|
850
846
|
};
|
|
851
847
|
// Recursively update the sub-agent using AgentSpecSync
|
|
852
848
|
// This ensures all fields including FunctionalRequirements and TechnicalDesign are updated
|
|
@@ -869,7 +865,7 @@ class AgentSpecSync {
|
|
|
869
865
|
* @throws {Error} If relationship save fails
|
|
870
866
|
*/
|
|
871
867
|
async saveRelatedSubAgent(agentId, SubAgentSpec) {
|
|
872
|
-
const md = new
|
|
868
|
+
const md = new global_1.Metadata();
|
|
873
869
|
const relationshipEntity = await md.GetEntityObject('MJ: AI Agent Relationships', this._contextUser);
|
|
874
870
|
// Load existing if ID provided
|
|
875
871
|
const isUpdate = !!SubAgentSpec.AgentRelationshipID;
|
|
@@ -926,8 +922,8 @@ class AgentSpecSync {
|
|
|
926
922
|
return;
|
|
927
923
|
}
|
|
928
924
|
console.log(`💬 savePrompts: Processing ${this.spec.Prompts.length} prompt(s)...`);
|
|
929
|
-
const md = new
|
|
930
|
-
const rv = new
|
|
925
|
+
const md = new global_1.Metadata();
|
|
926
|
+
const rv = new global_1.RunView();
|
|
931
927
|
// Step 1: Create or update AIPrompt records
|
|
932
928
|
for (let i = 0; i < this.spec.Prompts.length; i++) {
|
|
933
929
|
const promptSpec = this.spec.Prompts[i];
|
|
@@ -985,7 +981,7 @@ class AgentSpecSync {
|
|
|
985
981
|
const existingJunctionResult = await rv.RunView({
|
|
986
982
|
EntityName: 'MJ: AI Agent Prompts',
|
|
987
983
|
ExtraFilter: `AgentID='${agentId}' AND PromptID='${promptEntity.ID}'`,
|
|
988
|
-
ResultType: 'entity_object'
|
|
984
|
+
ResultType: 'entity_object',
|
|
989
985
|
}, this._contextUser);
|
|
990
986
|
let agentPromptEntity;
|
|
991
987
|
let isJunctionUpdate = false;
|
|
@@ -1032,7 +1028,7 @@ class AgentSpecSync {
|
|
|
1032
1028
|
return;
|
|
1033
1029
|
}
|
|
1034
1030
|
console.log(`🔷 saveSteps: Processing ${this.spec.Steps.length} step(s)...`);
|
|
1035
|
-
const md = new
|
|
1031
|
+
const md = new global_1.Metadata();
|
|
1036
1032
|
for (const stepSpec of this.spec.Steps) {
|
|
1037
1033
|
const stepEntity = await md.GetEntityObject('MJ: AI Agent Steps', this._contextUser);
|
|
1038
1034
|
// Load existing if ID provided
|
|
@@ -1085,18 +1081,16 @@ class AgentSpecSync {
|
|
|
1085
1081
|
// Map Action I/O mappings for Flow agent action steps
|
|
1086
1082
|
// Handle ActionInputMapping - convert object to JSON string if needed
|
|
1087
1083
|
if (stepSpec.ActionInputMapping) {
|
|
1088
|
-
stepEntity.ActionInputMapping =
|
|
1089
|
-
? stepSpec.ActionInputMapping
|
|
1090
|
-
: JSON.stringify(stepSpec.ActionInputMapping);
|
|
1084
|
+
stepEntity.ActionInputMapping =
|
|
1085
|
+
typeof stepSpec.ActionInputMapping === 'string' ? stepSpec.ActionInputMapping : JSON.stringify(stepSpec.ActionInputMapping);
|
|
1091
1086
|
}
|
|
1092
1087
|
else {
|
|
1093
1088
|
stepEntity.ActionInputMapping = null;
|
|
1094
1089
|
}
|
|
1095
1090
|
// Handle ActionOutputMapping - convert object to JSON string if needed
|
|
1096
1091
|
if (stepSpec.ActionOutputMapping) {
|
|
1097
|
-
stepEntity.ActionOutputMapping =
|
|
1098
|
-
? stepSpec.ActionOutputMapping
|
|
1099
|
-
: JSON.stringify(stepSpec.ActionOutputMapping);
|
|
1092
|
+
stepEntity.ActionOutputMapping =
|
|
1093
|
+
typeof stepSpec.ActionOutputMapping === 'string' ? stepSpec.ActionOutputMapping : JSON.stringify(stepSpec.ActionOutputMapping);
|
|
1100
1094
|
}
|
|
1101
1095
|
else {
|
|
1102
1096
|
stepEntity.ActionOutputMapping = null;
|
|
@@ -1130,7 +1124,7 @@ class AgentSpecSync {
|
|
|
1130
1124
|
return;
|
|
1131
1125
|
}
|
|
1132
1126
|
console.log(`🔶 saveStepPaths: Processing ${this.spec.Paths.length} path(s)...`);
|
|
1133
|
-
const md = new
|
|
1127
|
+
const md = new global_1.Metadata();
|
|
1134
1128
|
// Create a map of step names to IDs for easy lookup
|
|
1135
1129
|
const stepNameToId = new Map();
|
|
1136
1130
|
if (this.spec.Steps) {
|
|
@@ -1195,7 +1189,7 @@ class AgentSpecSync {
|
|
|
1195
1189
|
return JSON.parse(jsonString);
|
|
1196
1190
|
}
|
|
1197
1191
|
catch (error) {
|
|
1198
|
-
(0,
|
|
1192
|
+
(0, global_1.LogError)(`Failed to parse JSON field: ${error}`);
|
|
1199
1193
|
return undefined;
|
|
1200
1194
|
}
|
|
1201
1195
|
}
|
|
@@ -1250,7 +1244,7 @@ class AgentSpecSync {
|
|
|
1250
1244
|
Prompts: partial.Prompts || [],
|
|
1251
1245
|
// Flow agent fields - critical for Flow agent support
|
|
1252
1246
|
Steps: partial.Steps || [],
|
|
1253
|
-
Paths: partial.Paths || []
|
|
1247
|
+
Paths: partial.Paths || [],
|
|
1254
1248
|
};
|
|
1255
1249
|
}
|
|
1256
1250
|
/**
|
|
@@ -1339,41 +1333,40 @@ class AgentSpecSync {
|
|
|
1339
1333
|
* @throws {Error} If any query fails
|
|
1340
1334
|
*/
|
|
1341
1335
|
async loadCurrentDatabaseState(agentId) {
|
|
1342
|
-
const rv = new
|
|
1336
|
+
const rv = new global_1.RunView();
|
|
1343
1337
|
// Batch load all related records for this agent
|
|
1344
1338
|
const [actions, prompts, relationships, steps, childAgents] = await rv.RunViews([
|
|
1345
1339
|
{
|
|
1346
1340
|
EntityName: 'AI Agent Actions',
|
|
1347
1341
|
ExtraFilter: `AgentID='${agentId}'`,
|
|
1348
|
-
ResultType: 'entity_object'
|
|
1342
|
+
ResultType: 'entity_object',
|
|
1349
1343
|
},
|
|
1350
1344
|
{
|
|
1351
1345
|
EntityName: 'MJ: AI Agent Prompts',
|
|
1352
1346
|
ExtraFilter: `AgentID='${agentId}'`,
|
|
1353
|
-
ResultType: 'entity_object'
|
|
1347
|
+
ResultType: 'entity_object',
|
|
1354
1348
|
},
|
|
1355
1349
|
{
|
|
1356
1350
|
EntityName: 'MJ: AI Agent Relationships',
|
|
1357
1351
|
ExtraFilter: `AgentID='${agentId}'`,
|
|
1358
|
-
ResultType: 'entity_object'
|
|
1352
|
+
ResultType: 'entity_object',
|
|
1359
1353
|
},
|
|
1360
1354
|
{
|
|
1361
1355
|
EntityName: 'MJ: AI Agent Steps',
|
|
1362
1356
|
ExtraFilter: `AgentID='${agentId}'`,
|
|
1363
|
-
ResultType: 'entity_object'
|
|
1357
|
+
ResultType: 'entity_object',
|
|
1364
1358
|
},
|
|
1365
1359
|
{
|
|
1366
1360
|
EntityName: 'AI Agents',
|
|
1367
1361
|
ExtraFilter: `ParentID='${agentId}'`,
|
|
1368
|
-
ResultType: 'entity_object'
|
|
1369
|
-
}
|
|
1362
|
+
ResultType: 'entity_object',
|
|
1363
|
+
},
|
|
1370
1364
|
], this._contextUser);
|
|
1371
1365
|
// Check for errors
|
|
1372
|
-
if (!actions.Success || !prompts.Success || !relationships.Success ||
|
|
1373
|
-
!steps.Success || !childAgents.Success) {
|
|
1366
|
+
if (!actions.Success || !prompts.Success || !relationships.Success || !steps.Success || !childAgents.Success) {
|
|
1374
1367
|
const errors = [actions, prompts, relationships, steps, childAgents]
|
|
1375
|
-
.filter(r => !r.Success)
|
|
1376
|
-
.map(r => r.ErrorMessage)
|
|
1368
|
+
.filter((r) => !r.Success)
|
|
1369
|
+
.map((r) => r.ErrorMessage)
|
|
1377
1370
|
.join('; ');
|
|
1378
1371
|
throw new Error(`Failed to load database state: ${errors}`);
|
|
1379
1372
|
}
|
|
@@ -1385,7 +1378,7 @@ class AgentSpecSync {
|
|
|
1385
1378
|
pathsResult = await rv.RunView({
|
|
1386
1379
|
EntityName: 'MJ: AI Agent Step Paths',
|
|
1387
1380
|
ExtraFilter: `OriginStepID IN (${stepIds})`,
|
|
1388
|
-
ResultType: 'entity_object'
|
|
1381
|
+
ResultType: 'entity_object',
|
|
1389
1382
|
}, this._contextUser);
|
|
1390
1383
|
if (!pathsResult.Success) {
|
|
1391
1384
|
throw new Error(`Failed to load step paths: ${pathsResult.ErrorMessage}`);
|
|
@@ -1401,7 +1394,7 @@ class AgentSpecSync {
|
|
|
1401
1394
|
relationships: relationships.Results || [],
|
|
1402
1395
|
steps: stepRecords,
|
|
1403
1396
|
paths: pathsResult.Results || [],
|
|
1404
|
-
childAgents: childAgents.Results || []
|
|
1397
|
+
childAgents: childAgents.Results || [],
|
|
1405
1398
|
};
|
|
1406
1399
|
}
|
|
1407
1400
|
/**
|
|
@@ -1422,17 +1415,17 @@ class AgentSpecSync {
|
|
|
1422
1415
|
identifyOrphans(dbState, spec) {
|
|
1423
1416
|
return {
|
|
1424
1417
|
// Orphaned actions: DB actions not in spec.Actions
|
|
1425
|
-
actions: dbState.actions.filter(dbAction => !spec.Actions?.some(specAction => specAction.AgentActionID === dbAction.ID)),
|
|
1418
|
+
actions: dbState.actions.filter((dbAction) => !spec.Actions?.some((specAction) => specAction.AgentActionID === dbAction.ID)),
|
|
1426
1419
|
// Orphaned prompt junctions: DB prompts not in spec.Prompts
|
|
1427
|
-
prompts: dbState.prompts.filter(dbPrompt => !spec.Prompts?.some(specPrompt => specPrompt.ID === dbPrompt.ID)),
|
|
1420
|
+
prompts: dbState.prompts.filter((dbPrompt) => !spec.Prompts?.some((specPrompt) => specPrompt.ID === dbPrompt.ID)),
|
|
1428
1421
|
// Orphaned relationships: DB relationships not in spec.SubAgents (related type)
|
|
1429
|
-
relationships: dbState.relationships.filter(dbRel => !spec.SubAgents?.some(specSub => specSub.Type === 'related' && specSub.AgentRelationshipID === dbRel.ID)),
|
|
1422
|
+
relationships: dbState.relationships.filter((dbRel) => !spec.SubAgents?.some((specSub) => specSub.Type === 'related' && specSub.AgentRelationshipID === dbRel.ID)),
|
|
1430
1423
|
// Orphaned steps: DB steps not in spec.Steps
|
|
1431
|
-
steps: dbState.steps.filter(dbStep => !spec.Steps?.some(specStep => specStep.ID === dbStep.ID)),
|
|
1424
|
+
steps: dbState.steps.filter((dbStep) => !spec.Steps?.some((specStep) => specStep.ID === dbStep.ID)),
|
|
1432
1425
|
// Orphaned paths: DB paths not in spec.Paths
|
|
1433
|
-
paths: dbState.paths.filter(dbPath => !spec.Paths?.some(specPath => specPath.ID === dbPath.ID)),
|
|
1426
|
+
paths: dbState.paths.filter((dbPath) => !spec.Paths?.some((specPath) => specPath.ID === dbPath.ID)),
|
|
1434
1427
|
// Orphaned child agents: DB children not in spec.SubAgents (child type)
|
|
1435
|
-
childAgents: dbState.childAgents.filter(dbChild => !spec.SubAgents?.some(specSub => specSub.Type === 'child' && specSub.SubAgent.ID === dbChild.ID))
|
|
1428
|
+
childAgents: dbState.childAgents.filter((dbChild) => !spec.SubAgents?.some((specSub) => specSub.Type === 'child' && specSub.SubAgent.ID === dbChild.ID)),
|
|
1436
1429
|
};
|
|
1437
1430
|
}
|
|
1438
1431
|
/**
|
|
@@ -1451,7 +1444,7 @@ class AgentSpecSync {
|
|
|
1451
1444
|
* @throws {Error} If any delete operation fails
|
|
1452
1445
|
*/
|
|
1453
1446
|
async deleteOrphans(orphans) {
|
|
1454
|
-
const md = new
|
|
1447
|
+
const md = new global_1.Metadata();
|
|
1455
1448
|
// Phase 1: Leaf entities (Paths, Actions)
|
|
1456
1449
|
console.log(`🗑️ Phase 1: Deleting ${orphans.paths.length} paths and ${orphans.actions.length} actions...`);
|
|
1457
1450
|
for (const path of orphans.paths) {
|
|
@@ -1561,7 +1554,7 @@ class AgentSpecSync {
|
|
|
1561
1554
|
*/
|
|
1562
1555
|
async orphanChildAgent(childAgentId) {
|
|
1563
1556
|
console.log(`🔗 orphanChildAgent: Orphaning child agent ${childAgentId}...`);
|
|
1564
|
-
const md = new
|
|
1557
|
+
const md = new global_1.Metadata();
|
|
1565
1558
|
const childAgent = await md.GetEntityObject('AI Agents', this._contextUser);
|
|
1566
1559
|
const loaded = await childAgent.Load(childAgentId);
|
|
1567
1560
|
if (!loaded) {
|