Skip to content

Commit e33509a

Browse files
committed
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.
1 parent 09f6c06 commit e33509a

File tree

4 files changed

+102
-10
lines changed

4 files changed

+102
-10
lines changed

exts/ext-harmonyos/src/main/kotlin/cc/unitmesh/harmonyos/actions/AndroidPageToArkUiAction.kt

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,9 @@ import cc.unitmesh.devti.gui.sendToChatPanel
44
import cc.unitmesh.devti.intentions.action.base.ChatBaseIntention
55
import cc.unitmesh.devti.llms.LlmFactory
66
import com.intellij.openapi.editor.Editor
7+
import com.intellij.openapi.progress.ProgressManager
8+
import com.intellij.openapi.progress.impl.BackgroundableProcessIndicator
79
import com.intellij.openapi.project.Project
8-
import com.intellij.openapi.util.NlsSafe
910
import com.intellij.psi.PsiFile
1011

1112
class AndroidPageToArkUiAction : ChatBaseIntention() {
@@ -22,20 +23,17 @@ class AndroidPageToArkUiAction : ChatBaseIntention() {
2223
if (editor == null || file == null) return
2324
val selectedText = editor.selectionModel.selectedText ?: return
2425

25-
val autoUi = AutoArkUi(project, selectedText, editor)
26+
val context = ArkUiContext(selectedText)
2627

2728
sendToChatPanel(project) { contentPanel, _ ->
2829
val llmProvider = LlmFactory().create(project)
29-
// val context = AutoPageContext.build(reactAutoPage, language, frameworks)
30-
// val prompter = AutoPageFlow(context, contentPanel, llmProvider)
31-
//
32-
// ProgressManager.getInstance()
33-
// .runProcessWithProgressAsynchronously(task, BackgroundableProcessIndicator(task))
30+
val prompter = AutoArkUiFlow(contentPanel, llmProvider, context)
31+
val task = AutoPageTask(project, prompter, editor)
32+
33+
ProgressManager.getInstance()
34+
.runProcessWithProgressAsynchronously(task, BackgroundableProcessIndicator(task))
3435
}
3536
}
3637
}
3738

38-
class AutoArkUi(project: Project, selectedText: @NlsSafe String, editor: Editor) {
39-
// parse select text
40-
}
4139

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
package cc.unitmesh.harmonyos.actions
2+
3+
data class ArkUiContext(
4+
val selectedText: String,
5+
val layoutType: List<LayoutType> = emptyList(),
6+
val componentType: List<ComponentType> = emptyList(),
7+
)
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
package cc.unitmesh.harmonyos.actions
2+
3+
import cc.unitmesh.devti.AutoDevBundle
4+
import cc.unitmesh.devti.flow.TaskFlow
5+
import cc.unitmesh.devti.gui.chat.ChatCodingPanel
6+
import cc.unitmesh.devti.llms.LLMProvider
7+
import cc.unitmesh.devti.template.TemplateRender
8+
import kotlinx.coroutines.runBlocking
9+
10+
class AutoArkUiFlow(val panel: ChatCodingPanel, val llm: LLMProvider, val context: ArkUiContext) :
11+
TaskFlow<String> {
12+
override fun clarify(): String {
13+
val stepOnePrompt = generateStepOnePrompt(context)
14+
15+
panel.addMessage(stepOnePrompt, true, stepOnePrompt)
16+
panel.addMessage(AutoDevBundle.message("autodev.loading"))
17+
18+
return runBlocking {
19+
val prompt = llm.stream(stepOnePrompt, "")
20+
return@runBlocking panel.updateMessage(prompt)
21+
}
22+
}
23+
24+
private fun generateStepOnePrompt(context: ArkUiContext): String {
25+
val templateRender = TemplateRender("genius/harmonyos")
26+
val template = templateRender.getTemplate("arkui-clarify.vm")
27+
28+
templateRender.context = context
29+
30+
val prompter = templateRender.renderTemplate(template)
31+
return prompter
32+
}
33+
34+
35+
override fun design(context: Any): List<String> {
36+
val componentList = context as List<ComponentType>
37+
val stepTwoPrompt = generateStepTwoPrompt(componentList)
38+
39+
panel.addMessage(stepTwoPrompt, true, stepTwoPrompt)
40+
panel.addMessage(AutoDevBundle.message("autodev.loading"))
41+
42+
return runBlocking {
43+
val prompt = llm.stream(stepTwoPrompt, "")
44+
return@runBlocking panel.updateMessage(prompt)
45+
}.let { listOf(it) }
46+
}
47+
48+
private fun generateStepTwoPrompt(selectedComponents: List<ComponentType>): String {
49+
val templateRender = TemplateRender("genius/harmonyos")
50+
val template = templateRender.getTemplate("arkui-design.vm")
51+
52+
// context.pages = selectedComponents.map { it.format() }
53+
templateRender.context = context
54+
55+
val prompter = templateRender.renderTemplate(template)
56+
return prompter
57+
}
58+
}
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
package cc.unitmesh.harmonyos.actions
2+
3+
import cc.unitmesh.devti.AutoDevBundle
4+
import com.intellij.openapi.editor.Editor
5+
import com.intellij.openapi.progress.ProgressIndicator
6+
import com.intellij.openapi.progress.Task
7+
import com.intellij.openapi.project.Project
8+
9+
class AutoPageTask(
10+
private val project: Project,
11+
private val flow: AutoArkUiFlow,
12+
private val editor: Editor,
13+
) : Task.Backgroundable(project, "Gen Page", true) {
14+
override fun run(indicator: ProgressIndicator) {
15+
indicator.fraction = 0.2
16+
17+
indicator.text = AutoDevBundle.message("autopage.generate.clarify")
18+
val components = flow.clarify()
19+
// tables will be list in string format, like: `[table1, table2]`, we need to parse to Lists
20+
val componentNames = components.substringAfter("[").substringBefore("]")
21+
.split(", ").map { it.trim() }
22+
23+
indicator.fraction = 0.6
24+
indicator.text = AutoDevBundle.message("autopage.generate.design")
25+
26+
indicator.fraction = 0.8
27+
28+
}
29+
}

0 commit comments

Comments
 (0)