Skip to content

Commit 8770b9e

Browse files
committed
Pre-release 0.44.151
1 parent a757a4a commit 8770b9e

File tree

15 files changed

+224
-22
lines changed

15 files changed

+224
-22
lines changed

Core/Package.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -254,6 +254,7 @@ let package = Package(
254254
.target(
255255
name: "GitHubCopilotViewModel",
256256
dependencies: [
257+
"Client",
257258
.product(name: "GitHubCopilotService", package: "Tool"),
258259
.product(name: "ComposableArchitecture", package: "swift-composable-architecture"),
259260
.product(name: "Status", package: "Tool"),

Core/Sources/ConversationTab/ModeAndModelPicker/ModelManagerUtils.swift

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,7 @@ public extension CopilotModelManager {
179179
static func getDefaultChatModel(scope: PromptTemplateScope = .chatPanel) -> LLMModel? {
180180
let LLMs = CopilotModelManager.getAvailableLLMs()
181181
let LLMsInScope = LLMs.filter({ $0.scopes.contains(scope) })
182-
let defaultModel = LLMsInScope.first(where: { $0.isChatDefault })
182+
let defaultModel = LLMsInScope.first(where: { $0.isChatDefault && !$0.isAutoModel })
183183
// If a default model is found, return it
184184
if let defaultModel = defaultModel {
185185
return LLMModel(
@@ -202,7 +202,7 @@ public extension CopilotModelManager {
202202
}
203203

204204
// If no default model is found, fallback to the first available model
205-
if let firstModel = LLMsInScope.first {
205+
if let firstModel = LLMsInScope.first(where: { !$0.isAutoModel }) {
206206
return LLMModel(
207207
modelName: firstModel.modelName,
208208
modelFamily: firstModel.modelFamily,
@@ -270,3 +270,7 @@ public extension LLMModel {
270270
/// Apply to `Copilot Models`
271271
var isAutoModel: Bool { isStandardModel && modelName == "Auto" }
272272
}
273+
274+
extension CopilotModel {
275+
var isAutoModel: Bool { modelName == "Auto" }
276+
}

Core/Sources/GitHubCopilotViewModel/GitHubCopilotViewModel.swift

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import ComposableArchitecture
44
import Status
55
import SwiftUI
66
import Cache
7+
import Client
78

89
public struct SignInResponse {
910
public let status: SignInInitiateStatus
@@ -126,7 +127,7 @@ public class GitHubCopilotViewModel: ObservableObject {
126127
waitingForSignIn = false
127128
}
128129

129-
public func copyAndOpen() {
130+
public func copyAndOpen(fromHostApp: Bool = false) {
130131
waitingForSignIn = true
131132
guard let signInResponse else {
132133
toast("Missing sign in details.", .error)
@@ -137,10 +138,10 @@ public class GitHubCopilotViewModel: ObservableObject {
137138
pasteboard.setString(signInResponse.userCode, forType: NSPasteboard.PasteboardType.string)
138139
toast("Sign-in code \(signInResponse.userCode) copied", .info)
139140
NSWorkspace.shared.open(signInResponse.verificationURL)
140-
waitForSignIn()
141+
waitForSignIn(fromHostApp: fromHostApp)
141142
}
142143

143-
public func waitForSignIn() {
144+
public func waitForSignIn(fromHostApp: Bool = false) {
144145
Task {
145146
do {
146147
guard waitingForSignIn else { return }
@@ -155,14 +156,19 @@ public class GitHubCopilotViewModel: ObservableObject {
155156
self.status = status
156157
await Status.shared.updateAuthStatus(.loggedIn, username: username)
157158
broadcastStatusChange()
158-
let models = try? await service.models()
159-
if let models = models, !models.isEmpty {
160-
CopilotModelManager.updateLLMs(models)
159+
if !fromHostApp {
160+
let models = try? await service.models()
161+
if let models = models, !models.isEmpty {
162+
CopilotModelManager.updateLLMs(models)
163+
}
164+
} else {
165+
let xpcService = try getService()
166+
_ = try? await xpcService.updateCopilotModels()
161167
}
162168
} catch let error as GitHubCopilotError {
163169
switch error {
164170
case .languageServerError(.timeout):
165-
waitForSignIn()
171+
waitForSignIn(fromHostApp: fromHostApp)
166172
return
167173
case .languageServerError(
168174
.serverError(

Core/Sources/HostApp/AdvancedSettings/SuggestionSection.swift

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ struct SuggestionSection: View {
77
@AppStorage(\.realtimeNESToggle) var realtimeNESToggle
88
@State var isSuggestionFeatureDisabledLanguageListViewOpen = false
99
@State private var shouldPresentTurnoffSheet = false
10+
@ObservedObject private var featureFlags = FeatureFlagManager.shared
1011

1112
var realtimeSuggestionBinding : Binding<Bool> {
1213
Binding(
@@ -27,11 +28,15 @@ struct SuggestionSection: View {
2728
title: "Enable completions while typing",
2829
isOn: realtimeSuggestionBinding
2930
)
30-
Divider()
31-
SettingsToggle(
32-
title: "Enable Next Edit Suggestions (NES)",
33-
isOn: $realtimeNESToggle
34-
)
31+
32+
if featureFlags.isEditorPreviewEnabled {
33+
Divider()
34+
SettingsToggle(
35+
title: "Enable Next Edit Suggestions (NES)",
36+
isOn: $realtimeNESToggle
37+
)
38+
}
39+
3540
Divider()
3641
SettingsToggle(
3742
title: "Accept suggestions with Tab",

Core/Sources/HostApp/GeneralSettings/CopilotConnectionView.swift

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,10 @@ struct CopilotConnectionView: View {
5757
isPresented: $viewModel.isSignInAlertPresented,
5858
presenting: viewModel.signInResponse) { _ in
5959
Button("Cancel", role: .cancel, action: {})
60-
Button("Copy Code and Open", action: viewModel.copyAndOpen)
60+
Button(
61+
"Copy Code and Open",
62+
action: { viewModel.copyAndOpen(fromHostApp: true) }
63+
)
6164
} message: { response in
6265
Text("""
6366
Please enter the above code in the \

Core/Sources/Service/SuggestionCommandHandler/PseudoCommandHandler.swift

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import WorkspaceSuggestionService
1010
import XcodeInspector
1111
import XPCShared
1212
import AXHelper
13+
import GitHubCopilotService
1314

1415
/// It's used to run some commands without really triggering the menu bar item.
1516
///
@@ -59,7 +60,8 @@ struct PseudoCommandHandler {
5960
if Task.isCancelled { return }
6061

6162
let codeCompletionEnabled = UserDefaults.shared.value(for: \.realtimeSuggestionToggle)
62-
let nesEnabled = UserDefaults.shared.value(for: \.realtimeNESToggle)
63+
// Enabled both by Feature Flag and User.
64+
let nesEnabled = FeatureFlagNotifierImpl.shared.featureFlags.editorPreviewFeatures && UserDefaults.shared.value(for: \.realtimeNESToggle)
6365
guard codeCompletionEnabled || nesEnabled else {
6466
cleanupAllSuggestions(filespace: filespace, presenter: nil)
6567
return

Core/Sources/Service/XPCService.swift

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -594,6 +594,21 @@ public class XPCService: NSObject, XPCServiceProtocol {
594594
}
595595
}
596596

597+
public func updateCopilotModels(withReply reply: @escaping (Data?, Error?) -> Void) {
598+
Task { @MainActor in
599+
do {
600+
let service = try GitHubCopilotViewModel.shared.getGitHubCopilotAuthService()
601+
let models = try await service.models()
602+
CopilotModelManager.updateLLMs(models)
603+
let data = try JSONEncoder().encode(models)
604+
reply(data, nil)
605+
} catch {
606+
Logger.service.error("Failed to get models: \(error.localizedDescription)")
607+
reply(nil, NSError.from(error))
608+
}
609+
}
610+
}
611+
597612
// MARK: - BYOK
598613
public func saveBYOKApiKey(_ params: Data, withReply reply: @escaping (Data?) -> Void) {
599614
let decoder = JSONDecoder()

Core/Sources/SuggestionWidget/ChatWindow/ChatLoginView.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ struct ChatLoginView: View {
7777
Button("Cancel", role: .cancel, action: {})
7878
.scaledFont(.body)
7979

80-
Button("Copy Code and Open", action: viewModel.copyAndOpen)
80+
Button("Copy Code and Open", action: { viewModel.copyAndOpen(fromHostApp: false) })
8181
.scaledFont(.body)
8282
} message: { response in
8383
Text("""
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
import GitHubCopilotService
2+
3+
extension WidgetWindowsController {
4+
5+
@MainActor
6+
var isNESFeatureFlagEnabled: Bool {
7+
FeatureFlagNotifierImpl.shared.featureFlags.editorPreviewFeatures
8+
}
9+
10+
func setupFeatureFlagObservers() {
11+
Task { @MainActor in
12+
let sinker = FeatureFlagNotifierImpl.shared.featureFlagsDidChange
13+
.sink(receiveValue: { [weak self] _ in
14+
self?.onFeatureFlagChanged()
15+
})
16+
17+
await self.storeCancellables([sinker])
18+
}
19+
}
20+
21+
@MainActor
22+
func onFeatureFlagChanged() {
23+
if !isNESFeatureFlagEnabled {
24+
hideAllNESWindows()
25+
}
26+
}
27+
}

Core/Sources/SuggestionWidget/Extensions/WidgetWindowsController+NES.swift

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import AppKit
2+
import GitHubCopilotService
23

34
extension WidgetWindowsController {
45
func setupNESSuggestionPanelObservers() {
@@ -16,6 +17,40 @@ extension WidgetWindowsController {
1617
}
1718
}
1819

20+
@MainActor
21+
func applyOpacityForNESWindows(by noFocus: Bool) {
22+
guard !noFocus, isNESFeatureFlagEnabled
23+
else {
24+
hideAllNESWindows()
25+
return
26+
}
27+
28+
displayAllNESWindows()
29+
}
30+
31+
@MainActor
32+
func hideAllNESWindows() {
33+
windows.nesMenuWindow.alphaValue = 0
34+
windows.nesDiffWindow.setIsVisible(false)
35+
36+
hideNESDiffWindow()
37+
38+
windows.nesNotificationWindow.alphaValue = 0
39+
windows.nesNotificationWindow.setIsVisible(false)
40+
}
41+
42+
@MainActor
43+
func displayAllNESWindows() {
44+
windows.nesMenuWindow.alphaValue = 1
45+
windows.nesDiffWindow.setIsVisible(true)
46+
47+
windows.nesDiffWindow.alphaValue = 1
48+
windows.nesDiffWindow.setIsVisible(true)
49+
50+
windows.nesNotificationWindow.alphaValue = 1
51+
windows.nesNotificationWindow.setIsVisible(true)
52+
}
53+
1954
@MainActor
2055
func hideNESDiffWindow() {
2156
NSAnimationContext.runAnimationGroup { context in

0 commit comments

Comments
 (0)