Prefs: owner defaults (model, backend, persona_id, reel span/length)

Closes #127.

Grows user_ai_prefs with five nullable owner-default columns and makes
them the server-side fallback layer: request param -> stored pref ->
hard default, at insight generation (agentic + standard), all three
insight-chat turn variants, and reel creation.

- PUT /prefs accepts the fields with the existing three-state partial
  update semantics (TriState generalized to TriState<T> for the numeric
  reel_max_segments); validation (canonical BackendKind::parse,
  MemoriesSpan::from_str) runs before any write.
- GET /prefs returns the new fields.
- capture_prefs reads the existing row and carries the AI owner-defaults
  through unchanged (the upsert overwrites all columns), mirroring only
  the effective reel span/segments.
- MemoriesSpan gains Display + FromStr so stored spans round-trip
  losslessly.

1463/0 tests (+27), clippy clean.
This commit is contained in:
Cameron Cordes committed 2026-09-27 19:48:45 -04:00
1 parent aa3c58f051
commit a699c940b8
10 files changed
+863 -85

No files matched your search

+25
View File
@@ -108,6 +108,31 @@ pub enum MemoriesSpan {
Month,
}
/// Wire/storage string for the span (`"day"` | `"week"` | `"month"`) — the
/// same lowercase names as the serde rename, so a stored pref round-trips
/// through `MemoriesRequest.span` unchanged.
impl std::fmt::Display for MemoriesSpan {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
f.write_str(match self {
MemoriesSpan::Day => "day",
MemoriesSpan::Week => "week",
MemoriesSpan::Month => "month",
})
}
}
impl std::str::FromStr for MemoriesSpan {
type Err = String;
fn from_str(s: &str) -> Result<Self, Self::Err> {
match s.trim().to_ascii_lowercase().as_str() {
"day" => Ok(MemoriesSpan::Day),
"week" => Ok(MemoriesSpan::Week),
"month" => Ok(MemoriesSpan::Month),
other => Err(format!("invalid span {other:?} (expected day|week|month)")),
}
}
}
#[derive(Deserialize)]
pub struct MemoriesRequest {
pub span: Option<MemoriesSpan>,