Skip to content

Commit

Permalink
1.0.71 (#76)
Browse files Browse the repository at this point in the history
* 1.0.71

* wip

* wip
  • Loading branch information
acharneski authored May 16, 2024
1 parent b91c89a commit 7e828b8
Show file tree
Hide file tree
Showing 13 changed files with 113 additions and 941 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,9 @@ open class ActorSystem<T : Enum<*>>(
else -> throw RuntimeException("Unknown actor type: ${baseActor.javaClass}")
}
} catch (e: Throwable) {
log.warn("Error creating actor $actor", e)
actors[actor.name]!!
val baseActor = actors[actor.name]!!
log.warn("Error creating actor $actor, returning $baseActor", e)
baseActor
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Gradle Releases -> https://github.com/gradle/gradle/releases
libraryGroup = com.simiacryptus.skyenet
libraryVersion = 1.0.70
libraryVersion = 1.0.71
gradleVersion = 7.6.1
39 changes: 29 additions & 10 deletions webui/src/main/kotlin/com/simiacryptus/skyenet/Discussable.kt
Original file line number Diff line number Diff line change
Expand Up @@ -23,43 +23,48 @@ class Discussable<T : Any>(

val tabs = object : TabbedDisplay(task) {
override fun renderTabButtons() = """
|<div class="tabs">
|${
<div class="tabs">
${
tabs.withIndex().joinToString("\n")
{ (index: Int, t: Pair<String, StringBuilder>) ->
"""<button class="tab-button" data-for-tab="$index">${t.first}</button>"""
}
}
|${
${
ui.hrefLink("") {
val idx: Int = size
val newTask = ui.newTask(false)
val header = newTask.header("Retrying...")
this[label(idx)] = newTask.placeholder
val idx: Int = size
this.set(label(idx), newTask.placeholder)
main(idx, newTask)
this.selectedTab = idx
header?.clear()
newTask.complete()
}
}
|</div>
</div>
""".trimMargin()
}
private val acceptGuard = AtomicBoolean(false)

private fun main(tabIndex: Int, task: SessionTask) {
log.info("Starting main function for tabIndex: $tabIndex")
try {
val history = mutableListOf<Pair<String, Role>>()
val userMessage = userMessage()
log.info("User message: $userMessage")
history.add(userMessage to Role.user)
val design = initialResponse(userMessage)
log.info("Initial response generated: $design")
val rendered = outputFn(design)
log.info("Rendered output: $rendered")
history.add(rendered to Role.assistant)
val tabContent = task.add(rendered)!!
val feedbackForm = feedbackForm(tabIndex, tabContent, design, history, task)
tabContent?.append("\n" + feedbackForm.placeholder)
task.complete()
} catch (e: Throwable) {
log.error("Error in main function", e)
task.error(ui, e)
task.complete(ui.hrefLink("🔄 Retry") {
main(tabIndex = tabIndex, task = task)
Expand All @@ -74,6 +79,7 @@ class Discussable<T : Any>(
history: List<Pair<String, Role>>,
task: SessionTask,
) = ui.newTask(false).apply {
log.info("Creating feedback form for tabIndex: $tabIndex")
val feedbackSB = add("<div />")!!
feedbackSB.clear()
feedbackSB.append(
Expand All @@ -94,6 +100,7 @@ class Discussable<T : Any>(
feedbackSB: StringBuilder,
feedbackTask: SessionTask,
) = ui.hrefLink("Accept", classname = "href-link cmd-button") {
log.info("Accept link clicked for tabIndex: $tabIndex")
feedbackSB.clear()
feedbackTask.complete()
accept(tabIndex, tabContent, design)
Expand All @@ -109,13 +116,15 @@ class Discussable<T : Any>(
): String {
val feedbackGuard = AtomicBoolean(false)
return ui.textInput { userResponse ->
log.info("User response received: $userResponse")
if (feedbackGuard.getAndSet(true)) return@textInput
val prev = feedbackSB.toString()
try {
feedbackSB.clear()
feedbackTask.complete()
feedback(tabContent, userResponse, history, design, task)
} catch (e: Exception) {
log.error("Error processing user feedback", e)
task.error(ui, e)
feedbackSB.set(prev)
feedbackTask.complete()
Expand All @@ -133,16 +142,18 @@ class Discussable<T : Any>(
design: T,
task: SessionTask,
) {
log.info("Processing feedback for user response: $userResponse")
var history = history
history = history + (userResponse to Role.user)
val newValue = (tabContent.toString()
+ "<div class=\"user-message\">"
+ renderMarkdown(userResponse, ui = ui)
+ "</div>")
+ "<div class=\"user-message\">"
+ renderMarkdown(userResponse, ui = ui)
+ "</div>")
tabContent.set(newValue)
val stringBuilder = task.add("Processing...")
tabs.update()
val newDesign = reviseResponse(history)
log.info("Revised design: $newDesign")
val newTask = ui.newTask(root = false)
tabContent.set(newValue + "\n" + newTask.placeholder)
tabs.update()
Expand All @@ -162,6 +173,7 @@ class Discussable<T : Any>(
}

private fun accept(tabIndex: Int?, tabContent: StringBuilder, design: T) {
log.info("Accepting design for tabIndex: $tabIndex")
if (acceptGuard.getAndSet(true)) {
return
}
Expand All @@ -173,6 +185,7 @@ class Discussable<T : Any>(
tabs.update()
}
} catch (e: Exception) {
log.error("Error accepting design", e)
task.error(ui, e)
acceptGuard.set(false)
throw e
Expand All @@ -182,21 +195,27 @@ class Discussable<T : Any>(
}

override fun call(): T {
log.info("Calling Discussable with heading: $heading")
task.echo(heading)
val idx = tabs.size
val newTask = ui.newTask(false)
val header = newTask.header("Processing...")
tabs[tabs.label(idx)] = newTask.placeholder
main(idx, newTask)
tabs.selectedTab = idx
header?.clear()
newTask.complete()
semaphore.acquire()
log.info("Returning result from Discussable")
return atomicRef.get()
}

companion object {
private val log = org.slf4j.LoggerFactory.getLogger(Discussable::class.java)
}
}

fun java.lang.StringBuilder.set(newValue: String) {
clear()
append(newValue)
}
}
25 changes: 11 additions & 14 deletions webui/src/main/kotlin/com/simiacryptus/skyenet/TabbedDisplay.kt
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,10 @@ open class TabbedDisplay(
</div>
""".trimIndent()

val container: StringBuilder by lazy { task.add(render())!! }
val container: StringBuilder by lazy {
log.debug("Initializing container with rendered content")
task.add(render())!!
}

open fun renderTabButtons() = """
<div class="tabs">${
Expand All @@ -50,13 +53,15 @@ open class TabbedDisplay(
operator fun set(name: String, content: String) =
when (val index = find(name)) {
null -> {
log.debug("Adding new tab: $name")
val stringBuilder = StringBuilder(content)
tabs.add(name to stringBuilder)
update()
stringBuilder
}

else -> {
log.debug("Updating existing tab: $name")
val stringBuilder = tabs[index].second
stringBuilder.clear()
stringBuilder.append(content)
Expand All @@ -72,29 +77,21 @@ open class TabbedDisplay(
}

open fun clear() {
log.debug("Clearing all tabs")
tabs.clear()
update()
}

open fun update() {
log.debug("Updating container content")
if (container != null) synchronized(container) {
if (tabs.isNotEmpty() && (selectedTab < 0 || selectedTab >= tabs.size)) {
selectedTab = 0
}
container.clear()
container.append(render())
ensureActiveTab()
}
task.complete()
}

private fun ensureActiveTab() {
if (tabs.isNotEmpty() && (selectedTab < 0 || selectedTab >= tabs.size)) {
selectedTab = 0
}
tabs.forEachIndexed { index, _ ->
if (index == selectedTab) {
tabs[index].second.append("active")
} else {
tabs[index].second.clear()
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ import com.simiacryptus.skyenet.core.platform.*
import com.simiacryptus.skyenet.interpreter.Interpreter
import com.simiacryptus.skyenet.kotlin.KotlinInterpreter
import com.simiacryptus.skyenet.webui.application.ApplicationInterface
import com.simiacryptus.skyenet.webui.servlet.ToolServlet
import com.simiacryptus.skyenet.webui.session.SessionTask
import com.simiacryptus.skyenet.webui.util.MarkdownUtil.renderMarkdown
import com.simiacryptus.skyenet.webui.util.OpenAPI
Expand Down Expand Up @@ -230,11 +229,12 @@ abstract class ShellToolAgent<T : Interpreter>(
}
}
if (ApplicationServices.authorizationManager.isAuthorized(
ToolAgent.javaClass,
ShellToolAgent.javaClass,
user,
AuthorizationInterface.OperationType.Admin
)
) {
/*
ToolServlet.addTool(
ToolServlet.Tool(
path = openAPI.paths?.entries?.first()?.key?.removePrefix(toolsPrefix) ?: "unknown",
Expand All @@ -243,6 +243,7 @@ abstract class ShellToolAgent<T : Interpreter>(
servletCode = servletImpl
)
)
*/
}
buildTestPage(openAPI, servletImpl, task)
}
Expand Down
Loading

0 comments on commit 7e828b8

Please sign in to comment.