@memberjunction/ai-agent-manager 2.108.0 → 2.109.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.
@@ -0,0 +1,247 @@
1
+ "use strict";
2
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
3
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
4
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
5
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
6
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
7
+ };
8
+ Object.defineProperty(exports, "__esModule", { value: true });
9
+ exports.AgentArchitectAgent = void 0;
10
+ const ai_agents_1 = require("@memberjunction/ai-agents");
11
+ const core_1 = require("@memberjunction/core");
12
+ const global_1 = require("@memberjunction/global");
13
+ /**
14
+ * Architect Agent - Transforms technical design into validated AgentSpec JSON
15
+ *
16
+ * This agent creates AgentSpec objects from technical designs and validates them
17
+ * before passing to the Builder Agent for persistence. It overrides validateSuccessNextStep
18
+ * to ensure the generated AgentSpec is valid before proceeding.
19
+ *
20
+ * Key responsibilities:
21
+ * - Transform design documents into AgentSpec format
22
+ * - Validate required fields are present
23
+ * - Verify action IDs exist in database
24
+ * - Verify prompt IDs exist (if specified)
25
+ * - Validate SubAgent structure
26
+ * - Auto-correct minor issues (casing, missing optional fields)
27
+ * - Force retry with detailed errors if validation fails
28
+ */
29
+ let AgentArchitectAgent = class AgentArchitectAgent extends ai_agents_1.BaseAgent {
30
+ /**
31
+ * Applies payload changes if any are requested in the next step
32
+ */
33
+ applyPayloadChanges(payload, nextStep) {
34
+ if (nextStep.payloadChangeRequest) {
35
+ const pm = new ai_agents_1.PayloadManager();
36
+ const result = pm.applyAgentChangeRequest(payload, nextStep.payloadChangeRequest);
37
+ return result.result || payload;
38
+ }
39
+ return payload;
40
+ }
41
+ async validateSuccessNextStep(params, nextStep, currentPayload, agentRun, currentStep) {
42
+ // First call base validation
43
+ const baseValidation = await super.validateSuccessNextStep(params, nextStep, currentPayload, agentRun, currentStep);
44
+ if (baseValidation.step === 'Retry') {
45
+ return baseValidation;
46
+ }
47
+ // Apply payload changes to get the spec that would be sent forward
48
+ const payloadWithChanges = this.applyPayloadChanges(currentPayload, nextStep);
49
+ // Extract the agentSpec from the nested payload structure
50
+ // The payload has structure: { metadata, requirements, design, agentSpec }
51
+ const agentSpec = payloadWithChanges.agentSpec;
52
+ console.log('🏗️ Architect Agent: Validating AgentSpec:', agentSpec ? `Name="${agentSpec.Name}"` : 'agentSpec is null/undefined');
53
+ // Validate the AgentSpec
54
+ const validation = await this.validateAgentSpec(agentSpec, params);
55
+ if (validation.errors.length > 0) {
56
+ console.log('❌ Architect Agent: Validation failed with errors:', validation.errors);
57
+ // Return retry with detailed error messages
58
+ return {
59
+ ...nextStep,
60
+ step: 'Retry',
61
+ retryInstructions: this.formatValidationErrors(validation.errors),
62
+ newPayload: nextStep.newPayload
63
+ };
64
+ }
65
+ // If spec was auto-corrected, update the payload with corrected spec
66
+ if (validation.correctedSpec) {
67
+ console.log('✓ Architect Agent: Auto-corrected AgentSpec, updating payload');
68
+ const updatedPayload = {
69
+ ...payloadWithChanges,
70
+ agentSpec: validation.correctedSpec
71
+ };
72
+ return {
73
+ ...nextStep,
74
+ newPayload: updatedPayload
75
+ };
76
+ }
77
+ console.log('✅ Architect Agent: AgentSpec validation passed');
78
+ return nextStep;
79
+ }
80
+ /**
81
+ * Validates an AgentSpec object
82
+ * Returns errors array and potentially a corrected spec
83
+ */
84
+ async validateAgentSpec(spec, params) {
85
+ const errors = [];
86
+ let corrected = false;
87
+ // Check if spec exists
88
+ if (!spec) {
89
+ errors.push('❌ AgentSpec is null or undefined. Ensure you place the AgentSpec in payload.agentSpec (inside a payloadChangeRequest with newElements or replaceElements)');
90
+ return { errors };
91
+ }
92
+ const correctedSpec = { ...spec };
93
+ // 1. Validate required fields
94
+ if (!correctedSpec.Name || correctedSpec.Name.trim().length === 0) {
95
+ errors.push('❌ AgentSpec.Name is required and cannot be empty');
96
+ }
97
+ if (!correctedSpec.StartingPayloadValidationMode) {
98
+ // Auto-correct: add default
99
+ correctedSpec.StartingPayloadValidationMode = 'Fail';
100
+ corrected = true;
101
+ console.log('✓ Auto-corrected: Added default StartingPayloadValidationMode = "Fail"');
102
+ }
103
+ else if (correctedSpec.StartingPayloadValidationMode !== 'Fail' && correctedSpec.StartingPayloadValidationMode !== 'Warn') {
104
+ errors.push(`❌ StartingPayloadValidationMode must be either "Fail" or "Warn", got: "${correctedSpec.StartingPayloadValidationMode}"`);
105
+ }
106
+ // 2. Validate Actions if specified
107
+ if (correctedSpec.Actions && correctedSpec.Actions.length > 0) {
108
+ const actionValidation = await this.validateActions(correctedSpec.Actions, params);
109
+ if (actionValidation.errors.length > 0) {
110
+ errors.push(...actionValidation.errors);
111
+ }
112
+ }
113
+ // 3. Validate SubAgents if specified
114
+ if (correctedSpec.SubAgents && correctedSpec.SubAgents.length > 0) {
115
+ const subAgentValidation = this.validateSubAgents(correctedSpec.SubAgents);
116
+ if (subAgentValidation.errors.length > 0) {
117
+ errors.push(...subAgentValidation.errors);
118
+ }
119
+ if (subAgentValidation.corrected) {
120
+ corrected = true;
121
+ }
122
+ }
123
+ // 4. Validate optional but important fields
124
+ if (correctedSpec.FinalPayloadValidationMode &&
125
+ !['Fail', 'Retry', 'Warn'].includes(correctedSpec.FinalPayloadValidationMode)) {
126
+ errors.push(`❌ FinalPayloadValidationMode must be "Fail", "Retry", or "Warn", got: "${correctedSpec.FinalPayloadValidationMode}"`);
127
+ }
128
+ if (correctedSpec.InvocationMode &&
129
+ !['Any', 'Agent', 'User', 'Never'].includes(correctedSpec.InvocationMode)) {
130
+ errors.push(`❌ InvocationMode must be "Any", "Agent", "User", or "Never", got: "${correctedSpec.InvocationMode}"`);
131
+ }
132
+ return {
133
+ errors,
134
+ correctedSpec: corrected ? correctedSpec : undefined
135
+ };
136
+ }
137
+ /**
138
+ * Validates that action IDs exist in the database
139
+ */
140
+ async validateActions(actions, params) {
141
+ const errors = [];
142
+ if (!actions || actions.length === 0) {
143
+ return { errors };
144
+ }
145
+ try {
146
+ const rv = new core_1.RunView();
147
+ const actionIds = actions
148
+ .map(a => a.ActionID)
149
+ .filter(id => id && id.trim().length > 0);
150
+ if (actionIds.length === 0) {
151
+ errors.push('❌ All actions must have an ActionID');
152
+ return { errors };
153
+ }
154
+ // Query database for these action IDs
155
+ const filter = actionIds.map(id => `ID='${id}'`).join(' OR ');
156
+ const result = await rv.RunView({
157
+ EntityName: 'Actions',
158
+ ExtraFilter: filter,
159
+ ResultType: 'entity_object'
160
+ }, params.contextUser);
161
+ if (!result.Success) {
162
+ errors.push(`❌ Failed to validate actions: ${result.ErrorMessage}`);
163
+ return { errors };
164
+ }
165
+ const foundIds = new Set(result.Results.map(a => a.ID));
166
+ // Check which actions weren't found
167
+ for (const action of actions) {
168
+ if (!action.ActionID) {
169
+ errors.push('❌ Action is missing ActionID field');
170
+ continue;
171
+ }
172
+ if (!foundIds.has(action.ActionID)) {
173
+ errors.push(`❌ Action with ID "${action.ActionID}" not found in database. Please use "Find Best Action" or "List Actions" to get valid action IDs.`);
174
+ }
175
+ }
176
+ }
177
+ catch (error) {
178
+ errors.push(`❌ Error validating actions: ${error?.message || String(error)}`);
179
+ }
180
+ return { errors };
181
+ }
182
+ /**
183
+ * Validates SubAgent structure
184
+ */
185
+ validateSubAgents(subAgents) {
186
+ const errors = [];
187
+ let corrected = false;
188
+ if (!subAgents || subAgents.length === 0) {
189
+ return { errors, corrected };
190
+ }
191
+ for (let i = 0; i < subAgents.length; i++) {
192
+ const subAgent = subAgents[i];
193
+ // Validate Type field
194
+ if (!subAgent.Type) {
195
+ errors.push(`❌ SubAgent at index ${i} is missing required "Type" field (must be "child" or "related")`);
196
+ continue;
197
+ }
198
+ if (subAgent.Type !== 'child' && subAgent.Type !== 'related') {
199
+ errors.push(`❌ SubAgent at index ${i} has invalid Type "${subAgent.Type}" (must be "child" or "related")`);
200
+ continue;
201
+ }
202
+ // Validate SubAgent.SubAgent field
203
+ if (!subAgent.SubAgent) {
204
+ errors.push(`❌ SubAgent at index ${i} is missing required "SubAgent" field`);
205
+ continue;
206
+ }
207
+ // SubAgent.ID can be empty string "" for NEW sub-agents (Builder creates them recursively)
208
+ // Only validate that ID is not null/undefined
209
+ if (subAgent.SubAgent.ID === null || subAgent.SubAgent.ID === undefined) {
210
+ errors.push(`❌ SubAgent at index ${i} has null/undefined SubAgent.ID (use empty string "" for new sub-agents, or provide existing agent GUID)`);
211
+ }
212
+ // Validate SubAgent.SubAgent.Name
213
+ if (!subAgent.SubAgent.Name || subAgent.SubAgent.Name.trim().length === 0) {
214
+ errors.push(`❌ SubAgent at index ${i} is missing SubAgent.Name`);
215
+ }
216
+ // Auto-correct: Add default StartingPayloadValidationMode if missing
217
+ if (!subAgent.SubAgent.StartingPayloadValidationMode) {
218
+ subAgent.SubAgent.StartingPayloadValidationMode = 'Fail';
219
+ corrected = true;
220
+ console.log(`✓ Auto-corrected: Added SubAgent[${i}].SubAgent.StartingPayloadValidationMode = "Fail"`);
221
+ }
222
+ // Validate related-specific fields
223
+ if (subAgent.Type === 'related' && !subAgent.AgentRelationshipID) {
224
+ // AgentRelationshipID can be empty for new relationships, it will be created on save
225
+ // This is not an error
226
+ }
227
+ }
228
+ return { errors, corrected };
229
+ }
230
+ /**
231
+ * Formats validation errors into a clear, actionable message
232
+ */
233
+ formatValidationErrors(errors) {
234
+ if (errors.length === 0) {
235
+ return '';
236
+ }
237
+ const header = '## AgentSpec Validation Errors\n\nThe generated AgentSpec has the following issues that must be fixed:\n\n';
238
+ const errorList = errors.map((err, idx) => `${idx + 1}. ${err}`).join('\n');
239
+ const footer = '\n\n**Please fix these issues and regenerate the AgentSpec.**';
240
+ return header + errorList + footer;
241
+ }
242
+ };
243
+ exports.AgentArchitectAgent = AgentArchitectAgent;
244
+ exports.AgentArchitectAgent = AgentArchitectAgent = __decorate([
245
+ (0, global_1.RegisterClass)(ai_agents_1.BaseAgent, 'AgentArchitectAgent')
246
+ ], AgentArchitectAgent);
247
+ //# sourceMappingURL=architect-agent.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"architect-agent.js","sourceRoot":"","sources":["../../src/agents/architect-agent.ts"],"names":[],"mappings":";;;;;;;;;AAAA,yDAAsE;AAGtE,+CAAyD;AACzD,mDAAuD;AAEvD;;;;;;;;;;;;;;;GAeG;AAEI,IAAM,mBAAmB,GAAzB,MAAM,mBAAoB,SAAQ,qBAAS;IAE9C;;OAEG;IACO,mBAAmB,CAAI,OAAU,EAAE,QAA8B;QACvE,IAAI,QAAQ,CAAC,oBAAoB,EAAE,CAAC;YAChC,MAAM,EAAE,GAAG,IAAI,0BAAc,EAAE,CAAC;YAChC,MAAM,MAAM,GAAG,EAAE,CAAC,uBAAuB,CAAI,OAAO,EAAE,QAAQ,CAAC,oBAAoB,CAAC,CAAC;YACrF,OAAO,MAAM,CAAC,MAAM,IAAI,OAAO,CAAC;QACpC,CAAC;QACD,OAAO,OAAO,CAAC;IACnB,CAAC;IAEkB,KAAK,CAAC,uBAAuB,CAC5C,MAA0B,EAC1B,QAA8B,EAC9B,cAAiB,EACjB,QAAkC,EAClC,WAAyC;QAEzC,6BAA6B;QAC7B,MAAM,cAAc,GAAG,MAAM,KAAK,CAAC,uBAAuB,CAAC,MAAM,EAAE,QAAQ,EAAE,cAAc,EAAE,QAAQ,EAAE,WAAW,CAAC,CAAC;QACpH,IAAI,cAAc,CAAC,IAAI,KAAK,OAAO,EAAE,CAAC;YAClC,OAAO,cAAc,CAAC;QAC1B,CAAC;QAED,mEAAmE;QACnE,MAAM,kBAAkB,GAAG,IAAI,CAAC,mBAAmB,CAAI,cAAc,EAAE,QAAQ,CAAC,CAAC;QAEjF,0DAA0D;QAC1D,2EAA2E;QAC3E,MAAM,S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C;QAC5E,MAAM,MAAM,GAAG,+DAA+D,CAAC;QAE/E,OAAO,MAAM,GAAG,SAAS,GAAG,MAAM,CAAC;IACvC,CAAC;CACJ,CAAA;AA7QY,kDAAmB;8BAAnB,mBAAmB;IAD/B,IAAA,sBAAa,EAAC,qBAAS,EAAE,qBAAqB,CAAC;GACnC,mBAAmB,CA6Q/B"}
@@ -0,0 +1,29 @@
1
+ import { BaseAgent } from '@memberjunction/ai-agents';
2
+ import { ExecuteAgentParams, AgentConfiguration, BaseAgentNextStep } from '@memberjunction/ai-core-plus';
3
+ /**
4
+ * Builder Agent - Persists validated AgentSpec to database via AgentSpecSync
5
+ *
6
+ * This is a code-based agent that overrides executeAgentInternal to bypass
7
+ * the normal chat loop and directly execute persistence logic. It receives
8
+ * a validated AgentSpec from the Architect Agent and saves it to the database
9
+ * using AgentSpecSync.
10
+ *
11
+ * Key responsibilities:
12
+ * - Receive validated AgentSpec from payload
13
+ * - Create AgentSpecSync instance
14
+ * - Persist to database
15
+ * - Return success with created agent ID, or failure with error details
16
+ *
17
+ * This agent does NOT iterate - it runs once and returns Success or Failed.
18
+ */
19
+ export declare class AgentBuilderAgent extends BaseAgent {
20
+ /**
21
+ * Override executeAgentInternal to run code instead of chat loop
22
+ * This follows the Skip Code Generator pattern
23
+ */
24
+ protected executeAgentInternal<P = any>(params: ExecuteAgentParams<P>, _config: AgentConfiguration): Promise<{
25
+ finalStep: BaseAgentNextStep<P>;
26
+ stepCount: number;
27
+ }>;
28
+ }
29
+ //# sourceMappingURL=builder-agent.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"builder-agent.d.ts","sourceRoot":"","sources":["../../src/agents/builder-agent.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,2BAA2B,CAAC;AACtD,OAAO,EAAE,kBAAkB,EAAE,kBAAkB,EAAE,iBAAiB,EAAa,MAAM,8BAA8B,CAAC;AAIpH;;;;;;;;;;;;;;;GAeG;AACH,qBACa,iBAAkB,SAAQ,SAAS;IAE5C;;;OAGG;cACsB,oBAAoB,CAAC,CAAC,GAAG,GAAG,EACjD,MAAM,EAAE,kBAAkB,CAAC,CAAC,CAAC,EAC7B,OAAO,EAAE,kBAAkB,GAC5B,OAAO,CAAC;QAAE,SAAS,EAAE,iBAAiB,CAAC,CAAC,CAAC,CAAC;QAAC,SAAS,EAAE,MAAM,CAAA;KAAE,CAAC;CAyDrE"}
@@ -0,0 +1,84 @@
1
+ "use strict";
2
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
3
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
4
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
5
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
6
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
7
+ };
8
+ Object.defineProperty(exports, "__esModule", { value: true });
9
+ exports.AgentBuilderAgent = void 0;
10
+ const ai_agents_1 = require("@memberjunction/ai-agents");
11
+ const global_1 = require("@memberjunction/global");
12
+ const agent_spec_sync_1 = require("../agent-spec-sync");
13
+ /**
14
+ * Builder Agent - Persists validated AgentSpec to database via AgentSpecSync
15
+ *
16
+ * This is a code-based agent that overrides executeAgentInternal to bypass
17
+ * the normal chat loop and directly execute persistence logic. It receives
18
+ * a validated AgentSpec from the Architect Agent and saves it to the database
19
+ * using AgentSpecSync.
20
+ *
21
+ * Key responsibilities:
22
+ * - Receive validated AgentSpec from payload
23
+ * - Create AgentSpecSync instance
24
+ * - Persist to database
25
+ * - Return success with created agent ID, or failure with error details
26
+ *
27
+ * This agent does NOT iterate - it runs once and returns Success or Failed.
28
+ */
29
+ let AgentBuilderAgent = class AgentBuilderAgent extends ai_agents_1.BaseAgent {
30
+ /**
31
+ * Override executeAgentInternal to run code instead of chat loop
32
+ * This follows the Skip Code Generator pattern
33
+ */
34
+ async executeAgentInternal(params, _config) {
35
+ console.log('🔨 Builder Agent: Starting agent persistence...');
36
+ try {
37
+ // Extract AgentSpec from nested payload structure
38
+ // The payload has structure: { metadata, requirements, design, agentSpec }
39
+ const agentSpec = params.payload.agentSpec;
40
+ if (!agentSpec) {
41
+ throw new Error('No AgentSpec found in payload.agentSpec - ensure Architect Agent placed it there');
42
+ }
43
+ if (!agentSpec.Name) {
44
+ throw new Error('AgentSpec is missing required Name field');
45
+ }
46
+ console.log(`🔨 Builder Agent: Creating agent "${agentSpec.Name}"...`);
47
+ // Create AgentSpecSync instance
48
+ const specSync = new agent_spec_sync_1.AgentSpecSync(agentSpec, params.contextUser);
49
+ // Mark as dirty to ensure it saves
50
+ specSync.markDirty();
51
+ // Save to database
52
+ const agentId = await specSync.SaveToDatabase();
53
+ console.log(`✅ Builder Agent: Successfully created agent with ID: ${agentId}`);
54
+ // Return success with the created agent ID
55
+ const updatedSpec = { ...agentSpec, ID: agentId };
56
+ return {
57
+ finalStep: {
58
+ terminate: true,
59
+ step: 'Success',
60
+ reasoning: `Successfully created agent "${agentSpec.Name}" with ID: ${agentId}`,
61
+ newPayload: updatedSpec
62
+ },
63
+ stepCount: 1
64
+ };
65
+ }
66
+ catch (error) {
67
+ console.error('❌ Builder Agent: Failed to create agent:', error);
68
+ // Return failure with error details
69
+ return {
70
+ finalStep: {
71
+ terminate: true,
72
+ step: 'Failed',
73
+ reasoning: `Failed to create agent: ${error?.message || String(error)}`
74
+ },
75
+ stepCount: 1
76
+ };
77
+ }
78
+ }
79
+ };
80
+ exports.AgentBuilderAgent = AgentBuilderAgent;
81
+ exports.AgentBuilderAgent = AgentBuilderAgent = __decorate([
82
+ (0, global_1.RegisterClass)(ai_agents_1.BaseAgent, 'AgentBuilderAgent')
83
+ ], AgentBuilderAgent);
84
+ //# sourceMappingURL=builder-agent.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"builder-agent.js","sourceRoot":"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,UAAU,EAAE,WAAgB;iBAC/B;gBACD,SAAS,EAAE,CAAC;aACf,CAAC;QAEN,CAAC;QAAC,OAAO,KAAU,EAAE,CAAC;YAClB,OAAO,CAAC,KAAK,CAAC,0CAA0C,EAAE,KAAK,CAAC,CAAC;YAEjE,oCAAoC;YACpC,OAAO;gBACH,SAAS,EAAE;oBACP,SAAS,EAAE,IAAI;oBACf,IAAI,EAAE,QAAQ;oBACd,SAAS,EAAE,2BAA2B,KAAK,EAAE,OAAO,IAAI,MAAM,CAAC,KAAK,CAAC,EAAE;iBAC1E;gBACD,SAAS,EAAE,CAAC;aACf,CAAC;QACN,CAAC;IACL,CAAC;CACJ,CAAA;AAlEY,8CAAiB;4BAAjB,iBAAiB;IAD7B,IAAA,sBAAa,EAAC,qBAAS,EAAE,mBAAmB,CAAC;GACjC,iBAAiB,CAkE7B"}
package/dist/index.d.ts CHANGED
@@ -5,4 +5,14 @@
5
5
  */
6
6
  export * from './old/agent-definition.interface';
7
7
  export * from './agent-spec-sync';
8
+ export * from './agents/architect-agent';
9
+ export * from './agents/builder-agent';
10
+ /**
11
+ * Loads the Agent Manager Core module and ensures all agent classes are registered.
12
+ * This function prevents tree shaking from removing the agent class registrations.
13
+ *
14
+ * The function itself doesn't need to do anything - importing the module is enough
15
+ * to trigger the @RegisterClass decorators on AgentArchitectAgent and AgentBuilderAgent.
16
+ */
17
+ export declare function LoadAgentManagerCore(): void;
8
18
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAGH,cAAc,kCAAkC,CAAC;AAEjD,cAAc,mBAAmB,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAGH,cAAc,kCAAkC,CAAC;AAEjD,cAAc,mBAAmB,CAAC;AAGlC,cAAc,0BAA0B,CAAC;AACzC,cAAc,wBAAwB,CAAC;AAEvC;;;;;;GAMG;AACH,wBAAgB,oBAAoB,SAGnC"}
package/dist/index.js CHANGED
@@ -19,7 +19,25 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
19
19
  for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
20
20
  };
21
21
  Object.defineProperty(exports, "__esModule", { value: true });
22
+ exports.LoadAgentManagerCore = void 0;
22
23
  // Export all interfaces
23
24
  __exportStar(require("./old/agent-definition.interface"), exports);
24
25
  __exportStar(require("./agent-spec-sync"), exports);
26
+ // Export agent implementations
27
+ __exportStar(require("./agents/architect-agent"), exports);
28
+ __exportStar(require("./agents/builder-agent"), exports);
29
+ /**
30
+ * Loads the Agent Manager Core module and ensures all agent classes are registered.
31
+ * This function prevents tree shaking from removing the agent class registrations.
32
+ *
33
+ * The function itself doesn't need to do anything - importing the module is enough
34
+ * to trigger the @RegisterClass decorators on AgentArchitectAgent and AgentBuilderAgent.
35
+ */
36
+ function LoadAgentManagerCore() {
37
+ // Forces module to load and decorators to execute
38
+ // Classes are already exported and decorators run on import
39
+ }
40
+ exports.LoadAgentManagerCore = LoadAgentManagerCore;
41
+ // Auto-load on import to ensure decorators execute
42
+ LoadAgentManagerCore();
25
43
  //# sourceMappingURL=index.js.map
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AAAA;;;;GAIG;;;;;;;;;;;;;;;;AAEH,wBAAwB;AACxB,mEAAiD;AAEjD,oDAAkC"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AAAA;;;;GAIG;;;;;;;;;;;;;;;;;AAEH,wBAAwB;AACxB,mEAAiD;AAEjD,oDAAkC;AAElC,+BAA+B;AAC/B,2DAAyC;AACzC,yDAAuC;AAEvC;;;;;;GAMG;AACH,SAAgB,oBAAoB;IAChC,kDAAkD;IAClD,4DAA4D;AAChE,CAAC;AAHD,oDAGC;AAED,mDAAmD;AACnD,oBAAoB,EAAE,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@memberjunction/ai-agent-manager",
3
- "version": "2.108.0",
3
+ "version": "2.109.0",
4
4
  "description": "Core interfaces and types for the MemberJunction Agent Manager system",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -20,9 +20,10 @@
20
20
  "license": "ISC",
21
21
  "dependencies": {
22
22
  "@memberjunction/core": "2.100.3",
23
- "@memberjunction/core-entities": "^2.108.0",
23
+ "@memberjunction/core-entities": "^2.109.0",
24
24
  "@memberjunction/global": "2.100.3",
25
- "@memberjunction/ai-core-plus": "^2.108.0"
25
+ "@memberjunction/ai-core-plus": "^2.109.0",
26
+ "@memberjunction/ai-agents": "^2.109.0"
26
27
  },
27
28
  "devDependencies": {
28
29
  "@types/node": "^18.11.0",