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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
//! `anthropic_messages` ingress: Anthropic `POST /v1/messages` request JSON ⇄
//! the canonical model — the exact inverse of the egress `protocol::anthropic`
//! adapter read right-to-left (anthropic-messages spec). `decode` inverts §2's
//! request projection (dialect body → `CanonicalRequest`); `encode` inverts §3's
//! response projection (canonical events → the anthropic-native SSE stream with
//! `message_start`/`content_block_*`/`message_delta`/`message_stop` event framing,
//! plus §4's error envelope). Two anthropic-specific narrowings this dialect
//! discovers (documented, never silent — ingress.md §12):
//!
//! - **The replay stash (§5) is IDLE here.** Anthropic natively carries thinking
//! `signature`, `redacted_thinking`, and server-tool blocks in-band, so the
//! encoder emits them as real wire content blocks (never stash writes) and the
//! decoder reads the client's echoed blocks straight off the request. The wire
//! `thinking` knob rides `extra` (there is no clean `budget→effort` inverse), so
//! `req.reasoning` stays `None` and the §5 `thinking_replay` adaptation never
//! fires — the machinery is reused untouched, simply un-engaged for this dialect.
//! - **The error envelope carries no numeric status.** Anthropic's `{"type":"error",
//! "error":{"type","message"}}` names only a coarse `error.type` FAMILY, so a
//! specific upstream status (503) projects to the nearest family (`api_error`) and
//! re-decodes to that family's canonical status (500). The precise status still
//! rides the HTTP layer (`IngressState::status`, the listener's status line, §9);
//! only the in-band `error.type` is coarse (§4.2 read in reverse).
//!
//! Lossy projections are honest (ingress.md §2): known dialect fields land on the
//! typed canonical fields; unknown TOP-LEVEL keys (`thinking`, `metadata`, `top_k`,
//! `service_tier`, `container`, …) ride `req.extra` verbatim; per-block `cache_control`
//! marks are the encoder's own automatic policy (anthropic-messages §2.10) with no
//! canonical home, so the decoder ignores them (the tolerant-reader stance). Structural
//! impossibilities reject with `ParseInput` (rung 4, §3), naming the offending path.
pub use decode_request;
pub use encode_response;
pub use AnthAcc;
use ;
use IngressError;
/// A rung-4 rejection (ingress.md §3): `ParseInput`, named, before any round-trip.
/// The common wrong-shape rejection: `path` must be `want`.
/// Required string at `path` — absence and a wrong type are the same missing fact.
/// Required object at `path`.
/// Required array at `path`.
/// Optional string: absent and `null` are one absence.
/// A `u32` wire field (the token bound); floats and negatives are shapeless here.
/// An `f32` wire field (the sampling knobs).