-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Add Neuralwatt provider #2220
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Add Neuralwatt provider #2220
Changes from 14 commits
Commits
Show all changes
18 commits
Select commit
Hold shift + click to select a range
479e128
Add Neuralwatt provider
jrimmer d40fbd7
fix: harden Neuralwatt provider
steipete ccc6c59
fix: avoid duplicate Neuralwatt credits row
steipete c5d8f8b
fix: respect Neuralwatt quota limits
steipete 7556521
Fix Neuralwatt account refresh test
joeVenner 5fdb8d8
Use stored Neuralwatt test accounts
joeVenner b041e73
Narrow Neuralwatt account refresh coverage
joeVenner 40b7320
Fix Neuralwatt lint checks
joeVenner 69015e6
Split token account label helpers
joeVenner 079293f
Harden TTY working directory test
joeVenner 7f1e539
Merge remote-tracking branch 'origin/main' into codex/neuralwatt-prov…
steipete 72e7013
Merge remote-tracking branch 'origin/main' into codex/neuralwatt-prov…
steipete 979ec36
test: fix Neuralwatt metric picker expectation
steipete 0ececf1
Merge remote-tracking branch 'origin/main' into codex/neuralwatt-prov…
steipete 3d6d2e4
Merge remote-tracking branch 'origin/main' into codex/neuralwatt-prov…
steipete 4c0f8c4
feat: add Neuralwatt confetti palette
steipete 89befd1
Merge remote-tracking branch 'origin/main' into codex/neuralwatt-prov…
steipete 7b63ab4
test: harden Claude swap invocation proof
steipete File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
44 changes: 44 additions & 0 deletions
44
Sources/CodexBar/Providers/NeuralWatt/NeuralWattProviderImplementation.swift
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,44 @@ | ||
| import CodexBarCore | ||
| import Foundation | ||
|
|
||
| struct NeuralWattProviderImplementation: ProviderImplementation { | ||
| let id: UsageProvider = .neuralwatt | ||
|
|
||
| @MainActor | ||
| func presentation(context _: ProviderPresentationContext) -> ProviderPresentation { | ||
| ProviderPresentation { _ in "api" } | ||
| } | ||
|
|
||
| @MainActor | ||
| func observeSettings(_ settings: SettingsStore) { | ||
| _ = settings.neuralWattAPIKey | ||
| _ = settings.tokenAccountsData(for: .neuralwatt) | ||
| } | ||
|
|
||
| @MainActor | ||
| func isAvailable(context: ProviderAvailabilityContext) -> Bool { | ||
| if NeuralWattSettingsReader.apiKey(environment: context.environment) != nil { | ||
| return true | ||
| } | ||
| if !context.settings.neuralWattAPIKey.trimmingCharacters(in: .whitespacesAndNewlines).isEmpty { | ||
| return true | ||
| } | ||
| return !context.settings.tokenAccounts(for: .neuralwatt).isEmpty | ||
| } | ||
|
|
||
| @MainActor | ||
| func settingsFields(context: ProviderSettingsContext) -> [ProviderSettingsFieldDescriptor] { | ||
| [ | ||
| ProviderSettingsFieldDescriptor( | ||
| id: "neuralwatt-api-key", | ||
| title: "API key", | ||
| subtitle: "Stored in the CodexBar config file. Manage keys from the Neuralwatt dashboard.", | ||
| kind: .secure, | ||
| placeholder: "sk-...", | ||
| binding: context.stringBinding(\.neuralWattAPIKey), | ||
| actions: [], | ||
| isVisible: nil, | ||
| onActivate: nil), | ||
| ] | ||
| } | ||
| } |
14 changes: 14 additions & 0 deletions
14
Sources/CodexBar/Providers/NeuralWatt/NeuralWattSettingsStore.swift
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,14 @@ | ||
| import CodexBarCore | ||
| import Foundation | ||
|
|
||
| extension SettingsStore { | ||
| var neuralWattAPIKey: String { | ||
| get { self.configSnapshot.providerConfig(for: .neuralwatt)?.sanitizedAPIKey ?? "" } | ||
| set { | ||
| self.updateProviderConfig(provider: .neuralwatt) { entry in | ||
| entry.apiKey = self.normalizedConfigValue(newValue) | ||
| } | ||
| self.logSecretUpdate(provider: .neuralwatt, field: "apiKey", value: newValue) | ||
| } | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,35 @@ | ||
| import CodexBarCore | ||
| import Foundation | ||
|
|
||
| extension UsageStore { | ||
| func applyAccountLabel( | ||
| _ snapshot: UsageSnapshot, | ||
| provider: UsageProvider, | ||
| account: ProviderTokenAccount) -> UsageSnapshot | ||
| { | ||
| let label = account.label.trimmingCharacters(in: .whitespacesAndNewlines) | ||
| guard !label.isEmpty else { return snapshot } | ||
| let existing = snapshot.identity(for: provider) | ||
| let email = existing?.accountEmail?.trimmingCharacters(in: .whitespacesAndNewlines) | ||
| let resolvedEmail = (email?.isEmpty ?? true) ? label : email | ||
| let identity = ProviderIdentitySnapshot( | ||
| providerID: provider, | ||
| accountEmail: resolvedEmail, | ||
| accountOrganization: existing?.accountOrganization, | ||
| loginMethod: existing?.loginMethod) | ||
| return snapshot.withIdentity(identity) | ||
| } | ||
|
|
||
| func applyCodexVisibleAccountLabel(_ snapshot: UsageSnapshot, account: CodexVisibleAccount) -> UsageSnapshot { | ||
| let existing = snapshot.identity(for: .codex) | ||
| let email = existing?.accountEmail?.trimmingCharacters(in: .whitespacesAndNewlines) | ||
| let resolvedEmail = (email?.isEmpty ?? true) ? account.email : email | ||
| let loginMethod = existing?.loginMethod ?? account.workspaceLabel | ||
| let identity = ProviderIdentitySnapshot( | ||
| providerID: .codex, | ||
| accountEmail: resolvedEmail, | ||
| accountOrganization: existing?.accountOrganization, | ||
| loginMethod: loginMethod) | ||
| return snapshot.withIdentity(identity) | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,5 @@ | ||
| // Generated by Scripts/regenerate-codex-parser-hash.sh. Do not edit by hand. | ||
|
|
||
| enum CodexParserHash { | ||
| static let value = "8be945d1c2519e9b" | ||
| static let value = "168d4b6df03755cb" | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
50 changes: 50 additions & 0 deletions
50
Sources/CodexBarCore/Providers/NeuralWatt/NeuralWattProviderDescriptor.swift
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,50 @@ | ||
| import Foundation | ||
|
|
||
| public enum NeuralWattProviderDescriptor { | ||
| public static let descriptor: ProviderDescriptor = Self.makeDescriptor() | ||
|
|
||
| static func makeDescriptor() -> ProviderDescriptor { | ||
| ProviderDescriptor( | ||
| id: .neuralwatt, | ||
| metadata: ProviderMetadata( | ||
| id: .neuralwatt, | ||
| displayName: "Neuralwatt", | ||
| sessionLabel: "Subscription", | ||
| weeklyLabel: "Key allowance", | ||
| opusLabel: nil, | ||
| supportsOpus: false, | ||
| supportsCredits: false, | ||
| creditsHint: "Subscription kWh and prepaid USD balance.", | ||
| toggleTitle: "Show Neuralwatt usage", | ||
| cliName: "neuralwatt", | ||
| defaultEnabled: false, | ||
| isPrimaryProvider: false, | ||
| usesAccountFallback: false, | ||
| browserCookieOrder: nil, | ||
| dashboardURL: "https://portal.neuralwatt.com/dashboard", | ||
| subscriptionDashboardURL: "https://portal.neuralwatt.com/dashboard", | ||
| changelogURL: nil, | ||
| statusPageURL: nil, | ||
| statusLinkURL: nil), | ||
| branding: ProviderBranding( | ||
| iconStyle: .neuralwatt, | ||
| iconResourceName: "ProviderIcon-neuralwatt", | ||
| color: ProviderColor(red: 0.22, green: 0.85, blue: 0.55)), | ||
| tokenCost: ProviderTokenCostConfig( | ||
| supportsTokenCost: false, | ||
| noDataMessage: { "Neuralwatt token cost history is not available via the quota API." }), | ||
| fetchPlan: .apiToken( | ||
| strategyID: "neuralwatt.api", | ||
| resolveToken: { ProviderTokenResolver.neuralWattToken(environment: $0) }, | ||
| missingCredentialsError: { NeuralWattUsageError.missingCredentials }, | ||
| loadUsage: { apiKey, context in | ||
| try await NeuralWattUsageFetcher.fetchUsage( | ||
| apiKey: apiKey, | ||
| environment: context.env).toUsageSnapshot() | ||
| }), | ||
| cli: ProviderCLIConfig( | ||
| name: "neuralwatt", | ||
| aliases: ["nw", "neural"], | ||
| versionDetector: nil)) | ||
| } | ||
| } | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Because
.neuralwattis not added toSettingsStore.isBalanceOnlyProvideror otherwise special-cased,PreferencesProvidersPane.menuBarMetricPickertakes the generic branch and uses these labels to expose Primary and Secondary choices. The secondary choice is misleading for Neuralwatt because the key allowance is stored inextraRateWindows, notsnapshot.secondary, so selecting it falls back to the subscription window instead; this also contradicts the new coverage test that expects only Automatic. Add a Neuralwatt-specific/balance-only picker path or expose the allowance as a real selectable lane.Useful? React with 👍 / 👎.