Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Gradle Releases -> https://github.com/gradle/gradle/releases
libraryGroup=com.simiacryptus.skyenet
libraryVersion=1.2.19
libraryVersion=1.2.20
gradleVersion=7.6.1
kotlin.daemon.jvmargs=-Xmx4g
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ fun SocketManagerBase.addApplyFileDiffLinks(
api: API,
shouldAutoApply: (Path) -> Boolean = { false },
model: ChatModel? = null,
defaultFile: String? = null,
): String {
// Check if there's an unclosed code block and close it if necessary
val initiator = "(?s)```\\w*\n".toRegex()
Expand All @@ -43,6 +44,7 @@ fun SocketManagerBase.addApplyFileDiffLinks(
ui,
api,
model = model,
defaultFile = defaultFile,
)
}
val headerPattern = """(?<![^\n])#+\s*([^\n]+)""".toRegex() // capture filename
Expand All @@ -51,11 +53,11 @@ fun SocketManagerBase.addApplyFileDiffLinks(
val findAll = codeblockPattern.findAll(response).toList()
val codeblocks = findAll.filter { block ->
try {
val header = headers.lastOrNull { it.first.last <= block.range.first }
val header = headers.lastOrNull { it.first.last <= block.range.first }?.let { it.second } ?: defaultFile
if (header == null) {
return@filter false
}
val filename = resolve(root, header.second)
val filename = resolve(root, header)
!root.resolve(filename).toFile().exists()
} catch (e: Throwable) {
log.info("Error processing code block", e)
Expand All @@ -64,11 +66,11 @@ fun SocketManagerBase.addApplyFileDiffLinks(
}.map { it.range to it }.toList()
val patchBlocks = findAll.filter { block ->
try {
val header = headers.lastOrNull { it.first.last <= block.range.first }
val header = headers.lastOrNull { it.first.last <= block.range.first }?.let { it.second } ?: defaultFile
if (header == null) {
return@filter false
}
val filename = resolve(root, header.second)
val filename = resolve(root, header)
root.resolve(filename).toFile().exists()
} catch (e: Throwable) {
log.info("Error processing code block", e)
Expand Down Expand Up @@ -125,7 +127,7 @@ fun SocketManagerBase.addApplyFileDiffLinks(
// Process diff blocks and add patch links
val withPatchLinks: String = patchBlocks.foldIndexed(response) { index, markdown, diffBlock ->
val value = diffBlock.second.groupValues[2].trim()
var header = headers.lastOrNull { it.first.last < diffBlock.first.first }?.second ?: "Unknown"
var header = headers.lastOrNull { it.first.last < diffBlock.first.first }?.second ?: defaultFile ?: "Unknown"
header = corrections?.get("patch_$index") ?: header
val filename = resolve(root, header)
val newValue = renderDiffBlock(root, filename, value, handle, ui, api, shouldAutoApply)
Expand All @@ -135,7 +137,7 @@ fun SocketManagerBase.addApplyFileDiffLinks(
val withSaveLinks = codeblocks.foldIndexed(withPatchLinks) { index, markdown, codeBlock ->
val lang = codeBlock.second.groupValues[1]
val value = codeBlock.second.groupValues[2].trim()
var header = headers.lastOrNull { it.first.last < codeBlock.first.first }?.second
var header = headers.lastOrNull { it.first.last < codeBlock.first.first }?.second ?: defaultFile ?: "Unknown"
header = corrections?.get("code_$index") ?: header
val newMarkdown = renderNewFile(header, root, ui, shouldAutoApply, value, handle, lang)
markdown.replace(codeBlock.second.value, newMarkdown)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ open class TabbedDisplay(

val size: Int get() = tabs.size
val tabId = UUID.randomUUID()
open fun render() = if (tabs.isEmpty()) "<div/>" else {
private fun render() = if (tabs.isEmpty()) "<div/>" else {
"""
<div class="tabs-container" id="$tabId">
${renderTabButtons()}
Expand All @@ -32,7 +32,7 @@ open class TabbedDisplay(
task.add(render())!!
}

open fun renderTabButtons() = """
protected open fun renderTabButtons() = """
<div class="tabs">${
tabs.toTypedArray().withIndex().joinToString("\n") { (idx, pair) ->
if (idx == selectedTab) {
Expand All @@ -44,7 +44,7 @@ open class TabbedDisplay(
}</div>
"""

open fun renderContentTab(t: Pair<String, StringBuilder>, idx: Int) = """
protected open fun renderContentTab(t: Pair<String, StringBuilder>, idx: Int) = """
<div class="tab-content ${
when {
idx == selectedTab -> "active"
Expand Down
Loading