free-claude-code/api/admin_config/provider_manifest.py
Ali Khokhar 85b601884d
Some checks are pending
CI / Ban suppressions and legacy annotations (push) Waiting to run
CI / pytest (push) Waiting to run
CI / ruff-check (push) Waiting to run
CI / ruff-format (push) Waiting to run
CI / ty (push) Waiting to run
Remove legacy future annotation imports (#982)
## Problem

Python 3.14 provides native lazy annotations, but the codebase still
relied on legacy future annotation imports. Those imports also made
type-only import cycles easier to hide instead of fixing ownership
boundaries.

## Changes

| Before | After |
| --- | --- |
| Python files used `from __future__ import annotations`. | Python files
rely on Python 3.14 native lazy annotations. |
| Some runtime modules used `TYPE_CHECKING` or local imports for
required dependencies. | Runtime modules use top-level owner-module
imports with explicit boundaries. |
| Local and GitHub guardrails only rejected type ignore suppressions. |
Local and GitHub guardrails reject type ignore suppressions and legacy
future annotation imports. |
| Agent docs only documented the no-type-ignore rule. | Agent docs
document the Python 3.14 annotation and import-boundary rules. |

<!-- greptile_comment -->

<details open><summary><h3>Greptile Summary</h3></summary>

This PR moves the codebase to Python 3.14 native lazy annotations. The
main changes are:

- Removed legacy `from __future__ import annotations` imports across
Python modules.
- Promoted selected runtime dependencies from `TYPE_CHECKING` or local
imports to explicit owner-module imports.
- Added local, GitHub, and contract-test guardrails to reject legacy
future annotation imports.
- Updated agent docs with the annotation and import-boundary rules.
- Bumped the package patch version for production-file changes.
</details>

<h3>Confidence Score: 5/5</h3>

Safe to merge with low risk.

The changes are mostly mechanical annotation cleanup with matching CI
and contract-test guardrails. Reviewed import-boundary updates did not
show a confirmed runtime cycle or dependency break.

No files require special attention.

<details><summary><h3><a href="https://www.greptile.com/trex"><img
alt="T-Rex"
src="https://greptile-static-assets.s3.amazonaws.com/trex/trex_green.svg"
height="20" align="absmiddle"></a> T-Rex Logs</h3></summary>

**What T-Rex did**
- Performed an end-to-end validation of the guardrail contract suite: an
environment check confirmed uv availability, a guardrail pytest run used
CPython 3.14.0 with 5 passing contract tests, 3 focused CI-script tests
passed, and the direct CI suppressions guardrail command (including the
legacy future-annotations grep) also passed.

<a
href="https://app.greptile.com/trex/runs/13303335/artifacts"><picture><source
media="(prefers-color-scheme: dark)"
srcset="https://greptile-static-assets.s3.amazonaws.com/badges/ViewAllArtifactsDark.svg?v=4"><source
media="(prefers-color-scheme: light)"
srcset="https://greptile-static-assets.s3.amazonaws.com/badges/ViewAllArtifacts.svg?v=4"><img
alt="View all artifacts"
src="https://greptile-static-assets.s3.amazonaws.com/badges/ViewAllArtifacts.svg?v=4"></picture></a>

<sub><a href="https://www.greptile.com/trex"><img alt="T-Rex"
src="https://greptile-static-assets.s3.amazonaws.com/trex/trex_green.svg"
height="14" align="absmiddle"></a> Ran code and verified through
T-Rex</sub>
</details>

<details open><summary><h3>Important Files Changed</h3></summary>

| Filename | Overview |
|----------|----------|
| api/runtime.py | Moves messaging, CLI manager, session, limiter, and
tree dependencies from local/type-checking imports to explicit top-level
owner-module imports. |
| messaging/platforms/telegram.py | Removes future annotations and
promotes Telegram SDK type imports into the existing availability guard.
|
| messaging/platforms/telegram_inbound.py | Removes future annotations
and imports Telegram SDK types at module scope for inbound
normalization. |
| tests/contracts/test_import_boundaries.py | Adds an AST contract that
rejects legacy future annotation imports across Python files. |
| scripts/ci.sh | Extends the local suppression check to reject legacy
future annotation imports alongside type-ignore suppressions. |
| scripts/ci.ps1 | Mirrors the local PowerShell CI suppression check for
legacy future annotations. |
| .github/workflows/tests.yml | Renames and broadens the GitHub
guardrail job to reject both type suppressions and legacy future
annotations. |
| pyproject.toml | Bumps the patch version for production-file changes.
|

</details>

<details open><summary><h3>Sequence Diagram</h3></summary>

<a href="#gh-light-mode-only">

```mermaid
%%{init: {'theme': 'neutral'}}%%
sequenceDiagram
participant Dev as Developer/CI
participant Guard as Suppression guard
participant AST as Import-boundary contract test
participant Py as Python modules

Dev->>Guard: Run local/GitHub suppression check
Guard->>Py: "Scan *.py for type ignores and future annotations"
Guard-->>Dev: Fail if legacy annotation import remains
Dev->>AST: Run pytest contract tests
AST->>Py: Parse imports with ast
AST-->>Dev: Assert no future annotations/import-boundary violations
Py-->>Dev: Use Python 3.14 native lazy annotations
```

</a>
<a href="#gh-dark-mode-only">

```mermaid
%%{init: {'theme': 'base', 'themeVariables': {"darkMode": true, "background": "#0d1117", "primaryColor": "#21262d", "primaryTextColor": "#e6edf3", "primaryBorderColor": "#8b949e", "lineColor": "#8b949e", "textColor": "#e6edf3", "edgeLabelBackground": "#161b22", "actorBkg": "#21262d", "actorBorder": "#8b949e", "actorTextColor": "#e6edf3", "actorLineColor": "#8b949e", "signalColor": "#8b949e", "signalTextColor": "#e6edf3", "noteBkgColor": "#373320", "noteBorderColor": "#d4a72c", "noteTextColor": "#f0e6c0", "labelBoxBkgColor": "#21262d", "labelBoxBorderColor": "#8b949e", "labelTextColor": "#e6edf3", "loopTextColor": "#e6edf3", "activationBkgColor": "#30363d", "activationBorderColor": "#8b949e"}}}%%
sequenceDiagram
participant Dev as Developer/CI
participant Guard as Suppression guard
participant AST as Import-boundary contract test
participant Py as Python modules

Dev->>Guard: Run local/GitHub suppression check
Guard->>Py: "Scan *.py for type ignores and future annotations"
Guard-->>Dev: Fail if legacy annotation import remains
Dev->>AST: Run pytest contract tests
AST->>Py: Parse imports with ast
AST-->>Dev: Assert no future annotations/import-boundary violations
Py-->>Dev: Use Python 3.14 native lazy annotations
```

</a>
</details>

<sub>Reviews (2): Last reviewed commit: ["Remove legacy future
annotations
import"](6e6cda69da)
| [Re-trigger
Greptile](https://app.greptile.com/api/retrigger?id=41875785)</sub>

<!-- /greptile_comment -->
2026-07-04 21:41:51 -07:00

169 lines
5.8 KiB
Python

"""Catalog-derived Admin UI provider fields."""
from typing import Any
from config.provider_catalog import PROVIDER_CATALOG
from config.settings import Settings
_PROVIDER_FIELD_OVERRIDES: dict[str, dict[str, Any]] = {
"NVIDIA_NIM_API_KEY": {
"label": "NVIDIA NIM API Key",
"description": "Used by NVIDIA NIM chat and optional NIM voice transcription.",
},
"MISTRAL_API_KEY": {
"label": "Mistral API Key",
"description": (
"Mistral La Plateforme (api.mistral.ai); Experiment plan is free tier with rate limits."
),
},
"CODESTRAL_API_KEY": {
"label": "Codestral API Key",
"description": (
"Mistral Codestral endpoint (codestral.mistral.ai); distinct from Mistral "
"La Plateforme ``MISTRAL_API_KEY``. See Mistral docs for coding/FIM domains."
),
},
"OPENCODE_API_KEY": {
"label": "OpenCode API Key",
"description": (
"OpenCode Zen curated gateway (opencode.ai/zen/v1) and OpenCode Go subscription "
"gateway (opencode.ai/zen/go/v1); single key from opencode.ai/auth."
),
},
"ZAI_API_KEY": {
"label": "Z.ai API Key",
"description": "Z.ai Coding Plan API key.",
},
"FIREWORKS_API_KEY": {
"label": "Fireworks API Key",
"description": "Fireworks AI inference API key.",
},
"MINIMAX_API_KEY": {
"label": "MiniMax API Key",
"description": (
"MiniMax API key for the Anthropic-compatible Messages API at "
"api.minimax.io/anthropic/v1."
),
},
"CLOUDFLARE_API_TOKEN": {
"label": "Cloudflare API Token",
"description": (
"Cloudflare API token for account-scoped AI REST requests. "
"Use with CLOUDFLARE_ACCOUNT_ID."
),
},
"GEMINI_API_KEY": {
"label": "Gemini API Key",
"description": (
"Google AI Studio Gemini API key (Google AI Studio / Gemini API "
"[OpenAI-compatible](https://ai.google.dev/gemini-api/docs/openai)); "
"free tier has per-model rate limits and data may be used for improvement "
"outside the UK/CH/EEA/EU."
),
},
"GROQ_API_KEY": {
"label": "Groq API Key",
"description": (
"GroqCloud OpenAI-compatible API key ([console.groq.com/keys]("
"https://console.groq.com/keys)); see Groq "
"[OpenAI compatibility docs](https://console.groq.com/docs/openai)."
),
},
"CEREBRAS_API_KEY": {
"label": "Cerebras API Key",
"description": (
"Cerebras Inference API key (create in [Cloud Console](https://cloud.cerebras.ai)); "
"see [Quickstart](https://inference-docs.cerebras.ai/quickstart) and "
"[OpenAI compatibility](https://inference-docs.cerebras.ai/resources/openai)."
),
},
}
def provider_field_specs() -> tuple[dict[str, Any], ...]:
"""Return provider fields generated from the provider catalog."""
return (
*_credential_field_specs(),
*_cloudflare_account_field_specs(),
*_local_base_url_field_specs(),
*_proxy_field_specs(),
)
def _credential_field_specs() -> tuple[dict[str, Any], ...]:
specs: list[dict[str, Any]] = []
seen_env_keys: set[str] = set()
for descriptor in PROVIDER_CATALOG.values():
if descriptor.credential_env is None:
continue
if descriptor.credential_env in seen_env_keys:
continue
seen_env_keys.add(descriptor.credential_env)
spec = {
"key": descriptor.credential_env,
"label": f"{descriptor.display_name} API Key",
"section_id": "providers",
"field_type": "secret",
"settings_attr": descriptor.credential_attr,
"secret": True,
}
spec.update(_PROVIDER_FIELD_OVERRIDES.get(descriptor.credential_env, {}))
specs.append(spec)
return tuple(specs)
def _local_base_url_field_specs() -> tuple[dict[str, Any], ...]:
specs: list[dict[str, Any]] = []
for descriptor in PROVIDER_CATALOG.values():
if descriptor.base_url_attr is None:
continue
specs.append(
{
"key": _settings_env_key(descriptor.base_url_attr),
"label": f"{descriptor.display_name} Base URL",
"section_id": "providers",
"settings_attr": descriptor.base_url_attr,
"default": descriptor.default_base_url or "",
}
)
return tuple(specs)
def _cloudflare_account_field_specs() -> tuple[dict[str, Any], ...]:
return (
{
"key": "CLOUDFLARE_ACCOUNT_ID",
"label": "Cloudflare Account ID",
"section_id": "providers",
"settings_attr": "cloudflare_account_id",
"description": (
"Cloudflare account ID used to build the /accounts/{id}/ai/v1 endpoint."
),
},
)
def _proxy_field_specs() -> tuple[dict[str, Any], ...]:
specs: list[dict[str, Any]] = []
for descriptor in PROVIDER_CATALOG.values():
if descriptor.proxy_attr is None:
continue
specs.append(
{
"key": _settings_env_key(descriptor.proxy_attr),
"label": f"{descriptor.display_name} Proxy",
"section_id": "providers",
"field_type": "secret",
"settings_attr": descriptor.proxy_attr,
"secret": True,
"advanced": True,
}
)
return tuple(specs)
def _settings_env_key(settings_attr: str) -> str:
model_field = Settings.model_fields[settings_attr]
alias = model_field.validation_alias
return str(alias) if alias is not None else settings_attr