epic-12: after epic audit and init commit

This commit is contained in:
2026-05-16 11:42:00 +04:00
commit c77277af0b
461 changed files with 28958 additions and 0 deletions
@@ -0,0 +1,19 @@
plugins {
id 'java-library'
id 'org.jetbrains.kotlin.jvm'
id 'org.jetbrains.kotlin.plugin.serialization'
}
ext {
ktor_version = '3.0.3'
}
dependencies {
implementation project(':core:inference')
implementation project(':core:events')
implementation project(':core:context')
implementation "io.ktor:ktor-client-core:$ktor_version"
implementation "io.ktor:ktor-client-cio:$ktor_version"
implementation "io.ktor:ktor-client-content-negotiation:$ktor_version"
implementation "io.ktor:ktor-serialization-kotlinx-json:$ktor_version"
}
@@ -0,0 +1,26 @@
package com.correx.infrastructure.inference.commons
import com.correx.core.events.types.ProviderId
import com.correx.core.inference.InferenceProvider
import com.correx.core.inference.Tokenizer
/**
* A wrapper around [InferenceProvider] that tracks model lifecycle.
* Ensures the provider is tied to a specific [ModelManager] instance and [ModelDescriptor].
*/
interface ManagedInferenceProvider : InferenceProvider {
/**
* Unload the managed model.
*/
suspend fun unload()
/**
* Check if the underlying model is still loaded.
*/
fun isLoaded(): Boolean
/**
* Load a different model, replacing this one.
*/
suspend fun load(newDescriptor: ModelDescriptor): ManagedInferenceProvider
}
@@ -0,0 +1,15 @@
package com.correx.infrastructure.inference.commons
import com.correx.core.inference.CapabilityScore
/**
* Descriptor for a model instance with its configuration.
*/
data class ModelDescriptor(
val modelId: String,
val modelPath: String,
val residencyMode: ResidencyMode,
val idleTimeoutMs: Long = 60_000L,
val contextSize: Int = 8192,
val capabilities: Set<CapabilityScore> = emptySet(),
)
@@ -0,0 +1,11 @@
package com.correx.infrastructure.inference.commons
/**
* Thrown when model loading fails during ModelManager.load().
* No event is emitted on failure per event sourcing principles.
*/
class ModelLoadException(
override val message: String,
val modelId: String,
override val cause: Throwable? = null,
) : RuntimeException(message, cause)
@@ -0,0 +1,36 @@
package com.correx.infrastructure.inference.commons
import com.correx.core.inference.InferenceProvider
import com.correx.core.inference.ProviderHealth
/**
* Manages the lifecycle of models.
*/
interface ModelManager {
/**
* Loads a model and returns an InferenceProvider instance.
*
* @param descriptor Model configuration
* @return An InferenceProvider for the loaded model
* @throws ModelLoadException if a different model is already loaded
*/
suspend fun load(descriptor: ModelDescriptor): InferenceProvider
/**
* Unloads the currently loaded model.
*
* @param modelId The model ID to unload
* @throws ModelLoadException if no model is currently loaded
*/
suspend fun unload(modelId: String)
/**
* Returns the descriptor of the currently loaded model, or null if none.
*/
fun currentModel(): ModelDescriptor?
/**
* Health check for the current model.
*/
fun healthCheck(): ProviderHealth
}
@@ -0,0 +1,10 @@
package com.correx.infrastructure.inference.commons
/**
* Residency modes for model lifecycle management.
*/
enum class ResidencyMode {
PERSISTENT, // never unload
DYNAMIC, // unload after idle timeout
EPHEMERAL, // unload immediately after infer completes
}