Skip to content

Commit 8f6fccf

Browse files
committed
refactor: Extract RunOutputDock to reusable composable to avoid duplication
1 parent 8400b24 commit 8f6fccf

File tree

2 files changed

+33
-44
lines changed

2 files changed

+33
-44
lines changed

mpp-ui/src/commonMain/kotlin/cc/unitmesh/devins/ui/compose/agent/CodingAgentPage.kt

Lines changed: 25 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ fun CodingAgentPage(
147147
llmService = llmService
148148
)
149149
}
150-
150+
151151
val runConfigState by runConfigViewModel.state.collectAsState()
152152
val runConfigs by runConfigViewModel.configs.collectAsState()
153153
val defaultRunConfig by runConfigViewModel.defaultConfig.collectAsState()
@@ -157,7 +157,7 @@ fun CodingAgentPage(
157157
val runAnalysisLog by runConfigViewModel.analysisLog.collectAsState()
158158

159159
var showRunOutputDock by remember { mutableStateOf(false) }
160-
160+
161161
// Track which mode the dock is in (analysis or run output)
162162
val isAnalyzing = runConfigState == cc.unitmesh.agent.runconfig.RunConfigState.ANALYZING
163163
val dockTitle = if (isAnalyzing) "AI Analysis" else "Run Output"
@@ -170,6 +170,27 @@ fun CodingAgentPage(
170170
}
171171
}
172172

173+
// Extracted RunOutputDock composable to avoid duplication
174+
val runOutputDockContent: @Composable () -> Unit = {
175+
RunOutputDock(
176+
isVisible = showRunOutputDock,
177+
title = dockTitle,
178+
output = dockOutput,
179+
isRunning = isRunning,
180+
onClear = {
181+
runConfigViewModel.clearOutput()
182+
runConfigViewModel.clearAnalysisLog()
183+
},
184+
onClose = { showRunOutputDock = false },
185+
onStop = if (!isAnalyzing) {
186+
{ runConfigViewModel.stopRunning() }
187+
} else null,
188+
modifier = Modifier
189+
.fillMaxWidth()
190+
.padding(horizontal = 12.dp)
191+
)
192+
}
193+
173194
// Main content
174195
Box(modifier = modifier.fillMaxSize()) {
175196
if (isTreeViewVisibleState) {
@@ -260,23 +281,7 @@ fun CodingAgentPage(
260281
when (selectedAgentType) {
261282
AgentType.LOCAL_CHAT,
262283
AgentType.CODING -> {
263-
RunOutputDock(
264-
isVisible = showRunOutputDock,
265-
title = dockTitle,
266-
output = dockOutput,
267-
isRunning = isRunning,
268-
onClear = {
269-
runConfigViewModel.clearOutput()
270-
runConfigViewModel.clearAnalysisLog()
271-
},
272-
onClose = { showRunOutputDock = false },
273-
onStop = if (!isAnalyzing) {
274-
{ runConfigViewModel.stopRunning() }
275-
} else null,
276-
modifier = Modifier
277-
.fillMaxWidth()
278-
.padding(horizontal = 12.dp)
279-
)
284+
runOutputDockContent()
280285
DevInEditorInput(
281286
initialText = "",
282287
placeholder = "Describe your coding task...",
@@ -484,23 +489,7 @@ fun CodingAgentPage(
484489
)
485490
}
486491

487-
RunOutputDock(
488-
isVisible = showRunOutputDock,
489-
title = dockTitle,
490-
output = dockOutput,
491-
isRunning = isRunning,
492-
onClear = {
493-
runConfigViewModel.clearOutput()
494-
runConfigViewModel.clearAnalysisLog()
495-
},
496-
onClose = { showRunOutputDock = false },
497-
onStop = if (!isAnalyzing) {
498-
{ runConfigViewModel.stopRunning() }
499-
} else null,
500-
modifier = Modifier
501-
.fillMaxWidth()
502-
.padding(horizontal = 12.dp)
503-
)
492+
runOutputDockContent()
504493
DevInEditorInput(
505494
initialText = "",
506495
placeholder = "Describe your coding task...",

mpp-ui/src/commonMain/kotlin/cc/unitmesh/devins/ui/compose/agent/artifact/ArtifactMessageList.kt

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ import kotlinx.coroutines.launch
2222

2323
/**
2424
* Custom message list optimized for artifact generation.
25-
*
25+
*
2626
* Unlike AgentMessageList which shows full code details, this component:
2727
* - Shows user messages compactly
2828
* - Displays streaming output in a height-limited scrollable code block
@@ -114,7 +114,7 @@ fun ArtifactMessageList(
114114
userScrolledAway = false
115115
}
116116
}
117-
117+
118118
LazyColumn(
119119
state = listState,
120120
modifier = modifier.padding(horizontal = 12.dp),
@@ -138,7 +138,7 @@ fun ArtifactMessageList(
138138
}
139139
}
140140
}
141-
141+
142142
// Show thinking block if active
143143
if (renderer.isThinking && renderer.currentThinkingOutput.isNotEmpty()) {
144144
item(key = "thinking") {
@@ -149,7 +149,7 @@ fun ArtifactMessageList(
149149
)
150150
}
151151
}
152-
152+
153153
// Show streaming artifact content
154154
if (streamingArtifact != null) {
155155
item(key = "streaming-artifact") {
@@ -189,7 +189,7 @@ private fun ArtifactMessageItem(
189189
content: String
190190
) {
191191
val isUser = role == MessageRole.USER
192-
192+
193193
if (isUser) {
194194
// User messages - right aligned, limited width
195195
Row(
@@ -204,7 +204,7 @@ private fun ArtifactMessageItem(
204204
bottomStart = 12.dp,
205205
bottomEnd = 4.dp
206206
),
207-
modifier = Modifier.widthIn(max = 400.dp)
207+
modifier = Modifier.fillMaxWidth()
208208
) {
209209
Text(
210210
text = content,
@@ -268,7 +268,7 @@ private fun StreamingOutputBlock(
268268
) {
269269
// Extract artifact info if present in streaming output
270270
val hasArtifactTag = content.contains("<autodev-artifact")
271-
271+
272272
Surface(
273273
color = MaterialTheme.colorScheme.surfaceVariant.copy(alpha = 0.3f),
274274
shape = RoundedCornerShape(8.dp),
@@ -291,7 +291,7 @@ private fun StreamingOutputBlock(
291291
color = MaterialTheme.colorScheme.onSurface
292292
)
293293
}
294-
294+
295295
if (!hasArtifactTag && content.length < 500) {
296296
Spacer(modifier = Modifier.height(8.dp))
297297
Surface(

0 commit comments

Comments
 (0)