63 lines · 2.0 KB · Swift
RawDownload
import AppKitimport CodexBarCoreimport Foundationimport SwiftUI struct ZaiProviderImplementation: ProviderImplementation {    let id: UsageProvider = .zai     @MainActor    func presentation(context _: ProviderPresentationContext) -> ProviderPresentation {        ProviderPresentation { _ in "api" }    }     @MainActor    func observeSettings(_ settings: SettingsStore) {        _ = settings.zaiAPIToken        _ = settings.zaiAPIRegion    }     @MainActor    func settingsSnapshot(context: ProviderSettingsSnapshotContext) -> ProviderSettingsSnapshotContribution? {        _ = context        return .zai(context.settings.zaiSettingsSnapshot())    }     @MainActor    func isAvailable(context: ProviderAvailabilityContext) -> Bool {        if ZaiSettingsReader.apiToken(environment: context.environment) != nil {            return true        }        context.settings.ensureZaiAPITokenLoaded()        return !context.settings.zaiAPIToken.trimmingCharacters(in: .whitespacesAndNewlines).isEmpty    }     @MainActor    func settingsPickers(context: ProviderSettingsContext) -> [ProviderSettingsPickerDescriptor] {        let binding = Binding(            get: { context.settings.zaiAPIRegion.rawValue },            set: { raw in                context.settings.zaiAPIRegion = ZaiAPIRegion(rawValue: raw) ?? .global            })        let options = ZaiAPIRegion.allCases.map {            ProviderSettingsPickerOption(id: $0.rawValue, title: $0.displayName)        }         return [            ProviderSettingsPickerDescriptor(                id: "zai-api-region",                title: "API region",                subtitle: "Use BigModel for the China mainland endpoints (open.bigmodel.cn).",                binding: binding,                options: options,                isVisible: nil,                onChange: nil),        ]    }     @MainActor    func settingsFields(context: ProviderSettingsContext) -> [ProviderSettingsFieldDescriptor] {        _ = context        return []    }}