forked from github/CopilotForXcode
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathModelRowView.swift
More file actions
111 lines (101 loc) · 4.02 KB
/
ModelRowView.swift
File metadata and controls
111 lines (101 loc) · 4.02 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
import GitHubCopilotService
import Logger
import SharedUIComponents
import SwiftUI
struct ModelRowView: View {
var model: BYOKModelInfo
@ObservedObject var dataManager: BYOKModelManagerObservable
let isSelected: Bool
let onSelection: () -> Void
let onEditRequested: ((BYOKModelInfo) -> Void)? // New callback for edit action
@State private var isHovered: Bool = false
// Extract foreground colors to computed properties
private var primaryForegroundColor: Color {
isSelected ? Color(nsColor: .white) : .primary
}
private var secondaryForegroundColor: Color {
isSelected ? Color(nsColor: .white) : .secondary
}
var body: some View {
HStack(alignment: .center, spacing: 4) {
VStack(alignment: .leading, spacing: 4) {
HStack(alignment: .center, spacing: 4) {
Text(model.modelCapabilities?.name ?? model.modelId)
.foregroundColor(primaryForegroundColor)
Text(model.modelCapabilities?.name != nil ? model.modelId : "")
.foregroundColor(secondaryForegroundColor)
.font(.callout)
if model.isCustomModel {
Badge(
text: "Custom Model",
level: .info,
isSelected: isSelected
)
}
}
Group {
if let modelCapabilities = model.modelCapabilities,
modelCapabilities.toolCalling || modelCapabilities.vision {
HStack(spacing: 0) {
if modelCapabilities.toolCalling {
Text("Tools").help("Support Tool Calling")
}
if modelCapabilities.vision {
Text("・")
Text("Vision").help("Support Vision")
}
}
} else {
EmptyView()
}
}
.foregroundColor(secondaryForegroundColor)
}
Spacer()
// Show edit icon for custom model when selected or hovered
if model.isCustomModel {
Button(action: {
onEditRequested?(model)
}) {
Image(systemName: "gearshape")
}
.buttonStyle(HoverButtonStyle(
hoverColor: isSelected ? .white.opacity(0.1) : .hoverColor
))
.foregroundColor(primaryForegroundColor)
.opacity((isSelected || isHovered) ? 1.0 : 0.0)
.padding(.horizontal, 12)
}
Toggle(" ", isOn: Binding(
// Space in toggle label ensures proper checkbox centering alignment
get: { model.isRegistered },
set: { newValue in
// Only save when user directly toggles the checkbox
Task {
do {
var newModelInfo = model
newModelInfo.isRegistered = newValue
try await dataManager.saveModel(newModelInfo)
} catch {
Logger.client.error("Failed to update model: \(error.localizedDescription)")
}
}
}
))
.toggleStyle(.checkbox)
.labelStyle(.iconOnly)
.padding(.vertical, 4)
}
.padding(.leading, 36)
.padding(.trailing, 16)
.padding(.vertical, 4)
.contentShape(Rectangle())
.background(
isSelected ? Color(nsColor: .controlAccentColor) : Color.clear
)
.onTapGesture { onSelection() }
.onHover { hovering in
isHovered = hovering
}
}
}