Add CodeBuddy provider for credit usage tracking#296
Add CodeBuddy provider for credit usage tracking#296claude89757 wants to merge 1 commit intosteipete:mainfrom
Conversation
Implements CodeBuddy (Tencent Cloud AI assistant) integration with: - Cookie-based authentication from Chrome browser - Enterprise ID auto-detection from API responses - Credit usage fetching from billing API - Daily usage chart visualization - Session keepalive functionality - Unit tests for models, snapshots, and cookie parsing Follows existing provider patterns and architecture.
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: f2be96b90b
ℹ️ About Codex in GitHub
Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
| /// Default enterprise ID for most CodeBuddy users | ||
| private static let defaultEnterpriseID = "etahzsqej0n4" | ||
|
|
||
| var codebuddyEnterpriseID: String { | ||
| get { | ||
| let stored = self.configSnapshot.providerConfig(for: .codebuddy)?.enterpriseID | ||
| // Use default if not explicitly set | ||
| return stored ?? Self.defaultEnterpriseID | ||
| } |
There was a problem hiding this comment.
Avoid hard-coded enterprise ID fallback
The getter always returns defaultEnterpriseID when the user hasn’t configured one, which makes the provider look configured and forces API calls to use a hard-coded enterprise ID. In practice, users who haven’t set their own enterprise ID will either get repeated 403s or (if the cookie happens to allow it) see usage for the wrong enterprise. This should be nil/empty until explicitly set or auto-detected so availability and fetches reflect the user’s actual enterprise.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Re: enterprise ID default - The CodeBuddy API requires x-enterprise-id header, returning 400 without it. The default enables out-of-box functionality, and users can customize it via Settings → Enterprise ID field. Cookie validation still gates actual data access regardless of enterprise ID value.
Summary
This PR adds support for CodeBuddy (Tencent Cloud AI Coding Assistant) as a new usage provider. CodeBuddy is a popular AI coding assistant in China, and this integration enables users to track their credit usage directly from CodexBar.
Local Test
Features
Core Implementation
POST /billing/meter/get-enterprise-user-usagefor usage dataFiles Added (12 new files)
CodexBarCore/Providers/CodeBuddy/
CodeBuddyAPIError.swift- Error types for API failuresCodeBuddyCookieHeader.swift- Cookie header management and enterprise ID extractionCodeBuddyCookieImporter.swift- Browser cookie import logicCodeBuddyModels.swift- API response modelsCodeBuddyProviderDescriptor.swift- Provider metadata and configurationCodeBuddySessionKeepalive.swift- Session keepalive functionalityCodeBuddySettingsReader.swift- Settings reader for provider configurationCodeBuddyUsageFetcher.swift- Main usage fetching logicCodeBuddyUsageSnapshot.swift- Usage snapshot conversionCodexBar/Providers/CodeBuddy/
CodeBuddyProviderImplementation.swift- Provider implementationCodeBuddyProviderRuntime.swift- Runtime managementCodeBuddySettingsStore.swift- Settings store for UIViews
CodeBuddyDailyUsageChartMenuView.swift- Daily usage chart visualizationFiles Modified (17 files)
Tests
CodeBuddyTests.swift- Comprehensive unit tests covering:Usage Display
1,121 / 25,000(used / limit credits)credit / limitNum × 100https://tencent.sso.codebuddy.cn/profile/usageAuthentication Flow
sessionandsession_2cookies fromtencent.sso.codebuddy.cndomainTesting
swift test)Related
This follows the same architecture patterns as other providers (Claude, Gemini, Copilot, etc.).