feat(chat): intercept /new in canonical Bot Chat sessions to /compact (#979)
This commit is contained in:
5 files changed
+63
-1
No files matched your search
@@ -1573,7 +1573,22 @@ class ChatViewModel(
|
||||
}
|
||||
|
||||
is SlashResult.NewSession -> {
|
||||
createNewSession()
|
||||
val currentTitle = _uiState.value.chatTitle
|
||||
if (currentTitle.equals("Bot Chat", ignoreCase = true)) {
|
||||
// Bot Chat is a canonical forever-conversation — compact instead of creating an orphan
|
||||
val sessionId = _uiState.value.currentSessionId
|
||||
if (!sessionId.isNullOrBlank()) {
|
||||
addAssistantMessage(
|
||||
"Bot chats are one continuous conversation — compacting instead. " +
|
||||
"For a throwaway session, create a standard chat.",
|
||||
)
|
||||
dispatchViaRpc("/compact")
|
||||
} else {
|
||||
createNewSession()
|
||||
}
|
||||
} else {
|
||||
createNewSession()
|
||||
}
|
||||
}
|
||||
|
||||
is SlashResult.SessionBranch -> {
|
||||
|
||||
@@ -104,6 +104,7 @@
|
||||
<string name="action_reply">답장</string>
|
||||
|
||||
<!-- Chat Screen & Bubble -->
|
||||
<string name="bot_chat_never_resets_notice">봇 대화는 지속적인 대화입니다 — 대신 압축합니다. 임시 세션을 사용하려면 일반 채팅을 생성하세요.</string>
|
||||
<string name="chat_action_search">검색</string>
|
||||
<string name="chat_action_close_search">검색 닫기</string>
|
||||
<string name="chat_action_reconnect">재접속</string>
|
||||
|
||||
@@ -105,6 +105,7 @@
|
||||
<string name="notif_channel_chat_name">Hermes 对话回复</string>
|
||||
<string name="notif_channel_chat_desc">Hermes 新回复提醒</string>
|
||||
<string name="action_reply">回复</string>
|
||||
<string name="bot_chat_never_resets_notice">Bot 聊天是连续对话 — 正在压缩替代。如需临时会话,请使用普通聊天。</string>
|
||||
<string name="chat_action_search">搜索</string>
|
||||
<string name="chat_action_close_search">关闭搜索</string>
|
||||
<string name="chat_action_reconnect">重新连接</string>
|
||||
|
||||
@@ -122,6 +122,7 @@
|
||||
<string name="action_reply">Reply</string>
|
||||
|
||||
<!-- Chat Screen & Bubble -->
|
||||
<string name="bot_chat_never_resets_notice">Bot chats are one continuous conversation — compacting instead. For a throwaway session, create a standard chat.</string>
|
||||
<string name="chat_action_search">Search</string>
|
||||
<string name="chat_action_close_search">Close search</string>
|
||||
<string name="chat_action_reconnect">Reconnect</string>
|
||||
|
||||
@@ -288,6 +288,50 @@ class ChatViewModelTest {
|
||||
verify(atLeast = 1) { HermesWsClient.send(WsMethods.SESSION_CREATE, any(), any()) }
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testSlashCommand_new_inBotChat_compactsInsteadOfCreatingSession() =
|
||||
runTest {
|
||||
val (viewModel, sessionId) = createViewModelWithSession()
|
||||
// Set session title to "Bot Chat" via SESSION_LIST result
|
||||
mockEventsFlow.emit(
|
||||
WsEvent.RpcResult(
|
||||
id = "req-id-1",
|
||||
result =
|
||||
mapOf(
|
||||
"sessions" to
|
||||
listOf(
|
||||
mapOf(
|
||||
"id" to sessionId,
|
||||
"title" to "Bot Chat",
|
||||
"message_count" to 5.0,
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
)
|
||||
advanceUntilIdle()
|
||||
|
||||
// Reset recording on HermesWsClient to only inspect calls after /new
|
||||
clearMocks(HermesWsClient, answers = false, recordedCalls = true)
|
||||
|
||||
viewModel.sendMessage("/new")
|
||||
advanceUntilIdle()
|
||||
|
||||
// In Bot Chat, /new should NOT create a fresh session, but instead dispatch /compact
|
||||
verify(exactly = 0) {
|
||||
HermesWsClient.send(
|
||||
WsMethods.SESSION_CREATE,
|
||||
any(),
|
||||
any(),
|
||||
)
|
||||
}
|
||||
assertTrue(
|
||||
viewModel.uiState.value.messages.any {
|
||||
it.content.contains("compacting instead")
|
||||
},
|
||||
)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun profileSwitch_wipesOpenSessionForFreshStart() =
|
||||
runTest {
|
||||
|
||||
Reference in new issue
Block a user