Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
acharneski committed Dec 8, 2024
1 parent 5987b0a commit e49fe05
Show file tree
Hide file tree
Showing 7 changed files with 173 additions and 137 deletions.
258 changes: 148 additions & 110 deletions webapp/src/utils/tabHandling.ts

Large diffs are not rendered by default.

20 changes: 9 additions & 11 deletions webui/src/main/kotlin/com/simiacryptus/skyenet/TabbedDisplay.kt
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import java.util.*
open class TabbedDisplay(
val task: SessionTask,
val tabs: MutableList<Pair<String, StringBuilder>> = mutableListOf(),
val additionalClasses: String = ""
) {
var selectedTab: Int = 0

Expand All @@ -17,7 +18,7 @@ open class TabbedDisplay(
val tabId = UUID.randomUUID()
private fun render() = if (tabs.isEmpty()) "<div/>" else {
"""
<div class="tabs-container" id="$tabId">
<div class="${(additionalClasses.split(" ").toSet() + setOf("tabs-container")).filter { it.isNotEmpty() }.joinToString(" ")}" id="$tabId">
${renderTabButtons()}
${
tabs.toTypedArray().withIndex().joinToString("\n")
Expand All @@ -32,24 +33,21 @@ open class TabbedDisplay(
task.add(render())!!
}

protected open fun renderTabButtons() = """
<div class="tabs">${
protected open fun renderTabButtons() = """<div class="tabs">${
tabs.toTypedArray().withIndex().joinToString("\n") { (idx, pair) ->
if (idx == selectedTab) {
"""<button class="tab-button active" data-for-tab="$idx">${pair.first}</button>"""
} else {
"""<button class="tab-button" data-for-tab="$idx">${pair.first}</button>"""
}
}
}</div>
"""
}</div>"""

protected open fun renderContentTab(t: Pair<String, StringBuilder>, idx: Int) = """
<div class="tab-content ${
when {
idx == selectedTab -> "active"
else -> ""
}
protected open fun renderContentTab(t: Pair<String, StringBuilder>, idx: Int) = """<div class="${
(additionalClasses.split(" ") + setOf("tab-content") + when {
idx == selectedTab -> setOf("active")
else -> emptySet()
}).filter { it.isNotEmpty() }.joinToString(" ")
}" data-tab="$idx">${t.second}</div>"""


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ open class CodingAgent<T : Interpreter>(
|${if (!canPlay) "" else playButton(task, request, response, formText) { formHandle!! }}
|</div>
|${reviseMsg(task, request, response, formText) { formHandle!! }}
""".trimMargin(), className = "reply-message"
""".trimMargin(), additionalClasses = "reply-message"
)
formText.append(formHandle.toString())
formHandle.toString()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ abstract class ShellToolAgent<T : Interpreter>(
|${createToolButton(task, request, response, formText) { formHandle!! }}
|</div>
|${super.reviseMsg(task, request, response, formText) { formHandle!! }}
""".trimMargin(), className = "reply-message"
""".trimMargin(), additionalClasses = "reply-message"
)
formText.append(formHandle.toString())
formHandle.toString()
Expand Down Expand Up @@ -460,7 +460,7 @@ abstract class ShellToolAgent<T : Interpreter>(
}
}
}
""".trimMargin(), className = "reply-message"
""".trimMargin(), additionalClasses = "reply-message"
)
formText.append(formHandle.toString())
formHandle.toString()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,7 @@ open class AutoPlanChatApp(
task.verbose("API log: <a href=\"file:///$this\">$this</a>")
}
}
val tabbedDisplay = TabbedDisplay(task)
val tabbedDisplay = TabbedDisplay(task, additionalClasses = "iteration")
ui.newTask(false).apply {
tabbedDisplay["Inputs"] = placeholder
header("Project Info")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ Note: This task is for running simple and safe commands. Avoid executing command
${acceptButton(response)}
</div>
${super.reviseMsg(task, request, response, formText) { formHandle!! }}
""".trimMargin(), className = "reply-message"
""".trimMargin(), additionalClasses = "reply-message"
)
formText.append(formHandle.toString())
formHandle.toString()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,9 @@ abstract class SessionTask(
showSpinner: Boolean = true,
@Description("The html tag to wrap the message in (default: div)")
tag: String = "div",
@Description("The css class to apply to the message (default: response-message)")
className: String = "response-message"
) = append("""<$tag class="$className">$message</$tag>""", showSpinner)
@Description("Additional css class(es) to apply to the message")
additionalClasses: String = ""
) = append("""<$tag class="${(setOf(additionalClasses.split(" ")) + setOf("response-message")).joinToString(" ")}">$message</$tag>""", showSpinner)

@Description("Adds a hideable message to the task output.")
fun hideable(
Expand All @@ -69,8 +69,8 @@ abstract class SessionTask(
showSpinner: Boolean = true,
@Description("The html tag to wrap the message in (default: div)")
tag: String = "div",
@Description("The css class to apply to the message (default: response-message)")
className: String = "response-message"
@Description("Additional css class(es) to apply to the message")
additionalClasses: String = ""
): StringBuilder? {
var windowBuffer: StringBuilder? = null
val closeButton = """<span class="close">${
Expand All @@ -79,7 +79,7 @@ abstract class SessionTask(
send()
}
}</span>"""
windowBuffer = append("""<$tag class="$className">$closeButton$message</$tag>""", showSpinner)
windowBuffer = append("""<$tag class="${(additionalClasses.split(" ").toSet() + setOf("response-message")).joinToString(" ")}">$closeButton$message</$tag>""", showSpinner)
return windowBuffer
}

Expand All @@ -101,8 +101,8 @@ abstract class SessionTask(
showSpinner: Boolean = true,
@Description("The html tag to wrap the message in (default: div)")
tag: String = "div",
classname: String = "response-header"
) = add(message, showSpinner, tag, classname)
additionalClasses: String = ""
) = add(message, showSpinner, tag, additionalClasses)

@Description("Adds a verbose message to the task output; verbose messages are hidden by default.")
fun verbose(
Expand Down Expand Up @@ -177,9 +177,9 @@ abstract class SessionTask(
message: String = "",
@Description("The html tag to wrap the message in (default: div)")
tag: String = "div",
@Description("The css class to apply to the message (default: response-message)")
className: String = "response-message"
) = append(if (message.isNotBlank()) """<$tag class="$className">$message</$tag>""" else "", false)
@Description("Additional css class(es) to apply to the message")
additionalClasses: String = ""
) = append(if (message.isNotBlank()) """<$tag class="${(additionalClasses.split(" ").toSet() + setOf("response-message")).joinToString(" ")}">$message</$tag>""" else "", false)

@Description("Displays an image to the task output.")
fun image(
Expand Down

0 comments on commit e49fe05

Please sign in to comment.