com.simiacryptus.skyenet.apps.plan.AbstractTask.kt Maven / Gradle / Ivy
package com.simiacryptus.skyenet.apps.plan
import com.simiacryptus.jopenai.API
import com.simiacryptus.skyenet.set
import com.simiacryptus.skyenet.webui.application.ApplicationInterface
import com.simiacryptus.skyenet.webui.session.SessionTask
import java.io.File
import java.nio.file.Path
abstract class AbstractTask(
val planSettings: PlanSettings,
val planTask: T?
) {
var state: TaskState? = TaskState.Pending
protected val codeFiles = mutableMapOf()
protected open val root: Path
get() = planSettings.workingDir?.let { File(it).toPath() }
?: throw IllegalStateException("Working directory not set")
enum class TaskState {
Pending,
InProgress,
Completed,
}
protected fun getPriorCode(planProcessingState: PlanProcessingState) =
planTask?.task_dependencies?.joinToString("\n\n\n") { dependency ->
"""
|# $dependency
|
|${planProcessingState.taskResult[dependency] ?: ""}
""".trimMargin()
} ?: ""
protected fun acceptButtonFooter(ui: ApplicationInterface, fn: () -> Unit): String {
val footerTask = ui.newTask(false)
lateinit var textHandle: StringBuilder
textHandle = footerTask.complete(ui.hrefLink("Accept", classname = "href-link cmd-button") {
try {
textHandle.set(""",
planProcessingState: PlanProcessingState,
task: SessionTask,
api: API
)
companion object {
private val log = org.slf4j.LoggerFactory.getLogger(AbstractTask::class.java)
}
} """)
footerTask.complete()
} catch (e: Throwable) {
log.warn("Error", e)
}
fn()
})!!
return footerTask.placeholder
}
abstract fun promptSegment(): String
abstract fun run(
agent: PlanCoordinator,
taskId: String,
userMessage: String,
plan: Map