@memberjunction/ai-agent-manager-actions
Version:
Agent Management actions for creating and managing AI agents in MemberJunction
104 lines • 4.88 kB
TypeScript
import { ActionResultSimple, RunActionParams } from "@memberjunction/actions-base";
import { BaseAction } from "@memberjunction/actions";
import { IMetadataProvider, UserInfo } from "@memberjunction/core";
import { DatabaseProviderBase } from "@memberjunction/core";
import { MJAIAgentEntityExtended } from "@memberjunction/ai-core-plus";
import { AgentLoadResult, ParameterResult, AgentTypeValidationResult, PromptCreationResult, ObjectParameter } from "../types/agent-management.types.js";
/**
* Abstract base class for agent management actions.
* Provides common functionality for validating permissions, loading entities,
* and managing agent metadata. Only the Agent Manager agent should be able
* to execute these actions.
*/
export declare abstract class BaseAgentManagementAction extends BaseAction {
/**
* Validates that the action is being called by the Agent Manager agent
*/
protected validateAgentManagerPermission(params: RunActionParams): Promise<ActionResultSimple | null>;
/**
* Extract and validate a string parameter
*/
protected getStringParam(params: RunActionParams, paramName: string, required?: boolean): ParameterResult<string>;
/**
* Extract and validate an object parameter
*/
protected getObjectParam(params: RunActionParams, paramName: string, required?: boolean): ParameterResult<ObjectParameter>;
/**
* Resolve the metadata provider for the running action. Pass `params` from
* `InternalRunAction` so every entity load/save binds to the per-request provider
* (`params.Provider`) rather than the process-global default. Falls back to a default
* Metadata helper instance when no provider was passed (e.g. legacy callers).
*/
protected getMetadata(params?: RunActionParams): IMetadataProvider;
/**
* Validates if a string is a valid UUID format
*/
protected isValidUUID(uuid: string): boolean;
/**
* Extract and validate a UUID parameter
*/
protected getUuidParam(params: RunActionParams, paramName: string, required?: boolean): ParameterResult<string>;
/**
* Get database provider with transaction support validation
*
* @example
* ```typescript
* // Example usage for implementing transactions in actions:
* const providerResult = this.getTransactionProvider();
* if (providerResult.error) return providerResult.error;
* const provider = providerResult.provider!;
*
* // Begin transaction for multi-record operations
* await provider.BeginTransaction();
*
* try {
* // Perform multiple database operations
* const agent = await md.GetEntityObject<MJAIAgentEntity>('MJ: AI Agents', contextUser);
* await agent.Save();
*
* const prompt = await md.GetEntityObject<MJAIPromptEntity>('MJ: AI Prompts', contextUser);
* await prompt.Save();
*
* // Commit transaction - all operations succeeded
* await provider.CommitTransaction();
*
* return { Success: true, ResultCode: 'SUCCESS', Message: 'All operations completed successfully' };
*
* } catch (transactionError) {
* // Rollback transaction on any error
* await provider.RollbackTransaction();
* throw transactionError; // Re-throw to be caught by outer try-catch
* }
* ```
*/
protected getTransactionProvider(): {
provider?: DatabaseProviderBase;
error?: ActionResultSimple;
};
/**
* Load an AI Agent entity by ID. Pass the running action's `params` so the underlying
* entity load uses the per-request provider (multi-tenant correctness).
*/
protected loadAgent(agentID: string, contextUser: UserInfo, params?: RunActionParams): Promise<AgentLoadResult>;
/**
* Validate agent type exists. Pass the running action's `params` so the lookup uses
* the per-request provider (multi-tenant correctness).
*/
protected validateAgentType(typeID: string, contextUser: UserInfo, params?: RunActionParams): Promise<AgentTypeValidationResult>;
/**
* Common error handler
*/
protected handleError(error: unknown, operation: string): ActionResultSimple;
/**
* Creates a prompt and associates it with an agent. Pass the running action's `params`
* so the underlying entity creates bind to the per-request provider (multi-tenant
* correctness).
*/
protected createAndAssociatePrompt(agent: MJAIAgentEntityExtended, promptText: string, contextUser: UserInfo, params?: RunActionParams): Promise<PromptCreationResult>;
/**
* Gets the prompt type ID for a given type name. Pass the running action's `params`
* so the RunView binds to the per-request provider.
*/
private getPromptTypeID;
}
//# sourceMappingURL=base-agent-management.action.d.ts.map