(session: &AgentSession, event: &TurnEvent)
| 1254 | } |
| 1255 | |
| 1256 | fn response_text(session: &AgentSession, event: &TurnEvent) -> Option<String> { |
| 1257 | let raw = event.raw_json.as_ref(); |
| 1258 | let from_payload = |key: &str| -> Option<String> { |
| 1259 | raw.and_then(|value| value.get(key)) |
| 1260 | .and_then(serde_json::Value::as_str) |
| 1261 | .map(str::trim) |
| 1262 | .filter(|text| !text.is_empty()) |
| 1263 | .map(ToOwned::to_owned) |
| 1264 | }; |
| 1265 | from_payload("last_assistant_message") |
| 1266 | .or_else(|| from_payload("prompt_response")) |
| 1267 | .or_else(|| from_payload("response")) |
| 1268 | .or_else(|| { |
| 1269 | let path = session.transcript_path.as_ref()?; |
| 1270 | let data = std::fs::read(path).ok()?; |
| 1271 | transcript::last_assistant_text( |
| 1272 | &data, |
| 1273 | transcript::format_for_agent(&session.agent_name), |
| 1274 | ) |
| 1275 | }) |
| 1276 | } |
| 1277 | |
| 1278 | #[cfg(test)] |
| 1279 | mod generic_context_tests { |
no test coverage detected