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.

feat(model-hub): save providers before optional model tests (#1940)

Call White69d43d25f30e
diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml
index e80829065..f40fe0399 100644
--- a/.github/workflows/lint.yml
+++ b/.github/workflows/lint.yml
@@ -56,6 +56,7 @@ jobs:
run: |
npx playwright install --with-deps chromium
npm run test:model-catalog
+ npm run test:model-provider
npm run test:project-order
build-linux-artifacts:
diff --git a/core/handlers/model_hub/rpc.py b/core/handlers/model_hub/rpc.py
index 2d25703c8..5da138a52 100644
--- a/core/handlers/model_hub/rpc.py
+++ b/core/handlers/model_hub/rpc.py
@@ -81,6 +81,8 @@ async def dispatch_model_hub_rpc(
return await service.observe_source(payload.get("observation"))
if operation == "create_source":
return await service.create_source(payload.get("source"))
+ if operation == "probe_source":
+ return await service.probe_source(payload.get("source_id"), payload.get("probe"))
if operation == "patch_source":
return await service.patch_source(payload.get("source_id"), payload.get("patch"))
if operation == "replace_credential":
diff --git a/core/handlers/model_hub/service.py b/core/handlers/model_hub/service.py
index 852197d35..5eb373b13 100644
--- a/core/handlers/model_hub/service.py
+++ b/core/handlers/model_hub/service.py
@@ -171,6 +171,8 @@ def _storable_backend_model_metadata(
AGENT_CHAIN_CONTRACT_VERSION = 10
PROBE_RESULT_CONTRACT_VERSION = 10
+_SOURCE_DISCOVERY_TIMEOUT_SECONDS = 15
+_SOURCE_PROBE_TIMEOUT_SECONDS = 60
_REORDER_ORDER_UNSET = object()
_REASONING_EFFORT_TELEMETRY_MAX_BYTES = 256
# Settlement generations are minted per attempt start and live only in this
@@ -2989,6 +2991,22 @@ class ModelHubService:
source = ModelHubSourceConfig.from_payload(source.to_payload())
persisted = False
try:
+ if save_unverified:
+ # Inventory is useful, not admission evidence. Work on a
+ # clone so a failed listing cannot partly replace manual
+ # entries. The new Source still has one commit/nonce owner.
+ candidate = ModelHubSourceConfig.from_payload(source.to_payload())
+ try:
+ discovered = await asyncio.wait_for(
+ self._discover(candidate), timeout=_SOURCE_DISCOVERY_TIMEOUT_SECONDS,
+ )
+ self._apply_discovered_models(
+ candidate, candidate.models, discovered, allow_empty=True,
+ )
+ except (ModelHubError, asyncio.TimeoutError):
+ pass
+ else:
+ source = candidate
async with self._mutation_lock:
await self._commit_new_source_locked(source)
persisted = True
@@ -5164,6 +5182,8 @@ class ModelHubService:
source: ModelHubSourceConfig,
model_id: str,
backend: str,
+ *,
+ output_tokens: int = 1,
) -> ModelHubRequest:
# A probe enters the same translation seam as a live backend turn, so
# its payload must be shaped in the backend's client protocol.
@@ -5171,23 +5191,160 @@ class ModelHubService:
if request_protocol == "anthropic":
payload = {
"model": model_id,
- "max_tokens": 1,
+ "max_tokens": output_tokens,
"messages": [{"role": "user", "content": "ping"}],
}
elif request_protocol == "openai_responses":
payload = {
"model": model_id,
- "max_output_tokens": 1,
+ "max_output_tokens": output_tokens,
"input": "ping",
}
else:
payload = {
"model": model_id,
- "max_tokens": 1,
+ "max_tokens": output_tokens,
"messages": [{"role": "user", "content": "ping"}],
}
return ModelHubRequest(payload, protocol=request_protocol)
+ async def probe_source(self, source_id: str, payload: object) -> dict:
+ """Test one saved API-key model, independently of Agent route/health."""
+ if not isinstance(payload, dict) or set(payload) != {"model"}:
+ raise ModelHubError("discovery_failed")
+ model_id = payload["model"]
+ # This selects an existing inventory identity, not a newly admitted ID.
+ # Legacy persisted IDs remain testable even beyond today's input bound.
+ if not isinstance(model_id, str) or not model_id.strip():
+ raise ModelHubError("discovery_failed")
+ model_id = normalized_model_id(model_id)
+
+ def selected(config: ModelHubConfig) -> ModelHubSourceConfig:
+ source = self._source(config, source_id)
+ if (
+ source.kind != "api_key"
+ or source.supply_channel != "hub"
+ or not source.credential_ref
+ or not any(model.id == model_id and not model.retired for model in source.models)
+ ):
+ raise ModelHubError("mapping_target_unavailable", status=409)
+ return source
+
+ handle = None
+ outcome = None
+ source = None
+ admitted_at = None
+
+ async def invoke_selected() -> None:
+ nonlocal source, handle, outcome, admitted_at
+ # Bound local waiting too, but never call it a model failure before
+ # the adapter has actually admitted this Source/model invocation.
+ async with self._mutation_lock:
+ selected(self.store.load())
+ while True:
+ await self._prepare_engine_for_demand()
+ await self._mutation_lock.acquire()
+ held = True
+
+ def release_owner() -> None:
+ nonlocal held
+ if held:
+ held = False
+ self._mutation_lock.release()
+
+ def admitted() -> None:
+ nonlocal admitted_at
+ admitted_at = time.monotonic()
+ release_owner()
+
+ try:
+ source = ModelHubSourceConfig.from_payload(
+ selected(self.store.load()).to_payload(),
+ )
+ if not self._engine_synced:
+ continue
+ # OpenCode preserves the request's explicit protocol and
+ # API keys have unrestricted origins. No Agent resolver
+ # is involved: the adapter binds this exact Source.
+ handle = await self._engine_call(self.adapter.invoke(
+ source.id,
+ model_id,
+ self._probe_request(source, model_id, "opencode", output_tokens=128),
+ False,
+ "opencode",
+ on_admitted=admitted,
+ ))
+ break
+ finally:
+ release_owner()
+ if admitted_at is None:
+ raise ModelHubError("engine_down", status=503)
+ if handle.stream is not None:
+ async for _chunk in handle.stream:
+ pass
+ outcome = await self._engine_call(handle.outcome())
+
+ async def settle_attempt() -> None:
+ try:
+ if source is not None and outcome is not None:
+ await self._verify_successful_source(
+ source.id, source.credential_ref, source.verification_pending, outcome,
+ )
+ finally:
+ if handle is not None:
+ try:
+ await handle.close_stream()
+ finally:
+ await self._meter_call(
+ source_id=source_id, model_id=model_id,
+ outcome=outcome, observed=handle.observed,
+ )
+
+ try:
+ await asyncio.wait_for(invoke_selected(), timeout=_SOURCE_PROBE_TIMEOUT_SECONDS)
+ except asyncio.TimeoutError:
+ if admitted_at is None:
+ raise ModelHubError("engine_down", status=503) from None
+ outcome = RawCallOutcome(
+ kind=RawOutcomeKind.TIMEOUT,
+ http_status=None,
+ error_code=None,
+ redacted_message=None,
+ stream_started=False,
+ model_id=model_id,
+ source_id=source_id,
+ )
+ finally:
+ elapsed_ms = max(0, round((time.monotonic() - admitted_at) * 1000)) if admitted_at is not None else 0
+ # A known outcome belongs to the attempt even if its caller leaves.
+ # Drain finite settlement before propagating caller cancellation.
+ settlement_task = asyncio.create_task(settle_attempt())
+ try:
+ await asyncio.shield(settlement_task)
+ except asyncio.CancelledError as cancelled:
+ try:
+ await await_owned_task(settlement_task)
+ except BaseException:
+ # Cancellation owns the response, not resource settlement.
+ pass
+ raise cancelled
+ assert source is not None and outcome is not None
+ succeeded = outcome.kind is RawOutcomeKind.SUCCESS
+ # Classify for display only. A selected model failure cannot block other
+ # models on this Source, refresh credentials, or modify route state.
+ decision = classify_outcome(outcome)
+ if decision.action == "refresh":
+ decision = ResolutionDecision("fallback", reason="credential_revoked")
+ error = None if succeeded else self._probe_failure(outcome, decision)[0]
+ return {
+ "source_id": source.id,
+ "model_id": model_id,
+ "protocol": source.protocol,
+ "reachable": succeeded,
+ "latency_ms": elapsed_ms,
+ "error": error,
+ }
+
@staticmethod
def _probe_failure(
outcome: RawCallOutcome,
diff --git a/docs/plans/model-hub-contracts/README.md b/docs/plans/model-hub-contracts/README.md
index 2bf5d69a6..96d8d3619 100644
--- a/docs/plans/model-hub-contracts/README.md
+++ b/docs/plans/model-hub-contracts/README.md
@@ -176,6 +176,7 @@ revision; the discovering lane does not reinterpret or edit the contract in plac
| `backend-model.schema.json` | Backend Agent model identity, editable capability metadata, and server-owned lock/routeability projection. |
| `agent-chain.schema.json` | Effective route, manual override and origin projection plus current execution position, runnability, blockers, live connection backoff, retry metadata, and model supply state. |
| `probe-result.schema.json` | Saved recovery probes and route probes over the shared effective plan, including the live connection-backoff reason without persistent network health. |
+| `source-probe-result.schema.json` | Explicit API-key Source/model test, without Agent routing, fallback or provider-wide health mutation. |
| `observation-result.schema.json` | Non-persisting Add-time connectivity, authentication, protocol-establishment, and inventory observation. |
| `turn-provenance.schema.json` | Exactly attributed turn attempts and terminal outcome; no policy or mapping discriminator. The one versioned object persisted to disk, so it accepts every released version. |
| `usage-summary.schema.json` | Metered token usage over a trailing local-day window, aggregated from proxied turns. A report only: no consumer may feed it back into resolution, admission, or cooldown. |
diff --git a/docs/plans/model-hub-contracts/api-response.schema.json b/docs/plans/model-hub-contracts/api-response.schema.json
index 85bbe1066..ebcce3825 100644
--- a/docs/plans/model-hub-contracts/api-response.schema.json
+++ b/docs/plans/model-hub-contracts/api-response.schema.json
@@ -13,6 +13,7 @@
{"method": "POST", "path": "/api/models/sources/<id>/reauth", "response_schema": "OAuthFlowResponse", "exercise": {"path": "/api/models/sources/src_subscribe01/reauth", "status": 200, "json": {"acknowledge_irreversible": true}}},
{"method": "DELETE", "path": "/api/models/sources/<id>?force=<bool>", "response_schema": "SourceDeleteResponse", "exercise": {"path": "/api/models/sources/src_delete0001?force=false", "status": 200, "json": {}}},
{"method": "POST", "path": "/api/models/sources/<id>/refresh", "response_schema": "SourceMutationResponse", "exercise": {"path": "/api/models/sources/src_conform001/refresh", "status": 200, "json": {}}},
+ {"method": "POST", "path": "/api/models/sources/<id>/probe", "response_schema": "SourceProbeResponse", "exercise": {"path": "/api/models/sources/src_conform001/probe", "status": 200, "json": {"model": "claude-opus-4-6"}}},
{"method": "POST", "path": "/api/models/sources/<source_id>/models", "response_schema": "SourceResponse", "exercise": {"path": "/api/models/sources/src_conform001/models", "status": 201, "json": {"model_id": "manual-contract-model", "reasoning_efforts": []}}},
{"method": "PATCH", "path": "/api/models/sources/<source_id>/models/<model_id>", "response_schema": "SourceResponse", "exercise": {"path": "/api/models/sources/src_conform001/models/retire-model", "status": 200, "json": {"reasoning_efforts": ["high"]}}},
{"method": "DELETE", "path": "/api/models/sources/<source_id>/models/<model_id>", "response_schema": "SourceMutationResponse", "exercise": {"path": "/api/models/sources/src_conform001/models/retire-model", "status": 200, "json": {}}},
@@ -47,6 +48,16 @@
{"method": "POST", "path": "/api/models/runtime/stop", "response_schema": "RuntimeResponse", "exercise": {"path": "/api/models/runtime/stop", "status": 200}}
],
"definitions": {
+ "SourceProbeResponse": {
+ "type": "object",
+ "additionalProperties": false,
+ "required": ["ok", "contract_version", "probe"],
+ "properties": {
+ "ok": {"const": true},
+ "contract_version": {"const": 10},
+ "probe": {"$ref": "model-hub/source-probe-result.schema.json"}
+ }
+ },
"SourceApi": {
"allOf": [
{"$ref": "model-hub/source.schema.json"},
diff --git a/docs/plans/model-hub-contracts/api.md b/docs/plans/model-hub-contracts/api.md
index 927de5e16..6939a6f73 100644
--- a/docs/plans/model-hub-contracts/api.md
+++ b/docs/plans/model-hub-contracts/api.md
@@ -32,6 +32,7 @@ remain readable; ephemeral envelopes use only the terminal version.
| POST `/api/models/sources/<id>/reauth` | `{acknowledge_irreversible?: true}` → `{flow: OAuthFlow}` | Both Hub OAuth and `native_cli` Sources require the acknowledgement before OAuth starts. Missing or false acknowledgement returns `reauth_confirmation_required` before any adapter call. See repair rules. |
| DELETE `/api/models/sources/<id>?force=<bool>` | `{would_remove_hops?: RouteHopRef[], would_interrupt?: SupplyGap[]}` → guarded `409` or `{removed_hops, interrupted}` | A confirmed delete removes the Source from every backend Source order and Route chain in one transaction. A nonempty destructive plan commits only when the body exactly echoes the current refusal plan. |
| POST `/api/models/sources/<id>/refresh` | `{force?: boolean, would_remove_hops?: RouteHopRef[], would_interrupt?: SupplyGap[]}` → guarded Source-mutation envelope | The sole saved connectivity/discovery/recovery mutation. |
+| POST `/api/models/sources/<id>/probe` | `{model}` → `{probe: SourceProbeResult}` | Explicit API-key test through the managed invocation adapter, using this exact Source/model/protocol. The model must be a non-retired saved inventory row. No Agent routing, fallback, discovery, credential refresh or Source-health change. Only a successful matching credential invocation clears pending verification. Usage is metered; the total invocation deadline is 60 seconds. |
| POST `/api/models/sources/<source_id>/models` | `{model_id, display_name?, reasoning_efforts}` → `{source: Source}` | Creates one user-authored model entry. The Source identity comes only from the path. |
| PATCH `/api/models/sources/<source_id>/models/<model_id>` | `{reasoning_efforts}` → `{source: Source}` | Replaces the complete capability list only when `reasoning_efforts_source` is `user` or null, without changing identity, origin, or Routes. An `upstream` or `catalog` declaration returns HTTP 409 `source_model_tiers_managed` with its provenance in the `reasoning_efforts_source` sibling. |
| DELETE `/api/models/sources/<source_id>/models/<model_id>` | `{force?: boolean, would_remove_hops?: RouteHopRef[], would_interrupt?: SupplyGap[]}` → guarded `409` or Source-mutation success | Deletes a manual entry; for a discovered entry it persists `retired: true` without deleting the row. Both outcomes use the same exact-hop and supply guards. |
@@ -112,8 +113,10 @@ with failed inventory discovery produces no Source unless this request explicitl
`accept_unavailable_inventory: true`; the accepted Source has `models: []` and the
existing uncertain health projection.
-Explicit `save_unverified: true` instead saves the catalog-pinned or user-declared
-interface without upstream observation or discovery. Custom Auto without a declaration
+The add dialog always uses `save_unverified: true`: it saves the catalog-pinned or user-declared
+interface without upstream observation as an admission gate. It attempts one bounded
+inventory discovery with the provisioned credential before committing the new Source;
+failure preserves manual entries and does not block saving. Custom Auto without a declaration
is rejected before credential provisioning. Manual models remain manual; no inventory
is invented. The Source carries an opaque `verification_pending` marker, independently of its
routing health, and may be configured and invoked. List/detail surfaces label it
diff --git a/docs/plans/model-hub-contracts/source-create.schema.json b/docs/plans/model-hub-contracts/source-create.schema.json
index fbcdbc76f..50e406c50 100644
--- a/docs/plans/model-hub-contracts/source-create.schema.json
+++ b/docs/plans/model-hub-contracts/source-create.schema.json
@@ -2,7 +2,7 @@
"$schema": "http://json-schema.org/draft-07/schema#",
"$id": "model-hub/source-create.schema.json",
"title": "SourceCreate",
- "description": "API-key Source creation input. The default path requires authenticated observation and a protocol established by a shipped catalog pin, a declaration on custom, or matching response proof. Explicit save_unverified consent instead persists configuration with verification pending, without observation or discovery, and requires a catalog pin or a concrete custom declaration. The server owns Source identity, discovered inventory, health, usage, custody metadata and timestamps. Both paths use canonical validation and the same custody, rollback and reconciliation lifecycle. When client_nonce is present, the server reserves it atomically in process before observation or credential work; only a successful commit persists Source.client_nonce unchanged. A lost-response client reconciles through the ordinary Source list without a receipt or separate endpoint. Nonce uniqueness covers live-process reservations and live Sources; process restart or Source deletion releases it, and a later same-nonce request after the required list read is a fresh create.",
+ "description": "API-key Source creation input. The default path requires authenticated observation and a protocol established by a shipped catalog pin, a declaration on custom, or matching response proof. Explicit save_unverified consent instead persists configuration with verification pending, without observation, attempts best-effort inventory discovery, and requires a catalog pin or a concrete custom declaration. The server owns Source identity, discovered inventory, health, usage, custody metadata and timestamps. Both paths use canonical validation and the same custody, rollback and reconciliation lifecycle. When client_nonce is present, the server reserves it atomically in process before observation or credential work; only a successful commit persists Source.client_nonce unchanged. A lost-response client reconciles through the ordinary Source list without a receipt or separate endpoint. Nonce uniqueness covers live-process reservations and live Sources; process restart or Source deletion releases it, and a later same-nonce request after the required list read is a fresh create.",
"type": "object",
"required": ["vendor", "key"],
"additionalProperties": false,
@@ -10,7 +10,7 @@
"save_unverified": {
"type": "boolean",
"default": false,
- "description": "Explicit consent to save configuration without upstream observation or discovery. Requires a catalog-pinned or explicitly declared protocol; custom Auto cannot be guessed. Canonical input validation, credential custody, rollback and nonce reconciliation are unchanged. Sets Source.verification_pending, preserves manual models and does not claim usability."
+ "description": "Save configuration independently of observation. The default UI uses true. Requires a catalog-pinned or explicitly declared protocol; custom Auto cannot be guessed. Attempts bounded inventory discovery with the provisioned credential, but failed or invalid inventory never blocks saving or erases manual entries. Canonical input validation, credential custody, rollback and nonce reconciliation are unchanged. Sets Source.verification_pending and does not claim usability."
},
"vendor": {
"type": "string",
diff --git a/docs/plans/model-hub-contracts/source-probe-result.schema.json b/docs/plans/model-hub-contracts/source-probe-result.schema.json
new file mode 100644
index 000000000..41f5cdd12
--- /dev/null
+++ b/docs/plans/model-hub-contracts/source-probe-result.schema.json
@@ -0,0 +1,22 @@
+{
+ "$schema": "http://json-schema.org/draft-07/schema#",
+ "$id": "model-hub/source-probe-result.schema.json",
+ "title": "SourceProbeResult",
+ "description": "One explicitly selected API-key Source/model invocation. It does not claim provider-wide health and cannot fall back to another Source.",
+ "type": "object",
+ "additionalProperties": false,
+ "required": ["source_id", "model_id", "protocol", "reachable", "latency_ms", "error"],
+ "properties": {
+ "source_id": {"type": "string", "minLength": 1},
+ "model_id": {"type": "string", "minLength": 1},
+ "protocol": {"enum": ["anthropic", "openai_responses", "openai_chat"]},
+ "reachable": {"type": "boolean"},
+ "latency_ms": {"type": "integer", "minimum": 0},
+ "error": {"type": ["string", "null"]}
+ },
+ "allOf": [{
+ "if": {"properties": {"reachable": {"const": true}}},
+ "then": {"properties": {"error": {"type": "null"}}},
+ "else": {"properties": {"error": {"type": "string", "minLength": 1}}}
+ }]
+}
diff --git a/docs/plans/model-hub-e2e-test-plan.md b/docs/plans/model-hub-e2e-test-plan.md
index 17992bfc0..6312a6cb9 100644
--- a/docs/plans/model-hub-e2e-test-plan.md
+++ b/docs/plans/model-hub-e2e-test-plan.md
@@ -43,16 +43,16 @@ Out of scope (documented, not dropped silently):
### B. API-key sources (C16–C29)
| ID | Steps | Expect | Status |
|---|---|---|---|
-| B1 | observe against mock for each protocol, `protocol:'auto'` | correct protocol chosen by response shape; observation payload contract_version 10 | assert |
-| B2 | custom user-declared protocol differs from response shape, authentication succeeds | declaration badge and runtime-risk warning stay visible; explicit confirmation persists exactly the chosen protocol, not an inferred one. Authentication remains required. Auto still needs matching shape evidence (2026-09-04 declaration rule; adapter consumer rejects authenticated but unshaped Auto responses). | assert |
-| B3 | pull models (mock returns `display_name`, `context_length`, `pricing`, `supported_parameters`) | unrelated metadata is dropped; `supported_parameters` is retained in observation and the provenance ladder applies protocol-default tiers | assert |
-| B4 | discovery fails | 422 `inventory_unavailable` unless `accept_unavailable_inventory:true`; then source commits with `state.status=error` | assert |
+| B1 | save custom/catalog providers under their selected/pinned protocol | save-first UI invokes no model and does not require authentication evidence; inventory discovery is best effort and pending verification remains (2026-09-08 owner decision) | assert |
+| B2 | custom declaration differs from the upstream interface | save persists exactly the selected protocol, without an inferred protocol or verified claim; legacy observation API behavior is separate | assert |
+| B3 | save, inspect automatically fetched inventory, choose a model and run Test | preserve upstream inventory order and metadata ownership; preferred exact ID wins, otherwise first model; invoke only the chosen Source/model with no route fallback and clear only its matching credential marker | assert |
+| B4 | discovery fails | save succeeds with pending verification; preserve manual inventory and allow manual addition without refetching | assert |
| B5 | replay create with same `client_nonce` | idempotent, no duplicate source | assert |
| B6 | replace key happy + rollback; rename; patch base URL | C22/C23 contracts | assert |
| B7 | sole owned default source + exact one-hop manual route, verified by reads → delete source → guard 409 → echo plan → force | actual inherited supply gap; impact report lists interrupted agents; malformed echo rejected; canonical route and exact captured default order restored independently (only the owned deleted ID may be omitted) | assert |
| B8 | force transport asymmetry (`?force=` vs body) | document current split (B6 issue); decide normalization | baseline |
| B9 | refetch after upstream inventory change | added/removed diff; **`discovered_at` preserved for pre-existing models** (currently overwritten — fix-first, see B-list) | fix-first |
-| B10 | inspect catalog-managed tiers; edit user/null tiers; reload a v6 row and refresh | catalog edits return 409 `source_model_tiers_managed` with exact provenance; user tiers remain editable; refresh restores catalog truth and emits one redacted override event | assert |
+| B10 | open Advanced settings, inspect catalog-managed tiers; edit user/null tiers; reload a v6 row and refresh | default inventory hides capability details; advanced catalog edits return 409 `source_model_tiers_managed` with exact provenance; user tiers remain editable; refresh restores catalog truth and emits one redacted override event | assert |
| B11 | trigger each of: `mapping_target_unavailable`, `runtime_in_use`, `source_nonce_conflict`, `reauth_confirmation_required`, `turn_not_found` | UI renders human copy, never the raw `modelHub.errors.*` string (B1 — fix-first; baseline expected-fail) | fix-first |
### C. OAuth lifecycle (C30–C40, partial by §1)
diff --git a/docs/plans/model-hub-save-first-testing.md b/docs/plans/model-hub-save-first-testing.md
new file mode 100644
index 000000000..362fbdd4a
--- /dev/null
+++ b/docs/plans/model-hub-save-first-testing.md
@@ -0,0 +1,76 @@
+# Save-first API-key providers and explicit model tests
+
+Owner decision: 2026-09-08. This supersedes the add-dialog observation gate,
+not subscription OAuth admission or credential replacement.
+
+## Behavior contract
+
+- Saving a valid provider configuration does not require upstream evidence.
+ The dialog supplies the catalog protocol or the user's concrete protocol
+ selection (custom defaults visibly to OpenAI Chat Completions).
+- The save-first create path attempts discovery once with the provisioned
+ credential. Unavailable or invalid inventory cannot reject the save, erase
+ manual entries, or establish invocation success. Discovery occurs before the
+ new Source's single commit, so no existing-inventory destructive guard applies.
+- `verification_pending` remains until a real invocation succeeds for that
+ credential identity. Existing explicit observation APIs remain available to
+ older callers; the dialog does not call them.
+- Test is a separate, explicitly initiated action on a saved API-key Source.
+ It offers all non-retired discovered or manual models without reordering the
+ inventory. A centrally maintained ordered preference list selects the first
+ exact ID present; absent any match, select the first offered model. An existing
+ valid user selection wins over subsequent list updates.
+- An empty inventory does not disable saving. The existing manual-model editor
+ supplies IDs when discovery is unavailable; tests accept only a currently
+ present, non-retired model.
+- `POST /api/models/sources/<id>/probe` accepts exactly `{model: string}`.
+ It invokes that Source/model through the managed invocation adapter, using
+ the Source's protocol. It never resolves an Agent route, falls back, changes
+ provider health, or adds models. Failure describes this test, not the whole
+ provider. Success clears only the matching pending-verification identity.
+- Explicit testing is runtime demand and may start the managed engine through
+ the existing adapter. It does not change the saved runtime-enabled intent or
+ the Agent supply configuration.
+- Results contain Source ID, model ID, protocol, success, latency, and a
+ credential-free error key. Usage is metered by the existing Source/model
+ ledger. The test has a finite deadline and output budget and can incur a small
+ upstream charge.
+- The deadline bounds local preparation and admission as well as invocation.
+ Expiration before adapter admission is a request/engine error, not evidence
+ against the selected model. Reported latency covers admission through the
+ outcome, excluding preparation, cleanup, metering and verification writes.
+ Rejected API keys have credential-specific copy without refresh or health
+ mutation. Deadline handling preserves the supported Python 3.10 runtime.
+- Displayed results belong to the current effective selection and credential
+ identity. Inventory-driven selection changes clear completed results and
+ invalidate late results; unrelated inventory updates preserve them.
+ Publish a result only after the mutation owner reconciles a current matching
+ Source/model. Rejected, unread or stale reconciliation produces an unconfirmed
+ status, never a model verdict or an automatic second read.
+- A known invocation outcome owns finite verification, cleanup and metering
+ settlement through caller cancellation. Verify the matching credential before
+ cleanup, drain settlement exactly once, then propagate cancellation to the
+ caller. Cancellation before a known success cannot verify a credential.
+- Source deletion/credential replacement during a test cannot resurrect a
+ Source, overwrite current configuration, or verify a replacement credential.
+
+## Evidence
+
+Unit and HTTP/RPC contract tests cover save independence, inventory ordering,
+exact-source invocation, error isolation, and credential-identity settlement.
+UI tests cover default selection, optional testing, and asynchronous lifetime.
+No live credentials or running user instance are used for development.
+
+## Inventory presentation amendment
+
+Owner follow-up: 2026-09-08. Manual model addition performs no upstream
+discovery. Its loading indicator belongs to the add operation; only explicit
+refetch can animate the refetch button. Post-write local projection reads are
+not upstream model fetching.
+
+Reasoning levels are capability declarations consumed by managed model
+registration, not the effort setting for a conversation. Keep the data and
+editor, but show them only after opening Advanced settings. The default
+inventory shows model identities and ordinary model actions. In the advanced
+view, "Avibe preset levels" identifies capability metadata provenance without
+implying that a discovered model itself came from a built-in inventory.
diff --git a/docs/plans/model-hub-ui-spec.md b/docs/plans/model-hub-ui-spec.md
index dd6398742..7362421d8 100644
--- a/docs/plans/model-hub-ui-spec.md
+++ b/docs/plans/model-hub-ui-spec.md
@@ -1,5 +1,16 @@
# Model Hub — UI & Interaction Spec (gateway frames)
+## Save-first provider revision — 2026-09-08
+
+The owner-approved `model-hub-save-first-testing.md` supersedes the automatic
+observation gate in the API-key add dialog and the always-visible Source-model
+capability column below. Add saves a concrete protocol configuration and
+attempts inventory discovery, without requiring either discovery or a model
+test to succeed. An independent Test dialog selects a real saved model and
+reports only that invocation. Capability declarations remain under Advanced
+settings; ordinary model addition never fetches the upstream inventory.
+Subscription OAuth and credential replacement retain their existing lifecycle.
+
Companion to `model-hub.md`. That file is the **behaviour** authority; this one is
the **surface** authority: what each frame shows, which states it can be in, the
exact words it says in both locales, and what it does when the data is ugly.
diff --git a/docs/plans/model-hub.md b/docs/plans/model-hub.md
index ceeba778c..c9e0ece89 100644
--- a/docs/plans/model-hub.md
+++ b/docs/plans/model-hub.md
@@ -1,5 +1,14 @@
# Model Hub — Product Spec
+## Save-first API-key amendment — 2026-09-08
+
+`model-hub-save-first-testing.md` records the owner's replacement for add-time
+automatic-detection admission in the UI: save configuration, attempt optional
+inventory discovery, and offer a separate real-model test. Test failure does
+not block saving or condemn the provider. Discovery is not invocation proof;
+the existing credential-identity-bound verification marker remains authoritative.
+Older explicit observation clients and subscription OAuth admission are unchanged.
+
Status: **Routing modes, contract_version 10** (2026-09-06).
Owner-approved implementation contract: `model-hub-routing-modes.md`, frozen before
implementation at `2db273891`, with API-key scope/synchronization decision `c1d398d5f`
diff --git a/tests/scenarios/auth_setup/catalog.yaml b/tests/scenarios/auth_setup/catalog.yaml
index 3dc5aeb51..49fff84b4 100644
--- a/tests/scenarios/auth_setup/catalog.yaml
+++ b/tests/scenarios/auth_setup/catalog.yaml
@@ -114,7 +114,7 @@ scenarios:
backend: shared
test: tests/scenarios/auth_setup/test_auth_setup_scenarios.py::test_catalog_api_key_setup_observe_then_create_closed_loop
- id: AUTH-SETUP-112
- name: API-key setup keeps validation unverified and explicitly saves without upstream scheduling
+ name: API-key setup saves unverified with best-effort inventory and never schedules a model
status: covered
kind: happy_path
layer: scenario
diff --git a/tests/scenarios/auth_setup/test_auth_setup_scenarios.py b/tests/scenarios/auth_setup/test_auth_setup_scenarios.py
index a02663071..40ab658ec 100644
--- a/tests/scenarios/auth_setup/test_auth_setup_scenarios.py
+++ b/tests/scenarios/auth_setup/test_auth_setup_scenarios.py
@@ -2954,7 +2954,7 @@ def test_api_key_setup_does_not_schedule_a_model(
service, store, adapter = _service(tmp_path)
# Keep engine lifecycle simulated; exercise real credential custody, HTTP
# observation, inventory discovery, and Source admission together.
- for method in ("provision_credential", "provision_transient_credential", "revoke_credential", "observe_source"):
+ for method in ("provision_credential", "provision_transient_credential", "revoke_credential", "observe_source", "discover_models"):
monkeypatch.setattr(adapter, method, getattr(transport, method))
async def scenario():
@@ -3027,11 +3027,11 @@ def test_api_key_setup_does_not_schedule_a_model(
})
before = len(requests)
await service.create_source({"kind": "api_key", **draft, "save_unverified": True})
- assert len(requests) == before
+ assert requests[before:] == [("GET", "/v1/models", None)]
assert len(store.config.sources) == 1
h.source = store.config.sources[0].to_payload()
assert h.source["protocol"] == protocol
- assert h.source["models"] == []
+ assert [model["id"] for model in h.source["models"]] == ["relay-model"]
assert h.source["verification_pending"]
assert state_store.read_api_key(h.source["credential_ref"]) == valid_key
diff --git a/tests/test_model_hub_api.py b/tests/test_model_hub_api.py
index 31f200155..fba2415b3 100644
--- a/tests/test_model_hub_api.py
+++ b/tests/test_model_hub_api.py
@@ -148,6 +148,9 @@ class FakeInvokeHandle:
async def outcome(self):
return self._outcome
+ async def close_stream(self):
+ pass
+
class FakeAdapter:
def __init__(self):
diff --git a/tests/test_model_hub_source_probe.py b/tests/test_model_hub_source_probe.py
new file mode 100644
index 000000000..49e4c4b2f
--- /dev/null
+++ b/tests/test_model_hub_source_probe.py
@@ -0,0 +1,532 @@
+"""Save, inventory and explicitly selected model tests have independent results."""
+
+import asyncio
+import copy
+from dataclasses import replace
+from types import SimpleNamespace
+from unittest.mock import AsyncMock
+
+import pytest
+
+from core.handlers.model_hub.adapter import DiscoveredModel, RawOutcomeKind, SOURCE_PROTOCOLS, SourceBinding
+from core.handlers.model_hub.service import ModelHubError
+from core.handlers.model_hub import service as service_module
+from tests.test_model_hub_api import FakeAdapter, FakeInvokeHandle, _service
+from tests.test_model_hub_unverified import _draft
+
+
[email protected]("protocol", SOURCE_PROTOCOLS)
[email protected]("listing", ["success", "empty", "invalid", "failed"])
+def test_save_inventory_is_ordered_optional_and_never_authenticates(tmp_path, protocol, listing):
+ service, store, adapter = _service(tmp_path)
+ rows = {
+ "success": (DiscoveredModel("z-model"), DiscoveredModel("a-model")),
+ "empty": (),
+ "invalid": (DiscoveredModel("duplicate"), DiscoveredModel("duplicate")),
+ "failed": (),
+ }[listing]
+ adapter.discover_models = AsyncMock(
+ return_value=rows,
+ side_effect=ModelHubError("discovery_failed") if listing == "failed" else None,
+ )
+ adapter.observe_source = AsyncMock(side_effect=AssertionError("observation is not admission"))
+ result = asyncio.run(service.create_source(_draft(protocol=protocol)))["source"]
+ assert result["protocol"] == protocol
+ assert result["verification_pending"]
+ assert [model["id"] for model in result["models"]] == (
+ ["z-model", "a-model"] if listing == "success" else []
+ )
+ assert len(store.config.sources) == 1
+ adapter.discover_models.assert_awaited_once()
+ adapter.observe_source.assert_not_awaited()
+
+
[email protected]("protocol", SOURCE_PROTOCOLS)
[email protected]("kind", list(RawOutcomeKind))
+def test_probe_invokes_selected_source_even_without_agent_routes_and_isolates_failure(tmp_path, protocol, kind):
+ service, store, adapter = _service(tmp_path)
+
+ async def scenario():
+ result = (await service.create_source(_draft(protocol=protocol)))["source"]
+ for agent in store.config.agents.values():
+ agent.mode = "direct"
+ agent.sources.order = []
+ source_id = result["id"]
+ model_id = result["models"][0]["id"]
+ before = copy.deepcopy(store.config.to_payload())
+ original = adapter.invoke
+
+ async def invoke(*args, **kwargs):
+ handle = await original(*args, **kwargs)
+ return FakeInvokeHandle(replace(
+ await handle.outcome(), kind=kind,
+ http_status=200 if kind is RawOutcomeKind.SUCCESS else 401,
+ error_code=None if kind is RawOutcomeKind.SUCCESS else "invalid_api_key",
+ ))
+
+ adapter.invoke = AsyncMock(side_effect=invoke)
+ adapter.discover_models = AsyncMock(side_effect=AssertionError("no discovery during a test"))
+ answer = await service.probe_source(source_id, {"model": model_id})
+ assert answer["source_id"] == source_id
+ assert answer["model_id"] == model_id
+ assert answer["protocol"] == protocol
+ assert answer["reachable"] is (kind is RawOutcomeKind.SUCCESS)
+ assert (answer["error"] is None) is answer["reachable"]
+ adapter.invoke.assert_awaited_once()
+ args = adapter.invoke.call_args.args
+ assert args[:2] == (source_id, model_id)
+ assert args[2].protocol == protocol
+ assert args[2]["model"] == model_id
+ budget_key = "max_output_tokens" if protocol == "openai_responses" else "max_tokens"
+ assert args[2][budget_key] == 128
+ assert args[3:] == (False, "opencode")
+ adapter.discover_models.assert_not_awaited()
+ after = store.config.to_payload()
+ if answer["reachable"]:
+ assert not store.config.sources[0].verification_pending
+ before["sources"][0].pop("verification_pending", None)
+ after["sources"][0].pop("verification_pending", None)
+ assert before == after
+
+ asyncio.run(scenario())
+
+
[email protected]("change", ["delete", "replace", "same_handle"])
+def test_test_settlement_cannot_verify_a_different_credential_identity(tmp_path, change):
+ class ConcurrentAdapter(FakeAdapter):
+ async def invoke(self, *args, **kwargs):
+ handle = await super().invoke(*args, **kwargs)
+ if change == "delete":
+ store.config.sources.clear()
+ else:
+ current = store.config.sources[0]
+ if change == "replace":
+ current.credential_ref = "cred_replacement"
+ service._mark_source_unverified(current)
+ return handle
+
+ service, store, _ = _service(tmp_path, ConcurrentAdapter())
+
+ async def scenario():
+ source = (await service.create_source(_draft()))["source"]
+ answer = await service.probe_source(source["id"], {"model": source["models"][0]["id"]})
+ assert answer["reachable"]
+ if change == "delete":
+ assert not store.config.sources
+ else:
+ assert store.config.sources[0].verification_pending
+
+ asyncio.run(scenario())
+
+
[email protected]("payload", [{}, {"model": None}, {"model": "missing"}, {"model": "x", "key": "ignored"}])
+def test_probe_refuses_invalid_or_unknown_selection_before_runtime_work(tmp_path, payload):
+ service, _, adapter = _service(tmp_path)
+ source = asyncio.run(service.create_source(_draft()))["source"]
+ adapter.invoke = AsyncMock()
+ before = adapter.start_calls
+ with pytest.raises(ModelHubError):
+ asyncio.run(service.probe_source(source["id"], payload))
+ assert adapter.start_calls == before
+ adapter.invoke.assert_not_awaited()
+
+
+def test_manual_model_addition_never_calls_upstream_discovery(tmp_path):
+ service, store, adapter = _service(tmp_path)
+ source = asyncio.run(service.create_source(_draft()))["source"]
+ adapter.discover_models = AsyncMock(side_effect=AssertionError("manual means local inventory"))
+ adapter.observe_source = AsyncMock(side_effect=AssertionError("manual means no detection"))
+ before = copy.deepcopy(store.config.sources[0].models)
+ result = asyncio.run(service.add_custom_model(source["id"], {
+ "model_id": "manual-example", "reasoning_efforts": [],
+ }))
+ assert result["models"][-1]["id"] == "manual-example"
+ assert store.config.sources[0].models[:-1] == before
+ adapter.discover_models.assert_not_awaited()
+ adapter.observe_source.assert_not_awaited()
+
+
[email protected]("listing", ["empty", "invalid", "timeout"])
+def test_optional_discovery_preserves_manual_inventory(tmp_path, listing):
+ service, _, adapter = _service(tmp_path)
+ adapter.discover_models = AsyncMock(
+ return_value=(DiscoveredModel("duplicate"),) * 2 if listing == "invalid" else (),
+ side_effect=TimeoutError if listing == "timeout" else None,
+ )
+ draft = _draft()
+ draft["models"] = [{"id": "manual-model", "origin": "manual", "reasoning_efforts": []}]
+ source = asyncio.run(service.create_source(draft))["source"]
+ assert [(model["id"], model["origin"]) for model in source["models"]] == [("manual-model", "manual")]
+ assert source["verification_pending"]
+
+
[email protected]("protocol", SOURCE_PROTOCOLS)
+def test_source_probe_crosses_real_adapter_and_http_transport(tmp_path, protocol):
+ from aiohttp import web
+
+ from core.handlers.model_hub.rpc import dispatch_model_hub_rpc
+ from tests.test_model_hub_transport_leases import LeaseSupervisor
+ from vibe.model_hub_runtime.adapter import CLIProxyEngineAdapter
+ from vibe.model_hub_runtime.state import EngineStateStore
+
+ async def scenario():
+ requests = []
+
+ async def handler(request):
+ body = await request.json()
+ requests.append((request.path, body))
+ return web.json_response({
+ "choices": [{"message": {"content": "pong"}, "finish_reason": "stop"}],
+ "content": [{"type": "text", "text": "pong"}],
+ "output": [{"type": "message", "content": [{"type": "output_text", "text": "pong"}]}],
+ "usage": {"input_tokens": 2, "output_tokens": 1, "prompt_tokens": 2, "completion_tokens": 1},
+ })
+
+ app = web.Application()
+ app.router.add_post("/{path:.*}", handler)
+ runner = web.AppRunner(app)
+ await runner.setup()
+ site = web.TCPSite(runner, "127.0.0.1", 0)
+ await site.start()
+ try:
+ origin = f"http://127.0.0.1:{site._server.sockets[0].getsockname()[1]}"
+ service, store, adapter = _service(tmp_path)
+ source = (await service.create_source(_draft(protocol=protocol)))["source"]
+ model_id = source["models"][0]["id"]
+ runtime_store = EngineStateStore(tmp_path / "engine")
+ ref = runtime_store.store_api_key("fixture-key", protocol=protocol, base_url=source["base_url"])
+ binding = SourceBinding(
+ source_id=source["id"], vendor="custom", protocol=protocol,
+ base_url=source["base_url"], credential_ref=ref, allowed_origins=(), model_ids=(model_id,),
+ )
+ runtime_store.sync_sources([binding])
+ transport = CLIProxyEngineAdapter(supervisor=LeaseSupervisor(origin), state_store=runtime_store)
+ adapter.invoke = transport.invoke
+ service._meter_call = AsyncMock()
+ answer = await dispatch_model_hub_rpc(service, "probe_source", {
+ "source_id": source["id"], "probe": {"model": model_id},
+ })
+ assert answer["reachable"]
+ assert len(requests) == 1
+ path, body = requests[0]
+ assert path == {"anthropic": "/v1/messages", "openai_chat": "/v1/chat/completions", "openai_responses": "/v1/responses"}[protocol]
+ assert body["model"] == f"{runtime_store.get_source(source['id']).prefix}/{model_id}"
+ assert body["stream"] is False
+ assert transport._active_transports == 0
+ assert not store.config.sources[0].verification_pending
+ service._meter_call.assert_awaited_once()
+ assert service._meter_call.call_args.kwargs["outcome"].usage is not None
+ finally:
+ await runner.cleanup()
+
+ asyncio.run(scenario())
+
+
[email protected]("termination", ["cancel", "timeout"])
+def test_probe_termination_closes_handle_and_releases_mutation_owner(tmp_path, monkeypatch, termination):
+ service, store, adapter = _service(tmp_path)
+
+ async def scenario():
+ source = (await service.create_source(_draft()))["source"]
+ entered = asyncio.Event()
+ original = adapter.invoke
+ handle_closed = AsyncMock()
+
+ async def invoke(*args, **kwargs):
+ handle = await original(*args, **kwargs)
+
+ async def pending_outcome():
+ entered.set()
+ await asyncio.Event().wait()
+
+ handle.outcome = pending_outcome
+ handle.close_stream = handle_closed
+ return handle
+
+ adapter.invoke = invoke
+ service._meter_call = AsyncMock()
+ if termination == "timeout":
+ monkeypatch.setattr(service_module, "_SOURCE_PROBE_TIMEOUT_SECONDS", 0.02)
+ task = asyncio.create_task(service.probe_source(source["id"], {"model": source["models"][0]["id"]}))
+ await entered.wait()
+ if termination == "cancel":
+ task.cancel()
+ with pytest.raises(asyncio.CancelledError):
+ await task
+ else:
+ answer = await task
+ assert not answer["reachable"]
+ assert answer["error"] == "models.source.cooldown.timeout"
+ assert not service._mutation_lock.locked()
+ assert store.config.sources[0].verification_pending
+ handle_closed.assert_awaited_once()
+ service._meter_call.assert_awaited_once()
+
+ asyncio.run(scenario())
+
+
[email protected]("phase", ["selection_lock", "preparation", "transport"])
+def test_pre_admission_timeout_is_a_request_failure_not_a_model_result(tmp_path, monkeypatch, phase):
+ service, store, adapter = _service(tmp_path)
+
+ async def scenario():
+ source = (await service.create_source(_draft()))["source"]
+ before = copy.deepcopy(store.config.to_payload())
+ monkeypatch.setattr(service_module, "_SOURCE_PROBE_TIMEOUT_SECONDS", 0.02)
+ service._meter_call = AsyncMock()
+
+ async def stalled(*args, **kwargs):
+ await asyncio.Event().wait()
+
+ if phase == "selection_lock":
+ await service._mutation_lock.acquire()
+ elif phase == "preparation":
+ service._prepare_engine_for_demand = stalled
+ else:
+ adapter.invoke = stalled
+ try:
+ with pytest.raises(ModelHubError) as error:
+ await service.probe_source(source["id"], {"model": source["models"][0]["id"]})
+ assert error.value.code == "engine_down"
+ assert error.value.status == 503
+ assert service._mutation_lock.locked() is (phase == "selection_lock")
+ assert store.config.to_payload() == before
+ service._meter_call.assert_not_awaited()
+ finally:
+ if phase == "selection_lock":
+ service._mutation_lock.release()
+
+ asyncio.run(scenario())
+
+
[email protected]("phase", ["verification", "close", "meter"])
[email protected]("change", ["unchanged", "delete", "replace", "same_handle"])
+def test_known_success_settles_once_despite_cancellation(tmp_path, phase, change):
+ service, store, adapter = _service(tmp_path)
+
+ async def scenario():
+ source = (await service.create_source(_draft()))["source"]
+ entered, release = asyncio.Event(), asyncio.Event()
+ original_invoke, original_verify = adapter.invoke, service._verify_successful_source
+ steps = []
+
+ async def barrier(step):
+ steps.append(step)
+ if step == phase:
+ entered.set()
+ await release.wait()
+
+ async def verify(*args):
+ await barrier("verification")
+ await original_verify(*args)
+
+ async def close():
+ await barrier("close")
+
+ async def meter(**kwargs):
+ await barrier("meter")
+
+ async def invoke(*args, **kwargs):
+ handle = await original_invoke(*args, **kwargs)
+ handle.close_stream = AsyncMock(side_effect=close)
+ return handle
+
+ adapter.invoke = AsyncMock(side_effect=invoke)
+ service._verify_successful_source = AsyncMock(side_effect=verify)
+ service._meter_call = AsyncMock(side_effect=meter)
+ task = asyncio.create_task(service.probe_source(source["id"], {"model": source["models"][0]["id"]}))
+ await asyncio.wait_for(entered.wait(), timeout=1)
+ current = store.config.sources[0]
+ if change == "delete":
+ store.config.sources.clear()
+ elif change != "unchanged":
+ if change == "replace":
+ current.credential_ref = "cred_replacement"
+ service._mark_source_unverified(current)
+ pending = current.verification_pending
+ task.cancel()
+ await asyncio.sleep(0)
+ task.cancel()
+ await asyncio.sleep(0)
+ still_settling = not task.done()
+ release.set()
+ with pytest.raises(asyncio.CancelledError):
+ await asyncio.wait_for(task, timeout=1)
+ assert still_settling
+ assert steps == ["verification", "close", "meter"]
+ adapter.invoke.assert_awaited_once()
+ service._verify_successful_source.assert_awaited_once()
+ service._meter_call.assert_awaited_once()
+ assert service._meter_call.call_args.kwargs["outcome"].kind is RawOutcomeKind.SUCCESS
+ assert not service._mutation_lock.locked()
+ if change == "delete":
+ assert not store.config.sources
+ elif change == "unchanged":
+ assert store.config.sources[0].verification_pending is None
+ else:
+ assert store.config.sources[0].verification_pending == pending
+ assert pending is not None
+
+ asyncio.run(scenario())
+
+
+def test_unadmitted_engine_handle_is_not_presented_as_a_model_failure(tmp_path):
+ service, store, adapter = _service(tmp_path)
+
+ async def scenario():
+ source = (await service.create_source(_draft()))["source"]
+ original = adapter.invoke
+ closed = AsyncMock()
+
+ async def unavailable(*args, **kwargs):
+ kwargs.pop("on_admitted")
+ handle = await original(*args, **kwargs)
+ result = FakeInvokeHandle(replace(
+ await handle.outcome(), kind=RawOutcomeKind.NETWORK_ERROR,
+ http_status=None, error_code="engine_down",
+ ))
+ result.close_stream = closed
+ return result
+
+ adapter.invoke = unavailable
+ with pytest.raises(ModelHubError) as error:
+ await service.probe_source(source["id"], {"model": source["models"][0]["id"]})
+ assert error.value.code == "engine_down"
+ assert not service._mutation_lock.locked()
+ assert store.config.sources[0].verification_pending
+ closed.assert_awaited_once()
+
+ asyncio.run(scenario())
+
+
+def test_admitted_timeout_is_a_model_result_even_before_handle_delivery(tmp_path, monkeypatch):
+ service, store, adapter = _service(tmp_path)
+
+ async def scenario():
+ source = (await service.create_source(_draft()))["source"]
+
+ async def admitted_then_stalled(*args, on_admitted, **kwargs):
+ on_admitted()
+ await asyncio.Event().wait()
+
+ adapter.invoke = admitted_then_stalled
+ monkeypatch.setattr(service_module, "_SOURCE_PROBE_TIMEOUT_SECONDS", 0.02)
+ answer = await service.probe_source(source["id"], {"model": source["models"][0]["id"]})
+ assert not answer["reachable"]
+ assert answer["error"] == "models.source.cooldown.timeout"
+ assert store.config.sources[0].verification_pending
+ assert not service._mutation_lock.locked()
+
+ asyncio.run(scenario())
+
+
+def test_probe_latency_excludes_local_preparation_acquisition_and_settlement(tmp_path, monkeypatch):
+ service, _, adapter = _service(tmp_path)
+
+ async def scenario():
+ source = (await service.create_source(_draft()))["source"]
+ clock = SimpleNamespace(now=0.0)
+ monkeypatch.setattr(service_module, "time", SimpleNamespace(monotonic=lambda: clock.now))
+ prepare, invoke, verify = service._prepare_engine_for_demand, adapter.invoke, service._verify_successful_source
+
+ async def prepare_slowly():
+ clock.now += 20
+ await prepare()
+
+ async def invoke_after_acquisition(*args, **kwargs):
+ clock.now += 30
+ handle = await invoke(*args, **kwargs)
+ outcome = await handle.outcome()
+
+ async def respond():
+ clock.now += 0.125
+ return outcome
+
+ async def close():
+ clock.now += 40
+
+ handle.outcome, handle.close_stream = respond, close
+ return handle
+
+ async def meter_slowly(**kwargs):
+ clock.now += 50
+
+ async def verify_slowly(*args):
+ clock.now += 60
+ await verify(*args)
+
+ service._prepare_engine_for_demand = prepare_slowly
+ adapter.invoke = invoke_after_acquisition
+ service._meter_call = meter_slowly
+ service._verify_successful_source = verify_slowly
+ answer = await service.probe_source(source["id"], {"model": source["models"][0]["id"]})
+ assert answer["reachable"]
+ assert answer["latency_ms"] == 125
+ assert clock.now == 200.125
+
+ asyncio.run(scenario())
+
+
[email protected]("status,code", [(401, None), (400, "invalid_api_key")])
[email protected]("stream_started", [False, True])
+def test_key_rejection_has_credential_copy_without_refresh_or_health_changes(tmp_path, status, code, stream_started):
+ service, store, adapter = _service(tmp_path)
+
+ async def scenario():
+ source = (await service.create_source(_draft()))["source"]
+ before = copy.deepcopy(store.config.to_payload())
+ original = adapter.invoke
+
+ async def rejected(*args, **kwargs):
+ handle = await original(*args, **kwargs)
+ return FakeInvokeHandle(replace(
+ await handle.outcome(), kind=RawOutcomeKind.HTTP_ERROR,
+ http_status=status, error_code=code, stream_started=stream_started,
+ ))
+
+ adapter.invoke = AsyncMock(side_effect=rejected)
+ adapter.credential_supports_refresh = AsyncMock(side_effect=AssertionError("test never refreshes"))
+ answer = await service.probe_source(source["id"], {"model": source["models"][0]["id"]})
+ assert not answer["reachable"]
+ assert answer["error"] == "models.source.needs_action.credential_revoked"
+ adapter.invoke.assert_awaited_once()
+ adapter.credential_supports_refresh.assert_not_awaited()
+ assert store.config.to_payload() == before
+
+ asyncio.run(scenario())
+
+
+def test_save_and_model_probe_work_without_python311_timeout_context(tmp_path, monkeypatch):
+ service, _, _ = _service(tmp_path)
+ monkeypatch.delattr(asyncio, "timeout", raising=False)
+
+ async def scenario():
+ source = (await service.create_source(_draft()))["source"]
+ result = await service.probe_source(source["id"], {"model": source["models"][0]["id"]})
+ assert result["reachable"]
+
+ asyncio.run(scenario())
+
+
+def test_discovery_deadline_saves_manual_inventory_and_drains_cancelled_work(tmp_path, monkeypatch):
+ service, _, adapter = _service(tmp_path)
+
+ async def scenario():
+ cancelled = asyncio.Event()
+
+ async def stalled(*args):
+ try:
+ await asyncio.Event().wait()
+ finally:
+ cancelled.set()
+
+ adapter.discover_models = stalled
+ monkeypatch.setattr(service_module, "_SOURCE_DISCOVERY_TIMEOUT_SECONDS", 0.02)
+ draft = _draft()
+ draft["models"] = [{"id": "manual-model", "origin": "manual", "reasoning_efforts": []}]
+ source = (await service.create_source(draft))["source"]
+ assert cancelled.is_set()
+ assert [model["id"] for model in source["models"]] == ["manual-model"]
+ assert source["verification_pending"]
+
+ asyncio.run(scenario())
diff --git a/tests/test_model_hub_structure_guards.py b/tests/test_model_hub_structure_guards.py
index 46d38b7c5..2a681f827 100644
--- a/tests/test_model_hub_structure_guards.py
+++ b/tests/test_model_hub_structure_guards.py
@@ -645,8 +645,14 @@ def test_usage_metering_has_one_owner_per_call_population() -> None:
meter_calls = [
node for node in ast.walk(service_tree) if _call_name(node) == "_meter_call"
]
- assert len(meter_calls) == 1
- assert meter_calls[0] in set(ast.walk(invoke))
+ # Explicit Source tests consume their own response rather than forwarding a
+ # Turn to the gateway. They reuse the same metering owner, exactly once.
+ consumers = (invoke, _functions(service_tree)["probe_source"])
+ assert len(meter_calls) == len(consumers)
+ assert all(
+ sum(call in set(ast.walk(consumer)) for call in meter_calls) == 1
+ for consumer in consumers
+ )
# Any of the gateway's endings may report the forwarded call, so exactly-once
# rests on the write it owns; a caller that pre-checks or clears that handle
# would move the decision outside the owner. An ending may still need to know
diff --git a/tests/test_model_hub_unverified.py b/tests/test_model_hub_unverified.py
index 13b88adb4..ea88b6bac 100644
--- a/tests/test_model_hub_unverified.py
+++ b/tests/test_model_hub_unverified.py
@@ -35,10 +35,10 @@ def _draft(**changes):
[{"vendor": entry.id} for entry in api_key_vendor_catalog()]
+ [{"vendor": "custom", "protocol": protocol} for protocol in SOURCE_PROTOCOLS],
)
-def test_unverified_save_uses_declared_owner_without_upstream_work(tmp_path, owner):
+def test_save_first_uses_declared_owner_despite_unavailable_inventory(tmp_path, owner):
service, store, adapter = _service(tmp_path)
adapter.observe_source = AsyncMock(side_effect=AssertionError("unexpected observation"))
- adapter.discover_models = AsyncMock(side_effect=AssertionError("unexpected inventory"))
+ adapter.discover_models = AsyncMock(side_effect=ModelHubError("discovery_failed", status=502))
draft = _draft(**owner)
if owner["vendor"] != "custom":
draft.pop("protocol")
@@ -51,7 +51,7 @@ def test_unverified_save_uses_declared_owner_without_upstream_work(tmp_path, own
assert adapter.credential_count == 1
assert len(store.config.sources) == 1
adapter.observe_source.assert_not_awaited()
- adapter.discover_models.assert_not_awaited()
+ adapter.discover_models.assert_awaited_once()
with pytest.raises(ModelHubError):
asyncio.run(service.create_source(draft))
assert adapter.credential_count == 1
diff --git a/ui/e2e/b-add-api-key.spec.ts b/ui/e2e/b-add-api-key.spec.ts
index 2dab290a4..53fa93b2c 100644
--- a/ui/e2e/b-add-api-key.spec.ts
+++ b/ui/e2e/b-add-api-key.spec.ts
@@ -71,8 +71,7 @@ const settleKeyVerdict = async (
return last;
};
-// Each protocol's segment button carries its own label, and the observation is
-// supposed to reach the same verdict for all three without being told which.
+// Custom providers persist the protocol the user selected, without observation.
const PROTOCOLS = [
{ id: 'anthropic', label: copy('addKey.protocol.anthropicMessages') },
{ id: 'openai_responses', label: copy('addKey.protocol.openaiResponses') },
@@ -94,212 +93,110 @@ test.describe('B · add an API-key source', () => {
});
for (const protocol of PROTOCOLS) {
- test(`B1 · Add identifies a ${protocol.id} upstream without being told`, async ({ hub, mock, api }) => {
+ test('B1 · saves the selected ' + protocol.id + ' protocol without model invocation', async ({ hub, mock, api }) => {
await mock.configure({ auth: 'ok', protocol: protocol.id, models_endpoint: 'ok' });
- const name = `${E2E_SOURCE_PREFIX}auto-${protocol.id}`;
-
+ const name = E2E_SOURCE_PREFIX + 'selected-' + protocol.id;
await hub.goto();
await hub.addApiKeyButton.click();
- await expect(hub.addKeyDialog).toBeVisible();
- // No protocol is chosen: "Auto detect" is the default, and the response
- // shape is the only evidence the product is allowed to use.
- await fillApiKeyForm(hub.addKeyDialog, { name, baseUrl: mockBaseUrl(), apiKey: 'e2e-add' });
- await hub.addKeyDialog.getByRole('button', { name: copy('addKey.detect'), exact: true }).click();
- await hub.addKeyDialog.getByRole('button', { name: copy('addKey.confirm'), exact: true }).click({ timeout: 30_000 });
-
- // Success is defined by where the user lands, not by a toast: the dialog
- // closes and the new source's detail panel opens.
+ await fillApiKeyForm(hub.addKeyDialog, {
+ name, baseUrl: mockBaseUrl(), apiKey: 'e2e-add', protocol: protocol.label,
+ });
+ await mock.resetRequests();
+ await hub.addKeyDialog.getByRole('button', { name: copy('addKey.confirm'), exact: true }).click();
await expect(hub.addKeyDialog).toHaveCount(0, { timeout: 30_000 });
- await expect(hub.sourceDetailDialog).toBeVisible();
await expect(hub.sourceDetailDialog).toContainText(name);
-
const created = (await api.sources()).find((source) => source.display_name === name);
- expect(created?.protocol).toBe(protocol.id);
- expect(created?.vendor).toBe('custom');
+ expect(created).toMatchObject({ vendor: 'custom', protocol: protocol.id, verification_pending: expect.any(String) });
+ expect((await mock.requests()).filter((request) => request.method === 'POST' && request.path.startsWith('/v1/'))).toEqual([]);
});
}
- // B1 · the other rung of the same scenario. A vendor picked from the shipped
- // catalog is not asked to prove its interface by shape — the catalog row is the
- // proof, so detection only has to authenticate and fetch. The address is then
- // pointed at the mock, which is both the only way this suite can reach a real
- // upstream AND the state a user behind a gateway is actually in: it proves the
- // pin belongs to the VENDOR and not to the URL it proposed.
- test('B1 · a catalog vendor is added under its own id, with its interface pinned', async ({ hub, mock, api }) => {
+ test('B1 · a catalog vendor saves under its own id and pinned interface', async ({ hub, mock, api }) => {
const preset = CATALOG_VENDORS[0];
await mock.configure({ auth: 'ok', protocol: preset.protocol, models_endpoint: 'ok' });
- const name = `${E2E_SOURCE_PREFIX}catalog-${preset.id}`;
-
+ const name = E2E_SOURCE_PREFIX + 'catalog-' + preset.id;
await hub.goto();
await hub.addApiKeyButton.click();
- await expect(hub.addKeyDialog).toBeVisible();
- await fillApiKeyForm(hub.addKeyDialog, {
- // Picked the way a user picks it, by the name on the row; the id below is
- // what that click has to end up sending.
- vendor: preset.label,
- name,
- baseUrl: mockBaseUrl(),
- apiKey: 'e2e-add',
- });
-
- // The interface is stated, not asked: the pinned name is on screen with the
- // badge that says where it came from, and the control that would offer a
- // different one is gone rather than merely disabled.
- await expect(hub.addKeyDialog).toContainText(copy('addKey.protocol.catalogPinned'));
- await expect(
- hub.addKeyDialog.getByRole('button', { name: copy('addKey.protocol.manual'), exact: true }),
- ).toHaveCount(0);
-
- await hub.addKeyDialog.getByRole('button', { name: copy('addKey.detect'), exact: true }).click();
- await hub.addKeyDialog.getByRole('button', { name: copy('addKey.confirm'), exact: true }).click({ timeout: 30_000 });
-
+ await fillApiKeyForm(hub.addKeyDialog, { vendor: preset.label, name, baseUrl: mockBaseUrl(), apiKey: 'e2e-add' });
+ await expect(hub.addKeyDialog.getByRole('group', { name: copy('addKey.field.protocol') })).toHaveCount(0);
+ await expect(hub.addKeyDialog).toContainText(PROTOCOLS.find((item) => item.id === preset.protocol)!.label);
+ await hub.addKeyDialog.getByRole('button', { name: copy('addKey.confirm'), exact: true }).click();
await expect(hub.addKeyDialog).toHaveCount(0, { timeout: 30_000 });
- await expect(hub.sourceDetailDialog).toBeVisible();
-
- const created = (await api.sources()).find((source) => source.display_name === name);
- expect(created?.vendor).toBe(preset.id);
- expect(created?.protocol).toBe(preset.protocol);
+ expect((await api.sources()).find((source) => source.display_name === name)).toMatchObject({
+ vendor: preset.id, protocol: preset.protocol, verification_pending: expect.any(String),
+ });
});
- test('B1 · a rejected credential is named as a credential problem', async ({ hub, mock }) => {
+ test('B1 · upstream authentication failure cannot veto saving configuration', async ({ hub, mock, api }) => {
await mock.configure({ auth: '401', protocol: 'anthropic', models_endpoint: 'ok' });
-
+ const name = E2E_SOURCE_PREFIX + 'auth-unverified';
await hub.goto();
await hub.addApiKeyButton.click();
- // The suite prefix is on this "doomed" create too: if the regression under
- // test commits the source before reporting the failure, teardown still has
- // to be able to sweep it. A failure path that can leave state behind is a
- // failure path that poisons whichever spec runs next.
await fillApiKeyForm(hub.addKeyDialog, {
- name: `${E2E_SOURCE_PREFIX}auth-rejected`,
- baseUrl: mockBaseUrl(),
- apiKey: 'e2e-bad-key',
+ name, baseUrl: mockBaseUrl(), apiKey: 'e2e-bad-key', protocol: PROTOCOLS[0].label,
+ });
+ await hub.addKeyDialog.getByRole('button', { name: copy('addKey.confirm'), exact: true }).click();
+ await expect(hub.addKeyDialog).toHaveCount(0, { timeout: 30_000 });
+ expect((await api.sources()).find((source) => source.display_name === name)).toMatchObject({
+ protocol: 'anthropic', verification_pending: expect.any(String),
});
- await hub.addKeyDialog.getByRole('button', { name: copy('addKey.detect'), exact: true }).click();
-
- // The three lines are one message: what went wrong, where to look, and that
- // Add cannot proceed until it is fixed. A test that asserted only the first
- // would pass on a dialog that has stopped explaining itself.
- await expect(hub.addKeyDialog).toContainText(copy('addKey.fail.auth'), { timeout: 30_000 });
- await expect(hub.addKeyDialog).toContainText(copy('addKey.fail.auth.detail'));
- await expect(hub.addKeyDialog).toContainText(copy('addKey.fail.subtitle'));
- await expect(hub.addKeyDialog).toBeVisible();
});
- test('B2 · a declared interface is warned about and persisted without claiming response proof', async ({ hub, mock, api }) => {
- // A concrete custom interface is a declaration, not a response-shape claim.
- // Authentication still gates it; Auto's shape-proof branch is covered by B1
- // and test_source_observation_accepts_catalog_pin_and_custom_declaration_without_shape_proof.
+ test('B2 · a declared protocol persists without claiming response proof', async ({ hub, mock, api }) => {
await mock.configure({ auth: 'ok', protocol: 'openai_chat', models_endpoint: 'ok' });
- const name = `${E2E_SOURCE_PREFIX}mismatch`;
-
+ const name = E2E_SOURCE_PREFIX + 'mismatch';
await hub.goto();
await hub.addApiKeyButton.click();
await fillApiKeyForm(hub.addKeyDialog, {
- name,
- baseUrl: mockBaseUrl(),
- apiKey: 'e2e-mismatch',
- protocol: copy('addKey.protocol.anthropicMessages'),
+ name, baseUrl: mockBaseUrl(), apiKey: 'e2e-mismatch', protocol: PROTOCOLS[0].label,
});
- await hub.addKeyDialog.getByRole('button', { name: copy('addKey.detect'), exact: true }).click();
-
- await expect(hub.addKeyDialog.locator('.model-hub-add-key-protocol-badge')).toHaveText(copy('addKey.protocol.declared'));
- await expect(hub.addKeyDialog).toContainText(copy('addKey.field.protocol.hint'));
- const confirm = hub.addKeyDialog.getByRole('button', { name: copy('addKey.confirm'), exact: true });
- await expect(confirm).toBeEnabled({ timeout: 30_000 });
- expect((await api.sources()).filter((source) => source.display_name === name)).toEqual([]);
- await confirm.click();
+ await hub.addKeyDialog.getByRole('button', { name: copy('addKey.confirm'), exact: true }).click();
await expect(hub.addKeyDialog).toHaveCount(0, { timeout: 30_000 });
- await expect(hub.sourceDetailDialog).toBeVisible();
- await expect(hub.sourceDetailDialog).toContainText(name);
- const saved = (await api.sources()).filter((source) => source.display_name === name);
- expect(saved).toHaveLength(1);
- expect(saved[0]).toMatchObject({ vendor: 'custom', protocol: 'anthropic' });
+ expect((await api.sources()).find((source) => source.display_name === name)).toMatchObject({
+ vendor: 'custom', protocol: 'anthropic', verification_pending: expect.any(String),
+ });
});
- test('B3 · Detect reports the count, and only ids survive the save', async ({ hub, mock, api }) => {
- // The mock returns rich rows on purpose: `display_name`, `context_length`
- // and `pricing` all come back and all are dropped. §3 marks B3
- // `assert-current` — this documents the drop, it does not bless it.
+ test('B3 · automatically fetches ordered inventory, then tests only the chosen model', async ({ hub, mock, api, page }) => {
const inventory = anthropicInventory(['e2e-alpha', 'e2e-beta', 'e2e-gamma']);
- await mock.configure({
- auth: 'ok',
- protocol: 'anthropic',
- models_endpoint: 'ok',
- models: inventory,
- });
- const name = `${E2E_SOURCE_PREFIX}inventory`;
-
+ await mock.configure({ auth: 'ok', protocol: 'anthropic', models_endpoint: 'ok', models: inventory });
+ const name = E2E_SOURCE_PREFIX + 'inventory';
await hub.goto();
await hub.addApiKeyButton.click();
- await fillApiKeyForm(hub.addKeyDialog, { name, baseUrl: mockBaseUrl(), apiKey: 'e2e-pull' });
-
- // Detect is the mandatory pre-flight: it reports, it does not save.
- await hub.addKeyDialog.getByRole('button', { name: copy('addKey.detect'), exact: true }).click();
- await expect(hub.addKeyDialog).toContainText(
- copy('addKey.pull.result', { count: inventory.length }),
- { timeout: 30_000 },
- );
- expect(await api.sources()).not.toContainEqual(expect.objectContaining({ display_name: name }));
-
- await hub.addKeyDialog.getByRole('button', { name: copy('addKey.confirm'), exact: true }).click({ timeout: 30_000 });
+ await fillApiKeyForm(hub.addKeyDialog, { name, baseUrl: mockBaseUrl(), apiKey: 'e2e-pull', protocol: PROTOCOLS[0].label });
+ await hub.addKeyDialog.getByRole('button', { name: copy('addKey.confirm'), exact: true }).click();
await expect(hub.sourceDetailDialog).toBeVisible({ timeout: 30_000 });
-
const created = (await api.sources()).find((source) => source.display_name === name);
-
- // assert-current: everything the upstream said about a model except its id
- // is discarded on the way to storage. The whole row is stated rather than
- // its key set, so each drop is asserted as a value and not merely as a name
- // that exists. `reasoning_efforts_source` is the one that matters: it is
- // #1836's tier provenance, product shape to record here rather than a leak
- // to strip, and `null` is the claim — the persisted schema also admits
- // `catalog` alongside an empty tier list, so a regression stamping it would
- // make the UI treat these tiers as managed and non-editable while a key
- // check still passed. A field arriving later fails this too.
- const byId = (one: { id: string }, other: { id: string }) => one.id.localeCompare(other.id);
- expect([...(created?.models ?? [])].sort(byId)).toEqual(
- inventory
- .map((model) => ({
- id: model.id,
- origin: 'discovered',
- display_name: null,
- reasoning_efforts: [],
- reasoning_efforts_source: null,
- discovered_at: expect.any(String),
- retired: false,
- }))
- .sort(byId),
- );
+ expect(created?.models).toEqual(inventory.map((model) => ({
+ id: model.id, origin: 'discovered', display_name: null, reasoning_efforts: [],
+ reasoning_efforts_source: null, discovered_at: expect.any(String), retired: false,
+ })));
+ expect(created?.verification_pending).toEqual(expect.any(String));
+ await hub.sourceDetailDialog.getByRole('button', { name: copy('sourceTest.open'), exact: true }).click();
+ const dialog = page.getByRole('dialog', { name: copy('sourceTest.title', { source: name }), exact: true });
+ await expect(dialog.getByRole('combobox')).toContainText('e2e-alpha');
+ await dialog.getByRole('combobox').click();
+ await page.getByRole('option', { name: 'e2e-beta', exact: true }).click();
+ await mock.resetRequests();
+ await dialog.getByRole('button', { name: copy('sourceTest.run'), exact: true }).click();
+ await expect(dialog.getByRole('status')).toContainText('e2e-beta', { timeout: 75_000 });
+ await expect.poll(async () => (await api.sources()).find((source) => source.id === created?.id)?.verification_pending).toBeFalsy();
+ const requests = (await mock.requests()).filter((request) => request.method === 'POST' && request.path === '/v1/messages');
+ expect(requests).toHaveLength(1);
+ expect(requests[0].body).toMatchObject({ model: 'e2e-beta' });
});
- test('B4 · a proven interface with no model list can still be added, on the record', async ({ hub, mock, api }) => {
- // The interface answers; only discovery is broken. That is a different
- // situation from "we do not know what this is", and the product treats it
- // as one: it offers to add the source anyway. `models_endpoint: http_500`
- // is exactly this shape: the interface probes 200, `/v1/models` 500s.
+ test('B4 · unavailable inventory still saves an unverified provider', async ({ hub, mock, api }) => {
await mock.configure({ auth: 'ok', protocol: 'anthropic', models_endpoint: 'http_500' });
- const name = `${E2E_SOURCE_PREFIX}no-inventory`;
-
+ const name = E2E_SOURCE_PREFIX + 'no-inventory';
await hub.goto();
await hub.addApiKeyButton.click();
- await fillApiKeyForm(hub.addKeyDialog, { name, baseUrl: mockBaseUrl(), apiKey: 'e2e-empty' });
- await hub.addKeyDialog.getByRole('button', { name: copy('addKey.detect'), exact: true }).click();
-
- await expect(hub.addKeyDialog).toContainText(copy('addKey.inventory.title'), { timeout: 30_000 });
- const addAnyway = hub.addKeyDialog.getByRole('button', {
- name: copy('addKey.addAnyway'),
- exact: true,
- });
- await expect(addAnyway).toBeVisible();
- await addAnyway.click();
-
+ await fillApiKeyForm(hub.addKeyDialog, { name, baseUrl: mockBaseUrl(), apiKey: 'e2e-empty', protocol: PROTOCOLS[0].label });
+ await hub.addKeyDialog.getByRole('button', { name: copy('addKey.confirm'), exact: true }).click();
await expect(hub.sourceDetailDialog).toBeVisible({ timeout: 30_000 });
- const created = (await api.sources()).find((source) => source.display_name === name);
- // The source commits, and it commits carrying the failure — a source that
- // came in this way must not look identical to one that discovered cleanly.
- expect(created?.protocol).toBe('anthropic');
- expect(created?.models).toEqual([]);
- expect(created?.state.status).toBe('error');
+ expect((await api.sources()).find((source) => source.display_name === name)).toMatchObject({
+ protocol: 'anthropic', models: [], verification_pending: expect.any(String),
+ });
});
test('B6 · replacing the key reuses the same dialog, and reports what it did', async ({ hub, mock, api, gateway }) => {
diff --git a/ui/e2e/b-source-detail.spec.ts b/ui/e2e/b-source-detail.spec.ts
index 04d5cba2b..9a0fe597c 100644
--- a/ui/e2e/b-source-detail.spec.ts
+++ b/ui/e2e/b-source-detail.spec.ts
@@ -97,6 +97,7 @@ test.describe('B · the source detail panel', () => {
await hub.goto();
await hub.openSource(source.id);
+ await hub.sourceDetailDialog.getByRole('button', { name: copy('sourceDetail.advanced'), exact: true }).click();
await expect(hub.sourceDetailDialog).toBeVisible();
await hub.manageMenuTrigger(before).click();
@@ -143,6 +144,7 @@ test.describe('B · the source detail panel', () => {
await hub.goto();
await hub.openSource(source.id);
+ await hub.sourceDetailDialog.getByRole('button', { name: copy('sourceDetail.advanced'), exact: true }).click();
await hub.sourceDetailDialog
.getByRole('button', { name: copy('sourceDetail.action.refetch'), exact: true })
.click();
@@ -178,6 +180,7 @@ test.describe('B · the source detail panel', () => {
await hub.goto();
await hub.openSource(source.id);
+ await hub.sourceDetailDialog.getByRole('button', { name: copy('sourceDetail.advanced'), exact: true }).click();
await hub.sourceDetailDialog
.getByRole('button', { name: copy('sourceDetail.action.addModel'), exact: true })
.click();
@@ -247,6 +250,7 @@ test.describe('B · the source detail panel', () => {
await hub.goto();
await hub.openSource(source.id);
+ await hub.sourceDetailDialog.getByRole('button', { name: copy('sourceDetail.advanced'), exact: true }).click();
await hub.tierCell('e2e-vocab').click();
await expect(hub.modelRow('e2e-vocab').getByRole('textbox')).toBeVisible();
@@ -277,6 +281,7 @@ test.describe('B · the source detail panel', () => {
await hub.goto();
await hub.openSource(source.id);
+ await hub.sourceDetailDialog.getByRole('button', { name: copy('sourceDetail.advanced'), exact: true }).click();
await expectLockedRow(hub, catalogId, 'catalog');
// Locking is per model: the sibling the catalog does not know stays a door.
@@ -313,6 +318,7 @@ test.describe('B · the source detail panel', () => {
await hub.goto();
await hub.openSource(source.id);
+ await hub.sourceDetailDialog.getByRole('button', { name: copy('sourceDetail.advanced'), exact: true }).click();
await expectLockedRow(hub, upstreamId, 'upstream');
await hub.tierCell(siblingId).click();
@@ -369,6 +375,7 @@ test.describe('B · the source detail panel', () => {
await hub.goto();
await hub.openSource(source.id);
+ await hub.sourceDetailDialog.getByRole('button', { name: copy('sourceDetail.advanced'), exact: true }).click();
await expect(
hub.sourceDetailDialog.getByRole('button', {
name: copy('sourceDetail.action.refetch', undefined, locale),
diff --git a/ui/e2e/model-provider/fixture.html b/ui/e2e/model-provider/fixture.html
new file mode 100644
index 000000000..80a3506ef
--- /dev/null
+++ b/ui/e2e/model-provider/fixture.html
@@ -0,0 +1,2 @@
+<!doctype html>
+<html lang="en"><head><meta charset="UTF-8"><meta name="viewport" content="width=device-width, initial-scale=1.0"><title>Provider workflow fixture</title></head><body><div id="root"></div><script type="module" src="./fixture.tsx"></script></body></html>
diff --git a/ui/e2e/model-provider/fixture.tsx b/ui/e2e/model-provider/fixture.tsx
new file mode 100644
index 000000000..b4a117c70
--- /dev/null
+++ b/ui/e2e/model-provider/fixture.tsx
@@ -0,0 +1,99 @@
+import { useState } from 'react';
+import { createRoot } from 'react-dom/client';
+import { createInstance } from 'i18next';
+import { I18nextProvider } from 'react-i18next';
+import en from '../../src/i18n/en.json';
+import zh from '../../src/i18n/zh.json';
+import '../../src/index.css';
+import '../../src/components/settings/models/modelHubSurface.css';
+import { Button } from '../../src/components/ui/button';
+import { AddApiKeyDialog } from '../../src/components/settings/models/AddApiKeyDialog';
+import { SourceDetailPanel } from '../../src/components/settings/models/SourceDetailPanel';
+import { createSourceCollectionReadAuthority } from '../../src/components/settings/models/collectionReadAuthority';
+import { modelsApi } from '../../src/components/settings/models/modelsApi';
+import { readSurfaceLanding, sourceMutationLanding, type TrackSourceMutation } from '../../src/components/settings/models/mutationSettlement';
+import { CONTRACT_VERSION, type Source } from '../../src/components/settings/models/types';
+
+const params = new URLSearchParams(location.search);
+const language = createInstance();
+await language.init({ lng: params.get('lang') ?? 'en', resources: { en: { translation: en }, zh: { translation: zh } }, interpolation: { escapeValue: false } });
+document.documentElement.dataset.theme = params.get('theme') ?? 'dark';
+let saved: Source = {
+ id: 'src_fixture001', vendor: 'custom', kind: 'api_key', display_name: 'Example relay',
+ base_url: 'https://relay.example/v1', protocol: 'openai_chat', billing: 'metered', supply_channel: 'hub',
+ state: { status: 'standby', retry_at: null, detail_key: null }, credential_ref: 'cred_fixture001',
+ verification_pending: 'vp_fixture', last_discovered_at: '2026-09-08T00:00:00Z',
+ models: ['upstream-first-model', 'gpt-5.6-luna', 'claude-sonnet-5'].map((id) => ({
+ id, display_name: null, origin: 'discovered', reasoning_efforts: ['low', 'medium', 'high'], reasoning_efforts_source: 'catalog',
+ })),
+};
+const calls: string[] = [];
+modelsApi.listSources = async () => [saved];
+modelsApi.observeApiKeySource = async () => { throw new Error('Automatic detection must not run'); };
+modelsApi.createApiKeySource = async (draft) => {
+ calls.push('save');
+ if (!draft.save_unverified) throw new Error('Save must not require detection');
+ saved = { ...saved, client_nonce: draft.client_nonce, protocol: draft.protocol ?? saved.protocol };
+ return { source: saved, added_to: [], adopted_by: [] };
+};
+modelsApi.probeSource = async (id, model) => {
+ calls.push('test:' + id + '/' + model);
+ saved = { ...saved, verification_pending: null };
+ return { source_id: id, model_id: model, protocol: saved.protocol, reachable: true, latency_ms: 123, error: null };
+};
+modelsApi.refreshSource = async () => { calls.push('refetch'); return { source: saved, discovered: saved.models.length }; };
+modelsApi.addCustomModel = async (_id, draft) => {
+ calls.push('manual');
+ saved = { ...saved, models: [...saved.models, {
+ id: draft.model_id, display_name: null, origin: 'manual', reasoning_efforts: [], reasoning_efforts_source: null,
+ }] };
+ return saved;
+};
+const sourceReads = createSourceCollectionReadAuthority(modelsApi);
+
+export function Fixture() {
+ const [open, setOpen] = useState(false);
+ const [source, setSource] = useState(saved);
+ const [callLog, setCallLog] = useState<string[]>([]);
+ const reconcile = async () => {
+ const reads = await readSurfaceLanding({
+ sources: async () => {
+ if (params.get('reconcile') === 'failed') throw new Error('Fixture Source read unavailable');
+ return modelsApi.listSources();
+ },
+ supply: async () => [],
+ runtime: async () => ({
+ contract_version: CONTRACT_VERSION,
+ manifest: { name: 'cliproxyapi', resolution: 'unresolved', assets: [] },
+ status: { verified: false, health: 'not_started' },
+ }),
+ chains: async () => ({}),
+ }, []);
+ if (reads.sources.kind === 'ready') setSource(saved);
+ return sourceMutationLanding(reads, [], true);
+ };
+ const trackMutation: TrackSourceMutation = async (work) => {
+ try {
+ return await work(saved, {
+ source: async (next) => { setSource(next); return reconcile(); },
+ unread: reconcile,
+ gone: async () => ({ verdict: 'degraded', reads: null, affectedChains: [] }),
+ readInventory: async () => ({ sources: [saved], snapshot: 1 }),
+ release: () => {},
+ });
+ } finally {
+ setCallLog([...calls]);
+ }
+ };
+ return <I18nextProvider i18n={language}>
+ <main className="mx-auto flex h-dvh w-full max-w-[720px] flex-col bg-surface">
+ <Button onClick={() => setOpen(true)}>Add provider fixture</Button>
+ <SourceDetailPanel source={source} trackMutation={trackMutation} onReauth={() => {}}
+ onMutationCommitted={async (commit) => { await commit.settle(); }} />
+ <AddApiKeyDialog open={open} sourceReads={sourceReads} onClose={() => setOpen(false)}
+ onAdded={(created) => setSource(created.source)} />
+ <output hidden data-testid="calls">{JSON.stringify(callLog)}</output>
+ </main>
+ </I18nextProvider>;
+}
+createRoot(document.getElementById('root')!).render(<Fixture />);
diff --git a/ui/e2e/model-provider/provider.spec.ts b/ui/e2e/model-provider/provider.spec.ts
new file mode 100644
index 000000000..e02ced9ff
--- /dev/null
+++ b/ui/e2e/model-provider/provider.spec.ts
@@ -0,0 +1,47 @@
+import { expect, test } from '@playwright/test';
+import { hub } from '../support/copy';
+
+for (const lang of ['en', 'zh'] as const) {
+ test('save, optional selected-model test and manual inventory: ' + lang, async ({ page }, info) => {
+ const text = (key: string) => hub(key, undefined, lang);
+ await page.route('**/api/**', (route) => route.abort());
+ await page.goto('/e2e/model-provider/fixture.html?lang=' + lang);
+ await expect(page.getByText('Example relay', { exact: true })).toBeVisible();
+ await expect(page.getByText('high', { exact: true })).toHaveCount(0);
+ await page.getByRole('button', { name: 'Add provider fixture' }).click();
+ await page.getByRole('textbox', { name: 'Base URL', exact: true }).fill('https://relay.example/v1');
+ await page.getByLabel(text('addKey.field.apiKey'), { exact: true }).fill('fixture-placeholder');
+ await expect(page.getByRole('button', { name: text('addKey.confirm'), exact: true })).toBeInViewport();
+ await page.screenshot({ path: info.outputPath('save-dialog.png') });
+ await page.getByRole('button', { name: text('addKey.confirm'), exact: true }).click();
+ await expect(page.getByRole('dialog')).toHaveCount(0);
+ await page.getByRole('button', { name: text('sourceTest.open'), exact: true }).click();
+ await expect(page.getByRole('combobox')).toContainText('gpt-5.6-luna');
+ await page.getByRole('combobox').click();
+ await page.getByRole('option', { name: 'claude-sonnet-5', exact: true }).click();
+ await page.getByRole('button', { name: text('sourceTest.run'), exact: true }).click();
+ await expect(page.getByRole('status')).toContainText('claude-sonnet-5');
+ await page.screenshot({ path: info.outputPath('test-result.png') });
+ await page.getByRole('button', { name: lang === 'en' ? 'Close' : '关闭', exact: true }).first().click();
+ await page.getByRole('button', { name: text('sourceDetail.action.addModel'), exact: true }).click();
+ await page.getByPlaceholder(text('sourceDetail.col.id'), { exact: true }).fill('manual-model');
+ await page.getByRole('button', { name: text('sourceDetail.action.addModel'), exact: true }).last().click();
+ await expect(page.getByText('manual-model', { exact: true })).toBeVisible();
+ expect(await page.getByTestId('calls').textContent()).not.toContain('refetch');
+ await page.screenshot({ path: info.outputPath('inventory.png') });
+ expect(await page.evaluate(() => document.documentElement.scrollWidth <= window.innerWidth)).toBe(true);
+ });
+
+ test('unread Source reconciliation cannot publish a model verdict: ' + lang, async ({ page }, info) => {
+ const text = (key: string) => hub(key, undefined, lang);
+ await page.route('**/api/**', (route) => route.abort());
+ await page.goto('/e2e/model-provider/fixture.html?reconcile=failed&lang=' + lang);
+ await page.getByRole('button', { name: text('sourceTest.open'), exact: true }).click();
+ await page.getByRole('button', { name: text('sourceTest.run'), exact: true }).click();
+ await expect(page.getByRole('alert')).toHaveText(text('sourceTest.requestFailed'));
+ await expect(page.getByRole('status')).toHaveCount(0);
+ await page.screenshot({ path: info.outputPath('unconfirmed-result.png') });
+ expect(await page.getByTestId('calls').textContent()).toBe('["test:src_fixture001/gpt-5.6-luna"]');
+ expect(await page.evaluate(() => document.documentElement.scrollWidth <= window.innerWidth)).toBe(true);
+ });
+}
diff --git a/ui/e2e/model-provider/tsconfig.json b/ui/e2e/model-provider/tsconfig.json
new file mode 100644
index 000000000..d0496236c
--- /dev/null
+++ b/ui/e2e/model-provider/tsconfig.json
@@ -0,0 +1,6 @@
+{
+ "extends": "../../tsconfig.app.json",
+ "compilerOptions": { "types": ["vite/client", "node"] },
+ "include": ["*.ts", "*.tsx", "../../playwright.model-provider.config.ts", "../../agentation.d.ts"],
+ "exclude": []
+}
diff --git a/ui/e2e/support/api.ts b/ui/e2e/support/api.ts
index 1b557c381..ce24de00e 100644
--- a/ui/e2e/support/api.ts
+++ b/ui/e2e/support/api.ts
@@ -30,6 +30,7 @@ export type Source = {
base_url?: string | null;
credential_ref?: string | null;
client_nonce?: string | null;
+ verification_pending?: string | null;
models: {
id: string;
origin: string;
diff --git a/ui/e2e/support/hub.ts b/ui/e2e/support/hub.ts
index 05c011240..b2c9a210c 100644
--- a/ui/e2e/support/hub.ts
+++ b/ui/e2e/support/hub.ts
@@ -398,7 +398,7 @@ export const labelledButton = (scope: Locator, name: string): Locator =>
* `vendor` is the label a vendor is offered under and goes FIRST, because
* choosing one rewrites the Base URL and retires whatever interface was selected
* — filling those before it would fill them into a form the next click resets.
- * It also removes the manual disclosure, so `vendor` and `protocol` are
+ * It also removes the protocol selector, so `vendor` and `protocol` are
* alternatives, not a pair: the pin IS the interface, and there is no control
* left for `protocol` to press.
*
@@ -423,7 +423,6 @@ export const fillApiKeyForm = async (
await dialog.getByLabel(hub('addKey.field.name'), { exact: true }).fill(values.name);
}
if (values.protocol) {
- await dialog.getByRole('button', { name: hub('addKey.protocol.manual'), exact: true }).click();
await dialog.getByRole('button', { name: values.protocol, exact: true }).click();
}
await dialog.getByLabel(hub('addKey.field.baseUrl'), { exact: true }).fill(values.baseUrl);
diff --git a/ui/package.json b/ui/package.json
index 882e4c36d..a03697e59 100644
--- a/ui/package.json
+++ b/ui/package.json
@@ -23,6 +23,7 @@
"test:inbox-return": "tsc -p e2e/inbox-return/tsconfig.json --noEmit && playwright test --config playwright.inbox-return.config.ts",
"test:project-order": "tsc -p e2e/project-order/tsconfig.json --noEmit && playwright test --config playwright.project-order.config.ts",
"test:model-catalog": "tsc -p e2e/model-catalog/tsconfig.json --noEmit && playwright test --config playwright.model-catalog.config.ts",
+ "test:model-provider": "tsc -p e2e/model-provider/tsconfig.json --noEmit && playwright test --config playwright.model-provider.config.ts",
"validate:catalog": "node scripts/validate-scenario-catalog.mjs",
"validate:theme": "node scripts/validate-theme.mjs"
},
diff --git a/ui/playwright.config.ts b/ui/playwright.config.ts
index e8b33f2fd..73f9d29d3 100644
--- a/ui/playwright.config.ts
+++ b/ui/playwright.config.ts
@@ -16,7 +16,7 @@ import { BASE_URL } from './e2e/support/env';
export default defineConfig({
testDir: './e2e',
- testIgnore: ['**/chat-paging/**', '**/inbox-return/**', '**/model-catalog/**'],
+ testIgnore: ['**/chat-paging/**', '**/inbox-return/**', '**/model-catalog/**', '**/model-provider/**'],
outputDir: './e2e/.artifacts/test-results',
// Every spec mutates shared instance state (sources, agent modes, the
// runtime switch). Parallel workers would race on it, so the suite is serial
diff --git a/ui/playwright.model-provider.config.ts b/ui/playwright.model-provider.config.ts
new file mode 100644
index 000000000..145191008
--- /dev/null
+++ b/ui/playwright.model-provider.config.ts
@@ -0,0 +1,18 @@
+import { defineConfig, devices } from '@playwright/test';
+
+export default defineConfig({
+ testDir: './e2e/model-provider',
+ outputDir: './e2e/.artifacts/model-provider',
+ workers: 1,
+ retries: 0,
+ use: { baseURL: 'http://127.0.0.1:5207', trace: 'retain-on-failure' },
+ webServer: {
+ command: 'npm run dev -- --host 127.0.0.1 --port 5207 --strictPort',
+ env: { VIBE_UI_BACKEND: 'http://127.0.0.1:9' },
+ url: 'http://127.0.0.1:5207/e2e/model-provider/fixture.html',
+ },
+ projects: [
+ { name: 'desktop', use: { ...devices['Desktop Chrome'] } },
+ { name: 'mobile', use: { ...devices['iPhone 13'], browserName: 'chromium' } },
+ ],
+});
diff --git a/ui/src/components/settings/models/AddApiKeyDialog.test.tsx b/ui/src/components/settings/models/AddApiKeyDialog.test.tsx
index 0ac7bbd1c..8133de28d 100644
--- a/ui/src/components/settings/models/AddApiKeyDialog.test.tsx
+++ b/ui/src/components/settings/models/AddApiKeyDialog.test.tsx
@@ -16,25 +16,11 @@ import type {
TrackSourceMutation,
} from './mutationSettlement';
import {
- CONTRACT_VERSION,
- SOURCE_DISPLAY_NAME_MAX_LENGTH,
type RouteHopRef,
type Source,
- type SourceObservation,
type SupplyGap,
} from './types';
-const observed = (patch: Partial<SourceObservation> = {}): SourceObservation => ({
- contract_version: CONTRACT_VERSION,
- outcome: 'observed',
- reachable: true,
- authenticated: 'authenticated',
- protocol: 'openai_chat',
- discovery: 'succeeded',
- models: ['model-a', 'model-b'],
- ...patch,
-});
-
const source: Source = {
id: 'src_new',
last_discovered_at: null,
@@ -134,9 +120,7 @@ const renderReplacement = (
return { onClose, settlement };
};
-const DETECT = /^Detect$|^检测$/;
-const CONFIRM = /Confirm & add|确认添加/;
-const RETRY = /^Retry$|^重试$/i;
+const CONFIRM = /Add provider|添加供应商/;
const fillCredentials = async () => {
const user = userEvent.setup();
@@ -149,7 +133,6 @@ const fillCredentials = async () => {
* continues with whichever vendor is currently chosen. */
const vendorField = () => screen.getByRole('combobox', { name: /^(Vendor|服务商)(\s|$)/ });
const baseUrlInput = () => screen.getByRole('textbox', { name: /^Base URL$/i }) as HTMLInputElement;
-const disclosure = () => screen.queryByRole('button', { name: /Manually specify interface type|手动指定接口类型/i });
/** A catalog row read from the shipped file, so the case does not restate an id,
* a URL, or a pin that the backend owns. Chosen by protocol rather than by name:
@@ -181,14 +164,6 @@ const selectVendor = async (user: ReturnType<typeof userEvent.setup>, id: string
await user.click(await screen.findByRole('option', { name: vendorOptionName(id) }));
};
-const openManualProtocol = async (user: ReturnType<typeof userEvent.setup>) => {
- await user.click(screen.getByRole('button', { name: /Manually specify interface type|手动指定接口类型/i }));
-};
-
-const clickDetect = async (user: ReturnType<typeof userEvent.setup>) => {
- await user.click(screen.getByRole('button', { name: DETECT }));
-};
-
const clickConfirm = async (user: ReturnType<typeof userEvent.setup>) => {
await user.click(await screen.findByRole('button', { name: CONFIRM }));
};
@@ -211,233 +186,69 @@ afterEach(() => {
vi.unstubAllGlobals();
});
-describe('AddApiKeyDialog', () => {
- it('saves only a selected interface as unverified without observing', async () => {
+describe('AddApiKeyDialog · save reconciliation', () => {
+ it('saves directly with a visible protocol and never performs automatic detection', async () => {
const observe = vi.spyOn(modelsApi, 'observeApiKeySource');
const create = vi.spyOn(modelsApi, 'createApiKeySource').mockResolvedValue({
- source: { ...source, verification_pending: 'vp_0123456789abcdef0123456789abcdef' }, added_to: [], adopted_by: [],
+ source, added_to: [], adopted_by: [],
});
const { onAdded } = renderDialog();
const user = await fillCredentials();
- expect(screen.queryByRole('button', { name: 'Save unverified' })).toBeNull();
- await openManualProtocol(user);
- await user.click(screen.getByRole('button', { name: 'OpenAI Chat Completions' }));
- await user.click(screen.getByRole('button', { name: 'Save unverified' }));
- await waitFor(() => expect(onAdded).toHaveBeenCalledTimes(1));
+ expect(screen.getByRole('button', { name: 'OpenAI Chat Completions' }).getAttribute('aria-pressed')).toBe('true');
+ await clickConfirm(user);
+ await waitFor(() => expect(onAdded).toHaveBeenCalledOnce());
expect(create).toHaveBeenCalledWith(expect.objectContaining({
protocol: 'openai_chat', save_unverified: true, key: 'secret-key',
}));
expect(observe).not.toHaveBeenCalled();
});
- it('retains unverified consent and nonce while reconciling an unknown write', async () => {
- const create = vi.spyOn(modelsApi, 'createApiKeySource')
- .mockRejectedValueOnce(new Error('Connection interrupted'))
- .mockResolvedValue({ source: { ...source, verification_pending: 'vp_0123456789abcdef0123456789abcdef' }, added_to: [], adopted_by: [] });
- vi.spyOn(modelsApi, 'listSources').mockResolvedValue([]);
+ it.each(API_KEY_VENDOR_PRESETS)('saves $id with its catalog protocol without a connectivity gate', async (entry) => {
const observe = vi.spyOn(modelsApi, 'observeApiKeySource');
- const { onAdded } = renderDialog();
- const user = await fillCredentials();
- await selectVendor(user, preset('openai_chat').id);
- await user.click(screen.getByRole('button', { name: 'Save unverified' }));
- await user.click(await screen.findByRole('button', { name: RETRY }));
- await waitFor(() => expect(onAdded).toHaveBeenCalledTimes(1));
- expect(create).toHaveBeenCalledTimes(2);
- expect(create.mock.calls[1][0]).toEqual(create.mock.calls[0][0]);
- expect(create.mock.calls[1][0].save_unverified).toBe(true);
- expect(observe).not.toHaveBeenCalled();
- });
-
- it('detects without persisting, names the protocol, and drops the report when credentials change', async () => {
- vi.spyOn(modelsApi, 'observeApiKeySource').mockResolvedValueOnce(observed());
- const create = vi.spyOn(modelsApi, 'createApiKeySource');
- renderDialog();
- const user = await fillCredentials();
-
- await clickDetect(user);
- expect(await screen.findByText(/OpenAI Chat Completions/)).toBeTruthy();
- expect(screen.getByText(/Fetched 2 models|拉到 2 个模型/i)).toBeTruthy();
- expect(screen.queryByText('model-a')).toBeNull();
- expect(screen.getByRole('button', { name: CONFIRM })).toBeTruthy();
- expect(create).not.toHaveBeenCalled();
-
- await user.type(screen.getByRole('textbox', { name: /^Base URL$/i }), '/changed');
- expect(screen.queryByText(/Fetched 2 models|拉到 2 个模型/i)).toBeNull();
- expect(screen.getByRole('button', { name: DETECT })).toBeTruthy();
- });
-
- it('puts protocol-family glyphs on concrete interface names and never on Auto detect', async () => {
- vi.spyOn(modelsApi, 'observeApiKeySource').mockResolvedValueOnce(
- observed({ protocol: 'anthropic' }),
- );
- renderDialog();
- expect(screen.getByText(/Identified automatically once Base URL and API key are filled|填好 Base URL 和 API Key 后自动识别/)).toBeTruthy();
- const user = await fillCredentials();
- await openManualProtocol(user);
-
- expect(screen.getByRole('button', { name: /Auto detect|自动探测/i }).querySelector('svg')).toBeNull();
- expect(screen.getByRole('button', { name: 'Anthropic Messages' }).querySelector('svg')).toBeTruthy();
- expect(screen.getByRole('button', { name: 'OpenAI Responses' }).querySelector('svg')).toBeTruthy();
- expect(screen.getByRole('button', { name: 'OpenAI Chat Completions' }).querySelector('svg')).toBeTruthy();
-
- await clickDetect(user);
- await waitFor(() => {
- const identified = document.querySelector('.model-hub-add-key-strip--success');
- expect(identified?.textContent).toMatch(/Anthropic Messages/);
- expect(identified?.querySelector('.model-hub-add-key-protocol-glyph')).toBeTruthy();
- });
- });
-
- it('sends one manually selected interface on the first observation and create', async () => {
- const observe = vi.spyOn(modelsApi, 'observeApiKeySource')
- .mockResolvedValueOnce(observed({ protocol: 'openai_responses' }));
- const create = vi.spyOn(modelsApi, 'createApiKeySource').mockResolvedValueOnce({
- source,
- added_to: [],
- adopted_by: [],
- });
- renderDialog();
- const user = await fillCredentials();
-
- await openManualProtocol(user);
- expect(screen.getByRole('button', { name: /Auto detect|自动探测/i }).getAttribute('aria-pressed')).toBe('true');
- await user.click(screen.getByRole('button', { name: 'OpenAI Responses' }));
- await clickDetect(user);
- await clickConfirm(user);
-
- await waitFor(() => expect(create).toHaveBeenCalledOnce());
- expect(observe.mock.calls[0][0].protocol).toBe('openai_responses');
- expect(create.mock.calls[0][0].protocol).toBe('openai_responses');
- });
-
- it('turns an ambiguous auto-detection into one exact manual retry, then confirms', async () => {
- const observe = vi.spyOn(modelsApi, 'observeApiKeySource')
- .mockResolvedValueOnce(observed({
- outcome: 'ambiguous',
- authenticated: 'unknown',
- protocol: null,
- discovery: 'not_attempted',
- models: [],
- }))
- .mockResolvedValueOnce(observed({ protocol: 'openai_responses' }));
- const create = vi.spyOn(modelsApi, 'createApiKeySource').mockResolvedValueOnce({
- source,
- added_to: [],
- adopted_by: [],
- });
- const { onAdded } = renderDialog();
- const user = await fillCredentials();
-
- await clickDetect(user);
- const retry = await screen.findByRole('button', { name: /^Retry$|^重试$/i });
- expect((retry as HTMLButtonElement).disabled).toBe(true);
- await user.click(screen.getByRole('button', { name: 'OpenAI Responses' }));
- await user.click(retry);
-
- expect(await screen.findByRole('button', { name: CONFIRM })).toBeTruthy();
- expect(create).not.toHaveBeenCalled();
- await clickConfirm(user);
-
- await waitFor(() => expect(create).toHaveBeenCalledOnce());
- const secondObservation = observe.mock.calls[1][0];
- expect(secondObservation.protocol).toBe('openai_responses');
- expect(create.mock.calls[0][0].protocol).toBe('openai_responses');
- expect(onAdded).toHaveBeenCalledWith({ source, added_to: [], adopted_by: [] });
- });
-
- it('retries the complete observation from inventory failure and persists only through Add anyway', async () => {
- const inventory = observed({ discovery: 'failed', models: [] });
- const observe = vi.spyOn(modelsApi, 'observeApiKeySource').mockResolvedValue(inventory);
const create = vi.spyOn(modelsApi, 'createApiKeySource').mockResolvedValue({
- source,
- added_to: [],
- adopted_by: [],
+ source, added_to: [], adopted_by: [],
});
renderDialog();
- const user = await fillCredentials();
-
- await clickDetect(user);
- await screen.findByRole('button', { name: /Add anyway|仍要添加/i });
- await user.click(screen.getByRole('button', { name: /^Retry$|^重试$/i }));
- await waitFor(() => expect(observe).toHaveBeenCalledTimes(2));
- expect(create).not.toHaveBeenCalled();
- expect(screen.queryByText(/The list could not be read|清单没能读出来/i)).toBeNull();
-
- await user.click(await screen.findByRole('button', { name: /Add anyway|仍要添加/i }));
+ const user = userEvent.setup();
+ await selectVendor(user, entry.id);
+ await user.type(screen.getByLabelText(/^API key$/i), 'secret-key');
+ await clickConfirm(user);
await waitFor(() => expect(create).toHaveBeenCalledOnce());
- expect(create.mock.calls[0][0].protocol).toBe('openai_chat');
- expect(create.mock.calls[0][0].accept_unavailable_inventory).toBe(true);
- });
-
- it('adopts the new observation result when inventory retry moves to interface undetermined', async () => {
- const inventory = observed({ discovery: 'failed', models: [] });
- const ambiguous = observed({
- outcome: 'ambiguous',
- authenticated: 'unknown',
- protocol: null,
- discovery: 'not_attempted',
- models: [],
+ expect(create.mock.calls[0][0]).toMatchObject({
+ vendor: entry.id, protocol: entry.protocol, base_url: entry.official_base_url, save_unverified: true,
});
- const observe = vi.spyOn(modelsApi, 'observeApiKeySource')
- .mockResolvedValueOnce(inventory)
- .mockResolvedValueOnce(ambiguous);
- renderDialog();
- const user = await fillCredentials();
-
- await clickDetect(user);
- await screen.findByRole('button', { name: /Add anyway|仍要添加/i });
- await user.click(screen.getByRole('button', { name: /^Retry$|^重试$/i }));
-
- await waitFor(() => expect(observe).toHaveBeenCalledTimes(2));
- expect(await screen.findByText(i18n.t('settings.models.addKey.undetermined.title'))).toBeTruthy();
- expect(screen.queryByRole('button', { name: /Add anyway|仍要添加/i })).toBeNull();
+ expect(observe).not.toHaveBeenCalled();
});
- it('preserves unavailable-inventory consent across lost-response reconciliation', async () => {
- vi.spyOn(modelsApi, 'observeApiKeySource').mockResolvedValueOnce(
- observed({ discovery: 'failed', models: [] }),
- );
+ it('lets the user choose a custom protocol and keeps validation failures editable', async () => {
const create = vi.spyOn(modelsApi, 'createApiKeySource')
- .mockRejectedValueOnce(new TypeError('response lost'))
+ .mockRejectedValueOnce(new ApiCallError('discovery_failed', undefined, true, [], [], [], 400))
.mockResolvedValueOnce({ source, added_to: [], adopted_by: [] });
- vi.spyOn(modelsApi, 'listSources').mockResolvedValueOnce([]);
renderDialog();
const user = await fillCredentials();
-
- await clickDetect(user);
- await user.click(await screen.findByRole('button', { name: /Add anyway|仍要添加/i }));
- await user.click(await screen.findByRole('button', { name: /^Retry$|^重试$/i }));
-
+ await user.click(screen.getByRole('button', { name: 'Anthropic Messages' }));
+ await clickConfirm(user);
+ await screen.findByRole('button', { name: /^Retry$/ });
+ await user.type(baseUrlInput(), '/changed');
+ await clickConfirm(user);
await waitFor(() => expect(create).toHaveBeenCalledTimes(2));
- expect(create.mock.calls.map(([draft]) => draft.accept_unavailable_inventory)).toEqual([
- true,
- true,
- ]);
- expect(create.mock.calls[1][0].client_nonce).toBe(create.mock.calls[0][0].client_nonce);
+ expect(create.mock.calls[1][0]).toMatchObject({
+ protocol: 'anthropic', base_url: 'https://relay.example/v1/changed', save_unverified: true,
+ });
});
- it('aborts an in-flight detect and returns to the form without dismissing', async () => {
- let wasAborted = false;
- vi.spyOn(modelsApi, 'observeApiKeySource').mockImplementation((_draft, signal) => new Promise((_resolve, reject) => {
- signal?.addEventListener('abort', () => {
- wasAborted = true;
- reject(new DOMException('aborted', 'AbortError'));
- }, { once: true });
- }));
- const { onClose } = renderDialog();
+ it('does not submit missing credentials or an overlong display name', async () => {
+ const create = vi.spyOn(modelsApi, 'createApiKeySource');
+ renderDialog();
+ expect(screen.getByRole('button', { name: CONFIRM }).hasAttribute('disabled')).toBe(true);
const user = await fillCredentials();
-
- await clickDetect(user);
- await user.click(screen.getAllByRole('button', { name: /^Cancel$|^取消$/i }).at(-1)!);
-
- expect(wasAborted).toBe(true);
- expect(onClose).not.toHaveBeenCalled();
- expect(screen.getByRole('button', { name: DETECT })).toBeTruthy();
+ await user.type(screen.getByRole('textbox', { name: /Name|名称/i }), 'n'.repeat(65));
+ expect(screen.getByRole('button', { name: CONFIRM }).hasAttribute('disabled')).toBe(true);
+ expect(create).not.toHaveBeenCalled();
});
it('reconciles a lost source-create response by nonce without posting twice', async () => {
let nonce: string | undefined;
- vi.spyOn(modelsApi, 'observeApiKeySource').mockResolvedValueOnce(observed());
const create = vi.spyOn(modelsApi, 'createApiKeySource').mockImplementationOnce(async (draft) => {
nonce = draft.client_nonce;
throw new TypeError('response lost');
@@ -450,7 +261,6 @@ describe('AddApiKeyDialog', () => {
const { onAdded } = renderDialog();
const user = await fillCredentials();
- await clickDetect(user);
await clickConfirm(user);
await user.click(await screen.findByRole('button', { name: /^Retry$|^重试$/i }));
@@ -461,7 +271,6 @@ describe('AddApiKeyDialog', () => {
});
it('retries source creation only after the nonce is confirmed absent', async () => {
- vi.spyOn(modelsApi, 'observeApiKeySource').mockResolvedValueOnce(observed());
const create = vi.spyOn(modelsApi, 'createApiKeySource')
.mockRejectedValueOnce(new TypeError('response lost'))
.mockResolvedValueOnce({ source, added_to: [], adopted_by: [] });
@@ -469,7 +278,6 @@ describe('AddApiKeyDialog', () => {
renderDialog();
const user = await fillCredentials();
- await clickDetect(user);
await clickConfirm(user);
await user.click(await screen.findByRole('button', { name: /^Retry$|^重试$/i }));
@@ -480,13 +288,11 @@ describe('AddApiKeyDialog', () => {
it('cannot create or navigate after cancelling a pending lost-response reconciliation', async () => {
const pendingInventory = deferred<Source[]>();
- vi.spyOn(modelsApi, 'observeApiKeySource').mockResolvedValueOnce(observed());
const create = vi.spyOn(modelsApi, 'createApiKeySource').mockRejectedValueOnce(new TypeError('response lost'));
vi.spyOn(modelsApi, 'listSources').mockReturnValueOnce(pendingInventory.promise);
const { onAdded, onClose } = renderDialog();
const user = await fillCredentials();
- await clickDetect(user);
await clickConfirm(user);
await user.click(await screen.findByRole('button', { name: /^Retry$|^重试$/i }));
await user.click(screen.getAllByRole('button', { name: /^Cancel$|^取消$/i }).at(-1)!);
@@ -501,7 +307,6 @@ describe('AddApiKeyDialog', () => {
it('cannot replay a reconciled Source after the dialog attempt is cancelled', async () => {
const pendingInventory = deferred<Source[]>();
let nonce: string | undefined;
- vi.spyOn(modelsApi, 'observeApiKeySource').mockResolvedValueOnce(observed());
vi.spyOn(modelsApi, 'createApiKeySource').mockImplementationOnce(async (draft) => {
nonce = draft.client_nonce;
throw new TypeError('response lost');
@@ -510,7 +315,6 @@ describe('AddApiKeyDialog', () => {
const { onAdded } = renderDialog();
const user = await fillCredentials();
- await clickDetect(user);
await clickConfirm(user);
await user.click(await screen.findByRole('button', { name: /^Retry$|^重试$/i }));
await user.click(screen.getAllByRole('button', { name: /^Cancel$|^取消$/i }).at(-1)!);
@@ -520,248 +324,9 @@ describe('AddApiKeyDialog', () => {
expect(onAdded).not.toHaveBeenCalled();
});
- it('rejects a trimmed blank or overlong display name before observation', async () => {
- const observe = vi.spyOn(modelsApi, 'observeApiKeySource');
- renderDialog();
- const user = await fillCredentials();
- const name = screen.getByRole('textbox', { name: /^Name|^名称/i });
- const detect = screen.getByRole('button', { name: DETECT }) as HTMLButtonElement;
-
- await user.type(name, ' ');
- expect(detect.disabled).toBe(true);
- await user.clear(name);
- await user.type(name, 'x'.repeat(SOURCE_DISPLAY_NAME_MAX_LENGTH + 1));
- expect(detect.disabled).toBe(true);
- await user.click(detect);
- expect(observe).not.toHaveBeenCalled();
- });
-
- it('counts supplementary display-name characters as JSON Schema code points', async () => {
- renderDialog();
- const user = await fillCredentials();
- const name = screen.getByRole('textbox', { name: /^Name|^名称/i });
- const detect = screen.getByRole('button', { name: DETECT }) as HTMLButtonElement;
-
- await user.type(name, '😀'.repeat(SOURCE_DISPLAY_NAME_MAX_LENGTH));
- expect(detect.disabled).toBe(false);
- await user.type(name, '😀');
- expect(detect.disabled).toBe(true);
- });
-
- it('keeps a server-named create validation failure editable and out of save reconciliation', async () => {
- vi.stubGlobal('fetch', vi.fn(async (input: RequestInfo | URL) => {
- if (String(input) === '/api/csrf-token') return Response.json({ csrf_token: 'csrf' });
- return Response.json({ ok: false, error: 'invalid_source', detail: 'modelHub.errors.discovery_failed' }, { status: 422 });
- }));
- let validationError: unknown;
- try {
- await modelsApi.createApiKeySource({ kind: 'api_key', vendor: 'custom', base_url: 'https://relay.example/v1', key: 'secret-key' });
- } catch (error) {
- validationError = error;
- }
- vi.spyOn(modelsApi, 'observeApiKeySource').mockResolvedValueOnce(observed());
- const create = vi.spyOn(modelsApi, 'createApiKeySource').mockRejectedValue(validationError);
- const list = vi.spyOn(modelsApi, 'listSources');
- renderDialog();
- const user = await fillCredentials();
- const name = screen.getByRole('textbox', { name: /^Name|^名称/i });
- await user.type(name, 'Relay');
-
- await clickDetect(user);
- await clickConfirm(user);
-
- expect(await screen.findByText(i18n.t('settings.models.addKey.fail.unclassified'))).toBeTruthy();
- expect(screen.queryByText('modelHub.errors.discovery_failed')).toBeNull();
- expect((name as HTMLInputElement).disabled).toBe(false);
- expect(screen.queryByText(/not confirmed saved|确认.*保存/i)).toBeNull();
- expect(list).not.toHaveBeenCalled();
- await user.clear(name);
- await user.type(name, 'Fixed relay');
- expect(screen.getByRole('button', { name: DETECT })).toBeTruthy();
- expect(create).toHaveBeenCalledOnce();
- });
-
- it('retires the evidence of every exit that would persist without observing again', async () => {
- // One rule, stated over how a state exits rather than over which states exist:
- // ①″'s report and the protocol a server-named refusal still holds were each
- // proved against this endpoint, this credential and this probe constraint, so
- // changing any of those three ends both. Every combination is driven through
- // the UI so neither arm can quietly become its own special case.
- type Act = (user: ReturnType<typeof userEvent.setup>) => Promise<void>;
- const exits: Act[] = [
- async (user) => {
- await clickDetect(user);
- await screen.findByRole('button', { name: CONFIRM });
- },
- async (user) => {
- await clickDetect(user);
- await clickConfirm(user);
- await screen.findByRole('button', { name: RETRY });
- },
- ];
- const connectionEdits: Act[] = [
- async (user) => { await user.type(screen.getByRole('textbox', { name: /^Base URL$/i }), '/v2'); },
- async (user) => { await user.type(screen.getByLabelText(/^API key$/i), 'x'); },
- async (user) => {
- await openManualProtocol(user);
- await user.click(screen.getByRole('button', { name: 'Anthropic Messages' }));
- },
- ];
-
- for (const reachExit of exits) {
- for (const edit of connectionEdits) {
- vi.spyOn(modelsApi, 'observeApiKeySource').mockResolvedValue(observed());
- const create = vi.spyOn(modelsApi, 'createApiKeySource').mockRejectedValue(
- new ApiCallError('invalid_source', 'modelHub.errors.discovery_failed', true, [], [], [], 422),
- );
- renderDialog();
- const user = await fillCredentials();
- await reachExit(user);
- const persistedBefore = create.mock.calls.length;
-
- await edit(user);
-
- expect(screen.getByRole('button', { name: DETECT })).toBeTruthy();
- expect(screen.queryByRole('button', { name: CONFIRM })).toBeNull();
- expect(screen.queryByRole('button', { name: RETRY })).toBeNull();
- expect(create.mock.calls.length).toBe(persistedBefore);
-
- cleanup();
- vi.restoreAllMocks();
- }
- }
- });
-
- it('keeps a state whose own primary re-observes across the same edit', async () => {
- // The counterpart of the rule above, and the reason it is written over exits:
- // ④'s 重试 reads the fields as they now stand, so naming an interface there is
- // how the user answers it — not evidence to retire.
- vi.spyOn(modelsApi, 'observeApiKeySource').mockResolvedValue(observed({
- outcome: 'ambiguous',
- authenticated: 'unknown',
- protocol: null,
- discovery: 'not_attempted',
- models: [],
- }));
- renderDialog();
- const user = await fillCredentials();
-
- await clickDetect(user);
- await user.click(await screen.findByRole('button', { name: 'Anthropic Messages' }));
-
- expect(screen.getByRole('button', { name: RETRY })).toBeTruthy();
- expect(screen.queryByRole('button', { name: DETECT })).toBeNull();
- });
-
- it('names the interface Detect will send while the disclosure is closed', async () => {
- // The collapsed row and the expanded selector are one selection rendered two
- // ways, so the row states the active constraint rather than the default it
- // replaced, and the promise of automatic identification goes with it.
- const observe = vi.spyOn(modelsApi, 'observeApiKeySource').mockResolvedValue(observed());
- renderDialog();
- const user = await fillCredentials();
- const autoRow = document.querySelector('.model-hub-add-key-protocol-active');
- expect(autoRow?.textContent).toMatch(/Auto detect|自动探测/);
- expect(autoRow?.querySelector('.model-hub-add-key-protocol-glyph')).toBeNull();
-
- await openManualProtocol(user);
- expect(document.querySelector('.model-hub-add-key-protocol-active')).toBeNull();
- await user.click(screen.getByRole('button', { name: 'Anthropic Messages' }));
- await openManualProtocol(user);
-
- const chosenRow = document.querySelector('.model-hub-add-key-protocol-active');
- expect(chosenRow?.textContent).toMatch(/Anthropic Messages/);
- expect(chosenRow?.querySelector('.model-hub-add-key-protocol-glyph')).toBeTruthy();
- expect(screen.queryByText(i18n.t('settings.models.addKey.protocol.idleHint'))).toBeNull();
-
- await clickDetect(user);
- await screen.findByRole('button', { name: CONFIRM });
- expect(observe.mock.calls[0][0].protocol).toBe('anthropic');
- });
-
- it('renders the safe observation cause when create rejects after probing', async () => {
- const failure = new ApiCallError(
- 'discovery_failed',
- 'modelHub.errors.discovery_failed',
- true,
- [],
- [],
- [],
- 422,
- observed({
- outcome: 'authentication_failed',
- authenticated: 'rejected',
- protocol: null,
- discovery: 'not_attempted',
- models: [],
- }),
- );
- vi.spyOn(modelsApi, 'observeApiKeySource').mockResolvedValue(observed());
- vi.spyOn(modelsApi, 'createApiKeySource').mockRejectedValue(failure);
- renderDialog();
- const user = await fillCredentials();
-
- await clickDetect(user);
- await clickConfirm(user);
-
- expect(await screen.findByText(i18n.t('settings.models.addKey.fail.auth'))).toBeTruthy();
- expect(screen.queryByText(i18n.t('settings.models.addKey.fail.unclassified'))).toBeNull();
- });
-
- it('re-enters the classified observation state when create rejects with inventory evidence', async () => {
- const failure = new ApiCallError(
- 'discovery_failed',
- 'modelHub.errors.discovery_failed',
- true,
- [],
- [],
- [],
- 422,
- observed({ discovery: 'failed', models: [] }),
- );
- vi.spyOn(modelsApi, 'observeApiKeySource').mockResolvedValue(observed());
- vi.spyOn(modelsApi, 'createApiKeySource').mockRejectedValue(failure);
- renderDialog();
- const user = await fillCredentials();
-
- await clickDetect(user);
- await clickConfirm(user);
-
- expect(await screen.findByText(/model list did not come back|没拿到它的模型清单/i)).toBeTruthy();
- expect(screen.getByRole('button', { name: /Add anyway|仍要添加/i })).toBeTruthy();
- expect(screen.queryByText(i18n.t('settings.models.addKey.fail.unclassified'))).toBeNull();
- });
-
- it('re-enters the classified observation state when create rejects with ambiguous evidence', async () => {
- const failure = new ApiCallError(
- 'discovery_failed',
- 'modelHub.errors.discovery_failed',
- true,
- [],
- [],
- [],
- 422,
- observed({
- outcome: 'ambiguous',
- reachable: true,
- authenticated: 'authenticated',
- protocol: null,
- discovery: 'not_attempted',
- models: [],
- }),
- );
- vi.spyOn(modelsApi, 'observeApiKeySource').mockResolvedValue(observed());
- vi.spyOn(modelsApi, 'createApiKeySource').mockRejectedValue(failure);
- renderDialog();
- const user = await fillCredentials();
-
- await clickDetect(user);
- await clickConfirm(user);
-
- expect(await screen.findByText(i18n.t('settings.models.addKey.undetermined.title'))).toBeTruthy();
- expect(screen.queryByText(i18n.t('settings.models.addKey.fail.unclassified'))).toBeNull();
- });
+});
+describe('AddApiKeyDialog · replacement', () => {
it('reaches the credential PUT with only the trimmed key', async () => {
const requests: Array<{ input: string; init?: RequestInit }> = [];
vi.stubGlobal('fetch', vi.fn(async (input: RequestInfo | URL, init?: RequestInit) => {
@@ -1072,33 +637,7 @@ describe('AddApiKeyDialog', () => {
);
});
-// The vendor dropdown is the ladder's rung selector. A catalog row makes the
-// interface a fact this dialog READS — from the same shipped file the server
-// pins by — so detection only has to authenticate; 自定义 leaves the two rungs
-// that still ask, the response's shape or the user's word.
-describe('AddApiKeyDialog · vendor', () => {
- it('sends custom with nothing pinned when the vendor is left on 自定义', async () => {
- const observe = vi.spyOn(modelsApi, 'observeApiKeySource').mockResolvedValueOnce(observed());
- const create = vi.spyOn(modelsApi, 'createApiKeySource').mockResolvedValueOnce({
- source,
- added_to: [],
- adopted_by: [],
- });
- renderDialog();
- const user = await fillCredentials();
-
- await clickDetect(user);
- await clickConfirm(user);
-
- await waitFor(() => expect(create).toHaveBeenCalledOnce());
- expect(observe.mock.calls[0][0].vendor).toBe('custom');
- expect(observe.mock.calls[0][0].protocol).toBeUndefined();
- expect(create.mock.calls[0][0].vendor).toBe('custom');
- });
-
- // A vendor is recognised by its mark before its name is read, so the mark has
- // to be on the row AND on the field that shows what was chosen — the second is
- // the half a `<select>` could never carry.
+describe('AddApiKeyDialog · vendor accessibility', () => {
it('puts a mark on every row and on the field once a vendor is chosen', async () => {
const entry = preset('anthropic');
renderDialog();
@@ -1214,129 +753,4 @@ describe('AddApiKeyDialog · vendor', () => {
expect(screen.getByText(/No vendor by that name|没有同名的服务商/)).toBeTruthy();
});
- it('prefills the official address and sends the catalog id with its pinned interface', async () => {
- const entry = preset('openai_chat');
- const observe = vi.spyOn(modelsApi, 'observeApiKeySource')
- .mockResolvedValueOnce(observed({ protocol: entry.protocol }));
- const create = vi.spyOn(modelsApi, 'createApiKeySource').mockResolvedValueOnce({
- source,
- added_to: [],
- adopted_by: [],
- });
- renderDialog();
- const user = userEvent.setup();
-
- await selectVendor(user, entry.id);
- expect(baseUrlInput().value).toBe(entry.official_base_url);
- await user.type(screen.getByLabelText(/^API key$/i), 'secret-key');
- await clickDetect(user);
- await clickConfirm(user);
-
- await waitFor(() => expect(create).toHaveBeenCalledOnce());
- expect(observe.mock.calls[0][0]).toMatchObject({ vendor: entry.id, protocol: entry.protocol });
- expect(create.mock.calls[0][0]).toMatchObject({ vendor: entry.id, protocol: entry.protocol });
- });
-
- it('states the pinned interface as a fact and offers no way to choose another', async () => {
- const entry = preset('anthropic');
- renderDialog();
- const user = userEvent.setup();
-
- await selectVendor(user, entry.id);
-
- const row = document.querySelector('.model-hub-add-key-protocol-idle-row');
- expect(row?.textContent).toMatch(/Anthropic Messages/);
- expect(row?.querySelector('.model-hub-add-key-protocol-glyph')).toBeTruthy();
- expect(row?.textContent).toMatch(/Built-in catalog/);
- expect(disclosure()).toBeNull();
- expect(screen.queryByRole('button', { name: 'OpenAI Responses' })).toBeNull();
- });
-
- it('puts the pin’s explanation under the interface it explains, not beside it', async () => {
- // The statement and the sentence about it are two lines: the hint is the
- // longer text, so beside the glyph it wrapped around the very name it is
- // about. Asserted structurally, because "on the next line" is a fact about
- // which element the hint is a child of, not about its text.
- const entry = preset('anthropic');
- renderDialog();
- const user = userEvent.setup();
-
- await selectVendor(user, entry.id);
-
- const row = document.querySelector('.model-hub-add-key-protocol-idle-row');
- const statement = row?.querySelector('.model-hub-add-key-protocol-idle-line');
- const hint = row?.querySelector('.model-hub-add-key-hint');
- expect(statement?.textContent).toMatch(/Anthropic Messages/);
- expect(statement?.textContent).toMatch(/Built-in catalog/);
- expect(hint?.textContent).toBe(i18n.t('settings.models.addKey.protocol.catalogPinned.hint'));
- // A sibling of the statement's line, not a child of it.
- expect(hint?.parentElement).toBe(row);
- expect(statement?.contains(hint ?? null)).toBe(false);
- });
-
- it('retires an observation taken under the previous vendor', async () => {
- const entry = preset('openai_chat');
- vi.spyOn(modelsApi, 'observeApiKeySource').mockResolvedValueOnce(observed());
- renderDialog();
- const user = await fillCredentials();
-
- await clickDetect(user);
- expect(await screen.findByRole('button', { name: CONFIRM })).toBeTruthy();
-
- await selectVendor(user, entry.id);
-
- expect(screen.queryByRole('button', { name: CONFIRM })).toBeNull();
- expect(screen.getByRole('button', { name: DETECT })).toBeTruthy();
- expect(baseUrlInput().value).toBe(entry.official_base_url);
- });
-
- it('keeps the pin when a preset is pointed at another address', async () => {
- const entry = preset('openai_chat');
- const observe = vi.spyOn(modelsApi, 'observeApiKeySource')
- .mockResolvedValueOnce(observed({ protocol: entry.protocol }));
- const create = vi.spyOn(modelsApi, 'createApiKeySource').mockResolvedValueOnce({
- source,
- added_to: [],
- adopted_by: [],
- });
- renderDialog();
- const user = userEvent.setup();
-
- await selectVendor(user, entry.id);
- await user.clear(baseUrlInput());
- await user.type(baseUrlInput(), 'https://relay.example/v1');
- await user.type(screen.getByLabelText(/^API key$/i), 'secret-key');
-
- // A gateway in front of a catalog vendor is still that vendor: the address
- // is the one thing the preset only proposes.
- expect(document.querySelector('.model-hub-add-key-protocol-idle-row')?.textContent)
- .toMatch(/Built-in catalog/);
- expect(disclosure()).toBeNull();
-
- await clickDetect(user);
- await clickConfirm(user);
-
- await waitFor(() => expect(create).toHaveBeenCalledOnce());
- expect(observe.mock.calls[0][0]).toMatchObject({
- vendor: entry.id,
- base_url: 'https://relay.example/v1',
- protocol: entry.protocol,
- });
- expect(create.mock.calls[0][0]).toMatchObject({
- vendor: entry.id,
- base_url: 'https://relay.example/v1',
- });
- });
-
- it('gives the address and the interface choice back on the way to 自定义', async () => {
- const entry = preset('openai_chat');
- renderDialog();
- const user = userEvent.setup();
-
- await selectVendor(user, entry.id);
- await selectVendor(user, 'custom');
-
- expect(baseUrlInput().value).toBe('');
- expect(disclosure()).not.toBeNull();
- });
});
diff --git a/ui/src/components/settings/models/AddApiKeyDialog.tsx b/ui/src/components/settings/models/AddApiKeyDialog.tsx
index 3e9c1ffca..385b769de 100644
--- a/ui/src/components/settings/models/AddApiKeyDialog.tsx
+++ b/ui/src/components/settings/models/AddApiKeyDialog.tsx
@@ -2,11 +2,9 @@ import * as React from 'react';
import * as DialogPrimitive from '@radix-ui/react-dialog';
import {
CheckCircle2,
- ChevronDown,
CircleX,
Eye,
EyeOff,
- Info,
LoaderCircle,
Save,
TriangleAlert,
@@ -22,11 +20,7 @@ import { API_KEY_VENDOR_PRESETS, apiKeyVendorPreset, CUSTOM_VENDOR } from './api
import { classifyModelHubFailure, type ModelHubFailureClass } from './asyncLifetime';
import { Field } from './dialogFields';
import {
- classifyObservation,
- isAbortError,
PROTOCOL_COPY_KEYS,
- type AddApiKeyFailure,
- type AddApiKeyOrigin,
} from './addApiKeyState';
import type { CollectionReadAuthority } from './collectionReadAuthority';
import { GuardImpact } from './GuardImpact';
@@ -48,7 +42,6 @@ import {
type ApiKeySourceCreate,
type RouteHopRef,
type Source,
- type SourceObservation,
type SourceProtocol,
type SupplyGap,
} from './types';
@@ -57,41 +50,13 @@ import { optionalTrimmedTextWithin } from './validation';
import { VendorGlyph } from './vendorGlyph';
type Phase =
- | { kind: 'form'; report: SourceObservation | null }
- | { kind: 'working'; origin: AddApiKeyOrigin; stage: 'observe' | 'persist' }
- | { kind: 'failure'; origin: AddApiKeyOrigin; cause: AddApiKeyFailure }
- | { kind: 'undetermined'; origin: AddApiKeyOrigin; observation: SourceObservation }
- | { kind: 'inventory'; origin: AddApiKeyOrigin; observation: SourceObservation }
- | {
- kind: 'persist_failure';
- messageKey: string | null;
- protocol: SourceProtocol | undefined;
- acceptUnavailableInventory: boolean;
- saveUnverified: boolean;
- }
- | {
- kind: 'save_unconfirmed';
- protocol: SourceProtocol | undefined;
- acceptUnavailableInventory: boolean;
- saveUnverified: boolean;
- };
+ | { kind: 'form' }
+ | { kind: 'working' }
+ | { kind: 'persist_failure'; messageKey: string | null }
+ | { kind: 'save_unconfirmed' };
-const INITIAL_PHASE: Phase = { kind: 'form', report: null };
-type ProtocolSelection = 'auto' | SourceProtocol;
-
-// A phase whose primary commits WITHOUT observing again is carrying evidence
-// that only this endpoint, this credential and this probe constraint produced:
-// ①″'s report, ⑤'s waived inventory, and the protocol a refused or unanswered
-// create already proved. That is the property, not a list of the states that
-// happen to be reachable today — a phase added later inherits the rule from how
-// its own exit behaves. Phases whose primary re-observes (③ / ④ / ⑤'s 重试, ⑥)
-// are deliberately absent: their retry reads the fields as they now stand, and
-// §0.8 keeps the form intact across it.
-const persistsWithoutObserving = (phase: Phase): boolean =>
- (phase.kind === 'form' && phase.report !== null)
- || phase.kind === 'inventory'
- || phase.kind === 'persist_failure'
- || phase.kind === 'save_unconfirmed';
+const INITIAL_PHASE: Phase = { kind: 'form' };
+type ProtocolSelection = SourceProtocol;
const ProtocolSegments: React.FC<{
id?: string;
@@ -107,7 +72,7 @@ const ProtocolSegments: React.FC<{
aria-label={t('settings.models.addKey.field.protocol')}
className="model-hub-add-key-segments flex max-w-full flex-wrap"
>
- {(['auto', ...SOURCE_PROTOCOLS] as const).map((item) => (
+ {SOURCE_PROTOCOLS.map((item) => (
<button
key={item}
type="button"
@@ -119,10 +84,8 @@ const ProtocolSegments: React.FC<{
)}
onClick={() => onSelect(item)}
>
- {item !== 'auto' && <ProtocolGlyph protocol={item} />}
- {t(item === 'auto'
- ? 'settings.models.addKey.protocol.auto'
- : PROTOCOL_COPY_KEYS[item])}
+ <ProtocolGlyph protocol={item} />
+ {t(PROTOCOL_COPY_KEYS[item])}
</button>
))}
</div>
@@ -200,32 +163,8 @@ const sourceClientNonce = (): string => {
return `scn_${Array.from(bytes, (value) => value.toString(16).padStart(2, '0')).join('')}`;
};
-const failureCopy = (cause: AddApiKeyFailure): string => {
- switch (cause) {
- case 'auth': return 'settings.models.addKey.fail.auth';
- case 'network': return 'settings.models.addKey.fail.network';
- case 'interface': return 'settings.models.addKey.fail.undetermined';
- case 'engineDown': return 'settings.models.addKey.fail.engineDown';
- case 'unclassified': return 'settings.models.addKey.fail.unclassified';
- }
-};
-
-const observationFailureCopy = (observation: SourceObservation | undefined): string | null => {
- if (!observation) return null;
- if (observation.outcome === 'authentication_failed') return 'settings.models.addKey.fail.auth';
- if (observation.outcome === 'unreachable' || observation.outcome === 'timeout') return 'settings.models.addKey.fail.network';
- if (observation.outcome === 'ambiguous') return 'settings.models.addKey.fail.undetermined';
- if (observation.outcome === 'observed' && observation.discovery === 'failed') return 'settings.models.addKey.fail.inventory';
- return 'settings.models.addKey.fail.unclassified';
-};
-
-const failureMessageKey = (failure: ReturnType<typeof apiFailure>): string | null => {
- if (!failure) return null;
- const observationKey = observationFailureCopy(failure.observation);
- if (observationKey) return observationKey;
- if (failure.detail?.startsWith('modelHub.errors.')) return failure.detail;
- return failure.code || null;
-};
+const failureMessageKey = (failure: ReturnType<typeof apiFailure>): string | null =>
+ failure?.detail ?? failure?.code ?? null;
const REPLACE_FAILURE_KEY: Record<ModelHubFailureClass, string> = {
'authoritative-terminal': 'settings.models.repair.replaceFailed',
@@ -293,15 +232,13 @@ export const AddApiKeyDialog: React.FC<AddApiKeyDialogProps> = (props) => {
const [displayName, setDisplayName] = React.useState('');
const [baseUrl, setBaseUrl] = React.useState('');
const [apiKey, setApiKey] = React.useState('');
- const [protocolSelection, setProtocolSelection] = React.useState<ProtocolSelection>('auto');
+ const [protocolSelection, setProtocolSelection] = React.useState<ProtocolSelection>('openai_chat');
const [revealed, setRevealed] = React.useState(false);
- const [manualOpen, setManualOpen] = React.useState(false);
const [phase, setPhase] = React.useState<Phase>(INITIAL_PHASE);
const [replacePhase, setReplacePhase] = React.useState<ReplacePhase>({ kind: 'edit' });
const [continuation] = React.useState(createContinuationSettlement);
const [createdDelivery] = React.useState(createSourceCreatedDelivery);
const clientNonce = React.useRef(sourceClientNonce());
- const observationAbort = React.useRef<AbortController | null>(null);
const replaceCloseTimer = React.useRef<number | null>(null);
React.useEffect(() => {
if (addOnAdded) createdDelivery.update(addOnAdded, onClose);
@@ -309,8 +246,6 @@ export const AddApiKeyDialog: React.FC<AddApiKeyDialogProps> = (props) => {
React.useEffect(() => {
continuation.invalidate();
- observationAbort.current?.abort();
- observationAbort.current = null;
if (replaceCloseTimer.current !== null) {
window.clearTimeout(replaceCloseTimer.current);
replaceCloseTimer.current = null;
@@ -321,13 +256,13 @@ export const AddApiKeyDialog: React.FC<AddApiKeyDialogProps> = (props) => {
setDisplayName('');
setBaseUrl('');
setApiKey('');
- setProtocolSelection('auto');
+ setProtocolSelection('openai_chat');
setRevealed(false);
- setManualOpen(false);
setPhase(INITIAL_PHASE);
setReplacePhase({ kind: 'edit' });
}
return () => {
+ continuation.invalidate();
if (replaceCloseTimer.current !== null) {
window.clearTimeout(replaceCloseTimer.current);
replaceCloseTimer.current = null;
@@ -361,109 +296,29 @@ export const AddApiKeyDialog: React.FC<AddApiKeyDialogProps> = (props) => {
if (settle) void settle().catch(() => undefined);
}, [continuation]);
- const draft = React.useCallback((
- protocol?: SourceProtocol,
- acceptUnavailableInventory = false,
- saveUnverified = false,
- ): ApiKeySourceCreate => ({
- kind: 'api_key',
- vendor,
- // The name is left out when empty rather than filled in here: the server
- // already names a catalog source after its catalog label, and a second
- // owner of that default is a second thing to keep in step with the catalog.
+ const draft = React.useCallback((): ApiKeySourceCreate => ({
+ kind: 'api_key', vendor,
...(displayName.trim() ? { display_name: displayName.trim() } : {}),
- base_url: baseUrl.trim(),
- key: apiKey.trim(),
- client_nonce: clientNonce.current,
- ...(protocol ? { protocol } : {}),
- ...(acceptUnavailableInventory ? { accept_unavailable_inventory: true } : {}),
- ...(saveUnverified ? { save_unverified: true } : {}),
- }), [apiKey, baseUrl, displayName, vendor]);
+ base_url: baseUrl.trim(), key: apiKey.trim(),
+ protocol: apiKeyVendorPreset(vendor)?.protocol ?? protocolSelection,
+ client_nonce: clientNonce.current, save_unverified: true,
+ }), [apiKey, baseUrl, displayName, protocolSelection, vendor]);
- const persist = React.useCallback(async (
- seq: ContinuationTicket,
- protocol?: SourceProtocol,
- acceptUnavailableInventory = false,
- saveUnverified = false,
- ) => {
- if (continuation.settle(seq, () => setPhase({ kind: 'working', origin: 'add', stage: 'persist' })) === 'stale') return;
+ const persist = React.useCallback(async (seq: ContinuationTicket) => {
+ if (continuation.settle(seq, () => setPhase({ kind: 'working' })) === 'stale') return;
try {
- const created = await modelsApi.createApiKeySource(draft(protocol, acceptUnavailableInventory, saveUnverified));
+ const created = await modelsApi.createApiKeySource(draft());
createdDelivery.settle(continuation, seq, created);
} catch (error) {
const failure = apiFailure(error);
- const definitiveClientFailure = failure?.serverNamed
- && failure.responseStatus !== undefined
- && failure.responseStatus >= 400
- && failure.responseStatus < 500
- && failure.responseStatus !== 409;
- const verdict = failure?.observation ? classifyObservation(failure.observation) : null;
- continuation.settle(seq, () => {
- if (definitiveClientFailure && verdict && verdict.kind !== 'ready') {
- if (verdict.kind === 'undetermined') {
- setPhase({ kind: 'undetermined', origin: 'add', observation: verdict.observation });
- } else if (verdict.kind === 'inventory') {
- setPhase({ kind: 'inventory', origin: 'add', observation: verdict.observation });
- } else {
- setPhase({ kind: 'failure', origin: 'add', cause: verdict.cause });
- }
- return;
- }
- setPhase(definitiveClientFailure
- ? {
- kind: 'persist_failure',
- messageKey: failureMessageKey(failure),
- protocol,
- acceptUnavailableInventory,
- saveUnverified,
- }
- : { kind: 'save_unconfirmed', protocol, acceptUnavailableInventory, saveUnverified });
- });
+ const definitive = failure?.serverNamed && failure.responseStatus !== undefined
+ && failure.responseStatus >= 400 && failure.responseStatus < 500 && failure.responseStatus !== 409;
+ continuation.settle(seq, () => setPhase(definitive
+ ? { kind: 'persist_failure', messageKey: failureMessageKey(failure) }
+ : { kind: 'save_unconfirmed' }));
}
}, [continuation, createdDelivery, draft]);
- const observe = React.useCallback(async (
- origin: AddApiKeyOrigin,
- protocol?: SourceProtocol,
- ) => {
- const seq = continuation.begin();
- observationAbort.current?.abort();
- const controller = new AbortController();
- observationAbort.current = controller;
- setPhase({ kind: 'working', origin, stage: 'observe' });
- try {
- const observation = await modelsApi.observeApiKeySource({
- vendor,
- base_url: baseUrl.trim(),
- key: apiKey.trim(),
- ...(protocol ? { protocol } : {}),
- }, controller.signal);
- const verdict = classifyObservation(observation);
- continuation.settle(seq, () => {
- observationAbort.current = null;
- if (verdict.kind === 'ready') {
- setPhase({ kind: 'form', report: observation });
- } else if (verdict.kind === 'undetermined') {
- setPhase({ kind: 'undetermined', origin, observation });
- } else if (verdict.kind === 'inventory') {
- setPhase({ kind: 'inventory', origin, observation });
- } else {
- setPhase({ kind: 'failure', origin, cause: verdict.cause });
- }
- });
- } catch (error) {
- if (isAbortError(error)) return;
- continuation.settle(seq, () => {
- observationAbort.current = null;
- setPhase({
- kind: 'failure',
- origin,
- cause: apiFailure(error)?.code === 'engine_down' ? 'engineDown' : 'unclassified',
- });
- });
- }
- }, [apiKey, baseUrl, continuation, vendor]);
-
const submitReplacement = React.useCallback(async (force: boolean) => {
if (props.mode !== 'replace' || !apiKey.trim() || replacePhase.kind === 'submitting') return;
const confirmation = force && replacePhase.kind === 'guard'
@@ -552,39 +407,14 @@ export const AddApiKeyDialog: React.FC<AddApiKeyDialogProps> = (props) => {
onClose();
return;
}
- if (phase.kind === 'working' && phase.stage === 'persist') return;
+ if (phase.kind === 'working') return;
continuation.invalidate();
- observationAbort.current?.abort();
- observationAbort.current = null;
- if (phase.kind === 'working' && phase.stage === 'observe') {
- setPhase(INITIAL_PHASE);
- return;
- }
createdDelivery.close();
}, [continuation, createdDelivery, onClose, phase, replaceMode, replacePhase.kind]);
- // What the next observation will be made under. A catalog vendor pins the
- // interface (ladder rung 1: the catalog row is the proof, so the response only
- // has to authenticate); 自定义 leaves it to the disclosure — a concrete choice
- // is a declaration (rung 3), and Auto sends nothing so the shape must prove it
- // (rung 2). Read by the handlers below and by the render, because "what 检测
- // will send" and "what the row says 检测 will send" must be one value.
const vendorPreset = apiKeyVendorPreset(vendor);
- const selectedProtocol = protocolSelection === 'auto' ? undefined : protocolSelection;
- const constrainedProtocol = vendorPreset?.protocol ?? selectedProtocol;
-
+ const constrainedProtocol = vendorPreset?.protocol ?? protocolSelection;
const retry = async () => {
- if (phase.kind === 'undetermined') {
- if (!constrainedProtocol) return;
- await observe(phase.origin, constrainedProtocol);
- return;
- }
- if (phase.kind === 'inventory') {
- // 2026-08-11 ruling: retry repeats the complete observation. There is no
- // inventory-only credential lifetime or server capability.
- await observe(phase.origin, phase.observation.protocol ?? undefined);
- return;
- }
if (phase.kind === 'save_unconfirmed') {
if (!addSourceReads) return;
const seq = continuation.begin();
@@ -601,108 +431,49 @@ export const AddApiKeyDialog: React.FC<AddApiKeyDialogProps> = (props) => {
return;
}
if (reconciliation.kind === 'absent') {
- await persist(seq, phase.protocol, phase.acceptUnavailableInventory, phase.saveUnverified);
+ await persist(seq);
}
return;
}
- if (phase.kind === 'persist_failure') {
- await persist(
- continuation.begin(),
- phase.protocol,
- phase.acceptUnavailableInventory,
- phase.saveUnverified,
- );
- return;
- }
- if (phase.kind === 'failure') {
- await observe(phase.origin, constrainedProtocol);
- }
+ if (phase.kind === 'persist_failure') await persist(continuation.begin());
};
- const addAnyway = async () => {
- if (phase.kind !== 'inventory' || !phase.observation.protocol) return;
- const seq = continuation.begin();
- await persist(seq, phase.observation.protocol, true);
- };
-
- // §0.8 ①″: editing Base URL, the API key, or the protocol selection returns
- // the dialog to ① Ready with the report dropped. The same three inputs are
- // what every persisting exit's evidence was proved against, so one retirement
- // covers the whole class instead of each handler picking its own phase.
- const retireProvedEvidence = () => {
- setPhase((current) => (persistsWithoutObserving(current) ? INITIAL_PHASE : current));
+ const clearSaveFailure = () => {
+ setPhase((current) => current.kind === 'persist_failure' ? INITIAL_PHASE : current);
};
const editEndpoint = (value: string) => {
setBaseUrl(value);
- retireProvedEvidence();
+ clearSaveFailure();
};
const editKey = (value: string) => {
setApiKey(value);
if (replaceMode && replacePhase.kind === 'failure') setReplacePhase({ kind: 'edit' });
- retireProvedEvidence();
+ clearSaveFailure();
};
- // The display name is in no observation, so it proves and unproves nothing —
- // ①″ keeps its report across a rename. It IS in the create request, so a
- // server-named refusal of that request stops describing the request the user
- // now holds.
const editDisplayName = (value: string) => {
setDisplayName(value);
if (phase.kind === 'persist_failure') setPhase(INITIAL_PHASE);
};
const editProtocol = (value: ProtocolSelection) => {
setProtocolSelection(value);
- retireProvedEvidence();
+ clearSaveFailure();
};
- // A vendor is not one more field of the same request. It changes the endpoint
- // AND the interface the request is made under, so anything observed before the
- // switch was observed against a different pair — including a report that
- // `retireProvedEvidence` would have kept, and an ④/failure the new vendor may
- // simply not have. §1.5: switching resets the URL to the new vendor's official
- // one, drops the interface selection, and retires the observation outright.
- // Picking the vendor that is already picked is not a switch, and everything
- // below is destructive: it would throw away a hand-edited address, a declared
- // interface, and a completed detection to arrive back where it started. The
- // guard is here rather than in the picker because this function is what
- // destroys that state — a caller that re-announces the same choice is not
- // wrong, acting on it is.
+ // Re-selecting the current vendor must preserve a hand-edited endpoint and
+ // protocol. A different vendor starts from that vendor's defaults.
const editVendor = (value: string) => {
if (value === vendor) return;
setVendor(value);
setBaseUrl(apiKeyVendorPreset(value)?.official_base_url ?? '');
- setProtocolSelection('auto');
- setManualOpen(false);
+ setProtocolSelection('openai_chat');
setPhase(INITIAL_PHASE);
};
const isWorking = phase.kind === 'working';
const formLocked = isWorking || phase.kind === 'save_unconfirmed';
- const canCancel = replaceMode
- ? replacePhase.kind !== 'submitting'
- : !(phase.kind === 'working' && phase.stage === 'persist');
+ const canCancel = replaceMode ? replacePhase.kind !== 'submitting' : !isWorking;
const displayNameValid = optionalTrimmedTextWithin(displayName, SOURCE_DISPLAY_NAME_MAX_LENGTH);
- const canObserve = Boolean(baseUrl.trim() && apiKey.trim()) && !formLocked;
- const canSubmit = canObserve && displayNameValid;
- const protocolIdle = !baseUrl.trim() || !apiKey.trim();
- const detecting = isWorking && phase.kind === 'working' && phase.stage === 'observe';
- const identified = phase.kind === 'form' && phase.report !== null && Boolean(phase.report.protocol);
- const identifiedProtocol = identified && phase.kind === 'form' ? phase.report?.protocol ?? null : null;
- // The segments and the summary row are two renderings of one selection, so
- // only one of them is on screen at a time: expanded, the pressed segment IS
- // the statement; collapsed, the row carries it. Under a catalog pin neither
- // the disclosure nor ④'s forced selector may open one: the interface is not
- // this dialog's to choose, so offering the choice would be offering a control
- // whose value the request then ignores.
- const segmentsOpen = !vendorPreset && (phase.kind === 'undetermined' || (manualOpen && !isWorking));
- // Why the interface is what it is, on every strip that states it. A catalog
- // pin and a user declaration are the two answers that are not "the response
- // proved it" — and Auto, which is that third answer, carries no badge.
- const protocolBadge = vendorPreset
- ? <span className="model-hub-add-key-protocol-badge">{t('settings.models.addKey.protocol.catalogPinned')}</span>
- : selectedProtocol
- ? <span className="model-hub-add-key-protocol-badge">{t('settings.models.addKey.protocol.declared')}</span>
- : null;
- const showForm = phase.kind !== 'inventory';
+ const canSubmit = Boolean(baseUrl.trim() && apiKey.trim()) && displayNameValid && !formLocked;
const replaceTerminalFailure = replacePhase.kind === 'failure'
&& replacePhase.failureClass === 'authoritative-terminal';
const replaceFieldLocked = replacePhase.kind === 'submitting'
@@ -713,7 +484,7 @@ export const AddApiKeyDialog: React.FC<AddApiKeyDialogProps> = (props) => {
<DialogPrimitive.Portal>
<DialogPrimitive.Overlay className="model-hub-add-key-overlay fixed inset-0 z-50" />
<DialogPrimitive.Content
- className="model-hub-add-key-dialog fixed left-1/2 top-1/2 z-50 flex max-h-[calc(100dvh-2rem)] -translate-x-1/2 -translate-y-1/2 flex-col gap-0 overflow-y-auto border border-border-strong bg-surface p-0 shadow-xl outline-none"
+ className="model-hub-add-key-dialog fixed left-1/2 top-1/2 z-50 flex max-h-[calc(100dvh-2rem)] -translate-x-1/2 -translate-y-1/2 flex-col gap-0 overflow-hidden border border-border-strong bg-surface p-0 shadow-xl outline-none"
onEscapeKeyDown={(event) => { if (!canCancel) event.preventDefault(); }}
onPointerDownOutside={(event) => { if (!canCancel) event.preventDefault(); }}
>
@@ -743,7 +514,7 @@ export const AddApiKeyDialog: React.FC<AddApiKeyDialogProps> = (props) => {
? replacePhase.kind === 'guard'
? t('settings.models.guard.subtitle.replaceKey')
: t('settings.models.repair.replaceBody')
- : t('settings.models.addKey.subtitle')}
+ : t('settings.models.addKey.saveFirstHint')}
</DialogPrimitive.Description>
</header>
@@ -803,7 +574,7 @@ export const AddApiKeyDialog: React.FC<AddApiKeyDialogProps> = (props) => {
</div>
)}
- {!replaceMode && showForm && (
+ {!replaceMode && (
<div className="model-hub-add-key-body flex flex-col">
{/* First, because it is the field the rest are conditioned on: it
decides what the Base URL starts as and whether the interface is
@@ -853,119 +624,21 @@ export const AddApiKeyDialog: React.FC<AddApiKeyDialogProps> = (props) => {
onToggleReveal={() => setRevealed((value) => !value)}
/>
- <div className={cn(
- 'model-hub-add-key-protocol-area',
- protocolIdle && !isWorking && phase.kind !== 'undetermined' && 'is-idle',
- )}>
+ <div className="model-hub-add-key-protocol-area">
<span className="model-hub-add-key-label">{t('settings.models.addKey.field.protocol')}</span>
- {phase.kind === 'undetermined' && (
- <div className="model-hub-add-key-strip model-hub-add-key-strip--advisory">
- <Info className="model-hub-ink-gold size-3.5 shrink-0" />
- <div className="flex min-w-0 flex-col gap-[3px]">
- <span className="model-hub-add-key-strip-title model-hub-ink-gold">{t('settings.models.addKey.undetermined.title')}</span>
- <span className="model-hub-add-key-strip-detail">{t('settings.models.addKey.undetermined.detail')}</span>
- </div>
- {protocolBadge}
- </div>
- )}
- {detecting && (
- <div className="model-hub-add-key-protocol-detecting">
- <LoaderCircle className="model-hub-ink-mint size-3.5 shrink-0 animate-spin" />
- <span>{t('settings.models.addKey.protocol.detecting')}</span>
- </div>
- )}
- {identified && identifiedProtocol && (
- <div className="model-hub-add-key-strip model-hub-add-key-strip--success">
- <CheckCircle2 className="model-hub-ink-mint size-3.5 shrink-0" />
- <ProtocolGlyph protocol={identifiedProtocol} />
- <span>
- {t(PROTOCOL_COPY_KEYS[identifiedProtocol])}
- {' · '}
- {phase.kind === 'form' && phase.report && phase.report.models.length === 0
- ? t('settings.models.addKey.pull.empty')
- : t('settings.models.addKey.pull.result', {
- count: phase.kind === 'form' && phase.report ? phase.report.models.length : 0,
- })}
- </span>
- {protocolBadge}
- </div>
- )}
- {phase.kind === 'form' && !phase.report && !segmentsOpen && (
+ {vendorPreset ? (
<div className="model-hub-add-key-protocol-idle-row">
- {/* The statement and its badge are one line; the sentence that
- explains them is the next. Beside the glyph the hint read as
- a second statement competing with the first, and it is the
- longer of the two — it wrapped around the name it belongs
- to. Underneath, at its own smaller scale, it is plainly
- subordinate to the line above. */}
- <div className="model-hub-add-key-protocol-idle-line">
- {/* Whatever 检测 is about to send, and nothing else: a catalog
- pin and a concrete choice are each the active constraint
- even while the disclosure that could have made one is shut
- — or, under a pin, is not offered at all. */}
- <span className="model-hub-add-key-protocol-active">
- {constrainedProtocol && <ProtocolGlyph protocol={constrainedProtocol} />}
- {t(constrainedProtocol
- ? PROTOCOL_COPY_KEYS[constrainedProtocol]
- : 'settings.models.addKey.protocol.auto')}
- </span>
- {/* The pin is the reason this row has no control beside it, so
- it says so here rather than only on the strip 检测 returns. */}
- {vendorPreset && protocolBadge}
- </div>
- {/* The idle hint promises automatic identification, which is
- only what Auto does. A named interface has already answered
- it; a pin answers a different question — what 检测 still has
- to establish once the interface is no longer in doubt. */}
- {vendorPreset ? (
- <span className="model-hub-add-key-hint">{t('settings.models.addKey.protocol.catalogPinned.hint')}</span>
- ) : !selectedProtocol && (
- <span className="model-hub-add-key-hint">{t('settings.models.addKey.protocol.idleHint')}</span>
- )}
- </div>
- )}
- {segmentsOpen && (
- <div className="model-hub-add-key-protocol-manual">
- <ProtocolSegments
- disabled={formLocked}
- selection={protocolSelection}
- onSelect={editProtocol}
- />
- <p className="model-hub-add-key-hint">{t('settings.models.addKey.field.protocol.hint')}</p>
+ <span className="model-hub-add-key-protocol-active">
+ <ProtocolGlyph protocol={constrainedProtocol} />{t(PROTOCOL_COPY_KEYS[constrainedProtocol])}
+ </span>
</div>
- )}
- {!vendorPreset && !isWorking && phase.kind !== 'undetermined' && (
- <button
- type="button"
- className="model-hub-add-key-protocol-disclosure"
- aria-expanded={manualOpen}
- onClick={() => setManualOpen((open) => !open)}
- >
- <ChevronDown className={cn('size-3.5 shrink-0', manualOpen && 'rotate-180')} />
- {t('settings.models.addKey.protocol.manual')}
- </button>
- )}
+ ) : <ProtocolSegments disabled={formLocked} selection={protocolSelection} onSelect={editProtocol} />}
+ <p className="model-hub-add-key-hint">{t('settings.models.addKey.protocol.saveFirstHint')}</p>
</div>
-
- {phase.kind === 'working' && phase.stage === 'persist' && (
- <div className="model-hub-add-key-strip model-hub-add-key-strip--working">
- <LoaderCircle className="model-hub-ink-mint size-3.5 shrink-0 animate-spin" />
- <div className="flex min-w-0 flex-col gap-[3px]">
- <span className="model-hub-add-key-strip-title text-foreground">{t('settings.models.addKey.saving')}</span>
- <span className="model-hub-add-key-strip-detail">{t('settings.models.addKey.saving.detail')}</span>
- </div>
- </div>
- )}
- {phase.kind === 'failure' && (
- <div className="model-hub-add-key-strip model-hub-add-key-strip--error">
- <CircleX className="model-hub-add-key-error-ink size-3.5 shrink-0" />
- <div className="flex min-w-0 flex-col gap-[3px]">
- <span className="model-hub-add-key-error-ink model-hub-add-key-strip-title">{t(failureCopy(phase.cause))}</span>
- {phase.cause === 'auth' && <span className="model-hub-add-key-strip-detail">{t('settings.models.addKey.fail.auth.detail')}</span>}
- {phase.cause !== 'engineDown' && <span className="model-hub-add-key-strip-detail">{t('settings.models.addKey.fail.subtitle')}</span>}
- </div>
- </div>
- )}
+ {isWorking && <div className="model-hub-add-key-strip model-hub-add-key-strip--working">
+ <LoaderCircle className="model-hub-ink-mint size-3.5 animate-spin" />
+ <span className="model-hub-add-key-strip-title">{t('settings.models.addKey.saving')}</span>
+ </div>}
{phase.kind === 'save_unconfirmed' && (
<div className="model-hub-add-key-strip model-hub-add-key-strip--error">
<CircleX className="model-hub-add-key-error-ink size-3.5 shrink-0" />
@@ -984,15 +657,6 @@ export const AddApiKeyDialog: React.FC<AddApiKeyDialogProps> = (props) => {
</div>
)}
- {!replaceMode && phase.kind === 'inventory' && (
- <div className="model-hub-add-key-outcome-wrap">
- <div className="model-hub-add-key-strip model-hub-add-key-strip--advisory model-hub-add-key-strip--inventory">
- <TriangleAlert className="model-hub-ink-gold size-3.5 shrink-0" />
- <span className="model-hub-add-key-strip-title model-hub-ink-gold">{t('settings.models.addKey.inventory.title')}</span>
- </div>
- </div>
- )}
-
<footer className="model-hub-add-key-foot model-hub-fill-05 flex flex-row flex-wrap items-center justify-end border-t border-border">
{replaceMode ? (
<>
@@ -1039,68 +703,14 @@ export const AddApiKeyDialog: React.FC<AddApiKeyDialogProps> = (props) => {
>
{t('settings.models.addKey.cancel')}
</Button>
- {phase.kind === 'inventory' && (
- <Button type="button" variant="outline" className="model-hub-add-key-action" onClick={() => void addAnyway()}>
- {t('settings.models.addKey.addAnyway')}
- </Button>
- )}
- {constrainedProtocol && (phase.kind === 'undetermined' || phase.kind === 'failure' || (phase.kind === 'form' && !phase.report)) && (
- <Button
- type="button"
- variant="outline"
- className="model-hub-add-key-action"
- disabled={!canSubmit}
- onClick={() => void persist(continuation.begin(), constrainedProtocol, false, true)}
- >
- <Save className="size-3 shrink-0" />
- {t('settings.models.addKey.saveUnverified')}
- </Button>
- )}
- {phase.kind === 'form' && !phase.report && (
- <Button
- type="button"
- variant="brand"
- className="model-hub-add-key-action"
- disabled={!canSubmit}
- onClick={() => void observe('add', constrainedProtocol)}
- >
- {t('settings.models.addKey.detect')}
- </Button>
- )}
- {phase.kind === 'form' && phase.report?.protocol && (
- <Button
- type="button"
- variant="brand"
- className="model-hub-add-key-action"
- disabled={!canSubmit}
- onClick={() => void persist(continuation.begin(), phase.report?.protocol ?? undefined)}
- >
- {t('settings.models.addKey.confirm')}
- </Button>
- )}
- {phase.kind === 'working' && (
- <Button type="button" variant="brand" className="model-hub-add-key-action" disabled>
- <LoaderCircle className="size-3 animate-spin" />
- {t(phase.stage === 'persist'
- ? 'settings.models.addKey.saving'
- : 'settings.models.addKey.protocol.detecting')}
- </Button>
- )}
- {(phase.kind === 'failure' || phase.kind === 'persist_failure' || phase.kind === 'save_unconfirmed' || phase.kind === 'inventory' || phase.kind === 'undetermined') && (
- <Button
- type="button"
- variant="brand"
- className={cn(
- 'model-hub-add-key-action',
- (phase.kind === 'inventory' || phase.kind === 'save_unconfirmed' || (phase.kind === 'undetermined' && !constrainedProtocol))
- && 'model-hub-add-key-action--dim',
- )}
- disabled={phase.kind === 'undetermined' && !constrainedProtocol}
- onClick={() => void retry()}
- >
- {t('settings.models.addKey.retry')}
- </Button>
- )}
+ <Button type="button" variant="brand" className="model-hub-add-key-action"
+ disabled={isWorking || (phase.kind !== 'save_unconfirmed' && !canSubmit)}
+ onClick={() => void (phase.kind === 'save_unconfirmed' || phase.kind === 'persist_failure'
+ ? retry() : persist(continuation.begin()))}>
+ {isWorking ? <LoaderCircle className="size-3 animate-spin" /> : <Save className="size-3" />}
+ {t(isWorking ? 'settings.models.addKey.saving'
+ : phase.kind === 'form' ? 'settings.models.addKey.confirm' : 'settings.models.addKey.retry')}
+ </Button>
</>
)}
</footer>
diff --git a/ui/src/components/settings/models/SettingsModelsPage.render.test.tsx b/ui/src/components/settings/models/SettingsModelsPage.render.test.tsx
index e477078d3..51d52ae57 100644
--- a/ui/src/components/settings/models/SettingsModelsPage.render.test.tsx
+++ b/ui/src/components/settings/models/SettingsModelsPage.render.test.tsx
@@ -329,8 +329,7 @@ describe('SettingsModelsPage surface branches', () => {
await user.click(trigger);
await user.type(screen.getByRole('textbox', { name: /^Base URL$/i }), 'https://relay.example/v1');
await user.type(screen.getByLabelText(/^API key$/i), 'secret-key');
- await user.click(screen.getByRole('button', { name: /^Detect$|^检测$/ }));
- await user.click(await screen.findByRole('button', { name: /Confirm & add|确认添加/ }));
+ await user.click(await screen.findByRole('button', { name: /Add provider|添加供应商/ }));
const detail = await screen.findByRole('dialog', { name: 'Created API key' });
await user.click(within(detail).getByRole('button', { name: /Close provider details|关闭供应商详情/i }));
@@ -613,6 +612,7 @@ describe('SettingsModelsPage surface branches', () => {
const sourceOpener = (await screen.findByText('Retained source')).closest('button') as HTMLButtonElement;
await user.click(sourceOpener);
const sourceDialog = await screen.findByRole('dialog', { name: 'Retained source' });
+ await user.click(within(sourceDialog).getByRole('button', { name: /Advanced settings|高级设置/ }));
await user.click(within(sourceDialog).getByRole('button', { name: /high/i }));
const tierInput = within(sourceDialog).getByPlaceholderText(/Enter to add|回车添加/i);
await user.type(tierInput, 'draft');
diff --git a/ui/src/components/settings/models/SourceDetailPanel.test.tsx b/ui/src/components/settings/models/SourceDetailPanel.test.tsx
index 70fb9ea82..a9bc5fbf2 100644
--- a/ui/src/components/settings/models/SourceDetailPanel.test.tsx
+++ b/ui/src/components/settings/models/SourceDetailPanel.test.tsx
@@ -2,7 +2,7 @@
import { readFileSync } from 'node:fs';
import { join } from 'node:path';
import * as React from 'react';
-import { cleanup, render, screen, waitFor, within } from '@testing-library/react';
+import { cleanup, fireEvent, render as renderRaw, screen, waitFor, within } from '@testing-library/react';
import userEvent from '@testing-library/user-event';
import { I18nextProvider } from 'react-i18next';
import { afterEach, describe, expect, it, vi } from 'vitest';
@@ -34,6 +34,15 @@ import {
import type { Source, SourceDetailKey, SourceKind, SourceProtocol, SupplyChannel } from './types';
import { useSourceMutationReport } from './useSourceMutationReport';
+// Existing tier/editor invariants exercise the explicit advanced surface.
+// Default inventory behavior is tested separately with renderRaw below.
+const render = (ui: React.ReactNode) => {
+ const view = renderRaw(ui);
+ const advanced = screen.queryByRole('button', { name: /Advanced settings|高级设置/ });
+ if (advanced) fireEvent.click(advanced);
+ return view;
+};
+
const source: Source = {
id: 'src_detail',
last_discovered_at: '2026-08-11T08:00:00Z',
@@ -189,7 +198,7 @@ const chipTiers = () => Array.from(document.querySelectorAll('.model-hub-source-
*/
const MANAGED_BADGE: Readonly<Record<ManagedTierSource, RegExp>> = {
upstream: /^From provider$|^供应商声明$/,
- catalog: /^Built-in catalog$|^内置目录$/,
+ catalog: /^Avibe preset levels$|^Avibe 预置档位$/,
};
const EchoPanel: React.FC<{
@@ -245,6 +254,44 @@ afterEach(() => {
});
describe('SourceDetailPanel', () => {
+ it('keeps capability details out of the default inventory without removing advanced controls', async () => {
+ renderRaw(<I18nextProvider i18n={i18n}><ReportOwnedPanel source={source} trackMutation={immediateTrack} onReauth={noReauth} /></I18nextProvider>);
+ expect(screen.queryByRole('button', { name: /high/i })).toBeNull();
+ await userEvent.click(screen.getByRole('button', { name: /Advanced settings|高级设置/ }));
+ expect(screen.getByRole('button', { name: /high/i })).toBeTruthy();
+ });
+
+ it('never presents a manual model write as an upstream refetch', async () => {
+ const pending = new Promise<Source>(() => {});
+ const add = vi.spyOn(modelsApi, 'addCustomModel').mockReturnValue(pending);
+ const refetch = vi.spyOn(modelsApi, 'refreshSource');
+ renderRaw(<I18nextProvider i18n={i18n}><ReportOwnedPanel source={source} trackMutation={immediateTrack} onReauth={noReauth} /></I18nextProvider>);
+ const user = userEvent.setup();
+ await user.click(screen.getByRole('button', { name: /Add model|添加模型/ }));
+ await user.type(screen.getByPlaceholderText(/Model ID|模型 ID/), 'manual-model');
+ await user.click(screen.getAllByRole('button', { name: /Add model|添加模型/ }).at(-1)!);
+ expect(add).toHaveBeenCalledOnce();
+ expect(refetch).not.toHaveBeenCalled();
+ const button = screen.getByRole('button', { name: /^Refetch$|^重新拉取$/i });
+ expect(button.getAttribute('aria-busy')).toBe('false');
+ expect(button.querySelector('.animate-spin')).toBeNull();
+ });
+
+ it('shows refetch progress only on refetch while a manual draft is open', async () => {
+ vi.spyOn(modelsApi, 'refreshSource').mockReturnValue(new Promise(() => {}));
+ const add = vi.spyOn(modelsApi, 'addCustomModel');
+ renderRaw(<I18nextProvider i18n={i18n}><ReportOwnedPanel source={source} trackMutation={immediateTrack} onReauth={noReauth} /></I18nextProvider>);
+ await userEvent.click(screen.getByRole('button', { name: /Add model|添加模型/ }));
+ const refetch = screen.getByRole('button', { name: /^Refetch$|^重新拉取$/i });
+ await userEvent.click(refetch);
+ expect(refetch.getAttribute('aria-busy')).toBe('true');
+ expect(refetch.querySelector('.animate-spin')).toBeTruthy();
+ for (const button of screen.getAllByRole('button', { name: /Add model|添加模型/ })) {
+ expect(button.querySelector('.animate-spin')).toBeNull();
+ }
+ expect(add).not.toHaveBeenCalled();
+ });
+
it('exposes a stable, programmatically focusable heading for committed navigation', () => {
const headingRef = React.createRef<HTMLHeadingElement>();
render(
@@ -1232,7 +1279,7 @@ describe('SourceDetailPanel', () => {
]);
expect(screen.getByText(lng === 'en' ? 'From provider' : '供应商声明')).toBeTruthy();
- expect(screen.getByText(lng === 'en' ? 'Built-in catalog' : '内置目录')).toBeTruthy();
+ expect(screen.getByText(lng === 'en' ? 'Avibe preset levels' : 'Avibe 预置档位')).toBeTruthy();
await userEvent.click(screen.getByRole('button', { name: /high/i }));
await userEvent.type(screen.getByPlaceholderText(/Enter to add|回车添加/i), 'low{Enter}');
diff --git a/ui/src/components/settings/models/SourceDetailPanel.tsx b/ui/src/components/settings/models/SourceDetailPanel.tsx
index 368addbc5..3b9c10c8f 100644
--- a/ui/src/components/settings/models/SourceDetailPanel.tsx
+++ b/ui/src/components/settings/models/SourceDetailPanel.tsx
@@ -1,6 +1,6 @@
import * as React from 'react';
import * as DialogPrimitive from '@radix-ui/react-dialog';
-import { Info, Loader2, LogIn, MoreHorizontal, Pencil, Plus, RefreshCw, Search, Trash2, X } from 'lucide-react';
+import { FlaskConical, Info, Loader2, LogIn, MoreHorizontal, Pencil, Plus, RefreshCw, Search, Settings2, Trash2, X } from 'lucide-react';
import { useTranslation } from 'react-i18next';
import { Button } from '@/components/ui/button';
@@ -57,6 +57,7 @@ import {
} from './tierMutation';
import { TIER_SUGGESTIONS } from './tierSuggestions';
import { useDeadlineClock } from './useDeadlineClock';
+import { SourceTestDialog } from './SourceTestDialog';
import { ACCENT_ICON, ACCENT_TILE, sourceVisual } from './vendorMeta';
import type {
AgentBackend,
@@ -450,7 +451,11 @@ export const SourceDetailPanel: React.FC<{
const { t, i18n } = useTranslation();
const now = useDeadlineClock(source.state.status === 'cooldown' ? source.state.retry_at : null);
const { Icon, accent } = sourceVisual(source);
- const [busy, setBusy] = React.useState(false);
+ const [pendingAction, setPendingAction] = React.useState<'refetch' | 'add_model' | 'other' | null>(null);
+ const busy = pendingAction !== null;
+ const refetching = pendingAction === 'refetch';
+ const [testing, setTesting] = React.useState(false);
+ const [advanced, setAdvanced] = React.useState(false);
const [confirmingReauth, setConfirmingReauth] = React.useState(false);
const [replacingKey, setReplacingKey] = React.useState(false);
const [manageStage, dispatchManageStage] = React.useReducer(transitionManageStage, { kind: 'idle' });
@@ -491,7 +496,7 @@ export const SourceDetailPanel: React.FC<{
if (busy) return Promise.resolve();
setResult(null);
setRefetchFailed(false);
- setBusy(true);
+ setPendingAction('refetch');
return trackMutation(async (latest, settlement) => {
const before = new Set(latest.models.map((model) => model.id));
try {
@@ -522,7 +527,7 @@ export const SourceDetailPanel: React.FC<{
}
}
}
- }).finally(() => setBusy(false));
+ }).finally(() => setPendingAction(null));
};
const reconcileManualCreate = async (sourceId: string, modelId: string, settlement: SourceMutationSettlement) => reconcileUnknownWrite(
settlement.readInventory,
@@ -550,7 +555,7 @@ export const SourceDetailPanel: React.FC<{
if (!modelId) return;
setResult(null);
setRefetchFailed(false);
- setBusy(true);
+ setPendingAction('add_model');
return trackMutation(async (latest, settlement) => {
if (latest.models.some((model) => model.id === modelId)) {
setManualDraft(null);
@@ -599,7 +604,7 @@ export const SourceDetailPanel: React.FC<{
}
}
}
- }).finally(() => setBusy(false));
+ }).finally(() => setPendingAction(null));
};
const reconcileRemoval = async (sourceId: string, model: SuppliedModel, settlement: SourceMutationSettlement) => {
const reconciliation = await reconcileUnknownWrite(
@@ -626,7 +631,7 @@ export const SourceDetailPanel: React.FC<{
setResult(null);
setRefetchFailed(false);
setRemoveFailure(null);
- setBusy(true);
+ setPendingAction('other');
return trackMutation(async (latest, settlement) => {
if (!latest.models.some((candidate) => candidate.id === model.id)) {
setGuard(null);
@@ -647,7 +652,7 @@ export const SourceDetailPanel: React.FC<{
} else await reconcileRemoval(latest.id, model, settlement);
}
}
- }).finally(() => setBusy(false));
+ }).finally(() => setPendingAction(null));
};
const commitManagementMutation = async (
action: ManageCommitAction,
@@ -740,7 +745,7 @@ export const SourceDetailPanel: React.FC<{
plan,
surface: forced ? 'guard' : 'edit',
});
- setBusy(true);
+ setPendingAction('other');
return trackMutation(async (latest, settlement) => {
try {
const answer = await modelsApi.patchSource(
@@ -782,13 +787,13 @@ export const SourceDetailPanel: React.FC<{
}
}
}
- }).finally(() => setBusy(false));
+ }).finally(() => setPendingAction(null));
};
const submitDelete = (plan: ManageGuardPlan | null) => {
if (busy) return Promise.resolve();
const forced = plan !== null;
dispatchManageStage({ type: 'submit_delete', plan });
- setBusy(true);
+ setPendingAction('other');
return trackMutation(async (latest, settlement) => {
try {
const answer = await modelsApi.deleteSource(
@@ -822,12 +827,12 @@ export const SourceDetailPanel: React.FC<{
}
}
}
- }).finally(() => setBusy(false));
+ }).finally(() => setPendingAction(null));
};
const retryEditRead = (failed: Extract<ManageStage, { kind: 'edit_failed' }>) => {
if (busy) return Promise.resolve();
dispatchManageStage({ type: 'retry' });
- setBusy(true);
+ setPendingAction('other');
return trackMutation(async (_latest, settlement) => {
await reconcileEditWrite(
failed.before,
@@ -836,15 +841,15 @@ export const SourceDetailPanel: React.FC<{
failed.plan,
settlement,
);
- }).finally(() => setBusy(false));
+ }).finally(() => setPendingAction(null));
};
const retryDeleteRead = (failed: Extract<ManageStage, { kind: 'delete_failed' }>) => {
if (busy) return Promise.resolve();
dispatchManageStage({ type: 'retry' });
- setBusy(true);
+ setPendingAction('other');
return trackMutation(async (_latest, settlement) => {
await reconcileDeleteWrite(failed.before, failed.plan, settlement);
- }).finally(() => setBusy(false));
+ }).finally(() => setPendingAction(null));
};
const submitEditDialog = () => {
if (!editDraft || !editAssessment.valid || !editAssessment.patch) return;
@@ -930,7 +935,7 @@ export const SourceDetailPanel: React.FC<{
: t('settings.models.gateway.modelCount', { count: source.models.length });
return (
- <div className="model-hub-source-detail">
+ <div className="model-hub-source-detail" data-advanced={advanced}>
<section className="model-hub-source-bar flex shrink-0 items-center border-b border-border bg-surface">
<span className={cn('model-hub-source-tile flex shrink-0 items-center justify-center', ACCENT_TILE[accent])}><Icon className={cn('size-[18px]', ACCENT_ICON[accent])} /></span>
<div className="model-hub-source-copy flex min-w-0 flex-1 flex-col">
@@ -963,21 +968,26 @@ export const SourceDetailPanel: React.FC<{
<div className="flex shrink-0 items-center gap-2">
{repairDestination === 'reauth_dialog' && <Button size="xs" className="model-hub-source-action" data-repair-kind={repair} data-repair-destination={repairDestination} disabled={busy} onClick={() => setConfirmingReauth(true)}><LogIn />{t(REPAIR_LABEL_KEY.reauth)}</Button>}
{repairDestination === 'replace_key_dialog' && <Button size="xs" className="model-hub-source-action" data-repair-kind={repair} data-repair-destination={repairDestination} disabled={busy} onClick={() => setReplacingKey(true)}>{t(REPAIR_LABEL_KEY.replace_key)}</Button>}
- {source.supply_channel === 'hub' && <Button variant="outline" size="xs" className="model-hub-source-action" data-repair-kind={repairDestination === 'refetch_button' ? repair : undefined} data-repair-destination={repairDestination === 'refetch_button' ? repairDestination : undefined} disabled={busy} onClick={() => void refetch()}>{busy ? <Loader2 className="animate-spin" /> : <RefreshCw />}{t('settings.models.sourceDetail.action.refetch')}</Button>}
+ {source.supply_channel === 'hub' && <Button variant="outline" size="xs" className="model-hub-source-action" data-repair-kind={repairDestination === 'refetch_button' ? repair : undefined} data-repair-destination={repairDestination === 'refetch_button' ? repairDestination : undefined} disabled={busy} onClick={() => void refetch()} aria-busy={refetching}>{refetching ? <Loader2 className="animate-spin" /> : <RefreshCw />}{t('settings.models.sourceDetail.action.refetch')}</Button>}
+ {source.kind === 'api_key' && source.supply_channel === 'hub' && <Button variant="outline" size="xs" className="model-hub-source-action" disabled={busy} onClick={() => setTesting(true)}><FlaskConical />{t('settings.models.sourceTest.open')}</Button>}
+ <Button variant="ghost" size="xs" className="model-hub-source-action" aria-expanded={advanced}
+ disabled={busy} onClick={() => { setAdvanced((value) => !value); setEditingTiers(null); }}>
+ <Settings2 />{t('settings.models.sourceDetail.advanced')}
+ </Button>
{source.kind === 'api_key' && <Button size="xs" className="model-hub-source-action" disabled={busy || manualDraft !== null} onClick={() => setManualDraft({ modelId: '', tiers: [], failed: false, retryRead: false })}><Plus />{t('settings.models.sourceDetail.action.addModel')}</Button>}
<SourceManageMenu source={source} busy={busy || manageStage.kind !== 'idle'} onEdit={beginEdit} onDelete={beginDelete} />
</div>
</section>
<section className="model-hub-source-table flex min-h-0 flex-1 flex-col overflow-hidden bg-surface">
<div className="model-hub-source-table-head hidden border-b border-border font-semibold md:grid">
- <span className="truncate">{t('settings.models.sourceDetail.col.id')}</span><span className="flex min-w-0 items-center gap-1"><span className="truncate">{t('settings.models.sourceDetail.col.tiers')}</span><Info className="model-hub-ink-59 size-[13px] shrink-0" /></span><span />
+ <span className="truncate">{t('settings.models.sourceDetail.col.id')}</span>{advanced && <span className="flex min-w-0 items-center gap-1"><span className="truncate">{t('settings.models.sourceDetail.col.tiers')}</span><Info className="model-hub-ink-59 size-[13px] shrink-0" /></span>}<span />
</div>
<div className="model-hub-source-table-scroll min-h-0 flex-1 overflow-y-auto">
{filteredModels.length === 0 && !manualDraft && <p className="px-5 py-12 text-center text-[12px] text-muted">{t(normalizedQuery ? 'settings.models.sourceDetail.searchEmpty' : source.last_discovered_at ? 'settings.models.sourceDetail.empty' : 'settings.models.sourceDetail.emptyNeverFetched')}</p>}
{models.map((model) => (
<div key={model.id} hidden={!visibleModelIds.has(model.id)} className="model-hub-source-table-row grid gap-3 border-b border-border last:border-b-0 md:items-center md:gap-y-0">
<span className="flex min-w-0 items-center gap-2"><span className="model-hub-source-model truncate font-mono text-foreground" title={model.id}>{model.id}</span>{model.origin !== 'discovered' && <span className="model-hub-source-pill model-hub-source-entry-pill model-hub-source-entry-pill--manual w-fit rounded-full border font-semibold">{t('settings.models.sourceDetail.entry.manual')}</span>}{result?.added.includes(model.id) && <span className="model-hub-accent-pill--mint model-hub-source-pill rounded-full border px-2 py-0.5 font-semibold">{t('settings.models.sourceDetail.refetch.added')}</span>}</span>
- <TierEditor
+ {advanced && <TierEditor
model={model}
protocol={source.protocol}
editing={editingTiers === model.id}
@@ -988,21 +998,21 @@ export const SourceDetailPanel: React.FC<{
onClose={() => setEditingTiers((current) => (current === model.id ? null : current))}
onMutating={() => { setResult(null); setRefetchFailed(false); }}
trackMutation={trackMutation}
- />
+ />}
<div className="model-hub-source-row-actions flex items-center justify-end gap-1">
{removeFailure?.modelId === model.id && <span className="model-hub-source-tier text-right text-destructive-ink">{t('settings.models.sourceDetail.fail.removeModel')} <button type="button" disabled={busy} onClick={() => {
if (!removeFailure.retryRead) void remove(model);
else {
- setBusy(true);
+ setPendingAction('other');
void trackMutation(async (latest, settlement) => reconcileRemoval(latest.id, model, settlement))
- .finally(() => setBusy(false));
+ .finally(() => setPendingAction(null));
}
}} className="font-semibold underline underline-offset-2">{t('settings.models.sourceDetail.retry')}</button></span>}
{/* The pencil is a second door into the same tier editor, so a locked
row has to close it too — a manual entry whose id matches a
catalog model is locked exactly like a discovered one. Removing
the model itself is a different question and stays offered. */}
- {model.origin === 'manual' && <>{!managedTierSource(model.reasoning_efforts_source) && <button type="button" disabled={busy} aria-label={t('settings.models.sourceDetail.row.edit', { model: model.id }) as string} title={t('settings.models.sourceDetail.row.edit', { model: model.id }) as string} className="model-hub-source-row-action grid place-items-center text-muted hover:bg-surface-2 hover:text-foreground" onClick={() => setEditingTiers(model.id)}><Pencil className="size-3.5" /></button>}<ManualModelMenu model={model} busy={busy} onRemove={() => void remove(model)} /></>}
+ {model.origin === 'manual' && <>{advanced && !managedTierSource(model.reasoning_efforts_source) && <button type="button" disabled={busy} aria-label={t('settings.models.sourceDetail.row.edit', { model: model.id }) as string} title={t('settings.models.sourceDetail.row.edit', { model: model.id }) as string} className="model-hub-source-row-action grid place-items-center text-muted hover:bg-surface-2 hover:text-foreground" onClick={() => setEditingTiers(model.id)}><Pencil className="size-3.5" /></button>}<ManualModelMenu model={model} busy={busy} onRemove={() => void remove(model)} /></>}
</div>
</div>
))}
@@ -1024,16 +1034,17 @@ export const SourceDetailPanel: React.FC<{
placeholder={t('settings.models.sourceDetail.col.id') as string}
className="model-hub-source-manual-id model-hub-source-model h-8 min-w-0 font-mono"
/><span className="model-hub-source-pill model-hub-source-entry-pill model-hub-source-entry-pill--manual w-fit rounded-full border font-semibold">{t('settings.models.sourceDetail.entry.manual')}</span></span>
- <DraftTiers tiers={manualDraft.tiers} onChange={(tiers) => setManualDraft((current) => current ? { ...current, tiers, failed: false, retryRead: false } : current)} />
+ {advanced && <DraftTiers tiers={manualDraft.tiers} onChange={(tiers) => setManualDraft((current) => current ? { ...current, tiers, failed: false, retryRead: false } : current)} />}
<div className="flex justify-end gap-2">
<Button variant="ghost" size="xs" disabled={busy} onClick={() => setManualDraft(null)}>{t('common.cancel')}</Button>
- <Button size="xs" disabled={busy || !manualDraft.modelId.trim() || source.models.some((model) => model.id === manualDraft.modelId.trim())} onClick={() => void addManualModel()}>{manualDraft.failed ? t('settings.models.sourceDetail.retry') : t('settings.models.sourceDetail.action.addModel')}</Button>
+ <Button size="xs" disabled={busy || !manualDraft.modelId.trim() || source.models.some((model) => model.id === manualDraft.modelId.trim())} onClick={() => void addManualModel()}>{pendingAction === 'add_model' && <Loader2 className="animate-spin" />}{manualDraft.failed ? t('settings.models.sourceDetail.retry') : t('settings.models.sourceDetail.action.addModel')}</Button>
</div>
{manualDraft.failed && <p className="model-hub-source-draft-line text-[11px] text-destructive-ink">{t('settings.models.sourceDetail.fail.addModel')}</p>}
</div>
)}
</div>
</section>
+ {testing && <SourceTestDialog key={source.id} source={source} trackMutation={trackMutation} onClose={() => setTesting(false)} />}
{/* Confirmed before the journey opens, not inside it: `OAuthConnectDialog`
POSTs the re-auth as it mounts, and on a native source that call is the
irreversible half — `mark_native_irreversible_start` empties every
diff --git a/ui/src/components/settings/models/SourceTestDialog.test.tsx b/ui/src/components/settings/models/SourceTestDialog.test.tsx
new file mode 100644
index 000000000..6bd31a048
--- /dev/null
+++ b/ui/src/components/settings/models/SourceTestDialog.test.tsx
@@ -0,0 +1,220 @@
+// @vitest-environment jsdom
+import { cleanup, render, screen, waitFor } from '@testing-library/react';
+import userEvent from '@testing-library/user-event';
+import { I18nextProvider } from 'react-i18next';
+import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';
+import i18n from '@/i18n';
+import { modelsApi } from './modelsApi';
+import type { SourceMutationLanding, SourceMutationSettlement, TrackSourceMutation } from './mutationSettlement';
+import { readyRegion, unreadRegion } from './regionRead';
+import { SourceTestDialog } from './SourceTestDialog';
+import { CONTRACT_VERSION, type Source, type SourceProbeResult } from './types';
+
+const source: Source = {
+ id: 'src_test0001', kind: 'api_key', vendor: 'custom', display_name: 'My relay',
+ protocol: 'openai_chat', base_url: 'https://relay.example/v1', supply_channel: 'hub',
+ billing: 'metered', state: { status: 'standby', retry_at: null, detail_key: null },
+ credential_ref: 'cred_test001', verification_pending: 'vp_original', last_discovered_at: null,
+ models: ['first-model', 'gpt-5.6-luna', 'manual-model'].map((id) => ({
+ id, display_name: null, origin: 'discovered', reasoning_efforts: [], reasoning_efforts_source: null,
+ })),
+};
+const answer = (patch: Partial<SourceProbeResult> = {}): SourceProbeResult => ({
+ source_id: source.id, model_id: 'gpt-5.6-luna', protocol: source.protocol,
+ reachable: true, latency_ms: 123, error: null, ...patch,
+});
+const landing = (sources: Source[] = [source]): SourceMutationLanding => ({
+ verdict: 'landed', affectedChains: [], reads: {
+ sources: readyRegion(sources), supply: readyRegion([]), chains: readyRegion({}),
+ runtime: readyRegion({
+ contract_version: CONTRACT_VERSION,
+ manifest: { name: 'cliproxyapi', resolution: 'unresolved', assets: [] },
+ status: { verified: false, health: 'not_started' },
+ }),
+ },
+});
+const settlement = {
+ unread: vi.fn(),
+ gone: vi.fn().mockResolvedValue({ verdict: 'degraded', reads: null, affectedChains: [] }),
+} as unknown as SourceMutationSettlement;
+const track: TrackSourceMutation = (work) => work(source, settlement);
+const view = (current = source) => <I18nextProvider i18n={i18n}>
+ <SourceTestDialog source={current} onClose={vi.fn()} trackMutation={track} />
+</I18nextProvider>;
+
+beforeEach(async () => {
+ vi.mocked(settlement.unread).mockReset().mockResolvedValue(landing());
+ await i18n.changeLanguage('en');
+ vi.stubGlobal('ResizeObserver', class { observe() {} unobserve() {} disconnect() {} });
+ Element.prototype.scrollIntoView = vi.fn();
+});
+afterEach(() => { cleanup(); vi.restoreAllMocks(); vi.unstubAllGlobals(); });
+
+describe('SourceTestDialog', () => {
+ it('does no work until the user starts and invokes only the chosen source/model', async () => {
+ const probe = vi.spyOn(modelsApi, 'probeSource').mockResolvedValue(answer({ model_id: 'manual-model' }));
+ const refresh = vi.spyOn(modelsApi, 'refreshSource');
+ render(view());
+ expect(screen.getByRole('combobox').textContent).toContain('gpt-5.6-luna');
+ expect(probe).not.toHaveBeenCalled();
+ const user = userEvent.setup();
+ await user.click(screen.getByRole('combobox'));
+ await user.click(await screen.findByRole('option', { name: 'manual-model' }));
+ await user.click(screen.getByRole('button', { name: 'Run test' }));
+ await screen.findByText(/manual-model responded successfully/);
+ expect(probe).toHaveBeenCalledExactlyOnceWith(source.id, 'manual-model');
+ expect(refresh).not.toHaveBeenCalled();
+ });
+
+ it('keeps the result when success clears pending verification', async () => {
+ vi.spyOn(modelsApi, 'probeSource').mockResolvedValue(answer());
+ const rendered = render(view());
+ await userEvent.click(screen.getByRole('button', { name: 'Run test' }));
+ await screen.findByText(/responded successfully/);
+ rendered.rerender(view({ ...source, verification_pending: null }));
+ expect(screen.getByText(/responded successfully/)).toBeTruthy();
+ });
+
+ it('cannot show a late success for a replacement credential', async () => {
+ let resolve!: (result: SourceProbeResult) => void;
+ vi.spyOn(modelsApi, 'probeSource').mockReturnValue(new Promise((done) => { resolve = done; }));
+ const rendered = render(view());
+ await userEvent.click(screen.getByRole('button', { name: 'Run test' }));
+ rendered.rerender(view({ ...source, credential_ref: 'cred_new', verification_pending: 'vp_new' }));
+ resolve(answer());
+ await waitFor(() => expect(screen.getByRole('button', { name: 'Run test' }).hasAttribute('disabled')).toBe(false));
+ expect(screen.queryByText(/responded successfully/)).toBeNull();
+ });
+
+ it('explains unavailable results without losing the selected model or provider', async () => {
+ vi.spyOn(modelsApi, 'probeSource').mockRejectedValue(new Error('unavailable'));
+ render(view());
+ await userEvent.click(screen.getByRole('button', { name: 'Run test' }));
+ expect((await screen.findByRole('alert')).textContent).toContain('Your provider is still saved');
+ expect(screen.getByRole('combobox').textContent).toContain('gpt-5.6-luna');
+ expect(settlement.unread).toHaveBeenCalledTimes(1);
+ });
+
+ it.each([true, false])('publishes no verdict before reconciliation completes: reachable=%s', async (reachable) => {
+ vi.spyOn(modelsApi, 'probeSource').mockResolvedValue(answer({ reachable }));
+ let resolve!: (value: SourceMutationLanding) => void;
+ vi.mocked(settlement.unread).mockReturnValue(new Promise((done) => { resolve = done; }));
+ render(view());
+ await userEvent.click(screen.getByRole('button', { name: 'Run test' }));
+ await waitFor(() => expect(settlement.unread).toHaveBeenCalledTimes(1));
+ expect(screen.queryByRole('status')).toBeNull();
+ expect(screen.queryByRole('alert')).toBeNull();
+ resolve(landing());
+ expect((await screen.findByRole('status')).textContent).toContain('gpt-5.6-luna');
+ expect(screen.queryByRole('alert')).toBeNull();
+ });
+
+ it.each([true, false])('does not retry or publish a verdict after rejected reconciliation: reachable=%s', async (reachable) => {
+ const probe = vi.spyOn(modelsApi, 'probeSource').mockResolvedValue(answer({ reachable }));
+ vi.mocked(settlement.unread).mockRejectedValue(new Error('Source list unavailable'));
+ render(view());
+ await userEvent.click(screen.getByRole('button', { name: 'Run test' }));
+ await screen.findByRole('alert');
+ expect(screen.queryByRole('status')).toBeNull();
+ expect(settlement.unread).toHaveBeenCalledTimes(1);
+ expect(probe).toHaveBeenCalledTimes(1);
+ });
+
+ it.each(['unread', 'stale', 'deleted', 'credential', 'marker', 'base_url', 'protocol', 'model'])('requires a current matching Source after reconciliation: %s', async (change) => {
+ vi.spyOn(modelsApi, 'probeSource').mockResolvedValue(answer());
+ const current = { ...source };
+ if (change === 'credential') current.credential_ref = 'cred_replacement';
+ if (change === 'marker') current.verification_pending = 'vp_replacement';
+ if (change === 'base_url') current.base_url = 'https://other.example/v1';
+ if (change === 'protocol') current.protocol = 'anthropic';
+ if (change === 'model') current.models = [];
+ const result = landing(change === 'deleted' ? [] : [current]);
+ if (change === 'unread') result.reads!.sources = unreadRegion();
+ if (change === 'stale') result.verdict = 'degraded';
+ vi.mocked(settlement.unread).mockResolvedValue(result);
+ render(view());
+ await userEvent.click(screen.getByRole('button', { name: 'Run test' }));
+ await screen.findByRole('alert');
+ expect(screen.queryByRole('status')).toBeNull();
+ expect(settlement.unread).toHaveBeenCalledTimes(1);
+ });
+
+ it('accepts reconciliation that clears the tested credential marker', async () => {
+ vi.spyOn(modelsApi, 'probeSource').mockResolvedValue(answer());
+ vi.mocked(settlement.unread).mockResolvedValue(landing([{ ...source, verification_pending: null }]));
+ render(view());
+ await userEvent.click(screen.getByRole('button', { name: 'Run test' }));
+ await screen.findByText(/responded successfully/);
+ expect(screen.queryByRole('alert')).toBeNull();
+ });
+
+ it('invalidates a reconciliation result when the dialog identity changes while it waits', async () => {
+ vi.spyOn(modelsApi, 'probeSource').mockResolvedValue(answer());
+ let resolve!: (value: SourceMutationLanding) => void;
+ vi.mocked(settlement.unread).mockReturnValue(new Promise((done) => { resolve = done; }));
+ const rendered = render(view());
+ await userEvent.click(screen.getByRole('button', { name: 'Run test' }));
+ await waitFor(() => expect(settlement.unread).toHaveBeenCalledTimes(1));
+ rendered.rerender(view({ ...source, credential_ref: 'cred_new', verification_pending: 'vp_new' }));
+ resolve(landing());
+ await waitFor(() => expect(screen.getByRole('button', { name: 'Run test' }).hasAttribute('disabled')).toBe(false));
+ expect(screen.queryByRole('status')).toBeNull();
+ expect(screen.queryByRole('alert')).toBeNull();
+ });
+
+ it('replaces an unconfirmed status only after a new explicit test settles', async () => {
+ const probe = vi.spyOn(modelsApi, 'probeSource').mockResolvedValue(answer());
+ vi.mocked(settlement.unread).mockRejectedValueOnce(new Error('unavailable'));
+ render(view());
+ await userEvent.click(screen.getByRole('button', { name: 'Run test' }));
+ await screen.findByRole('alert');
+ expect(probe).toHaveBeenCalledTimes(1);
+ await userEvent.click(screen.getByRole('button', { name: 'Run test' }));
+ await screen.findByText(/responded successfully/);
+ expect(screen.queryByRole('alert')).toBeNull();
+ expect(probe).toHaveBeenCalledTimes(2);
+ expect(settlement.unread).toHaveBeenCalledTimes(2);
+ });
+
+ it.each(['remove', 'retire', 'empty'])('clears a completed result when inventory changes selection: %s', async (change) => {
+ vi.spyOn(modelsApi, 'probeSource').mockResolvedValue(answer());
+ const rendered = render(view());
+ await userEvent.click(screen.getByRole('button', { name: 'Run test' }));
+ await screen.findByText(/responded successfully/);
+ const models = change === 'empty' ? [] : change === 'remove'
+ ? source.models.filter((model) => model.id !== 'gpt-5.6-luna')
+ : source.models.map((model) => ({ ...model, retired: model.id === 'gpt-5.6-luna' }));
+ rendered.rerender(view({ ...source, models }));
+ expect(screen.queryByRole('status')).toBeNull();
+ if (change !== 'empty') expect(screen.getByRole('combobox').textContent).toContain('first-model');
+ });
+
+ it('rejects a late result after inventory chooses a different model', async () => {
+ let resolve!: (result: SourceProbeResult) => void;
+ vi.spyOn(modelsApi, 'probeSource').mockReturnValue(new Promise((done) => { resolve = done; }));
+ const rendered = render(view());
+ await userEvent.click(screen.getByRole('button', { name: 'Run test' }));
+ rendered.rerender(view({ ...source, models: source.models.filter((model) => model.id !== 'gpt-5.6-luna') }));
+ resolve(answer());
+ await waitFor(() => expect(screen.getByRole('button', { name: 'Run test' }).hasAttribute('disabled')).toBe(false));
+ expect(screen.getByRole('combobox').textContent).toContain('first-model');
+ expect(screen.queryByRole('status')).toBeNull();
+ });
+
+ it('preserves a result across inventory updates that retain the selected model', async () => {
+ vi.spyOn(modelsApi, 'probeSource').mockResolvedValue(answer());
+ const rendered = render(view());
+ await userEvent.click(screen.getByRole('button', { name: 'Run test' }));
+ await screen.findByText(/responded successfully/);
+ rendered.rerender(view({ ...source, models: [...source.models].reverse() }));
+ expect(screen.getByRole('combobox').textContent).toContain('gpt-5.6-luna');
+ expect(screen.getByText(/responded successfully/)).toBeTruthy();
+ });
+
+ it('lets an empty inventory exit to the existing manual model editor', () => {
+ render(view({ ...source, models: [] }));
+ expect(screen.getByText(/add a model ID manually/)).toBeTruthy();
+ expect(screen.getByRole('button', { name: 'Run test' }).hasAttribute('disabled')).toBe(true);
+ expect(screen.getAllByRole('button', { name: 'Close' }).length).toBeGreaterThan(0);
+ });
+});
diff --git a/ui/src/components/settings/models/SourceTestDialog.tsx b/ui/src/components/settings/models/SourceTestDialog.tsx
new file mode 100644
index 000000000..d7c7f54f8
--- /dev/null
+++ b/ui/src/components/settings/models/SourceTestDialog.tsx
@@ -0,0 +1,116 @@
+import * as React from 'react';
+import { FlaskConical, LoaderCircle } from 'lucide-react';
+import { useTranslation } from 'react-i18next';
+
+import { Button } from '@/components/ui/button';
+import { Combobox } from '@/components/ui/combobox';
+import { Dialog, DialogContent, DialogDescription, DialogFooter, DialogTitle } from '@/components/ui/dialog';
+import { Field } from './dialogFields';
+import { apiFailure, modelsApi } from './modelsApi';
+import { createContinuationSettlement, type TrackSourceMutation } from './mutationSettlement';
+import { foldRegionRead } from './regionRead';
+import { serverText } from './serverCopy';
+import { selectTestModel } from './testModelPreference';
+import type { Source, SourceProbeResult } from './types';
+
+type TestStatus = { kind: 'result'; result: SourceProbeResult } | { kind: 'unconfirmed' } | null;
+
+export const SourceTestDialog: React.FC<{
+ source: Source;
+ onClose: () => void;
+ trackMutation: TrackSourceMutation;
+}> = ({ source, onClose, trackMutation }) => {
+ const { t } = useTranslation();
+ const [selection, setSelection] = React.useState(() => selectTestModel(source.models));
+ const [busy, setBusy] = React.useState(false);
+ const [status, setStatus] = React.useState<TestStatus>(null);
+ const [continuation] = React.useState(createContinuationSettlement);
+ const running = React.useRef(false);
+ const identity = `${source.id}/${source.credential_ref}/${source.base_url}/${source.protocol}`;
+ const selected = selectTestModel(source.models, selection);
+ React.useEffect(() => {
+ continuation.invalidate();
+ setStatus(null);
+ return () => { continuation.invalidate(); };
+ }, [continuation, identity, selected]);
+ React.useEffect(() => {
+ if (source.verification_pending) {
+ continuation.invalidate();
+ setStatus(null);
+ }
+ }, [continuation, source.verification_pending]);
+ const options = source.models.filter((model) => !model.retired).map((model) => ({
+ value: model.id, label: model.id,
+ }));
+ const run = async () => {
+ if (!selected || running.current) return;
+ running.current = true;
+ setBusy(true);
+ setStatus(null);
+ const ticket = continuation.begin();
+ try {
+ await trackMutation(async (latest, settlement) => {
+ let answer: SourceProbeResult;
+ try {
+ answer = await modelsApi.probeSource(latest.id, selected);
+ } catch (error) {
+ if (apiFailure(error)?.code === 'source_not_found') await settlement.gone(latest.id);
+ else await settlement.unread();
+ continuation.settle(ticket, () => setStatus({ kind: 'unconfirmed' }));
+ return;
+ }
+ // Reconciliation, not an old dialog snapshot, owns the current identity.
+ // Its failure must neither publish a verdict nor retry the same read.
+ const landing = await settlement.unread();
+ const current = landing.verdict === 'landed' ? foldRegionRead<Source[], Source | undefined>(landing.reads.sources, {
+ loading: () => undefined,
+ ready: (sources) => sources.find((item) => item.id === latest.id),
+ unread: () => undefined,
+ degraded: () => undefined,
+ }) : undefined;
+ const matches = current && current.credential_ref === latest.credential_ref
+ && current.base_url === latest.base_url && current.protocol === latest.protocol
+ && (!current.verification_pending || current.verification_pending === latest.verification_pending)
+ && current.models.some((model) => model.id === selected && !model.retired);
+ continuation.settle(ticket, () => setStatus(matches
+ ? { kind: 'result', result: answer } : { kind: 'unconfirmed' }));
+ });
+ } catch {
+ continuation.settle(ticket, () => setStatus({ kind: 'unconfirmed' }));
+ } finally {
+ running.current = false;
+ setBusy(false);
+ }
+ };
+ const result = status?.kind === 'result' ? status.result : null;
+ return (
+ <Dialog open onOpenChange={(open) => { if (!open) onClose(); }}>
+ <DialogContent closeLabel={t('common.close')}>
+ <DialogTitle className="min-w-0 break-words pr-6">{t('settings.models.sourceTest.title', { source: source.display_name })}</DialogTitle>
+ <DialogDescription>{t('settings.models.sourceTest.hint')}</DialogDescription>
+ <Field label={t('settings.models.sourceTest.model')}>
+ {(id) => <Combobox id={id} ariaLabel={t('settings.models.sourceTest.model')} options={options}
+ value={selected} disabled={busy || options.length === 0} allowCustomValue={false}
+ onValueChange={(value) => { setSelection(value); setStatus(null); }} />}
+ </Field>
+ {options.length === 0 && <p className="text-sm text-muted">{t('settings.models.sourceTest.empty')}</p>}
+ {result && <p role="status" className="min-w-0 break-words text-sm">
+ {result.reachable
+ ? t('settings.models.sourceTest.success', { model: result.model_id, ms: result.latency_ms })
+ : t('settings.models.sourceTest.failure', {
+ model: result.model_id,
+ reason: serverText(t, result.error, 'settings.models.sourceTest.unknown'),
+ })}
+ </p>}
+ {status?.kind === 'unconfirmed' && <p role="alert" className="text-sm text-destructive-ink">{t('settings.models.sourceTest.requestFailed')}</p>}
+ <DialogFooter>
+ <Button variant="outline" onClick={onClose}>{t('common.close')}</Button>
+ <Button disabled={busy || !selected} onClick={() => void run()}>
+ {busy ? <LoaderCircle className="size-4 animate-spin" /> : <FlaskConical className="size-4" />}
+ {t(busy ? 'settings.models.sourceTest.running' : 'settings.models.sourceTest.run')}
+ </Button>
+ </DialogFooter>
+ </DialogContent>
+ </Dialog>
+ );
+};
diff --git a/ui/src/components/settings/models/addApiKeyState.test.ts b/ui/src/components/settings/models/addApiKeyState.test.ts
deleted file mode 100644
index 918535e6d..000000000
--- a/ui/src/components/settings/models/addApiKeyState.test.ts
+++ /dev/null
@@ -1,52 +0,0 @@
-import { describe, expect, it } from 'vitest';
-
-import { classifyObservation } from './addApiKeyState';
-import { CONTRACT_VERSION, type SourceObservation } from './types';
-
-const observation = (patch: Partial<SourceObservation>): SourceObservation => ({
- contract_version: CONTRACT_VERSION,
- outcome: 'observed',
- reachable: true,
- authenticated: 'authenticated',
- protocol: 'openai_chat',
- discovery: 'succeeded',
- models: ['model-a'],
- ...patch,
-});
-
-describe('Add API key observation state', () => {
- it('separates proven inventory failure from unknown protocol and connectivity failures', () => {
- const inventory = observation({ discovery: 'failed', models: [] });
- expect(classifyObservation(inventory)).toEqual({ kind: 'inventory', observation: inventory });
- expect(classifyObservation(observation({
- outcome: 'ambiguous',
- authenticated: 'unknown',
- protocol: null,
- discovery: 'not_attempted',
- models: [],
- })).kind).toBe('undetermined');
- expect(classifyObservation(observation({
- outcome: 'authentication_failed',
- authenticated: 'rejected',
- protocol: null,
- discovery: 'not_attempted',
- models: [],
- }))).toEqual({ kind: 'failure', cause: 'auth' });
- expect(classifyObservation(observation({
- outcome: 'timeout',
- reachable: null,
- authenticated: 'unknown',
- protocol: null,
- discovery: 'not_attempted',
- models: [],
- }))).toEqual({ kind: 'failure', cause: 'network' });
- expect(classifyObservation(observation({
- outcome: 'unreachable',
- reachable: false,
- authenticated: 'unknown',
- protocol: null,
- discovery: 'not_attempted',
- models: [],
- }))).toEqual({ kind: 'failure', cause: 'network' });
- });
-});
diff --git a/ui/src/components/settings/models/addApiKeyState.ts b/ui/src/components/settings/models/addApiKeyState.ts
index af48fe70f..54947de20 100644
--- a/ui/src/components/settings/models/addApiKeyState.ts
+++ b/ui/src/components/settings/models/addApiKeyState.ts
@@ -1,42 +1,7 @@
-import type { SourceObservation, SourceProtocol } from './types';
-
-export type AddApiKeyOrigin = 'add' | 'pull';
-export type AddApiKeyFailure = 'auth' | 'network' | 'interface' | 'unclassified' | 'engineDown';
-
-export type ObservationVerdict =
- | { kind: 'ready'; observation: SourceObservation }
- | { kind: 'undetermined'; observation: SourceObservation }
- | { kind: 'inventory'; observation: SourceObservation }
- | { kind: 'failure'; cause: AddApiKeyFailure };
+import type { SourceProtocol } from './types';
export const PROTOCOL_COPY_KEYS: Record<SourceProtocol, string> = {
anthropic: 'settings.models.addKey.protocol.anthropicMessages',
openai_responses: 'settings.models.addKey.protocol.openaiResponses',
openai_chat: 'settings.models.addKey.protocol.openaiChatCompletions',
};
-
-export function classifyObservation(observation: SourceObservation): ObservationVerdict {
- switch (observation.outcome) {
- case 'observed':
- if (observation.protocol && observation.discovery === 'succeeded') {
- return { kind: 'ready', observation };
- }
- if (observation.protocol && observation.discovery === 'failed') {
- return { kind: 'inventory', observation };
- }
- return { kind: 'failure', cause: 'unclassified' };
- case 'ambiguous':
- return { kind: 'undetermined', observation };
- case 'authentication_failed':
- return { kind: 'failure', cause: 'auth' };
- case 'unreachable':
- case 'timeout':
- return { kind: 'failure', cause: 'network' };
- case 'adapter_error':
- return { kind: 'failure', cause: observation.reachable ? 'interface' : 'unclassified' };
- }
-}
-
-export function isAbortError(error: unknown): boolean {
- return error instanceof DOMException && error.name === 'AbortError';
-}
diff --git a/ui/src/components/settings/models/modelHubSurface.css b/ui/src/components/settings/models/modelHubSurface.css
index db32fd77a..e166ea867 100644
--- a/ui/src/components/settings/models/modelHubSurface.css
+++ b/ui/src/components/settings/models/modelHubSurface.css
@@ -710,6 +710,7 @@
}
.model-hub-add-key-head {
+ flex-shrink: 0;
--model-hub-add-key-head-gap: 4px;
--model-hub-add-key-head-padding-x: 20px;
--model-hub-add-key-head-padding-y: 16px;
@@ -725,6 +726,8 @@
font-size: var(--model-hub-add-key-subtitle-size);
}
.model-hub-add-key-body {
+ min-height: 0;
+ overflow-y: auto;
--model-hub-add-key-body-gap: 14px;
--model-hub-add-key-body-padding: 20px;
padding: var(--model-hub-add-key-body-padding);
@@ -963,6 +966,7 @@
color: var(--mint-ink);
}
.model-hub-add-key-foot {
+ flex-shrink: 0;
--model-hub-add-key-footer-fill: var(--model-hub-wash-05);
--model-hub-add-key-foot-gap: 8px;
--model-hub-add-key-foot-padding-x: 20px;
@@ -1304,6 +1308,10 @@
column-gap: var(--model-hub-source-table-gap);
padding-inline: var(--model-hub-source-table-padding-x);
}
+
+.model-hub-source-detail[data-advanced="false"] :is(.model-hub-source-table-head, .model-hub-source-table-row, .model-hub-source-table-draft) {
+ grid-template-columns: minmax(0, 1fr) auto;
+}
/* The columns are what a heading makes a claim about, so only the bands read
against that heading take them. */
.model-hub-source-table-head,
diff --git a/ui/src/components/settings/models/modelsApi.ts b/ui/src/components/settings/models/modelsApi.ts
index 96f1e7823..5d342cbb0 100644
--- a/ui/src/components/settings/models/modelsApi.ts
+++ b/ui/src/components/settings/models/modelsApi.ts
@@ -37,6 +37,7 @@ import type {
Source,
SourceObservation,
SourcePatch,
+ SourceProbeResult,
SourceRepaired,
SupplyChannel,
SupplyGap,
@@ -105,6 +106,7 @@ export type ModelsApi = {
* it clears the blocker and returns the source to standby. v3 adds no second
* 「recover」 endpoint, so this is the whole retry affordance. */
refreshSource(id: string, confirmation?: GuardConfirmation): Promise<SourceRefresh>;
+ probeSource(id: string, model: string): Promise<SourceProbeResult>;
/** Delete a source. A destructive retry echoes the server's exact guard plan. */
deleteSource(id: string, confirmation?: GuardConfirmation): Promise<SourceDeleted>;
/** Replace the credential of a hub-channel api_key source. The normal guarded
@@ -574,6 +576,9 @@ export const modelsApi: ModelsApi = {
createApiKeySource: (draft) => call<SourceCreatedResponse>('/api/models/sources', jsonInit('POST', draft)).then(created),
patchSource: (id, patch) => call<SourcePatchedResponse>(`/api/models/sources/${encodeURIComponent(id)}`, jsonInit('PATCH', patch)).then(sourcePatched),
refreshSource: (id, confirmation) => call<SourceRefresh>(`/api/models/sources/${encodeURIComponent(id)}/refresh`, jsonInit('POST', confirmation ?? {})),
+ probeSource: (id, model) => call<{ probe: SourceProbeResult }>(
+ `/api/models/sources/${encodeURIComponent(id)}/probe`, jsonInit('POST', { model }),
+ ).then((r) => r.probe),
deleteSource: (id, confirmation) => call<SourceDeletedResponse>(
`/api/models/sources/${encodeURIComponent(id)}${confirmation ? '?force=true' : ''}`,
jsonInit('DELETE', confirmation ? {
diff --git a/ui/src/components/settings/models/testModelPreference.test.ts b/ui/src/components/settings/models/testModelPreference.test.ts
new file mode 100644
index 000000000..80475382d
--- /dev/null
+++ b/ui/src/components/settings/models/testModelPreference.test.ts
@@ -0,0 +1,30 @@
+import { describe, expect, it } from 'vitest';
+import { PREFERRED_TEST_MODEL_IDS, selectTestModel } from './testModelPreference';
+import type { SuppliedModel } from './types';
+
+const rows = (...ids: string[]): SuppliedModel[] => ids.map((id) => ({
+ id, display_name: null, origin: 'discovered', reasoning_efforts: [], reasoning_efforts_source: null,
+}));
+
+describe('test model preference', () => {
+ it('intersects the preference list with inventory in preference order', () => {
+ const inventory = rows('old-model', ...[...PREFERRED_TEST_MODEL_IDS].reverse());
+ expect(selectTestModel(inventory)).toBe(PREFERRED_TEST_MODEL_IDS[0]);
+ expect(inventory[0].id).toBe('old-model');
+ });
+
+ it('uses the first inventory model without guessing names or sorting upstream rows', () => {
+ expect(selectTestModel(rows('z-model', 'a-model'))).toBe('z-model');
+ expect(selectTestModel(rows(`${PREFERRED_TEST_MODEL_IDS[0]}-other`, 'a-model')))
+ .toBe(`${PREFERRED_TEST_MODEL_IDS[0]}-other`);
+ });
+
+ it('preserves any valid user selection and excludes retired rows', () => {
+ expect(selectTestModel(rows(PREFERRED_TEST_MODEL_IDS[0], 'chosen'), 'chosen')).toBe('chosen');
+ expect(selectTestModel([
+ { ...rows(PREFERRED_TEST_MODEL_IDS[0])[0], retired: true },
+ ...rows('available'),
+ ], PREFERRED_TEST_MODEL_IDS[0])).toBe('available');
+ expect(selectTestModel([])).toBe('');
+ });
+});
diff --git a/ui/src/components/settings/models/testModelPreference.ts b/ui/src/components/settings/models/testModelPreference.ts
new file mode 100644
index 000000000..39cb88075
--- /dev/null
+++ b/ui/src/components/settings/models/testModelPreference.ts
@@ -0,0 +1,20 @@
+import type { SuppliedModel } from './types';
+
+// Ordered preferences, not invented inventory. These exact IDs are already
+// present in the bundled backend catalog; only upstream/manual rows may win.
+// Keep tuning this small list separate from provider/model capability metadata.
+export const PREFERRED_TEST_MODEL_IDS = [
+ 'gpt-5.6-luna',
+ 'claude-sonnet-5',
+ 'gpt-5.4-mini',
+ 'claude-sonnet-4-6',
+] as const;
+
+export const selectTestModel = (
+ models: readonly SuppliedModel[],
+ selected = '',
+): string => {
+ const ids = models.filter((model) => !model.retired).map((model) => model.id);
+ if (selected && ids.includes(selected)) return selected;
+ return PREFERRED_TEST_MODEL_IDS.find((id) => ids.includes(id)) ?? ids[0] ?? '';
+};
diff --git a/ui/src/components/settings/models/types.ts b/ui/src/components/settings/models/types.ts
index 0be405b7d..c9a7ecec3 100644
--- a/ui/src/components/settings/models/types.ts
+++ b/ui/src/components/settings/models/types.ts
@@ -853,7 +853,16 @@ export type ApiKeySourceObservation = {
protocol?: SourceProtocol;
};
-/** POST /api/models/sources — observation is bypassed only by explicit consent. */
+export type SourceProbeResult = {
+ source_id: string;
+ model_id: string;
+ protocol: SourceProtocol;
+ reachable: boolean;
+ latency_ms: number;
+ error: string | null;
+};
+
+/** POST /api/models/sources — the UI always uses save-first configuration. */
export type ApiKeySourceCreate = {
kind: 'api_key';
vendor: string;
@@ -866,7 +875,7 @@ export type ApiKeySourceCreate = {
protocol?: SourceProtocol;
/** Explicit consent for a repeated, protocol-proven inventory failure. */
accept_unavailable_inventory?: boolean;
- /** Save a catalog-pinned or declared interface without calling the upstream. */
+ /** Save independently of verification; inventory discovery is best-effort. */
save_unverified?: boolean;
};
diff --git a/ui/src/i18n/en.json b/ui/src/i18n/en.json
index dc8aaed4f..81c0f5ca8 100644
--- a/ui/src/i18n/en.json
+++ b/ui/src/i18n/en.json
@@ -1430,6 +1430,7 @@
"deletedSource": "deleted"
},
"addKey": {
+ "saveFirstHint": "Save your provider and try fetching its models. Testing is optional and can be done afterwards.",
"title": "Add API key",
"subtitle": "API key and model interface",
"field": {
@@ -1453,7 +1454,7 @@
"empty": "Connected, but this source lists no models"
},
"detect": "Detect",
- "confirm": "Confirm & add",
+ "confirm": "Add provider",
"adding": "Connecting…",
"adding.detail": "Connect, validate the interface, fetch the model list · usually 1–3s",
"saving": "Saving…",
@@ -1476,6 +1477,7 @@
"detail": "The response does not establish both the interface and credential validity"
},
"protocol": {
+ "saveFirstHint": "Choose the provider's API format. Saving does not require successful detection or a model test.",
"auto": "Auto detect",
"anthropicMessages": "Anthropic Messages",
"openaiResponses": "OpenAI Responses",
@@ -1656,7 +1658,21 @@
"codex": "Codex",
"opencode": "OpenCode"
},
+ "sourceTest": {
+ "open": "Test",
+ "title": "Test {{source}}",
+ "hint": "Send one short request using this provider and the selected model. This can incur a small charge. The result applies only to this model.",
+ "model": "Test model",
+ "empty": "No models available. Close this dialog to fetch the list or add a model ID manually.",
+ "run": "Run test",
+ "running": "Testing…",
+ "success": "{{model}} responded successfully · {{ms}} ms",
+ "failure": "{{model}} did not pass this test: {{reason}}",
+ "unknown": "The model request failed.",
+ "requestFailed": "The test result could not be confirmed. Your provider is still saved."
+ },
"sourceDetail": {
+ "advanced": "Advanced settings",
"back": "Back to sources",
"close": "Close provider details",
"modelsHeading": "Models",
@@ -1777,7 +1793,7 @@
"managedHint": "Set automatically — these cannot be added or removed",
"managed": {
"upstream": "From provider",
- "catalog": "Built-in catalog"
+ "catalog": "Avibe preset levels"
}
},
"addRow": {
diff --git a/ui/src/i18n/zh.json b/ui/src/i18n/zh.json
index c3840bb3f..48f48dedb 100644
--- a/ui/src/i18n/zh.json
+++ b/ui/src/i18n/zh.json
@@ -1430,6 +1430,7 @@
"deletedSource": "已删除"
},
"addKey": {
+ "saveFirstHint": "保存供应商时会尝试拉取模型列表。测试是可选的,可在添加后进行。",
"title": "添加 API Key",
"subtitle": "API Key 与模型接口",
"field": {
@@ -1453,7 +1454,7 @@
"empty": "已经连接,但这个供应商没有可用模型"
},
"detect": "检测",
- "confirm": "确认添加",
+ "confirm": "添加供应商",
"adding": "连接中…",
"adding.detail": "连接 + 验证接口 + 首次拉取模型列表 · 通常 1–3 秒",
"saving": "保存中…",
@@ -1476,6 +1477,7 @@
"detail": "这次响应不足以同时确认接口类型和凭证有效性"
},
"protocol": {
+ "saveFirstHint": "选择供应商使用的 API 格式,无需检测或测试通过即可保存。",
"auto": "自动探测",
"anthropicMessages": "Anthropic Messages",
"openaiResponses": "OpenAI Responses",
@@ -1656,7 +1658,21 @@
"codex": "Codex",
"opencode": "OpenCode"
},
+ "sourceTest": {
+ "open": "测试",
+ "title": "测试 {{source}}",
+ "hint": "使用此供应商和选中的模型发送一次简短请求,可能产生少量费用。结果仅代表这个模型。",
+ "model": "测试模型",
+ "empty": "暂无模型。关闭此窗口后,可拉取列表或手动添加模型 ID。",
+ "run": "开始测试",
+ "running": "测试中…",
+ "success": "{{model}} 调用成功 · {{ms}} 毫秒",
+ "failure": "{{model}} 本次测试未通过:{{reason}}",
+ "unknown": "模型请求失败。",
+ "requestFailed": "暂时无法确认测试结果,供应商配置仍已保存。"
+ },
"sourceDetail": {
+ "advanced": "高级设置",
"back": "返回模型供应商列表",
"close": "关闭供应商详情",
"modelsHeading": "模型",
@@ -1777,7 +1793,7 @@
"managedHint": "自动确定,不能添加或移除",
"managed": {
"upstream": "供应商声明",
- "catalog": "内置目录"
+ "catalog": "Avibe 预置档位"
}
},
"addRow": {
diff --git a/vibe/model_hub_client.py b/vibe/model_hub_client.py
index 9ce038e09..2eb4422c9 100644
--- a/vibe/model_hub_client.py
+++ b/vibe/model_hub_client.py
@@ -90,6 +90,9 @@ class ModelHubRemoteService:
async def create_source(self, payload: dict) -> dict:
return await _rpc("create_source", {"source": payload})
+ async def probe_source(self, source_id: str, payload: object) -> dict:
+ return await _rpc("probe_source", {"source_id": source_id, "probe": payload})
+
async def patch_source(self, source_id: str, payload: dict) -> dict:
return await _rpc("patch_source", {"source_id": source_id, "patch": payload})
diff --git a/vibe/ui_server.py b/vibe/ui_server.py
index ace9c783d..5c5c35e26 100644
--- a/vibe/ui_server.py
+++ b/vibe/ui_server.py
@@ -4491,6 +4491,17 @@ async def model_hub_sources_patch(source_id):
return _model_hub_error(exc)
[email protected]("/api/models/sources/<source_id>/probe", methods=["POST"])
+async def model_hub_source_probe(source_id):
+ from core.handlers.model_hub import ModelHubError
+
+ try:
+ result = await _model_hub_service().probe_source(source_id, _model_hub_json_object())
+ return _model_hub_success(probe=result)
+ except ModelHubError as exc:
+ return _model_hub_error(exc)
+
+
@app.route("/api/models/sources/<source_id>/credential", methods=["PUT"])
async def model_hub_source_credential_put(source_id):
from core.handlers.model_hub import ModelHubError