Skip to content

Add multi-account token support for Codex and API-key providers#461

Open
Minoo7 wants to merge 13 commits intosteipete:mainfrom
Minoo7:feature/multi-account-api-providers
Open

Add multi-account token support for Codex and API-key providers#461
Minoo7 wants to merge 13 commits intosteipete:mainfrom
Minoo7:feature/multi-account-api-providers

Conversation

@Minoo7
Copy link

@Minoo7 Minoo7 commented Mar 2, 2026

Summary

  • extend token-account support catalog for Codex plus API-key providers (Copilot, Kimi K2, Synthetic, Warp, OpenRouter)
  • enable Codex token-account settings visibility when cookie source is manual so users can add accounts before any token exists
  • add Codex manual-cookie actions in Preferences: Test cookie (validates immediately) and Save as account (appends token accounts)
  • surface Codex cookie import/test status directly in the Codex settings pane subtitle
  • keep token-account injection consistent so selected accounts override configured API keys in app and CLI environments
  • add regression tests for Codex catalog support, Codex manual cookie actions, >2 account appends, Codex CLI snapshot cookie-source forcing, Codex settings visibility, and API-provider precedence

Verification

  • swift test --filter ProviderSettingsDescriptorTests/codexManualCookieFieldExposesTestAndSaveActions
  • swift test --filter ProviderSettingsDescriptorTests/codexSaveCookieActionAppendsAccountsBeyondTwo
  • swift test --filter TokenAccountEnvironmentPrecedenceTests
  • swift test --filter ProviderSettingsDescriptorTests/codex
  • swiftformat Sources Tests && swiftlint --strict
  • pnpm check
  • ./Scripts/compile_and_run.sh

@Minoo7 Minoo7 changed the title Add token-account support for API-key providers Add multi-account token support for Codex and API-key providers Mar 2, 2026
if self.settings.codexCookieSource == .manual,
!self.settings.tokenAccounts(for: .codex).isEmpty
{
return nil
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could this targetEmail becoming nil in manual token-account mode interact with the account-switch path in a way that keeps stale dashboard state after switching accounts?

!previous.isEmpty,
previous != normalized
{
let emailChanged = if let previous, !previous.isEmpty, let normalizedOrNil {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should transitions like previous email -> nil or previous tokenAccountID nil -> non-nil be treated as account changes here, or is there a reason we want to keep existing dashboard state in that first switch case?

private static let headerPatterns: [String] = [
#"(?i)-H\s*'Cookie:\s*([^']+)'"#,
#"(?i)-H\s*\"Cookie:\s*([^\"]+)\""#,
#"(?i)(?:^|\s)-H\s+'Cookie:\s*([^']+)'"#,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are we intentionally requiring whitespace after -H now, or should compact forms like -H'Cookie: ...' still be accepted?

#"(?i)(?:--cookie|-b)\s*'([^']+)'"#,
#"(?i)(?:--cookie|-b)\s*\"([^\"]+)\""#,
#"(?i)(?:--cookie|-b)\s*([^\s]+)"#,
#"(?i)(?:^|\s)(?:--cookie|-b)\s+'([^']+)'"#,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For --cookie / -b, do we still want to accept compact input like -b'...', or should it only match when there is whitespace?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants