From 221599e6dbf5c4482582814df358c6848310544d Mon Sep 17 00:00:00 2001 From: "Liu Juanjuan (Helen)" <31027645+liujuanjuan1984@users.noreply.github.com> Date: Mon, 24 Aug 2026 08:21:49 +0000 Subject: [PATCH] refactor: remove high-confidence redundant code --- src/opencode_a2a/auth.py | 6 ------ src/opencode_a2a/extension_negotiation.py | 17 ----------------- src/opencode_a2a/jsonrpc/dispatch.py | 7 ------- src/opencode_a2a/server/agent_card.py | 9 ++++++--- 4 files changed, 6 insertions(+), 33 deletions(-) diff --git a/src/opencode_a2a/auth.py b/src/opencode_a2a/auth.py index a869e52..0973b06 100644 --- a/src/opencode_a2a/auth.py +++ b/src/opencode_a2a/auth.py @@ -67,12 +67,6 @@ def build_static_auth_credentials(settings: Settings) -> tuple[StaticAuthCredent return tuple(credentials) -def has_configured_auth_scheme(settings: Settings, scheme: str) -> bool: - return any( - credential.auth_scheme == scheme for credential in build_static_auth_credentials(settings) - ) - - def authenticate_static_credential( *, credentials: tuple[StaticAuthCredential, ...], diff --git a/src/opencode_a2a/extension_negotiation.py b/src/opencode_a2a/extension_negotiation.py index d9d0c01..1ec09b0 100644 --- a/src/opencode_a2a/extension_negotiation.py +++ b/src/opencode_a2a/extension_negotiation.py @@ -12,30 +12,13 @@ from .a2a_utils import clone_proto from .contracts.extensions import ( INTERRUPT_CALLBACK_EXTENSION_URI, - INTERRUPT_CALLBACK_METHODS, - INTERRUPT_RECOVERY_EXTENSION_URI, - INTERRUPT_RECOVERY_METHODS, MODEL_SELECTION_EXTENSION_URI, - PROVIDER_DISCOVERY_EXTENSION_URI, - PROVIDER_DISCOVERY_METHODS, SESSION_BINDING_EXTENSION_URI, - SESSION_MANAGEMENT_EXTENSION_URI, - SESSION_METHODS, STREAMING_EXTENSION_URI, - WORKSPACE_CONTROL_EXTENSION_URI, - WORKSPACE_CONTROL_METHODS, ) _STREAMING_SHARED_METADATA_KEYS = ("stream", "progress", "usage") -JSONRPC_EXTENSION_URI_BY_METHOD: dict[str, str] = { - **{method: SESSION_MANAGEMENT_EXTENSION_URI for method in SESSION_METHODS.values()}, - **{method: PROVIDER_DISCOVERY_EXTENSION_URI for method in PROVIDER_DISCOVERY_METHODS.values()}, - **{method: INTERRUPT_RECOVERY_EXTENSION_URI for method in INTERRUPT_RECOVERY_METHODS.values()}, - **{method: INTERRUPT_CALLBACK_EXTENSION_URI for method in INTERRUPT_CALLBACK_METHODS.values()}, - **{method: WORKSPACE_CONTROL_EXTENSION_URI for method in WORKSPACE_CONTROL_METHODS.values()}, -} - @dataclass(frozen=True) class ExtensionRequirement: diff --git a/src/opencode_a2a/jsonrpc/dispatch.py b/src/opencode_a2a/jsonrpc/dispatch.py index 91e9872..813624f 100644 --- a/src/opencode_a2a/jsonrpc/dispatch.py +++ b/src/opencode_a2a/jsonrpc/dispatch.py @@ -91,9 +91,7 @@ class ExtensionMethodSpec: class ExtensionMethodRegistry: def __init__(self, specs: Iterable[ExtensionMethodSpec]) -> None: method_map: dict[str, ExtensionMethodSpec] = {} - normalized_specs: list[ExtensionMethodSpec] = [] for spec in specs: - normalized_specs.append(spec) for method in spec.methods: existing = method_map.get(method) if existing is not None: @@ -102,13 +100,8 @@ def __init__(self, specs: Iterable[ExtensionMethodSpec]) -> None: f"{existing.name!r} and {spec.name!r}" ) method_map[method] = spec - self._specs = tuple(normalized_specs) self._method_map = method_map - @property - def specs(self) -> tuple[ExtensionMethodSpec, ...]: - return self._specs - def methods(self) -> frozenset[str]: return frozenset(self._method_map) diff --git a/src/opencode_a2a/server/agent_card.py b/src/opencode_a2a/server/agent_card.py index d722fbd..bd6718e 100644 --- a/src/opencode_a2a/server/agent_card.py +++ b/src/opencode_a2a/server/agent_card.py @@ -13,7 +13,7 @@ SecurityScheme, ) -from ..auth import has_configured_auth_scheme +from ..auth import build_static_auth_credentials from ..config import Settings from ..contracts.extensions import ( AUTHENTICATED_ONLY_EXTENSION_URIS, @@ -483,7 +483,10 @@ def build_agent_card( runtime_profile = build_runtime_profile(settings) security_schemes: dict[str, SecurityScheme] = {} security_requirements: list[SecurityRequirement] = [] - if has_configured_auth_scheme(settings, "bearer"): + configured_auth_schemes = { + credential.auth_scheme for credential in build_static_auth_credentials(settings) + } + if "bearer" in configured_auth_schemes: security_schemes["bearerAuth"] = SecurityScheme( http_auth_security_scheme=HTTPAuthSecurityScheme( description="Bearer token authentication", @@ -492,7 +495,7 @@ def build_agent_card( ) ) security_requirements.append(SecurityRequirement(schemes=cast(Any, {"bearerAuth": {}}))) - if has_configured_auth_scheme(settings, "basic"): + if "basic" in configured_auth_schemes: security_schemes["basicAuth"] = SecurityScheme( http_auth_security_scheme=HTTPAuthSecurityScheme( description="Basic authentication",