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
//! Data-URL parsing utility shared across the SDK.
/// Parses a data URL, returning `(full_mime, base64_payload)`.
///
/// Expects the format `data:{type}/{subtype};base64,{payload}` and
/// validates that **the entire input is a single data URL** — the
/// payload must be exclusively standard base64 characters
/// (`[A-Za-z0-9+/=]`) and the mime carries no whitespace. That
/// rules out strings where a data-URL prefix is followed by
/// unrelated text (e.g. a tool output that happens to start with
/// `data:image/png;base64,XYZ\nfollowed by prose…`); those round-
/// trip as `None` so callers reliably pass them through as text.
///
/// Returns `None` for:
/// - Strings missing the `data:` prefix (including any leading
/// whitespace or content before it).
/// - Strings missing the `;base64,` marker.
/// - Strings whose payload contains anything outside the standard
/// base64 alphabet (newlines, spaces, trailing prose, etc.).
/// - Strings whose mime portion contains ASCII whitespace.
///
/// `#[inline]` because this is on the hot path of every MCP
/// content-block conversion (`From<ContentBlock>`,
/// `RichContentPart::from_text_or_data_url`, and the per-leaf
/// `file_content` extraction during log writes) and the body is
/// a handful of cheap string ops — the call overhead would be a
/// measurable fraction of the work.
/// True for bytes in the standard base64 alphabet
/// (`[A-Za-z0-9+/=]`). Excludes whitespace and every URL-safe or
/// padding-variant character — data URLs are required to use the
/// standard alphabet, and rejecting anything else is exactly what
/// makes [`parse_data_url`] refuse to swallow non-data-URL content.