(
&self,
input: &PromptInput,
session: &mut Session,
)
| 170 | } |
| 171 | |
| 172 | pub async fn create_user_message( |
| 173 | &self, |
| 174 | input: &PromptInput, |
| 175 | session: &mut Session, |
| 176 | ) -> anyhow::Result<()> { |
| 177 | // Collect text parts for the primary message |
| 178 | let text = input |
| 179 | .parts |
| 180 | .iter() |
| 181 | .filter_map(|p| match p { |
| 182 | PartInput::Text { text } => Some(text.clone()), |
| 183 | _ => None, |
| 184 | }) |
| 185 | .collect::<Vec<_>>() |
| 186 | .join("\n"); |
| 187 | |
| 188 | let has_non_text = input |
| 189 | .parts |
| 190 | .iter() |
| 191 | .any(|p| !matches!(p, PartInput::Text { .. })); |
| 192 | |
| 193 | if text.is_empty() && !has_non_text { |
| 194 | return Err(anyhow::anyhow!("No content in prompt")); |
| 195 | } |
| 196 | |
| 197 | let project_root = session.directory.clone(); |
| 198 | |
| 199 | // Create the user message with text (or empty if only non-text parts) |
| 200 | let msg = if text.is_empty() { |
| 201 | session.add_user_message(" ") |
| 202 | } else { |
| 203 | session.add_user_message(&text) |
| 204 | }; |
| 205 | |
| 206 | // Add non-text parts to the message |
| 207 | for part in &input.parts { |
| 208 | match part { |
| 209 | PartInput::Text { .. } => {} // already handled above |
| 210 | PartInput::File { |
| 211 | url, |
| 212 | filename, |
| 213 | mime, |
| 214 | } => { |
| 215 | self.add_file_part( |
| 216 | msg, |
| 217 | url, |
| 218 | filename.as_deref(), |
| 219 | mime.as_deref(), |
| 220 | &project_root, |
| 221 | ) |
| 222 | .await; |
| 223 | } |
| 224 | PartInput::Agent { name } => { |
| 225 | msg.add_agent(name.clone()); |
| 226 | // Add synthetic text instructing the LLM to invoke the agent |
| 227 | msg.add_text(format!( |
| 228 | "Use the above message and context to generate a prompt and call the task tool with subagent: {}", |
| 229 | name |
no test coverage detected