feat: add image attachments for vision models
ci / checks (push) Successful in 56s
ci / test (push) Successful in 1m1s
ci / chart (push) Successful in 6s
ci / web (push) Successful in 29s
ci / docker (push) Successful in 2m37s
ci / publish-edge-image (push) Successful in 11s
ci / publish-edge-chart (push) Successful in 4s

A chat line can carry up to four images, each capped at 5 MB and
sniffed from its bytes. Uploads go to a room route first, the message
references the ids, and the bytes are served back to members; an
upload no message claims within an hour is swept on the next send.

Images only make sense when the model can look at them, and the
catalog's answer is tri-state, so the gate is a stored fact, not a
guess: the provider listing remembers supports_vision per kind and
model, the upload and send routes refuse when the room's effective
model is not a known vision model, and the composer hides the attach
button on the same fact, which rides the room payload. At turn time
the fact goes to the host agent, which sends the blocks on a vision
model and leaves a note where each image was on the rest.
This commit is contained in:
vhaudiquet committed 2026-12-01 21:59:53 +01:00
1 parent acc545ede7
commit 2e17e7463c
18 files changed
+624 -46

No files matched your search

+36 -1
View File
@@ -26,6 +26,8 @@ pub struct TurnConfig {
pub workspace: String,
pub repo_url: Option<String>,
pub model: String,
/// The model's stored vision fact; `None` is unknown, not no.
pub supports_vision: Option<bool>,
pub max_turn_steps: u32,
pub absorbed_seq: i64,
pub seeded: bool,
@@ -135,12 +137,14 @@ pub fn load_turn_config(state: &Shared, room_id: &str) -> AppResult<TurnConfig>
if model.trim().is_empty() {
return Err(AppError::bad_request("room has no model selected"));
}
let supports_vision = crate::util::model_supports_vision(&conn, &kind, &model);
Ok(TurnConfig {
room_id: room_id.to_owned(),
room_name: name,
workspace,
repo_url,
model,
supports_vision,
max_turn_steps: max_steps.max(1) as u32,
absorbed_seq: absorbed,
seeded: seeded != 0,
@@ -358,7 +362,7 @@ pub fn build_agent(state: &Shared, config: &TurnConfig, session: Session) -> App
concat!("rhema-together ", env!("CARGO_PKG_VERSION")),
)),
user_preferences: None,
supports_vision: None,
supports_vision: config.supports_vision,
vision: None,
jobs: None,
websearch: None,
@@ -397,6 +401,37 @@ pub fn load_session(state: &Shared, room: &str) -> AppResult<Session> {
}
}
/// The images a human message carries, read back as inline blocks.
/// An attachment that vanished or is not a wire format the providers
/// share is skipped: the text still reaches the model.
pub fn load_images(
state: &Shared,
room: &str,
attachments: &[crate::models::Attachment],
) -> Vec<rhema_core::Image> {
use base64::Engine as _;
let conn = state.db.conn();
let mut images = Vec::with_capacity(attachments.len());
for attachment in attachments {
let row = conn.query_row(
"SELECT mime, bytes FROM attachments WHERE id = ?1 AND room_id = ?2",
rusqlite::params![attachment.id, room],
|row| Ok((row.get::<_, String>(0)?, row.get::<_, Vec<u8>>(1)?)),
);
let Ok((mime, bytes)) = row else {
continue;
};
let Some(media) = rhema_core::ImageMediaType::parse(&mime) else {
continue;
};
images.push(rhema_core::Image::new(
media,
base64::engine::general_purpose::STANDARD.encode(bytes),
));
}
images
}
/// Persists a session outside the commit hook (the end of a turn).
pub fn save_session(state: &Shared, room: &str, session: &Session) -> AppResult<()> {
let json = serde_json::to_string(session)?;