Repository navigation
feat(agent): funfa auth + subscription-backed web_search - #28
Merged
Merged
Conversation
Add 'funfa auth': an in-process pi OAuth login (AuthStorage.login) with a provider picker, so users sign in to Claude Pro/Max, ChatGPT, or GitHub Copilot without a separate pi binary. The game positional is now optional (parent + subcommand), and the no-credential error points at 'funfa auth'. Route web_search through whichever subscription is authed instead of requiring a Parallel key. New provider chain (web-search-providers.ts): Anthropic via the server-side web_search_20250305 tool (OAuth shaped as Claude Code), Codex via the chatgpt.com backend Responses web_search tool (JWT account-id + SSE), then the Parallel fallback, then a fetch_page degradation hint. Request shapes mirror @earendil-works/pi-ai 0.78.0 so the calls are accepted on the same credential. Verified: full suite 105 pass / 1 skip / 0 fail, typecheck + lint clean, and a live web_search on a ChatGPT/Codex sub returns synthesized answer + sources.
There was a problem hiding this comment.
Your free trial has ended. If you'd like to continue receiving code reviews, you can add a payment method here.
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
What & why
Since funfa embeds pi as a library (not the
piCLI), users had no way to authenticate, andweb_searchwas a no-op without a separatePARALLEL_API_KEY. This PR makes funfa self-sufficient on a single model subscription: sign in, then search through that same sub.1.
funfa auth— in-process OAuth loginagent/auth.tsdrives pi'sAuthStorage.login(providerId, callbacks)directly (nopibinary required), persisting to the same~/.pi/agent/auth.jsonthe next run reads.authsubcommand with an interactive provider picker (anthropic= Claude Pro/Max,openai-codex= ChatGPT,github-copilot) or an explicit arg:funfa auth [provider].<game>positional became optional (a parent command can't also require a positional alongside subcommands); the parent handler prints its own missing-game usage error.funfa authinstead of "runpi".@inquirerselect/input + best-effort browser open) is injected, so the orchestration is unit-tested without a real OAuth round-trip.2. Subscription-backed
web_searchagent/tools/web-search-providers.ts: a provider chain that routes through whichever subscription is authed, then a keyed fallback, then afetch_pagedegradation hint.claude-haiku-4-5call to the public Messages API with the server-sideweb_search_20250305tool. OAuth tokens are shaped as Claude Code requests (the form Anthropic accepts for a subscription token).chatgpt.com/backend-api/codex/responsesendpoint funfa already drives the loop through, with the built-inweb_searchtool; auth is the OAuth JWT and the ChatGPT account-id is decoded from it (SSE-parsed).@earendil-works/pi-ai0.78.0 internals, so calls are accepted on the same credential.WebSearchResultgained an optionalanswerto carry the synthesized summary.Verification
tsc+ Ultracite clean; binary compiles.auth.test.ts(provider resolution, cancel/fail classification, callback wiring) andweb-search-providers.test.ts(JWT account-id decode + chain selection, network-free).web_searchon a ChatGPT/Codex sub returned a synthesized answer (PROTON_PREFER_SDL=1+ GE-Proton) plus source URLs in ~21s, with no Parallel key.Caveats
fetch_pagegracefully, so failures are non-fatal.claude-cli/account-id request shaping is pinned to pi-ai 0.78.0 conventions; revisit on pi upgrades.