forked from github/CopilotForXcode
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMCPRegistryURLSheet.swift
More file actions
75 lines (67 loc) · 2.81 KB
/
MCPRegistryURLSheet.swift
File metadata and controls
75 lines (67 loc) · 2.81 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
import GitHubCopilotService
import SwiftUI
import SharedUIComponents
struct MCPRegistryURLSheet: View {
@AppStorage(\.mcpRegistryBaseURL) private var mcpRegistryBaseURL
@AppStorage(\.mcpRegistryBaseURLHistory) private var mcpRegistryBaseURLHistory
@Environment(\.dismiss) private var dismiss
@State private var originalMcpRegistryBaseURL: String = ""
@State private var isFormValid: Bool = true
let mcpRegistryEntry: MCPRegistryEntry?
let onURLUpdated: (() -> Void)?
init(mcpRegistryEntry: MCPRegistryEntry? = nil, onURLUpdated: (() -> Void)? = nil) {
self.mcpRegistryEntry = mcpRegistryEntry
self.onURLUpdated = onURLUpdated
}
var body: some View {
Form {
VStack(alignment: .center, spacing: 20) {
HStack(alignment: .center) {
Spacer()
Text("MCP Registry Base URL").font(.headline)
Spacer()
AdaptiveHelpLink(action: openHelpLink)
}
VStack(alignment: .leading, spacing: 4) {
MCPRegistryURLInputField(
urlText: $originalMcpRegistryBaseURL,
isSheet: true,
mcpRegistryEntry: mcpRegistryEntry,
onValidationChange: { isValid in
isFormValid = isValid
}
)
}
HStack(spacing: 8) {
Spacer()
Button("Cancel", role: .cancel) { dismiss() }
Button("Update") {
// Check if URL changed before updating
originalMcpRegistryBaseURL = originalMcpRegistryBaseURL
.trimmingCharacters(in: .whitespacesAndNewlines)
.trimmingCharacters(in: CharacterSet(charactersIn: "/"))
if originalMcpRegistryBaseURL != mcpRegistryBaseURL {
mcpRegistryBaseURL = originalMcpRegistryBaseURL
onURLUpdated?()
}
dismiss()
}
.buttonStyle(.borderedProminent)
.disabled(!isFormValid || mcpRegistryEntry?.registryAccess == .registryOnly)
}
}
.textFieldStyle(.plain)
.multilineTextAlignment(.trailing)
.padding(20)
}
.onAppear {
loadExistingURL()
}
}
private func loadExistingURL() {
originalMcpRegistryBaseURL = mcpRegistryBaseURL
}
private func openHelpLink() {
NSWorkspace.shared.open(URL(string: "https://docs.github.com/en/copilot/how-tos/provide-context/use-mcp/select-an-mcp-registry")!)
}
}