Files
imeai-aKode/akode-rs/context-fragments/src/answered_question.rs
andrea.difonzo 7c1c6dfa8d Rinomina: crate akode-*, cartelle akode-rs/ e akode-cli/, binario akode, ~/.akode, AKODE_* (A)
Riapplica la fase 5 di aKode (86e7c72e) sulla base ripulita:
- crate codex-* -> akode-*, codex-rs -> akode-rs, codex-cli -> akode-cli, binario e ausiliari akode;
- ~/.codex -> ~/.akode, CODEX_HOME -> AKODE_HOME, variabili CODEX_* -> AKODE_*, .codex/ -> .akode/ di progetto;
  nessun fallback a ~/.codex o a CODEX_*;
- testi per l'utente "Codex" -> "aKode"; testi verso il modello e istruzioni di sistema invariati;
- snapshot insta rinominati (non ancora rigenerati).
I conflitti con la base ripulita sono stati risolti riapplicando la rinomina ai file senza le
funzioni di imeAI (script di mappa dei token per file).

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
2026-11-17 12:37:52 +01:00

63 lines
2.0 KiB
Rust

//! Async answers use the desktop's existing reply envelope and stable question identity.
//! Model-authored framing is bounded; oversized identities use the previous plain-text format.
use super::ContextualUserFragment;
use akode_protocol::models::ContentItem;
use akode_protocol::models::ContentItemKind;
use akode_protocol::models::input_text;
/// Identifies an answered question without repeating an unbounded model-authored prompt.
pub struct AnsweredQuestion<'a> {
question_id: Option<&'a str>,
question: String,
answer: &'a str,
}
impl<'a> AnsweredQuestion<'a> {
pub fn new(question_id: &'a str, question: &str, answer: &'a str) -> Self {
let end = question.floor_char_boundary(question.len().min(512));
Self {
question_id: (question_id.len() <= 512).then_some(question_id),
question: question[..end].replace(['\n', '\r'], " "),
answer,
}
}
}
impl ContextualUserFragment for AnsweredQuestion<'_> {
fn content_kind(&self) -> ContentItemKind {
ContentItemKind("user.answered_question".into())
}
fn role(&self) -> &'static str {
"user"
}
fn markers(&self) -> (&'static str, &'static str) {
if self.question_id.is_some() {
Self::type_markers()
} else {
("", "")
}
}
fn type_markers() -> (&'static str, &'static str) {
(
"<send_user_message_question_reply>",
"</send_user_message_question_reply>",
)
}
fn body(&self) -> ContentItem {
let Some(question_id) = self.question_id else {
return input_text(format!("> {}\n\n{}", self.question, self.answer));
};
let replies = serde_json::json!([{
"answer": self.answer,
"question": self.question,
"questionItemId": question_id,
}]);
input_text(format!("\n{replies}\n"))
}
}
#[cfg(test)]
#[path = "answered_question_tests.rs"]
mod tests;