Class BaseAIProvider

java.lang.Object
hudson.model.AbstractDescribableImpl<BaseAIProvider>
io.jenkins.plugins.explain_error.provider.BaseAIProvider
All Implemented Interfaces:
ExtensionPoint, Describable<BaseAIProvider>
Direct Known Subclasses:
AzureOpenAIProvider, ChatModelAIProvider, CustomOktaAIProvider, LangGraphProvider

public abstract class BaseAIProvider extends AbstractDescribableImpl<BaseAIProvider> implements ExtensionPoint
  • Field Details

  • Constructor Details

    • BaseAIProvider

      public BaseAIProvider(String url, String model)
  • Method Details

    • createAssistant

      public abstract BaseAIProvider.Assistant createAssistant(@CheckForNull Item item, @CheckForNull org.springframework.security.core.Authentication authentication, @CheckForNull Double temperature)
      The single assistant factory providers implement. It receives the full request context — credentials scope and temperature — so that a provider cannot accidentally drop a parameter by overriding the wrong overload (the narrower createAssistant variants are final and delegate here). Providers without item-scoped credentials simply ignore item/authentication.
      Parameters:
      item - the item defining the credentials scope, or null
      authentication - the authentication for credentials lookup, or null
      temperature - the temperature to use, or null for the provider default
      Returns:
      the assistant
    • createAssistant

      public final BaseAIProvider.Assistant createAssistant()
    • createFixAssistant

      public abstract FixAssistant createFixAssistant(@CheckForNull Item item, @CheckForNull org.springframework.security.core.Authentication authentication)
      The single fix-assistant factory providers implement; the no-arg createFixAssistant() is final and delegates here.
      Parameters:
      item - the item defining the credentials scope, or null
      authentication - the authentication for credentials lookup, or null
      Returns:
      the fix assistant
    • isNotValid

      public abstract boolean isNotValid(@CheckForNull TaskListener listener)
    • getUrl

      public String getUrl()
    • getModel

      public String getModel()
    • explainError

      public final String explainError(String errorLogs, TaskListener listener) throws ExplanationException
      Explain error logs using the configured AI provider.
      Parameters:
      errorLogs - the error logs to explain
      Returns:
      the AI explanation
      Throws:
      ExplanationException - if there's a communication error
    • explainError

      public final String explainError(String errorLogs, TaskListener listener, String language) throws ExplanationException
      Explain error logs using the configured AI provider.
      Parameters:
      errorLogs - the error logs to explain
      language - the preferred response language
      Returns:
      the AI explanation
      Throws:
      ExplanationException - if there's a communication error
    • explainError

      public final String explainError(String errorLogs, TaskListener listener, String language, String customContext) throws ExplanationException
      Explain error logs using the configured AI provider.
      Parameters:
      errorLogs - the error logs to explain
      listener - the task listener for logging
      language - the preferred response language
      customContext - additional custom context/instructions for the AI
      Returns:
      the AI explanation
      Throws:
      ExplanationException - if there's a communication error
    • explainError

      public final String explainError(String errorLogs, TaskListener listener, String language, String customContext, @CheckForNull Item item, @CheckForNull org.springframework.security.core.Authentication authentication) throws ExplanationException
      Explain error logs using the configured AI provider with item-scoped credentials context.
      Parameters:
      errorLogs - the error logs to explain
      listener - the task listener for logging
      language - the preferred response language
      customContext - additional custom context/instructions for the AI
      item - the item defining credentials scope
      authentication - the authentication used for credentials lookup
      Returns:
      the AI explanation
      Throws:
      ExplanationException - if there's a communication error
    • explainError

      public final String explainError(String errorLogs, TaskListener listener, String language, String customContext, @CheckForNull Item item, @CheckForNull org.springframework.security.core.Authentication authentication, @CheckForNull Double temperature) throws ExplanationException
      Explain error logs using the configured AI provider with item-scoped credentials context.
      Parameters:
      errorLogs - the error logs to explain
      listener - the task listener for logging
      language - the preferred response language
      customContext - additional custom context/instructions for the AI
      item - the item defining credentials scope
      authentication - the authentication used for credentials lookup
      temperature - the temperature to use, or null to let provider defaults apply
      Returns:
      the AI explanation
      Throws:
      ExplanationException - if there's a communication error
    • analyzeError

      @NonNull public final JenkinsLogAnalysis analyzeError(String errorLogs, TaskListener listener, String language, String customContext, @CheckForNull Item item, @CheckForNull org.springframework.security.core.Authentication authentication, @CheckForNull Double temperature) throws ExplanationException
      Analyze error logs using the configured AI provider and return the structured result. explainError(java.lang.String, hudson.model.TaskListener) renders the same analysis as plain text.
      Parameters:
      errorLogs - the error logs to explain
      listener - the task listener for logging
      language - the preferred response language
      customContext - additional custom context/instructions for the AI
      item - the item defining credentials scope
      authentication - the authentication used for credentials lookup
      temperature - the temperature to use, or null to let provider defaults apply
      Returns:
      the structured AI analysis
      Throws:
      ExplanationException - if there's a communication error
    • getDescriptor

      public BaseAIProvider.BaseProviderDescriptor getDescriptor()
      Specified by:
      getDescriptor in interface Describable<BaseAIProvider>
    • createAssistant

      public final BaseAIProvider.Assistant createAssistant(@CheckForNull Item item, @CheckForNull org.springframework.security.core.Authentication authentication)
    • createAssistant

      public final BaseAIProvider.Assistant createAssistant(@CheckForNull Double temperature)
      Create an assistant with a specific temperature setting.
      Parameters:
      temperature - the temperature value, or null to let provider defaults apply
      Returns:
      the assistant
    • createFixAssistant

      public final FixAssistant createFixAssistant()
    • isNotValid

      public boolean isNotValid(@CheckForNull TaskListener listener, @CheckForNull Item item, @CheckForNull org.springframework.security.core.Authentication authentication)
    • buildSystemPrompt

      protected final String buildSystemPrompt()
    • buildUserPrompt

      protected final String buildUserPrompt(String errorLogs, String language, String customContext)
    • newJenkinsHttpClientBuilder

      protected final HttpClient.Builder newJenkinsHttpClientBuilder()
    • getProxyAuthorizationHeader

      @CheckForNull protected final String getProxyAuthorizationHeader()
      Preemptive Proxy-Authorization header value for the Jenkins proxy, or null when no proxy credentials are configured.

      Sent as a user-set header instead of relying on a JDK Authenticator: with an Authenticator present, the JDK HttpClient drops user-set Authorization headers (JDK-8326949, fixed only in JDK 24), which silently removes the API key from AI requests on Jenkins instances with an authenticated proxy.

    • getEffectiveEndpointForDiagnostics

      @CheckForNull public String getEffectiveEndpointForDiagnostics()
      The endpoint URL this provider would call, used only to run connection diagnostics when a configuration test fails. Providers with a fixed or derivable default endpoint should override this to return it when no explicit URL is configured.
      Returns:
      the effective endpoint URL, or null when unknown
    • newLangChainHttpClientBuilder

      protected final dev.langchain4j.http.client.HttpClientBuilder newLangChainHttpClientBuilder()
    • getProviderName

      public String getProviderName()