chore: reworked some specs and did small addition to database schema based on gaps in spec, also rechecked the core plan

This commit is contained in:
2026-07-18 22:21:02 +02:00
parent 943e5fa39b
commit 5c1b333cce
12 changed files with 183 additions and 54 deletions

View File

@@ -0,0 +1,3 @@
-- This file should undo anything in `up.sql`
ALTER TABLE chat_messages DROP COLUMN token_usage_output;
ALTER TABLE chat_messages DROP COLUMN token_usage_input;

View File

@@ -0,0 +1,3 @@
-- Your SQL goes here
ALTER TABLE chat_messages ADD COLUMN token_usage_input INTEGER;
ALTER TABLE chat_messages ADD COLUMN token_usage_output INTEGER;

View File

@@ -35,7 +35,7 @@ mod tests {
let applied = db
.conn()
.with_migrations(|conn| conn.applied_migrations().unwrap().len());
assert_eq!(applied, 1);
assert_eq!(applied, 2);
}
#[test]
@@ -82,7 +82,7 @@ mod tests {
#[test]
fn migrations_expose_current_ai_catalog_and_usage_columns() {
let db = migrated_database();
let (provider_ref, model_ref, cache_tokens) = db
let (provider_ref, model_ref, usage_tokens) = db
.conn()
.with(|conn| {
diesel::insert_into(ai_providers::table)
@@ -124,6 +124,8 @@ mod tests {
chat_messages::conversation_id.eq("conversation"),
chat_messages::role.eq("assistant"),
chat_messages::created_at.eq(1_i64),
chat_messages::token_usage_input.eq(Some(56)),
chat_messages::token_usage_output.eq(Some(78)),
chat_messages::cache_read_tokens.eq(Some(12)),
chat_messages::cache_write_tokens.eq(Some(34)),
))
@@ -138,16 +140,18 @@ mod tests {
.first::<Option<String>>(conn)?,
chat_messages::table
.select((
chat_messages::token_usage_input,
chat_messages::token_usage_output,
chat_messages::cache_read_tokens,
chat_messages::cache_write_tokens,
))
.first::<(Option<i32>, Option<i32>)>(conn)?,
.first::<(Option<i32>, Option<i32>, Option<i32>, Option<i32>)>(conn)?,
))
})
.unwrap();
assert_eq!(provider_ref.as_deref(), Some("provider-package"));
assert_eq!(model_ref.as_deref(), Some("model-package"));
assert_eq!(cache_tokens, (Some(12), Some(34)));
assert_eq!(usage_tokens, (Some(56), Some(78), Some(12), Some(34)));
}
}

View File

@@ -80,6 +80,8 @@ diesel::table! {
created_at -> BigInt,
cache_read_tokens -> Nullable<Integer>,
cache_write_tokens -> Nullable<Integer>,
token_usage_input -> Nullable<Integer>,
token_usage_output -> Nullable<Integer>,
}
}

View File

@@ -240,8 +240,7 @@ pub fn view<'a>(
vec![
button(text(t(locale, "editor.quickActions")).size(13))
.on_press_maybe(
ai_enabled
.then_some(Message::MediaEditor(MediaEditorMsg::ToggleQuickActions)),
ai_enabled.then_some(Message::MediaEditor(MediaEditorMsg::ToggleQuickActions)),
)
.style(inputs::secondary_button)
.padding([6, 16])
@@ -549,7 +548,11 @@ pub fn view<'a>(
.into()
}
fn quick_action_item<'a>(label: String, msg: MediaEditorMsg, enabled: bool) -> Element<'a, Message> {
fn quick_action_item<'a>(
label: String,
msg: MediaEditorMsg,
enabled: bool,
) -> Element<'a, Message> {
button(text(label).size(12).shaping(Shaping::Advanced))
.on_press_maybe(enabled.then_some(Message::MediaEditor(msg)))
.padding([6, 12])
@@ -612,7 +615,8 @@ mod tests {
#[test]
fn quick_actions_menu_starts_closed() {
let state = MediaEditorState::from_media(&make_media(), &["en".to_string()], &[], Vec::new());
let state =
MediaEditorState::from_media(&make_media(), &["en".to_string()], &[], Vec::new());
assert!(!state.quick_actions_open);
}