Skip to content

armgit / avibe

Public Imported from GitHub
0

Make your computer a home for your AI partner. Avibe is the local-first Agent OS: Vibey, its built-in AI partner, works out of the box, and Claude Code, Codex & OpenCode run unchanged beside it — reach them from your browser, phone, or any chat app.

fix(model-hub): accept unprefixed Claude models (#2155)

rkrkrkka89727463b45
diff --git a/core/handlers/model_hub/catalog_admission.py b/core/handlers/model_hub/catalog_admission.py
index fb475837a..6b0c0a2ae 100644
--- a/core/handlers/model_hub/catalog_admission.py
+++ b/core/handlers/model_hub/catalog_admission.py
@@ -16,18 +16,17 @@ def backend_model_admission_error(
model_id: object,
*,
claude_builtin_ids: Iterable[str] = (),
-) -> Literal["backend_model_id_invalid", "backend_model_id_prefix"] | None:
+) -> Literal["backend_model_id_invalid"] | None:
"""Return the request-boundary error for one generated model identity."""
canonical = canonical_model_id(model_id)
if canonical is None or canonical != model_id:
return "backend_model_id_invalid"
- if (
- backend == "claude"
- and canonical not in set(claude_builtin_ids)
- and not canonical.startswith(("claude-", "anthropic-"))
- ):
- return "backend_model_id_prefix"
+ if backend == "claude" and canonical == "default":
+ return "backend_model_id_invalid"
+ # Backend model IDs are routing identities, not vendor labels. In
+ # particular, Claude Code may explicitly launch a Hub model such as
+ # ``grok-4.7`` and the Gateway must preserve that exact spelling.
return None
diff --git a/tests/test_backend_model_catalog.py b/tests/test_backend_model_catalog.py
index 186bd3d14..53ea3ed9c 100644
--- a/tests/test_backend_model_catalog.py
+++ b/tests/test_backend_model_catalog.py
@@ -998,6 +998,9 @@ def test_retiring_a_model_keeps_persisted_selections_admissible():
is None
), model
+ assert backend_model_admission_error("claude", "grok-4.7") is None
+ assert backend_model_admission_error("claude", "default") == "backend_model_id_invalid"
+
def test_visible_backend_model_entries_drops_only_hidden_rows():
catalog = {
diff --git a/tests/test_model_hub_api.py b/tests/test_model_hub_api.py
index 49706a6e1..c415cfb9d 100644
--- a/tests/test_model_hub_api.py
+++ b/tests/test_model_hub_api.py
@@ -2584,7 +2584,7 @@ def test_candidate_protocol_projection_is_total_only_for_opencode(tmp_path):
)
-def test_candidates_exclude_ids_the_backend_write_would_reject(monkeypatch, tmp_path):
+def test_candidates_exclude_only_noncanonical_ids(monkeypatch, tmp_path):
service, store, _adapter = _service(tmp_path)
invalid_claude_id = "not-a-claude-family"
unencodable = "claude-invalid\ud800"
@@ -2622,7 +2622,7 @@ def test_candidates_exclude_ids_the_backend_write_would_reject(monkeypatch, tmp_
candidates = service.agent_model_candidates("claude")
ids = {item["id"] for group in candidates.values() for item in group}
- assert invalid_claude_id not in ids
+ assert invalid_claude_id in ids
assert unencodable not in ids
@@ -3239,7 +3239,7 @@ def test_model_producers_emit_admissible_backend_payloads(
assert parsed == ModelHubBackendModelConfig.from_payload(parsed.to_payload())
-def test_claude_reconcile_excludes_non_claude_cli_override(monkeypatch, tmp_path):
+def test_claude_reconcile_accepts_explicit_non_claude_cli_override(monkeypatch, tmp_path):
service, store, _adapter = _service(tmp_path)
monkeypatch.setattr(
service,
@@ -3258,7 +3258,7 @@ def test_claude_reconcile_excludes_non_claude_cli_override(monkeypatch, tmp_path
asyncio.run(service.reconcile_builtin_models(("claude",)))
model_ids = {model.id for model in store.config.agents["claude"].models}
- assert "deepseek-v3.2" not in model_ids
+ assert "deepseek-v3.2" in model_ids
assert "claude-sonnet-9" in model_ids
@@ -3876,22 +3876,21 @@ def test_backend_catalog_restores_a_removed_claude_builtin_alias(
assert model_id not in store.config.agents["claude"].removed_model_ids
-def test_backend_catalog_still_rejects_an_unknown_unprefixed_claude_id(tmp_path):
+def test_backend_catalog_saves_an_unknown_unprefixed_claude_id(tmp_path):
service, _store, _adapter = _service(tmp_path)
baseline = next(agent["catalog_models"] for agent in service.list_agents() if agent["backend"] == "claude")
unknown = {
**baseline[1],
- "id": "deepseek-v4",
+ "id": "grok-4.7",
"origin": "manual",
}
- with pytest.raises(ModelHubError) as raised:
- asyncio.run(service.set_agent_models("claude", baseline, [*baseline, unknown]))
+ result = asyncio.run(service.set_agent_models("claude", baseline, [*baseline, unknown]))
- assert raised.value.code == "backend_model_id_prefix"
+ assert any(model["id"] == "grok-4.7" for model in result["agent"]["catalog_models"])
-def test_backend_catalog_rejects_a_new_unprefixed_claude_id_forged_into_baseline(
+def test_backend_catalog_accepts_a_new_unprefixed_claude_id_in_baseline(
tmp_path,
):
service, _store, _adapter = _service(tmp_path)
@@ -3902,16 +3901,15 @@ def test_backend_catalog_rejects_a_new_unprefixed_claude_id_forged_into_baseline
"origin": "manual",
}
- with pytest.raises(ModelHubError) as raised:
- asyncio.run(
- service.set_agent_models(
- "claude",
- [*baseline, forged],
- [*baseline, forged],
- )
+ result = asyncio.run(
+ service.set_agent_models(
+ "claude",
+ baseline,
+ [*baseline, forged],
)
+ )
- assert raised.value.code == "backend_model_id_prefix"
+ assert any(model["id"] == "deepseek-v4" for model in result["agent"]["catalog_models"])
def test_backend_catalog_saves_claude_models_without_native_default(tmp_path):
@@ -3935,7 +3933,7 @@ def test_backend_catalog_rejects_claude_native_default_selection(tmp_path):
assert raised.value.code == "backend_model_id_invalid"
-def test_backend_catalog_reports_claude_discovery_prefix_requirement(tmp_path):
+def test_backend_catalog_accepts_a_new_unprefixed_claude_id(tmp_path):
service, _store, _adapter = _service(tmp_path)
baseline = next(agent["catalog_models"] for agent in service.list_agents() if agent["backend"] == "claude")
invalid = {
@@ -3944,10 +3942,9 @@ def test_backend_catalog_reports_claude_discovery_prefix_requirement(tmp_path):
"origin": "manual",
}
- with pytest.raises(ModelHubError) as raised:
- asyncio.run(service.set_agent_models("claude", baseline, [*baseline, invalid]))
+ result = asyncio.run(service.set_agent_models("claude", baseline, [*baseline, invalid]))
- assert raised.value.code == "backend_model_id_prefix"
+ assert any(model["id"] == "deepseek-v4" for model in result["agent"]["catalog_models"])
def test_agents_endpoint_projects_cli_presence_from_runtime(tmp_path):
diff --git a/tests/test_model_hub_resolution.py b/tests/test_model_hub_resolution.py
index cfc9bdfed..f9201399c 100644
--- a/tests/test_model_hub_resolution.py
+++ b/tests/test_model_hub_resolution.py
@@ -483,6 +483,51 @@ def test_runtime_fallback_uses_selected_hops_exact_model_id():
assert resolution.supply_status == "degraded"
+def test_claude_hub_route_preserves_bare_xai_model_id():
+ source = _source("src_xai0001", ("grok-4.7",), vendor="xai")
+ config = _config([source], model="grok-4.7")
+ config.agents["claude"].routes["grok-4.7"] = ModelHubRouteConfig(
+ hops=(ModelHubRouteHopConfig(source.id, "grok-4.7"),)
+ )
+
+ resolution = resolve_model_hub_turn(config, "claude", "grok-4.7")
+
+ assert resolution.source is source
+ assert resolution.target_model == "grok-4.7"
+
+
+def test_claude_hub_invocation_sends_bare_xai_model_id(tmp_path):
+ source = _source("src_xai0002", ("grok-4.7",), vendor="xai")
+ config = _config([source], model="grok-4.7")
+ config.agents["claude"].routes["grok-4.7"] = ModelHubRouteConfig(
+ hops=(ModelHubRouteHopConfig(source.id, "grok-4.7"),)
+ )
+ adapter = FakeAdapter()
+ adapter.outcomes.append(
+ RawCallOutcome(
+ kind=RawOutcomeKind.SUCCESS,
+ http_status=200,
+ error_code=None,
+ redacted_message=None,
+ stream_started=False,
+ model_id="grok-4.7",
+ source_id=source.id,
+ )
+ )
+ service, _store, _ = _service(tmp_path, config, adapter)
+
+ resolved = asyncio.run(
+ service.resolve(
+ backend="claude",
+ model_id="grok-4.7",
+ request=ModelHubRequest({}, protocol="anthropic"),
+ )
+ )
+
+ assert resolved.source_id == source.id
+ assert adapter.invocations == [(source.id, "grok-4.7")]
+
+
def test_supply_is_degraded_when_a_later_exact_hop_is_blocked():
first = _source("src_route020", ("requested",))
second = _source("src_route021", ("requested",), status="cooldown")
diff --git a/ui/src/components/settings/models/serverCopy.test.ts b/ui/src/components/settings/models/serverCopy.test.ts
index 9c3c4671f..09b538474 100644
--- a/ui/src/components/settings/models/serverCopy.test.ts
+++ b/ui/src/components/settings/models/serverCopy.test.ts
@@ -170,7 +170,6 @@ describe('catalogSaveFailureKey', () => {
['backend_model_in_route', 'saveRouted'],
['candidate_suppliers_changed', 'saveSuppliersChanged'],
['backend_model_conflict', 'saveConflict'],
- ['backend_model_id_prefix', 'saveIdPrefix'],
['backend_model_id_invalid', 'saveIdInvalid'],
['backend_model_duplicate', 'saveDuplicate'],
['backend_model_locked', 'saveLocked'],
@@ -197,12 +196,9 @@ describe('catalogSaveFailureKey', () => {
expect(texts).not.toContain(t('en')('settings.models.gateway.catalog.saveFailed'));
});
- it('asks for a re-add where the ID rule is broken, because the field is read-only', () => {
+ it('asks for a re-add where the ID is invalid, because the field is read-only', () => {
// Edit mode keeps the backend model id read-only, so 「fix the ID」 would be
// advice this dialog refuses to take.
- const prefix = catalogSaveFailureKey('modelHub.errors.backend_model_id_prefix');
- expect(t('en')(prefix)).toMatch(/add it again/i);
- expect(t('zh')(prefix)).toContain('重新添加');
const invalid = catalogSaveFailureKey('modelHub.errors.backend_model_id_invalid');
expect(t('en')(invalid)).toMatch(/add it again/i);
expect(t('zh')(invalid)).toContain('重新添加');
diff --git a/ui/src/components/settings/models/serverCopy.ts b/ui/src/components/settings/models/serverCopy.ts
index 7c977f997..b84821a61 100644
--- a/ui/src/components/settings/models/serverCopy.ts
+++ b/ui/src/components/settings/models/serverCopy.ts
@@ -119,7 +119,6 @@ const CATALOG_SAVE_FAILURE_COPY: Readonly<Record<string, TranslationKey>> = {
'modelHub.errors.backend_model_in_route': 'settings.models.gateway.catalog.saveRouted',
'modelHub.errors.candidate_suppliers_changed': 'settings.models.gateway.catalog.saveSuppliersChanged',
'modelHub.errors.backend_model_conflict': 'settings.models.gateway.catalog.saveConflict',
- 'modelHub.errors.backend_model_id_prefix': 'settings.models.gateway.catalog.saveIdPrefix',
'modelHub.errors.backend_model_id_invalid': 'settings.models.gateway.catalog.saveIdInvalid',
'modelHub.errors.backend_model_duplicate': 'settings.models.gateway.catalog.saveDuplicate',
'modelHub.errors.backend_model_locked': 'settings.models.gateway.catalog.saveLocked',
diff --git a/ui/src/i18n/en.json b/ui/src/i18n/en.json
index f6150578c..490ac2b4b 100644
--- a/ui/src/i18n/en.json
+++ b/ui/src/i18n/en.json
@@ -961,7 +961,6 @@
"saveRouted": "A model you removed still has a route. The list was re-read from the server; clear the route first, then remove it.",
"saveSuppliersChanged": "The available providers changed. The list was re-read from the server; review the model's providers and save again.",
"saveConflict": "This list changed elsewhere while you were editing. Your changes were replayed onto the newer list; check it and save again.",
- "saveIdPrefix": "Claude model IDs must start with claude- or anthropic-. Remove the model and add it again with a valid ID.",
"saveIdInvalid": "A model ID in this list is not valid for this backend. Remove the model and add it again.",
"saveDuplicate": "Two models in this list share the same ID. Remove one, then save again.",
"saveLocked": "This list disagrees with a model the server owns. It was re-read from the server; check it and save again.",
diff --git a/ui/src/i18n/keyCoverage.test.ts b/ui/src/i18n/keyCoverage.test.ts
index 23258ccb9..e46542df0 100644
--- a/ui/src/i18n/keyCoverage.test.ts
+++ b/ui/src/i18n/keyCoverage.test.ts
@@ -878,7 +878,6 @@ const NON_KEY_LITERALS = [
'modelHub.errors.backend_model_conflict',
'modelHub.errors.backend_model_duplicate',
'modelHub.errors.backend_model_id_invalid',
- 'modelHub.errors.backend_model_id_prefix',
'modelHub.errors.backend_model_in_route',
'modelHub.errors.backend_model_locked',
'modelHub.errors.candidate_suppliers_changed',
diff --git a/ui/src/i18n/zh.json b/ui/src/i18n/zh.json
index 056f9a23c..cc78bd7da 100644
--- a/ui/src/i18n/zh.json
+++ b/ui/src/i18n/zh.json
@@ -961,7 +961,6 @@
"saveRouted": "你移除的模型仍配置了路由。已重新读取服务器上的列表,请先清空该路由再移除。",
"saveSuppliersChanged": "可用供应商已发生变化。已重新读取服务器上的列表,请确认模型的供应商后重新保存。",
"saveConflict": "编辑期间该列表在别处发生了变更。你的改动已重放到新列表上,请确认后重新保存。",
- "saveIdPrefix": "Claude 模型 ID 必须以 claude- 或 anthropic- 开头。请移除该模型,再用合法的 ID 重新添加。",
"saveIdInvalid": "列表中有模型 ID 不适用于这个后端。请移除该模型后重新添加。",
"saveDuplicate": "列表中有两个模型使用了相同的 ID,请移除其中一个后重新保存。",
"saveLocked": "该列表与服务端自有的模型不一致。已重新读取服务器上的列表,请确认后重新保存。",
diff --git a/vibe/i18n/en.json b/vibe/i18n/en.json
index 1ed6bc1f9..993b67ac9 100644
--- a/vibe/i18n/en.json
+++ b/vibe/i18n/en.json
@@ -980,7 +980,6 @@
"mode_switch_blocked": "This operation is blocked by the current supply mode or selection.",
"backend_model_catalog_invalid": "The backend model list contains invalid fields.",
"backend_model_id_invalid": "This backend model ID is invalid.",
- "backend_model_id_prefix": "Claude Code custom model IDs must start with claude- or anthropic-.",
"backend_model_duplicate": "Each backend model ID may appear only once.",
"backend_model_locked": "Claude Code Default and built-in model origins cannot be changed.",
"backend_model_in_route": "Clear this model's route before removing it from the backend model list.",
diff --git a/vibe/i18n/zh.json b/vibe/i18n/zh.json
index 97d27f527..393e5ff61 100644
--- a/vibe/i18n/zh.json
+++ b/vibe/i18n/zh.json
@@ -980,7 +980,6 @@
"mode_switch_blocked": "当前模型管理方式或选择阻止了此操作。",
"backend_model_catalog_invalid": "Backend 模型列表中包含无效字段。",
"backend_model_id_invalid": "这个 Backend 模型 ID 无效。",
- "backend_model_id_prefix": "Claude Code 自定义模型 ID 必须以 claude- 或 anthropic- 开头。",
"backend_model_duplicate": "同一个 Backend 模型 ID 只能出现一次。",
"backend_model_locked": "不能修改 Claude Code 的 Default 项或内置模型的来源类型。",
"backend_model_in_route": "请先清空该模型的路由,再从 Backend 模型列表中移除。",