Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions Sources/CodexBar/ProviderRegistry.swift
Original file line number Diff line number Diff line change
Expand Up @@ -122,9 +122,14 @@ struct ProviderRegistry {
tokenOverride: tokenOverride,
codexActiveSourceOverride: codexActiveSourceOverride)
for implementation in ProviderCatalog.all {
if let contribution = implementation.settingsSnapshot(context: context) {
builder.apply(contribution)
let registration = ProviderDescriptorRegistry.descriptor(for: implementation.id).settingsSection
guard let contribution = implementation.settingsSnapshot(context: context) else {
preconditionFailure("Missing settings snapshot section for provider '\(implementation.id.rawValue)'")
}
guard registration.accepts(contribution) else {
preconditionFailure("Mismatched settings snapshot section for provider '\(implementation.id.rawValue)'")
}
builder.apply(contribution)
}
return builder.build()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,6 @@ struct OpenRouterProviderImplementation: ProviderImplementation {
_ = settings.openRouterAPIToken
}

@MainActor
func settingsSnapshot(context: ProviderSettingsSnapshotContext) -> ProviderSettingsSnapshotContribution? {
_ = context
return nil
}

@MainActor
func isAvailable(context: ProviderAvailabilityContext) -> Bool {
if OpenRouterSettingsReader.apiToken(environment: context.environment) != nil {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ extension ProviderImplementation {

@MainActor
func settingsSnapshot(context _: ProviderSettingsSnapshotContext) -> ProviderSettingsSnapshotContribution? {
nil
ProviderDescriptorRegistry.descriptor(for: self.id).settingsSection.defaultContribution
}

@MainActor
Expand Down
61 changes: 31 additions & 30 deletions Sources/CodexBarCLI/TokenAccountCLI.swift
Original file line number Diff line number Diff line change
Expand Up @@ -296,36 +296,37 @@ struct TokenAccountCLIContext {
zoommate: ProviderSettingsSnapshot.ZoomMateProviderSettings? = nil,
notion: ProviderSettingsSnapshot.NotionProviderSettings? = nil) -> ProviderSettingsSnapshot
{
ProviderSettingsSnapshot.make(
codex: codex,
claude: claude,
cursor: cursor,
opencode: opencode,
opencodego: opencodego,
alibaba: alibaba,
alibabaTokenPlan: alibabaTokenPlan,
qwenCloud: qwenCloud,
factory: factory,
minimax: minimax,
manus: manus,
zai: zai,
kilo: kilo,
kimi: kimi,
longcat: longcat,
augment: augment,
moonshot: moonshot,
amp: amp,
zoommate: zoommate,
notion: notion,
commandcode: commandcode,
ollama: ollama,
jetbrains: jetbrains,
perplexity: perplexity,
mimo: mimo,
abacus: abacus,
mistral: mistral,
qoder: qoder,
stepfun: stepfun)
ProviderSettingsSnapshot(contributions: [
codex.map(ProviderSettingsSnapshotContribution.codex),
claude.map(ProviderSettingsSnapshotContribution.claude),
cursor.map(ProviderSettingsSnapshotContribution.cursor),
opencode.map(ProviderSettingsSnapshotContribution.opencode),
opencodego.map(ProviderSettingsSnapshotContribution.opencodego),
alibaba.map(ProviderSettingsSnapshotContribution.alibaba),
alibabaTokenPlan.map(ProviderSettingsSnapshotContribution.alibabaTokenPlan),
qwenCloud.map(ProviderSettingsSnapshotContribution.qwenCloud),
factory.map(ProviderSettingsSnapshotContribution.factory),
minimax.map(ProviderSettingsSnapshotContribution.minimax),
manus.map(ProviderSettingsSnapshotContribution.manus),
zai.map(ProviderSettingsSnapshotContribution.zai),
kilo.map(ProviderSettingsSnapshotContribution.kilo),
kimi.map(ProviderSettingsSnapshotContribution.kimi),
longcat.map(ProviderSettingsSnapshotContribution.longcat),
augment.map(ProviderSettingsSnapshotContribution.augment),
moonshot.map(ProviderSettingsSnapshotContribution.moonshot),
amp.map(ProviderSettingsSnapshotContribution.amp),
zoommate.map(ProviderSettingsSnapshotContribution.zoommate),
notion.map(ProviderSettingsSnapshotContribution.notion),
commandcode.map(ProviderSettingsSnapshotContribution.commandcode),
ollama.map(ProviderSettingsSnapshotContribution.ollama),
jetbrains.map(ProviderSettingsSnapshotContribution.jetbrains),
perplexity.map(ProviderSettingsSnapshotContribution.perplexity),
mimo.map(ProviderSettingsSnapshotContribution.mimo),
abacus.map(ProviderSettingsSnapshotContribution.abacus),
mistral.map(ProviderSettingsSnapshotContribution.mistral),
qoder.map(ProviderSettingsSnapshotContribution.qoder),
stepfun.map(ProviderSettingsSnapshotContribution.stepfun),
].compactMap(\.self))
}

private func makeCodexSettingsSnapshot(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ public enum AbacusProviderDescriptor {
static func makeDescriptor() -> ProviderDescriptor {
ProviderDescriptor(
id: .abacus,
settingsSection: .init(AbacusProviderSettingsKey.self),
metadata: ProviderMetadata(
id: .abacus,
displayName: "Abacus AI",
Expand Down
33 changes: 33 additions & 0 deletions Sources/CodexBarCore/Providers/Abacus/AbacusProviderSettings.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import Foundation

public struct AbacusProviderSettings: ProviderCookieSettings {
public let cookieSource: ProviderCookieSource
public let manualCookieHeader: String?

public init(cookieSource: ProviderCookieSource, manualCookieHeader: String?) {
self.cookieSource = cookieSource
self.manualCookieHeader = manualCookieHeader
}
}

public enum AbacusProviderSettingsKey: ProviderSettingsSectionKey {
public static let providerID = ProviderInstanceID.abacus
public typealias Section = AbacusProviderSettings
}

extension ProviderSettingsSnapshot {
public typealias AbacusProviderSettings = CodexBarCore.AbacusProviderSettings
public var abacus: AbacusProviderSettings? {
self[AbacusProviderSettingsKey.self]
}

public static func make(abacus: AbacusProviderSettings?) -> Self {
self.make(abacus, for: AbacusProviderSettingsKey.self)
}
}

extension ProviderSettingsSnapshotContribution {
public static func abacus(_ section: AbacusProviderSettings) -> Self {
Self(section, for: AbacusProviderSettingsKey.self)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ public enum AlibabaCodingPlanProviderDescriptor {

return ProviderDescriptor(
id: .alibaba,
settingsSection: .init(AlibabaCodingPlanProviderSettingsKey.self),
metadata: ProviderMetadata(
id: .alibaba,
displayName: "Alibaba",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
import Foundation

public struct AlibabaCodingPlanProviderSettings: Sendable {
public let cookieSource: ProviderCookieSource
public let manualCookieHeader: String?
public let apiRegion: AlibabaCodingPlanAPIRegion

public init(
cookieSource: ProviderCookieSource = .auto,
manualCookieHeader: String? = nil,
apiRegion: AlibabaCodingPlanAPIRegion = .international)
{
self.cookieSource = cookieSource
self.manualCookieHeader = manualCookieHeader
self.apiRegion = apiRegion
}
}

public struct AlibabaTokenPlanProviderSettings: ProviderCookieSettings {
public let cookieSource: ProviderCookieSource
public let manualCookieHeader: String?
public let apiRegion: AlibabaTokenPlanAPIRegion

public init(
cookieSource: ProviderCookieSource = .auto,
manualCookieHeader: String? = nil,
apiRegion: AlibabaTokenPlanAPIRegion = .international)
{
self.cookieSource = cookieSource
self.manualCookieHeader = manualCookieHeader
self.apiRegion = apiRegion
}

public init(cookieSource: ProviderCookieSource, manualCookieHeader: String?) {
self.init(cookieSource: cookieSource, manualCookieHeader: manualCookieHeader, apiRegion: .international)
}
}

public enum AlibabaCodingPlanProviderSettingsKey: ProviderSettingsSectionKey {
public static let providerID = ProviderInstanceID.alibaba
public typealias Section = AlibabaCodingPlanProviderSettings
}

public enum AlibabaTokenPlanProviderSettingsKey: ProviderSettingsSectionKey {
public static let providerID = ProviderInstanceID.alibabatokenplan
public typealias Section = AlibabaTokenPlanProviderSettings
}

extension ProviderSettingsSnapshot {
public typealias AlibabaCodingPlanProviderSettings = CodexBarCore.AlibabaCodingPlanProviderSettings
public typealias AlibabaTokenPlanProviderSettings = CodexBarCore.AlibabaTokenPlanProviderSettings
public var alibaba: AlibabaCodingPlanProviderSettings? {
self[AlibabaCodingPlanProviderSettingsKey.self]
}

public var alibabaTokenPlan: AlibabaTokenPlanProviderSettings? {
self[AlibabaTokenPlanProviderSettingsKey.self]
}

public static func make(alibaba: AlibabaCodingPlanProviderSettings?) -> Self {
self.make(alibaba, for: AlibabaCodingPlanProviderSettingsKey.self)
}

public static func make(alibabaTokenPlan: AlibabaTokenPlanProviderSettings?) -> Self {
self.make(alibabaTokenPlan, for: AlibabaTokenPlanProviderSettingsKey.self)
}
}

extension ProviderSettingsSnapshotContribution {
public static func alibaba(_ section: AlibabaCodingPlanProviderSettings) -> Self {
Self(section, for: AlibabaCodingPlanProviderSettingsKey.self)
}

public static func alibabaTokenPlan(_ section: AlibabaTokenPlanProviderSettings) -> Self {
Self(section, for: AlibabaTokenPlanProviderSettingsKey.self)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ public enum AlibabaTokenPlanProviderDescriptor {

return ProviderDescriptor(
id: .alibabatokenplan,
settingsSection: .init(AlibabaTokenPlanProviderSettingsKey.self),
metadata: ProviderMetadata(
id: .alibabatokenplan,
displayName: "Alibaba Token Plan",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ public enum AmpProviderDescriptor {
static func makeDescriptor() -> ProviderDescriptor {
ProviderDescriptor(
id: .amp,
settingsSection: .init(AmpProviderSettingsKey.self),
metadata: ProviderMetadata(
id: .amp,
displayName: "Amp",
Expand Down
33 changes: 33 additions & 0 deletions Sources/CodexBarCore/Providers/Amp/AmpProviderSettings.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import Foundation

public struct AmpProviderSettings: ProviderCookieSettings {
public let cookieSource: ProviderCookieSource
public let manualCookieHeader: String?

public init(cookieSource: ProviderCookieSource, manualCookieHeader: String?) {
self.cookieSource = cookieSource
self.manualCookieHeader = manualCookieHeader
}
}

public enum AmpProviderSettingsKey: ProviderSettingsSectionKey {
public static let providerID = ProviderInstanceID.amp
public typealias Section = AmpProviderSettings
}

extension ProviderSettingsSnapshot {
public typealias AmpProviderSettings = CodexBarCore.AmpProviderSettings
public var amp: AmpProviderSettings? {
self[AmpProviderSettingsKey.self]
}

public static func make(amp: AmpProviderSettings?) -> Self {
self.make(amp, for: AmpProviderSettingsKey.self)
}
}

extension ProviderSettingsSnapshotContribution {
public static func amp(_ section: AmpProviderSettings) -> Self {
Self(section, for: AmpProviderSettingsKey.self)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ public enum AugmentProviderDescriptor {

return ProviderDescriptor(
id: .augment,
settingsSection: .init(AugmentProviderSettingsKey.self),
metadata: ProviderMetadata(
id: .augment,
displayName: "Augment",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import Foundation

public struct AugmentProviderSettings: ProviderCookieSettings {
public let cookieSource: ProviderCookieSource
public let manualCookieHeader: String?

public init(cookieSource: ProviderCookieSource, manualCookieHeader: String?) {
self.cookieSource = cookieSource
self.manualCookieHeader = manualCookieHeader
}
}

public enum AugmentProviderSettingsKey: ProviderSettingsSectionKey {
public static let providerID = ProviderInstanceID.augment
public typealias Section = AugmentProviderSettings
}

extension ProviderSettingsSnapshot {
public typealias AugmentProviderSettings = CodexBarCore.AugmentProviderSettings
public var augment: AugmentProviderSettings? {
self[AugmentProviderSettingsKey.self]
}

public static func make(augment: AugmentProviderSettings?) -> Self {
self.make(augment, for: AugmentProviderSettingsKey.self)
}
}

extension ProviderSettingsSnapshotContribution {
public static func augment(_ section: AugmentProviderSettings) -> Self {
Self(section, for: AugmentProviderSettingsKey.self)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ public enum ClaudeProviderDescriptor {
static func makeDescriptor() -> ProviderDescriptor {
ProviderDescriptor(
id: .claude,
settingsSection: .init(ClaudeProviderSettingsKey.self),
metadata: ProviderMetadata(
id: .claude,
displayName: "Claude",
Expand Down
45 changes: 45 additions & 0 deletions Sources/CodexBarCore/Providers/Claude/ClaudeProviderSettings.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
import Foundation

public struct ClaudeProviderSettings: Sendable {
public let usageDataSource: ClaudeUsageDataSource
public let webExtrasEnabled: Bool
public let cookieSource: ProviderCookieSource
public let manualCookieHeader: String?
public let organizationID: String?

public init(
usageDataSource: ClaudeUsageDataSource,
webExtrasEnabled: Bool,
cookieSource: ProviderCookieSource,
manualCookieHeader: String?,
organizationID: String? = nil)
{
self.usageDataSource = usageDataSource
self.webExtrasEnabled = webExtrasEnabled
self.cookieSource = cookieSource
self.manualCookieHeader = manualCookieHeader
self.organizationID = organizationID
}
}

public enum ClaudeProviderSettingsKey: ProviderSettingsSectionKey {
public static let providerID = ProviderInstanceID.claude
public typealias Section = ClaudeProviderSettings
}

extension ProviderSettingsSnapshot {
public typealias ClaudeProviderSettings = CodexBarCore.ClaudeProviderSettings
public var claude: ClaudeProviderSettings? {
self[ClaudeProviderSettingsKey.self]
}

public static func make(claude: ClaudeProviderSettings?) -> Self {
self.make(claude, for: ClaudeProviderSettingsKey.self)
}
}

extension ProviderSettingsSnapshotContribution {
public static func claude(_ section: ClaudeProviderSettings) -> Self {
Self(section, for: ClaudeProviderSettingsKey.self)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ public enum CodexProviderDescriptor {
static func makeDescriptor() -> ProviderDescriptor {
ProviderDescriptor(
id: .codex,
settingsSection: .init(CodexProviderSettingsKey.self),
metadata: ProviderMetadata(
id: .codex,
displayName: "Codex",
Expand Down
Loading