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 link click actions within Q chat #44

Merged
merged 4 commits into from
Oct 1, 2024
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,40 @@
// Copyright 2024 Amazon.com, Inc. or its affiliates. All Rights Reserved.

package software.aws.toolkits.eclipse.amazonq.chat.models;
Copy link
Contributor

Choose a reason for hiding this comment

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

missing copyright header. I need to also add a check for this.


import com.fasterxml.jackson.annotation.JsonProperty;

public class InfoLinkClickParams {
@JsonProperty("tabId")
private String tabId;

@JsonProperty("link")
private String link;

@JsonProperty("eventId")
private String eventId;

public final String getTabId() {
return tabId;
}

public final void setTabId(final String tabId) {
this.tabId = tabId;
}

public final String getLink() {
return link;
}

public final void setLink(final String link) {
this.link = link;
}

public final String getEventId() {
return eventId;
}

public final void setEventId(final String eventId) {
this.eventId = eventId;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@
import org.eclipse.core.runtime.FileLocator;
import org.eclipse.core.runtime.Path;
import org.eclipse.core.runtime.Platform;
import org.eclipse.jface.dialogs.MessageDialog;
import org.eclipse.swt.graphics.Image;
import org.eclipse.swt.widgets.Display;
import org.eclipse.ui.PlatformUI;
import org.osgi.framework.Bundle;
import org.osgi.framework.FrameworkUtil;
Expand Down Expand Up @@ -98,4 +100,19 @@ public static void openWebpage(final String url) {
PluginLogger.warn("Error while trying to open an external web page:", ex);
}
}

public static boolean showConfirmDialog(final String title, final String message) {
final boolean[] result = new boolean[] {false};
try {
Display.getDefault().syncExec(new Runnable() {
@Override
public void run() {
result[0] = MessageDialog.openConfirm(Display.getDefault().getActiveShell(), title, message);
}
});
} catch (Exception ex) {
PluginLogger.error(ex.getMessage());
}
return result[0];
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,11 @@
import software.aws.toolkits.eclipse.amazonq.chat.models.ChatResult;
import software.aws.toolkits.eclipse.amazonq.chat.models.ChatUIInboundCommand;
import software.aws.toolkits.eclipse.amazonq.chat.models.ChatUIInboundCommandName;
import software.aws.toolkits.eclipse.amazonq.chat.models.InfoLinkClickParams;
import software.aws.toolkits.eclipse.amazonq.exception.AmazonQPluginException;
import software.aws.toolkits.eclipse.amazonq.util.JsonHandler;
import software.aws.toolkits.eclipse.amazonq.util.PluginLogger;
import software.aws.toolkits.eclipse.amazonq.util.PluginUtils;
import software.aws.toolkits.eclipse.amazonq.util.ProgressNotficationUtils;
import software.aws.toolkits.eclipse.amazonq.views.model.Command;
import software.aws.toolkits.eclipse.amazonq.views.model.ParsedCommand;
Expand Down Expand Up @@ -54,6 +56,16 @@ public final void handleCommand(final ParsedCommand parsedCommand, final Browser
chatCommunicationManager.sendMessageToChatUI(browser, chatUIInboundCommand);
});
break;
case CHAT_INFO_LINK_CLICK:
case CHAT_LINK_CLICK:
case CHAT_SOURCE_LINK_CLICK:
InfoLinkClickParams infoLinkClickParams = jsonHandler.convertObject(params, InfoLinkClickParams.class);
var link = infoLinkClickParams.getLink();
if (link == null || link.isEmpty()) {
throw new IllegalArgumentException("Link parameter cannot be null or empty");
}
handleExternalLinkClick(link);
break;
case CHAT_READY:
chatCommunicationManager.sendMessageToChatServer(browser, command, params);
break;
Expand All @@ -67,6 +79,16 @@ public final void handleCommand(final ParsedCommand parsedCommand, final Browser
}
}

private void handleExternalLinkClick(final String link) {
try {
var result = PluginUtils.showConfirmDialog("Amazon Q", "Do you want to open the external website?\n\n" + link);
if (result) {
PluginUtils.openWebpage(link);
}
} catch (Exception ex) {
PluginLogger.error("Failed to open url in browser", ex);
}
}

/*
* Handles chat progress notifications from the Amazon Q LSP server. Sends a partial chat prompt message to the webview.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ public enum Command {
CHAT_READY("aws/chat/ready"),
CHAT_TAB_ADD("aws/chat/tabAdd"),
CHAT_SEND_PROMPT("aws/chat/sendChatPrompt"),
CHAT_LINK_CLICK("aws/chat/linkClick"),
CHAT_INFO_LINK_CLICK("aws/chat/infoLinkClick"),
CHAT_SOURCE_LINK_CLICK("aws/chat/sourceLinkClick"),
TELEMETRY_EVENT("telemetry/event"),

// Auth
Expand Down