import AppKit import SwiftUI import BucksleyKit import BucksleyUI /// Switching who answers Ask. Apple Intelligence stays on this Mac; any other source gets the person's /// numbers, so Bucksley shows what it would send and asks first. Used by Settings and the Ask screen. @MainActor enum AskSource { static func confirm(_ source: AskProvider, current: AskProvider) -> Bool { guard source != .apple else { return true } let alert = NSAlert() alert.messageText = "Send your financial data to \(source.title)?" alert.informativeText = "When you ask a question, \(source.title) gets your question, your account names and balances, spending totals, budgets, recurring charges and up to 40 recent transactions" + (source.usesTools ? ", and it can read more through Bucksley's read-only tools." : ".") + " That goes to \(source.company) under your own account and their terms. Apple Intelligence keeps everything on this Mac, and you can switch back any time in Settings." alert.addButton(withTitle: "Use \(source.title)") alert.addButton(withTitle: "Keep \(current.title)") return alert.runModal() == .alertFirstButtonReturn } static func choose(_ source: AskProvider, current: AskProvider, model: AppModel) { guard source != current, confirm(source, current: current) else { return } model.updateWorkspace { $0.settings.askProvider = source } } } /// The "who answers Ask" pills, shared by Settings and the Agents screen. struct AskSourcePicker: View { @Environment(AppModel.self) private var model @Environment(\.palette) private var palette var body: some View { let provider = AskBucksley.provider(for: model.workspace.settings) let sources: [AskProvider] = [.apple] + AskBucksley.installedAgents() + [.claude, .openai] HStack(spacing: 6) { ForEach(sources, id: \.self) { source in let on = provider == source Button { AskSource.choose(source, current: provider, model: model) } label: { Label { Text(source.title) } icon: { ProviderMark(source, size: 12, tint: on ? palette.accentText : (source == .apple || source == .claude || source == .claudeCode ? nil : palette.text)) } .font(.system(size: 12, weight: on ? .semibold : .regular)) .padding(.horizontal, 12).padding(.vertical, 6) .foregroundStyle(on ? palette.accentText : palette.text) .background(on ? palette.accent : palette.card, in: Capsule()) .overlay { Capsule().strokeBorder(on ? Color.clear : palette.line) } } .buttonStyle(.plain) } } } }