feat: file/image upload + separated framework root (sessions/data/uploads)

- POST /api/uploads: base64 -> shared ~/.strata-ctl/uploads store (uuid+ext),
  content-sniffed kind (image/text/binary), text token-counted via the model
  tokenizer; metadata persisted in a new uploads table.
- Chat attachments routed by kind: images -> Vision bridge (multipart image_url),
  small text (<=2000 tokens) inlined, large text/binary -> path + shell_exec
  reminder; binaries never inlined. Attachment context persisted with the turn.
- GUI: attach button + file picker, removable chips, attachments sent with the
  turn and shown on the user bubble; cleared on session switch.
- Framework root ~/.strata-ctl separated by type: sessions/<name>/, data/ (SQLite,
  moved from ~/.config/strata-ctl), uploads/. Legacy DB copied once on first run.
- count_tokens seam on Formatter (real tokenizer override) + ChatService.
- i18n: upload errors + attachment markers (backend) and attach.* (GUI), it+en.
- 121 tests + 2 ignored; clippy/fmt clean; validated live (upload routing, real
  tokenizer count, image->Vision answered "Rosso", new layout).
This commit is contained in:
adm committed 2026-11-25 16:25:55 +01:00
1 parent 498e3dbc1b
commit 65f8111ba2
19 files changed
+672 -47

No files matched your search

+61
View File
@@ -120,6 +120,21 @@ pub struct Stats {
pub completion_tokens: u64,
}
/// Metadata for an uploaded file (bytes live on disk under the shared upload dir).
#[derive(Debug, Clone, Serialize)]
pub struct UploadMeta {
/// Stored filename (uuid + extension), unique; resolves the on-disk path.
pub id: String,
pub original_name: String,
pub path: String,
/// "image" | "text" | "binary" — decided by content sniff, not extension.
pub kind: String,
/// Token count for text (0 otherwise), measured with the model tokenizer.
pub tokens: u32,
pub size: u64,
pub created_at: i64,
}
/// The storage interface. Synchronous; call via `spawn_blocking` from async code.
pub trait Store: Send + Sync {
fn create_session(
@@ -141,6 +156,8 @@ pub trait Store: Send + Sync {
/// The global default settings template (None until seeded).
fn get_defaults(&self) -> Result<Option<SessionSettings>>;
fn set_defaults(&self, settings: &SessionSettings) -> Result<()>;
fn save_upload(&self, meta: &UploadMeta) -> Result<()>;
fn get_upload(&self, id: &str) -> Result<Option<UploadMeta>>;
}
fn now_secs() -> i64 {
@@ -190,6 +207,15 @@ CREATE TABLE IF NOT EXISTS defaults (
id INTEGER PRIMARY KEY CHECK (id = 1),
settings_json TEXT NOT NULL
);
CREATE TABLE IF NOT EXISTS uploads (
id TEXT PRIMARY KEY,
original_name TEXT NOT NULL,
path TEXT NOT NULL,
kind TEXT NOT NULL,
tokens INTEGER NOT NULL DEFAULT 0,
size INTEGER NOT NULL DEFAULT 0,
created_at INTEGER NOT NULL
);
";
/// SQLite-backed store (bundled SQLite, compiled into the binary). WAL mode for
@@ -470,6 +496,41 @@ impl Store for SqliteStore {
)?;
Ok(())
}
fn save_upload(&self, meta: &UploadMeta) -> Result<()> {
let conn = self.lock();
conn.execute(
"INSERT OR REPLACE INTO uploads (id, original_name, path, kind, tokens, size, created_at)
VALUES (?1, ?2, ?3, ?4, ?5, ?6, ?7)",
params![
meta.id,
meta.original_name,
meta.path,
meta.kind,
meta.tokens as i64,
meta.size as i64,
meta.created_at
],
)?;
Ok(())
}
fn get_upload(&self, id: &str) -> Result<Option<UploadMeta>> {
let conn = self.lock();
let mut stmt = conn.prepare("SELECT * FROM uploads WHERE id = ?1")?;
let mut rows = stmt.query_map(params![id], |r| {
Ok(UploadMeta {
id: r.get("id")?,
original_name: r.get("original_name")?,
path: r.get("path")?,
kind: r.get("kind")?,
tokens: r.get::<_, i64>("tokens")? as u32,
size: r.get::<_, i64>("size")? as u64,
created_at: r.get("created_at")?,
})
})?;
Ok(rows.next().transpose()?)
}
}
#[cfg(test)]