| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091 |
- """GitHub Copilot ACP provider profile.
- copilot-acp does not speak OpenAI-over-HTTP: it drives an external ACP subprocess over
- stdio, so the profile supplies its own client via :meth:`ProviderProfile.create_client`.
- Registered by the plugin's top-level ``__init__`` next to the ``copilot`` profile.
- """
- from typing import Any
- from providers.base import ProviderProfile
- from .auth_rows import AUTH_ROW_FIELDS
- from .catalog import acp_picker_catalog, clear_session_memo
- from .picker import PICKER_FIELDS
- from .setup import SETUP_FIELDS
- class CopilotACPProfile(ProviderProfile):
- """GitHub Copilot ACP — external process, no REST models endpoint."""
- def external_auth_evidence(self) -> tuple[bool, str | None] | None:
- """Sign-in evidence without spawning the CLI: a supported env token only; the CLI's own token
- files are never read (rules owned by the sibling ``copilot`` credentials module)."""
- from ..copilot.credentials import copilot_cli_auth_evidence
- return copilot_cli_auth_evidence()
- def create_client(self, **client_kwargs: Any) -> Any:
- """Build the ACP stdio shim rather than an HTTP client."""
- from .client import CopilotACPClient
- return CopilotACPClient(**client_kwargs)
- def fetch_models(
- self, *, api_key: str | None = None, base_url: str | None = None, timeout: float = 15.0
- ) -> list[str] | None:
- """Enabled models advertised by a short-lived signed-in ACP session (``session/new``).
- The CLI may keep its login in an OS credential store with no token Hermes can reuse, so
- the session is the only source that reflects the account's enablement. ``api_key`` /
- ``base_url`` are ignored: the subprocess owns auth. None when the CLI is missing, refuses
- ``--acp``, or the probe fails/times out — callers fall back to their next source.
- """
- from hermes_cli.auth import resolve_external_process_provider_credentials
- try:
- creds = resolve_external_process_provider_credentials(self.name)
- if not str(creds.get("base_url") or "").startswith("acp://"):
- return None
- client = self.create_client(
- api_key=creds.get("api_key"), base_url=creds.get("base_url"),
- command=creds.get("command"), args=creds.get("args"))
- return client.list_models(timeout_seconds=timeout) or None
- except Exception:
- # Missing CLI (AuthError), refused --acp / failed spawn (RuntimeError), probe
- # timeout — the base fetch_models contract is "None if the fetch failed".
- return None
- def live_context_length(self, model: str, *, api_key: str = "", base_url: str = "") -> int | None:
- """Same account catalog as the HTTP ``copilot`` provider (lane L4 seam)."""
- from providers import get_provider_profile
- copilot = get_provider_profile("copilot")
- return copilot.live_context_length(model, api_key=api_key, base_url=base_url) if copilot else None
- def invalidate_catalog_cache(self) -> None:
- clear_session_memo()
- def normalize_model_id(self, model: str, *, api_key: str = "") -> str | None:
- """Copilot id space; the ACP marker key never reaches the HTTP catalog."""
- from providers import get_provider_profile
- copilot = get_provider_profile("copilot")
- return copilot.normalize_model_id(model) if copilot else None
- copilot_acp = CopilotACPProfile(
- name="copilot-acp", aliases=("github-copilot-acp", "copilot-acp-agent"),
- api_mode="chat_completions", # ACP subprocess uses chat_completions routing
- env_vars=(), # Managed by ACP subprocess
- base_url="acp://copilot", # ACP internal scheme
- auth_type="external_process",
- # How to launch the CLI; env var names predate this profile (formerly hardcoded in
- # hermes_cli/auth.py), so existing setups keep working.
- process_command="copilot",
- process_args=("--acp", "--stdio"),
- process_command_env_vars=("HERMES_COPILOT_ACP_COMMAND", "COPILOT_CLI_PATH"),
- process_args_env_var="HERMES_COPILOT_ACP_ARGS",
- picker_catalog=acp_picker_catalog, static_models=("copilot-acp",),
- **SETUP_FIELDS, **PICKER_FIELDS, **AUTH_ROW_FIELDS,
- )
|