[Rust Frontend] Make ToolParserOutput a seq of ToolParserEvent to preserve order (#46584)

Signed-off-by: Bugen Zhao <i@bugenzhao.com>
This commit is contained in:
Bugen Zhao
2026-06-25 06:27:07 +00:00
committed by GitHub
parent 77c1d9fe9b
commit 4d3b4b9b01
32 changed files with 1155 additions and 820 deletions
@@ -425,6 +425,18 @@ mod tests {
}
}
fn tool_call_arguments(arguments: &str) -> UnifiedParserOutput {
UnifiedParserOutput {
events: vec![vllm_parser::unified::UnifiedParserEvent::ToolCall(
ToolCallDelta {
tool_index: 0,
name: None,
arguments: arguments.to_string(),
},
)],
}
}
fn combined(first: UnifiedParserOutput, second: UnifiedParserOutput) -> UnifiedParserOutput {
let mut output = first;
output.append(second);
@@ -531,6 +543,38 @@ mod tests {
);
}
#[tokio::test]
async fn unified_stream_emits_tool_arguments_before_trailing_text() {
let events = collect(
ScriptedParser::new([
ScriptedStep::Output(tool_call("get_weather", "")),
ScriptedStep::Output(combined(
tool_call_arguments(r#"{"location":"Paris"}"#),
text(" done"),
)),
]),
vec![decoded_delta("start"), decoded_delta("finish")],
)
.await;
assert_eq!(
events,
vec![
AssistantEvent::ToolCallStart {
id: "call_test".to_string(),
name: "get_weather".to_string(),
},
AssistantEvent::ToolCallArgumentsDelta {
delta: r#"{"location":"Paris"}"#.to_string(),
},
AssistantEvent::TextDelta {
kind: AssistantBlockKind::Text,
delta: " done".to_string(),
},
]
);
}
#[tokio::test]
async fn unified_stream_fallback_keeps_committed_output_and_disables_later_parsing() {
let events = collect(