Using Spectron from Kotlin applications and agents on JVM, Android, and iOS.
The Spectron client for Kotlin ships inside the SurrealDB Kotlin SDK — there is no separate package. It lives in the com.surrealdb.kotlin.spectron package and talks to Spectron's HTTP API directly, independently of the SurrealDB RPC engine. Like the rest of the Kotlin SDK, it is Kotlin Multiplatform (JVM, Android, iOS) and every method is a suspend function.
Note
The Kotlin SDK is in early development (0.1.0-SNAPSHOT) and the Spectron client is not yet released. The APIs below are provisional.
Installation
Add the Kotlin SDK to your project as described in the installation guide:
val session = memory.sessions.create(scope = listOf("user/tobie"))
// Server-driven turn scoped to the session. val reply = session.chat("What do you know about me?")
// Or drive the turns yourself. session.remember("I just got promoted to CTO", role = TurnRole.USER) val ctx = session.context("What is Tobie's role?")
Scopes and acting on behalf of others
Scopes are hierarchical slash-path strings. Build them with the scopePaths helper:
import com.surrealdb.kotlin.spectron.scopePaths
scopePaths("team" to "eng", "org" to "acme") // ["team/eng", "org/acme"]
Every method accepts an optional onBehalfOf, which sends the X-Spectron-On-Behalf-Of header so a privileged caller can act as another principal: