Skip to content

React Native (@agentimhq/client-react-native) API

Generated from the source and its doc comments (sdk/client-react-native/src/client.ts).

Terminal window
npm install @agentimhq/client-react-native
interface ClientOptions

How the client starts: the server address, this device’s id, the token provider, the cache and how it names itself.

url: string

https://chat.example.com.

deviceId: string

This device’s id, the same every run (1..64 of A-Z a-z 0-9 _ -).

tokenProvider: () => Promise<string>

A client token from your backend; throw TokenRefused to stop.

storeDir?: string

Where the cache lives (the app’s documents directory); none keeps it in memory.

deviceName?: string

A name for this device in the user’s device list, like “Maya’s laptop”.

platform?: string

The platform reported to the server (web, ios, android…), for the device list and push.

clientName?: string

This app’s name, sent with each connection (for diagnostics and the server’s minimum-version rules).

clientVersion?: string

This app’s version, sent with clientName.

commandTimeoutMs?: number

How long a command waits for its answer before failing with timeout, in ms (default 60000).

class AgentIMClient

The AgentIM client for one account on one device: keeps the connection, syncs, sends the offline queue in order, keeps the local cache, and turns everything into observable state.

readonly connection = new Observable<Connection>({ state: 'closed' })

The connection state (closed, connecting, connected, disconnected, suspended, failed) and why; subscribe to follow it.

readonly conversations = new Observable<any[]>([])

The conversation list, newest first, kept up to date.

static version(): string

The version of the native core.

static create(o: ClientOptions): AgentIMClient

Starts a client with its options: the server address, this device’s id, the token provider and the cache. Nothing connects until connect. The native core runs on its own thread.

command(cmd: Record<string, unknown>, applyInOrder?: (r: any) => void): Promise<any>

Any core command ({cmd: …}); resolves with its result.

on(type: string, fn: Listener): () => void

Events: operation, side, signal, reset, storage, event, read, mute.

setNetwork(online: boolean)

NetInfo: call on every change.

setForeground(foreground: boolean)

AppState: active is the foreground.

messages(convId: string): Messages

The messages of a conversation, oldest first, kept up to date while subscribed; pages back with loadOlder.

connect()

Connects and keeps connecting: reconnects with backoff when the network or the server goes, syncs what it missed, sends the offline queue.

close()

Disconnects; the queue and the cache stay. connect again picks up where it stopped.

logout()

Logs out here: closes and wipes the cache and the queue (GDPR).

send(convId: string, text: string, opts: { kind?: string; payload?: unknown; replyTo?: string; clientMsgId?: string; threadId?: string; alsoInConv?: boolean } = {})

Sends a text (or a custom kind with its payload): shown at once as sending, sent when the connection allows, in order. Returns the client_msg_id and the local key; a retry with the same client_msg_id is the same message.

sendFile(convId: string, path: string, opts: { name?: string; mime?: string; caption?: string; replyTo?: string; clientMsgId?: string; keepMetadata?: boolean } = {})

Sends a file or a photo from a path (file:// URIs work): shown at once as uploading, sent when it is up. A photo loses its EXIF and GPS (unless keepMetadata) and gets a 320-pixel thumbnail (docs/en/design/messaging.md).

localPreview(key?: string | null): string | undefined

A local address for a file this device is sending (payload.local_thumb or local_source: paths).

fileUrl(convId: string, fileId: string, variant: 'original' | 'thumb' = 'original'): Promise<{ url: string; variant: string; expires_at: number }>

A link (valid a few minutes) to read a file: original or thumb.

edit(convId: string, target: { msgId?: string; clientMsgId?: string }, text: string)

Edits one of my messages (by msgId, or by clientMsgId while it is still queued); the change shows at once.

recall(convId: string, target: { msgId?: string; clientMsgId?: string })

Recalls one of my messages for everyone; a message still in the queue is simply not sent.

read(convId: string, seq?: number)

Marks the conversation read up to seq (default: the newest) on all my devices.

feedback(convId: string, msgId: string, rating: 'up' | 'down', reason?: string)

Rates an agent’s message up or down, with an optional reason.

react(convId: string, msgId: string, key: string): Promise<{ changed: boolean; seq?: number }>

Adds a reaction (one emoji, or one of the app’s :names:); adding it twice changes nothing.

unreact(convId: string, msgId: string, key: string): Promise<{ changed: boolean; seq?: number }>

Removes my reaction; removing one that is not there changes nothing.

listReactions(convId: string, msgId: string, key: string, opts: { afterSeq?: number; limit?: number } = {})

Who reacted to a message with a key, oldest first.

pin(convId: string, msgId: string): Promise<{ changed: boolean; seq?: number }>

Pins a message to the conversation; pinning it again changes nothing.

unpin(convId: string, msgId: string): Promise<{ changed: boolean; seq?: number }>

Unpins a message.

listPins(convId: string, opts: { beforeSeq?: number; limit?: number } = {})

The conversation’s pinned messages, latest pin first.

pullThread(convId: string, threadId: string, opts: { afterSeq?: number; limit?: number } = {})

A thread’s root and its replies after afterSeq.

listThreads(opts: { convId?: string; before?: number; limit?: number } = {})

The threads I follow (in one conversation, or all), latest reply first, with unread counts.

readThread(convId: string, threadId: string, seq: number)

Marks a thread read up to seq on all my devices.

followThread(convId: string, threadId: string, follow = true)

Follows a thread (its replies notify me) or stops following it.

msgSummary(convId: string, msgIds: string[])

The thread summary, reactions and pin of up to 100 messages (for messages loaded from history).

respond(convId: string, msgId: string, blockId: string, r: { action?: string; values?: Record<string, unknown> })

Answers a card: a button (action) or a filled form (values).

retry(convId: string, clientMsgId: string)

Sends a failed message again (the same client_msg_id, so it is never doubled).

discard(convId: string, clientMsgId: string)

Drops a failed or waiting message from the queue.

pendingOps()

What waits in the offline queue.

call(op: string, args: Record<string, unknown> = {})

A request that needs the server now (approvals, decisions, queries); fails at once when offline.

debugState()

Everything that helps report a problem: the connection, positions, the queue and recent failures.

dispose()

Stops the client; no event arrives after it. Waiting calls fail with closed.