Skip to content

Commit

Permalink
feat(harmonyos): add AutoArkUiFlow class and ArkUiContext data class
Browse files Browse the repository at this point in the history
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
phodal committed Feb 23, 2024
1 parent 09f6c06 commit e33509a
Show file tree
Hide file tree
Showing 4 changed files with 102 additions and 10 deletions.
Expand Up @@ -4,8 +4,9 @@ import cc.unitmesh.devti.gui.sendToChatPanel
import cc.unitmesh.devti.intentions.action.base.ChatBaseIntention
import cc.unitmesh.devti.llms.LlmFactory
import com.intellij.openapi.editor.Editor
import com.intellij.openapi.progress.ProgressManager
import com.intellij.openapi.progress.impl.BackgroundableProcessIndicator
import com.intellij.openapi.project.Project
import com.intellij.openapi.util.NlsSafe
import com.intellij.psi.PsiFile

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

val autoUi = AutoArkUi(project, selectedText, editor)
val context = ArkUiContext(selectedText)

sendToChatPanel(project) { contentPanel, _ ->
val llmProvider = LlmFactory().create(project)
// val context = AutoPageContext.build(reactAutoPage, language, frameworks)
// val prompter = AutoPageFlow(context, contentPanel, llmProvider)
//
// ProgressManager.getInstance()
// .runProcessWithProgressAsynchronously(task, BackgroundableProcessIndicator(task))
val prompter = AutoArkUiFlow(contentPanel, llmProvider, context)
val task = AutoPageTask(project, prompter, editor)

ProgressManager.getInstance()
.runProcessWithProgressAsynchronously(task, BackgroundableProcessIndicator(task))
}
}
}

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

@@ -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(),
)
@@ -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
}
}
@@ -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

}
}

0 comments on commit e33509a

Please sign in to comment.