forked from intitni/CopilotForXcode
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBuiltinExtension.swift
More file actions
89 lines (72 loc) · 2.92 KB
/
Copy pathBuiltinExtension.swift
File metadata and controls
89 lines (72 loc) · 2.92 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
import ChatBasic
import ChatTab
import CopilotForXcodeKit
import Foundation
import Preferences
public protocol BuiltinExtension: CopilotForXcodeExtensionCapability {
/// An identifier for the extension.
var extensionIdentifier: String { get }
/// All chat builders provided by this extension.
var chatTabTypes: [any CustomChatTab] { get }
/// It's usually called when the app is about to quit,
/// you should clean up all the resources here.
func terminate()
}
// MARK: - Default Implementation
public extension BuiltinExtension {
var suggestionServiceId: BuiltInSuggestionFeatureProvider? { nil }
var chatTabTypes: [any CustomChatTab] { [] }
}
// MAKR: - ChatService
/// A temporary protocol for ChatServiceType. Migrate it to CopilotForXcodeKit when finished.
public protocol BuiltinExtensionChatServiceType: ChatServiceType {
typealias Message = ChatMessage
func sendMessage(
_ message: String,
history: [Message],
references: [RetrievedContent],
workspace: WorkspaceInfo
) async -> AsyncThrowingStream<String, Error>
}
public struct RetrievedContent {
public var document: ChatMessage.Reference
public var priority: Int
public init(document: ChatMessage.Reference, priority: Int) {
self.document = document
self.priority = priority
}
}
public enum ChatServiceMemoryMutation: Codable {
public typealias Message = ChatMessage
/// Add a new message to the end of memory.
/// If an id is not provided, a new id will be generated.
/// If an id is provided, and a message with the same id exists the message with the same
/// id will be updated.
case appendMessage(id: String?, role: Message.Role, text: String)
/// Update the message with the given id.
case updateMessage(id: String, role: Message.Role, text: String)
/// Stream the content into a message with the given id.
case streamIntoMessage(id: String, role: Message.Role?, text: String?)
}
public protocol CustomChatTab {
var name: String { get }
var isDefaultChatTabReplacement: Bool { get }
var canHandleOpenChatCommand: Bool { get }
func chatBuilders() -> [ChatTabBuilder]
func defaultChatBuilder() -> ChatTabBuilder
func restore(from data: Data) async throws -> any ChatTabBuilder
}
public struct TypedCustomChatTab: CustomChatTab {
public let type: ChatTab.Type
public init(of type: ChatTab.Type) {
self.type = type
}
public var name: String { type.name }
public var isDefaultChatTabReplacement: Bool { type.isDefaultChatTabReplacement }
public var canHandleOpenChatCommand: Bool { type.canHandleOpenChatCommand }
public func chatBuilders() -> [ChatTabBuilder] { type.chatBuilders() }
public func defaultChatBuilder() -> ChatTabBuilder { type.defaultChatBuilder() }
public func restore(from data: Data) async throws -> any ChatTabBuilder {
try await type.restore(from: data)
}
}