Member Junction
    Preparing search index...

    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.

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

    Hierarchy (View Summary)

    Implements

    Index

    Constructors

    Properties

    Accessors

    Methods

    AddOrUpdateSingleExampleEmbedding AddOrUpdateSingleNoteEmbedding AgenteNoteTypeIDByName AgentSupportsAttachments AgentSupportsModality CacheResult CanUserDeleteAgent CanUserEditAgent CanUserRunAgent CanUserViewAgent CheckResultCache ClearAgentBaseCatalogCache ClearAgentPermissionsCache ClearEmbeddingCache composeExampleFilters composeNoteFilters Config EmbedContent EmbedText EmbedTextLocal EnsureLoaded ExecuteAIAction ExecuteEntityAIAction FindSimilarActions FindSimilarAgentExamples FindSimilarAgentNotes FindSimilarAgents GetAccessibleAgents GetActiveModelCost GetAgentBaseCatalog GetAgentByID GetAgentByName GetAgentConfigurationPresetByName GetAgentConfigurationPresets GetAgentModalitiesByDirection GetAgentStepByID GetAgentSteps GetAgentSupportedInputModalities GetAutoActivatableSkillsForAgent GetClientToolsForAgent GetConfigurationChain GetConfigurationParam GetConfigurationParams GetConfigurationParamsWithInheritance GetCredentialBindingsForTarget GetDefaultAgentConfigurationPreset getDriver GetGlobalObjectStore GetHighestPowerLLM GetHighestPowerModel GetModalityByName GetModelModalitiesByDirection GetPathsFromStep GetSkillActionIDs GetSkillsForAgent GetSkillSubAgentIDs GetStringOutputFromActionResults GetSubAgents GetUserAgentPermissions HandleStartup HasCredentialBindings IsInferenceProvider markupUserMessage ModelSupportsModality packageExampleMetadata packageNoteMetadata ParallelLLMCompletions PrepareChatMessages PrepareLLMInstance RefreshActionEmbeddings RefreshActions RefreshAgentEmbeddings RefreshAgentPermissionsCache RefreshExampleEmbeddings RefreshNoteEmbeddings RefreshServerSpecificMetadata RegenerateEmbeddings RemoveSingleExampleEmbedding RemoveSingleNoteEmbedding SetAgentBaseCatalog SimpleLLMCompletion getInstance

    Constructors

    Properties

    EmbeddingModelTypeName: string = 'Embeddings'
    LocalEmbeddingModelVendorName: string = 'LocalEmbeddings'

    Accessors

    • get GlobalKey(): string

      Returns string

    • get Loaded(): boolean

      Returns true if both the base engine and server capabilities are loaded

      Returns boolean

    • get SystemActions(): MJActionEntity[]

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

      Returns MJActionEntity[]

    Methods

    • Parameters

      • agentNoteTypeName: string

      Returns string

    • Parameters

      • agentId: string
      • modalityName: string
      • direction: "Input" | "Output"

      Returns boolean

    • Wipes the entire agent base-catalog cache. Called on relevant entity changes and on reload.

      Returns void

    • Compose base scope filters (agentId/userId/companyId) with an optional additional filter into a single filter callback for use with FindNearest on examples.

      Mirrors composeNoteFilters: Status filtering is NOT performed here. The vector store is kept in sync with persisted Status by MJAIAgentExampleEntityServer.Save() / Delete(), which call AddOrUpdateSingleExampleEmbedding / RemoveSingleExampleEmbedding based on the example's current Status.

      Parameters

      • OptionalagentId: string
      • OptionaluserId: string
      • OptionalcompanyId: string
      • OptionaladditionalFilter: (metadata: ExampleEmbeddingMetadata) => boolean

      Returns (metadata: ExampleEmbeddingMetadata) => boolean

    • Compose base scope filters (agentId/userId/companyId) with an optional additional filter into a single filter callback for use with FindNearest.

      Status filtering is NOT performed here. The invariant the retrieval path relies on is: _noteVectorService contains an entry for a note iff its persisted Status is 'Active'. That invariant is maintained write-side by MJAIAgentNoteEntityServer.Save(), which calls AddOrUpdateSingleNoteEmbedding on Active saves and RemoveSingleNoteEmbedding on non-Active saves. Deletes are handled by the same subclass's Delete() override.

      This avoids a subtle bug the earlier Status-check-at-retrieval approach had: BaseAIEngine overrides AdditionalLoading(), which disables BaseEngine's immediate-mutation path for _agentNotes. Newly-created notes don't appear in this.AgentNotes until the next Config(true) — so any retrieval-time lookup against that cache returned undefined for post-startup notes and rejected everything.

      Parameters

      • OptionalagentId: string
      • OptionaluserId: string
      • OptionalcompanyId: string
      • OptionaladditionalFilter: (metadata: NoteEmbeddingMetadata) => boolean

      Returns (metadata: NoteEmbeddingMetadata) => 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

      • OptionalforceRefresh: boolean

        If true, forces a full reload even if already loaded

      • OptionalcontextUser: UserInfo

        User context for server-side operations (required)

      • Optionalprovider: IMetadataProvider

        Optional metadata provider override

      Returns Promise<void>

    • Generates a single embedding vector from multimodal content (text and/or interleaved image/audio/video/document blocks) using the given model's embedding provider.

      This is the multimodal counterpart to EmbedText. Text-only content is routed through EmbedText so it reuses that method's caching, in-flight dedup, and empty-text guard. Actual media content takes the uncached provider path — multimodal payloads carry large base64 media that make a text-style cache key impractical and rarely repeat; providers that can't embed the media reject it.

      Parameters

      • model: MJAIModelEntityExtended

        the embedding model to use (provides DriverClass + APIName)

      • content: ChatMessageContent

        text, or interleaved text+media blocks, to embed into one fused vector

      • OptionalapiKey: string

        optional API key override

      Returns Promise<EmbedTextResult>

      the embedding result, or null if the provider instance couldn't be created

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

      Includes an LRU cache (see _embeddingCache) that dedupes concurrent calls for the same (model, text) pair — the in-flight Promise is shared until it settles.

      Parameters

      • model: MJAIModelEntityExtended
      • text: string
      • OptionalapiKey: string
      • Optionaloptions: { bypassCache?: boolean; noCache?: boolean }
        • OptionalbypassCache?: boolean

          when true, skips the cache read but still populates it on success

        • OptionalnoCache?: boolean

          when true, neither reads nor writes the cache (also forfeits promise dedup — a noCache caller always re-infers, even if an equivalent inference is already in flight)

          Empty/whitespace text short-circuits to null without invoking the embedding provider.

      Returns Promise<EmbedTextResult>

    • Ensures AIEngine is fully loaded (both base metadata and server-specific capabilities like vector services) before the caller reads engine state. Idempotent: if already loaded, returns immediately. If a load is in flight (e.g. the deferred startup or another consumer triggered it), returns the same in-progress promise.

      Mirrors BaseEngine.EnsureLoaded — added here because AIEngine extends BaseSingleton (not BaseEngine) and has its own load orchestration to cover server-specific setup (RefreshServerSpecificMetadata).

      Use at any consumption point that touches AIEngine state, especially given AIEngineBase is registered as deferred at startup.

      Parameters

      Returns Promise<void>

    • Find actions similar to a task description using semantic search.

      Parameters

      • taskDescription: string
      • topK: number = 10
      • minSimilarity: number = 0.5

      Returns Promise<ActionMatchResult[]>

    • Find examples similar to query text using semantic search. Falls back to returning examples from cache if vector service is unavailable.

      Parameters

      • queryText: string
      • OptionalagentId: string
      • OptionaluserId: string
      • OptionalcompanyId: string
      • topK: number = 3
      • minSimilarity: number = 0.5
      • OptionaladditionalFilter: (metadata: ExampleEmbeddingMetadata) => boolean

      Returns Promise<ExampleMatchResult[]>

    • Find notes similar to query text using semantic search. Falls back to returning notes from cache if vector service is unavailable.

      Parameters

      • queryText: string
      • OptionalagentId: string
      • OptionaluserId: string
      • OptionalcompanyId: string
      • topK: number = 5
      • minSimilarity: number = 0.5
      • OptionaladditionalFilter: (metadata: NoteEmbeddingMetadata) => boolean

      Returns Promise<NoteMatchResult[]>

    • Find agents similar to a task description using semantic search.

      Parameters

      • taskDescription: string
      • topK: number = 5
      • minSimilarity: number = 0.5

      Returns Promise<AgentMatchResult[]>

    • Returns the cached base catalog for an agent, or undefined if not yet built / invalidated. The shape is defined and typed by the caller (BaseAgent) — pass the concrete type as T.

      Type Parameters

      • T extends object

      Parameters

      • agentID: string

      Returns T

    • 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 MJAIConfigurationEntity[]

      Array of MJAIConfigurationEntity objects representing the inheritance chain

      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 MJAIConfigurationParamEntity[]

      Array of MJAIConfigurationParamEntity 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 GlobalObjectStore

    • Parameters

      • agentID: string
      • Optionalstatus: "Active" | "Disabled" | "Pending"
      • OptionalrelationshipStatus: "Active" | "Pending" | "Revoked"

      Returns MJAIAgentEntityExtended[]

    • Executes the background startup sequence. This method is called automatically by the StartupManager. It runs AIEngine configuration and pre-warms the local embedding models and vector caches.

      Parameters

      • OptionalcontextUser: UserInfo

        The authenticated user context (system/boot user context)

      • Optionalprovider: IMetadataProvider

        Optional metadata provider override

      Returns Promise<void>

    • Parameters

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

      Returns boolean

    • Parameters

      • modelId: string
      • modalityName: string
      • direction: "Input" | "Output"

      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

      • OptionalsystemPrompt: 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)

      • Optionalmodel: MJAIModelEntityExtended

        Optional specific model to use, otherwise uses highest power LLM

      • OptionalapiKey: string

        Optional API key to use with the model

      • Optionalcallbacks: 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

      • OptionalsystemPrompt: 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

      • Optionalmodel: MJAIModelEntityExtended

        Optional specific model to use, otherwise uses highest power LLM

      • OptionalapiKey: string

        Optional API key to use with the model

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

      Object containing the prepared model instance and model information

    • Dynamically calculation of embeddings for all Active actions. Assumes that the internal Actions array is up to date, call

      Returns Promise<void>

      RefreshActions first if you do not think they are already.

      This operation dynamically calculates embeddings from the text in the Action metadata and is an expensive operation, use it sparingly.

    • Loads Active actions from the base engine (contained within this class). Does not refresh from the database, simply pulls the latest Active actions from the base class into its server side only array.

      Parameters

      Returns Promise<void>

    • Refreshes Agent embeddings - agents are pre-loaded at this point, but we need to generate, dynamically, embeddings from the text stored in the agent. This is not a cheap operation, use it sparingly.

      Returns Promise<void>

    • Refresh the vector service with the latest persisted vectors that are stored in the Agent Examples table. This does not calculate embeddings, that is done by the AI Agent Example sub-class upon save as needed. This method simply uses the stored vectors and parses them from their JSON serialized format into vectors that are used by the vector service.

      Parameters

      Returns Promise<void>

    • Refresh the vector service with the latest persisted vectors that are stored in the Agent Notes table. This does not calculate embeddings, that is done by the AI Agent Note sub-class upon save as needed. This method simply uses the stored vectors and parses them from their JSON serialized format into vectors that are used by the vector service.

      Parameters

      Returns Promise<void>

    • Refreshes the server metadata including active actions. Refreshes the embeddings in the engine's vector service for

      • Agents (dynamic recalc of embeddings)
      • Actions (dynamic recalc of embeddings)
      • Notes (parsed from DB)
      • Examples (parsed from DB)

      If you only need to refresh specific elements noted above, call the individual methods:

      • RefreshActions (refreshes just the server side action metadata - e.g. 'Active' Actions)
      • RefreshActionEmbeddings (dynamic recalc of embedings from stored data)
      • RefreshAgentEmbeddings (dynamic recalc of embeddings from stored data)
      • RefreshNoteEmbeddings
      • RefreshExampleEmbeddings

      Parameters

      Returns Promise<void>

    • 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

      • OptionalcontextUser: UserInfo

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

      Returns Promise<void>

    • Drops an example from the in-memory vector service. Called by the server-side entity subclass when an example is saved with a non-Active Status or is deleted, so subsequent FindSimilarAgentExamples calls cannot return it. Silently no-ops if the vector service isn't initialized yet (e.g., during early startup before Config has run).

      Parameters

      • exampleId: string

      Returns void

    • Drops a note from the in-memory vector service. Called by the server-side entity subclass when a note is saved with a non-Active Status or is deleted, so subsequent FindSimilarAgentNotes calls cannot return it. Silently no-ops if the vector service isn't initialized yet (e.g., during early startup before Config has run).

      Parameters

      • noteId: string

      Returns void

    • Stores the base catalog for an agent (built once, reused across runs until invalidated).

      Parameters

      • agentID: string
      • catalog: object

      Returns 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

      • OptionalsystemPrompt: string

        Optional system prompt to set context/persona for the model

      • Optionalmodel: MJAIModelEntityExtended

        Optional specific model to use, otherwise uses highest power LLM

      • OptionalapiKey: string

        Optional API key to use with the model

      Returns Promise<string>

      The text response from the LLM

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

    • 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
      • OptionalclassName: string

      Returns T