pub struct ValidatedMessageList { /* private fields */ }Expand description
Drop-in Vec replacement that enforces message pair invariants.
All reads (iteration, indexing, len) work through messages().
Mutations are intercepted via validated methods.
Implementations§
Source§impl ValidatedMessageList
impl ValidatedMessageList
Sourcepub fn new(initial: Option<Vec<ApiMessage>>, strict: bool) -> Self
pub fn new(initial: Option<Vec<ApiMessage>>, strict: bool) -> Self
Create a new validated message list.
If initial is provided, bulk-loads without per-message validation
(trusts existing data), then rebuilds pending state.
Sourcepub fn messages(&self) -> &[ApiMessage] ⓘ
pub fn messages(&self) -> &[ApiMessage] ⓘ
Access the underlying messages (read-only).
Sourcepub fn into_inner(self) -> Vec<ApiMessage> ⓘ
pub fn into_inner(self) -> Vec<ApiMessage> ⓘ
Consume self and return the inner Vec.
pub fn len(&self) -> usize
pub fn is_empty(&self) -> bool
Sourcepub fn pending_tool_ids(&self) -> HashSet<String>
pub fn pending_tool_ids(&self) -> HashSet<String>
Tool call IDs still awaiting results.
Sourcepub fn has_pending_tools(&self) -> bool
pub fn has_pending_tools(&self) -> bool
True if in EXPECT_TOOL_RESULTS state.
Sourcepub fn add_user(&mut self, content: &str)
pub fn add_user(&mut self, content: &str)
Append a user message. Auto-completes pending tool results if any.
Sourcepub fn add_assistant(
&mut self,
content: Option<&str>,
tool_calls: Option<Vec<Value>>,
)
pub fn add_assistant( &mut self, content: Option<&str>, tool_calls: Option<Vec<Value>>, )
Append assistant message. If tool_calls present, enters EXPECT_TOOL_RESULTS.
Sourcepub fn add_tool_result(
&mut self,
tool_call_id: &str,
content: &str,
) -> Result<(), String>
pub fn add_tool_result( &mut self, tool_call_id: &str, content: &str, ) -> Result<(), String>
Append tool result. Rejects orphaned IDs not in pending set (in strict mode).
Sourcepub fn add_tool_results_batch(
&mut self,
tool_calls: &[Value],
results_by_id: &HashMap<String, String>,
)
pub fn add_tool_results_batch( &mut self, tool_calls: &[Value], results_by_id: &HashMap<String, String>, )
Batch-add tool results. Fills missing with synthetic errors.
Sourcepub fn replace_all(&mut self, messages: Vec<ApiMessage>)
pub fn replace_all(&mut self, messages: Vec<ApiMessage>)
Replace all messages (e.g., after compaction). Rebuilds pending state.