Trait BotClient

Source
pub trait BotClient: Send {
    // Required methods
    fn send(
        &mut self,
        bot_id: &BotId,
        messages: &[Message],
        tools: &[Tool],
    ) -> BoxPlatformSendStream<'static, ClientResult<MessageContent>>;
    fn bots(&self) -> BoxPlatformSendFuture<'static, ClientResult<Vec<Bot>>>;
    fn clone_box(&self) -> Box<dyn BotClient>;

    // Provided method
    fn content_widget(
        &mut self,
        _cx: &mut Cx,
        _previous_widget: WidgetRef,
        _templates: &HashMap<LiveId, LivePtr>,
        _content: &MessageContent,
    ) -> Option<WidgetRef> { ... }
}
Expand description

A standard interface to fetch bots information and send messages to them.

Warning: Expect this to be cloned to avoid borrow checking issues with makepad’s widgets. Also, it may be cloned inside async contexts. So keep this cheap to clone and synced.

Note: Generics do not play well with makepad’s widgets, so this trait relies on dynamic dispatch (with its limitations).

Required Methods§

Source

fn send( &mut self, bot_id: &BotId, messages: &[Message], tools: &[Tool], ) -> BoxPlatformSendStream<'static, ClientResult<MessageContent>>

Send a message to a bot with support for streamed response.

Each message yielded by the stream should be a snapshot of the full message as it is being built.

You are free to add, modify or remove content on-the-go.

Source

fn bots(&self) -> BoxPlatformSendFuture<'static, ClientResult<Vec<Bot>>>

Interrupt the bot’s current operation. Bots available under this client.

Source

fn clone_box(&self) -> Box<dyn BotClient>

Make a boxed dynamic clone of this client to pass around.

Provided Methods§

Source

fn content_widget( &mut self, _cx: &mut Cx, _previous_widget: WidgetRef, _templates: &HashMap<LiveId, LivePtr>, _content: &MessageContent, ) -> Option<WidgetRef>

Optionally override how the content of a message is rendered by Makepad.

Not expected to be implemented by most clients, however if this client interfaces with a service that gives content in non-standard formats, this can be used to extend moly-kit to support it.

Prefer reusing previous widget if matches the expected type instead of creating a new one on every call to preserve state and avoid perfomance issues.

Trait Implementations§

Source§

impl Clone for Box<dyn BotClient>

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more

Implementors§