Skip to main content

gproxy_protocol/claude/common/
context_management.rs

1use serde::{Deserialize, Serialize};
2
3use super::{BoolOrStringArray, TypedObject};
4
5#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, gproxy_protocol_macros::WireBuilder)]
6#[cfg_attr(not(feature = "exhaustive"), non_exhaustive)]
7pub struct ContextManagementConfig {
8    #[serde(skip_serializing_if = "Option::is_none")]
9    pub edits: Option<Vec<ContextEdit>>,
10    #[serde(default, flatten, skip_serializing_if = "serde_json::Map::is_empty")]
11    pub rest: serde_json::Map<String, serde_json::Value>,
12}
13
14#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
15#[serde(untagged)]
16#[cfg_attr(not(feature = "exhaustive"), non_exhaustive)]
17pub enum ContextEdit {
18    Known(KnownContextEdit),
19    Unknown(TypedObject),
20}
21
22#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
23#[serde(tag = "type")]
24#[cfg_attr(not(feature = "exhaustive"), non_exhaustive)]
25pub enum KnownContextEdit {
26    #[serde(rename = "clear_tool_uses_20250919")]
27    ClearToolUses {
28        #[serde(skip_serializing_if = "Option::is_none")]
29        clear_at_least: Option<InputTokensValue>,
30        #[serde(skip_serializing_if = "Option::is_none")]
31        clear_tool_inputs: Option<BoolOrStringArray>,
32        #[serde(skip_serializing_if = "Option::is_none")]
33        exclude_tools: Option<Vec<String>>,
34        #[serde(skip_serializing_if = "Option::is_none")]
35        keep: Option<ToolUsesValue>,
36        #[serde(skip_serializing_if = "Option::is_none")]
37        trigger: Option<ContextTrigger>,
38        #[serde(default, flatten, skip_serializing_if = "serde_json::Map::is_empty")]
39        rest: serde_json::Map<String, serde_json::Value>,
40    },
41    #[serde(rename = "clear_thinking_20251015")]
42    ClearThinking {
43        #[serde(skip_serializing_if = "Option::is_none")]
44        keep: Option<ThinkingKeep>,
45        #[serde(default, flatten, skip_serializing_if = "serde_json::Map::is_empty")]
46        rest: serde_json::Map<String, serde_json::Value>,
47    },
48    #[serde(rename = "compact_20260112")]
49    Compact {
50        #[serde(skip_serializing_if = "Option::is_none")]
51        instructions: Option<String>,
52        #[serde(skip_serializing_if = "Option::is_none")]
53        pause_after_compaction: Option<bool>,
54        #[serde(skip_serializing_if = "Option::is_none")]
55        trigger: Option<InputTokensValue>,
56        #[serde(default, flatten, skip_serializing_if = "serde_json::Map::is_empty")]
57        rest: serde_json::Map<String, serde_json::Value>,
58    },
59}
60
61#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, gproxy_protocol_macros::WireBuilder)]
62#[cfg_attr(not(feature = "exhaustive"), non_exhaustive)]
63pub struct InputTokensValue {
64    #[serde(rename = "type")]
65    pub type_: InputTokensValueType,
66    pub value: u64,
67    #[serde(default, flatten, skip_serializing_if = "serde_json::Map::is_empty")]
68    pub rest: serde_json::Map<String, serde_json::Value>,
69}
70
71#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
72#[cfg_attr(not(feature = "exhaustive"), non_exhaustive)]
73pub enum InputTokensValueType {
74    #[serde(rename = "input_tokens")]
75    InputTokens,
76}
77
78#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, gproxy_protocol_macros::WireBuilder)]
79#[cfg_attr(not(feature = "exhaustive"), non_exhaustive)]
80pub struct ToolUsesValue {
81    #[serde(rename = "type")]
82    pub type_: ToolUsesValueType,
83    pub value: u64,
84    #[serde(default, flatten, skip_serializing_if = "serde_json::Map::is_empty")]
85    pub rest: serde_json::Map<String, serde_json::Value>,
86}
87
88#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
89#[cfg_attr(not(feature = "exhaustive"), non_exhaustive)]
90pub enum ToolUsesValueType {
91    #[serde(rename = "tool_uses")]
92    ToolUses,
93}
94
95#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
96#[serde(untagged)]
97#[cfg_attr(not(feature = "exhaustive"), non_exhaustive)]
98pub enum ContextTrigger {
99    InputTokens(InputTokensValue),
100    ToolUses(ToolUsesValue),
101}
102
103#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
104#[serde(untagged)]
105#[cfg_attr(not(feature = "exhaustive"), non_exhaustive)]
106pub enum ThinkingKeep {
107    Object(ThinkingKeepObject),
108    All(ThinkingAllValue),
109}
110
111#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
112#[serde(tag = "type")]
113#[cfg_attr(not(feature = "exhaustive"), non_exhaustive)]
114pub enum ThinkingKeepObject {
115    #[serde(rename = "thinking_turns")]
116    ThinkingTurns {
117        value: u64,
118        #[serde(default, flatten, skip_serializing_if = "serde_json::Map::is_empty")]
119        rest: serde_json::Map<String, serde_json::Value>,
120    },
121    #[serde(rename = "all")]
122    All {
123        #[serde(default, flatten, skip_serializing_if = "serde_json::Map::is_empty")]
124        rest: serde_json::Map<String, serde_json::Value>,
125    },
126}
127
128#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
129#[cfg_attr(not(feature = "exhaustive"), non_exhaustive)]
130pub enum ThinkingAllValue {
131    #[serde(rename = "all")]
132    All,
133}
134
135#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, gproxy_protocol_macros::WireBuilder)]
136#[cfg_attr(not(feature = "exhaustive"), non_exhaustive)]
137pub struct ContextManagementResponse {
138    #[serde(skip_serializing_if = "Option::is_none")]
139    pub applied_edits: Option<Vec<AppliedContextEdit>>,
140    #[serde(default, flatten, skip_serializing_if = "serde_json::Map::is_empty")]
141    pub rest: serde_json::Map<String, serde_json::Value>,
142}
143
144#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
145#[serde(untagged)]
146#[cfg_attr(not(feature = "exhaustive"), non_exhaustive)]
147pub enum AppliedContextEdit {
148    Known(KnownAppliedContextEdit),
149    Unknown(TypedObject),
150}
151
152#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
153#[serde(tag = "type")]
154#[cfg_attr(not(feature = "exhaustive"), non_exhaustive)]
155pub enum KnownAppliedContextEdit {
156    #[serde(rename = "clear_tool_uses_20250919")]
157    ClearToolUses {
158        cleared_input_tokens: u64,
159        cleared_tool_uses: u64,
160        #[serde(default, flatten, skip_serializing_if = "serde_json::Map::is_empty")]
161        rest: serde_json::Map<String, serde_json::Value>,
162    },
163    #[serde(rename = "clear_thinking_20251015")]
164    ClearThinking {
165        cleared_input_tokens: u64,
166        cleared_thinking_turns: u64,
167        #[serde(default, flatten, skip_serializing_if = "serde_json::Map::is_empty")]
168        rest: serde_json::Map<String, serde_json::Value>,
169    },
170}