Skip to content

Commit 7a7c2b9

Browse files
committed
feat(agent): add Local agent type and session handling #453
Introduce a "Local" agent type with corresponding display name and update session selection and creation logic to support agent mode handlers for local agents.
1 parent 2fc4403 commit 7a7c2b9

File tree

2 files changed

+17
-19
lines changed

2 files changed

+17
-19
lines changed

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

Lines changed: 15 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@ import cc.unitmesh.devins.workspace.WorkspaceManager
3131
import cc.unitmesh.llm.KoogLLMService
3232
import cc.unitmesh.llm.ModelConfig
3333
import kotlinx.coroutines.launch
34-
// Import UnifiedApp components for Session Management
3534
import cc.unitmesh.devins.ui.app.UnifiedAppContent
3635

3736
@OptIn(ExperimentalMaterial3Api::class)
@@ -111,13 +110,9 @@ private fun AutoDevContent(
111110

112111
val workspaceState by WorkspaceManager.workspaceFlow.collectAsState()
113112

114-
// Agent 类型切换处理函数 - 统一保存到配置
115113
fun handleAgentTypeChange(type: String) {
116-
println("🔄 切换 Agent Type: $type")
117114
if (type == "Remote") {
118-
val hasValidServerConfig = serverUrl.isNotBlank() &&
119-
serverUrl != "http://localhost:8080"
120-
115+
val hasValidServerConfig = serverUrl.isNotBlank() && serverUrl != "http://localhost:8080"
121116
if (!hasValidServerConfig) {
122117
showRemoteConfigDialog = true
123118
return
@@ -296,22 +291,18 @@ private fun AutoDevContent(
296291
chatHistoryManager = chatHistoryManager,
297292
currentSessionId = chatHistoryManager.getCurrentSession().id,
298293
onSessionSelected = { sessionId ->
299-
// Agent 模式:调用 Agent ViewModel 的处理器
300294
if (useAgentMode && agentSessionSelectedHandler != null) {
301295
agentSessionSelectedHandler?.invoke(sessionId)
302296
} else {
303-
// Chat 模式:直接更新本地状态
304297
chatHistoryManager.switchSession(sessionId)
305298
messages = chatHistoryManager.getMessages()
306299
currentStreamingOutput = ""
307300
}
308301
},
309302
onNewChat = {
310-
// Agent 模式:调用 Agent ViewModel 的处理器
311303
if (useAgentMode && agentNewChatHandler != null) {
312304
agentNewChatHandler?.invoke()
313305
} else {
314-
// Chat 模式:直接更新本地状态
315306
chatHistoryManager.createSession()
316307
messages = emptyList()
317308
currentStreamingOutput = ""
@@ -386,32 +377,37 @@ private fun AutoDevContent(
386377
}
387378

388379
if (useAgentMode) {
389-
// Conditional rendering based on agent type
390380
if (selectedAgentType == "Local") {
391381
AgentChatInterface(
392382
llmService = llmService,
393383
isTreeViewVisible = isTreeViewVisible,
394384
onConfigWarning = { showModelConfigDialog = true },
395385
onToggleTreeView = { isTreeViewVisible = it },
396-
// 传入会话管理(Agent 模式也支持会话历史)
397386
chatHistoryManager = chatHistoryManager,
398-
// 会话切换回调
399387
onSessionSelected = { sessionId ->
400-
// Agent 模式的 session 切换由 ViewModel 处理
401-
println("✅ [Agent] Switched to session: $sessionId")
388+
if (useAgentMode && agentSessionSelectedHandler != null) {
389+
agentSessionSelectedHandler?.invoke(sessionId)
390+
} else {
391+
chatHistoryManager.switchSession(sessionId)
392+
messages = chatHistoryManager.getMessages()
393+
currentStreamingOutput = ""
394+
}
402395
},
403396
onNewChat = {
404-
// Agent 模式的 new session 由 ViewModel 处理
405-
println("✅ [Agent] Created new session")
397+
if (useAgentMode && agentNewChatHandler != null) {
398+
agentNewChatHandler?.invoke()
399+
} else {
400+
chatHistoryManager.createSession()
401+
messages = emptyList()
402+
currentStreamingOutput = ""
403+
}
406404
},
407-
// 导出内部处理器给 SessionSidebar 使用
408405
onInternalSessionSelected = { handler ->
409406
agentSessionSelectedHandler = handler
410407
},
411408
onInternalNewChat = { handler ->
412409
agentNewChatHandler = handler
413410
},
414-
// TopBar 参数
415411
hasHistory = messages.isNotEmpty(),
416412
hasDebugInfo = compilerOutput.isNotEmpty(),
417413
currentModelConfig = currentModelConfig,

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,12 @@ package cc.unitmesh.devins.ui.compose.agent
44
* Enum representing available agent types
55
*/
66
enum class AgentType {
7+
LOCAL,
78
CODING,
89
CODE_REVIEW;
910

1011
fun getDisplayName(): String = when (this) {
12+
LOCAL -> "Local Agent"
1113
CODING -> "Coding Agent"
1214
CODE_REVIEW -> "Code Review"
1315
}

0 commit comments

Comments
 (0)