Skip to content

Commit

Permalink
feat(harmonyos): update AutoArkUiFlow and related classes
Browse files Browse the repository at this point in the history
- Updated `AutoArkUiFlow` class to use `AutoArkUiContext` instead of `ArkUiContext` for better type safety.
- Renamed `ArkUiContext` to `AutoArkUiContext` for consistency and clarity.
- Updated references to `LayoutType` and `ComponentType` to `ArkUiComponentType`.
- Renamed `AutoPageTask` class to `AutoArkUiTask` for consistency.
- Added new template file `arkui-clarify.vm` for displaying user code/requirements.
- Updated `AutoArkUiAction` to use `AutoArkUiContext` and `AutoArkUiTask`.
- Renamed `ComponentType` enum to `ArkUiComponentType` for clarity.

This commit improves the AutoArkUiFlow functionality by making use of the newly introduced `AutoArkUiContext` class. The class now accepts an instance of this context instead of `ArkUiContext`, providing better type safety and clarity. Additionally, the `generateStepOnePrompt` and `generateStepTwoPrompt` functions have been updated to use `AutoArkUiContext` and `ArkUiComponentType` as well.

To accompany these changes, the `ArkUiContext` class has been renamed to `AutoArkUiContext` for consistency and clarity. The class now includes additional properties (`requirement`, `layoutOverride`, `componentOverride`, `layouts`, and `components`) for better handling of user requirements and layout/component overrides.

Furthermore, the `LayoutType` enum has been renamed to `FlexLayout` to align with the conventions of the ArkUi framework. Similarly, the `ComponentType` enum has been renamed to `ArkUiComponentType` to clarify its purpose and relationship to ArkUi.

To enhance the user experience, a new template file `arkui-clarify.vm` has been added. This file provides a formatted display of the user's code and requirements, prompting the user to choose the best layout and components based on given information.

The `AutoArkUiTask` class (previously `AutoPageTask`) has been renamed to maintain consistency throughout the codebase.

Finally, the `AutoArkUiAction` class has been updated to use `AutoArkUiContext` and `AutoArkUiTask` instead of the previous classes, ensuring compatibility with the latest changes.

These updates result in a more robust and user-friendly AutoArkUiFlow functionality, making it easier for users to select the appropriate layouts and components for their needs in the HarmonyOS project.
  • Loading branch information
phodal committed Feb 23, 2024
1 parent 592e793 commit a6ef010
Show file tree
Hide file tree
Showing 9 changed files with 41 additions and 18 deletions.
Expand Up @@ -3,9 +3,9 @@ package cc.unitmesh.harmonyos.actions
import cc.unitmesh.devti.gui.sendToChatPanel
import cc.unitmesh.devti.intentions.action.base.ChatBaseIntention
import cc.unitmesh.devti.llms.LlmFactory
import cc.unitmesh.harmonyos.actions.auto.ArkUiContext
import cc.unitmesh.harmonyos.actions.auto.AutoArkUiContext
import cc.unitmesh.harmonyos.actions.auto.AutoArkUiFlow
import cc.unitmesh.harmonyos.actions.auto.AutoPageTask
import cc.unitmesh.harmonyos.actions.auto.AutoArkUiTask
import com.intellij.openapi.editor.Editor
import com.intellij.openapi.progress.ProgressManager
import com.intellij.openapi.progress.impl.BackgroundableProcessIndicator
Expand All @@ -26,12 +26,12 @@ class AutoArkUiAction : ChatBaseIntention() {
if (editor == null || file == null) return
val selectedText = editor.selectionModel.selectedText ?: return

val context = ArkUiContext(selectedText)
val context = AutoArkUiContext(selectedText)

sendToChatPanel(project) { contentPanel, _ ->
val llmProvider = LlmFactory().create(project)
val prompter = AutoArkUiFlow(contentPanel, llmProvider, context)
val task = AutoPageTask(project, prompter, editor)
val task = AutoArkUiTask(project, prompter, editor)

ProgressManager.getInstance()
.runProcessWithProgressAsynchronously(task, BackgroundableProcessIndicator(task))
Expand Down
@@ -1,6 +1,6 @@
package cc.unitmesh.harmonyos.actions.auto

enum class ComponentType(description: String, example: String) {
enum class ArkUiComponentType(description: String, example: String) {
Button(
"可快速创建不同样式的按钮。", "Button('Ok', { type: ButtonType.Normal, stateEffect: true }) \n" +
" .borderRadius(8) \n" +
Expand Down

This file was deleted.

@@ -0,0 +1,9 @@
package cc.unitmesh.harmonyos.actions.auto

data class AutoArkUiContext(
val requirement: String,
val layoutOverride: String,
val componentOverride: String,
val layouts: List<String> = emptyList(),
val components: List<String> = emptyList(),
)
Expand Up @@ -7,7 +7,7 @@ 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) :
class AutoArkUiFlow(val panel: ChatCodingPanel, val llm: LLMProvider, val context: AutoArkUiContext) :
TaskFlow<String> {
override fun clarify(): String {
val stepOnePrompt = generateStepOnePrompt(context)
Expand All @@ -21,7 +21,7 @@ class AutoArkUiFlow(val panel: ChatCodingPanel, val llm: LLMProvider, val contex
}
}

private fun generateStepOnePrompt(context: ArkUiContext): String {
private fun generateStepOnePrompt(context: AutoArkUiContext): String {
val templateRender = TemplateRender("genius/harmonyos")
val template = templateRender.getTemplate("arkui-clarify.vm")

Expand All @@ -33,7 +33,7 @@ class AutoArkUiFlow(val panel: ChatCodingPanel, val llm: LLMProvider, val contex


override fun design(context: Any): List<String> {
val componentList = context as List<ComponentType>
val componentList = context as List<ArkUiComponentType>
val stepTwoPrompt = generateStepTwoPrompt(componentList)

panel.addMessage(stepTwoPrompt, true, stepTwoPrompt)
Expand All @@ -45,7 +45,7 @@ class AutoArkUiFlow(val panel: ChatCodingPanel, val llm: LLMProvider, val contex
}.let { listOf(it) }
}

private fun generateStepTwoPrompt(selectedComponents: List<ComponentType>): String {
private fun generateStepTwoPrompt(selectedComponents: List<ArkUiComponentType>): String {
val templateRender = TemplateRender("genius/harmonyos")
val template = templateRender.getTemplate("arkui-design.vm")

Expand Down
Expand Up @@ -6,7 +6,7 @@ import com.intellij.openapi.progress.ProgressIndicator
import com.intellij.openapi.progress.Task
import com.intellij.openapi.project.Project

class AutoPageTask(
class AutoArkUiTask(
private val project: Project,
private val flow: AutoArkUiFlow,
private val editor: Editor,
Expand Down
@@ -1,7 +1,7 @@
package cc.unitmesh.harmonyos.actions.auto

enum class LayoutType(val description: String, val example: String) {
Flex(
FlexLayout(
"弹性布局(Flex)提供更加有效的方式对容器中的子元素进行排列、对齐和分配剩余空间。",
"Column({ space: 5 }) {\n" +
" Flex({ direction: FlexDirection.Row, wrap: FlexWrap.NoWrap, justifyContent: FlexAlign.SpaceBetween, alignItems: ItemAlign.Center }) {\n" +
Expand Down
@@ -0,0 +1,21 @@
You are a professional Legacy System migration expert, specif in frontend.
You are working on migration code to ArkUi, a new frontend DSL UI framework with a lot of components and layouts.
According to the user's code/requirements, you should choose the best Layout and components for the user.

— ArkUi layout: ${context.layoutOverride}
- ArkUi component: ${context.componentOverride}

For example:

User: // maybe send Android Layout code, maybe some requirements
Your Answer: [FlexLayout, Button, CheckBox, Checkbox, Button]

----

Here are the User code/requirements:

```markdown
${context.requirement}
```

Please choose the best Layout and components for the user, just return the components and layouts names in a list, no explaining.
Empty file.

0 comments on commit a6ef010

Please sign in to comment.