diff --git a/Cargo.lock b/Cargo.lock index 27c3a2fdb1..a22db1b35d 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -101,6 +101,7 @@ version = "0.1.0" dependencies = [ "anyhow", "assets", + "chrono", "collections", "editor", "futures 0.3.28", diff --git a/crates/ai/Cargo.toml b/crates/ai/Cargo.toml index 14817916f4..861a9e4785 100644 --- a/crates/ai/Cargo.toml +++ b/crates/ai/Cargo.toml @@ -19,11 +19,12 @@ theme = { path = "../theme" } util = { path = "../util" } workspace = { path = "../workspace" } -serde.workspace = true -serde_json.workspace = true anyhow.workspace = true +chrono = "0.4" futures.workspace = true isahc.workspace = true +serde.workspace = true +serde_json.workspace = true [dev-dependencies] editor = { path = "../editor", features = ["test-support"] } diff --git a/crates/ai/src/assistant.rs b/crates/ai/src/assistant.rs index 14ac741114..c6c5d4d009 100644 --- a/crates/ai/src/assistant.rs +++ b/crates/ai/src/assistant.rs @@ -1,5 +1,6 @@ use crate::{OpenAIRequest, OpenAIResponseStreamEvent, RequestMessage, Role}; use anyhow::{anyhow, Result}; +use chrono::{DateTime, Local}; use collections::HashMap; use editor::{Editor, ExcerptId, ExcerptRange, MultiBuffer}; use futures::{io::BufReader, AsyncBufReadExt, AsyncReadExt, Stream, StreamExt}; @@ -343,6 +344,7 @@ impl Assistant { let message = Message { role, content: content.clone(), + sent_at: Local::now(), }; self.messages.push(message.clone()); self.messages_by_id.insert(excerpt_id, message.clone()); @@ -394,7 +396,16 @@ impl AssistantEditor { }; Flex::row() - .with_child(sender) + .with_child(sender.aligned()) + .with_child( + Label::new( + message.sent_at.format("%I:%M%P").to_string(), + style.sent_at.text.clone(), + ) + .contained() + .with_style(style.sent_at.container) + .aligned(), + ) .aligned() .left() .contained() @@ -461,6 +472,7 @@ impl Item for AssistantEditor { struct Message { role: Role, content: ModelHandle, + sent_at: DateTime, } async fn stream_completion( diff --git a/crates/theme/src/theme.rs b/crates/theme/src/theme.rs index 0056230766..1f99742cfe 100644 --- a/crates/theme/src/theme.rs +++ b/crates/theme/src/theme.rs @@ -972,6 +972,7 @@ pub struct TerminalStyle { pub struct AssistantStyle { pub container: ContainerStyle, pub header: ContainerStyle, + pub sent_at: ContainedText, pub user_sender: ContainedText, pub assistant_sender: ContainedText, } diff --git a/styles/src/styleTree/assistant.ts b/styles/src/styleTree/assistant.ts index ea02c3b383..0ff65a22ae 100644 --- a/styles/src/styleTree/assistant.ts +++ b/styles/src/styleTree/assistant.ts @@ -18,6 +18,10 @@ export default function assistant(colorScheme: ColorScheme) { }, assistant_sender: { ...text(layer, "sans", "accent", { size: "sm", weight: "bold" }), + }, + sent_at: { + margin: { top: 2, left: 8 }, + ...text(layer, "sans", "default", { size: "2xs" }), } } }