Skip to content

Commit 9e0969d

Browse files
committed
feat(endpoints): enhance web API endpoint display format
- Add a descriptive header to the web API endpoint output. - Wrap compilation and conversation creation in `invokeLater` to ensure thread safety. - Refactor output handling to improve readability and maintainability.
1 parent bd4060d commit 9e0969d

File tree

2 files changed

+27
-23
lines changed

2 files changed

+27
-23
lines changed

exts/devins-lang/src/main/kotlin/cc/unitmesh/devti/language/run/DevInsRunConfigurationProfileState.kt

Lines changed: 24 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ import com.intellij.ide.scratch.ScratchRootType
2727
import com.intellij.openapi.actionSystem.ActionManager
2828
import com.intellij.openapi.actionSystem.DefaultActionGroup
2929
import com.intellij.openapi.application.ApplicationManager
30+
import com.intellij.openapi.application.invokeLater
3031
import com.intellij.openapi.application.runInEdt
3132
import com.intellij.openapi.application.runReadAction
3233
import com.intellij.openapi.application.runWriteAction
@@ -101,34 +102,35 @@ open class DevInsRunConfigurationProfileState(
101102
}
102103

103104
// save the run result
104-
val compiler = DevInsCompiler(myProject, file)
105-
val compileResult = compiler.compile()
105+
invokeLater {
106+
val compiler = DevInsCompiler(myProject, file)
107+
val compileResult = compiler.compile()
106108

107-
myProject.service<DevInsConversationService>().createConversation(configuration.getScriptPath(), compileResult)
109+
myProject.service<DevInsConversationService>().createConversation(configuration.getScriptPath(), compileResult)
108110

109-
val output = compileResult.output
110-
val agent = compileResult.executeAgent
111+
val output = compileResult.output
112+
val agent = compileResult.executeAgent
111113

112-
output.split("\n").forEach {
113-
if (it.contains(DEVINS_ERROR)) {
114-
console.print(it, ConsoleViewContentType.LOG_ERROR_OUTPUT)
115-
} else {
116-
console.print(it, ConsoleViewContentType.USER_INPUT)
114+
output.split("\n").forEach {
115+
if (it.contains(DEVINS_ERROR)) {
116+
console.print(it, ConsoleViewContentType.LOG_ERROR_OUTPUT)
117+
} else {
118+
console.print(it, ConsoleViewContentType.USER_INPUT)
119+
}
120+
console.print("\n", ConsoleViewContentType.NORMAL_OUTPUT)
117121
}
118-
console.print("\n", ConsoleViewContentType.NORMAL_OUTPUT)
119-
}
120122

121-
console.print("\n--------------------\n", ConsoleViewContentType.NORMAL_OUTPUT)
123+
console.print("\n--------------------\n", ConsoleViewContentType.NORMAL_OUTPUT)
122124

123-
if (output.contains(DEVINS_ERROR)) {
124-
processHandler.exitWithError()
125-
return DefaultExecutionResult(console, processHandler)
126-
}
127-
128-
if (agent != null) {
129-
agentRun(output, console, processHandler, agent)
130-
} else {
131-
defaultRun(output, console, processHandler, compileResult.isLocalCommand)
125+
if (output.contains(DEVINS_ERROR)) {
126+
processHandler.exitWithError()
127+
} else {
128+
if (agent != null) {
129+
agentRun(output, console, processHandler, agent)
130+
} else {
131+
defaultRun(output, console, processHandler, compileResult.isLocalCommand)
132+
}
133+
}
132134
}
133135

134136
return DefaultExecutionResult(console, processHandler)

exts/ext-endpoints/src/233/main/kotlin/cc/unitmesh/endpoints/bridge/WebApiViewFunctionProvider.kt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,8 @@ class WebApiViewFunctionProvider : ToolchainFunctionProvider {
4343
}.flatten()
4444
}.flatten()
4545

46-
return map.joinToString("\n")
46+
return """Here is current project web api endpoints, ${map.size}:""" + map.joinToString("\n") {
47+
"endpoint: ${it.method} - ${it.urlPath}"
48+
}
4749
}
4850
}

0 commit comments

Comments
 (0)