| 1914 | } |
| 1915 | |
| 1916 | fn collect_pending_subtasks(message: &SessionMessage) -> Vec<PendingSubtask> { |
| 1917 | let metadata_by_id: HashMap<String, (String, String, String)> = message |
| 1918 | .metadata |
| 1919 | .get("pending_subtasks") |
| 1920 | .and_then(|v| v.as_array()) |
| 1921 | .map(|items| { |
| 1922 | items |
| 1923 | .iter() |
| 1924 | .filter_map(|item| { |
| 1925 | let id = item.get("id").and_then(|v| v.as_str())?.to_string(); |
| 1926 | let agent = item |
| 1927 | .get("agent") |
| 1928 | .and_then(|v| v.as_str()) |
| 1929 | .unwrap_or("general") |
| 1930 | .to_string(); |
| 1931 | let prompt = item |
| 1932 | .get("prompt") |
| 1933 | .and_then(|v| v.as_str()) |
| 1934 | .unwrap_or("") |
| 1935 | .to_string(); |
| 1936 | let description = item |
| 1937 | .get("description") |
| 1938 | .and_then(|v| v.as_str()) |
| 1939 | .unwrap_or("") |
| 1940 | .to_string(); |
| 1941 | Some((id, (agent, prompt, description))) |
| 1942 | }) |
| 1943 | .collect() |
| 1944 | }) |
| 1945 | .unwrap_or_default(); |
| 1946 | |
| 1947 | message |
| 1948 | .parts |
| 1949 | .iter() |
| 1950 | .enumerate() |
| 1951 | .filter_map(|(part_index, part)| match &part.part_type { |
| 1952 | PartType::Subtask { |
| 1953 | id, |
| 1954 | description, |
| 1955 | status, |
| 1956 | } if status == "pending" => { |
| 1957 | let (agent, prompt, meta_description) = metadata_by_id |
| 1958 | .get(id) |
| 1959 | .cloned() |
| 1960 | .unwrap_or_else(|| (id.clone(), description.clone(), description.clone())); |
| 1961 | let description = if meta_description.is_empty() { |
| 1962 | description.clone() |
| 1963 | } else { |
| 1964 | meta_description |
| 1965 | }; |
| 1966 | let prompt = if prompt.trim().is_empty() { |
| 1967 | description.clone() |
| 1968 | } else { |
| 1969 | prompt |
| 1970 | }; |
| 1971 | Some(PendingSubtask { |
| 1972 | part_index, |
| 1973 | subtask_id: id.clone(), |