session_info.rs (1368B)
1 /// Session info parsing utilities for Claude backend responses. 2 use crate::messages::SessionInfo; 3 4 /// Parse a System message into SessionInfo 5 pub fn parse_session_info(system_msg: &claude_agent_sdk_rs::SystemMessage) -> SessionInfo { 6 let data = &system_msg.data; 7 8 // Extract slash_commands from data 9 let slash_commands = data 10 .get("slash_commands") 11 .and_then(|v| v.as_array()) 12 .map(|arr| { 13 arr.iter() 14 .filter_map(|v| v.as_str().map(String::from)) 15 .collect() 16 }) 17 .unwrap_or_default(); 18 19 // Extract agents from data 20 let agents = data 21 .get("agents") 22 .and_then(|v| v.as_array()) 23 .map(|arr| { 24 arr.iter() 25 .filter_map(|v| v.as_str().map(String::from)) 26 .collect() 27 }) 28 .unwrap_or_default(); 29 30 // Extract CLI version 31 let cli_version = data 32 .get("claude_code_version") 33 .and_then(|v| v.as_str()) 34 .map(String::from); 35 36 SessionInfo { 37 tools: system_msg.tools.clone().unwrap_or_default(), 38 model: system_msg.model.clone(), 39 permission_mode: system_msg.permission_mode.clone(), 40 slash_commands, 41 agents, 42 cli_version, 43 cwd: system_msg.cwd.clone(), 44 claude_session_id: system_msg.session_id.clone(), 45 } 46 }