Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support for suppressible Chat license acknowledgement #316

Merged
merged 1 commit into from
Jan 10, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
// Copyright 2024 Amazon.com, Inc. or its affiliates. All Rights Reserved.
// SPDX-License-Identifier: Apache-2.0

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

public final class PluginStoreKeys {

private PluginStoreKeys() {
// Prevent instantiation
}

public static final String CHAT_DISCLAIMER_ACKNOWLEDGED = "qchatDisclaimerAcknowledged";

}
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public QLspConnectionProvider() throws IOException {
protected final void addEnvironmentVariables(final Map<String, String> env) {
String httpsProxyPreference = Activator.getDefault().getPreferenceStore().getString(AmazonQPreferencePage.HTTPS_PROXY);
String caCertPreference = Activator.getDefault().getPreferenceStore().getString(AmazonQPreferencePage.CA_CERT);
if (!StringUtils.isEmpty(caCertPreference)) {
if (!StringUtils.isEmpty(httpsProxyPreference)) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nice catch

env.put("HTTPS_PROXY", httpsProxyPreference);
}
if (!StringUtils.isEmpty(caCertPreference)) {
Expand Down
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");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

in what condition would this be set to a false?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As of now, never - the presence of the setting alone implies acknowledgement, but I feel this gives us an out in case we ever want to roll it back if the acknowledgement text changes for example.

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
Loading