All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.simiacryptus.skyenet.apps.plan.AbstractTask.kt Maven / Gradle / Ivy

There is a newer version: 1.2.21
Show newest version
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 open 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("""
Accepted
""") 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, planProcessingState: PlanProcessingState, task: SessionTask, api: API, resultFn: (String) -> Unit ) companion object { private val log = org.slf4j.LoggerFactory.getLogger(AbstractTask::class.java) } }




© 2015 - 2024 Weber Informatics LLC | Privacy Policy