-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Expand file tree
/
Copy pathGitHubCopilotConversationService.swift
More file actions
95 lines (77 loc) · 4.98 KB
/
GitHubCopilotConversationService.swift
File metadata and controls
95 lines (77 loc) · 4.98 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
import CopilotForXcodeKit
import Foundation
import ConversationServiceProvider
import BuiltinExtension
import Workspace
import LanguageServerProtocol
public final class GitHubCopilotConversationService: ConversationServiceType {
private let serviceLocator: ServiceLocator
init(serviceLocator: ServiceLocator) {
self.serviceLocator = serviceLocator
}
private func getWorkspaceFolders(workspace: WorkspaceInfo) -> [WorkspaceFolder] {
let projects = WorkspaceFile.getProjects(workspace: workspace)
return projects.map { project in
WorkspaceFolder(uri: project.uri, name: project.name)
}
}
public func createConversation(_ request: ConversationRequest, workspace: WorkspaceInfo) async throws {
guard let service = await serviceLocator.getService(from: workspace) else { return }
return try await service.createConversation(request.content,
workDoneToken: request.workDoneToken,
workspaceFolder: workspace.projectURL.absoluteString,
workspaceFolders: getWorkspaceFolders(workspace: workspace),
activeDoc: request.activeDoc,
skills: request.skills,
ignoredSkills: request.ignoredSkills,
references: request.references ?? [],
model: request.model,
turns: request.turns,
agentMode: request.agentMode,
userLanguage: request.userLanguage)
}
public func createTurn(with conversationId: String, request: ConversationRequest, workspace: WorkspaceInfo) async throws {
guard let service = await serviceLocator.getService(from: workspace) else { return }
return try await service.createTurn(request.content,
workDoneToken: request.workDoneToken,
conversationId: conversationId,
turnId: request.turnId,
activeDoc: request.activeDoc,
ignoredSkills: request.ignoredSkills,
references: request.references ?? [],
model: request.model,
workspaceFolder: workspace.projectURL.absoluteString,
workspaceFolders: getWorkspaceFolders(workspace: workspace),
agentMode: request.agentMode)
}
public func cancelProgress(_ workDoneToken: String, workspace: WorkspaceInfo) async throws {
guard let service = await serviceLocator.getService(from: workspace) else { return }
await service.cancelProgress(token: workDoneToken)
}
public func rateConversation(turnId: String, rating: ConversationRating, workspace: WorkspaceInfo) async throws {
guard let service = await serviceLocator.getService(from: workspace) else { return }
try await service.rateConversation(turnId: turnId, rating: rating)
}
public func copyCode(request: CopyCodeRequest, workspace: WorkspaceInfo) async throws {
guard let service = await serviceLocator.getService(from: workspace) else { return }
try await service.copyCode(turnId: request.turnId, codeBlockIndex: request.codeBlockIndex, copyType: request.copyType, copiedCharacters: request.copiedCharacters, totalCharacters: request.totalCharacters, copiedText: request.copiedText)
}
public func templates(workspace: WorkspaceInfo) async throws -> [ChatTemplate]? {
guard let service = await serviceLocator.getService(from: workspace) else { return nil }
return try await service.templates()
}
public func models(workspace: WorkspaceInfo) async throws -> [CopilotModel]? {
guard let service = await serviceLocator.getService(from: workspace) else { return nil }
return try await service.models()
}
public func notifyDidChangeWatchedFiles(_ event: DidChangeWatchedFilesEvent, workspace: WorkspaceInfo) async throws {
guard let service = await serviceLocator.getService(from: workspace) else {
return
}
return try await service.notifyDidChangeWatchedFiles(.init(workspaceUri: event.workspaceUri, changes: event.changes))
}
public func agents(workspace: WorkspaceInfo) async throws -> [ChatAgent]? {
guard let service = await serviceLocator.getService(from: workspace) else { return nil }
return try await service.agents()
}
}