pub enum DeltaPart {
Text {
text: String,
},
ToolCall {
partial_json: Value,
},
InputJson {
partial_json: String,
},
}Expand description
A delta (incremental update) for content within a streaming response.
Each variant represents a different kind of incremental data that the API sends. Consumers should append the payload to the appropriate in-progress part.
§Variants
Text— Append to the text buffer for text parts.ToolCall— Append to the JSON buffer for tool-call parts.InputJson— Append to the JSON buffer (raw string form).
§Example
use loopctl::stream::DeltaPart;
let delta_content = DeltaPart::Text { text: "hello".to_string() };
let mut buffer = String::new();
let mut json_buf = String::new();
match &delta_content {
DeltaPart::Text { text } => buffer.push_str(text),
DeltaPart::InputJson { partial_json } => json_buf.push_str(partial_json),
DeltaPart::ToolCall { partial_json } => {
if let Some(s) = partial_json.as_str() {
json_buf.push_str(s);
}
}
}Variants§
Text
Text delta — append to the existing text content.
Emitted for text parts. Each delta contains a small fragment of the final text output.
Serialized as "type":"text_delta" with a "text" field.
Fields
ToolCall
Tool-call input delta — append to the JSON input.
Emitted for tool-call parts. Each delta contains
a fragment of the tool’s JSON input, which should be
concatenated and parsed once PartStop arrives.
Serialized as "type":"tool_call_delta" with a "partial_json" field.
Fields
partial_json: ValueA JSON value fragment to append to the tool input.
Typically a string that forms part of the final JSON
when concatenated with all prior deltas. Use
serde_json::from_str on the concatenated result
after the part completes.
InputJson
Partial JSON input delta — append to the tool input buffer.
Similar to ToolCall but carries a raw
string fragment rather than a JSON value. Concatenate all
fragments and parse as JSON when the part ends.
Serialized as "type":"input_json_delta" with a "partial_json" field.