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§
Sourcefn send(
&mut self,
bot_id: &BotId,
messages: &[Message],
tools: &[Tool],
) -> BoxPlatformSendStream<'static, ClientResult<MessageContent>>
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.
Sourcefn bots(&self) -> BoxPlatformSendFuture<'static, ClientResult<Vec<Bot>>>
fn bots(&self) -> BoxPlatformSendFuture<'static, ClientResult<Vec<Bot>>>
Interrupt the bot’s current operation. Bots available under this client.
Provided Methods§
Sourcefn content_widget(
&mut self,
_cx: &mut Cx,
_previous_widget: WidgetRef,
_templates: &HashMap<LiveId, LivePtr>,
_content: &MessageContent,
) -> Option<WidgetRef>
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.