refactor: extract resolve_model_provider helper, fix cross-provider routing

Replace duplicated inline provider resolution in routes.py and streaming.py
with a shared resolve_model_provider() helper in config.py.

Improvements over original:
- If model ID has a prefix matching any known direct-API provider
  (not just the config provider), strip it and route correctly.
  This handles edge cases like localStorage restoring a model from
  a different provider group.
- Single source of truth for the resolution logic.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
Nathan Esquenazi
2026-04-01 22:56:34 -07:00
parent 2864c2b691
commit 241357595d
3 changed files with 37 additions and 21 deletions

View File

@@ -629,15 +629,9 @@ def _handle_chat_sync(handler, body):
try:
from run_agent import AIAgent
with CHAT_LOCK:
from api.config import cfg as _hcfg
_model = s.model or ''
_prov = None
_mc = _hcfg.get('model', {})
if isinstance(_mc, dict):
_prov = _mc.get('provider')
if _prov and '/' in _model and _model.startswith(_prov + '/'):
_model = _model.split('/', 1)[1]
agent = AIAgent(model=_model, provider=_prov, platform='cli', quiet_mode=True,
from api.config import resolve_model_provider
_model, _provider = resolve_model_provider(s.model)
agent = AIAgent(model=_model, provider=_provider, platform='cli', quiet_mode=True,
enabled_toolsets=CLI_TOOLSETS, session_id=s.session_id)
workspace_ctx = f"[Workspace: {s.workspace}]\n"
workspace_system_msg = (