State, streams and errors

The listenables and streams on KletsoClient, sending structured values, conversations, and the exception hierarchy.

Listenables

MemberTypeMeaning
connectionKletsoValueListenable<KletsoConnectionState>closed, connecting, open, reconnecting
sessionKletsoValueListenable<KletsoSessionBootstrap?>Session, end user, agent info, theme, URL allowlist
messagesKletsoValueListenable<List<KletsoMessage>>Active conversation, oldest first, including pending echoes and surfaces
conversationsKletsoValueListenable<List<KletsoConversation>>Most recent first
activeConversationKletsoValueListenable<KletsoConversation?>
agentTypingKletsoValueListenable<bool>True while deltas arrive, with a TTL
contextMap<String, Object?>Current context (read-only view)

Use .asFlutter() (from kletso_flutter) to get a ValueListenable for ValueListenableBuilder.

Streams

  • events: every KletsoEvent: KletsoServerEvent(envelope), KletsoConnectionChanged, KletsoClientError, KletsoUnknownComponent, KletsoLocalActionRan.
  • notifications: KletsoNotification (payload, conversation, source live or push), deduplicated.
  • ui.commandResults, ui.notificationResults: outcomes of server commands and notifications.

Conversations

await client.startConversation(title: 'Support');
await client.switchConversation(id);
final list = await client.listConversations();
final c = await client.ensureConversation();   // most recent open one, or a new one

Sending

await client.send(KletsoOutbound.text('Where is my order?'));
await client.send(KletsoOutbound.value({'intent': 'select_flight', 'flightId': 'NH873'}, label: 'NH873'));

KletsoOutbound.action, .form and .confirm exist for widgets; the built-in blocks use them. Every send adds an optimistic echo to messages and is queued if offline. Sending before identifyAnonymous/authenticate throws KletsoStateException.

Exceptions

All extend KletsoException: KletsoNetworkException, KletsoTimeoutException, KletsoAuthException (expired flag), KletsoRateLimitException, KletsoProtocolException, KletsoServerException (code, statusCode, retryable), KletsoToolException, KletsoWorkflowException, KletsoStateException, KletsoQueueOverflowException. Connection-level failures are delivered as KletsoClientError on events rather than thrown into your UI.

Last updated 2026-09-28 · Report an issue with this page