feat: add HTTP/HTTPS proxy support for all API traffic#301
feat: add HTTP/HTTPS proxy support for all API traffic#301aaronsewall wants to merge 9 commits intoNoeFabris:devfrom
Conversation
- Add fetchWithProxy() utility using https-proxy-agent - Thread proxyUrl through all fetch call sites (token refresh, project context, quota, search) - Save proxy URL from ANTIGRAVITY_LOGIN_PROXY env during login - Store proxyUrl per-account in antigravity-accounts.json - Add docs/PROXY.md with configuration guide - Update README with proxy quick start section Supports: http://host:port, http://user:pass@host:port, https://host:port Note: SOCKS5 proxies are NOT supported
|
Important Review skippedAuto reviews are disabled on base/target branches other than the default branch. Please check the settings in the CodeRabbit UI or the You can disable this status message by setting the
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
|
To use Codex here, create an environment for this repo. |
Greptile OverviewGreptile SummaryThis PR adds comprehensive HTTP/HTTPS proxy support for all API traffic in the Antigravity authentication plugin. The implementation threads proxy URLs through OAuth login, token refresh, project discovery, quota checks, search tools, and all API requests. Key changes:
Architecture: Issues found:
Confidence Score: 4/5
Important Files Changed
Sequence DiagramsequenceDiagram
participant User
participant CLI as OpenCode CLI
participant Plugin as Antigravity Plugin
participant ProxyModule as proxy.ts
participant ProxyAgent as undici ProxyAgent
participant Proxy as HTTP Proxy
participant GoogleAPI as Google APIs
Note over User,GoogleAPI: OAuth Login Flow with Proxy
User->>CLI: ANTIGRAVITY_LOGIN_PROXY=http://proxy:8080<br/>opencode auth login
CLI->>Plugin: Login command
Plugin->>ProxyModule: fetchWithProxy(token endpoint, ..., proxyUrl)
ProxyModule->>ProxyModule: getProxyAgent(proxyUrl)
ProxyModule->>ProxyAgent: new ProxyAgent({uri: proxyUrl})
ProxyAgent-->>ProxyModule: agent
ProxyModule->>ProxyModule: Cache agent in agentCache Map
ProxyModule->>ProxyAgent: undiciFetch(url, {dispatcher: agent})
ProxyAgent->>Proxy: CONNECT to oauth2.googleapis.com
Proxy->>GoogleAPI: Forward token exchange request
GoogleAPI-->>Proxy: Access token + refresh token
Proxy-->>ProxyAgent: Response
ProxyAgent-->>Plugin: OAuth tokens
Plugin->>Plugin: Save proxyUrl to antigravity-accounts.json
Note over User,GoogleAPI: API Request Flow with Cached Proxy
User->>CLI: opencode run "Hello" --model=google/claude-sonnet-4-5
CLI->>Plugin: Request
Plugin->>Plugin: Load account (with proxyUrl)
Plugin->>ProxyModule: fetchWithProxy(API endpoint, ..., account.proxyUrl)
ProxyModule->>ProxyModule: getProxyAgent(account.proxyUrl)
ProxyModule->>ProxyModule: Return cached agent from agentCache
ProxyModule->>ProxyAgent: undiciFetch(url, {dispatcher: agent})
ProxyAgent->>Proxy: Reuse connection to proxy
Proxy->>GoogleAPI: Forward API request
GoogleAPI-->>Proxy: Streaming response
Proxy-->>ProxyAgent: Stream
ProxyAgent-->>Plugin: Response stream
Plugin-->>User: Stream output
Note over User,GoogleAPI: All Traffic Routes Through Proxy
Plugin->>ProxyModule: Token refresh (account.proxyUrl)
Plugin->>ProxyModule: Project discovery (account.proxyUrl)
Plugin->>ProxyModule: Quota checks (account.proxyUrl)
Plugin->>ProxyModule: Search tool (account.proxyUrl)
|
Additional Comments (1)
Prompt To Fix With AIThis is a comment left during a code review.
Path: src/plugin/accounts.ts
Line: 762:775
Comment:
`proxyUrl` is missing from the account mapping in `saveToDisk()`. The proxy configuration will not persist across application restarts, even though it's saved during login in `plugin.ts:345`. Add `proxyUrl: a.proxyUrl` to the mapped account object.
How can I resolve this? If you propose a fix, please make it concise. |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 8f2fa57280
ℹ️ 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".
proxyUrl was missing from saveToDisk() mapping and constructor hydration, causing proxy config to be lost on restart and all API calls to bypass proxy.
Co-authored-by: greptile-apps[bot] <165735046+greptile-apps[bot]@users.noreply.github.com> Signed-off-by: Aaron Sewall <[email protected]>
Request objects were accepted but properties (method, headers, body) were silently lost. All call sites pass strings, so narrowing the type prevents future misuse. Removed test for Request input since it's no longer valid.
Resolve conflicts to keep both proxy support and new quota caching features. Added proxyUrl parameter to fetchGeminiCliQuota for parallel quota fetching.
Signed-off-by: Aaron Sewall <[email protected]>
Co-authored-by: greptile-apps[bot] <165735046+greptile-apps[bot]@users.noreply.github.com> Signed-off-by: Aaron Sewall <[email protected]>
Additional Comments (1)
Both Add Prompt To Fix With AIThis is a comment left during a code review.
Path: src/plugin/quota.ts
Line: 329:336
Comment:
proxy not used for token refresh and project context during quota checks
Both `refreshAccessToken()` and `ensureProjectContext()` are missing the `account.proxyUrl` parameter. This means quota checks will bypass the configured proxy for authentication and project discovery, even though the actual quota API calls (lines 345-347) correctly use the proxy.
Add `account.proxyUrl` as the 4th parameter to `refreshAccessToken()` on line 329, and as the 2nd parameter to `ensureProjectContext()` on line 336.
How can I resolve this? If you propose a fix, please make it concise. |
Signed-off-by: Aaron Sewall <[email protected]>
- Add MAX_AGENT_CACHE_SIZE (50) with LRU eviction to prevent unbounded growth - Add disposeProxyAgent() for explicit cleanup when accounts are removed - Fix proxyUrl clearing logic: use explicit undefined check instead of ?? (allows removing proxy by setting empty string, not treated as falsy) - Pass account.proxyUrl to refreshAccessToken() and ensureProjectContext() in quota checks to ensure proxy is used for all auth operations
| refreshToken: parts.refreshToken, | ||
| projectId: parts.projectId ?? existing.projectId, | ||
| managedProjectId: parts.managedProjectId ?? existing.managedProjectId, | ||
| proxyUrl: proxyUrl !== undefined ? proxyUrl : existing.proxyUrl, |
There was a problem hiding this comment.
proxy cannot be cleared once set - undefined falls back to existing proxy
if user logs in without ANTIGRAVITY_LOGIN_PROXY after previously setting a proxy, the old proxy persists. empty string ("") would also be falsy and fall back.
to enable proxy clearing, distinguish between "not provided" vs "explicitly cleared":
| proxyUrl: proxyUrl !== undefined ? proxyUrl : existing.proxyUrl, | |
| proxyUrl: proxyUrl !== undefined ? proxyUrl : existing.proxyUrl, |
could become:
// Use null to explicitly clear proxy
proxyUrl: proxyUrl !== undefined ? (proxyUrl || null) : existing.proxyUrl,
then users could clear with ANTIGRAVITY_LOGIN_PROXY="" opencode auth login
Prompt To Fix With AI
This is a comment left during a code review.
Path: src/plugin.ts
Line: 423:423
Comment:
proxy cannot be cleared once set - `undefined` falls back to existing proxy
if user logs in without `ANTIGRAVITY_LOGIN_PROXY` after previously setting a proxy, the old proxy persists. empty string (`""`) would also be falsy and fall back.
to enable proxy clearing, distinguish between "not provided" vs "explicitly cleared":
```suggestion
proxyUrl: proxyUrl !== undefined ? proxyUrl : existing.proxyUrl,
```
could become:
```
// Use null to explicitly clear proxy
proxyUrl: proxyUrl !== undefined ? (proxyUrl || null) : existing.proxyUrl,
```
then users could clear with `ANTIGRAVITY_LOGIN_PROXY="" opencode auth login`
How can I resolve this? If you propose a fix, please make it concise.
Supports: http://host:port, http://user:pass@host:port, https://host:port
Note: SOCKS5 proxies are NOT supported