-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Expand file tree
/
Copy pathGitHubCopilotRequest+Conversation.swift
More file actions
241 lines (206 loc) · 6.82 KB
/
GitHubCopilotRequest+Conversation.swift
File metadata and controls
241 lines (206 loc) · 6.82 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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
import CopilotForXcodeKit
import Foundation
import LanguageServerProtocol
import SuggestionBasic
import ConversationServiceProvider
import JSONRPC
import Logger
enum ConversationSource: String, Codable {
case panel, inline
}
public struct FileReference: Codable, Equatable, Hashable {
public var type: String = "file"
public let uri: String
public let position: Position?
public let visibleRange: SuggestionBasic.CursorRange?
public let selection: SuggestionBasic.CursorRange?
public let openedAt: String?
public let activeAt: String?
}
public struct DirectoryReference: Codable, Equatable, Hashable {
public var type: String = "directory"
public let uri: String
}
public enum Reference: Codable, Equatable, Hashable {
case file(FileReference)
case directory(DirectoryReference)
public func encode(to encoder: Encoder) throws {
switch self {
case .file(let fileRef):
try fileRef.encode(to: encoder)
case .directory(let directoryRef):
try directoryRef.encode(to: encoder)
}
}
private enum CodingKeys: String, CodingKey {
case type
}
public init(from decoder: Decoder) throws {
let container = try decoder.container(keyedBy: CodingKeys.self)
let type = try container.decode(String.self, forKey: .type)
switch type {
case "file":
let fileRef = try FileReference(from: decoder)
self = .file(fileRef)
case "directory":
let directoryRef = try DirectoryReference(from: decoder)
self = .directory(directoryRef)
default:
throw DecodingError.dataCorrupted(
DecodingError.Context(
codingPath: decoder.codingPath,
debugDescription: "Unknown reference type: \(type)"
)
)
}
}
public static func from(_ ref: ConversationAttachedReference) -> Reference {
switch ref {
case .file(let fileRef):
return .file(
.init(
uri: fileRef.url.absoluteString,
position: nil,
visibleRange: nil,
selection: nil,
openedAt: nil,
activeAt: nil
)
)
case .directory(let directoryRef):
return .directory(.init(uri: directoryRef.url.absoluteString))
}
}
}
struct ConversationCreateParams: Codable {
var workDoneToken: String
var turns: [TurnSchema]
var capabilities: Capabilities
var textDocument: Doc?
var references: [Reference]?
var computeSuggestions: Bool?
var source: ConversationSource?
var workspaceFolder: String?
var workspaceFolders: [WorkspaceFolder]?
var ignoredSkills: [String]?
var model: String?
var modelProviderName: String?
var chatMode: String?
var needToolCallConfirmation: Bool?
var userLanguage: String?
struct Capabilities: Codable {
var skills: [String]
var allSkills: Bool?
}
}
// MARK: Conversation Progress
public enum ConversationProgressKind: String, Codable {
case begin, report, end
}
protocol BaseConversationProgress: Codable {
var kind: ConversationProgressKind { get }
var conversationId: String { get }
var turnId: String { get }
}
public struct ConversationProgressBegin: BaseConversationProgress {
public let kind: ConversationProgressKind
public let conversationId: String
public let turnId: String
}
public struct ConversationProgressReport: BaseConversationProgress {
public let kind: ConversationProgressKind
public let conversationId: String
public let turnId: String
public let reply: String?
public let references: [FileReference]?
public let steps: [ConversationProgressStep]?
public let editAgentRounds: [AgentRound]?
}
public struct ConversationProgressEnd: BaseConversationProgress {
public let kind: ConversationProgressKind
public let conversationId: String
public let turnId: String
public let error: CopilotLanguageServerError?
public let followUp: ConversationFollowUp?
public let suggestedTitle: String?
}
enum ConversationProgressContainer: Decodable {
case begin(ConversationProgressBegin)
case report(ConversationProgressReport)
case end(end: ConversationProgressEnd)
enum CodingKeys: String, CodingKey {
case kind
}
init(from decoder: Decoder) throws {
do {
let container = try decoder.container(keyedBy: CodingKeys.self)
let kind = try container.decode(ConversationProgressKind.self, forKey: .kind)
switch kind {
case .begin:
let begin = try ConversationProgressBegin(from: decoder)
self = .begin(begin)
case .report:
let report = try ConversationProgressReport(from: decoder)
self = .report(report)
case .end:
let end = try ConversationProgressEnd(from: decoder)
self = .end(end: end)
}
} catch {
Logger.gitHubCopilot.error("Error decoding ConversationProgressContainer: \(error)")
throw error
}
}
}
// MARK: Conversation rating
struct ConversationRatingParams: Codable {
var turnId: String
var rating: ConversationRating
var doc: Doc?
var source: ConversationSource?
}
// MARK: Conversation templates
struct ConversationTemplatesParams: Codable {
var workspaceFolders: [WorkspaceFolder]?
}
// MARK: Conversation turn
struct TurnCreateParams: Codable {
var workDoneToken: String
var conversationId: String
var turnId: String?
var message: MessageContent
var textDocument: Doc?
var ignoredSkills: [String]?
var references: [Reference]?
var model: String?
var modelProviderName: String?
var workspaceFolder: String?
var workspaceFolders: [WorkspaceFolder]?
var chatMode: String?
var needToolCallConfirmation: Bool?
}
// MARK: Copy
struct CopyCodeParams: Codable {
var turnId: String
var codeBlockIndex: Int
var copyType: CopyKind
var copiedCharacters: Int
var totalCharacters: Int
var copiedText: String
var doc: Doc?
var source: ConversationSource?
}
// MARK: Conversation context
public struct ConversationContextParams: Codable {
public var conversationId: String
public var turnId: String
public var skillId: String
}
public typealias ConversationContextRequest = JSONRPCRequest<ConversationContextParams>
// MARK: Watched Files
public struct WatchedFilesParams: Codable {
public var workspaceFolder: WorkspaceFolder
public var excludeGitignoredFiles: Bool
public var excludeIDEIgnoredFiles: Bool
}
public typealias WatchedFilesRequest = JSONRPCRequest<WatchedFilesParams>