2026-09-02 11:23:23 -07:00
|
|
|
"""CommandCode provider profiles: ``commandcode`` (chat_completions) and
|
|
|
|
|
``commandcode-anthropic`` (anthropic_messages, Bearer auth — see
|
|
|
|
|
``agent/anthropic_adapter.py``). Same key and base URL for both."""
|
2026-05-26 21:08:01 -04:00
|
|
|
|
|
|
|
|
import json
|
|
|
|
|
import logging
|
|
|
|
|
import urllib.request
|
|
|
|
|
|
2026-09-12 20:09:42 -07:00
|
|
|
from hermes_cli.urllib_security import open_credentialed_url
|
2026-09-13 19:27:28 +05:30
|
|
|
from providers import get_provider_profile, register_provider
|
2026-05-26 21:08:01 -04:00
|
|
|
from providers.base import ProviderProfile, _profile_user_agent
|
|
|
|
|
|
|
|
|
|
logger = logging.getLogger(__name__)
|
|
|
|
|
|
|
|
|
|
_COMMANDCODE_BASE = "https://api.commandcode.ai/provider/v1"
|
|
|
|
|
_COMMANDCODE_MODELS_URL = f"{_COMMANDCODE_BASE}/models"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class CommandCodeProfile(ProviderProfile):
|
|
|
|
|
"""CommandCode — OpenAI-compatible chat completions endpoint."""
|
|
|
|
|
|
|
|
|
|
def fetch_models(
|
2026-09-02 11:23:23 -07:00
|
|
|
self, *, api_key: str | None = None, base_url: str | None = None, timeout: float = 8.0
|
2026-05-26 21:08:01 -04:00
|
|
|
) -> list[str] | None:
|
2026-09-02 21:04:38 -07:00
|
|
|
"""Public (unauthenticated) /models endpoint. The picker passes base_url
|
|
|
|
|
unconditionally, so only a value differing from the default is a custom endpoint."""
|
|
|
|
|
caller_base = (base_url or "").strip().rstrip("/")
|
|
|
|
|
custom = caller_base and caller_base != _COMMANDCODE_BASE
|
|
|
|
|
models_url = caller_base + "/models" if custom else _COMMANDCODE_MODELS_URL
|
|
|
|
|
try:
|
|
|
|
|
req = urllib.request.Request(models_url)
|
|
|
|
|
req.add_header("Accept", "application/json")
|
|
|
|
|
req.add_header("User-Agent", _profile_user_agent())
|
2026-09-12 20:09:42 -07:00
|
|
|
with open_credentialed_url(req, timeout=timeout) as resp:
|
2026-09-02 21:04:38 -07:00
|
|
|
data = json.loads(resp.read().decode())
|
|
|
|
|
return [m["id"] for m in data.get("data", []) if isinstance(m, dict) and "id" in m]
|
|
|
|
|
except Exception as exc:
|
|
|
|
|
logger.debug("fetch_models(commandcode): %s", exc)
|
|
|
|
|
return None
|
2026-05-26 21:08:01 -04:00
|
|
|
|
|
|
|
|
|
2026-09-12 19:16:22 -07:00
|
|
|
def build_api_kwargs_extras(
|
|
|
|
|
self, *, reasoning_config: dict | None = None, model: str | None = None, **context
|
|
|
|
|
) -> tuple[dict, dict]:
|
|
|
|
|
"""DeepSeek ids (``deepseek/deepseek-v4-flash``) get the native DeepSeek wire
|
|
|
|
|
controls: DeepSeek V4+ defaults to thinking when ``thinking`` is omitted, so
|
|
|
|
|
without them ``/reasoning`` never reaches the request (#95232). Other model
|
|
|
|
|
families stay a no-op — CommandCode declares no reasoning vocabulary for them."""
|
|
|
|
|
m = (model or "").strip()
|
2026-09-13 19:27:28 +05:30
|
|
|
if not m.lower().startswith("deepseek/"):
|
2026-09-12 19:16:22 -07:00
|
|
|
return {}, {}
|
2026-09-13 19:27:28 +05:30
|
|
|
# Registry lookup, not a module import: the deepseek shim is only a loader-injected
|
|
|
|
|
# sys.modules entry, and the registry honours a user override of the profile.
|
|
|
|
|
native = get_provider_profile("deepseek")
|
|
|
|
|
if native is None:
|
|
|
|
|
return {}, {}
|
|
|
|
|
return native.build_api_kwargs_extras(
|
2026-09-12 19:16:22 -07:00
|
|
|
reasoning_config=reasoning_config, model=m.split("/", 1)[1], **context,
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
2026-09-02 21:04:38 -07:00
|
|
|
class CommandCodeAnthropicProfile(CommandCodeProfile):
|
2026-09-02 11:23:23 -07:00
|
|
|
"""CommandCode — Anthropic Messages API-compatible endpoint."""
|
|
|
|
|
|
|
|
|
|
def fetch_models(
|
|
|
|
|
self, *, api_key: str | None = None, base_url: str | None = None, timeout: float = 8.0
|
|
|
|
|
) -> list[str] | None:
|
|
|
|
|
"""Public /models endpoint, filtered to Anthropic-family models."""
|
2026-09-02 21:04:38 -07:00
|
|
|
all_models = super().fetch_models(api_key=api_key, base_url=base_url, timeout=timeout)
|
|
|
|
|
return None if all_models is None else [m for m in all_models if m.startswith("claude-")]
|
2026-09-02 11:23:23 -07:00
|
|
|
|
|
|
|
|
|
2026-05-26 21:08:01 -04:00
|
|
|
commandcode = CommandCodeProfile(
|
2026-09-02 21:45:13 -07:00
|
|
|
name="commandcode", aliases=("commandcode-chat",), api_mode="chat_completions",
|
2026-09-02 11:23:23 -07:00
|
|
|
# Same key as the anthropic profile; distinct base-URL override vars so each
|
|
|
|
|
# profile renders its own card on the desktop Keys tab (rows keyed by env var).
|
|
|
|
|
env_vars=("COMMANDCODE_API_KEY", "COMMANDCODE_BASE_URL"),
|
2026-09-02 21:45:13 -07:00
|
|
|
display_name="CommandCode", description="CommandCode — 20+ models via OpenAI-compatible API",
|
|
|
|
|
signup_url="https://commandcode.ai/", base_url=_COMMANDCODE_BASE, models_url=_COMMANDCODE_MODELS_URL,
|
2026-05-26 21:08:01 -04:00
|
|
|
fallback_models=(
|
refactor(model-providers): compact reasoning-translation profiles (opencode, kimi, zai, minimax, nous, qwen, custom, upstage, nebius, meta-ai, deepseek, copilot, deepinfra, vertex, gemini), fold catalog tuples
2026-09-02 21:36:03 -07:00
|
|
|
"deepseek/deepseek-v4-pro", "deepseek/deepseek-v4-flash", "Qwen/Qwen3.7-Max", "Qwen/Qwen3.6-Plus",
|
|
|
|
|
"moonshotai/Kimi-K2.6", "zai-org/GLM-5.1", "MiniMaxAI/MiniMax-M2.7", "stepfun/Step-3.5-Flash",
|
|
|
|
|
"xiaomi/mimo-v2.5-pro", "google/gemini-3.5-flash", "gpt-5.5",
|
2026-05-26 21:08:01 -04:00
|
|
|
),
|
|
|
|
|
default_aux_model="deepseek/deepseek-v4-flash",
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
commandcode_anthropic = CommandCodeAnthropicProfile(
|
2026-09-02 21:45:13 -07:00
|
|
|
name="commandcode-anthropic", aliases=("commandcode-claude",), api_mode="anthropic_messages",
|
2026-09-02 11:23:23 -07:00
|
|
|
env_vars=("COMMANDCODE_API_KEY", "COMMANDCODE_ANTHROPIC_BASE_URL"),
|
2026-05-26 21:08:01 -04:00
|
|
|
display_name="CommandCode (Anthropic)",
|
|
|
|
|
description="CommandCode — Claude models via Anthropic Messages API",
|
2026-09-02 21:45:13 -07:00
|
|
|
signup_url="https://commandcode.ai/", base_url=_COMMANDCODE_BASE, models_url=_COMMANDCODE_MODELS_URL,
|
2026-09-02 11:23:23 -07:00
|
|
|
fallback_models=("claude-sonnet-4-6", "claude-opus-4-7", "claude-haiku-4-5-20251001"),
|
2026-05-26 21:08:01 -04:00
|
|
|
default_aux_model="claude-haiku-4-5-20251001",
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
register_provider(commandcode)
|
|
|
|
|
register_provider(commandcode_anthropic)
|