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
98
99
100
101
102
103
104
105
106
107
//! The committed transcript entry's on-disk shape — the one home for it
//! (ARCH §2.3 *Origins and wire framing*, *The transcript writer*).
//!
//! A `messages/NNN-<origin>.json` entry is an **API-shaped message
//! object**: the canonical [`Content`] blocks under `content`, with the
//! provider's token `usage` report as its sibling when the provider
//! reported one:
//!
//! ```json
//! {"content":[{"type":"text","text":"hi"}],"usage":{"input_tokens":5,"output_tokens":3}}
//! ```
//!
//! **A bare array of blocks is equally lawful** — the shape every entry
//! carried before usage rode along, and the shape a tool entry still
//! carries. So the reader answers one question over both — *where do the
//! blocks live* ([`blocks`]) — and absence of `usage` is the general path
//! with empty inputs, never an error (`docs/PRINCIPLES.md`).
//!
//! **Usage is the provider's report, never lernie's arithmetic.** A
//! provider may state one report in installments — Anthropic's
//! `message_start` carries the input side, its terminal `message_delta`
//! the output side — so [`UsageReport`] records each counter *as the
//! provider last reported it* and omits every counter the provider never
//! reported (a `0` would be a lie, brazen's zero-vs-unknown rule). It
//! adds nothing, scales nothing, estimates nothing: the sealed object is
//! what the same call would have returned unstreamed. The fold is over
//! the serialized counter names rather than named fields, so a counter
//! brazen adds under `v=1` (its [`Usage`] is `#[non_exhaustive]`) rides
//! through with no edit here.
//!
//! Spend metering is a *different* fact and keeps its own home: §6/§8
//! bill every attempt segment of the diagnostic `response.json`,
//! including the discarded ones (`crate::prompt::budget`). This entry
//! records only what the committed output itself cost — the authoritative
//! segment's report (§4.4 segment authority).
use ;
use Deserialize;
use ;
/// The provider's usage report for the entry under construction, folded
/// per counter as `usage` events arrive. Empty — the default — is "the
/// provider reported nothing", which seals no `usage` key at all.
pub ;
/// The bytes that open an entry under construction: the object up to
/// its first block. The array stays open until [`close`].
pub
/// The bytes that close a sealed entry: the `content` array, then the
/// provider's `usage` sibling iff any counter was reported.
pub
/// **Where a committed entry's content blocks live** — the one answer,
/// used by every reader (assembly §5, the writer's read-back at commit,
/// the unsettled-tail scan). Harness-written (the staging seal /
/// `commit_tool`, §2.3), so neither lawful shape can fail to parse and a
/// failure is a programmer error, not a reachable state.
pub
/// The two lawful entry shapes (above). Tried in order, so the object
/// shape claims an object and the bare array an array; `usage` and any other
/// sibling is ignored here — no lernie reader consumes it, and the
/// committed bytes are its home for the readers that do.