Skip to content

Commit 1196e02

Browse files
authored
1.8.0 (#194)
* 1.8.0 * fix * fix
1 parent fee55c1 commit 1196e02

File tree

79 files changed

+614
-413
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

79 files changed

+614
-413
lines changed

build.gradle.kts

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ plugins {
1111
id("org.jetbrains.intellij.platform") version "2.1.0"
1212
id("org.jetbrains.changelog") version "2.2.1"
1313
id("org.jetbrains.qodana") version "2024.2.3"
14-
id("org.jetbrains.kotlinx.kover") version "0.9.0-RC"
14+
//id("org.jetbrains.kotlinx.kover") version "0.9.0-RC"
1515
id("org.jetbrains.dokka") version "2.0.0-Beta"
1616
}
1717

@@ -28,7 +28,7 @@ repositories {
2828

2929
val jetty_version = "11.0.24"
3030
val slf4j_version = "2.0.16"
31-
val skyenet_version = "1.2.11"
31+
val skyenet_version = "1.2.12"
3232
val remoterobot_version = "0.11.23"
3333
val jackson_version = "2.17.2"
3434

@@ -43,15 +43,15 @@ dependencies {
4343
implementation("com.googlecode.java-diff-utils:diffutils:1.3.0")
4444
implementation(group = "org.apache.httpcomponents.client5", name = "httpclient5", version = "5.2.3")
4545

46-
implementation(group = "com.simiacryptus", name = "jo-penai", version = "1.1.9")
46+
implementation(group = "com.simiacryptus", name = "jo-penai", version = "1.1.10")
4747
implementation(group = "com.simiacryptus.skyenet", name = "kotlin", version = skyenet_version)
4848
implementation(group = "com.simiacryptus.skyenet", name = "core", version = skyenet_version)
4949
implementation(group = "com.simiacryptus.skyenet", name = "webui", version = skyenet_version)
5050

5151
implementation(group = "com.fasterxml.jackson.core", name = "jackson-databind", version = jackson_version)
5252
implementation(group = "com.fasterxml.jackson.core", name = "jackson-annotations", version = jackson_version)
5353
implementation(group = "com.fasterxml.jackson.module", name = "jackson-module-kotlin", version = jackson_version)
54-
implementation ("com.fasterxml.jackson.datatype:jackson-datatype-jsr310:$jackson_version")
54+
implementation("com.fasterxml.jackson.datatype:jackson-datatype-jsr310:$jackson_version")
5555

5656
implementation(group = "org.eclipse.jetty", name = "jetty-server", version = jetty_version)
5757
implementation(group = "org.eclipse.jetty", name = "jetty-servlet", version = jetty_version)
@@ -181,7 +181,7 @@ intellijPlatform {
181181
}
182182

183183
publishing {
184-
// Include VCS plugin
184+
// Include VCS plugin
185185
token = providers.environmentVariable("PUBLISH_TOKEN")
186186
// The pluginVersion is based on the SemVer (https://semver.org) and supports pre-release labels, like 2.1.7-alpha.3
187187
// Specify pre-release label to publish the plugin in a custom Release Channel automatically. Read more:
@@ -208,6 +208,7 @@ changelog {
208208
}
209209

210210
// Configure Gradle Kover Plugin - read more: https://github.com/Kotlin/kotlinx-kover#configuration
211+
/*
211212
kover {
212213
reports {
213214
total {
@@ -217,6 +218,7 @@ kover {
217218
}
218219
}
219220
}
221+
*/
220222

221223
tasks {
222224
wrapper {

gradle.properties

Lines changed: 7 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,24 @@
11
pluginName=intellij-aicoder
22
pluginRepositoryUrl=https://github.com/SimiaCryptus/intellij-aicoder
3-
pluginVersion=1.7.2
4-
3+
pluginVersion=1.8.0
54
jvmArgs=-Xmx8g
65
org.gradle.jvmargs=-Xmx8g -XX:MaxMetaspaceSize=1g
7-
86
# Supported build number ranges and IntelliJ Platform versions -> https://plugins.jetbrains.com/docs/intellij/build-number-ranges.html
97
pluginSinceBuild=233
108
pluginUntilBuild=242.*
11-
12-
platformType = IU
9+
platformType=IU
1310
platformVersion=2024.2
1411
gradleVersion=8.10.2
15-
16-
platformPlugins =
17-
platformBundledPlugins =
18-
12+
platformPlugins=
13+
platformBundledPlugins=
1914
# Opt-out flag for bundling Kotlin standard library -> https://plugins.jetbrains.com/docs/intellij/kotlin.html#kotlin-standard-library
2015
# suppress inspection "UnusedProperty"
2116
kotlin.stdlib.default.dependency=false
22-
2317
# Enable Gradle Build Cache -> https://docs.gradle.org/current/userguide/build_cache.html
24-
org.gradle.configuration-cache = false
25-
org.gradle.caching = true
26-
18+
org.gradle.configuration-cache=false
19+
org.gradle.caching=true
2720
# Enable Gradle Kotlin DSL Lazy Property Assignment -> https://docs.gradle.org/current/userguide/kotlin_dsl.html#kotdsl:assignment
28-
systemProp.org.gradle.unsafe.kotlin.assignment = true
21+
systemProp.org.gradle.unsafe.kotlin.assignment=true
2922
org.jetbrains.dokka.experimental.gradle.pluginMode=V2Enabled
3023
org.jetbrains.dokka.experimental.gradle.pluginMode.noWarn=true
3124
# Disable deprecated features warnings

src/main/kotlin/com/github/simiacryptus/aicoder/actions/BaseAction.kt

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,7 @@ import com.github.simiacryptus.aicoder.util.IdeaOpenAIClient
55
import com.github.simiacryptus.aicoder.util.UITools
66
import com.intellij.openapi.actionSystem.AnAction
77
import com.intellij.openapi.actionSystem.AnActionEvent
8-
import com.intellij.openapi.util.NlsSafe
98
import com.simiacryptus.jopenai.ChatClient
10-
import com.simiacryptus.jopenai.OpenAIClient
119
import org.slf4j.LoggerFactory
1210
import javax.swing.Icon
1311

src/main/kotlin/com/github/simiacryptus/aicoder/actions/FileContextAction.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ abstract class FileContextAction<T : Any>(
5050
}
5151
val start = System.currentTimeMillis()
5252
val fileSystem = LocalFileSystem.getInstance()
53-
while(null == fileSystem.refreshAndFindFileByIoFile(newFiles.firstOrNull() ?: throw IllegalStateException())) {
53+
while (null == fileSystem.refreshAndFindFileByIoFile(newFiles.firstOrNull() ?: throw IllegalStateException())) {
5454
if (System.currentTimeMillis() - start > 10000) {
5555
throw IllegalStateException("File not found: ${newFiles.firstOrNull()}")
5656
}

src/main/kotlin/com/github/simiacryptus/aicoder/actions/OpenWebPageAction.kt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
package com.github.simiacryptus.aicoder.actions
22

3-
import com.github.simiacryptus.aicoder.util.BrowseUtil
43
import com.github.simiacryptus.aicoder.util.BrowseUtil.browse
54
import com.intellij.openapi.actionSystem.AnAction
65
import com.intellij.openapi.actionSystem.AnActionEvent

src/main/kotlin/com/github/simiacryptus/aicoder/actions/SelectionAction.kt

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
package com.github.simiacryptus.aicoder.actions
22

33
import com.github.simiacryptus.aicoder.util.ComputerLanguage
4-
import com.github.simiacryptus.aicoder.util.UITools
54
import com.github.simiacryptus.aicoder.util.LanguageUtils
5+
import com.github.simiacryptus.aicoder.util.UITools
66
import com.intellij.openapi.actionSystem.AnActionEvent
77
import com.intellij.openapi.actionSystem.CommonDataKeys
88
import com.intellij.openapi.command.WriteCommandAction
@@ -55,9 +55,9 @@ abstract class SelectionAction<T : Any>(
5555
val editorState = editorState(editor)
5656
val (start, end) = retarget(editorState, selectedText, selectionStart, selectionEnd) ?: return
5757
val text = editorState.text
58-
selectedText = text.substring(start.coerceIn(0, text.length-1), end.coerceIn(0, text.length-1))
59-
selectionEnd = end.coerceIn(0, text.length-1)
60-
selectionStart = start.coerceIn(0, text.length-1)
58+
selectedText = text.substring(start.coerceIn(0, (text.length - 1).coerceAtLeast(0)), end.coerceIn(0, (text.length - 1).coerceAtLeast(0)))
59+
selectionEnd = end.coerceIn(0, (text.length - 1).coerceAtLeast(0))
60+
selectionStart = start.coerceIn(0, (text.length - 1).coerceAtLeast(0))
6161

6262
UITools.redoableTask(e) {
6363
val document = e.getData(CommonDataKeys.EDITOR)?.document
@@ -74,7 +74,7 @@ abstract class SelectionAction<T : Any>(
7474
selectionOffset = selectionStart,
7575
selectionLength = selectionEnd - selectionStart,
7676
entireDocument = editor.document.text,
77-
language = LanguageUtils.getComputerLanguage(e),
77+
language = LanguageUtils.getComputerLanguage(e),
7878
indent = indent,
7979
contextRanges = editorState.contextRanges,
8080
psiFile = editorState.psiFile,
@@ -160,7 +160,7 @@ abstract class SelectionAction<T : Any>(
160160
if (start >= end) return false
161161
}
162162
}
163-
val computerLanguage = LanguageUtils.getComputerLanguage(event)
163+
val computerLanguage = LanguageUtils.getComputerLanguage(event)
164164
return isLanguageSupported(computerLanguage)
165165
}
166166

@@ -177,7 +177,7 @@ abstract class SelectionAction<T : Any>(
177177
)
178178

179179
open fun isLanguageSupported(computerLanguage: ComputerLanguage?): Boolean {
180-
return LanguageUtils.isLanguageSupported(computerLanguage)
180+
return LanguageUtils.isLanguageSupported(computerLanguage)
181181
}
182182

183183
open fun defaultSelection(editorState: EditorState, offset: Int) = editorState.line

src/main/kotlin/com/github/simiacryptus/aicoder/actions/code/DescribeAction.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@ package com.github.simiacryptus.aicoder.actions.code
22

33
import com.github.simiacryptus.aicoder.actions.SelectionAction
44
import com.github.simiacryptus.aicoder.config.AppSettingsState
5-
import com.simiacryptus.jopenai.models.chatModel
65
import com.github.simiacryptus.aicoder.util.IndentedText
76
import com.intellij.openapi.actionSystem.ActionUpdateThread
87
import com.intellij.openapi.project.Project
8+
import com.simiacryptus.jopenai.models.chatModel
99
import com.simiacryptus.jopenai.proxy.ChatProxy
1010
import com.simiacryptus.util.StringUtil
1111

src/main/kotlin/com/github/simiacryptus/aicoder/actions/code/PasteAction.kt

Lines changed: 59 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -2,20 +2,20 @@ package com.github.simiacryptus.aicoder.actions.code
22

33
import com.github.simiacryptus.aicoder.actions.SelectionAction
44
import com.github.simiacryptus.aicoder.config.AppSettingsState
5-
import com.simiacryptus.jopenai.models.chatModel
6-
import org.jsoup.Jsoup
7-
import org.jsoup.nodes.Document
85
import com.github.simiacryptus.aicoder.util.ComputerLanguage
96
import com.intellij.openapi.actionSystem.ActionUpdateThread
107
import com.intellij.openapi.actionSystem.AnActionEvent
118
import com.intellij.openapi.project.Project
12-
import com.simiacryptus.jopenai.models.ChatModels
9+
import com.simiacryptus.jopenai.models.ChatModel
10+
import com.simiacryptus.jopenai.models.chatModel
1311
import com.simiacryptus.jopenai.proxy.ChatProxy
12+
import org.jsoup.Jsoup
13+
import org.jsoup.nodes.Document
1414
import java.awt.Toolkit
1515
import java.awt.datatransfer.DataFlavor
1616
import kotlin.toString
1717

18-
abstract class PasteActionBase(private val model: (AppSettingsState) -> ChatModels) : SelectionAction<String>(false) {
18+
abstract class PasteActionBase(private val model: (AppSettingsState) -> ChatModel) : SelectionAction<String>(false) {
1919
override fun getActionUpdateThread() = ActionUpdateThread.BGT
2020

2121
interface VirtualAPI {
@@ -81,20 +81,62 @@ abstract class PasteActionBase(private val model: (AppSettingsState) -> ChatMode
8181
}
8282
}
8383

84-
protected open fun scrubHtml(str: String): String {
84+
protected open fun scrubHtml(str: String, maxLength: Int = 100 * 1024): String {
8585
val document: Document = Jsoup.parse(str)
86-
document.select("script, style").remove() // Remove script and style tags
87-
document.select("*").forEach { element ->
88-
val importantAttributes = listOf("href", "src", "alt", "title", "width", "height", "style", "class", "id")
89-
element.attributes().filter { it.key !in importantAttributes }.forEach { element.removeAttr(it.key) }
90-
} // Remove all non-important attributes
91-
document.select("*").forEach { element ->
92-
if (element.text().isNullOrEmpty()) {
93-
element.remove()
86+
// Remove unnecessary elements, attributes, and optimize the document
87+
document.apply {
88+
if (document.body().html().length > maxLength) return@apply
89+
select("script, style, link, meta, iframe, noscript").remove() // Remove unnecessary and potentially harmful tags
90+
outputSettings().prettyPrint(false) // Disable pretty printing for compact output
91+
if (document.body().html().length > maxLength) return@apply
92+
// Remove comments
93+
select("*").forEach { it.childNodes().removeAll { node -> node.nodeName() == "#comment" } }
94+
if (document.body().html().length > maxLength) return@apply
95+
// Remove data-* attributes
96+
select("*[data-*]").forEach { it.attributes().removeAll { attr -> attr.key.startsWith("data-") } }
97+
if (document.body().html().length > maxLength) return@apply
98+
select("*").forEach { element ->
99+
val importantAttributes = setOf("href", "src", "alt", "title", "width", "height", "style", "class", "id", "name")
100+
element.attributes().removeAll { it.key !in importantAttributes }
101+
}
102+
if (document.body().html().length > maxLength) return@apply
103+
// Remove empty elements
104+
select("*").filter { it.text().isBlank() && it.attributes().isEmpty() && !it.hasAttr("img") }.forEach { remove() }
105+
if (document.body().html().length > maxLength) return@apply
106+
// Unwrap single-child elements with no attributes
107+
select("*").forEach { element ->
108+
if (element.childNodes().size == 1 && element.childNodes()[0].nodeName() == "#text" && element.attributes().isEmpty()) {
109+
element.unwrap()
110+
}
111+
}
112+
if (document.body().html().length > maxLength) return@apply
113+
// Convert relative URLs to absolute
114+
select("[href],[src]").forEach { element ->
115+
element.attr("href")?.let { href -> element.attr("href", href.makeAbsolute()) }
116+
element.attr("src")?.let { src -> element.attr("src", src.makeAbsolute()) }
94117
}
95-
} // Remove elements with empty text
96-
val text = document.toString()
97-
return text // Return the plain text content
118+
if (document.body().html().length > maxLength) return@apply
119+
// Remove empty attributes
120+
select("*").forEach { element ->
121+
element.attributes().removeAll { it.value.isBlank() }
122+
}
123+
}
124+
125+
// Truncate if necessary
126+
val result = document.body().html()
127+
return if (result.length > maxLength) {
128+
result.substring(0, maxLength)
129+
} else {
130+
result
131+
}
132+
}
133+
134+
private fun String.makeAbsolute(): String {
135+
return if (startsWith("http://") || startsWith("https://") || startsWith("//")) {
136+
this
137+
} else {
138+
"https://$this"
139+
}
98140
}
99141
}
100142

src/main/kotlin/com/github/simiacryptus/aicoder/actions/dev/LineFilterChatAction.kt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@ import com.intellij.openapi.actionSystem.CommonDataKeys
1212
import com.intellij.openapi.fileEditor.FileDocumentManager
1313
import com.simiacryptus.jopenai.models.chatModel
1414
import com.simiacryptus.skyenet.core.platform.ApplicationServices
15-
import com.simiacryptus.skyenet.core.platform.StorageInterface
16-
import com.simiacryptus.skyenet.core.platform.User
15+
import com.simiacryptus.skyenet.core.platform.Session
16+
import com.simiacryptus.skyenet.core.platform.model.User
1717
import com.simiacryptus.skyenet.util.MarkdownUtil.renderMarkdown
1818
import com.simiacryptus.skyenet.webui.application.ApplicationServer
1919
import com.simiacryptus.skyenet.webui.chat.ChatSocketManager
@@ -27,7 +27,7 @@ class LineFilterChatAction : BaseAction() {
2727

2828
override fun handle(e: AnActionEvent) {
2929
val editor = e.getData(CommonDataKeys.EDITOR) ?: return
30-
val session = StorageInterface.newGlobalID()
30+
val session = Session.newGlobalID()
3131
val language = ComputerLanguage.getComputerLanguage(e)?.name ?: return
3232
val filename = FileDocumentManager.getInstance().getFile(editor.document)?.name ?: return
3333
val code = editor.caretModel.primaryCaret.selectedText ?: editor.document.text

src/main/kotlin/com/github/simiacryptus/aicoder/actions/generic/CodeChatAction.kt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,16 @@
33
import com.github.simiacryptus.aicoder.AppServer
44
import com.github.simiacryptus.aicoder.actions.BaseAction
55
import com.github.simiacryptus.aicoder.config.AppSettingsState
6-
import com.simiacryptus.jopenai.models.chatModel
6+
import com.github.simiacryptus.aicoder.util.BrowseUtil.browse
77
import com.github.simiacryptus.aicoder.util.CodeChatSocketManager
88
import com.github.simiacryptus.aicoder.util.LanguageUtils
9-
import com.github.simiacryptus.aicoder.util.BrowseUtil.browse
109
import com.intellij.openapi.actionSystem.ActionUpdateThread
1110
import com.intellij.openapi.actionSystem.AnActionEvent
1211
import com.intellij.openapi.actionSystem.CommonDataKeys
1312
import com.intellij.openapi.fileEditor.FileDocumentManager
13+
import com.simiacryptus.jopenai.models.chatModel
1414
import com.simiacryptus.skyenet.core.platform.ApplicationServices
15-
import com.simiacryptus.skyenet.core.platform.StorageInterface
15+
import com.simiacryptus.skyenet.core.platform.Session
1616
import com.simiacryptus.skyenet.webui.application.AppInfoData
1717
import com.simiacryptus.skyenet.webui.application.ApplicationServer
1818
import org.slf4j.LoggerFactory
@@ -23,7 +23,7 @@ class CodeChatAction : BaseAction() {
2323
override fun handle(e: AnActionEvent) {
2424
val editor = e.getData(CommonDataKeys.EDITOR) ?: return
2525

26-
val session = StorageInterface.newGlobalID()
26+
val session = Session.newGlobalID()
2727
val language = LanguageUtils.getComputerLanguage(e)?.name ?: ""
2828
val filename = FileDocumentManager.getInstance().getFile(editor.document)?.name ?: return
2929

0 commit comments

Comments
 (0)