Package com.vaadin.copilot.userinfo
Class UserInfoServerClient
java.lang.Object
com.vaadin.copilot.CopilotServerClient
com.vaadin.copilot.userinfo.UserInfoServerClient
-
Nested Class Summary
Nested classes/interfaces inherited from class com.vaadin.copilot.CopilotServerClient
CopilotServerClient.AccessControlData, CopilotServerClient.AIProvider -
Field Summary
Fields inherited from class com.vaadin.copilot.CopilotServerClient
SERVER_URL_ENV -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic UserInfoRequests to Copilot Server to get user information with local pro key if presentstatic voidChecks whether AI usage is allowed based on various runtime conditions, and throws anAIUsageDisabledExceptionif usage is not permitted.Methods inherited from class com.vaadin.copilot.CopilotServerClient
buildRequest, getHttpClient, getQueryURI, getServerBaseUrl, sendCopilotRequest, sendCopilotRequest, sendReactive
-
Constructor Details
-
UserInfoServerClient
public UserInfoServerClient()
-
-
Method Details
-
getUserInfoWithLocalProKey
Requests to Copilot Server to get user information with local pro key if present- Returns:
- Returns null when pro key not exist or when request is not succeeded.
-
throwIfAIUsageDisabled
public static void throwIfAIUsageDisabled()Checks whether AI usage is allowed based on various runtime conditions, and throws anAIUsageDisabledExceptionif usage is not permitted.This method validates the following conditions in order:
- If there is no
UserInfoavailable and the preview is inactive (as returned byPreviewHandler.getLatestPreview().active()), usage is not allowed. - If the
UserInfoindicates that the project must not leave localhost (viauserInfo.copilotProjectCannotLeaveLocalhost()), usage is not allowed. - If the machine configuration explicitly disallows AI usage (via
MachineConfiguration.get().isAIUsageAllowed()returningAIUsageAllowed.NO), usage is not allowed.
If none of the above conditions block access, then we assume AI usage is allowed. In the case of
AIUsageAllowed.ASK, it is assumed the user has confirmed usage via a client-side popup.- Throws:
AIUsageDisabledException- if any of the above conditions disallow AI usage
- If there is no
-