From 1d61fdc29970da66694688b6034a66d48b337b21 Mon Sep 17 00:00:00 2001 From: DavidKoleczek <45405824+DavidKoleczek@users.noreply.github.com> Date: Mon, 20 Jul 2026 15:20:54 -0400 Subject: [PATCH] fix: rename provider id to github-copilot-amplifier for exact cost MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit opencode only enables raw-usage passthrough (includeRawChunks) when the provider id contains the substring "github-copilot". That passthrough is what lets amplifier-agent's per-turn copilot_usage.total_nano_aiu reach opencode and override its inaccurate token-times-rate cost estimate, which otherwise overstates session cost under Anthropic prompt caching. - Rename DEFAULT_PROVIDER_ID from "amplifier" to "github-copilot-amplifier". The provider's display name stays "Amplifier". - On config rewrite, drop any stale provider block previously written under a different id but the same baseURL, so upgrading configs do not end up with a duplicate "Amplifier" provider. Requires the companion change in amplifier-agent (emit copilot_usage on the terminal chunk). Both are required together. Refs: microsoft-amplifier/amplifier-support#352 🤖 Generated with [Amplifier](https://github.com/microsoft/amplifier) Co-Authored-By: Amplifier <240397093+microsoft-amplifier@users.noreply.github.com> --- src/amplifier_app_opencode/cli.py | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/src/amplifier_app_opencode/cli.py b/src/amplifier_app_opencode/cli.py index bed7a1b..ef9c092 100644 --- a/src/amplifier_app_opencode/cli.py +++ b/src/amplifier_app_opencode/cli.py @@ -63,7 +63,10 @@ # under 5s and exit the poll loop early. DEFAULT_SERVER_READY_TIMEOUT_S = 120.0 DEFAULT_SERVER_PROBE_TIMEOUT_S = 2.0 -DEFAULT_PROVIDER_ID = "amplifier" +# The "github-copilot" substring is load-bearing: opencode only enables raw-usage +# passthrough (which carries amplifier-agent's exact copilot_usage) for provider +# ids that contain it. +DEFAULT_PROVIDER_ID = "github-copilot-amplifier" DEFAULT_PROVIDER_NAME = "Amplifier" DEFAULT_PROVIDER_NPM = "@ai-sdk/openai-compatible" # Opt-in ceiling for the advertised per-model context window. None == forward @@ -448,6 +451,21 @@ def write_opencode_config( raise click.ClickException( f"Existing {config_path}.provider is not a dict; refusing to overwrite." ) + + # Drop any stale block this bridge previously wrote under a different id but the + # same baseURL, so an upgraded config doesn't keep a duplicate provider. + # Providers at any other baseURL are left untouched. + our_base_url = (provider.get("options") or {}).get("baseURL") + if our_base_url: + for stale_id in [ + key + for key, block in existing["provider"].items() + if key != provider_id + and isinstance(block, dict) + and (block.get("options") or {}).get("baseURL") == our_base_url + ]: + del existing["provider"][stale_id] + existing["provider"][provider_id] = provider config_path.write_text(json.dumps(existing, indent=2, sort_keys=False) + "\n")