Skip to main content

ChatApp

Struct ChatApp 

Source
pub struct ChatApp {
Show 22 fields pub model_name: String, pub history: Vec<ChatHistoryEntry>, pub textarea: TextArea<'static>, pub mode: ChatMode, pub editor_text: String, pub scroll_offset: usize, pub status: Option<String>, pub cols: u16, pub rows: u16, pub quit: bool, pub session_id: Option<Uuid>, pub show_thinking: bool, pub pending_toasts: Vec<String>, pub pending_prompts: VecDeque<String>, pub gen_config: Arc<RwLock<ChatGenConfig>>, pub settings_draft: ChatGenConfig, pub requested_context_window: Option<usize>, pub is_server_spawned: bool, pub tool_descriptions: HashMap<String, String>, pub tool_call_format: ToolCallFormat, pub pending_tool_calls: usize, pub spinner_tick: u32, /* private fields */
}

Fields§

§model_name: String§history: Vec<ChatHistoryEntry>§textarea: TextArea<'static>§mode: ChatMode§editor_text: String

Current text content held by the editor (set on Ctrl-E, read on Ctrl-S).

§scroll_offset: usize

Number of lines from the tail to scroll back (0 = show tail).

§status: Option<String>§cols: u16§rows: u16§quit: bool§session_id: Option<Uuid>

UUID for this private session (used as the storage filename key).

§show_thinking: bool

Whether to display thinking blocks expanded (Ctrl-O to toggle).

§pending_toasts: Vec<String>

Error messages queued for the outer compositor to surface as toasts. Drained by the event loop each tick (see shell_handlers.rs).

§pending_prompts: VecDeque<String>

Prompts queued while an inference is in flight.

§gen_config: Arc<RwLock<ChatGenConfig>>

Shared generation config (read by spawner each invocation).

§settings_draft: ChatGenConfig

In-progress edits to generation config (committed on Enter, discarded on Esc).

§requested_context_window: Option<usize>

Set when user saves a new context_window; polled by shell_handlers to trigger model reload. 0 = use model default.

§is_server_spawned: bool

True when this ChatApp is hosted inside TuiService (server-spawned). In that mode, context window changes are surfaced as a toast rather than triggering an automatic model reload.

§tool_descriptions: HashMap<String, String>

UUID → human-readable description map built once from list_tools().

§tool_call_format: ToolCallFormat

Format-specific markers to detect in the token stream.

§pending_tool_calls: usize

Number of tool calls dispatched but not yet resolved.

§spinner_tick: u32

Spinner frame index — incremented each tick while tool calls are in flight.

Implementations§

Source§

impl ChatApp

Source

pub fn new( model_name: String, cols: u16, rows: u16, spawner: StreamSpawner, ) -> Self

Source

pub fn new_private( model_name: String, cols: u16, rows: u16, spawner: StreamSpawner, session_id: Uuid, load_hook: LoadHook, save_hook: SaveHook, ) -> Self

Create a private chat app with encrypted history persistence.

load_hook is called immediately to restore any prior conversation. save_hook is called after each StreamComplete to persist history.

Source

pub fn with_gen_config(self, gen_config: Arc<RwLock<ChatGenConfig>>) -> Self

Replace the default gen_config with a pre-created Arc (to share with the spawner).

Source

pub fn with_server_spawned(self) -> Self

Mark this ChatApp as server-spawned (hosted inside TuiService).

When true, context window changes from the Settings modal push a toast with CLI instructions rather than triggering an automatic model reload.

Source

pub fn with_vfs(self, ns: Arc<Namespace>, subject: Subject) -> Self

Attach a VFS namespace for /path command routing.

The Tcl shell owner thread and the direct-Namespace driver thread (see crate::shell_driver) are both created lazily on first use, because TclShell is !Send and ChatApp must cross a thread boundary in spawn_app_process before it can settle on the thread its owner will spawn from.

Source

pub fn with_vfs_proxy( self, ns: Arc<Namespace>, subject: Subject, _vfs_tx: Sender<VfsRequest>, ) -> Self

Attach VFS namespace for /path command routing (compat shim).

The _vfs_tx parameter is ignored — TclShell now awaits namespace operations directly. This method exists for call-site compatibility; prefer with_vfs for new code.

Source

pub fn with_tool_caller( self, tool_caller: ToolCaller, tool_descriptions: HashMap<String, String>, tool_call_format: ToolCallFormat, ) -> Self

Configure tool calling. Call after construction if the MCP service is available.

tool_caller executes a tool by UUID and sends ToolCallResult back. tool_descriptions maps UUID → human label for display purposes. format selects the model-specific tool call syntax.

Source

pub fn on_token(&mut self, token: &str)

Ingest a streamed token from an external event source.

Source

pub fn on_stream_complete(&mut self)

Signal that the inference stream completed successfully.

Source

pub fn on_stream_cancelled(&mut self)

Signal that the inference stream was cancelled.

Source

pub fn on_stream_error(&mut self, msg: String)

Signal an inference error.

Source

pub fn on_template_error(&mut self, msg: String)

Signal a template application error.

Source

pub fn submit_message_payload(&mut self, user_text: String) -> String

Build the inference request payload as a JSON string (for WASM OSC output).

Trait Implementations§

Source§

impl TerminalApp for ChatApp

Available on non-WASI only.
Source§

type Command = KeyPress

App-specific command type. Must accept framework KeyPress via From.
Source§

fn render(&self, frame: &mut Frame<'_>)

Render the current frame.
Source§

fn handle_input(&mut self, key: KeyPress) -> bool

Handle a parsed input command. Return true if display needs redrawing.
Source§

fn tick(&mut self, _delta_ms: u64) -> bool

Advance state by delta_ms. Return true if redraw needed.
Source§

fn should_quit(&self) -> bool

Whether the application should exit.
§

fn input_extensions( &self, ) -> Vec<Box<dyn Fn(&[u8]) -> Option<(Self::Command, usize)>>>

Override to register custom OSC input handlers.

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<T> Instrument for T

§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided [Span], returning an Instrumented wrapper. Read more
§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts 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
§

impl<T> JaggedSlice<T> for T

§

type Index = Index2

§

fn push_into(self, array: &mut Jagged<T>)

§

fn insert_into(self, index: <T as JaggedSlice<T>>::Index, array: &mut Jagged<T>)

§

impl<T> Pointable for T

§

const ALIGN: usize

The alignment of pointer.
§

type Init = T

The type for initializers.
§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
§

impl<T> PolicyExt for T
where T: ?Sized,

§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns [Action::Follow] only if self and other return Action::Follow. Read more
§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns [Action::Follow] if either self or other returns Action::Follow. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
§

impl<T> ServiceExt for T

§

fn map_response_body<F>(self, f: F) -> MapResponseBody<Self, F>
where Self: Sized,

Apply a transformation to the response body. Read more
§

fn trace_for_http(self) -> Trace<Self, SharedClassifier<ServerErrorsAsFailures>>
where Self: Sized,

High level tracing that classifies responses using HTTP status codes. Read more
§

fn trace_for_grpc(self) -> Trace<Self, SharedClassifier<GrpcErrorsAsFailures>>
where Self: Sized,

High level tracing that classifies responses using gRPC headers. Read more
§

fn follow_redirects(self) -> FollowRedirect<Self>
where Self: Sized,

Follow redirect resposes using the Standard policy. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

§

fn vzip(self) -> V

§

impl<T> WithSubscriber for T

§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a [WithDispatch] wrapper. Read more
§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a [WithDispatch] wrapper. Read more
§

impl<T> ErasedDestructor for T
where T: 'static,

§

impl<T> MaybeSend for T
where T: Send,

§

impl<T> MaybeSend for T
where T: Send,