Files
Ali Khokhar 8d2e5b95f7 Refactor OpenAI Responses into modular adapter facade (#847)
## Summary

- Split monolithic `core/openai_responses/conversion.py` and `sse.py`
into focused protocol modules (input, output, stream, tools, reasoning,
events, etc.) behind an `OpenAIResponsesAdapter` facade.
- Wire `ClaudeProxyService.create_response()` through the adapter
instead of importing conversion helpers directly, tightening the
API/import boundary.
- Add Codex bridging for Responses `custom_tool_call` items and document
the adapter architecture in `ARCHITECTURE.md`.

## Test plan

- [x] `uv run pytest tests/core/openai_responses/
tests/api/test_openai_responses.py tests/cli/test_adapters.py
tests/contracts/test_import_boundaries.py`
- [x] Full CI via `.\scripts\ci.ps1`
2026-06-17 20:19:51 -07:00

26 lines
811 B
Python

"""Translate Anthropic SSE streams into OpenAI Responses SSE streams."""
from __future__ import annotations
from collections.abc import AsyncIterable, AsyncIterator, Mapping
from typing import Any
from .anthropic_sse import iter_sse_events
from .stream_state import ResponsesStreamAssembler
async def iter_responses_sse_from_anthropic(
chunks: AsyncIterable[Any],
request: Mapping[str, Any],
) -> AsyncIterator[str]:
"""Yield Responses SSE events translated from an Anthropic SSE stream."""
assembler = ResponsesStreamAssembler(request)
async for event in iter_sse_events(chunks):
for chunk in assembler.process_anthropic_event(event):
yield chunk
if assembler.terminal:
return
for chunk in assembler.finish_if_needed():
yield chunk