Class CopilotServerClient

java.lang.Object
com.vaadin.copilot.CopilotServerClient
Direct Known Subclasses:
AnalyticsClient, FeedbackClient, TestGenerationServerClient, UserInfoServerClient

public class CopilotServerClient extends Object
Base class for Copilot Server API clients
  • Field Details

  • Constructor Details

    • CopilotServerClient

      public CopilotServerClient()
      Constructor initializing HttpClient and ObjectMapper
  • Method Details

    • getHttpClient

      public HttpClient getHttpClient()
    • buildRequest

      public HttpRequest buildRequest(URI uri, Object request)
    • getQueryURI

      public URI getQueryURI(String path)
    • getServerBaseUrl

      protected static String getServerBaseUrl()
    • sendCopilotRequest

      public <REQ, RESP> void sendCopilotRequest(String path, REQ request, Class<RESP> responseType, Consumer<RESP> responseHandler, com.vaadin.base.devserver.DevToolsInterface devToolsInterface, String command, tools.jackson.databind.JsonNode respData)
    • reportRequestFailure

      public static String reportRequestFailure(org.slf4j.Logger logger, String context, Throwable error)
      Logs a failed Copilot server request and returns a user-facing error message. A proxy authentication failure is logged at WARN with a clear explanation and returned as-is; any other error is logged at ERROR with its stack trace and yields a generic message. Centralizes failure reporting so every (synchronous) caller behaves consistently.
      Parameters:
      logger - the caller's logger
      context - a short description of what failed, used for the error-level log
      error - the error that was thrown
      Returns:
      a message suitable for showing to the user
    • sendCopilotRequest

      public <REQ, RESP> void sendCopilotRequest(String path, REQ request, Class<RESP> responseType, Consumer<RESP> responseHandler, Consumer<Throwable> errorHandler)
    • sendFireAndForget

      public void sendFireAndForget(String path, Object request)
      Sends a best-effort, fire-and-forget POST request to the Copilot server.

      The caller never observes the result, and a failure must never affect the calling thread. It reuses the shared HttpClient (rather than a reactor-netty client, whose eager HTTP/3 SSL init can fail with a LinkageError on hosts that pin a conflicting Netty version) and swallows request failures so best-effort traffic stays isolated.

      Parameters:
      path - server path to POST to
      request - payload serialized to JSON
    • getCopilotServerReachability

      public static Boolean getCopilotServerReachability()
      Returns the Copilot server reachability state. null means no request has been attempted, false means an attempt failed, and true means a response was received.
    • markCopilotServerReached

      protected static void markCopilotServerReached()
    • markCopilotServerUnreachable

      protected static void markCopilotServerUnreachable()
      Records a failed request unless the server has already been reached in this application run.
    • resolveAiProvider

      public static CopilotServerClient.AIProvider resolveAiProvider()