Files
free-claude-code/providers/opencode/client.py
Ali Khokhar fa01c2a3a6 Refactor provider transports into packages (#845)
## Summary
- move provider transport families under `providers/transports/`
- split OpenAI-chat transport into thin transport, stream runner,
tool-call assembly, and recovery modules
- split native Anthropic transport into thin transport, stream runner,
recovery, and HTTP helper modules
- update concrete provider imports, architecture docs, transport import
contracts, version, and lockfile

## Verification
- `uv run pytest tests/providers/test_streaming_errors.py
tests/providers/test_openai_compat_5xx_retry.py
tests/providers/test_anthropic_messages.py
tests/providers/test_anthropic_messages_429_retry.py
tests/providers/test_provider_transport_logging.py
tests/providers/test_gemini.py
tests/providers/test_nvidia_nim_request.py
tests/providers/test_subagent_interception.py
tests/contracts/test_import_boundaries.py`
- `uv run ruff format`
- `./scripts/ci.ps1`
2026-06-17 15:56:19 -07:00

32 lines
1014 B
Python

"""OpenCode Zen provider implementation (OpenAI-compatible Chat Completions)."""
from __future__ import annotations
from typing import Any
from providers.base import ProviderConfig
from providers.defaults import OPENCODE_DEFAULT_BASE
from providers.transports.openai_chat import OpenAIChatTransport
from .request import build_request_body
class OpenCodeProvider(OpenAIChatTransport):
"""OpenCode Zen provider using ``https://opencode.ai/zen/v1/chat/completions``."""
def __init__(self, config: ProviderConfig, provider_name: str = "OPENCODE"):
super().__init__(
config,
provider_name=provider_name,
base_url=config.base_url or OPENCODE_DEFAULT_BASE,
api_key=config.api_key,
)
def _build_request_body(
self, request: Any, thinking_enabled: bool | None = None
) -> dict:
return build_request_body(
request,
thinking_enabled=self._is_thinking_enabled(request, thinking_enabled),
)