forked from intitni/CopilotForXcode
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPromptToCodeAgent.swift
More file actions
91 lines (79 loc) · 2.5 KB
/
PromptToCodeAgent.swift
File metadata and controls
91 lines (79 loc) · 2.5 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
import ComposableArchitecture
import Foundation
import SuggestionBasic
public enum PromptToCodeAgentResponse {
case code(String)
case description(String)
}
public struct PromptToCodeAgentRequest {
var code: String
var requirement: String
var source: PromptToCodeSource
var isDetached: Bool
var extraSystemPrompt: String?
var generateDescriptionRequirement: Bool?
public struct PromptToCodeSource {
public var language: CodeLanguage
public var documentURL: URL
public var projectRootURL: URL
public var content: String
public var lines: [String]
public var range: CursorRange
public init(
language: CodeLanguage,
documentURL: URL,
projectRootURL: URL,
content: String,
lines: [String],
range: CursorRange
) {
self.language = language
self.documentURL = documentURL
self.projectRootURL = projectRootURL
self.content = content
self.lines = lines
self.range = range
}
}
}
public protocol PromptToCodeAgent {
typealias Request = PromptToCodeAgentRequest
typealias Response = PromptToCodeAgentResponse
func send(_ request: Request) -> AsyncThrowingStream<Response, any Error>
}
public struct PromptToCodeSnippet: 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 PromptToCodeAttachedTarget: Equatable {
case file(URL, projectURL: URL, code: String, lines: [String])
case dynamic
}
public struct PromptToCodeHistoryNode: Equatable {
public var snippets: IdentifiedArrayOf<PromptToCodeSnippet>
public var instruction: String
public init(snippets: IdentifiedArrayOf<PromptToCodeSnippet>, instruction: String) {
self.snippets = snippets
self.instruction = instruction
}
}