Swift (iOS, macOS) API
Generated from the source and its doc comments (sdk/client-swift/Sources/AgentIM/AgentIMClient.swift).
.package(url: "https://github.com/wmkrfjnwvb-svg/agentim-swift", from: "0.1.0")ClientOptions
Section titled “ClientOptions”public struct ClientOptionsHow the client starts: the server address, this device’s id, the cache, the token provider and how it names itself.
ClientOptions.url
Section titled “ClientOptions.url”public var url: Stringhttps://chat.example.com.
ClientOptions.deviceId
Section titled “ClientOptions.deviceId”public var deviceId: StringThis device’s id, the same every run (1..64 of A-Z a-z 0-9 _ -).
ClientOptions.storeDir
Section titled “ClientOptions.storeDir”public var storeDir: String?Where the cache lives; nil keeps it in memory.
ClientOptions.deviceName
Section titled “ClientOptions.deviceName”public var deviceName: String?A name for this device in the user’s device list, like “Maya’s iPhone”.
ClientOptions.platform
Section titled “ClientOptions.platform”public var platform: String?The platform reported to the server (ios, android, windows…), for the device list and push.
ClientOptions.tokenProvider
Section titled “ClientOptions.tokenProvider”public var tokenProvider: @Sendable () async throws -> StringA client token from your backend; throw TokenRefused to stop.
ClientOptions.clientName
Section titled “ClientOptions.clientName”public var clientName = "agentim-swift"This app’s name, sent to the server with each connection (for diagnostics and minimum-version rules).
ClientOptions.clientVersion
Section titled “ClientOptions.clientVersion”public var clientVersion = "0.1.0"This app’s version, sent with clientName.
ClientOptions.commandTimeout
Section titled “ClientOptions.commandTimeout”public var commandTimeout: TimeInterval = 60How long a command waits for its answer before failing with timeout. In seconds.
ClientOptions.init
Section titled “ClientOptions.init”public init(url: String, deviceId: String, storeDir: String? = nil, deviceName: String? = nil, platform: String? = nil,Options with the required server address, device id and token provider; the rest are optional.
TokenRefused
Section titled “TokenRefused”public struct TokenRefused: ErrorThrown by a token provider when the backend refuses the user.
TokenRefused.init
Section titled “TokenRefused.init”public init() {}Throw TokenRefused() from the token provider.
AgentIMError
Section titled “AgentIMError”public struct AgentIMError: Error, CustomStringConvertibleThe server’s code (forbidden, not_found, conflict, bad_request, blocked, rate_limited…) or the client’s (disconnected, timeout, closed…); unknown codes pass through as they are.
AgentIMError.code
Section titled “AgentIMError.code”public let code: StringThe error code: the server’s (forbidden, not_found, conflict, bad_request, …) or the client’s (disconnected, timeout, closed, unauthenticated).
AgentIMError.message
Section titled “AgentIMError.message”public let message: StringA human-readable explanation, for logs (not for showing to users).
AgentIMError.retryable
Section titled “AgentIMError.retryable”public let retryable: BoolWhether the same request may work later.
AgentIMError.retryAfterMs
Section titled “AgentIMError.retryAfterMs”public let retryAfterMs: Int64?How long the server asked to wait before trying again.
AgentIMError.init
Section titled “AgentIMError.init”public init(code: String, message: String, retryable: Bool = false, retryAfterMs: Int64? = nil)An error with its code; used by the client and by tests.
AgentIMError.description
Section titled “AgentIMError.description”public var description: String { "\(code): \(message)" }code: message.
Connection
Section titled “Connection”public struct Connection: EquatableThe connection state and why: state is closed, connecting, connected, disconnected, suspended or failed.
Connection.state
Section titled “Connection.state”public let state: Stringclosed, connecting, connected, disconnected, suspended or failed.
Connection.reason
Section titled “Connection.reason”public let reason: String?Why it is not connected (an error code), when it is not.
Connection.retryAt
Section titled “Connection.retryAt”public let retryAt: Int64?When the next reconnect attempt is due (Unix ms), while waiting to reconnect.
Message
Section titled “Message”public struct MessageOne message as shown; raw has every field the core gives.
Message.key
Section titled “Message.key”public let key: StringThe stable local key: the same while the message goes from sending to sent, for list identity.
Message.msgId
Section titled “Message.msgId”public let msgId: String?The server’s id, once sent.
Message.clientMsgId
Section titled “Message.clientMsgId”public let clientMsgId: String?The id this device gave the message, for retries.
Message.content
Section titled “Message.content”public let content: StringThe text (for a streaming reply, what has arrived so far).
Message.status
Section titled “Message.status”public let status: Stringsent, sending or failed.
Message.state
Section titled “Message.state”public let state: String?The server state: normal, edited, recalled…
Message.senderType
Section titled “Message.senderType”public let senderType: String?human, agent, system: agent messages must show the AI mark (EU AI Act art. 50).
Message.order
Section titled “Message.order”public let order: DoubleThe sort position in the list.
Message.raw
Section titled “Message.raw”public let raw: JSONObjectEvery field as the core sent it.
Conversation
Section titled “Conversation”public struct ConversationOne conversation in the list.
Conversation.convId
Section titled “Conversation.convId”public let convId: StringThe conversation id.
Conversation.raw
Section titled “Conversation.raw”public let raw: JSONObjectEvery field as the core sent it.
Messages
Section titled “Messages”public final class MessagesOne conversation’s messages as shown, oldest first.
Messages.convId
Section titled “Messages.convId”public let convId: StringThe conversation these messages belong to.
Messages.loadOlder
Section titled “Messages.loadOlder”public func loadOlder() async throws -> BoolThe page before the oldest shown: the cache first, then the server. False at the start.
Messages.jumpTo
Section titled “Messages.jumpTo”public func jumpTo(_ seq: Int64) async throwsA page around a message (it stays loaded).
AgentIMClient
Section titled “AgentIMClient”public final class AgentIMClient: @unchecked SendableThe 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.
AgentIMClient.version
Section titled “AgentIMClient.version”public static var version: String { String(cString: agentim_version()) }The version of the native core.
AgentIMClient.init
Section titled “AgentIMClient.init”public init(_ o: ClientOptions, queue: DispatchQueue = .main) throwsqueue: where state changes, events and replies are handled, in order (main by default).
AgentIMClient.command
Section titled “AgentIMClient.command”public func command(_ cmd: JSONObject) async throws -> Any?Any core command (["cmd": …]); returns its result.
AgentIMClient.on
Section titled “AgentIMClient.on”public func on(_ type: String, _ fn: @escaping (JSONObject) -> Void) -> SubscriptionEvents: operation, side, signal, reset, storage, event, read, mute (and the ones above). Handled on the client’s queue; call cancel() on the result to stop.
AgentIMClient.setNetwork
Section titled “AgentIMClient.setNetwork”public func setNetwork(online: Bool)The platform’s network: call on every change (NWPathMonitor).
AgentIMClient.setForeground
Section titled “AgentIMClient.setForeground”public func setForeground(_ foreground: Bool)The app came to the foreground or went to the background (scenePhase).
AgentIMClient.messages
Section titled “AgentIMClient.messages”public func messages(_ convId: String) -> MessagesThe conversation’s messages, kept up to date. Call on the client’s queue (main).
AgentIMClient.connect
Section titled “AgentIMClient.connect”public func connect() async throws { try await command(["cmd": "connect"]) }Connects and keeps connecting: reconnects with backoff when the network or the server goes, syncs what it missed, sends the offline queue.
AgentIMClient.disconnect
Section titled “AgentIMClient.disconnect”public func disconnect() async throws { try await command(["cmd": "close"]) }Closes the connection (the client stays usable; close() frees it).
AgentIMClient.logout
Section titled “AgentIMClient.logout”public func logout() async throws { try await command(["cmd": "logout"]) }Logs out here: closes and wipes the cache and the queue (GDPR).
AgentIMClient.send
Section titled “AgentIMClient.send”public func send(_ convId: String, _ text: String, clientMsgId: String? = nil, replyTo: String? = nil, threadId: String? = nil, alsoInConv: Bool = false) async throws -> JSONObjectReturns client_msg_id and key once the message is queued and shown.
AgentIMClient.sendFile
Section titled “AgentIMClient.sendFile”public func sendFile(_ convId: String, path: String, name: String? = nil, mime: String? = nil, caption: String? = nil, replyTo: String? = nil, keepMetadata: Bool = false) async throws -> JSONObjectSends a file or a photo from a path: 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).
AgentIMClient.fileUrl
Section titled “AgentIMClient.fileUrl”public func fileUrl(_ convId: String, fileId: String, variant: String = "original") async throws -> JSONObjectA link (valid a few minutes) to read a file: original or thumb.
AgentIMClient.edit
Section titled “AgentIMClient.edit”public func edit(_ convId: String, msgId: String, _ text: String) async throwsEdits one of my messages (by msgId, or by clientMsgId while it is still queued); the change shows at once.
AgentIMClient.recall
Section titled “AgentIMClient.recall”public func recall(_ convId: String, msgId: String) async throwsRecalls one of my messages for everyone; a message still in the queue is simply not sent.
AgentIMClient.read
Section titled “AgentIMClient.read”public func read(_ convId: String, seq: Int64? = nil) async throwsMarks the conversation read up to seq (default: the newest) on all my devices.
AgentIMClient.retry
Section titled “AgentIMClient.retry”public func retry(_ convId: String, clientMsgId: String) async throwsSends a failed message again (the same client_msg_id, so it is never doubled).
AgentIMClient.discard
Section titled “AgentIMClient.discard”public func discard(_ convId: String, clientMsgId: String) async throwsDrops a failed or waiting message from the queue.
AgentIMClient.react
Section titled “AgentIMClient.react”public func react(_ convId: String, msgId: String, key: String) async throws -> JSONObjectAdds a reaction (one emoji, or one of the app’s :names:); adding it twice changes nothing.
AgentIMClient.unreact
Section titled “AgentIMClient.unreact”public func unreact(_ convId: String, msgId: String, key: String) async throws -> JSONObjectRemoves my reaction; removing one that is not there changes nothing.
AgentIMClient.pin
Section titled “AgentIMClient.pin”public func pin(_ convId: String, msgId: String) async throws -> JSONObjectPins a message to the conversation; pinning it again changes nothing.
AgentIMClient.unpin
Section titled “AgentIMClient.unpin”public func unpin(_ convId: String, msgId: String) async throws -> JSONObjectUnpins a message.
AgentIMClient.listPins
Section titled “AgentIMClient.listPins”public func listPins(_ convId: String) async throws -> JSONObjectThe conversation’s pinned messages, latest pin first.
AgentIMClient.pullThread
Section titled “AgentIMClient.pullThread”public func pullThread(_ convId: String, threadId: String, afterSeq: Int64 = 0) async throws -> JSONObjectA thread’s root and its replies after afterSeq.
AgentIMClient.listThreads
Section titled “AgentIMClient.listThreads”public func listThreads(convId: String? = nil) async throws -> JSONObjectThe threads I follow (in one conversation, or all), latest reply first, with unread counts.
AgentIMClient.readThread
Section titled “AgentIMClient.readThread”public func readThread(_ convId: String, threadId: String, seq: Int64) async throwsMarks a thread read up to seq on all my devices.
AgentIMClient.followThread
Section titled “AgentIMClient.followThread”public func followThread(_ convId: String, threadId: String, follow: Bool = true) async throwsFollows a thread (its replies notify me) or stops following it.
AgentIMClient.msgSummary
Section titled “AgentIMClient.msgSummary”public func msgSummary(_ convId: String, msgIds: [String]) async throws -> JSONObjectThe thread summary, reactions and pin of up to 100 messages (for messages loaded from history).
AgentIMClient.call
Section titled “AgentIMClient.call”public func call(_ op: String, _ args: JSONObject = [:]) async throws -> Any?A request that needs the server now (approvals, decisions, queries).
AgentIMClient.debugState
Section titled “AgentIMClient.debugState”public func debugState() async throws -> Any? { try await command(["cmd": "debug_state"]) }Everything that helps report a problem: the connection, positions, the queue and recent failures.
AgentIMClient.close
Section titled “AgentIMClient.close”public func close()Stops the client; no event arrives after it returns. Waiting calls fail with closed. Not from the SDK’s own thread.
Subscription
Section titled “Subscription”public final class SubscriptionA subscription to client events; cancel it to stop.
Subscription.cancel
Section titled “Subscription.cancel”public func cancel()Stops the subscription; calling it again does nothing.