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
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:
1 parent
acc545ede7
commit
2e17e7463c
18 files changed
+624
-46
No files matched your search
+52
@@ -137,6 +137,35 @@ pub fn safe_rel_path(path: &str) -> Result<String, String> {
|
||||
})
|
||||
}
|
||||
|
||||
/// The stored vision fact for one model id, when a listing carried it.
|
||||
/// `None` is unknown: no row, or a row the last listing left blank.
|
||||
pub fn model_supports_vision(conn: &rusqlite::Connection, kind: &str, model: &str) -> Option<bool> {
|
||||
conn.query_row(
|
||||
"SELECT supports_vision FROM model_facts WHERE kind = ?1 AND model_id = ?2",
|
||||
rusqlite::params![kind, model],
|
||||
|row| row.get::<_, Option<i64>>(0),
|
||||
)
|
||||
.ok()
|
||||
.flatten()
|
||||
.map(|value| value != 0)
|
||||
}
|
||||
|
||||
/// The room's effective model vision: the stored fact for the room's
|
||||
/// provider kind and its effective model, the room override or the
|
||||
/// provider default. `None` when the room has no provider or no fact.
|
||||
pub fn room_model_vision(conn: &rusqlite::Connection, room: &str) -> Option<bool> {
|
||||
let (kind, model): (String, String) = conn
|
||||
.query_row(
|
||||
"SELECT p.kind, COALESCE(NULLIF(r.model, ''), p.model)
|
||||
FROM rooms r JOIN provider_configs p ON p.id = r.provider_config_id
|
||||
WHERE r.id = ?1",
|
||||
rusqlite::params![room],
|
||||
|row| Ok((row.get(0)?, row.get(1)?)),
|
||||
)
|
||||
.ok()?;
|
||||
model_supports_vision(conn, &kind, &model)
|
||||
}
|
||||
|
||||
/// `@rhema` in any case, as a whole word.
|
||||
pub fn mentions_agent(text: &str) -> bool {
|
||||
let lower = text.to_lowercase();
|
||||
@@ -212,6 +241,29 @@ mod tests {
|
||||
assert!(check_target_address("1.1.1.1", 22).await.is_ok());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn vision_facts_read_back_and_stay_unknown_when_absent() {
|
||||
let conn = rusqlite::Connection::open_in_memory().unwrap();
|
||||
conn.execute_batch(crate::db::SCHEMA).unwrap();
|
||||
assert_eq!(model_supports_vision(&conn, "openai", "gpt-5"), None);
|
||||
conn.execute(
|
||||
"INSERT INTO model_facts (kind, model_id, supports_vision, updated_at)
|
||||
VALUES ('openai', 'gpt-5', 1, 0), ('llama-cpp', 'qwen', NULL, 0)",
|
||||
[],
|
||||
)
|
||||
.unwrap();
|
||||
assert_eq!(model_supports_vision(&conn, "openai", "gpt-5"), Some(true));
|
||||
assert_eq!(model_supports_vision(&conn, "llama-cpp", "qwen"), None);
|
||||
assert_eq!(model_supports_vision(&conn, "openai", "other"), None);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn a_room_without_a_provider_has_no_vision_fact() {
|
||||
let conn = rusqlite::Connection::open_in_memory().unwrap();
|
||||
conn.execute_batch(crate::db::SCHEMA).unwrap();
|
||||
assert_eq!(room_model_vision(&conn, "room"), None);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn mentions_need_a_word_boundary() {
|
||||
assert!(mentions_agent("@rhema fix this"));
|
||||
|
||||
Reference in new issue
Block a user