pub struct ChatView { /* private fields */ }Expand description
A streamed, Markdown transcript with metadata and source chips.
ChatView owns the transcript state and one TextViewState per message,
so tokens can be appended without rebuilding the whole document. It emits
ChatViewEvent for actions the host must handle.
Implementations§
Source§impl ChatView
impl ChatView
Sourcepub fn empty_state(self, empty: EmptyState) -> Self
pub fn empty_state(self, empty: EmptyState) -> Self
Replace the empty state.
Sourcepub fn set_empty_state(&mut self, empty: EmptyState, cx: &mut Context<'_, Self>)
pub fn set_empty_state(&mut self, empty: EmptyState, cx: &mut Context<'_, Self>)
Replace the empty state and redraw.
Sourcepub fn state(&self) -> &Entity<ChatState>
pub fn state(&self) -> &Entity<ChatState>
The underlying reducer, for hosts that need read access.
Sourcepub fn push_message(
&mut self,
message: NewMessage,
cx: &mut Context<'_, Self>,
) -> MessageId
pub fn push_message( &mut self, message: NewMessage, cx: &mut Context<'_, Self>, ) -> MessageId
Append a message and create its render state.
Sourcepub fn push_user(
&mut self,
text: impl Into<String>,
cx: &mut Context<'_, Self>,
) -> MessageId
pub fn push_user( &mut self, text: impl Into<String>, cx: &mut Context<'_, Self>, ) -> MessageId
Append a user message.
Sourcepub fn push_system(
&mut self,
text: impl Into<String>,
cx: &mut Context<'_, Self>,
) -> MessageId
pub fn push_system( &mut self, text: impl Into<String>, cx: &mut Context<'_, Self>, ) -> MessageId
Append a system notice.
Sourcepub fn push_system_before(
&mut self,
before: MessageId,
text: impl Into<String>,
cx: &mut Context<'_, Self>,
) -> bool
pub fn push_system_before( &mut self, before: MessageId, text: impl Into<String>, cx: &mut Context<'_, Self>, ) -> bool
Insert a system notice immediately before before.
Use this for per-question context notes: the note then appears between
the question and the assistant placeholder, exactly where the attached
papers belong. Returns false when before is unknown.
Sourcepub fn begin_assistant(&mut self, cx: &mut Context<'_, Self>) -> MessageId
pub fn begin_assistant(&mut self, cx: &mut Context<'_, Self>) -> MessageId
Start an empty streaming assistant message.
Sourcepub fn append(
&mut self,
id: MessageId,
delta: &str,
cx: &mut Context<'_, Self>,
) -> bool
pub fn append( &mut self, id: MessageId, delta: &str, cx: &mut Context<'_, Self>, ) -> bool
Append a token batch to a streaming message.
Sourcepub fn finish(&mut self, id: MessageId, cx: &mut Context<'_, Self>) -> bool
pub fn finish(&mut self, id: MessageId, cx: &mut Context<'_, Self>) -> bool
Finish a streaming message and normalize its final Markdown.
Sourcepub fn stop(&mut self, id: MessageId, cx: &mut Context<'_, Self>) -> bool
pub fn stop(&mut self, id: MessageId, cx: &mut Context<'_, Self>) -> bool
Stop a streaming message, keeping the partial body.
Sourcepub fn fail(
&mut self,
id: MessageId,
error: impl Into<String>,
cx: &mut Context<'_, Self>,
) -> bool
pub fn fail( &mut self, id: MessageId, error: impl Into<String>, cx: &mut Context<'_, Self>, ) -> bool
Mark a message as failed, keeping the partial body.
Sourcepub fn set_meta(
&mut self,
id: MessageId,
meta: MessageMeta,
cx: &mut Context<'_, Self>,
) -> bool
pub fn set_meta( &mut self, id: MessageId, meta: MessageMeta, cx: &mut Context<'_, Self>, ) -> bool
Replace a message’s footer metadata.
Sourcepub fn add_source(
&mut self,
id: MessageId,
source: SourceRef,
cx: &mut Context<'_, Self>,
) -> bool
pub fn add_source( &mut self, id: MessageId, source: SourceRef, cx: &mut Context<'_, Self>, ) -> bool
Add one source to a message footer.
Sourcepub fn remove(&mut self, id: MessageId, cx: &mut Context<'_, Self>) -> bool
pub fn remove(&mut self, id: MessageId, cx: &mut Context<'_, Self>) -> bool
Remove one message, e.g. before retrying a failed answer.
Returns whether the message existed.
Sourcepub fn replace(
&mut self,
messages: impl IntoIterator<Item = NewMessage>,
cx: &mut Context<'_, Self>,
)
pub fn replace( &mut self, messages: impl IntoIterator<Item = NewMessage>, cx: &mut Context<'_, Self>, )
Replace the transcript, for loading a session.
Sourcepub fn scroll_to_end(&mut self, cx: &mut Context<'_, Self>)
pub fn scroll_to_end(&mut self, cx: &mut Context<'_, Self>)
Scroll to the newest message and resume tail following.
Sourcepub fn copy_message(&mut self, id: MessageId, cx: &mut Context<'_, Self>)
pub fn copy_message(&mut self, id: MessageId, cx: &mut Context<'_, Self>)
Copy a message body to the clipboard.
Sourcepub fn retry(&mut self, id: MessageId, cx: &mut Context<'_, Self>)
pub fn retry(&mut self, id: MessageId, cx: &mut Context<'_, Self>)
Ask the host to retry a failed message.
Sourcepub fn source_clicked(&mut self, source: SourceRef, cx: &mut Context<'_, Self>)
pub fn source_clicked(&mut self, source: SourceRef, cx: &mut Context<'_, Self>)
Ask the host to act on a source.
Trait Implementations§
impl EventEmitter<ChatViewEvent> for ChatView
Auto Trait Implementations§
impl !RefUnwindSafe for ChatView
impl !UnwindSafe for ChatView
impl Freeze for ChatView
impl Send for ChatView
impl Sync for ChatView
impl Unpin for ChatView
impl UnsafeUnpin for ChatView
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
Source§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>. Box<dyn Any> can
then be further downcast into Box<ConcreteType> where ConcreteType implements Trait.Source§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
Rc<Trait> (where Trait: Downcast) to Rc<Any>. Rc<Any> can then be
further downcast into Rc<ConcreteType> where ConcreteType implements Trait.Source§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
&Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &Any’s vtable from &Trait’s.Source§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
&mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &mut Any’s vtable from &mut Trait’s.Source§impl<T> DowncastSync for T
impl<T> DowncastSync for T
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> Instrumented<Self> ⓘ
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> Instrumented<Self> ⓘ
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more