Branchwell

Bucksley / app · bucksley.ai / Apps / Mac / AskSource.swift

Raw 2.7 KB on 2a3e7de1b9c1688dfa2cabc83b9d3a106dafd996
1import AppKit
2import SwiftUI
3import BucksleyKit
4import BucksleyUI
5
6/// Switching who answers Ask. Apple Intelligence stays on this Mac; any other source gets the person's
7/// numbers, so Bucksley shows what it would send and asks first. Used by Settings and the Ask screen.
8@MainActor
9enum AskSource {
10 static func confirm(_ source: AskProvider, current: AskProvider) -> Bool {
11 guard source != .apple else { return true }
12 let alert = NSAlert()
13 alert.messageText = "Send your financial data to \(source.title)?"
14 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" +
15 (source.usesTools ? ", and it can read more through Bucksley's read-only tools." : ".") +
16 " 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."
17 alert.addButton(withTitle: "Use \(source.title)")
18 alert.addButton(withTitle: "Keep \(current.title)")
19 return alert.runModal() == .alertFirstButtonReturn
20 }
21
22 static func choose(_ source: AskProvider, current: AskProvider, model: AppModel) {
23 guard source != current, confirm(source, current: current) else { return }
24 model.updateWorkspace { $0.settings.askProvider = source }
25 }
26}
27
28/// The "who answers Ask" pills, shared by Settings and the Agents screen.
29struct AskSourcePicker: View {
30 @Environment(AppModel.self) private var model
31 @Environment(\.palette) private var palette
32
33 var body: some View {
34 let provider = AskBucksley.provider(for: model.workspace.settings)
35 let sources: [AskProvider] = [.apple] + AskBucksley.installedAgents() + [.claude, .openai]
36 HStack(spacing: 6) {
37 ForEach(sources, id: \.self) { source in
38 let on = provider == source
39 Button { AskSource.choose(source, current: provider, model: model) } label: {
40 Label { Text(source.title) } icon: { ProviderMark(source, size: 12, tint: on ? palette.accentText : (source == .apple || source == .claude || source == .claudeCode ? nil : palette.text)) }
41 .font(.system(size: 12, weight: on ? .semibold : .regular))
42 .padding(.horizontal, 12).padding(.vertical, 6)
43 .foregroundStyle(on ? palette.accentText : palette.text)
44 .background(on ? palette.accent : palette.card, in: Capsule())
45 .overlay { Capsule().strokeBorder(on ? Color.clear : palette.line) }
46 }
47 .buttonStyle(.plain)
48 }
49 }
50 }
51}