feat: proxy auto-discovery for OpenCode + init proxy-route injection#13
Merged
Conversation
routes.rs: - Added scan_opencode_configs() — discovers upstream by scanning opencode.json providers - Added scan_claude_config() — discovers upstream from ~/.claude.json - Added scan_cline_config() — discovers upstream from Cline config - Added normalize_url() — ensures proper /chat/completions or /v1/messages suffix - Auto-discovery cascade: proxy-routes.json > OpenCode > Claude > Cline > Pi > env vars init.rs: - inject_opencode_proxy_routes() — reads opencode.json, mutates provider baseURLs to http://127.0.0.1:9090/v1, generates proxy-routes.json - restore_opencode_proxy_routes() — restores original baseURLs on uninstall - Prompt asks user Y/N before mutating config
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.
Problem
Setting up the Reliary proxy for all OpenCode providers required manually changing
baseURLper provider and maintainingproxy-routes.json. Adding a new provider meant more manual editing. High friction.Solution
Auto-discovery in routes.rs: The proxy now scans 5 agent configs on unknown API key:
proxy-routes.json(explicit user override, highest priority)opencode.jsonproviders~/.claude.json~/.pi/agent/models.jsonWhen a provider sends a request through the proxy with its API key, the proxy auto-discovers the real upstream URL by scanning these configs. New provider = zero config.
Init proxy-route injection:
reliary-agent initnow asks:If yes: mutates all provider
baseURLs tohttp://127.0.0.1:9090/v1, generatesproxy-routes.jsonmapping apiKey → original upstream URL.Clean uninstall:
reliary-agent uninstallrestores originalbaseURLs from the backup inproxy-routes.json.Key design decisions
initasks Y/N before mutating -- no silent config changesproxy-routes.jsonas__backupskey -- single file, no separate backupnormalize_url()handles both OpenAI (/chat/completions) and Anthropic (/v1/messages) URL patternsTests