forked from intitni/CopilotForXcode
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathModificationAgent.swift
More file actions
117 lines (104 loc) · 3.27 KB
/
ModificationAgent.swift
File metadata and controls
117 lines (104 loc) · 3.27 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
import ChatBasic
import ComposableArchitecture
import Foundation
import SuggestionBasic
public enum ModificationAgentResponse {
case code(String)
case explanation(String)
}
public struct ModificationAgentRequest {
public var code: String
public var requirement: String
public var source: ModificationSource
public var isDetached: Bool
public var extraSystemPrompt: String?
public var range: CursorRange
public var references: [ChatMessage.Reference]
public var topics: [ChatMessage.Reference]
public struct ModificationSource: Equatable {
public var language: CodeLanguage
public var documentURL: URL
public var projectRootURL: URL
public var content: String
public var lines: [String]
public init(
language: CodeLanguage,
documentURL: URL,
projectRootURL: URL,
content: String,
lines: [String]
) {
self.language = language
self.documentURL = documentURL
self.projectRootURL = projectRootURL
self.content = content
self.lines = lines
}
}
public init(
code: String,
requirement: String,
source: ModificationSource,
isDetached: Bool,
extraSystemPrompt: String? = nil,
range: CursorRange,
references: [ChatMessage.Reference],
topics: [ChatMessage.Reference]
) {
self.code = code
self.requirement = requirement
self.source = source
self.isDetached = isDetached
self.extraSystemPrompt = extraSystemPrompt
self.range = range
self.references = references
self.topics = topics
}
}
public protocol ModificationAgent {
typealias Request = ModificationAgentRequest
typealias Response = ModificationAgentResponse
func send(_ request: Request) -> AsyncThrowingStream<Response, any Error>
}
public struct ModificationSnippet: Equatable, Identifiable {
public let id = UUID()
public var startLineIndex: Int
public var originalCode: String
public var modifiedCode: String
public var description: String
public var error: String?
public var attachedRange: CursorRange
public init(
startLineIndex: Int,
originalCode: String,
modifiedCode: String,
description: String,
error: String?,
attachedRange: CursorRange
) {
self.startLineIndex = startLineIndex
self.originalCode = originalCode
self.modifiedCode = modifiedCode
self.description = description
self.error = error
self.attachedRange = attachedRange
}
}
public enum ModificationAttachedTarget: Equatable {
case file(URL, projectURL: URL, code: String, lines: [String])
case dynamic
}
public struct ModificationHistoryNode {
public var snippets: IdentifiedArrayOf<ModificationSnippet>
public var instruction: NSAttributedString
public var references: [ChatMessage.Reference]
public init(
snippets: IdentifiedArrayOf<ModificationSnippet>,
instruction: NSAttributedString,
references: [ChatMessage.Reference]
) {
self.snippets = snippets
self.instruction = instruction
self.references = references
}
}