tool_parser/types.rs
1use serde::{Deserialize, Serialize};
2
3/// Parsed tool call from model output
4#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
5pub struct ToolCall {
6 /// Function call details
7 pub function: FunctionCall,
8}
9
10/// Function call within a tool call
11#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
12pub struct FunctionCall {
13 /// Name of the function to call
14 pub name: String,
15 /// Arguments as JSON string
16 pub arguments: String,
17}
18
19/// Simple partial tool call for streaming
20#[derive(Debug, Clone)]
21pub struct PartialToolCall {
22 /// Tool name (if parsed)
23 pub name: Option<String>,
24 /// Buffer for accumulating arguments
25 pub arguments_buffer: String,
26 /// Start position in the input buffer
27 pub start_position: usize,
28 /// Whether the name has been sent (for streaming)
29 pub name_sent: bool,
30 /// Arguments already streamed
31 pub streamed_args: String,
32}
33
34/// Result of streaming parse operation (matches Python StreamingParseResult)
35#[derive(Debug, Clone, Default)]
36pub struct StreamingParseResult {
37 /// Normal text that's not part of tool calls
38 pub normal_text: String,
39 /// Tool call items parsed from the chunk
40 pub calls: Vec<ToolCallItem>,
41}
42
43/// Simple encapsulation of parsed tool call for streaming (matches Python ToolCallItem)
44#[derive(Debug, Clone)]
45pub struct ToolCallItem {
46 /// Tool index in the array
47 pub tool_index: usize,
48 /// Tool name (only present on first chunk)
49 pub name: Option<String>,
50 /// Incremental JSON arguments
51 pub parameters: String,
52}