13
13
import software .aws .toolkits .eclipse .amazonq .chat .models .GenericTabParams ;
14
14
import software .aws .toolkits .eclipse .amazonq .exception .AmazonQPluginException ;
15
15
import software .aws .toolkits .eclipse .amazonq .util .JsonHandler ;
16
+ import software .aws .toolkits .eclipse .amazonq .util .PluginLogger ;
16
17
import software .aws .toolkits .eclipse .amazonq .views .model .Command ;
17
18
18
19
/**
19
- * ChatCommunicationManager is responsible for managing communication between
20
- * the Amazon Q Eclipse Plugin and the LSP server as well as communication
21
- * between the Amazon Q Eclipse Plugin and the webview. It is implemented
22
- * as a singleton to centralize control of all communication in the plugin.
20
+ * ChatCommunicationManager is a central component of the Amazon Q Eclipse Plugin that
21
+ * acts as a bridge between the plugin's UI and the LSP server. It is also responsible
22
+ * for managing communication between the plugin and the webview used for displaying
23
+ * chat conversations. It is implemented as a singleton to centralize control of all
24
+ * communication in the plugin.
23
25
*/
24
26
public final class ChatCommunicationManager {
25
27
private static ChatCommunicationManager instance ;
26
28
27
29
private final JsonHandler jsonHandler ;
28
30
private final CompletableFuture <ChatMessageProvider > chatMessageProvider ;
29
- private final ChatPartialResultManager chatPartialResultManager ;
31
+ private final ChatPartialResultMap chatPartialResultMap ;
30
32
31
33
private ChatCommunicationManager () {
32
34
this .jsonHandler = new JsonHandler ();
33
35
this .chatMessageProvider = ChatMessageProvider .createAsync ();
34
- this .chatPartialResultManager = ChatPartialResultManager . getInstance ();
36
+ this .chatPartialResultMap = new ChatPartialResultMap ();
35
37
}
36
38
37
39
public static synchronized ChatCommunicationManager getInstance () {
@@ -41,13 +43,13 @@ public static synchronized ChatCommunicationManager getInstance() {
41
43
return instance ;
42
44
}
43
45
44
- public CompletableFuture <ChatResult > sendMessageToChatServer (final Command command , final Object params ) {
46
+ public CompletableFuture <ChatResult > sendMessageToChatServer (final Browser browser , final Command command , final Object params ) {
45
47
return chatMessageProvider .thenCompose (chatMessageProvider -> {
46
48
try {
47
49
switch (command ) {
48
50
case CHAT_SEND_PROMPT :
49
51
ChatRequestParams chatRequestParams = jsonHandler .convertObject (params , ChatRequestParams .class );
50
- return chatMessageProvider .sendChatPrompt (chatRequestParams );
52
+ return chatMessageProvider .sendChatPrompt (browser , chatRequestParams );
51
53
case CHAT_READY :
52
54
chatMessageProvider .sendChatReady ();
53
55
return CompletableFuture .completedFuture (null );
@@ -68,7 +70,7 @@ public CompletableFuture<ChatResult> sendMessageToChatServer(final Command comma
68
70
public void sendMessageToChatUI (final Browser browser , final ChatUIInboundCommand command ) {
69
71
// Mynah-ui will not render the partial result if null values are included. Must serialize with ignoreNulls set to True.
70
72
Boolean ignoreNull = true ;
71
- String message = this . jsonHandler .serialize (command , ignoreNull );
73
+ String message = jsonHandler .serialize (command , ignoreNull );
72
74
73
75
String script = "window.postMessage(" + message + ");" ;
74
76
browser .getDisplay ().asyncExec (() -> {
0 commit comments