Skip to content

Commit

Permalink
Pre-release 0.31.106
Browse files Browse the repository at this point in the history
  • Loading branch information
actions-user committed Mar 10, 2025
1 parent b9029ca commit 37407e4
Show file tree
Hide file tree
Showing 8 changed files with 83 additions and 25 deletions.
36 changes: 28 additions & 8 deletions Core/Sources/ConversationTab/ModelPicker.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import SwiftUI
import ChatService
import Persist
import ComposableArchitecture
import GitHubCopilotService

public let SELECTED_LLM_KEY = "selectedLLM"

Expand All @@ -27,6 +28,18 @@ extension AppState {
}
}

extension CopilotModelManager {
static func getAvailableChatLLMs() -> [LLMModel] {
let LLMs = CopilotModelManager.getAvailableLLMs()
let availableModels = LLMs.filter(
{ $0.scopes.contains(.chatPanel) }
).map {
LLMModel(modelName: $0.modelName, modelFamily: $0.modelFamily)
}
return availableModels.isEmpty ? [defaultModel] : availableModels
}
}

struct LLMModel: Codable, Hashable {
let modelName: String
let modelFamily: String
Expand All @@ -35,12 +48,15 @@ struct LLMModel: Codable, Hashable {
let defaultModel = LLMModel(modelName: "GPT-4o", modelFamily: "gpt-4o")
struct ModelPicker: View {
@State private var selectedModel = defaultModel.modelName
@State private var models: [LLMModel] = [ defaultModel ]
@State private var isHovered = false
@State private var isPressed = false

init() {
self.updateCurrentModel()
self.updateCurrentModel()
}

var models: [LLMModel] {
CopilotModelManager.getAvailableChatLLMs()
}

func updateCurrentModel() {
Expand Down Expand Up @@ -74,13 +90,9 @@ struct ModelPicker: View {
isHovered = hovering
}
.onAppear() {
updateCurrentModel()
Task {
updateCurrentModel()
self.models = await ChatService.shared.copilotModels().filter(
{ $0.scopes.contains(.chatPanel) }
).map {
LLMModel(modelName: $0.modelName, modelFamily: $0.modelFamily)
}
await refreshModels()
}
}
.help("Pick Model")
Expand All @@ -93,6 +105,14 @@ struct ModelPicker: View {
let width = selectedModel.size(withAttributes: attributes).width
return CGFloat(width + 20)
}

@MainActor
func refreshModels() async {
let copilotModels = await ChatService.shared.copilotModels()
if !copilotModels.isEmpty {
CopilotModelManager.updateLLMs(copilotModels)
}
}
}

struct ModelPicker_Previews: PreviewProvider {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,10 @@ public class GitHubCopilotViewModel: ObservableObject {
waitingForSignIn = false
self.username = username
self.status = status
let models = try? await service.models()
if let models = models, !models.isEmpty {
CopilotModelManager.updateLLMs(models)
}
await Status.shared.updateAuthStatus(.loggedIn, username: username)
broadcastStatusChange()
} catch let error as GitHubCopilotError {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,7 @@ struct PseudoCommandHandler {
if now.timeIntervalSince(lastBundleNotFoundTime) > 60 * 60 {
Self.lastBundleNotFoundTime = now
toast.toast(
title: "Extension Permission Not Granted",
title: "GitHub Copilot Extension Permission Not Granted",
content: """
Enable Extensions → Xcode Source Editor → GitHub Copilot \
for Xcode for faster and full-featured code completion. \
Expand All @@ -287,7 +287,7 @@ struct PseudoCommandHandler {
content: "Quit and restart Xcode to enable extension.",
level: .warning,
button: .init(
title: "Restart",
title: "Restart Xcode",
action: { NSWorkspace.restartXcode() }
)
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -744,7 +744,7 @@ public final class WidgetWindows {
it.isReleasedWhenClosed = false
it.isOpaque = false
it.backgroundColor = .clear
it.level = widgetLevel(0)
it.level = widgetLevel(2)
it.collectionBehavior = [.fullScreenAuxiliary, .transient, .canJoinAllSpaces]
it.hasShadow = false
it.contentView = NSHostingView(
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import ConversationServiceProvider

public class CopilotModelManager {
private static var availableLLMs: [CopilotModel] = []

public static func updateLLMs(_ models: [CopilotModel]) {
availableLLMs = models
}

public static func getAvailableLLMs() -> [CopilotModel] {
return availableLLMs
}

public static func hasLLMs() -> Bool {
return !availableLLMs.isEmpty
}

public static func clearLLMs() {
availableLLMs = []
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -683,6 +683,12 @@ public final class GitHubCopilotService:
private func updateServiceAuthStatus(_ status: GitHubCopilotRequest.CheckStatus.Response) async {
Logger.gitHubCopilot.info("check status response: \(status)")
if status.status == .ok || status.status == .maybeOk {
if !CopilotModelManager.hasLLMs() {
let models = try? await models()
if let models = models, !models.isEmpty {
CopilotModelManager.updateLLMs(models)
}
}
await Status.shared.updateAuthStatus(.loggedIn, username: status.user)
await unwatchAuthStatus()
} else if status.status == .notAuthorized {
Expand Down Expand Up @@ -874,6 +880,8 @@ public final class GitHubCopilotService:

if let signoutError {
throw signoutError
} else {
CopilotModelManager.clearLLMs()
}
}
}
Expand Down
10 changes: 5 additions & 5 deletions Tool/Sources/Toast/NotificationView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ struct AutoDismissMessage: View {
message.level.color as Color,
in: RoundedRectangle(cornerRadius: 8)
)
.frame(minWidth: 300)
}
}

Expand Down Expand Up @@ -53,7 +54,10 @@ public struct NotificationView: View {
Spacer()

if let button = message.button {
Button(action: button.action) {
Button(action: {
button.action()
onDismiss()
}) {
Text(button.title)
.padding(.horizontal, 7)
.padding(.vertical, 3)
Expand All @@ -76,10 +80,6 @@ public struct NotificationView: View {
} else {
AutoDismissMessage(message: message)
.frame(maxWidth: .infinity)
.overlay {
RoundedRectangle(cornerRadius: 8)
.stroke(Color.black.opacity(0.3), lineWidth: 1)
}
}
}
}
23 changes: 14 additions & 9 deletions Tool/Sources/Toast/Toast.swift
Original file line number Diff line number Diff line change
Expand Up @@ -271,15 +271,20 @@ public extension NSWorkspace {
}
NSWorkspace.shared.open(URL(string: urlString)!)
} else {
let script = NSAppleScript(
source: """
tell application "System Preferences"
activate
set the current pane to pane id "com.apple.preferences.extensions"
end tell
"""
)
script?.executeAndReturnError(nil)
let process = Process()
process.executableURL = URL(fileURLWithPath: "/usr/bin/open")
process.arguments = [
"-b",
"com.apple.systempreferences",
"/System/Library/PreferencePanes/Extensions.prefPane"
]

do {
try process.run()
} catch {
// Handle error silently
return
}
}
}

Expand Down

0 comments on commit 37407e4

Please sign in to comment.