-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Expand file tree
/
Copy pathModels.swift
More file actions
168 lines (136 loc) · 4.46 KB
/
Models.swift
File metadata and controls
168 lines (136 loc) · 4.46 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
import CodableWrappers
import Foundation
import ConversationServiceProvider
import GitHubCopilotService
// move here avoid circular reference
public struct ConversationReference: Codable, Equatable, Hashable {
public enum Kind: Codable, Equatable, Hashable {
case `class`
case `struct`
case `enum`
case `actor`
case `protocol`
case `extension`
case `case`
case property
case `typealias`
case function
case method
case text
case webpage
case other
// reference for turn - request
case fileReference(FileReference)
// reference from turn - response
case reference(Reference)
}
public enum Status: String, Codable {
case included, blocked, notfound, empty
}
public var uri: String
public var status: Status?
public var kind: Kind
public var ext: String {
return url?.pathExtension ?? ""
}
public var fileName: String {
return url?.lastPathComponent ?? ""
}
public var filePath: String {
return url?.path ?? ""
}
public var url: URL? {
return URL(string: uri)
}
public init(
uri: String,
status: Status?,
kind: Kind
) {
self.uri = uri
self.status = status
self.kind = kind
}
}
public struct ChatMessage: Equatable, Codable {
public typealias ID = String
public enum Role: String, Codable, Equatable {
case user
case assistant
case system
}
/// The role of a message.
public var role: Role
/// The content of the message, either the chat message, or a result of a function call.
public var content: String
/// The attached image content of the message
public var contentImageReferences: [ImageReference]
/// The id of the message.
public var id: ID
/// The conversation id (not the CLS conversation id)
public var chatTabID: String
/// The CLS turn id of the message which is from CLS.
public var clsTurnID: ID?
/// Rate assistant message
public var rating: ConversationRating
/// The references of this message.
public var references: [ConversationReference]
/// The followUp question of this message
public var followUp: ConversationFollowUp?
public var suggestedTitle: String?
/// The error occurred during responding chat in server
public var errorMessages: [String]
/// The steps of conversation progress
public var steps: [ConversationProgressStep]
public var editAgentRounds: [AgentRound]
public var panelMessages: [CopilotShowMessageParams]
/// The timestamp of the message.
public var createdAt: Date
public var updatedAt: Date
public init(
id: String = UUID().uuidString,
chatTabID: String,
clsTurnID: String? = nil,
role: Role,
content: String,
contentImageReferences: [ImageReference] = [],
references: [ConversationReference] = [],
followUp: ConversationFollowUp? = nil,
suggestedTitle: String? = nil,
errorMessages: [String] = [],
rating: ConversationRating = .unrated,
steps: [ConversationProgressStep] = [],
editAgentRounds: [AgentRound] = [],
panelMessages: [CopilotShowMessageParams] = [],
createdAt: Date? = nil,
updatedAt: Date? = nil
) {
self.role = role
self.content = content
self.contentImageReferences = contentImageReferences
self.id = id
self.chatTabID = chatTabID
self.clsTurnID = clsTurnID
self.references = references
self.followUp = followUp
self.suggestedTitle = suggestedTitle
self.errorMessages = errorMessages
self.rating = rating
self.steps = steps
self.editAgentRounds = editAgentRounds
self.panelMessages = panelMessages
let now = Date.now
self.createdAt = createdAt ?? now
self.updatedAt = updatedAt ?? now
}
}
extension ConversationReference {
public func getPathRelativeToHome() -> String {
guard !filePath.isEmpty else { return filePath}
let homeDirectory = FileManager.default.homeDirectoryForCurrentUser.path
if !homeDirectory.isEmpty{
return filePath.replacingOccurrences(of: homeDirectory, with: "~")
}
return filePath
}
}