Skip to content

Commit a6ef010

Browse files
committed
feat(harmonyos): update AutoArkUiFlow and related classes
- 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.
1 parent 592e793 commit a6ef010

File tree

9 files changed

+41
-18
lines changed

9 files changed

+41
-18
lines changed

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@ package cc.unitmesh.harmonyos.actions
33
import cc.unitmesh.devti.gui.sendToChatPanel
44
import cc.unitmesh.devti.intentions.action.base.ChatBaseIntention
55
import cc.unitmesh.devti.llms.LlmFactory
6-
import cc.unitmesh.harmonyos.actions.auto.ArkUiContext
6+
import cc.unitmesh.harmonyos.actions.auto.AutoArkUiContext
77
import cc.unitmesh.harmonyos.actions.auto.AutoArkUiFlow
8-
import cc.unitmesh.harmonyos.actions.auto.AutoPageTask
8+
import cc.unitmesh.harmonyos.actions.auto.AutoArkUiTask
99
import com.intellij.openapi.editor.Editor
1010
import com.intellij.openapi.progress.ProgressManager
1111
import com.intellij.openapi.progress.impl.BackgroundableProcessIndicator
@@ -26,12 +26,12 @@ class AutoArkUiAction : ChatBaseIntention() {
2626
if (editor == null || file == null) return
2727
val selectedText = editor.selectionModel.selectedText ?: return
2828

29-
val context = ArkUiContext(selectedText)
29+
val context = AutoArkUiContext(selectedText)
3030

3131
sendToChatPanel(project) { contentPanel, _ ->
3232
val llmProvider = LlmFactory().create(project)
3333
val prompter = AutoArkUiFlow(contentPanel, llmProvider, context)
34-
val task = AutoPageTask(project, prompter, editor)
34+
val task = AutoArkUiTask(project, prompter, editor)
3535

3636
ProgressManager.getInstance()
3737
.runProcessWithProgressAsynchronously(task, BackgroundableProcessIndicator(task))

exts/ext-harmonyos/src/main/kotlin/cc/unitmesh/harmonyos/actions/auto/ComponentType.kt renamed to exts/ext-harmonyos/src/main/kotlin/cc/unitmesh/harmonyos/actions/auto/ArkUiComponentType.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
package cc.unitmesh.harmonyos.actions.auto
22

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

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

Lines changed: 0 additions & 7 deletions
This file was deleted.
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
package cc.unitmesh.harmonyos.actions.auto
2+
3+
data class AutoArkUiContext(
4+
val requirement: String,
5+
val layoutOverride: String,
6+
val componentOverride: String,
7+
val layouts: List<String> = emptyList(),
8+
val components: List<String> = emptyList(),
9+
)

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import cc.unitmesh.devti.llms.LLMProvider
77
import cc.unitmesh.devti.template.TemplateRender
88
import kotlinx.coroutines.runBlocking
99

10-
class AutoArkUiFlow(val panel: ChatCodingPanel, val llm: LLMProvider, val context: ArkUiContext) :
10+
class AutoArkUiFlow(val panel: ChatCodingPanel, val llm: LLMProvider, val context: AutoArkUiContext) :
1111
TaskFlow<String> {
1212
override fun clarify(): String {
1313
val stepOnePrompt = generateStepOnePrompt(context)
@@ -21,7 +21,7 @@ class AutoArkUiFlow(val panel: ChatCodingPanel, val llm: LLMProvider, val contex
2121
}
2222
}
2323

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

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

3434

3535
override fun design(context: Any): List<String> {
36-
val componentList = context as List<ComponentType>
36+
val componentList = context as List<ArkUiComponentType>
3737
val stepTwoPrompt = generateStepTwoPrompt(componentList)
3838

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

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

exts/ext-harmonyos/src/main/kotlin/cc/unitmesh/harmonyos/actions/auto/AutoPageTask.kt renamed to exts/ext-harmonyos/src/main/kotlin/cc/unitmesh/harmonyos/actions/auto/AutoArkUiTask.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import com.intellij.openapi.progress.ProgressIndicator
66
import com.intellij.openapi.progress.Task
77
import com.intellij.openapi.project.Project
88

9-
class AutoPageTask(
9+
class AutoArkUiTask(
1010
private val project: Project,
1111
private val flow: AutoArkUiFlow,
1212
private val editor: Editor,

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
package cc.unitmesh.harmonyos.actions.auto
22

33
enum class LayoutType(val description: String, val example: String) {
4-
Flex(
4+
FlexLayout(
55
"弹性布局(Flex)提供更加有效的方式对容器中的子元素进行排列、对齐和分配剩余空间。",
66
"Column({ space: 5 }) {\n" +
77
" Flex({ direction: FlexDirection.Row, wrap: FlexWrap.NoWrap, justifyContent: FlexAlign.SpaceBetween, alignItems: ItemAlign.Center }) {\n" +
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
You are a professional Legacy System migration expert, specif in frontend.
2+
You are working on migration code to ArkUi, a new frontend DSL UI framework with a lot of components and layouts.
3+
According to the user's code/requirements, you should choose the best Layout and components for the user.
4+
5+
— ArkUi layout: ${context.layoutOverride}
6+
- ArkUi component: ${context.componentOverride}
7+
8+
For example:
9+
10+
User: // maybe send Android Layout code, maybe some requirements
11+
Your Answer: [FlexLayout, Button, CheckBox, Checkbox, Button]
12+
13+
----
14+
15+
Here are the User code/requirements:
16+
17+
```markdown
18+
${context.requirement}
19+
```
20+
21+
Please choose the best Layout and components for the user, just return the components and layouts names in a list, no explaining.

exts/ext-harmonyos/src/main/resources/genius/harmonyos/arkui-design.vm

Whitespace-only changes.

0 commit comments

Comments
 (0)