Skip to main content

Crate inline_client

Crate inline_client 

Source
Expand description

§inline-client

Stateful Rust client foundation for Inline.

This crate sits above inline-sdk. The SDK owns lower-level API, upload, and realtime RPC helpers. inline-client is the long-term TDLib-style client layer: auth/session lifecycle, realtime reconnect, update ordering, local cache, sync cursors, pending transactions, idempotent sends, and committed client events.

The first public surface is intentionally small. It defines shared vocabulary for hosts such as agents, CLI, bots, servers, native app bindings, and bridge adapters:

  • native peer, dialog, history, participant, message, and mutation records
  • typed async InlineClient handle plus single-owner ClientRunner
  • bounded command/event queues and in-flight backend request concurrency
  • backend and store boundaries
  • in-memory backend/store for client tests and host adapter tests
  • SQLite store for sessions, sync journals/cursors, a durable client-event outbox, dialogs, users, spaces, memberships, messages, tombstones, reactions, read state, and transactions
  • SDK-backed production backend using one multiplexed realtime RPC/event session
  • realtime connector boundary with SDK and fake connector implementations
  • host-provided external IDs for idempotency
  • Inline random IDs and transaction identity
  • client status and redacted error categories
  • committed client events
  • lossless vs best-effort event classification

Design rules:

  • keep inline-protocol, inline-sdk, and inline-client as separate layers
  • keep host-specific behavior out of the Rust client core
  • expose a small facade over an internal async client actor
  • use bounded command and event queues so overload becomes visible backpressure
  • emit committed state events after durable update application
  • classify realtime updates as lossless or best-effort before applying cache policy
  • keep live reads and cached reads explicit: a failed live request is never reported as a successful cached response
  • advance a cold bucket cursor only after rebuilding the state owned by that bucket: account identity/deletions, space membership, or a chat snapshot plus its bounded recent-history window
  • keep local storage pluggable so CLI, agents, desktop, and mobile clients can share the same sync model without sharing filesystem assumptions
  • use the standard Rust log facade in library code and leave logger initialization to parent binaries
  • redact tokens, message bodies, captions, local paths, and auth-sensitive fields from public debug output

inline-client is pre-1.0 and its public API may still evolve. The runtime routes auth/session lifecycle, live and cached dialogs/history, durable reconciliation snapshots, participant mutations, chat metadata/deletion, DM/thread/reply-thread creation, text/media sends, edits, message deletion, reactions, read and marked-unread state, and typing through a backend trait.

The SDK backend owns a long-lived multiplexed realtime connection, heartbeat and RPC timeouts, reconnect-triggered catch-up, InlineKit-compatible bucket discovery/gap recovery, bounded bucket concurrency, and a write-ahead sync journal so a crash cannot advance a bucket cursor past unapplied state. The built-in sync path negotiates a lossless schema revision, requires explicit accounting for every advanced sequence, rejects conflicting page envelopes, and treats realtime hints only as catch-up targets. Warm gaps are committed one validated page at a time, so very long gaps resume from durable progress rather than replaying an entire in-memory batch. Incompatible pending journals are discarded without cursor advance and refetched from the authoritative server. Built-in stores commit each cursor change and its resulting lossless events in one transaction. Lossless events remain in an outbox until the consumer acknowledges their delivery, so a restart replays events whose host handoff may not have completed. Custom stores that do not implement the outbox extension fail before committing a cursor that produced lossless events. Cached reads are available for consumers that need to reconcile without causing network bursts. Use DialogsOrder::StableChatId for mutation-safe full-account reconciliation; the default recent-activity order is intended for user-facing lists. Live getChats results are visibility-filtered snapshots: they merge current records into the durable store, but omission alone never tombstones a cached dialog. Lossless deletion updates and explicit reconciliation tombstones own chat deletion. Logout attempts to revoke the active Inline server session before clearing all local account state.

Cold chat repair intentionally fetches the current chat snapshot and the latest 50 messages, matching InlineKit’s ownership boundary. Older history is paged by normal history APIs and host checkpoints; a cold user bucket does not walk every chat, download an account’s complete message history, or fetch every space’s membership. Space membership remains owned by its independently repairable space bucket.

Message sends expose their durable transaction state. Retriable or uncertain stored sends are reconciled by reissuing the same server-idempotent random ID; terminal failures are returned explicitly instead of masquerading as pending messages.

Host-only protocol envelopes, HTTP/WebSocket routes, process flags, Matrix projection, and deployment behavior remain outside this crate. Production consumers should take the single bounded lossless event receiver. Use recv_delivery() and call LosslessEventDelivery::ack() only after the event is durable in the host. Dropping a delivery without a successful acknowledgement releases its process-local claim for replay. The compatibility recv() method attempts acknowledgement before it returns and is intended for consumers that accept the legacy at-most-once host handoff. A host that has lost its own delivery history can reconcile from account_state, chat_state, cached dialogs, and cached history. The built-in SQLite store protects credentials only with filesystem permissions; hosts that require encrypted-at-rest session storage should provide a ClientStore implementation backed by their platform keychain or secret store.

Re-exports§

pub use backend::BackendError;
pub use backend::BackendResult;
pub use backend::ClientBackend;
pub use backend::InMemoryBackend;
pub use backend::OperationOutcome;
pub use backend::SendTextOutcome;
pub use realtime::FakeRealtimeAttempt;
pub use realtime::FakeRealtimeConnector;
pub use realtime::RealtimeConnectRequest;
pub use realtime::RealtimeConnectionInfo;
pub use realtime::RealtimeConnector;
pub use realtime::SdkRealtimeConnector;
pub use runtime::ClientCommandError;
pub use runtime::ClientRequestError;
pub use runtime::ClientRunner;
pub use runtime::DEFAULT_COMMAND_QUEUE_CAPACITY;
pub use runtime::DEFAULT_EVENT_QUEUE_CAPACITY;
pub use runtime::DEFAULT_LOSSLESS_EVENT_QUEUE_CAPACITY;
pub use runtime::DEFAULT_MAX_CONCURRENT_REQUESTS;
pub use runtime::InlineClient;
pub use runtime::InlineClientBuilder;
pub use runtime::InlineClientRuntime;
pub use runtime::LosslessEventDelivery;
pub use runtime::LosslessEventReceiver;
pub use runtime::ReconnectPolicy;
pub use sdk_backend::SdkBackend;
pub use sdk_backend::SdkBackendBuildError;
pub use sdk_backend::SdkBackendBuilder;
pub use store::AccountStateSnapshot;
pub use store::ChatStateSnapshot;
pub use store::ClientEventDelivery;
pub use store::ClientStore;
pub use store::InMemoryStore;
pub use store::PendingSyncBatch;
pub use store::SqliteStore;
pub use store::StoreError;
pub use store::StoreResult;
pub use store::StoredReaction;
pub use store::StoredReadState;
pub use store::StoredSession;
pub use store::StoredTransaction;
pub use store::SyncBucketKey;
pub use store::SyncBucketPeer;
pub use store::SyncBucketState;
pub use store::SyncState;
pub use sync::SyncConfig;
pub use types::AddChatParticipantRequest;
pub use types::AuthContactKind;
pub use types::AuthCredential;
pub use types::AuthStartRequest;
pub use types::AuthStartResult;
pub use types::AuthToken;
pub use types::AuthVerifyRequest;
pub use types::AuthVerifyResult;
pub use types::ChatCreateParticipant;
pub use types::ChatParticipantRecord;
pub use types::ChatParticipantsPage;
pub use types::ChatParticipantsRequest;
pub use types::ClientStatusSnapshot;
pub use types::ConnectRequest;
pub use types::CreateDmRequest;
pub use types::CreateReplyThreadRequest;
pub use types::CreateThreadRequest;
pub use types::CreatedChat;
pub use types::DeleteChatRequest;
pub use types::DeleteMessageRequest;
pub use types::DialogFollowMode;
pub use types::DialogNotificationMode;
pub use types::DialogRecord;
pub use types::DialogsOrder;
pub use types::DialogsPage;
pub use types::DialogsRequest;
pub use types::EditMessageRequest;
pub use types::HistoryPage;
pub use types::HistoryRequest;
pub use types::MediaKind;
pub use types::MessageContent;
pub use types::MessageMutation;
pub use types::MessageRecord;
pub use types::NotificationMode;
pub use types::PeerRef;
pub use types::ReactRequest;
pub use types::ReadRequest;
pub use types::RemoveChatParticipantRequest;
pub use types::SendTextRequest;
pub use types::SetMarkedUnreadRequest;
pub use types::SpaceMemberRecord;
pub use types::SpaceMemberRole;
pub use types::SpaceRecord;
pub use types::TypingRequest;
pub use types::UpdateChatInfoRequest;
pub use types::UpdateDialogNotificationsRequest;
pub use types::UploadHandle;
pub use types::UploadRequest;
pub use types::UserRecord;
pub use types::UserSettingsRecord;

Modules§

backend
Backend/store boundary for client runtime operations. Backend boundary for client runtime operations.
prelude
Convenient imports for common client consumers.
realtime
Realtime connector boundary. Realtime connector boundary.
runtime
Async client facade and runner. Async client facade and runner.
sdk_backend
SDK-backed backend implementation. SDK-backed production backend.
store
Durable store boundary. Store boundary for durable client state.
sync
Inline-native update discovery and bucket recovery policy. Inline-native update discovery, ordering, and bucket recovery.
types
Native Inline client request and record types. Native Inline client request and record types.

Structs§

ClientFailure
Redacted failure value suitable for status endpoints and bridge errors.
ClientIdentity
Application identity sent with Inline HTTP and realtime requests.
ExternalId
Opaque host-provided ID used for idempotency and echo reconciliation.
InlineId
Opaque Inline ID used by high-level client events.
RandomId
Deterministic random ID attached to an Inline mutation.
TransactionEvent
Transaction event emitted after client state changes.
TransactionId
Stable client transaction ID.
TransactionIdentity
Identity data used to reconcile a mutation across host, client, and server.

Enums§

ClientError
Errors returned by public inline-client helper types.
ClientErrorCategory
Stable error categories exposed to client hosts.
ClientEvent
Committed client event for apps, bridges, agents, and hosts.
ClientStatus
High-level connection/auth state for apps, bridges, and agents.
EventReliability
Reliability class for events delivered to hosts.
TransactionState
State of a durable client transaction.

Constants§

CORE_SYNC_SCHEMA_REVISION
Lossless bucket-sync schema implemented by this client release.
VERSION
Published package version.