UNPKG

@memberjunction/ai-agent-manager-actions

Version:

Agent Management actions for creating and managing AI agents in MemberJunction

114 lines 5.26 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.LoadListActionsAction = exports.ListActionsAction = 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 available actions that can be associated with agents. * Used by the Planning Designer Agent to discover available actions. * * @example * ```typescript * const result = await runAction({ * ActionName: 'List Actions', * Params: [ * { Name: 'CategoryID', Value: 'category-id' }, // Optional filter * { Name: 'ExcludeAgentManagement', Value: 'true' } // Optional, default true * ] * }); * // Returns Actions array in output params * ``` */ let ListActionsAction = class ListActionsAction extends base_agent_management_action_1.BaseAgentManagementAction { async InternalRunAction(params) { try { // Note: This action may be called by sub-agents, so we might relax permission check // For now, keeping it restricted to Agent Manager ecosystem // Extract parameters const categoryIDResult = this.getStringParam(params, 'CategoryID', false); const excludeAgentMgmtResult = this.getStringParam(params, 'ExcludeAgentManagement', false); const excludeAgentMgmt = excludeAgentMgmtResult.value?.toLowerCase() !== 'false'; // Default true // Build filter let filters = ["Status = 'Active'"]; // Add category filter if provided if (categoryIDResult.value) { filters.push(`CategoryID = '${categoryIDResult.value}'`); } // Exclude agent management actions by default (to prevent recursion) if (excludeAgentMgmt) { // This assumes Agent Management category has been created filters.push(`CategoryID NOT IN (SELECT ID FROM ActionCategory WHERE Name = 'Agent Management')`); } // Run the view to get actions const rv = new core_1.RunView(); const result = await rv.RunView({ EntityName: 'Actions', ExtraFilter: filters.join(' AND '), OrderBy: 'Category, Name', ResultType: 'entity_object' }, params.ContextUser); if (result.Success) { // Transform the results to return only necessary fields const actions = (result.Results || []).map(action => ({ ID: action.ID, Name: action.Name, Description: action.Description, Type: action.Type, Category: action.Category, CategoryID: action.CategoryID, Status: action.Status, // Include parameter information for planning Parameters: this.extractActionParameters(action) })); // Add output parameter params.Params.push({ Name: 'Actions', Value: actions, Type: 'Output' }); return { Success: true, ResultCode: 'SUCCESS', Message: `Found ${actions.length} available action${actions.length !== 1 ? 's' : ''}`, Params: params.Params }; } else { return { Success: false, ResultCode: 'QUERY_FAILED', Message: result.ErrorMessage || 'Failed to query actions' }; } } catch (e) { return this.handleError(e, 'list actions'); } } /** * Extract parameter information from an action entity * This would typically load the Action Params related entities */ extractActionParameters(action) { // TODO: In a complete implementation, this would load the Action Params // For now, returning a placeholder return []; } }; exports.ListActionsAction = ListActionsAction; exports.ListActionsAction = ListActionsAction = __decorate([ (0, global_1.RegisterClass)(actions_1.BaseAction, "List Actions") ], ListActionsAction); function LoadListActionsAction() { // This function exists to prevent tree shaking from removing the action class } exports.LoadListActionsAction = LoadListActionsAction; //# sourceMappingURL=list-actions.action.js.map