Skip to content

Add Perplexity provider#606

Merged
ratulsarna merged 11 commits intomainfrom
codex/pr-449-audit
Mar 27, 2026
Merged

Add Perplexity provider#606
ratulsarna merged 11 commits intomainfrom
codex/pr-449-audit

Conversation

@ratulsarna
Copy link
Copy Markdown
Collaborator

Supersedes #449.

Rebased onto current main and includes the audit-branch fixes discussed during review.

Credit and thanks to @BeelixGit for the original implementation and follow-up work.

John Budnick and others added 9 commits March 26, 2026 00:24
Tracks usage-based API credits from Perplexity Pro/Max plans via the
/rest/billing/credits endpoint using a browser session cookie.

- Three-tier display: recurring credits (monthly), bonus credits
  (promotional grants), and purchased on-demand credits
- Infers plan name (Free/Pro/Max) from recurring credit pool size
- Cookie auth: auto browser import from Chrome/Chromium, manual paste,
  or PERPLEXITY_SESSION_TOKEN / PERPLEXITY_COOKIE env var fallback
- Waterfall attribution: recurring → purchased → promotional
- Empty credit pools render as depleted bars, not full ones
- Login flow opens perplexity.ai/signin with the standard key icon
- 10 unit tests covering parsing, waterfall logic, plan inference,
  empty-pool rendering, and UsageSnapshot conversion

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
…warning

- Cache Perplexity session cookies via CookieHeaderCache (matching
  Claude/Cursor pattern): try cache before browser import, cache on
  success, clear + retry on 401/403, preserve cache on transient errors
- Fix PerplexityCreditGrant.expiresAtTs to be optional — the API returns
  null for purchased grants, causing parse failures
- Remove deprecated kSecUseAuthenticationUIFail (macOS 14+ only needs
  LAContext.interactionNotAllowed)
- Add debug logging for parse failures (raw response preview)
- Add 6 tests for cookie cache behavior

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Perplexity now sends purchased credits as a credit_grant with
type="purchased" instead of (or in addition to) the top-level
current_period_purchased_cents field. Take the larger of the two
sources to avoid double-counting while catching either path.

Without this fix, 40k purchased credits were invisible to the
waterfall calculation, causing bonus credits to show 100% used
when they still had ~42% remaining.
@ratulsarna ratulsarna mentioned this pull request Mar 26, 2026
6 tasks
@ratulsarna ratulsarna marked this pull request as ready for review March 26, 2026 10:59
Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 13eecaf076

ℹ️ About Codex in GitHub

Your team has set up Codex to 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 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@ratulsarna
Copy link
Copy Markdown
Collaborator Author

@BeelixGit Could you please run this branch at your end and see if all works well in manual testing?

@BeelixGit
Copy link
Copy Markdown
Contributor

Tested this branch locally:

  • Build: swift build succeeds cleanly (release build also completes)
  • Tests: All 139 test suites passed, 0 failures. The test runner exits with signal 11 during process teardown (known Swift Testing runner issue on macOS, not related to this PR's changes).
  • App launch: Built, packaged, and launched the app successfully — it starts and stays running.
  • Perplexity provider: All 5 Perplexity-specific test suites pass (PerplexityCookieCacheTests, PerplexityCookieHeaderTests, PerplexityUsageFetcherTests, PerplexitySettingsReaderTests, PerplexityProviderTests).

The Perplexity provider code in this PR is functionally identical to what was in #449. The chunked cookie reassembly and credential-retry logic look solid. Tested on macOS (arm64).

Thanks @ratulsarna for the audit pass and rebase!

@ratulsarna ratulsarna merged commit a90dde7 into main Mar 27, 2026
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants