-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Expand file tree
/
Copy pathCopilotPolicyNotifier.swift
More file actions
53 lines (46 loc) · 2 KB
/
CopilotPolicyNotifier.swift
File metadata and controls
53 lines (46 loc) · 2 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
import Combine
import SwiftUI
import JSONRPC
public extension Notification.Name {
static let gitHubCopilotPolicyDidChange = Notification
.Name("com.github.CopilotForXcode.CopilotPolicyDidChange")
}
public struct CopilotPolicy: Hashable, Codable {
public var mcpContributionPointEnabled: Bool = true
public var customAgentEnabled: Bool = true
public var subagentEnabled: Bool = true
public var cveRemediatorAgentEnabled: Bool = true
public var agentModeAutoApprovalEnabled: Bool = false
enum CodingKeys: String, CodingKey {
case mcpContributionPointEnabled = "mcp.contributionPoint.enabled"
case customAgentEnabled = "customAgent.enabled"
case subagentEnabled = "subagent.enabled"
case cveRemediatorAgentEnabled = "cveRemediatorAgent.enabled"
case agentModeAutoApprovalEnabled = "agentMode.autoApproval.enabled"
}
}
public protocol CopilotPolicyNotifier {
var copilotPolicy: CopilotPolicy { get }
var policyDidChange: PassthroughSubject<CopilotPolicy, Never> { get }
func handleCopilotPolicyNotification(_ policy: CopilotPolicy)
}
public class CopilotPolicyNotifierImpl: CopilotPolicyNotifier {
public private(set) var copilotPolicy: CopilotPolicy
public static let shared = CopilotPolicyNotifierImpl()
public var policyDidChange: PassthroughSubject<CopilotPolicy, Never>
init(
copilotPolicy: CopilotPolicy = CopilotPolicy(),
policyDidChange: PassthroughSubject<CopilotPolicy, Never> = PassthroughSubject<CopilotPolicy, Never>()
) {
self.copilotPolicy = copilotPolicy
self.policyDidChange = policyDidChange
}
public func handleCopilotPolicyNotification(_ policy: CopilotPolicy) {
self.copilotPolicy = policy
DispatchQueue.main.async { [weak self] in
guard let self else { return }
self.policyDidChange.send(self.copilotPolicy)
DistributedNotificationCenter.default().post(name: .gitHubCopilotPolicyDidChange, object: nil)
}
}
}