UNPKG

@memberjunction/ai-agent-manager-actions

Version:

Agent Management actions for creating and managing AI agents in MemberJunction

115 lines 5.17 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.LoadListAgentsAction = exports.ListAgentsAction = void 0; const global_1 = require("@memberjunction/global"); const core_1 = require("@memberjunction/core"); const base_agent_management_action_1 = require("./base-agent-management.action"); const actions_1 = require("@memberjunction/actions"); /** * Lists AI agents with optional filtering. * This action is restricted to the Agent Manager agent only. * * @example * ```typescript * const result = await runAction({ * ActionName: 'List Agents', * Params: [ * { Name: 'IncludeInactive', Value: 'false' }, // Optional, default false * { Name: 'ParentID', Value: 'parent-agent-id' }, // Optional filter * { Name: 'TypeID', Value: 'agent-type-id' } // Optional filter * ] * }); * // Returns Agents array in output params * ``` */ let ListAgentsAction = class ListAgentsAction 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 includeInactiveResult = this.getStringParam(params, 'IncludeInactive', false); const parentIDResult = this.getStringParam(params, 'ParentID', false); const typeIDResult = this.getStringParam(params, 'TypeID', false); // Build filter let filters = []; // By default, only show active agents unless specified const includeInactive = includeInactiveResult.value?.toLowerCase() === 'true'; if (!includeInactive) { filters.push("Status = 'Active'"); } // Add parent filter if provided if (parentIDResult.value) { filters.push(`ParentID = '${parentIDResult.value}'`); } // Add type filter if provided if (typeIDResult.value) { filters.push(`TypeID = '${typeIDResult.value}'`); } // Run the view to get agents const rv = new core_1.RunView(); const result = await rv.RunView({ EntityName: 'AI Agents', ExtraFilter: filters.length > 0 ? filters.join(' AND ') : '', OrderBy: 'Name', ResultType: 'entity_object' }, params.ContextUser); if (result.Success) { // Transform the results to return only necessary fields const agents = (result.Results || []).map(agent => ({ ID: agent.ID, Name: agent.Name, Description: agent.Description, TypeID: agent.TypeID, Type: agent.Type, ParentID: agent.ParentID, Parent: agent.Parent, Status: agent.Status, ExecutionOrder: agent.ExecutionOrder, ExposeAsAction: agent.ExposeAsAction, __mj_CreatedAt: agent.__mj_CreatedAt, __mj_UpdatedAt: agent.__mj_UpdatedAt })); // Add output parameter params.Params.push({ Name: 'Agents', Value: agents, Type: 'Output' }); return { Success: true, ResultCode: 'SUCCESS', Message: `Found ${agents.length} agent${agents.length !== 1 ? 's' : ''}. Details are in the output parameter 'Agents'.`, Params: params.Params }; } else { return { Success: false, ResultCode: 'QUERY_FAILED', Message: result.ErrorMessage || 'Failed to query agents' }; } } catch (e) { return this.handleError(e, 'list agents'); } } }; exports.ListAgentsAction = ListAgentsAction; exports.ListAgentsAction = ListAgentsAction = __decorate([ (0, global_1.RegisterClass)(actions_1.BaseAction, "List Agents") ], ListAgentsAction); function LoadListAgentsAction() { // This function exists to prevent tree shaking from removing the action class } exports.LoadListAgentsAction = LoadListAgentsAction; //# sourceMappingURL=list-agents.action.js.map