llm_tool/types/truncation/placeholder.rs
1//! Placeholder definitions and substitution tokens for marker templates.
2
3/// Named placeholders supported in custom marker templates.
4#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
5pub enum MarkerPlaceholder {
6 /// Number of bytes omitted from the middle (`"{omitted_bytes}"`).
7 OmittedBytes,
8 /// Total byte length of the original un-truncated input (`"{original_bytes}"`).
9 OriginalBytes,
10 /// Starting byte offset in original input where truncation began (`"{offset_start}"`).
11 OffsetStart,
12 /// Ending byte offset in original input where truncation ended (`"{offset_end}"`).
13 OffsetEnd,
14 /// Typed reference handle for recall (`"{ref}"`).
15 SpillRef,
16}
17
18impl MarkerPlaceholder {
19 /// Canonical token string for [`MarkerPlaceholder::OmittedBytes`].
20 pub const TOKEN_OMITTED_BYTES: &'static str = "{omitted_bytes}";
21 /// Canonical token string for [`MarkerPlaceholder::OriginalBytes`].
22 pub const TOKEN_ORIGINAL_BYTES: &'static str = "{original_bytes}";
23 /// Canonical token string for [`MarkerPlaceholder::OffsetStart`].
24 pub const TOKEN_OFFSET_START: &'static str = "{offset_start}";
25 /// Canonical token string for [`MarkerPlaceholder::OffsetEnd`].
26 pub const TOKEN_OFFSET_END: &'static str = "{offset_end}";
27 /// Canonical token string for [`MarkerPlaceholder::SpillRef`].
28 pub const TOKEN_SPILL_REF: &'static str = "{ref}";
29
30 /// Legacy deprecated placeholder `{count}` (alias of `{omitted_bytes}`).
31 pub const DEPRECATED_COUNT: &'static str = "{count}";
32 /// Legacy deprecated placeholder `{bytes}` (alias of `{omitted_bytes}`).
33 pub const DEPRECATED_BYTES: &'static str = "{bytes}";
34 /// Legacy deprecated placeholder `<N>` (alias of `{omitted_bytes}`).
35 pub const DEPRECATED_N: &'static str = "<N>";
36
37 /// Return the canonical placeholder token string.
38 #[must_use]
39 pub const fn token(&self) -> &'static str {
40 match self {
41 Self::OmittedBytes => Self::TOKEN_OMITTED_BYTES,
42 Self::OriginalBytes => Self::TOKEN_ORIGINAL_BYTES,
43 Self::OffsetStart => Self::TOKEN_OFFSET_START,
44 Self::OffsetEnd => Self::TOKEN_OFFSET_END,
45 Self::SpillRef => Self::TOKEN_SPILL_REF,
46 }
47 }
48}