diff --git a/README.md b/README.md index a206bbb..b2995b4 100644 --- a/README.md +++ b/README.md @@ -7,8 +7,9 @@ agent; the people and the agent see the same sandbox. The room is a browser workspace: - **Chat** with the room and with `@rhema`. Human messages carry their - author's name; the agent speaks through a `message` tool so that its - private reasoning never leaks into the room. + author's name and can carry images when the room's model has vision; + the agent speaks through a `message` tool so that its private + reasoning never leaks into the room. - **Preview** iframe for a dev server or a static build, set from the chat by the agent's `preview` tool. - **Files** pane: the tree, a read-only file view, `git status`, and diff --git a/specs/rhema-together.md b/specs/rhema-together.md index 4869da3..6961e3b 100644 --- a/specs/rhema-together.md +++ b/specs/rhema-together.md @@ -350,7 +350,12 @@ paged backwards. Composer at the bottom with `@` completion for the agent and for people. Each message carries author, colour, time, and, for agent messages, the turn. Images and pastes ride the message row; the bytes are served from a room route, and vision models get inline -image blocks the way the claw already sends them. +image blocks the way the claw already sends them. A line carries at +most four images, each capped at 5 MB and sniffed from its bytes. Only +a model the provider listing says has vision accepts them: the composer +hides the attach button and the upload route refuses otherwise, and the +turn passes the fact to the host agent, which masks the blocks for a +model that cannot see. A running turn has no transcript card. The status line above the composer shows `Rhema is working...` until `turn_end`. When the turn ends, the log @@ -610,6 +615,12 @@ members(room_id, id, account_id, display_name, role, color, guest_token_hash, invites(token_hash, room_id, role, created_by, expires_at, max_uses, uses) messages(room_id, seq, id, author_kind, author_id, text, mentions_json, turn_id, created_at) +attachments(id, room_id, uploader, mime, bytes, size, message_id, + created_at) -- message_id set when a line sent it; older + -- unreferenced uploads are swept after an hour +model_facts(kind, model_id, supports_vision, updated_at) -- filled by + -- the provider listing; the send, upload, and turn paths + -- read it instead of repeating a live call turn_events(room_id, seq, turn_id, kind, body_json, created_at) turns(room_id, id, status, started_by, started_at, ended_at, steps, usage_json, cost_usd) @@ -645,7 +656,7 @@ Refuse to start on a non-loopback `listen` without a `public_url`, a secret key, and at least one account. First run prints a one-time setup token that creates the first account. -Backups: the SQLite file, the secret key, and the attachment directory. +Backups: the SQLite file (attachments included) and the secret key. ## 11. Framework changes diff --git a/src/api/attachments.rs b/src/api/attachments.rs new file mode 100644 index 0000000..0d250b7 --- /dev/null +++ b/src/api/attachments.rs @@ -0,0 +1,157 @@ +//! Room image attachments. An upload stores the bytes and their +//! sniffed type; a message carries the ids, and a turn turns them into +//! inline image blocks when the model can see. + +use axum::Json; +use axum::body::Bytes; +use axum::extract::{Path, State}; +use axum::http::{HeaderValue, StatusCode, header}; +use axum::response::{IntoResponse, Response}; +use rhema_core::ImageMediaType; +use serde_json::{Value, json}; + +use crate::auth::AuthUser; +use crate::error::{AppError, AppResult}; +use crate::models::Attachment; +use crate::state::Shared; +use crate::util::{now_ms, random_id, room_model_vision}; + +use super::rooms::member_of; + +/// Five megabytes per image. The picker on the client refuses bigger +/// files before the upload starts; this is the server's own cap. +pub const MAX_ATTACHMENT_BYTES: usize = 5 * 1024 * 1024; + +/// Images ride one message in groups of at most four. +pub const MAX_ATTACHMENTS_PER_MESSAGE: usize = 4; + +/// How long an upload that no message picked up stays stored. +const ORPHAN_TTL_MS: i64 = 60 * 60 * 1000; + +/// The room's model must be a known vision model: attachments are for +/// the agent to look at, and an upload a model cannot see is noise. +pub fn require_vision(state: &Shared, room: &str) -> AppResult<()> { + if room_model_vision(&state.db.conn(), room) == Some(true) { + return Ok(()); + } + Err(AppError::bad_request( + "image attachments need a model with vision; this room's model does not have it, or the room has no model", + )) +} + +/// Stores one image. The body is the raw file, the way the avatar +/// route takes it: the client sends bytes, the server sniffs the type +/// and never trusts a claimed content type. +pub async fn upload( + user: AuthUser, + State(state): State, + Path(room): Path, + body: Bytes, +) -> AppResult> { + member_of(&state, &room, &user.user.id)?; + require_vision(&state, &room)?; + if body.is_empty() { + return Err(AppError::bad_request("the attachment is empty")); + } + if body.len() > MAX_ATTACHMENT_BYTES { + return Err(AppError::new( + StatusCode::PAYLOAD_TOO_LARGE, + "images are capped at 5 MB", + )); + } + let media = ImageMediaType::sniff(&body).ok_or_else(|| { + AppError::bad_request("attachments must be PNG, JPEG, GIF, or WebP images") + })?; + let id = random_id(16); + state.db.conn().execute( + "INSERT INTO attachments (id, room_id, uploader, mime, bytes, size, message_id, created_at) + VALUES (?1, ?2, ?3, ?4, ?5, ?6, NULL, ?7)", + rusqlite::params![ + id, + room, + user.user.id, + media.as_str(), + body.as_ref(), + body.len() as i64, + now_ms() + ], + )?; + Ok(Json(json!({ + "attachment": { "id": id, "mime": media.as_str(), "size": body.len() } + }))) +} + +/// Serves one stored image to a room member. The id never changes, so +/// the response caches forever in the member's browser. +pub async fn get( + user: AuthUser, + State(state): State, + Path((room, attachment)): Path<(String, String)>, +) -> AppResult { + member_of(&state, &room, &user.user.id)?; + let row = state + .db + .conn() + .query_row( + "SELECT mime, bytes FROM attachments WHERE id = ?1 AND room_id = ?2", + rusqlite::params![attachment, room], + |row| Ok((row.get::<_, String>(0)?, row.get::<_, Vec>(1)?)), + ) + .map_err(|_| AppError::not_found("attachment not found"))?; + let mut response = row.1.into_response(); + let headers = response.headers_mut(); + headers.insert( + header::CONTENT_TYPE, + HeaderValue::from_str(&row.0) + .unwrap_or(HeaderValue::from_static("application/octet-stream")), + ); + headers.insert( + header::CACHE_CONTROL, + HeaderValue::from_static("private, max-age=31536000, immutable"), + ); + Ok(response) +} + +/// Fills in the metadata a message stores beside the ids, refusing an +/// id that is not one of this room's uploads. +pub fn load_metadata(state: &Shared, room: &str, ids: &[String]) -> AppResult> { + let conn = state.db.conn(); + let mut attachments = Vec::with_capacity(ids.len()); + for id in ids { + let (mime, size) = conn + .query_row( + "SELECT mime, size FROM attachments WHERE id = ?1 AND room_id = ?2", + rusqlite::params![id, room], + |row| Ok((row.get::<_, String>(0)?, row.get::<_, i64>(1)?)), + ) + .map_err(|_| AppError::bad_request("an attachment is missing; upload it again"))?; + attachments.push(Attachment { + id: id.clone(), + mime, + size, + }); + } + Ok(attachments) +} + +/// Marks the uploads a posted message carries, so the sweep keeps them. +pub fn mark_used(state: &Shared, room: &str, message_id: &str, ids: &[String]) { + let conn = state.db.conn(); + for id in ids { + let _ = conn.execute( + "UPDATE attachments SET message_id = ?1 WHERE id = ?2 AND room_id = ?3", + rusqlite::params![message_id, id, room], + ); + } +} + +/// Deletes uploads nobody sent within the hour. Runs beside a send, +/// where uploads just settled: one statement, and only this room's +/// orphans go. +pub fn sweep(state: &Shared, room: &str) { + let cutoff = now_ms() - ORPHAN_TTL_MS; + let _ = state.db.conn().execute( + "DELETE FROM attachments WHERE room_id = ?1 AND message_id IS NULL AND created_at < ?2", + rusqlite::params![room, cutoff], + ); +} diff --git a/src/api/messages.rs b/src/api/messages.rs index 84f0d74..660b07d 100644 --- a/src/api/messages.rs +++ b/src/api/messages.rs @@ -29,6 +29,9 @@ pub type EventStream = Pin> + #[derive(Deserialize)] pub struct SendBody { pub text: String, + /// Ids from `POST /rooms/{id}/attachments`, uploaded just before. + #[serde(default)] + pub attachments: Vec, } /// Posts one human line and wakes the agent when it mentions `@rhema`. @@ -40,7 +43,26 @@ pub async fn send( ) -> AppResult> { let member = member_of(&state, &room, &user.user.id)?; let text = body.text.trim(); - if text.is_empty() { + let ids = &body.attachments; + if ids.len() > super::attachments::MAX_ATTACHMENTS_PER_MESSAGE { + return Err(AppError::bad_request( + "a message carries at most four images", + )); + } + if ids.iter().any(|id| id.is_empty()) { + return Err(AppError::bad_request("an attachment id is empty")); + } + let duplicate = (1..ids.len()).any(|at| ids[..at].contains(&ids[at])); + if duplicate { + return Err(AppError::bad_request("the same attachment is listed twice")); + } + let attachments = if ids.is_empty() { + Vec::new() + } else { + super::attachments::require_vision(&state, &room)?; + super::attachments::load_metadata(&state, &room, ids)? + }; + if text.is_empty() && attachments.is_empty() { return Err(AppError::bad_request("the message is empty")); } if text.chars().count() > 16_000 { @@ -57,6 +79,7 @@ pub async fn send( text: text.to_owned(), mentions, created_at: now_ms(), + attachments, }; let data = serde_json::to_value(&message)?; state.hub.insert(&state.db, &room, seq, "message", &data)?; @@ -68,6 +91,8 @@ pub async fn send( data, }, ); + super::attachments::mark_used(&state, &room, &message.id, ids); + super::attachments::sweep(&state, &room); state.rooms.wake( &state, &room, @@ -312,6 +337,7 @@ pub async fn interrupt( text, mentions: false, created_at: now_ms(), + attachments: Vec::new(), }; let data = serde_json::to_value(&message)?; state.hub.insert(&state.db, &room, seq, "message", &data)?; diff --git a/src/api/mod.rs b/src/api/mod.rs index 4cada65..b4263b5 100644 --- a/src/api/mod.rs +++ b/src/api/mod.rs @@ -1,6 +1,7 @@ //! HTTP routes: the JSON API, the event feed, the presence socket, and //! the built client. +pub mod attachments; pub mod auth; pub mod files; pub mod messages; @@ -76,6 +77,16 @@ pub fn router(state: Shared) -> Router { "/rooms/{id}/messages", get(messages::list).post(messages::send), ) + .route( + "/rooms/{id}/attachments", + post(attachments::upload).layer(DefaultBodyLimit::max( + attachments::MAX_ATTACHMENT_BYTES + 64 * 1024, + )), + ) + .route( + "/rooms/{id}/attachments/{attachment}", + get(attachments::get), + ) .route("/rooms/{id}/events", get(messages::events)) .route("/rooms/{id}/presence", get(messages::presence)) .route("/rooms/{id}/files", get(files::list)) diff --git a/src/api/rooms.rs b/src/api/rooms.rs index 2b5bca9..f1a3e87 100644 --- a/src/api/rooms.rs +++ b/src/api/rooms.rs @@ -54,34 +54,32 @@ pub fn owner_of(state: &Shared, room: &str, account: &str) -> AppResult) -> rusqlite::Result { - Ok(Room { - id: row.get("id")?, - name: row.get("name")?, - owner_id: row.get("owner_id")?, - provider_config_id: row.get("provider_config_id")?, - sandbox_target_id: row.get("sandbox_target_id")?, - workspace: row.get("workspace")?, - repo_url: row.get("repo_url")?, - model: row.get("model")?, - max_turn_steps: row.get("max_turn_steps")?, - created_at: row.get("created_at")?, - archived_at: row.get("archived_at")?, - }) -} - fn load_room(state: &Shared, id: &str) -> AppResult { - state - .db - .conn() - .query_row( - "SELECT id, name, owner_id, provider_config_id, sandbox_target_id, workspace, - repo_url, model, max_turn_steps, created_at, archived_at - FROM rooms WHERE id = ?1", - rusqlite::params![id], - room_from_row, - ) - .map_err(|_| AppError::not_found("room not found")) + let conn = state.db.conn(); + let vision = crate::util::room_model_vision(&conn, id); + conn.query_row( + "SELECT id, name, owner_id, provider_config_id, sandbox_target_id, workspace, + repo_url, model, max_turn_steps, created_at, archived_at + FROM rooms WHERE id = ?1", + rusqlite::params![id], + |row| { + Ok(Room { + id: row.get("id")?, + name: row.get("name")?, + owner_id: row.get("owner_id")?, + provider_config_id: row.get("provider_config_id")?, + sandbox_target_id: row.get("sandbox_target_id")?, + workspace: row.get("workspace")?, + repo_url: row.get("repo_url")?, + model: row.get("model")?, + max_turn_steps: row.get("max_turn_steps")?, + model_vision: vision, + created_at: row.get("created_at")?, + archived_at: row.get("archived_at")?, + }) + }, + ) + .map_err(|_| AppError::not_found("room not found")) } fn load_members(state: &Shared, room: &str) -> AppResult> { diff --git a/src/api/settings.rs b/src/api/settings.rs index 6980979..2f590cb 100644 --- a/src/api/settings.rs +++ b/src/api/settings.rs @@ -290,12 +290,43 @@ pub async fn list_provider_models( tracing::warn!(provider = %id, error = %err, "provider catalog"); AppError::new(StatusCode::BAD_GATEWAY, catalog_error(&err)) })?; + remember_model_facts(&state, &kind, &models); Ok(Json(json!({ "provider": { "id": id, "kind": kind, "model": model }, "models": models, }))) } +/// Keeps each card's vision fact, keyed by the provider kind and the +/// model id. The send, upload, and turn paths read the table instead +/// of repeating a live listing, and a model the listing leaves blank +/// stays unknown. A failed write only loses facts, so it logs. +fn remember_model_facts(state: &Shared, kind: &str, models: &[rhema_provider::ModelCard]) { + let now = crate::util::now_ms(); + let result: rusqlite::Result<()> = (|| { + let conn = state.db.conn(); + let mut stmt = conn.prepare( + "INSERT INTO model_facts (kind, model_id, supports_vision, updated_at) + VALUES (?1, ?2, ?3, ?4) + ON CONFLICT(kind, model_id) DO UPDATE SET + supports_vision = excluded.supports_vision, + updated_at = excluded.updated_at", + )?; + for card in models { + stmt.execute(rusqlite::params![ + kind, + card.id, + card.supports_vision.map(|value| value as i64), + now + ])?; + } + Ok(()) + })(); + if let Err(err) = result { + tracing::warn!(provider_kind = %kind, error = %err, "model facts"); + } +} + /// A short reason for a failed catalog fetch. The provider's own body /// can be an HTML error page and is not worth showing; the full error /// stays in the log. diff --git a/src/db.rs b/src/db.rs index 3d280a1..ea45b7f 100644 --- a/src/db.rs +++ b/src/db.rs @@ -47,7 +47,7 @@ impl Db { } } -const SCHEMA: &str = r#" +pub(crate) const SCHEMA: &str = r#" CREATE TABLE IF NOT EXISTS meta ( key TEXT PRIMARY KEY, value TEXT NOT NULL @@ -161,7 +161,27 @@ CREATE TABLE IF NOT EXISTS events ( PRIMARY KEY (room_id, seq) ) STRICT; +CREATE TABLE IF NOT EXISTS attachments ( + id TEXT PRIMARY KEY, + room_id TEXT NOT NULL REFERENCES rooms(id) ON DELETE CASCADE, + uploader TEXT NOT NULL REFERENCES accounts(id) ON DELETE CASCADE, + mime TEXT NOT NULL, + bytes BLOB NOT NULL, + size INTEGER NOT NULL, + message_id TEXT, + created_at INTEGER NOT NULL +) STRICT; + +CREATE TABLE IF NOT EXISTS model_facts ( + kind TEXT NOT NULL, + model_id TEXT NOT NULL, + supports_vision INTEGER, + updated_at INTEGER NOT NULL, + PRIMARY KEY (kind, model_id) +) STRICT; + CREATE INDEX IF NOT EXISTS members_room ON members(room_id); CREATE INDEX IF NOT EXISTS events_room_seq ON events(room_id, seq); CREATE INDEX IF NOT EXISTS auth_sessions_account ON auth_sessions(account_id); +CREATE INDEX IF NOT EXISTS attachments_room ON attachments(room_id); "#; diff --git a/src/models.rs b/src/models.rs index 0f17a37..47630e7 100644 --- a/src/models.rs +++ b/src/models.rs @@ -15,6 +15,19 @@ pub struct Message { pub text: String, pub mentions: bool, pub created_at: i64, + /// The images riding this line, metadata only: the bytes are served + /// from the room's attachment route. Empty for older rows. + #[serde(default, skip_serializing_if = "Vec::is_empty")] + pub attachments: Vec, +} + +/// An image attached to a chat line. `mime` comes from the stored +/// bytes' magic, never from the uploader's header. +#[derive(Debug, Clone, Serialize, Deserialize)] +pub struct Attachment { + pub id: String, + pub mime: String, + pub size: i64, } /// A room as the sidebar needs it. @@ -40,6 +53,9 @@ pub struct Room { pub repo_url: Option, pub model: Option, pub max_turn_steps: i64, + /// Whether the room's effective model is known to accept images. + /// `None` is unknown, not no: facts arrive with a provider listing. + pub model_vision: Option, pub created_at: i64, pub archived_at: Option, } diff --git a/src/room/agent.rs b/src/room/agent.rs index 6848a3b..9dd05fd 100644 --- a/src/room/agent.rs +++ b/src/room/agent.rs @@ -26,6 +26,8 @@ pub struct TurnConfig { pub workspace: String, pub repo_url: Option, pub model: String, + /// The model's stored vision fact; `None` is unknown, not no. + pub supports_vision: Option, 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 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 { } } +/// 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 { + 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>(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)?; diff --git a/src/room/message_tool.rs b/src/room/message_tool.rs index 601ea92..a90da1b 100644 --- a/src/room/message_tool.rs +++ b/src/room/message_tool.rs @@ -23,6 +23,7 @@ pub fn post_agent_message(state: &Shared, room: &str, text: &str) -> AppResult) { } }; for message in &pending { - session.history.push(Message::text( - Role::User, - format!("{}: {}", message.author_name, message.text), - )); + let text = format!("{}: {}", message.author_name, message.text); + let images = agent::load_images(&state, &room, &message.attachments); + session.history.push(if images.is_empty() { + Message::text(Role::User, text) + } else { + Message::text_with_images(Role::User, text, images) + }); } if let Err(err) = agent::save_session(&state, &room, &session) { notice(&state, &room, "error", err.message); diff --git a/src/util.rs b/src/util.rs index 7e96bf1..2064af2 100644 --- a/src/util.rs +++ b/src/util.rs @@ -137,6 +137,35 @@ pub fn safe_rel_path(path: &str) -> Result { }) } +/// 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 { + conn.query_row( + "SELECT supports_vision FROM model_facts WHERE kind = ?1 AND model_id = ?2", + rusqlite::params![kind, model], + |row| row.get::<_, Option>(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 { + 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")); diff --git a/web/app/assets/css/main.css b/web/app/assets/css/main.css index 56fef59..802786d 100644 --- a/web/app/assets/css/main.css +++ b/web/app/assets/css/main.css @@ -1213,6 +1213,27 @@ button { margin-bottom: 0; } +.msg-attachments { + display: flex; + flex-wrap: wrap; + gap: var(--sp-2); + margin-top: var(--sp-1); +} + +.msg-attachment { + display: block; + border: 1px solid var(--border); + border-radius: var(--r-card); + overflow: hidden; + line-height: 0; +} + +.msg-attachment img { + display: block; + max-width: 240px; + max-height: 180px; +} + .msg-text p, .msg-text ul, .msg-text ol, @@ -1577,6 +1598,48 @@ button { padding-left: var(--sp-2); } +.composer-attachments { + display: flex; + flex-wrap: wrap; + gap: var(--sp-2); + padding: var(--sp-1) var(--sp-2) var(--sp-2); +} + +.composer-attachment { + position: relative; +} + +.composer-attachment-thumb { + display: block; + width: 56px; + height: 56px; + object-fit: cover; + border: 1px solid var(--border); + border-radius: var(--r-control); +} + +.composer-attachment-remove { + position: absolute; + top: -6px; + right: -6px; + display: grid; + place-items: center; + width: 18px; + height: 18px; + padding: 0; + border: 1px solid var(--border-strong); + border-radius: var(--r-avatar); + background: var(--surface); + color: var(--muted); + cursor: pointer; + line-height: 0; +} + +.composer-attachment-remove:hover { + color: var(--danger); + border-color: var(--danger); +} + .composer-buttons { display: flex; align-items: center; diff --git a/web/app/components/ChatComposer.vue b/web/app/components/ChatComposer.vue index 1bc83d0..346e2c1 100644 --- a/web/app/components/ChatComposer.vue +++ b/web/app/components/ChatComposer.vue @@ -1,16 +1,28 @@ @@ -136,7 +218,22 @@ onBeforeUnmount(() => { placeholder="Message the room. Use @rhema to ask the agent." @input="onInput" @keydown="onKeydown" + @paste="onPaste" /> +
+
+ + +
+