1+ import ChatService
12import CopilotModel
23import Foundation
3- import SuggestionWidget
44import OpenAIService
5+ import SuggestionWidget
56
67struct PresentInWindowSuggestionPresenter {
78 func presentSuggestion(
@@ -46,14 +47,14 @@ struct PresentInWindowSuggestionPresenter {
4647 controller. presentError ( error. localizedDescription)
4748 }
4849 }
49-
50+
5051 func presentErrorMessage( _ message: String ) {
5152 Task { @MainActor in
5253 let controller = GraphicalUserInterfaceController . shared. suggestionWidget
5354 controller. presentError ( message)
5455 }
5556 }
56-
57+
5758 func closeChatRoom( fileURL: URL ) {
5859 Task { @MainActor in
5960 let controller = GraphicalUserInterfaceController . shared. suggestionWidget
@@ -63,6 +64,7 @@ struct PresentInWindowSuggestionPresenter {
6364
6465 func presentChatGPTConversation( _ service: ChatGPTService , fileURL: URL ) {
6566 let chatRoom = ChatRoom ( )
67+ let chatService = ChatService ( chatGPTService: service)
6668 let cancellable = service. objectWillChange. sink { [ weak chatRoom] in
6769 guard let chatRoom else { return }
6870 Task { @MainActor in
@@ -81,31 +83,31 @@ struct PresentInWindowSuggestionPresenter {
8183 _ = cancellable
8284 Task {
8385 do {
84- _ = try await service . send ( content: message)
86+ _ = try await chatService . send ( content: message)
8587 } catch {
8688 presentError ( error)
8789 }
8890 }
8991 }
9092 chatRoom. onStop = {
9193 Task {
92- await service . stopReceivingMessage ( )
94+ await chatService . stopReceivingMessage ( )
9395 }
9496 }
95-
97+
9698 chatRoom. onClear = {
9799 Task {
98- await service . clearHistory ( )
100+ await chatService . clearHistory ( )
99101 }
100102 }
101-
103+
102104 chatRoom. onClose = {
103105 Task {
104- await service . stopReceivingMessage ( )
106+ await chatService . stopReceivingMessage ( )
105107 closeChatRoom ( fileURL: fileURL)
106108 }
107109 }
108-
110+
109111 Task { @MainActor in
110112 let controller = GraphicalUserInterfaceController . shared. suggestionWidget
111113 controller. presentChatRoom ( chatRoom, fileURL: fileURL)
0 commit comments