generated from JetBrains/intellij-platform-plugin-template
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(harmonyos): add AutoArkUiFlow class and ArkUiContext data class
Add `AutoArkUiFlow` class and `ArkUiContext` data class to the `ext-harmonyos` module. These classes are necessary for implementing the automated UI flow in HarmonyOS. The `AutoArkUiFlow` class contains methods for clarifying and designing UI components, while the `ArkUiContext` data class holds the relevant information for the UI design process.
- Loading branch information
Showing
4 changed files
with
102 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
7 changes: 7 additions & 0 deletions
7
exts/ext-harmonyos/src/main/kotlin/cc/unitmesh/harmonyos/actions/ArkUiContext.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
package cc.unitmesh.harmonyos.actions | ||
|
||
data class ArkUiContext( | ||
val selectedText: String, | ||
val layoutType: List<LayoutType> = emptyList(), | ||
val componentType: List<ComponentType> = emptyList(), | ||
) |
58 changes: 58 additions & 0 deletions
58
exts/ext-harmonyos/src/main/kotlin/cc/unitmesh/harmonyos/actions/AutoArkUiFlow.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
package cc.unitmesh.harmonyos.actions | ||
|
||
import cc.unitmesh.devti.AutoDevBundle | ||
import cc.unitmesh.devti.flow.TaskFlow | ||
import cc.unitmesh.devti.gui.chat.ChatCodingPanel | ||
import cc.unitmesh.devti.llms.LLMProvider | ||
import cc.unitmesh.devti.template.TemplateRender | ||
import kotlinx.coroutines.runBlocking | ||
|
||
class AutoArkUiFlow(val panel: ChatCodingPanel, val llm: LLMProvider, val context: ArkUiContext) : | ||
TaskFlow<String> { | ||
override fun clarify(): String { | ||
val stepOnePrompt = generateStepOnePrompt(context) | ||
|
||
panel.addMessage(stepOnePrompt, true, stepOnePrompt) | ||
panel.addMessage(AutoDevBundle.message("autodev.loading")) | ||
|
||
return runBlocking { | ||
val prompt = llm.stream(stepOnePrompt, "") | ||
return@runBlocking panel.updateMessage(prompt) | ||
} | ||
} | ||
|
||
private fun generateStepOnePrompt(context: ArkUiContext): String { | ||
val templateRender = TemplateRender("genius/harmonyos") | ||
val template = templateRender.getTemplate("arkui-clarify.vm") | ||
|
||
templateRender.context = context | ||
|
||
val prompter = templateRender.renderTemplate(template) | ||
return prompter | ||
} | ||
|
||
|
||
override fun design(context: Any): List<String> { | ||
val componentList = context as List<ComponentType> | ||
val stepTwoPrompt = generateStepTwoPrompt(componentList) | ||
|
||
panel.addMessage(stepTwoPrompt, true, stepTwoPrompt) | ||
panel.addMessage(AutoDevBundle.message("autodev.loading")) | ||
|
||
return runBlocking { | ||
val prompt = llm.stream(stepTwoPrompt, "") | ||
return@runBlocking panel.updateMessage(prompt) | ||
}.let { listOf(it) } | ||
} | ||
|
||
private fun generateStepTwoPrompt(selectedComponents: List<ComponentType>): String { | ||
val templateRender = TemplateRender("genius/harmonyos") | ||
val template = templateRender.getTemplate("arkui-design.vm") | ||
|
||
// context.pages = selectedComponents.map { it.format() } | ||
templateRender.context = context | ||
|
||
val prompter = templateRender.renderTemplate(template) | ||
return prompter | ||
} | ||
} |
29 changes: 29 additions & 0 deletions
29
exts/ext-harmonyos/src/main/kotlin/cc/unitmesh/harmonyos/actions/AutoPageTask.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
package cc.unitmesh.harmonyos.actions | ||
|
||
import cc.unitmesh.devti.AutoDevBundle | ||
import com.intellij.openapi.editor.Editor | ||
import com.intellij.openapi.progress.ProgressIndicator | ||
import com.intellij.openapi.progress.Task | ||
import com.intellij.openapi.project.Project | ||
|
||
class AutoPageTask( | ||
private val project: Project, | ||
private val flow: AutoArkUiFlow, | ||
private val editor: Editor, | ||
) : Task.Backgroundable(project, "Gen Page", true) { | ||
override fun run(indicator: ProgressIndicator) { | ||
indicator.fraction = 0.2 | ||
|
||
indicator.text = AutoDevBundle.message("autopage.generate.clarify") | ||
val components = flow.clarify() | ||
// tables will be list in string format, like: `[table1, table2]`, we need to parse to Lists | ||
val componentNames = components.substringAfter("[").substringBefore("]") | ||
.split(", ").map { it.trim() } | ||
|
||
indicator.fraction = 0.6 | ||
indicator.text = AutoDevBundle.message("autopage.generate.design") | ||
|
||
indicator.fraction = 0.8 | ||
|
||
} | ||
} |