KSLAppSession

class KSLAppSession(val provider: ModelProviderIfc? = null, scope: CoroutineScope? = null) : AutoCloseable(source)

Unified façade over the app runner/orchestrator layer.

UI code should hold one session for the application lifetime, submit RunSpec instances through submit, observe the returned RunHandle, and call close during application shutdown.

Quick start (synchronous)

Callers that just want to "run a configuration and read the result" — typical test code or a non-coroutine fun main() — can use submitAndAwaitBlocking to skip coroutines entirely:

fun main() {
val session = KSLAppSession(provider)
val result = session.submitAndAwaitBlocking(RunSpec.Single(myConfig))
println(result)
}

The asynchronous submit / RunHandle path remains the right choice for GUIs and any caller that wants to observe lifecycle events; see submitAndAwaitBlocking for the full set of caveats.

Dispatch

submit selects validator and execution path by RunSpec variant:

Validation errors return an immediately-failed RunHandle rather than throwing, so the same event/result protocol covers all outcomes.

Lifecycle

Every handle returned from submit is retained on the session so that close can cancel any in-flight runs and release the owned coroutine scope. close() is idempotent.

Constructors

Link copied to clipboard
constructor(provider: ModelProviderIfc? = null, scope: CoroutineScope? = null)

Properties

Link copied to clipboard

Functions

Link copied to clipboard
open override fun close()

Cancels every run submitted through this session and cancels the owned scope when the session created it. Safe to call more than once.

Link copied to clipboard
fun submit(spec: RunSpec, attachments: List<RunAttachmentIfc> = emptyList(), validate: Boolean = true): RunHandle

Submit a run for asynchronous execution.

Link copied to clipboard
fun submitAndAwaitBlocking(spec: RunSpec, attachments: List<RunAttachmentIfc> = emptyList(), validate: Boolean = true): RunResult

Submits spec and synchronously waits for the run to terminate, returning its RunResult. Convenience shorthand for submit(spec, attachments, validate).awaitResultBlocking().