Server-side AI Engine that wraps AIEngineBase and adds server-only capabilities.

This class uses composition (containment) rather than inheritance to avoid duplicate data loading. It delegates all base functionality to AIEngineBase.Instance while adding server-specific features like embeddings, vector search, and LLM execution.

Description

ONLY USE ON SERVER-SIDE. For metadata only, use the AIEngineBase class which can be used anywhere.

Hierarchy (view full)

Constructors

Properties

Accessors

Methods

Constructors

Properties

EmbeddingModelTypeName: string = 'Embeddings'
LocalEmbeddingModelVendorName: string = 'LocalEmbeddings'
_actionEmbeddingsCache: Map<string, boolean> = ...
_actionVectorService: SimpleVectorService<ActionEmbeddingMetadata> = null
_actions: ActionEntity[] = []
_agentEmbeddingsCache: Map<string, boolean> = ...
_agentVectorService: SimpleVectorService<AgentEmbeddingMetadata> = null
_contextUser: UserInfo
_embeddingsGenerated: boolean = false
_exampleVectorService: SimpleVectorService<ExampleEmbeddingMetadata> = null
_loaded: boolean = false
_loading: boolean = false
_loadingPromise: Promise<void> = null
_noteVectorService: SimpleVectorService<NoteEmbeddingMetadata> = null

Accessors

  • get GlobalKey(): string
  • Returns string

  • get HighestPowerLocalEmbeddingModel(): AIModelEntityExtended
  • Returns the highest power local embedding model

    Returns AIModelEntityExtended

  • get Loaded(): boolean
  • Returns true if both the base engine and server capabilities are loaded

    Returns boolean

  • get LocalEmbeddingModels(): AIModelEntityExtended[]
  • Returns an array of the local embedding models, sorted with the highest power models first

    Returns AIModelEntityExtended[]

  • get LowestPowerLocalEmbeddingModel(): AIModelEntityExtended
  • Returns the lowest power local embedding model

    Returns AIModelEntityExtended

  • get SystemActions(): ActionEntity[]
  • Get all available actions loaded from the database. Loaded during Config() - will be empty before AIEngine.Config() completes. NOTE: This returns ActionEntity (MJ Action system), not the deprecated AIActionEntity. For deprecated AI Actions, see the inherited Actions property.

    Returns ActionEntity[]

Methods

  • Parameters

    • model: AIModelEntityExtended
    • prompt: AIPromptEntityExtended
    • promptText: string
    • resultText: string

    Returns Promise<boolean>

  • Configures the AIEngine by first ensuring AIEngineBase is configured, then loading server-specific capabilities (embeddings, actions, etc.).

    This method is safe to call from multiple places concurrently - it will return the same promise to all callers during loading.

    Parameters

    • Optional forceRefresh: boolean

      If true, forces a full reload even if already loaded

    • Optional contextUser: UserInfo

      User context for server-side operations (required)

    • Optional provider: IMetadataProvider

      Optional metadata provider override

    Returns Promise<void>

  • Helper method to instantiate a class instance for the given model and calculate an embedding vector from the provided text.

    Parameters

    • model: AIModelEntityExtended
    • text: string
    • Optional apiKey: string

    Returns Promise<EmbedTextResult>

  • Helper method that generates an embedding for the given text using the highest power local embedding model.

    Parameters

    • text: string

    Returns Promise<{
        model: AIModelEntityExtended;
        result: EmbedTextResult;
    }>

  • Find examples similar to query text using semantic search.

    Parameters

    • queryText: string
    • Optional agentId: string
    • Optional userId: string
    • Optional companyId: string
    • topK: number = 3
    • minSimilarity: number = 0.5

    Returns Promise<ExampleMatchResult[]>

  • Find notes similar to query text using semantic search.

    Parameters

    • queryText: string
    • Optional agentId: string
    • Optional userId: string
    • Optional companyId: string
    • topK: number = 5
    • minSimilarity: number = 0.5

    Returns Promise<NoteMatchResult[]>

  • Parameters

    • user: UserInfo
    • permission: "view" | "run" | "edit" | "delete"

    Returns Promise<AIAgentEntityExtended[]>

  • Returns the inheritance chain for a configuration, starting with the specified configuration and walking up through parent configurations to the root. Delegates to AIEngineBase.GetConfigurationChain.

    Parameters

    • configurationId: string

      The ID of the configuration to get the chain for

    Returns AIConfigurationEntity[]

    Array of AIConfigurationEntity objects representing the inheritance chain

    Throws

    Error if a circular reference is detected in the configuration hierarchy

  • Returns all configuration parameters for a configuration, including inherited parameters from parent configurations. Child parameters override parent parameters. Delegates to AIEngineBase.GetConfigurationParamsWithInheritance.

    Parameters

    • configurationId: string

      The ID of the configuration to get parameters for

    Returns AIConfigurationParamEntity[]

    Array of AIConfigurationParamEntity objects, with child overrides applied

  • The Global Object Store is a place to store global objects that need to be shared across the application. Depending on the execution environment, this could be the window object in a browser, or the global object in a node environment, or something else in other contexts. The key here is that in some cases static variables are not truly shared because it is possible that a given class might have copies of its code in multiple paths in a deployed application. This approach ensures that no matter how many code copies might exist, there is only one instance of the object in question by using the Global Object Store.

    Returns typeof globalThis

  • Parameters

    • Optional vendorName: string
    • Optional contextUser: UserInfo

    Returns Promise<AIModelEntityExtended>

  • Parameters

    • vendorName: string
    • modelType: string
    • Optional contextUser: UserInfo

    Returns Promise<AIModelEntityExtended>

  • Parameters

    • agentID: string
    • Optional status: "Active" | "Disabled" | "Pending"
    • Optional relationshipStatus: "Active" | "Pending" | "Revoked"

    Returns AIAgentEntityExtended[]

  • Parameters

    Returns Promise<EffectiveAgentPermissions>

  • Parameters

    • bindingType: "Vendor" | "ModelVendor" | "PromptModel"
    • targetId: string

    Returns boolean

  • Executes multiple parallel chat completions with the same model but potentially different parameters.

    Parameters

    • userPrompt: string

      The user's message/question to send to the model

    • contextUser: UserInfo

      The user context for authentication and logging

    • Optional systemPrompt: string

      Optional system prompt to set the context/persona

    • iterations: number = 3

      Number of parallel completions to run (default: 3)

    • temperatureIncrement: number = 0.1

      The amount to increment temperature for each iteration (default: 0.1)

    • baseTemperature: number = 0.7

      The starting temperature value (default: 0.7)

    • Optional model: AIModelEntityExtended

      Optional specific model to use, otherwise uses highest power LLM

    • Optional apiKey: string

      Optional API key to use with the model

    • Optional callbacks: ParallelChatCompletionsCallbacks

      Optional callbacks for monitoring progress

    Returns Promise<ChatResult[]>

    Array of ChatResult objects, one for each parallel completion

  • Prepares standard chat parameters with system and user messages.

    Parameters

    • userPrompt: string

      The user message/query to send to the model

    • Optional systemPrompt: string

      Optional system prompt to set context/persona for the model

    Returns ChatMessage[]

    Array of properly formatted chat messages

  • Prepares an LLM model instance with the appropriate parameters. This method handles common tasks needed before calling an LLM:

    • Loading AI metadata if needed
    • Selecting the appropriate model (user-provided or highest power)
    • Getting the correct API key
    • Creating the LLM instance

    Parameters

    • contextUser: UserInfo

      The user context for authentication and permissions

    • Optional model: AIModelEntityExtended

      Optional specific model to use, otherwise uses highest power LLM

    • Optional apiKey: string

      Optional API key to use with the model

    Returns Promise<{
        modelInstance: BaseLLM;
        modelToUse: AIModelEntityExtended;
    }>

    Object containing the prepared model instance and model information

  • Force regeneration of all embeddings for agents and actions.

    Use this method when:

    • Switching to a different embedding model
    • Agent or Action descriptions have been significantly updated
    • You want to ensure embeddings are up-to-date after bulk changes
    • Troubleshooting embedding-related issues

    Note: This is an expensive operation and should not be called frequently. Normal auto-refresh operations will NOT regenerate embeddings to avoid performance issues.

    Parameters

    • Optional contextUser: UserInfo

      User context for database operations (required on server-side)

    Returns Promise<void>

  • Executes a simple completion task using the provided parameters.

    Parameters

    • userPrompt: string

      The user message/query to send to the model

    • contextUser: UserInfo

      The user context for authentication and permissions

    • Optional systemPrompt: string

      Optional system prompt to set context/persona for the model

    • Optional model: AIModelEntityExtended

      Optional specific model to use, otherwise uses highest power LLM

    • Optional apiKey: string

      Optional API key to use with the model

    Returns Promise<string>

    The text response from the LLM

    Throws

    Error if user prompt is not provided or if there are issues with model creation

  • Private

    Generate embedding for a single action and add it to the vector service. Used for incremental updates when new actions are created.

    Parameters

    Returns Promise<void>

  • Private

    Generate embedding for a single agent and add it to the vector service. Used for incremental updates when new agents are created.

    Parameters

    • agent: AIAgentEntityExtended

      The agent to generate embeddings for

    Returns Promise<void>

  • Internal loading logic - separated for clean promise management

    Parameters

    Returns Promise<void>

  • Private

    Load embeddings for all actions. Uses actions loaded in loadActions() - no additional database round trip needed. Only generates embeddings for actions that don't already have them cached.

    Returns Promise<void>

  • Private

    Load Actions from database. Called during Config to populate the Actions list.

    Parameters

    Returns Promise<void>

  • Private

    Load embeddings for all agents. Uses agents already loaded by AIEngineBase - no database round trip needed. Only generates embeddings for agents that don't already have them cached.

    Returns Promise<void>

  • Private

    Load example embeddings from database and build vector service. Only loads active examples with embeddings already generated.

    Parameters

    Returns Promise<void>

  • Private

    Load note embeddings from database and build vector service. Only loads active notes with embeddings already generated.

    Parameters

    Returns Promise<void>

  • Load server-specific capabilities: actions and embeddings

    Parameters

    Returns Promise<void>

  • Returns the singleton instance of the class. If the instance does not exist, it is created and stored in the Global Object Store. If className is provided it will be used as part of the key in the Global Object Store, otherwise the actual class name will be used. NOTE: the class name used by default is the lowest level of the object hierarchy, so if you have a class that extends another class, the lowest level class name will be used.

    Type Parameters

    Parameters

    • this: (new () => T)
        • new (): T
        • Returns T

    • Optional className: string

    Returns T