Class LibrarySupportLogic

java.lang.Object
sk.iway.iwcm.components.ai.providers.LibrarySupportLogic
All Implemented Interfaces:
AiInterface
Direct Known Subclasses:
GeminiService, LocalEmbeddingService, LocalTextService, LocalTranslateService, OpenAiService, OpenRouterService

public abstract class LibrarySupportLogic extends Object implements AiInterface
CMS adapter around the framework-neutral webjet-ai client.

CMS-side provider integrations should extend this class.

  • Constructor Details

    • LibrarySupportLogic

      protected LibrarySupportLogic(com.webjetcms.ai.AiClient aiClient, WebjetAiConfigurationService configurationService)
    • LibrarySupportLogic

      protected LibrarySupportLogic(com.webjetcms.ai.AiClient aiClient, WebjetAiConfigurationService configurationService, LibrarySupportLogic.LiteralTranslationOptionsResolver literalTranslationOptionsResolver)
      Creates a CMS provider adapter with optional literal-translation support. The resolver may supply translation options only. Request construction and all security invariants remain owned by this class.
      Parameters:
      aiClient - client used to execute provider requests
      configurationService - service used to resolve provider configuration
      literalTranslationOptionsResolver - resolver for literal translation options, or null for the standard protected-prompt request pipeline
  • Method Details

    • isInit

      public boolean isInit()
      Specified by:
      isInit in interface AiInterface
    • getSupportedModels

      public List<LabelValue> getSupportedModels(Prop prop, jakarta.servlet.http.HttpServletRequest request)
      Lists models available from the configured provider for the current request. Provider failures are recorded in the audit log and produce an empty result.
      Specified by:
      getSupportedModels in interface AiInterface
      Parameters:
      prop - translations used to format provider errors
      request - request used to resolve provider configuration
      Returns:
      provider models represented as label-value options
    • getAiResponse

      public AssistantResponseDTO getAiResponse(AssistantDefinitionEntity assistant, InputDataDTO inputData, Prop prop, AiStatRepository statRepo, jakarta.servlet.http.HttpServletRequest request) throws ProviderCallException
      Executes a text request, restores protected INCLUDE commands, and records usage and audit data.
      Specified by:
      getAiResponse in interface AiInterface
      Parameters:
      assistant - assistant configuration used for the request
      inputData - input text, user prompt, and related request data
      prop - translations used to format provider errors
      statRepo - repository used to record token statistics
      request - request used to resolve provider configuration and statistics context
      Returns:
      response DTO containing the generated text and token usage
      Throws:
      ProviderCallException - if request preparation, provider execution, or response processing fails
    • getAiStreamResponse

      public AssistantResponseDTO getAiStreamResponse(AssistantDefinitionEntity assistant, InputDataDTO inputData, Prop prop, AiStatRepository statRepo, BufferedWriter writer, jakarta.servlet.http.HttpServletRequest request) throws ProviderCallException
      Streams a text request while restoring protected INCLUDE commands and records usage and audit data.
      Specified by:
      getAiStreamResponse in interface AiInterface
      Parameters:
      assistant - assistant configuration used for the request
      inputData - input text, user prompt, and related request data
      prop - translations used to format provider errors
      statRepo - repository used to record token statistics
      writer - destination for streamed response content
      request - request used to resolve provider configuration and statistics context
      Returns:
      response DTO containing the complete streamed text and token usage
      Throws:
      ProviderCallException - if request preparation, provider execution, streaming, or response processing fails
    • getAiImageResponse

      public AssistantResponseDTO getAiImageResponse(AssistantDefinitionEntity assistant, InputDataDTO inputData, Prop prop, AiStatRepository statRepo, jakarta.servlet.http.HttpServletRequest request) throws ProviderCallException
      Executes an image generation or editing request and stores returned images in temporary storage.
      Specified by:
      getAiImageResponse in interface AiInterface
      Parameters:
      assistant - assistant configuration used for the request
      inputData - image prompt, source image, and requested image options
      prop - translations used to format provider errors
      statRepo - repository used to record token statistics
      request - request used to resolve provider configuration and statistics context
      Returns:
      response DTO containing temporary image files, a generated filename, and token usage
      Throws:
      ProviderCallException - if request preparation, provider execution, or image processing fails
    • configurationService

      protected final WebjetAiConfigurationService configurationService()
    • getBonusHtml

      public String getBonusHtml(AssistantDefinitionEntity assistant, Prop prop)
      Builds provider-supported image option controls for the assistant UI.
      Specified by:
      getBonusHtml in interface AiInterface
      Parameters:
      assistant - assistant whose operation and model define the available controls
      prop - translations used for control labels
      Returns:
      HTML controls, or an empty string when the assistant has no supported image options
    • validatePromptExpansion

      protected void validatePromptExpansion(com.webjetcms.ai.AiPromptTemplate.ExpansionResult expansion, Long assistantId) throws IOException
      Validates content expanded into trusted prompt instructions before a request is built. The default implementation accepts every expansion. Providers may override this hook to reject suspicious expanded sources.
      Parameters:
      expansion - expanded prompt and its source classifications
      assistantId - assistant identifier used when auditing validation failures
      Throws:
      IOException - if a provider-specific validation rejects the expansion