Package com.vaadin.copilot
Class CopilotServerClient
java.lang.Object
com.vaadin.copilot.CopilotServerClient
- Direct Known Subclasses:
AnalyticsClient,FeedbackClient,TestGenerationServerClient,UserInfoServerClient
Base class for Copilot Server API clients
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic final recordstatic enum -
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionbuildRequest(URI uri, Object request) static BooleanReturns the Copilot server reachability state.getQueryURI(String path) protected static Stringprotected static voidprotected static voidRecords a failed request unless the server has already been reached in this application run.static StringreportRequestFailure(org.slf4j.Logger logger, String context, Throwable error) Logs a failed Copilot server request and returns a user-facing error message.Resolves which AI provider region should be used, based on the current user's project settings.<REQ,RESP>
voidsendCopilotRequest(String path, REQ request, Class<RESP> responseType, Consumer<RESP> responseHandler, com.vaadin.base.devserver.DevToolsInterface devToolsInterface, String command, tools.jackson.databind.JsonNode respData) <REQ,RESP>
voidsendCopilotRequest(String path, REQ request, Class<RESP> responseType, Consumer<RESP> responseHandler, Consumer<Throwable> errorHandler) voidsendFireAndForget(String path, Object request) Sends a best-effort, fire-and-forget POST request to the Copilot server.sendStreamingRequest(URI uri, Object request, Duration idleTimeout, Consumer<String> lineHandler, Consumer<Throwable> errorHandler, Runnable completionHandler) Sends a POST request to the Copilot server and streams the response body to the given handler, one line at a time, as it arrives.
-
Field Details
-
SERVER_URL_ENV
- See Also:
-
-
Constructor Details
-
CopilotServerClient
public CopilotServerClient()Constructor initializing HttpClient and ObjectMapper
-
-
Method Details
-
getHttpClient
-
buildRequest
-
getQueryURI
-
getServerBaseUrl
-
sendCopilotRequest
-
reportRequestFailure
Logs a failed Copilot server request and returns a user-facing error message. A proxy authentication failure is logged atWARNwith a clear explanation and returned as-is; any other error is logged atERRORwith its stack trace and yields a generic message. Centralizes failure reporting so every (synchronous) caller behaves consistently.- Parameters:
logger- the caller's loggercontext- a short description of what failed, used for the error-level logerror- the error that was thrown- Returns:
- a message suitable for showing to the user
-
sendCopilotRequest
-
sendFireAndForget
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
HttpClientand swallows request failures so best-effort traffic stays isolated.- Parameters:
path- server path to POST torequest- payload serialized to JSON
-
sendStreamingRequest
public Runnable sendStreamingRequest(URI uri, Object request, Duration idleTimeout, Consumer<String> lineHandler, Consumer<Throwable> errorHandler, Runnable completionHandler) Sends a POST request to the Copilot server and streams the response body to the given handler, one line at a time, as it arrives.Exactly one of
errorHandlerandcompletionHandleris called, unless the request is cancelled through the returned handle, after which no handler is called anymore. The request fails with anHttpTimeoutExceptionwhen no response, or no further data, is received withinidleTimeout, and with aCopilotServerResponseExceptionwhen the server, or a proxy on the way, answers with a status other than 200.- Parameters:
uri- the URI to POST torequest- payload serialized to JSONidleTimeout- the maximum time to wait for the response and for each further piece of the response bodylineHandler- receives each line of the response bodyerrorHandler- called if the request or reading the response failscompletionHandler- called when the whole response body has been read- Returns:
- a handle that cancels the request when run
-
getCopilotServerReachability
Returns the Copilot server reachability state.nullmeans no request has been attempted,falsemeans an attempt failed, andtruemeans 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
Resolves which AI provider region should be used, based on the current user's project settings.
-