fix(aux): honour a custom OpenCode-family entry's declared api_mode, like the main runtime
opencode_transport() re-derived the wire for every OpenCode-family custom entry, while hermes_cli/runtime_provider_custom.py::_resolve_named_custom_runtime only re-derives when the entry declares no api_mode. Aux now mirrors that gate, so an entry pinned to chat_completions stays a plain chat client on both paths. Test grid trimmed to [None, one wrong mode]; the bridge fixture drops its api_mode (the override no longer applies to it) and a pinned entry asserts the honoured mode instead.
This commit is contained in:
@@ -35,12 +35,16 @@ def opencode_transport(provider: Optional[str], model: Optional[str], base_url:
|
||||
hosts all count.
|
||||
"""
|
||||
from hermes_cli.models import normalize_opencode_base_url, normalize_opencode_model_id, opencode_model_api_mode
|
||||
from hermes_cli.runtime_provider_custom import _opencode_family_for_custom
|
||||
from hermes_cli.runtime_provider_custom import _get_named_custom_provider, _opencode_family_for_custom
|
||||
|
||||
url = str(base_url or "")
|
||||
family = _opencode_family_for_custom(str(provider or ""), url)
|
||||
if family is None:
|
||||
return None, url
|
||||
# A custom entry that declares its own api_mode keeps it, exactly like the main runtime
|
||||
# (_resolve_named_custom_runtime only re-derives when the entry has none).
|
||||
if (_get_named_custom_provider(str(provider or "")) or {}).get("api_mode"):
|
||||
return None, url
|
||||
# ``<provider>/<model>`` config ids are stripped against the entry name before the family lookup.
|
||||
api_mode = opencode_model_api_mode(family, normalize_opencode_model_id(provider, model))
|
||||
return api_mode, normalize_opencode_base_url(provider, api_mode, url)
|
||||
|
||||
@@ -25,6 +25,9 @@ def _isolated_home(tmp_path, monkeypatch):
|
||||
" - name: opencode-go-bridge\n"
|
||||
" base_url: https://opencode.ai/zen/go/v1\n"
|
||||
" api_key: sk-bridge\n"
|
||||
" - name: opencode-go-pinned\n"
|
||||
" base_url: https://opencode.ai/zen/go/v1\n"
|
||||
" api_key: sk-pinned\n"
|
||||
" api_mode: chat_completions\n"
|
||||
)
|
||||
return home
|
||||
@@ -38,7 +41,7 @@ _WIRE_BY_MODEL = [
|
||||
|
||||
|
||||
@pytest.mark.parametrize("model, expected", _WIRE_BY_MODEL)
|
||||
@pytest.mark.parametrize("stale_api_mode", [None, "chat_completions", "codex_responses"])
|
||||
@pytest.mark.parametrize("stale_api_mode", [None, "chat_completions"])
|
||||
def test_builtin_opencode_go_client_follows_the_model_not_the_persisted_mode(model, expected, stale_api_mode):
|
||||
client, resolved = aux.resolve_provider_client("opencode-go", model=model, api_mode=stale_api_mode)
|
||||
assert resolved == model
|
||||
@@ -49,7 +52,7 @@ def test_builtin_opencode_go_client_follows_the_model_not_the_persisted_mode(mod
|
||||
|
||||
@pytest.mark.parametrize("model, expected", _WIRE_BY_MODEL)
|
||||
def test_named_custom_opencode_family_entry_follows_the_model(model, expected):
|
||||
"""An ``opencode-go-*`` custom entry persisted one api_mode at save time; each model still gets its own wire."""
|
||||
"""An ``opencode-go-*`` custom entry without an api_mode of its own gets each model's wire, like main."""
|
||||
client, resolved = aux.resolve_provider_client("custom:opencode-go-bridge", model=model)
|
||||
assert resolved == model
|
||||
assert type(client) is expected
|
||||
@@ -58,3 +61,11 @@ def test_named_custom_opencode_family_entry_follows_the_model(model, expected):
|
||||
else:
|
||||
base = client._real_client.base_url if expected is aux.CodexAuxiliaryClient else client.base_url
|
||||
assert str(base).rstrip("/") == "https://opencode.ai/zen/go/v1"
|
||||
|
||||
|
||||
def test_named_custom_opencode_family_entry_with_declared_api_mode_is_honoured():
|
||||
"""An entry that declares ``api_mode`` keeps it — the main runtime only re-derives when the entry has none."""
|
||||
client, resolved = aux.resolve_provider_client("custom:opencode-go-pinned", model="gpt-5.6-luna")
|
||||
assert resolved == "gpt-5.6-luna"
|
||||
assert type(client) is OpenAI
|
||||
assert str(client.base_url).rstrip("/") == "https://opencode.ai/zen/go/v1"
|
||||
|
||||
Reference in New Issue
Block a user