UNPKG

@memberjunction/ai-agent-manager-actions

Version:

Agent Management actions for creating and managing AI agents in MemberJunction

116 lines 5.23 kB
"use strict"; var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) { var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d; if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc); 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; return c > 3 && r && Object.defineProperty(target, key, r), r; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.LoadAssociateActionWithAgentAction = exports.AssociateActionWithAgentAction = void 0; const global_1 = require("@memberjunction/global"); const base_agent_management_action_1 = require("./base-agent-management.action"); const actions_1 = require("@memberjunction/actions"); /** * Associates an action with an agent. * This action is restricted to the Agent Manager agent only. * * @example * ```typescript * const result = await runAction({ * ActionName: 'Associate Action With Agent', * Params: [ * { Name: 'AgentID', Value: 'agent-id' }, * { Name: 'ActionID', Value: 'action-id' }, * { Name: 'Status', Value: 'Active' } // Optional, default 'Active' * ] * }); * // Returns AgentActionID in output params * ``` */ let AssociateActionWithAgentAction = class AssociateActionWithAgentAction extends base_agent_management_action_1.BaseAgentManagementAction { async InternalRunAction(params) { try { // Validate permission const permissionError = await this.validateAgentManagerPermission(params); if (permissionError) return permissionError; // Extract parameters const agentIDResult = this.getStringParam(params, 'AgentID'); if (agentIDResult.error) return agentIDResult.error; const actionIDResult = this.getStringParam(params, 'ActionID'); if (actionIDResult.error) return actionIDResult.error; const statusResult = this.getStringParam(params, 'Status', false); const status = statusResult.value || 'Active'; // Validate agent exists const agentValidation = await this.loadAgent(agentIDResult.value, params.ContextUser); if (agentValidation.error) return agentValidation.error; // TODO: Validate action exists // This would require loading the Action entity to ensure it's valid // Create the association const md = this.getMetadata(); const agentAction = await md.GetEntityObject('AI Agent Actions', params.ContextUser); if (!agentAction) { return { Success: false, ResultCode: 'FAILED', Message: 'Failed to create AI Agent Action entity object' }; } // Set properties agentAction.NewRecord(); agentAction.AgentID = agentIDResult.value; agentAction.ActionID = actionIDResult.value; switch (status.toLowerCase()) { case 'active': agentAction.Status = 'Active'; break; case 'revoked': agentAction.Status = 'Revoked'; break; case 'pending': default: agentAction.Status = 'Pending'; break; } // Save the association const saveResult = await agentAction.Save(); if (saveResult) { // Add output parameter params.Params.push({ Name: 'AgentActionID', Value: agentAction.ID, Type: 'Output' }); return { Success: true, ResultCode: 'SUCCESS', Message: `Successfully associated action with agent`, Params: params.Params }; } else { const latestResult = agentAction.LatestResult; return { Success: false, ResultCode: 'SAVE_FAILED', Message: latestResult?.Message || 'Failed to save agent action association' }; } } catch (e) { return this.handleError(e, 'associate action with agent'); } } }; exports.AssociateActionWithAgentAction = AssociateActionWithAgentAction; exports.AssociateActionWithAgentAction = AssociateActionWithAgentAction = __decorate([ (0, global_1.RegisterClass)(actions_1.BaseAction, "Associate Action With Agent") ], AssociateActionWithAgentAction); function LoadAssociateActionWithAgentAction() { // This function exists to prevent tree shaking from removing the action class } exports.LoadAssociateActionWithAgentAction = LoadAssociateActionWithAgentAction; //# sourceMappingURL=associate-action-with-agent.action.js.map