Skip to content

Commit 42f36ea

Browse files
andrejvysnyclaude
andcommitted
Fix review blockers and cleanup for PR merge
- Fix blocking urlopen in async GET /api/config/model via asyncio.to_thread - Fix LM Studio use_raw_model_name sending prefixed model id to API - Fix _is_anthropic_model matching openrouter/anthropic/ routes - Add message-count limit (2000) on restore-session-summary - Add provider config check on model switch (openai-compat/ env guard) - Cache _all_adapter_prefixes with lru_cache - Extract useModelCatalog hook from ChatInput (635 -> 528 lines) - Memoize provider groups calculation - Add Enter key support to CustomModelDialog - Fix useEffect dependency loop on selectedModelInfo Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent 4ac4f1a commit 42f36ea

6 files changed

Lines changed: 468 additions & 337 deletions

File tree

agent/core/provider_adapters.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
"""Provider adapters for runtime params and model catalog metadata."""
22

3+
import functools
34
import json
45
import os
56
import time
@@ -64,6 +65,7 @@ def _provider_avatar_url(provider_id: str) -> str:
6465
return avatars.get(provider_id, "https://huggingface.co/api/avatars/huggingface")
6566

6667

68+
@functools.lru_cache(maxsize=1)
6769
def _all_adapter_prefixes() -> tuple[str, ...]:
6870
prefixes: list[str] = []
6971
for adapter in ADAPTERS:
@@ -396,7 +398,7 @@ def build_params(
396398

397399
model_id = model_name.removeprefix(self.prefixes[0])
398400
params: dict[str, Any] = {
399-
"model": model_name if self.use_raw_model_name else f"openai/{model_id}",
401+
"model": model_id if self.use_raw_model_name else f"openai/{model_id}",
400402
"api_base": self.resolved_api_base(),
401403
"api_key": self.resolved_api_key(),
402404
}

backend/routes/agent.py

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,15 +34,19 @@
3434

3535
from agent.core.llm_errors import health_error_type, render_llm_error_message
3636
from agent.core.llm_params import _resolve_llm_params
37-
from agent.core.provider_adapters import build_model_catalog, is_valid_model_name
37+
from agent.core.provider_adapters import (
38+
build_model_catalog,
39+
is_valid_model_name,
40+
resolve_adapter,
41+
)
3842

3943
logger = logging.getLogger(__name__)
4044

4145
router = APIRouter(prefix="/api", tags=["agent"])
4246

4347

4448
def _is_anthropic_model(model_id: str) -> bool:
45-
return "anthropic" in model_id
49+
return model_id.startswith(("anthropic/", "bedrock/"))
4650

4751

4852
async def _require_hf_for_anthropic(request: Request, model_id: str) -> None:
@@ -162,7 +166,9 @@ async def llm_health_check() -> LLMHealthResponse:
162166
@router.get("/config/model")
163167
async def get_model() -> dict:
164168
"""Get current model and available models. No auth required."""
165-
return build_model_catalog(session_manager.config.model_name)
169+
return await asyncio.to_thread(
170+
build_model_catalog, session_manager.config.model_name
171+
)
166172

167173

168174
_TITLE_STRIP_CHARS = str.maketrans("", "", "`*_~#[]()")
@@ -290,6 +296,8 @@ async def restore_session_summary(
290296
messages = body.get("messages")
291297
if not isinstance(messages, list) or not messages:
292298
raise HTTPException(status_code=400, detail="Missing 'messages' array")
299+
if len(messages) > 2000:
300+
raise HTTPException(status_code=400, detail="Too many messages (max 2000)")
293301

294302
hf_token = None
295303
auth_header = request.headers.get("Authorization", "")
@@ -361,6 +369,11 @@ async def set_session_model(
361369
raise HTTPException(status_code=400, detail="Missing 'model' field")
362370
if not is_valid_model_name(model_id):
363371
raise HTTPException(status_code=400, detail=f"Unknown model: {model_id}")
372+
adapter = resolve_adapter(model_id)
373+
if adapter and not adapter.should_show():
374+
raise HTTPException(
375+
status_code=400, detail=f"Provider not configured for: {model_id}"
376+
)
364377
await _require_hf_for_anthropic(request, model_id)
365378
agent_session = session_manager.sessions.get(session_id)
366379
if not agent_session:

0 commit comments

Comments
 (0)