use rho_protocol::ContentBlock;
use super::{ChatMedia, TurnPrompt};
pub(super) fn prompt_content(turn: &TurnPrompt, media: &[ChatMedia]) -> Vec<ContentBlock> {
let text = prompt_text(turn);
let mut content = Vec::with_capacity(1 + media.len());
if !text.is_empty() {
content.push(ContentBlock::Text { text });
}
content.extend(media.iter().cloned().map(ChatMedia::wire_block));
content
}
pub(super) fn steer_parts(text: String, media: &[ChatMedia]) -> (String, Vec<ContentBlock>) {
let mut texts = Vec::with_capacity(1 + media.len());
texts.extend((!text.is_empty()).then_some(text));
let mut attachments = Vec::new();
for media in media {
match media {
ChatMedia::TextDocument(document) => texts.push(document.clone().model_text()),
ChatMedia::Image(_) => attachments.push(media.clone().wire_block()),
}
}
(texts.join("\n\n"), attachments)
}
fn prompt_text(turn: &TurnPrompt) -> String {
let Some(skill) = turn.skills.first() else {
return turn.model.clone();
};
let command = format!("/${skill}");
match turn.model.strip_prefix(&format!("/skill:{skill}")) {
Some(args) if args.is_empty() || args.starts_with(char::is_whitespace) => {
format!("{command}{args}")
}
_ if turn.model.is_empty() => command,
_ => format!("{command} {}", turn.model),
}
}
#[cfg(test)]
#[path = "daemon_prompt_tests.rs"]
mod tests;