Skip to main content

Crate ai_ui_core

Crate ai_ui_core 

Source
Expand description

Rust port of @assistant-ui/core: the thread message model, the branching message repository, the model adapter contract and the local thread runtime.

use ai_ui_core::{adapter, AppendMessage, ChatModelRunResult, LocalRuntimeOptions, LocalThreadRuntime};

let runtime = LocalThreadRuntime::new(
    |_options| adapter::from_results([Ok(ChatModelRunResult::text("Hello!"))]),
    LocalRuntimeOptions::default(),
);
let run = runtime.append(AppendMessage::user_text(None, "Hi")).unwrap();
futures_executor::block_on(run).unwrap();
assert_eq!(runtime.messages().last().unwrap().text(), "Hello!");

Re-exports§

pub use abort::AbortController;
pub use abort::AbortSignal;
pub use adapter::ChatModelAdapter;
pub use adapter::ChatModelRunOptions;
pub use adapter::ChatModelRunResult;
pub use adapter::ModelContext;
pub use adapter::RunError;
pub use adapter::RunStream;
pub use external_store::ExternalStore;
pub use external_store::ExternalStoreRuntime;
pub use external_store::StoreFuture;
pub use local::Composer;
pub use local::LocalRuntimeOptions;
pub use local::LocalThreadRuntime;
pub use local::Tool;
pub use local::ToolContext;
pub use local::ToolFuture;
pub use local::ToolRegistry;
pub use repository::ExportedMessage;
pub use repository::ExportedRepository;
pub use repository::MessageChanges;
pub use repository::MessageRepository;
pub use repository::RepositoryError;
pub use runtime::ComposerHost;
pub use runtime::RunFuture;
pub use runtime::RuntimeCapabilities;
pub use runtime::RuntimeError;
pub use runtime::StartRunConfig;
pub use runtime::ThreadRuntime;
pub use runtime::ToolResult;
pub use smooth::SmoothOptions;
pub use smooth::SmoothText;
pub use thread_list::AdapterFuture;
pub use thread_list::RemoteThread;
pub use thread_list::Spawner;
pub use thread_list::ThreadItem;
pub use thread_list::ThreadList;
pub use thread_list::ThreadListAdapter;
pub use thread_list::ThreadStatus;
pub use types::*;

Modules§

abort
Cancellation for model runs, standing in for the web AbortSignal.
adapter
The model adapter contract, ported from chat-model-adapter.ts.
external_store
The external-store runtime, after upstream’s useExternalStoreRuntime.
local
In-memory thread runtime driving a ChatModelAdapter, ported from runtimes/local/local-thread-runtime-core.ts.
repository
Branching message store, ported from message-repository.ts.
runtime
The thread runtime interface, after upstream’s ThreadRuntimeCore.
smooth
Smooth streaming text, ported from @assistant-ui/react’s useSmooth (TextStreamAnimator).
thread_list
The thread list, after upstream’s ThreadListRuntimeCore and its remote variant: many threads, one of them the main thread.
types
Thread message model, ported from @assistant-ui/core types/message.ts.

Structs§

Subscribers
A list of change callbacks shared by runtimes and view layers.
Subscription
Keeps a callback registered; dropping it unsubscribes.