Class UserInfoServerClient

java.lang.Object
com.vaadin.copilot.CopilotServerClient
com.vaadin.copilot.userinfo.UserInfoServerClient

public class UserInfoServerClient extends CopilotServerClient
  • Constructor Details

    • UserInfoServerClient

      public UserInfoServerClient()
  • Method Details

    • getUserInfoWithLocalProKey

      public static UserInfo 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 an AIUsageDisabledException if usage is not permitted.

      This method validates the following conditions in order:

      • If there is no UserInfo available and the preview is inactive (as returned by PreviewHandler.getLatestPreview().active()), usage is not allowed.
      • If the UserInfo indicates that the project must not leave localhost (via userInfo.copilotProjectCannotLeaveLocalhost()), usage is not allowed.
      • If the machine configuration explicitly disallows AI usage (via MachineConfiguration.get().isAIUsageAllowed() returning AIUsageAllowed.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