(session: &AgentSession, event: &TurnEvent)
| 919 | } |
| 920 | |
| 921 | fn response_text(session: &AgentSession, event: &TurnEvent) -> Option<String> { |
| 922 | let raw = event.raw_json.as_ref(); |
| 923 | let from_payload = |key: &str| -> Option<String> { |
| 924 | raw.and_then(|value| value.get(key)) |
| 925 | .and_then(serde_json::Value::as_str) |
| 926 | .map(str::trim) |
| 927 | .filter(|text| !text.is_empty()) |
| 928 | .map(ToOwned::to_owned) |
| 929 | }; |
| 930 | from_payload("last_assistant_message") |
| 931 | .or_else(|| from_payload("prompt_response")) |
| 932 | .or_else(|| from_payload("response")) |
| 933 | .or_else(|| { |
| 934 | let path = session.transcript_path.as_ref()?; |
| 935 | let data = std::fs::read(path).ok()?; |
| 936 | transcript::last_assistant_text( |
| 937 | &data, |
| 938 | transcript::format_for_agent(&session.agent_name), |
| 939 | ) |
| 940 | }) |
| 941 | } |
| 942 | |
| 943 | /// Extract the generic end-of-turn todo snapshot supplied by current agent |
| 944 | /// hooks. Preserve an upstream stable `id` when present. Agents that omit IDs |
no test coverage detected