Skip to content

Commit

Permalink
Support for suppressible Chat license acknowledgement
Browse files Browse the repository at this point in the history
  • Loading branch information
breedloj committed Jan 9, 2025
1 parent 7d0945c commit b61f313
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,5 +25,5 @@ private LspConstants() {
public static final String LSP_SUBDIRECTORY = "lsp";
public static final String AMAZONQ_LSP_SUBDIRECTORY = Paths.get(LSP_SUBDIRECTORY, "AmazonQ").toString();

public static final VersionRange LSP_SUPPORTED_VERSION_RANGE = new VersionRange("[2.3.0, 2.3.10)");
public static final VersionRange LSP_SUPPORTED_VERSION_RANGE = new VersionRange("[3.0.0, 3.0.10)");
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

package software.aws.toolkits.eclipse.amazonq.views;


import java.util.Arrays;
import java.util.Optional;
import java.util.concurrent.atomic.AtomicReference;
Expand All @@ -24,6 +23,7 @@
import software.aws.toolkits.eclipse.amazonq.chat.models.CopyToClipboardParams;
import software.aws.toolkits.eclipse.amazonq.chat.models.InfoLinkClickParams;
import software.aws.toolkits.eclipse.amazonq.chat.models.InsertToCursorPositionParams;
import software.aws.toolkits.eclipse.amazonq.configuration.PluginStoreKeys;
import software.aws.toolkits.eclipse.amazonq.exception.AmazonQPluginException;
import software.aws.toolkits.eclipse.amazonq.lsp.auth.model.AuthFollowUpClickedParams;
import software.aws.toolkits.eclipse.amazonq.lsp.auth.model.AuthFollowUpType;
Expand Down Expand Up @@ -117,6 +117,9 @@ public final void handleCommand(final ParsedCommand parsedCommand, final Browser
AuthFollowUpClickedParams authFollowUpClickedParams = jsonHandler.convertObject(params, AuthFollowUpClickedParams.class);
handleAuthFollowUpClicked(authFollowUpClickedParams);
break;
case DISCLAIMER_ACKNOWLEDGED:
Activator.getPluginStore().put(PluginStoreKeys.CHAT_DISCLAIMER_ACKNOWLEDGED, "true");
break;
default:
throw new AmazonQPluginException("Unexpected command received from Amazon Q Chat: " + command.toString());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import software.aws.toolkits.eclipse.amazonq.chat.ChatCommunicationManager;
import software.aws.toolkits.eclipse.amazonq.chat.ChatStateManager;
import software.aws.toolkits.eclipse.amazonq.chat.ChatTheme;
import software.aws.toolkits.eclipse.amazonq.configuration.PluginStoreKeys;
import software.aws.toolkits.eclipse.amazonq.lsp.AwsServerCapabiltiesProvider;
import software.aws.toolkits.eclipse.amazonq.lsp.auth.model.AuthState;
import software.aws.toolkits.eclipse.amazonq.lsp.model.ChatOptions;
Expand Down Expand Up @@ -223,6 +224,7 @@ private String generateCss() {

private String generateJS(final String jsEntrypoint) {
var chatQuickActionConfig = generateQuickActionConfig();
var disclaimerAcknowledged = Activator.getPluginStore().get(PluginStoreKeys.CHAT_DISCLAIMER_ACKNOWLEDGED);
return String.format("""
<script type="text/javascript" src="%s" defer></script>
<script type="text/javascript">
Expand All @@ -234,14 +236,18 @@ private String generateJS(final String jsEntrypoint) {
postMessage: (message) => {
ideCommand(JSON.stringify(message));
}
}, %s);
}, {
quickActionCommands: %s,
disclaimerAcknowledged: %b
});
})
.catch(error => console.error('Error initializing chat:', error));
}
window.addEventListener('load', init);
</script>
""", jsEntrypoint, getWaitFunction(), chatQuickActionConfig);
""", jsEntrypoint, getWaitFunction(), chatQuickActionConfig,
disclaimerAcknowledged.equals("true"));
}

/*
Expand All @@ -252,14 +258,13 @@ private String generateJS(final String jsEntrypoint) {
private String generateQuickActionConfig() {
return Optional.ofNullable(AwsServerCapabiltiesProvider.getInstance().getChatOptions())
.map(ChatOptions::quickActions).map(QuickActions::quickActionsCommandGroups)
.map(this::serializeQuickActionCommands).orElse("");
.map(this::serializeQuickActionCommands).orElse("[]");
}

private String serializeQuickActionCommands(final List<QuickActionsCommandGroup> quickActionCommands) {
try {
ObjectMapper mapper = ObjectMapperFactory.getInstance();
String json = mapper.writeValueAsString(quickActionCommands);
return String.format("{\"quickActionCommands\": %s}", json);
return mapper.writeValueAsString(quickActionCommands);
} catch (Exception e) {
Activator.getLogger().warn("Error occurred when json serializing quick action commands", e);
return "";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ public enum Command {
CHAT_COPY_TO_CLIPBOARD("copyToClipboard"),
CHAT_INSERT_TO_CURSOR_POSITION("insertToCursorPosition"),
AUTH_FOLLOW_UP_CLICKED("authFollowUpClicked"), //Auth command handled in QChat webview
DISCLAIMER_ACKNOWLEDGED("disclaimerAcknowledged"),

// Auth
LOGIN_BUILDER_ID("loginBuilderId"),
Expand Down

0 comments on commit b61f313

Please sign in to comment.