@@ -14,6 +14,7 @@ class CopilotLocalProcessServer {
1414 private var wrappedServer : CustomJSONRPCLanguageServer ?
1515 var terminationHandler : ( ( ) -> Void ) ?
1616 @MainActor var ongoingCompletionRequestIDs : [ JSONId ] = [ ]
17+ @MainActor var ongoingConversationRequestIDs : [ String : JSONId ] = [ : ]
1718
1819 public convenience init (
1920 path: String ,
@@ -58,6 +59,21 @@ class CopilotLocalProcessServer {
5859 Task { @MainActor [ weak self] in
5960 self ? . ongoingCompletionRequestIDs. append ( request. id)
6061 }
62+ } else if request. method == " conversation/create " {
63+ Task { @MainActor [ weak self] in
64+ if let paramsData = try ? JSONEncoder ( ) . encode ( request. params) {
65+ do {
66+ let params = try JSONDecoder ( ) . decode (
67+ GitHubCopilotRequest . ConversationCreate. RequestBody. self,
68+ from: paramsData
69+ )
70+ self ? . ongoingConversationRequestIDs [ params. workDoneToken] = request. id
71+ } catch {
72+ // Handle decoding error
73+ print ( " Error decoding ConversationCreateParams: \( error) " )
74+ }
75+ }
76+ }
6177 }
6278 }
6379
@@ -131,19 +147,35 @@ extension CopilotLocalProcessServer: LanguageServerProtocol.Server {
131147
132148 let task = Task { @MainActor in
133149 for id in self . ongoingCompletionRequestIDs {
134- switch id {
135- case let . numericId( id) :
136- try ? await server. sendNotification ( . protocolCancelRequest( . init( id: id) ) )
137- case let . stringId( id) :
138- try ? await server. sendNotification ( . protocolCancelRequest( . init( id: id) ) )
139- }
150+ await cancelTask ( id)
140151 }
141152 self . ongoingCompletionRequestIDs = [ ]
142153 }
143154
144155 await task. value
145156 }
146157
158+ public func cancelOngoingTask( workDoneToken: String ) async {
159+ let task = Task { @MainActor in
160+ guard let id = ongoingConversationRequestIDs [ workDoneToken] else { return }
161+ await cancelTask ( id)
162+ }
163+ await task. value
164+ }
165+
166+ public func cancelTask( _ id: JSONId ) async {
167+ guard let server = wrappedServer, process. isRunning else {
168+ return
169+ }
170+
171+ switch id {
172+ case let . numericId( id) :
173+ try ? await server. sendNotification ( . protocolCancelRequest( . init( id: id) ) )
174+ case let . stringId( id) :
175+ try ? await server. sendNotification ( . protocolCancelRequest( . init( id: id) ) )
176+ }
177+ }
178+
147179 public func sendRequest< Response: Codable > (
148180 _ request: ClientRequest ,
149181 completionHandler: @escaping ( ServerResult < Response > ) -> Void
0 commit comments