-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Foundation of Chat communication with LSP (#15)
- Loading branch information
Showing
19 changed files
with
253 additions
and
21 deletions.
There are no files selected for viewing
33 changes: 33 additions & 0 deletions
33
plugin/src/software/aws/toolkits/eclipse/amazonq/chat/ChatCommunicationManager.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
// Copyright 2024 Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
|
||
package software.aws.toolkits.eclipse.amazonq.chat; | ||
|
||
import software.aws.toolkits.eclipse.amazonq.chat.models.GenericTabParams; | ||
import software.aws.toolkits.eclipse.amazonq.util.JsonHandler; | ||
import software.aws.toolkits.eclipse.amazonq.util.PluginLogger; | ||
import software.aws.toolkits.eclipse.amazonq.views.model.Command; | ||
|
||
public final class ChatCommunicationManager { | ||
|
||
private final JsonHandler jsonHandler; | ||
private final ChatMessageProvider chatMessageProivder; | ||
|
||
public ChatCommunicationManager() { | ||
this.jsonHandler = new JsonHandler(); | ||
this.chatMessageProivder = new ChatMessageProvider(); | ||
} | ||
|
||
public void sendMessageToChatServerAsync(final Command command, final Object params) { | ||
|
||
String jsonParams = jsonHandler.serialize(params); | ||
|
||
switch (command) { | ||
case CHAT_TAB_ADD: | ||
GenericTabParams tabParams = jsonHandler.deserialize(jsonParams, GenericTabParams.class); | ||
chatMessageProivder.sendTabAdd(tabParams); | ||
break; | ||
default: | ||
PluginLogger.error("Unhandled chat command: " + command.toString()); | ||
} | ||
} | ||
} |
33 changes: 33 additions & 0 deletions
33
plugin/src/software/aws/toolkits/eclipse/amazonq/chat/ChatMessageProvider.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
// Copyright 2024 Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
|
||
package software.aws.toolkits.eclipse.amazonq.chat; | ||
|
||
import java.util.concurrent.ExecutionException; | ||
|
||
import software.aws.toolkits.eclipse.amazonq.chat.models.GenericTabParams; | ||
import software.aws.toolkits.eclipse.amazonq.lsp.AmazonQLspServer; | ||
import software.aws.toolkits.eclipse.amazonq.providers.LspProvider; | ||
import software.aws.toolkits.eclipse.amazonq.util.PluginLogger; | ||
import software.aws.toolkits.eclipse.amazonq.views.model.Command; | ||
|
||
public final class ChatMessageProvider { | ||
|
||
private AmazonQLspServer amazonQLspServer; | ||
|
||
public ChatMessageProvider() { | ||
try { | ||
amazonQLspServer = LspProvider.getAmazonQServer().get(); | ||
} catch (InterruptedException | ExecutionException e) { | ||
PluginLogger.error("Error occurred while retrieving Amazon Q LSP server. Failed to instantiate ChatMessageProvider."); | ||
} | ||
} | ||
|
||
public void sendTabAdd(final GenericTabParams tabParams) { | ||
try { | ||
PluginLogger.info("Sending " + Command.CHAT_TAB_ADD + " message to Amazon Q LSP server"); | ||
amazonQLspServer.tabAdd(tabParams).get(); | ||
} catch (InterruptedException | ExecutionException e) { | ||
PluginLogger.error("Error occurred while sending message to Amazon Q LSP server for command " + Command.CHAT_TAB_ADD); | ||
} | ||
} | ||
} |
14 changes: 14 additions & 0 deletions
14
plugin/src/software/aws/toolkits/eclipse/amazonq/chat/models/ChatItemAction.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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. | ||
|
||
package software.aws.toolkits.eclipse.amazonq.chat.models; | ||
|
||
import com.fasterxml.jackson.annotation.JsonProperty; | ||
|
||
public record ChatItemAction( | ||
@JsonProperty("pillText") String pillText, | ||
@JsonProperty("prompt") String prompt, | ||
@JsonProperty("disabled") Boolean disabled, | ||
@JsonProperty("description") String description, | ||
@JsonProperty("type") String type | ||
) { }; | ||
|
11 changes: 11 additions & 0 deletions
11
plugin/src/software/aws/toolkits/eclipse/amazonq/chat/models/ChatPrompt.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
// Copyright 2024 Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
|
||
package software.aws.toolkits.eclipse.amazonq.chat.models; | ||
|
||
import com.fasterxml.jackson.annotation.JsonProperty; | ||
|
||
public record ChatPrompt( | ||
@JsonProperty("prompt") String prompt, | ||
@JsonProperty("escapedPrompt") String escapedPrompt, | ||
@JsonProperty("command") String command | ||
) { } |
11 changes: 11 additions & 0 deletions
11
plugin/src/software/aws/toolkits/eclipse/amazonq/chat/models/ChatRequestParams.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
// Copyright 2024 Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
|
||
package software.aws.toolkits.eclipse.amazonq.chat.models; | ||
|
||
import com.fasterxml.jackson.annotation.JsonProperty; | ||
|
||
public record ChatRequestParams( | ||
@JsonProperty("tabId") String tabId, | ||
@JsonProperty("prompt") ChatPrompt prompt | ||
) { } | ||
|
14 changes: 14 additions & 0 deletions
14
plugin/src/software/aws/toolkits/eclipse/amazonq/chat/models/ChatResult.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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. | ||
|
||
package software.aws.toolkits.eclipse.amazonq.chat.models; | ||
|
||
import com.fasterxml.jackson.annotation.JsonProperty; | ||
|
||
public record ChatResult( | ||
@JsonProperty("body") String body, | ||
@JsonProperty("messageId") String messageId, | ||
@JsonProperty("canBeVoted") Boolean canBeVoted, | ||
@JsonProperty("relatedContent") RelatedContent relatedContent, | ||
@JsonProperty("followUp") FollowUp followUp, | ||
@JsonProperty("codeReference") ReferenceTrackerInformation[] codeReference | ||
) { }; |
11 changes: 11 additions & 0 deletions
11
plugin/src/software/aws/toolkits/eclipse/amazonq/chat/models/FollowUp.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
// Copyright 2024 Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
|
||
package software.aws.toolkits.eclipse.amazonq.chat.models; | ||
|
||
import com.fasterxml.jackson.annotation.JsonProperty; | ||
|
||
public record FollowUp( | ||
@JsonProperty("text") String text, | ||
@JsonProperty("options") ChatItemAction[] options | ||
) { } | ||
|
10 changes: 10 additions & 0 deletions
10
plugin/src/software/aws/toolkits/eclipse/amazonq/chat/models/GenericTabParams.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
// Copyright 2024 Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
|
||
package software.aws.toolkits.eclipse.amazonq.chat.models; | ||
|
||
import com.fasterxml.jackson.annotation.JsonProperty; | ||
|
||
public record GenericTabParams( | ||
@JsonProperty("tabId") String tabId | ||
) { } | ||
|
10 changes: 10 additions & 0 deletions
10
plugin/src/software/aws/toolkits/eclipse/amazonq/chat/models/RecommendationContentSpan.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
// Copyright 2024 Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
|
||
package software.aws.toolkits.eclipse.amazonq.chat.models; | ||
|
||
import com.fasterxml.jackson.annotation.JsonProperty; | ||
|
||
public record RecommendationContentSpan( | ||
@JsonProperty("start") Integer start, | ||
@JsonProperty("end") Integer end | ||
) { }; |
13 changes: 13 additions & 0 deletions
13
...in/src/software/aws/toolkits/eclipse/amazonq/chat/models/ReferenceTrackerInformation.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
// Copyright 2024 Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
|
||
package software.aws.toolkits.eclipse.amazonq.chat.models; | ||
|
||
import com.fasterxml.jackson.annotation.JsonProperty; | ||
|
||
public record ReferenceTrackerInformation( | ||
@JsonProperty("licenseName") String licenseName, | ||
@JsonProperty("repository") String repository, | ||
@JsonProperty("url") String url, | ||
@JsonProperty("recommendationContentSpan") RecommendationContentSpan recommendationContentSpan, | ||
@JsonProperty("information") String information | ||
) { }; |
10 changes: 10 additions & 0 deletions
10
plugin/src/software/aws/toolkits/eclipse/amazonq/chat/models/RelatedContent.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
// Copyright 2024 Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
|
||
package software.aws.toolkits.eclipse.amazonq.chat.models; | ||
|
||
import com.fasterxml.jackson.annotation.JsonProperty; | ||
|
||
public record RelatedContent( | ||
@JsonProperty("title") String title, | ||
@JsonProperty("content") SourceLink[] content | ||
) { } |
11 changes: 11 additions & 0 deletions
11
plugin/src/software/aws/toolkits/eclipse/amazonq/chat/models/SourceLink.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
// Copyright 2024 Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
|
||
package software.aws.toolkits.eclipse.amazonq.chat.models; | ||
|
||
import com.fasterxml.jackson.annotation.JsonProperty; | ||
|
||
public record SourceLink( | ||
@JsonProperty("title") String title, | ||
@JsonProperty("url") String url, | ||
@JsonProperty("body") String body | ||
) { }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
35 changes: 35 additions & 0 deletions
35
plugin/src/software/aws/toolkits/eclipse/amazonq/util/JsonHandler.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
// Copyright 2024 Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
|
||
package software.aws.toolkits.eclipse.amazonq.util; | ||
|
||
import com.fasterxml.jackson.core.JsonProcessingException; | ||
import com.fasterxml.jackson.databind.ObjectMapper; | ||
|
||
public final class JsonHandler { | ||
private final ObjectMapper objectMapper; | ||
|
||
public JsonHandler() { | ||
this.objectMapper = ObjectMapperFactory.getInstance(); | ||
} | ||
|
||
public String serialize(final Object obj) { | ||
String serializedObj = null; | ||
try { | ||
serializedObj = objectMapper.writeValueAsString(obj); | ||
} catch (JsonProcessingException e) { | ||
PluginLogger.error("Error occurred while serializing object: " + obj.toString(), e); | ||
return null; | ||
} | ||
return serializedObj; | ||
} | ||
|
||
public <T> T deserialize(final String jsonString, final Class<T> cls) { | ||
try { | ||
T params = objectMapper.readValue(jsonString, cls); | ||
return params; | ||
} catch (JsonProcessingException e) { | ||
PluginLogger.error("Error occurred while deserializing jsonString: " + jsonString, e); | ||
} | ||
return null; | ||
} | ||
} |
20 changes: 15 additions & 5 deletions
20
plugin/src/software/aws/toolkits/eclipse/amazonq/views/AmazonQChatViewActionHandler.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
14 changes: 4 additions & 10 deletions
14
plugin/src/software/aws/toolkits/eclipse/amazonq/views/model/CommandRequest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,22 +1,16 @@ | ||
// Copyright 2024 Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
package software.aws.toolkits.eclipse.amazonq.views.model; | ||
import java.util.Optional; | ||
|
||
import com.fasterxml.jackson.annotation.JsonProperty; | ||
|
||
public record CommandRequest( | ||
@JsonProperty("command") String commandString, | ||
@JsonProperty("params") Object params) { | ||
public Optional<ParsedCommand> getParsedCommand() { | ||
Optional<Command> command = Command.fromString(commandString); | ||
|
||
if (!command.isPresent()) { | ||
return Optional.empty(); | ||
} | ||
|
||
ParsedCommand parsedCommand = new ParsedCommand(command.get(), Optional.ofNullable(params)); | ||
return Optional.ofNullable(parsedCommand); | ||
public ParsedCommand getParsedCommand() { | ||
Command command = Command.fromString(commandString).orElse(null); | ||
ParsedCommand parsedCommand = new ParsedCommand(command, params); | ||
return parsedCommand; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters