mirror of
https://github.com/HKUDS/DeepTutor.git
synced 2026-12-02 03:09:49 +08:00
fix: correct the provider PRs merged this round
An adversarial pass over #818 / #789 / #780 after merging. **Codex sign-ins from before this week stopped working (#789).** ``validate_runtime_profile`` compared the profile's ``codex_account_binding`` for equality, but that key is written only by ``sync_codex_catalog`` — every managed profile published by #690/#774 has none, so ``None != <hash>`` made each of them look like another account's and locked its owner out of Codex until they re-ran "Refresh models". Absent now reads as legacy; a binding that is present and different is still an account switch and still refused. **Overriding reasoning effort for one turn returned 409 (#789).** The same function also required the request's effort to be byte-equal to the value stored in the catalog. Effort is a per-request knob, not part of the identity that ties a config to a token — the check now stops at model membership. Its test asserted the old behaviour and has been rewritten around what the function is actually for. **The reasoning-effort endpoint left the runtime caches stale (#789).** It writes the catalog the runtime resolves against, like every other catalog write in this router, but skipped ``_invalidate_runtime_caches()``. **OrcaRouter claimed Anthropic prompt caching (#818).** ``supports_prompt_caching`` makes ``_build_kwargs`` inject ``cache_control`` blocks into any ``anthropic/*`` or ``claude*`` request — an OpenRouter extension. No other gateway sets it and nothing established the second one accepts it; a strict gateway would 400 every Claude turn. Also fixed ``anthropic/claude-sonnet-4.6`` in the fallback list, which the rest of the repo spells with dashes, so a user picking it from our own menu would have got "model not found". **OrcaRouter inserted itself into the curated menus (#818).** The featured lists are hand-picked and rendered as a positional numbered menu, so adding an entry shifted Ollama from [10] to [11]. The registry entry alone already makes a provider reachable via "Show all" and the Settings dropdown; which providers are featured is a maintainer decision. The README paragraph goes with it — no other provider has per-provider prose there, and it would have been translated into ten languages.
This commit is contained in:
@@ -219,8 +219,6 @@ deeptutor start # starts backend + frontend; keep the terminal open
|
||||
|
||||
`deeptutor init` prompts for backend port (default `8001`), frontend port (default `3782`), LLM provider / base URL / API key / model, and an optional embedding provider for Knowledge Base / RAG.
|
||||
|
||||
[OrcaRouter](https://www.orcarouter.ai) is supported as a named OpenAI-compatible gateway for both LLM and embedding. With one `ORCAROUTER_API_KEY` (keys start with `sk-orca-`) you get 150+ models from OpenAI, Anthropic, Google, DeepSeek, Qwen, MiniMax and xAI behind a single `https://api.orcarouter.ai/v1` endpoint. Pick it in the `deeptutor init` provider menu (or **Settings → Models**), use gateway model ids like `anthropic/claude-sonnet-4.6`, `deepseek/deepseek-v4-pro`, or `orcarouter/auto` for OrcaRouter's auto-routing alias, and set embedding models such as `openai/text-embedding-3-large`. It also runs gateway-level, zero-trust security for AI agents on the same endpoint — screening every prompt/response and governing every tool call on a default-deny basis, with no application code changes.
|
||||
|
||||
After `deeptutor start`, open the frontend URL printed in the terminal — by default [http://127.0.0.1:3782](http://127.0.0.1:3782). Press `Ctrl+C` in that terminal to stop both backend and frontend. Skipping `deeptutor init` is fine for a quick trial; the app boots with default ports and empty model settings, configure them later in **Settings → Models**.
|
||||
|
||||
</details>
|
||||
|
||||
@@ -645,12 +645,17 @@ async def update_openai_codex_reasoning_effort(
|
||||
) -> dict[str, Any]:
|
||||
_require_codex_oauth_actor()
|
||||
try:
|
||||
return await get_codex_oauth_service().set_reasoning_effort(
|
||||
status_payload = await get_codex_oauth_service().set_reasoning_effort(
|
||||
payload.model,
|
||||
payload.reasoning_effort,
|
||||
)
|
||||
except CodexAuthError as exc:
|
||||
raise _codex_http_exception(exc) from None
|
||||
# This writes the catalog the runtime resolves against, like every other
|
||||
# catalog write here — without it the next turn keeps the old effort until
|
||||
# something else happens to invalidate.
|
||||
_invalidate_runtime_caches()
|
||||
return status_payload
|
||||
|
||||
|
||||
@router.get("/catalog")
|
||||
|
||||
@@ -82,6 +82,15 @@ def codex_model_id(slug: str) -> str:
|
||||
return f"llm-model-openai-codex-{digest}"
|
||||
|
||||
|
||||
def _stale_codex_config() -> CodexAuthError:
|
||||
"""The one 409 every runtime-profile rejection raises."""
|
||||
return CodexAuthError(
|
||||
"codex_catalog_unavailable",
|
||||
"Refresh Codex models before using this configuration.",
|
||||
409,
|
||||
)
|
||||
|
||||
|
||||
def _codex_account_binding(account_id: str) -> str:
|
||||
return hashlib.sha256(account_id.encode("utf-8")).hexdigest()
|
||||
|
||||
@@ -604,9 +613,14 @@ class CodexOAuthService:
|
||||
self,
|
||||
token: CodexToken,
|
||||
model_slug: str,
|
||||
reasoning_effort: str | None,
|
||||
reasoning_effort: str | None = None,
|
||||
) -> None:
|
||||
"""Reject a model config that no longer belongs to the loaded token."""
|
||||
"""Reject a model config that no longer belongs to the loaded token.
|
||||
|
||||
``reasoning_effort`` is accepted for call compatibility and
|
||||
deliberately unused — see the membership check below.
|
||||
"""
|
||||
del reasoning_effort
|
||||
credentials = self._store.load_credentials()
|
||||
catalog = self._model_catalog.load()
|
||||
profiles = catalog.get("services", {}).get("llm", {}).get("profiles", [])
|
||||
@@ -617,27 +631,24 @@ class CodexOAuthService:
|
||||
or credentials.generation != token.generation
|
||||
or credentials.account_id != token.account_id
|
||||
or not isinstance(profile, Mapping)
|
||||
or profile.get("codex_account_binding") != _codex_account_binding(token.account_id)
|
||||
):
|
||||
raise CodexAuthError(
|
||||
"codex_catalog_unavailable",
|
||||
"Refresh Codex models before using this configuration.",
|
||||
409,
|
||||
)
|
||||
raise _stale_codex_config()
|
||||
|
||||
# Only a binding that is PRESENT and different is an account switch.
|
||||
# Profiles published before this key existed carry none at all, and
|
||||
# reading absence as a mismatch would lock every account that signed in
|
||||
# before it shipped out of Codex until they re-ran "Refresh models".
|
||||
binding = profile.get("codex_account_binding")
|
||||
if binding is not None and binding != _codex_account_binding(token.account_id):
|
||||
raise _stale_codex_config()
|
||||
|
||||
# Membership only. ``reasoning_effort`` is a per-request knob, not part
|
||||
# of the identity that ties a config to a token: a caller that varies it
|
||||
# for one turn is making a legal request, not presenting a stale config.
|
||||
for model in profile.get("models", []):
|
||||
if not isinstance(model, Mapping) or model.get("model") != model_slug:
|
||||
continue
|
||||
stored_effort = model.get("reasoning_effort")
|
||||
effective_effort = stored_effort if isinstance(stored_effort, str) else None
|
||||
if effective_effort == reasoning_effort:
|
||||
if isinstance(model, Mapping) and model.get("model") == model_slug:
|
||||
return
|
||||
break
|
||||
raise CodexAuthError(
|
||||
"codex_catalog_unavailable",
|
||||
"Refresh Codex models before using this configuration.",
|
||||
409,
|
||||
)
|
||||
raise _stale_codex_config()
|
||||
|
||||
async def _refresh_credentials(
|
||||
self,
|
||||
|
||||
@@ -169,7 +169,6 @@ PROVIDERS: tuple[ProviderSpec, ...] = (
|
||||
detect_by_key_prefix="sk-orca-",
|
||||
detect_by_base_keyword="orcarouter",
|
||||
default_api_base="https://api.orcarouter.ai/v1",
|
||||
supports_prompt_caching=True,
|
||||
),
|
||||
ProviderSpec(
|
||||
name="edenai",
|
||||
|
||||
@@ -47,7 +47,6 @@ FEATURED_LLM_PROVIDERS: tuple[str, ...] = (
|
||||
"gemini",
|
||||
"siliconflow",
|
||||
"openrouter",
|
||||
"orcarouter",
|
||||
"ollama",
|
||||
)
|
||||
|
||||
@@ -77,7 +76,7 @@ LLM_FALLBACK_MODELS: dict[str, tuple[str, ...]] = {
|
||||
),
|
||||
"orcarouter": (
|
||||
"orcarouter/auto",
|
||||
"anthropic/claude-sonnet-4.6",
|
||||
"anthropic/claude-sonnet-4-6",
|
||||
"deepseek/deepseek-v4-pro",
|
||||
"openai/gpt-4o",
|
||||
),
|
||||
@@ -96,7 +95,6 @@ FEATURED_EMBEDDING_PROVIDERS: tuple[str, ...] = (
|
||||
"jina",
|
||||
"cohere",
|
||||
"openrouter",
|
||||
"orcarouter",
|
||||
"azure_openai",
|
||||
"vllm", # also covers LM Studio, llama.cpp via the same OpenAI-compatible adapter
|
||||
"ollama",
|
||||
|
||||
@@ -771,20 +771,68 @@ async def test_owner_sets_supported_reasoning_effort_on_their_managed_model(
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_runtime_validation_rejects_a_stale_reasoning_effort(tmp_path: Path) -> None:
|
||||
async def test_runtime_validation_accepts_any_effort_for_a_bound_model(tmp_path: Path) -> None:
|
||||
"""Effort is a per-request knob, not part of what binds a config to a token.
|
||||
|
||||
Rejecting a request whose effort differs from the stored default would fail
|
||||
every caller that varies it for a single turn.
|
||||
"""
|
||||
snapshot = _snapshot("live", _model("gpt-5.6-sol"))
|
||||
service, _model_catalog = _bound_reasoning_service(tmp_path, snapshot)
|
||||
token = await service.get_token()
|
||||
|
||||
for effort in ("high", "low", None):
|
||||
service.validate_runtime_profile(token, "gpt-5.6-sol", effort)
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_runtime_validation_rejects_a_model_outside_the_profile(tmp_path: Path) -> None:
|
||||
snapshot = _snapshot("live", _model("gpt-5.6-sol"))
|
||||
service, _model_catalog = _bound_reasoning_service(tmp_path, snapshot)
|
||||
token = await service.get_token()
|
||||
validator = getattr(service, "validate_runtime_profile", None)
|
||||
|
||||
assert callable(validator)
|
||||
with pytest.raises(CodexAuthError) as exc_info:
|
||||
validator(token, "gpt-5.6-sol", "high")
|
||||
service.validate_runtime_profile(token, "some-other-model", None)
|
||||
|
||||
assert exc_info.value.code == "codex_catalog_unavailable"
|
||||
assert exc_info.value.http_status == 409
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_a_profile_predating_the_account_binding_still_works(tmp_path: Path) -> None:
|
||||
"""Absent is legacy, not "someone else's".
|
||||
|
||||
Managed profiles published before ``codex_account_binding`` existed carry
|
||||
no such key. Reading that as a mismatch would lock every account that
|
||||
signed in before it shipped out of Codex entirely.
|
||||
"""
|
||||
snapshot = _snapshot("live", _model("gpt-5.6-sol"))
|
||||
service, model_catalog = _bound_reasoning_service(tmp_path, snapshot)
|
||||
token = await service.get_token()
|
||||
|
||||
catalog = model_catalog.load()
|
||||
_managed_profile(catalog).pop("codex_account_binding", None)
|
||||
model_catalog.save(catalog)
|
||||
|
||||
service.validate_runtime_profile(token, "gpt-5.6-sol", None)
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_a_profile_bound_to_another_account_is_still_refused(tmp_path: Path) -> None:
|
||||
snapshot = _snapshot("live", _model("gpt-5.6-sol"))
|
||||
service, model_catalog = _bound_reasoning_service(tmp_path, snapshot)
|
||||
token = await service.get_token()
|
||||
|
||||
catalog = model_catalog.load()
|
||||
_managed_profile(catalog)["codex_account_binding"] = "another-account-binding"
|
||||
model_catalog.save(catalog)
|
||||
|
||||
with pytest.raises(CodexAuthError) as exc_info:
|
||||
service.validate_runtime_profile(token, "gpt-5.6-sol", None)
|
||||
|
||||
assert exc_info.value.http_status == 409
|
||||
|
||||
|
||||
def test_profile_binding_matches_only_current_credentials(tmp_path: Path) -> None:
|
||||
snapshot = _snapshot("live", _model("gpt-5.6-sol"))
|
||||
service, model_catalog = _bound_reasoning_service(tmp_path, snapshot)
|
||||
|
||||
Reference in New Issue
Block a user