feat: Add LICENSE file and refactor MITM response handling and tracing.

This commit is contained in:
Nikketryhard
2026-02-18 02:43:05 -06:00
parent c0c12de83c
commit ad0aa1556c
26 changed files with 1132 additions and 569 deletions

View File

@@ -133,7 +133,8 @@ impl StreamingAccumulator {
let args = fc["args"].clone();
// thoughtSignature is a SIBLING of functionCall in the part,
// not nested inside functionCall
let thought_signature = part.get("thoughtSignature")
let thought_signature = part
.get("thoughtSignature")
.and_then(|v| v.as_str())
.map(|s| s.to_string());
info!(
@@ -155,7 +156,9 @@ impl StreamingAccumulator {
// Capture non-thinking response text
else {
// Capture thoughtSignature from response parts (not function call parts)
if let Some(sig) = part.get("thoughtSignature").and_then(|v| v.as_str()) {
if let Some(sig) =
part.get("thoughtSignature").and_then(|v| v.as_str())
{
self.thinking_signature = Some(sig.to_string());
}
if let Some(text) = part["text"].as_str() {
@@ -619,7 +622,10 @@ data: {"response": {"candidates": [{"content": {"role": "model","parts": [{"text
let event = "data: {\"response\": {\"candidates\": [{\"content\": {\"role\": \"model\", \"parts\": [{\"functionCall\": {\"name\": \"read_file\", \"args\": {\"path\": \"/foo\"}}}]}, \"finishReason\": \"FUNCTION_CALL\"}], \"usageMetadata\": {\"promptTokenCount\": 50, \"candidatesTokenCount\": 5, \"totalTokenCount\": 55}, \"modelVersion\": \"gemini-3-flash\"}}\n";
parse_streaming_chunk(event, &mut acc);
assert!(acc.is_complete, "FUNCTION_CALL finishReason should set is_complete");
assert!(
acc.is_complete,
"FUNCTION_CALL finishReason should set is_complete"
);
assert_eq!(acc.stop_reason, Some("FUNCTION_CALL".to_string()));
assert_eq!(acc.function_calls.len(), 1);
assert_eq!(acc.function_calls[0].name, "read_file");
@@ -633,7 +639,10 @@ data: {"response": {"candidates": [{"content": {"role": "model","parts": [{"text
let event = "data: {\"response\": {\"candidates\": [{\"content\": {\"role\": \"model\", \"parts\": [{\"text\": \"truncated...\"}]}, \"finishReason\": \"MAX_TOKENS\"}], \"usageMetadata\": {\"promptTokenCount\": 50, \"candidatesTokenCount\": 100, \"totalTokenCount\": 150}}}\n";
parse_streaming_chunk(event, &mut acc);
assert!(acc.is_complete, "MAX_TOKENS finishReason should set is_complete");
assert!(
acc.is_complete,
"MAX_TOKENS finishReason should set is_complete"
);
assert_eq!(acc.stop_reason, Some("MAX_TOKENS".to_string()));
assert_eq!(acc.response_text, "truncated...");
}