A tiny friend in your Mac's notch and on your iPhone that keeps an eye on your AI coding agents: Claude Code, Codex, Cursor, Gemini CLI, Antigravity and more. Approve from the notch or your Lock Screen.
Swift ai-agentsanthropicantigravityclaudeclaude-codecodexcursordynamic-islandgemini-cliiosiphonlinuxmacosmacos-appmenubar-appnotchopen-sourceswiftswiftuiwindows
Fix model picker: sonnet-4-6 default, live list from API, readable errors
Louis Raille4c615953b79c
diff --git a/NotchBuddy/Sources/App/AppState.swift b/NotchBuddy/Sources/App/AppState.swiftindex baafa7eb..7ce7f890 100644--- a/NotchBuddy/Sources/App/AppState.swift+++ b/NotchBuddy/Sources/App/AppState.swift@@ -75,7 +75,7 @@ final class AppState: ObservableObject {}// Claude model used by the chat and the search — persisted- static let defaultClaudeModel = "claude-opus-5-5"+ static let defaultClaudeModel = "claude-sonnet-4-6"@Published var claudeModel: String = AppState.defaultClaudeModel {didSet { UserDefaults.standard.set(claudeModel, forKey: "claudeModel") }}diff --git a/NotchBuddy/Sources/App/ClaudeService.swift b/NotchBuddy/Sources/App/ClaudeService.swiftindex 9961cfb7..06dc9a54 100644--- a/NotchBuddy/Sources/App/ClaudeService.swift+++ b/NotchBuddy/Sources/App/ClaudeService.swift@@ -108,6 +108,26 @@ final class ClaudeService {private let endpoint = URL(string: "https://api.anthropic.com/v1/messages")!private let anthropicVersion = "2023-06-01"++ // MARK: - Model list++ /// Fetches available models from the Anthropic API in the order the API returns them+ /// (newest first). Returns an empty array on any error — callers fall back to a static list.+ static func fetchModels(apiKey: String) async -> [(id: String, label: String)] {+ guard let url = URL(string: "https://api.anthropic.com/v1/models?limit=100") else { return [] }+ var req = URLRequest(url: url, timeoutInterval: 10)+ req.setValue(apiKey, forHTTPHeaderField: "x-api-key")+ req.setValue("2023-06-01", forHTTPHeaderField: "anthropic-version")+ guard let (data, response) = try? await URLSession.shared.data(for: req),+ (response as? HTTPURLResponse)?.statusCode == 200,+ let json = try? JSONSerialization.jsonObject(with: data) as? [String: Any],+ let items = json["data"] as? [[String: Any]] else { return [] }+ return items.compactMap { item in+ guard let id = item["id"] as? String,+ let name = item["display_name"] as? String else { return nil }+ return (id: id, label: name)+ }+ }/// Chosen in Settings; falls back to the default when the field is left empty.private var model: String {let m = AppState.shared.claudeModel.trimmingCharacters(in: .whitespacesAndNewlines)@@ -176,7 +196,7 @@ final class ClaudeService {await handleChatResult(data, state: state)} catch {conversationMessages.removeLast()- await showError("Network error: \(error.localizedDescription)", state: state)+ await showError(error.localizedDescription, state: state)}}@@ -227,7 +247,7 @@ final class ClaudeService {let result = try await callAPI(body: body, key: key, beta: "web-search-2025-03-05")await handleResult(result, state: state)} catch {- await showError("Network error: \(error.localizedDescription)", state: state)+ await showError(error.localizedDescription, state: state)}}@@ -246,6 +266,20 @@ final class ClaudeService {let (data, response) = try await URLSession.shared.data(for: request)guard let http = response as? HTTPURLResponse, http.statusCode == 200 else {+ // Parse Anthropic error format: {"type":"error","error":{"type":"…","message":"…"}}+ if let json = try? JSONSerialization.jsonObject(with: data) as? [String: Any],+ let err = json["error"] as? [String: Any],+ let errType = err["type"] as? String,+ let errMsg = err["message"] as? String {+ if errType == "not_found_error" {+ let id = AppState.shared.claudeModel+ throw NSError(domain: "Claude", code: 0,+ userInfo: [NSLocalizedDescriptionKey:+ "Model not found: \(id). Pick another one in Settings."])+ }+ throw NSError(domain: "Claude", code: 0,+ userInfo: [NSLocalizedDescriptionKey: errMsg])+ }let msg = String(data: data, encoding: .utf8) ?? "unknown error"throw NSError(domain: "Claude", code: 0, userInfo: [NSLocalizedDescriptionKey: msg])}diff --git a/NotchBuddy/Sources/App/SettingsView.swift b/NotchBuddy/Sources/App/SettingsView.swiftindex 9b24e49b..e08ccd8b 100644--- a/NotchBuddy/Sources/App/SettingsView.swift+++ b/NotchBuddy/Sources/App/SettingsView.swift@@ -6,22 +6,26 @@ struct SettingsView: View {@ObservedObject private var state = AppState.shared@State private var apiKey: String = KeychainStore.shared.get("anthropic-api-key") ?? ""- // Claude model — presets plus a free field for any other model ID- private static let modelPresets: [(id: String, label: String)] = [- ("claude-opus-5-5", "Claude Opus 5.5"),- ("claude-fable-5-1", "Claude Fable 5.1"),- ("claude-sonnet-5-5", "Claude Sonnet 5.5"),- ("claude-haiku-4-5", "Claude Haiku 4.5"),+ // Claude model — dynamic list fetched from the API, static fallback if unavailable+ private static let fallbackModels: [(id: String, label: String)] = [+ ("claude-sonnet-4-6", "Claude Sonnet 4.6"),+ ("claude-sonnet-5-5", "Claude Sonnet 5.5"),+ ("claude-opus-5-5", "Claude Opus 5.5"),+ ("claude-haiku-4-5-20251001", "Claude Haiku 4.5"),]private static let customModelTag = "__custom__"+ @State private var fetchedModels: [(id: String, label: String)] = []@State private var modelChoice: String = {let m = AppState.shared.claudeModel- return SettingsView.modelPresets.contains { $0.id == m } ? m : SettingsView.customModelTag+ return SettingsView.fallbackModels.contains { $0.id == m } ? m : SettingsView.customModelTag}()@State private var customModel: String = {let m = AppState.shared.claudeModel- return SettingsView.modelPresets.contains { $0.id == m } ? "" : m+ return SettingsView.fallbackModels.contains { $0.id == m } ? "" : m}()+ private var displayModels: [(id: String, label: String)] {+ fetchedModels.isEmpty ? Self.fallbackModels : fetchedModels+ }@State private var launchAtStartup: Bool = (SMAppService.mainApp.status == .enabled)@State private var statusMessage: String = ""@State private var showDiff: Bool = false@@ -77,7 +81,7 @@ struct SettingsView: View {Divider().padding(.vertical, 2)Picker("Model", selection: $modelChoice) {- ForEach(Self.modelPresets, id: \.id) { preset in+ ForEach(displayModels, id: \.id) { preset inText(preset.label).tag(preset.id)}Text("Custom…").tag(Self.customModelTag)@@ -91,12 +95,12 @@ struct SettingsView: View {}if modelChoice == Self.customModelTag {- TextField("Model ID (e.g. claude-opus-5-5)", text: $customModel)+ TextField("Model ID (e.g. claude-sonnet-4-6)", text: $customModel).textFieldStyle(.roundedBorder).onChange(of: customModel) { _, value in applyCustomModel(value) }}- Text("Used by the chat and the search. Fable needs access on your API account.")+ Text("Used by the chat. The list comes from your Anthropic account.").font(.system(size: 11)).foregroundColor(.secondary)}@@ -382,6 +386,25 @@ struct SettingsView: View {}.padding(20)}+ .onAppear {+ guard fetchedModels.isEmpty,+ let key = KeychainStore.shared.get("anthropic-api-key"), !key.isEmpty else { return }+ Task {+ let models = await ClaudeService.fetchModels(apiKey: key)+ guard !models.isEmpty else { return }+ await MainActor.run {+ fetchedModels = models+ let m = state.claudeModel+ if models.contains(where: { $0.id == m }) {+ modelChoice = m+ customModel = ""+ } else if modelChoice != Self.customModelTag {+ modelChoice = Self.customModelTag+ customModel = m+ }+ }+ }+ }.frame(minWidth: 420, maxWidth: .infinity, minHeight: 320, maxHeight: .infinity)}