In the provider compatibility layer for Gemini (and other providers requiring ), fully support the flow, round-trip, and placeholder fallback of thought_signature.

This commit is contained in:
sunmanbitch
2026-06-04 21:13:55 +08:00
parent 4619375c14
commit b119afcaca
11 changed files with 193 additions and 43 deletions
+13 -3
View File
@@ -37,6 +37,7 @@ pub enum AssistantEvent {
id: String,
name: String,
input: String,
thought_signature: Option<String>,
},
Usage(TokenUsage),
PromptCache(PromptCacheEvent),
@@ -381,7 +382,7 @@ where
.blocks
.iter()
.filter_map(|block| match block {
ContentBlock::ToolUse { id, name, input } => {
ContentBlock::ToolUse { id, name, input, .. } => {
Some((id.clone(), name.clone(), input.clone()))
}
_ => None,
@@ -741,9 +742,9 @@ fn build_assistant_message(
});
}
AssistantEvent::TextDelta(delta) => text.push_str(&delta),
AssistantEvent::ToolUse { id, name, input } => {
AssistantEvent::ToolUse { id, name, input, thought_signature } => {
flush_text_block(&mut text, &mut blocks);
blocks.push(ContentBlock::ToolUse { id, name, input });
blocks.push(ContentBlock::ToolUse { id, name, input, thought_signature });
}
AssistantEvent::Usage(value) => usage = Some(value),
AssistantEvent::PromptCache(event) => prompt_cache_events.push(event),
@@ -880,6 +881,7 @@ mod tests {
id: "tool-1".to_string(),
name: "add".to_string(),
input: "2,2".to_string(),
thought_signature: None,
},
AssistantEvent::Usage(TokenUsage {
input_tokens: 20,
@@ -1046,6 +1048,7 @@ mod tests {
id: "tool-1".to_string(),
name: "blocked".to_string(),
input: "secret".to_string(),
thought_signature: None,
},
AssistantEvent::MessageStop,
])
@@ -1091,6 +1094,7 @@ mod tests {
id: "tool-1".to_string(),
name: "blocked".to_string(),
input: r#"{"path":"secret.txt"}"#.to_string(),
thought_signature: None,
},
AssistantEvent::MessageStop,
])
@@ -1153,6 +1157,7 @@ mod tests {
id: "tool-1".to_string(),
name: "blocked".to_string(),
input: r#"{"path":"secret.txt"}"#.to_string(),
thought_signature: None,
},
AssistantEvent::MessageStop,
])
@@ -1213,6 +1218,7 @@ mod tests {
id: "tool-1".to_string(),
name: "add".to_string(),
input: r#"{"lhs":2,"rhs":2}"#.to_string(),
thought_signature: None,
},
AssistantEvent::MessageStop,
]),
@@ -1288,6 +1294,7 @@ mod tests {
id: "tool-1".to_string(),
name: "fail".to_string(),
input: r#"{"path":"README.md"}"#.to_string(),
thought_signature: None,
},
AssistantEvent::MessageStop,
]),
@@ -1755,6 +1762,7 @@ mod tests {
id: "tool-1".to_string(),
name: "echo".to_string(),
input: "payload".to_string(),
thought_signature: None,
},
AssistantEvent::MessageStop,
];
@@ -1778,6 +1786,7 @@ mod tests {
id: "tool-1".to_string(),
name: "echo".to_string(),
input: "payload".to_string(),
thought_signature: None,
},
]
);
@@ -1811,6 +1820,7 @@ mod tests {
id: "tool-1".to_string(),
name: "echo".to_string(),
input: "payload".to_string(),
thought_signature: None,
},
AssistantEvent::MessageStop,
])