1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
//! Wire-protocol translation for LLM providers.
//!
//! `causa-protocol` renders `ContextFrame` → provider wire bodies and
//! parses wire responses → kernel `ModelOutput`.
//! `translation::context_frame` is the shared policy walk; the three
//! renderers (`translation::anthropic`, `openai_chat`,
//! `openai_responses`) are thin emitters over it. The crate serves the
//! `causa_kernel::ModelGateway` seam and is consumed by `causa-provider`'s
//! gateways. It is transport-free.
//!
//! [`translation::streaming::StreamDecoder`] incrementally decodes raw SSE bytes
//! into kernel observations and a complete terminal output. [`SseParser`] is
//! the lower-level bounded byte framer. Neither owns HTTP, execution control,
//! retries, event history or a background task.
//!
//! Layering:
//!
//! ```text
//! causa-kernel (facts, ModelGateway seam)
//! <- causa-protocol (render/parse) <- causa-provider
//! ```
//!
//! `causa-protocol` must not depend on reqwest, Axum, or any concrete
//! provider SDK.
//!
//! # Protocol options and wire rendering
//!
//! - **Generation options**: OpenAI Chat renders `max_tokens` as
//! `max_completion_tokens` (or `max_tokens`, by its render option),
//! Responses renders it as `max_output_tokens`, and Anthropic renders it
//! as `max_tokens`. `None` omits the limit on the
//! two OpenAI wires; Anthropic requires the field, so that renderer rejects
//! a missing value before any HTTP.
//! - **Reasoning effort**: a string, written as the host gave it to OpenAI
//! Chat `reasoning_effort`, Responses `reasoning.effort` and Anthropic
//! `output_config.effort`. No value is refused, mapped or combined with
//! another field; which values a model accepts is the host's knowledge.
//! - **Extra request fields**:
//! [`causa_kernel::GenerationOptions::extra_body`] is merged into the
//! body. Objects merge key by key with what the renderer wrote, so
//! `reasoning.summary` joins `reasoning.effort`; any other value the
//! renderer wrote is kept, and arrays are never merged. The rule goes by
//! key name, and `output_schema` is kept whole: a key beside the schema
//! is merged, a key inside it is not. An Anthropic `thinking` object is
//! sent this way.
//! - **Structured outputs**: `output_schema` renders as `response_format` on
//! Chat and `text.format` on Responses; the Anthropic adapter rejects it.
//! - **Prompt cache directives**: [`causa_kernel::CacheDirective::StablePrefix`]
//! renders explicit `cache_control` breakpoints on Anthropic; OpenAI-family
//! providers cache automatically server-side, treating the directive as a no-op.
//! - **Stop values**: Anthropic maps wire `stop_reason`, Chat maps `finish_reason`,
//! and Responses maps `status` (or `status.reason` when status is `incomplete`
//! and carries a reason).
pub use Protocol;
pub use ;