Tanvrit Compute SDK
> The com.tanvrit:compute Kotlin Multiplatform module — consumed by the > compute portal, Tanvrit AI, Tanvrit Market, and any downstream app.
Installation
Add the Maven artifact to your build.gradle.kts:
dependencies {
implementation("com.tanvrit:compute:0.8.4") // common
implementation("com.tanvrit:compute-jvm:0.8.4") // JVM/desktop targets
implementation("com.tanvrit:compute-android:0.8.4") // Android
}
Then ensure your settings.gradle.kts includes the Tanvrit Maven proxy (or GitHub Packages with credentials):
dependencyResolutionManagement {
repositories {
maven { url = uri("https://maven.tanvrit.com") } // Cloudflare Worker proxy
// or: maven { url = uri("https://maven.pkg.github.com/tanvrit/compute") }
}
}
Koin setup
import com.tanvrit.compute.di.computeModule
import org.koin.core.context.startKoin
startKoin {
modules(computeModule) // registers job, node, execution, template, credit, schedule
}
Canonical feature layout
The SDK mirrors the /sdk/customers layout exactly. Each sub-feature exposes:
feature/<name>/
├── model/ @Serializable DTOs and domain types
├── event/ route path constants
├── network/ I<Name>Network interface + <Name>Network Ktor impl
├── repository/ MutableStateFlow holders for reactive UI state
├── handler/ Koin bridge linking repo + viewModel
└── viewModel/ AppViewModel subclass with actions + StateFlow properties
Sub-features shipped in com.tanvrit:compute
| Sub-feature | Package | What it does | |--- |--- |--- | | job | com.tanvrit.compute.feature.job | submit, retrieve, cancel, retry, list, bulk, stats | | node | com.tanvrit.compute.feature.node | list, drain, pause, resume, delete, rotate-key | | execution | com.tanvrit.compute.feature.execution | per-attempt execution history by job / node | | template | com.tanvrit.compute.feature.template | list, create, submit-from-template | | credit | com.tanvrit.compute.feature.credit | balance + ledger (free-tier model) | | schedule | com.tanvrit.compute.feature.schedule | cron-triggered recurring jobs |
Submit a job (DSL)
The compute-engine module provides a type-safe builder:
import com.tanvrit.compute.engine.dsl.computeJob
import com.tanvrit.compute.feature.job.viewModel.ComputeJobViewModel
import org.koin.java.KoinJavaComponent.get
val vm: ComputeJobViewModel = get(ComputeJobViewModel::class.java)
val req = computeJob {
docker("ghcr.io/ggerganov/llama.cpp:server-cuda")
env("MODEL", "llama-3-70b")
gpu("cuda")
memory(24_576)
priority(9)
tag("inference")
}
vm.submitJob(req) { success -> println("submitted=$success") }
Watch a job's live logs
vm.repository.liveLogs.collect { lines ->
// bind to a LogViewer composable
}
// open the SSE stream from the server
The portal's LogViewer composable (/compute/composeApp/.../component/LogViewer.kt) subscribes to vm.liveLogs and appends each new line as it arrives from the /api/compute/jobs/{jobId}/logs/stream server-sent-event endpoint.
List nodes with filters
import com.tanvrit.compute.feature.node.model.ListComputeNodesRequest
import com.tanvrit.compute.feature.node.viewModel.ComputeNodeViewModel
val nodeVm: ComputeNodeViewModel = get(ComputeNodeViewModel::class.java)
nodeVm.listNodes(ListComputeNodesRequest(businessId = "biz-123", status = "ONLINE")) { ok ->
if (ok) println("got ${nodeVm.allNodes.value.size} nodes")
}
Schedule a recurring job
import com.tanvrit.compute.feature.schedule.model.CreateComputeScheduleRequest
import com.tanvrit.compute.feature.schedule.viewModel.ComputeScheduleViewModel
val scheduleVm: ComputeScheduleViewModel = get(ComputeScheduleViewModel::class.java)
scheduleVm.createSchedule(
CreateComputeScheduleRequest(
name = "Nightly backup",
cronExpression = "0 3 * * *", // every day 03:00 UTC
jobType = "COMMAND",
command = "backup.sh --target s3://tanvrit-backups/",
),
) { ok -> println("scheduled=$ok") }