KletsoFakeBackend class final
A complete fake runtime in memory: REST (KletsoApi) and realtime (KletsoTransport) with an agent that answers from the protocol fixtures.
Say "flight", "hotel", "products", "sales", "cancel my order", "callback", "order", "human" or "error" to get the matching surface or behaviour; anything else is echoed with quick replies. Actions on surfaces are answered too (select flight, book, add to cart, confirm, submit form).
- Implemented types
Constructors
- KletsoFakeBackend({KletsoFakeScenario scenario = const KletsoFakeScenario(), DateTime? now})
- Creates a backend.
Properties
- audioBytesReceived → int
-
Bytes of microphone PCM received over all sockets, for assertions.
no setter
- handshakes → int
-
Number of handshakes attempted.
no setter
- hashCode → int
-
The hash code for this object.
no setterinherited
- name → String
-
Short name for logs (
ws,sse,fake).no setteroverride - openSockets → int
-
Sockets currently open.
no setter
- pushesSent → int
-
How many push payloads sendPush produced.
no setter
-
pushTokens
→ Map<
String, KletsoPushToken> -
Push tokens registered per end user, for assertions.
no setter
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
- scenario → KletsoFakeScenario
-
Behaviour knobs.
final
-
sentFrames
→ Stream<
KletsoClientFrame> -
Every client frame any socket received (for assertions).
no setter
Methods
-
close(
) → void -
Releases sockets. The instance is unusable afterwards.
override
-
contextOf(
String endUserId) → Map< String, Object?> -
The runtime context the fake holds for
endUserId(fromcontextframes andPUT/PATCHcalls), for assertions. -
createConversation(
KletsoSession session, {String? agentId, String? title}) → Future< KletsoConversation> -
POST /v1/conversations.override -
createSession(
{required String agentId, required KletsoDevice device, String? userToken, String? visitorId, JsonMap context = const <String, Object?>{}}) → Future< KletsoSessionBootstrap> -
POST /v1/sessions.override -
deleteSession(
KletsoSession session) → Future< void> -
DELETE /v1/sessions/current.override -
dropAllSockets(
[int code = 1001, String reason = 'deploy']) → void -
Closes every open socket with
code(simulates a deploy). -
emit(
String conversationId, String type, JsonMap data, {String? turnId}) → void -
Appends a server-authored event of
typewithdatato a conversation (e.g.agent.typing, or a trigger opening a conversation). -
expireTokens(
) → void - Marks the current session tokens expired: open sockets close with 4403 and the next handshake with an old token fails until refreshed.
-
listConversations(
KletsoSession session) → Future< List< KletsoConversation> > -
GET /v1/conversations.override -
listEvents(
KletsoSession session, String conversationId, {int after = 0, int limit = 200}) → Future< List< KletsoEventEnvelope> > -
GET /v1/conversations/:id/events?after=.override -
logOf(
String conversationId) → List< KletsoEventEnvelope> -
Event log of
conversationId, for assertions. -
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
notify(
String endUserId, KletsoAppNotification n) → KletsoEventEnvelope - Server-originated notification (what a dashboard workflow's "notify the app" step does): delivered live over the user's socket, attached to the user's latest open conversation (created if needed).
-
open(
KletsoTransportRequest request) → Future< KletsoSocket> -
Connects and authenticates.
override
-
postAction(
KletsoSession session, String conversationId, KletsoActionFrame frame) → Future< void> -
POST /v1/conversations/:id/actions(used by the SSE transport).override -
postMessage(
KletsoSession session, String conversationId, KletsoMessageFrame frame) → Future< void> -
POST /v1/conversations/:id/messages(used by the SSE transport).override -
postTrigger(
KletsoSession session, KletsoClientFrame frame) → Future< void> -
POST /v1/events(track/screen triggers over HTTP).override -
refreshSession(
KletsoSession current, {String? userToken}) → Future< KletsoSession> -
POST /v1/sessions/refresh;userTokenre-verifies a renewed host JWT.override -
registerPushToken(
KletsoSession session, KletsoPushToken token) → Future< void> -
PUT /v1/sessions/current/push-token: lets the runtime reach this device withapp.notifyevents while the app is in the background.override -
sendPush(
String endUserId, KletsoAppNotification n) → Map< String, Object?> -
Builds the data map a push provider would deliver for
nwhile the app is in the background:{'kletso': '<envelope json>'}. Hosts feed it toKletsoClient.handlePushPayload. Requires a registered push token. Nothing is sent over the socket, so the only way the app learns about it is through the push. -
toString(
) → String -
A string representation of this object.
inherited
-
unregisterPushToken(
KletsoSession session) → Future< void> -
DELETE /v1/sessions/current/push-token.override -
updateContext(
KletsoSession session, JsonMap context, {required bool replace}) → Future< void> -
PUT/PATCH /v1/sessions/current/context.override
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited
Constants
- agentId → const String
- Agent id the fake serves.
-
allowedComponents
→ const List<
String> - The custom component type the fake agent may render.
-
allowedUrlHosts
→ const List<
String> - Hosts the fake agent links to.
-
fakeAvatar
→ const Map<
String, Object?> - The avatar block the fake session bootstrap carries (mirrors the runtime's defaults).