(data_lines: &[String], event_tx: &Sender<Event>)
| 3680 | } |
| 3681 | |
| 3682 | fn forward_server_event(data_lines: &[String], event_tx: &Sender<Event>) { |
| 3683 | if data_lines.is_empty() { |
| 3684 | return; |
| 3685 | } |
| 3686 | let payload = data_lines.join("\n"); |
| 3687 | let Ok(value) = serde_json::from_str::<serde_json::Value>(&payload) else { |
| 3688 | return; |
| 3689 | }; |
| 3690 | let event_type = value.get("type").and_then(|item| item.as_str()); |
| 3691 | let session_id = value |
| 3692 | .get("sessionID") |
| 3693 | .and_then(|item| item.as_str()) |
| 3694 | .or_else(|| value.get("sessionId").and_then(|item| item.as_str())); |
| 3695 | match event_type { |
| 3696 | Some("session.updated") => { |
| 3697 | let Some(session_id) = session_id else { |
| 3698 | return; |
| 3699 | }; |
| 3700 | let _ = event_tx.send(Event::Custom(CustomEvent::StateChanged( |
| 3701 | StateChange::SessionUpdated(session_id.to_string()), |
| 3702 | ))); |
| 3703 | } |
| 3704 | Some("session.status") => { |
| 3705 | let Some(session_id) = session_id else { |
| 3706 | return; |
| 3707 | }; |
| 3708 | let status_type = value |
| 3709 | .get("status") |
| 3710 | .and_then(|status| status.get("type")) |
| 3711 | .and_then(|item| item.as_str()) |
| 3712 | .or_else(|| value.get("status").and_then(|item| item.as_str())); |
| 3713 | match status_type { |
| 3714 | Some("busy") => { |
| 3715 | let _ = event_tx.send(Event::Custom(CustomEvent::StateChanged( |
| 3716 | StateChange::SessionStatusBusy(session_id.to_string()), |
| 3717 | ))); |
| 3718 | } |
| 3719 | Some("idle") => { |
| 3720 | let _ = event_tx.send(Event::Custom(CustomEvent::StateChanged( |
| 3721 | StateChange::SessionStatusIdle(session_id.to_string()), |
| 3722 | ))); |
| 3723 | } |
| 3724 | Some("retry") => { |
| 3725 | let attempt = value |
| 3726 | .get("status") |
| 3727 | .and_then(|status| status.get("attempt")) |
| 3728 | .and_then(|item| item.as_u64()) |
| 3729 | .and_then(|v| u32::try_from(v).ok()) |
| 3730 | .unwrap_or(0); |
| 3731 | let message = value |
| 3732 | .get("status") |
| 3733 | .and_then(|status| status.get("message")) |
| 3734 | .and_then(|item| item.as_str()) |
| 3735 | .unwrap_or_default() |
| 3736 | .to_string(); |
| 3737 | let next = value |
| 3738 | .get("status") |
| 3739 | .and_then(|status| status.get("next")) |
no test coverage detected